nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Taylor Stark <tstark@linux.microsoft.com>
To: dan.j.williams@intel.com, vishal.l.verma@intel.com,
	dave.jiang@intel.com, ira.weiny@intel.com
Cc: nvdimm@lists.linux.dev, apais@microsoft.com,
	tyhicks@microsoft.com, jamorris@microsoft.com,
	benhill@microsoft.com, sunilmut@microsoft.com,
	grahamwo@microsoft.com, tstark@microsoft.com
Subject: [PATCH v2 2/2] virtio-pmem: Set DRIVER_OK status prior to creating pmem region
Date: Thu, 15 Jul 2021 15:36:38 -0700	[thread overview]
Message-ID: <20210715223638.GA29649@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> (raw)

Update virtio-pmem to call virtio_device_ready prior to creating the pmem
region. Otherwise, the guest may try to access the pmem region prior to
the DRIVER_OK status being set.

In the case of Hyper-V, the backing pmem file isn't mapped to the guest
until the DRIVER_OK status is set. Therefore, attempts to access the pmem
region can cause the guest to crash. Hyper-V could map the file earlier,
for example at VM creation, but we didn't want to pay the mapping cost if
the device is never used. Additionally, it felt weird to allow the guest
to access the region prior to the device fully coming online.

Signed-off-by: Taylor Stark <tstark@microsoft.com>
---
 drivers/nvdimm/virtio_pmem.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c
index 43c1d835a449..ea9e111f3ea1 100644
--- a/drivers/nvdimm/virtio_pmem.c
+++ b/drivers/nvdimm/virtio_pmem.c
@@ -91,6 +91,11 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
 
 	dev_set_drvdata(&vdev->dev, vpmem->nvdimm_bus);
 
+	/* Online the device prior to creating a pmem region, to ensure that
+	 * the region is never touched while the device is offline.
+	 */
+	virtio_device_ready(vdev);
+
 	ndr_desc.res = &res;
 	ndr_desc.numa_node = nid;
 	ndr_desc.flush = async_pmem_flush;
@@ -105,6 +110,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
 	nd_region->provider_data = dev_to_virtio(nd_region->dev.parent->parent);
 	return 0;
 out_nd:
+	vdev->config->reset(vdev);
 	nvdimm_bus_unregister(vpmem->nvdimm_bus);
 out_vq:
 	vdev->config->del_vqs(vdev);
-- 
2.32.0


             reply	other threads:[~2021-07-15 22:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 22:36 Taylor Stark [this message]
2021-07-19 20:05 ` [PATCH v2 2/2] virtio-pmem: Set DRIVER_OK status prior to creating pmem region Pankaj Gupta

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=20210715223638.GA29649@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net \
    --to=tstark@linux.microsoft.com \
    --cc=apais@microsoft.com \
    --cc=benhill@microsoft.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=grahamwo@microsoft.com \
    --cc=ira.weiny@intel.com \
    --cc=jamorris@microsoft.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=sunilmut@microsoft.com \
    --cc=tstark@microsoft.com \
    --cc=tyhicks@microsoft.com \
    --cc=vishal.l.verma@intel.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).