Skip to contentSkip to conversation

Change in reported values of some block integrity sysfs attributes

DISCUSSION M Nikhil 5 participants 10 messages Dec 13, 2024 – Feb 25, 2025

Subsystems (6)
lore
Share & tools
lore

M Nikhil

author
#0 lore raw

Hi Everyone,

* We have observed change in the values of some of the block integrity sysfs attributes for the block devices on the master branch. The sysfs attributes related to block device integrity , write_generate and read_verify are  enabled for the block device when the parameter device_is_integrity_capable is disabled. This behaviour is seen on the scsi disks irrespective of DIF protection enabled or disabled on the disks.

*Logs of the block integrity sysfs attributes for one of the block device:*

a3560030:~ # cat /sys/block/sda/integrity/write_generate

1

a3560030:~ # cat /sys/block/sda/integrity/read_verify

1

a3560030:~ # cat /sys/block/sda/integrity/device_is_integrity_capable

0

* Similarly unexpected values of block integrity sysfs attributes are seen for multipath devices as well. Multipath device reporting value 1 for device_is_integrity_capable even though it is based on SCSI disk devices, which all have 0 for device_is_integrity_capable.

a3560030:~ # cat /sys/block/dm-0/integrity/device_is_integrity_capable

1

a3560030:~ # cat /sys/block/dm-0/integrity/read_verify

1

a3560030:~ # cat /sys/block/dm-0/integrity/write_generate

1

* Earlier the block integrity sysfs parameters "write_generate" and "read_verify" reported value 0 when the sysfs attribute device_is_integrity_capable was not set. But when tested with a recent upstream kernel, there is a change in the block device integrity sysfs attributes.
* In the process of finding the kernel changes which might have caused the change in functionality, we have identified the below commit which was leading to the change in the sysfs attributes. 9f4aa46f2a74 ("block: invert the BLK_INTEGRITY_{GENERATE,VERIFY} flags")
* By reverting the code changes which are part of above commit and when tested the values of attributes read_verify and write_generate were set to 0 which was the older functionality.
* From the description in the patch related to above commit, what we understand is that the changes are meant to invert the block integrity flags(READ_VERIFY and WRITE_GENERATE) vs the values in sysfs for making the user values persistent.
* We would like to know if the change in the values of sysfs attributes write_generate and read_verify is expected?
* And some additional information on in which scenario the attributes will be disabled or set to 0 and the affect of other block integrity attribute device_is_integrity_capable on attributes read_verify and write_generate.

Regards,

*M Nikhil
*

Software Engineer

ISDL, Bangalore, India

Linux on IBM Z and LinuxONE

#1 lore raw

Hi M,

Quoted 9 lines · M Nikhil

Hi Everyone,

* We have observed change in the values of some of the block integrity sysfs attributes for the block devices on the master branch. The sysfs attributes related to block device integrity , write_generate and read_verify are  enabled for the block device when the parameter device_is_integrity_capable is disabled. This behaviour is seen on the scsi disks irrespective of DIF protection enabled or disabled on the disks.

As in after a "echo 1 > /sys/.../device_is_integrity_capable" ?

I'll look into it.

author
#2 lore raw

Hi Christoph,

We did not modify 'device_is_integrity_capable' attribute.

Quoted 16 lines · Christoph Hellwig

Hi M,

Quoted 9 lines · M Nikhil

Hi Everyone,

* We have observed change in the values of some of the block integrity sysfs attributes for the block devices on the master branch. The sysfs attributes related to block device integrity , write_generate and read_verify are  enabled for the block device when the parameter device_is_integrity_capable is disabled. This behaviour is seen on the scsi disks irrespective of DIF protection enabled or disabled on the disks.

As in after a "echo 1 > /sys/.../device_is_integrity_capable" ?

I'll look into it.

#3 lore raw
In reply to M Nikhil
Quoted 4 lines

The sysfs attributes related to block device integrity , write_generate and read_verify are enabled for the block device when the parameter device_is_integrity_capable is disabled.

'device_is_integrity_capable' is set if storage device (media) is formatted with PI.

That is completely orthogonal to 'write_generate' and 'read_verify' which are enabled if the HBA supports DIX. If the HBA supports DIX Type 0, 'write_generate' and 'read_verify' are enabled even if the attached disk is not formatted with PI.

I don't see any change in what's reported with block/for-next in a regular SCSI HBA/disk setup. Will have to look at whether there is a stacking issue wrt. multipathing.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author
#4 lore raw

