Skip to contentSkip to conversation

Add OP-TEE based RPMB driver for UFS devices

PATCH Superseded Bean Huo 4 participants 8 messages Oct 8, 2025 – Oct 17, 2025

Subsystems (3)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Bean Huo

author
#0 lore raw

v4 cover Add OP-TEE based RPMB driver for UFS devices

This patch series introduces OP-TEE based RPMB (Replay Protected Memory Block) support for UFS devices, extending the kernel-level secure storage capabilities that are currently available for eMMC devices.

Previously, OP-TEE required a userspace supplicant to access RPMB partitions, which created complex dependencies and reliability issues, especially during early boot scenarios. Recent work by Linaro has moved core supplicant functionality directly into the Linux kernel for eMMC devices, eliminating userspace dependencies and enabling immediate secure storage access. This series extends the same approach to UFS devices, which are used in enterprise and mobile applications that require secure storage capabilities.

Benefits:
- Eliminates dependency on userspace supplicant for UFS RPMB access
- Enables early boot secure storage access (e.g., fTPM, secure UEFI variables)
- Provides kernel-level RPMB access as soon as UFS driver is initialized
- Removes complex initramfs dependencies and boot ordering requirements
- Ensures reliable and deterministic secure storage operations
- Supports both built-in and modular fTPM configurations.

v3 -- v4:
1. Replaced patch "scsi: ufs: core: Remove duplicate macro definitions" with "scsi: ufs: core: Convert string descriptor format macros to enum" based on feedback from Bart Van Assche
2. Converted SD_ASCII_STD and SD_RAW from boolean macros to enum type for improved code readability
3. Moved ufshcd_read_string_desc() declaration from include/ufs/ufshcd.h to drivers/ufs/core/ufshcd-priv.h since it's not exported

v2 -- v3:
1. Removed patch "rpmb: move rpmb_frame struct and constants to common header". since it has been queued in mmc tree, and added a new patch:
"scsi: ufs: core: Remove duplicate macro definitions"
2. Incorporated suggestions from Jens
3. Added check if Advanced RPMB is enabled, if enabled we will not register UFS OP-TEE RPMB.

v1 -- v2:
1. Added fix tag for patch [2/3]
2. Incorporated feedback and suggestions from Bart

RFC v1 -- v1:
1. Added support for all UFS RPMB regions based on https://github.com/OP-TEE/optee_os/issues/7532
2. Incorporated feedback and suggestions from Bart

Bean Huo (3):
scsi: ufs: core: Convert string descriptor format macros to enum
scsi: ufs: core: fix incorrect buffer duplication in
ufshcd_read_string_desc()
scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices

 drivers/misc/Kconfig           |   2 +-
 drivers/ufs/core/Makefile      |   1 +
 drivers/ufs/core/ufs-rpmb.c    | 249 +++++++++++++++++++++++++++++++++
 drivers/ufs/core/ufshcd-priv.h |  27 +++-
 drivers/ufs/core/ufshcd.c      |  40 ++++--
 include/ufs/ufs.h              |   4 +
 include/ufs/ufshcd.h           |  12 +-
 7 files changed, 314 insertions(+), 21 deletions(-)
 create mode 100644 drivers/ufs/core/ufs-rpmb.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v4 1/3 scsi: ufs: core: Convert string descriptor format macros to enum

From: Bean Huo <[email protected]>

Convert SD_ASCII_STD and SD_RAW from boolean macros to enum values for improved code readability. This makes ufshcd_read_string_desc() calls self-documenting by using explicit enum values instead of true/false.

Move the ufshcd_read_string_desc() declaration from include/ufs/ufshcd.h to drivers/ufs/core/ufshcd-priv.h since this function is not exported.

---
 drivers/ufs/core/ufshcd-priv.h | 14 ++++++++++----
 drivers/ufs/core/ufshcd.c      |  8 +++-----
 include/ufs/ufshcd.h           |  4 ----
 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/ufs/core/ufshcd-priv.h +10 -4
index d0a2c963a27d..d74742a855b2 100644
@@ -78,11 +78,17 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag);
 void ufshcd_release_scsi_cmd(struct ufs_hba *hba,
 			     struct ufshcd_lrb *lrbp);
 
-#define SD_ASCII_STD true
-#define SD_RAW false
-int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
-			    u8 **buf, bool ascii);
+/**
+ * enum ufs_descr_fmt - UFS string descriptor format
+ * @SD_RAW: Raw UTF-16 format
+ * @SD_ASCII_STD: Convert to null-terminated ASCII string
+ */
+enum ufs_descr_fmt {
+	SD_RAW = 0,
+	SD_ASCII_STD = 1,
+};
 
+int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum ufs_descr_fmt fmt);
 int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
 int ufshcd_send_bsg_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
 
drivers/ufs/core/ufshcd.c +3 -5
index 2e1fa8cf83f5..773926b04149 100644
@@ -3759,16 +3759,14 @@ static inline char ufshcd_remove_non_printable(u8 ch)
  * @desc_index: descriptor index
  * @buf: pointer to buffer where descriptor would be read,
  *       the caller should free the memory.
- * @ascii: if true convert from unicode to ascii characters
- *         null terminated string.
+ * @fmt: if %SD_ASCII_STD, convert from UTF-16 to ASCII
  *
  * Return:
  * *      string size on success.
  * *      -ENOMEM: on allocation failure
  * *      -EINVAL: on a wrong parameter
  */
-int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
-			    u8 **buf, bool ascii)
+int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum ufs_descr_fmt fmt)
 {
 	struct uc_string_id *uc_str;
 	u8 *str;
@@ -3797,7 +3795,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
 		goto out;
 	}
 
-	if (ascii) {
+	if (fmt == SD_ASCII_STD) {
 		ssize_t ascii_len;
 		int i;
 		/* remove header and divide by 2 to move from UTF16 to UTF8 */
include/ufs/ufshcd.h +0 -4
index 1d3943777584..9ed188d24cb0 100644
@@ -1453,10 +1453,6 @@ static inline int ufshcd_disable_host_tx_lcc(struct ufs_hba *hba)
 void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
 void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
 			     const struct ufs_dev_quirk *fixups);
-#define SD_ASCII_STD true
-#define SD_RAW false
-int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
-			    u8 **buf, bool ascii);
 
 void ufshcd_hold(struct ufs_hba *hba);
 void ufshcd_release(struct ufs_hba *hba);
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v4 2/3 scsi: ufs: core: fix incorrect buffer duplication in ufshcd_read_string_desc()

In reply to Bean Huo

From: Bean Huo <[email protected]>

The function ufshcd_read_string_desc() was duplicating memory starting from the beginning of struct uc_string_id, which included the length and type fields. As a result, the allocated buffer contained unwanted metadata in addition to the string itself.

The correct behavior is to duplicate only the Unicode character array in the structure. Update the code so that only the actual string content is copied into the new buffer.

Fixes 5f57704dbcfe ("scsi: ufs: Use kmemdup in ufshcd_read_string_desc()")
---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +1 -1
index 773926b04149..d65169733a69 100644
@@ -3821,7 +3821,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum u
 		str[ret++] = '\0';
 
 	} else {
-		str = kmemdup(uc_str, uc_str->len, GFP_KERNEL);
+		str = kmemdup(uc_str->uc, uc_str->len, GFP_KERNEL);
 		if (!str) {
 			ret = -ENOMEM;
 			goto out;
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v4 3/3 scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices

In reply to Bean Huo

From: Bean Huo <[email protected]>

This patch adds OP-TEE based RPMB support for UFS devices. This enables secure RPMB operations on UFS devices through OP-TEE, providing the same functionality available for eMMC devices and extending kernel-based secure storage support to UFS-based systems.

Benefits of OP-TEE based RPMB implementation:
- Eliminates dependency on userspace supplicant for RPMB access
- Enables early boot secure storage access (e.g., fTPM, secure UEFI variables)
- Provides kernel-level RPMB access as soon as UFS driver is initialized
- Removes complex initramfs dependencies and boot ordering requirements
- Ensures reliable and deterministic secure storage operations
- Supports both built-in and modular fTPM configurations

---
 drivers/misc/Kconfig           |   2 +-
 drivers/ufs/core/Makefile      |   1 +
 drivers/ufs/core/ufs-rpmb.c    | 249 +++++++++++++++++++++++++++++++++
 drivers/ufs/core/ufshcd-priv.h |  13 ++
 drivers/ufs/core/ufshcd.c      |  30 +++-
 include/ufs/ufs.h              |   4 +
 include/ufs/ufshcd.h           |   8 +-
 7 files changed, 300 insertions(+), 7 deletions(-)
 create mode 100644 drivers/ufs/core/ufs-rpmb.c
drivers/misc/Kconfig +1 -1
index b9ca56930003..46ffa62eac6e 100644
@@ -106,7 +106,7 @@ config PHANTOM
 
 config RPMB
 	tristate "RPMB partition interface"
-	depends on MMC
+	depends on MMC || SCSI_UFSHCD
 	help
 	  Unified RPMB unit interface for RPMB capable devices such as eMMC and
 	  UFS. Provides interface for in-kernel security controllers to access
drivers/ufs/core/Makefile +1 -0
index cf820fa09a04..51e1867e524e 100644
@@ -2,6 +2,7 @@
 
 obj-$(CONFIG_SCSI_UFSHCD)		+= ufshcd-core.o
 ufshcd-core-y				+= ufshcd.o ufs-sysfs.o ufs-mcq.o
+ufshcd-core-$(CONFIG_RPMB)		+= ufs-rpmb.o
 ufshcd-core-$(CONFIG_DEBUG_FS)		+= ufs-debugfs.o
 ufshcd-core-$(CONFIG_SCSI_UFS_BSG)	+= ufs_bsg.o
 ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO)	+= ufshcd-crypto.o
drivers/ufs/core/ufs-rpmb.c new file +249 -0

249 lines not on this page · raw message

drivers/ufs/core/ufshcd-priv.h +13 -0
index d74742a855b2..e63b0e9075e0 100644
@@ -417,4 +417,17 @@ static inline u32 ufshcd_mcq_get_sq_head_slot(struct ufs_hw_queue *q)
 	return val / sizeof(struct utp_transfer_req_desc);
 }
 
+#ifdef CONFIG_RPMB
+int ufs_rpmb_probe(struct ufs_hba *hba);
+void ufs_rpmb_remove(struct ufs_hba *hba);
+#else
+static inline int ufs_rpmb_probe(struct ufs_hba *hba)
+{
+	return 0;
+}
+static inline void ufs_rpmb_remove(struct ufs_hba *hba)
+{
+}
+#endif
+
 #endif /* _UFSHCD_PRIV_H_ */
drivers/ufs/core/ufshcd.c +26 -4
index d65169733a69..3de284759a6a 100644
@@ -5238,10 +5238,15 @@ static void ufshcd_lu_init(struct ufs_hba *hba, struct scsi_device *sdev)
 	    desc_buf[UNIT_DESC_PARAM_LU_WR_PROTECT] == UFS_LU_POWER_ON_WP)
 		hba->dev_info.is_lu_power_on_wp = true;
 
-	/* In case of RPMB LU, check if advanced RPMB mode is enabled */
-	if (desc_buf[UNIT_DESC_PARAM_UNIT_INDEX] == UFS_UPIU_RPMB_WLUN &&
-	    desc_buf[RPMB_UNIT_DESC_PARAM_REGION_EN] & BIT(4))
-		hba->dev_info.b_advanced_rpmb_en = true;
+	/* In case of RPMB LU, check if advanced RPMB mode is enabled, and get region size */
+	if (desc_buf[UNIT_DESC_PARAM_UNIT_INDEX] == UFS_UPIU_RPMB_WLUN) {
+		if (desc_buf[RPMB_UNIT_DESC_PARAM_REGION_EN] & BIT(4))
+			hba->dev_info.b_advanced_rpmb_en = true;
+		hba->dev_info.rpmb_region_size[0] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION0_SIZE];
+		hba->dev_info.rpmb_region_size[1] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION1_SIZE];
+		hba->dev_info.rpmb_region_size[2] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION2_SIZE];
+		hba->dev_info.rpmb_region_size[3] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION3_SIZE];
+	}
 
 
 	kfree(desc_buf);
@@ -8149,8 +8154,11 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
 		ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL);
 	if (IS_ERR(sdev_rpmb)) {
 		ret = PTR_ERR(sdev_rpmb);
+		hba->ufs_rpmb_wlun = NULL;
+		dev_err(hba->dev, "%s: RPMB WLUN not found\n", __func__);
 		goto remove_ufs_device_wlun;
 	}
+	hba->ufs_rpmb_wlun = sdev_rpmb;
 	ufshcd_blk_pm_runtime_init(sdev_rpmb);
 	scsi_device_put(sdev_rpmb);
 
@@ -8423,6 +8431,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
 	int err;
 	u8 model_index;
 	u8 *desc_buf;
+	u8 serial_index;
 	struct ufs_dev_info *dev_info = &hba->dev_info;
 
 	desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL);
