Skip to contentSkip to conversation

scsi: ufs: docs: Describe how to test with QEMU

PATCH Superseded Stanley Jhu 3 participants 3 messages Oct 11 – Oct 12

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: docs: Describe how to test with QEMU

QEMU emulates a UFS host controller and logical units, but the kernel tree does not mention it, so developers without UFS hardware have no documented way to exercise the UFS core.

Add a short section with the required kernel options, an example QEMU command line, and what the emulation does not cover.

---
 Documentation/scsi/ufs.rst | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
Documentation/scsi/ufs.rst +33 -0
index a7b2b2ed1c3a..1ff1c8218bf1 100644
@@ -19,6 +19,7 @@ Universal Flash Storage
      3.4 SCSI Error handling
    4. BSG Support
    5. UFS Reference Clock Frequency configuration
+   6. Testing with QEMU
 
 
 1. Overview
@@ -208,3 +209,35 @@ the UFS specification. UFS subsystem will attempt to read the value when
 executing common controller initialization. If the value is available, UFS
 subsystem will ensure the bRefClkFreq attribute of the UFS storage device is
 set accordingly and will modify it if there is a mismatch.
+
+6. Testing with QEMU
+====================
+
+QEMU emulates a UFS host controller as a PCI device named "ufs" and
+logical units named "ufs-lu". This can be used to test changes to the
+UFS core and to ufshcd-pci without UFS hardware.
+
+Enable the following kernel options on top of the architecture
+defconfig::
+
+	CONFIG_SCSI_UFSHCD=y
+	CONFIG_SCSI_UFSHCD_PCI=y
+	CONFIG_BLK_DEV_SD=y
+
+Example for an arm64 guest with one 1 GiB logical unit::
+
+	qemu-img create -f raw ufs.img 1G
+	qemu-system-aarch64 -M virt -cpu max -smp 4 -m 2G -nographic \
+		-kernel arch/arm64/boot/Image -initrd rootfs.cpio.gz \
+		-append "console=ttyAMA0" \
+		-drive file=ufs.img,if=none,id=lu0,format=raw \
+		-device ufs,id=ufs0,serial=0001,mcq=on \
+		-device ufs-lu,drive=lu0,bus=ufs0,lun=0
+
+The logical unit appears as a SCSI disk (/dev/sda). Drop "mcq=on" to
+test the single doorbell mode instead of MCQ. The same -device options
+work with qemu-system-x86_64.
+
+The emulation does not model UniPro, M-PHY, power mode changes,
+hibernation or clock gating hardware, and vendor host drivers are not
+exercised. Changes in those areas still need testing on real hardware.
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines

-----Original Message-----
From: Stanley Jhu <[email protected]>
Sent: Sunday, October 11, 2026 4:03 PM
To: Martin K. Petersen <[email protected]>; James E.J. Bottomley <[email protected]>; Jonathan Corbet <[email protected]>
Cc: Bart Van Assche <[email protected]>; Alim Akhtar <[email protected]>; Shuah Khan <[email protected]>; Randy Dunlap <[email protected]>; Jeuk Kim <[email protected]>; Bean Huo <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]
Subject: [PATCH] scsi: ufs: docs: Describe how to test with QEMU

QEMU emulates a UFS host controller and logical units, but the kernel tree does not mention it, so developers without UFS hardware have no documented way to exercise the UFS core.

Quoted 5 lines

Add a short section with the required kernel options, an example QEMU command line, and what the emulation does not cover.

---

Thanks Stanley!
This helps

#2 lore raw
In reply to Stanley Jhu

Stanley,

Thanks, this is very useful, a few comments as below:

Quoted 29 lines · Stanley Jhu

QEMU emulates a UFS host controller and logical units, but the kernel tree does not mention it, so developers without UFS hardware have no documented way to exercise the UFS core.

Add a short section with the required kernel options, an example QEMU command line, and what the emulation does not cover.

---
 Documentation/scsi/ufs.rst | 33 +++++++++++++++++++++++++++++++++

 1 file changed, 33 insertions(+)
Documentation/scsi/ufs.rst +0 -0
index a7b2b2ed1c3a..1ff1c8218bf1 100644
@@ -19,6 +19,7 @@ Universal Flash Storage

      3.4 SCSI Error handling
    4. BSG Support
    5. UFS Reference Clock Frequency configuration +   6. Testing with QEMU


 1. Overview

Documentation/scsi/ufs.rst +0 -0
@@ -208,3 +209,35 @@ the UFS specification. UFS subsystem will attempt to read

the value when
 executing common controller initialization. If the value is available, UFS subsystem will ensure the bRefClkFreq attribute of the UFS storage device is set accordingly and will modify it if there is a mismatch.

Documentation/scsi/ufs.rst the UFS specification. UFS subsystem will attempt to read the value when · line 219

Quoted 8 lines
Documentation/scsi/ufs.rst +8 -0
+
+6. Testing with QEMU
+====================
+
+QEMU emulates a UFS host controller as a PCI device named "ufs" and
+logical units named "ufs-lu". This can be used to test changes to the
+UFS core and to ufshcd-pci without UFS hardware.
+

should here state the minimum QEMU version for the ufs device, and for mcq=on, since the older version QEMU may not have them or one of them.

Quoted 8 lines
Documentation/scsi/ufs.rst +8 -0
+Enable the following kernel options on top of the architecture
+defconfig::
+
+       CONFIG_SCSI_UFSHCD=y
+       CONFIG_SCSI_UFSHCD_PCI=y
+       CONFIG_BLK_DEV_SD=y
+
+Example for an arm64 guest with one 1 GiB logical unit::

Documentation/scsi/ufs.rst the UFS specification. UFS subsystem will attempt to read the value when

Quoted 10 lines
Documentation/scsi/ufs.rst +10 -0
+
+       qemu-img create -f raw ufs.img 1G
+       qemu-system-aarch64 -M virt -cpu max -smp 4 -m 2G -nographic \
+               -kernel arch/arm64/boot/Image -initrd rootfs.cpio.gz \
+               -append "console=ttyAMA0" \
+               -drive file=ufs.img,if=none,id=lu0,format=raw \
+               -device ufs,id=ufs0,serial=0001,mcq=on \
+               -device ufs-lu,drive=lu0,bus=ufs0,lun=0
+
+The logical unit appears as a SCSI disk (/dev/sda).

maybe here adds "for example"-> The logical unit appears as a SCSI disk (for example /dev/sda)

Documentation/scsi/ufs.rst the UFS specification. UFS subsystem will attempt to read the value when · line 241

Quoted 5 lines

Drop "mcq=on" to

Documentation/scsi/ufs.rst +4 -0
+test the single doorbell mode instead of MCQ. The same -device options
+work with qemu-system-x86_64.
+
+The emulation does not model UniPro, M-PHY, power mode changes,

I am cconfused by this statement, since I checked QEMU, the latest QEMU accepts some UIC commands such as hibern8 enter/exit, if I am correct, here "accepts but does not model" would be more precise, you can check hw/ufs/ufs.c:

static void ufs_process_uiccmd(UfsHc *u, uint32_t val)

Documentation/scsi/ufs.rst the UFS specification. UFS subsystem will attempt to read the value when · line 243

Quoted 2 lines
Documentation/scsi/ufs.rst +2 -0
+hibernation or clock gating hardware, and vendor host drivers are not
+exercised. Changes in those areas still need testing on real hardware.

Kind regards,
Bean