From patchwork Tue Mar 12 17:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1911303 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=UDXQBjP7; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=kRuNqlDr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvLHG2xYLz1yWt for ; Wed, 13 Mar 2024 04:29:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5tr-00027Q-U1; Tue, 12 Mar 2024 13:26:51 -0400 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 1rk5te-00023y-VD; Tue, 12 Mar 2024 13:26:39 -0400 Received: from wfhigh5-smtp.messagingengine.com ([64.147.123.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk5td-0005No-3C; Tue, 12 Mar 2024 13:26:38 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id C544E1800082; Tue, 12 Mar 2024 13:26:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 12 Mar 2024 13:26:34 -0400 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=fm3; t=1710264393; x= 1710350793; bh=l7VA1kmIdj5go01fibCCpJkzwEtHzwcL+nZbGerYsTM=; b=U DXQBjP7uwKHDAMpLUHr2zI6IxglSZamC59bz3tvU15Z4dBjrYtqg/8VMK6Vj8Ciq MRsTkWuX1KHTzw2c75878Y8h333ccbqVDtmDb8a60oLCAJ2ynJ+idoJM4Ld7W9kM RsQ6UX1fkdYT/RONRhGKAZ6nhDuuh4P3fxA9IKPmkMP9hAiH0Cs3o3y/vfYawrFt YXz4/2cpo1pC/T5PjHtcAPVtKoFWr5ryYETFCxhne/f0wjmafLaYbMpMf6p43zue cngM9PUv4E4PGkxd+1DVqZPBLjm3h+W5k7LgocSjnpWzDW/BWLSaHfembbVBA590 t4IxZZPMId3N0mfJAgSpA== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710264393; x= 1710350793; bh=l7VA1kmIdj5go01fibCCpJkzwEtHzwcL+nZbGerYsTM=; b=k RuNqlDrQ3AeSvm3hBFgk742HrZMCTuiBW9ik8lInjBuUeBDf9nbd9gYoSJhJPIi4 JQzdwKmBsqLhaawoDE0clrp575AputN7xumMJJ28FSDLDxZzTP6o1ne5FjQj0cBB m2khCEiJJO3FFFY0Bj5KtzPmCTKNum5BJ55Q1hGObM9cQiznDWITXgHDCm9cEXE8 9c/Lpjj/drEkh/8o8in9H0MSbm7FsI/SQGW/08h2jGdbB5WTmaSgTh3WD8yLT+2q l5LUCYG/vo71i1fSpQWzS4HNv5qg7U6nNVdDXeKTXMTFOF0kx6VoI479tskzWZvl kk/6PvoippOT14KcZwYYQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeefgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudej udegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepih htshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Mar 2024 13:26:30 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , qemu-block@nongnu.org, Yanan Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Jesper Devantier , Minwoo Im , qemu-stable@nongnu.org, Klaus Jensen Subject: [PULL v2 1/6] hw/nvme: separate 'serial' property for VFs Date: Tue, 12 Mar 2024 18:26:24 +0100 Message-ID: <20240312172622.58652-9-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312172622.58652-8-its@irrelevant.dk> References: <20240312172622.58652-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1724; i=k.jensen@samsung.com; h=from:subject; bh=XddK9fgznLnaxCGQz8aWhKGnoFKoCfbUCAuoljS2hIM=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXwkD4Zj5olpC72zzipnjwY6NMt1OnU4pj+p RI2dDcXbu+bZokBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl8JA+AAoJEE3hrzFt Tw3pWqMH/AwJRSDnSKEMrUuOcvBzROTcNBhOLXH+Tkjue3pa3YtejzAVChAI8jyr9BfWYit4/Ug 2zCzLfOZPAWGcZrSdbdlSzx/7dziCAehdiH5Ay+14Hjm0CyKijq32XJnSDbMiiCR+GNS3Ga+Zss qA5iNnGlDbO3zUQLl6eEiXbnX+GQPxyOr6/ygVWFYuaDioaieT9wp7SK4lPBfq/05smnUo8zS5C ZUmSaVyGowyk8iAXyZjTyKXKH4nA7cQl6E95VVpqV/rZ+uWdOoPs9cywdaQTDUVwZZGLtgA1DQb fPn/STtEFe+XL23NkfEpgnjdnp/wip6ydiT7B64mFDv2CqyyDT1D96RE X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.156; envelope-from=its@irrelevant.dk; helo=wfhigh5-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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Minwoo Im Currently, when a VF is created, it uses the 'params' object of the PF as it is. In other words, the 'params.serial' string memory area is also shared. In this situation, if the VF is removed from the system, the PF's 'params.serial' object is released with object_finalize() followed by object_property_del_all() which release the memory for 'serial' property. If that happens, the next VF created will inherit a serial from a corrupted memory area. If this happens, an error will occur when comparing subsys->serial and n->params.serial in the nvme_subsys_register_ctrl() function. Cc: qemu-stable@nongnu.org Fixes: 44c2c09488db ("hw/nvme: Add support for SR-IOV") Signed-off-by: Minwoo Im Reviewed-by: Klaus Jensen Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 76fe0397045b..94ef63945725 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8309,9 +8309,15 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) if (pci_is_vf(pci_dev)) { /* * VFs derive settings from the parent. PF's lifespan exceeds - * that of VF's, so it's safe to share params.serial. + * that of VF's. */ memcpy(&n->params, &pn->params, sizeof(NvmeParams)); + + /* + * Set PF's serial value to a new string memory to prevent 'serial' + * property object release of PF when a VF is removed from the system. + */ + n->params.serial = g_strdup(pn->params.serial); n->subsys = pn->subsys; } From patchwork Tue Mar 12 17:26:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1911300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=ZQqN30J2; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=eZuv9pzi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvLGX2M2Gz1yWt for ; Wed, 13 Mar 2024 04:28:52 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5tt-00028n-PK; Tue, 12 Mar 2024 13:26:53 -0400 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 1rk5tk-00024n-LH; Tue, 12 Mar 2024 13:26:45 -0400 Received: from wfout4-smtp.messagingengine.com ([64.147.123.147]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk5tg-0005OJ-RS; Tue, 12 Mar 2024 13:26:44 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id DD9081C000ED; Tue, 12 Mar 2024 13:26:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 12 Mar 2024 13:26:39 -0400 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=fm3; t=1710264397; x= 1710350797; bh=13jK2IFXNV4aTtLcfKWBEUfG4qVN5gepwxltR43I56A=; b=Z QqN30J2F30OBspg40v8ru6qKpoWsIqI0brGv/XtTcyZYN4rueZJc/5EUGnDniQod pbYUvGK+kUyv9kOzlQNhYrm6c8XzP/SPGtOgAtxgWz7RQzlaYbnjMhYEcPgXc9wb MpK4lNEVCE2krBydFZhtT/SwtwOtneDvsvuMrxwPaCYuWa2AernTxFJBlgil404g SfyMoOVdQZsmpzgT1Ms+wuEv1Aq4b5ySmck6XyHSDfBcggEjshq1THVMFbZn3M57 sCU4T46f4stEYCQifCKuOzfo3nNtNHQ6Iacmo0RHHHazX1YwXYMqv5o7PbMuL3BK CTBPiFWY0g8nxmhx8g2Jg== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710264397; x= 1710350797; bh=13jK2IFXNV4aTtLcfKWBEUfG4qVN5gepwxltR43I56A=; b=e Zuv9pziKW2fe0yT0WuMjyVAzNchkPHqAGDUXnlb7eBgoUwaLw9PGM7HYT/fofGLw A9Rr6Z4HDAeHi6c8h8wT/or+BeLMo1JwqS7PnVjuT+WRulQFhn8Qq9bWqm5p7nR0 5HJrVFWGQTbsZyl/P4i8jTIo9/lI0ji9iQaxkzMXuht6AvCmf7wSGY5w6DMUERDY fLdNs9KN6MQbRju/S6CJ4irf0FcNMAVEIgTnCR6D+DFBL4edRv8te6bZZg+T5uDg EwxxNV1VGn1KlzKv911JSKllK68RSPmRqZ6GkeiTBeR0VIsC9NpOjBQ8/ZUd9zht QUxNdVkOEkWYRcJXTJ1YQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeefgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudej udegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepih htshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Mar 2024 13:26:35 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , qemu-block@nongnu.org, Yanan Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Jesper Devantier , Klaus Jensen , qemu-stable@nongnu.org, Minwoo Im Subject: [PULL v2 2/6] hw/nvme: fix invalid check on mcl Date: Tue, 12 Mar 2024 18:26:25 +0100 Message-ID: <20240312172622.58652-10-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312172622.58652-8-its@irrelevant.dk> References: <20240312172622.58652-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1006; i=k.jensen@samsung.com; h=from:subject; bh=29IW2qUZendh/4uF6O1NNuOeOuNodGl0+hczTMx8y10=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXwkD63MM2YL4haIMM0TcnKl5nI/enGn4KRx 98LSvMfPETdkYkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl8JA+AAoJEE3hrzFt Tw3pdSoIAKxnRQFqJt0TRRsWMK5MLkkGpPp4frlTjU4MsFRglprwM9qP3gEAlhVMvmdf8aRtAp2 G/IZvpl/YDY8zHOJvWoHr1qESKAef22YeAKMcllZyzQnNHuNsVcg7JIU9d4M/JIsBgzdPtABFMw 8U1QRSDQDnljoj6ExXD6XGuak9ug58E3l4y02ERll9zwjfCyJKHi+RtuS7f8D92KMR4+fIew6sG 55YjJXUqUF/yX5lt9+cKLCVmM5XEiyrQi2qm47PAfPwWUIvImE0H1mpzFkjAUqgSWGq8jbC/Syt JkDR59RdYt/rJ9cVAV+wTNrC7BOVjfT9SLMN+t+K6yQik+2IWRKAZqF5 X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.147; envelope-from=its@irrelevant.dk; helo=wfout4-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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Klaus Jensen The number of logical blocks within a source range is converted into a 1s based number at the time of parsing. However, when verifying the copy length we add one again, causing the check against MCL to fail in error. Cc: qemu-stable@nongnu.org Fixes: 381ab99d8587 ("hw/nvme: check maximum copy length (MCL) for COPY") Reviewed-by: Minwoo Im Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 94ef63945725..abc0387f2ca8 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -2855,7 +2855,7 @@ static inline uint16_t nvme_check_copy_mcl(NvmeNamespace *ns, uint32_t nlb; nvme_copy_source_range_parse(iocb->ranges, idx, iocb->format, NULL, &nlb, NULL, NULL, NULL); - copy_len += nlb + 1; + copy_len += nlb; } if (copy_len > ns->id_ns.mcl) { From patchwork Tue Mar 12 17:26:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1911301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=pfpjysZK; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=kSqCt5f7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvLGf44rRz1yWt for ; Wed, 13 Mar 2024 04:28:58 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5tt-00028A-6E; Tue, 12 Mar 2024 13:26:53 -0400 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 1rk5tm-000256-7R; Tue, 12 Mar 2024 13:26:46 -0400 Received: from wfhigh5-smtp.messagingengine.com ([64.147.123.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk5tk-0005Ob-MJ; Tue, 12 Mar 2024 13:26:45 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id ED2D818000A1; Tue, 12 Mar 2024 13:26:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 12 Mar 2024 13:26:42 -0400 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=fm3; t=1710264401; x= 1710350801; bh=/PYIyLQQniuFKFxiWnarB/Z18O8/5Ip6/+Dmm2IYPGs=; b=p fpjysZKPgsao9icOdLEw3BTbrbSIzCMj3ZaH/FjAYofnudvP1mglKdOp77MwLFKp LzRHn6vzPi+TDKk/c8HMk0OBDeABOz7S+iB6tsypEfeiOHpnLRMWUEDeBKZjPP3G j6xBEqK9W0PdAgpg1jTl3xxzL6ijp//i1UrvBlBZtrVmwKlovLOf+uprsGXE8LrH ImoQD19oFwAbNPNtU1gg/bQeRw6DnbRRM/+l0Rl4WZ7K9LLwS8P8cLSpm7WMzZ3g h7IiGreg9ErjcNga2MeMLsKTNNiVnMvIm3s8AmzKvONPNu98pucZoVMv1XDb/h1y q+n2yDKxNJYMuyo+zxcFA== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710264401; x= 1710350801; bh=/PYIyLQQniuFKFxiWnarB/Z18O8/5Ip6/+Dmm2IYPGs=; b=k SqCt5f7Db4qWucKE38mVO7gjGIS9ifumvCMsFgLtcpN9cl8xoB4FvwRvUy3PtJFu LsfKtevN1WnmIeXIu/kNKYqJFmcqskzyjcYa25zZ+OGI7Zwx+Be9ILPazamIkq1V 6ACWgQ6yd6LKObAvwTvA8AZ5cSBQkycf8rEuo8vSJvJm5DA0wG+UVW/DVR/zFRFM rcPGWSr328RQM9wr3M+HmnHrpMSCmdHTJ3QzGz+nQF2w/IYQKeK5vBMM99/zsbHS ozj2WqbP0hR0fhrTHm/K8+/4aj4v0q+3jRaiw7vGyj26Crrbz9z3aT6GXSaZNLVD mTaB+Cb8GixFC1ydTkkpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeefgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudej udegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepih htshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Mar 2024 13:26:39 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , qemu-block@nongnu.org, Yanan Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Jesper Devantier , Klaus Jensen Subject: [PULL v2 3/6] MAINTAINERS: add Jesper as reviewer on hw/nvme Date: Tue, 12 Mar 2024 18:26:26 +0100 Message-ID: <20240312172622.58652-11-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312172622.58652-8-its@irrelevant.dk> References: <20240312172622.58652-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=709; i=k.jensen@samsung.com; h=from:subject; bh=BWg6jMLKfC3h7/J+jZb66LMNRqpEhFJl5OKFCAevhf4=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXwkD8rMg67lMLGRmNwOp3cP9oS8HjHTmfB2 1A74ypi8pLjXIkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl8JA/AAoJEE3hrzFt Tw3pyq4IAKhF4mQTXHuZ1oO1dihIEY+ubP+58tje6Jfa8ktrWCzRT1nVAUHo9xOKEoxMe/uj+g3 59KJcVzDIFow8eMZAhB0oqxmX2jSij1ZuIL2zJwCzWkIRJ1osxbdpdCoSFKk5lyp2Swm92gq8gP iUMEpm0cWk9GEY4CsvWrsJFeD161RqI4XJkUlSXUNyDyXKc34UYRnrtjI/sAP15W69gUBeh4yvi CbXMYcBhNNZy8J8HtbpOEozjIw6zL88hUI8iREcpuqdKs7EZU0SXTHDyx0wH0kD2d9JsoQBeWYq ziT12nc/GJRJDfgOgJj04ggY+JBvE7PL4lectzW73kTs4ogMJ4NCWaTP X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.156; envelope-from=its@irrelevant.dk; helo=wfhigh5-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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Klaus Jensen My colleague, Jesper, will be assiting with hw/nvme related reviews. Add him with R: so he gets automatically bugged going forward. Cc: Jesper Devantier Acked-by: Jesper Devantier Signed-off-by: Klaus Jensen --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 12f5e47a11f4..7f96ce857486 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2407,6 +2407,7 @@ F: docs/system/devices/virtio-snd.rst nvme M: Keith Busch M: Klaus Jensen +R: Jesper Devantier L: qemu-block@nongnu.org S: Supported F: hw/nvme/* From patchwork Tue Mar 12 17:26:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1911299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=Lp1BqOSi; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=TSryep9q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvLGS3l95z1yWt for ; Wed, 13 Mar 2024 04:28:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5tv-0002Ab-0r; Tue, 12 Mar 2024 13:26:55 -0400 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 1rk5tr-000271-A4; Tue, 12 Mar 2024 13:26:51 -0400 Received: from wfout4-smtp.messagingengine.com ([64.147.123.147]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk5tp-0005Pb-4E; Tue, 12 Mar 2024 13:26:51 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 29A2F1C000ED; Tue, 12 Mar 2024 13:26:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 12 Mar 2024 13:26:47 -0400 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=fm3; t=1710264405; x= 1710350805; bh=CL070b4BGR4o23FsAxR9eeclFDLoEOJMatO1Gas4ulo=; b=L p1BqOSizknAziegUa+5tjhfAnwHwfvTcGnGrrTUpm0V7XFr2lWAY+vZAdTfE7uy6 k4OgdbAMwPsdOFjNpiw89//1+QUETtifHVE6Q1c9JWTumcBTF8en8fmrZCtSAWaB W2cEwtpyQNuhy9r4zRBpd8Sc5J7kTDR17Vgq1YL7fTtdslLGsD0rtLwvrBCouvL0 jx6CV6+2FvQNj8lvl3u64mBt2xA1KG+EjptHQECQK42n9oVa+oWt61/92U5PxuGT bnhAqw5xZCC7kKC66s0cI9WIJJQqEKep59t02YOkLLYyRTYz7O7ELsXb5udcHkyz Yz5Gw9HidqwzeLUs/Jklg== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710264405; x= 1710350805; bh=CL070b4BGR4o23FsAxR9eeclFDLoEOJMatO1Gas4ulo=; b=T Sryep9qtWI13PJQXgIMMdk7xzFUUOBHtvg2MEM6PItGpuVuClRXccd5YUMRCFV7x ycA8W4ntpDCU+BtLD7PdnNiNntp0cOCnfAlcmlQAaK++014xuK0xug3J0STF69hK 58+kidJu6XTEce16PdPONCDB3zPxagdyLvMI7xxKQOS4aO/buIxh+oNSgWEkw58j QWFae9aXN+l3wQihZY5AbaqYHGR0tbXVxXDtAWI66hM2ewLMr23gMdLGoPbH+ixS CPzVQCY6zipGdsP4nrdK/lK/j1yzYUw5V4QCcs05oJC0brgLLWTQFPB0bQF1J8wx AkApJO2WlxBQI8zvl0xHA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeefgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepteeffeffieelheeuvedtieejfeduleejheeigfegtdefhedtuedvgfffgeej jeeknecuffhomhgrihhnpehnghhuihgurdgurghtrgenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Mar 2024 13:26:43 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , qemu-block@nongnu.org, Yanan Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Jesper Devantier , Roque Arcudia Hernandez , Nabih Estefan , Klaus Jensen Subject: [PULL v2 4/6] hw/nvme: Add NVMe NGUID property Date: Tue, 12 Mar 2024 18:26:27 +0100 Message-ID: <20240312172622.58652-12-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312172622.58652-8-its@irrelevant.dk> References: <20240312172622.58652-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=11228; i=k.jensen@samsung.com; h=from:subject; bh=if9pvYLcwRx1YNXtDGaMFbOULNcR5Y8rsNcfNn8aV94=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXwkD8P5IoqhCHIv52aJdfZsMKfcA7xShrcc Q3tAN/V597n5okBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl8JA/AAoJEE3hrzFt Tw3peXgH+gITvjbZVMN8rO4ifPGoPKDz2oL2OGYSYweb0EXqeGvDdHF2ltcf09WYTbNUsvT2RYo NEXI3MgV5wP0c7fEg8ZyA6gFZsduvcne7kZ447Sn3E8p/Fc00mDWbtMIPguXjgH3QS9Qc7ILko/ IACxuUYwxW1132g1TZ7VN4ixYgGo+WKMvVJfv6DeU/hz9iOJdVcdlUmtA8+7EFUsdiEGQ49KrVJ YXOJn6yeBYW3mdtcNi2N8RFnrJqIb3t/G2uLQ65sDIs/ic2N+SQNd47R4aT2fSteAB2m4vj+l7p a0DPeuFkPBfPHSAZ6lFAN4iUkZ/o9VAk3416EmV0Wm45Rjk5oRyhCq50 X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.147; envelope-from=its@irrelevant.dk; helo=wfout4-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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Roque Arcudia Hernandez This patch adds a way to specify an NGUID for a given NVMe Namespace using a string of hexadecimal digits with an optional '-' separator to group bytes. For instance: -device nvme-ns,nguid="e9accd3b83904e13167cf0593437f57d" If provided, the NGUID will be part of the Namespace Identification Descriptor list and the Identify Namespace data. Signed-off-by: Roque Arcudia Hernandez Signed-off-by: Nabih Estefan Reviewed-by: Klaus Jensen Signed-off-by: Klaus Jensen --- docs/system/devices/nvme.rst | 7 ++ hw/nvme/ctrl.c | 12 +++ hw/nvme/meson.build | 2 +- hw/nvme/nguid.c | 187 +++++++++++++++++++++++++++++++++++ hw/nvme/ns.c | 2 + hw/nvme/nvme.h | 26 +++-- 6 files changed, 229 insertions(+), 7 deletions(-) create mode 100644 hw/nvme/nguid.c diff --git a/docs/system/devices/nvme.rst b/docs/system/devices/nvme.rst index 4ea957baed10..d2b1ca96455f 100644 --- a/docs/system/devices/nvme.rst +++ b/docs/system/devices/nvme.rst @@ -81,6 +81,13 @@ There are a number of parameters available: Set the UUID of the namespace. This will be reported as a "Namespace UUID" descriptor in the Namespace Identification Descriptor List. +``nguid`` + Set the NGUID of the namespace. This will be reported as a "Namespace Globally + Unique Identifier" descriptor in the Namespace Identification Descriptor List. + It is specified as a string of hexadecimal digits containing exactly 16 bytes + or "auto" for a random value. An optional '-' separator could be used to group + bytes. If not specified the NGUID will remain all zeros. + ``eui64`` Set the EUI-64 of the namespace. This will be reported as a "IEEE Extended Unique Identifier" descriptor in the Namespace Identification Descriptor List. diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index abc0387f2ca8..6c5a2b875da8 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -5640,6 +5640,10 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req) NvmeIdNsDescr hdr; uint8_t v[NVME_NIDL_UUID]; } QEMU_PACKED uuid = {}; + struct { + NvmeIdNsDescr hdr; + uint8_t v[NVME_NIDL_NGUID]; + } QEMU_PACKED nguid = {}; struct { NvmeIdNsDescr hdr; uint64_t v; @@ -5668,6 +5672,14 @@ static uint16_t nvme_identify_ns_descr_list(NvmeCtrl *n, NvmeRequest *req) pos += sizeof(uuid); } + if (!nvme_nguid_is_null(&ns->params.nguid)) { + nguid.hdr.nidt = NVME_NIDT_NGUID; + nguid.hdr.nidl = NVME_NIDL_NGUID; + memcpy(nguid.v, ns->params.nguid.data, NVME_NIDL_NGUID); + memcpy(pos, &nguid, sizeof(nguid)); + pos += sizeof(nguid); + } + if (ns->params.eui64) { eui64.hdr.nidt = NVME_NIDT_EUI64; eui64.hdr.nidl = NVME_NIDL_EUI64; diff --git a/hw/nvme/meson.build b/hw/nvme/meson.build index 1a6a2ca2f307..7d5caa53c280 100644 --- a/hw/nvme/meson.build +++ b/hw/nvme/meson.build @@ -1 +1 @@ -system_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', 'ns.c', 'subsys.c')) +system_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', 'ns.c', 'subsys.c', 'nguid.c')) \ No newline at end of file diff --git a/hw/nvme/nguid.c b/hw/nvme/nguid.c new file mode 100644 index 000000000000..829832bd9f41 --- /dev/null +++ b/hw/nvme/nguid.c @@ -0,0 +1,187 @@ +/* + * QEMU NVMe NGUID functions + * + * Copyright 2024 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" +#include "qapi/visitor.h" +#include "qemu/ctype.h" +#include "nvme.h" + +#define NGUID_SEPARATOR '-' + +#define NGUID_VALUE_AUTO "auto" + +#define NGUID_FMT \ + "%02hhx%02hhx%02hhx%02hhx" \ + "%02hhx%02hhx%02hhx%02hhx" \ + "%02hhx%02hhx%02hhx%02hhx" \ + "%02hhx%02hhx%02hhx%02hhx" + +#define NGUID_STR_LEN (2 * NGUID_LEN + 1) + +bool nvme_nguid_is_null(const NvmeNGUID *nguid) +{ + static NvmeNGUID null_nguid; + return memcmp(nguid, &null_nguid, sizeof(NvmeNGUID)) == 0; +} + +static void nvme_nguid_generate(NvmeNGUID *out) +{ + int i; + uint32_t x; + + QEMU_BUILD_BUG_ON((NGUID_LEN % sizeof(x)) != 0); + + for (i = 0; i < NGUID_LEN; i += sizeof(x)) { + x = g_random_int(); + memcpy(&out->data[i], &x, sizeof(x)); + } +} + +/* + * The Linux Kernel typically prints the NGUID of an NVMe namespace using the + * same format as the UUID. For instance: + * + * $ cat /sys/class/block/nvme0n1/nguid + * e9accd3b-8390-4e13-167c-f0593437f57d + * + * When there is no UUID but there is NGUID the Kernel will print the NGUID as + * wwid and it won't use the UUID format: + * + * $ cat /sys/class/block/nvme0n1/wwid + * eui.e9accd3b83904e13167cf0593437f57d + * + * The NGUID has different fields compared to the UUID, so the grouping used in + * the UUID format has no relation with the 3 fields of the NGUID. + * + * This implementation won't expect a strict format as the UUID one and instead + * it will admit any string of hexadecimal digits. Byte groups could be created + * using the '-' separator. The number of bytes needs to be exactly 16 and the + * separator '-' has to be exactly in a byte boundary. The following are + * examples of accepted formats for the NGUID string: + * + * nguid="e9accd3b-8390-4e13-167c-f0593437f57d" + * nguid="e9accd3b83904e13167cf0593437f57d" + * nguid="FEDCBA9876543210-ABCDEF-0123456789" + */ +static bool nvme_nguid_is_valid(const char *str) +{ + int i; + int digit_count = 0; + + for (i = 0; i < strlen(str); i++) { + const char c = str[i]; + if (qemu_isxdigit(c)) { + digit_count++; + continue; + } + if (c == NGUID_SEPARATOR) { + /* + * We need to make sure the separator is in a byte boundary, the + * string does not start with the separator and they are not back to + * back "--". + */ + if ((i > 0) && (str[i - 1] != NGUID_SEPARATOR) && + (digit_count % 2) == 0) { + continue; + } + } + return false; + } + /* + * The string should have the correct byte length and not finish with the + * separator + */ + return (digit_count == (2 * NGUID_LEN)) && (str[i - 1] != NGUID_SEPARATOR); +} + +static int nvme_nguid_parse(const char *str, NvmeNGUID *nguid) +{ + uint8_t *id = &nguid->data[0]; + int ret = 0; + int i; + const char *ptr = str; + + if (!nvme_nguid_is_valid(str)) { + return -1; + } + + for (i = 0; i < NGUID_LEN; i++) { + ret = sscanf(ptr, "%02hhx", &id[i]); + if (ret != 1) { + return -1; + } + ptr += 2; + if (*ptr == NGUID_SEPARATOR) { + ptr++; + } + } + + return 0; +} + +/* + * When converted back to string this implementation will use a raw hex number + * with no separators, for instance: + * + * "e9accd3b83904e13167cf0593437f57d" + */ +static void nvme_nguid_stringify(const NvmeNGUID *nguid, char *out) +{ + const uint8_t *id = &nguid->data[0]; + snprintf(out, NGUID_STR_LEN, NGUID_FMT, + id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], + id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]); +} + +static void get_nguid(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) +{ + Property *prop = opaque; + NvmeNGUID *nguid = object_field_prop_ptr(obj, prop); + char buffer[NGUID_STR_LEN]; + char *p = buffer; + + nvme_nguid_stringify(nguid, buffer); + + visit_type_str(v, name, &p, errp); +} + +static void set_nguid(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) +{ + Property *prop = opaque; + NvmeNGUID *nguid = object_field_prop_ptr(obj, prop); + char *str; + + if (!visit_type_str(v, name, &str, errp)) { + return; + } + + if (!strcmp(str, NGUID_VALUE_AUTO)) { + nvme_nguid_generate(nguid); + } else if (nvme_nguid_parse(str, nguid) < 0) { + error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str); + } + g_free(str); +} + +const PropertyInfo qdev_prop_nguid = { + .name = "str", + .description = + "NGUID or \"" NGUID_VALUE_AUTO "\" for random value", + .get = get_nguid, + .set = set_nguid, +}; diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 0eabcf5cf500..ea8db175dbd1 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -89,6 +89,7 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) id_ns->mcl = cpu_to_le32(ns->params.mcl); id_ns->msrc = ns->params.msrc; id_ns->eui64 = cpu_to_be64(ns->params.eui64); + memcpy(&id_ns->nguid, &ns->params.nguid.data, sizeof(id_ns->nguid)); ds = 31 - clz32(ns->blkconf.logical_block_size); ms = ns->params.ms; @@ -797,6 +798,7 @@ static Property nvme_ns_props[] = { DEFINE_PROP_BOOL("shared", NvmeNamespace, params.shared, true), DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0), DEFINE_PROP_UUID_NODEFAULT("uuid", NvmeNamespace, params.uuid), + DEFINE_PROP_NGUID_NODEFAULT("nguid", NvmeNamespace, params.nguid), DEFINE_PROP_UINT64("eui64", NvmeNamespace, params.eui64, 0), DEFINE_PROP_UINT16("ms", NvmeNamespace, params.ms, 0), DEFINE_PROP_UINT8("mset", NvmeNamespace, params.mset, 0), diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 5f2ae7b28b9c..392c02942682 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -171,13 +171,27 @@ static const uint8_t nvme_fdp_evf_shifts[FDP_EVT_MAX] = { [FDP_EVT_RUH_IMPLICIT_RU_CHANGE] = 33, }; +#define NGUID_LEN 16 + +typedef struct { + uint8_t data[NGUID_LEN]; +} NvmeNGUID; + +bool nvme_nguid_is_null(const NvmeNGUID *nguid); + +extern const PropertyInfo qdev_prop_nguid; + +#define DEFINE_PROP_NGUID_NODEFAULT(_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_nguid, NvmeNGUID) + typedef struct NvmeNamespaceParams { - bool detached; - bool shared; - uint32_t nsid; - QemuUUID uuid; - uint64_t eui64; - bool eui64_default; + bool detached; + bool shared; + uint32_t nsid; + QemuUUID uuid; + NvmeNGUID nguid; + uint64_t eui64; + bool eui64_default; uint16_t ms; uint8_t mset; From patchwork Tue Mar 12 17:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1911298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=S7N1C5kd; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=dKsVpAIB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvLGK0kPGz1yWt for ; Wed, 13 Mar 2024 04:28:41 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5ty-0002D2-RP; Tue, 12 Mar 2024 13:26:58 -0400 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 1rk5tx-0002Be-2v; Tue, 12 Mar 2024 13:26:57 -0400 Received: from wfhigh5-smtp.messagingengine.com ([64.147.123.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk5tv-0005RA-HE; Tue, 12 Mar 2024 13:26:56 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 9504D18000A1; Tue, 12 Mar 2024 13:26:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 12 Mar 2024 13:26:51 -0400 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=fm3; t=1710264410; x= 1710350810; bh=l9nOFDTS8LcbBpigNVpgDoOy5FiXsRfRuBjWwLRQY0I=; b=S 7N1C5kdalO4O0XoT+CxkSWzlmUOMgFIPOstYSwUnVhsYsDKw5ssA/Gdp88iXm8Fw lB2y9R9ZfmWQYS1mrq+WjexOMTlgUcH/9E/4/0+TdySpUNDRluT1q7RfQMtMhjEM +0aIU10mD36wvxjNQ9V9zgdq6Wc9IWP89DaB9i89Cz7cEPfOaOnLXRZgqhOU6bKH mzl4FPdtLTcdXi6yaSXAIiFGS9eZcJ2A/F0nbJ8va5/i24FZCdLtaovx77BeSVHQ +PHR/d6dAtEZVv57+Ji9k9Q1bzTaD9V8P7yjZAEQGZcUk09dv+FBFMIOGLAwMpUh QXOupVz2MqJu7FJl3N2zA== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710264410; x= 1710350810; bh=l9nOFDTS8LcbBpigNVpgDoOy5FiXsRfRuBjWwLRQY0I=; b=d KsVpAIBvxIw0IKfi1CMPoR157JcIdE0oGv/oWWnPboOj56AkABI1s2wJSGECqkwX T4tAhyP4+rZGronTSw+d5kdcVFiMp76qrXgHC5i+MyeZ1DrXbHVxlrj5y7Yo3nhe 5vf4tiERxQMwTle7Y05KBvdRLZXbuGRJTHvpsWlN90bti5iWp4tdBzIlP80TnYjf h5DWdGPve8bbaqe7ns6/CF1gW1ePKvA+LETw5hpAHPwtPuns6z6Owl2wJTewrKrX WYvFcjyVjIAldpRD3pOK9lKeazioQTEhz5Io2DGTodinp6aXlADWsLiVDV4KzF14 TEiomIgHY9sQykOnX5bvQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeefgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudej udegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepih htshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Mar 2024 13:26:47 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , qemu-block@nongnu.org, Yanan Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Jesper Devantier , Klaus Jensen , qemu-stable@nongnu.org Subject: [PULL v2 5/6] hw/nvme: generalize the mbar size helper Date: Tue, 12 Mar 2024 18:26:28 +0100 Message-ID: <20240312172622.58652-13-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312172622.58652-8-its@irrelevant.dk> References: <20240312172622.58652-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3393; i=k.jensen@samsung.com; h=from:subject; bh=0TYYe10yD0zFBG8lqqj25rVmuAAL5nlGUG9iJVrtEgQ=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXwkD/fsWU05nSaixiusoIMgpY/o3B3kgsE8 KK9R52un8IQXIkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl8JA/AAoJEE3hrzFt Tw3pPGcIALpyZbVg0KpU/83tO3MxBKN8mKUjCS+td9eODhAE5Gdj/4FdC5g1V9R3kCK22vsekQ1 AnbxTy1Dm7XOypCcCl9UmeF6+3Ou3dm9TkJlIqK+0btulzKWYhzZCzPeR0PaxyFFYvRof2mTtxJ 9Un+JEctAXPHWQNulz9dwpYTMM2dxeyncLZHZDueqquti5/4eO9CfrFMebQWZJh7NkkaN4rYobw Un+X6olrHbq60d4moBtcEALrJuWGQFKbgkeOW1ZvbX516n6bLM5wB7iqMdq7y+LAum7Bym6XZwF wqLDWBwZlYv+PaNbkJcLC4COH9zVfL7rQqdYkTRIfQf485ppjJsPIq57 X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.156; envelope-from=its@irrelevant.dk; helo=wfhigh5-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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Klaus Jensen Generalize the mbar size helper such that it can handle cases where the MSI-X table and PBA are expected to be in an exclusive bar. Cc: qemu-stable@nongnu.org Reviewed-by: Jesper Wendel Devantier Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 6c5a2b875da8..efcfd7171066 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8015,13 +8015,18 @@ static void nvme_init_pmr(NvmeCtrl *n, PCIDevice *pci_dev) memory_region_set_enabled(&n->pmr.dev->mr, false); } -static uint64_t nvme_bar_size(unsigned total_queues, unsigned total_irqs, - unsigned *msix_table_offset, - unsigned *msix_pba_offset) +static uint64_t nvme_mbar_size(unsigned total_queues, unsigned total_irqs, + unsigned *msix_table_offset, + unsigned *msix_pba_offset) { - uint64_t bar_size, msix_table_size, msix_pba_size; + uint64_t bar_size, msix_table_size; bar_size = sizeof(NvmeBar) + 2 * total_queues * NVME_DB_SIZE; + + if (total_irqs == 0) { + goto out; + } + bar_size = QEMU_ALIGN_UP(bar_size, 4 * KiB); if (msix_table_offset) { @@ -8036,11 +8041,10 @@ static uint64_t nvme_bar_size(unsigned total_queues, unsigned total_irqs, *msix_pba_offset = bar_size; } - msix_pba_size = QEMU_ALIGN_UP(total_irqs, 64) / 8; - bar_size += msix_pba_size; + bar_size += QEMU_ALIGN_UP(total_irqs, 64) / 8; - bar_size = pow2ceil(bar_size); - return bar_size; +out: + return pow2ceil(bar_size); } static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset) @@ -8048,7 +8052,7 @@ static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offset) uint16_t vf_dev_id = n->params.use_intel_id ? PCI_DEVICE_ID_INTEL_NVME : PCI_DEVICE_ID_REDHAT_NVME; NvmePriCtrlCap *cap = &n->pri_ctrl_cap; - uint64_t bar_size = nvme_bar_size(le16_to_cpu(cap->vqfrsm), + uint64_t bar_size = nvme_mbar_size(le16_to_cpu(cap->vqfrsm), le16_to_cpu(cap->vifrsm), NULL, NULL); @@ -8087,7 +8091,7 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) ERRP_GUARD(); uint8_t *pci_conf = pci_dev->config; uint64_t bar_size; - unsigned msix_table_offset, msix_pba_offset; + unsigned msix_table_offset = 0, msix_pba_offset = 0; int ret; pci_conf[PCI_INTERRUPT_PIN] = 1; @@ -8110,8 +8114,8 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) } /* add one to max_ioqpairs to account for the admin queue pair */ - bar_size = nvme_bar_size(n->params.max_ioqpairs + 1, n->params.msix_qsize, - &msix_table_offset, &msix_pba_offset); + bar_size = nvme_mbar_size(n->params.max_ioqpairs + 1, n->params.msix_qsize, + &msix_table_offset, &msix_pba_offset); memory_region_init(&n->bar0, OBJECT(n), "nvme-bar0", bar_size); memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", From patchwork Tue Mar 12 17:26:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1911297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm3 header.b=Im81mzWg; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=J4oObXhZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvLFm4Nj5z1yWt for ; Wed, 13 Mar 2024 04:28:12 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5u3-0002Ez-UH; Tue, 12 Mar 2024 13:27:04 -0400 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 1rk5tz-0002EX-Fz; Tue, 12 Mar 2024 13:26:59 -0400 Received: from wfout4-smtp.messagingengine.com ([64.147.123.147]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk5tx-0005Tf-I3; Tue, 12 Mar 2024 13:26:59 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 8EA2C1C000B1; Tue, 12 Mar 2024 13:26:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 12 Mar 2024 13:26:55 -0400 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=fm3; t=1710264414; x= 1710350814; bh=JKnGlfO0W7+PIXDSveDO2EZeh/9I2JiRCj4XnWkBROk=; b=I m81mzWgHNoCNANvyZmvyVHGvhf+Rcg1Yqp6xCwUVcsoPrNeU+5LVdwAvvKinuWn0 D2VECzmAx5mRPjbt7CzZtEfvAAsx+k4ZxJsjcXxRvVYPpExJADcjt8kxoF6xOFnS sugkg8QLk8Fw2SmFrbQUBwx6A4qZoI99GAsWZeA5w7Pq8ehCqMfIQvTDvmE3SSjW 3mEEwM6E6hmGfURJ2D5RX5OLv5ryzMtDxS1MyGvFkN03hr3CMVecL21Vle5z3pJ7 BXFaPy9ZA1vdvxB5/W+YI743APb02uSReIk7NnwDl64UGwl/0+66G/lFwX1NgXO4 crqms0+cwuFUdUxuZconw== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710264414; x= 1710350814; bh=JKnGlfO0W7+PIXDSveDO2EZeh/9I2JiRCj4XnWkBROk=; b=J 4oObXhZyML6rx3yhG9OVq2o0CXzRtGw/sK+mPulM8Xkh49QB/cJnqfsh6gos1KzY KuAD3rBXCy/7RQznwQz0w3/4HoceuZb8XNrqdWZMW7KH4IVuu6YauVckaqD36yLY EVAbEETYlHYxq8JOKrVg9CUZ8SI289IcbKYPoyoIVYQa0jfs3VwhKpk83Vc9urgN ojpiASQZ8IjJlk9TEBZ+piM3HtWW6OJWlpv7ZGL2o9slyKIsRi7xlmPrIzHRsShA bDhKPApPo16IH7/1LYEsLBUfI8a0WyrBtyNOQmrWl7J+qC/8yi2C/enOoX6tUOjb vvkwrRnTFsiOSF15eghFA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeefgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepfeehteeghefffeegkefghfegieejkeevfffhjeevfeekudeiieevheetledu jedunecuffhomhgrihhnpehgihhtlhgrsgdrtghomhenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Mar 2024 13:26:51 -0400 (EDT) From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: Eduardo Habkost , qemu-block@nongnu.org, Yanan Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Jesper Devantier , Klaus Jensen , qemu-stable@nongnu.org Subject: [PULL v2 6/6] hw/nvme: add machine compatibility parameter to enable msix exclusive bar Date: Tue, 12 Mar 2024 18:26:29 +0100 Message-ID: <20240312172622.58652-14-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312172622.58652-8-its@irrelevant.dk> References: <20240312172622.58652-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5504; i=k.jensen@samsung.com; h=from:subject; bh=9U433+XAOj8OOfgXrbOWFIMp7VQJFrBKGigW0tpjK0U=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXwkD9vpQchn3rz4O1XZWmjXX07vy2yxb+Q5 /OkSKbyWV6rDYkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl8JA/AAoJEE3hrzFt Tw3pPCIIAMTaM2k0OnU5sQ0uriYlBy2U8V/C6bLEA2/TChnho6Qt7+kH24vCJLuBqnVN3lBQw/K as8K6P9dcwxnZKJNbhPA4OujCBSzRWIlchvUrrNThlapDDv4Nbm+nSYWDYdvCQ9d8PcmMxy4dio iPzVuQ72ZHLhM6zY5XTrrIOWl3vXDE9Bhddr+C73WPrVNA4Pv4BRA0cO70kQzs9Ne1xnSHfGNzb USkaO+GRBFp0h8dbWaH9rPEHmNxYxq76FWguGQHSFNkgCX8HP3YViLOeCZoomP8DY2rf/ltZfFe ByZQ0HsbnY1Ao4XzCKOwD3B08pl5Gh+uKmeRr4If1D67Ir/vUEvZfKu2 X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=64.147.123.147; envelope-from=its@irrelevant.dk; helo=wfout4-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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Klaus Jensen Commit 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0") moved the MSI-X table and PBA to BAR 0 to make room for enabling CMR and PMR at the same time. As reported by Julien Grall in #2184, this breaks migration through system hibernation. Add a machine compatibility parameter and set it on machines pre 6.0 to enable the old behavior automatically, restoring the hibernation migration support. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2184 Fixes: 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0") Reported-by: Julien Grall julien@xen.org Tested-by: Julien Grall julien@xen.org Reviewed-by: Jesper Wendel Devantier Signed-off-by: Klaus Jensen --- hw/core/machine.c | 1 + hw/nvme/ctrl.c | 53 +++++++++++++++++++++++++++++++++-------------- hw/nvme/nvme.h | 1 + 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 0e9d646b61e1..37e5d4c8dfd5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -102,6 +102,7 @@ GlobalProperty hw_compat_5_2[] = { { "PIIX4_PM", "smm-compat", "on"}, { "virtio-blk-device", "report-discard-granularity", "off" }, { "virtio-net-pci-base", "vectors", "3"}, + { "nvme", "msix-exclusive-bar", "on"}, }; const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2); diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index efcfd7171066..036b15403a02 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -7810,6 +7810,11 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp) } if (n->pmr.dev) { + if (params->msix_exclusive_bar) { + error_setg(errp, "not enough BARs available to enable PMR"); + return false; + } + if (host_memory_backend_is_mapped(n->pmr.dev)) { error_setg(errp, "can't use already busy memdev: %s", object_get_canonical_path_component(OBJECT(n->pmr.dev))); @@ -8113,24 +8118,38 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) pcie_ari_init(pci_dev, 0x100); } - /* add one to max_ioqpairs to account for the admin queue pair */ - bar_size = nvme_mbar_size(n->params.max_ioqpairs + 1, n->params.msix_qsize, - &msix_table_offset, &msix_pba_offset); - - memory_region_init(&n->bar0, OBJECT(n), "nvme-bar0", bar_size); - memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", - msix_table_offset); - memory_region_add_subregion(&n->bar0, 0, &n->iomem); - - if (pci_is_vf(pci_dev)) { - pcie_sriov_vf_register_bar(pci_dev, 0, &n->bar0); - } else { + if (n->params.msix_exclusive_bar && !pci_is_vf(pci_dev)) { + bar_size = nvme_mbar_size(n->params.max_ioqpairs + 1, 0, NULL, NULL); + memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", + bar_size); pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | - PCI_BASE_ADDRESS_MEM_TYPE_64, &n->bar0); + PCI_BASE_ADDRESS_MEM_TYPE_64, &n->iomem); + ret = msix_init_exclusive_bar(pci_dev, n->params.msix_qsize, 4, errp); + } else { + assert(n->params.msix_qsize >= 1); + + /* add one to max_ioqpairs to account for the admin queue pair */ + bar_size = nvme_mbar_size(n->params.max_ioqpairs + 1, + n->params.msix_qsize, &msix_table_offset, + &msix_pba_offset); + + memory_region_init(&n->bar0, OBJECT(n), "nvme-bar0", bar_size); + memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", + msix_table_offset); + memory_region_add_subregion(&n->bar0, 0, &n->iomem); + + if (pci_is_vf(pci_dev)) { + pcie_sriov_vf_register_bar(pci_dev, 0, &n->bar0); + } else { + pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_TYPE_64, &n->bar0); + } + + ret = msix_init(pci_dev, n->params.msix_qsize, + &n->bar0, 0, msix_table_offset, + &n->bar0, 0, msix_pba_offset, 0, errp); } - ret = msix_init(pci_dev, n->params.msix_qsize, - &n->bar0, 0, msix_table_offset, - &n->bar0, 0, msix_pba_offset, 0, errp); + if (ret == -ENOTSUP) { /* report that msix is not supported, but do not error out */ warn_report_err(*errp); @@ -8434,6 +8453,8 @@ static Property nvme_props[] = { params.sriov_max_vi_per_vf, 0), DEFINE_PROP_UINT8("sriov_max_vq_per_vf", NvmeCtrl, params.sriov_max_vq_per_vf, 0), + DEFINE_PROP_BOOL("msix-exclusive-bar", NvmeCtrl, params.msix_exclusive_bar, + false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 392c02942682..bed8191bd5fd 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -536,6 +536,7 @@ typedef struct NvmeParams { uint16_t sriov_vi_flexible; uint8_t sriov_max_vq_per_vf; uint8_t sriov_max_vi_per_vf; + bool msix_exclusive_bar; } NvmeParams; typedef struct NvmeCtrl {