Fall 2025 quizzes

quiz for week 2

Question 1 (4 pt; mean 3.81)

Consider the following C code:

int a[4] = {1, 2, 3, 4};
int *b[4] = {NULL, NULL, NULL, NULL};
int **pp1 = &b[1];
pp1[0] = &a[1];
int *pp2 = b[1];
*pp1[0] = 2;

After the above statements, which of the following are likely to access out of bounds memory? Select all that apply.

  1. likely compile error; we should have asked something like pp1[pp2[2]] = 3;

Regrade request
Question 2 (5 pt; mean 4.42)

Consider the following Makefile:

all: a b c d

a: e f g
    buildA

b: e d
    buildB

c: e g
    buildC

d: a c
    buildD

(assume there are tab characters before the buildX lines).

Which of the following are true? Select all that apply.

  1. buildB will run since d is updated

  2. buildB runs because of b's dependency on d

Regrade request

Consider the following files and their chmod-style permissions:

a.out: u=rwx,g=rx,o=
a.h: u=rw,g=r,o=r
a.c: u=rw,g=,o=
Question 3 (6 pt; mean 5.9) (see above)

The owner of these files wants to allow somebody in their group to view and modify a.c and a.h and not give others any access. Which, if any, of the following command(s) should they run? Do not include commands which will have no effect or which will allow for more access than they want. Select all that apply.

Regrade request
Question 4 (5 pt; mean 4.45) (see above)

Suppose the owner of a.out wants to make it runnable by any user and make it run with its effective user ID set to the owner's user ID. Which command(s), if any, would achieve this? Select all that apply.

Regrade request
Question 5 (4 pt; mean 3.86)

Consider a program that counts the number of lines of text the files in the current directory have. The program works by:

  1. obtain a list of the names of files in the current directory;
  2. running a loop for each such file:
    1. open the file;
    2. if opening the file is successful:
      1. read the entire contents of the file;
      2. count the number of newlines in what was read;
      3. print the filename and number of newlines found, flushing the output immediately;
      4. close the file
  3. then, sum up the number of newlines found in all files
  4. and print the sum

Based on the operations above, if this program were run on a directory with 1 file, we would expect system calls to be made for which (if any) of the steps above? Select all that apply.

Regrade request
Return to course pageReturn to index 

quiz for week 3

Consider the following sequence of events on a single core system:

  1. an SSH program requests input from the network, but that input is not yet available
  2. while the SSH program is waiting for input, a compiler uses the processor
  3. the system receives input from the network for an SSH program and stores it for later
  4. the compiler outputs a .o file
  5. the compiler exits
  6. the SSH program retrieves its input
  7. the SSH program requests that a response be sent on the network, and the system sends that response immediately
Question 1 (4 pt; mean 3.35) (see above)

Which of the above items describe a step that includes an exception triggered because the processor got a signal from an I/O device?

Write the numbers of steps. (For example, write "145" for steps 1, 4 and 5.)

Answer:
Key: 3

-1 per disagreement [to be handled in manual grading]

Regrade request
Question 2 (4 pt; mean 3.81) (see above)

In the above sequence of events, where is a context switch likely to occur? Select all that apply.

Regrade request
Question 3 (4 pt; mean 3.81)

Consider the following C code that uses the POSIX (Unix) API:

pid_t p, q, r;
p = fork();
if (p > 0) {
    q = fork();
    r = fork();
    if (q > 0) {
        exit(1);
    } else {
        exit(2);
    }
} else {
    exit(3);
}

If we start running the above code in exactly one process, some new processes will end up executing parts of the above code because of the calls to fork(). In that situation, what is the maximum number of processes that could be executing some part of the above code simulatenously? Include the original process in your count.

Answer:
Key: 5

[Added 2025-09-16 6:40pm] our intended interpretation of this question was that each of N processes could be running different parts of the code above, but they'd all be doing that simulatenously. Some people read this as N processes would each be running a specific instruction of thecode above at the same time. Under that assumption "4" is the correct answer and we also accepted that.

