# US 10,120,709 B2 · Guest initiated atomic instructions for shared memory page host copy on write

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 10,120,709 B2
- Document ID: US10120709B2
- Status: Granted
- Kind: B2
- Application number: 15/056,778
- Filed: 2016-02-29
- Published: 2017-08-31
- Granted: 2018-11-06
- Earliest claimed: 2016-02-29
- Assignees: Red Hat Israel, Ltd.
- Applicants: Red Hat Israel, LTD
- Inventors: Michael Tsirkin; Andrea Arcangeli
- Web page: https://patentgrep.com/patent/US10120709B2

## CPC

- G06F 9/45558: {Hypervisor-specific management and integration aspects}
- G06F 12/1081: for peripheral access to main memory, e.g. direct memory access [DMA]
- G06F 12/1475: {in a virtual system, e.g. with translation means}
- G06F 13/1663: {Access to shared memory}
- G06F 13/28: using burst mode transfer, e.g. direct memory access {DMA}, cycle steal (G06F13/32 takes precedence)
- G06F 2009/45579: {I/O management, e.g. providing access to device drivers or storage}
- G06F 2212/1052: Security improvement
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A guest OS detects a DMA write request for a device assigned to the guest OS to perform a DMA write to a shared page of memory that has a write protection attribute to cause a protection page fault upon an attempt to write to the shared page of memory. The guest OS reads a portion of the shared page of memory from a location of that page, determines the value of the portion, and executes an atomic instruction that writes the value back to the location of the shared page of memory to trigger the page protection fault. Upon executing the atomic instruction, the guest OS sends the DMA write request to the device to cause the device to write to a writeable copy of the shared page of memory.

## Claims

### Claim 1

A method comprising:
detecting, by a processing device, a direct memory access (DMA) write request for a device assigned to a guest operating system to perform a DMA write to a shared page of memory, wherein the shared page of memory has a write protection attribute to cause a protection page fault upon an attempt to write to the shared page of memory;
reading, by the processing device, a portion of the shared page of memory from a location of the shared page of memory;
executing, by the processing device, an atomic instruction that writes a value of the portion of the shared page of memory back to the location of the shared page of memory to trigger the protection page fault in view of the write protection attribute; and
upon executing the atomic instruction, sending, by the processing device, the DMA write request to the device to cause the device to write to a writable copy of the shared page of memory, the writable copy created responsive to the protection page fault.

### Claim 2 (depends on 1)

The method of claim 1, further comprising:
determining the value of the portion of the shared page of memory; and
responsive to determining that the atomic instruction completed unsuccessfully:
re-reading the portion of the shared page of memory from the location of the shared page of memory;
determining a new value of the portion of the shared page of memory; and
executing the atomic instruction that writes the new value of the portion of the shared page of memory back to the location of the shared page of memory to trigger the protection page fault in view of the write protection attribute.

### Claim 3 (depends on 1)

The method of claim 1, wherein executing the atomic instruction comprises:
executing an atomic compare and swap instruction using the value of the portion of the shared memory page.

### Claim 4 (depends on 1)

The method of claim 1, wherein executing the atomic instruction comprises:
executing an atomic instruction that performs a logical OR operation on the value of the portion of the shared page of memory with a value of all zeros.

### Claim 5 (depends on 1)

The method of claim 1, wherein executing the atomic instruction comprises:
executing an atomic instruction that performs a logical AND operation on the value of the portion of the shared page of memory with a value of all ones.

### Claim 6 (depends on 1)

The method of claim 1, wherein executing the atomic instruction comprises:
executing an atomic instruction that performs an arithmetic operation on the value of the portion of the shared page of memory using the value of all zeros, wherein the arithmetic operation comprises at least one of an add operation or a subtract operation.

### Claim 7 (depends on 1)

The method of claim 1, wherein executing the atomic instruction comprises:
executing an atomic instruction that performs an arithmetic operation on the value of the portion of the shared page of memory using the value of ones, wherein the arithmetic operation comprises a multiply operation.

### Claim 8 (depends on 1)

The method of claim 1, wherein reading the portion of the shared page of memory from the location of the shared page of memory is completed during the execution of the atomic instruction.

### Claim 9

