From patchwork Tue Nov 5 19:55:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863491 Received: from mail-il1-f202.google.com (mail-il1-f202.google.com [209.85.166.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C57B2141BB for ; Tue, 5 Nov 2024 19:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836593; cv=none; b=p/PZyWrfl/FT3bzdv/hc5PZEZOQyXIbd3lKxGaF9kgzIEUS8U2nfQTY9JcjC4j8K7RWkXSyGhlpq5pf52ci/W2fkD1b7CLr54BfPBodi1OimwXlZ4qqhpsRxbkfP0nPdaTrF4QDq+qLSFdI/eTnTHikW7acavqxVgFbiiEDzH0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836593; c=relaxed/simple; bh=dLIL2i/Biud1ORZ7js8CqRFmSmrKZrxHun5wYBVxjTQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bxTZ6qHbqRAJ9bm8rsnbfxNmfEPkplZJSGvqlD549vBMlU6Uj+KAPT8OtYciarCL3jW0VNGfnWxR2ML1Z7jwx5msBiFxb/nWGJSAtBZtCYk2Vt0UVpUMzOGHPhtJZfh9Ulqk7OZaW49kWiRA20ooDgR33TS0uEeqx2+fBpkl/mY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=a3bUT3KT; arc=none smtp.client-ip=209.85.166.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="a3bUT3KT" Received: by mail-il1-f202.google.com with SMTP id e9e14a558f8ab-3a3c5a6c5e1so76049915ab.2 for ; Tue, 05 Nov 2024 11:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836590; x=1731441390; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EPb0hqOBb6kblWxXXARI3ocpeztWq9KwTirxTPs2l4Y=; b=a3bUT3KTmTxnYZLZShXEB6OqvwhWcWJnsWtNf+5LxQ3sOPVeswhpFmdFMTnmb7fExJ B0gU8DdqOUDvj5oe8RczOj3L3w5i7z3tbcNzeoCFQY5PJM1FKi0ObftUDkRIgVGXb27b e7IcrZBVYEEGMsl+pnFM8KYlSXs4LAyQkeUi0dkVctl3ryp2o0VHKjAgbGUhutfABtLW WF3bO0PeiwBBM7y0okzEsfZZiqK64ELsK2grvwHCYAJEUtDpN1IOu/zNqrGI4ad26RD6 6DHciqBOY05qbJUXvHjKvnjoVOQXuM6fiR6Zgo+ehdRBXZI3diRtt6kxVZXNjnm1ALze CnfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836590; x=1731441390; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EPb0hqOBb6kblWxXXARI3ocpeztWq9KwTirxTPs2l4Y=; b=kzig3gtWrtYH2p6ByMPpVTtVeSsz7Ur8TIjxEZg9J9ITvfW1GIpRwoCxXhr1e6t0fj Puaz6HwF0c8tVrNhgCxhiY5qWI3vCR/XzyR6v+vqMzwD6NwwTGSrn/iew74zp3X92PaG wBzX4uk3RIFNA6IvsOoraTVBGFrcRsAGRTfxoHDibhY2LySh5oJrO8UNM+/Cwbf22n7E LgK4YBpg+nxVtgG5WpCi3XSBrwpgUeg6hjogkX2ZxVuAVvqqi5Lv+ZLNT1cc8CpGgO1i JGMB4Wxn3gmMbR6ubmUO9U4yhuxjaXJgVb70bn3FLQZ8x0D9Zy0AgnCRh0FU8+nQAcQW q87A== X-Gm-Message-State: AOJu0YySVKOJs8D+OdiLW9gaZt9KI94/pEyDnASjb2CqZmkicCMQGkwz fY2lH+ZK6iceyTWvqTpv/idQAe7Gja3x+dz34mw/lS9t8wrPnnAjS/GUbZRGjwuAOMiKXoW11cW KYiSRlIij31kD1zcsI7+Awo/oHNHKhGkmJUADqkHTmlugNgEgOqrVK7Fg1LhqtogCgV2NBJSpYI OXm19hGcUVQzt7KNYjkk/YZkvEIngO9K+FD2ZIlOWQAvn2iic4AVrou7A= X-Google-Smtp-Source: AGHT+IHah6Nqgqq9N69ws0DKUP/HTUx1alzkcwBsGSQWk19UCQk0MEnTOVuN0lF159yK8HSXoS8zbdDz2TvwiOw9WA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a92:d702:0:b0:3a6:ca09:6d48 with SMTP id e9e14a558f8ab-3a6ca09715emr1563885ab.2.1730836590276; Tue, 05 Nov 2024 11:56:30 -0800 (PST) Date: Tue, 5 Nov 2024 19:55:58 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-2-coltonlewis@google.com> Subject: [PATCH v6 1/5] arm: perf: Drop unused functions From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis For arm's implementation, perf_instruction_pointer() and perf_misc_flags() are equivalent to the generic versions in include/linux/perf_event.h so arch/arm doesn't need to provide its own versions. Drop them here. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/arm/include/asm/perf_event.h | 7 ------- arch/arm/kernel/perf_callchain.c | 17 ----------------- 2 files changed, 24 deletions(-) diff --git a/arch/arm/include/asm/perf_event.h b/arch/arm/include/asm/perf_event.h index bdbc1e590891..c08f16f2e243 100644 --- a/arch/arm/include/asm/perf_event.h +++ b/arch/arm/include/asm/perf_event.h @@ -8,13 +8,6 @@ #ifndef __ARM_PERF_EVENT_H__ #define __ARM_PERF_EVENT_H__ -#ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) -#endif - #define perf_arch_fetch_caller_regs(regs, __ip) { \ (regs)->ARM_pc = (__ip); \ frame_pointer((regs)) = (unsigned long) __builtin_frame_address(0); \ diff --git a/arch/arm/kernel/perf_callchain.c b/arch/arm/kernel/perf_callchain.c index 1d230ac9d0eb..a2601b1ef318 100644 --- a/arch/arm/kernel/perf_callchain.c +++ b/arch/arm/kernel/perf_callchain.c @@ -96,20 +96,3 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re arm_get_current_stackframe(regs, &fr); walk_stackframe(&fr, callchain_trace, entry); } - -unsigned long perf_instruction_pointer(struct pt_regs *regs) -{ - return instruction_pointer(regs); -} - -unsigned long perf_misc_flags(struct pt_regs *regs) -{ - int misc = 0; - - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - - return misc; -} From patchwork Tue Nov 5 19:55:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863492 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B75C21441E for ; Tue, 5 Nov 2024 19:56:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836594; cv=none; b=iM+r/k/djPVzHmvlH/bG5hIHp5PLZVq6Av3nmkKpRtIc/GYylqOD2dUbOn9DhY1VOWPot7J+hwf3pg5VYsPAFkQq6WDKCkGZsOFpLwzRX9Dt4EcEbwx08c/F85vO6W6LF9Fhyy7G516DoFs9S+VidwnaeCC+ESwG3bri2te6m4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836594; c=relaxed/simple; bh=41knp2f9+tFuA0hGkx33CUINGIH/Cir2wKVXo2+/wMs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=J+EzE1eei2BQUqrWooh37Jo/6sLLOar/wUcTmaofh8y07MR1FD5FLmtz8Yd0R8laTCoIVHMLFtOW/wGAEiZq/Yc1tPhgIxAdCz5iq0RQCHqV4sb03tZhzB/Q7ury2UI/jUd1TIWrdxESgM95bg/uzzeDlrgBu/Nek8XVh/RS8UU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1ysJov10; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1ysJov10" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e7fb84f999so91184397b3.2 for ; Tue, 05 Nov 2024 11:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836591; x=1731441391; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lW2hnUZ08ySVaaKZC/4iu7cWmp25J7OzTnpA90UyACk=; b=1ysJov107C78JOZhgce3leZ2CHJdQxjrL4PQ1HsTxYLK4C0IcEIqev66WMvZwIisRA QooggbmC4fE7V7NfTZArJ/rytlnQ1W0dLgMBDXvcNCU+4QEB2/oqfnTv3uhg5GiqOPnr 8e7dXtoW4m4louQURuxsGmzFyLBEdjaTvqd8Wim8EVrQIaz7bTEiS2WluyIYdLzzdTpH S4h1ASYDK3hVaUTRm8OPrQU7y6xOGdWwZLvCQRgbE9669x4DAJID1Wm6FbBBlPMjXa5G 4GjJi6Ecp8pMMd+eC3ygrUHLAGI8lW+AkTN9WwLaxKbzNsK3zc9h7yJX+WhrI+g9mIF5 yxsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836591; x=1731441391; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lW2hnUZ08ySVaaKZC/4iu7cWmp25J7OzTnpA90UyACk=; b=o7nqNFZoiMxH1qlLCqTVyOIxdfmDZhsoJAKf+eAEOwQQ0PGHwkz0wr5/okOTyGQsG5 RS3+6oj/G5EBRAyOLG0j+jABbPuEXRgxXEWkunGwJP9Snvx57SkiseMH9pGCUaaDFhaM cXyNCXHFTHuWlX7DDr51EHhdgAJM+mXMJ/yXk6blDhQQfehcOZxLo7EBukh/nWIz+ch4 nMr3FSzS3H6R4bMgQpYTRiTTYG7mAwoa8aIj36eHbSDizVeQx2bPKIKCHX1SH8plaaoR rGsQoHKKX2eV2096xC+4bMoWMD8+SN8mppQBYWqmlydxe8UBk42/ygv0TmsyCwPfFHNq VzXw== X-Gm-Message-State: AOJu0Ywo7wfNKmG5fpeQeVPmqAJWJU5ID4r+Q7Q2Kyg+OP1FaIGhslQk KwpPwXWRG2WlDdyZe2WCju1qaPPdHnEz0JNRjOYXCDRGiU0TIkFOyg5W4IW8OvJb2+YC9qWuGAR y5XIh6E4FYGaK7oHl9acT/lPpdyZUGes6KYv3MoWml/GhGs6HL+uKi9rcYnThyyrE2kPlfzitSD 57r0E8u+FEsSUq4hgAdI/+A2CVa9a9Ew77jEEnzDgjbZ+7Z3jX3yHHGtk= X-Google-Smtp-Source: AGHT+IEiTrVSWVdbBHruxNgcosSV6u9mlFrXHqLs4GJ39SmBXoHMQUH72lnNFzg3J+Krrje+KBYNpkQ7INqPc+ge4w== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a5b:bc7:0:b0:e16:68fb:f261 with SMTP id 3f1490d57ef6-e33025817a8mr11774276.5.1730836591154; Tue, 05 Nov 2024 11:56:31 -0800 (PST) Date: Tue, 5 Nov 2024 19:55:59 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-3-coltonlewis@google.com> Subject: [PATCH v6 2/5] perf: Hoist perf_instruction_pointer() and perf_misc_flags() From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis , Thomas Richter , Madhavan Srinivasan For clarity, rename the arch-specific definitions of these functions to perf_arch_* to denote they are arch-specifc. Define the generic-named functions in one place where they can call the arch-specific ones as needed. Signed-off-by: Colton Lewis Acked-by: Thomas Richter Acked-by: Mark Rutland Acked-by: Madhavan Srinivasan Reviewed-by: Oliver Upton --- arch/arm64/include/asm/perf_event.h | 6 +++--- arch/arm64/kernel/perf_callchain.c | 4 ++-- arch/powerpc/include/asm/perf_event_server.h | 6 +++--- arch/powerpc/perf/core-book3s.c | 4 ++-- arch/s390/include/asm/perf_event.h | 6 +++--- arch/s390/kernel/perf_event.c | 4 ++-- arch/x86/events/core.c | 4 ++-- arch/x86/include/asm/perf_event.h | 10 +++++----- include/linux/perf_event.h | 9 ++++++--- kernel/events/core.c | 10 ++++++++++ 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h index eb7071c9eb34..31a5584ed423 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -11,9 +11,9 @@ #ifdef CONFIG_PERF_EVENTS struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index e8ed5673f481..01a9d08fc009 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -39,7 +39,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, arch_stack_walk(callchain_trace, entry, current, regs); } -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { if (perf_guest_state()) return perf_guest_get_ip(); @@ -47,7 +47,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs) return instruction_pointer(regs); } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); int misc = 0; diff --git a/arch/powerpc/include/asm/perf_event_server.h b/arch/powerpc/include/asm/perf_event_server.h index 5995614e9062..af0f46e2373b 100644 --- a/arch/powerpc/include/asm/perf_event_server.h +++ b/arch/powerpc/include/asm/perf_event_server.h @@ -102,8 +102,8 @@ struct power_pmu { int __init register_power_pmu(struct power_pmu *pmu); struct pt_regs; -extern unsigned long perf_misc_flags(struct pt_regs *regs); -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); extern unsigned long int read_bhrb(int n); /* @@ -111,7 +111,7 @@ extern unsigned long int read_bhrb(int n); * if we have hardware PMU support. */ #ifdef CONFIG_PPC_PERF_CTRS -#define perf_misc_flags(regs) perf_misc_flags(regs) +#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) #endif /* diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c index 42867469752d..dc01aa604cc1 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2332,7 +2332,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, * Called from generic code to get the misc flags (i.e. processor mode) * for an event_id. */ -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { u32 flags = perf_get_misc_flags(regs); @@ -2346,7 +2346,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs) * Called from generic code to get the instruction pointer * for an event_id. */ -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { unsigned long siar = mfspr(SPRN_SIAR); diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/perf_event.h index 29ee289108c5..e53894cedf08 100644 --- a/arch/s390/include/asm/perf_event.h +++ b/arch/s390/include/asm/perf_event.h @@ -37,9 +37,9 @@ extern ssize_t cpumf_events_sysfs_show(struct device *dev, /* Perf callbacks */ struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs /* Perf pt_regs extension for sample-data-entry indicators */ diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c index 5fff629b1a89..f9000ab49f4a 100644 --- a/arch/s390/kernel/perf_event.c +++ b/arch/s390/kernel/perf_event.c @@ -57,7 +57,7 @@ static unsigned long instruction_pointer_guest(struct pt_regs *regs) return sie_block(regs)->gpsw.addr; } -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { return is_in_guest(regs) ? instruction_pointer_guest(regs) : instruction_pointer(regs); @@ -84,7 +84,7 @@ static unsigned long perf_misc_flags_sf(struct pt_regs *regs) return flags; } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { /* Check if the cpum_sf PMU has created the pt_regs structure. * In this case, perf misc flags can be easily extracted. Otherwise, diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 65ab6460aed4..d19e939f3998 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3003,7 +3003,7 @@ static unsigned long code_segment_base(struct pt_regs *regs) return 0; } -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { if (perf_guest_state()) return perf_guest_get_ip(); @@ -3011,7 +3011,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs) return regs->ip + code_segment_base(regs); } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); int misc = 0; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 91b73571412f..feb87bf3d2e9 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -536,15 +536,15 @@ struct x86_perf_regs { u64 *xmm_regs; }; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) #include /* - * We abuse bit 3 from flags to pass exact information, see perf_misc_flags - * and the comment with PERF_EFLAGS_EXACT. + * We abuse bit 3 from flags to pass exact information, see + * perf_arch_misc_flags() and the comment with PERF_EFLAGS_EXACT. */ #define perf_arch_fetch_caller_regs(regs, __ip) { \ (regs)->ip = (__ip); \ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index fb908843f209..772ad352856b 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1655,10 +1655,13 @@ extern void perf_tp_event(u16 event_type, u64 count, void *record, struct task_struct *task); extern void perf_bp_event(struct perf_event *event, void *data); -#ifndef perf_misc_flags -# define perf_misc_flags(regs) \ +extern unsigned long perf_misc_flags(struct pt_regs *regs); +extern unsigned long perf_instruction_pointer(struct pt_regs *regs); + +#ifndef perf_arch_misc_flags +# define perf_arch_misc_flags(regs) \ (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) -# define perf_instruction_pointer(regs) instruction_pointer(regs) +# define perf_arch_instruction_pointer(regs) instruction_pointer(regs) #endif #ifndef perf_arch_bpf_user_pt_regs # define perf_arch_bpf_user_pt_regs(regs) regs diff --git a/kernel/events/core.c b/kernel/events/core.c index df27d08a7232..2c44ffd6f4d8 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7022,6 +7022,16 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif +unsigned long perf_misc_flags(struct pt_regs *regs) +{ + return perf_arch_misc_flags(regs); +} + +unsigned long perf_instruction_pointer(struct pt_regs *regs) +{ + return perf_arch_instruction_pointer(regs); +} + static void perf_output_sample_regs(struct perf_output_handle *handle, struct pt_regs *regs, u64 mask) From patchwork Tue Nov 5 19:56:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863493 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E7B1215C73 for ; Tue, 5 Nov 2024 19:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836595; cv=none; b=f7992kDdYV1KvGi5zqQMNvipCebcXldnq8aGSx/bTfde7jBwXJhWs3zodK6mEEFb1k6wXoyRCdo7X/P75GHIF8HKiaVPJs+OZJ/Vt/Ke1k7/mv+OkkHdiT8gf8K5azlRO9yNPD8wiaI4Y4qdzuX1xN1agg8ak5njukZ3WSzaj1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836595; c=relaxed/simple; bh=wSz2wg4Whtfo/EFpwfiSjTtt4Xe91rIimgScnrimpn4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NlSzAObZwGt0UppgUfoQAs4Ub8eG8CpP5K/0diVv0EUIOzR9PU1AwqndoDjR1F/SzCtISf7ZgHbGHlQmu9A6eAreywcI+aRbmFwc24u/3gac4KSJm/8NOeO6JHrrECQ9lwoQskviK+VJ2G4XqpRBQLhMJClLawN2kU/jO6ov+Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FQqo0Ec+; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FQqo0Ec+" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e38fabff35so103802937b3.0 for ; Tue, 05 Nov 2024 11:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836592; x=1731441392; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sW1pAHD8RX7fvQhBgDL/ivZoJ4MMiFBudzlwbhbqZhM=; b=FQqo0Ec+hHd93ayT2azT+kPq4whnCYy27uq61IJFChMD09/8NELNvKIC42NigwCK6y n2XKmNDLBRQkoIYPMsE9oWOT+7Nrbl4y5e+dGZefFhav6tIPSXHTUbv7mlYgwO2V1hTI YABZZHCFoXwK2qm3my6Ro2fpD2Drg/D2RnRj+1F+ew3OL+sCt0VXpG4gzxJ76Yv8c9V3 4OE8hiJZA9+ZaYxAiNVPhUYziBQMRm8XBdeUQ+LigSEafNnTPNUDZDaoHn8dqv4oF9YV LAKFaDIqF/K6OOPLeORRr1NBNJIW3r4JSIWfle+LBj7cfJQhKgC6VwSVDKMdyV2XbB21 0ZKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836592; x=1731441392; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sW1pAHD8RX7fvQhBgDL/ivZoJ4MMiFBudzlwbhbqZhM=; b=Wj8XdXai6AZwXHeKd0HBvu54eSX9zQ36EKN51SEZ7s3L4xlEdsXIM5OcsHfg+QUxCB Sm8FO/MBk2Gv9SOW82UZz97/6BTh1Kh1jFe4fZaihxfE+/DscLYf+kPaPG222Ysakdr2 k6//Uw6reeSODuzP/H0oikpFIVWL/sObdPTp9r1arjJZjucH+2LUyqN1aksNHo34NolL VPJ2lppEOnb4jyquE//dxkLHoTP0YJrjZMQZPJfhU2ifychlcOzdRziYV0K/aXiFlJGZ oMRl4/8MH5kQeiNM79Z2fGzkGweenx7xHVWTZjGq7kPyndmcNPZs9rrD0+Z8xZRxi3vH AMSA== X-Gm-Message-State: AOJu0YxHlEuUDfiWADFuiBPqQSp0JpqkvcWgrViggfQEf/AHeu1obUMq Zo/8hNIUcFV7tx0isdhPzPZQmuVn4quCsVm7vIBk7z1dsAG1A3ORMUQ0+sLYeReK/hZNU/y1lMV qHgRwaFODRlrOuZcgrsm8WevVvNSX74sY0CWbzB20HkPVkJVMmnUOHlmdKDviX3M91qFSJ7MDZm ZXyM8vFoe19IsdpWE+URC0rQz0tiTVOPXXjBUVrXKJJoVvPHZgXcRVXnk= X-Google-Smtp-Source: AGHT+IFe5esZfmV8PpNtTKhf67GNSznritdlgCuivBreGx7Lwrw/eQ/PIB8HLPh/Mq6jxCM85J+7ZrWnfVuJw3jbsg== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:4489:b0:6db:c6eb:bae9 with SMTP id 00721157ae682-6e9d898f08bmr17263797b3.2.1730836592357; Tue, 05 Nov 2024 11:56:32 -0800 (PST) Date: Tue, 5 Nov 2024 19:56:00 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-4-coltonlewis@google.com> Subject: [PATCH v6 3/5] powerpc: perf: Use perf_arch_instruction_pointer() From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis , Madhavan Srinivasan Make sure powerpc uses the arch-specific function now that those have been reorganized. Signed-off-by: Colton Lewis Acked-by: Madhavan Srinivasan Reviewed-by: Oliver Upton --- arch/powerpc/perf/callchain.c | 2 +- arch/powerpc/perf/callchain_32.c | 2 +- arch/powerpc/perf/callchain_64.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c index 6b4434dd0ff3..26aa26482c9a 100644 --- a/arch/powerpc/perf/callchain.c +++ b/arch/powerpc/perf/callchain.c @@ -51,7 +51,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re lr = regs->link; sp = regs->gpr[1]; - perf_callchain_store(entry, perf_instruction_pointer(regs)); + perf_callchain_store(entry, perf_arch_instruction_pointer(regs)); if (!validate_sp(sp, current)) return; diff --git a/arch/powerpc/perf/callchain_32.c b/arch/powerpc/perf/callchain_32.c index ea8cfe3806dc..ddcc2d8aa64a 100644 --- a/arch/powerpc/perf/callchain_32.c +++ b/arch/powerpc/perf/callchain_32.c @@ -139,7 +139,7 @@ void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry, long level = 0; unsigned int __user *fp, *uregs; - next_ip = perf_instruction_pointer(regs); + next_ip = perf_arch_instruction_pointer(regs); lr = regs->link; sp = regs->gpr[1]; perf_callchain_store(entry, next_ip); diff --git a/arch/powerpc/perf/callchain_64.c b/arch/powerpc/perf/callchain_64.c index 488e8a21a11e..115d1c105e8a 100644 --- a/arch/powerpc/perf/callchain_64.c +++ b/arch/powerpc/perf/callchain_64.c @@ -74,7 +74,7 @@ void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry, struct signal_frame_64 __user *sigframe; unsigned long __user *fp, *uregs; - next_ip = perf_instruction_pointer(regs); + next_ip = perf_arch_instruction_pointer(regs); lr = regs->link; sp = regs->gpr[1]; perf_callchain_store(entry, next_ip); From patchwork Tue Nov 5 19:56:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863494 Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D645215F45 for ; Tue, 5 Nov 2024 19:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836596; cv=none; b=TLPxTcD5gagw7AJKNJkGlIsozWAIF9GgDbdqXimqyddM8F3uYaSCRKpG4j97xQBXZ64KW4Y6Pp7AYAN1boVOYKgoJNgb9ASIPy3dYQlOwiglRZe/jkC6KGWUSjObePv+2UJi++num6nu+R6dpNtiaC1ANUW+T4bWGBtEYaC7O1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836596; c=relaxed/simple; bh=L5dg5GAs/HO43xeeUw0eVVB1COvg02FxEjYWig5XfNQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HvRirl8WTFiotiiIt8pWqodu7lle0b2+uvCyUV5ixMMSJ4jya1usI492deovyQSFzq6B+X+0JvLsZkq4HMRpSnPPRcJVyQ599NYBQJzplZUph1V49zsZlUHd77FocqZ6FH4Iw7+7WIRd1BtkHJ7xu1bWgXuArcqkzhMKcvtZDpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RCpiLJSD; arc=none smtp.client-ip=209.85.166.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RCpiLJSD" Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-83abb2b6d42so568515839f.3 for ; Tue, 05 Nov 2024 11:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836593; x=1731441393; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g+A/E6dh30+B+DuVgwcV18/qvNhG5j8MCeVP9K0OnPU=; b=RCpiLJSDRAnKCYCgYmtr5aFffKKqzBMFps5OWsprH430AJEXOmBRpUZ0KcMvAngKd7 3pgKqRMpdHGqpY1xZu45ttA6AtdrKEJ7nwIZR2rzSMJOX2Sa6cyiIKKiddgwLiIs+hG4 poG5XdRTT5K+4i+s2B6lA+HFfVGUqpOQkOpekcZyNo3ljbCNQeJ8EP9iRSZNvduMWxso MQeJAQpRbKyZpBEpx1L9j44VDce99yUYzUGG+yexEXSiyTlUY9krhYEiMjLHGcaTd3Te MyuxTH+KXdc9SQfLHSB9MJhdBG6R7VH30iNMX4UwwxSmF31QJ4BZxE0tO3611jWXNxW/ Zt3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836593; x=1731441393; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g+A/E6dh30+B+DuVgwcV18/qvNhG5j8MCeVP9K0OnPU=; b=OPxw2QSl5g/fpMuChhSTYT2hkYLOaZi4MUlEzfNKAHdfsZMJGtQrl44Ut2FnxH/nWI FbxCssMMJ+/Fs6U4tsrgO25bi3AddEOryl33QzXqW3tcskciMd7tFkv0T1+lYfIQCk6p q0nYeLcd8UmrhzOh/S6li2h9ZLxhatRgWoepjYFxQHEPeJliCLQrqg+Yn+uZ+8eaZAnx Jz1mVtT5XVEuvmzjip3msEbFzGnwTYMySWwInmlRhTptC/ZR2U/QiXvAb69jUgkukO7E 1I+zZdqRmAVKsTgMrXt6ZSOYCtKzx6s+zyrYwxVRLU6ZE8wqFFF6i6D2ePwKGQrEtJKX c+Hg== X-Gm-Message-State: AOJu0YykftqcelGMBt2USt39J1GM0P5Eg4YCRyu63MPMFLYTxd0B48K5 5ILMAdkoEOTCiD8+no6a9QcqgqUkRdJd4N7HlEqkS/JOD2E5sr3VEQFs7ZLPYjHWWWf5CRAocV7 wDxedfFdcxb2b1bbxWnPEBBS3ExvT5rlgebtcuG8hqIPR0BZRaSDQZFBOGt5RD82oDXtbZd/vgl PMDUX/DuHyIzPtRjgGWuo5pH5WLYszNdC0tkBX8tZmhnb8MdlGvUN6Gpg= X-Google-Smtp-Source: AGHT+IHwq3hF4ElsT4RerqS5KSh2j8l+o/SOi33LC2KdnD9j/u2Nkb6pf++GYEETuSfSuC1nI4Yu4HiUAJoPcaH3GQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6638:210d:b0:4db:e5f0:ceaf with SMTP id 8926c6da1cb9f-4de0257ba11mr134988173.0.1730836593213; Tue, 05 Nov 2024 11:56:33 -0800 (PST) Date: Tue, 5 Nov 2024 19:56:01 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-5-coltonlewis@google.com> Subject: [PATCH v6 4/5] x86: perf: Refactor misc flag assignments From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis Break the assignment logic for misc flags into their own respective functions to reduce the complexity of the nested logic. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/x86/events/core.c | 31 +++++++++++++++++++++++-------- arch/x86/include/asm/perf_event.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index d19e939f3998..24910c625e3d 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3011,16 +3011,34 @@ unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) return regs->ip + code_segment_base(regs); } +static unsigned long common_misc_flags(struct pt_regs *regs) +{ + if (regs->flags & PERF_EFLAGS_EXACT) + return PERF_RECORD_MISC_EXACT_IP; + + return 0; +} + +unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state = perf_guest_state(); + unsigned long flags = common_misc_flags(regs); + + if (guest_state & PERF_GUEST_USER) + flags |= PERF_RECORD_MISC_GUEST_USER; + else if (guest_state & PERF_GUEST_ACTIVE) + flags |= PERF_RECORD_MISC_GUEST_KERNEL; + + return flags; +} + unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); - int misc = 0; + unsigned long misc = common_misc_flags(regs); if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; + misc |= perf_arch_guest_misc_flags(regs); } else { if (user_mode(regs)) misc |= PERF_RECORD_MISC_USER; @@ -3028,9 +3046,6 @@ unsigned long perf_arch_misc_flags(struct pt_regs *regs) misc |= PERF_RECORD_MISC_KERNEL; } - if (regs->flags & PERF_EFLAGS_EXACT) - misc |= PERF_RECORD_MISC_EXACT_IP; - return misc; } diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index feb87bf3d2e9..d95f902acc52 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -538,7 +538,9 @@ struct x86_perf_regs { extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +extern unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs); #define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) +#define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs) #include From patchwork Tue Nov 5 19:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863495 Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B01562161E0 for ; Tue, 5 Nov 2024 19:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836597; cv=none; b=Lj9MByXhCQddZnkbar4kpefd1hNhBNEApQQfPvClHqJxSbkJdoOnDb5JMmHjcWNNMX/Ny0JEi8rG23Fn4749HxM0BNN6LY1xTnNkHKXUKArCNptbyKnuWzVKq6RZ2yQMpZNZQd3DL1yklghxUsXvms0tzItzdIhEI276oQ9/wYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730836597; c=relaxed/simple; bh=l1rv9ZRZCEsMJagCqCJCU6OUmj4qSL7qwYsMuLLwVjU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jtXpwRdiuDiCCnHla3Aw0HSnwBAUeWFV1ah3SwvAw+3Pkn4YLoeQqrM1pq+qEpKdnQlSd6cYS5MsUWy9jzN61TIgfvveeW6uLExj9ZPpZ0LG5u6WYqH9m+vIzT82syd0fxy4sY0FQYWSjjCA/qbFAvZHyTW/dSi/HauGuwruYys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=h4JdDgx4; arc=none smtp.client-ip=209.85.166.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h4JdDgx4" Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-83ac1f28d2bso613259939f.0 for ; Tue, 05 Nov 2024 11:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836595; x=1731441395; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=m4LSX7jp2Qk0unPMxnSvbmTUvnRmwzrHBbuAe/XVNyI=; b=h4JdDgx4RjpjAzEQIBjjrIp2Es68j2Eq9zhotqDJ6XFsdf8fwcp8HvpGX5wikJuAtL rXuXLDzREhE6rRBotYkk1SF6XxUGcgo/HFB+ukzGHupHTSv7m3fqOIpuYDDKblb9vrsF xgHAv3hFZOXQsJz77Djhmrw9dJvPMpO4XRexedLsYPJMi9ZmV81fZLDgS3UHuezjhDZf /uuvKLKY97/BqIYxVJRCYHTkbFeusa4T2BOFVFidMA4bA+NSJQDWBWikcbS3Gf3SZAgO WI9hPB1IBWFaUZ+jMd2297vWVlol49xs5ZbsSSu+bDuW+u/x8wDAvh3qnl6adqmXu/97 FnIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836595; x=1731441395; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=m4LSX7jp2Qk0unPMxnSvbmTUvnRmwzrHBbuAe/XVNyI=; b=jsPvEo1RhH6ulY2bI4A34SWx5F2GM2iQm0xFwVKXhDa9vcVWFx5j25wY6YW911ZnIL DQwiHywm+L6JwNyFhm/BVvjwcRzttxbk9VTfK7dkbs4tteDYxBbnA9c9XmLYnfc1q7QO PWTyC+JkS7HZd8YP22kSgUbdplXihJb9qTLMDzSV1t0sy4tdHsgFrKabxj8uiogmBvA3 pp3lUvxFMDaZ+R0QodRU5TuMZ4/+x6DfeTOaMSJeyNt1S4Pr05fXFkvycD0+pItfScl8 zxxauRHJgsId5USNkJkbB2sasSaKbvT/1ZZo30Eaj6iT/vjIH/YEoQ8ZfT8cUAhkuAK8 8OYg== X-Gm-Message-State: AOJu0YxYEiY5b0hyG3Fc+UO5PWkNBr2zbr+6onVpAbgw/6dbjYiBZZHe X6rg4bFGqo8Br3um2PTKuglFyjui3HWtEY+Os/TAbdl8Q3SOdmLUKVfDthDjtgQeUXalqZYLQul eu9OqpXB4n+jSFriPAhHfas6I+/4LIHrYHnD9H/7TFQJr0H1ZfG311Y0LGi812sV1Gbg3mt69Uc R6HUW5w7DsplkoNHJL9vjE4xa35XJxZ7Df5H5F2LKItRkC7VXKR85WWwE= X-Google-Smtp-Source: AGHT+IGFWv6Kn3TvX6dXV3OFqthDQLbL+dvhQJb9vkUUge7jztFf2TETEHNZy98hndWREoqhSt0rcXIvqTH5LIwoGQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6602:3f81:b0:82d:821:96a7 with SMTP id ca18e2360f4ac-83b1c4c870cmr11455439f.3.1730836594061; Tue, 05 Nov 2024 11:56:34 -0800 (PST) Date: Tue, 5 Nov 2024 19:56:02 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-6-coltonlewis@google.com> Subject: [PATCH v6 5/5] perf: Correct perf sampling with guest VMs From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis Previously any PMU overflow interrupt that fired while a VCPU was loaded was recorded as a guest event whether it truly was or not. This resulted in nonsense perf recordings that did not honor perf_event_attr.exclude_guest and recorded guest IPs where it should have recorded host IPs. Rework the sampling logic to only record guest samples for events with exclude_guest = 0. This way any host-only events with exclude_guest set will never see unexpected guest samples. The behaviour of events with exclude_guest = 0 is unchanged. Note that events configured to sample both host and guest may still misattribute a PMI that arrived in the host as a guest event depending on KVM arch and vendor behavior. Signed-off-by: Colton Lewis Acked-by: Mark Rutland Reviewed-by: Oliver Upton --- arch/arm64/include/asm/perf_event.h | 4 ---- arch/arm64/kernel/perf_callchain.c | 28 ---------------------------- arch/x86/events/core.c | 16 ++++------------ include/linux/perf_event.h | 21 +++++++++++++++++++-- kernel/events/core.c | 21 +++++++++++++++++---- 5 files changed, 40 insertions(+), 50 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h index 31a5584ed423..ee45b4e77347 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -10,10 +10,6 @@ #include #ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); -#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index 01a9d08fc009..9b7f26b128b5 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -38,31 +38,3 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, arch_stack_walk(callchain_trace, entry, current, regs); } - -unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) -{ - if (perf_guest_state()) - return perf_guest_get_ip(); - - return instruction_pointer(regs); -} - -unsigned long perf_arch_misc_flags(struct pt_regs *regs) -{ - unsigned int guest_state = perf_guest_state(); - int misc = 0; - - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } - - return misc; -} diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 24910c625e3d..aae0c5eabf09 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3005,9 +3005,6 @@ static unsigned long code_segment_base(struct pt_regs *regs) unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { - if (perf_guest_state()) - return perf_guest_get_ip(); - return regs->ip + code_segment_base(regs); } @@ -3034,17 +3031,12 @@ unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) unsigned long perf_arch_misc_flags(struct pt_regs *regs) { - unsigned int guest_state = perf_guest_state(); unsigned long misc = common_misc_flags(regs); - if (guest_state) { - misc |= perf_arch_guest_misc_flags(regs); - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } + if (user_mode(regs)) + misc |= PERF_RECORD_MISC_USER; + else + misc |= PERF_RECORD_MISC_KERNEL; return misc; } diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 772ad352856b..e207acdd9e73 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1655,8 +1655,9 @@ extern void perf_tp_event(u16 event_type, u64 count, void *record, struct task_struct *task); extern void perf_bp_event(struct perf_event *event, void *data); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_misc_flags(struct perf_event *event, struct pt_regs *regs); +extern unsigned long perf_instruction_pointer(struct perf_event *event, + struct pt_regs *regs); #ifndef perf_arch_misc_flags # define perf_arch_misc_flags(regs) \ @@ -1667,6 +1668,22 @@ extern unsigned long perf_instruction_pointer(struct pt_regs *regs); # define perf_arch_bpf_user_pt_regs(regs) regs #endif +#ifndef perf_arch_guest_misc_flags +static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state = perf_guest_state(); + + if (guest_state & PERF_GUEST_USER) + return PERF_RECORD_MISC_GUEST_USER; + + if (guest_state & PERF_GUEST_ACTIVE) + return PERF_RECORD_MISC_GUEST_KERNEL; + + return 0; +} +# define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs) +#endif + static inline bool has_branch_stack(struct perf_event *event) { return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK; diff --git a/kernel/events/core.c b/kernel/events/core.c index 2c44ffd6f4d8..c62164a2ff23 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7022,13 +7022,26 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif -unsigned long perf_misc_flags(struct pt_regs *regs) +static bool should_sample_guest(struct perf_event *event) { + return !event->attr.exclude_guest && perf_guest_state(); +} + +unsigned long perf_misc_flags(struct perf_event *event, + struct pt_regs *regs) +{ + if (should_sample_guest(event)) + return perf_arch_guest_misc_flags(regs); + return perf_arch_misc_flags(regs); } -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_instruction_pointer(struct perf_event *event, + struct pt_regs *regs) { + if (should_sample_guest(event)) + return perf_guest_get_ip(); + return perf_arch_instruction_pointer(regs); } @@ -7849,7 +7862,7 @@ void perf_prepare_sample(struct perf_sample_data *data, __perf_event_header__init_id(data, event, filtered_sample_type); if (filtered_sample_type & PERF_SAMPLE_IP) { - data->ip = perf_instruction_pointer(regs); + data->ip = perf_instruction_pointer(event, regs); data->sample_flags |= PERF_SAMPLE_IP; } @@ -8013,7 +8026,7 @@ void perf_prepare_header(struct perf_event_header *header, { header->type = PERF_RECORD_SAMPLE; header->size = perf_sample_data_size(data, event); - header->misc = perf_misc_flags(regs); + header->misc = perf_misc_flags(event, regs); /* * If you're adding more sample types here, you likely need to do