@@ -8458,6 +8467,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
 				UFS_DEV_HID_SUPPORT;
 
 	model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
+	serial_index = desc_buf[DEVICE_DESC_PARAM_SN];
 
 	err = ufshcd_read_string_desc(hba, model_index,
 				      &dev_info->model, SD_ASCII_STD);
@@ -8467,6 +8477,12 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
 		goto out;
 	}
 
+	err = ufshcd_read_string_desc(hba, serial_index, &dev_info->serial_number, SD_RAW);
+	if (err < 0) {
+		dev_err(hba->dev, "%s: Failed reading Serial Number. err = %d\n", __func__, err);
+		goto out;
+	}
+
 	hba->luns_avail = desc_buf[DEVICE_DESC_PARAM_NUM_LU] +
 		desc_buf[DEVICE_DESC_PARAM_NUM_WLU];
 
@@ -8502,6 +8518,8 @@ static void ufs_put_device_desc(struct ufs_hba *hba)
 
 	kfree(dev_info->model);
 	dev_info->model = NULL;
+	kfree(dev_info->serial_number);
+	dev_info->serial_number = NULL;
 }
 
 /**
@@ -8645,6 +8663,8 @@ static int ufshcd_device_geo_params_init(struct ufs_hba *hba)
 	else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 0)
 		hba->dev_info.max_lu_supported = 8;
 
+	hba->dev_info.rpmb_io_size = desc_buf[GEOMETRY_DESC_PARAM_RPMB_RW_SIZE];
+
 out:
 	kfree(desc_buf);
 	return err;
@@ -8830,6 +8850,7 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
 
 	ufs_bsg_probe(hba);
 	scsi_scan_host(hba->host);
+	ufs_rpmb_probe(hba);
 
 out:
 	return ret;
@@ -10389,6 +10410,7 @@ void ufshcd_remove(struct ufs_hba *hba)
 		ufshcd_rpm_get_sync(hba);
 	ufs_hwmon_remove(hba);
 	ufs_bsg_remove(hba);
+	ufs_rpmb_remove(hba);
 	ufs_sysfs_remove_nodes(hba->dev);
 	cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
 	blk_mq_destroy_queue(hba->tmf_queue);
include/ufs/ufs.h +4 -0
index 72fd385037a6..1d44e2b32253 100644
@@ -651,6 +651,10 @@ struct ufs_dev_info {
 	u8 rtt_cap; /* bDeviceRTTCap */
 
 	bool hid_sup;
+
+	u8 *serial_number;
+	u8 rpmb_io_size;
+	u8 rpmb_region_size[4];
 };
 
 /*
include/ufs/ufshcd.h +6 -2
index 9ed188d24cb0..5d04da9acb52 100644
@@ -851,6 +851,7 @@ enum ufshcd_mcq_opr {
  * @host: Scsi_Host instance of the driver
  * @dev: device handle
  * @ufs_device_wlun: WLUN that controls the entire UFS device.
+ * @ufs_rpmb_wlun: RPMB WLUN SCSI device
  * @hwmon_device: device instance registered with the hwmon core.
  * @curr_dev_pwr_mode: active UFS device power mode.
  * @uic_link_state: active state of the link to the UFS device.
@@ -965,8 +966,8 @@ enum ufshcd_mcq_opr {
  * @pm_qos_enabled: flag to check if pm qos is enabled
  * @critical_health_count: count of critical health exceptions
  * @dev_lvl_exception_count: count of device level exceptions since last reset
- * @dev_lvl_exception_id: vendor specific information about the
- * device level exception event.
+ * @dev_lvl_exception_id: vendor specific information about the device level exception event.
+ * @rpmbs: list of OP-TEE RPMB devices (one per RPMB region)
  */
 struct ufs_hba {
 	void __iomem *mmio_base;
@@ -984,6 +985,7 @@ struct ufs_hba {
 	struct Scsi_Host *host;
 	struct device *dev;
 	struct scsi_device *ufs_device_wlun;
+	struct scsi_device *ufs_rpmb_wlun;
 
 #ifdef CONFIG_SCSI_UFS_HWMON
 	struct device *hwmon_device;
@@ -1140,6 +1142,8 @@ struct ufs_hba {
 	int critical_health_count;
 	atomic_t dev_lvl_exception_count;
 	u64 dev_lvl_exception_id;
+
+	struct list_head rpmbs;
 };
 
 /**
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices

kernel test robot noticed the following build errors:

Hi Bean,

kernel test robot noticed the following build errors:

[auto build test ERROR on v6.17]
[also build test ERROR on next-20251009]
[cannot apply to mkp-scsi/for-next jejb-scsi/for-next char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus linus/master] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bean-Huo/scsi-ufs-core-Convert-string-descriptor-format-macros-to-enum/20251009-204745
base:   v6.17
patch link:    https://lore.kernel.org/r/20251008201920.89575-4-beanhuo%40iokpp.de
patch subject: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices
config: sh-randconfig-002-20251010 (https://download.01.org/0day-ci/archive/20251010/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251010/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/linux/byteorder/big_endian.h:5,

                    from arch/sh/include/uapi/asm/byteorder.h:8,
                    from arch/sh/include/asm/bitops.h:10,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from include/asm-generic/div64.h:55,
                    from ./arch/sh/include/generated/asm/div64.h:1,
                    from include/linux/math.h:6,
                    from include/linux/math64.h:6,
                    from include/linux/time.h:6,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/ufs/core/ufs-rpmb.c:13:
   drivers/ufs/core/ufs-rpmb.c: In function 'ufs_rpmb_route_frames':
   drivers/ufs/core/ufs-rpmb.c:72:39: error: invalid use of undefined type 'struct rpmb_frame'
      72 |         req_type = be16_to_cpu(frm_out->req_resp);
         |                                       ^~
   include/uapi/linux/byteorder/big_endian.h:43:51: note: in definition of macro '__be16_to_cpu'
      43 | #define __be16_to_cpu(x) ((__force __u16)(__be16)(x))
         |                                                   ^
   drivers/ufs/core/ufs-rpmb.c:72:20: note: in expansion of macro 'be16_to_cpu'
      72 |         req_type = be16_to_cpu(frm_out->req_resp);
         |                    ^~~~~~~~~~~
   drivers/ufs/core/ufs-rpmb.c:75:14: error: 'RPMB_PROGRAM_KEY' undeclared (first use in this function)
      75 |         case RPMB_PROGRAM_KEY:
         |              ^~~~~~~~~~~~~~~~
   drivers/ufs/core/ufs-rpmb.c:75:14: note: each undeclared identifier is reported only once for each function it appears in
   drivers/ufs/core/ufs-rpmb.c:76:39: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      76 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                       ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:76:80: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      76 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                                                                ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:79:14: error: 'RPMB_GET_WRITE_COUNTER' undeclared (first use in this function)
      79 |         case RPMB_GET_WRITE_COUNTER:
         |              ^~~~~~~~~~~~~~~~~~~~~~
   drivers/ufs/core/ufs-rpmb.c:80:39: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      80 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                       ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:80:80: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      80 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                                                                ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:84:14: error: 'RPMB_WRITE_DATA' undeclared (first use in this function)
      84 |         case RPMB_WRITE_DATA:
         |              ^~~~~~~~~~~~~~~
   drivers/ufs/core/ufs-rpmb.c:85:38: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      85 |                 if (req_len % sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                      ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:85:79: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      85 |                 if (req_len % sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                                                               ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:88:14: error: 'RPMB_READ_DATA' undeclared (first use in this function); did you mean 'D_REAL_DATA'?
      88 |         case RPMB_READ_DATA:
         |              ^~~~~~~~~~~~~~
         |              D_REAL_DATA
   drivers/ufs/core/ufs-rpmb.c:89:39: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      89 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len % sizeof(struct rpmb_frame))
         |                                       ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:89:79: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      89 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len % sizeof(struct rpmb_frame))
         |                                                                               ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:109:43: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
     109 |                 memset(frm_resp, 0, sizeof(*frm_resp));
         |                                           ^
   drivers/ufs/core/ufs-rpmb.c:110:25: error: invalid use of undefined type 'struct rpmb_frame'
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
         |                         ^~
   drivers/ufs/core/ufs-rpmb.c:110:50: error: 'RPMB_RESULT_READ' undeclared (first use in this function)
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
         |                                                  ^~~~~~~~~~~~~~~~
   include/uapi/linux/byteorder/big_endian.h:42:51: note: in definition of macro '__cpu_to_be16'
      42 | #define __cpu_to_be16(x) ((__force __be16)(__u16)(x))
         |                                                   ^
   drivers/ufs/core/ufs-rpmb.c:110:38: note: in expansion of macro 'cpu_to_be16'
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
         |                                      ^~~~~~~~~~~
   drivers/ufs/core/ufs-rpmb.c: At top level:
>> drivers/ufs/core/ufs-rpmb.c:135:5: error: redefinition of 'ufs_rpmb_probe'
     135 | int ufs_rpmb_probe(struct ufs_hba *hba)
         |     ^~~~~~~~~~~~~~
   In file included from drivers/ufs/core/ufs-rpmb.c:22:
   drivers/ufs/core/ufshcd-priv.h:424:19: note: previous definition of 'ufs_rpmb_probe' with type 'int(struct ufs_hba *)'
     424 | static inline int ufs_rpmb_probe(struct ufs_hba *hba)
         |                   ^~~~~~~~~~~~~~
>> drivers/ufs/core/ufs-rpmb.c:229:6: error: redefinition of 'ufs_rpmb_remove'

229 | void ufs_rpmb_remove(struct ufs_hba *hba)
| ^~~~~~~~~~~~~~~
drivers/ufs/core/ufshcd-priv.h:428:20: note: previous definition of 'ufs_rpmb_remove' with type 'void(struct ufs_hba *)'
428 | static inline void ufs_rpmb_remove(struct ufs_hba *hba)
| ^~~~~~~~~~~~~~~

vim +/ufs_rpmb_probe +135 drivers/ufs/core/ufs-rpmb.c

133
134 /* UFS RPMB device registration */

 > 135	int ufs_rpmb_probe(struct ufs_hba *hba)
   136	{
   137		struct ufs_rpmb_dev *ufs_rpmb, *it, *tmp;
   138		struct rpmb_dev *rdev;
   139		u8 cid[16] = { };
   140		int region;
   141		u8 *sn;
   142		u32 cap;
   143		int ret;
   144	
   145		if (!hba->ufs_rpmb_wlun || hba->dev_info.b_advanced_rpmb_en) {
   146			dev_info(hba->dev, "Skip OP-TEE RPMB registration\n");
   147			return -ENODEV;
   148		}
   149	
   150		/* Get the UNICODE serial number data */
   151		sn = hba->dev_info.serial_number;
   152		if (!sn) {
   153			dev_err(hba->dev, "Serial number not available\n");
   154			return -EINVAL;
   155		}
   156	
   157		INIT_LIST_HEAD(&hba->rpmbs);
   158	
   159		/* Copy serial number into device ID (max 15 chars + NUL). */
   160		strscpy(cid, sn);
   161	
   162		struct rpmb_descr descr = {
   163			.type = RPMB_TYPE_UFS,
   164			.route_frames = ufs_rpmb_route_frames,
   165			.dev_id_len = sizeof(cid),
   166			.reliable_wr_count = hba->dev_info.rpmb_io_size,
   167		};
   168	
   169		for (region = 0; region < ARRAY_SIZE(hba->dev_info.rpmb_region_size); region++) {
   170			cap = hba->dev_info.rpmb_region_size[region];
   171			if (!cap)
   172				continue;
   173	
   174			ufs_rpmb = devm_kzalloc(hba->dev, sizeof(*ufs_rpmb), GFP_KERNEL);
   175			if (!ufs_rpmb) {
   176				ret = -ENOMEM;
   177				goto err_out;
   178			}
   179	
   180			ufs_rpmb->hba = hba;
   181			ufs_rpmb->dev.parent = &hba->ufs_rpmb_wlun->sdev_gendev;
   182			ufs_rpmb->dev.bus = &ufs_rpmb_bus_type;
   183			ufs_rpmb->dev.release = ufs_rpmb_device_release;
   184			dev_set_name(&ufs_rpmb->dev, "ufs_rpmb%d", region);
   185	
   186			/* Set driver data BEFORE device_register */
   187			dev_set_drvdata(&ufs_rpmb->dev, ufs_rpmb);
   188	
   189			ret = device_register(&ufs_rpmb->dev);
   190			if (ret) {
   191				dev_err(hba->dev, "Failed to register UFS RPMB device %d\n", region);
   192				put_device(&ufs_rpmb->dev);
   193				goto err_out;
   194			}
   195	
   196			/* Make CID unique for this region by appending region numbe */
   197			cid[sizeof(cid) - 1] = region;
   198			descr.dev_id = cid;
   199			descr.capacity = cap;
   200	
   201			/* Register RPMB device */
   202			rdev = rpmb_dev_register(&ufs_rpmb->dev, &descr);
   203			if (IS_ERR(rdev)) {
   204				dev_err(hba->dev, "Failed to register UFS RPMB device.\n");
   205				device_unregister(&ufs_rpmb->dev);
   206				ret = PTR_ERR(rdev);
   207				goto err_out;
   208			}
   209	
   210			ufs_rpmb->rdev = rdev;
   211			ufs_rpmb->region_id = region;
   212	
   213			list_add_tail(&ufs_rpmb->node, &hba->rpmbs);
   214	
   215			dev_info(hba->dev, "UFS RPMB region %d registered (capacity=%u)\n", region, cap);
   216		}
   217	
   218		return 0;
   219	err_out:
   220		list_for_each_entry_safe(it, tmp, &hba->rpmbs, node) {
   221			list_del(&it->node);
   222			device_unregister(&it->dev);
   223		}
   224	
   225		return ret;
   226	}
   227	
   228	/* UFS RPMB remove handler */
 > 229	void ufs_rpmb_remove(struct ufs_hba *hba)

230 {
231 struct ufs_rpmb_dev *ufs_rpmb, *tmp;
232
233 if (list_empty(&hba->rpmbs))
234 return;
235
236 /* Remove all registered RPMB devices */
237 list_for_each_entry_safe(ufs_rpmb, tmp, &hba->rpmbs, node) {
238 dev_info(hba->dev, "Removing UFS RPMB region %d\n", ufs_rpmb->region_id);
239 /* Remove from list first */
240 list_del(&ufs_rpmb->node);
241 /* Unregister device */
242 device_unregister(&ufs_rpmb->dev);
243 }
244
245 dev_info(hba->dev, "All UFS RPMB devices unregistered\n");
246 }
247

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices

since the patch "rpmb: move rpmb_frame struct and constants to common header" has been queued in mmc git tree, I didn't add it patch in scsi tree for this version:

https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/commit/?h=next

do I need to add this queued patch for scsi tree as well?

Kind regards,
Bean

Quoted 294 lines · kernel test robot

Hi Bean,

kernel test robot noticed the following build errors:

[auto build test ERROR on v6.17]
[also build test ERROR on next-20251009]
[cannot apply to mkp-scsi/for-next jejb-scsi/for-next char-misc/char-misc- testing char-misc/char-misc-next char-misc/char-misc-linus linus/master] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Bean-Huo/scsi-ufs-core-Convert-string-descriptor-format-macros-to-enum/20251009-204745
base:   v6.17
patch link:
https://lore.kernel.org/r/20251008201920.89575-4-beanhuo%40iokpp.de
patch subject: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices
config: sh-randconfig-002-20251010
(https://download.01.org/0day-ci/archive/20251010/202510100521.pnAPqTFK-lkp@in
tel.com/config)
compiler: sh4-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20251010/202510100521.pnAPqTFK-lkp@in
tel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags

Quoted 3 lines

Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

   In file included from include/linux/byteorder/big_endian.h:5, from arch/sh/include/uapi/asm/byteorder.h:8, from arch/sh/include/asm/bitops.h:10,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from include/asm-generic/div64.h:55,
                    from ./arch/sh/include/generated/asm/div64.h:1, from include/linux/math.h:6,
                    from include/linux/math64.h:6,
                    from include/linux/time.h:6,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/ufs/core/ufs-rpmb.c:13:
   drivers/ufs/core/ufs-rpmb.c: In function 'ufs_rpmb_route_frames':
   drivers/ufs/core/ufs-rpmb.c:72:39: error: invalid use of undefined type 'struct rpmb_frame'
      72 |         req_type = be16_to_cpu(frm_out->req_resp);
         |                                       ^~ include/uapi/linux/byteorder/big_endian.h:43:51: note: in definition of macro '__be16_to_cpu'
      43 | #define __be16_to_cpu(x) ((__force __u16)(__be16)(x)) |                                                   ^ drivers/ufs/core/ufs-rpmb.c:72:20: note: in expansion of macro 'be16_to_cpu'
      72 |         req_type = be16_to_cpu(frm_out->req_resp);
         |                    ^~~~~~~~~~~ drivers/ufs/core/ufs-rpmb.c:75:14: error: 'RPMB_PROGRAM_KEY' undeclared (first use in this function)
      75 |         case RPMB_PROGRAM_KEY:
         |              ^~~~~~~~~~~~~~~~ drivers/ufs/core/ufs-rpmb.c:75:14: note: each undeclared identifier is reported only once for each function it appears in drivers/ufs/core/ufs-rpmb.c:76:39: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      76 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                       ^~~~~~ drivers/ufs/core/ufs-rpmb.c:76:80: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      76 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))

