Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2290806pxb; Fri, 5 Feb 2021 14:02:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDdDNHJFxR/ej/AkwHhtZABTYKcliK8A+CL5Q+1ND62QejqSGy8MEJIRmmAhVRT0RTvVWq X-Received: by 2002:a05:6402:28e:: with SMTP id l14mr5845854edv.307.1612562563749; Fri, 05 Feb 2021 14:02:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612562563; cv=none; d=google.com; s=arc-20160816; b=LmfQaWxaqcmz0pNKJ6rMssZeMp6sKeThi2M4t6iY87DVoVRAVIkFPOQdcQQzaqjU5t niMO35e1dm3muit492Y/kAyrXFRRJXTd0Hqghx3zdHLyGBpc3kl72uTICe2JNygieTSx 7dWTS+6wOg8Qcba17J8DLzmZfc6uFiuj6d0IWXv1AieVIXSYAvN3xHckXo/aNH8XOPLX uANvRLg+HWgFXzwejRhF0QJhPMl7YDJboXKZAHjiZXNGdhmVo9GaNrs6Rt49GHgNHorJ jJdNgf/nH9FMS3MNvSfKNOfWxm4kpk9TcsSAypQVzDkAf2eMTjFjEFBCLtJhUhjYvjj2 JP3Q== 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=/HBcJw8Kurp5z3alF0KUVWpYi7jJrteqYinm/Klw4GE=; b=sQ7ZMGGj7B8A/pKrKZ2EjfwVQAXe2jt5QBSMWjXDQbCxVjiztremovel4pnunH6z79 T0GORBapI7FUbTxkZTmf+urQnfPMWUYtjdJa2qNNbsGj4hvKXyxCWTip17X/1JtSs6Zs RF0QhKVcR4zpIxWHpX+js4oW45GEH3KkTzOafffo/+yD1zoQu84FgYD1plF7MkhR5amB R8ECI65faHBdWqepdJsGwdTuROChl+HFZO8gy4M8UiwTmdKg7Di1rlppmWIaP6t1i6yQ e7ws/XyzA0gdQyxUJpOc1vhPDtj7BeR/zcnYywSmUEDhJdsKx3dtPgpbVslCAZ5ppjiI WdJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uOwdlFpp; 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 f21si6622377edc.230.2021.02.05.14.02.18; Fri, 05 Feb 2021 14:02:43 -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=uOwdlFpp; 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 S232767AbhBEV7J (ORCPT + 99 others); Fri, 5 Feb 2021 16:59:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:45252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233010AbhBEO7i (ORCPT ); Fri, 5 Feb 2021 09:59:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DF0EE65066; Fri, 5 Feb 2021 14:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534366; bh=fl2F30CRd+mW6gXgKQt3PGr4zq/8oNPPtd/TxfOKpDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOwdlFppXibH4sB8S+L+p8RXWkFfc3V5LdH5DZaHIIafqreWOk2of28UXPY2ce8yM /WowePbAbwljNCMxJxAvKbEqkZFozaKlKjvDBYhblE6W6O3NgSldhNbwKQz+va0noZ U1xUMc7ykkIDSuFQsxLEGYiEoyi5PCh47EWALyjU= 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.4 26/32] nvme: check the PRINFO bit before deciding the host buffer length Date: Fri, 5 Feb 2021 15:07:41 +0100 Message-Id: <20210205140653.453987181@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140652.348864025@linuxfoundation.org> References: <20210205140652.348864025@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 7a964271959d8..c2cabd77884bf 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1295,8 +1295,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->ext) { length += meta_len; -- 2.27.0