* [PATCH-for-10.1 0/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected @ 2025-08-08 13:51 Philippe Mathieu-Daudé 2025-08-08 13:51 ` [PATCH-for-10.1 1/2] " Philippe Mathieu-Daudé 2025-08-08 13:51 ` [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD " Philippe Mathieu-Daudé 0 siblings, 2 replies; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2025-08-08 13:51 UTC (permalink / raw) To: qemu-devel Cc: Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Philippe Mathieu-Daudé, Palmer Dabbelt, qemu-block Trivial fix for the issue reported by Guenter here: https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/ - Return dummy byte when no card is connected - Add a test Philippe Mathieu-Daudé (2): hw/sd/ssi-sd: Return noise (dummy byte) when no card connected tests/functional: Test SPI-SD adapter without SD card connected hw/sd/ssi-sd.c | 4 ++++ tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) -- 2.49.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH-for-10.1 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected 2025-08-08 13:51 [PATCH-for-10.1 0/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Philippe Mathieu-Daudé @ 2025-08-08 13:51 ` Philippe Mathieu-Daudé 2025-08-08 20:12 ` Guenter Roeck 2025-08-12 13:20 ` Alex Bennée 2025-08-08 13:51 ` [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD " Philippe Mathieu-Daudé 1 sibling, 2 replies; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2025-08-08 13:51 UTC (permalink / raw) To: qemu-devel Cc: Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Philippe Mathieu-Daudé, Palmer Dabbelt, qemu-block Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card code") exposed a bug in the SPI adapter: if no SD card is plugged, we shouldn't return any particular packet response, but the noise shifted on the MISO line. Return the dummy byte, otherwise we get: qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed. Reported-by: Guenter Roeck <linux@roeck-us.net> Fixes: 775616c3ae8 ("Partial SD card SPI mode support") Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/sd/ssi-sd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index 594dead19ee..3aacbd03871 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val) SDRequest request; uint8_t longresp[5]; + if (!sdbus_get_inserted(&s->sdbus)) { + return SSI_DUMMY; + } + /* * Special case: allow CMD12 (STOP TRANSMISSION) while reading data. * -- 2.49.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH-for-10.1 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected 2025-08-08 13:51 ` [PATCH-for-10.1 1/2] " Philippe Mathieu-Daudé @ 2025-08-08 20:12 ` Guenter Roeck 2025-08-12 13:20 ` Alex Bennée 1 sibling, 0 replies; 8+ messages in thread From: Guenter Roeck @ 2025-08-08 20:12 UTC (permalink / raw) To: Philippe Mathieu-Daudé, qemu-devel Cc: qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Palmer Dabbelt, qemu-block On 8/8/25 06:51, Philippe Mathieu-Daudé wrote: > Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card > code") exposed a bug in the SPI adapter: if no SD card is plugged, > we shouldn't return any particular packet response, but the noise > shifted on the MISO line. Return the dummy byte, otherwise we get: > > qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed. > > Reported-by: Guenter Roeck <linux@roeck-us.net> > Fixes: 775616c3ae8 ("Partial SD card SPI mode support") > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Guenter Roeck <linux@roeck-us.net> Guenter > --- > hw/sd/ssi-sd.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c > index 594dead19ee..3aacbd03871 100644 > --- a/hw/sd/ssi-sd.c > +++ b/hw/sd/ssi-sd.c > @@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val) > SDRequest request; > uint8_t longresp[5]; > > + if (!sdbus_get_inserted(&s->sdbus)) { > + return SSI_DUMMY; > + } > + > /* > * Special case: allow CMD12 (STOP TRANSMISSION) while reading data. > * ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH-for-10.1 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected 2025-08-08 13:51 ` [PATCH-for-10.1 1/2] " Philippe Mathieu-Daudé 2025-08-08 20:12 ` Guenter Roeck @ 2025-08-12 13:20 ` Alex Bennée 2025-08-12 13:27 ` Philippe Mathieu-Daudé 1 sibling, 1 reply; 8+ messages in thread From: Alex Bennée @ 2025-08-12 13:20 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: qemu-devel, Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Palmer Dabbelt, qemu-block Philippe Mathieu-Daudé <philmd@linaro.org> writes: > Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card > code") exposed a bug in the SPI adapter: if no SD card is plugged, > we shouldn't return any particular packet response, but the noise > shifted on the MISO line. Return the dummy byte, otherwise we get: > > qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed. > > Reported-by: Guenter Roeck <linux@roeck-us.net> > Fixes: 775616c3ae8 ("Partial SD card SPI mode support") > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/sd/ssi-sd.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c > index 594dead19ee..3aacbd03871 100644 > --- a/hw/sd/ssi-sd.c > +++ b/hw/sd/ssi-sd.c > @@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val) > SDRequest request; > uint8_t longresp[5]; > > + if (!sdbus_get_inserted(&s->sdbus)) { > + return SSI_DUMMY; > + } > + Seems fair although it's hard to track what is consuming this value. I think we end up in ssi_transfer() which a surprising number of calls don't even bother checking the return value, other just seem to | the result when iterating across devices. We should probably improve on the definitions of transfer/transfer_raw and explain what the return value is. Anyway: Reviewed-by: Alex Bennée <alex.bennee@linaro.org> > /* > * Special case: allow CMD12 (STOP TRANSMISSION) while reading data. > * -- Alex Bennée Virtualisation Tech Lead @ Linaro ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH-for-10.1 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected 2025-08-12 13:20 ` Alex Bennée @ 2025-08-12 13:27 ` Philippe Mathieu-Daudé 0 siblings, 0 replies; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2025-08-12 13:27 UTC (permalink / raw) To: Alex Bennée Cc: qemu-devel, Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Palmer Dabbelt, qemu-block On 12/8/25 15:20, Alex Bennée wrote: > Philippe Mathieu-Daudé <philmd@linaro.org> writes: > >> Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card >> code") exposed a bug in the SPI adapter: if no SD card is plugged, >> we shouldn't return any particular packet response, but the noise >> shifted on the MISO line. Return the dummy byte, otherwise we get: >> >> qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed. >> >> Reported-by: Guenter Roeck <linux@roeck-us.net> >> Fixes: 775616c3ae8 ("Partial SD card SPI mode support") >> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >> --- >> hw/sd/ssi-sd.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c >> index 594dead19ee..3aacbd03871 100644 >> --- a/hw/sd/ssi-sd.c >> +++ b/hw/sd/ssi-sd.c >> @@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val) >> SDRequest request; >> uint8_t longresp[5]; >> >> + if (!sdbus_get_inserted(&s->sdbus)) { >> + return SSI_DUMMY; >> + } >> + > > Seems fair although it's hard to track what is consuming this value. I > think we end up in ssi_transfer() which a surprising number of calls > don't even bother checking the return value, other just seem to | the > result when iterating across devices. A SPI transaction consists of shifting bit in sync the CLK line, writing on the MOSI (output) line / and reading MISO (input) line. IOW, each time you write a word, you also read it at the same time. When a driver just wants to write, it is OK to ignore the returned values. In this case, we don't want to return "There is a card with error" because there is no card. We shift the request on the MOSI line, but nothing replies on the MISO line. Should I reword the commit description? > > We should probably improve on the definitions of transfer/transfer_raw > and explain what the return value is. Agreed. > > Anyway: > > Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Thanks! ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected 2025-08-08 13:51 [PATCH-for-10.1 0/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Philippe Mathieu-Daudé 2025-08-08 13:51 ` [PATCH-for-10.1 1/2] " Philippe Mathieu-Daudé @ 2025-08-08 13:51 ` Philippe Mathieu-Daudé 2025-08-12 13:24 ` Alex Bennée 1 sibling, 1 reply; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2025-08-08 13:51 UTC (permalink / raw) To: qemu-devel Cc: Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Philippe Mathieu-Daudé, Palmer Dabbelt, qemu-block SPI-SD adapter should be usable, even without any SD card wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it more generic and add another test, inspired by this report: https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/ Inspired-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/functional/test_riscv64_sifive_u.py b/tests/functional/test_riscv64_sifive_u.py index dc4cb8a4a96..f7ab1abfd56 100755 --- a/tests/functional/test_riscv64_sifive_u.py +++ b/tests/functional/test_riscv64_sifive_u.py @@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest): 'rootfs.ext2.gz'), 'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b') - def test_riscv64_sifive_u_mmc_spi(self): + def do_test_riscv64_sifive_u_mmc_spi(self, connect_card): self.set_machine('sifive_u') kernel_path = self.ASSET_KERNEL.fetch() rootfs_path = self.uncompress(self.ASSET_ROOTFS) self.vm.set_console() kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + - 'root=/dev/mmcblk0 rootwait ' 'earlycon=sbi console=ttySIF0 ' - 'panic=-1 noreboot') + 'root=/dev/mmcblk0 ') self.vm.add_args('-kernel', kernel_path, - '-drive', f'file={rootfs_path},if=sd,format=raw', '-append', kernel_command_line, '-no-reboot') + if connect_card: + self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw') + kernel_command_line += 'panic=-1 noreboot rootwait ' + pattern = 'Boot successful.' + else: + kernel_command_line += 'panic=0 noreboot ' + pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)' + self.vm.launch() - self.wait_for_console_pattern('Boot successful.') + self.wait_for_console_pattern(pattern) os.remove(rootfs_path) + def _test_riscv64_sifive_u_nommc_spi(self): + self.do_test_riscv64_sifive_u_mmc_spi(False) + + def test_riscv64_sifive_u_mmc_spi(self): + self.do_test_riscv64_sifive_u_mmc_spi(True) + if __name__ == '__main__': LinuxKernelTest.main() -- 2.49.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected 2025-08-08 13:51 ` [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD " Philippe Mathieu-Daudé @ 2025-08-12 13:24 ` Alex Bennée 2025-08-12 13:28 ` Philippe Mathieu-Daudé 0 siblings, 1 reply; 8+ messages in thread From: Alex Bennée @ 2025-08-12 13:24 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: qemu-devel, Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Palmer Dabbelt, qemu-block Philippe Mathieu-Daudé <philmd@linaro.org> writes: > SPI-SD adapter should be usable, even without any SD card > wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it > more generic and add another test, inspired by this report: > https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/ > > Inspired-by: Guenter Roeck <linux@roeck-us.net> > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) > > diff --git a/tests/functional/test_riscv64_sifive_u.py b/tests/functional/test_riscv64_sifive_u.py > index dc4cb8a4a96..f7ab1abfd56 100755 > --- a/tests/functional/test_riscv64_sifive_u.py > +++ b/tests/functional/test_riscv64_sifive_u.py > @@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest): > 'rootfs.ext2.gz'), > 'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b') > > - def test_riscv64_sifive_u_mmc_spi(self): > + def do_test_riscv64_sifive_u_mmc_spi(self, connect_card): > self.set_machine('sifive_u') > kernel_path = self.ASSET_KERNEL.fetch() > rootfs_path = self.uncompress(self.ASSET_ROOTFS) > > self.vm.set_console() > kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + > - 'root=/dev/mmcblk0 rootwait ' > 'earlycon=sbi console=ttySIF0 ' > - 'panic=-1 noreboot') > + 'root=/dev/mmcblk0 ') > self.vm.add_args('-kernel', kernel_path, > - '-drive', f'file={rootfs_path},if=sd,format=raw', > '-append', kernel_command_line, > '-no-reboot') > + if connect_card: > + self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw') > + kernel_command_line += 'panic=-1 noreboot rootwait ' > + pattern = 'Boot successful.' > + else: > + kernel_command_line += 'panic=0 noreboot ' > + pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)' > + > self.vm.launch() > - self.wait_for_console_pattern('Boot successful.') > + self.wait_for_console_pattern(pattern) > > os.remove(rootfs_path) > > + def _test_riscv64_sifive_u_nommc_spi(self): > + self.do_test_riscv64_sifive_u_mmc_spi(False) This test won't run because of the leading _ > + > + def test_riscv64_sifive_u_mmc_spi(self): > + self.do_test_riscv64_sifive_u_mmc_spi(True) > + > > if __name__ == '__main__': > LinuxKernelTest.main() -- Alex Bennée Virtualisation Tech Lead @ Linaro ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected 2025-08-12 13:24 ` Alex Bennée @ 2025-08-12 13:28 ` Philippe Mathieu-Daudé 0 siblings, 0 replies; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2025-08-12 13:28 UTC (permalink / raw) To: Alex Bennée Cc: qemu-devel, Guenter Roeck, qemu-riscv, Liu Zhiwei, Bin Meng, Daniel Henrique Barboza, Alistair Francis, Weiwei Li, Palmer Dabbelt, qemu-block On 12/8/25 15:24, Alex Bennée wrote: > Philippe Mathieu-Daudé <philmd@linaro.org> writes: > >> SPI-SD adapter should be usable, even without any SD card >> wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it >> more generic and add another test, inspired by this report: >> https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/ >> >> Inspired-by: Guenter Roeck <linux@roeck-us.net> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >> --- >> tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++----- >> 1 file changed, 17 insertions(+), 5 deletions(-) >> >> diff --git a/tests/functional/test_riscv64_sifive_u.py b/tests/functional/test_riscv64_sifive_u.py >> index dc4cb8a4a96..f7ab1abfd56 100755 >> --- a/tests/functional/test_riscv64_sifive_u.py >> +++ b/tests/functional/test_riscv64_sifive_u.py >> @@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest): >> 'rootfs.ext2.gz'), >> 'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b') >> >> - def test_riscv64_sifive_u_mmc_spi(self): >> + def do_test_riscv64_sifive_u_mmc_spi(self, connect_card): >> self.set_machine('sifive_u') >> kernel_path = self.ASSET_KERNEL.fetch() >> rootfs_path = self.uncompress(self.ASSET_ROOTFS) >> >> self.vm.set_console() >> kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + >> - 'root=/dev/mmcblk0 rootwait ' >> 'earlycon=sbi console=ttySIF0 ' >> - 'panic=-1 noreboot') >> + 'root=/dev/mmcblk0 ') >> self.vm.add_args('-kernel', kernel_path, >> - '-drive', f'file={rootfs_path},if=sd,format=raw', >> '-append', kernel_command_line, >> '-no-reboot') >> + if connect_card: >> + self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw') >> + kernel_command_line += 'panic=-1 noreboot rootwait ' >> + pattern = 'Boot successful.' >> + else: >> + kernel_command_line += 'panic=0 noreboot ' >> + pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)' >> + >> self.vm.launch() >> - self.wait_for_console_pattern('Boot successful.') >> + self.wait_for_console_pattern(pattern) >> >> os.remove(rootfs_path) >> >> + def _test_riscv64_sifive_u_nommc_spi(self): >> + self.do_test_riscv64_sifive_u_mmc_spi(False) > > This test won't run because of the leading _ Oops, I was carefully testing one case after each other and missed to remove this leading char! > >> + >> + def test_riscv64_sifive_u_mmc_spi(self): >> + self.do_test_riscv64_sifive_u_mmc_spi(True) >> + >> >> if __name__ == '__main__': >> LinuxKernelTest.main() > ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-08-12 13:29 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-08 13:51 [PATCH-for-10.1 0/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Philippe Mathieu-Daudé 2025-08-08 13:51 ` [PATCH-for-10.1 1/2] " Philippe Mathieu-Daudé 2025-08-08 20:12 ` Guenter Roeck 2025-08-12 13:20 ` Alex Bennée 2025-08-12 13:27 ` Philippe Mathieu-Daudé 2025-08-08 13:51 ` [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD " Philippe Mathieu-Daudé 2025-08-12 13:24 ` Alex Bennée 2025-08-12 13:28 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).