From patchwork Wed Sep 11 22:24:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13801167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04ABCEE57DB for ; Wed, 11 Sep 2024 22:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=98KHHfZAU1dotPbU8K3avps0YbHY8rCmN7CSHv68LAQ=; b=NuqWN+zshtgwg0nXqD+AvwIt4V gqLSf2mbl+aa8L0Fetix8MgpnocSKCY3dvdf+nJJYZYhe8zXCikxsxJhbKBngb2gv5iw07nw2Ty1i ZNBlQYOvJQctQ+PwVelcb0UBqTZMhMcamDDe4sdTNX0dLBpG0ScC4BC4YaE+oHxbeQ3cmT/kYi/+k kiI5Ket3GOJlw1jFUEWT+lidjFsSbh+zmGdkwJJlFkfhNOi6xIye9oBebezSaTM6tKT2/SbRnMPOM Lx4mQh/e6y12YLoDxAMqynuEwXlIhGYWa5vvuGOx1Jj980WGsHjQ+tf4NxaZPlgtrG3bib/ru7xtB X8tzlWkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVo3-0000000BBcr-2YBP; Wed, 11 Sep 2024 22:27:23 +0000 Received: from mail-il1-x149.google.com ([2607:f8b0:4864:20::149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVlv-0000000BAyB-3M0U for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 22:25:13 +0000 Received: by mail-il1-x149.google.com with SMTP id e9e14a558f8ab-3a050af2717so7248205ab.0 for ; Wed, 11 Sep 2024 15:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093510; x=1726698310; darn=lists.infradead.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=98KHHfZAU1dotPbU8K3avps0YbHY8rCmN7CSHv68LAQ=; b=jb7IHP16DE/EcWiACuyCB5mgm99rEqzG7sfUBQZT+aaV9Rbl6nE1w4h1t4dHCsL3jW 46au2MvrVCIAz44ADcUx61r9jC7f5JRjXuW6ljJb2w1D4RVPp14xpyUtcQE677DRXOKc nNh0+N1qV8GCCGmvFKWg3e7iAU01LM2TqZaKurJOtgefJxZVLHlaLweRd6FtABl4ghRY rUl3g14ZGa7JR1Tc9P6xEt166nvEBXdzhalI8KyyaAOeEhUZXDPqcAvL0EeLKuQso1YS TDAK8pIDFdShUmxS6+zkjzistsclKFQwXReeoAGFAUATPd1rzRkk6CeLQsC9TikuclPV umZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093510; x=1726698310; 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=98KHHfZAU1dotPbU8K3avps0YbHY8rCmN7CSHv68LAQ=; b=jFxBDRkNTr3Wiwa6/UCS1NlHiEmn5j9v4+oo6qLILF0FCuuM32zEE9feN6TWaG54If y7nceHbNpfoGwDXoxQ8SbiGHQVVjZTiStCXqqOm/nfeDXiJtkH4DxSG3B3udFupsacy8 aar9CSkxJCldxjX7H8+hHDA56AWGSjlWVxJ0AxKwXz6XBUREUToszznjeSwKm3HNZRiw 6U7ufej987SNKv8gbUfBX1tEh29nXhARkxbXIwdQuJ11qD/6/WcxkIbuzgVWYkxHh4JN +L7hpYfBQphqa7bvFxC2kTN7gqwITMCD3vfxM7YUbZM23Hy5+8mS1gwUn1pC51sfM75K yhbg== X-Forwarded-Encrypted: i=1; AJvYcCUwtG5Z86ttLR6kvFFGZZmHp+aUv37T+ITbwCwx6+CGMFv9K3SO6KL6O7Tuw9IPziVZpyDZVD8zgDxVy6FMDwoh@lists.infradead.org X-Gm-Message-State: AOJu0YxGGfMuSkHl7cdr78EAhRIwZAuah/A7eiBHVEU0xZWG8DTMejoS EySHnmFgcmB/d6faGEyyCzzKEqHrVLLWdv/x1lfW+yNi6F9J89Bc5sCW9/9oRAkwPZUSyrTH5rP a39gbEQtN3B/uz+vSth0oQw== X-Google-Smtp-Source: AGHT+IHezO/FS6DrvjzqydPLEapvMWYoVJd9AX1NthmyW6WKSgM57sEvRhPyRtAfj2mQLXNB4v5VRUm4UvpIqG0BYA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6e02:1c48:b0:39f:549d:e39d with SMTP id e9e14a558f8ab-3a084967570mr302085ab.5.1726093510446; Wed, 11 Sep 2024 15:25:10 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:28 +0000 In-Reply-To: <20240911222433.3415301-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-2-coltonlewis@google.com> Subject: [PATCH v2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_152511_863043_E68FFB53 X-CRM114-Status: GOOD ( 11.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- arch/arm/include/asm/perf_event.h | 7 ------- arch/arm/kernel/perf_callchain.c | 17 ----------------- 2 files changed, 24 deletions(-) -- 2.46.0.598.g6f2099f65c-goog diff --git a/arch/arm/include/asm/perf_event.h b/arch/arm/include/asm/perf_event.h index bdbc1e590891..c08f16f2e243 100644 --- a/arch/arm/include/asm/perf_event.h +++ b/arch/arm/include/asm/perf_event.h @@ -8,13 +8,6 @@ #ifndef __ARM_PERF_EVENT_H__ #define __ARM_PERF_EVENT_H__ -#ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) -#endif - #define perf_arch_fetch_caller_regs(regs, __ip) { \ (regs)->ARM_pc = (__ip); \ frame_pointer((regs)) = (unsigned long) __builtin_frame_address(0); \ diff --git a/arch/arm/kernel/perf_callchain.c b/arch/arm/kernel/perf_callchain.c index 1d230ac9d0eb..a2601b1ef318 100644 --- a/arch/arm/kernel/perf_callchain.c +++ b/arch/arm/kernel/perf_callchain.c @@ -96,20 +96,3 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re arm_get_current_stackframe(regs, &fr); walk_stackframe(&fr, callchain_trace, entry); } - -unsigned long perf_instruction_pointer(struct pt_regs *regs) -{ - return instruction_pointer(regs); -} - -unsigned long perf_misc_flags(struct pt_regs *regs) -{ - int misc = 0; - - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - - return misc; -} From patchwork Wed Sep 11 22:24:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13801168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E07CBEE57DB for ; Wed, 11 Sep 2024 22:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=crmhw2mLEZ3+RGHHnhBbhpz6G/wxlsr9F/cDgMbCNx0=; b=QONc8Er5a1hotZr5ewy8zhicnC eRIuFUS/2pOahnmBUbJqtuWRqKO540JqyAN11WWtS4XlBSEq1mGcskuACNvK4mveVpFXXNeZWe3PY eTsyYJynBPUlbg/bGR/Xfswi5s5cXuoqjTvaRLux2CaVjqL/kUKmogJdzNjpSuEZCB1DCTW3JweLQ Xn7k8qY8t9hSUeMOulK/peUs9r9uJemB/0Acol+wpJsLOZvQqRPk76NneM0gH/vYY9qxJTiyQFilv PJSMGai37KwZacUc10NLN4emgQ8dcaDgf8jvScBQ5JDAM9rTR1nKvGbfkfRzQjjRa9ThD681cnulv mCfPXE1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVp4-0000000BBpS-43tj; Wed, 11 Sep 2024 22:28:26 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVlx-0000000BAyl-13t0 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 22:25:14 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6d4bd76f5a8so17941757b3.0 for ; Wed, 11 Sep 2024 15:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093511; x=1726698311; darn=lists.infradead.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=crmhw2mLEZ3+RGHHnhBbhpz6G/wxlsr9F/cDgMbCNx0=; b=NPXp7KP2pf9xH9mQ2qr+Dd1jOTVIhDIDQqHixlSM08wuizCcOyutSxIT+Dz95JVDvg TELzpVj0lM0pvGHuOk1+wtAHd85dhXEkw/QrRMzQ31lxpeTUXyg589m1Y0thR1e9nnhb GRPCrfmRpAoyCdXGJrrNLoAsUtesUoZVfSZ9UEP3xldJLaBM854kuKBxvO6weDXF6e6U bc6GGMKsIwQEgF0izZKHeNdpnI6qO7UaoXWhWm8KMCh9S4vSojuwL4AK0VpT5im1RMwj OMSZCHniBh5ijpZC8MH7tEORaUSrAngot1Im4h2DpVbKKm9QWImO5btDtz4nc5FVphEy nYmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093511; x=1726698311; 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=crmhw2mLEZ3+RGHHnhBbhpz6G/wxlsr9F/cDgMbCNx0=; b=bNcf8g13kcusuCigqxiESBeINOFiLwrGAFLMsKuIEZ1AvK+gwyV+bjynf4yjz0Ermf CoAqtpOxTDsM8xZCk/oyjJ5GAepsNvM/fsrT92LtL7pmWQLdyRBk/xECDQvaeGej5Olh Y3PrpzLNL3mIuGuT47MWyGPvlbL2CDoBAZJ+uti/xzSvI0WRJDZHjetdLpL7Zj7ZAEsi HODP8oljpCrpm6tPvfOpNbFCXLWf7Zb3fvipSJD9vJWIUhSWhBQR5XS4RTl3Fybg134j lesBmpoOJFgoCMR54UQ96sBAaviadKNNqUAM/IQyBCcvbt9Ya9TlmlChbC/xUJCw6B8L fnkg== X-Forwarded-Encrypted: i=1; AJvYcCVDma6ElVNX9MApnm5/2VAEGIeDHVZBeZQPApbu6H44B45kEJZlWwCCCuzF8GhGwq6W6DuN4DcAIBP3w7LWB+cb@lists.infradead.org X-Gm-Message-State: AOJu0YwWp37RUh9s2yPqR7Hj7CpPgE8nr7/4ASZsVsX9ALiC2ILsbF2Y EFhjVPb4bQcdFBoczFkzDTdmkZfV5bylKFn2FmzokVLEbpbkMZf4kvUoT6oN9080g/7nGKPq8iT 4SmQ4gqIRCD0FoLBVGrxAPg== X-Google-Smtp-Source: AGHT+IG/kcNrSc00DiV0Ogd+lp7Te7joIo9TjDes3ay3ZaxS7IQuZ1/VH3N+WObF+/ClPQF8BfSZxNsumtK7iHDYfg== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:6c8f:b0:6ad:e9c1:fc4f with SMTP id 00721157ae682-6dbb6b8c62bmr380167b3.5.1726093511584; Wed, 11 Sep 2024 15:25:11 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:29 +0000 In-Reply-To: <20240911222433.3415301-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-3-coltonlewis@google.com> Subject: [PATCH v2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_152513_323215_FC6B8D46 X-CRM114-Status: GOOD ( 20.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- arch/arm64/include/asm/perf_event.h | 6 +++--- arch/arm64/kernel/perf_callchain.c | 4 ++-- arch/powerpc/include/asm/perf_event_server.h | 6 +++--- arch/powerpc/perf/core-book3s.c | 4 ++-- arch/s390/include/asm/perf_event.h | 6 +++--- arch/s390/kernel/perf_event.c | 4 ++-- arch/x86/events/core.c | 4 ++-- arch/x86/include/asm/perf_event.h | 10 +++++----- include/linux/perf_event.h | 9 ++++++--- kernel/events/core.c | 10 ++++++++++ 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h index eb7071c9eb34..31a5584ed423 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -11,9 +11,9 @@ #ifdef CONFIG_PERF_EVENTS struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index e8ed5673f481..01a9d08fc009 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -39,7 +39,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, arch_stack_walk(callchain_trace, entry, current, regs); } -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { if (perf_guest_state()) return perf_guest_get_ip(); @@ -47,7 +47,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs) return instruction_pointer(regs); } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); int misc = 0; diff --git a/arch/powerpc/include/asm/perf_event_server.h b/arch/powerpc/include/asm/perf_event_server.h index 5995614e9062..41587d3f8446 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_misc_flags(regs) #endif /* diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c index 42867469752d..dc01aa604cc1 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2332,7 +2332,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, * Called from generic code to get the misc flags (i.e. processor mode) * for an event_id. */ -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { u32 flags = perf_get_misc_flags(regs); @@ -2346,7 +2346,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs) * Called from generic code to get the instruction pointer * for an event_id. */ -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { unsigned long siar = mfspr(SPRN_SIAR); diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/perf_event.h index 9917e2717b2b..f2d83289ec7a 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_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs /* Perf pt_regs extension for sample-data-entry indicators */ diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c index 5fff629b1a89..f9000ab49f4a 100644 --- a/arch/s390/kernel/perf_event.c +++ b/arch/s390/kernel/perf_event.c @@ -57,7 +57,7 @@ static unsigned long instruction_pointer_guest(struct pt_regs *regs) return sie_block(regs)->gpsw.addr; } -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { return is_in_guest(regs) ? instruction_pointer_guest(regs) : instruction_pointer(regs); @@ -84,7 +84,7 @@ static unsigned long perf_misc_flags_sf(struct pt_regs *regs) return flags; } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { /* Check if the cpum_sf PMU has created the pt_regs structure. * In this case, perf misc flags can be easily extracted. Otherwise, diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index be01823b1bb4..760ad067527c 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2940,7 +2940,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(); @@ -2948,7 +2948,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs) return regs->ip + code_segment_base(regs); } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); int misc = 0; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 91b73571412f..feb87bf3d2e9 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -536,15 +536,15 @@ struct x86_perf_regs { u64 *xmm_regs; }; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) #include /* - * We abuse bit 3 from flags to pass exact information, see perf_misc_flags - * and the comment with PERF_EFLAGS_EXACT. + * We abuse bit 3 from flags to pass exact information, see + * perf_arch_misc_flags() and the comment with PERF_EFLAGS_EXACT. */ #define perf_arch_fetch_caller_regs(regs, __ip) { \ (regs)->ip = (__ip); \ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 1a8942277dda..d061e327ad54 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1633,10 +1633,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 8a6c6bbcd658..eeabbf791a8c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6921,6 +6921,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 Sep 11 22:24:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13801169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E0B7EE57D7 for ; Wed, 11 Sep 2024 22:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=l4XmBjdboaUqTeMgRqbSdf4DSeJIVFEq/lNcpwN1ftE=; b=TD/pUz1KMngoZmBBUHGCWosAs1 GjFjdCOBtMI/fFJdyeKM5YLD8rTReNYTMC39Puuram+GbKti9Vi2OMB86yEby1lqO2SkxKH3q4jRy CgObpXiMhQX7CRcTTtQI6LTK2Om9kfvh/1drFdcXsv4bigrbLJ/mDQ+CbBTyO7gy+hQviOEL7B0z8 5zAbLVhcNQvIlVCH5G9/7K8opRHIFWZIorDWbgBYocfo3gYlfkC6AWcZmQSaZsczJskJDOVziaQN4 XCH7RvCbb+7p4TEXjL5HzDpbUDaK9oM6qXytCuCzJhR3HyXdIUzb/FC/uOl7MFAY4BLWV7I8IteU6 eOFIdG2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVq6-0000000BBw5-1oJZ; Wed, 11 Sep 2024 22:29:30 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVly-0000000BAzK-1Ejs for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 22:25:15 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6db791c42e3so13133167b3.1 for ; Wed, 11 Sep 2024 15:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093513; x=1726698313; darn=lists.infradead.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=l4XmBjdboaUqTeMgRqbSdf4DSeJIVFEq/lNcpwN1ftE=; b=3a0r4TncWKJnZ4v2+gQT6NdDmmVLuaPWe4tOIaT2l1SFUt6HINbDA5gtq1ME69mmxW kmpVJCoCzMJcowB2KBiAm7tr9GACYvAqv/NuKA6DTJXZyKmmHKb9oFoMDQk/5dKyuC8d dOHQto4AYStFpFEaqOS+pZ1Rq8eKcuhEpz4AA2pCD087CPAxLHnxXzgaMyLFe4by9sS5 kGLp7VqFnoe6qM23dagC/HdGtJODymVRhOavLC2WSG1JPH76XbYc6sJCNwGqWQJz0Mi4 S/ee6sZant6Jh86XXGnUsxC2El77HEzwSUyJjLe/1AAgL5ihk3J/Xj5+e3nkJqU1U3YH qRkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093513; x=1726698313; 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=l4XmBjdboaUqTeMgRqbSdf4DSeJIVFEq/lNcpwN1ftE=; b=RD2E4jEzBwEWVfO8Xb/AfyeTOTTUnv9Nyzr5ZYjuCVx9VcH2nmH/K/XD3zLk2EDGXA 3whec/BGKlbE6Xogrw9PnLoGv1lArs9+cSMV/sabRNeoEqJvyUofYVVrwKrs6iC826qL j23o2ABitfiTybPcrMEEw9OX4ex861bjDiNZDmJ/6IhJpsijV0YnSv5+9/mntZAVTd46 fYRr3CWkC+aGYD93j/CIMwhdVBjdYp+7Ns5UcHZkYIh4h5T7SWPVxYG6TFLjXjE61AXY jgqh1acyDEjy7PqPPZp0NxN9HR5LaJP3Z8tNqTvRWnSHksefqaKbgJheb2d6kzq3+hKr Xofw== X-Forwarded-Encrypted: i=1; AJvYcCVKY9q9Z9rZlA+byGaWd5w5ZKtA5Pjcuf0AJJMtKeYFCZ7sWsr5tuRiFxbq3AZC5dB1ZwjoO13Np/qTRh/i//S6@lists.infradead.org X-Gm-Message-State: AOJu0YyZIzjICKGy2q8vEZ6CoWmuG+WkZ4RCJCbZ4IvnkD02iTRwL8XB FwhGpHo4QvwJZCnVhhjsnN4bCveN7tL1OwVbcY8QP2TSTdBTne5BObUXxkfPCennKsIy3ho5zRO A8wrb4bBFf/UgkpN0dU41hA== X-Google-Smtp-Source: AGHT+IHahPlfxq0OnDlBxbNh4kFfba2/NbBP9j+SjDxLZau6fx+NZ8cgucf9q6YqSrrkRp98eVZcQ/vy+HEi7ntE2A== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:6083:b0:6c3:e9e5:e6a with SMTP id 00721157ae682-6dbb6ba1041mr322647b3.8.1726093512763; Wed, 11 Sep 2024 15:25:12 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:30 +0000 In-Reply-To: <20240911222433.3415301-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-4-coltonlewis@google.com> Subject: [PATCH v2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_152514_384698_354AB28D X-CRM114-Status: GOOD ( 13.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make sure powerpc uses the arch-specific function now that those have been reorganized. Signed-off-by: Colton Lewis --- arch/powerpc/perf/callchain.c | 2 +- arch/powerpc/perf/callchain_32.c | 2 +- arch/powerpc/perf/callchain_64.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c index 6b4434dd0ff3..26aa26482c9a 100644 --- a/arch/powerpc/perf/callchain.c +++ b/arch/powerpc/perf/callchain.c @@ -51,7 +51,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re lr = regs->link; sp = regs->gpr[1]; - perf_callchain_store(entry, perf_instruction_pointer(regs)); + perf_callchain_store(entry, perf_arch_instruction_pointer(regs)); if (!validate_sp(sp, current)) return; diff --git a/arch/powerpc/perf/callchain_32.c b/arch/powerpc/perf/callchain_32.c index ea8cfe3806dc..ddcc2d8aa64a 100644 --- a/arch/powerpc/perf/callchain_32.c +++ b/arch/powerpc/perf/callchain_32.c @@ -139,7 +139,7 @@ void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry, long level = 0; unsigned int __user *fp, *uregs; - next_ip = perf_instruction_pointer(regs); + next_ip = perf_arch_instruction_pointer(regs); lr = regs->link; sp = regs->gpr[1]; perf_callchain_store(entry, next_ip); diff --git a/arch/powerpc/perf/callchain_64.c b/arch/powerpc/perf/callchain_64.c index 488e8a21a11e..115d1c105e8a 100644 --- a/arch/powerpc/perf/callchain_64.c +++ b/arch/powerpc/perf/callchain_64.c @@ -74,7 +74,7 @@ void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry, struct signal_frame_64 __user *sigframe; unsigned long __user *fp, *uregs; - next_ip = perf_instruction_pointer(regs); + next_ip = perf_arch_instruction_pointer(regs); lr = regs->link; sp = regs->gpr[1]; perf_callchain_store(entry, next_ip); From patchwork Wed Sep 11 22:24:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13801170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC4F5EE57D7 for ; Wed, 11 Sep 2024 22:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qY7jazBJP8pJhg0f/dQ9sIJIXrzux0tRJtWLf7xpCl4=; b=k44HnBgQMKHSeoZN+Ioe0vBE+u 1sqfTF9Dekt82gGU/DdYiA5Y/s0cRj4fTbOV/sBK53m7hSY1z0tgUIpCOTRUV/1c5zWk6I+9E40zD YzW3NG+IsixgqqUuR2n+CxThMZuAXUoq1i6NxYpzG/t6peEFIUpJWFpEdTpPpERSN0Psk/xQ0ZSzj byXjhJ9KFBO/eWGzoMbugH/eH2LoDFGbN63QMM9dQEL/76z1h0f3Q3YBiHmzPillgctTaEbPYLpDF YNQtDmaPO5TQvEzpHvP6R+iDUxTJ2YxUrSJ3uDyo6DsI8WRun3jpqRZVQSbZUuyvb18xBYQXEso/4 e+yi4Hmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVr6-0000000BC5k-2uWZ; Wed, 11 Sep 2024 22:30:32 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVlz-0000000BB00-1eRE for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 22:25:16 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e0b3d35ccfbso727918276.3 for ; Wed, 11 Sep 2024 15:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093514; x=1726698314; darn=lists.infradead.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=qY7jazBJP8pJhg0f/dQ9sIJIXrzux0tRJtWLf7xpCl4=; b=AFX0DJkMWUcNdRGXS2B2mk321K6YozTyIfIfqm9upOK9f1leBw8OcsGuUKnh8d9+rX kxvZ7z7anoHQK8vcKzIrTsp93ln/e6ZuH28XUw8OGMmo2lXae5nf44pVsU89aQ1vaieT rQcfJDc/zOMaRsi3vb4SktM44sKoerYtL4uT+JfC7gAxEYX8LND1ixsa6dIMlH3JuC9L /2D4WRyfJJatelz7VpUjEVfhLdW+/dGoO0DWJpYKqXuLHO2Ylumbal48EhjKmeriwI6p at2LjRCAVikAjPFz2op47IqUo0tUeIQp5/3qR1EZSrGU5N+a1Dj0n5s0LT6XMnUGBJE0 tjPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093514; x=1726698314; 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=qY7jazBJP8pJhg0f/dQ9sIJIXrzux0tRJtWLf7xpCl4=; b=uVb4i83AliCwhpCNm7o5znHpJaHD/ynvD8FvJ5xZUvc43dbh0WbZImZs6qfmR5PYgE msYryh5FlLiJCDwINVT02iNEWVcqy8WT3OTK12hBHtagnxrLn9iq0nKer0j6sztIW2XU 8xrRpk502xWL4gElxQxrC+T1U18017dmPSkW3BTJUYOIjS/7DcvqhgYXS1FFiLX0UlWv Tq/M0BzhNDVrhKeq/WJgMOwXuCENGZyHN0gnTLqdataJ4eiB5k9SZP0lhtF6C/GMm77B CNEgd29T/0z6rwx4FWaa8TfYeluiqjElrdmdZwEGeh9lof+0xgQfDplUcrV3KZG5LeJX cm4A== X-Forwarded-Encrypted: i=1; AJvYcCXypIvUoapcs4YnQEXRrbM6/TNoonNw27e685TNBQyhcCm2DP+bsWZyf6Do/eHrWB+tMWDtbwyq9NNGYddQ5IvI@lists.infradead.org X-Gm-Message-State: AOJu0Yy+FyZzwO7w/SKQyafwK8nsj7j0dd3dTdYKCIE1fyC4HuxgUmML CqK0CwzVEBBK2nPgFD0Zqv9k0FnXsYlNDZY92WUqWTk7oruHLNbtSoSOv8m5aNTkVJA7xK+j+EI iD3hnHyFlIf46YsjMYpe7cA== X-Google-Smtp-Source: AGHT+IEJ4qXFa/RnEyqgs+UMl0d9RUxwmlrJg7JrBYtR4wSiyNcS6y1wcbWXE0ormIQyuX+hDspZQAPbFzn+ORG1EA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:27c1:b0:e1a:22d5:d9eb with SMTP id 3f1490d57ef6-e1d9db894c5mr1072276.1.1726093513931; Wed, 11 Sep 2024 15:25:13 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:31 +0000 In-Reply-To: <20240911222433.3415301-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-5-coltonlewis@google.com> Subject: [PATCH v2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_152515_456519_79075292 X-CRM114-Status: GOOD ( 15.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- arch/x86/events/core.c | 31 +++++++++++++++++++++++-------- arch/x86/include/asm/perf_event.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 760ad067527c..d51e5d24802b 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2948,16 +2948,34 @@ unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) return regs->ip + code_segment_base(regs); } +static unsigned long common_misc_flags(struct pt_regs *regs) +{ + if (regs->flags & PERF_EFLAGS_EXACT) + return PERF_RECORD_MISC_EXACT_IP; + + return 0; +} + +unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state = perf_guest_state(); + unsigned long flags = common_misc_flags(regs); + + if (guest_state & PERF_GUEST_USER) + flags |= PERF_RECORD_MISC_GUEST_USER; + else if (guest_state & PERF_GUEST_ACTIVE) + flags |= PERF_RECORD_MISC_GUEST_KERNEL; + + return flags; +} + unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); - int misc = 0; + unsigned long misc = common_misc_flags(regs); if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; + misc |= perf_arch_guest_misc_flags(regs); } else { if (user_mode(regs)) misc |= PERF_RECORD_MISC_USER; @@ -2965,9 +2983,6 @@ unsigned long perf_arch_misc_flags(struct pt_regs *regs) misc |= PERF_RECORD_MISC_KERNEL; } - if (regs->flags & PERF_EFLAGS_EXACT) - misc |= PERF_RECORD_MISC_EXACT_IP; - return misc; } diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index feb87bf3d2e9..d95f902acc52 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -538,7 +538,9 @@ struct x86_perf_regs { extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +extern unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs); #define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) +#define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs) #include From patchwork Wed Sep 11 22:24:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13801171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D521EE57D7 for ; Wed, 11 Sep 2024 22:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=anqmPTOCFLWtYH4INX466EMjOxNIdwCN/nyhNcnm/nY=; b=oVJZXy6oKf23Y5hP1bXbbdcEF4 H8ss7+jxirKaC6t96MdJOpKp5JEvU1EOOcsUgWWBPhheiT6oBffjHp3h6Bz1SXbtumpNiXmbss4WN k1HZJA7fXrJo1nAiThU7Mig31Kbjkf+KX4Zv0i1ZibmVJ4kwi2T9uOH83BuvnsCETtKF78OXgAueL tiPk79/rXSVcUysfoNVoQO1JL1KWuxLQVINhIf8PxBrCW8wpvuVVFgaXSiqvJ1G7RVZVamSTWam2F dXOq/tA5IlOAjAHj6vMEFNfg9EV/J8q4fg7MPxPpHDF+tlrghc7YwxtOyfD1JjN3PgvmgLIg9G/c0 9uBSvmwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVs8-0000000BCLs-0vdT; Wed, 11 Sep 2024 22:31:36 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soVm1-0000000BB0d-0DMg for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 22:25:18 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e035949cc4eso883450276.1 for ; Wed, 11 Sep 2024 15:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093515; x=1726698315; darn=lists.infradead.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=anqmPTOCFLWtYH4INX466EMjOxNIdwCN/nyhNcnm/nY=; b=toiFve6iAEbhOp76daNtj7vXyp8hcSY7ypICacUZvKpdKPodbyz4hhdhE+Vee0DRfI qLQv5eDcqHPnsP3U5JHQ5LZWhAEpqsnn4OiFX7z1mxqu5/LcAPHgTfkKBvJm2Jx5l+bF 9xpI1xB0BGwnwkmy1nEnGmzvMsOz4g2or3O0j1ozzajaERKSnMKOhSrsjm/W5sifHGbl AQSfGS7Q29i6pBFdpokVmw9qUdjKkuHuNAkMyRTRZQvbfz3K4//3igWjj1e4J5iQHQr8 VzD7+qHaea0zsV0nlf+mQFba4ntp9bfGRQkS05mqnQNBBAiLADQax4cNrLQbwp8iJ/5t 98Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093515; x=1726698315; 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=anqmPTOCFLWtYH4INX466EMjOxNIdwCN/nyhNcnm/nY=; b=I0UC+aKYW/YLAWqRNhaE83VfJL0FCdlUi90UURp9Bo/OK0xeRVDTQ/RTYhhWznW2qf XeFnoHLqUaJ+c32RMpu9zrPRufx7nt6ummJr8rwny6mg+u5NnpedpEEwqWlYx3R6/1bS dErfGfqUcZLB4XnQKpgEKM8/VeTBmkfuDdRlQLodBf4jbIHRkp8sDnqh7w/xUMac3c/0 hwOQtCQzajOzrp00xB5djNRzRE/sjAPPg8/6XZLHOpwre8wvwYiW1uklpiKdjst/rxc3 JiWNcIr6FUMXe6hsUyC9NuzXjy3n/AjjliH3DoJtiqOxVtfaOvc06aP2CDa/uH3uS5KD IkQg== X-Forwarded-Encrypted: i=1; AJvYcCUr6LGJr9Oc+dbqa0q3dYAk8wUMd6PyH0F4wacYVEgRryPvyd4vH/nVXiP11zLECfZ17efR7XoCknsnzldZWIMh@lists.infradead.org X-Gm-Message-State: AOJu0Yw0+drnM8XpXpunN/pC3YE7+j1dgARbKIAeVQgm3bZZ9o7rtF7d xdZi2csR2yKoBwFwFnltdxzmCgKtigVMDK+XZvwSIq95YarzmLcEQ/3EASHZzqkVgid5+0W2Wm7 2qhRTVnI1iC7DcT0WIHtLGQ== X-Google-Smtp-Source: AGHT+IG/v34+rc6eLaOGVWlOE43Zx45msmHQv1J2ivFD+GxJdG/Q3VFoefy68ei4cpHyCypXn3PaKYm2Ons1cxS0+w== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a25:e812:0:b0:e16:51f9:59da with SMTP id 3f1490d57ef6-e1d9dc1b42emr3306276.6.1726093515114; Wed, 11 Sep 2024 15:25:15 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:32 +0000 In-Reply-To: <20240911222433.3415301-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-6-coltonlewis@google.com> Subject: [PATCH v2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_152517_145918_E018CA2D X-CRM114-Status: GOOD ( 19.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 clear. This way any host-only events with exclude_guest set will never see unexpected guest samples. The behaviour of events with exclude_guest clear is unchanged. Signed-off-by: Colton Lewis --- arch/arm64/include/asm/perf_event.h | 4 ---- arch/arm64/kernel/perf_callchain.c | 28 ---------------------------- arch/x86/events/core.c | 15 ++++----------- include/linux/perf_event.h | 21 +++++++++++++++++++-- kernel/events/core.c | 21 +++++++++++++++++---- 5 files changed, 40 insertions(+), 49 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h index 31a5584ed423..ee45b4e77347 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -10,10 +10,6 @@ #include #ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); -#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index 01a9d08fc009..9b7f26b128b5 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -38,31 +38,3 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, arch_stack_walk(callchain_trace, entry, current, regs); } - -unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) -{ - if (perf_guest_state()) - return perf_guest_get_ip(); - - return instruction_pointer(regs); -} - -unsigned long perf_arch_misc_flags(struct pt_regs *regs) -{ - unsigned int guest_state = perf_guest_state(); - int misc = 0; - - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } - - return misc; -} diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index d51e5d24802b..5f119b9516dc 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2942,9 +2942,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); } @@ -2974,14 +2971,10 @@ unsigned long perf_arch_misc_flags(struct pt_regs *regs) unsigned int guest_state = perf_guest_state(); unsigned long misc = common_misc_flags(regs); - if (guest_state) { - misc |= perf_arch_guest_misc_flags(regs); - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } + if (user_mode(regs)) + misc |= PERF_RECORD_MISC_USER; + else + misc |= PERF_RECORD_MISC_KERNEL; return misc; } diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index d061e327ad54..968f3edd95e4 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1633,8 +1633,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) \ @@ -1645,6 +1646,22 @@ extern unsigned long perf_instruction_pointer(struct pt_regs *regs); # define perf_arch_bpf_user_pt_regs(regs) regs #endif +#ifndef perf_arch_guest_misc_flags +static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state = perf_guest_state(); + + if (guest_state & PERF_GUEST_USER) + return PERF_RECORD_MISC_GUEST_USER; + + if (guest_state & PERF_GUEST_ACTIVE) + return PERF_RECORD_MISC_GUEST_KERNEL; + + return 0; +} +# define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs) +#endif + static inline bool has_branch_stack(struct perf_event *event) { return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK; diff --git a/kernel/events/core.c b/kernel/events/core.c index eeabbf791a8c..c5e57c024d9a 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6921,13 +6921,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); } @@ -7743,7 +7756,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; } @@ -7907,7 +7920,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