* [PATCH] nvme-multipath: require exact iopolicy names for module parameter
@ 2026-05-29 8:51 dayou5941
2026-06-01 14:44 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: dayou5941 @ 2026-05-29 8:51 UTC (permalink / raw)
To: kbusch, axboe, hch, sagi; +Cc: linux-nvme, liyouhong
From: liyouhong <liyouhong@kylinos.cn>
The iopolicy module parameter uses strncmp prefix matching, so values
like "numax" are accepted as "numa". The per-subsystem sysfs attribute
already requires an exact match via sysfs_streq(). Parse both through
a shared helper so invalid values are rejected consistently.
Signed-off-by: liyouhong <liyouhong@kylinos.cn>
---
drivers/nvme/host/multipath.c | 40 +++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 263161cb8ac0..ce8dbb741d57 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -73,19 +73,29 @@ static const char *nvme_iopolicy_names[] = {
static int iopolicy = NVME_IOPOLICY_NUMA;
+static int nvme_iopolicy_parse(const char *str)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) {
+ if (sysfs_streq(str, nvme_iopolicy_names[i]))
+ return i;
+ }
+ return -EINVAL;
+}
+
static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)
{
+ int policy;
+
if (!val)
return -EINVAL;
- if (!strncmp(val, "numa", 4))
- iopolicy = NVME_IOPOLICY_NUMA;
- else if (!strncmp(val, "round-robin", 11))
- iopolicy = NVME_IOPOLICY_RR;
- else if (!strncmp(val, "queue-depth", 11))
- iopolicy = NVME_IOPOLICY_QD;
- else
- return -EINVAL;
+ policy = nvme_iopolicy_parse(val);
+ if (policy < 0)
+ return policy;
+
+ iopolicy = policy;
return 0;
}
@@ -1039,16 +1049,14 @@ static ssize_t nvme_subsys_iopolicy_store(struct device *dev,
{
struct nvme_subsystem *subsys =
container_of(dev, struct nvme_subsystem, dev);
- int i;
+ int policy;
- for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) {
- if (sysfs_streq(buf, nvme_iopolicy_names[i])) {
- nvme_subsys_iopolicy_update(subsys, i);
- return count;
- }
- }
+ policy = nvme_iopolicy_parse(buf);
+ if (policy < 0)
+ return policy;
- return -EINVAL;
+ nvme_subsys_iopolicy_update(subsys, policy);
+ return count;
}
SUBSYS_ATTR_RW(iopolicy, S_IRUGO | S_IWUSR,
nvme_subsys_iopolicy_show, nvme_subsys_iopolicy_store);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] nvme-multipath: require exact iopolicy names for module parameter
2026-05-29 8:51 [PATCH] nvme-multipath: require exact iopolicy names for module parameter dayou5941
@ 2026-06-01 14:44 ` Christoph Hellwig
2026-06-01 15:25 ` John Garry
2026-06-02 10:17 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-06-01 14:44 UTC (permalink / raw)
To: dayou5941; +Cc: kbusch, axboe, hch, sagi, linux-nvme, liyouhong
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvme-multipath: require exact iopolicy names for module parameter
2026-05-29 8:51 [PATCH] nvme-multipath: require exact iopolicy names for module parameter dayou5941
2026-06-01 14:44 ` Christoph Hellwig
@ 2026-06-01 15:25 ` John Garry
2026-06-02 10:17 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: John Garry @ 2026-06-01 15:25 UTC (permalink / raw)
To: dayou5941, kbusch, axboe, hch, sagi; +Cc: linux-nvme, liyouhong
On 29/05/2026 09:51, dayou5941@163.com wrote:
> From: liyouhong <liyouhong@kylinos.cn>
>
> The iopolicy module parameter uses strncmp prefix matching, so values
> like "numax" are accepted as "numa". The per-subsystem sysfs attribute
> already requires an exact match via sysfs_streq(). Parse both through
> a shared helper so invalid values are rejected consistently.
>
> Signed-off-by: liyouhong <liyouhong@kylinos.cn>
Feel free to ignore my comments below, FWIW:
Reviewed-by: John Garry <john.g.garry@oracle.com>
> ---> drivers/nvme/host/multipath.c | 40
+++++++++++++++++++++--------------
> 1 file changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 263161cb8ac0..ce8dbb741d57 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -73,19 +73,29 @@ static const char *nvme_iopolicy_names[] = {
>
> static int iopolicy = NVME_IOPOLICY_NUMA;
>
> +static int nvme_iopolicy_parse(const char *str)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) {
> + if (sysfs_streq(str, nvme_iopolicy_names[i]))
> + return i;
> + }
> + return -EINVAL;
This is nearly duplicating __sysfs_match_string
BTW, going slightly off topic, I think that nvme_iopolicy_names could be
made const char *const
> +}
> +
> static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)
> {
> + int policy;
> +
> if (!val)
> return -EINVAL;
> - if (!strncmp(val, "numa", 4))
> - iopolicy = NVME_IOPOLICY_NUMA;
> - else if (!strncmp(val, "round-robin", 11))
> - iopolicy = NVME_IOPOLICY_RR;
> - else if (!strncmp(val, "queue-depth", 11))
> - iopolicy = NVME_IOPOLICY_QD;
> - else
> - return -EINVAL;
>
> + policy = nvme_iopolicy_parse(val);
> + if (policy < 0)
> + return policy;
> +
> + iopolicy = policy;
> return 0;
> }
>
> @@ -1039,16 +1049,14 @@ static ssize_t nvme_subsys_iopolicy_store(struct device *dev,
> {
> struct nvme_subsystem *subsys =
> container_of(dev, struct nvme_subsystem, dev);
> - int i;
> + int policy;
>
> - for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) {
> - if (sysfs_streq(buf, nvme_iopolicy_names[i])) {
> - nvme_subsys_iopolicy_update(subsys, i);
> - return count;
> - }
> - }
> + policy = nvme_iopolicy_parse(buf);
> + if (policy < 0)
> + return policy;
>
> - return -EINVAL;
> + nvme_subsys_iopolicy_update(subsys, policy);
> + return count;
> }
> SUBSYS_ATTR_RW(iopolicy, S_IRUGO | S_IWUSR,
> nvme_subsys_iopolicy_show, nvme_subsys_iopolicy_store);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvme-multipath: require exact iopolicy names for module parameter
2026-05-29 8:51 [PATCH] nvme-multipath: require exact iopolicy names for module parameter dayou5941
2026-06-01 14:44 ` Christoph Hellwig
2026-06-01 15:25 ` John Garry
@ 2026-06-02 10:17 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2026-06-02 10:17 UTC (permalink / raw)
To: dayou5941; +Cc: axboe, hch, sagi, linux-nvme, liyouhong
On Fri, May 29, 2026 at 04:51:43PM +0800, dayou5941@163.com wrote:
> From: liyouhong <liyouhong@kylinos.cn>
>
> The iopolicy module parameter uses strncmp prefix matching, so values
> like "numax" are accepted as "numa". The per-subsystem sysfs attribute
> already requires an exact match via sysfs_streq(). Parse both through
> a shared helper so invalid values are rejected consistently.
Thanks, applied to nvme-7.2.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-02 10:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 8:51 [PATCH] nvme-multipath: require exact iopolicy names for module parameter dayou5941
2026-06-01 14:44 ` Christoph Hellwig
2026-06-01 15:25 ` John Garry
2026-06-02 10:17 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox