Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2049154pxb; Mon, 8 Mar 2021 12:43:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXbIc+quy2pLvhVI3AUG9q+Spi9t3OyrszcV/dtVQrTrxllhyyWYyergg9PUK8FCB9NSY6 X-Received: by 2002:a17:906:684b:: with SMTP id a11mr16164786ejs.329.1615236188480; Mon, 08 Mar 2021 12:43:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615236188; cv=none; d=google.com; s=arc-20160816; b=V7Pc+KdFiYxYVoNRICUBdwf9otR8dag+JACZ4DWA1Cp1Y9opUHWA/ncCFL0rBhVbce pqZNe9bU8Wgg4FwCW0pcrUxjyM1nsNQq6k5yH29CTuhpM4V1a0e5Enmi8ULvJDYk1zCG zkqXOs4b0P78RrGbfVayHN0bF5DyKIY1QZ4g+CYeZ4/ykUv6ZFj4y2/AHJGXoV4dkbkC 1eiIPpowLxmjQrI/zrsbHqiFAylIXhFe4U1HaGiK9R04FdOVVkzWAaKYe6MfJsiqBzhT G5Tcc8vTZAsoNkhB5L82EuPSdDLlDGo4OGCuIGU2PNOCNPu7bMH3O3PcXc+APUBHirBu c2Qw== 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=YieL4r+TN+gn7WlBHT97uAGWLZ5+RH9FuBAcVj4s06U=; b=VxVKj9nmA2XvTncH55c+IkuoHuR+1ZAJfXjW8o4XisNwrqeEiyzC3xUdyrQeRZtRw5 MPQVeM4FpnXmkRKu3JAl8/LCsn6vtr2lQafAm0ah/7IokHlhHwc5OI5q/NGhpyroAaTW 7yo8kK/37vG+e1WYKThaIpBml2AsiGD+jnDv4W4W+W/yk6bcIJ+9ZiiXbi7B6QvbOTUV c4/XlyeRX+4owotl32f2PvdEgWkAgH10xa9PDd60NM3wEV+xWsPFtnUyH0Bjb76OTH0v x7dMiCHWewihr1xx9+XYfScs9IXqF4OdI8sxQOBZb5UERQMT9HTaFZHmkjAp9OUYIAJt 7GZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZFGEV3DP; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 39si7873115edq.111.2021.03.08.12.42.45; Mon, 08 Mar 2021 12:43:08 -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=@google.com header.s=20161025 header.b=ZFGEV3DP; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbhCHUlR (ORCPT + 99 others); Mon, 8 Mar 2021 15:41:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbhCHUkx (ORCPT ); Mon, 8 Mar 2021 15:40:53 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA967C06175F for ; Mon, 8 Mar 2021 12:40:52 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id c16so5462691ply.0 for ; Mon, 08 Mar 2021 12:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YieL4r+TN+gn7WlBHT97uAGWLZ5+RH9FuBAcVj4s06U=; b=ZFGEV3DPNQZz37SL1BXfQkCq19S9we9dg+Cy44D92qHZPJ9reMhamBLz2Pam8qT77S SGT9QYiesdFSexslHwU9naxYNHyljqxxbRs5YFvPAGNOETxfFZ21N0oCU8a03261XyVz IiOGbfRSo3FMXbevkMgJTXUZC6pUm1rUBrbb2BMH0HaL9tSnHKjGw+e87pqOIxL9bUsQ /cZRNaK1CiVXM/h/X0XpBYN6a6iw6uDG+TZ0k8ryt3VhHyMFIxLFaXNpquZ1JGdOQYkn z8YTagHXadjU9hp4ThfgAqAIsOiTcAmAGM1V5y3xjAnvFvAkuF2+EBzrt7GXArFYBhfy /R5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YieL4r+TN+gn7WlBHT97uAGWLZ5+RH9FuBAcVj4s06U=; b=CYlKgqRFA3BFxojA+0KvUYV4FkVcnIL7aw3vWMR93hh4mQtja2xFyFGvwALTmHyOrN 6zrojYwdk/aN2wvs1qXFFE0hlPydl5fNik1LheT81nATzod7oITktsKikpZApTT2iP/q Y1VactUdfgR17Kd7ZyT4BZqcUiL41cye54JKdb+OakPH7e0K2wusxMpichQzc9vHd1+t Qh1c8WF8V2Yiwlh3HxdyZPGZy3L/2TtTyMu+GJolooaFJT2ZUDvd0UEnOlhWieVQ1LR9 kz/eyyvZt9WGFSa69HdH8PYzEMSBtHg5kdStsxK/+I6U4e4r7aw5L+yOad7JUyXlLdiD GNIw== X-Gm-Message-State: AOAM5338aXqVWjy8kqKpN7KRgI0MspLLSuLwB5S5U9jtj7CPHMkDcZXA o7f4S6dDQi4WsvI04ppOM4Z9tQ== X-Received: by 2002:a17:902:7287:b029:e5:bd05:4a97 with SMTP id d7-20020a1709027287b02900e5bd054a97mr22397043pll.27.1615236052207; Mon, 08 Mar 2021 12:40:52 -0800 (PST) Received: from google.com ([2620:15c:f:10:8:847a:d8b5:e2cc]) by smtp.gmail.com with ESMTPSA id gw20sm230132pjb.3.2021.03.08.12.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 12:40:51 -0800 (PST) Date: Mon, 8 Mar 2021 12:40:44 -0800 From: Sean Christopherson To: Peter Zijlstra 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 Mon, Mar 08, 2021, Peter Zijlstra wrote: > On Mon, Mar 08, 2021 at 10:25:59AM +0800, Xu, Like wrote: > > On 2021/3/6 6:33, Sean Christopherson wrote: > > > Handle a NULL x86_pmu.guest_get_msrs at invocation instead of patching > > > in perf_guest_get_msrs_nop() during setup. If there is no PMU, setup > > > > "If there is no PMU" ... > > Then you shouldn't be calling this either ofcourse :-) This effectively is KVM's check to find out there is no PMU. I certainly don't want to replicate the switch statement in init_hw_perf_events(), plus whatever is buried in check_hw_exists(). The alternative would be to add X86_FEATURE_PMU so that KVM can easily check for PMU existence. I don't really see the point though, as bare metal KVM, where we really care about performance, is likely to have a functional PMU, and if it doesn't then I doubt whoever is running KVM cares much about performance. > > > @@ -671,7 +671,11 @@ void x86_pmu_disable_all(void) > > > struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) > > > { > > > - return static_call(x86_pmu_guest_get_msrs)(nr); > > > + if (x86_pmu.guest_get_msrs) > > > + return static_call(x86_pmu_guest_get_msrs)(nr); > > > > How about using "static_call_cond" per commit "452cddbff7" ? > > 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: NOTE: this is 'obviously' limited to functions with a 'void' return type. Even if we somehow bypass the (void) cast, IIUC it will compile to a single 'ret', and return whatever happens to be in RAX, not NULL as is needed. > Still, it calling atomic_switch_perf_msrs() and > intel_pmu_lbr_is_enabled() when there isn't a PMU at all is of course, a