From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42A0A199E9A for ; Mon, 25 Nov 2024 12:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732536776; cv=none; b=iat6EvGyOW0EVw5R1UR3/iC0ODxGBJ+Hsv9lo3Movtakn8DAUKObJSeB8hqTYMVOPv0eT+XeZYQQByYJY4oARlxp9Jw+JZht21QO2FJcI5Qf0NDLbJQa2asPLDcJjS5SdytzEdUlsa76rNv9y+7U1Dfh2/2VxilJJau43ZxAwKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732536776; c=relaxed/simple; bh=MLSnpYpnDdb83dsO57HHirQDqJsYFWMfLYTyYFt8hlo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uTNnbPK2K8AXZPUkDQkvBg49b+INwzswv6czi8otqw0Uny+7FTO8AAvqZM72/ev0yINW6qnsysoAFb37G8I3ZVXkrM7ZLivhjFvoOEpUHirXxjbWZxixxBybt+SVXqPE0h2o6cgKbCihKatZFNgcYT0t3NHj1tYQYCXCsGGdlXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=hRKToxGi; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="hRKToxGi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1732536775; x=1764072775; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VuJnPUW5Fhdz8JcOpH25yROzJDJT0HPvWssL8Otml84=; b=hRKToxGiBsTQM4efStdJr5mVx8qVcuLGBu2KCsQkLtwYMcNeLhdraJBP GPELaI3hC6akychm0boge/G58LltiBZh9FMi7qEc5N4VxkUslOlM6m/J0 JHGqwaxqON1Tgs0of7QlSEWbROpjOj1fyqSbJRP1WSk4mg6YDQTgMgGOX 4=; X-IronPort-AV: E=Sophos;i="6.12,182,1728950400"; d="scan'208";a="147710617" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 12:12:52 +0000 Received: from EX19MTAUEA001.ant.amazon.com [10.0.29.78:27324] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.44.125:2525] with esmtp (Farcaster) id 7aaf9800-6c70-4714-ac16-584346abaf7c; Mon, 25 Nov 2024 12:12:52 +0000 (UTC) X-Farcaster-Flow-ID: 7aaf9800-6c70-4714-ac16-584346abaf7c Received: from EX19EXOUEB002.ant.amazon.com (10.252.135.74) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 25 Nov 2024 12:12:52 +0000 Received: from EX19MTAUEB002.ant.amazon.com (10.252.135.47) by EX19EXOUEB002.ant.amazon.com (10.252.135.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 25 Nov 2024 12:12:51 +0000 Received: from email-imr-corp-prod-iad-all-1b-85daddd1.us-east-1.amazon.com (10.124.125.2) by mail-relay.amazon.com (10.252.135.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Mon, 25 Nov 2024 12:12:51 +0000 Received: from dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com [10.253.65.58]) by email-imr-corp-prod-iad-all-1b-85daddd1.us-east-1.amazon.com (Postfix) with ESMTP id C4A5E403C2; Mon, 25 Nov 2024 12:12:51 +0000 (UTC) Received: by dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (Postfix, from userid 23002382) id 8631922462; Mon, 25 Nov 2024 12:12:51 +0000 (UTC) From: Hagar Hemdan To: CC: , Puranjay Mohan , "Christoph Hellwig" , Sagi Grimberg , Anuj Gupta , Keith Busch , Hagar Hemdan Subject: [PATCH 5.15] nvme: fix metadata handling in nvme-passthrough Date: Mon, 25 Nov 2024 12:10:08 +0000 Message-ID: <20241125121009.17855-3-hagarhem@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241125121009.17855-1-hagarhem@amazon.com> References: <20241125121009.17855-1-hagarhem@amazon.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain From: Puranjay Mohan [ Upstream commit 7c2fd76048e95dd267055b5f5e0a48e6e7c81fd9 ] On an NVMe namespace that does not support metadata, it is possible to send an IO command with metadata through io-passthru. This allows issues like [1] to trigger in the completion code path. nvme_map_user_request() doesn't check if the namespace supports metadata before sending it forward. It also allows admin commands with metadata to be processed as it ignores metadata when bdev == NULL and may report success. Reject an IO command with metadata when the NVMe namespace doesn't support it and reject an admin command if it has metadata. [1] https://lore.kernel.org/all/mb61pcylvnym8.fsf@amazon.com/ Suggested-by: Christoph Hellwig Signed-off-by: Puranjay Mohan Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg Reviewed-by: Anuj Gupta Signed-off-by: Keith Busch [ Move the changes from nvme_map_user_request() to nvme_submit_user_cmd() to make it work on 5.15 ] Signed-off-by: Hagar Hemdan --- drivers/nvme/host/ioctl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 7397fad4c96f..22ff0e617b8f 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -61,11 +61,16 @@ static int nvme_submit_user_cmd(struct request_queue *q, bool write = nvme_is_write(cmd); struct nvme_ns *ns = q->queuedata; struct block_device *bdev = ns ? ns->disk->part0 : NULL; + bool supports_metadata = bdev && blk_get_integrity(bdev->bd_disk); + bool has_metadata = meta_buffer && meta_len; struct request *req; struct bio *bio = NULL; void *meta = NULL; int ret; + if (has_metadata && !supports_metadata) + return -EINVAL; + req = nvme_alloc_request(q, cmd, 0); if (IS_ERR(req)) return PTR_ERR(req); @@ -82,7 +87,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, bio = req->bio; if (bdev) bio_set_dev(bio, bdev); - if (bdev && meta_buffer && meta_len) { + if (has_metadata) { meta = nvme_add_user_metadata(bio, meta_buffer, meta_len, meta_seed, write); if (IS_ERR(meta)) { -- 2.40.1