From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAF6BC43217 for ; Thu, 1 Dec 2022 10:24:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230284AbiLAKYQ (ORCPT ); Thu, 1 Dec 2022 05:24:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbiLAKYO (ORCPT ); Thu, 1 Dec 2022 05:24:14 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D428E25E9D; Thu, 1 Dec 2022 02:24:12 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 47667D6E; Thu, 1 Dec 2022 02:24:19 -0800 (PST) Received: from [10.57.7.90] (unknown [10.57.7.90]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 364F63F67D; Thu, 1 Dec 2022 02:24:11 -0800 (PST) Message-ID: Date: Thu, 1 Dec 2022 10:24:09 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] perf/core: Reset remaining bits in perf_clear_branch_entry_bitfields() Content-Language: en-US To: Anshuman Khandual , linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org References: <20221201055103.302019-1-anshuman.khandual@arm.com> From: James Clark In-Reply-To: <20221201055103.302019-1-anshuman.khandual@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/12/2022 05:51, Anshuman Khandual wrote: > perf_clear_branch_entry_bitfields() resets all struct perf_branch_entry bit > fields before capturing branch records. This resets remaining bit fields > except 'new_type', which is valid only when 'type' is PERF_BR_EXTEND_ABI. > > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Arnaldo Carvalho de Melo > Cc: Mark Rutland > Cc: Alexander Shishkin > Cc: Jiri Olsa > Cc: Namhyung Kim > Cc: linux-perf-users@vger.kernel.org> > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Anshuman Khandual > --- > This applies on v6.1-rc6 > > 'perf_branch_entry.new_type' can remain uninitialized as explained earlier. > Also there is no PERF_BR_NEW_UNKNOWN to spare, because 'perf_branch_entry. > new_type' enumeration starts at PERF_BR_NEW_FAULT_ALGN, to save a position > for the extended branch types instead. > > include/linux/perf_event.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > index 0031f7b4d9ab..c97b5f6f77a4 100644 > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -1110,8 +1110,9 @@ static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *b > br->in_tx = 0; > br->abort = 0; > br->cycles = 0; > - br->type = 0; > + br->type = PERF_BR_UNKNOWN; > br->spec = PERF_BR_SPEC_NA; > + br->priv = PERF_BR_PRIV_UNKNOWN; > br->reserved = 0; > } I would vote for just memsetting the whole struct to 0 at this point and making it work by ensuring the cleared from and to values are only set after this function. Or do the thing where it's wrapped in a union and the 'u64 value' member is assigned 0. See union perf_mem_data_src. I don't know if this would be a breaking change, but it doesn't look like it. Currently this is a bit too fragile and the kind of bugs it will cause are almost undetectable. But as my proposal is an extra change on top of this: Reviewed-by: James Clark James >