From patchwork Wed Aug 9 13:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 13348054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7C01C04A6A for ; Wed, 9 Aug 2023 13:41:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTjPH-0002lZ-O0; Wed, 09 Aug 2023 09:39:23 -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 1qTjPF-0002k0-IB; Wed, 09 Aug 2023 09:39:21 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTjPC-0002hL-Vh; Wed, 09 Aug 2023 09:39:21 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id CC8315C012C; Wed, 9 Aug 2023 09:39:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 09 Aug 2023 09:39:15 -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:sender:subject:subject:to:to; s=fm2; t=1691588355; x= 1691674755; bh=wCay5dbNnQDqO2GlNeVpeAedGu4LOH6JZR1cxTrIzyY=; b=P jXgM+BNUORCR7XZW1uoPtoA7CZv80QiotoAapW6yqyhZsSYW8nyZuCKN/gr1PzRK auPSyS8kqcM7xSzkAUqoZ6ArJc5MYmsv0eqPH6wsDd+waSeQddafsP4e6i3r/p5r d6eRj5QECAB2Nt/reqgUv/M02BpTHBYo6CTLCG0Jqo5icL0NP7yPH9w0xQhLNfZb AJOboLJeKK0PwhHDKBtBBZyyCiE8QwRtpoDljj1D4JuuT/KnTQKMTeZBYFDZs4iK ilzbvmIIx3oDZIpDBku6IclphHrbw8C/jn0sQl8lmYaBN/K0q7o6iF5wZAp5Ul/0 j3t4bNHZkFJPYBYLuPLcQ== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1691588355; x= 1691674755; bh=wCay5dbNnQDqO2GlNeVpeAedGu4LOH6JZR1cxTrIzyY=; b=N ZXIMeBzNXLurO1TD0+OMF6T87uDv72v6Q/GX7vUeoHhuO2e3kHopcz+2Y5kzYggn 0KMfq0hRc01N08BiNfMgie/AhD/dftCnve7A/UMATztcTzumoYnBTMBD+L/zNZsv iG27m+G01SoFvrEv5rOBl3YMDIo1Ku0mGBqHRPtZE1n2YGF8SMc/jCxO013X7GLf siANLLuu6AxC2CWBYa8dpfZbd0Q/GB1nnORNPvn13iE6BPvQVO+13SzCOgYwHxgo bMFubYxyu0TOJzzyfcMk75wUQdrvHGvKHb/Koh1AFlUDDNEB2TG0TcWmm0edyFdv agSkSww6u+wij9igXbkmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrleeggdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeefheetgeehffefgeekgffhgeeijeekveffhfejveefkeduieeiveehteeludej udenucffohhmrghinhepghhithhlrggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Aug 2023 09:39:14 -0400 (EDT) From: Klaus Jensen To: Richard Henderson , qemu-devel@nongnu.org Cc: Klaus Jensen , qemu-block@nongnu.org, Keith Busch , Klaus Jensen , qemu-stable@nongnu.org, Jesper Wendel Devantier Subject: [PULL 1/2] hw/nvme: fix null pointer access in directive receive Date: Wed, 9 Aug 2023 15:39:11 +0200 Message-ID: <20230809133909.45818-5-its@irrelevant.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230809133909.45818-4-its@irrelevant.dk> References: <20230809133909.45818-4-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1180; i=k.jensen@samsung.com; h=from:subject; bh=8zxP4G6hW0k+nMxUcpBk6P+QkGbwFl0Xn43SbCWW3Fw=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGTTlv6M3bujKrYRAAelElbz+RSpdsCkbpD/8 Htl+/pVtzWFmokBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJk05b+AAoJEE3hrzFt Tw3pIg4H/1B6mIfmHeDCDOrNVWd/+vyzbZaGWL/HyrAalRJDMJnjD2U4c2J2JwU5EWil0EiL/Pu sy8oZ/AQQw0qo+Vm2/GwG+1hYo0OIr091dZR36gZieouoL4QrfQsBHyTmE+SGzLPubJuEqU6oew Va76YjX/Ge+sj3OTRWxJ11ASaXPyGduPXfP4ClaXoN6wCzOZIRCXqZcg47EQM9AxJ1RNabFPmw9 f2wJR+Ucwf2JbPds1DgrrjcOXp5HKvSLJDlRFUe6UYH3Mg4LaP9dXWYLjVFxGPyaWsQXs3KBuvu Uqdntnf1pjWqG4U637sscHqbsMxPwSnMMbkTr9KBKvBkPBqb0yan5KtC X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=66.111.4.29; envelope-from=its@irrelevant.dk; helo=out5-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_H5=0.001, RCVD_IN_MSPIKE_WL=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Klaus Jensen nvme_directive_receive() does not check if an endurance group has been configured (set) prior to testing if flexible data placement is enabled or not. Fix this. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1815 Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation") Reviewed-by: Jesper Wendel Devantier 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 d217ae91b506..e5b5c7034d2b 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6900,7 +6900,7 @@ static uint16_t nvme_directive_receive(NvmeCtrl *n, NvmeRequest *req) case NVME_DIRECTIVE_IDENTIFY: switch (doper) { case NVME_DIRECTIVE_RETURN_PARAMS: - if (ns->endgrp->fdp.enabled) { + if (ns->endgrp && ns->endgrp->fdp.enabled) { id.supported |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT; id.enabled |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT; id.persistent |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT; From patchwork Wed Aug 9 13:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 13348055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5F36C0015E for ; Wed, 9 Aug 2023 13:41:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTjPH-0002lT-JD; Wed, 09 Aug 2023 09:39:23 -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 1qTjPF-0002je-Ai; Wed, 09 Aug 2023 09:39:21 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTjPD-0002hn-0h; Wed, 09 Aug 2023 09:39:21 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A35195C0160; Wed, 9 Aug 2023 09:39:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 09 Aug 2023 09:39:17 -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:sender:subject:subject:to:to; s=fm2; t=1691588357; x= 1691674757; bh=t5lxifavT4W3Y7H2EtCg2nTkexwbBa5nYqgEzRzCmHw=; b=W dOgD/JJwo6fu4NRWejFY0m5TzQ4J2MjA5T8IXWoxYRdUKgyLKDAQ+21qiQVL8Fv9 FWSbAtTQ8OlB44VIK/rZXkmAwoV+Jqreayb6r1iVAqczKTcRp+T51hzWA5TB09lk PBiioR5qcZdrkESkuu/e/NZBZFywMaF4wX93MpZUFjTvdbDhf+v8FlEihtbKz3eP 4ZXAnt8kJSB1/dVHeA/5aLWgeU6rrRkHWcH4NXD01B07VdIQqZB8JIKyAgA1nV5c VkwA+B7EmeN7iffYUKddgDcEu/objJteDxAH3r5Dr5SwlvRgosuoPINvwAW8OJFp mgk/2Q8sQSVVczT9KroWA== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1691588357; x= 1691674757; bh=t5lxifavT4W3Y7H2EtCg2nTkexwbBa5nYqgEzRzCmHw=; b=d N7nmS43R/Qbx+n7+Vt6Bxjr+JCKyYc3dq9k8ZJZpEKP1oPaTIkEietS7T6eAGxQq wLl7hAt3Se1/DBI30ywKvFldG4JBlDdHx699m0OmyYbG3VXME+wsEKLnQePwnM2V L4ByQxT1lbN65ogsAMk19mX0RVopg8DjcymMx9IWQVgFWFPFvuKwaUja6tfNTET2 ZEhLMc8uFmHUvcshSUN8E2P9265nbhFYJcbpEwvtiGhkhlBg8dOXckykwrkQs6I8 bk8xpiN/PFAcTuWvhH6ubIEKP3FnzWcEu0QLy+f+slHxy/mdzhjQ8Q+I1tJ3BnlP BOrrVtoYLdP0PTgZVCtaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrleeggdeiiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeejgfeilefgieevheekueevheehkeefveegiefgheefgfejjeehffefgedujedu geenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehith hssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Aug 2023 09:39:16 -0400 (EDT) From: Klaus Jensen To: Richard Henderson , qemu-devel@nongnu.org Cc: Klaus Jensen , qemu-block@nongnu.org, Keith Busch , Klaus Jensen , qemu-stable@nongnu.org, Jesper Wendel Devantier Subject: [PULL 2/2] hw/nvme: fix null pointer access in ruh update Date: Wed, 9 Aug 2023 15:39:12 +0200 Message-ID: <20230809133909.45818-6-its@irrelevant.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230809133909.45818-4-its@irrelevant.dk> References: <20230809133909.45818-4-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1214; i=k.jensen@samsung.com; h=from:subject; bh=0dn3iSE2dXbkED8tHmgi5PAt78m2jCsPM0x9+q4HGJk=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGTTlv4VZVewRYMf8XVHHIENJ3lH1CxEGCp2r Jv6ZNlAOYA3k4kBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJk05b+AAoJEE3hrzFt Tw3pyKEH/3/1o2vfVooxQqmVrCCAtdWJxWgfU1PoOGxZvPyWtkSteUmNHjdFER5q4IgRd7WA0R9 QOdUJuBf6Je0XcS6hOb7nu3Rf7pchjXGRkd2Sm0TFfKIgPL/Z+DNn/3ISqGSoZ5QVx5JJa9iSM+ 4bwQ1Nome2qsd9UmEsD6q6rVjqrIHgT2lZL3QQbUy3+1vCVdCum/BmI6mEOBqbb0XJQ1q+VQcOQ 3Wgvw9JJnqO5+u4V7ZTpOzoR4thp3heDnk9oaSENxABAD6CMJU697p+Fmq5FRjOPsrakeWXy/dS Qz8JQ9dMyxkL/QQHWIgMe0ibef8ncLGUWP59tJDOK7wMw3RkVgBpbqTC X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 Received-SPF: pass client-ip=66.111.4.29; envelope-from=its@irrelevant.dk; helo=out5-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_H5=0.001, RCVD_IN_MSPIKE_WL=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Klaus Jensen The Reclaim Unit Update operation in I/O Management Receive does not verify the presence of a configured endurance group prior to accessing it. Fix this. Cc: qemu-stable@nongnu.org Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation") Reviewed-by: Jesper Wendel Devantier 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 e5b5c7034d2b..539d27355313 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -4361,7 +4361,13 @@ static uint16_t nvme_io_mgmt_send_ruh_update(NvmeCtrl *n, NvmeRequest *req) uint32_t npid = (cdw10 >> 1) + 1; unsigned int i = 0; g_autofree uint16_t *pids = NULL; - uint32_t maxnpid = n->subsys->endgrp.fdp.nrg * n->subsys->endgrp.fdp.nruh; + uint32_t maxnpid; + + if (!ns->endgrp || !ns->endgrp->fdp.enabled) { + return NVME_FDP_DISABLED | NVME_DNR; + } + + maxnpid = n->subsys->endgrp.fdp.nrg * n->subsys->endgrp.fdp.nruh; if (unlikely(npid >= MIN(NVME_FDP_MAXPIDS, maxnpid))) { return NVME_INVALID_FIELD | NVME_DNR;