Skip to content

Commit 61082ad

Browse files
virtio-mem: support VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE
The initial virtio-mem spec states that while unplugged memory should not be read, the device still has to allow for reading unplugged memory inside the usable region. The primary motivation for this default handling was to simplify bringup of virtio-mem, because there were corner cases where Linux might have accidentially read unplugged memory inside added Linux memory blocks. In the meantime, we: 1. Removed /dev/kmem in commit bbcd53c ("drivers/char: remove /dev/kmem for good") 2. Disallowed access to virtio-mem device memory via /dev/mem in commit 2128f4e ("virtio-mem: disallow mapping virtio-mem memory via /dev/mem") 3. Sanitized access to virtio-mem device memory via /proc/kcore in commit 0daa322 ("fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages") 4. Sanitized access to virtio-mem device memory via /proc/vmcore in commit ce28146 ("virtio-mem: kdump mode to sanitize /proc/vmcore access") "Accidential" access to unplugged memory is no longer possible; we can support the new VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE feature that will be required by some hypervisors implementing virtio-mem in the near future. Acked-by: Michael S. Tsirkin <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Jason Wang <[email protected]> Cc: Marek Kedzierski <[email protected]> Cc: Hui Zhu <[email protected]> Cc: Sebastien Boeuf <[email protected]> Cc: Pankaj Gupta <[email protected]> Cc: Wei Yang <[email protected]> Signed-off-by: David Hildenbrand <[email protected]>
1 parent cb690f5 commit 61082ad

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,7 @@ static unsigned int virtio_mem_features[] = {
28892889
#if defined(CONFIG_NUMA) && defined(CONFIG_ACPI_NUMA)
28902890
VIRTIO_MEM_F_ACPI_PXM,
28912891
#endif
2892+
VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE,
28922893
};
28932894

28942895
static const struct virtio_device_id virtio_mem_id_table[] = {

include/uapi/linux/virtio_mem.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@
6868
* explicitly triggered (VIRTIO_MEM_REQ_UNPLUG).
6969
*
7070
* There are no guarantees what will happen if unplugged memory is
71-
* read/written. Such memory should, in general, not be touched. E.g.,
72-
* even writing might succeed, but the values will simply be discarded at
73-
* random points in time.
71+
* read/written. In general, unplugged memory should not be touched, because
72+
* the resulting action is undefined. There is one exception: without
73+
* VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, unplugged memory inside the usable
74+
* region can be read, to simplify creation of memory dumps.
7475
*
7576
* It can happen that the device cannot process a request, because it is
7677
* busy. The device driver has to retry later.
@@ -87,6 +88,8 @@
8788

8889
/* node_id is an ACPI PXM and is valid */
8990
#define VIRTIO_MEM_F_ACPI_PXM 0
91+
/* unplugged memory must not be accessed */
92+
#define VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE 1
9093

9194

9295
/* --- virtio-mem: guest -> host requests --- */

0 commit comments

Comments
 (0)