Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] nvme: expose active quirks in sysfs
@ 2025-11-03 14:44 Maurizio Lombardi
  2025-11-03 20:29 ` Chaitanya Kulkarni
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Maurizio Lombardi @ 2025-11-03 14:44 UTC (permalink / raw)
  To: kbusch; +Cc: mlombard, bgurney, bvanassche, linux-nvme

Currently, there is no straightforward way for a user to inspect
which quirks are active for a given device from userspace.

Add a new "quirks" sysfs attribute to the nvme controller device.

Reading this file will display a human-readable list
of all active quirks, with each quirk name on a new line.
If no quirks are active, it will display "none".

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---

V2: Do not expose kernel-internal constants to userspace.
    Move the quirks attribute to the controller device, where it belongs.

 drivers/nvme/host/nvme.h  | 54 +++++++++++++++++++++++++++++++++++++++
 drivers/nvme/host/sysfs.c | 23 +++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 102fae6a231c..647f19dd57e9 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -180,6 +180,60 @@ enum nvme_quirks {
 	NVME_QUIRK_DMAPOOL_ALIGN_512		= (1 << 22),
 };
 
+static inline char *nvme_quirk_name(enum nvme_quirks q)
+{
+	switch (q) {
+	case NVME_QUIRK_STRIPE_SIZE:
+		return "stripe_size";
+	case NVME_QUIRK_IDENTIFY_CNS:
+		return "identify_cns";
+	case NVME_QUIRK_DEALLOCATE_ZEROES:
+		return "deallocate_zeroes";
+	case NVME_QUIRK_DELAY_BEFORE_CHK_RDY:
+		return "delay_before_chk_rdy";
+	case NVME_QUIRK_NO_APST:
+		return "no_apst";
+	case NVME_QUIRK_NO_DEEPEST_PS:
+		return "no_deepest_ps";
+	case NVME_QUIRK_QDEPTH_ONE:
+		return "qdepth_one";
+	case NVME_QUIRK_MEDIUM_PRIO_SQ:
+		return "medium_prio_sq";
+	case NVME_QUIRK_IGNORE_DEV_SUBNQN:
+		return "ignore_dev_subnqn";
+	case NVME_QUIRK_DISABLE_WRITE_ZEROES:
+		return "disable_write_zeroes";
+	case NVME_QUIRK_SIMPLE_SUSPEND:
+		return "simple_suspend";
+	case NVME_QUIRK_SINGLE_VECTOR:
+		return "single_vector";
+	case NVME_QUIRK_128_BYTES_SQES:
+		return "128_bytes_sqes";
+	case NVME_QUIRK_SHARED_TAGS:
+		return "shared_tags";
+	case NVME_QUIRK_NO_TEMP_THRESH_CHANGE:
+		return "no_temp_thresh_change";
+	case NVME_QUIRK_NO_NS_DESC_LIST:
+		return "no_ns_desc_list";
+	case NVME_QUIRK_DMA_ADDRESS_BITS_48:
+		return "dma_address_bits_48";
+	case NVME_QUIRK_SKIP_CID_GEN:
+		return "skip_cid_gen";
+	case NVME_QUIRK_BOGUS_NID:
+		return "bogus_nid";
+	case NVME_QUIRK_NO_SECONDARY_TEMP_THRESH:
+		return "no_secondary_temp_thresh";
+	case NVME_QUIRK_FORCE_NO_SIMPLE_SUSPEND:
+		return "force_no_simple_suspend";
+	case NVME_QUIRK_BROKEN_MSI:
+		return "broken_msi";
+	case NVME_QUIRK_DMAPOOL_ALIGN_512:
+		return "dmapool_align_512";
+	}
+
+	return "unknown";
+}
+
 /*
  * Common request structure for NVMe passthrough.  All drivers must have
  * this structure as the first member of their request-private data.
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 29430949ce2f..16c6fea4b2db 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -601,6 +601,28 @@ static ssize_t dctype_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(dctype);
 
+static ssize_t quirks_show(struct device *dev, struct device_attribute *attr,
+                char *buf)
+{
+	int count = 0, i;
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	unsigned long quirks = ctrl->quirks;
+
+	if (!quirks)
+		return sysfs_emit(buf, "none\n");
+
+	for (i = 0; quirks; ++i) {
+		if (quirks & 1) {
+			count += sysfs_emit_at(buf, count, "%s\n",
+					nvme_quirk_name(BIT(i)));
+		}
+		quirks >>= 1;
+	}
+
+	return count;
+}
+static DEVICE_ATTR_RO(quirks);
+
 #ifdef CONFIG_NVME_HOST_AUTH
 static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -742,6 +764,7 @@ static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_kato.attr,
 	&dev_attr_cntrltype.attr,
 	&dev_attr_dctype.attr,
+	&dev_attr_quirks.attr,
 #ifdef CONFIG_NVME_HOST_AUTH
 	&dev_attr_dhchap_secret.attr,
 	&dev_attr_dhchap_ctrl_secret.attr,
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
@ 2025-11-03 20:29 ` Chaitanya Kulkarni
  2025-11-05  3:05 ` Martin K. Petersen
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-03 20:29 UTC (permalink / raw)
  To: Maurizio Lombardi, kbusch@kernel.org
  Cc: mlombard@bsdbackstore.eu, bgurney@redhat.com, bvanassche@acm.org,
	linux-nvme@lists.infradead.org

On 11/3/25 06:44, Maurizio Lombardi wrote:
> Currently, there is no straightforward way for a user to inspect
> which quirks are active for a given device from userspace.
>
> Add a new "quirks" sysfs attribute to the nvme controller device.
>
> Reading this file will display a human-readable list
> of all active quirks, with each quirk name on a new line.
> If no quirks are active, it will display "none".
>
> Signed-off-by: Maurizio Lombardi<mlombard@redhat.com>
> ---

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
  2025-11-03 20:29 ` Chaitanya Kulkarni
