Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2308711pxb; Fri, 5 Feb 2021 14:36:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyI8Ev3tWx0S2dyLRrcrbREL2v/0hSLu3aOSiKmq5+PmjFHV+321F85XvBP09jzFq4AHTZ5 X-Received: by 2002:a17:906:cf86:: with SMTP id um6mr6334810ejb.426.1612564609369; Fri, 05 Feb 2021 14:36:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612564609; cv=none; d=google.com; s=arc-20160816; b=tH2SXmluk0YpLbc6HpekgGreik2h/xkeuGszJBlunkJ57JnOUBsp3+REnBBqW3/zEt HpNHugqOensvNvz6wjDSEf3V6TIfr8RA9TP8WLCisPxmI5metzjO/0MqbOTVVEjWqwAJ cF5+jClGNB2GgiZJp8Dk6DJDOjNHkXI+jEfMUIqVys7ylJ+ki8pIfNieZqq6jUUg/Wcr YPutjkauuRAEDfvkMIi9m13XAciE2ndfGOrRi2Ly7PcI7xFdA3hHZPaaCobWQJZg3zGa QjHuFGyPLvq4Wrpn2ihwECsQW5CwyKAdmlikwvQF5JZPyvtJr7DtmhAbQBfxuQg1mI+h sDEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TZkB9Lgatl/jCLB7aHxtjGZLfZQLOkyOer/aJySWZDQ=; b=NHGnRXuPu6EPr8fZwtHdsdJoopPQC+B/l6ocityCHhwiceXq2j6C1Zm4r3QXZrv2d1 s5w8sQERhQLLRLOHQmpyamNgFDfRsfNX2cTfcmQmPM40Tp87ZMv9GXM0Xo2hnNwAIY4f g9grGbwpsgiBxnTlMfl7NM5UTrVIJ+jfxcn9jiNc999DCOztn/0rEH2d/u+bvwUUsJ5p WkVvT7diK1kNphxvO4fwbo9poHRoZCSyAmc6+78ZWvbkK+wEUpdG+U4Oz5IhAqxoRmwO EwSYG4hbl6zcRwwDrxWl4p7RoaUxnnCxGG0wwy0w4qGPM8knDCjmdkYSCJVZ0n6AsL7U fo+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HmhII6f5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si6137656edt.282.2021.02.05.14.36.23; Fri, 05 Feb 2021 14:36:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HmhII6f5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231364AbhBEWem (ORCPT + 99 others); Fri, 5 Feb 2021 17:34:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:44672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbhBEOyd (ORCPT ); Fri, 5 Feb 2021 09:54:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C161D6500B; Fri, 5 Feb 2021 14:10:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534239; bh=gH0/SydLCp5UUqUHkOONSasTZq/pbxF7IpgE89cUa0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmhII6f5BAO5XhKV6xH90UShGMfT0VMl6ygYfiJpKTDxrDuY8mhoDUH99di8cikfy vSXKW1Q8iiU7aUZOb+PwHQFa04l0DgwCLKyC3DhvpZ8CcHN7OASZ9gZg99W2A/LAw8 /VKqOD3mLpdqYlwMTnlSymOW0ylr97sMaDWmI/18= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Revanth Rajashekar , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.10 39/57] nvme: check the PRINFO bit before deciding the host buffer length Date: Fri, 5 Feb 2021 15:07:05 +0100 Message-Id: <20210205140657.649424015@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140655.982616732@linuxfoundation.org> References: <20210205140655.982616732@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Revanth Rajashekar [ Upstream commit 4d6b1c95b974761c01cbad92321b82232b66d2a2 ] According to NVMe spec v1.4, section 8.3.1, the PRINFO bit and the metadata size play a vital role in deteriming the host buffer size. If PRIFNO bit is set and MS==8, the host doesn't add the metadata buffer, instead the controller adds it. Signed-off-by: Revanth Rajashekar Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 34cb59b2fcd67..4ec5f05dabe1d 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1489,8 +1489,21 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) } length = (io.nblocks + 1) << ns->lba_shift; - meta_len = (io.nblocks + 1) * ns->ms; - metadata = nvme_to_user_ptr(io.metadata); + + if ((io.control & NVME_RW_PRINFO_PRACT) && + ns->ms == sizeof(struct t10_pi_tuple)) { + /* + * Protection information is stripped/inserted by the + * controller. + */ + if (nvme_to_user_ptr(io.metadata)) + return -EINVAL; + meta_len = 0; + metadata = NULL; + } else { + meta_len = (io.nblocks + 1) * ns->ms; + metadata = nvme_to_user_ptr(io.metadata); + } if (ns->features & NVME_NS_EXT_LBAS) { length += meta_len; -- 2.27.0