Regrade request
Question 4 (4 pt; mean 3.3)

Consider the following C code that uses the POSIX (Unix) API:

pid_t p;
p = fork();
if (p == 0) {
    int y = 0;
    while (y < 100000) {
        y += 1;
    }
    exit(0);
} else {
    printf("HERE\n");
}

Assume that fork does not fail.

If this is run on a single-core system, then just before printf("HERE\n") makes a system call to output to the screen, the value of local variable y in the code above may be stored ___. Select all that apply.

Regrade request
Return to course pageReturn to index 

quiz for week 4

Question 1 (5 pt; mean 4.8)

Consider the following C code that uses the POSIX (Unix) API:

pid_t p, q;
p = fork();
if (p > 0) {
    q = fork();
    if (q > 0) {
        /* place 1 */
        printf("A"); fflush(stdout);
        exit(1);
    } else {
        /* place 2 */
        printf("B"); fflush(stdout);
        exit(2);
    }
} else {
    /* place 3 */
    printf("C"); fflush(stdout);
    exit(3);
}

Assume that fork does not fail.

Currently, the program can output A, B, and C in any order. Which of the following would restrict the order in which they can be output? Select all that apply.

Note that when waitpid is called and there is no child process of the current process to wait for, it returns an error immediately.

Regrade request

Consider the following incomplete C code that uses the POSIX API:

int fd1 = open("file", O_WRONLY | O_CREAT, 0666);
int fd2 = open("file", O_RDONLY);

pid_t p, q;
dup2(fd1, STDOUT_FILENO);
p = fork();
if (p == 0) {
    const char *argv[] = {"./output_stuff", NULL};
    execv("./output_stuff", argv);
    exit(1);
}
q = fork();
dup2(fd2, STDIN_FILENO);
if (q == 0) {
    const char *argv[] = {"./input_stuff", NULL};
    execv("./input_stuff", argv);
    exit(1);
}
waitpid(q, NULL, 0);
waitpid(p, NULL, 0);

Assume dup2, execv, fork, waitpid do not fail.

For the following questions, suppose the output_stuff program computes something and outputs it to its stdout, and the input_stuff program reads from its stdin until it reaches end-of-file.

Question 2 (4 pt; mean 3.92) (see above)

Sometimes the input_stuff reads the file while output_stuff is still writing it, and so reaches the end of the file when it is incomplete. As a result, input_stuff only reads part of what output_stuff writes. Which, if any, of the following would fix this issue?

Regrade request
Question 3 (4 pt; mean 3.55) (see above)

If the input_stuff program outputs something to stdout while it run by the above code, then that output may ____. Select all that apply.

Regrade request
Question 4 (4 pt; mean 3.75)

Consider the following page table:

virtual page number (binary)valid?physical page number (binary)
0000
001101110
010101101
0110
0110
1000
101110000
110100111
1110

Suppose this is used on a system with 1024-byte pages. On that system, what is a virtual address that corresponds to the physical address (written in binary) 00111 10000 01101? Write your answer as a binary number. If there is no such address, write "impossible".

Answer:
Key: 110 10000 01101
Regrade request
Return to course pageReturn to index 

quiz for week 5

Consider a system with single-level page tables and 16384-byte pages (implying 14-bit page offsets). On this system page table entries are stored as 64-bit integers with the following format, listing bits from least significant to most significant:

Question 1 (4 pt; mean 3.32) (see above)

The processor on this system runs a user-mode program with a mov instruction that stores the values 0x1234567 to virtual address 0x567890. To complete that write, the processor retrieves a page table entry to lookup the virtual address then, writes to physical address 0x667890. What is a possible value for the page table entry the processor retrieves? Write your answer as a 64-bit integer in hexadecimal.

Answer:
Key: 0x66400b or 0x[something]66400b or 0x66400f or 0x66401f or similar

0x667890: physical page number 0x199; page offset 0x3890

(0x199 << 14 [page number part]) + 1 [valid] + 2 [user accessible] + 8 [writeable] = 0x66400b

plus could have readable/executable bits set;

