LKML Archive on
help / color / mirror / Atom feed
From: "Williams, Dan J" <>
To: "" <>,
	"" <>
Subject: Re: [PATCH v3 2/3] kernel/resource: disallow access to exclusive system RAM regions
Date: Wed, 1 Sep 2021 19:37:36 +0000	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Tue, 2021-08-31 at 22:21 +0200, David Hildenbrand wrote:
> virtio-mem dynamically exposes memory inside a device memory region as
> system RAM to Linux, coordinating with the hypervisor which parts are
> actually "plugged" and consequently usable/accessible. On the one hand, the
> virtio-mem driver adds/removes whole memory blocks, creating/removing busy
> IORESOURCE_SYSTEM_RAM resources, on the other hand, it logically (un)plugs
> memory inside added memory blocks, dynamically either exposing them to
> the buddy or hiding them from the buddy and marking them PG_offline.
> In contrast to physical devices, like a DIMM, the virtio-mem driver
> is required to actually make use of any of the device-provided memory,
> because it performs the handshake with the hypervisor. virtio-mem memory
> cannot simply be access via /dev/mem without a driver.
> There is no safe way to:
> a) Access plugged memory blocks via /dev/mem, as they might contain
>    unplugged holes or might get silently unplugged by the virtio-mem
>    driver and consequently turned inaccessible.
> b) Access unplugged memory blocks via /dev/mem because the virtio-mem
>    driver is required to make them actually accessible first.
> The virtio-spec states that unplugged memory blocks MUST NOT be
> written, and only selected unplugged memory blocks MAY be read. We want
> to make sure, this is the case in sane environments -- where the
> virtio-mem driver was loaded.
> We want to make sure that in a sane environment, nobody "accidentially"
> accesses unplugged memory inside the device managed region. For example,
> a user might spot a memory region in /proc/iomem and try accessing it via
> /dev/mem via gdb or dumping it via something else. By the time the mmap()
> happens, the memory might already have been removed by the virtio-mem
> driver silently: the mmap() would succeeed and user space might
> accidentially access unplugged memory.
> So once the driver was loaded and detected the device along the
> device-managed region, we just want to disallow any access via
> /dev/mem to it.
> In an ideal world, we would mark the whole region as busy ("owned by a
> driver") and exclude it; however, that would be wrong, as we don't
> really have actual system RAM at these ranges added to Linux ("busy system
> RAM"). Instead, we want to mark such ranges as "not actual busy system RAM
> but still soft-reserved and prepared by a driver for future use."
> Let's teach iomem_is_exclusive() to reject access to any range
> and even if "iomem=relaxed" is set.
> For now, there are no applicable ranges and we'll modify virtio-mem next to
> properly set IORESOURCE_EXCLUSIVE on the parent resource container it
> creates to contain all actual busy system RAM added via
> add_memory_driver_managed().

Looks good,

Reviewed-by: Dan Williams <>

  reply	other threads:[~2021-09-01 19:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 20:21 [PATCH v3 0/3] virtio-mem: disallow mapping virtio-mem memory via /dev/mem David Hildenbrand
2021-08-31 20:21 ` [PATCH v3 1/3] kernel/resource: clean up and optimize iomem_is_exclusive() David Hildenbrand
2021-09-01 19:43   ` Williams, Dan J
2021-09-02  7:52     ` David Hildenbrand
2021-09-02 15:54       ` Dan Williams
2021-08-31 20:21 ` [PATCH v3 2/3] kernel/resource: disallow access to exclusive system RAM regions David Hildenbrand
2021-09-01 19:37   ` Williams, Dan J [this message]
2021-08-31 20:21 ` [PATCH v3 3/3] virtio-mem: disallow mapping virtio-mem memory via /dev/mem David Hildenbrand
2021-09-01 19:39   ` Williams, Dan J

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \
    --subject='Re: [PATCH v3 2/3] kernel/resource: disallow access to exclusive system RAM regions' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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