From nobody Tue Nov 18 19:45:37 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612294378; cv=none; d=zohomail.com; s=zohoarc; b=c+mMINenT+0Y1LzeMTxvtUg97QNYIcUJ0mPCTFCPyImG3xzXO/qfas4lNaOuLXfSadj0X2ugi+Q5cv2IeTBnw5Mr7EmsQYAmDU61EbVtKuv3fArxjjuzFVG6N1abPOsdXnFhcFtX++YHMmGqB92jx8N/+KuWKur57iy4mmVlYpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612294378; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ji6KeukqbRf7zODdJI6lHJJTAz5NSV5XkIwI85m3pt4=; b=SYDjyZK7GTwtQECrvDn/0knzgK2hRNFjOyi6WINm3Ro3bR8iHUCPsCbUEibcqQq1abNrdvVeTCgJJVusnqUjquguE6KLWKW5cfqMMzOHXbhTutoN9SwIYuLdF1cl5JzQ+fevC5LYvNuGzVds/IMZXgM3I/l0rJaN/zzy7jc5jpk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612294378335398.7163774661268; Tue, 2 Feb 2021 11:32:58 -0800 (PST) Received: from localhost ([::1]:48454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l71Q1-0001ON-77 for importer@patchew.org; Tue, 02 Feb 2021 14:32:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l71OG-0008Sy-SA for qemu-devel@nongnu.org; Tue, 02 Feb 2021 14:31:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l71OE-0001Iu-Vb for qemu-devel@nongnu.org; Tue, 02 Feb 2021 14:31:08 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-nxIsz9zMP6GTyFYNLWm2Dw-1; Tue, 02 Feb 2021 14:30:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 083DA1084D61; Tue, 2 Feb 2021 19:30:26 +0000 (UTC) Received: from localhost (ovpn-3-197.rdu2.redhat.com [10.22.3.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3B1350B44; Tue, 2 Feb 2021 19:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612294266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ji6KeukqbRf7zODdJI6lHJJTAz5NSV5XkIwI85m3pt4=; b=Ma1E28rzJvydaieiEmH34czMD1KTX5VJxe7P0W21X95MqMTn37pXGnqMS0ibbn99aDPjT2 FYIZNth13migQhJpVEoMZdseKXupp62rhBL/1yzYJ0QeUunzpqFSqr1JKsMsewVAP6728I QbjdM820iJnAmUtJCnxcEeqOYViUS5A= X-MC-Unique: nxIsz9zMP6GTyFYNLWm2Dw-1 From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 3/3] nvdimm: check -object memory-backend-file, readonly=on option Date: Tue, 2 Feb 2021 14:30:20 -0500 Message-Id: <20210202193020.4107711-4-ehabkost@redhat.com> In-Reply-To: <20210202193020.4107711-1-ehabkost@redhat.com> References: <20210202193020.4107711-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Stefan Hajnoczi Check that -device nvdimm,unarmed=3Don is used when -object memory-backend-file,readonly=3Don and document that -device nvdimm,unarmed=3Don|off controls whether the NVDIMM appears read-only to the guest. Signed-off-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Liam Merwick Acked-by: Michael S. Tsirkin Message-Id: <20210104171320.575838-4-stefanha@redhat.com> Signed-off-by: Eduardo Habkost --- 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 c2c6e441b34..0aae682be3e 100644 --- a/docs/nvdimm.txt +++ b/docs/nvdimm.txt @@ -17,8 +17,8 @@ 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 - -device nvdimm,id=3Dnvdimm1,memdev=3Dmem1 + -object memory-backend-file,id=3Dmem1,share=3Don,mem-path=3D$PATH,size=3D= $NVDIMM_SIZE,readonly=3Doff + -device nvdimm,id=3Dnvdimm1,memdev=3Dmem1,unarmed=3Doff =20 Where, =20 @@ -31,9 +31,10 @@ 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" - 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=3Dmem1,share=3Don,mem-path=3D$PATH, + size=3D$NVDIMM_SIZE,readonly=3Doff" 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 "share=3Don/off" controls the visibility of guest writes. If "share=3Don", then guest writes will be applied to the backend @@ -42,8 +43,17 @@ Where, "share=3Doff", then guest writes won't be applied to the backend file and thus will be invisible to other guests. =20 - - "device nvdimm,id=3Dnvdimm1,memdev=3Dmem1" creates a virtual NVDIMM - device whose storage is provided by above memory backend device. + "readonly=3Don/off" controls whether the file $PATH is opened read-only= or + read/write (default). + + - "device nvdimm,id=3Dnvdimm1,memdev=3Dmem1,unarmed=3Doff" 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 a= ccept + 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=3Don. =20 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 03c2201b564..e0a9d606e1b 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; } =20 + if (!nvdimm->unarmed && memory_region_is_rom(mr)) { + HostMemoryBackend *hostmem =3D 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 =3D g_new(MemoryRegion, 1); memory_region_init_alias(nvdimm->nvdimm_mr, OBJECT(dimm), "nvdimm-memory", mr, 0, pmem_size); --=20 2.28.0