[PATCH 0/3] semihosting: Fix a few semihosting bugs

Sean Anderson posted 3 patches 3 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251017213529.998267-1-sean.anderson@linux.dev
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
gdbstub/syscalls.c            |  2 +-
semihosting/arm-compat-semi.c | 22 +++++++++++++++-------
2 files changed, 16 insertions(+), 8 deletions(-)
[PATCH 0/3] semihosting: Fix a few semihosting bugs
Posted by Sean Anderson 3 months, 3 weeks ago
While discussing [1], it came to my attention that QEMU does not
properly truncate/error SYS_FLEN on 32-bit systems. Fix this, and some
other bugs with GDB File I/O that I found while working on this series.
That said, GDB File I/O has been substantially broken for two years now,
so it makes me wonder if anyone actually uses it! It would certainly
simplify the implementation if we didn't have to support it.

[1] https://lore.kernel.org/u-boot/20251017195322.GF6688@bill-the-cat/T/#m493c42570d3103b8c606c5f50faeb78d27719de6


Sean Anderson (3):
  gdbstub: Fix %s formatting
  semihosting: Fix GDB File-I/O FLEN
  semihosting: Check for overflow in FLEN on 32-bit systems

 gdbstub/syscalls.c            |  2 +-
 semihosting/arm-compat-semi.c | 22 +++++++++++++++-------
 2 files changed, 16 insertions(+), 8 deletions(-)

-- 
2.35.1.1320.gc452695387.dirty
Re: [PATCH 0/3] semihosting: Fix a few semihosting bugs
Posted by Michael Tokarev 3 months, 1 week ago
On 10/18/25 00:35, Sean Anderson wrote:
> While discussing [1], it came to my attention that QEMU does not
> properly truncate/error SYS_FLEN on 32-bit systems. Fix this, and some
> other bugs with GDB File I/O that I found while working on this series.
> That said, GDB File I/O has been substantially broken for two years now,
> so it makes me wonder if anyone actually uses it! It would certainly
> simplify the implementation if we didn't have to support it.
> 
> [1] https://lore.kernel.org/u-boot/20251017195322.GF6688@bill-the-cat/T/#m493c42570d3103b8c606c5f50faeb78d27719de6
> 
> 
> Sean Anderson (3):
>    gdbstub: Fix %s formatting
>    semihosting: Fix GDB File-I/O FLEN

Is this qemu-stable material (for 10.0 & 10.1)?
Please let me know if it isn't.

Thanks,

/mjt
Re: [PATCH 0/3] semihosting: Fix a few semihosting bugs
Posted by Alex Bennée 3 months, 1 week ago
Michael Tokarev <mjt@tls.msk.ru> writes:

> On 10/18/25 00:35, Sean Anderson wrote:
>> While discussing [1], it came to my attention that QEMU does not
>> properly truncate/error SYS_FLEN on 32-bit systems. Fix this, and some
>> other bugs with GDB File I/O that I found while working on this series.
>> That said, GDB File I/O has been substantially broken for two years now,
>> so it makes me wonder if anyone actually uses it! It would certainly
>> simplify the implementation if we didn't have to support it.
>> [1]
>> https://lore.kernel.org/u-boot/20251017195322.GF6688@bill-the-cat/T/#m493c42570d3103b8c606c5f50faeb78d27719de6
>> Sean Anderson (3):
>>    gdbstub: Fix %s formatting
>>    semihosting: Fix GDB File-I/O FLEN
>
> Is this qemu-stable material (for 10.0 & 10.1)?

Yeah they are simple fixes and should backport easily.

> Please let me know if it isn't.
>
> Thanks,
>
> /mjt

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 0/3] semihosting: Fix a few semihosting bugs
Posted by Alex Bennée 3 months, 1 week ago
Sean Anderson <sean.anderson@linux.dev> writes:

> While discussing [1], it came to my attention that QEMU does not
> properly truncate/error SYS_FLEN on 32-bit systems. Fix this, and some
> other bugs with GDB File I/O that I found while working on this series.
> That said, GDB File I/O has been substantially broken for two years now,
> so it makes me wonder if anyone actually uses it! It would certainly
> simplify the implementation if we didn't have to support it.
>
> [1] https://lore.kernel.org/u-boot/20251017195322.GF6688@bill-the-cat/T/#m493c42570d3103b8c606c5f50faeb78d27719de6
>

Queued 1-2 to maintainer/8.2-softfreeze, thanks.

As there is some discussion on patch 3 I'll leave that for now. We can
still merge bug fixes after softfreeze but it doesn't seem like its a
critical problem.
>
> Sean Anderson (3):
>   gdbstub: Fix %s formatting
>   semihosting: Fix GDB File-I/O FLEN
>   semihosting: Check for overflow in FLEN on 32-bit systems
>
>  gdbstub/syscalls.c            |  2 +-
>  semihosting/arm-compat-semi.c | 22 +++++++++++++++-------
>  2 files changed, 16 insertions(+), 8 deletions(-)

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 0/3] semihosting: Fix a few semihosting bugs
Posted by Alex Bennée 3 months, 2 weeks ago
Sean Anderson <sean.anderson@linux.dev> writes:

> While discussing [1], it came to my attention that QEMU does not
> properly truncate/error SYS_FLEN on 32-bit systems.

TIL that semihostingfs was a thing!

> Fix this, and some
> other bugs with GDB File I/O that I found while working on this series.
> That said, GDB File I/O has been substantially broken for two years now,
> so it makes me wonder if anyone actually uses it!

I suspect this is at the upper end of things to use semihosting for as
its real purpose is to help bootstrap things on the barest of metal
until you have enough bits going to selfhost. In QEMU land it is a
convenient way to do host calls for test cases.

We don't have much actual testing of semihosting in the tree although I
do run Peter's semihosting tests from time to time:

  https://git.linaro.org/people/peter.maydell/semihosting-tests.git/

the tests do include flen() but obviously don't cover the extreme
filesize cases or overflow.

> It would certainly
> simplify the implementation if we didn't have to support it.

While semihosting does have the concept of optional extensions SYS_FLEN
is not one of them.

>
> [1] https://lore.kernel.org/u-boot/20251017195322.GF6688@bill-the-cat/T/#m493c42570d3103b8c606c5f50faeb78d27719de6
>
>
> Sean Anderson (3):
>   gdbstub: Fix %s formatting
>   semihosting: Fix GDB File-I/O FLEN
>   semihosting: Check for overflow in FLEN on 32-bit systems
>
>  gdbstub/syscalls.c            |  2 +-
>  semihosting/arm-compat-semi.c | 22 +++++++++++++++-------
>  2 files changed, 16 insertions(+), 8 deletions(-)

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 0/3] semihosting: Fix a few semihosting bugs
Posted by Sean Anderson 3 months, 2 weeks ago
On 10/20/25 11:03, Alex Bennée wrote:
> Sean Anderson <sean.anderson@linux.dev> writes:
> 
>> While discussing [1], it came to my attention that QEMU does not
>> properly truncate/error SYS_FLEN on 32-bit systems.
> 
> TIL that semihostingfs was a thing!
> 
>> Fix this, and some
>> other bugs with GDB File I/O that I found while working on this series.
>> That said, GDB File I/O has been substantially broken for two years now,
>> so it makes me wonder if anyone actually uses it!
> 
> I suspect this is at the upper end of things to use semihosting for as
> its real purpose is to help bootstrap things on the barest of metal
> until you have enough bits going to selfhost. In QEMU land it is a
> convenient way to do host calls for test cases.
> 
> We don't have much actual testing of semihosting in the tree although I
> do run Peter's semihosting tests from time to time:
> 
>   https://git.linaro.org/people/peter.maydell/semihosting-tests.git/
> 
> the tests do include flen() but obviously don't cover the extreme
> filesize cases or overflow.
> 
>> It would certainly
>> simplify the implementation if we didn't have to support it.
> 
> While semihosting does have the concept of optional extensions SYS_FLEN
> is not one of them.

The above comments refer to GDB File I/O, which currently cannot open
files due to the problem fixed in patch 1/3. FLEN is not really broken
for most use-cases (as long as the user doesn't access large files).

--Sean