From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752032AbcHPF3Z (ORCPT ); Tue, 16 Aug 2016 01:29:25 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:14577 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750752AbcHPF3Y (ORCPT ); Tue, 16 Aug 2016 01:29:24 -0400 X-IBM-Helo: d28dlp03.in.ibm.com X-IBM-MailFrom: maddy@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf/core: Fix the mask in perf_output_sample_regs To: Peter Zijlstra References: <1467568918-24377-1-git-send-email-maddy@linux.vnet.ibm.com> <20160811122710.GP6879@twins.programming.kicks-ass.net> Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Yury Norov , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Michael Ellerman From: Madhavan Srinivasan Date: Tue, 16 Aug 2016 10:59:05 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160811122710.GP6879@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16081605-0008-0000-0000-0000030B1CD3 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16081605-0009-0000-0000-00000EC0525D Message-Id: <80480a53-c9db-d912-c560-0c31b81100ce@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-08-16_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608160060 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 :/ >