|
   ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:79:14: error: 'RPMB_GET_WRITE_COUNTER' undeclared (first use in this function)
      79 |         case RPMB_GET_WRITE_COUNTER:
         |              ^~~~~~~~~~~~~~~~~~~~~~ drivers/ufs/core/ufs-rpmb.c:80:39: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      80 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                       ^~~~~~ drivers/ufs/core/ufs-rpmb.c:80:80: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      80 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))

|
   ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:84:14: error: 'RPMB_WRITE_DATA' undeclared (first use in this function)
      84 |         case RPMB_WRITE_DATA:
         |              ^~~~~~~~~~~~~~~ drivers/ufs/core/ufs-rpmb.c:85:38: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      85 |                 if (req_len % sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
         |                                      ^~~~~~ drivers/ufs/core/ufs-rpmb.c:85:79: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      85 |                 if (req_len % sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))

|
  ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:88:14: error: 'RPMB_READ_DATA' undeclared (first use in this function); did you mean 'D_REAL_DATA'?
      88 |         case RPMB_READ_DATA:
         |              ^~~~~~~~~~~~~~
         |              D_REAL_DATA drivers/ufs/core/ufs-rpmb.c:89:39: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      89 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len % sizeof(struct rpmb_frame))
         |                                       ^~~~~~ drivers/ufs/core/ufs-rpmb.c:89:79: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
      89 |                 if (req_len != sizeof(struct rpmb_frame) || resp_len % sizeof(struct rpmb_frame))

|
  ^~~~~~
   drivers/ufs/core/ufs-rpmb.c:109:43: error: invalid application of 'sizeof' to incomplete type 'struct rpmb_frame'
     109 |                 memset(frm_resp, 0, sizeof(*frm_resp)); |                                           ^ drivers/ufs/core/ufs-rpmb.c:110:25: error: invalid use of undefined type 'struct rpmb_frame'
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ); |                         ^~ drivers/ufs/core/ufs-rpmb.c:110:50: error: 'RPMB_RESULT_READ' undeclared (first use in this function)
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ); |                                                  ^~~~~~~~~~~~~~~~ include/uapi/linux/byteorder/big_endian.h:42:51: note: in definition of macro '__cpu_to_be16'
      42 | #define __cpu_to_be16(x) ((__force __be16)(__u16)(x)) |                                                   ^ drivers/ufs/core/ufs-rpmb.c:110:38: note: in expansion of macro 'cpu_to_be16'
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ); |                                      ^~~~~~~~~~~ drivers/ufs/core/ufs-rpmb.c: At top level:

