From nobody Sat Nov 23 08:38:07 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 6C97D2038DD for ; Wed, 13 Nov 2024 19:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524523; cv=none; b=jvp/MH2KAomkUOqrL3icmfMGnFVasgIki/82fe9KIzkRzhhWUvoaVdugGiUlGY1DNAbuKUteglm4nxxCDJGh1CvQoGRukHoPLYCfn6sXkR4ie2HNoVlVaGC6JK0fpp7TWTM9FIaxckEyES88pniEomBKjTIGpfy7Etu/nY03mVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524523; c=relaxed/simple; bh=NbcQuU5q+usE1Vfx+epUjEaR55c3/0PQVXgf9pjjXZ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rP8EUZavljGCosXmle+HXIKJAIPIIDHeUXU5zpvwd0ImLDI1UpOfsVc8yVF0sF/CHvAFOPZfYBxHuYMNojWvV7qQo2MlQLy/Yv5ChN8BdialRFx4rcrZhCTnJphgedkn8UjY/dOHsGrtWM9lZk7DrjRQbsIb4BbnQXzNjNVq0zY= 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=wBoq/cw8; arc=none smtp.client-ip=209.85.219.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="wBoq/cw8" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e293150c2c6so13297855276.1 for ; Wed, 13 Nov 2024 11:02:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731524520; x=1732129320; 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=Ps8myr2QRGzBkspMaTCSz6a/NGAbW5KYOWNi6Q8v63A=; b=wBoq/cw8c5N7q6THVrOltmzTzT/NDa7QGf7kh1ZsVka0e2woecpKrWoixnJSdNSiJE yuwf7jXVLylgRbbSE9yclBnIqtvjZC/L+0Qa/+x1ZHhHYITF1zgimscvw8wg2yBr1ZBp 4HrkuyzvEIUsX65kFlSLDpKYSlmti8XWaHwlXA8L/bUHBO7BW1d9rKT+7ZzTuvPdu/B6 9fkO2S7lSZ/QaormNIVeE1TTHLHnrS8Igqc6z8XJxNnaHXK6X49IpwgtlauY4KGiz+a8 KosuUkeF5VSRkcUmDG+//oP2bt32Bod1/h/LpHYWm1bOotIY5pWWdn29liwYVvVTMUxu PhgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524520; x=1732129320; 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=Ps8myr2QRGzBkspMaTCSz6a/NGAbW5KYOWNi6Q8v63A=; b=ljgRCGZgwUFHXq6kLKP1PvvCWa5D7zKfsVxVWgJgT+6P093/stBeEfqFYXRYw4JD20 6IBYOGYHisWTn/vp5LIp4t5tyImMl3cp79ru6ACQ7mQBroAY0dczLzLsj/QRklxfpmbg 25UOTvwSAInn4ofNTIyA0C8SvU+eOhMJiMLEa5jbCVXZvdrntEPnFWlaoRSynKyIlVht 842f7TnTfB2DcQeB2LApFuiRmOg5FeMo/Cb8DSGcuz4seW7aHf1eTg95PvJnCZiPaQpZ jAFgfFEVcbiFBz5mtAd/3K4YvFW5pcOpgtX+FkNxD7PuEW7Xf92z51hYcx9bNoITPPbh 464A== X-Forwarded-Encrypted: i=1; AJvYcCUaxc2JWnT2/H2rVDHboJHZrVT1OUbWbVLTxAMVz+xrZG/ERr/MrLLj8EoN/HUu3l7KUj5Q1iQvxJELk18=@vger.kernel.org X-Gm-Message-State: AOJu0YwvOSxSO0GJhCItY/vbbMbj5p8WZzJGLZHjvZO7JBgvhMmSeYoR XxckHFCKVAFAv1eIIetdJbA3fv7i0XcSbOCzCNz5nht6EeR0waP/s2wl2RYv4n+/gfxMjMJm9hh CPbvJrWVpj+MZtdj2k6/2Dw== X-Google-Smtp-Source: AGHT+IGMwJxojcrbV2XaWtAxjGZhIMKLD/TWp2TYO47jqONg2YGViPdlhPH/gu+8jwib2jMpO8Gmgpa+P/L1ZLf8OA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:3349:b0:6e3:d670:f62a with SMTP id 00721157ae682-6ecb343d0b9mr2033797b3.3.1731524520358; Wed, 13 Nov 2024 11:02:00 -0800 (PST) Date: Wed, 13 Nov 2024 19:01:51 +0000 In-Reply-To: <20241113190156.2145593-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241113190156.2145593-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241113190156.2145593-2-coltonlewis@google.com> Subject: [PATCH v8 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Will Deacon 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 bdbc1e590891e..c08f16f2e2435 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__ =20 -#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 =3D (__ip); \ frame_pointer((regs)) =3D (unsigned long) __builtin_frame_address(0); \ diff --git a/arch/arm/kernel/perf_callchain.c b/arch/arm/kernel/perf_callch= ain.c index 1d230ac9d0eb5..a2601b1ef3182 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 *e= ntry, 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 =3D 0; - - if (user_mode(regs)) - misc |=3D PERF_RECORD_MISC_USER; - else - misc |=3D PERF_RECORD_MISC_KERNEL; - - return misc; -} --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 08:38:07 2024 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 C47BA205E12 for ; Wed, 13 Nov 2024 19:02:02 +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=1731524524; cv=none; b=eUr6rYdwRLLW503k9CDAsLtH/+4BlEt8SF0xfUSJNomdcOerwPQujFGtcYbjoLHp1vNe1m+uYCoNhCPyesl35kEbLX6qKjpUDtD+cV/Ryxl4vHUoCUsUywiU109hqZXJrLq5GYsurJo4eHRjM7AvlY8QsJobFYLRMW7ZYqQRzJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524524; c=relaxed/simple; bh=vLbt9/juw8Z//mAjDK6js0PBnm8wzA+ZBHhiQUHqJrA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kH2MqwXBUHmxKmQSdl30QEcUa25NJjdt0k9PxBO7q0ICcBnNPV+u/vgVxu42FSKomxoxCwUhS1kt7BrWifzuny7DmYTPF4RRqQM030yaLtYTNksrTlbRPl5aviACZ05aqM7WziL282xjYBG30drsPL2kZOpRHJcKRbxC0KeICV4= 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=pu1SKYrN; 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="pu1SKYrN" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8794f354so127288577b3.2 for ; Wed, 13 Nov 2024 11:02:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731524522; x=1732129322; 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=NyYNjbjk4/qmDmP3x+G8tnYKw5xPTbyL8J59cvk1BGk=; b=pu1SKYrNZG1u52alVVWZZItoek82q7ViQLitcOqQ0v/gC7FZ6e96jqtyOswfKPujSK BKDhsZH5/OEx0NjJL0ZcKUZe/0H543Lqm4kSFK2JZuiDT9TVNEz8hTojOyGzyZpVqZ7r wZiSUzXCWyV18gt/fPMoh6lXtq3vKZHvse5Ajwv12nUaf9gHX6LeBi7K9bPHGXDr7QP6 ZXpjiYs8UOYqP3KU41JZaZ1gwJl4N+nWW1bSuyzYQy7puud5hnWXteZDgc0gRhUu/7iv zVbpJ9jrYznh2gqtzymaTmx1UOxYUoFfF+SxbtkuXXasFPpns/htSzOUitTfnT8pTriG Q/OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524522; x=1732129322; 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=NyYNjbjk4/qmDmP3x+G8tnYKw5xPTbyL8J59cvk1BGk=; b=W/9c2lWNbRhgYKTiYxItxP59H/n7AqIGtpkCX8B0kEu0yqfKFEkiuppfDnak0fOdBp IsklifYfIDS5Es6+b0PLG0M7IaEG3qNafRIAOy0uprJOkqezHcNzXI29ayQt6YmDziIi meWpB8qpO1hXI9chPiHNBHCsHuSb4qP1QCbl61XK29DMTJ5lL7Jx/NjOW4FJtRyExt9l 2R+L/+JPj0kIK7mVyBtOlyfkzBZdhmTaXJ56kgzqToOc8htt3xNlrnLpam1RrpCp6qai KtRSmml9yMtqJyOOHQ2fq0cozKo9Xfge8LJYJe7oYdjXLnaQ5WkkukE/Ls0XJTixduGQ rI1A== X-Forwarded-Encrypted: i=1; AJvYcCUhhfsyLVsFDiDFCpt86N4x9OfCwvktaCL+QA3FYKk5a2byQuPqaRvDL9/TpG3zw2SHPAG3JVhrZarORSA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2gVK439PVtCFHKEi1AQ20ExNIxdf+kCJalL53TTNhaudFYIpc +ZhFB9HbYPWRZtJcx2fQT0NrHOhj4hAanqHJ9A4yKWhC3/MzWDqO9bBxjV9KU+o2FyEmFCkXxQy 53s8NFunYjdDazPXbI+FPZg== X-Google-Smtp-Source: AGHT+IExTyQGT4C3MPyRboq/16qqGXa8dkz1c00ponu+1+51Vjwoch0YQlT9YqzaiyonVF1EDUg5DExNp4MKKVOOnA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:3505:b0:69b:c01:82a5 with SMTP id 00721157ae682-6eaddff0e00mr3606317b3.7.1731524521813; Wed, 13 Nov 2024 11:02:01 -0800 (PST) Date: Wed, 13 Nov 2024 19:01:52 +0000 In-Reply-To: <20241113190156.2145593-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241113190156.2145593-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241113190156.2145593-3-coltonlewis@google.com> Subject: [PATCH v8 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Kan Liang 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/p= erf_event.h index eb7071c9eb343..31a5584ed4232 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -11,9 +11,9 @@ =20 #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 =20 diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_ca= llchain.c index e8ed5673f4817..01a9d08fc0090 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_ct= x *entry, arch_stack_walk(callchain_trace, entry, current, regs); } =20 -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 *re= gs) return instruction_pointer(regs); } =20 -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state =3D perf_guest_state(); int misc =3D 0; diff --git a/arch/powerpc/include/asm/perf_event_server.h b/arch/powerpc/in= clude/asm/perf_event_server.h index 5995614e90629..af0f46e2373bd 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); =20 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); =20 /* @@ -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 =20 /* diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3= s.c index 42867469752d7..dc01aa604cc1e 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 *eve= nt, 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 =3D perf_get_misc_flags(regs); =20 @@ -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 =3D mfspr(SPRN_SIAR); =20 diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/per= f_event.h index 29ee289108c56..e53894cedf088 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, =20 /* 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 =20 /* 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 5fff629b1a898..f9000ab49f4ad 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; } =20 -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 *r= egs) return flags; } =20 -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 65ab6460aed4d..d19e939f39983 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; } =20 -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); } =20 -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state =3D perf_guest_state(); int misc =3D 0; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 91b73571412f1..feb87bf3d2e9c 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; }; =20 -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) =20 #include =20 /* - * 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 =3D (__ip); \ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index fb908843f2092..772ad352856b6 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); =20 -#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 df27d08a72326..2c44ffd6f4d80 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7022,6 +7022,16 @@ void perf_unregister_guest_info_callbacks(struct per= f_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif =20 +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) --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 08:38:07 2024 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 02ACA20515A for ; Wed, 13 Nov 2024 19:02:04 +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=1731524526; cv=none; b=tQ97tNDTYGVumw2SZHdvMlcBBgaT0cFANL3439vsPygOgonQPB7rhbgGzNr+JT762z1lr4fmtVmiyAIn1cAhQNskDQzl2OHp6P2OnaL74TbyCqfXXyquy812RxrBNGuu+FO/6EdoXTPYOu5UXkuIDIRHVBAaCz3dggUxIoCN94M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524526; c=relaxed/simple; bh=zfHGGul4boURCIlF9sZ0v7jHEGbHHtIvQPtjpwKmZjI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i7EViSOubz/lUrAJkuFStjAZK5qR9xSDMJTQMIxo67fFrn5Qz7FrYd93PFzP8ATL2+eUf38eoMooRmEqwQvtf42C97m7OrA/2BH4gOnMZdXdq/MBl2P7AkZ3t3G0lMTtaLAYrFPGYioxgwjY1Dbx9In0ateqTCkPeeSTyzAR6fY= 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=J3ek19d5; 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="J3ek19d5" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8901dff1so139437077b3.1 for ; Wed, 13 Nov 2024 11:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731524524; x=1732129324; 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=tgqFKvoVHXye/CyIJghap8jc4W684iliK9zLYmCZ1Zc=; b=J3ek19d5SzafdyqjgJsw4UrEG6aw3LRaSJM1tbuEUPFryd5x39/u8EijyF+sGNPmKl T3XOzhBNeq6AIknh2HQDQO8RNdoPBlmeTcrJXtI14Z/cAxt7+z0ViTpYQ3RbFvxVlHIy gm0GC/27X5NwsIYsR1s5b0SaaoG653C+6L91sHUaPSbxaxr3KoY5ij1NIhUjnseI2YlR wo7HTwWI8U+ZFcO8NJ7lZ+IShIa9u1F40fukwfGJuE+qKA/OZTiyqldj7wiPnbcTr63J K8AtUR+ABYBT+fvfK53nZSP/KtcmvezGoV5XAGJU8Ku0Sy5FKPIcU6XKm53LX0UAlE03 JdaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524524; x=1732129324; 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=tgqFKvoVHXye/CyIJghap8jc4W684iliK9zLYmCZ1Zc=; b=VDKiX3xlZ7DVnvyz04o7gbwcPGfk/SHPajofjh5/G9QR2qGvaBAeK4xjZR3sGvdxuM Fo5NYY2ldDm7iT9WrZmvO7OeABa63vUh7Gm/jOxGqvMp+s1tdMMXP9gziWV+rhaUlHYR rFDeU9q2NjPa1sfSnXIKqDWmwMTK49joUznBlvQXO81gkbg0bHzGl5kAOJhVfoXF7rkg i9eHBakl8ZXB8V/xReObiGtvqTcXYpTGhxPxNWALCE68uj8x313C4bMtxxemHteAeld4 E6N/hTzXefh8Vf+D07h/XA3o93xk1B19e9kbKu+9fb38I0Gn9JwvXGiFmEYOT+z5gcZB YXiw== X-Forwarded-Encrypted: i=1; AJvYcCVl8mM4ruK70BKLTrBXd/MdQ2+kgJUbGsYHQCTFNZH8opqUcNIrhnikYF23QOFkiaO0+dO3JEk42F04Oj4=@vger.kernel.org X-Gm-Message-State: AOJu0YyBs5ReF9ZmdAPdmZUOsVvhvK3w9XnwhSiUWMnIccHKq0bLBKd/ snHxyxvSvDw6pYspqFUnJ3QCzrXFAMIXs6yjBBDN30o6Zu1zUvi1SNmIBO6LKcRuI1dOI/wLmwb 4FyeCGqoW2CyKu9kQ9syT7A== X-Google-Smtp-Source: AGHT+IFNr9w/0dGnK6PRtslGYFp20zZooyO9LSsLAArex0mr+uzyM7no72zQ+L4NJiH7IrVQOwJt58oXd0jflNUvgA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:2411:b0:e38:c40:380f with SMTP id 3f1490d57ef6-e380c4039bfmr33947276.3.1731524524115; Wed, 13 Nov 2024 11:02:04 -0800 (PST) Date: Wed, 13 Nov 2024 19:01:53 +0000 In-Reply-To: <20241113190156.2145593-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241113190156.2145593-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241113190156.2145593-4-coltonlewis@google.com> Subject: [PATCH v8 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 6b4434dd0ff30..26aa26482c9ac 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 *en= try, struct pt_regs *re =20 lr =3D regs->link; sp =3D regs->gpr[1]; - perf_callchain_store(entry, perf_instruction_pointer(regs)); + perf_callchain_store(entry, perf_arch_instruction_pointer(regs)); =20 if (!validate_sp(sp, current)) return; diff --git a/arch/powerpc/perf/callchain_32.c b/arch/powerpc/perf/callchain= _32.c index ea8cfe3806dce..ddcc2d8aa64a5 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 =3D 0; unsigned int __user *fp, *uregs; =20 - next_ip =3D perf_instruction_pointer(regs); + next_ip =3D perf_arch_instruction_pointer(regs); lr =3D regs->link; sp =3D 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 488e8a21a11ea..115d1c105e8a8 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_c= tx *entry, struct signal_frame_64 __user *sigframe; unsigned long __user *fp, *uregs; =20 - next_ip =3D perf_instruction_pointer(regs); + next_ip =3D perf_arch_instruction_pointer(regs); lr =3D regs->link; sp =3D regs->gpr[1]; perf_callchain_store(entry, next_ip); --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 08:38:07 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 95FB820721E for ; Wed, 13 Nov 2024 19:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524528; cv=none; b=s3BQPVGFzMQ2Jd/e/icMl5KWoyp3fMBM2CUOE0Q+NTgzGDDMaKcvUGhDEKsCPubnY/fRJamRR/1g81PS4TaJIiWf/XUuIvqYNfpeOILOvD8QRu2cCKOJzUJqKYdZB9HL8hdPTlkTfKtgb5t/ZbrEGW432FOCthvCQuCSz5gemTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524528; c=relaxed/simple; bh=OMb3jG971jmx2YJYYmtMd1jdhDZJTQd5uT/KvMEr7uE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gais3XCeyv+qmcKSDkw2fU3IBR7WHJ7bQuecwvw8NdJHgGmaKfr6TnOGDnRMLcAPdfrG7dcHS6hYnQowIYacMWg5EJM7mPyx6zt1ooCAN62/8i7HIORY6H0si7WsJvvbXh3ZIotxcfUE7mdtQmDUz5VyBs78Dznq6KVCdLzmjBU= 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=vimj57Zg; arc=none smtp.client-ip=209.85.128.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="vimj57Zg" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea82a5480fso130130507b3.0 for ; Wed, 13 Nov 2024 11:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731524525; x=1732129325; 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=QQFdXgHR/yBinKM9akC7F2JFw2+gnKw6F8HpNI5yy4Y=; b=vimj57Zg+4IsIh5ujxBbiF0Lv8ztyCCCO4dxWbLMKAqutI49nS4pMM3mvKHdNSuJTc 1YwFavZj9xr6uWR6yGrraiMRaTJ8F6poPfBO2O0gXykTlGoIZ2j/WaC8amva+zaHzWQz hF8Go48gvYHMZKkIEeOBKbb4wXXs75PUz/WWAzogYjeyVKt69a4JwyOdsq+Y52ZxKDju cRh3Y/TElUbLgtA1maSZPlKl+zPp9USHCsdewiycps+QBgZBxJZdxRTOGIKy/UEbwYcK VffPv3ponYDxPgHR6cdWbjnOW7SpYe8vRGxI8pZOsEuHe0IWvrOXqrnoCsUeYDSG6hwu puAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524525; x=1732129325; 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=QQFdXgHR/yBinKM9akC7F2JFw2+gnKw6F8HpNI5yy4Y=; b=AipuhLyymdTga+MqShcbss4J5MUhGBzlL7kAWQajFv8KZKOz0guTID9Z4A/hnNKC9a rSQV9PpzmpWrmQ0YjjJemnvBxCfaLA6oB1+ThlC3f7VLHr2Qfc4pSgILDENLElL3WCFA NHsg69BESXE1Z/vfzYhMpXjNJNXR92dzOX4Cn2uvedMI1WUDcbYSiFsnhBcIcEJKz76r +lYev9n+f8Tj2zp+Ovsrz0q8SrLXUEaKAVeaL8yEUO1H2XEa7VNiW5EJ4xWL1KfhbSaA zIYzWqmTo4ZEDifJbDpLNEuV+ksld0w+sXbG4JivIAK9cd+Fb2egeSeQwnePp47GoS99 JvyQ== X-Forwarded-Encrypted: i=1; AJvYcCXPGmc3You96qw/c5Yim6Fu2SfW1YmNX7cY9h3JGNrVOeYcjqb6gO9J87pZrq6tWbyf0mdE1YmiQ/iHTAI=@vger.kernel.org X-Gm-Message-State: AOJu0YwwC5ugYxKj0zPoe22lhN80zK7mC3fJHk/nkmEOyFmSurnd2ktV Fu2tpMtmQByc3r8p84UJRRvGIzD5g0N+8Z9NhaKVVMrNP9jAfrp4+CXXf6wgEypfVkQEwJhNPOj j+2LGnKaH80XHyh5xsMdVjA== X-Google-Smtp-Source: AGHT+IFhulDvoY0sGq7EYnbunXmF/EqPCQ3tEG2uX7XcBCI6dgYlk8NlhbbJtWap3voWbgrqyi9w6iV13kRImFawvA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a81:8a44:0:b0:6ea:e011:f122 with SMTP id 00721157ae682-6eae011fd7cmr1805147b3.5.1731524525438; Wed, 13 Nov 2024 11:02:05 -0800 (PST) Date: Wed, 13 Nov 2024 19:01:54 +0000 In-Reply-To: <20241113190156.2145593-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241113190156.2145593-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241113190156.2145593-5-coltonlewis@google.com> Subject: [PATCH v8 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Kan Liang Reviewed-by: Oliver Upton --- arch/x86/events/core.c | 59 ++++++++++++++++++++++--------- arch/x86/include/asm/perf_event.h | 2 ++ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index d19e939f39983..bfc0a35fe3993 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3011,27 +3011,52 @@ unsigned long perf_arch_instruction_pointer(struct = pt_regs *regs) return regs->ip + code_segment_base(regs); } =20 -unsigned long perf_arch_misc_flags(struct pt_regs *regs) +static unsigned long common_misc_flags(struct pt_regs *regs) { - unsigned int guest_state =3D perf_guest_state(); - int misc =3D 0; + if (regs->flags & PERF_EFLAGS_EXACT) + return PERF_RECORD_MISC_EXACT_IP; =20 - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |=3D PERF_RECORD_MISC_GUEST_USER; - else - misc |=3D PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |=3D PERF_RECORD_MISC_USER; - else - misc |=3D PERF_RECORD_MISC_KERNEL; - } + return 0; +} =20 - if (regs->flags & PERF_EFLAGS_EXACT) - misc |=3D PERF_RECORD_MISC_EXACT_IP; +static unsigned long guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state =3D perf_guest_state(); + + if (!(guest_state & PERF_GUEST_ACTIVE)) + return 0; + + if (guest_state & PERF_GUEST_USER) + return PERF_RECORD_MISC_GUEST_USER; + else + return PERF_RECORD_MISC_GUEST_KERNEL; + +} + +static unsigned long host_misc_flags(struct pt_regs *regs) +{ + if (user_mode(regs)) + return PERF_RECORD_MISC_USER; + else + return PERF_RECORD_MISC_KERNEL; +} + +unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long flags =3D common_misc_flags(regs); + + flags |=3D guest_misc_flags(regs); + + return flags; +} + +unsigned long perf_arch_misc_flags(struct pt_regs *regs) +{ + unsigned long flags =3D common_misc_flags(regs); + + flags |=3D host_misc_flags(regs); =20 - return misc; + return flags; } =20 void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index feb87bf3d2e9c..d95f902acc521 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 { =20 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) =20 #include =20 --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 08:38:07 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 92430209F2D for ; Wed, 13 Nov 2024 19:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524530; cv=none; b=t9SNo/F6kDwfCBNEX5Y0JXLsrpl+Knm1uw6vDDPul+WqsUk7A8Nkn56BFchq5uiaFlLpCmj+lkDGKIsBRl/gg3AKQvXFpZ/kg6fgJAOe9sErk/to2KZEKvYdVCeW1yT35QTX69NcK9wI0rBKHb2zyr8PYjM5zrqavUGnpOsUoZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524530; c=relaxed/simple; bh=ZbI2dCQ2t6UVu8Y0vsUSVYF43fUxjINBxE2hDpD/UJY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=egkh2gYENCJJJCao1mE7Lpz6++yAPDiZciQlqPsaVZw/VxwrjgF32veEv61N1jQFn9eXUzvo7uCS8zDUbosz0HchEWfiMFKKCF6BEzX47vKJu89CWz8XI8KE/PCYehDJHeDwKxpTSET0au2QEd0OxmTQMTgQwA3kwHOFbJyEP9E= 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=PZyEkekn; arc=none smtp.client-ip=209.85.219.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="PZyEkekn" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e32ff6f578eso1365988276.1 for ; Wed, 13 Nov 2024 11:02:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731524528; x=1732129328; 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=W3z9O4Nh1QIYeHjkTYeY8Uz2tjDm/EBln1nfLrKHjVI=; b=PZyEkeknSVZoJ2yXDEv+i+eTXxSxrKhwRCmye57m1lE0j6GmuOtsWSbtaIZJ1/lMgR g+6W72kCaul5Dvb1/sWrfTaRVML4jg5WRKMu02aRyI8A5JBk7Mvd3I1EQ9ELWew3KJsT 5wBjlvC4vwaJB+dpLAmE/c3jncPIxd/JxqyMClNsmy6ej9EHzpeNAhTurLjUKUPjxiHP pdsufNYk0DMyBTXSJllyMOB7z8GKYqCILlTXJhFttlKylLPdyfqDFR6szGOtqbpX3sE9 mWrofMZlX5pZxZekvYNviIDiyrTw+GcduWqZoX9AqFMyhhgj7cDY+JuaEkDODpyhEG6V JzTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524528; x=1732129328; 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=W3z9O4Nh1QIYeHjkTYeY8Uz2tjDm/EBln1nfLrKHjVI=; b=GiGhkcClxi13lwMy06Z3BrAJVWys8L76dDcLCfoYR1/UthrElFgQ5I32fypQ6Q4iuW cuLLlWWjaiREFtMo9URvmjplthhD+VQOon51QLUFfgoTbgUBpOTdMrlMhrMGaNWUkGWx c5a4j/W3tSGJWnmqLf9qsZ2ikRftlaT6/xNBUPvW8SJvI1murClkMTFOPQSnHOlG2di2 Uu6TqchdPmheYBmQ2qmpPH22RObEqlpAsAO2uDN7LFCWjYmVTPUltXh6g2LDPy7HUtyi j4BcxYk32CV74pm884kY0HYDPvfS0h+cDwAwMixHJyXGNU9Vk0Qap+fS9C/hF4Gx1DL1 LWFg== X-Forwarded-Encrypted: i=1; AJvYcCU6sdDIiYGjuKTj3wQclC6TTYdy3G5LQDk+sQDNX+P98VocHq50UP1VYkvXPSTpNz5zr5fUdNJFyC3mSD4=@vger.kernel.org X-Gm-Message-State: AOJu0YyCRlPVbYpqNg5dLARj+cydIxFCfGiidpJT22Yqt51sx8dPFXbd 0naz1wdx09eX96SrTn0xw0aUn3XDQ/MBIsXis1N2b+z4Z9zTuVBSnmAdm02D3Gs1d/axhQcUYFL neCAv/DkW5Xm2glqG4+hqRg== X-Google-Smtp-Source: AGHT+IH+p6Jkhv80JbftlyPSva2V+XD4uDlfcpENEqpQ5lUMycdgk8CZBg1V5KJjBNXlSVJn+OptimsRTZOrtvSBNQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a25:ab07:0:b0:e26:3788:9ea2 with SMTP id 3f1490d57ef6-e380df137cemr10752276.0.1731524527798; Wed, 13 Nov 2024 11:02:07 -0800 (PST) Date: Wed, 13 Nov 2024 19:01:55 +0000 In-Reply-To: <20241113190156.2145593-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241113190156.2145593-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241113190156.2145593-6-coltonlewis@google.com> Subject: [PATCH v8 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 0. This way any host-only events with exclude_guest set will never see unexpected guest samples. The behaviour of events with exclude_guest =3D 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 Acked-by: Kan Liang Reviewed-by: Oliver Upton --- arch/arm64/include/asm/perf_event.h | 4 ---- arch/arm64/kernel/perf_callchain.c | 28 ---------------------------- arch/x86/events/core.c | 3 --- include/linux/perf_event.h | 21 +++++++++++++++++++-- kernel/events/core.c | 21 +++++++++++++++++---- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/p= erf_event.h index 31a5584ed4232..ee45b4e773470 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -10,10 +10,6 @@ #include =20 #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 =20 diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_ca= llchain.c index 01a9d08fc0090..9b7f26b128b51 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_c= tx *entry, =20 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 =3D perf_guest_state(); - int misc =3D 0; - - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |=3D PERF_RECORD_MISC_GUEST_USER; - else - misc |=3D PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |=3D PERF_RECORD_MISC_USER; - else - misc |=3D PERF_RECORD_MISC_KERNEL; - } - - return misc; -} diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index bfc0a35fe3993..c75c482d4c52f 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) =20 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); } =20 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 772ad352856b6..368ea0e9577c7 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); =20 -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_r= egs *regs); +extern unsigned long perf_instruction_pointer(struct perf_event *event, + struct pt_regs *regs); =20 #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 =20 +#ifndef perf_arch_guest_misc_flags +static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *reg= s) +{ + unsigned long guest_state =3D perf_guest_state(); + + if (!(guest_state & PERF_GUEST_ACTIVE)) + return 0; + + if (guest_state & PERF_GUEST_USER) + return PERF_RECORD_MISC_GUEST_USER; + else + return PERF_RECORD_MISC_GUEST_KERNEL; +} +# 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 2c44ffd6f4d80..c62164a2ff23a 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7022,13 +7022,26 @@ void perf_unregister_guest_info_callbacks(struct pe= rf_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif =20 -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); } =20 -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); } =20 @@ -7849,7 +7862,7 @@ void perf_prepare_sample(struct perf_sample_data *dat= a, __perf_event_header__init_id(data, event, filtered_sample_type); =20 if (filtered_sample_type & PERF_SAMPLE_IP) { - data->ip =3D perf_instruction_pointer(regs); + data->ip =3D perf_instruction_pointer(event, regs); data->sample_flags |=3D PERF_SAMPLE_IP; } =20 @@ -8013,7 +8026,7 @@ void perf_prepare_header(struct perf_event_header *he= ader, { header->type =3D PERF_RECORD_SAMPLE; header->size =3D perf_sample_data_size(data, event); - header->misc =3D perf_misc_flags(regs); + header->misc =3D perf_misc_flags(event, regs); =20 /* * If you're adding more sample types here, you likely need to do --=20 2.47.0.338.g60cca15819-goog