plus could have value for any of the unused bits that do not need to be 0

Regrade request
Question 2 (4 pt; mean 3.65) (see above)

The page table base register is at physical address 0x16000. A program accesses virtual address 0x3FFFF8. To translate this to a physical address, the processor accesses a pagetable entry at address ____. Write your answer as a hexadecimal number. If not enough information is given, write "unknown".

Answer:
Key: 0x16000 + 0xFF * 8 = 0x167f8

0x3FFFF8 = VPN 0xFF ( = 0x3FFFF8 >> 14); page offset 0x3FF8

Regrade request
Question 3 (4 pt; mean 3.28)

Suppose we have a three-level page table structure with 8192-byte pages (implying 13-bit page offsets) and page tables (at each level) with 1024 entries, each of which takes up 8 bytes.

Since the page tables have 1024 entries, 10 bits from the virtual page number are used to form the index to the page tables at each level.

Suppose the page table base register is set to physical address 0x1000000.

As part of looking up the virtual address 0xABCDEF000 with the page table base register, the processor may retrieve a first-level page table entry from physical address ____.

Write your answer as a hexadecimal number. If there is not enough information given, write "unknown" and explain briefly in the comments.

Answer:
Key: 0x1000028

0x1000000 + (0xABCDEF000 >> (13+10*2)) * 8 = 0x1000028

Regrade request
Question 4 (4 pt; mean 3.85)

Consider a virtual memory system with:

If one wanted to modify this system to support 20 bit virtual addresses without changing the size of pages or physical page numbers, then the number of entries in the resulting page table would be _____ (instead of 16 now).

If it is not possible to increase the virtual address size this way while not changing the size of pages or physical addresses, write "impossible". If not enough information is given, write "unknown" and explain in the comments.

Answer:
Key: 256
Regrade request
Return to course pageReturn to index 

quiz for week 6

Consider the following direct-mapped cache:

set indextag (written in binary)validdata bytes (in hexadecimal; lowest address first)
00
10
21
310000111 22 33 44
40
501011155 66 77 88
6110001FF FF FF FF
7111001FF FF FF FF
80
90
100
110
120
13101101FF FF FF FF
14111101FF FF FF FF
15000001FF FF FF FF

Since two hexadecimal digits make up a byte, the blocks in this direct-mapped cache are 4-byte blocks.

Question 1 (4 pt; mean 3.88) (see above)

Give an example of an address which when read using this cache would retrieve the cached value 0x22? Write your answer as binary number.

Answer:
Key: 10000 0011 01
Regrade request
Question 2 (4 pt; mean 3.7) (see above)

Give an example of an address whose offset bits have the value 01 where reading it (using the above cache) might cause the "77" stored in cache set 5 to change.

Write your answer as a binary number. If no such address is possible, write "impossible" and explain briefly in the comments.

Answer:
Key: [any 5 bits but 01011] 0101 01
Regrade request
Question 3 (4 pt; mean 3.91) (see above)

If we change the cache to be two-way set associative without changing the size of cache blocks or the total number of cache blocks, which, if any, of the following changes will occur? Select all that apply.

Regrade request
Question 4 (4 pt; mean 3.77)

Consider a 65536 byte 4-way set associative cache with 64-byte blocks and a random replacement policy running on a system with 64-bit addresses. How many bits in total does this cache use to store valid bits and tag bits? (Count the bits used over all the sets of the cache, not just the bits used for one block or set.)

Answer:
Key: 52224

1024 blocks

65536 / 64 / 4 = 256 sets --> 8 index bits

64 byte blocks --> 6 offset bits

64- 8- 6 = 50 tag bits

(50 tag bits + 1 index bit) * 1024 = 52224

Regrade request
Return to course pageReturn to index  no quiz named week07Return to course pageReturn to index  no quiz named week08Return to course pageReturn to index 

quiz for week 9

Consider the following direct-mapped cache with a write-back, write-allocate policy:

set index tag (written in binary)validdata bytes (in hexadecimal; lowest address first)dirty
01000111 22 33 441
11001155 66 77 880
21010199 AA BB CC0
3000111A 2B 3C 3D1

