From patchwork Wed Nov 13 19:01:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13874196 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 CD87B20515A for ; Wed, 13 Nov 2024 19:02:01 +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=1731524523; cv=none; b=cZtkJwh5UtsopS62tNNp/hmjj+/0ujac6zPQ3JGYLfnNOgTad4rzeTtIQE+DBUv1Ty+EjIIAUQFyf71cJPYwKxFSwozmQTTivHwHp59T1bFBR58OjiNcC2HLtjW9Jt2X3gWCZ7trFiYgnA4Fbj38rjjN3I/nKRTUoVg3daFU3ds= 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=P4V4bJaE; 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="P4V4bJaE" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea33140094so128159717b3.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=1731524521; x=1732129321; 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=P4V4bJaEg+EZ1BU+BW9+6Dm+sQ58YOOoyVBFV13wsThULFbLBOc2LiLcJPuYasvrKw F43D+F9W1EhoNGk0DSgwGk6PmkBVbDCYPFuqWHN8Pg6WC9rVzAmYeijgolfBCo7hjI2O TBMRGM7oQ9Cw9WWIdvC2PyqYOxNjOth/2rI0yGA2h+THLceRxr8OGoRonJBcQepAUbu2 lgoBd/nZ8VdpODqFTwu68gWavwuhldr/17qWrmx2kbxM91ucMcqWixkdQpgxMCOmlB6b mYLecDVUzJiuc/jGlJw4zjuU6w0mW/ZsWCfb0iZI6u8XjymKFJfE95GBum/SOmSOUotz UkDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524521; x=1732129321; 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=QlXALgO9HbXvJT0fL4CVy6mL8ss6DgUuI5XLPeFDOVhdTTV9KAJa2c0e6OkhOeL8I2 E15PBKe3SfwoLTpQGIT5Wh9I4h6Cv68G9e1CrmGbTeXOWFov2wXwYuEDHctk7/p5ykNq Ib3YSdSZbfQa4TubaixVkvOsxvpohk7GVW3GtqhykdqBcerL9hyrb4NkPp6d9n6WeP+V qz34d73dfyRtEfk/4LOfUJiXx1tDS5jUVUiRyQt3hdnU2wZqAIfbqEC9ONZltj6n1oDu BOsbUZ9DbcOHI/RnN6kAoIenyUXsh56sV/zAJHyzPGDDb4NJsdgTh0ZX56OFHrPIbv1V KebA== X-Gm-Message-State: AOJu0YyT4S0mFNhQyYctagQqS5XzByNrddutuFBQUO1CS9nPHss9Ju92 qALW9Uh4fanFLF1CRki5/8Cu3MJrX+cD3z3tjkOq12X7uh1tOPTrKJanq5GBb77oRn72pDBIcUe eE/+pibLsEUS8Msiq9AidH3EtK3hJ56Xri7uMMlSrUZVNlq5YR6ouaAGmK4SuJy28NlqEZuc7sg 7pT5S0NWt9JpZ6rpoite+qbDAOPN1XoapHRYpyQENm1k6m0JBaEYyS9jc= 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: kvm@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 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__ -#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 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 *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 Wed Nov 13 19:01:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13874197 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 B4FF6206070 for ; Wed, 13 Nov 2024 19:02:03 +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=1731524525; cv=none; b=MZLBff7DWxP7h3P8ZcN6bJMvPdpzGnSz61e2ngQp70dWPUFOHRqqeqx1jobcAP0LuspPjVamqen1cUWShKk/EpIhlQVbE0Njx98beFLk4cHnFe0U60sCEiH5NDoIdBjtiZJJ67NM/LsGDSNhG/ZhPhnuV9iUdd4B5UsF6MWseBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524525; 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=j5Oa05z7/szlNAgNHB0v6M1A8U4DVLij/ZQtmRPJBna4eZOCTqD+i7CTW69WDAxA2JYKnyc9X/rLISyk3gepwpQ3nk4R4sXuexDEIInbeOOLodcKDfI9CCc/GQY6Mc1StFuhNYMeOEC0F24qbnFyzOcCel676kKjZ78Jt2/+72o= 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.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="pu1SKYrN" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8794f354so127288727b3.2 for ; Wed, 13 Nov 2024 11:02:03 -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=ezapSwXl6KdDB3PO1M2qCzMiW62Z9hCsOj1SS3nZNfp3PA7VC87HWVKqkL5l37aydi ro6lLdf9eLBQoy/Ek3LInJUeFgpDv31a/wdz67oeKOoT5kGdiZD8tyP4IhK/W85c1t4B Uc2tHvzWxFkRyICln175Tn8RHJmL0LbT5xYF6IXVFmpDCEgIWJRSr/8r2TRZRuUcvSHu tWZCPDxTqiTUSkgxXUF7RO7WAp6qc5BGHe9jyD7D0H8XAwlJfqcmt6wFaOhQ5ea1fxHI E96/KF7O4JY5PvgfSYs3TbWY+2L1eVvUhH8BKDa1PSwiJNSwjHS1YH50vHjVGVWejRA3 fQsQ== X-Gm-Message-State: AOJu0Yzg8Oyu0cQbr3mCZDKILbe6bJM+zVIyG6OB8mRXPzLhaWnQnATn BFxBye+dHCfgnzVGFjrIZCf1PrzOFhhcaZrlp1Ytt+cx2r8YuKXOtVjTkuszkdM9nWgkiwAZpDI DfORjgZJKsYPEgmhY4BcB/a7aPNMz0KtH+tJnfZxXzQvCBxWlNV8w5k2foHmbDMb5g+Ki3Oanxm hS9AnAICLADdPRVMFuYx2rdIrlNkD130W7eOWw0OFZPa68zOhhVL0dPUM= 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: kvm@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 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/perf_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 @@ #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 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_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 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); 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 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 *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 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, /* 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 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; } -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 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; } -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 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; }; -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 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); -#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 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 Wed Nov 13 19:01:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13874198 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 9FC07206E78 for ; Wed, 13 Nov 2024 19:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524527; cv=none; b=MuACYSQx6v7Mn1KO/K+s19SJeTPsWe629JMe9rF9YOraJdlaemkGt9gVcwcdnKErMweg4LVMD0GZ9qaMpZw3bpVH75Af9BrVct16JbprBklYrWLd4uu+yESiNODlrP+vjyCwjkOhz6fqQOJN1W9W3d13nxL2/xUt+whvkwEoNEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524527; c=relaxed/simple; bh=zfHGGul4boURCIlF9sZ0v7jHEGbHHtIvQPtjpwKmZjI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EsfpzF5xU5ZRm7yz8dZvAggsjwT6hmeoITDkyNl6y5lxcgW1y5LBSC5U1f+PGD5EpbZyUg/PJerGwH7xK3fBHtBRrMMnvxULE8hxma/Ct5V/wDHHfb2swg7VEEhY2eEQiypNYKZqey//uiia4txP4lY2nq/PyoKUmnzkSNw29K8= 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.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3808d76206so762779276.1 for ; Wed, 13 Nov 2024 11:02:05 -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=QWkwuAB6d6qs4srNEY3htYO97/0O9SrE5kJo/m0geymPw6urGah3+fyZxZs2pqipz5 CsOgKdYCaA7y5B5uT4AMvFQVExMdWfXz+mkA3CzAjo5u80QmwLMp6UGkDbf/Q0JkkO4d 54ntYIZe6h8Wqnre2rwBWkFB8mivM3JJ9P1/8Ki6T7jL3GIlOelJdimv/vClxOYUTN2C nVZGBUd21bv02o0S7+BQgMZfUQp4J7ZfpHvwpyoGSuEI1SkmDPiTeIN2hWBSgLHu3bcR ATqIpD1vURlNpTB3y6krmDdlPqSvqQy3joFdzvSinlciT9IhMfAqF+mzj/g5hYclK+LH u9LA== X-Gm-Message-State: AOJu0YxP02QVyq8Ez/+8erSIh7+9usiik4UxUE8iX5FDOyLGrM8/YwGb SdvfI0XXYXM8O9yxsw3Lr4Ht9s5LubirP6egXRNmetjAoC9rjRL5pMxSx2PJ4Bhj0lE7YMgKk4r OOp1V1sLUvXuWH5Kk1ktpEcmmkZ4ZbXJ0qr6GjjJmhTwcLOSRRetJhp2HtmzvVKc5FJ1J1d+irO BF4S/aVkGTPjgfjN35gfZ4PVOWbSKyDDgAVOB9GCUHbQxSnVnmfKccqMY= 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: kvm@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 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 *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 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 = 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 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_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 Wed Nov 13 19:01:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13874199 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 B25022076B3 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=1731524529; cv=none; b=VB1mIJfiAV71IKQqePLB7KecAUkOMEMrCG9pUIA7n5+ODjtEp/HEWzeuJBylUEQutwY2rrxKklB+TifuV2NP4TqjykMtt5a2Z4HLP7iuk74XUpm2pAB7LzsRETMwu5Oo7v35r8KOB42GIvtEuiabgOV9tUwrdP6UOi0P1p1XMpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524529; c=relaxed/simple; bh=OMb3jG971jmx2YJYYmtMd1jdhDZJTQd5uT/KvMEr7uE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F3vcrhHCf+0MsAGE5LyUZy+7uDL3YtFx5vA+jQCfLqGv8OePElQNkTvZ00CuNPgd4th36aeQbgId+nA44B4vE5RYkUkQE4kf7FWayKSWXw/JCqCpPfSm/uPSJ/7WXfSB+GuGhIsNJDxeFkmr8iIyMO+Fv8yNdJhetq+PUqfVnxg= 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=m3IpI1PA; 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="m3IpI1PA" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6eae6aba72fso93178137b3.2 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=1731524526; x=1732129326; 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=m3IpI1PADZT6WgPrnDe9Y91wSa2CzCyf0S/y/ipIPCtVcmuEdrPYNRFO5EjT5A8AzG 5UeaKw9PM5d6wFa3SXcVmraXfaRtBGRQeqHptwV2IrArvTxo7QCb9WxiiHv9QoAKZJ/5 YKOAjEyRgZoKJ68IpYA+jfK5ypDw+2k+l8RcwXKs+b/h5beo4/q1v1H8t78ignlgzPrd SCHRx0XNWFc1FmCZio/p0x3BbqnGQGjoe9+vnq5IYliAuVB/Ic+F3lHoDZOcc3bkBrnN hS8SRSCK/r8fvI9OMSQDP1he6eQ2DUz73AoZRWRuH0L+vYQnsjUNoUOQfCYLrEb6W4Vg X/qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524526; x=1732129326; 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=RJrh3T6h0tBx3mKWYqogYmiSZ10j15UZqoYb9Zwslgu/s9MS5yhii46i7kqKMrCsy9 jbAjsA9k9HDDahhJ+7UGn200ahK2gVYlyL1R0Vq7bXGSfdDnu2LtjRZeXCpIbu9SnbyL T21l0rk+1fA/qJAsKTyP363Q+l2new+kgCPZHcpx6qn9f8sW8OBk1ZBGsvU70igJIy2U gy1kRSacXrbLvW3f3R9jeoT/cD/DnVqcEW5CuhTHFUgBI7L0+81wnWUazCEZp6m8mLAd qpC5CVvhLG8M8sHOBcWzGnf7uCCYwAA9XLJjSetXsoV7MHr5UqwD8G6dr+mN33hayEZB rf8g== X-Gm-Message-State: AOJu0YyOU8Dyai5mj23ImvBJSJSLfxIyRdrCPJ6Y0XFCwyyvC2RV/M61 JYHuN+7If4Fg4HGGtcFVc4lrTPJKJTiDJaSz66zkSpwwnuD2XeXedber9TuoN+2PsZs0vCeQgRG B6X6CUPnHdvXPWwe+7kvcjmAfBSwt6LfE0AAjNYc3WfClh6Jcs9efzFx+NOOi6yj/KODZqGi6bf iu5eMixwVYE5zavWHTkgGVwRy8EHse/O3p0sQZyqgNEJeRQxtL+6ei4Bc= 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: kvm@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 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); } -unsigned long perf_arch_misc_flags(struct pt_regs *regs) +static unsigned long common_misc_flags(struct pt_regs *regs) { - unsigned int guest_state = perf_guest_state(); - int misc = 0; + if (regs->flags & PERF_EFLAGS_EXACT) + return PERF_RECORD_MISC_EXACT_IP; - 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 0; +} - if (regs->flags & PERF_EFLAGS_EXACT) - misc |= PERF_RECORD_MISC_EXACT_IP; +static unsigned long guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state = 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 = common_misc_flags(regs); + + flags |= guest_misc_flags(regs); + + return flags; +} + +unsigned long perf_arch_misc_flags(struct pt_regs *regs) +{ + unsigned long flags = common_misc_flags(regs); + + flags |= host_misc_flags(regs); - return misc; + return flags; } 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 { 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 Wed Nov 13 19:01:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13874200 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 C037D20ADC7 for ; Wed, 13 Nov 2024 19:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731524530; cv=none; b=eqIETb4zImNxGslpZvfVqkk6+Jxb+neYL9qYrvLMMjseOyHg81UvQz4HL76UXDFejeyupBXhLKtG7Jqu/uDvwmf58AruBoQOwGqtIU29GaJkIXQ4OWV/Ad/m+f9Yy2vMjEZOHIngGgYMwWCaEHRdz9QQCNla/nykKbwvzrBhOEU= 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.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="PZyEkekn" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e32ff6f578eso1365999276.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=B8sLQGN38U4rflA3yu9krMamL+Ur6q4Dq0CPoJKSwMbnjaZDT2Q8LxEqQYLBGfLgb/ gee/PYajnC5Xkgb1RGIlzn6bLJeSkju436iu1CeXnzCnniql8XXpaEn9l2l84wubjc1W jjlmA/hebQrCoeZKWAkMOLP+FvOP/G/bBrRKGYTMBhHYtnS7z8laUXkZ49w+MnNaVOa7 zh7FmhmaGzjs0h93UxJTcOdSj5wWgY8qfw3n3T3AlvQwEV2O94n7kSaqcmCnjtpU99iy M3sS5l4x/G4yYjTqqJJ60Y+5PmQOkYwaZf6AJ17Jnz1wCALhkb/G83TcBvzd4H2vlI+6 2LxA== X-Gm-Message-State: AOJu0YwrKU7K7VhLmoPQBRxXuTvvUgs0ePz2WhFp18cGsAKIi4GD2zlf k5UFv0JZm3/HSOrrTA1KIvAmpm6LRg4KCeTex+wwsuihkojExF+MsaRAwTn+QxaJrmZMyswHH0S +rhR3EaKYXe7hkkHe3QmGJHsFZsI3s/XunX7tKFYGO0ZQXth+xttPxSKNqCBNZ6fadONqhWHD5Y R4SUesRpngIecim+AW8HronaDhBUgKVFNj3sXHEpqfNMnswKImP964yEg= 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: kvm@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 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 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/perf_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 #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 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_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 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) 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); } 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); -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_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 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