[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] nvdimm: honor -object memory-backend-file, readonly=on optio
From: |
Stefan Hajnoczi |
Subject: |
[PATCH 3/3] nvdimm: honor -object memory-backend-file, readonly=on option |
Date: |
Tue, 4 Aug 2020 11:12:44 +0100 |
Make it possible to present read-only files to the guest as "unarmed"
NVDIMMs. The Linux NVDIMM device (/dev/pmemX) is read-only.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
docs/nvdimm.txt | 8 +++++++-
hw/mem/nvdimm.c | 4 ++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/docs/nvdimm.txt b/docs/nvdimm.txt
index c2c6e441b3..c0b52de111 100644
--- a/docs/nvdimm.txt
+++ b/docs/nvdimm.txt
@@ -17,7 +17,7 @@ following command line options:
-machine pc,nvdimm
-m $RAM_SIZE,slots=$N,maxmem=$MAX_SIZE
- -object memory-backend-file,id=mem1,share=on,mem-path=$PATH,size=$NVDIMM_SIZE
+ -object
memory-backend-file,id=mem1,share=on,mem-path=$PATH,size=$NVDIMM_SIZE,readonly=off
-device nvdimm,id=nvdimm1,memdev=mem1
Where,
@@ -42,6 +42,12 @@ Where,
"share=off", then guest writes won't be applied to the backend
file and thus will be invisible to other guests.
+ "readonly=on/off" controls whether the the file $PATH is opened read-only or
+ read/write (default). "readonly=on" sets the ACPI NFIT NVDIMM Region Mapping
+ Structure "NVDIMM State Flags" Bit 3 indicating that the device is "unarmed"
+ and cannot accept persistent writes. Linux guest drivers set the device to
+ read-only when this bit is present.
+
- "device nvdimm,id=nvdimm1,memdev=mem1" creates a virtual NVDIMM
device whose storage is provided by above memory backend device.
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index e1574bc07c..694223450e 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -151,6 +151,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice
*nvdimm, Error **errp)
"nvdimm-memory", mr, 0, pmem_size);
memory_region_set_nonvolatile(nvdimm->nvdimm_mr, true);
nvdimm->nvdimm_mr->align = align;
+
+ if (memory_region_is_rom(mr)) {
+ nvdimm->unarmed = true; /* this device is read-only */
+ }
}
static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
--
2.26.2
[PATCH 2/3] hostmem-file: add readonly=on|off option, Stefan Hajnoczi, 2020/08/04
[PATCH 3/3] nvdimm: honor -object memory-backend-file, readonly=on option,
Stefan Hajnoczi <=
Re: [PATCH 0/3] nvdimm: read-only file support, Michael S. Tsirkin, 2020/08/04
Re: [PATCH 0/3] nvdimm: read-only file support, Stefan Hajnoczi, 2020/08/21