Consider starting with the above cache and performing all of the following writes, one after the other:

Question 1 (4 pt; mean 3.87) (see above)

How many bytes will the cache write to the next level of cache or main memory as part of performing all of the above writes? Do not include any writes by the cache which would not be triggered until there is a later cache access.

Answer:
Key: 8

10001110 = offset 10; index 11 (3); tag 1000 = miss; replaces dirty; writes 4 + reads [at least] 3 bytes from next leve

00000000 = offset 00; index 00 (0); tag 0000 = miss; replaces dirty; writes 4 + reads [at least] 3 bytes from next level

10101000 = offset 00; index 10 (2); tag 1010 = hit; marks as dirty; writes/reads 0 bytes on next level (marks block as dirty)

Regrade request
Question 2 (4 pt; mean 3.72) (see above)

How many bytes will the cache read from the next level of cache or main memory as part of performing all of the above writes?

Answer:
Key: 6 or 8
Regrade request

Consider a system with 256-byte pages and a direct-mapped TLB with the following contents:

set index validtag (written in binary)write?exec?physical page number (written in binary)
0 0
1 110111110000111
2 0
3 0
Question 3 (4 pt; mean 3.82) (see above)

Give an example of a virtual address which would be a hit in the above TLB. Write the virtual address in binary.

Answer:
Key: 10111101 followed by any 8 bits
Regrade request

Consider the following C code;

struct example {
    int x;
    int *y;
};
int z;
void *thread_func(void *arg) {
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
    struct example *e = (struct example*) arg;
    z += e->x;
    for (int i = 0; i < 10; i += 1) {
        e->y[i] *= arr[i];
    }
}
int global_arr0[10] = {0,1,2,3,4,5,6,7,8,9};
int global_arr1[10] = {0,1,2,3,4,5,6,7,8,9};
int main() {
    pthread_t t1, t2;
    struct example info[2];
    info[0].x = 100; info[0].x = 100;
    info[0].y = global_arr0; info[1].y = global_arr1;
    pthread_create(&t1, NULL, &thread_func, (void*) &info[0]);
    pthread_create(&t2, NULL, &thread_func, (void*) &info[1]);
    pthread_join(t1);
    pthread_join(t2);
    return 0;
}
Question 4 (4 pt; mean 3.49) (see above)

When the e->y[i] *= arr[i] runs, which of the folowing is true? Select all that apply.

We meant to write pthread_join() with two arguments (both times) above (which affects whether the code runs); and to set info[1].x (which is unlikely to change things in practice, though technically results in undefined behavior due to using an uninintialized value).

Regrade request
Return to course pageReturn to index 

quiz for week 10

Question 1 (4 pt; mean 3.71)

Consider the following code. You may assume a main() calls pthread_create for ThreadA and ThreadB and joins them:

pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
string one = "init one", two = "init two";

void ThreadA() {
    pthread_mutex_lock(&lock1);
    one = "A1";
    pthread_mutex_unlock(&lock1);
    pthread_mutex_lock(&lock2);
    two = "A2";
    pthread_mutex_unlock(&lock2);
}

void ThreadB() {
    pthread_mutex_lock(&lock2);
    two = "B2";
    pthread_mutex_unlock(&lock2);
    pthread_mutex_lock(&lock1);
    one = "B1";
    pthread_mutex_unlock(&lock1);
}

Which of the following are possible final values for "one" and "two", respectively?

Regrade request

Consider the following C code that uses the POSIX API:

struct Book {
    pthread_mutex_t lock;
    long id;
    long category_id;
    char title[112];
    struct Patron *taken_out_by;
};

struct Patron {
    pthread_mutex_t lock;
    struct Book* pending_checkout[10];
    int number_checked_out;
}

