Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2522099rwb; Mon, 3 Oct 2022 01:53:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Xmlot5vvErcASB1W1fAGBsAhOYaKf3NMeySDYLu/+SbxBbOGPMCZ6Mm6D7UKdvtc53YMz X-Received: by 2002:a05:6a00:1704:b0:55a:d85a:f226 with SMTP id h4-20020a056a00170400b0055ad85af226mr21332153pfc.19.1664787198011; Mon, 03 Oct 2022 01:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664787198; cv=none; d=google.com; s=arc-20160816; b=H2G2f+kzPbES8D6yhg8OKTG3AJ+Tz/vxqFyJQuvAsUnR7l+7KHf/s6f9lhmrY/Yk4B KPuWL3KiQ8ZmaBWwzFBsX2uFmwCREQNUXzyXceJ6t+ilMnhzBLen33vgLzO7Hz4xo5/x xLCzlkur9DeEVSE+T9Q/ypNyKtdlDKTyzeWQplGP8fwFwYsLOfE6EtllEZrrp2Xu1ppO xqEUxOrOCBkWHcmd51mZo4MOHkByPcQkK3ZRUSEP4pGDNtwCeMZYS0EuPU/n8/ISOQQt uDwHmYCAQ4ELjuMGN4SEY72m6vxG/+WNklHQd8duwrEwSiEBNZTS8J5niOtvPSUXF+7X riKg== 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=IdeiCobYf4OOMaCjwTJQZIWmz8/dmdnmRbJgjlD20cU=; b=Og2yWRmtAzoexGftQvsLz5mvirbvFH8nqIulEJ8HQIyipQiNt1YxeuFNJ0l9yBQBIX pLTsLYcpM9+hTOCQnKW1Jza2nIj0gSpi7h6ZT7V6mv3664Q1o6DcG+43l4TBPPYU8vBG TmApl4RkZz0FHpNI/UrqvN4G2I7WVEcdVXZ8AOUSjRT7QE9uvyclz4XvXdgaNhNRRF85 CJ1hBoWED+NnZmZCk7DN2Xo5Uc2tcWX3TxqK511VQah5CNYlKaGWp7UKP02Qb0mK0i2R yKnfH5r5cw1Cul+91PqSn7pDCb3aMOnlsy6MjKqBcKpvkAQdblTZUF+E1WrBHpRmO6G3 9UXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y9ooMqLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 123-20020a630881000000b004468ff8fc5bsi6717624pgi.299.2022.10.03.01.53.06; Mon, 03 Oct 2022 01:53:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y9ooMqLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229719AbiJCH4A (ORCPT + 99 others); Mon, 3 Oct 2022 03:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbiJCHzc (ORCPT ); Mon, 3 Oct 2022 03:55:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DCA52127D; Mon, 3 Oct 2022 00:32:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BE03B60FA2; Mon, 3 Oct 2022 07:25:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3A4BC433D6; Mon, 3 Oct 2022 07:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781925; bh=QTx2zcyJaFTx5dJid3Fi2UGBhUpjVPbtJms/BBu/RO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y9ooMqLd6ws3xIwURKiokmQGDq642TCVHjH1RXLXjH+zzhaFyH1fT6PEx4E9ywrkI xOiJH6+CcIkXzJbF+vO5MJVSSsAtU8QT2jM8JTmPKI1VhF5BHTsUJnbcFuWaHhmhnV pF53OSS63o9cmVaejmwKKnFx34iIeFprP0qzQ4GE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Kelley , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.19 23/25] nvme: Fix IOC_PR_CLEAR and IOC_PR_RELEASE ioctls for nvme devices Date: Mon, 3 Oct 2022 09:12:26 +0200 Message-Id: <20221003070716.094318426@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070715.406550966@linuxfoundation.org> References: <20221003070715.406550966@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Kelley [ Upstream commit c292a337d0e45a292c301e3cd51c35aa0ae91e95 ] The IOC_PR_CLEAR and IOC_PR_RELEASE ioctls are non-functional on NVMe devices because the nvme_pr_clear() and nvme_pr_release() functions set the IEKEY field incorrectly. The IEKEY field should be set only when the key is zero (i.e, not specified). The current code does it backwards. Furthermore, the NVMe spec describes the persistent reservation "clear" function as an option on the reservation release command. The current implementation of nvme_pr_clear() erroneously uses the reservation register command. Fix these errors. Note that NVMe version 1.3 and later specify that setting the IEKEY field will return an error of Invalid Field in Command. The fix will set IEKEY when the key is zero, which is appropriate as these ioctls consider a zero key to be "unspecified", and the intention of the spec change is to require a valid key. Tested on a version 1.4 PCI NVMe device in an Azure VM. Fixes: 1673f1f08c88 ("nvme: move block_device_operations and ns/ctrl freeing to common code") Fixes: 1d277a637a71 ("NVMe: Add persistent reservation ops") Signed-off-by: Michael Kelley Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 44ee6dc5e0ca..582c3b190418 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1722,14 +1722,14 @@ static int nvme_pr_preempt(struct block_device *bdev, u64 old, u64 new, static int nvme_pr_clear(struct block_device *bdev, u64 key) { - u32 cdw10 = 1 | (key ? 1 << 3 : 0); + u32 cdw10 = 1 | (key ? 0 : 1 << 3); - return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_register); + return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_release); } static int nvme_pr_release(struct block_device *bdev, u64 key, enum pr_type type) { - u32 cdw10 = nvme_pr_type(type) << 8 | (key ? 1 << 3 : 0); + u32 cdw10 = nvme_pr_type(type) << 8 | (key ? 0 : 1 << 3); return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_release); } -- 2.35.1