From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (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 11E0D3C98B9 for ; Wed, 27 May 2026 14:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779891673; cv=none; b=M6YIp/05sHsuUWIj98OjaSWrz664Mnm7i2EmntSSrMMWO+V9G3TUQ4ANWmyKVz+bp+BA2v3YoLpLIntH3lULKbBjpJoqqiVPL+vrpQENfdLhiQCd3NGSyXgxYeVuoXhQIabHKp4l8Nm66k4zDiuKKb5PvgXZeSIJzUs+D8+g7Qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779891673; c=relaxed/simple; bh=KTJRJaXxhdm5TXcYnUSSqw5GvA2Pq3Ix3GHTbMQ48DQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o+hqYYEjtREhQbbNmZu689XYSCQz0eR+smOE2rD0k2rhgoHKYr4qJ8pRFBkxjT6bFhqi64Omx9uPXZTQkuOHJZQa+gCjD6FV83XUpZBWZBubaVRtbJ/HOgvY7QTjtAimHj00HBJ8uvkao/Db8yMxczZ/5VpQ1ris70CkB/Rjk+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id BDB2D68B05; Wed, 27 May 2026 16:21:07 +0200 (CEST) Date: Wed, 27 May 2026 16:21:07 +0200 From: Christoph Hellwig To: Keith Busch Cc: Chao Shi , 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: <20260527142107.GA13687@lst.de> 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: User-Agent: Mutt/1.5.17 (2007-11-01) On Fri, May 22, 2026 at 01:32:38PM -0600, Keith Busch wrote: > 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(): Sorry for only catching this. Adding it to the common function is of course good, but I think it's grown to a size where splitting that common code into sub-helper as suggested probably helps readability.