* [PATCH v2 0/2] cdrom: gdrom: fix block I/O and capacity setting
@ 2026-04-19 16:28 Florian Fuchs
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
2026-04-19 16:28 ` [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open Florian Fuchs
0 siblings, 2 replies; 8+ messages in thread
From: Florian Fuchs @ 2026-04-19 16:28 UTC (permalink / raw)
To: linux-sh, John Paul Adrian Glaubitz, Artur Rojek
Cc: Adrian McMenamin, linux-kernel, Florian Fuchs
Hi all,
This series fixes a gdrom driver Oops due to bad MMIO register access and
fixes the missing updates of the block layer gendisk capacity that
prevented ISO9660 mounts from working.
The change was tested on real Sega Dreamcast devices (PAL-E, NTSC-J,
NTSC-U) with physical CD-R discs and with GDEMU emulated discs. Before:
Oops on mount and an unusable drive. After: Successfully able to mount
and use the inserted medium.
Thanks,
Florian
---
v1->v2: for "cdrom: gdrom: replace port I/O with MMIO accessors": Don't
use helper functions with io.*_rep(), but writesw() and readsw()
local in the respective functions. Improved failure case of
gdrom_update_capacity() in gdrom_bdops_open().
v1: https://lore.kernel.org/linux-sh/20260405082330.4104672-1-fuchsfl@gmail.com/
Florian Fuchs (2):
cdrom: gdrom: replace port I/O with MMIO accessors
cdrom: gdrom: update gendisk capacity on open
drivers/cdrom/gdrom.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors
2026-04-19 16:28 [PATCH v2 0/2] cdrom: gdrom: fix block I/O and capacity setting Florian Fuchs
@ 2026-04-19 16:28 ` Florian Fuchs
2026-04-19 16:50 ` Artur Rojek
` (2 more replies)
2026-04-19 16:28 ` [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open Florian Fuchs
1 sibling, 3 replies; 8+ messages in thread
From: Florian Fuchs @ 2026-04-19 16:28 UTC (permalink / raw)
To: linux-sh, John Paul Adrian Glaubitz, Artur Rojek
Cc: Adrian McMenamin, linux-kernel, Florian Fuchs
GDROM_DATA_REG is a memory-mapped data register, but the driver uses
outsw() and insw() only for this register. Replace this with MMIO
accessors readsw() / writesw().
Before, it oopsed accessing the data register, as the io_port_base
P2SEG gets added to the argument in outsw() / insw(), which leads to an
unusable drive:
BUG: unable to handle kernel paging request at 405f7080
PC: [<8c28d5b4>] gdrom_spicommand+0x6c/0xb0
Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
---
v1->v2: Don't use helper functions with io.*_rep(), but writesw() and
readsw() local in the respective functions
v1: https://lore.kernel.org/linux-sh/20260405082330.4104672-2-fuchsfl@gmail.com/
---
drivers/cdrom/gdrom.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 4ba4dd06cbf4..89938d9b2825 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -198,7 +198,7 @@ static void gdrom_spicommand(void *spi_string, int buflen)
gdrom_getsense(NULL);
return;
}
- outsw(GDROM_DATA_REG, cmd, 6);
+ writesw((void __iomem *)GDROM_DATA_REG, cmd, 6);
}
@@ -282,7 +282,7 @@ static int gdrom_readtoc_cmd(struct gdromtoc *toc, int session)
err = -EINVAL;
goto cleanup_readtoc;
}
- insw(GDROM_DATA_REG, toc, tocsize/2);
+ readsw((void __iomem *)GDROM_DATA_REG, toc, tocsize / 2);
if (gd.status & 0x01)
err = -EINVAL;
@@ -433,7 +433,7 @@ static int gdrom_getsense(short *bufstring)
GDROM_DEFAULT_TIMEOUT);
if (gd.pending)
goto cleanup_sense;
- insw(GDROM_DATA_REG, &sense, sense_command->buflen/2);
+ readsw((void __iomem *)GDROM_DATA_REG, &sense, sense_command->buflen / 2);
if (sense[1] & 40) {
pr_info("Drive not ready - command aborted\n");
goto cleanup_sense;
@@ -612,7 +612,7 @@ static blk_status_t gdrom_readdisk_dma(struct request *req)
cpu_relax();
gd.pending = 1;
gd.transfer = 1;
- outsw(GDROM_DATA_REG, &read_command->cmd, 6);
+ writesw((void __iomem *)GDROM_DATA_REG, read_command->cmd, 6);
timeout = jiffies + HZ / 2;
/* Wait for any pending DMA to finish */
while (__raw_readb(GDROM_DMA_STATUS_REG) &&
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open
2026-04-19 16:28 [PATCH v2 0/2] cdrom: gdrom: fix block I/O and capacity setting Florian Fuchs
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
@ 2026-04-19 16:28 ` Florian Fuchs
2026-04-19 16:59 ` Artur Rojek
1 sibling, 1 reply; 8+ messages in thread
From: Florian Fuchs @ 2026-04-19 16:28 UTC (permalink / raw)
To: linux-sh, John Paul Adrian Glaubitz, Artur Rojek
Cc: Adrian McMenamin, linux-kernel, Florian Fuchs
Update the gendisk capacity of the media. Without the capacity, the block
reads fail before reaching the request queue, which prevented ISO9660
mounts. Refresh the capacity from the TOC leadout in gdrom_bdops_open()
so it checks the inserted media.
Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
---
v1->v2: no change for gdrom_update_capacity(), but for
gdrom_bdops_open(): handle the failure case when
gdrom_update_capacity() fails but previous cdrom_open() succeeded,
to cleanup the successful cdrom_open() with cdrom_release()
v1: https://lore.kernel.org/linux-sh/20260405082330.4104672-3-fuchsfl@gmail.com/
---
drivers/cdrom/gdrom.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 89938d9b2825..fb95288fad72 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -474,6 +474,25 @@ static const struct cdrom_device_ops gdrom_ops = {
CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
};
+static int gdrom_update_capacity(void)
+{
+ sector_t cap;
+ int ret;
+
+ if (gdrom_drivestatus(gd.cd_info, CDSL_CURRENT) != CDS_DISC_OK) {
+ set_capacity(gd.disk, 0);
+ return -ENOMEDIUM;
+ }
+ ret = gdrom_readtoc_cmd(gd.toc, 0);
+ if (ret) {
+ set_capacity(gd.disk, 0);
+ return ret;
+ }
+ cap = (sector_t)get_entry_lba(gd.toc->leadout) * GD_TO_BLK;
+ set_capacity(gd.disk, cap);
+ return 0;
+}
+
static int gdrom_bdops_open(struct gendisk *disk, blk_mode_t mode)
{
int ret;
@@ -482,6 +501,12 @@ static int gdrom_bdops_open(struct gendisk *disk, blk_mode_t mode)
mutex_lock(&gdrom_mutex);
ret = cdrom_open(gd.cd_info, mode);
+ if (ret)
+ goto out;
+ ret = gdrom_update_capacity();
+ if (ret)
+ cdrom_release(gd.cd_info);
+out:
mutex_unlock(&gdrom_mutex);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
@ 2026-04-19 16:50 ` Artur Rojek
2026-04-20 10:20 ` Adrian McMenamin
2026-04-20 12:29 ` Adrian McMenamin
2 siblings, 0 replies; 8+ messages in thread
From: Artur Rojek @ 2026-04-19 16:50 UTC (permalink / raw)
To: Florian Fuchs
Cc: linux-sh, John Paul Adrian Glaubitz, Adrian McMenamin,
linux-kernel
On 2026-04-19 18:28, Florian Fuchs wrote:
> GDROM_DATA_REG is a memory-mapped data register, but the driver uses
> outsw() and insw() only for this register. Replace this with MMIO
> accessors readsw() / writesw().
>
> Before, it oopsed accessing the data register, as the io_port_base
> P2SEG gets added to the argument in outsw() / insw(), which leads to an
> unusable drive:
>
> BUG: unable to handle kernel paging request at 405f7080
> PC: [<8c28d5b4>] gdrom_spicommand+0x6c/0xb0
>
> Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
Acked-by: Artur Rojek <contact@artur-rojek.eu>
> ---
> v1->v2: Don't use helper functions with io.*_rep(), but writesw() and
> readsw() local in the respective functions
>
> v1:
> https://lore.kernel.org/linux-sh/20260405082330.4104672-2-fuchsfl@gmail.com/
> ---
> drivers/cdrom/gdrom.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
> index 4ba4dd06cbf4..89938d9b2825 100644
> --- a/drivers/cdrom/gdrom.c
> +++ b/drivers/cdrom/gdrom.c
> @@ -198,7 +198,7 @@ static void gdrom_spicommand(void *spi_string, int
> buflen)
> gdrom_getsense(NULL);
> return;
> }
> - outsw(GDROM_DATA_REG, cmd, 6);
> + writesw((void __iomem *)GDROM_DATA_REG, cmd, 6);
> }
>
>
> @@ -282,7 +282,7 @@ static int gdrom_readtoc_cmd(struct gdromtoc *toc,
> int session)
> err = -EINVAL;
> goto cleanup_readtoc;
> }
> - insw(GDROM_DATA_REG, toc, tocsize/2);
> + readsw((void __iomem *)GDROM_DATA_REG, toc, tocsize / 2);
> if (gd.status & 0x01)
> err = -EINVAL;
>
> @@ -433,7 +433,7 @@ static int gdrom_getsense(short *bufstring)
> GDROM_DEFAULT_TIMEOUT);
> if (gd.pending)
> goto cleanup_sense;
> - insw(GDROM_DATA_REG, &sense, sense_command->buflen/2);
> + readsw((void __iomem *)GDROM_DATA_REG, &sense, sense_command->buflen
> / 2);
> if (sense[1] & 40) {
> pr_info("Drive not ready - command aborted\n");
> goto cleanup_sense;
> @@ -612,7 +612,7 @@ static blk_status_t gdrom_readdisk_dma(struct
> request *req)
> cpu_relax();
> gd.pending = 1;
> gd.transfer = 1;
> - outsw(GDROM_DATA_REG, &read_command->cmd, 6);
> + writesw((void __iomem *)GDROM_DATA_REG, read_command->cmd, 6);
> timeout = jiffies + HZ / 2;
> /* Wait for any pending DMA to finish */
> while (__raw_readb(GDROM_DMA_STATUS_REG) &&
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open
2026-04-19 16:28 ` [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open Florian Fuchs
@ 2026-04-19 16:59 ` Artur Rojek
0 siblings, 0 replies; 8+ messages in thread
From: Artur Rojek @ 2026-04-19 16:59 UTC (permalink / raw)
To: Florian Fuchs
Cc: linux-sh, John Paul Adrian Glaubitz, Adrian McMenamin,
linux-kernel
On 2026-04-19 18:28, Florian Fuchs wrote:
> Update the gendisk capacity of the media. Without the capacity, the
> block
> reads fail before reaching the request queue, which prevented ISO9660
> mounts. Refresh the capacity from the TOC leadout in gdrom_bdops_open()
> so it checks the inserted media.
>
> Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
> ---
> v1->v2: no change for gdrom_update_capacity(), but for
> gdrom_bdops_open(): handle the failure case when
> gdrom_update_capacity() fails but previous cdrom_open()
> succeeded,
> to cleanup the successful cdrom_open() with cdrom_release()
>
> v1:
> https://lore.kernel.org/linux-sh/20260405082330.4104672-3-fuchsfl@gmail.com/
> ---
> drivers/cdrom/gdrom.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
> index 89938d9b2825..fb95288fad72 100644
> --- a/drivers/cdrom/gdrom.c
> +++ b/drivers/cdrom/gdrom.c
> @@ -474,6 +474,25 @@ static const struct cdrom_device_ops gdrom_ops = {
> CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
> };
>
> +static int gdrom_update_capacity(void)
> +{
> + sector_t cap;
> + int ret;
> +
> + if (gdrom_drivestatus(gd.cd_info, CDSL_CURRENT) != CDS_DISC_OK) {
> + set_capacity(gd.disk, 0);
> + return -ENOMEDIUM;
> + }
> + ret = gdrom_readtoc_cmd(gd.toc, 0);
> + if (ret) {
> + set_capacity(gd.disk, 0);
> + return ret;
> + }
> + cap = (sector_t)get_entry_lba(gd.toc->leadout) * GD_TO_BLK;
> + set_capacity(gd.disk, cap);
> + return 0;
> +}
> +
> static int gdrom_bdops_open(struct gendisk *disk, blk_mode_t mode)
> {
> int ret;
> @@ -482,6 +501,12 @@ static int gdrom_bdops_open(struct gendisk *disk,
> blk_mode_t mode)
>
> mutex_lock(&gdrom_mutex);
> ret = cdrom_open(gd.cd_info, mode);
> + if (ret)
> + goto out;
> + ret = gdrom_update_capacity();
> + if (ret)
> + cdrom_release(gd.cd_info);
> +out:
> mutex_unlock(&gdrom_mutex);
> return ret;
> }
Hey Florian,
thanks for v2!
Acked-by: Artur Rojek <contact@artur-rojek.eu>
PS. I found the reason behind mount failing for the first time after
a disc swap - you need to send a dummy 0x0 SPI command to "sink"
the pending UNIT_ATTENTION error, otherwise it will permeate at
the next command executed, which in our case is gdrom_preparedisk_cmd().
I already sent you a WIP patch via IRC. Once you test it, would you
consider including it in this series and sending v3?
Cheers,
Artur
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
2026-04-19 16:50 ` Artur Rojek
@ 2026-04-20 10:20 ` Adrian McMenamin
2026-04-20 11:01 ` John Paul Adrian Glaubitz
2026-04-20 12:29 ` Adrian McMenamin
2 siblings, 1 reply; 8+ messages in thread
From: Adrian McMenamin @ 2026-04-20 10:20 UTC (permalink / raw)
To: Florian Fuchs
Cc: linux-sh, John Paul Adrian Glaubitz, Artur Rojek, linux-kernel
On Sun, 19 Apr 2026 at 17:29, Florian Fuchs <fuchsfl@gmail.com> wrote:
>
Not tested this on real hardware but I can confirm it addresses the
identified bug and is logically correct.
Adrian McMenamin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors
2026-04-20 10:20 ` Adrian McMenamin
@ 2026-04-20 11:01 ` John Paul Adrian Glaubitz
0 siblings, 0 replies; 8+ messages in thread
From: John Paul Adrian Glaubitz @ 2026-04-20 11:01 UTC (permalink / raw)
To: Adrian McMenamin, Florian Fuchs; +Cc: linux-sh, Artur Rojek, linux-kernel
Hi Adrian,
On Mon, 2026-04-20 at 11:20 +0100, Adrian McMenamin wrote:
> On Sun, 19 Apr 2026 at 17:29, Florian Fuchs <fuchsfl@gmail.com> wrote:
> >
> Not tested this on real hardware but I can confirm it addresses the
> identified bug and is logically correct.
Want to add your Reviewed-by maybe?
Adrian
--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
`. `' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
2026-04-19 16:50 ` Artur Rojek
2026-04-20 10:20 ` Adrian McMenamin
@ 2026-04-20 12:29 ` Adrian McMenamin
2 siblings, 0 replies; 8+ messages in thread
From: Adrian McMenamin @ 2026-04-20 12:29 UTC (permalink / raw)
To: Florian Fuchs
Cc: linux-sh, John Paul Adrian Glaubitz, Artur Rojek, linux-kernel
On Sun, 19 Apr 2026 at 17:29, Florian Fuchs <fuchsfl@gmail.com> wrote:
>
This patch addresses the bug and is logically correct and so looks good to me.
Reviewed-by: Adrian McMenamin <adrianmcmenamin@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-04-20 12:29 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 16:28 [PATCH v2 0/2] cdrom: gdrom: fix block I/O and capacity setting Florian Fuchs
2026-04-19 16:28 ` [PATCH v2 1/2] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
2026-04-19 16:50 ` Artur Rojek
2026-04-20 10:20 ` Adrian McMenamin
2026-04-20 11:01 ` John Paul Adrian Glaubitz
2026-04-20 12:29 ` Adrian McMenamin
2026-04-19 16:28 ` [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open Florian Fuchs
2026-04-19 16:59 ` Artur Rojek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox