From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Xiao Guangrong" <xiaoguangrong.eric@gmail.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Julio Montes" <julio.montes@intel.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
eric.g.ernst@gmail.com, "Stefan Hajnoczi" <stefanha@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Richard Henderson" <rth@twiddle.net>
Subject: [PATCH v3 3/3] nvdimm: check -object memory-backend-file, readonly=on option
Date: Mon, 4 Jan 2021 17:13:20 +0000 [thread overview]
Message-ID: <20210104171320.575838-4-stefanha@redhat.com> (raw)
In-Reply-To: <20210104171320.575838-1-stefanha@redhat.com>
Check that -device nvdimm,unarmed=on is used when -object
memory-backend-file,readonly=on and document that -device
nvdimm,unarmed=on|off controls whether the NVDIMM appears read-only to
the guest.
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
v3:
* Produce an error when -device nvdimm,unarmed=off is used with -object
memory-backend-file,readonly=on instead of silently switching on
unarmed. [Igor]
---
docs/nvdimm.txt | 24 +++++++++++++++++-------
hw/mem/nvdimm.c | 9 +++++++++
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/docs/nvdimm.txt b/docs/nvdimm.txt
index c2c6e441b3..0aae682be3 100644
--- a/docs/nvdimm.txt
+++ b/docs/nvdimm.txt
@@ -17,8 +17,8 @@ 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
- -device nvdimm,id=nvdimm1,memdev=mem1
+ -object memory-backend-file,id=mem1,share=on,mem-path=$PATH,size=$NVDIMM_SIZE,readonly=off
+ -device nvdimm,id=nvdimm1,memdev=mem1,unarmed=off
Where,
@@ -31,9 +31,10 @@ Where,
of normal RAM devices and vNVDIMM devices, e.g. $MAX_SIZE should be
>= $RAM_SIZE + $NVDIMM_SIZE here.
- - "object memory-backend-file,id=mem1,share=on,mem-path=$PATH,size=$NVDIMM_SIZE"
- creates a backend storage of size $NVDIMM_SIZE on a file $PATH. All
- accesses to the virtual NVDIMM device go to the file $PATH.
+ - "object memory-backend-file,id=mem1,share=on,mem-path=$PATH,
+ size=$NVDIMM_SIZE,readonly=off" creates a backend storage of size
+ $NVDIMM_SIZE on a file $PATH. All accesses to the virtual NVDIMM device go
+ to the file $PATH.
"share=on/off" controls the visibility of guest writes. If
"share=on", then guest writes will be applied to the backend
@@ -42,8 +43,17 @@ Where,
"share=off", then guest writes won't be applied to the backend
file and thus will be invisible to other guests.
- - "device nvdimm,id=nvdimm1,memdev=mem1" creates a virtual NVDIMM
- device whose storage is provided by above memory backend device.
+ "readonly=on/off" controls whether the file $PATH is opened read-only or
+ read/write (default).
+
+ - "device nvdimm,id=nvdimm1,memdev=mem1,unarmed=off" creates a read/write
+ virtual NVDIMM device whose storage is provided by above memory backend
+ device.
+
+ "unarmed" controls 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. Set unarmed to on when the memdev has readonly=on.
Multiple vNVDIMM devices can be created if multiple pairs of "-object"
and "-device" are provided.
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 03c2201b56..e0a9d606e1 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -146,6 +146,15 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice *nvdimm, Error **errp)
return;
}
+ if (!nvdimm->unarmed && memory_region_is_rom(mr)) {
+ HostMemoryBackend *hostmem = dimm->hostmem;
+
+ error_setg(errp, "'unarmed' property must be off since memdev %s "
+ "is read-only",
+ object_get_canonical_path_component(OBJECT(hostmem)));
+ return;
+ }
+
nvdimm->nvdimm_mr = g_new(MemoryRegion, 1);
memory_region_init_alias(nvdimm->nvdimm_mr, OBJECT(dimm),
"nvdimm-memory", mr, 0, pmem_size);
--
2.29.2
next prev parent reply other threads:[~2021-01-04 17:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-04 17:13 [PATCH v3 0/3] nvdimm: read-only file support Stefan Hajnoczi
2021-01-04 17:13 ` [PATCH v3 1/3] memory: add readonly support to memory_region_init_ram_from_file() Stefan Hajnoczi
2021-01-04 17:13 ` [PATCH v3 2/3] hostmem-file: add readonly=on|off option Stefan Hajnoczi
2021-01-04 17:13 ` Stefan Hajnoczi [this message]
2021-01-04 21:02 ` [PATCH v3 0/3] nvdimm: read-only file support Eduardo Habkost
2021-01-14 14:05 ` Stefan Hajnoczi
2021-01-21 20:41 ` Eduardo Habkost
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210104171320.575838-4-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=ehabkost@redhat.com \
--cc=eric.g.ernst@gmail.com \
--cc=imammedo@redhat.com \
--cc=julio.montes@intel.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=xiaoguangrong.eric@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).