@ 2025-11-05  3:05 ` Martin K. Petersen
  2025-11-17 22:12 ` John Meneghini
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2025-11-05  3:05 UTC (permalink / raw)
  To: Maurizio Lombardi; +Cc: kbusch, mlombard, bgurney, bvanassche, linux-nvme


Maurizio,

> Currently, there is no straightforward way for a user to inspect which
> quirks are active for a given device from userspace.
>
> Add a new "quirks" sysfs attribute to the nvme controller device.
>
> Reading this file will display a human-readable list of all active
> quirks, with each quirk name on a new line. If no quirks are active,
> it will display "none".

Looks OK to me.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
  2025-11-03 20:29 ` Chaitanya Kulkarni
  2025-11-05  3:05 ` Martin K. Petersen
@ 2025-11-17 22:12 ` John Meneghini
  2025-11-18  1:46   ` Chaitanya Kulkarni
  2025-11-30 23:09 ` Sagi Grimberg
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: John Meneghini @ 2025-11-17 22:12 UTC (permalink / raw)
  To: Maurizio Lombardi, kbusch; +Cc: mlombard, bgurney, bvanassche, linux-nvme

Reviewed-by: John Meneghini <jmeneghi@redhat.com>
Tested-by: John Meneghini <jmeneghi@redhat.com>

Looks good to me. Testing this on my VM shows the correct quirk information for both

   -device nvme,use-intel-id=on and
   -device nvme,use-intel-id=off

root@target-vm:~# grep . /sys/class/nvme/nvme0/quirk* /sys/class/nvme/nvme0/device/{vendor,device}
/sys/class/nvme/nvme0/quirks:0x00040202
/sys/class/nvme/nvme0/device/vendor:0x8086
/sys/class/nvme/nvme0/device/device:0x5845
root@target-vm:~# grep . /sys/class/nvme/nvme1/quirk* /sys/class/nvme/nvme1/device/{vendor,device}
/sys/class/nvme/nvme1/quirks:0x00040000
/sys/class/nvme/nvme1/device/vendor:0x1b36
/sys/class/nvme/nvme1/device/device:0x0010

Keith, please merge this patch.

/John

On 11/3/25 9:44 AM, Maurizio Lombardi wrote:
> Currently, there is no straightforward way for a user to inspect
> which quirks are active for a given device from userspace.
> 
> Add a new "quirks" sysfs attribute to the nvme controller device.
> 
> Reading this file will display a human-readable list
> of all active quirks, with each quirk name on a new line.
> If no quirks are active, it will display "none".
> 
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> ---
> 
> V2: Do not expose kernel-internal constants to userspace.
>      Move the quirks attribute to the controller device, where it belongs.
> 
>   drivers/nvme/host/nvme.h  | 54 +++++++++++++++++++++++++++++++++++++++
>   drivers/nvme/host/sysfs.c | 23 +++++++++++++++++
>   2 files changed, 77 insertions(+)
> 
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 102fae6a231c..647f19dd57e9 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -180,6 +180,60 @@ enum nvme_quirks {
>   	NVME_QUIRK_DMAPOOL_ALIGN_512		= (1 << 22),
>   };
>   
> +static inline char *nvme_quirk_name(enum nvme_quirks q)
> +{
> +	switch (q) {
> +	case NVME_QUIRK_STRIPE_SIZE:
> +		return "stripe_size";
> +	case NVME_QUIRK_IDENTIFY_CNS:
> +		return "identify_cns";
> +	case NVME_QUIRK_DEALLOCATE_ZEROES:
> +		return "deallocate_zeroes";
> +	case NVME_QUIRK_DELAY_BEFORE_CHK_RDY:
> +		return "delay_before_chk_rdy";
> +	case NVME_QUIRK_NO_APST:
> +		return "no_apst";
> +	case NVME_QUIRK_NO_DEEPEST_PS:
> +		return "no_deepest_ps";
> +	case NVME_QUIRK_QDEPTH_ONE:
> +		return "qdepth_one";
> +	case NVME_QUIRK_MEDIUM_PRIO_SQ:
> +		return "medium_prio_sq";
> +	case NVME_QUIRK_IGNORE_DEV_SUBNQN:
> +		return "ignore_dev_subnqn";
> +	case NVME_QUIRK_DISABLE_WRITE_ZEROES:
> +		return "disable_write_zeroes";
> +	case NVME_QUIRK_SIMPLE_SUSPEND:
> +		return "simple_suspend";
> +	case NVME_QUIRK_SINGLE_VECTOR:
> +		return "single_vector";
> +	case NVME_QUIRK_128_BYTES_SQES:
> +		return "128_bytes_sqes";
> +	case NVME_QUIRK_SHARED_TAGS:
> +		return "shared_tags";
> +	case NVME_QUIRK_NO_TEMP_THRESH_CHANGE:
> +		return "no_temp_thresh_change";
> +	case NVME_QUIRK_NO_NS_DESC_LIST:
> +		return "no_ns_desc_list";
> +	case NVME_QUIRK_DMA_ADDRESS_BITS_48:
> +		return "dma_address_bits_48";
> +	case NVME_QUIRK_SKIP_CID_GEN:
> +		return "skip_cid_gen";
> +	case NVME_QUIRK_BOGUS_NID:
> +		return "bogus_nid";
> +	case NVME_QUIRK_NO_SECONDARY_TEMP_THRESH:
> +		return "no_secondary_temp_thresh";
> +	case NVME_QUIRK_FORCE_NO_SIMPLE_SUSPEND:
> +		return "force_no_simple_suspend";
> +	case NVME_QUIRK_BROKEN_MSI:
> +		return "broken_msi";
> +	case NVME_QUIRK_DMAPOOL_ALIGN_512:
> +		return "dmapool_align_512";
> +	}
> +
> +	return "unknown";
> +}
> +
>   /*
>    * Common request structure for NVMe passthrough.  All drivers must have
>    * this structure as the first member of their request-private data.
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 29430949ce2f..16c6fea4b2db 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -601,6 +601,28 @@ static ssize_t dctype_show(struct device *dev,
>   }
>   static DEVICE_ATTR_RO(dctype);
>   
> +static ssize_t quirks_show(struct device *dev, struct device_attribute *attr,
> +                char *buf)
> +{
> +	int count = 0, i;
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	unsigned long quirks = ctrl->quirks;
> +
> +	if (!quirks)
> +		return sysfs_emit(buf, "none\n");
> +
> +	for (i = 0; quirks; ++i) {
> +		if (quirks & 1) {
> +			count += sysfs_emit_at(buf, count, "%s\n",
> +					nvme_quirk_name(BIT(i)));
> +		}
> +		quirks >>= 1;
> +	}
> +
> +	return count;
> +}
> +static DEVICE_ATTR_RO(quirks);
> +
>   #ifdef CONFIG_NVME_HOST_AUTH
>   static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,
>   		struct device_attribute *attr, char *buf)
> @@ -742,6 +764,7 @@ static struct attribute *nvme_dev_attrs[] = {
>   	&dev_attr_kato.attr,
>   	&dev_attr_cntrltype.attr,
>   	&dev_attr_dctype.attr,
> +	&dev_attr_quirks.attr,
>   #ifdef CONFIG_NVME_HOST_AUTH
>   	&dev_attr_dhchap_secret.attr,
>   	&dev_attr_dhchap_ctrl_secret.attr,



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-17 22:12 ` John Meneghini
@ 2025-11-18  1:46   ` Chaitanya Kulkarni
  0 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-18  1:46 UTC (permalink / raw)
  To: John Meneghini, Maurizio Lombardi, kbusch@kernel.org
  Cc: mlombard@bsdbackstore.eu, bgurney@redhat.com, bvanassche@acm.org,
	linux-nvme@lists.infradead.org

On 11/17/25 14:12, John Meneghini wrote:
> Reviewed-by: John Meneghini <jmeneghi@redhat.com>
> Tested-by: John Meneghini <jmeneghi@redhat.com>
>
> Looks good to me. Testing this on my VM shows the correct quirk 
> information for both
>
>   -device nvme,use-intel-id=on and
>   -device nvme,use-intel-id=off
>
> root@target-vm:~# grep . /sys/class/nvme/nvme0/quirk* 
> /sys/class/nvme/nvme0/device/{vendor,device}
> /sys/class/nvme/nvme0/quirks:0x00040202
> /sys/class/nvme/nvme0/device/vendor:0x8086
> /sys/class/nvme/nvme0/device/device:0x5845
> root@target-vm:~# grep . /sys/class/nvme/nvme1/quirk* 
> /sys/class/nvme/nvme1/device/{vendor,device}
> /sys/class/nvme/nvme1/quirks:0x00040000
> /sys/class/nvme/nvme1/device/vendor:0x1b36
> /sys/class/nvme/nvme1/device/device:0x0010
>
> Keith, please merge this patch.
>
> /John
>
> On 11/3/25 9:44 AM, Maurizio Lombardi wrote:
>> Currently, there is no straightforward way for a user to inspect
>> which quirks are active for a given device from userspace.
>>
>> Add a new "quirks" sysfs attribute to the nvme controller device.
>>
>> Reading this file will display a human-readable list
>> of all active quirks, with each quirk name on a new line.
>> If no quirks are active, it will display "none".
>>
>> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>

It will be nice to merge this if there are no major objections.

-ck



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
                   ` (2 preceding siblings ...)
  2025-11-17 22:12 ` John Meneghini
@ 2025-11-30 23:09 ` Sagi Grimberg
  2025-12-09 22:02 ` Maurizio Lombardi
  2026-01-13 21:53 ` Keith Busch
  5 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2025-11-30 23:09 UTC (permalink / raw)
  To: Maurizio Lombardi, kbusch; +Cc: mlombard, bgurney, bvanassche, linux-nvme



