Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3572914rwb; Tue, 20 Sep 2022 01:26:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rfJZ0jvDuKl+HcJ3elJte7ZQpgkl05yAcuOkn15y20PiNB+/WHps45w/8RQ5/wxHSEdZX X-Received: by 2002:aa7:cd8e:0:b0:452:2682:a955 with SMTP id x14-20020aa7cd8e000000b004522682a955mr19254852edv.379.1663662373163; Tue, 20 Sep 2022 01:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663662373; cv=none; d=google.com; s=arc-20160816; b=nP3ySFDSWzZ7wH3EvZ1zH6gjrSr4tYcT55+kxTZHgGGGeaorDLzK94wzDvKf/TdHdd U80M2vww3tm/tIeM1h3Vqp92T94vnzo3oj/tUIZIrJ+pUmO/pxwKmHi8zCjOqMJqQrJI SUgc56Kw5r03ta9I4Jj7+V0aGvaQpuJOnOMqPle5cAxtkLBousoMAlmUewqvTPkeqm1v WAvvzun5KG79RohcW55rl3iKqKnq3nG83mvUivx7WSIVWE4zsPnF6m5NT/d0Y2y/1s8e NcmNs0kFlQIMYnPUdGXxRp2sWSsRxGJaNzQHZlbcDbXrn5hZiqYw6mlwZfDQUoruigkg CBqg== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=1+rrVO93NDmOlIUnSwDzWkTM+P8LQ+RPw309XhLJrYc=; b=Cj0mXyVxDln4nLE8QTuD6dthcE6N+pBwSR9lwUsR6O2uqInKgMRGd9xwxRNpeRVMsJ SpKI6Z8n61iSEQDNDJU5SSWRvVX5nasnkD7h0ut37aBoW7k1jW4CuXtY5nierKZb3I2z gNMGvkpGwDlebeKYyqOx/c2ZPpvZDKMtp1cfX1g96ETWTnHJg3DpQVg9SwHU+es9P7+c TymhbXt1vN5ZBbhoNA6VDbAxK7P8bPIei/yMYo9jbLZ0Bt20xgDSFivVLdLgNyk3rAlp xbqCPeoQAyRFhI56csvPRLecj2hAXgLPQ4go5UAOE4vlpW/vWbHtPJ7QhSeqXDhuwsyo oV3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="O/r6KuBJ"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a0564020e0100b0044f2723fb67si1041497edh.32.2022.09.20.01.25.40; Tue, 20 Sep 2022 01:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@redhat.com header.s=mimecast20190719 header.b="O/r6KuBJ"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbiITIXX (ORCPT + 99 others); Tue, 20 Sep 2022 04:23:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231436AbiITIW7 (ORCPT ); Tue, 20 Sep 2022 04:22:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 097526717E for ; Tue, 20 Sep 2022 01:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663662054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1+rrVO93NDmOlIUnSwDzWkTM+P8LQ+RPw309XhLJrYc=; b=O/r6KuBJ9LSnyOrm9z4C23xyOaxAZTHfEoJ2t1ZmiLVfHW37j7YfoCeiaq8rKgNDWmzK6h PS1HKCtwGTQhYOg9LZJwZ5coqg2/0GlI65RFXP6aF70TFyNMpyHJs8oP31tYafCTDPtqoX 19c/ISN2TodTdsn3gzxkCpGZxc6Ark0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-191-TSxntFU9NCa2kuTdazv7wQ-1; Tue, 20 Sep 2022 04:20:53 -0400 X-MC-Unique: TSxntFU9NCa2kuTdazv7wQ-1 Received: by mail-wr1-f72.google.com with SMTP id d9-20020adfa349000000b0022ad6fb2845so830679wrb.17 for ; Tue, 20 Sep 2022 01:20:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date; bh=1+rrVO93NDmOlIUnSwDzWkTM+P8LQ+RPw309XhLJrYc=; b=2mr1zkiSPi/xIi+UuzsiacHUOAAoUbO/8TGeO4AbTMYSmj9h1q674vjtWZLdlMI0pS 3dvr5x+r7+MI4CiwK3f6H8Q/c20QXWgrwx9OAK0N3Q2px3f+8C0sFXDN8rfE/+P9sbEX 9SU8mnNwIDRVD84q1Cm8QHu9d1SFcMbROD7ue7/UokfCSaLbAHsOWz0TnkMpBBNtdjIc QYfu+RSo7rUialL5V21mXltYNc80esIi2b19oS7490N/uWZo7rTxkXHbB+bfVbScXrBq ZXQ+sMMl4TkgLEsmrfsnr4P1/p3IUPpMZ0j8gfxlD+MZG87H76Lw9s4YVW/rJJZFN/td G4TQ== X-Gm-Message-State: ACrzQf1gmsddtFlk+UvVNV2ts9hQJaaLk/RTg/pZnDCJ1gwo6KJ+5qt0 bxOtvy07fT4PfYUSWc4YjfDw6BAhLSsCOFsBLDff8rTB/rPn5TySSdoger+M4w7f6S6KwJViybe u/SiAo57x9jTAPTfIF5TbJRrw X-Received: by 2002:adf:eb52:0:b0:223:9164:b5b4 with SMTP id u18-20020adfeb52000000b002239164b5b4mr13499025wrn.518.1663662051683; Tue, 20 Sep 2022 01:20:51 -0700 (PDT) X-Received: by 2002:adf:eb52:0:b0:223:9164:b5b4 with SMTP id u18-20020adfeb52000000b002239164b5b4mr13499001wrn.518.1663662051415; Tue, 20 Sep 2022 01:20:51 -0700 (PDT) Received: from [10.35.4.238] (bzq-82-81-161-50.red.bezeqint.net. [82.81.161.50]) by smtp.gmail.com with ESMTPSA id iw18-20020a05600c54d200b003b492b30822sm1436129wmb.2.2022.09.20.01.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 01:20:50 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 1/5] perf/x86/intel/lbr: use setup_clear_cpu_cap instead of clear_cpu_cap From: Maxim Levitsky To: Borislav Petkov Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Pawan Gupta , Ingo Molnar , Josh Poimboeuf , Namhyung Kim , Tony Luck , Paolo Bonzini , "H. Peter Anvin" , Arnaldo Carvalho de Melo , Thomas Gleixner , Alexander Shishkin , Tim Chen , "David S. Miller" , Dave Hansen , "Chang S. Bae" , Jane Malalane , Kees Cook , Kan Liang , Peter Zijlstra , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Herbert Xu , Jiri Olsa , Mark Rutland , linux-perf-users@vger.kernel.org, "open list:CRYPTO API" Date: Tue, 20 Sep 2022 11:20:47 +0300 In-Reply-To: References: <20220718141123.136106-1-mlevitsk@redhat.com> <20220718141123.136106-2-mlevitsk@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-5.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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-crypto@vger.kernel.org On Mon, 2022-09-19 at 16:31 +0200, Borislav Petkov wrote: > On Mon, Jul 18, 2022 at 05:11:19PM +0300, Maxim Levitsky wrote: > > clear_cpu_cap(&boot_cpu_data) is very similar to setup_clear_cpu_cap > > except that the latter also sets a bit in 'cpu_caps_cleared' which > > later clears the same cap in secondary cpus, which is likely > > what is meant here. > > > > Fixes: 47125db27e47 ("perf/x86/intel/lbr: Support Architectural LBR") > > > > Reviewed-by: Kan Liang > > Signed-off-by: Maxim Levitsky > > --- > >  arch/x86/events/intel/lbr.c | 2 +- > >  1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c > > index 13179f31fe10fa..b08715172309a7 100644 > > --- a/arch/x86/events/intel/lbr.c > > +++ b/arch/x86/events/intel/lbr.c > > @@ -1860,7 +1860,7 @@ void __init intel_pmu_arch_lbr_init(void) > >         return; > >   > >  clear_arch_lbr: > > -       clear_cpu_cap(&boot_cpu_data, X86_FEATURE_ARCH_LBR); > > +       setup_clear_cpu_cap(X86_FEATURE_ARCH_LBR); > > setup_clear_cpu_cap() has a very specific purpose - see > apply_forced_caps(). > > This whole call sequence is an early_initcall() which is way after the > whole CPU features picking apart happens. > > So what is actually this fixing? > If I understand that correctly, the difference between clear_cpu_cap and setup_clear_cpu_cap is that setup_clear_cpu_cap should be called early when only the boot cpu is running and it 1. works on 'boot_cpu_data' which represents the boot cpu. 2. sets a bit in 'cpu_caps_cleared' which are later applied to all CPUs, including these that are hotplugged. On the other hand the clear_cpu_cap just affects the given 'struct cpuinfo_x86'. Call of 'clear_cpu_cap(&boot_cpu_data, X86_FEATURE_ARCH_LBR)' is weird since it still affects 'boot_cpu_data' but doesn't affect 'cpu_caps_cleared' I assumed that this was a mistake and the intention was to disable the feature on all CPUs. I need this patch because in the next patch, I change the clear_cpu_cap such as it detects being called on boot_cpu_data and in this case also clears bits in 'cpu_caps_cleared', thus while this patch does introduce a functional change, the next patch doesn't since this is the only place where clear_cpu_cap is called explicitly on 'boot_cpu_data' I do now notice that initcalls are run after smp is initialized, which means that this code doesn't really disable the CPUID feature on all CPUs at all. Maybe we can drop the call instead, which does seem to be wrong? Best regards, Maxim Levitsky