Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7073428rwi; Mon, 24 Oct 2022 09:29:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM73Y1i/A++bRqWXWVQ/3aGLhQ382p9/ohsAgQc7oydEY8naXaGc7+PT8jc1ph4COjc7cc9B X-Received: by 2002:aa7:dc10:0:b0:440:b446:c0cc with SMTP id b16-20020aa7dc10000000b00440b446c0ccmr31252333edu.34.1666628965961; Mon, 24 Oct 2022 09:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666628965; cv=none; d=google.com; s=arc-20160816; b=AJISFagDvSw/8h2c5KT908ECNAl+TQ6s+dy6xp/nXfERt8uvBpcw3DHSYYfP7+G+FQ khONkNS+1nQ0IspiYxntucej34qZVJ0tgodVgbiAIGIbmOUMgLLZHzLmJbu+w1ue6QuR rb9igfva/kTs7miiBCXJnG3Ux+W9ITT5+5lsBTngfF0tDC7gB4I7tYWooNyhdnMzpYaq 3rPCchpM43oe9jE+8jOXBZbz6ulO+yNulz1yJ2LatYJtxILhiSi0kJAiZw1vBmdLWKUY njafQxf227MtkXOs0WDmS7u6UHyrLHvcUzqNIhb3fL3h0dgZlavOzsrxmPlTOU1d/KZx LCgw== 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=TwFcJJkyzg7YO6TUVQ04NdLOCHGVQ6TyZBGjnZr1wt0=; b=XvhF4gDRwvbEkiz1fU/Dg54FaI9nLlzxZ56Ivi/j8XFPTY/LXL+GYAj4hn2ruAyOwo 2KR3Uc1KpwEbRGy4P1+XvKb1kttQ0S3WQ0E18H6CJeHMYhsF9+6RAfM059mfoEqJSxZe WEzkg5gZDkwPw1f76wh2NBMCPE5aqT7Y7+ihwSYUEv1RUqRCzexGx5G8KCxL5M+CxMN9 Zq4tCzlVAxT1zlOp95OOrLeXLVYiQ1JNOBZFWa6cEXdFQBJ9AEdRpIWpwrv/tN4pdMdM Denxt2/cMzxQfLVnYMBnnIuEhFLU/fccwB6K8nEtkT0d64saO7G73U6dSQ0DBttMKV5T wGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aqFGKy3c; 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 hs36-20020a1709073ea400b0078e27ef9510si141135ejc.747.2022.10.24.09.29.01; Mon, 24 Oct 2022 09:29:25 -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=aqFGKy3c; 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 S232941AbiJXQFh (ORCPT + 99 others); Mon, 24 Oct 2022 12:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbiJXQDU (ORCPT ); Mon, 24 Oct 2022 12:03:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 747CC1CBAA7; Mon, 24 Oct 2022 07:55:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id 1CD0FB81142; Mon, 24 Oct 2022 11:38:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CD09C433D6; Mon, 24 Oct 2022 11:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611523; bh=iN2Js/H7duln38ZwZOp92nMIMPUms12TLUjDHJN09ps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aqFGKy3cakGSeaJDzlgwiHFsjFL8ac9bS2nJ+PIo8PBlYBgh1GSCzNhHrNO/txqEp +aPdkEihGlS6RBqKqnX7UnWzD+k2Be9FGChJH7Wwjl1vXfRQLrdaC6namsK9QiWhyN wgkP62h6DwtBqJVhDpHqQXHn4/l56z1zmDqVclFE= 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.9 012/159] nvme: Fix IOC_PR_CLEAR and IOC_PR_RELEASE ioctls for nvme devices Date: Mon, 24 Oct 2022 13:29:26 +0200 Message-Id: <20221024112949.803490011@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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.6 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 051bc7430af2..f260ef59dda2 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1050,14 +1050,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