From nobody Tue Feb 10 01:50:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=yadro.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166930560772854.722664627682775; Thu, 24 Nov 2022 08:00:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyEdH-0002f5-Au; Thu, 24 Nov 2022 10:59:23 -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 1oyEd5-0002Ns-Qq; Thu, 24 Nov 2022 10:59:13 -0500 Received: from mta-02.yadro.com ([89.207.88.252] helo=mta-01.yadro.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyEd3-0005Ip-Le; Thu, 24 Nov 2022 10:59:11 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 35D4140311; Thu, 24 Nov 2022 15:59:05 +0000 (UTC) Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xSVwTlhnNwLv; Thu, 24 Nov 2022 18:59:02 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (T-EXCH-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id E51DE4014D; Thu, 24 Nov 2022 18:59:02 +0300 (MSK) Received: from T-EXCH-09.corp.yadro.com (172.17.11.59) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 24 Nov 2022 18:59:02 +0300 Received: from archlinux.yadro.com (10.178.113.54) by T-EXCH-09.corp.yadro.com (172.17.11.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.9; Thu, 24 Nov 2022 18:59:01 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received:received; s= mta-01; t=1669305542; x=1671119943; bh=TyDsjRjeQub7YIZdTGQR9xxCB bJwRxPEqnZOuMpHouQ=; b=JP5GyAyP/aqpRpQMTudINdRjfsfDVLX0fseNp/gBh XGekNELD4Q0BS1qCGQCMyUAK15tZjsywOnA5qZJVyycXmulzsULht3QQcRbAFJnb WlOgzw6YX61ZsqZ6qouZG2k/hWBrhYusYoFX5gTIhzeIH1xQ0APcv6USLKEIuyxy ZE= X-Virus-Scanned: amavisd-new at yadro.com From: Dmitry Tihov To: CC: , , , , , , Subject: [RFC 3/5] hw/nvme: add protection information pass parameter Date: Thu, 24 Nov 2022 18:58:19 +0300 Message-ID: <20221124155821.1501969-4-d.tihov@yadro.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221124155821.1501969-1-d.tihov@yadro.com> References: <20221124155821.1501969-1-d.tihov@yadro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.178.113.54] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-09.corp.yadro.com (172.17.11.59) 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=89.207.88.252; envelope-from=d.tihov@yadro.com; helo=mta-01.yadro.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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.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-ZM-MESSAGEID: 1669305608644100003 Content-Type: text/plain; charset="utf-8" Allow namespace to enable pass-through of protection information between guest and integrity capable BlockBackend. Signed-off-by: Dmitry Tihov --- hw/nvme/ns.c | 59 +++++++++++++++++++++++++++++++++++++++++++++----- hw/nvme/nvme.h | 2 ++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 62a1f97be0..da0cff71f8 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -35,7 +35,11 @@ void nvme_ns_init_format(NvmeNamespace *ns) ns->lbaf =3D id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; ns->lbasz =3D 1 << ns->lbaf.ds; =20 - nlbas =3D ns->size / (ns->lbasz + ns->lbaf.ms); + if (ns->pip) { + nlbas =3D ns->size / (ns->lbasz); + } else { + nlbas =3D ns->size / (ns->lbasz + ns->lbaf.ms); + } =20 id_ns->nsze =3D cpu_to_le64(nlbas); =20 @@ -60,17 +64,22 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) static uint64_t ns_count; NvmeIdNs *id_ns =3D &ns->id_ns; NvmeIdNsNvm *id_ns_nvm =3D &ns->id_ns_nvm; + BlockDriverInfo bdi; uint8_t ds; uint16_t ms; - int i; + int i, ret; + + ns->pip =3D ns->params.pip; =20 ns->csi =3D NVME_CSI_NVM; ns->status =3D 0x0; =20 ns->id_ns.dlfeat =3D 0x1; =20 - /* support DULBE and I/O optimization fields */ - id_ns->nsfeat |=3D (0x4 | 0x10); + if (!ns->pip) { + /* support DULBE and I/O optimization fields */ + id_ns->nsfeat |=3D (0x4 | 0x10); + } =20 if (ns->params.shared) { id_ns->nmic |=3D NVME_NMIC_NS_SHARED; @@ -89,7 +98,11 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) id_ns->eui64 =3D cpu_to_be64(ns->params.eui64); =20 ds =3D 31 - clz32(ns->blkconf.logical_block_size); - ms =3D ns->params.ms; + if (ns->pip) { + ms =3D 8; + } else { + ms =3D ns->params.ms; + } =20 id_ns->mc =3D NVME_ID_NS_MC_EXTENDED | NVME_ID_NS_MC_SEPARATE; =20 @@ -105,6 +118,14 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **err= p) =20 ns->pif =3D ns->params.pif; =20 + if (ns->pip) { + ret =3D bdrv_get_info(blk_bs(ns->blkconf.blk), &bdi); + if (ret >=3D 0) { + id_ns->dps =3D bdi.protection_type; + ns->pif =3D NVME_PI_GUARD_16; + } + } + static const NvmeLBAF lbaf[16] =3D { [0] =3D { .ds =3D 9 }, [1] =3D { .ds =3D 9, .ms =3D 8 }, @@ -380,13 +401,38 @@ static void nvme_zoned_ns_shutdown(NvmeNamespace *ns) static int nvme_ns_check_constraints(NvmeNamespace *ns, Error **errp) { unsigned int pi_size; + BlockDriverInfo bdi; + int ret; =20 if (!ns->blkconf.blk) { error_setg(errp, "block backend not configured"); return -1; } =20 - if (ns->params.pi) { + if (ns->params.pip) { + if (ns->params.mset) { + error_setg(errp, "invalid mset parameter, metadata must be " + "stored in a separate buffer to use integrity passthrough"= ); + return -1; + } + ret =3D bdrv_get_info(blk_bs(ns->blkconf.blk), &bdi); + if (ret < 0) { + error_setg(errp, "could not determine host block device" + " integrity information"); + return -1; + } + if (!bdi.protection_type) { + error_setg(errp, "nvme-ns backend block device does not" + " support integrity passthrough"); + return -1; + } + if (bdi.protection_interval !=3D ns->blkconf.logical_block_size) { + error_setg(errp, "logical block size parameter (%u bytes) must= be" + " equal to protection information interval (%u bytes)", + ns->blkconf.logical_block_size, bdi.protection_interval); + return -1; + } + } else if (ns->params.pi) { if (ns->params.pi > NVME_ID_NS_DPS_TYPE_3) { error_setg(errp, "invalid 'pi' value"); return -1; @@ -623,6 +669,7 @@ static Property nvme_ns_props[] =3D { DEFINE_PROP_UINT8("pi", NvmeNamespace, params.pi, 0), DEFINE_PROP_UINT8("pil", NvmeNamespace, params.pil, 0), DEFINE_PROP_UINT8("pif", NvmeNamespace, params.pif, 0), + DEFINE_PROP_BOOL("pip", NvmeNamespace, params.pip, false), DEFINE_PROP_UINT16("mssrl", NvmeNamespace, params.mssrl, 128), DEFINE_PROP_UINT32("mcl", NvmeNamespace, params.mcl, 128), DEFINE_PROP_UINT8("msrc", NvmeNamespace, params.msrc, 127), diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 79f5c281c2..4876670d26 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -109,6 +109,7 @@ typedef struct NvmeNamespaceParams { uint8_t pi; uint8_t pil; uint8_t pif; + bool pip; =20 uint16_t mssrl; uint32_t mcl; @@ -143,6 +144,7 @@ typedef struct NvmeNamespace { uint16_t status; int attached; uint8_t pif; + bool pip; =20 struct { uint16_t zrwas; --=20 2.38.1