Bug 289836 - Unhanded instructions mfatbu and mfatbl
Summary: Unhanded instructions mfatbu and mfatbl
Status: CONFIRMED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.7.0
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-26 10:03 UTC by Aneesh
Modified: 2022-08-30 08:07 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Patch to add support for mfatbu and mfatbl (3.22 KB, patch)
2011-12-26 10:03 UTC, Aneesh
Details
Test program to check the correctness of the patch (757 bytes, text/x-csrc)
2011-12-27 04:37 UTC, Aneesh
Details
A rebased (to latest upstream commit) version of the patch (3.16 KB, text/plain)
2022-08-30 08:07 UTC, Alexander Kanavin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aneesh 2011-12-26 10:03:07 UTC
Created attachment 67114 [details]
Patch to add support for mfatbu and mfatbl

PowerPC uses two alternate time base registers which are read from user space by using PPC instructions mfatbu and mfatbl . However these instructions are not not supported by Valgrind.

Here are the logs when an application executing such instruction is executed with Valgrind:

dis_proc_ctl(ppc)(mfspr,SPR)(0x20F)
disInstr(ppc): unhandled instruction: 0x7C0F82A6
                 primary 31(0x1F), secondary 678(0x2A6)
==2204== valgrind: Unrecognised instruction at address 0x10003dfc.
==2204==    at 0x10003DFC: ??? (in /usr/bin/simple_crypto)
==2204==    by 0x1000181B: ??? (in /usr/bin/simple_crypto)
==2204==    by 0xFE179E7: ??? (in /lib/libpthread-2.13.so)
==2204==    by 0x40EEA9B: ??? (in /lib/libc-2.13.so)
==2204== Your program just tried to execute an instruction that Valgrind
==2204== did not recognise.  There are two possible reasons for this.
==2204== 1. Your program has a bug and erroneously jumped to a non-code
==2204==    location.  If you are running Memcheck and you just saw a
==2204==    warning about a bad jump, it's probably your program's fault.
==2204== 2. The instruction is legitimate but Valgrind doesn't handle it,
==2204==    i.e. it's Valgrind's fault.  If you think this is the case or
==2204==    you are not sure, please let us know and we'll try to fix it.
==2204== Either way, Valgrind will now raise a SIGILL signal which will
==2204== probably kill your program.


We have developed a path to fix the issue.
Kindly find it attached.
Comment 1 Bart Van Assche 2011-12-26 10:19:17 UTC
It seems like a test program that triggers the mfatb[ul] instructions and that allows to verify the correctness of this patch is missing ? See e.g. none/tests/ppc32/lsw.c for an example.
Comment 2 Bart Van Assche 2011-12-26 10:34:29 UTC
Another possible starting point for a test program is none/tests/ppc32/bug139050-ppc32.c.
Comment 3 Aneesh 2011-12-27 04:37:48 UTC
Created attachment 67145 [details]
Test program to check the correctness of the patch
Comment 4 Bart Van Assche 2011-12-27 14:51:58 UTC
Thanks for the test program. In order to integrate the test program in the Valgrind regression test suite we need to know which PowerPC CPUs support the special-purpose registers 526 and 527 and which CPUs do not. The test program must be run only on CPUs that support these special-purpose registers.
Comment 5 vakul 2011-12-28 05:02:56 UTC
(In reply to comment #4)
> Thanks for the test program. In order to integrate the test program in the
> Valgrind regression test suite we need to know which PowerPC CPUs support the
> special-purpose registers 526 and 527 and which CPUs do not. The test program
> must be run only on CPUs that support these special-purpose registers.

All BookE PowerPC CPUs (such as e500mc, e500, e5500 etc) support special-purpose registers 526 and 527. I will ask the experts in this area about PowerPC CPUs which do not support these registers and post here.
Comment 6 michael-dev 2013-06-05 18:21:32 UTC
Also affects e500v2 
see #306590
see #268106
Comment 7 michael-dev 2013-06-05 18:39:00 UTC
(In reply to comment #6)
> Also affects e500v2 
> see #306590
> see #268106

The patch does not work on e500v2

==5506== Memcheck, a memory error detector
==5506== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==5506== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==5506== Command: ls
==5506==
dis_proc_ctl(ppc)(mfspr,SPR)(0x200)
disInstr(ppc): unhandled instruction: 0x7D4082A6
                 primary 31(0x1F), secondary 678(0x2A6)
Comment 8 Alexander Kanavin 2022-08-30 08:07:37 UTC
Created attachment 151700 [details]
A rebased (to latest upstream commit) version of the patch