On 03/11/2025 16:44, Maurizio Lombardi wrote:
> Currently, there is no straightforward way for a user to inspect
> which quirks are active for a given device from userspace.
>
> Add a new "quirks" sysfs attribute to the nvme controller device.
>
> Reading this file will display a human-readable list
> of all active quirks, with each quirk name on a new line.
> If no quirks are active, it will display "none".
>
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> ---
>
> V2: Do not expose kernel-internal constants to userspace.
>      Move the quirks attribute to the controller device, where it belongs.
>
>   drivers/nvme/host/nvme.h  | 54 +++++++++++++++++++++++++++++++++++++++
>   drivers/nvme/host/sysfs.c | 23 +++++++++++++++++
>   2 files changed, 77 insertions(+)
>
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 102fae6a231c..647f19dd57e9 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -180,6 +180,60 @@ enum nvme_quirks {
>   	NVME_QUIRK_DMAPOOL_ALIGN_512		= (1 << 22),
>   };
>   
> +static inline char *nvme_quirk_name(enum nvme_quirks q)
> +{
> +	switch (q) {
> +	case NVME_QUIRK_STRIPE_SIZE:
> +		return "stripe_size";
> +	case NVME_QUIRK_IDENTIFY_CNS:
> +		return "identify_cns";
> +	case NVME_QUIRK_DEALLOCATE_ZEROES:
> +		return "deallocate_zeroes";
> +	case NVME_QUIRK_DELAY_BEFORE_CHK_RDY:
> +		return "delay_before_chk_rdy";
> +	case NVME_QUIRK_NO_APST:
> +		return "no_apst";
> +	case NVME_QUIRK_NO_DEEPEST_PS:
> +		return "no_deepest_ps";
> +	case NVME_QUIRK_QDEPTH_ONE:
> +		return "qdepth_one";
> +	case NVME_QUIRK_MEDIUM_PRIO_SQ:
> +		return "medium_prio_sq";
> +	case NVME_QUIRK_IGNORE_DEV_SUBNQN:
> +		return "ignore_dev_subnqn";
> +	case NVME_QUIRK_DISABLE_WRITE_ZEROES:
> +		return "disable_write_zeroes";
> +	case NVME_QUIRK_SIMPLE_SUSPEND:
> +		return "simple_suspend";
> +	case NVME_QUIRK_SINGLE_VECTOR:
> +		return "single_vector";
> +	case NVME_QUIRK_128_BYTES_SQES:
> +		return "128_bytes_sqes";
> +	case NVME_QUIRK_SHARED_TAGS:
> +		return "shared_tags";
> +	case NVME_QUIRK_NO_TEMP_THRESH_CHANGE:
> +		return "no_temp_thresh_change";
> +	case NVME_QUIRK_NO_NS_DESC_LIST:
> +		return "no_ns_desc_list";
> +	case NVME_QUIRK_DMA_ADDRESS_BITS_48:
> +		return "dma_address_bits_48";
> +	case NVME_QUIRK_SKIP_CID_GEN:
> +		return "skip_cid_gen";
> +	case NVME_QUIRK_BOGUS_NID:
> +		return "bogus_nid";
> +	case NVME_QUIRK_NO_SECONDARY_TEMP_THRESH:
> +		return "no_secondary_temp_thresh";
> +	case NVME_QUIRK_FORCE_NO_SIMPLE_SUSPEND:
> +		return "force_no_simple_suspend";
> +	case NVME_QUIRK_BROKEN_MSI:
> +		return "broken_msi";
> +	case NVME_QUIRK_DMAPOOL_ALIGN_512:
> +		return "dmapool_align_512";
> +	}
> +
> +	return "unknown";

How about simply print the value/bit in this case?

Other than that, looks fine,
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
                   ` (3 preceding siblings ...)
  2025-11-30 23:09 ` Sagi Grimberg
@ 2025-12-09 22:02 ` Maurizio Lombardi
  2026-01-13 21:53 ` Keith Busch
  5 siblings, 0 replies; 8+ messages in thread
From: Maurizio Lombardi @ 2025-12-09 22:02 UTC (permalink / raw)
  To: Maurizio Lombardi, kbusch; +Cc: bgurney, bvanassche, linux-nvme

Hello Keith,

What do you think about this patch? Would you merge it?

Thanks,
Maurizio


On Mon Nov 3, 2025 at 3:44 PM CET, Maurizio Lombardi wrote:
> Currently, there is no straightforward way for a user to inspect
> which quirks are active for a given device from userspace.
>
> Add a new "quirks" sysfs attribute to the nvme controller device.
>
> Reading this file will display a human-readable list
> of all active quirks, with each quirk name on a new line.
> If no quirks are active, it will display "none".
>
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> ---
>
> V2: Do not expose kernel-internal constants to userspace.
>     Move the quirks attribute to the controller device, where it belongs.
>
>  drivers/nvme/host/nvme.h  | 54 +++++++++++++++++++++++++++++++++++++++
>  drivers/nvme/host/sysfs.c | 23 +++++++++++++++++
>  2 files changed, 77 insertions(+)
>
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 102fae6a231c..647f19dd57e9 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -180,6 +180,60 @@ enum nvme_quirks {
>  	NVME_QUIRK_DMAPOOL_ALIGN_512		= (1 << 22),
>  };
>  
> +static inline char *nvme_quirk_name(enum nvme_quirks q)
> +{
> +	switch (q) {
> +	case NVME_QUIRK_STRIPE_SIZE:
> +		return "stripe_size";
> +	case NVME_QUIRK_IDENTIFY_CNS:
> +		return "identify_cns";
> +	case NVME_QUIRK_DEALLOCATE_ZEROES:
> +		return "deallocate_zeroes";
> +	case NVME_QUIRK_DELAY_BEFORE_CHK_RDY:
> +		return "delay_before_chk_rdy";
> +	case NVME_QUIRK_NO_APST:
> +		return "no_apst";
> +	case NVME_QUIRK_NO_DEEPEST_PS:
> +		return "no_deepest_ps";
> +	case NVME_QUIRK_QDEPTH_ONE:
> +		return "qdepth_one";
> +	case NVME_QUIRK_MEDIUM_PRIO_SQ:
> +		return "medium_prio_sq";
> +	case NVME_QUIRK_IGNORE_DEV_SUBNQN:
> +		return "ignore_dev_subnqn";
> +	case NVME_QUIRK_DISABLE_WRITE_ZEROES:
> +		return "disable_write_zeroes";
> +	case NVME_QUIRK_SIMPLE_SUSPEND:
> +		return "simple_suspend";
> +	case NVME_QUIRK_SINGLE_VECTOR:
> +		return "single_vector";
> +	case NVME_QUIRK_128_BYTES_SQES:
> +		return "128_bytes_sqes";
> +	case NVME_QUIRK_SHARED_TAGS:
> +		return "shared_tags";
> +	case NVME_QUIRK_NO_TEMP_THRESH_CHANGE:
> +		return "no_temp_thresh_change";
> +	case NVME_QUIRK_NO_NS_DESC_LIST:
> +		return "no_ns_desc_list";
> +	case NVME_QUIRK_DMA_ADDRESS_BITS_48:
> +		return "dma_address_bits_48";
> +	case NVME_QUIRK_SKIP_CID_GEN:
> +		return "skip_cid_gen";
> +	case NVME_QUIRK_BOGUS_NID:
> +		return "bogus_nid";
> +	case NVME_QUIRK_NO_SECONDARY_TEMP_THRESH:
> +		return "no_secondary_temp_thresh";
> +	case NVME_QUIRK_FORCE_NO_SIMPLE_SUSPEND:
> +		return "force_no_simple_suspend";
> +	case NVME_QUIRK_BROKEN_MSI:
> +		return "broken_msi";
> +	case NVME_QUIRK_DMAPOOL_ALIGN_512:
> +		return "dmapool_align_512";
> +	}
> +
> +	return "unknown";
> +}
> +
>  /*
>   * Common request structure for NVMe passthrough.  All drivers must have
>   * this structure as the first member of their request-private data.
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 29430949ce2f..16c6fea4b2db 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -601,6 +601,28 @@ static ssize_t dctype_show(struct device *dev,
>  }
>  static DEVICE_ATTR_RO(dctype);
>  
> +static ssize_t quirks_show(struct device *dev, struct device_attribute *attr,
> +                char *buf)
> +{
> +	int count = 0, i;
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	unsigned long quirks = ctrl->quirks;
> +
> +	if (!quirks)
> +		return sysfs_emit(buf, "none\n");
> +
> +	for (i = 0; quirks; ++i) {
> +		if (quirks & 1) {
> +			count += sysfs_emit_at(buf, count, "%s\n",
> +					nvme_quirk_name(BIT(i)));
> +		}
> +		quirks >>= 1;
> +	}
> +
> +	return count;
> +}
> +static DEVICE_ATTR_RO(quirks);
> +
>  #ifdef CONFIG_NVME_HOST_AUTH
>  static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,
>  		struct device_attribute *attr, char *buf)
> @@ -742,6 +764,7 @@ static struct attribute *nvme_dev_attrs[] = {
>  	&dev_attr_kato.attr,
>  	&dev_attr_cntrltype.attr,
>  	&dev_attr_dctype.attr,
> +	&dev_attr_quirks.attr,
>  #ifdef CONFIG_NVME_HOST_AUTH
>  	&dev_attr_dhchap_secret.attr,
>  	&dev_attr_dhchap_ctrl_secret.attr,



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] nvme: expose active quirks in sysfs
  2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
                   ` (4 preceding siblings ...)
  2025-12-09 22:02 ` Maurizio Lombardi
@ 2026-01-13 21:53 ` Keith Busch
  5 siblings, 0 replies; 8+ messages in thread
From: Keith Busch @ 2026-01-13 21:53 UTC (permalink / raw)
  To: Maurizio Lombardi; +Cc: mlombard, bgurney, bvanassche, linux-nvme

On Mon, Nov 03, 2025 at 03:44:06PM +0100, Maurizio Lombardi wrote:
> Currently, there is no straightforward way for a user to inspect
> which quirks are active for a given device from userspace.
> 
> Add a new "quirks" sysfs attribute to the nvme controller device.
> 
> Reading this file will display a human-readable list
> of all active quirks, with each quirk name on a new line.
> If no quirks are active, it will display "none".

Thanks, applied to nvme-7.0.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-01-13 21:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 14:44 [PATCH V2] nvme: expose active quirks in sysfs Maurizio Lombardi
2025-11-03 20:29 ` Chaitanya Kulkarni
2025-11-05  3:05 ` Martin K. Petersen
2025-11-17 22:12 ` John Meneghini
2025-11-18  1:46   ` Chaitanya Kulkarni
2025-11-30 23:09 ` Sagi Grimberg
2025-12-09 22:02 ` Maurizio Lombardi
2026-01-13 21:53 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox