LKML Archive on
help / color / mirror / Atom feed
@ 2021-10-06 12:27 David Hildenbrand
  0 siblings, 0 replies; only message in thread
From: David Hildenbrand @ 2021-10-06 12:27 UTC (permalink / raw)
  To: linux-kernel
  Cc: virtualization, David Hildenbrand, Michael S. Tsirkin,
	Jason Wang, Cornelia Huck, Marek Kedzierski, Hui Zhu,
	Sebastien Boeuf, Pankaj Gupta, Wei Yang

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:
* Removed /dev/kmem
* Disallowed access to virtio-mem device memory via /dev/mem
* Sanitized access to virtio-mem device memory via /proc/kcore
* Sanitized access to virtio-mem device memory via /proc/vmcore

"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.

Cc: "Michael S. Tsirkin" <>
Cc: Jason Wang <>
Cc: Cornelia Huck <>
Cc: Marek Kedzierski <>
Cc: Hui Zhu <>
Cc: Sebastien Boeuf <>
Cc: Pankaj Gupta <>
Cc: Wei Yang <>
Signed-off-by: David Hildenbrand <>

Michael, I want this patch in v5.16 if the following two series that
are already queued by Andrew via the -MM tree go into v5.16 (which I
I assume but we never know :) ):
* [PATCH v5 0/3] virtio-mem: disallow mapping virtio-mem memory via
* [PATCH v2 0/9] proc/vmcore: sanitize access to virtio-mem memory

This is the follow-up of:
The spec updated was proposed in:

v1 -> v2:
- Now that we handle /dev/mem and /proc/vmcore cleaner, we can get
  simplify and just support the flag unconditionally

 drivers/virtio/virtio_mem.c     | 1 +
 include/uapi/linux/virtio_mem.h | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index bef8ad6bf466..78dfdc9c98a1 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -2758,6 +2758,7 @@ static unsigned int virtio_mem_features[] = {
 #if defined(CONFIG_NUMA) && defined(CONFIG_ACPI_NUMA)
 static const struct virtio_device_id virtio_mem_id_table[] = {
diff --git a/include/uapi/linux/virtio_mem.h b/include/uapi/linux/virtio_mem.h
index 70e01c687d5e..e9122f1d0e0c 100644
--- a/include/uapi/linux/virtio_mem.h
+++ b/include/uapi/linux/virtio_mem.h
@@ -68,9 +68,10 @@
  * explicitly triggered (VIRTIO_MEM_REQ_UNPLUG).
  * There are no guarantees what will happen if unplugged memory is
- * read/written. Such memory should, in general, not be touched. E.g.,
- * even writing might succeed, but the values will simply be discarded at
- * random points in time.
+ * read/written. In general, unplugged memory should not be touched, because
+ * the resulting action is undefined. There is one exception: without
+ * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, unplugged memory inside the usable
+ * region can be read, to simplify creation of memory dumps.
  * It can happen that the device cannot process a request, because it is
  * busy. The device driver has to retry later.
@@ -87,6 +88,8 @@
 /* node_id is an ACPI PXM and is valid */
+/* unplugged memory must not be accessed */
 /* --- virtio-mem: guest -> host requests --- */

base-commit: 9e1ff307c779ce1f0f810c7ecce3d95bbae40896

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-06 12:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06 12:27 [PATCH v2] virtio-mem: support VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).