A computing apparatus comprising:
a memory to store instructions; and
a processing device, operatively coupled to the memory, to execute the instructions, wherein the processing device is to:
detect, by the processing device, a direct memory access (DMA) write request for a device assigned to a guest operating system to perform a DMA write to a shared page of memory, wherein the shared page of memory has a write protection attribute to cause a protection page fault upon an attempt to write to the shared page of memory;
read, by the processing device, a portion of the shared page of memory from a location of the shared page of memory;
execute, by the processing device, an atomic instruction that writes a value of the portion of the shared page of memory back to the location of the shared page of memory to trigger the protection page fault in view of the write protection attribute; and
upon executing the atomic instruction, send, by the processing device, the DMA write request to the device to cause the device to write to a writable copy of the shared page of memory, the writable copy created responsive to the protection page fault.

### Claim 10 (depends on 9)

The apparatus of claim 9, wherein the processing device is further to:
determine the value of the portion of the shared page of memory; and
responsive to determining that the atomic instruction completed unsuccessfully:
re-read the portion of the shared page of memory from the location of the shared page of memory;
determine a new value of the portion of the shared page of memory; and
execute the atomic instruction that writes the new value of the portion of the shared page of memory back to the location of the shared page of memory to trigger the protection page fault in view of the write protection attribute.

### Claim 11 (depends on 9)

The apparatus of claim 9, wherein to execute the atomic instruction, the processing device is further to:
execute an atomic compare and swap instruction using the value of the portion of the shared memory page.

### Claim 12 (depends on 9)

The apparatus of claim 9, wherein to execute the atomic instruction, the processing device is further to:
execute an atomic instruction that performs a logical OR operation on the value of the portion of the shared page of memory with a value of all zeros.

### Claim 13 (depends on 9)

The apparatus of claim 9, wherein to execute the atomic instruction, the processing device is further to:
execute an atomic instruction that performs a logical AND operation on the value of the portion of the shared page of memory with a value of all ones.

### Claim 14 (depends on 9)

The apparatus of claim 9, wherein to execute the atomic instruction, the processing device is further to:
execute an atomic instruction that performs an arithmetic operation on the value of the portion of the shared page of memory using the value of all zeros, wherein the arithmetic operation comprises at least one of an add operation or a subtract operation.

### Claim 15 (depends on 9)

The apparatus of claim 9, wherein to execute the atomic instruction, the processing device is further to:
execute an atomic instruction that performs an arithmetic operation on the value of the portion of the shared page of memory using the value of ones, wherein the arithmetic operation comprises a multiply operation.

### Claim 16

A non-transitory computer readable storage medium, having instructions stored therein, which when executed by a processing device of a computer system, cause the processing device to:
detect, by the processing device, a direct memory access (DMA) write request for a device assigned to a guest operating system to perform a DMA write to a shared page of memory, wherein the shared page of memory has a write protection attribute to cause a protection page fault upon an attempt to write to the shared page of memory; and
execute, by the processing device, an atomic instruction that reads a portion of the shared page of memory from a location of the shared page of memory and writes a value of the portion of the shared page of memory back to the location of the shared page of memory to trigger the protection page fault in view of the write protection attribute.

### Claim 17 (depends on 16)

The non-transitory computer readable storage medium of claim 16, wherein the processing device is further to:
determine the value of the portion of the shared page of memory; and
responsive to determining that the atomic instruction completed successfully, send, by the processing device, the DMA write request to the device to cause the device to write to a writable copy of the shared page of memory, the writable copy created responsive to the protection page fault; and
responsive to determining that the atomic instruction completed unsuccessfully:
re-read the portion of the shared page of memory from the location of the shared page of memory;
determine a new value of the portion of the shared page of memory;
execute the atomic instruction that writes the new value of the portion of the shared page of memory back to the location of the shared page of memory to trigger the protection page fault in view of the write protection attribute; and
send, by the processing device, the DMA write request to the device to cause the device to write to a writable copy of the shared page of memory, the writable copy created responsive to the protection page fault.

### Claim 18 (depends on 16)

The non-transitory computer readable storage medium of claim 16, wherein to execute the atomic instruction, wherein the processing device is further to:
execute an atomic compare and swap instruction using the value of the portion of the shared memory page.

### Claim 19 (depends on 16)

The non-transitory computer readable storage medium of claim 16, wherein to execute the atomic instruction, wherein the processing device is further to:
execute an atomic instruction that performs at least one of a logical OR operation on the value of the portion of the shared page of memory with a value of all zeros, or an arithmetic operation on the value of the portion of the shared page of memory using the value of all zeros, wherein the arithmetic operation comprises at least one of an add operation or a subtract operation.

### Claim 20 (depends on 16)

The non-transitory computer readable storage medium of claim 16, wherein to execute the atomic instruction, wherein the processing device is further to:
execute an atomic instruction that performs a logical AND operation on the value of the portion of the shared page of memory with a value of all ones.
