From nobody Fri Nov 29 18:26:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1632269238; cv=none; d=zohomail.com; s=zohoarc; b=Km/mNSM4MZWjA3k3bBsfAy3Y4txDMZcefC27xaKIjV07lrH3Fx0aivOVfyH+z9tNjXjVj44WgDvnAP8TFhq9vQxsW16bdlmhsdOTiITlnOH5w69gp5ec20fscSl92C2Nk3oJwjNVRWh06B+HKgUaUyT8v/qTfOikagSMKSE9O54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632269238; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=lHJOof24VqkiYhFcIRNTWKzKjki/p0Ze5CnPJ3pN3mI=; b=gSTG4mwRSv6VZpbAp2efHzEKPIZ9GKy9qjPZbzjXUWZQreVrQdD6RSGkGS19oUg/NjEXxBALl9hkOHITinT681trgXeW03mTkCxe+XNgjUKxgLMYg51DZdGN37nQPsajN2YGSokqKG1caRqssZpo3Jj/1PoV0CltFvpHs+d0QNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1632269238913800.0929292891886; Tue, 21 Sep 2021 17:07:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.192016.342272 (Exim 4.92) (envelope-from ) id 1mSpmx-0005pU-MI; Wed, 22 Sep 2021 00:07:03 +0000 Received: by outflank-mailman (output) from mailman id 192016.342272; Wed, 22 Sep 2021 00:07:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSpmx-0005pN-I7; Wed, 22 Sep 2021 00:07:03 +0000 Received: by outflank-mailman (input) for mailman id 192016; Wed, 22 Sep 2021 00:07:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSpme-0000pt-Qp for xen-devel@lists.xenproject.org; Wed, 22 Sep 2021 00:06:44 +0000 Received: from mail-qk1-x74a.google.com (unknown [2607:f8b0:4864:20::74a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0c3c9709-3be7-4442-856f-1126aba6663d; Wed, 22 Sep 2021 00:06:03 +0000 (UTC) Received: by mail-qk1-x74a.google.com with SMTP id 70-20020a370b49000000b003d2f5f0dcc6so5794724qkl.9 for ; Tue, 21 Sep 2021 17:06:03 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0c3c9709-3be7-4442-856f-1126aba6663d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=lHJOof24VqkiYhFcIRNTWKzKjki/p0Ze5CnPJ3pN3mI=; b=NAVCfHnfawHtrL2iCYw8HgTBlFYN7yri+HxZMhsBlfVlSZIQEmh1AdRNXtYQ9FoGZS jRIrxb0XEtBmkG58IBs5w+mP9+jXc2C3HLEK37fIIPlowXZ4g2A0PlKvfuqb2ADJxmfT gWcyAqrNLMzTqwoc6qruf1z2Si6VfevO8CbFRhssYP8/HJFWfja6Iw9rCUyZd9oSQg+F 9XbckVVG4ADd3HGel6flTZI1kY7ZlS2ePo2n4ME18ZOc0prkN5QAWF7paKBJF7TwSTpL +vKX7u3jx0Z8b6TwojXazIBTpdi6hKJXbUEPbqRRJ9J3bLcqDW1CgpBqnGXO30fQFOsf UrIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=lHJOof24VqkiYhFcIRNTWKzKjki/p0Ze5CnPJ3pN3mI=; b=iZT5JDYOfE/lhBtN73esX6l8f/B74MUnF+NAQq1YwunmAlLQvsMQfiLktBeF1W8FWr 3NNpJs2ZxziwPhIbAd1EgFdmK0mDa1haOu0/m20QXbwSYW7TgjE+5atVTFfoX8WgORgA FxpIs/Xd2lIiJxYfaO5CnlPXZcZxnvtHzEb2x8cr910DaTtKLeyzYuJZTFmcisY775b+ QJeIaLexoDGLnyrt+2N2kYPwt+an6B8mj9c+/2R/aTfQ228Jn/Dt/OElXSWa7G4KE2xQ xhYsi/X+GZ0pdyc3PYfMRGlalzeIM1bEwi6UDEQ8EFMpTObTB28VD12kptnm2D5oTPEZ HYvA== X-Gm-Message-State: AOAM531dYyYJ3pRpWGqH9fp9GCzgLbaHid9umHj5AK48KwSQzpQNe/gS Lny6JEaaaHJh8c+NWL6iddUVzDjhM3k= X-Google-Smtp-Source: ABdhPJxiVysqs+seAL8tPuZXn+zjjV1XTgLeF1Hv4M206n5zRNvGf9PMhGCvhpJwuIHM26SWahcPIvZUjtg= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:b022:92d6:d37b:686c]) (user=seanjc job=sendgmr) by 2002:a05:6214:732:: with SMTP id c18mr33750621qvz.9.1632269163200; Tue, 21 Sep 2021 17:06:03 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 21 Sep 2021 17:05:26 -0700 In-Reply-To: <20210922000533.713300-1-seanjc@google.com> Message-Id: <20210922000533.713300-10-seanjc@google.com> Mime-Version: 1.0 References: <20210922000533.713300-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH v3 09/16] perf/core: Use static_call to optimize perf_guest_info_callbacks From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Will Deacon , Mark Rutland , Marc Zyngier , Guo Ren , Nick Hu , Greentime Hu , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , Paolo Bonzini , Boris Ostrovsky , Juergen Gross Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , James Morse , Alexandru Elisei , Suzuki K Poulose , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Stefano Stabellini , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, Artem Kashkanov , Like Xu , Zhu Lingshan X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1632269240536100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use static_call to optimize perf's guest callbacks on arm64 and x86, which are now the only architectures that define the callbacks. Use DEFINE_STATIC_CALL_RET0 as the default/NULL for all guest callbacks, as the callback semantics are that a return value '0' means "not in guest". static_call obviously avoids the overhead of CONFIG_RETPOLINE=3Dy, but is also advantageous versus other solutions, e.g. per-cpu callbacks, in that a per-cpu memory load is not needed to detect the !guest case. Based on code from Peter and Like. Suggested-by: Peter Zijlstra (Intel) Cc: Like Xu Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini --- include/linux/perf_event.h | 28 ++++++---------------------- kernel/events/core.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index eefa197d5354..d582dfeb4e20 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1240,37 +1240,21 @@ extern void perf_event_bpf_event(struct bpf_prog *p= rog, =20 #ifdef CONFIG_GUEST_PERF_EVENTS extern struct perf_guest_info_callbacks *perf_guest_cbs; -static inline struct perf_guest_info_callbacks *perf_get_guest_cbs(void) -{ - /* Reg/unreg perf_guest_cbs waits for readers via synchronize_rcu(). */ - lockdep_assert_preemption_disabled(); +DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state); +DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip); +DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->ha= ndle_intel_pt_intr); =20 - /* Prevent reloading between a !NULL check and dereferences. */ - return READ_ONCE(perf_guest_cbs); -} static inline unsigned int perf_guest_state(void) { - struct perf_guest_info_callbacks *guest_cbs =3D perf_get_guest_cbs(); - - return guest_cbs ? guest_cbs->state() : 0; + return static_call(__perf_guest_state)(); } static inline unsigned long perf_guest_get_ip(void) { - struct perf_guest_info_callbacks *guest_cbs =3D perf_get_guest_cbs(); - - /* - * Arbitrarily return '0' in the unlikely scenario that the callbacks - * are unregistered between checking guest state and getting the IP. - */ - return guest_cbs ? guest_cbs->get_ip() : 0; + return static_call(__perf_guest_get_ip)(); } static inline unsigned int perf_guest_handle_intel_pt_intr(void) { - struct perf_guest_info_callbacks *guest_cbs =3D perf_get_guest_cbs(); - - if (guest_cbs && guest_cbs->handle_intel_pt_intr) - return guest_cbs->handle_intel_pt_intr(); - return 0; + return static_call(__perf_guest_handle_intel_pt_intr)(); } extern void perf_register_guest_info_callbacks(struct perf_guest_info_call= backs *cbs); extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_ca= llbacks *cbs); diff --git a/kernel/events/core.c b/kernel/events/core.c index c6ec05809f54..79c8ee1778a4 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6485,12 +6485,23 @@ static void perf_pending_event(struct irq_work *ent= ry) #ifdef CONFIG_GUEST_PERF_EVENTS struct perf_guest_info_callbacks *perf_guest_cbs; =20 +DEFINE_STATIC_CALL_RET0(__perf_guest_state, *perf_guest_cbs->state); +DEFINE_STATIC_CALL_RET0(__perf_guest_get_ip, *perf_guest_cbs->get_ip); +DEFINE_STATIC_CALL_RET0(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs= ->handle_intel_pt_intr); + void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *= cbs) { if (WARN_ON_ONCE(perf_guest_cbs)) return; =20 WRITE_ONCE(perf_guest_cbs, cbs); + static_call_update(__perf_guest_state, cbs->state); + static_call_update(__perf_guest_get_ip, cbs->get_ip); + + /* Implementing ->handle_intel_pt_intr is optional. */ + if (cbs->handle_intel_pt_intr) + static_call_update(__perf_guest_handle_intel_pt_intr, + cbs->handle_intel_pt_intr); } EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks); =20 @@ -6500,6 +6511,10 @@ void perf_unregister_guest_info_callbacks(struct per= f_guest_info_callbacks *cbs) return; =20 WRITE_ONCE(perf_guest_cbs, NULL); + static_call_update(__perf_guest_state, (void *)&__static_call_return0); + static_call_update(__perf_guest_get_ip, (void *)&__static_call_return0); + static_call_update(__perf_guest_handle_intel_pt_intr, + (void *)&__static_call_return0); synchronize_rcu(); } EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); --=20 2.33.0.464.g1972c5931b-goog