From: Keith Busch <kbusch@meta.com>
To: <linux-nvme@lists.infradead.org>, <hch@lst.de>, <sagi@grimberg.me>
Cc: Keith Busch <kbusch@kernel.org>
Subject: [PATCH 1/6] nvme-ioctl: fold open_for_write into flags
Date: Mon, 24 Feb 2025 10:21:23 -0800 [thread overview]
Message-ID: <20250224182128.2042061-2-kbusch@meta.com> (raw)
In-Reply-To: <20250224182128.2042061-1-kbusch@meta.com>
From: Keith Busch <kbusch@kernel.org>
Helps to reduce the number of parameters passed around.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/nvme/host/ioctl.c | 84 ++++++++++++++++++++++-----------------
1 file changed, 48 insertions(+), 36 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index e8930146847af..a3082414c7714 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -12,10 +12,11 @@
enum {
NVME_IOCTL_VEC = (1 << 0),
NVME_IOCTL_PARTITION = (1 << 1),
+ NVME_IOCTL_WRITABLE = (1 << 2),
};
static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
- unsigned int flags, bool open_for_write)
+ unsigned int flags)
{
u32 effects;
@@ -78,7 +79,7 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
* writing.
*/
if ((nvme_is_write(c) || (effects & NVME_CMD_EFFECTS_LBCC)) &&
- !open_for_write)
+ !(flags & NVME_IOCTL_WRITABLE))
goto admin;
return true;
@@ -293,8 +294,7 @@ static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
}
static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
- struct nvme_passthru_cmd __user *ucmd, unsigned int flags,
- bool open_for_write)
+ struct nvme_passthru_cmd __user *ucmd, unsigned int flags)
{
struct nvme_passthru_cmd cmd;
struct nvme_command c;
@@ -322,7 +322,7 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.common.cdw14 = cpu_to_le32(cmd.cdw14);
c.common.cdw15 = cpu_to_le32(cmd.cdw15);
- if (!nvme_cmd_allowed(ns, &c, 0, open_for_write))
+ if (!nvme_cmd_allowed(ns, &c, flags))
return -EACCES;
if (cmd.timeout_ms)
@@ -341,8 +341,7 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
}
static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
- struct nvme_passthru_cmd64 __user *ucmd, unsigned int flags,
- bool open_for_write)
+ struct nvme_passthru_cmd64 __user *ucmd, unsigned int flags)
{
struct nvme_passthru_cmd64 cmd;
struct nvme_command c;
@@ -369,7 +368,7 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.common.cdw14 = cpu_to_le32(cmd.cdw14);
c.common.cdw15 = cpu_to_le32(cmd.cdw15);
- if (!nvme_cmd_allowed(ns, &c, flags, open_for_write))
+ if (!nvme_cmd_allowed(ns, &c, flags))
return -EACCES;
if (cmd.timeout_ms)
@@ -467,6 +466,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
struct request *req;
blk_opf_t rq_flags = REQ_ALLOC_CACHE;
blk_mq_req_flags_t blk_flags = 0;
+ unsigned int flags = 0;
int ret;
c.common.opcode = READ_ONCE(cmd->opcode);
@@ -490,7 +490,9 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.common.cdw14 = cpu_to_le32(READ_ONCE(cmd->cdw14));
c.common.cdw15 = cpu_to_le32(READ_ONCE(cmd->cdw15));
- if (!nvme_cmd_allowed(ns, &c, 0, ioucmd->file->f_mode & FMODE_WRITE))
+ if (ioucmd->file->f_mode & FMODE_WRITE)
+ flags |= NVME_IOCTL_WRITABLE;
+ if (!nvme_cmd_allowed(ns, &c, flags))
return -EACCES;
d.metadata = READ_ONCE(cmd->metadata);
@@ -538,13 +540,13 @@ static bool is_ctrl_ioctl(unsigned int cmd)
}
static int nvme_ctrl_ioctl(struct nvme_ctrl *ctrl, unsigned int cmd,
- void __user *argp, bool open_for_write)
+ void __user *argp, unsigned int flags)
{
switch (cmd) {
case NVME_IOCTL_ADMIN_CMD:
- return nvme_user_cmd(ctrl, NULL, argp, 0, open_for_write);
+ return nvme_user_cmd(ctrl, NULL, argp, flags);
case NVME_IOCTL_ADMIN64_CMD:
- return nvme_user_cmd64(ctrl, NULL, argp, 0, open_for_write);
+ return nvme_user_cmd64(ctrl, NULL, argp, flags);
default:
return sed_ioctl(ctrl->opal_dev, cmd, argp);
}
@@ -569,14 +571,14 @@ struct nvme_user_io32 {
#endif /* COMPAT_FOR_U64_ALIGNMENT */
static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
- void __user *argp, unsigned int flags, bool open_for_write)
+ void __user *argp, unsigned int flags)
{
switch (cmd) {
case NVME_IOCTL_ID:
force_successful_syscall_return();
return ns->head->ns_id;
case NVME_IOCTL_IO_CMD:
- return nvme_user_cmd(ns->ctrl, ns, argp, flags, open_for_write);
+ return nvme_user_cmd(ns->ctrl, ns, argp, flags);
/*
* struct nvme_user_io can have different padding on some 32-bit ABIs.
* Just accept the compat version as all fields that are used are the
@@ -591,8 +593,7 @@ static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
flags |= NVME_IOCTL_VEC;
fallthrough;
case NVME_IOCTL_IO64_CMD:
- return nvme_user_cmd64(ns->ctrl, ns, argp, flags,
- open_for_write);
+ return nvme_user_cmd64(ns->ctrl, ns, argp, flags);
default:
return -ENOTTY;
}
@@ -602,28 +603,32 @@ int nvme_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long arg)
{
struct nvme_ns *ns = bdev->bd_disk->private_data;
- bool open_for_write = mode & BLK_OPEN_WRITE;
void __user *argp = (void __user *)arg;
unsigned int flags = 0;
+ if (mode & BLK_OPEN_WRITE)
+ flags |= NVME_IOCTL_WRITABLE;
if (bdev_is_partition(bdev))
flags |= NVME_IOCTL_PARTITION;
if (is_ctrl_ioctl(cmd))
- return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, open_for_write);
- return nvme_ns_ioctl(ns, cmd, argp, flags, open_for_write);
+ return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, flags);
+ return nvme_ns_ioctl(ns, cmd, argp, flags);
}
long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct nvme_ns *ns =
container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev);
- bool open_for_write = file->f_mode & FMODE_WRITE;
void __user *argp = (void __user *)arg;
+ unsigned int flags = 0;
+
+ if (file->f_mode & FMODE_WRITE)
+ flags |= NVME_IOCTL_WRITABLE;
if (is_ctrl_ioctl(cmd))
- return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, open_for_write);
- return nvme_ns_ioctl(ns, cmd, argp, 0, open_for_write);
+ return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, flags);
+ return nvme_ns_ioctl(ns, cmd, argp, flags);
}
static int nvme_uring_cmd_checks(unsigned int issue_flags)
@@ -682,7 +687,7 @@ int nvme_ns_chr_uring_cmd_iopoll(struct io_uring_cmd *ioucmd,
#ifdef CONFIG_NVME_MULTIPATH
static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,
void __user *argp, struct nvme_ns_head *head, int srcu_idx,
- bool open_for_write)
+ unsigned int flags)
__releases(&head->srcu)
{
struct nvme_ctrl *ctrl = ns->ctrl;
@@ -690,7 +695,7 @@ static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,
nvme_get_ctrl(ns->ctrl);
srcu_read_unlock(&head->srcu, srcu_idx);
- ret = nvme_ctrl_ioctl(ns->ctrl, cmd, argp, open_for_write);
+ ret = nvme_ctrl_ioctl(ns->ctrl, cmd, argp, flags);
nvme_put_ctrl(ctrl);
return ret;
@@ -700,12 +705,13 @@ int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long arg)
{
struct nvme_ns_head *head = bdev->bd_disk->private_data;
- bool open_for_write = mode & BLK_OPEN_WRITE;
void __user *argp = (void __user *)arg;
struct nvme_ns *ns;
int srcu_idx, ret = -EWOULDBLOCK;
unsigned int flags = 0;
+ if (mode & BLK_OPEN_WRITE)
+ flags |= NVME_IOCTL_WRITABLE;
if (bdev_is_partition(bdev))
flags |= NVME_IOCTL_PARTITION;
@@ -721,9 +727,9 @@ int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode,
*/
if (is_ctrl_ioctl(cmd))
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
- open_for_write);
+ flags);
- ret = nvme_ns_ioctl(ns, cmd, argp, flags, open_for_write);
+ ret = nvme_ns_ioctl(ns, cmd, argp, flags);
out_unlock:
srcu_read_unlock(&head->srcu, srcu_idx);
return ret;
@@ -732,13 +738,16 @@ int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode,
long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
- bool open_for_write = file->f_mode & FMODE_WRITE;
struct cdev *cdev = file_inode(file)->i_cdev;
struct nvme_ns_head *head =
container_of(cdev, struct nvme_ns_head, cdev);
void __user *argp = (void __user *)arg;
struct nvme_ns *ns;
int srcu_idx, ret = -EWOULDBLOCK;
+ unsigned int flags = 0;
+
+ if (file->f_mode & FMODE_WRITE)
+ flags |= NVME_IOCTL_WRITABLE;
srcu_idx = srcu_read_lock(&head->srcu);
ns = nvme_find_path(head);
@@ -747,9 +756,9 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
if (is_ctrl_ioctl(cmd))
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
- open_for_write);
+ flags);
- ret = nvme_ns_ioctl(ns, cmd, argp, 0, open_for_write);
+ ret = nvme_ns_ioctl(ns, cmd, argp, flags);
out_unlock:
srcu_read_unlock(&head->srcu, srcu_idx);
return ret;
@@ -799,7 +808,7 @@ int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
}
static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp,
- bool open_for_write)
+ unsigned int flags)
{
struct nvme_ns *ns;
int ret, srcu_idx;
@@ -826,7 +835,7 @@ static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp,
}
srcu_read_unlock(&ctrl->srcu, srcu_idx);
- ret = nvme_user_cmd(ctrl, ns, argp, 0, open_for_write);
+ ret = nvme_user_cmd(ctrl, ns, argp, flags);
nvme_put_ns(ns);
return ret;
@@ -838,17 +847,20 @@ static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp,
long nvme_dev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
- bool open_for_write = file->f_mode & FMODE_WRITE;
struct nvme_ctrl *ctrl = file->private_data;
void __user *argp = (void __user *)arg;
+ unsigned int flags = 0;
+
+ if (file->f_mode & FMODE_WRITE)
+ flags |= NVME_IOCTL_WRITABLE;
switch (cmd) {
case NVME_IOCTL_ADMIN_CMD:
- return nvme_user_cmd(ctrl, NULL, argp, 0, open_for_write);
+ return nvme_user_cmd(ctrl, NULL, argp, flags);
case NVME_IOCTL_ADMIN64_CMD:
- return nvme_user_cmd64(ctrl, NULL, argp, 0, open_for_write);
+ return nvme_user_cmd64(ctrl, NULL, argp, flags);
case NVME_IOCTL_IO_CMD:
- return nvme_dev_user_cmd(ctrl, argp, open_for_write);
+ return nvme_dev_user_cmd(ctrl, argp, flags);
case NVME_IOCTL_RESET:
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
--
2.43.5
next prev parent reply other threads:[~2025-02-24 18:32 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 18:21 [PATCH 0/6] nvme ioctl cleanups Keith Busch
2025-02-24 18:21 ` Keith Busch [this message]
2025-02-24 22:17 ` [PATCH 1/6] nvme-ioctl: fold open_for_write into flags Damien Le Moal
2025-02-24 22:21 ` Chaitanya Kulkarni
2025-02-24 23:10 ` Christoph Hellwig
2025-02-25 9:05 ` Kanchan Joshi
2025-02-24 18:21 ` [PATCH 2/6] nvme-ioctl: use common type for user data addresses Keith Busch
2025-02-24 22:22 ` Damien Le Moal
2025-02-24 22:30 ` Christoph Hellwig
2025-02-24 22:47 ` Keith Busch
2025-02-25 9:07 ` Kanchan Joshi
2025-02-25 14:29 ` Nilay Shroff
2025-02-24 18:21 ` [PATCH 3/6] nvme-ioctl: fold 'vec' into flags Keith Busch
2025-02-24 22:23 ` Damien Le Moal
2025-02-24 22:34 ` Christoph Hellwig
2025-02-25 9:08 ` Kanchan Joshi
2025-02-24 18:21 ` [PATCH 4/6] nvme-ioctl: common user timeout setting Keith Busch
2025-02-24 22:29 ` Damien Le Moal
2025-02-24 22:34 ` Christoph Hellwig
2025-02-25 9:08 ` Kanchan Joshi
2025-02-24 18:21 ` [PATCH 5/6] nvme-ioctl: combine alloc and map Keith Busch
2025-02-24 22:30 ` Damien Le Moal
2025-02-24 22:35 ` Christoph Hellwig
2025-02-25 9:33 ` Kanchan Joshi
2025-02-24 18:21 ` [PATCH 6/6] nvme-ioctl: simplify parameters Keith Busch
2025-02-24 22:32 ` Damien Le Moal
2025-02-24 22:37 ` Christoph Hellwig
2025-02-25 9:35 ` Kanchan Joshi
2025-02-25 0:44 ` [PATCH 0/6] nvme ioctl cleanups Chaitanya Kulkarni
2025-03-03 20:03 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250224182128.2042061-2-kbusch@meta.com \
--to=kbusch@meta.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.