bool Checkout(struct Patron *patron) {
    pthread_mutex_lock(&patron->lock);
    struct Book *pending_checkout[10];
    memcpy(
        pending_checkout,
        patron->pending_checkout,
        sizeof(patron->pending_checkout));
    bool can_checkout_all = true;
    for (int i = 0; i < 10; i += 1) {
        struct Book *book;
        book = pending_checkout[i];
        if (book) {
            pthread_mutex_lock(&book->lock);
            if (book->taken_out_by != NULL) {
                can_checkout_all = false;
            }
            /* LOCATION A */
        }
    }
    if (can_checkout_all) {
        for (int i = 0; i < 10; i += 1) {
            struct Book *book;
            /* LOCATION B */
            book = pending_checkout[i];
            if (book) {
                book->taken_out_by = patron;
                patron->pending_checkout[i] = NULL;
                patron->number_checked_out += 1;
            }
            /* LOCATION C */
        }
    }
    for (int i = 0; i < 10; i += 1) {
        struct Book *book;
        book = pending_checkout[i];
        if (book) {
            pthread_mutex_unlock(&book->lock);
        }
    }
    pthread_mutex_unlock(&patron->lock);
    return can_checkout_all;
}
Question 2 (4 pt; mean 3.91) (see above)

Which of the following situations would be likely to result in a deadlock? Select all that apply.

Regrade request
Question 3 (4 pt; mean 3.77) (see above)

The Checkout() function currently ensures that if two different patrons call Checkout() at the same time with the same book, then only one of the patrons will succeed at checking it out. For the other patron, the function will return false, indicating that the checkout failed.

If we removed all locks from the Checkout() function, then this would fix the deadlock, but this change would allow Checkout() erroneously return true for both patrons in the scenario where two patrons both checkout the same book.

What could we do to fix or reduce deadlock in Checkout() without erroneously returning true in that scenario? Select all that apply.

  1. this does not resolve most deadlocks, but you can argue this reduces deadlock because some scenarios that would previously have deadlock will not anymore due to some locks not being required

Regrade request

Consider the following C code:

 1       pthread_barrier_t barrier; int x = 0, y = 0;
 2       
 3       void thread_one() {
 4           y = 5;
 5           pthread_barrier_wait(&barrier);
 6           y = x + y;
 7           pthread_barrier_wait(&barrier);
 8           printf("%d %d\n", x, y);
 9       }
10        
11       void thread_two() {
12           x = 10;
13           pthread_barrier_wait(&barrier);
14           x = x + y;
15           pthread_barrier_wait(&barrier);
16       }

Assume that barrier is initialized with a count of two and two threads are started, one running thread_one and the other running thread_two.

Question 4 (4 pt; mean 3.53) (see above)

The above code has a data race. How can we fix it? Select all that apply.

Regrade request
Return to course pageReturn to index 

quiz for week 11

Consider the following incomplete C code:

pthread_mutex_t lock;
pthread_cond_t cv;
unsigned int count;

void IncreaseCountBy(unsigned int amount) {
    pthread_mutex_lock(&lock);
    count += amount;
    pthread_cond_broadcast(&cv);
    pthread_mutex_unlock(&lock);
}

void WaitForCountToDouble() {
    pthread_mutex_lock(&lock);
    int old_count = count;

    ____________________________ /* BLANK 1 */
    pthread_mutex_unlock(&lock);
}

Assume the underscores followed by /* BLANK ... */ comments represent omitted code.

Question 1 (4 pt; mean 3.96) (see above)

Which of the following would be most appropriate to put in BLANK 1?

Regrade request

Suppose we have a system where multiple threads need to wait for a chance to to access the network (which they need to take turns doing).

We split these threads into three classes: high, medium, and low priority. The medium priority threads should only access the network if no high priority threads are waiting (and the network is not already being accessed), the low priority threads only if no medium or high priority threads are waiting (and the network is not already being accessed).

To implement this we use the following variables:

pthread_mutex_t lock;
int number_of_waiting_high_priority;
int number_of_waiting_medium_priority;
int number_of_waiting_low_priority;
bool network_being_accessed;
pthread_cond_t cv;

The code for a medium-priority thread to access the network looks like:

