Re: Software FPU emulation in linux kernel

Thorsten Otto
2025-03-06T15:24:29Z

There are problems in fp_fsqrt when using the fp_one constant.

fp_one is declared as

static const struct fp_ext fp_one = {
.exp = 0x3fff,
};

So, despite the comment, this is not normalized (the explicit bit is not set).
This will have the effect that it is changed to zero, when fp_dyadic_check is
called in the entry of fp_add. So this call does not only have no effect, it
will also modify the constant.

And even if that is changed, fp_add will also write to it:

https://github.com/torvalds/linux/blob/
848e076317446f9c663771ddec142d7c2eb4cb43/arch/m68k/math-emu/fp_arith.c#L90:

dest->lowmant = src->lowmant = 0;

And 2 lines later, the call to
fp_denormalize(src, diff);

will also modify the src argument.

Wouldn't that crash the kernel, if it tries to write to a write-protected
section?