Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3049207rwe; Mon, 29 Aug 2022 05:08:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Najs2HAYu5JdR727KyFP0UXG3N/0YefPBXvpRdKmwy34MXWmZjIAXebbK9xh/oOKCgPRF X-Received: by 2002:a05:6402:4305:b0:448:5b80:757a with SMTP id m5-20020a056402430500b004485b80757amr5302116edc.198.1661774911313; Mon, 29 Aug 2022 05:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661774911; cv=none; d=google.com; s=arc-20160816; b=ObzpRIYsM9HOWV9oTYuNUSfBeRsywkTrKBJW+NFWvJJIyrkDgesto/U0YR+L2BK/r5 Qx9qAREfGfZz0K6vtmsiWG0k+BwJm6bmBlmv3VllliqSAxJzQGUVXrO+urD/fZshYHKX u8RDDdxNtDMh0vVPcgzxNb8mc53Koc57LYU3OJG5Zor2dYfguM1a6C+Ni5edpRlv0Kri dyzUTK0E/XuUIWPjEmxeuzkTmrMHfjYdixYGfEHt7ICnDwinmMlXxoBurQ6oIaePHQmj +C4UNif6t9V5vfM/bDx0jku6WwdjS3hNrxPiURweHFycLfBppzJJHaoVid8ELWm1LDXL 2Vdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=My4SAVU7R7hjuqgNzjbyKlpocRpQUBgT9zhOUpYV/VE=; b=aU+5paAQWFcUt62xulVUkpkvuZO2xSVUxumeq2FyOdp5EBLFDd3w4i97SkHCpgu4gw gVTdhkpnIrX+8lFZDrmLC2yF6I2FPBKC826kta5vgSzZvcVGduZbIYdfAtUOgxNsqhTd oH0iZfmCZDqBt/cOaOTUEwLsr3Y6N4TyLP69qvT4ZD+u/p4sVTnEZRiR9LPqiXr4sYOJ W7WM67wzPRljhRz6qBIv2OJN0YikE9dol4W/UI4cW6ujo7Pike3YY1cetXyy7mT9YTsr P/FvcvYKYgb6Re0glz14AFWpFKNUgChWBohD7PXH++K3NQ6Z4eoZCl9RA5Uv8F8mVl80 q0Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A7SUL+dK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020aa7d614000000b00446ac62af48si5850958edr.70.2022.08.29.05.08.03; Mon, 29 Aug 2022 05:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A7SUL+dK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbiH2LUa (ORCPT + 99 others); Mon, 29 Aug 2022 07:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231654AbiH2LS4 (ORCPT ); Mon, 29 Aug 2022 07:18:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D70E13DF2; Mon, 29 Aug 2022 04:12:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E2093611DD; Mon, 29 Aug 2022 11:10:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F07C0C433C1; Mon, 29 Aug 2022 11:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771447; bh=0RcrxzIq4WhOjo87Hq+HJS6+Nz8mi0V3Oos3YAzgquo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A7SUL+dKE0+S7zQeEorDRc4u/hSW/xEioZSdefYkQD2m3YxxKhyU3w07IoC+1Tdv+ N6+bRfxcTcCRfmjWb0QQvXnlpCVvTEDOV1q6pTzvza9bWVhFwhOtqA0IkDzshbMirX owT2I/KK1vDFL7OB6S0q0JQawxALBCEOrFT28Mhk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Eranian , Kan Liang , "Peter Zijlstra (Intel)" Subject: [PATCH 5.10 68/86] perf/x86/lbr: Enable the branch type for the Arch LBR by default Date: Mon, 29 Aug 2022 12:59:34 +0200 Message-Id: <20220829105759.331636667@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang commit 32ba156df1b1c8804a4e5be5339616945eafea22 upstream. On the platform with Arch LBR, the HW raw branch type encoding may leak to the perf tool when the SAVE_TYPE option is not set. In the intel_pmu_store_lbr(), the HW raw branch type is stored in lbr_entries[].type. If the SAVE_TYPE option is set, the lbr_entries[].type will be converted into the generic PERF_BR_* type in the intel_pmu_lbr_filter() and exposed to the user tools. But if the SAVE_TYPE option is NOT set by the user, the current perf kernel doesn't clear the field. The HW raw branch type leaks. There are two solutions to fix the issue for the Arch LBR. One is to clear the field if the SAVE_TYPE option is NOT set. The other solution is to unconditionally convert the branch type and expose the generic type to the user tools. The latter is implemented here, because - The branch type is valuable information. I don't see a case where you would not benefit from the branch type. (Stephane Eranian) - Not having the branch type DOES NOT save any space in the branch record (Stephane Eranian) - The Arch LBR HW can retrieve the common branch types from the LBR_INFO. It doesn't require the high overhead SW disassemble. Fixes: 47125db27e47 ("perf/x86/intel/lbr: Support Architectural LBR") Reported-by: Stephane Eranian Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20220816125612.2042397-1-kan.liang@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/lbr.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -1114,6 +1114,14 @@ static int intel_pmu_setup_hw_lbr_filter if (static_cpu_has(X86_FEATURE_ARCH_LBR)) { reg->config = mask; + + /* + * The Arch LBR HW can retrieve the common branch types + * from the LBR_INFO. It doesn't require the high overhead + * SW disassemble. + * Enable the branch type by default for the Arch LBR. + */ + reg->reg |= X86_BR_TYPE_SAVE; return 0; }