pthread_mutex_lock(&lock);
number_of_waiting_medium_priority += 1;
while (network_being_accessed || number_of_waiting_high_priority > 0) {
    pthread_cond_wait(&cv, &lock);
}
number_of_waiting_medium_priority -= 1;
network_being_accessed = true;
pthread_mutex_unlock(&lock);
AccessNetwork();
pthread_mutex_lock(&lock);
network_being_accessed = false;
pthread_cond_broadcast(&cv);
pthread_mutex_unlock(&lock);
Question 2 (4 pt; mean 3.92) (see above)

The equivalent code for a low-priority thread would have what while loop condition?

Regrade request
Question 3 (4 pt; mean 3.64) (see above)

The above code is inefficient because it uses just one condition variable, rather than three separate condition variables for the high, medium, and low-priority threads to wait on. Suppose we modify the code to have three separate condition variables, called high_cv, medium_cv, and low_cv.

In this case, what would be best to replace the pthread_cond_broadcast(&cv) in the medium-priority thread code above?

Regrade request
Question 4 (4 pt; mean 3.48)

Suppose our network uses acknowledgments and sequence numbers like described in lecture to send data from machine A to machine B over a network that follows the mailbox model.

In this scheme, machine A does not send a data message until after it receives an acknowledgment message for its previous data message, so that it can handle cases where the network fails to deliver its data.

Suppose while a particular data transfer occurs, the network is 99.9% reliable for sending messages from A to B, but only 33.3% reliable for messages from B to A. For this purposes of this problem, assume that this packet loss follows a regular pattern:

(Note: actual packet loss is stochastic – not actually every Nth packet, as we will assume for the purposes of this problem.)

If the data transfer sends data from A to B that is split across 3000 data messages, how many messages, including lost data and acknowledgment messages, will be sent across the network in total? (Include messages that are sent but lost in your count.)

Answer:
Key: 9002

B will send an ack for 1, 2, then ack 3 gets lost. So A has to re-send data packet 3 as a result. B will send an ack for 3, 4, then 5 gets lost. Etc. So A has to re-send 3, 5, 7 … 2999.

A will send 1, then 2, then miss ACK for 3, resend 3, then send 4, then send 5, then miss ACK for 5, then resend 5, send 6, miss ACK for 7, and so on.

So A ends up resending 3, 5, 7, 9, ..., 2999 = 1499 messages. Out of the total 4499 messages it sends, 4 (1000, 2000, 3000, 4000) never reach B, so they need to get resent, so A sends 4503.

B sends an acknowledgment for each of A's 4499 messages that reach B.

So the answer is 4503+4499 = 9002

Under the interpretation that 3rd, 6th, etc. data packet is lost the first time it is sent and the 1000th, 2000th, etc. ack packet is lost; we have 4003 from A to B (3 extra from lost data packets; 1000 extra from lost acks) from B to A (3000 successful ACKs, plus 1000 lost ACKs resent later) = 8003

Regrade request
Return to course pageReturn to index 

quiz for week 12

Question 1 (4 pt; mean 3.73)

Suppose we want to transform code like:

value = ReadNext();
while (value == 1) {
    value = ReadNext();
}
Process(value);
value = ReadNext();
Process(value);
while (true) {
    ReadNext(); // ignore remaining values
}

into a callback-based programming model. In this model, instead of being able to call ReadNext() function, a "main loop" calls a Recieved() function (similar to the networking lab).

Consider the following incomplete implementation of such a Received() function:

static int count = 0;
void Received(int value) {
    if (__________ /* BLANK 1 */) {
        ______________ /* BLANK 2 */
        Process(value);
        count += 1;
    }
}

To do closest to the same thing as the original code, which of the following would be most appropriate to place in the blanks marked BLANK 1 and BLANK 2, respectively?

Regrade request
Question 2 (4 pt; mean 3.85)

Suppose the virginia.edu domain name server is compromised. Which of the following vulnerabilities does this create? Select all that apply.

Regrade request
Question 3 (4 pt; mean 3.71)

