From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63F8CC3DA7D for ; Tue, 3 Jan 2023 18:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233544AbjACSki (ORCPT ); Tue, 3 Jan 2023 13:40:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238315AbjACSkD (ORCPT ); Tue, 3 Jan 2023 13:40:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DD3413F3E; Tue, 3 Jan 2023 10:39:58 -0800 (PST) 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 D9A21B810AA; Tue, 3 Jan 2023 18:39:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4A88C433F1; Tue, 3 Jan 2023 18:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672771195; bh=jktih1V+pEJSNMJGLXpJMhxqZlHX4fppjmcyULYa1Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=coPo01GgIzfcYW4dKKFpwZ5V1UdEC/7xd53rxop8aDsOV/gbmwDt8kuCktljidEmh xAzyNozER4wkseAYJV9FetPkDokjUwOWu+6V4T4d01+ueEPapwNGQ78r8nOX5E7lVv Xk9Kde49FTv5iS7RjPJoK6haQbwzNvwPYhZI2dMPnjP+z7OLXhFGH5kRMbrij6l0rG ZtoAijflwMYiStPT98Jf7hq7ZC+MT2FJ2H0jMFLbcPSCtm2uQ/fXQuO3HhZ6KGELB6 kR4GtN1dUsB0L1/AfbWCNtXeUzbm5fNJ+1N0lZVDx9LOhe6V1db/Afd289ES0xWZ3j ReFKsmEtqfnHQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christoph Hellwig , Keith Busch , Kanchan Joshi , Sasha Levin , axboe@fb.com, sagi@grimberg.me, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.1 10/10] nvme: also return I/O command effects from nvme_command_effects Date: Tue, 3 Jan 2023 13:39:34 -0500 Message-Id: <20230103183934.2022663-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230103183934.2022663-1-sashal@kernel.org> References: <20230103183934.2022663-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig [ Upstream commit 831ed60c2aca2d7c517b2da22897a90224a97d27 ] To be able to use the Commands Supported and Effects Log for allowing unprivileged passtrough, it needs to be corretly reported for I/O commands as well. Return the I/O command effects from nvme_command_effects, and also add a default list of effects for the NVM command set. For other command sets, the Commands Supported and Effects log is required to be present already. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Kanchan Joshi Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 108b5022cead..1ded96d1bfd2 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1069,6 +1069,18 @@ static u32 nvme_known_admin_effects(u8 opcode) return 0; } +static u32 nvme_known_nvm_effects(u8 opcode) +{ + switch (opcode) { + case nvme_cmd_write: + case nvme_cmd_write_zeroes: + case nvme_cmd_write_uncor: + return NVME_CMD_EFFECTS_LBCC; + default: + return 0; + } +} + u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) { u32 effects = 0; @@ -1076,16 +1088,24 @@ u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) if (ns) { if (ns->head->effects) effects = le32_to_cpu(ns->head->effects->iocs[opcode]); + if (ns->head->ids.csi == NVME_CAP_CSS_NVM) + effects |= nvme_known_nvm_effects(opcode); if (effects & ~(NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC)) dev_warn_once(ctrl->device, - "IO command:%02x has unhandled effects:%08x\n", + "IO command:%02x has unusual effects:%08x\n", opcode, effects); - return 0; - } - if (ctrl->effects) - effects = le32_to_cpu(ctrl->effects->acs[opcode]); - effects |= nvme_known_admin_effects(opcode); + /* + * NVME_CMD_EFFECTS_CSE_MASK causes a freeze all I/O queues, + * which would deadlock when done on an I/O command. Note that + * We already warn about an unusual effect above. + */ + effects &= ~NVME_CMD_EFFECTS_CSE_MASK; + } else { + if (ctrl->effects) + effects = le32_to_cpu(ctrl->effects->acs[opcode]); + effects |= nvme_known_admin_effects(opcode); + } return effects; } -- 2.35.1