All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/6] ufs: rpmb: route OP-TEE RPMB secure storage over UFS
@ 2026-09-18 20:06 Jorge Ramirez-Ortiz
  2026-09-18 20:06 ` [PATCH v5 1/6] ufs: decode string descriptors as UTF-16 big-endian Jorge Ramirez-Ortiz
                   ` (6 more replies)
  0 siblings, 7 replies; 22+ messages in thread
From: Jorge Ramirez-Ortiz @ 2026-09-18 20:06 UTC (permalink / raw)
  To: jorge.ramirez, dlechner, trini, jens.wiklander, ilias.apalodimas,
	peng.fan, jh80.chung, tanmay.kathpalia, neil.armstrong,
	bhupesh.linux, n-francis, xypron.glpk, s-vadapalli, michal.simek,
	jbx6244, marek.vasut+renesas, sumit.garg, jens.wiklander
  Cc: u-boot

OP-TEE secure storage (CFG_RPMB_FS) relies on an RPMB partition, but
U-Boot's OP-TEE RPMB supplicant only speaks the legacy single-command
interface, which is bound to eMMC. SoCs that are UFS-only and have no
eMMC (for example the Qualcomm SA8775P) therefore cannot back OP-TEE
secure storage from U-Boot today. This series adds that support.

It introduces the transport-agnostic OP-TEE RPMB "subsystem" interface
(PROBE_RESET / PROBE_NEXT / FRAMES), where the normal world enumerates
the RPMB device and reports its kind, size and CID, then carries the
signed frames. The legacy eMMC supplicant is preserved unchanged, only
renamed to rpmb_emmc.c, with the new UFS backend added as a separate
rpmb_ufs.c; the two are mutually exclusive via Kconfig (SUPPORT_UFS_RPMB
depends on !SUPPORT_EMMC_RPMB) because the OP-TEE supplicant handles a
single RPMB transport. The subsystem interface is UFS-only for now; eMMC
can be migrated onto it later as the legacy path is retired.

On top of that it adds a UFS RPMB transport that moves JEDEC RPMB frames
to and from the RPMB Well-Known LUN using SCSI SECURITY PROTOCOL IN/OUT.
The per-region 16-byte CID is derived by BLAKE2b-hashing the exact
device-id string the Linux kernel builds (ufshcd_create_device_id()
plus a "-R<region>" suffix), so OP-TEE derives an RPMB key that matches
the one Linux would use.

The first patch is a standalone UFS descriptor fix the RPMB path depends
on (UTF-16BE string decoding). A small preparatory patch surfaces the
RESPONSE UPIU sense data from ufs_scsi_exec() so the transport can retry
only on a power-on UNIT ATTENTION; the transport patch also bounces
unaligned frames through a DMA-aligned buffer for the RPMB WLUN.

Note: reading UFS descriptors reliably also requires the descriptor
data-segment cache-invalidation fix, which has already been posted and
merged separately, so this series is based on top of it.

Tested on the Qualcomm IQ-9075-EVK (SA8775P): OP-TEE with CFG_RPMB_FS
programs the RPMB key through U-Boot and reads/writes secure-storage
objects, with the derived CID matching the Linux UFS device_id ABI.

Dependencies:
Linux kernel:
 https://lore.kernel.org/linux-scsi/20260716083728.2226422-1-jorge.ramirez@oss.qualcomm.com/
Op-tee
 https://github.com/OP-TEE/optee_os/pull/7881

v5:
 - ufs: decode string descriptors: added a Fixes: tag; the EFI
   file_open() callers now pass UTF16_LITTLE_ENDIAN (UEFI CHAR16 / FAT
   paths are little-endian by origin) instead of UTF16_HOST_ENDIAN.
   UTF16_HOST_ENDIAN is kept in the enum to mirror the kernel's
   utf16s_to_utf8s().
 - ufs: new patch "surface sense data from ufs_scsi_exec()": copy the
   RESPONSE UPIU sense data into the SCSI command so callers can read the
   sense key. No current caller inspects it, so behaviour is unchanged.
 - ufs: RPMB transport: retry the SECURITY PROTOCOL only on a UNIT
   ATTENTION sense key (using the surfaced sense data) rather than on any
   error; build the status frame with put_unaligned_be16(); move
   GEOMETRY_DESC_RPMB_RW_SIZE to the per-region CID patch that first uses
   it.
 - Series is now 6 patches (was 5).

v4:
 - ufs: decode string descriptors: dropped the in-place
   ufshcd_str_desc_to_cpu() byte-swap helper; instead added an endian
   argument to utf16_to_utf8() (UTF16_HOST/LITTLE/BIG_ENDIAN) and decode
   with UTF16_BIG_ENDIAN, mirroring the kernel's utf16s_to_utf8s().
   Existing EFI callers pass UTF16_HOST_ENDIAN.
 - ufs: RPMB transport: build the SECURITY PROTOCOL CDB with
   put_unaligned_be16()/put_unaligned_be32(); drop the
   rpmb_frame_request() helper in favour of get_unaligned_be16(); move
   ufs_rpmb_read_geometry() to the patch that first uses it so it is not
   an unused static function during git bisect.
 - ufs: per-region CID/size: reject an out-of-range device-reported
   logical block size before shifting and split the size computation into
   separate statements for readability; order <u-boot/...> after
   <linux/...>; note that the serial hex encoding matches the kernel
   device-id ABI.