Quoted 1 line
Quoted 1 line

drivers/ufs/core/ufs-rpmb.c:135:5: error: redefinition of 'ufs_rpmb_probe'

     135 | int ufs_rpmb_probe(struct ufs_hba *hba)
         |     ^~~~~~~~~~~~~~
   In file included from drivers/ufs/core/ufs-rpmb.c:22:
   drivers/ufs/core/ufshcd-priv.h:424:19: note: previous definition of 'ufs_rpmb_probe' with type 'int(struct ufs_hba *)'
     424 | static inline int ufs_rpmb_probe(struct ufs_hba *hba) |                   ^~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

drivers/ufs/core/ufs-rpmb.c:229:6: error: redefinition of 'ufs_rpmb_remove'

     229 | void ufs_rpmb_remove(struct ufs_hba *hba)
         |      ^~~~~~~~~~~~~~~ drivers/ufs/core/ufshcd-priv.h:428:20: note: previous definition of 'ufs_rpmb_remove' with type 'void(struct ufs_hba *)'
     428 | static inline void ufs_rpmb_remove(struct ufs_hba *hba) |                    ^~~~~~~~~~~~~~~

vim +/ufs_rpmb_probe +135 drivers/ufs/core/ufs-rpmb.c

   133
   134  /* UFS RPMB device registration */
 > 135  int ufs_rpmb_probe(struct ufs_hba *hba)
   136  {
   137          struct ufs_rpmb_dev *ufs_rpmb, *it, *tmp;
   138          struct rpmb_dev *rdev;
   139          u8 cid[16] = { };
   140          int region;
   141          u8 *sn;
   142          u32 cap;
   143          int ret;
   144
   145          if (!hba->ufs_rpmb_wlun || hba->dev_info.b_advanced_rpmb_en) { 146                  dev_info(hba->dev, "Skip OP-TEE RPMB registration\n"); 147                  return -ENODEV;
   148          }
   149
   150          /* Get the UNICODE serial number data */
   151          sn = hba->dev_info.serial_number;
   152          if (!sn) {
   153                  dev_err(hba->dev, "Serial number not available\n"); 154                  return -EINVAL;
   155          }
   156
   157          INIT_LIST_HEAD(&hba->rpmbs);
   158
   159          /* Copy serial number into device ID (max 15 chars + NUL). */ 160          strscpy(cid, sn);
   161
   162          struct rpmb_descr descr = {
   163                  .type = RPMB_TYPE_UFS,
   164                  .route_frames = ufs_rpmb_route_frames, 165                  .dev_id_len = sizeof(cid),
   166                  .reliable_wr_count = hba->dev_info.rpmb_io_size, 167          };
   168
   169          for (region = 0; region < ARRAY_SIZE(hba-

Quoted 1 line

dev_info.rpmb_region_size); region++) {

   170                  cap = hba->dev_info.rpmb_region_size[region]; 171                  if (!cap)
   172                          continue;
   173
   174                  ufs_rpmb = devm_kzalloc(hba->dev, sizeof(*ufs_rpmb), GFP_KERNEL);
   175                  if (!ufs_rpmb) {
   176                          ret = -ENOMEM;
   177                          goto err_out;
   178                  }
   179
   180                  ufs_rpmb->hba = hba;
   181                  ufs_rpmb->dev.parent = &hba->ufs_rpmb_wlun-

Quoted 1 line

sdev_gendev;

   182                  ufs_rpmb->dev.bus = &ufs_rpmb_bus_type; 183                  ufs_rpmb->dev.release = ufs_rpmb_device_release; 184                  dev_set_name(&ufs_rpmb->dev, "ufs_rpmb%d", region); 185
   186                  /* Set driver data BEFORE device_register */ 187                  dev_set_drvdata(&ufs_rpmb->dev, ufs_rpmb); 188
   189                  ret = device_register(&ufs_rpmb->dev); 190                  if (ret) {
   191                          dev_err(hba->dev, "Failed to register UFS RPMB device %d\n", region);
   192                          put_device(&ufs_rpmb->dev);
   193                          goto err_out;
   194                  }
   195
   196                  /* Make CID unique for this region by appending region numbe */
   197                  cid[sizeof(cid) - 1] = region;
   198                  descr.dev_id = cid;
   199                  descr.capacity = cap;
   200
   201                  /* Register RPMB device */
   202                  rdev = rpmb_dev_register(&ufs_rpmb->dev, &descr); 203                  if (IS_ERR(rdev)) {
   204                          dev_err(hba->dev, "Failed to register UFS RPMB device.\n");
   205                          device_unregister(&ufs_rpmb->dev); 206                          ret = PTR_ERR(rdev);
   207                          goto err_out;
   208                  }
   209
   210                  ufs_rpmb->rdev = rdev;
   211                  ufs_rpmb->region_id = region;
   212
   213                  list_add_tail(&ufs_rpmb->node, &hba->rpmbs); 214
   215                  dev_info(hba->dev, "UFS RPMB region %d registered (capacity=%u)\n", region, cap);
   216          }
   217
   218          return 0;
   219  err_out:
   220          list_for_each_entry_safe(it, tmp, &hba->rpmbs, node) { 221                  list_del(&it->node);
   222                  device_unregister(&it->dev);
   223          }
   224
   225          return ret;
   226  }
   227
   228  /* UFS RPMB remove handler */
 > 229  void ufs_rpmb_remove(struct ufs_hba *hba)
   230  {
   231          struct ufs_rpmb_dev *ufs_rpmb, *tmp;
   232
   233          if (list_empty(&hba->rpmbs))
   234                  return;
   235
   236          /* Remove all registered RPMB devices */
   237          list_for_each_entry_safe(ufs_rpmb, tmp, &hba->rpmbs, node) { 238                  dev_info(hba->dev, "Removing UFS RPMB region %d\n", ufs_rpmb->region_id);
   239                  /* Remove from list first */
   240                  list_del(&ufs_rpmb->node);
   241                  /* Unregister device */
   242                  device_unregister(&ufs_rpmb->dev);
   243          }
   244
   245          dev_info(hba->dev, "All UFS RPMB devices unregistered\n"); 246  }
   247

#6 lore raw

Re: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices

Quoted 10 lines · Bean Huo

since the patch "rpmb: move rpmb_frame struct and constants to common header" has been queued in mmc git tree, I didn't add it patch in scsi tree for this version:

https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/commit/?h=next

do I need to add this queued patch for scsi tree as well?

I have just sent the patch to Linus to get included in rc2. Sorry, I failed to send it for rc1.

That said, if you re-spin a version of the series that is based on rc2 on Monday that should work, I think.

Kind regards
Uffe

Quoted 302 lines

Kind regards,
Bean

Quoted 294 lines · kernel test robot

Hi Bean,

kernel test robot noticed the following build errors:

[auto build test ERROR on v6.17]
[also build test ERROR on next-20251009]
[cannot apply to mkp-scsi/for-next jejb-scsi/for-next char-misc/char-misc- testing char-misc/char-misc-next char-misc/char-misc-linus linus/master] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Bean-Huo/scsi-ufs-core-Convert-string-descriptor-format-macros-to-enum/20251009-204745
base: v6.17
patch link:
https://lore.kernel.org/r/20251008201920.89575-4-beanhuo%40iokpp.de
patch subject: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices
config: sh-randconfig-002-20251010
(https://download.01.org/0day-ci/archive/20251010/202510100521.pnAPqTFK-lkp@in
tel.com/config)
compiler: sh4-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20251010/202510100521.pnAPqTFK-lkp@in
tel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags

Quoted 3 lines

Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

   In file included from include/linux/byteorder/big_endian.h:5,
                    from arch/sh/include/uapi/asm/byteorder.h:8,
                    from arch/sh/include/asm/bitops.h:10,
                    from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from include/asm-generic/div64.h:55,
                    from ./arch/sh/include/generated/asm/div64.h:1,
                    from include/linux/math.h:6,
                    from include/linux/math64.h:6,
                    from include/linux/time.h:6,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/ufs/core/ufs-rpmb.c:13:
   drivers/ufs/core/ufs-rpmb.c: In function 'ufs_rpmb_route_frames':
   drivers/ufs/core/ufs-rpmb.c:72:39: error: invalid use of undefined type
'struct rpmb_frame'
      72 |         req_type = be16_to_cpu(frm_out->req_resp);
         |                                       ^~
   include/uapi/linux/byteorder/big_endian.h:43:51: note: in definition of
macro '__be16_to_cpu'
      43 | #define __be16_to_cpu(x) ((__force __u16)(__be16)(x))
         |                                                   ^
   drivers/ufs/core/ufs-rpmb.c:72:20: note: in expansion of macro
'be16_to_cpu'
      72 |         req_type = be16_to_cpu(frm_out->req_resp);
         |                    ^~~~~~~~~~~

drivers/ufs/core/ufs-rpmb.c:75:14: error: 'RPMB_PROGRAM_KEY' undeclared
(first use in this function)
75 | case RPMB_PROGRAM_KEY:
| ^~~~~~~~~~~~~~~~
drivers/ufs/core/ufs-rpmb.c:75:14: note: each undeclared identifier is
reported only once for each function it appears in
drivers/ufs/core/ufs-rpmb.c:76:39: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      76 |                 if (req_len != sizeof(struct rpmb_frame) ||

resp_len != sizeof(struct rpmb_frame))
| ^~~~~~
drivers/ufs/core/ufs-rpmb.c:76:80: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      76 |                 if (req_len != sizeof(struct rpmb_frame) ||

resp_len != sizeof(struct rpmb_frame))

|
^~~~~~
drivers/ufs/core/ufs-rpmb.c:79:14: error: 'RPMB_GET_WRITE_COUNTER'
undeclared (first use in this function)
79 | case RPMB_GET_WRITE_COUNTER:
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/ufs/core/ufs-rpmb.c:80:39: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      80 |                 if (req_len != sizeof(struct rpmb_frame) ||

resp_len != sizeof(struct rpmb_frame))
| ^~~~~~
drivers/ufs/core/ufs-rpmb.c:80:80: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      80 |                 if (req_len != sizeof(struct rpmb_frame) ||

resp_len != sizeof(struct rpmb_frame))

|
^~~~~~
drivers/ufs/core/ufs-rpmb.c:84:14: error: 'RPMB_WRITE_DATA' undeclared
(first use in this function)
84 | case RPMB_WRITE_DATA:
| ^~~~~~~~~~~~~~~
drivers/ufs/core/ufs-rpmb.c:85:38: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      85 |                 if (req_len % sizeof(struct rpmb_frame) || resp_len

!= sizeof(struct rpmb_frame))
| ^~~~~~
drivers/ufs/core/ufs-rpmb.c:85:79: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      85 |                 if (req_len % sizeof(struct rpmb_frame) || resp_len

!= sizeof(struct rpmb_frame))

|
^~~~~~
drivers/ufs/core/ufs-rpmb.c:88:14: error: 'RPMB_READ_DATA' undeclared
(first use in this function); did you mean 'D_REAL_DATA'?

      88 |         case RPMB_READ_DATA:
         |              ^~~~~~~~~~~~~~
         |              D_REAL_DATA
   drivers/ufs/core/ufs-rpmb.c:89:39: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'
      89 |                 if (req_len != sizeof(struct rpmb_frame) ||

resp_len % sizeof(struct rpmb_frame))
| ^~~~~~
drivers/ufs/core/ufs-rpmb.c:89:79: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

      89 |                 if (req_len != sizeof(struct rpmb_frame) ||

resp_len % sizeof(struct rpmb_frame))

|
^~~~~~
drivers/ufs/core/ufs-rpmb.c:109:43: error: invalid application of 'sizeof'
to incomplete type 'struct rpmb_frame'

     109 |                 memset(frm_resp, 0, sizeof(*frm_resp));
         |                                           ^
   drivers/ufs/core/ufs-rpmb.c:110:25: error: invalid use of undefined type
'struct rpmb_frame'
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
         |                         ^~
   drivers/ufs/core/ufs-rpmb.c:110:50: error: 'RPMB_RESULT_READ' undeclared
(first use in this function)
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
         |                                                  ^~~~~~~~~~~~~~~~
   include/uapi/linux/byteorder/big_endian.h:42:51: note: in definition of
macro '__cpu_to_be16'
      42 | #define __cpu_to_be16(x) ((__force __be16)(__u16)(x))
         |                                                   ^
   drivers/ufs/core/ufs-rpmb.c:110:38: note: in expansion of macro
'cpu_to_be16'
     110 |                 frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
         |                                      ^~~~~~~~~~~

drivers/ufs/core/ufs-rpmb.c: At top level:

Quoted 1 line
Quoted 1 line

