[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <80480a53-c9db-d912-c560-0c31b81100ce@linux.vnet.ibm.com>
Date: Tue, 16 Aug 2016 10:59:05 +0530
From: Madhavan Srinivasan <maddy@...ux.vnet.ibm.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
Yury Norov <ynorov@...iumnetworks.com>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Michael Ellerman <mpe@...erman.id.au>
Subject: Re: [PATCH] perf/core: Fix the mask in perf_output_sample_regs
On Thursday 11 August 2016 05:57 PM, Peter Zijlstra wrote:
> Sorry, found it in my inbox while clearing out backlog..
>
> On Sun, Jul 03, 2016 at 11:31:58PM +0530, Madhavan Srinivasan wrote:
>> When decoding the perf_regs mask in perf_output_sample_regs(),
>> we loop through the mask using find_first_bit and find_next_bit functions.
>> While the exisitng code works fine in most of the case,
>> the logic is broken for 32bit kernel (Big Endian).
>> When reading u64 mask using (u32 *)(&val)[0], find_*_bit() assumes it gets
>> lower 32bits of u64 but instead gets upper 32bits which is wrong.
>> Proposed fix is to swap the words of the u64 to handle this case.
>> This is _not_ endianness swap.
> But it looks an awful lot like it..
Hit this issue when testing my perf_arch_regs patchset. Yep exactly
the reason for adding that comment in the commit message.
>
>> +++ b/kernel/events/core.c
>> @@ -5205,8 +5205,10 @@ perf_output_sample_regs(struct perf_output_handle *handle,
>> struct pt_regs *regs, u64 mask)
>> {
>> int bit;
>> + DECLARE_BITMAP(_mask, 64);
>>
>> - for_each_set_bit(bit, (const unsigned long *) &mask,
>> + bitmap_from_u64(_mask, mask);
>> + for_each_set_bit(bit, _mask,
>> sizeof(mask) * BITS_PER_BYTE) {
>> u64 val;
>> +++ b/lib/bitmap.c
>> +void bitmap_from_u64(unsigned long *dst, u64 mask)
>> +{
>> + dst[0] = mask & ULONG_MAX;
>> +
>> + if (sizeof(mask) > sizeof(unsigned long))
>> + dst[1] = mask >> 32;
>> +}
>> +EXPORT_SYMBOL(bitmap_from_u64);
> Looks small enough for an inline.
>
> Alternatively you can go all the way and add bitmap_from_u64array(), but
> that seems massive overkill.
Ok will make it inline and resend.
Maddy
>
> Tedious stuff.. I can't come up with anything prettier :/
>
Powered by blists - more mailing lists