Suppose a router using network address translation has the following table in place:

    remote address:port     public IP port    private IP address           private IP port
    128.165.17.3:443         23423              192.168.1.7                 55938
    128.155.148.7:443        23424              192.168.1.8                 61243
    128.155.148.7:443        23425              192.168.1.9                 61839

Assume this is on a router with an IP address of 1.2.3.4 on the public network and 192.168.1.1 on a private network. Network address translation allows all the machines on the private network to share the router's public IP address.

Based on the above table, if a packet comes in from the public network with a source address of 128.155.148.7, source port of 443, and destination address of 1.2.3.4, and destination port of 23424, the router should send on the private network ...

Regrade request

Suppose we have a server to handle course registration that uses the following insecure protocol to communicate with clients run on behalf of registering students. Both the server and client have a keypair for asymmetric encryption and a keypair for digital signatures. In advance, the server and client share the public keys for each of these keypairs.

Question 4 (4 pt; mean 3.96) (see above)

Suppose there exists a machine in the middle attacker who has obtained the ID and private keys for encryption and signature from student X. The attacker can now ___. Select all that apply.

  1. [edited 18 Nov 8:40p] should have written "any server's response" to conclusive exclude replay attacks

Regrade request
Return to course pageReturn to index 

quiz for week 13

Question 1 (5 pt; mean 4.59)

Consider a TLS handshake like the one we described in lecture. Suppose a client is trying to contact a server foo.example.com but instead reaches a machine in the middle attacker.

Assume the intended server’s private key has not been compromised, and that the certificate authorities trusted by the client have only signed certificates for foo.example.com that include the server's intended public key.

Which, if any, of the following could happen (depending on what the machine-in-the-middle does)? Select all that apply.

Regrade request
Question 2 (4 pt; mean 2.48)

Suppose a 5-stage pipelined processor, similar to the design discussed in lecture, executes a program with 100 million instructions. If there were no hazards, this program would execute in about 100 million cycles.

Suppose that we do not have forwarding (also known as bypassing) from the memory stage to the execute stage. 30% of the program's instructions use the data cache, either loading a value of from data cache or storing a value. Of the those data cache using instructions, 70% are loads. 10% of those loads are followed by an instruction that has a data dependency on the load.

Assuming no cache misses, we’d expect the program to execute around __% slower than the ideal 100 million cycle case.

Answer:
Key: 2.1

21% of instructions are loads, 10% of those will have a 1-cycle stall, so 2.1%

Regrade request

Suppose we start with the 5-staged pipelined processor with forwarding and branch prediction discussed in lecture, but make some modifications:

We want a larger L1 data cache, whose access time doesn’t fit into one cycle. (Or else the entire pipeline would have to run at a slower clock speed).  So we break the memory stage into two stages. So our pipeline consists of F-D-E-M1-M2-W. Assume the two part memory stages use the same inputs and outputs as an unsplit memory stage, and they need the inputs (the address to access and any value to store) near the beginning of the memory part 1 stage and only have outputs (any value loaded) near the end of the memory part 2 stage.

Question 3 (4 pt; mean 3.36) (see above)

Consider this instruction sequence:

movq %r8, (%r10)
subq %r10, %r9
movq (%r9), %r8
addq %r8, %r9

If the movq %r8, (%r10) finishes its writeback stage during cycle number 6 on the processor described above, then the addq %r8, %r9 should finish its writeback stage during cycle number ____.

Answer:
Key: 11

movq  F-D-E-M1-M2-W

subq  --F-D-E-M1-M2-W

movq ----F-D-E-M1-M2-W

addq ------F-D-D-D-E-M1-M2-W

Regrade request
Question 4 (4 pt; mean 3.5) (see above)

Suppose the processor design change described above increases the data cache hit rate from 90 to 99% for the programs being run, and a cache miss costs 100 cycles. But this change also causes 10% of the instructions the processor runs to take an extra cycle from stalling (because of a data hazard involving the M2 stage) when previously no instructions required stalling. Which of the following best describes how much the decision help or hurt performance?

Regrade request
Return to course pageReturn to index 

