From nobody Sat Feb 7 07:25:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1764060527; cv=none; d=zohomail.com; s=zohoarc; b=Q5QnXlYDkqREIJYYGnL2CREOXROaVd6Or22VQlFG4Vf6bTft9PK50Bu4AU52GBCv81CmmBvR6guAA34j7cu+xrIwwznagIbQYVp6IKzJHlznn2/ZYd3KUNOB+81O8bdKQpwOf+nM9KoOQUw35C8YhBame9fr4EOlzV/dyShn1lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764060527; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U1dP0nMMkej6FkoKDYCmZzMg0wuFTFgueJv1PwHiHLs=; b=P427nq5EM3tXUr1HNpWLYV7fnaP50qDIgMFKtleVubvO8tDQ6fG76iGKLehz4A0ajurMnAL7SJZpJCYUZAdAeGHqBalGzdd9ucBxsqY5llXeB96oTDxxjWjrY4i+uUSl1aTwdgLBeiNNDXoqEEznG0lj8jnyHmDZV+nvVAX6nLA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764060526807774.3808669188862; Tue, 25 Nov 2025 00:48:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNoiE-00088D-Gi; Tue, 25 Nov 2025 03:47:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNoiD-00087D-2n; Tue, 25 Nov 2025 03:47:49 -0500 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNoiA-0008Bz-RG; Tue, 25 Nov 2025 03:47:48 -0500 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 4DA191D00234; Tue, 25 Nov 2025 03:47:45 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 25 Nov 2025 03:47:45 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 Nov 2025 03:47:42 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1764060465; x= 1764146865; bh=U1dP0nMMkej6FkoKDYCmZzMg0wuFTFgueJv1PwHiHLs=; b=j B++LrCVy7ijtwDVhzum9NCRFiOZMMZCw1pWseGnP/v7HEhzvIdGslSEWtZt3I9N/ phBotEeZfGZ56wiC5KXPvcfDIjsTlkJLURqohwWQ18rLMikUtH23P2ZJzNLMUTp/ vRfudemqxb0EqYD8oKFXMgH73XrLzL64EdJAkGTJqV7CbaAatUENQmr4kjT1R4tm t0LLTlRxBrlUfdLv/USCgBPL3UQhWmymINfKsv/oKAO4uRX8lTF3BQTq8y82laDr 5kRGXT7p2qgBTHfTJoAynd/YFRmhBsXB7a/bFRi8yLbmKhQ2QDvBgKcCyZW/bm+d sh1HNA2Gz3H/EpYwhfSbw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1764060465; x=1764146865; bh=U 1dP0nMMkej6FkoKDYCmZzMg0wuFTFgueJv1PwHiHLs=; b=ietzRB2UlpU6ZE+fD Kl2n4phs95NhicRgISOMMkXINPmCLHjVUs/reyUrSPX1/TZWQ2qy+l0pioDGIOYE bayqrExS576stfn9E6YoIiQUL6LEnVkLHkZN0pbufAaMrWsMwEObSnUOgfg1ZsK8 nQfTNOK6fzo2Nn0bjM9/cQH7fzKiM9OYwj1PQS1rMLbQPP5oCy5Dk65eYfdiTuTM iBmi1S/wVvLO6LPBqvXFDkiHZ7aUPd09lKzmFUiBJwHKwZ8UzQSk1vmDyAlQlOfa e4/qaC8VSuG9sW8ZGYmIS83Ffc7pw5u/qK9NWwImLnrbb9bHSjlOvay69fhRtHsO c4IMw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgedutddvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghushcu lfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrthhtvg hrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudejudeg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhtsh esihhrrhgvlhgvvhgrnhhtrdgukhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehqvghmuhdquggvvhgvlhesnhhonhhgnhhurdhorhhgpd hrtghpthhtohepphgvthgvrhdrmhgrhiguvghllheslhhinhgrrhhordhorhhgpdhrtghp thhtohepkhdrjhgvnhhsvghnsehsrghmshhunhhgrdgtohhmpdhrtghpthhtohepfhhosh hsseguvghfmhgrtghrohdrihhtpdhrtghpthhtohepkhgsuhhstghhsehkvghrnhgvlhdr ohhrghdprhgtphhtthhopehithhssehirhhrvghlvghvrghnthdrughkpdhrtghpthhtoh epshhtvghfrghnhhgrsehrvgguhhgrthdrtghomhdprhgtphhtthhopehfrghmsegvuhhp hhhonhdrnhgvthdprhgtphhtthhopehphhhilhhmugeslhhinhgrrhhordhorhhg X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: qemu-devel@nongnu.org Cc: Peter Maydell , Klaus Jensen , Jesper Wendel Devantier , Keith Busch , Klaus Jensen , Stefan Hajnoczi , Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org Subject: [PULL 1/3] hw/nvme: fix namespace atomic parameter setup Date: Tue, 25 Nov 2025 09:47:23 +0100 Message-ID: <20251125084725.4632-2-its@irrelevant.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251125084725.4632-1-its@irrelevant.dk> References: <20251125084725.4632-1-its@irrelevant.dk> MIME-Version: 1.0 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=202.12.124.148; envelope-from=its@irrelevant.dk; helo=fout-b5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @irrelevant.dk) X-ZM-MESSAGEID: 1764060529817019200 Content-Type: text/plain; charset="utf-8" From: Klaus Jensen Coverity complains about a possible copy-paste error in the verification of the namespace atomic parameters (CID 1642811). While the check is correct, the code (and the intention) is unclear. Fix this by reworking how the parameters are verified. Peter also identified that the realize function was not correctly erroring out if parameters were misconfigured, so fix that too. Lastly, change the error messages to be more describing. Coverity: CID 1642811 Fixes: bce51b83709b ("hw/nvme: add atomic boundary support") Fixes: 3b41acc96299 ("hw/nvme: enable ns atomic writes") Reviewed-by: Jesper Wendel Devantier Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 115 +++++++++++++------------- hw/nvme/ns.c | 189 ++++++++++++++++++++++++++----------------- hw/nvme/nvme.h | 25 +++--- include/block/nvme.h | 2 +- 4 files changed, 185 insertions(+), 146 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 4d150c7206ad..901d4d863355 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6524,6 +6524,53 @@ static uint16_t nvme_set_feature_fdp_events(NvmeCtrl= *n, NvmeNamespace *ns, return NVME_SUCCESS; } =20 +void nvme_atomic_configure_max_write_size(bool dn, uint16_t awun, + uint16_t awupf, NvmeAtomic *atom= ic) +{ + atomic->atomic_max_write_size =3D (dn ? awupf : awun) + 1; + + if (atomic->atomic_max_write_size > 1) { + atomic->atomic_writes =3D 1; + } +} + +static uint16_t nvme_set_feature_write_atomicity(NvmeCtrl *n, NvmeRequest = *req) +{ + NvmeCmd *cmd =3D &req->cmd; + + uint32_t dw11 =3D le32_to_cpu(cmd->cdw11); + + uint16_t awun =3D le16_to_cpu(n->id_ctrl.awun); + uint16_t awupf =3D le16_to_cpu(n->id_ctrl.awupf); + + n->dn =3D dw11 & 0x1; + + nvme_atomic_configure_max_write_size(n->dn, awun, awupf, &n->atomic); + + for (int i =3D 1; i <=3D NVME_MAX_NAMESPACES; i++) { + uint16_t nawun, nawupf, nabsn, nabspf; + + NvmeNamespace *ns =3D nvme_ns(n, i); + if (!ns) { + continue; + } + + nawun =3D le16_to_cpu(ns->id_ns.nawun); + nawupf =3D le16_to_cpu(ns->id_ns.nawupf); + + nvme_atomic_configure_max_write_size(n->dn, nawun, nawupf, + &ns->atomic); + + nabsn =3D le16_to_cpu(ns->id_ns.nabsn); + nabspf =3D le16_to_cpu(ns->id_ns.nabspf); + + nvme_ns_atomic_configure_boundary(n->dn, nabsn, nabspf, + &ns->atomic); + } + + return NVME_SUCCESS; +} + static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req) { NvmeNamespace *ns =3D NULL; @@ -6536,8 +6583,6 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeReq= uest *req) uint8_t save =3D NVME_SETFEAT_SAVE(dw10); uint16_t status; int i; - NvmeIdCtrl *id =3D &n->id_ctrl; - NvmeAtomic *atomic =3D &n->atomic; =20 trace_pci_nvme_setfeat(nvme_cid(req), nsid, fid, save, dw11); =20 @@ -6691,50 +6736,7 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRe= quest *req) case NVME_FDP_EVENTS: return nvme_set_feature_fdp_events(n, ns, req); case NVME_WRITE_ATOMICITY: - - n->dn =3D 0x1 & dw11; - - if (n->dn) { - atomic->atomic_max_write_size =3D le16_to_cpu(id->awupf) + 1; - } else { - atomic->atomic_max_write_size =3D le16_to_cpu(id->awun) + 1; - } - - if (atomic->atomic_max_write_size =3D=3D 1) { - atomic->atomic_writes =3D 0; - } else { - atomic->atomic_writes =3D 1; - } - for (i =3D 1; i <=3D NVME_MAX_NAMESPACES; i++) { - ns =3D nvme_ns(n, i); - if (ns && ns->atomic.atomic_writes) { - if (n->dn) { - ns->atomic.atomic_max_write_size =3D - le16_to_cpu(ns->id_ns.nawupf) + 1; - if (ns->id_ns.nabspf) { - ns->atomic.atomic_boundary =3D - le16_to_cpu(ns->id_ns.nabspf) + 1; - } else { - ns->atomic.atomic_boundary =3D 0; - } - } else { - ns->atomic.atomic_max_write_size =3D - le16_to_cpu(ns->id_ns.nawun) + 1; - if (ns->id_ns.nabsn) { - ns->atomic.atomic_boundary =3D - le16_to_cpu(ns->id_ns.nabsn) + 1; - } else { - ns->atomic.atomic_boundary =3D 0; - } - } - if (ns->atomic.atomic_max_write_size =3D=3D 1) { - ns->atomic.atomic_writes =3D 0; - } else { - ns->atomic.atomic_writes =3D 1; - } - } - } - break; + return nvme_set_feature_write_atomicity(n, req); default: return NVME_FEAT_NOT_CHANGEABLE | NVME_DNR; } @@ -7669,6 +7671,10 @@ static int nvme_atomic_boundary_check(NvmeCtrl *n, N= vmeCmd *cmd, =20 imask =3D ~(atomic->atomic_boundary - 1); if ((slba & imask) !=3D (elba & imask)) { + /* + * The write crosses an atomic boundary and the controller pro= vides + * no atomicity guarantees unless AWUN/AWUPF are non-zero. + */ if (n->atomic.atomic_max_write_size && ((nlb + 1) <=3D n->atomic.atomic_max_write_size)) { return 1; @@ -8709,7 +8715,6 @@ static void nvme_init_state(NvmeCtrl *n) NvmeSecCtrlEntry *list =3D n->sec_ctrl_list; NvmeSecCtrlEntry *sctrl; PCIDevice *pci =3D PCI_DEVICE(n); - NvmeAtomic *atomic =3D &n->atomic; NvmeIdCtrl *id =3D &n->id_ctrl; uint8_t max_vfs; int i; @@ -8781,19 +8786,9 @@ static void nvme_init_state(NvmeCtrl *n) id->awupf =3D 0; } =20 - if (n->dn) { - atomic->atomic_max_write_size =3D id->awupf + 1; - } else { - atomic->atomic_max_write_size =3D id->awun + 1; - } - - if (atomic->atomic_max_write_size =3D=3D 1) { - atomic->atomic_writes =3D 0; - } else { - atomic->atomic_writes =3D 1; - } - atomic->atomic_boundary =3D 0; - atomic->atomic_nabo =3D 0; + nvme_atomic_configure_max_write_size(n->dn, n->params.atomic_awun, + n->params.atomic_awupf, + &n->atomic); } } =20 diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 86f5ab0a7572..253e7b406b4e 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -718,85 +718,119 @@ static void nvme_ns_unrealize(DeviceState *dev) nvme_ns_cleanup(ns); } =20 +void nvme_ns_atomic_configure_boundary(bool dn, uint16_t nabsn, + uint16_t nabspf, NvmeAtomic *atomic) +{ + atomic->atomic_boundary =3D dn ? nabspf : nabsn; + + if (atomic->atomic_boundary > 0) { + atomic->atomic_boundary +=3D 1; + } +} + +static bool nvme_ns_set_nab(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) +{ + NvmeIdNs *id_ns =3D &ns->id_ns; + NvmeIdCtrl *id_ctrl =3D &n->id_ctrl; + + uint16_t nabsn =3D ns->params.atomic.nabsn; + uint16_t nabspf =3D ns->params.atomic.nabspf; + uint16_t nabo =3D ns->params.atomic.nabo; + + if (nabsn && nabsn < le16_to_cpu(id_ctrl->awun)) { + error_setg(errp, "nabsn must be greater than or equal to awun"); + return false; + } + + if (nabspf && nabspf < le16_to_cpu(id_ctrl->awupf)) { + error_setg(errp, "nabspf must be greater than or equal to awupf"); + return false; + } + + if (id_ns->nsfeat & NVME_ID_NS_NSFEAT_NSABP) { + if (nabsn && nabsn < le16_to_cpu(id_ns->nawun)) { + error_setg(errp, "nabsn must be greater than or equal to nawun= "); + return false; + } + + if (nabspf && nabspf < le16_to_cpu(id_ns->nawupf)) { + error_setg(errp, "nabspf must be great than or equal to nawupf= "); + return false; + } + } + + if (nabo && (nabo > nabsn || nabo > nabspf)) { + error_setg(errp, "nabo must be less than or equal to nabsn and nab= spf"); + return false; + } + + id_ns->nabsn =3D cpu_to_le16(nabsn); + id_ns->nabspf =3D cpu_to_le16(nabspf); + id_ns->nabo =3D cpu_to_le16(nabo); + + ns->atomic.atomic_nabo =3D nabo; + + nvme_ns_atomic_configure_boundary(n->dn, nabsn, nabspf, &ns->atomic); + + return true; +} + +static bool nvme_ns_set_nsabp(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) +{ + NvmeIdNs *id_ns =3D &ns->id_ns; + NvmeIdCtrl *id_ctrl =3D &n->id_ctrl; + + uint16_t awun =3D le16_to_cpu(id_ctrl->awun); + uint16_t awupf =3D le16_to_cpu(id_ctrl->awupf); + + uint16_t nawun =3D ns->params.atomic.nawun; + uint16_t nawupf =3D ns->params.atomic.nawupf; + + if (nawupf > nawun) { + if (nawun =3D=3D 0) { + nawun =3D nawupf; + } else { + error_setg(errp, "nawupf must be less than or equal to nawun"); + return false; + } + } + + /* neither nawun or nawupf is set */ + if (nawun =3D=3D 0) { + return true; + } + + if (nawun < awun) { + error_setg(errp, "nawun must be greater than or equal to awun"); + return false; + } + + if (nawupf < awupf) { + error_setg(errp, "nawupf must be greater than or equal to awupf"); + return false; + } + + id_ns->nsfeat |=3D NVME_ID_NS_NSFEAT_NSABP; + + id_ns->nawun =3D cpu_to_le16(nawun); + id_ns->nawupf =3D cpu_to_le16(nawupf); + + nvme_atomic_configure_max_write_size(n->dn, nawun, nawupf, &ns->atomic= ); + + return true; +} + static void nvme_ns_realize(DeviceState *dev, Error **errp) { NvmeNamespace *ns =3D NVME_NS(dev); BusState *s =3D qdev_get_parent_bus(dev); NvmeCtrl *n =3D NVME(s->parent); NvmeSubsystem *subsys =3D n->subsys; - NvmeIdCtrl *id =3D &n->id_ctrl; - NvmeIdNs *id_ns =3D &ns->id_ns; uint32_t nsid =3D ns->params.nsid; int i; =20 assert(subsys); =20 - /* Set atomic write parameters */ - if (ns->params.atomic_nsfeat) { - id_ns->nsfeat |=3D NVME_ID_NS_NSFEAT_NSABPNS; - id_ns->nawun =3D cpu_to_le16(ns->params.atomic_nawun); - if (!id->awupf || (id_ns->nawun && (id_ns->nawun < id->awun))) { - error_report("Invalid NAWUN: %x AWUN=3D%x", id_ns->nawun, id->= awun); - } - id_ns->nawupf =3D cpu_to_le16(ns->params.atomic_nawupf); - if (!id->awupf || (id_ns->nawupf && (id_ns->nawupf < id->awupf))) { - error_report("Invalid NAWUPF: %x AWUPF=3D%x", - id_ns->nawupf, id->awupf); - } - if (id_ns->nawupf > id_ns->nawun) { - error_report("Invalid: NAWUN=3D%x NAWUPF=3D%x", - id_ns->nawun, id_ns->nawupf); - } - id_ns->nabsn =3D cpu_to_le16(ns->params.atomic_nabsn); - id_ns->nabspf =3D cpu_to_le16(ns->params.atomic_nabspf); - id_ns->nabo =3D cpu_to_le16(ns->params.atomic_nabo); - if (!id->awun || (id_ns->nabsn && ((id_ns->nabsn < id_ns->nawun) || - (id_ns->nabsn < id->awun)))) { - error_report("Invalid NABSN: %x NAWUN=3D%x AWUN=3D%x", - id_ns->nabsn, id_ns->nawun, id->awun); - } - if (!id->awupf || (id_ns->nabspf && ((id_ns->nabspf < id_ns->nawup= f) || - (id_ns->nawupf < id->awupf)))) { - error_report("Invalid NABSPF: %x NAWUPF=3D%x AWUPF=3D%x", - id_ns->nabspf, id_ns->nawupf, id->awupf); - } - if (id_ns->nabo && ((id_ns->nabo > id_ns->nabsn) || - (id_ns->nabo > id_ns->nabspf))) { - error_report("Invalid NABO: %x NABSN=3D%x NABSPF=3D%x", - id_ns->nabo, id_ns->nabsn, id_ns->nabspf); - } - if (id_ns->nawupf > id_ns->nawun) { - error_report("Invalid: NAWUN=3D%x NAWUPF=3D%x", id_ns->nawun, - id_ns->nawupf); - } - } - - if (id_ns->nawun || id_ns->nawupf) { - NvmeAtomic *atomic =3D &ns->atomic; - - if (n->dn) { - atomic->atomic_max_write_size =3D cpu_to_le16(id_ns->nawupf) += 1; - if (id_ns->nabspf) { - atomic->atomic_boundary =3D cpu_to_le16(id_ns->nabspf) + 1; - } else { - atomic->atomic_boundary =3D 0; - } - } else { - atomic->atomic_max_write_size =3D cpu_to_le16(id_ns->nawun) + = 1; - if (id_ns->nabsn) { - atomic->atomic_boundary =3D cpu_to_le16(id_ns->nabsn) + 1; - } else { - atomic->atomic_boundary =3D 0; - } - } - if (atomic->atomic_max_write_size =3D=3D 1) { - atomic->atomic_writes =3D 0; - } else { - atomic->atomic_writes =3D 1; - } - atomic->atomic_nabo =3D cpu_to_le16(id_ns->nabo); - } - /* reparent to subsystem bus */ if (!qdev_set_parent_bus(dev, &subsys->bus.parent_bus, errp)) { return; @@ -804,6 +838,14 @@ static void nvme_ns_realize(DeviceState *dev, Error **= errp) ns->subsys =3D subsys; ns->endgrp =3D &subsys->endgrp; =20 + if (!nvme_ns_set_nsabp(n, ns, errp)) { + return; + } + + if (!nvme_ns_set_nab(n, ns, errp)) { + return; + } + if (nvme_ns_setup(ns, errp)) { return; } @@ -872,12 +914,11 @@ static const Property nvme_ns_props[] =3D { DEFINE_PROP_BOOL("eui64-default", NvmeNamespace, params.eui64_default, false), DEFINE_PROP_STRING("fdp.ruhs", NvmeNamespace, params.fdp.ruhs), - DEFINE_PROP_UINT16("atomic.nawun", NvmeNamespace, params.atomic_nawun,= 0), - DEFINE_PROP_UINT16("atomic.nawupf", NvmeNamespace, params.atomic_nawup= f, 0), - DEFINE_PROP_UINT16("atomic.nabspf", NvmeNamespace, params.atomic_nabsp= f, 0), - DEFINE_PROP_UINT16("atomic.nabsn", NvmeNamespace, params.atomic_nabsn,= 0), - DEFINE_PROP_UINT16("atomic.nabo", NvmeNamespace, params.atomic_nabo, 0= ), - DEFINE_PROP_BOOL("atomic.nsfeat", NvmeNamespace, params.atomic_nsfeat,= 0), + DEFINE_PROP_UINT16("atomic.nawun", NvmeNamespace, params.atomic.nawun,= 0), + DEFINE_PROP_UINT16("atomic.nawupf", NvmeNamespace, params.atomic.nawup= f, 0), + DEFINE_PROP_UINT16("atomic.nabsn", NvmeNamespace, params.atomic.nabsn,= 0), + DEFINE_PROP_UINT16("atomic.nabspf", NvmeNamespace, params.atomic.nabsp= f, 0), + DEFINE_PROP_UINT16("atomic.nabo", NvmeNamespace, params.atomic.nabo, 0= ), }; =20 static void nvme_ns_class_init(ObjectClass *oc, const void *data) diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index a7d225d2d80b..8f8c78c85036 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -218,12 +218,14 @@ typedef struct NvmeNamespaceParams { struct { char *ruhs; } fdp; - uint16_t atomic_nawun; - uint16_t atomic_nawupf; - uint16_t atomic_nabsn; - uint16_t atomic_nabspf; - uint16_t atomic_nabo; - bool atomic_nsfeat; + + struct { + uint16_t nawun; + uint16_t nawupf; + uint16_t nabsn; + uint16_t nabspf; + uint16_t nabo; + } atomic; } NvmeNamespaceParams; =20 typedef struct NvmeAtomic { @@ -288,11 +290,7 @@ typedef struct NvmeNamespace { /* reclaim unit handle identifiers indexed by placement handle */ uint16_t *phs; } fdp; - uint16_t atomic_nawun; - uint16_t atomic_nawupf; - uint16_t atomic_nabsn; - uint16_t atomic_nabspf; - uint16_t atomic_nabo; + NvmeAtomic atomic; } NvmeNamespace; =20 @@ -742,4 +740,9 @@ void nvme_rw_complete_cb(void *opaque, int ret); uint16_t nvme_map_dptr(NvmeCtrl *n, NvmeSg *sg, size_t len, NvmeCmd *cmd); =20 +void nvme_atomic_configure_max_write_size(bool dn, uint16_t awun, + uint16_t awupf, NvmeAtomic *atom= ic); +void nvme_ns_atomic_configure_boundary(bool dn, uint16_t nabsn, + uint16_t nabspf, NvmeAtomic *atomic= ); + #endif /* HW_NVME_NVME_H */ diff --git a/include/block/nvme.h b/include/block/nvme.h index 9fa2ecaf281c..8640dfa8269f 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -1589,7 +1589,7 @@ enum NvmeIdNsMc { =20 enum NvmeIdNsNsfeat { NVME_ID_NS_NSFEAT_THINP =3D 1 << 0, - NVME_ID_NS_NSFEAT_NSABPNS =3D 1 << 1, + NVME_ID_NS_NSFEAT_NSABP =3D 1 << 1, NVME_ID_NS_NSFEAT_DAE =3D 1 << 2, NVME_ID_NS_NSFEAT_UIDREUSE =3D 1 << 3, NVME_ID_NS_NSFEAT_OPTPERF_ALL =3D 3 << 4, --=20 2.51.0 From nobody Sat Feb 7 07:25:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1764060527; cv=none; d=zohomail.com; s=zohoarc; b=Kd8tmNJLwtx1HY+jyMt7OowWlhZ2QNtu0IVDB1DOHgbKUDfZ6MtlXlmGDInGCBhNXNgHmxBfcZGS2BFECrpQveaQ7n5IqJbo/GruoI46Xruf7ys+U+EUSp2cLOIRgZUOhan/LSLAgQhq0AfTIRT9XluzxPlbq5gVPP8OcjUnf4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764060527; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QyUo03bV+OULvhaQCtypRWEx7FCP+TKJrB3LovbCkkk=; b=LALltKzXqKkJmt7Ms3KlUn60F1Z6OU2KMaTYt/YKonrF0tf7lKzxFiIgw3PuOTBzmCobuiA3oY4wrjHeY82XQYjkQJdp2QeUjBHF2SYIjSgNpyiE+J/RSHz6rlpZxrmjev11QG/WQ3hK0jKB3056GBROPjDbw48ytNk6+MvR0M8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764060527574369.0125822705173; Tue, 25 Nov 2025 00:48:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNoiF-00089Z-QR; Tue, 25 Nov 2025 03:47:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNoiD-00087w-Vz; Tue, 25 Nov 2025 03:47:50 -0500 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNoiC-0008CM-JA; Tue, 25 Nov 2025 03:47:49 -0500 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 817B61D00221; Tue, 25 Nov 2025 03:47:47 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 25 Nov 2025 03:47:47 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 Nov 2025 03:47:45 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1764060467; x= 1764146867; bh=QyUo03bV+OULvhaQCtypRWEx7FCP+TKJrB3LovbCkkk=; b=f 4MJIz41f2kYgW/pcfH4UNEBOM9IxqFwWPGzj9iiy5jZ07XUNlyuAvnNCucLMDEgC BPuITj51AuSiwgjZ/qusbXXgwQWoxvar+6l0FHd0iIdZ0B/dSqD0ASikgGQCjckx BErQvUuyK4uasJ7GiiXDs+fNRlNYMFJnuY32Tv+xd8UMRN95sABfcIMQhcmD7SB4 R3PR3N08cEzWDgBBuwmaQreDFER4v8rS9ckEOX0+7KDF/PA9gaXzioit1T2RVyAU Qc1wOiYduo/wSTvpUM94w0zA1l94CY1KuO/OqsYNC6O1Bq8Kvl0yM7nL5+DjqkhU LphRqB8yAo2g7E7w0fFPQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1764060467; x=1764146867; bh=Q yUo03bV+OULvhaQCtypRWEx7FCP+TKJrB3LovbCkkk=; b=0iZe5uolOEQ174nMY URp66bvH9iaI5MCs4uyHzJokZjP9W5qh7rMOGodGsBWvqTjh60aO9pqvxqHvtMZT YzGXPtk/igpmp4HntgrMzbBVUE7wo+0Zn9r7VnU1wQfP1RJ3LdlSB/kJi/mVkhYf YfbE4HKuu9aMRocvlSDzmwHb8QZbr7D/WB0oTNsBHR3MFjW4QzruPPG0Rqs5tYPT yB91v1j+3Q1qhS+0nC7WrBbvGN6Us8+K5ZL8AFsW4HAWtoNSXXJnBTztFyqUsC5P JZK+vdA4ZsH3Zvyik55JSjxamPOKoqFCoLiMxFOXvypsE/xyA1aPtrW1fGS1BRtg 24sWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgedutdefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghushcu lfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrthhtvg hrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudejudeg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhtsh esihhrrhgvlhgvvhgrnhhtrdgukhdpnhgspghrtghpthhtohepjedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrghdprh gtphhtthhopehpvghtvghrrdhmrgihuggvlhhlsehlihhnrghrohdrohhrghdprhgtphht thhopehksghushgthheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhdrjhgvnhhsvg hnsehsrghmshhunhhgrdgtohhmpdhrtghpthhtohepihhtshesihhrrhgvlhgvvhgrnhht rdgukhdprhgtphhtthhopehfohhsshesuggvfhhmrggtrhhordhithdprhgtphhtthhope hqvghmuhdqsghlohgtkhesnhhonhhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: qemu-devel@nongnu.org Cc: Peter Maydell , Keith Busch , Klaus Jensen , Klaus Jensen , Jesper Devantier , qemu-block@nongnu.org Subject: [PULL 2/3] hw/nvme: fix up extended protection information format Date: Tue, 25 Nov 2025 09:47:24 +0100 Message-ID: <20251125084725.4632-3-its@irrelevant.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251125084725.4632-1-its@irrelevant.dk> References: <20251125084725.4632-1-its@irrelevant.dk> MIME-Version: 1.0 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=202.12.124.148; envelope-from=its@irrelevant.dk; helo=fout-b5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @irrelevant.dk) X-ZM-MESSAGEID: 1764060531413019200 Content-Type: text/plain; charset="utf-8" From: Keith Busch Set the protection information format (pif) only in the formats that can support the larger guard types, and update the current in-use format information when the user changes it. Signed-off-by: Keith Busch [k.jensen: fix missing braces and wrong indentation] Signed-off-by: Klaus Jensen --- hw/nvme/ns.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 253e7b406b4e..58800b3414a3 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -32,11 +32,13 @@ void nvme_ns_init_format(NvmeNamespace *ns) NvmeIdNs *id_ns =3D &ns->id_ns; NvmeIdNsNvm *id_ns_nvm =3D &ns->id_ns_nvm; BlockDriverInfo bdi; - int npdg, ret; + int npdg, ret, index; int64_t nlbas; =20 + index =3D NVME_ID_NS_FLBAS_INDEX(id_ns->flbas); ns->lbaf =3D id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; ns->lbasz =3D 1 << ns->lbaf.ds; + ns->pif =3D NVME_ID_NS_NVM_ELBAF_PIF(ns->id_ns_nvm.elbaf[index]); =20 nlbas =3D ns->size / (ns->lbasz + ns->lbaf.ms); =20 @@ -112,8 +114,6 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) id_ns->dps |=3D NVME_ID_NS_DPS_FIRST_EIGHT; } =20 - ns->pif =3D ns->params.pif; - static const NvmeLBAF defaults[16] =3D { [0] =3D { .ds =3D 9 }, [1] =3D { .ds =3D 9, .ms =3D 8 }, @@ -129,6 +129,12 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **err= p) =20 memcpy(&id_ns->lbaf, &defaults, sizeof(defaults)); =20 + for (i =3D 0; i < ns->nlbaf; i++) { + if (id_ns->lbaf[i].ms >=3D 16) { + id_ns_nvm->elbaf[i] =3D (ns->params.pif & 0x3) << 7; + } + } + for (i =3D 0; i < ns->nlbaf; i++) { NvmeLBAF *lbaf =3D &id_ns->lbaf[i]; if (lbaf->ds =3D=3D ds) { @@ -142,13 +148,14 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **er= rp) /* add non-standard lba format */ id_ns->lbaf[ns->nlbaf].ds =3D ds; id_ns->lbaf[ns->nlbaf].ms =3D ms; + if (ms >=3D 16) { + id_ns_nvm->elbaf[ns->nlbaf] =3D (ns->params.pif & 0x3) << 7; + } ns->nlbaf++; =20 id_ns->flbas |=3D i; =20 - lbaf_found: - id_ns_nvm->elbaf[i] =3D (ns->pif & 0x3) << 7; id_ns->nlbaf =3D ns->nlbaf - 1; nvme_ns_init_format(ns); =20 --=20 2.51.0 From nobody Sat Feb 7 07:25:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1764060534; cv=none; d=zohomail.com; s=zohoarc; b=BToyIA1Q/7w0woM0bgiz6apW8q0ZXsyWEbNQMmbYj0uqzdCLI4yl14Py93VcarwsZrxIQl9mvJBD6s2X4R9QDo6UWShQdmYs34moF58i1vnZsT0X7waaExkl1eZ17i3uah9mwiaaQpyoY7fXIKbofPFjPSM6ioIB1/2YcF7OhTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764060534; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7IS0y0KL6f9wIcEoT4675tOP1YM8wZ2gL3bKB8rQKTI=; b=SnoWhK/wXYDQi3EMsreZKPqppkPPZvSbgyI3z4z/vgh/QFZY0UvWtEV2MW1OMH2YAvqRUlb+ha57KmAAvdn8AlIsFTACGHDePhgORSAbrOH5Ljvd7rqDdOeqSKmIg+J03vUXhE/eJTNC162RBcSVJvg5RFiVpTf+f/UbB63FTR8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764060534450580.8294842410968; Tue, 25 Nov 2025 00:48:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vNoiI-0008Bi-U7; Tue, 25 Nov 2025 03:47:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNoiG-0008A4-NK; Tue, 25 Nov 2025 03:47:52 -0500 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vNoiF-0008Ct-5j; Tue, 25 Nov 2025 03:47:52 -0500 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id E73E97A00FE; Tue, 25 Nov 2025 03:47:49 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 25 Nov 2025 03:47:50 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 Nov 2025 03:47:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm2; t=1764060469; x=1764146869; bh=7IS0y0KL6f9wIcEoT4675tOP1YM8wZ2g L3bKB8rQKTI=; b=SyoFkkAyEIMfn0/TaTFITKdFI7+Epjci+wlkOyLMzH8E47EI bPEuC2PVm9jAjQ8A8jka8Wt8U59zKysgg9lhKgN8ArJXmdcCRnxd5qnIWKcBh7Rl +W8cWrzpEe4XnxopNJQnJrYdrXs/RN+A874mEUKRpZv40fqtyfZaAdZUThmD9Prv MJk/BFde9rSVqguNL8nTfvpiVkBuPveFhb4TaT3lFygbaoIWUyCYKt5iVsENLJ/G i2Pyr65aY16aU1RoQLHJnd3HobeqeoZjcwy+eRv14llek3tRofDjHxDMDLMid+d9 M4pv3tyCUT21czbrjvj78Q8aSP2vERV/5qfjfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1764060469; x= 1764146869; bh=7IS0y0KL6f9wIcEoT4675tOP1YM8wZ2gL3bKB8rQKTI=; b=a QfusAA6ca15pCgxi214wetINa/CF3UObMdO4j6mBjNPW40KG+/607SwCjAd/AErQ SlK0Yd+uXzx4l8zvGZIucMI6hXqkA9XYxEgzvwzZ8eCFfLkMKaA7tpYY7optskZN THcXg7uqzwuYLbLl6KeDaz4L3fH1pO3U8k0AJXFQ7kwi1U9uppyO184Js0RCHDGy EZe0lgMLMMGW3xbhp+oj1dl4t9pRK8VdMvpUFoRUA/ka3/5Tpf0kc0SYgXpm/20S quagh6CgwA/BKsK7qCyw5iok3eyRb8s5pQkdT/0xjmI9wzRKYIqEz/Xy2R3SKUhE kKpPFBnL2h+wk3ArzZzbw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgedutdefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeefvedtueetueduffevgffgtdeftdeuleffhfeigeffkeegfeejfeffteejiefh vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehith hssehirhhrvghlvghvrghnthdrughkpdhnsggprhgtphhtthhopeduuddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh dprhgtphhtthhopehpvghtvghrrdhmrgihuggvlhhlsehlihhnrghrohdrohhrghdprhgt phhtthhopehphhhilhhmugeslhhinhgrrhhordhorhhgpdhrtghpthhtohepkhdrjhgvnh hsvghnsehsrghmshhunhhgrdgtohhmpdhrtghpthhtohepkhgsuhhstghhsehkvghrnhgv lhdrohhrghdprhgtphhtthhopehithhssehirhhrvghlvghvrghnthdrughkpdhrtghpth htohepfhhoshhsseguvghfmhgrtghrohdrihhtpdhrtghpthhtohepfhgrrhhoshgrshes shhushgvrdguvgdprhgtphhtthhopehlvhhivhhivghrsehrvgguhhgrthdrtghomh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Klaus Jensen , Keith Busch , Klaus Jensen , Jesper Devantier , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , qemu-block@nongnu.org Subject: [PULL 3/3] hw/nvme: Validate PMR memory size Date: Tue, 25 Nov 2025 09:47:25 +0100 Message-ID: <20251125084725.4632-4-its@irrelevant.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251125084725.4632-1-its@irrelevant.dk> References: <20251125084725.4632-1-its@irrelevant.dk> MIME-Version: 1.0 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=202.12.124.156; envelope-from=its@irrelevant.dk; helo=fhigh-b5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @irrelevant.dk) X-ZM-MESSAGEID: 1764060535817019200 From: Philippe Mathieu-Daud=C3=A9 Per the PCI spec 3.0, in section 6.2.5.1, "Address Maps": A 32-bit register can be implemented to support a single memory size that is a power of 2 from 16 bytes to 2 GB. Add a check in nvme_init_pmr(), returning an error if the PMR region size is too small; and update the QTest. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Klaus Jensen Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 13 +++++++++++-- tests/qtest/nvme-test.c | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 901d4d863355..cc4593cd427a 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8814,10 +8814,15 @@ static void nvme_init_cmb(NvmeCtrl *n, PCIDevice *p= ci_dev) } } =20 -static void nvme_init_pmr(NvmeCtrl *n, PCIDevice *pci_dev) +static bool nvme_init_pmr(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) { uint32_t pmrcap =3D ldl_le_p(&n->bar.pmrcap); =20 + if (memory_region_size(&n->pmr.dev->mr) < 16) { + error_setg(errp, "PMR device must have at least 16 bytes"); + return false; + } + NVME_PMRCAP_SET_RDS(pmrcap, 1); NVME_PMRCAP_SET_WDS(pmrcap, 1); NVME_PMRCAP_SET_BIR(pmrcap, NVME_PMR_BIR); @@ -8832,6 +8837,8 @@ static void nvme_init_pmr(NvmeCtrl *n, PCIDevice *pci= _dev) PCI_BASE_ADDRESS_MEM_PREFETCH, &n->pmr.dev->mr); =20 memory_region_set_enabled(&n->pmr.dev->mr, false); + + return true; } =20 static uint64_t nvme_mbar_size(unsigned total_queues, unsigned total_irqs, @@ -9050,7 +9057,9 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci= _dev, Error **errp) } =20 if (n->pmr.dev) { - nvme_init_pmr(n, pci_dev); + if (!nvme_init_pmr(n, pci_dev, errp)) { + return false; + } } =20 return true; diff --git a/tests/qtest/nvme-test.c b/tests/qtest/nvme-test.c index 5ad6821f7af9..4aec1651e6e2 100644 --- a/tests/qtest/nvme-test.c +++ b/tests/qtest/nvme-test.c @@ -149,7 +149,7 @@ static void nvme_register_nodes(void) .before_cmd_line =3D "-drive id=3Ddrv0,if=3Dnone,file=3Dnull-co://= ," "file.read-zeroes=3Don,format=3Draw " "-object memory-backend-ram,id=3Dpmr0," - "share=3Don,size=3D8", + "share=3Don,size=3D16", }; =20 add_qpci_address(&opts, &(QPCIAddress) { .devfn =3D QPCI_DEVFN(4, 0) }= ); --=20 2.51.0