From nobody Tue May 7 12:24:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508144319843246.51424669730022; Mon, 16 Oct 2017 01:58:39 -0700 (PDT) Received: from localhost ([::1]:60038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e41E7-0007lM-Iw for importer@patchew.org; Mon, 16 Oct 2017 04:58:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e41Cw-00076N-FN for qemu-devel@nongnu.org; Mon, 16 Oct 2017 04:57:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e41Ct-0003vN-FQ for qemu-devel@nongnu.org; Mon, 16 Oct 2017 04:57:10 -0400 Received: from mga01.intel.com ([192.55.52.88]:18896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e41Ct-0003uO-6u for qemu-devel@nongnu.org; Mon, 16 Oct 2017 04:57:07 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2017 01:57:03 -0700 Received: from yangzhon-virtual.bj.intel.com ([10.238.145.49]) by orsmga003.jf.intel.com with ESMTP; 16 Oct 2017 01:57:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,386,1503385200"; d="scan'208";a="1025586030" From: Yang Zhong To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 16:56:22 +0800 Message-Id: <1508144183-30844-2-git-send-email-yang.zhong@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508144183-30844-1-git-send-email-yang.zhong@intel.com> References: <1508144183-30844-1-git-send-email-yang.zhong@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [PATCH 1/2] hostmem-file: Add "nopin" option for memory-backend-file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, xiaoguangrong.eric@gmail.com, alex.williamson@redhat.com, anthony.xu@intel.com, pbonzini@redhat.com, ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since qemu does not need pin nvdimm memory during the VFIO hotplug, the new option can be used to avoid pin whole nvdimm memory. The default value is still "nopin=3Doff" as previous. Signed-off-by: Yang Zhong --- backends/hostmem-file.c | 23 +++++++++++++++++++++++ hw/vfio/common.c | 12 +++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index e44c319..e402077 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -33,6 +33,7 @@ struct HostMemoryBackendFile { =20 bool share; bool discard_data; + bool nopin; char *mem_path; }; =20 @@ -128,6 +129,25 @@ static void file_backend_unparent(Object *obj) } } =20 +static bool file_memory_backend_get_nopin(Object *o, Error **errp) +{ + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); + + return fb->nopin; +} + +static void file_memory_backend_set_nopin(Object *o, bool value, Error **e= rrp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); + + if (memory_region_size(&backend->mr)) { + error_setg(errp, "cannot change property value"); + return; + } + fb->nopin =3D value; +} + static void file_backend_class_init(ObjectClass *oc, void *data) { @@ -142,6 +162,9 @@ file_backend_class_init(ObjectClass *oc, void *data) object_class_property_add_bool(oc, "discard-data", file_memory_backend_get_discard_data, file_memory_backend_set_disc= ard_data, &error_abort); + object_class_property_add_bool(oc, "nopin", + file_memory_backend_get_nopin, file_memory_backend_set_nopin, + &error_abort); object_class_property_add_str(oc, "mem-path", get_mem_path, set_mem_path, &error_abort); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7b2924c..f36ff24 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -408,7 +408,8 @@ static void vfio_listener_region_add(MemoryListener *li= stener, void *vaddr; int ret; VFIOHostDMAWindow *hostwin; - bool hostwin_found; + bool hostwin_found, nopin; + Object *obj =3D section->mr->owner; =20 if (vfio_listener_skipped_section(section)) { trace_vfio_listener_region_add_skip( @@ -424,6 +425,15 @@ static void vfio_listener_region_add(MemoryListener *l= istener, return; } =20 + if (obj && object_dynamic_cast(obj, "memory-backend-file")) { + nopin =3D object_property_get_bool(obj, "nopin", NULL); + if (nopin) { + error_report("warning: If VFIO DMA still map to NVDIMM memory,= " + "the VM will crash"); + return; + } + } + iova =3D TARGET_PAGE_ALIGN(section->offset_within_address_space); llend =3D int128_make64(section->offset_within_address_space); llend =3D int128_add(llend, section->size); --=20 1.9.1 From nobody Tue May 7 12:24:22 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508144399539759.6432303367621; Mon, 16 Oct 2017 01:59:59 -0700 (PDT) Received: from localhost ([::1]:60042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e41FM-000087-Sx for importer@patchew.org; Mon, 16 Oct 2017 04:59:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e41Cw-00076P-G8 for qemu-devel@nongnu.org; Mon, 16 Oct 2017 04:57:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e41Ct-0003vf-Ty for qemu-devel@nongnu.org; Mon, 16 Oct 2017 04:57:10 -0400 Received: from mga01.intel.com ([192.55.52.88]:51760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e41Ct-0003tI-LR for qemu-devel@nongnu.org; Mon, 16 Oct 2017 04:57:07 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2017 01:57:04 -0700 Received: from yangzhon-virtual.bj.intel.com ([10.238.145.49]) by orsmga003.jf.intel.com with ESMTP; 16 Oct 2017 01:57:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,386,1503385200"; d="scan'208";a="1025586051" From: Yang Zhong To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 16:56:23 +0800 Message-Id: <1508144183-30844-3-git-send-email-yang.zhong@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508144183-30844-1-git-send-email-yang.zhong@intel.com> References: <1508144183-30844-1-git-send-email-yang.zhong@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [PATCH 2/2] nvdimm: Add "nopin" for related documents X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, xiaoguangrong.eric@gmail.com, alex.williamson@redhat.com, anthony.xu@intel.com, pbonzini@redhat.com, ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Added the "nopin" related changes in nvdimm.txt and qemu-options.hx. Signed-off-by: Yang Zhong --- docs/nvdimm.txt | 10 ++++++++-- qemu-options.hx | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/nvdimm.txt b/docs/nvdimm.txt index 2d9f8c0..41ac1c2 100644 --- a/docs/nvdimm.txt +++ b/docs/nvdimm.txt @@ -17,7 +17,7 @@ following command line options: =20 -machine pc,nvdimm -m $RAM_SIZE,slots=3D$N,maxmem=3D$MAX_SIZE - -object memory-backend-file,id=3Dmem1,share=3Don,mem-path=3D$PATH,size=3D= $NVDIMM_SIZE + -object memory-backend-file,id=3Dmem1,share=3Don,nopin=3Don,mem-path=3D$P= ATH,size=3D$NVDIMM_SIZE -device nvdimm,id=3Dnvdimm1,memdev=3Dmem1 =20 Where, @@ -31,7 +31,7 @@ Where, of normal RAM devices and vNVDIMM devices, e.g. $MAX_SIZE should be >=3D $RAM_SIZE + $NVDIMM_SIZE here. =20 - - "object memory-backend-file,id=3Dmem1,share=3Don,mem-path=3D$PATH,size= =3D$NVDIMM_SIZE" + - "object memory-backend-file,id=3Dmem1,share=3Don,nopin=3Don,mem-path=3D= $PATH,size=3D$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. =20 @@ -42,6 +42,12 @@ Where, "share=3Doff", then guest writes won't be applied to the backend file and thus will be invisible to other guests. =20 + "nopin=3Don/off" controls the memory pining of memory backend file + during the VFIO device hotplug. If "nopin=3Don", then VFIO device + hotplug can skip the NVDIMM memory pining because qemu does not + need pining NVDIMM memory for devices. If "nopin=3Doff", the VFIO + device hotplug need NVDIMM memory pining. + - "device nvdimm,id=3Dnvdimm1,memdev=3Dmem1" creates a virtual NVDIMM device whose storage is provided by above memory backend device. =20 diff --git a/qemu-options.hx b/qemu-options.hx index 981742d..d21ce2e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4173,7 +4173,7 @@ property must be set. These objects are placed in the =20 @table @option =20 -@item -object memory-backend-file,id=3D@var{id},size=3D@var{size},mem-path= =3D@var{dir},share=3D@var{on|off},discard-data=3D@var{on|off} +@item -object memory-backend-file,id=3D@var{id},size=3D@var{size},mem-path= =3D@var{dir},share=3D@var{on|off},discard-data=3D@var{on|off},nopin=3D@var{= on|off} =20 Creates a memory file backend object, which can be used to back the guest RAM with huge pages. The @option{id} parameter is a @@ -4191,6 +4191,10 @@ to avoid unnecessarily flushing data to the backing = file. Note that @option{discard-data} is only an optimization, and QEMU might not discard file contents if it aborts unexpectedly or is terminated using SIGKILL. +Setting the @option{nopin} boolean option to @var{on} indicates +that if the memory-backend-file is nvdimm or else, the memory +pining can be disable during VFIO device hotplug. The default +nopin is still off, which is same with previous value. =20 @item -object rng-random,id=3D@var{id},filename=3D@var{/dev/random} =20 --=20 1.9.1