From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C19733659FD for ; Fri, 22 May 2026 19:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779478361; cv=none; b=uIpE1YBpUgJBz4Ks96SKOQnCl5AFMwCDKghk0sFTdeccajzYxocOZ+3uGYZb50TD6B0RLzhIf7RRFpDjkRjJcYTBKNG1o22GsZHe9T9v8+QLmQKq61ynIgOvVp7pa8v0yx+K/leyXDXhrNHnayI9KEwndK7G/mojp6YuThYMBK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779478361; c=relaxed/simple; bh=09PzH5xBq05rHFOqpN95m09XAd/pBY5rKqi1o8LCGfE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bzj/uHAbWWJ8FlKelhIqw6k3vZvmgdWuk5l70KjBPkcYE3pLiTr87tEuWovLB/ARVgil/5yCNh2NkFoVBlWxcM4jIBTlvYcKR36AKNkLcUKKSTpGUOHXdO/YSyNV9YT6gu7zEwByptfb2urJwTJLZQFO3OALdv2Qrsq6l/19k3w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AGRrKuch; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AGRrKuch" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 045EC1F000E9; Fri, 22 May 2026 19:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779478360; bh=QSMMfEPFHek8pZ9CbVMlJ3mr2ELej7XZeoLYlBEmfF0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=AGRrKuchx3Su9jRdDyO1g7F4wpXSRoSf+fevwvbLQ2aZjdgjxYOs3E6A3wEi15Gwd 0GBOb7i323SbeIWj7MNHkg+zQh5PbKK0JTSES4pJi+Oav4SQwSdWzmuErOiG8BB5+J x/D+PnNlKqQYymvmwuJGSUOPIvKeqwEniTw9SECX+t7+buVqCpvaEbSbYhf/FdE2YU jMnPUHIBNPToT/PK0X9VBk/KyIM6CCCSqrQvZSZ2k94zMQdDEkkXRJMH1GXK/F53sf 7b06IesJc6pFE2vSTZlsgLl/oaNY1N+uIj/dYDK/Xyd7uDIoyRD8KqG/L0k4TTmbau I5x2jhjwwfs2A== Date: Fri, 22 May 2026 13:32:38 -0600 From: Keith Busch To: Chao Shi Cc: linux-nvme@lists.infradead.org, Christoph Hellwig , Sagi Grimberg , Jens Axboe , Tatsuya Sasaki , Maurizio Lombardi , linux-kernel@vger.kernel.org, Sungwoo Kim , Dave Tian , Weidong Zhu Subject: Re: [PATCH v4] nvme: reject keep-alive passthrough on non-fabrics Message-ID: References: <20260522162639.395802-1-coshi036@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260522162639.395802-1-coshi036@gmail.com> On Fri, May 22, 2026 at 12:26:39PM -0400, Chao Shi wrote: > +/* > + * Some Set Features commands change controller behaviour that the driver is > + * not prepared to handle on every transport. Reject such commands from > + * userspace passthrough rather than letting them put the controller into a > + * state the driver cannot deal with. The list can be extended as other > + * problematic features are identified. > + */ > +static bool nvme_passthru_cmd_allowed(struct nvme_ctrl *ctrl, > + struct nvme_ns *ns, > + struct nvme_command *c) > +{ > + /* > + * This only filters admin commands (ns == NULL). I/O commands share > + * the opcode space with admin commands - Dataset Management is 0x09, > + * the same value as Set Features - so they must not be inspected here. > + */ > + if (ns || c->common.opcode != nvme_admin_set_features) > + return true; > + > + switch (le32_to_cpu(c->common.cdw10) & 0xff) { > + case NVME_FEAT_KATO: > + /* > + * Keep Alive is optional on PCIe (NVMe 2.0a 5.27.1.12) and the > + * driver only arms keep-alive for fabrics. Enabling it on > + * other transports starts a keep-alive command the driver is > + * not set up for and harms idle power states, so reject it. > + */ > + return ctrl->ops->flags & NVME_F_FABRICS; > + default: > + return true; > + } > +} This doesn't need to be its own function. You can add these checks to the existing nvme_cmd_allowed(): --- @@ -50,6 +53,18 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c, case NVME_ID_CNS_CTRL: return true; } + } else if (c->common.opcode == nvme_admin_set_features) { + switch (cpu_to_le32(c->features.fid) & 0xff) { + case NVME_FEAT_KATO: + if (ctrl->ops->flags & NVME_F_FABRICS) + break; + fallthrough; + case NVME_FEAT_HOST_BEHAVIOR: + case NVME_FEAT_HOST_MEM_BUF: + case NVME_FEAT_NUM_QUEUES: + case NVME_FEAT_AUTO_PST: + return false; + } } goto admin; } --