v3:
 - Renamed the legacy eMMC supplicant to rpmb_emmc.c (was rpmb_legacy.c)
   and kept it as a pure 100% rename: the UFS RPMB subsystem backend now
   lives in its own rpmb_ufs.c instead of being folded into rpmb.c, so
   the eMMC path is left byte-for-byte unchanged.
 - Added CONFIG_UFS_RPMB_CONTROLLER to select the RPMB-owning UFS
   controller on boards with more than one UFS controller.
 - Reworked the commit messages to lead with the motivation rather than
   the implementation detail.

v2:
 - Squashed the standalone "retry SECURITY PROTOCOL on power-on UNIT
   ATTENTION" and "bounce unaligned frames through a DMA-aligned buffer"
   patches into the UFS RPMB transport patch; the series is now 5 patches.
 - Reused the existing ufshcd_read_desc_param() (now exported) for all
   descriptor reads instead of adding a new ufshcd_read_descriptor()
   wrapper.
 - Moved the SECURITY PROTOCOL IN/OUT opcodes to the generic SCSI header
   as SCSI_SECURITY_PROTOCOL_IN/OUT instead of private UFS defines.
 - Factored the UTF-16BE string-descriptor byte-swap into a
   ufshcd_str_desc_to_cpu() helper.
 - Dropped the ufs_rpmb_get_scsi_dev() wrapper; callers now use
   uclass_get_device(UCLASS_SCSI, ...) directly.

Jorge Ramirez-Ortiz (6):
  ufs: decode string descriptors as UTF-16 big-endian
  ufs: surface sense data from ufs_scsi_exec()
  ufs: add RPMB transport over SCSI SECURITY PROTOCOL
  ufs: derive the per-region RPMB CID and size for OP-TEE
  optee: rename rpmb.c to rpmb_emmc.c
  optee: implement the RPMB subsystem interface for UFS

 drivers/tee/optee/Makefile                |   3 +-
 drivers/tee/optee/optee_msg_supplicant.h  |   8 +
 drivers/tee/optee/optee_private.h         |  41 +++
 drivers/tee/optee/{rpmb.c => rpmb_emmc.c} |   0
 drivers/tee/optee/rpmb_ufs.c              | 141 +++++++++
 drivers/tee/optee/supplicant.c            |   9 +
 drivers/ufs/Kconfig                       |  21 ++
 drivers/ufs/Makefile                      |   1 +
 drivers/ufs/ufs-rpmb.c                    | 347 ++++++++++++++++++++++
 drivers/ufs/ufs-uclass.c                  |  38 ++-
 drivers/ufs/ufs.h                         |   7 +
 include/charset.h                         |  17 +-
 include/scsi.h                            |   2 +
 include/ufs.h                             |  10 +
 lib/charset.c                             |  15 +-
 lib/efi_loader/efi_file.c                 |   4 +-
 16 files changed, 652 insertions(+), 12 deletions(-)
 rename drivers/tee/optee/{rpmb.c => rpmb_emmc.c} (100%)
 create mode 100644 drivers/tee/optee/rpmb_ufs.c
 create mode 100644 drivers/ufs/ufs-rpmb.c


base-commit: b8e0086b585791a771416ce51b58ce0097bc0b28
-- 
2.54.0


^ permalink raw reply	[flat|nested] 22+ messages in thread
* Re: [PATCH v5 0/6] ufs: rpmb: route OP-TEE RPMB secure storage over UFS
@ 2026-09-29  8:35 Macpaul Lin (林智斌)
  0 siblings, 0 replies; 22+ messages in thread
From: Macpaul Lin (林智斌) @ 2026-09-29  8:35 UTC (permalink / raw)
  To: Ilias Apalodimas, Jorge Ramirez
  Cc: Jens Wiklander, Tom Rini, David Lechner, Carlo Caione,
	Julien Stephan, stanleyjhu@google.com, Beanhuo@micron.com,
	Zhaoxuan Zhai, Ethan Hsieh, Jian Hui Lee,
	jens.wiklander@linaro.org, peng.fan@nxp.com,
	jh80.chung@samsung.com, tanmay.kathpalia@altera.com,
	neil.armstrong@linaro.org, bhupesh.linux@gmail.com,
	n-francis@ti.com, xypron.glpk@gmx.de, s-vadapalli@ti.com,
	michal.simek@amd.com, jbx6244@gmail.com,
	Bear Wang (萩原惟德),
	Ht Lin (林瀚宗),
	Pablo Sun (孫毓翔),
	marek.vasut+renesas@mailbox.org, sumit.garg@oss.qualcomm.com,
	u-boot@lists.u-boot-project.org

