From nobody Mon Dec 1 22:35:44 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 D1E802701DA for ; Wed, 26 Nov 2025 16:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174975; cv=none; b=LDy6TBwJUCq+eCMkFhRsgvqHnJzHqtDvEOL8nKbddSBBxgnmjml4KPrkCGuK39XlPx198a8IDybfZVlKviZLKbsHmCyTUsxFM61GelG7K0GbiypDaiL21e/tsU7Ns+ci8EYTrOtZX+SZV5q5I1nfQ2vIvvcDXB0FwKIxLU0iL5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174975; c=relaxed/simple; bh=hwN0X3MlXRgzLf/i/Ti7PYZd5dSD1XSxvGZQlmoWXRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=amxrwgmNhzwJ3+bUXEaPscB1Ysk+IImCW9VA4A8YdacLQqxXVbqsu8jgr7NuQtbcUy9r4+8okQ8kg3TzQGd7UL676YX75gMFpP6WkY5aQlhWaY210wSIwZ8tgwkyCRd3dibVRfOTRkh5cRSz1QUWj7Bey2jwtAMbeARjnJgB5ZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TULbnYAS; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TULbnYAS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764174972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n8ULdLo4b3ORYhVubgD3gy7oPbpY6qArrsrgQiRkmsY=; b=TULbnYASTV47y4KeV8rkkp+4GMQDFlDKS9sUZ8IGcEJNlJ8yVob4meQdTVGmMH4rNvg6mA uTVRxh3a1qEWAxXEicY+mv1iZr+4T+QdhW40SQxkfxGOLPsEf8V2wJSdoZPld3F2RuAa9O 3YXmWOYhJdo/JOJarNN6U4Cvv/HGxao= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-137-9p40aK1TNFeth8KEkFpF8g-1; Wed, 26 Nov 2025 11:36:09 -0500 X-MC-Unique: 9p40aK1TNFeth8KEkFpF8g-1 X-Mimecast-MFC-AGG-ID: 9p40aK1TNFeth8KEkFpF8g_1764174967 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33FAA1800451; Wed, 26 Nov 2025 16:36:07 +0000 (UTC) Received: from localhost (unknown [10.2.16.50]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C4A319560A2; Wed, 26 Nov 2025 16:36:05 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: "Martin K. Petersen" , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Mike Christie , Jens Axboe , linux-nvme@lists.infradead.org, Keith Busch , Sagi Grimberg , linux-scsi@vger.kernel.org, Christoph Hellwig , Stefan Hajnoczi Subject: [PATCH 1/4] scsi: sd: reject invalid pr_read_keys() num_keys values Date: Wed, 26 Nov 2025 11:35:57 -0500 Message-ID: <20251126163600.583036-2-stefanha@redhat.com> In-Reply-To: <20251126163600.583036-1-stefanha@redhat.com> References: <20251126163600.583036-1-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The pr_read_keys() interface has a u32 num_keys parameter. The SCSI PERSISTENT RESERVE IN command has a maximum READ KEYS service action size of 65536 bytes. Reject num_keys values that are too large to fit into the SCSI command. This will become important when pr_read_keys() is exposed to untrusted userspace via an ioctl. Signed-off-by: Stefan Hajnoczi --- drivers/scsi/sd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 0252d3f6bed17..d65646f35f453 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1974,9 +1974,18 @@ static int sd_pr_read_keys(struct block_device *bdev= , struct pr_keys *keys_info) { int result, i, data_offset, num_copy_keys; u32 num_keys =3D keys_info->num_keys; - int data_len =3D num_keys * 8 + 8; + int data_len; u8 *data; =20 + /* + * Each reservation key takes 8 bytes and there is an 8-byte header + * before the reservation key list. The total size must fit into the + * 16-bit ALLOCATION LENGTH field. + */ + if (num_keys > (65536 - 8) / 8) + return -EINVAL; + + data_len =3D num_keys * 8 + 8; data =3D kzalloc(data_len, GFP_KERNEL); if (!data) return -ENOMEM; --=20 2.52.0 From nobody Mon Dec 1 22:35:44 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 D5BE033F381 for ; Wed, 26 Nov 2025 16:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174982; cv=none; b=ramq//7O5s/4eDwvpy/uV81LULAFoJRUc39oB25kXWnskjdwgClqD7YFy3OPwS+MnBJIZ6Wwc9Z5WrCvlEmZUTpAr19WalS5+ykG/4ZkZai7R/CTOTQx07hph5gBdU8rT0G7qb7YNHN01+1ajlw4S/6raTJpCUlshWuxALJaE0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174982; c=relaxed/simple; bh=IU4kgx8Wn4nALVRtMfyab5Yub53eM6C01xg0lQHuTo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OFKA2CH5TNnQQrn+W5Qq9BaG0mTvLfJx1qpA4WUoxpmW37GXktblqw7if1P/2+/6VPIiOSrrxVwPhqaxG6CEk10B/4RRx02tTVQrczuXinU3OQ0cEQ+/6+PNYzFrHvRj7Un4HZz0aZAxHsWNsfAjfjhVCbudjfFqT7lRV5fsz8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QdqvE0j8; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QdqvE0j8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764174980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fLbOYH1ZNvDH2OUPDGLBHO7mvrdHvaUK8HEzMWWFf5s=; b=QdqvE0j8eYFgqoDPsq91QNInIaCINVaJ3OoWKcvbTiOA0CJGkP8lae4HLEPLDyNQBZm08n BxPe60vp3h1AbEQCt5dcfkBewxH7fik2HMs7UrfNHLN05rpeH3ayWaPDu6W/o3LU4ueHlT m4SC/6xOCnqtHLqeqM5Nty3qsKGQII8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-V2gLIDVUMA231heVvoz5qg-1; Wed, 26 Nov 2025 11:36:11 -0500 X-MC-Unique: V2gLIDVUMA231heVvoz5qg-1 X-Mimecast-MFC-AGG-ID: V2gLIDVUMA231heVvoz5qg_1764174969 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9057B1954B06; Wed, 26 Nov 2025 16:36:09 +0000 (UTC) Received: from localhost (unknown [10.2.16.50]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 80B941800878; Wed, 26 Nov 2025 16:36:08 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: "Martin K. Petersen" , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Mike Christie , Jens Axboe , linux-nvme@lists.infradead.org, Keith Busch , Sagi Grimberg , linux-scsi@vger.kernel.org, Christoph Hellwig , Stefan Hajnoczi Subject: [PATCH 2/4] nvme: reject invalid pr_read_keys() num_keys values Date: Wed, 26 Nov 2025 11:35:58 -0500 Message-ID: <20251126163600.583036-3-stefanha@redhat.com> In-Reply-To: <20251126163600.583036-1-stefanha@redhat.com> References: <20251126163600.583036-1-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The pr_read_keys() interface has a u32 num_keys parameter. The NVMe Reservation Report command has a u32 maximum length. Reject num_keys values that are too large to fit. This will become important when pr_read_keys() is exposed to untrusted userspace via an ioctl. Signed-off-by: Stefan Hajnoczi Reviewed-by: Hannes Reinecke --- drivers/nvme/host/pr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index ca6a74607b139..476a0518a11ca 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -233,6 +233,11 @@ static int nvme_pr_read_keys(struct block_device *bdev, int ret, i; bool eds; =20 + /* Check that keys fit into u32 rse_len */ + if (num_keys > -(u32)offsetof(typeof(*rse), regctl_eds) / + sizeof(rse->regctl_eds[0])) + return -EINVAL; + /* * Assume we are using 128-bit host IDs and allocate a buffer large * enough to get enough keys to fill the return keys buffer. --=20 2.52.0 From nobody Mon Dec 1 22:35:44 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 7787333DEC5 for ; Wed, 26 Nov 2025 16:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174983; cv=none; b=YIuR2Adt3T5vGl22nIRndz6+7ZADgpovNYa6klIwRvAGmFQL9Bdn3uQ0+RnzC3HmblUfY7F6bfgklAgL8fa/30rVOzK+R9yQIekogpWIooHMA6Fb66DOKKjD6ad/6ANZcbUsmk/DUCPYY4Uyln9cLTAurboCuj7Zq3rcWDmFWWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174983; c=relaxed/simple; bh=hJ6Wd5UdHxQ7JlXBVBf96oHo4OCVe4ElVnMwlaHDaEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9+iIXKR7ulPprLVyww6GTV4Ms4r2RU//HvbnYbk9v6nMS+aEjE0eZf59iWaohsAU/S5ZVIV1u0eN1+nR20lgWnkrtkHcG7L/xcJv5e6Am8Kg275ECkRTLymaN6TypFVrunyIqbx/x+S/nd/uj5L3RHwt8foatEjW8/3CxQSr+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cW1pXZzq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cW1pXZzq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764174980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y7acRfl4IkuQFx8mKPn8HoH4mgf78BRMNYKMfEK8ccQ=; b=cW1pXZzqNibGl5mg0LZqHFvPCC7pSG5TZmgbBtvuPjUDbwnZjLYfpDuXweCg3zMaNJfjeS X/fiJhcfEb9O0qx/Krn3SOFZWv4mJK7QH5oWap+kXYxDeJD0uG69ktBCNbUf6XhIIiPVGL MTsUvzYYDEuCADDXu3bvGX40l6cXsbI= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-wVtkfr5wO-2CEH1AYylILQ-1; Wed, 26 Nov 2025 11:36:14 -0500 X-MC-Unique: wVtkfr5wO-2CEH1AYylILQ-1 X-Mimecast-MFC-AGG-ID: wVtkfr5wO-2CEH1AYylILQ_1764174972 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37F20195606B; Wed, 26 Nov 2025 16:36:12 +0000 (UTC) Received: from localhost (unknown [10.2.16.50]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB99118004A3; Wed, 26 Nov 2025 16:36:10 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: "Martin K. Petersen" , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Mike Christie , Jens Axboe , linux-nvme@lists.infradead.org, Keith Busch , Sagi Grimberg , linux-scsi@vger.kernel.org, Christoph Hellwig , Stefan Hajnoczi Subject: [PATCH 3/4] block: add IOC_PR_READ_KEYS ioctl Date: Wed, 26 Nov 2025 11:35:59 -0500 Message-ID: <20251126163600.583036-4-stefanha@redhat.com> In-Reply-To: <20251126163600.583036-1-stefanha@redhat.com> References: <20251126163600.583036-1-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add a Persistent Reservations ioctl to read the list of currently registered reservation keys. This calls the pr_ops->read_keys() function that was previously added in commit c787f1baa503 ("block: Add PR callouts for read keys and reservation") but was only used by the in-kernel SCSI target so far. The IOC_PR_READ_KEYS ioctl is necessary so that userspace applications that rely on Persistent Reservations ioctls have a way of inspecting the current state. Cluster managers and validation tests need this functionality. Signed-off-by: Stefan Hajnoczi --- include/uapi/linux/pr.h | 7 ++++++ block/ioctl.c | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/uapi/linux/pr.h b/include/uapi/linux/pr.h index d8126415966f3..fcb74eab92c80 100644 --- a/include/uapi/linux/pr.h +++ b/include/uapi/linux/pr.h @@ -56,6 +56,12 @@ struct pr_clear { __u32 __pad; }; =20 +struct pr_read_keys { + __u32 generation; + __u32 num_keys; + __u64 keys_ptr; +}; + #define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */ =20 #define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration) @@ -64,5 +70,6 @@ struct pr_clear { #define IOC_PR_PREEMPT _IOW('p', 203, struct pr_preempt) #define IOC_PR_PREEMPT_ABORT _IOW('p', 204, struct pr_preempt) #define IOC_PR_CLEAR _IOW('p', 205, struct pr_clear) +#define IOC_PR_READ_KEYS _IOWR('p', 206, struct pr_read_keys) =20 #endif /* _UAPI_PR_H */ diff --git a/block/ioctl.c b/block/ioctl.c index d7489a56b33c3..e87c424c15ae9 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -423,6 +424,54 @@ static int blkdev_pr_clear(struct block_device *bdev, = blk_mode_t mode, return ops->pr_clear(bdev, c.key); } =20 +static int blkdev_pr_read_keys(struct block_device *bdev, blk_mode_t mode, + struct pr_read_keys __user *arg) +{ + const struct pr_ops *ops =3D bdev->bd_disk->fops->pr_ops; + struct pr_keys *keys_info __free(kfree) =3D NULL; + struct pr_read_keys inout; + int ret; + + if (!blkdev_pr_allowed(bdev, mode)) + return -EPERM; + if (!ops || !ops->pr_read_keys) + return -EOPNOTSUPP; + + if (copy_from_user(&inout, arg, sizeof(inout))) + return -EFAULT; + + if (inout.num_keys > -sizeof(*keys_info) / sizeof(keys_info->keys[0])) + return -EINVAL; + + size_t keys_info_len =3D struct_size(keys_info, keys, inout.num_keys); + + keys_info =3D kzalloc(keys_info_len, GFP_KERNEL); + if (!keys_info) + return -ENOMEM; + + keys_info->num_keys =3D inout.num_keys; + + ret =3D ops->pr_read_keys(bdev, keys_info); + if (ret) + return ret; + + /* Copy out individual keys */ + u64 __user *keys_ptr =3D u64_to_user_ptr(inout.keys_ptr); + u32 num_copy_keys =3D min(inout.num_keys, keys_info->num_keys); + size_t keys_copy_len =3D num_copy_keys * sizeof(keys_info->keys[0]); + + if (copy_to_user(keys_ptr, keys_info->keys, keys_copy_len)) + return -EFAULT; + + /* Copy out the arg struct */ + inout.generation =3D keys_info->generation; + inout.num_keys =3D keys_info->num_keys; + + if (copy_to_user(arg, &inout, sizeof(inout))) + return -EFAULT; + return ret; +} + static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd, unsigned long arg) { @@ -644,6 +693,8 @@ static int blkdev_common_ioctl(struct block_device *bde= v, blk_mode_t mode, return blkdev_pr_preempt(bdev, mode, argp, true); case IOC_PR_CLEAR: return blkdev_pr_clear(bdev, mode, argp); + case IOC_PR_READ_KEYS: + return blkdev_pr_read_keys(bdev, mode, argp); default: return blk_get_meta_cap(bdev, cmd, argp); } --=20 2.52.0 From nobody Mon Dec 1 22:35:44 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 458CE33E34B for ; Wed, 26 Nov 2025 16:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174982; cv=none; b=teyshULO6EFuyos0gZpzCmXb9Dr+c3QDHHJ3Y5HKVkJqeJeNI7+Z9QBeS07f0t5ITtux2gwV1lBxf6GFAkBR211fh81fXavmfKKMRZQE4Jlqq0U2zxWNeLTWTHcnCfJQMYVb9O5o2jotsijVXO4xFQL+JoBN4f0M+CREsL3Y6wI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764174982; c=relaxed/simple; bh=gyIXhfyr6nZM6LF63rYOm8b1zevtzeUIHbeqJNAK3Mk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r9bJzvHo6/uFJerEDEE4xsHiLDoKIHaSa4E9c812rfoxMxu/tWmdNx/kCMmB6wY1yI6gz7shLgBLC/zaBuhmwJWs1DGBeXCLg9sZuA9gD9EuPzyYAROuv9dotWKWPMz7EG4IlWruXbUHhQaNclN3wl5LbupPz1hQjbRciXEff4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fHK6aQAG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fHK6aQAG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764174979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4YKeJBoqj49IiVaa5396deScmldRsSYyxygJIXwbHUQ=; b=fHK6aQAGWhkRbuG3F7Mk7l5u8eRxf86l7FGUU2RE/IRfnqr9lixWkS3Sh70KYGRRmMPbbY ch7135X1A6va3ve5OPzrGTOjTM809v13bmhVKxj7fpKK6fVuPjcUywHfSQEyYBsx3ejWlz Ned6xIY7MYLgnVsmOyhz+CdCdr0dAIk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-363-iV1plFoROoSzVVS9yFOPdQ-1; Wed, 26 Nov 2025 11:36:15 -0500 X-MC-Unique: iV1plFoROoSzVVS9yFOPdQ-1 X-Mimecast-MFC-AGG-ID: iV1plFoROoSzVVS9yFOPdQ_1764174974 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1C43B180057A; Wed, 26 Nov 2025 16:36:14 +0000 (UTC) Received: from localhost (unknown [10.2.16.50]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8368930044E0; Wed, 26 Nov 2025 16:36:13 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: "Martin K. Petersen" , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Mike Christie , Jens Axboe , linux-nvme@lists.infradead.org, Keith Busch , Sagi Grimberg , linux-scsi@vger.kernel.org, Christoph Hellwig , Stefan Hajnoczi Subject: [PATCH 4/4] block: add IOC_PR_READ_RESERVATION ioctl Date: Wed, 26 Nov 2025 11:36:00 -0500 Message-ID: <20251126163600.583036-5-stefanha@redhat.com> In-Reply-To: <20251126163600.583036-1-stefanha@redhat.com> References: <20251126163600.583036-1-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Add a Persistent Reservations ioctl to read the current reservation. This calls the pr_ops->read_reservation() function that was previously added in commit c787f1baa503 ("block: Add PR callouts for read keys and reservation") but was only used by the in-kernel SCSI target so far. The IOC_PR_READ_RESERVATION ioctl is necessary so that userspace applications that rely on Persistent Reservations ioctls have a way of inspecting the current state. Cluster managers and validation tests need this functionality. Signed-off-by: Stefan Hajnoczi Reviewed-by: Hannes Reinecke --- include/uapi/linux/pr.h | 7 +++++++ block/ioctl.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/uapi/linux/pr.h b/include/uapi/linux/pr.h index fcb74eab92c80..847f3051057af 100644 --- a/include/uapi/linux/pr.h +++ b/include/uapi/linux/pr.h @@ -62,6 +62,12 @@ struct pr_read_keys { __u64 keys_ptr; }; =20 +struct pr_read_reservation { + __u64 key; + __u32 generation; + __u32 type; +}; + #define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */ =20 #define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration) @@ -71,5 +77,6 @@ struct pr_read_keys { #define IOC_PR_PREEMPT_ABORT _IOW('p', 204, struct pr_preempt) #define IOC_PR_CLEAR _IOW('p', 205, struct pr_clear) #define IOC_PR_READ_KEYS _IOWR('p', 206, struct pr_read_keys) +#define IOC_PR_READ_RESERVATION _IOR('p', 207, struct pr_read_reservation) =20 #endif /* _UAPI_PR_H */ diff --git a/block/ioctl.c b/block/ioctl.c index e87c424c15ae9..7e6d5e532d16b 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -472,6 +472,32 @@ static int blkdev_pr_read_keys(struct block_device *bd= ev, blk_mode_t mode, return ret; } =20 +static int blkdev_pr_read_reservation(struct block_device *bdev, + blk_mode_t mode, struct pr_read_reservation __user *arg) +{ + const struct pr_ops *ops =3D bdev->bd_disk->fops->pr_ops; + struct pr_held_reservation rsv =3D {}; + struct pr_read_reservation out =3D {}; + int ret; + + if (!blkdev_pr_allowed(bdev, mode)) + return -EPERM; + if (!ops || !ops->pr_read_reservation) + return -EOPNOTSUPP; + + ret =3D ops->pr_read_reservation(bdev, &rsv); + if (ret) + return ret; + + out.key =3D rsv.key; + out.generation =3D rsv.generation; + out.type =3D rsv.type; + + if (copy_to_user(arg, &out, sizeof(out))) + return -EFAULT; + return 0; +} + static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd, unsigned long arg) { @@ -695,6 +721,8 @@ static int blkdev_common_ioctl(struct block_device *bde= v, blk_mode_t mode, return blkdev_pr_clear(bdev, mode, argp); case IOC_PR_READ_KEYS: return blkdev_pr_read_keys(bdev, mode, argp); + case IOC_PR_READ_RESERVATION: + return blkdev_pr_read_reservation(bdev, mode, argp); default: return blk_get_meta_cap(bdev, cmd, argp); } --=20 2.52.0