From patchwork Thu Sep 19 19:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13807962 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 40278CF3963 for ; Thu, 19 Sep 2024 19:10: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=1u8+tIRQu1/+Yzznd3YfSwPNzKiT5HV8vjSuz+hJEoI=; b=N35t/OCOTILEtxU7jeJz1fqa5D W6MOM1uHw1EHtrbNVW21S2s4qFpMQIRZg7rHgXPWOJKMqWlIhWBapuOSENaXwBs7Sx0hq/K+it1A/ mcASNcEtXGeNP4G7jHylB+6dPHUv1SRbaXm5MaUv+Mh7CZxi2IrvaauJ7BJY0/uL0eXxnWePGkzZu wkjg7W2JdcDmUWX2YBwjNbYmGOPNSVy2o5EVkwzgaVIrzMC6F8mg3OdD37bsEaam82RfN5Q81mV0M enQV6XMfa4SHE5SLjHh38NKJnB74HUSQ4zNJFJ1FLZWFsluLbSESttNtN2dKNkJMiExxxOjtiJJPl dZ2TqAvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srMXp-0000000AtKC-1Spr; Thu, 19 Sep 2024 19:10:25 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srMVZ-0000000Ashp-3Y4A for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 19:08:07 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ddcf7599ddso18953487b3.1 for ; Thu, 19 Sep 2024 12:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726772884; x=1727377684; 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=1u8+tIRQu1/+Yzznd3YfSwPNzKiT5HV8vjSuz+hJEoI=; b=ZR4rtVGvx1CVyR07q6SvHFpB7T4RHrnGQywG2Gv2fhT00b/45NHrCNBdbUNCCenPSz tAgXzRIOpThTKcGKOJD2ArKiECyJDk7f2lvKniD6Ddk2dV+N2dvPG6TmXeVgYAqviSE1 lP8QtysWoCo1ZG2rYbmIlv7J9bFJv2bbCmC2FjNdLDKs3NyRPfBf7E+CncSLOtt9N2pC sgHML3X9CAfhQkEcOg9cXzMW37T65VGFtmx3+75JmEWb1eFksqhOV5W0OwzNcxnxWgWz nbjDNeu3zPIlHlgAMChCavPsy1f4ZnzQ1K0bIqJC7t+luLqkDFrQMruXV/Ib7w0wOtxM bAvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726772884; x=1727377684; 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=1u8+tIRQu1/+Yzznd3YfSwPNzKiT5HV8vjSuz+hJEoI=; b=Dfx6auzav8SiMieas8gayiAGkXVgRM5D6e+9ASSsfH32pGzPMCS2FSzSvkm26l6324 23dZqRB4/L+3E//axnLNjzca+NKHftSU4B9mbjwcuSakJ9z6QM/40ORezl7USO2gJxcI xh09tHRGof2+gFaAo7eLN9x7wsluRVmYwGa+LXG+VmrGxbdis8m4UdngrDThFz6fvY3Y FK08g+K4GCQPC62/vjaMuUn3r9ZqV8rUB+hFJUvI2j+Qw/OMlfVjrdDQj0rdixBC8JnE T531r5PwYZnM2WBXA8tIdPodmWawVP+uo2Y20ZIpkjRvDiN3/7L8mnGgTq6xIWpFNEK5 67xg== X-Forwarded-Encrypted: i=1; AJvYcCWjb62jvy4+vhnF0P2xbSMkjTApEw2YduIPQ5RFlrt8HIz9Ek6kQQuqrobqMXvsKJXbt14IfequwIB+YQquPs8L@lists.infradead.org X-Gm-Message-State: AOJu0YzsaFEEfHaln1EyH2/nln1M76Q/9I6TyZ0ilO4jTqUa5fs6O3mk eGiWDQM09R1GyHFxSG4DkuFravs+rXS9/oJeHzQB4sivzU00Ju+XUQ7tpCgyhnju73n+Y/KwWvs KCvmnFcRlLGd8oFfWw0KRTg== X-Google-Smtp-Source: AGHT+IGDiKrctQsFm0erPBgmwBCKnufFRGsSs3qB+YNCGyJVR/2h6144NBut+d+5hRqNGNQ/pKN4LdcbFv0AmZEt/Q== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a81:a88a:0:b0:6db:c6eb:bae9 with SMTP id 00721157ae682-6dfeed1dec3mr31057b3.2.1726772884551; Thu, 19 Sep 2024 12:08:04 -0700 (PDT) Date: Thu, 19 Sep 2024 19:07:46 +0000 In-Reply-To: <20240919190750.4163977-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240919190750.4163977-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240919190750.4163977-2-coltonlewis@google.com> Subject: [PATCH v4 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-20240919_120805_906999_7B50483F X-CRM114-Status: GOOD ( 12.20 ) 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(-) 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 Thu Sep 19 19:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13807964 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 73C1BCF3962 for ; Thu, 19 Sep 2024 19:12:50 +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=PI01NOAwUBTbTYBhGD7vAZyLVwWtrbZIdss2qywEk8I=; b=JDywywzOqwSIrFg/vzoQWsOUZj XYd1giC6QyTnrI8trS69MPtRr0mtDw3KDr3z7715Td8v9yp303f6kD5YUhfSqLwc8uQrOm8Lp7ZQ1 oz8zDfbvvMKrszglUyAejpwQj7Ph/9c8Irn6qpSi9IfLymnGg+lPv0DEweutnC4Hf5eIBq7K9PrF7 i0MLYkc8n246X7liGjxmYMQwiOfppJ8XFv+CXL2ehGxXGPavRUSBnbIJ9sOc012Jh3PK1dklfzZQt lcc9V52iICzipwjwml4yvOQQTGog42fxQ1/SXkougcyVJwfL3rApM/cVt00Os4cwDUFifLS8oaVz1 yPKSf8zQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srMZx-0000000AtYO-3fSw; Thu, 19 Sep 2024 19:12:37 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srMVb-0000000AsiK-2B9H for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 19:08:11 +0000 Received: by mail-io1-xd4a.google.com with SMTP id ca18e2360f4ac-82cdd759b8cso107396239f.1 for ; Thu, 19 Sep 2024 12:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726772886; x=1727377686; 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=PI01NOAwUBTbTYBhGD7vAZyLVwWtrbZIdss2qywEk8I=; b=AMsSlU+tyw+8y7+oXfvFu78HUjrrR2SVaUhtLVQXLieyPfjwc00H3F8mhtk0AMo3J+ 2x9b6+49qH0lJDZ4/3jte/DU9sakOSlGrsPi3YdXtnbneYpYVgT6Qd9FYa/XIVv1d5wG HXorqW5wxtxzcdbk3v0vfSF1XB7pCxZgd4FHVmy+x1nmoJw4nscTJt7RFCz/meYylEJu RU2kPwjJbPa4OgIu9WntJc+Mu0y8tuVvPPzkNbODziPnMAcPlKLxxdF/su54qdxNz7rI mh9FjBszhhFo8tU8O9i5sdOOD/rq3umKTYhiSR1C9WHP/y9E1wt0w0uKnokXwI/MEUUq ++eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726772886; x=1727377686; 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=PI01NOAwUBTbTYBhGD7vAZyLVwWtrbZIdss2qywEk8I=; b=FpE/GAioyrspVnkSDEGQrJntLjR1HlNU5ip531EJgZAF2DdpdwTp0W1GZXIj7dq8Jf nvk4aOO5Mx/ey0g44X1u2UtrOCg5HQV/T9f9cugvcgl5nfiEXA1m0hFKO8JiZbbFx0KN 7G4jJHzBKsjfs0NU/YHu/Nwil1EEMMZJWg6d2W8KotZ16mzR+V6K86meGmdGby07m00y /SAeizQ2LNdz5XCUOeooJgcoRN8qiPq8FVkYjpPYcYr8VqL1VdYImQO/n7FAzTOTNX7O +Hv/fGasimcXigulYSpI/3DMoDAjtdhvbDxM70LRJG4jqgLCnAzQMlkRt/E6jKwpqDOE JPyw== X-Forwarded-Encrypted: i=1; AJvYcCX9zN5ETQkfWs208gy3IplO6xxv/XmtWrwM65IauA/6znlOchTIrNraZol/yEoikvokOPERpIh11pjuaqFy4enk@lists.infradead.org X-Gm-Message-State: AOJu0YxXfyrd2yf7BediZIG03nmN/W/ovXzxHolrKHtl8t45sdfWKo9T 2qxpZ6jBrT85GfLWxTADPNMrDs+nee0eQ19olaChXxSXyvVM+A+moW+jtV/3X6xGbh9J4gmE8Ue zn+rDW2u7w9I/SK/gtp6r/w== X-Google-Smtp-Source: AGHT+IFXF42PxsE/0eJNPgXYyij53e22bxgy0o5zvBDcPWfeczAztmoWZY1bSRZHpVpQzrCe+MiXIaYy8y/4W5uIkw== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6638:8507:b0:4b9:ad94:2074 with SMTP id 8926c6da1cb9f-4d3d684d324mr6497173.3.1726772885573; Thu, 19 Sep 2024 12:08:05 -0700 (PDT) Date: Thu, 19 Sep 2024 19:07:47 +0000 In-Reply-To: <20240919190750.4163977-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240919190750.4163977-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240919190750.4163977-3-coltonlewis@google.com> Subject: [PATCH v4 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-20240919_120807_596298_7F9766B6 X-CRM114-Status: GOOD ( 20.91 ) 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..af0f46e2373b 100644 --- a/arch/powerpc/include/asm/perf_event_server.h +++ b/arch/powerpc/include/asm/perf_event_server.h @@ -102,8 +102,8 @@ struct power_pmu { int __init register_power_pmu(struct power_pmu *pmu); struct pt_regs; -extern unsigned long perf_misc_flags(struct pt_regs *regs); -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); extern unsigned long int read_bhrb(int n); /* @@ -111,7 +111,7 @@ extern unsigned long int read_bhrb(int n); * if we have hardware PMU support. */ #ifdef CONFIG_PPC_PERF_CTRS -#define perf_misc_flags(regs) perf_misc_flags(regs) +#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) #endif /* diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c index 42867469752d..dc01aa604cc1 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2332,7 +2332,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, * Called from generic code to get the misc flags (i.e. processor mode) * for an event_id. */ -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { u32 flags = perf_get_misc_flags(regs); @@ -2346,7 +2346,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs) * Called from generic code to get the instruction pointer * for an event_id. */ -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { unsigned long siar = mfspr(SPRN_SIAR); diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/perf_event.h index 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 Thu Sep 19 19:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13807963 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 17838CF3962 for ; Thu, 19 Sep 2024 19:11:40 +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=i5Qt5np/Ap8e8S56AX/TaOyn++MQC/aFN8Qv/OewSh4=; b=vArjeKUC5tFYr+i6h53m+7eROF OoeAwJDnvs22DQif9er4NHxO8ahtWIth/4rX70gsfb0K1ptCnGa2z4Ex0qyXVjEFCled+Sk9cDHjm 57Pe9gwPMbeMZNRx9IEbBxhvW+ukieKgh9uqsTatVqSCl6vs5qedhMvgqP/BwphVyAHu4pVXM4oyz 203xqheYWTkoGaLtuUmmI3mgMBFCF1xZ16py6xAkmKKM9FB31+i+MpatLWV7gF1Y5EC7wewXpIipf fGspW+mlF1HRweI8oL6k7Aa0aUcTAtUReFCSxdAMpkJZKfs/wyCQOa6nLiJKLUJeNVoEli2LNlYYk 3eyknIsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srMYt-0000000AtQZ-0093; Thu, 19 Sep 2024 19:11:31 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srMVc-0000000AsjO-28Kb for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 19:08:10 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ddd7800846so28773277b3.0 for ; Thu, 19 Sep 2024 12:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726772887; x=1727377687; 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=i5Qt5np/Ap8e8S56AX/TaOyn++MQC/aFN8Qv/OewSh4=; b=3uzSsUKDNlaZani9rsYm1qdaiH7XK935K7FSMbUOT4fvYjx0TbagkqLpxShvx5XvXR yFWDQ9q/mtjsOVvuY5HewbOQ5zwlAdspa30quoFYfPKRHd3t/FdAzqxuazncBdWiE5oZ d/etd4X9O3TAi0ve8hzqKO4NHBLSZ5LV5c4sYmU2uhCXMeHwQBIG+LOd0wATm5jcx3mS Y0dPVI+PbNz0jwboIUlH5sNuh3drhYjgq6cf36XfvFicYD09xp6fwpvX6ruJ5ybYYcqs MkJu3Aw7YlVB5GlaqCCEdAx7Q0/RGr6G264EbjWk2jLgBoqNjXewgs7x92KO2e5/bdtN 0sng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726772887; x=1727377687; 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=i5Qt5np/Ap8e8S56AX/TaOyn++MQC/aFN8Qv/OewSh4=; b=ftMW2qlgaxaCfLXKVy5ArCtCk5KkHM7Ak856ejGKiZ4XU8ey8pgoUuxkAS4eAxnimA 52UVk+iBJfnAr/62Lz8uo4xFgUBQ2tCYbJyI/J4lYx+8ORHds3lSqHhBNoV0wGBt9pkq qcImG30oRACx7TvDV3yMVgSRwviw038mXjH3BGBLi4r4xMGjpB+jN59FnEDFJVRviFad DmnZ5ANe+adc1UUmfN3IzZ9UYlRBYdfr2b6MO/UuhQD9X3vRaRbd2Un6KltA+5eVSm/5 VdILB/WuDSz09bRByaSysBJOVRDyEOvyhuEVPFhTKT8wy+0GLIZmyBNFI7FQdlYynFr9 5NHw== X-Forwarded-Encrypted: i=1; AJvYcCUlq2IVcIQ2lBFB7ZjJPEIsRB77g2oy9BQ7/Duc61pXzvrHo82Iklggrsqw4b3ttjoIq8sUSmiMvZGGIIo8Qmbd@lists.infradead.org X-Gm-Message-State: AOJu0YyOcub41lPFr/kp2fFFkXp9ggx674nJOYyEuAvX7MSdSjUWb0By EV4yF2Q6ixwRxHgSXc7Vub6hFZ5FmbsJwRL6tfu4adIP6sC/+KJhqoC7Zdc1VAYlAOghNkoq+Nz 48h1rImWU0mt6zRnd2zmzow== X-Google-Smtp-Source: AGHT+IG+gWtFXvOjppbknvofQy7F475eldlmwCdDkPmmKXe3fWWYdIxyDCZn7gT+ZyDPYmZ3bf2GZI0Klu7wUcLEaA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a81:a88a:0:b0:68d:52a1:bed with SMTP id 00721157ae682-6dfeec11e0amr8827b3.1.1726772886738; Thu, 19 Sep 2024 12:08:06 -0700 (PDT) Date: Thu, 19 Sep 2024 19:07:48 +0000 In-Reply-To: <20240919190750.4163977-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240919190750.4163977-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240919190750.4163977-4-coltonlewis@google.com> Subject: [PATCH v4 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-20240919_120808_568657_2A464AA0 X-CRM114-Status: GOOD ( 14.17 ) 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 Thu Sep 19 19:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13807965 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 8ADCACF3964 for ; Thu, 19 Sep 2024 19:14:17 +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=os3Yqql37R8r3BEesV69Cp0Wu//D+lGOxICBFWLJF5s=; b=BK8SEUjstKUzpxMW7QMRtee89r ui8mdYC+85+MPs8FrwBfKjD4TwcM8VlTJ+P+/8xgpu9tHBl1PKBhWKleMF0+xAuhIeo+CazG0MXMt QHcPk075v3wzEltajbKdIC9mCtKlNYnxg2c4BlZAIFDB8UD8Thgyc8JR97MebE0X9nLt8ef+aSBow ylfO9XwT9YpBoDNMX/wepv+Er6PkV55lobTeWeLs5bWeIPB+rO4O9qHirrEQ/DVh7J9b7TkfWqs5H 5DH5u+Uz8MGSYZFhOp5riThg6iB82p5i3QvjuMWnpfigiKVWk0vG7U21KjzlBcvtkrd7nrtLUxthL kJayUA2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srMbQ-0000000AtiZ-0p9l; Thu, 19 Sep 2024 19:14:08 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srMVe-0000000Asjx-1hEz for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 19:08:11 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e1a74f824f9so2276267276.1 for ; Thu, 19 Sep 2024 12:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726772888; x=1727377688; 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=os3Yqql37R8r3BEesV69Cp0Wu//D+lGOxICBFWLJF5s=; b=XfXhTVFTwmfd0jdclMazYj3OZk9S1YmnU3ltLnqW4hQTB1gFdkiS3WlJTRIVuqXJVU LnrJ6JDHXBopqF0oh4+Ho+pUFjZ/mGoqNSYeLubxB1D7fasidSEChkdosGeHEEYBvvKa qpY4GD1ihH/VQANRbg1Zrdi852LU08lx8u44wsxUt/kNPxub94WzfbzyL52ZxNR/RElb 3ib3r7Fd6p63qUOfW36nuR9UDjk1GgdVvQK4tAi2BoXa0GKR0hx7jCcGSNM2KTdH7+oh bLPIaNnC7KabjD9TYoEiqWuiRJYwCbOPdGb3HJ0Y0DzeJb6BQK6ZhqLLNmCBwcw4Sag1 Lg2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726772888; x=1727377688; 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=os3Yqql37R8r3BEesV69Cp0Wu//D+lGOxICBFWLJF5s=; b=jr+bvCcMmgPAWaRKRWQtl3GpJVzVMT69s1bIrpM6kzSBqArrAWrofm5HlrWIIyxEer /hw4KFi+la975j66qFOcKc8RWcTcDgm/om3gP1EhjBTVP0QzZay7Wv7waiC3RG46f8eq V0lG/SZw6VmiXKUM+QkP+53zNQSWfZY0yH6dYPBecykpTshrmMkguVpuEh4Y9l2Qsw18 /h9BhqcEf0LlLcUSTChheRRdKq7KJ4Sw9vPkFxT8SGGAl1eHrMQ6xqNZMUC4kgZ6DGT1 ZQwkzLJ8JC/oGcCOiNgmRnwbNLeVCZ7kFdaR7u4q1vbqw0XyjlsJjRk+ES0BEBkbfMmT 7z5w== X-Forwarded-Encrypted: i=1; AJvYcCV4sYoVpP2eo9GD97rO3Y1hZAggOneG6Soph/bOQm5cRhViGU6Pjcx5DyxVt5esKFkAvOEnL16E+1rlYcbZ4D8r@lists.infradead.org X-Gm-Message-State: AOJu0Yx+dDpnpmlTBnhrBB+aBqH26H2wjLiQmjz1gYoIABqWlDTHuovO QTmIPF0thbPpyD1+TE3D5UExd7BPHTXSfROS9xpuGGpZ9OUm+Ll7rbAjkWvJ19PItrjdDcUxRPD lP6nHJgd1Ume8ZGu/+gFHVw== X-Google-Smtp-Source: AGHT+IEWKocKtUeJyLcIg/Q0/lFfDEFCwNKFuqL4bh0kqfDWnkDMObP8hKFL4orR1R805yrNr96S1GsShGwKfOHrhQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a25:b20e:0:b0:e20:298c:541 with SMTP id 3f1490d57ef6-e2250cd4633mr337276.9.1726772888086; Thu, 19 Sep 2024 12:08:08 -0700 (PDT) Date: Thu, 19 Sep 2024 19:07:49 +0000 In-Reply-To: <20240919190750.4163977-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240919190750.4163977-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240919190750.4163977-5-coltonlewis@google.com> Subject: [PATCH v4 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-20240919_120810_551654_F83505CE X-CRM114-Status: GOOD ( 16.05 ) 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 Thu Sep 19 19:07:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13807966 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 B0DE1CF3962 for ; Thu, 19 Sep 2024 19:15:27 +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=09zZtsyjNKU34RxIAdYq19fo4EG569yh76FDw7B839k=; b=V/f6Vn6nS9Q0wvy99dsZwp0hnG xdctzARc5XU+nf7MIf9ZJG7PTJ+hZoOS7QzxXjJt8XX1qTjcO8qq2Gybnd1jTxbEjkCudMhHbB0iU eRBh3HEHM5QKtGFKC/Dwyb7pcz354CUVgZIf3JMyRRnQv+JcUiuRaoIuNGkYVGAg9Y1xIRELy0ifh 5SD/s3Jy67iifoPXeCDYsJPg07agXWPwAcs3ioKh6mqxoj5QvdNNbBW1ekbs+LXapgMGUAT4mCGXl hazXN20QnkbYYgpeev5sOcdA1cRUFuMfWJEejc9DDge3sDNjPmWKDR21lBLH/y1FFh+3VJCO48OcR r5wXXH7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srMcU-0000000Atp6-39vu; Thu, 19 Sep 2024 19:15:14 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srMVf-0000000AskM-0v67 for linux-arm-kernel@lists.infradead.org; Thu, 19 Sep 2024 19:08:12 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e1dc0585fbfso1887724276.3 for ; Thu, 19 Sep 2024 12:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726772889; x=1727377689; 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=09zZtsyjNKU34RxIAdYq19fo4EG569yh76FDw7B839k=; b=GHGIB1R3ZPIut962NQgmkBs6gPvuaeBhxpetdR6oqcfzwg6lZM8yP5kWRRZLrJRTJD wK/Ydj1dbGr+WODcUqpN1HWuSP+Q4x64QN/e0Grr1Q/hnv1sOzH9/s01/y9m0qj3N8Sn DAshbPm7xoqDasnKZfuAUSh07JnDWTxNyP/N2U6fAaPM9Whg5CDvOw19NTT0vLuT20Bv ndqMb4OBzQZRO2RFgQL3LyxfUoT2UuJPXHb9EnUlKouGn83zH3L2z6GuPGMRKNOh+0wi 22pTraKiD+YxSQWWuAyvCDR6yuMW3oc+cqAXpXGAUtbB41MJe1U9JiNGZHaQMGafXsDj PiTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726772889; x=1727377689; 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=09zZtsyjNKU34RxIAdYq19fo4EG569yh76FDw7B839k=; b=VJqIY4m9yyq6D6Z3pwZYnYEfhyMHBssqumBmfoPoEq3nMK3IbWyJ53HJN4VrwWnKht Ktuq2RInWaDuAj3pRVuO/+ZH6mFp7RExKfg4u/cNw+lM8PH5mV/Spp5uduhHeYT5vcRc j5qcCXnhBQYAQXMKv+SMZ78gQy/LHtSjIXcgIZ0snx0NOQqf6CjkgHFgfR7gGZLPSO/a zV9Oq0ucp9wiaXb36Iv848etGVMQ4WhOp39+Org9VLKxYn11g90skXr6sUaBCDRqScuQ kQz8ht6oXkJWtc7FSExRcIc+C/727vSgFA9IKF1tLIGENhVoQPcX8w9Md646ZEKv4b6p uRKg== X-Forwarded-Encrypted: i=1; AJvYcCWVDLV4PR9arwGWqGR48QUAKfOd8cc6xVTZJp0vbDLY5xs2/1n3KhntBurt0pDCzPI3GrZln3m9quE3Yrx0y/Gl@lists.infradead.org X-Gm-Message-State: AOJu0YwZZxueo2XJPwh5PUqvIzN66z+G9gFpR16FXCn/mdL4cKpLd+2W YVYxDwC4TZplvnaHMaypKWdPAR4Mct30jzbUw6PoX5ZIpJBAVx8PaQXRqSrFNX2pRzN54fZUvF9 nHhZKe51XQfIgMGugUj50xQ== X-Google-Smtp-Source: AGHT+IH7DS+SKBUjwFhvlyrXRx7BdcWzXxigrbQzKIYP4oeDJso13ZKWEUISE2cE3y2zWZHTyZIEgxGF1DgagD7KPQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:1347:b0:e0b:958a:3344 with SMTP id 3f1490d57ef6-e2250cd2f53mr3552276.10.1726772889473; Thu, 19 Sep 2024 12:08:09 -0700 (PDT) Date: Thu, 19 Sep 2024 19:07:50 +0000 In-Reply-To: <20240919190750.4163977-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240919190750.4163977-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240919190750.4163977-6-coltonlewis@google.com> Subject: [PATCH v4 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-20240919_120811_311173_4D4A52B5 X-CRM114-Status: GOOD ( 21.81 ) 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 = 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 --- arch/arm64/include/asm/perf_event.h | 4 ---- arch/arm64/kernel/perf_callchain.c | 28 ---------------------------- arch/x86/events/core.c | 16 ++++------------ include/linux/perf_event.h | 21 +++++++++++++++++++-- kernel/events/core.c | 21 +++++++++++++++++---- 5 files changed, 40 insertions(+), 50 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h index 31a5584ed423..ee45b4e77347 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -10,10 +10,6 @@ #include #ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); -#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index 01a9d08fc009..9b7f26b128b5 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -38,31 +38,3 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, arch_stack_walk(callchain_trace, entry, current, regs); } - -unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) -{ - if (perf_guest_state()) - return perf_guest_get_ip(); - - return instruction_pointer(regs); -} - -unsigned long perf_arch_misc_flags(struct pt_regs *regs) -{ - unsigned int guest_state = perf_guest_state(); - int misc = 0; - - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } - - return misc; -} diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index d51e5d24802b..3c5f512d2bcf 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); } @@ -2971,17 +2968,12 @@ unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) unsigned long perf_arch_misc_flags(struct pt_regs *regs) { - unsigned int guest_state = perf_guest_state(); unsigned long misc = common_misc_flags(regs); - if (guest_state) { - misc |= perf_arch_guest_misc_flags(regs); - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } + if (user_mode(regs)) + misc |= PERF_RECORD_MISC_USER; + else + misc |= PERF_RECORD_MISC_KERNEL; return misc; } diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 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