quiz for week 15

Question 1 (4 pt; mean 3.74)

Suppose an out-of-order processor has two execution units for arithmetic, each pipelined with two stages. All arithmetic instructions use both stages.

How many cycles minimum would this processor need to do the arithmetic for the following assembly snippet? (Don't include time needed for instruction fetch, register renaming, etc., ie cycle 1 is when the first instruction starts its first execute stage, and your answer is the cycle when the last instruction finishes its last execute stage)

imulq %r8, %r12
imulq %r8, %r10
imulq %r12, %r8
imulq %r9, %r8
imulq %r10, %r14
imulq %r10, %r15
Answer:
Key: 6

imulq %r8, %r12 [starts cycle 1, finishes cycle 2]

imulq %r8, %r10 [starts cycle 1, finishes cycle 2]

imulq %r12, %r8 [starts cycle 3, finishes cycle 4]

imulq %r9, %r8 [starts cycle 5, finishes cycle 6]

imulq %r10, %r14 [starts cycle 3, finishes cycle 4]

imulq %r10, %r15 [starts cycle 4, finishes cycle 5]

Regrade request
Question 2 (4 pt; mean 3.62)

Consider the following C code:

array1[mystery * 512] += array2[mystery * 64];

Suppose array1 is an array of 1 million chars located at address 0x4000000, and array2 is an array of 1 million chars located at address 0x5001000 and we have a system with a 65536-byte direct-mapped cache with 64-byte blocks which does not use virtual memory.

When running the above code we discover that something from cache sets 313 and from cache set 968 are evicted. What is a possible value of mystery? Assume all accesses to array1 and array2 are in bounds for the arrays.

Answer:
Key: 249 or 1273

cache has 1024 sets

array1's access uses set 0 + mystery * 512/64 mod 1024 = mystery * 8 mod 1024; array2's uses set 0x1000/64 + mystery * 64 / 64 MOD 1024 = 64 + mystery MOD 1024

since mystery * 8 MOD 1024 has to be a multiple of 2, so the cachset set 968 eviction must account for that

solving 968 = mystery * 8 mod 1024 and 313 = 64 + mystery MOD 1024:

mystery = 249 MOD 1024; or mystery = 249 + 1024K from the second equation

substituting into the second, we get 968 = (249 + 1024K)8 MOD 1024 or 968 = 1992 MOD 1024 + 10248*K MOD 1024, which is true independent of K, so all possible Ks work except for the restriction that the indices must be in bound

using K=0, K=1 gives mystery * 512 < 1million, but K=2 gives mystery * 512 > 1 million and K=-1 gives mystery * 512 < 0, so the only valid values of K are 0 and 1.

Regrade request

Suppose we are perform a Spectre-style attack on a system call implementation that includes this assembly snippet (where each instruction is annotated with its memory address):

 0x4100000:   movq $0x610000,%rbx
 0x4100007:   cmpq $0x7b,%rdi
 0x410000b:   jge 0x4100015
 0x410000d:   addq %rdi,%rbx
 0x4100010:   movq (%rbx),%rax
 0x4100013:   jmp 0x410001c
 0x4100015:   movq $0x0,%rax
 0x410001c:   ...
Question 3 (4 pt; mean 3.82) (see above)

As part of the Spectre-style attack, the attacker wants the branch predictor to predict the jge instruction at 0x410000b as not taken.

Suppose the processor has a branch predictor which has a table with 1 bit (taken or not taken) entries indexed by the least significant 8 bits of the branch instruction address that it uses to predict branches.

To do this, the attacker will run some code before making the system call that actually performs the Spectre-style attack. Which of the following would be appropriate code to run? Select all that apply.

Regrade request
Question 4 (4 pt; mean 3.81) (see above)

As part of the Spectre-style attack, the attacker supplies a value for %rdi and expects to learn about the contents of memory at an address related to that value.

For this to work, it would be most useful if the assembly code starting with 0x410001c ____.

  1. cache access to array will allow determining info about %rax's value using side channel

Regrade request
Return to course pageReturn to index