RFC: extern illegal instruction trap and trap RDCYCLE

Ben Dooks ben.dooks at codethink.co.uk
Tue Oct 1 14:07:11 PDT 2024


On 01/10/2024 22:00, Ben Dooks wrote:
> On 01/10/2024 10:41, Alexandre Ghiti wrote:
>> Hi Atish, Ben,
>>
>> On 19/09/2024 01:23, Atish Kumar Patra wrote:
>>> On Wed, Sep 18, 2024 at 2:57 AM Ben Dooks <ben.dooks at codethink.co.uk> 
>>> wrote:
>>>> On 18/09/2024 10:55, Atish Patra wrote:
>>>>> On 9/17/24 7:01 AM, Ben Dooks wrote:
>>>>>> On 17/09/2024 14:46, Palmer Dabbelt wrote:
>>>>>>> On Tue, 17 Sep 2024 06:08:50 PDT (-0700), ben.dooks at codethink.co.uk
>>>>>>> wrote:
>>>>>>>> This is a RFC series to change how the illegal instruction trap
>>>>>>>> is handled and then how to trap RDCYCLE and emulate it with RDTIME
>>>>>>>> instead.
>>>>>>> Only 1/3 made it to lore for me, not sure if it's just stuck 
>>>>>>> somewhere.
>>>>>>>
>>>>>>>> I did this when we found multiple libraries using RDCYCLE and
>>>>>>>> upgrading multiple runners to newer kernels caused many problems
>>>>>>> OK, so I think we're kind of just stuck with RDCYCLE then -- it was
>>>>>>> part of the base ISA when we merged the port, and every time it
>>>>>>> disappears we end up breaking userspace.
>>>>>> Yes, it was an annoyance, we managed to track down all the users and
>>>>>> patch out.
>>>>>>
>>>>>> I thought this might be a useful idea for more generic type, so might
>>>>>> look at updating to have a table of instruction masks to call.
>>>>>>
>>>>>>> I'm not sure what exactly the right way to do this is: IIRC there's
>>>>>>> some perf-related hooks for this, but there's also systems that just
>>>>>>> don't implement the RDCYCLE instruction at all and thus we'll need
>>>>>>> some sort of emulation for those.
>>>>>> I couldn't get the PMU driver to allow it, not sure if there was an
>>>>>> issue higher up or some other issue?
>>>>>>
>>>>> Here is the way to properly allow it via the driver.
>>>>>
>>>>> https://www.kernel.org/doc/Documentation/admin-guide/sysctl/kernel.rst
>>>>>
>>>>> Check the perf_user_access
>>>> Didn't work for me, not sure why
>>>>
>>> +Alexandre Ghiti
>>>
>>> Hmm. That's weird. Maybe some bug crept in recently. Can you provide
>>> some more details
>>> on the platform, kernel version and procedure followed to change it ?
>>
>>
>> So I have just tried perf_user_access on 6.11 and it works fine, 
>> meaning setting the "legacy" behaviour (ie 2) allows a userspace 
>> application to directly access RDCYCLE.
>>
>> Can you provide more details Ben?
> 
> I've gone through and checked this again, I think it is very likely
> that I got the enable as 1 instead of 2. It works on QEMU, I've not
> got access to the runners that we upgraded and we've fixed the issue
> by upgrading libabsl to a later version.
> 
> Thanks.

And I put some test code up at I used for testing my patch at:
https://gitlab.com/CodethinkLabs/riscv_rdcycle_test


-- 
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html



More information about the linux-riscv mailing list