[Qemu-devel] [PATCH] linux-user/arm/nwfpe: Check coprocessor number for FPA emulation

Peter Maydell posted 1 patch 6 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1511890447-13601-1-git-send-email-peter.maydell@linaro.org
Test checkpatch passed
Test docker passed
Test ppc passed
Test s390x passed
linux-user/arm/nwfpe/fpa11.c | 9 +++++++++
1 file changed, 9 insertions(+)
[Qemu-devel] [PATCH] linux-user/arm/nwfpe: Check coprocessor number for FPA emulation
Posted by Peter Maydell 6 years, 4 months ago
Our copy of the nwfpe code for emulating of the old FPA11 floating
point unit doesn't check the coprocessor number in the instruction
when it emulates it.  This means that we might treat some
instructions which should really UNDEF as being FPA11 instructions by
accident.

The kernel's copy of the nwfpe code doesn't make this error; I suspect
the bug was noticed and fixed as part of the process of mainlining
the nwfpe code more than a decade ago.

Add a check that the coprocessor number (which is always in bits
[11:8] of the instruction) is either 1 or 2, which is where the
FPA11 lives.

Reported-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Tested with a chroot of arm debian lenny, which is the last one that
still used the calling convention that mandated use of the old FPA11 FPU
and thus needs nwfpe emulation.
---
 linux-user/arm/nwfpe/fpa11.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/linux-user/arm/nwfpe/fpa11.c b/linux-user/arm/nwfpe/fpa11.c
index 441e3b1..f6f8163 100644
--- a/linux-user/arm/nwfpe/fpa11.c
+++ b/linux-user/arm/nwfpe/fpa11.c
@@ -137,8 +137,17 @@ unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs)
   unsigned int nRc = 0;
 //  unsigned long flags;
   FPA11 *fpa11;
+  unsigned int cp;
 //  save_flags(flags); sti();
 
+  /* Check that this is really an FPA11 instruction: the coprocessor
+   * field in bits [11:8] must be 1 or 2.
+   */
+  cp = (opcode >> 8) & 0xf;
+  if (cp != 1 && cp != 2) {
+    return 0;
+  }
+
   qemufpa=qfpa;
   user_registers=qregs;
 
-- 
2.7.4


Re: [Qemu-devel] [PATCH] linux-user/arm/nwfpe: Check coprocessor number for FPA emulation
Posted by Richard Henderson 6 years, 4 months ago
On 11/28/2017 05:34 PM, Peter Maydell wrote:
> Our copy of the nwfpe code for emulating of the old FPA11 floating
> point unit doesn't check the coprocessor number in the instruction
> when it emulates it.  This means that we might treat some
> instructions which should really UNDEF as being FPA11 instructions by
> accident.
> 
> The kernel's copy of the nwfpe code doesn't make this error; I suspect
> the bug was noticed and fixed as part of the process of mainlining
> the nwfpe code more than a decade ago.
> 
> Add a check that the coprocessor number (which is always in bits
> [11:8] of the instruction) is either 1 or 2, which is where the
> FPA11 lives.
> 
> Reported-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Tested with a chroot of arm debian lenny, which is the last one that
> still used the calling convention that mandated use of the old FPA11 FPU
> and thus needs nwfpe emulation.
> ---
>  linux-user/arm/nwfpe/fpa11.c | 9 +++++++++
>  1 file changed, 9 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [Qemu-devel] [PATCH] linux-user/arm/nwfpe: Check coprocessor number for FPA emulation
Posted by Peter Maydell 6 years, 3 months ago
On 29 November 2017 at 09:30, Richard Henderson
<richard.henderson@linaro.org> wrote:
> On 11/28/2017 05:34 PM, Peter Maydell wrote:
>> Our copy of the nwfpe code for emulating of the old FPA11 floating
>> point unit doesn't check the coprocessor number in the instruction
>> when it emulates it.  This means that we might treat some
>> instructions which should really UNDEF as being FPA11 instructions by
>> accident.
>>
>> The kernel's copy of the nwfpe code doesn't make this error; I suspect
>> the bug was noticed and fixed as part of the process of mainlining
>> the nwfpe code more than a decade ago.
>>
>> Add a check that the coprocessor number (which is always in bits
>> [11:8] of the instruction) is either 1 or 2, which is where the
>> FPA11 lives.
>>
>> Reported-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>> Tested with a chroot of arm debian lenny, which is the last one that
>> still used the calling convention that mandated use of the old FPA11 FPU
>> and thus needs nwfpe emulation.
>> ---
>>  linux-user/arm/nwfpe/fpa11.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Thanks; applied to target-arm.next (since it's as much an arm patch
as a linux-user one).

-- PMM