[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]

On Mon, 2026-09-28 at 13:02 +0300, Ilias Apalodimas wrote:
> Hi Jorge,
> 
> 
> On Sun, 27 Sept 2026 at 00:09, Jorge Ramirez
> <jorge.ramirez@oss.qualcomm.com> wrote:
> > 
> > On 26/09/26 22:41:00, Jorge Ramirez wrote:
> > > On 25/09/26 12:59:28, Ilias Apalodimas wrote:
> > > > Thanks for the detailed analysis.
> > > > 
> > > > I am pulling in Jens for OP-TEE and I'll have a closer look
> > > > next week as well.
> > > 
> > > the concernt I read - please correct me if I am wrong - is that
> > > this code affects
> > > downstream projects.
> > > 
> > > This is just not acceptable to me - downstream implementations
> > > should have been
> > > posted to prevent exactly these kind issues.
> > > 
> > > We spent  time and effort doing an implementation and sharing it
> > > with the
> > > community - it wouldnt be fair to us to block this merge on the
> > > basis of
> > > downstream projects being impacted.
> > > 
> > > 
> > 
> > in summary and to be very clear
> > 
> > 1- the upstream CID derivation is the u-boot/op-tee contract that
> > matches mainline linux's ufshcd_create_device_id(). The contract is
> > an
> > OP-TEE-defined ABI, not a Global Platform spec.
> > 
> > 2. Moreover CID-key is OP-TEE's own HUK-based derivation, not GP,
> > not JEDEC.
> > 
> > 3- Nothing here blocks anyone from overriding the static
> > ufs_rpmb_build_cid()
> > downstream.
> > 
> > 3- if downstream scheme differs, that's the cost of having kept it
> > out of tree,
> > not a reason to hold this series for speculative plug-in
> > infrastructure with a
> > single backend.
> 
> +1. Macpaul is there anything else you can review apart from the
> downstream breakage. TBH since you didn;t bother upstreaming that,
> objecting to code that adds real support doesn't really stand as an
> arguement.
> 
> Jorge, I did a quick pass and I don't see any big issues with the
> series. I'll do another pass later this week and send a PR if the CI
> agrees.
> 
> Cheers
> /Ilias

Got it. That's quite reasonable for taking the current implementation.
MediaTek will try to propose the vendor specific helper functions
and and upstream other backends for some downstream
implementation. Hope this could be happened soon. Thanks for taking
time to read the previous reply.

Best regards,
Macpaul Lin


[-- Attachment #2: Type: text/html, Size: 5294 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread
[parent not found: <6abb787b.db7c5649.307e91.b4fcSMTPIN_ADDED_BROKEN@mx.google.com>]

end of thread, other threads:[~2026-10-13 17:51 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18 20:06 [PATCH v5 0/6] ufs: rpmb: route OP-TEE RPMB secure storage over UFS Jorge Ramirez-Ortiz
2026-09-18 20:06 ` [PATCH v5 1/6] ufs: decode string descriptors as UTF-16 big-endian Jorge Ramirez-Ortiz
2026-09-18 20:06 ` [PATCH v5 2/6] ufs: surface sense data from ufs_scsi_exec() Jorge Ramirez-Ortiz
2026-10-02 11:16   ` Ilias Apalodimas
2026-10-13 17:48     ` Jorge Ramirez
2026-10-13 17:51       ` Tom Rini
2026-09-18 20:06 ` [PATCH v5 3/6] ufs: add RPMB transport over SCSI SECURITY PROTOCOL Jorge Ramirez-Ortiz
2026-09-29  3:29   ` Stanley Jhu
2026-09-18 20:06 ` [PATCH v5 4/6] ufs: derive the per-region RPMB CID and size for OP-TEE Jorge Ramirez-Ortiz
2026-09-18 20:06 ` [PATCH v5 5/6] optee: rename rpmb.c to rpmb_emmc.c Jorge Ramirez-Ortiz
2026-10-02 11:14   ` Ilias Apalodimas
2026-09-18 20:06 ` [PATCH v5 6/6] optee: implement the RPMB subsystem interface for UFS Jorge Ramirez-Ortiz
2026-10-02 11:14   ` Ilias Apalodimas
2026-09-18 20:15 ` [PATCH v5 0/6] ufs: rpmb: route OP-TEE RPMB secure storage over UFS Jorge Ramirez
2026-09-24 17:50   ` Macpaul Lin (林智斌)
2026-09-25  9:59     ` Ilias Apalodimas
2026-09-26 20:41       ` Jorge Ramirez
2026-09-26 21:08         ` Jorge Ramirez
2026-09-28  7:32           ` Jens Wiklander
2026-09-28 10:02           ` Ilias Apalodimas
  -- strict thread matches above, loose matches on Subject: below --
2026-09-29  8:35 Macpaul Lin (林智斌)
     [not found] <6abb787b.db7c5649.307e91.b4fcSMTPIN_ADDED_BROKEN@mx.google.com>
2026-10-02  8:33 ` Ilias Apalodimas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.