Skip to contentSkip to conversation

scsi_debug: Make CRC_T10DIF support optional

PATCH In review Bart Van Assche 3 participants 8 messages Mar 5, 2024 – Mar 11, 2024 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi_debug: Make CRC_T10DIF support optional

Not all scsi_debug users need data integrity support. Hence modify the scsi_debug driver such that it becomes possible to build this driver without data integrity support. The changes in this patch are as follows:
- Split the scsi_debug source code into two files without modifying any functionality.
- Instead of selecting CRC_T10DIF no matter how the scsi_debug driver is built, only select CRC_T10DIF if the scsi_debug driver is built-in to the kernel.

Cc Douglas Gilbert <[email protected]>
Cc John Garry <[email protected]>

---

Changes compared with v1: made the patch description more detailed.

 drivers/scsi/Kconfig                          |   2 +-
 drivers/scsi/Makefile                         |   2 +
 drivers/scsi/scsi_debug-dif.h                 |  65 +++++
 drivers/scsi/scsi_debug_dif.c                 | 224 +++++++++++++++
 .../scsi/{scsi_debug.c => scsi_debug_main.c}  | 257 ++----------------
 5 files changed, 308 insertions(+), 242 deletions(-)
 create mode 100644 drivers/scsi/scsi_debug-dif.h
 create mode 100644 drivers/scsi/scsi_debug_dif.c
 rename drivers/scsi/{scsi_debug.c => scsi_debug_main.c} (97%)
drivers/scsi/Kconfig +1 -1
index 3328052c8715..b7c92d7af73d 100644
@@ -1227,7 +1227,7 @@ config SCSI_WD719X
 config SCSI_DEBUG
 	tristate "SCSI debugging host and device simulator"
 	depends on SCSI
-	select CRC_T10DIF
+	select CRC_T10DIF if SCSI_DEBUG = y
 	help
 	  This pseudo driver simulates one or more hosts (SCSI initiators),
 	  each with one or more targets, each with one or more logical units.
drivers/scsi/Makefile +2 -0
index 1313ddf2fd1a..6287d9d65f04 100644
@@ -156,6 +156,8 @@ obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas/
 
 # This goes last, so that "real" scsi devices probe earlier
 obj-$(CONFIG_SCSI_DEBUG)	+= scsi_debug.o
+scsi_debug-y			+= scsi_debug_main.o
+scsi_debug-$(CONFIG_CRC_T10DIF) += scsi_debug_dif.o
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o \
 				   scsicam.o scsi_error.o scsi_lib.o
 scsi_mod-$(CONFIG_SCSI_CONSTANTS) += constants.o
drivers/scsi/scsi_debug-dif.h new file +65 -0

65 lines not on this page · raw message

drivers/scsi/scsi_debug_dif.c new file +224 -0

224 lines not on this page · raw message

drivers/scsi/scsi_debug_main.c renamed from drivers/scsi/scsi_debug.c +16 -241

359 lines not on this page · raw message

#1 lore raw
Quoted 14 lines · Bart Van Assche

Not all scsi_debug users need data integrity support. Hence modify the scsi_debug driver such that it becomes possible to build this driver without data integrity support. The changes in this patch are as follows:
- Split the scsi_debug source code into two files without modifying any functionality.
- Instead of selecting CRC_T10DIF no matter how the scsi_debug driver is built, only select CRC_T10DIF if the scsi_debug driver is built-in to the kernel.

Cc Douglas Gilbert <[email protected]>
Cc John Garry <[email protected]>
Quoted 8 lines

---

Changes compared with v1: made the patch description more detailed.

  drivers/scsi/Kconfig                          |   2 +-
  drivers/scsi/Makefile                         |   2 +
  drivers/scsi/scsi_debug-dif.h                 |  65 +++++
  drivers/scsi/scsi_debug_dif.c                 | 224 +++++++++++++++

inconsistent filename format: scsi_debug-dif.c vs scsi_debug_dif.h - is that intentional?

Quoted 11 lines
  .../scsi/{scsi_debug.c => scsi_debug_main.c}  | 257 ++----------------
  5 files changed, 308 insertions(+), 242 deletions(-)

create mode 100644 drivers/scsi/scsi_debug-dif.h create mode 100644 drivers/scsi/scsi_debug_dif.c rename drivers/scsi/{scsi_debug.c => scsi_debug_main.c} (97%)

drivers/scsi/Kconfig +0 -0
index 3328052c8715..b7c92d7af73d 100644

drivers/scsi/Kconfig config SCSI_WD719X · line 1230

Quoted 5 lines
drivers/scsi/Kconfig +1 -1
@@ -1227,7 +1227,7 @@ config SCSI_WD719X
  config SCSI_DEBUG
  	tristate "SCSI debugging host and device simulator"
  	depends on SCSI
-	select CRC_T10DIF
+	select CRC_T10DIF if SCSI_DEBUG = y

Do we really need to select at all now? What does this buy us? Preference is generally not to use select.

Quoted 22 lines
drivers/scsi/Kconfig +0 -0
  	help
  	  This pseudo driver simulates one or more hosts (SCSI initiators),
  	  each with one or more targets, each with one or more logical units.
drivers/scsi/Makefile +2 -0
index 1313ddf2fd1a..6287d9d65f04 100644
@@ -156,6 +156,8 @@ obj-$(CONFIG_SCSI_HISI_SAS) += hisi_sas/
 
  # This goes last, so that "real" scsi devices probe earlier
  obj-$(CONFIG_SCSI_DEBUG)	+= scsi_debug.o
+scsi_debug-y			+= scsi_debug_main.o
+scsi_debug-$(CONFIG_CRC_T10DIF) += scsi_debug_dif.o
  scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o \
  				   scsicam.o scsi_error.o scsi_lib.o
  scsi_mod-$(CONFIG_SCSI_CONSTANTS) += constants.o
drivers/scsi/scsi_debug-dif.h new file +0 -0
new file mode 100644
index 000000000000..d1d9e57b528b

drivers/scsi/scsi_debug-dif.h line 9

Quoted 9 lines
drivers/scsi/scsi_debug-dif.h new file +9 -0
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SCSI_DEBUG_DIF_H
+#define _SCSI_DEBUG_DIF_H
+
+#include <linux/kconfig.h>
+#include <linux/types.h>
+#include <linux/spinlock_types.h>
+
+struct scsi_cmnd;

Do you really need to have a prototype for this? I'm a bit in shock seeing this in a scsi low-level driver.

drivers/scsi/scsi_debug-dif.h line 10

Quoted 1 line
drivers/scsi/scsi_debug-dif.h new file +1 -0
+struct sdebug_dev_info;

How is this specific to dif? This should be defined in a common header file if used by both scsi_debug_main.c and scsi_debug_dif.c

drivers/scsi/scsi_debug-dif.h line 13

Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +3 -0
+struct t10_pi_tuple;
+
+extern int dix_writes;

For whos benefit is this in a dif header file?

dix_writes is defined in main.c, so surely this extern needs to be in scsi_debug_dif.c or a common header

For me, I would actually just declare this in scsi_debug_dif.c and have scsi_debug_dif_get_dix_writes() or similar to return this value. This function would be stubbed for CONFIG_CRC_T10DIF=n

drivers/scsi/scsi_debug-dif.h line 21

Quoted 8 lines
drivers/scsi/scsi_debug-dif.h new file +8 -0
+extern int dix_reads;
+extern int dif_errors;
+extern struct xarray *const per_store_ap;
+extern int sdebug_dif;
+extern int sdebug_dix;
+extern unsigned int sdebug_guard;
+extern int sdebug_sector_size;
+extern unsigned int sdebug_store_sectors;

I doubt why all these are here

drivers/scsi/scsi_debug-dif.h line 24

Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +3 -0
+
+/* There is an xarray of pointers to this struct's objects, one per host */
+struct sdeb_store_info {

this is not specific to dif, yet in a dif header

drivers/scsi/scsi_debug-dif.h line 37

Quoted 13 lines
drivers/scsi/scsi_debug-dif.h new file +13 -0
+	rwlock_t macc_lck;	/* for atomic media access on this store */
+	u8 *storep;		/* user data storage (ram) */
+	struct t10_pi_tuple *dif_storep; /* protection info */
+	void *map_storep;	/* provisioning map */
+};
+
+struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip,
+				  bool bug_if_fake_rw);
+
+#if IS_ENABLED(CONFIG_CRC_T10DIF)
+
+int dif_verify(struct t10_pi_tuple *sdt, const void *data, sector_t sector,
+	       u32 ei_lba);

Is this actually used in main.c?

I do also notice that we have chunks of code in main.c that does PI checking, like in resp_write_scat() - surely dif stuff should be in dif.c now

drivers/scsi/scsi_debug-dif.h line 48

Quoted 11 lines
drivers/scsi/scsi_debug-dif.h new file +11 -0
+int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec,
+		     unsigned int sectors, u32 ei_lba);
+int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
+		      unsigned int sectors, u32 ei_lba);
+
+#else /* CONFIG_CRC_T10DIF */
+
+static inline int dif_verify(struct t10_pi_tuple *sdt, const void *data,
+			     sector_t sector, u32 ei_lba)
+{
+	return 0x01; /*GUARD check failed*/

leave space before and after /* and */

Quoted 23 lines
drivers/scsi/scsi_debug-dif.h new file +17 -0
+}
+
+static inline int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec,
+				   unsigned int sectors, u32 ei_lba)
+{
+	return 0x01; /*GUARD check failed*/
+}
+
+static inline int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
+				    unsigned int sectors, u32 ei_lba)
+{
+	return 0x01; /*GUARD check failed*/
+}
+
+#endif /* CONFIG_CRC_T10DIF */
+
+#endif /* _SCSI_DEBUG_DIF_H */
drivers/scsi/scsi_debug_dif.c new file +0 -0
new file mode 100644
index 000000000000..a6599d787248

drivers/scsi/scsi_debug_dif.c line 2

Quoted 2 lines
drivers/scsi/scsi_debug_dif.c new file +2 -0
@@ -0,0 +1,224 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "scsi_debug-dif.h"

I always find it is strange to include driver proprietary header files before common header files - I guess that is why the scsi_cmnd prototype is declared, above

drivers/scsi/scsi_debug_dif.c line 7

Quoted 5 lines
drivers/scsi/scsi_debug_dif.c new file +5 -0
+#include <linux/crc-t10dif.h>
+#include <linux/t10-pi.h>
+#include <net/checksum.h>
+#include <scsi/scsi_cmnd.h>
+

Thanks,
John

#2 lore raw
Quoted 7 lines · John Garry
Quoted 4 lines · Bart Van Assche

  drivers/scsi/Kconfig                          |   2 +- drivers/scsi/Makefile                         |   2 + drivers/scsi/scsi_debug-dif.h                 |  65 +++++ drivers/scsi/scsi_debug_dif.c                 | 224 +++++++++++++++

inconsistent filename format: scsi_debug-dif.c vs scsi_debug_dif.h - is that intentional?

That should be fixed. Do you perhaps have a preference?

Quoted 6 lines
Quoted 6 lines

  .../scsi/{scsi_debug.c => scsi_debug_main.c}  | 257 ++----------------

  5 files changed, 308 insertions(+), 242 deletions(-)

  create mode 100644 drivers/scsi/scsi_debug-dif.h create mode 100644 drivers/scsi/scsi_debug_dif.c rename drivers/scsi/{scsi_debug.c => scsi_debug_main.c} (97%)

Quoted 12 lines
Quoted 10 lines
drivers/scsi/Kconfig +0 -0
index 3328052c8715..b7c92d7af73d 100644
@@ -1227,7 +1227,7 @@ config SCSI_WD719X

  config SCSI_DEBUG
      tristate "SCSI debugging host and device simulator" depends on SCSI
-    select CRC_T10DIF
+    select CRC_T10DIF if SCSI_DEBUG = y

Do we really need to select at all now? What does this buy us? Preference is generally not to use select.

I want to exclude the CRC_T10DIF = m and SCSI_DEBUG = y combination because it causes the build to fail. I will leave out the select statement and will change "depends on SCSI" into the following:

	depends on SCSI && (m || CRC_T10DIF = y)
Quoted 6 lines
Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +3 -0
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SCSI_DEBUG_DIF_H
+#define _SCSI_DEBUG_DIF_H
Quoted 8 lines

drivers/scsi/scsi_debug-dif.h line 9

Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +6 -0
+
+#include <linux/kconfig.h>
+#include <linux/types.h>
+#include <linux/spinlock_types.h>
+
+struct scsi_cmnd;

Do you really need to have a prototype for this? I'm a bit in shock seeing this in a scsi low-level driver.

I will leave the above out and add "#include <scsi/scsi_cmnd.h>" instead.

Quoted 1 line

dix_writes is defined in main.c, so surely this extern needs to be in scsi_debug_dif.c or a common header

The scsi_debug-dif.h header file is included from two .c files. Without this header file, the compiler wouldn't be able to check the consistency of the declarations in scsi_debug-dif.h with the definitions in the two scsi_debug .c files.

Quoted 1 line

For me, I would actually just declare this in scsi_debug_dif.c and have scsi_debug_dif_get_dix_writes() or similar to return this value. This function would be stubbed for CONFIG_CRC_T10DIF=n

My goal is to minimize changes while splitting the scsi_debug source code. Hence the "extern" declaration.

Quoted 10 lines

drivers/scsi/scsi_debug-dif.h line 21

Quoted 8 lines
drivers/scsi/scsi_debug-dif.h new file +8 -0
+extern int dix_reads;
+extern int dif_errors;
+extern struct xarray *const per_store_ap;
+extern int sdebug_dif;
+extern int sdebug_dix;
+extern unsigned int sdebug_guard;
+extern int sdebug_sector_size;
+extern unsigned int sdebug_store_sectors;

I doubt why all these are here

All the variables declared above are used in both scsi_debug_dif.c and scsi_debug_main.c.

Quoted 5 lines
Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +1 -0
+int dif_verify(struct t10_pi_tuple *sdt, const void *data, sector_t 

sector,
+           u32 ei_lba);

Is this actually used in main.c?

It is not. I will remove it.

Quoted 1 line

I do also notice that we have chunks of code in main.c that does PI checking, like in resp_write_scat() - surely dif stuff should be in dif.c now

I'm concerned that moving that code would make resp_write_scat() much less readable. Please note that the code in resp_write_scat() that does PI checking is guarded by an 'if (have_dif_prot)' check and that have_dif_prot = false if CONFIG_CRC_T10DIF=n.

Quoted 7 lines

drivers/scsi/scsi_debug_dif.c line 2

Quoted 5 lines
drivers/scsi/scsi_debug_dif.c new file +2 -0
@@ -0,0 +1,224 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "scsi_debug-dif.h"

I always find it is strange to include driver proprietary header files before common header files - I guess that is why the scsi_cmnd prototype is declared, above

Including driver-private header files first is required by some coding style guides because it causes the build to fail if the driver-private header file does not include all include files it should include. See also
https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes
(I am aware that this style guide does not apply to Linux kernel code).

Thanks,

Bart.

#3 lore raw

On 06/03/2024 18:27, Bart Van Assche wrote:

As an alternative, what about something like this:

----->8----

drivers/scsi/Kconfig +0 -1
index 3328052c8715..3120e951f5d2 100644
@@ -1227,7 +1227,6 @@ config SCSI_WD719X
 config SCSI_DEBUG
 	tristate "SCSI debugging host and device simulator"
 	depends on SCSI
-	select CRC_T10DIF
 	help
 	  This pseudo driver simulates one or more hosts (SCSI initiators),
 	  each with one or more targets, each with one or more logical units.
drivers/scsi/scsi_debug.c +13 -0
index acf0592d63da..5bac3b5aa5fa 100644
@@ -3471,6 +3471,7 @@ static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num,
 	return res;
 }
 
+#if (IS_ENABLED(CONFIG_CRC_T10DIF))
 static __be16 dif_compute_csum(const void *buf, int len)
 {
 	__be16 csum;
@@ -3509,6 +3510,13 @@ static int dif_verify(struct t10_pi_tuple *sdt, const void *data,
 	}
 	return 0;
 }
+#else
+static int dif_verify(struct t10_pi_tuple *sdt, const void *data,
+		      sector_t sector, u32 ei_lba)
+{
+	return -EOPNOTSUPP;
+}
+#endif
 
 static void dif_copy_prot(struct scsi_cmnd *scp, sector_t sector,
 			  unsigned int sectors, bool read)
@@ -7421,7 +7429,12 @@ static int __init scsi_debug_init(void)
 	case T10_PI_TYPE1_PROTECTION:
 	case T10_PI_TYPE2_PROTECTION:
 	case T10_PI_TYPE3_PROTECTION:
+		#if (IS_ENABLED(CONFIG_CRC_T10DIF))
 		have_dif_prot = true;
+		#else
+		pr_err("CRC_T10DIF not enabled\n");
+		return -EINVAL;
+		#endif
 		break;
 
 	default:

----8<-----

I know that IS_ENABLED(CONFIG_XXX)) ain't too nice to use, but this is a lot less change and we also don't need multiple files for the driver. As below, it's not easy to separate the CRC_T10DIF-related stuff out.

Thanks,
John

EOM

Quoted 114 lines · John Garry
Quoted 7 lines · Bart Van Assche
Quoted 4 lines

  drivers/scsi/Kconfig                          |   2 +- drivers/scsi/Makefile                         |   2 + drivers/scsi/scsi_debug-dif.h                 |  65 +++++ drivers/scsi/scsi_debug_dif.c                 | 224 +++++++++++++++

inconsistent filename format: scsi_debug-dif.c vs scsi_debug_dif.h - is that intentional?

That should be fixed. Do you perhaps have a preference?

Quoted 6 lines
Quoted 6 lines

  .../scsi/{scsi_debug.c => scsi_debug_main.c}  | 257 ++----------------

  5 files changed, 308 insertions(+), 242 deletions(-)

  create mode 100644 drivers/scsi/scsi_debug-dif.h create mode 100644 drivers/scsi/scsi_debug_dif.c rename drivers/scsi/{scsi_debug.c => scsi_debug_main.c} (97%)

Quoted 12 lines
Quoted 10 lines
drivers/scsi/Kconfig +0 -0
index 3328052c8715..b7c92d7af73d 100644
@@ -1227,7 +1227,7 @@ config SCSI_WD719X

  config SCSI_DEBUG
      tristate "SCSI debugging host and device simulator" depends on SCSI
-    select CRC_T10DIF
+    select CRC_T10DIF if SCSI_DEBUG = y

Do we really need to select at all now? What does this buy us? Preference is generally not to use select.

I want to exclude the CRC_T10DIF = m and SCSI_DEBUG = y combination because it causes the build to fail. I will leave out the select statement and will change "depends on SCSI" into the following:

    depends on SCSI && (m || CRC_T10DIF = y)

Quoted 6 lines
Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +3 -0
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SCSI_DEBUG_DIF_H
+#define _SCSI_DEBUG_DIF_H
Quoted 8 lines

drivers/scsi/scsi_debug-dif.h line 9

Quoted 6 lines
drivers/scsi/scsi_debug-dif.h new file +6 -0
+
+#include <linux/kconfig.h>
+#include <linux/types.h>
+#include <linux/spinlock_types.h>
+
+struct scsi_cmnd;

Do you really need to have a prototype for this? I'm a bit in shock seeing this in a scsi low-level driver.

I will leave the above out and add "#include <scsi/scsi_cmnd.h>" instead.

Quoted 1 line

dix_writes is defined in main.c, so surely this extern needs to be in scsi_debug_dif.c or a common header

The scsi_debug-dif.h header file is included from two .c files. Without this header file, the compiler wouldn't be able to check the consistency of the declarations in scsi_debug-dif.h with the definitions in the two scsi_debug .c files.

Quoted 1 line

For me, I would actually just declare this in scsi_debug_dif.c and have scsi_debug_dif_get_dix_writes() or similar to return this value. This function would be stubbed for CONFIG_CRC_T10DIF=n

My goal is to minimize changes while splitting the scsi_debug source code. Hence the "extern" declaration.

Quoted 10 lines

drivers/scsi/scsi_debug-dif.h line 17

Quoted 8 lines
drivers/scsi/scsi_debug-dif.h new file +8 -0
+extern int dix_reads;
+extern int dif_errors;
+extern struct xarray *const per_store_ap;
+extern int sdebug_dif;
+extern int sdebug_dix;
+extern unsigned int sdebug_guard;
+extern int sdebug_sector_size;
+extern unsigned int sdebug_store_sectors;

I doubt why all these are here

All the variables declared above are used in both scsi_debug_dif.c and scsi_debug_main.c.

Quoted 5 lines
Quoted 3 lines
drivers/scsi/scsi_debug-dif.h new file +1 -0
+int dif_verify(struct t10_pi_tuple *sdt, const void *data, sector_t 

sector,
+           u32 ei_lba);

Is this actually used in main.c?

It is not. I will remove it.

Quoted 1 line

I do also notice that we have chunks of code in main.c that does PI checking, like in resp_write_scat() - surely dif stuff should be in dif.c now

I'm concerned that moving that code would make resp_write_scat() much less readable. Please note that the code in resp_write_scat() that does PI checking is guarded by an 'if (have_dif_prot)' check and that have_dif_prot = false if CONFIG_CRC_T10DIF=n.

Quoted 7 lines

drivers/scsi/scsi_debug_dif.c line 2

Quoted 5 lines
drivers/scsi/scsi_debug_dif.c new file +2 -0
@@ -0,0 +1,224 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "scsi_debug-dif.h"

I always find it is strange to include driver proprietary header files before common header files - I guess that is why the scsi_cmnd prototype is declared, above

Including driver-private header files first is required by some coding style guides because it causes the build to fail if the driver-private header file does not include all include files it should include. See also
https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes
(I am aware that this style guide does not apply to Linux kernel code).

Thanks,

Bart.

#4 lore raw
Quoted 43 lines · John Garry
drivers/scsi/scsi_debug.c +1 -0
index acf0592d63da..5bac3b5aa5fa 100644
@@ -3471,6 +3471,7 @@ static bool comp_write_worker(struct 
 sdeb_store_info *sip, u64 lba, u32 num,
      return res;
  }
 
+#if (IS_ENABLED(CONFIG_CRC_T10DIF))
  static __be16 dif_compute_csum(const void *buf, int len)
  {

     __be16 csum;

drivers/scsi/scsi_debug.c +7 -0
@@ -3509,6 +3510,13 @@ static int dif_verify(struct t10_pi_tuple *sdt, 
 const void *data,
      }
      return 0;
  }
+#else
+static int dif_verify(struct t10_pi_tuple *sdt, const void *data,
+              sector_t sector, u32 ei_lba)
+{
+    return -EOPNOTSUPP;
+}
+#endif
 
  static void dif_copy_prot(struct scsi_cmnd *scp, sector_t sector,

               unsigned int sectors, bool read)

drivers/scsi/scsi_debug.c +5 -1
@@ -7421,7 +7429,12 @@ static int __init scsi_debug_init(void)
      case T10_PI_TYPE1_PROTECTION:
      case T10_PI_TYPE2_PROTECTION:
      case T10_PI_TYPE3_PROTECTION:
+        #if (IS_ENABLED(CONFIG_CRC_T10DIF))
          have_dif_prot = true;
+        #else
+        pr_err("CRC_T10DIF not enabled\n");
+        return -EINVAL;
+        #endif
          break;
 
      default:
----8<-----
Quoted 1 line

I know that IS_ENABLED(CONFIG_XXX)) ain't too nice to use, but this is a lot less change and we also don't need multiple files for the driver. As below, it's not easy to separate the CRC_T10DIF-related stuff out.

The above suggestion violates the following rule from the Linux kernel coding style: "As a general rule, #ifdef use should be confined to header files whenever possible." See also
Documentation/process/4.Coding.rst.

The approach to use multiple files in order to avoid #ifdefs in .c files is strongly preferred in Linux kernel code.

Thanks,

Bart.

#5 lore raw
Quoted 25 lines · Bart Van Assche
Quoted 25 lines
drivers/scsi/scsi_debug.c +7 -0
+#else
+static int dif_verify(struct t10_pi_tuple *sdt, const void *data,
+              sector_t sector, u32 ei_lba)
+{
+    return -EOPNOTSUPP;
+}
+#endif

  static void dif_copy_prot(struct scsi_cmnd *scp, sector_t sector, unsigned int sectors, bool read)

(quoted diff) +0 -0
@@ -7421,7 +7429,12 @@ static int __init scsi_debug_init(void)

      case T10_PI_TYPE1_PROTECTION:
      case T10_PI_TYPE2_PROTECTION:
      case T10_PI_TYPE3_PROTECTION:
+        #if (IS_ENABLED(CONFIG_CRC_T10DIF))
          have_dif_prot = true;
+        #else
+        pr_err("CRC_T10DIF not enabled\n");
+        return -EINVAL;
+        #endif
          break;

      default:
----8<-----

Quoted 8 lines
Quoted 1 line

I know that IS_ENABLED(CONFIG_XXX)) ain't too nice to use, but this is a lot less change and we also don't need multiple files for the driver. As below, it's not easy to separate the CRC_T10DIF-related stuff out.

The above suggestion violates the following rule from the Linux kernel coding style: "As a general rule, #ifdef use should be confined to header files whenever possible." See also
Documentation/process/4.Coding.rst.

The approach to use multiple files in order to avoid #ifdefs in .c files is strongly preferred in Linux kernel code.

Then what about this change in this patch:

Quoted 4 lines

+#ifdef CONFIG_CRC_T10DIF
MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)"); MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)"); +#endif

The idea of putting #ifdef in headers is that we can stub APIs. But that does not work for CRC_T10DIF, as the APIs don't return error codes - that's why there are no stubs today.

And, as noted, this is a general rule.

BTW, I don't think that modparams should be compiled out like this. Better would be to leave as is, and error when the user sets them.

scsi_debug is complex, to put it gently. I don't see any value in splitting it into further files, spreading the complexity. More especially when there seems to be little gain. scsi_debug requires CRC_T10DIF, so let it have it.

Thanks,
John

#6 lore raw

John,

Quoted 4 lines

scsi_debug is complex, to put it gently. I don't see any value in splitting it into further files, spreading the complexity. More especially when there seems to be little gain. scsi_debug requires CRC_T10DIF, so let it have it.

Yeah, I'm not sure this is worth the effort. It's a debug driver.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#7 lore raw
In reply to John Garry
Quoted 10 lines · John Garry
Quoted 2 lines · Bart Van Assche

The approach to use multiple files in order to avoid #ifdefs in .c files is strongly preferred in Linux kernel code.

Then what about this change in this patch:

Quoted 4 lines

+#ifdef CONFIG_CRC_T10DIF
MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)"); MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)"); +#endif

This ifdef has been removed in v3.

Quoted 1 line

BTW, I don't think that modparams should be compiled out like this. Better would be to leave as is, and error when the user sets them.

Hmm ... aren't unrecognized kernel module parameters ignored silently? See also unknown_module_param_cb() in the kernel code.

Quoted 1 line

scsi_debug is complex, to put it gently. I don't see any value in splitting it into further files, spreading the complexity. More especially when there seems to be little gain. scsi_debug requires CRC_T10DIF, so let it have it.

We are using the scsi_debug driver in Android for kernel regression testing but there are no plans to support T10-PI in Android. Any proposals for alternative solutions for removing the dependency of the scsi_debug driver on the CRC_T10DIF code are welcome.

Thanks,

Bart.