drivers/ufs/core/ufs-rpmb.c:135:5: error: redefinition of 'ufs_rpmb_probe'

135 | int ufs_rpmb_probe(struct ufs_hba *hba)
| ^~~~~~~~~~~~~~
In file included from drivers/ufs/core/ufs-rpmb.c:22:
drivers/ufs/core/ufshcd-priv.h:424:19: note: previous definition of
'ufs_rpmb_probe' with type 'int(struct ufs_hba *)'
424 | static inline int ufs_rpmb_probe(struct ufs_hba *hba)
| ^~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

drivers/ufs/core/ufs-rpmb.c:229:6: error: redefinition of 'ufs_rpmb_remove'

229 | void ufs_rpmb_remove(struct ufs_hba *hba)
| ^~~~~~~~~~~~~~~
drivers/ufs/core/ufshcd-priv.h:428:20: note: previous definition of
'ufs_rpmb_remove' with type 'void(struct ufs_hba *)'
428 | static inline void ufs_rpmb_remove(struct ufs_hba *hba)
| ^~~~~~~~~~~~~~~

vim +/ufs_rpmb_probe +135 drivers/ufs/core/ufs-rpmb.c

133

   134  /* UFS RPMB device registration */
 > 135  int ufs_rpmb_probe(struct ufs_hba *hba)
   136  {
   137          struct ufs_rpmb_dev *ufs_rpmb, *it, *tmp;
   138          struct rpmb_dev *rdev;
   139          u8 cid[16] = { };
   140          int region;
   141          u8 *sn;
   142          u32 cap;
   143          int ret;
   144
   145          if (!hba->ufs_rpmb_wlun || hba->dev_info.b_advanced_rpmb_en) {
   146                  dev_info(hba->dev, "Skip OP-TEE RPMB registration\n");
   147                  return -ENODEV;
   148          }
   149
   150          /* Get the UNICODE serial number data */
   151          sn = hba->dev_info.serial_number;
   152          if (!sn) {
   153                  dev_err(hba->dev, "Serial number not available\n");
   154                  return -EINVAL;
   155          }
   156
   157          INIT_LIST_HEAD(&hba->rpmbs);
   158
   159          /* Copy serial number into device ID (max 15 chars + NUL). */
   160          strscpy(cid, sn);
   161
   162          struct rpmb_descr descr = {
   163                  .type = RPMB_TYPE_UFS,
   164                  .route_frames = ufs_rpmb_route_frames,
   165                  .dev_id_len = sizeof(cid),
   166                  .reliable_wr_count = hba->dev_info.rpmb_io_size,
   167          };
   168
   169          for (region = 0; region < ARRAY_SIZE(hba-
Quoted 1 line

dev_info.rpmb_region_size); region++) {

   170                  cap = hba->dev_info.rpmb_region_size[region];
   171                  if (!cap)
   172                          continue;
   173
   174                  ufs_rpmb = devm_kzalloc(hba->dev, sizeof(*ufs_rpmb),
GFP_KERNEL);
   175                  if (!ufs_rpmb) {
   176                          ret = -ENOMEM;
   177                          goto err_out;
   178                  }
   179
   180                  ufs_rpmb->hba = hba;
   181                  ufs_rpmb->dev.parent = &hba->ufs_rpmb_wlun-
Quoted 1 line

sdev_gendev;

   182                  ufs_rpmb->dev.bus = &ufs_rpmb_bus_type;
   183                  ufs_rpmb->dev.release = ufs_rpmb_device_release;
   184                  dev_set_name(&ufs_rpmb->dev, "ufs_rpmb%d", region);
   185
   186                  /* Set driver data BEFORE device_register */
   187                  dev_set_drvdata(&ufs_rpmb->dev, ufs_rpmb);
   188
   189                  ret = device_register(&ufs_rpmb->dev);
   190                  if (ret) {
   191                          dev_err(hba->dev, "Failed to register UFS RPMB
device %d\n", region);
   192                          put_device(&ufs_rpmb->dev);
   193                          goto err_out;
   194                  }
   195
   196                  /* Make CID unique for this region by appending region
numbe */
   197                  cid[sizeof(cid) - 1] = region;
   198                  descr.dev_id = cid;
   199                  descr.capacity = cap;
   200
   201                  /* Register RPMB device */
   202                  rdev = rpmb_dev_register(&ufs_rpmb->dev, &descr);
   203                  if (IS_ERR(rdev)) {
   204                          dev_err(hba->dev, "Failed to register UFS RPMB
device.\n");
   205                          device_unregister(&ufs_rpmb->dev);
   206                          ret = PTR_ERR(rdev);
   207                          goto err_out;
   208                  }
   209
   210                  ufs_rpmb->rdev = rdev;
   211                  ufs_rpmb->region_id = region;
   212
   213                  list_add_tail(&ufs_rpmb->node, &hba->rpmbs);
   214
   215                  dev_info(hba->dev, "UFS RPMB region %d registered
(capacity=%u)\n", region, cap);
   216          }
   217
   218          return 0;
   219  err_out:
   220          list_for_each_entry_safe(it, tmp, &hba->rpmbs, node) {
   221                  list_del(&it->node);
   222                  device_unregister(&it->dev);
   223          }
   224
   225          return ret;
   226  }
   227
   228  /* UFS RPMB remove handler */
Quoted 1 line

229 void ufs_rpmb_remove(struct ufs_hba *hba)

   230  {
   231          struct ufs_rpmb_dev *ufs_rpmb, *tmp;
   232
   233          if (list_empty(&hba->rpmbs))
   234                  return;
   235
   236          /* Remove all registered RPMB devices */
   237          list_for_each_entry_safe(ufs_rpmb, tmp, &hba->rpmbs, node) {
   238                  dev_info(hba->dev, "Removing UFS RPMB region %d\n",
ufs_rpmb->region_id);
   239                  /* Remove from list first */
   240                  list_del(&ufs_rpmb->node);
   241                  /* Unregister device */
   242                  device_unregister(&ufs_rpmb->dev);
   243          }
   244
   245          dev_info(hba->dev, "All UFS RPMB devices unregistered\n");
   246  }
   247
#7 lore raw

Re: [PATCH v4 3/3] scsi: ufs: core: Add OP-TEE based RPMB driver for UFS devices

Quoted 11 lines · Ulf Hansson
Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/commit/?h=next

do I need to add this queued patch for scsi tree as well?

I have just sent the patch to Linus to get included in rc2. Sorry, I failed to send it for rc1.

That said, if you re-spin a version of the series that is based on rc2 on Monday that should work, I think.

Thanks, I’ll send the updated version to address the unique device ID concern.

Kind regards,
Bean