From patchwork Wed Sep 4 20:41: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: 13791431 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 3EECBCD4F32 for ; Wed, 4 Sep 2024 20:47:30 +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=i72PSOIXWhCeY4HgM9YgFlmZggdii21Cl4McUfu+68c=; b=x2SqFnCAqVaQkbMWY5SCZwhfOA cEqCXG3soRsfaZDOmGZfoTgb00XhJtxsMZiQzUUO1e490uUzTBKfXiYcKN68rZrInJhD6UO18jYFV GH+zDnKg2jXMnZlL1jbeZaBtYMTfSD24u+q+P/V1u++hj0jW1RVexYBiSuHwHtUJMxGjM3IXMp3jO NM6P6hwFw+Thx2Q2QN8H0u2tuf+lE9/U4ggQHfK7GVkDMh94gfCMVEI7qGwB1jFv9l9mfegbMPhVH DObKpITsn3jGOyonEBAzzJlGH+IL9O2ghGCzJCBi8jBLQtMxoCshwMA7d/8bEx02TBjhgv1FoUt4Z T4vOwO5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slwuN-0000000628x-1iSe; Wed, 04 Sep 2024 20:47:19 +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 1slwpk-000000060kk-1TSa for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 20:42:33 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e02a4de4f4eso187649276.1 for ; Wed, 04 Sep 2024 13:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725482550; x=1726087350; 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=i72PSOIXWhCeY4HgM9YgFlmZggdii21Cl4McUfu+68c=; b=kLaVTkaC0KjNMjHccZc4YlTDjfcFQIUQOhBrGEClIBLbOMcaLuTh+D+IctTYzmL3db b8bBEateijfIqzuZe5Stj2ULjKaPLZSJZjOHQRHtFv2VjQP9BqIb1KRGnh2scBT34ghl 9lzRhkhfNubOvUr4sJ5qw/8y8/tJ8dD+uzW/VPykOgjBMpIWTAVHJFePrFjByFNB6xpB flYdI4Dp78YNPJK6x/FHZ1+N/2yo1l8cq0Fm/lc3z+QzJStP6H6zdnRaSglpoZVUK3KD SCwG232uUiilZTX9fBEvuODJ4qxlOHry5OrJuQMlyWrNFbdGqSPueJG0sHsBRh6ESEXP ZHTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725482550; x=1726087350; 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=i72PSOIXWhCeY4HgM9YgFlmZggdii21Cl4McUfu+68c=; b=Aws10b1096I9+AQa3Zki/cJ0HrdibriT6ueKUKFC+OKa8El2kgst0Y0rEJPUR/8vAQ p2zzF9qFTHxiw46+xQIkiyn+1ZLs/xQFwlbLaaDCjTCDCu7g9LgUWJhex5S88v7k1HrS xfFHSzlMGpdotjFXLkRRpjsRK0bprsTSTv36UdceC89iK5Xzan6USrUHAcl7fZaubU9X 5EGy9qeuw3RUBI0Z/MEvreufFAuD+ERHH2ASntzgWbVR5sPzPdkgoe5ImFbZyQ1MehQK HC8b7wAAKCfGDnxYAi0wyLLBHTy2zGHMTZd994kfIafIz9BX2SL/QyJt5zb81qBHbPiI spKg== X-Forwarded-Encrypted: i=1; AJvYcCVmCVE3Gu4Ye9ASNpVjbRK1KpZuPlXEWFszekuXPKhUGWyOrKyZPaSe/CEnDgqMBOH4SU2+cfqZpl2MYcyqm0ww@lists.infradead.org X-Gm-Message-State: AOJu0YxzZFh87Ky1SB8DI5meUX8kOfoHqWKJvuxIHeypkWs2D7YYV+jc OlFPpunitq3r6BEIbBCdOzi3SV1VEvWPZIs0A0tydSUNqHfiKl2oOxxq6QkglZcvzF+IZmAOGrU r/lQWBnaZAkJw2Jj2l48OpA== X-Google-Smtp-Source: AGHT+IFmR24uVrOJthtOJz6K2WVb+jtHXjG+hacdDNR8Ql4EFrmp0GPrZ3zw2M5BxgYPY6TLAf+W8lj+BLe1iw09KQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:14ce]) (user=coltonlewis job=sendgmr) by 2002:a25:361a:0:b0:e0e:445b:606 with SMTP id 3f1490d57ef6-e1d0e58575emr4988276.0.1725482550264; Wed, 04 Sep 2024 13:42:30 -0700 (PDT) Date: Wed, 4 Sep 2024 20:41:32 +0000 In-Reply-To: <20240904204133.1442132-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240904204133.1442132-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240904204133.1442132-5-coltonlewis@google.com> Subject: [PATCH 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-20240904_134232_412872_65E85C24 X-CRM114-Status: GOOD ( 16.02 ) 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..87457e5d7f65 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(); + + 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(); 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