Thanks for the inputs Martin.

We have observed that even though the HBA does not support DIX Type, still the integrity attributes 'write_generate' and 'read_verify' are set to 1 for the block devices.

a3560030:~ # cat /sys/class/scsi_host/host0/prot_capabilities 0
a3560030:~ # cat /sys/class/scsi_host/host1/prot_capabilities 0

a3560030:~ # cat /sys/block/sdc/integrity/write_generate 1
a3560030:~ # cat /sys/block/sdc/integrity/read_verify 1

Thanks and Regards,

Nikhil

Quoted 15 lines · Martin K. Petersen
Quoted 3 lines

The sysfs attributes related to block device integrity , write_generate and read_verify are enabled for the block device when the parameter device_is_integrity_capable is disabled.

'device_is_integrity_capable' is set if storage device (media) is formatted with PI.

That is completely orthogonal to 'write_generate' and 'read_verify' which are enabled if the HBA supports DIX. If the HBA supports DIX Type 0, 'write_generate' and 'read_verify' are enabled even if the attached disk is not formatted with PI.

I don't see any change in what's reported with block/for-next in a regular SCSI HBA/disk setup. Will have to look at whether there is a stacking issue wrt. multipathing.

author
#5 lore raw

gentle ping!!!

Hopefully I haven't missed anything. I was wondering if you could find out something and if I can provide more information.

#6 lore raw
In reply to Martin K. Petersen
Quoted 3 lines

I don't see any change in what's reported with block/for-next in a regular SCSI HBA/disk setup. Will have to look at whether there is a stacking issue wrt. multipathing.

Hi Martin, Christoph,

It seems this change in behaviour is not limited to SCSI only. As Nikhil mentioned an earlier commit
[9f4aa46f2a74 ("block: invert the BLK_INTEGRITY_{GENERATE,VERIFY} flags")] causes this change in behaviour. On my setup with a NVMe drive not formatted with PI, I see that:

Without this commit:
Value reported by read_verify and write_generate sysfs entries is 0.

With this commit:
Value reported by read_verify and write_generate sysfs entries is 1.

Diving a bit deeper, both these flags got inverted due to this commit. But during init (in nvme_init_integrity) these values get initialized to 0, inturn setting the sysfs entries to 1. In order to fix this, the driver has to initialize both these flags to 1 in nvme_init_integrity if PI is not supported. That way, the value in sysfs for these entries would become 0 again. Tried this approach in my setup, and I am able to see the right values now. Then something like this would also need to be done for SCSI too.

#7 lore raw
Quoted 18 lines · Anuj gupta
Quoted 3 lines

I don't see any change in what's reported with block/for-next in a regular SCSI HBA/disk setup. Will have to look at whether there is a stacking issue wrt. multipathing.

Hi Martin, Christoph,

It seems this change in behaviour is not limited to SCSI only. As Nikhil mentioned an earlier commit
[9f4aa46f2a74 ("block: invert the BLK_INTEGRITY_{GENERATE,VERIFY} flags")] causes this change in behaviour. On my setup with a NVMe drive not formatted with PI, I see that:

Without this commit:
Value reported by read_verify and write_generate sysfs entries is 0.

With this commit:
Value reported by read_verify and write_generate sysfs entries is 1.

Quoted 7 lines

Diving a bit deeper, both these flags got inverted due to this commit. But during init (in nvme_init_integrity) these values get initialized to 0, inturn setting the sysfs entries to 1. In order to fix this, the driver has to initialize both these flags to 1 in nvme_init_integrity if PI is not supported. That way, the value in sysfs for these entries would become 0 again. Tried this approach in my setup, and I am able to see the right values now. Then something like this would also need to be done for SCSI too.

This is the patch that I used:

drivers/nvme/host/core.c +9 -0
index 818d4e49aab5..6cd9f57131cc 100644
@@ -1799,6 +1799,7 @@ static bool nvme_init_integrity(struct nvme_ns_head *head,
 
 	memset(bi, 0, sizeof(*bi));
 
+	bi->flags |= BLK_INTEGRITY_NOGENERATE | BLK_INTEGRITY_NOVERIFY;
 	if (!head->ms)
 		return true;
 
@@ -1817,11 +1818,15 @@ static bool nvme_init_integrity(struct nvme_ns_head *head,
 			bi->csum_type = BLK_INTEGRITY_CSUM_CRC;
 			bi->tag_size = sizeof(u16) + sizeof(u32);
 			bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
+			bi->flags &= ~(BLK_INTEGRITY_NOGENERATE |
+				       BLK_INTEGRITY_NOVERIFY);
 			break;
 		case NVME_NVM_NS_64B_GUARD:
 			bi->csum_type = BLK_INTEGRITY_CSUM_CRC64;
 			bi->tag_size = sizeof(u16) + 6;
 			bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
+			bi->flags &= ~(BLK_INTEGRITY_NOGENERATE |
+				       BLK_INTEGRITY_NOVERIFY);
 			break;
 		default:
 			break;
@@ -1835,12 +1840,16 @@ static bool nvme_init_integrity(struct nvme_ns_head *head,
 			bi->tag_size = sizeof(u16);
 			bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE |
 				     BLK_INTEGRITY_REF_TAG;
+			bi->flags &= ~(BLK_INTEGRITY_NOGENERATE |
+				       BLK_INTEGRITY_NOVERIFY);
 			break;
 		case NVME_NVM_NS_64B_GUARD:
 			bi->csum_type = BLK_INTEGRITY_CSUM_CRC64;
 			bi->tag_size = sizeof(u16);
 			bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE |
 				     BLK_INTEGRITY_REF_TAG;
+			bi->flags &= ~(BLK_INTEGRITY_NOGENERATE |
+				       BLK_INTEGRITY_NOVERIFY);
 			break;
 		default:
 			break;
#8 lore raw
In reply to Anuj gupta
Quoted 18 lines · Anuj gupta
Quoted 3 lines

I don't see any change in what's reported with block/for-next in a regular SCSI HBA/disk setup. Will have to look at whether there is a stacking issue wrt. multipathing.

Hi Martin, Christoph,

It seems this change in behaviour is not limited to SCSI only. As Nikhil mentioned an earlier commit
[9f4aa46f2a74 ("block: invert the BLK_INTEGRITY_{GENERATE,VERIFY} flags")] causes this change in behaviour. On my setup with a NVMe drive not formatted with PI, I see that:

Without this commit:
Value reported by read_verify and write_generate sysfs entries is 0.

With this commit:
Value reported by read_verify and write_generate sysfs entries is 1.

Quoted 8 lines

Diving a bit deeper, both these flags got inverted due to this commit. But during init (in nvme_init_integrity) these values get initialized to 0, inturn setting the sysfs entries to 1. In order to fix this, the driver has to initialize both these flags to 1 in nvme_init_integrity if PI is not supported. That way, the value in sysfs for these entries would become 0 again. Tried this approach in my setup, and I am able to see the right values now. Then something like this would also need to be done for SCSI too.

I tried to make it work for SCSI too. However my testing is limited as I don't have a SCSI device. With scsi_debug I see this currently:

# modprobe scsi_debug dev_size_mb=128 dix=0 dif=0
# cat /sys/block/sda/integrity/write_generate
1
# cat /sys/block/sda/integrity/read_verify
1
# cat /sys/class/scsi_host/host0/prot_capabilities
0

To fix this, I added this. Nikhil can you try below patch? Martin, can you please take a look as well.

After this patch, with the same scsi_debug device, I see sysfs entries populated as 0.

drivers/scsi/sd_dif.c +3 -1
index ae6ce6f5d622..be2cd06f500b 100644
@@ -40,8 +40,10 @@ void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim)
 		dif = 0; dix = 1;
 	}
 
-	if (!dix)
+	if (!dix) {
+		bi->flags |= BLK_INTEGRITY_NOGENERATE | BLK_INTEGRITY_NOVERIFY;
 		return;
+	}
 
 	/* Enable DMA of protection information */
 	if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP)
#9 lore raw

Anuj,

Quoted 7 lines
drivers/scsi/sd_dif.c +0 -0
index ae6ce6f5d622..be2cd06f500b 100644
@@ -40,8 +40,10 @@ void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim)
 		dif = 0; dix = 1;

drivers/scsi/sd_dif.c void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim) · line 49

Quoted 10 lines
drivers/scsi/sd_dif.c +3 -1
 	}
 
-	if (!dix)
+	if (!dix) {
+		bi->flags |= BLK_INTEGRITY_NOGENERATE | BLK_INTEGRITY_NOVERIFY;
 		return;
+	}
 
 	/* Enable DMA of protection information */
 	if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP)

This looks good to me. Originally we didn't register an integrity profile at all unless the device was capable.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering