Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2385586pxb; Tue, 9 Mar 2021 00:48:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvfZxcTGYcKypzrtS+qO2yajjn6CA6LN+yAOaUTj6Jr0kOHQ730x0iEFjqL42SQQwlSW2D X-Received: by 2002:aa7:d54c:: with SMTP id u12mr2945034edr.234.1615279706564; Tue, 09 Mar 2021 00:48:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615279706; cv=none; d=google.com; s=arc-20160816; b=Kp3eYNUexSlPezwfy9/iJung7mCZuu7yET24q/EfjBiBqAxxV5TnDNvSwnGgjKx3W5 vuXrA0orE2ZRZpjTHh+psndMJ/Z3/dnNN8myYyNpYTEQq4FPlt+/KA1VQG7GwhE4k1mF JTsoZ1s/ock4xjwgwjyb+1CitW60j3B486TKCIOVGqK55S8HO8v0/MVwlM5GS6EJwzcD 0BBdg7OyWIs+4tf3Nb1aOhe12Z5J4Rt4hmefsV3uCnC3khERQiCeqEp0M+QOgIYcEusj lZyfKvgl1JMnw8mtxM9b/ye9BWW/yadwf9kE8+468/xdpm6I/V4saCBckpjb6kqCr9NP gGVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=G2k3R4Tdi/Hx20QLdrIl7Gd0ODGJ454XbaXMZQmyqdc=; b=rMjzVy6+XfDQl6Hk7dpeHEDB+A2h3a7UyZfpSsJ8RUAm5Mq96SU49m6tpQA4mn6+R6 Ns4nT8sxeODF1dB0bd3aCMtxjJJT1vBVhpAjG+GYu9rkcTv+E2HBYz1wnK511jwHdGc+ s6eRDh5jc3gn3XR2sA6Ybx2d9NPvdTO81IfYIQRc3Yy+lN3sW1eKxTWCCIaCK4nt2Kxg 2VY+YaAnz7bHyNxK7cDUKsyQR6nhFNE+naz5BUcckuMHX3CvpH9yhVa/THPofw3QaSd2 eSMD/K7f3U93SksG40XCJvgQ9A6kuZFIw8V7rhfW4B3QvZJx8U43lhMXJaWc1tjwYdcs rpew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=BfNvIj93; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi22si8712795edb.191.2021.03.09.00.48.04; Tue, 09 Mar 2021 00:48:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=BfNvIj93; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbhCIIqg (ORCPT + 99 others); Tue, 9 Mar 2021 03:46:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbhCIIp5 (ORCPT ); Tue, 9 Mar 2021 03:45:57 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35059C06174A; Tue, 9 Mar 2021 00:45:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=G2k3R4Tdi/Hx20QLdrIl7Gd0ODGJ454XbaXMZQmyqdc=; b=BfNvIj93IMzsXqG7n+fpKKD5HB 7SyO6rt2YhcfAVUh1zG7n5g49xapE5f/5xmQofHqlr0e0OE+Hc5FDLiopskI1Q7uORjt53Y44TxVf tgJOEC4YBmW1sUP9+N1HIdM3Dr0F/DcHKxaqaCfdSS7G7GpVGjPYbiNVlcXNkPCG1tVo2Qm52sUjY gd2gK0bjnap+drG4izl2l2BTF1lSpOY9iVnNFbeMs+jWxD66jaX4IsW8O1sk2L0j81n1pSS8eXJLF JMmKnUb1XlFWgKkvyLVlb+5paovs1AWUbMaOmAbKvbwaR89l5BlE5Epd+QHPUSm/g2v1C3tbyWEti zcFfqNrw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lJXzN-000Fqx-W3; Tue, 09 Mar 2021 08:45:17 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5B4B5301A32; Tue, 9 Mar 2021 09:45:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 45CCA2351CF0D; Tue, 9 Mar 2021 09:45:12 +0100 (CET) Date: Tue, 9 Mar 2021 09:45:12 +0100 From: Peter Zijlstra To: Sean Christopherson Cc: "Xu, Like" , Dmitry Vyukov , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Like Xu , Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, "Thomas Gleixner (x86/pti/timer/core/smp/irq/perf/efi/locking/ras/objtool) (x86@kernel.org)" , Borislav Petkov , Arnaldo Carvalho de Melo , Ingo Molnar Subject: Re: [PATCH] x86/perf: Fix guest_get_msrs static call if there is no PMU Message-ID: References: <20210305223331.4173565-1-seanjc@google.com> <053d0a22-394d-90d0-8d3b-3cd37ca3f378@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 09, 2021 at 08:46:49AM +0100, Peter Zijlstra wrote: > On Mon, Mar 08, 2021 at 12:40:44PM -0800, Sean Christopherson wrote: > > On Mon, Mar 08, 2021, Peter Zijlstra wrote: > > > > Given the one user in atomic_switch_perf_msrs() that should work because > > > it doesn't seem to care about nr_msrs when !msrs. > > > > Uh, that commit quite cleary says: > > D0h! I got static_call_cond() and __static_call_return0 mixed up. > Anyway, let me see if I can make something work here. Does this work? I can never seem to start a VM, and if I do accidentally manage, then it never contains the things I need :/ --- diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 6ddeed3cd2ac..fadcecd73e1a 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -81,7 +81,11 @@ DEFINE_STATIC_CALL_NULL(x86_pmu_swap_task_ctx, *x86_pmu.swap_task_ctx); DEFINE_STATIC_CALL_NULL(x86_pmu_drain_pebs, *x86_pmu.drain_pebs); DEFINE_STATIC_CALL_NULL(x86_pmu_pebs_aliases, *x86_pmu.pebs_aliases); -DEFINE_STATIC_CALL_NULL(x86_pmu_guest_get_msrs, *x86_pmu.guest_get_msrs); +/* + * This one is magic, it will get called even when PMU init fails (because + * there is no PMU), in which case it should simply return NULL. + */ +__DEFINE_STATIC_CALL(x86_pmu_guest_get_msrs, *x86_pmu.guest_get_msrs, __static_call_return0); u64 __read_mostly hw_cache_event_ids [PERF_COUNT_HW_CACHE_MAX] @@ -1944,13 +1948,6 @@ static void _x86_pmu_read(struct perf_event *event) x86_perf_event_update(event); } -static inline struct perf_guest_switch_msr * -perf_guest_get_msrs_nop(int *nr) -{ - *nr = 0; - return NULL; -} - static int __init init_hw_perf_events(void) { struct x86_pmu_quirk *quirk; @@ -2024,9 +2021,6 @@ static int __init init_hw_perf_events(void) if (!x86_pmu.read) x86_pmu.read = _x86_pmu_read; - if (!x86_pmu.guest_get_msrs) - x86_pmu.guest_get_msrs = perf_guest_get_msrs_nop; - x86_pmu_static_call_update(); /*