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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A643C54F4C for ; Tue, 28 Jul 2026 06:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=lxgQ4TGWvMDnk4IAmesFG3860mf8uXHUfe7W+qGSGEE=; b=o+n4qeZ/qzixvZWsjNlRk/FFHT m/2rVCXZ/CEoQhhBZMXPAfzG7MJcw3mTXBnufNKDSX6wC8EiX/EacFN5+Y6Q5OBpqB0mznE+mDbEU dWrEl/6Itu7EiXrZXKfPzThVFfDDVxXfQTmAm2bAs0fKgx8MgdNP2pdTrFua61cr4xC10llalz6bu WcH+TQkUlPx2lOyA3SR0g07wu7XgTI/f+fAuLZJ/iU61sfo84jPnPg8zXBuduULXpnsd19DuNV3T0 mStN47rH2/vfXvjnsk0tW/9eYSAkZzQRnhVfnN5AZ39mCrhbB1IctZ8/Ky4Hh6Y808gYz2aaPQP68 j8deoNgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wobDF-00000004WhR-3HyV; Tue, 28 Jul 2026 06:22:49 +0000 Received: from out30-101.freemail.mail.aliyun.com ([115.124.30.101]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wobDB-00000004WgA-3zJe for linux-nvme@lists.infradead.org; Tue, 28 Jul 2026 06:22:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1785219759; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; bh=lxgQ4TGWvMDnk4IAmesFG3860mf8uXHUfe7W+qGSGEE=; b=MDfkUZsV3NQhbrqgtp+S3EjZRv1TX6g/LelDY/kY3cFK8KDpKFwdGuwEUkpjFmd6pmelbwnQGiiPUpisRJQKiCcNWki/YCbxuov+oTeoIC4/toxOu9gNKxciqfUH8WtPvT4HPXwYWGS12bo7vZR+xkyMyFcNMNMMoendeFP6RvY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R491e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=zhengrong_li@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0X7zfl8f_1785219752; Received: from U-92DF4J33-2338.local(mailfrom:zhengrong_li@linux.alibaba.com fp:SMTPD_---0X7zfl8f_1785219752 cluster:ay36) by smtp.aliyun-inc.com; Tue, 28 Jul 2026 14:22:38 +0800 From: Zhengrong Li To: linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, kch@nvidia.com, zhengrong_li@linux.alibaba.com Subject: [PATCH] nvmet: fix Reservation Register Replace for unregistered host with IEKEY Date: Sat, 25 Jul 2026 11:50:54 +0800 Message-ID: <178521959386.52051.17173420094473200063@linux.alibaba.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260727_232246_717189_CE27FE97 X-CRM114-Status: GOOD ( 11.81 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org When a host sends a Reservation Register command with RREGA=Replace and IEKEY=1 without being previously registered, nvmet returns Reservation Conflict. SPDK accepts this combination and creates a new registrant with the provided NRKEY, with an explicit unit test covering this scenario (test/unit/lib/nvmf/subsystem.c). Fix nvmet_pr_replace() to add a new registrant when the host is not found in the registrant list and IEKEY is set with a non-zero NRKEY, consistent with SPDK's behavior. Tested with nvme-cli against nvmet-tcp: # no prior registration nvme resv-register /dev/nvmeXn1 -n 1 --rrega=2 --iekey --nrkey=0x9999 Before: RESERVATION_CONFLICT (0x4083) After: success, registrant created with rkey 0x9999 Signed-off-by: Zhengrong Li --- drivers/nvme/target/pr.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c index c71ae46244ff..f00de35683ca 100644 --- a/drivers/nvme/target/pr.c +++ b/drivers/nvme/target/pr.c @@ -355,12 +355,14 @@ static u16 nvmet_pr_replace(struct nvmet_req *req, u16 status = NVME_SC_RESERVATION_CONFLICT | NVME_STATUS_DNR; struct nvmet_ctrl *ctrl = req->sq->ctrl; struct nvmet_pr *pr = &req->ns->pr; - struct nvmet_pr_registrant *reg; + struct nvmet_pr_registrant *reg, *new; u64 nrkey = le64_to_cpu(d->nrkey); + bool found = false; down(&pr->pr_sem); list_for_each_entry_rcu(reg, &pr->registrant_list, entry) { if (uuid_equal(®->hostid, &ctrl->hostid)) { + found = true; if (ignore_key || reg->rkey == le64_to_cpu(d->crkey)) status = nvmet_pr_update_reg_attr(pr, reg, nvmet_pr_update_reg_rkey, @@ -368,6 +370,22 @@ static u16 nvmet_pr_replace(struct nvmet_req *req, break; } } + + if (!found && ignore_key && nrkey) { + new = kmalloc_obj(*new); + if (!new) { + status = NVME_SC_INTERNAL; + goto out; + } + memset(new, 0, sizeof(*new)); + INIT_LIST_HEAD(&new->entry); + new->rkey = nrkey; + uuid_copy(&new->hostid, &ctrl->hostid); + list_add_tail_rcu(&new->entry, &pr->registrant_list); + status = NVME_SC_SUCCESS; + } + +out: up(&pr->pr_sem); return status; } -- 2.43.7