From patchwork Sun Oct 8 14:52:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 149755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1401888vqo; Sun, 8 Oct 2023 07:53:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjjoZN0hbdRU2kK17STyMMP8p4uL40RKrpz1MzqPJy5XIOsItuJwqR8Qy7Zd2avlRmrDyt X-Received: by 2002:a17:902:e811:b0:1b8:8af0:416f with SMTP id u17-20020a170902e81100b001b88af0416fmr17036951plg.1.1696776809115; Sun, 08 Oct 2023 07:53:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696776809; cv=pass; d=google.com; s=arc-20160816; b=UOT6PPyCD3jzFLg+5lewLqlRbNWW6zRTnWm3c8G7/Q7BHrUNZXMwE6oHQ8UPszTqrN UDmyxYNvvztXBO3ja4zfvBd0viWovPOI7Wr1p6J+PQO2esNoOJEoDhQwleVU2RZjsU9c u7AtkqXy6jpg+HtAMZhonIEcjP+PFCnJIvCym/7VKkmBY4Bnr3zSwHJJRhAo8btrPeKX zGtdaVtfSbuJ45XzXfpO4OD6sKKsE5aWVFifIsJ+70XrbtHJ6ly9eGWrXDGH8yWOspBB GK9ZrZtZzXJcNXbsAlQfwb7s4yIOUXzDftfdNnhPRnhgLgGEjaU9yYcC3a84nsdMStDW Ae1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4CxXtiQ9USb3dDRkpn0l1+Exe6nY1VWP5IqNPZ/uctk=; fh=F5FYRTUV4xCU93BuG+U5i7IE8Bv2SgSTNGSJMbfAlmQ=; b=Bb4SjjPJTQqbi1HsfbdOiJClvMXrxNxWtCU8gT/46SFdUzLajhWRwZiE+rcHWqTGH5 +qEXHeLqhJFEuY+AQmB7TH/Jpxk3SwswP9FfJnnYSfUBAU68hyLeMPuH9xD/fMDPWsTQ bU8YifSYtB5ihG+FFEUnLRYi1bNQt7SmkMbmSm2w9/Klgi1ofQZ3lL92aLAuWSnfcPdY fbse7W9+tjxYAFx9N5qUozoD0KqMxgteRTu8W250x3WMjhKYihFnpLr5yst5gK1074GO ui2S1Rx5lSBwXewx8atL6IcESbxhLL2rR0vdnoYiutKTtKtM8mffpSFoOmYp368dMf2a aRNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=BxxLcwRr; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id kt4-20020a170903088400b001c60c5726b8si7364678plb.5.2023.10.08.07.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 07:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=BxxLcwRr; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 18ADC8026831; Sun, 8 Oct 2023 07:53:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344899AbjJHOxN (ORCPT + 18 others); Sun, 8 Oct 2023 10:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbjJHOxL (ORCPT ); Sun, 8 Oct 2023 10:53:11 -0400 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2156.outbound.protection.outlook.com [40.92.63.156]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD52A4; Sun, 8 Oct 2023 07:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hcPenzeoMVj3NWwKD1fZPwzFKRph1JZMs+VeDteEKOU8RFEcq4Kf+G7W6+OSNTC+oYUWzSPs6tU98ObLY7fpYqEB32HS5MFSlWUOrZwdB6aDuqyGSheLK6Mw9E7G6mlbxGeQQ1YvBa3Nf25wVg2o2OLr/FsWm0q6+3NwintCdxwdyV7n9PGcFtFdIPjEn3LG06FJUPynRM7rcAtdOyzag/PiL13sD4osXi+vc44uYcMWaw4mQwhRR7cdAwrbvDBGGKi8JSxBIH5gFweuxI3v5z2x9jRXHSuI7lsGGI/UhM0nnQMOYYEyRFBeZxhK92tAh8sT/j8cwcOY4UvttxiiIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4CxXtiQ9USb3dDRkpn0l1+Exe6nY1VWP5IqNPZ/uctk=; b=AIJYr3qWjzF1xcgbrXosLf0wgDHyuUF9waj1jZcKAp3ug3mbwLD0J1v07PKkcWjWfdH4cnu/3Jy7TBWSuFODMiD2BAwjPgqs+WfQFbptkfzg8Syr09JN7CQnAGfl9DOa7PywSt8Y+DF+u1mc+5tSPOY0YV639P0CRxXY5TtpHuOKNIvLT1kKEYxadDzApj/GemhNjUcofI09yyZdmiqq4u8wPlH8VYQ8WRFK7OKqQbChU8HDlKDe5U6X/oqL51sAu48j7PsPEFbNQYS3Xa+hYUMU69EeruPoFVvebhoXoS7vbOD8L5aG/c4Wz7IIWuinEdvV4Vqw8TN9oRGLmVibSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4CxXtiQ9USb3dDRkpn0l1+Exe6nY1VWP5IqNPZ/uctk=; b=BxxLcwRr7Brk6iKa9EjdbueLfhB//Q8NlEiihSA9vVZOP0R7+BOQY6/wYQOBtpdFPTnjgUGMjCFRPlwS5SxLeoiiWChMaV3MuJBR4OVjYbUK52hSMjOhG4Cc2WURTgGbOtSWCR5GFjR7zW/Msz8SQtWJR1s2lkSHXORsq33/zdXu5wgCW7nbMkOMYbHhQbu0anR03B7Gy/zznE1KcDsDAcCX88gXTqp1emlnZ7epigy0F1TVcsArou7ym1MMJxBGmXEFzCL+RP5WFtbBHqAyXPEC4jTvlmQ/EbZDFkNwRUOrOzh0WZe5WYi6/BJLoiN/uhxl6UReaNdHT6Frt+LIjA== Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) by SY4P282MB1371.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:a2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Sun, 8 Oct 2023 14:53:03 +0000 Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8]) by SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8%3]) with mapi id 15.20.6838.040; Sun, 8 Oct 2023 14:53:03 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v2 1/5] KVM: Add arch specific interfaces for sampling guest callchains Date: Sun, 8 Oct 2023 22:52:20 +0800 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: X-TMN: [dT35Yg0Ztuvx/B/C13xQirvyaWVIvY1Jsoj0E78mW46eB3Mbm3wgrw==] X-ClientProxiedBy: SGAP274CA0024.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::36) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20231008145220.7220-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1084:EE_|SY4P282MB1371:EE_ X-MS-Office365-Filtering-Correlation-Id: b93ee731-1a71-405c-4f7c-08dbc80e459a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aGsZAKOkUwNp2fXgX9x9kENhiCrK6+zipDPILE6muw/KvTn1Lny2mgsh9Wd/U0coAImxUPPcpENoYHlc+eMcWzLX0mZGoPe95/rNrg/MSe0Bn8JKxfQoFZ0NzuTP6McF1SncJkyYYodDnb3sRrIkSCj8iQaFXbAG7UU2TcCcTTvb7+a1yd2FyCpgKofvEWpnFWBORZhgZw/fe+UpMvhgBB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y1vX+SX1wHMZLoU5Q1FdM4UIDDgFtYiYpnieshiyiot2qFlJzZNV8+5f8IV3dLfakto77wIdIesqqLIBvhGY6FQEw9mrvBj59T3jvMnSebU41WQTNCh9B2dB1fXUQ9Z9YxUCRBBLK3zKw9EStrMV7WQq2u4YyXzPmzeM3UGr6f3tfJI4a/iJrPJ+mZn7jACIj4WBhflY5v27n6zXgO5rHNCWB1o+V5W7pOVIBZVRfCpDMRTbyWnnt2vbjcNl1XbUpE1HOmM1O2PJi3+hmPen4lkIg0x2rOfJDvZrTykc9wZRbSF/EZ5p7uhfciFrIL5eSKMmnLANBdKKXM4sdjJJDvhVwi90lVljMRjeOpa8vg/f89VoqS6Qr/6pr1EQudsriEf1nkzSMXdWVa/Ms12m3S4bcU8GVJb+DGjHAR/EXtJafjAUlh2gffZNPs/IPNWrxb4FE8Hziw965Pf5UGIWB0A9xxUQCxQcMijYQlOuHLhTSFsOkIkkH1KpQ5CFKs+QK6CjV+ij6vWvmKIVImPQ7ui1EJHbTMLqHEuHtdxwhypVxPwMjQFvtp4SZ3wM5hOgbLvmgpCDCfbQXKbzKTEdIWYof7mBrEK01T28HQGt9dyr/DrTYM1uKMxs1ZS19UtVxv2zEx0GWmsYAAN800fwPGFmYh6pw6alYX1c11zeCkxMj3aMtpwZNbpJI431 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b93ee731-1a71-405c-4f7c-08dbc80e459a X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2023 14:53:03.7523 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY4P282MB1371 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 08 Oct 2023 07:53:27 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779199439526839849 X-GMAIL-MSGID: 1779199439526839849 This patch adds three architecture specific interfaces and x86 implementations used by `perf kvm`: - kvm_arch_vcpu_get_frame_pointer: Return the frame pointer of vcpu, for x86 it's RBP, and for arm64 it's x29. - kvm_arch_vcpu_read_virt: Read data from a virtual address of the given guest vm. - kvm_arch_vcpu_is_64bit: Return whether the vcpu is working in 64-bit mode. It's used for determining the size of a stack frame. Since arm64 hasn't provided some foundational infrastructure, stub the arm64 implementation for now because it's a bit complex. Signed-off-by: Tianyi Liu --- arch/arm64/kvm/arm.c | 17 +++++++++++++++++ arch/x86/kvm/x86.c | 18 ++++++++++++++++++ include/linux/kvm_host.h | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 4866b3f7b..b57b88c58 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -571,6 +571,23 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) { return *vcpu_pc(vcpu); } + +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu) +{ + /* TODO: implement */ + return NULL; +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, unsigned int length) +{ + /* TODO: implement */ + return false; +} + +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu) +{ + return !vcpu_mode_is_32bit(vcpu); +} #endif static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9f18b06bb..17dea02b7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12904,6 +12904,24 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) return kvm_rip_read(vcpu); } +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu) +{ + return kvm_register_read_raw(vcpu, VCPU_REGS_RBP); +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, unsigned int length) +{ + struct x86_exception e; + + /* Return true on success */ + return kvm_read_guest_virt(vcpu, addr, dest, length, &e) == X86EMUL_CONTINUE; +} + +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu) +{ + return is_64_bit_mode(vcpu); +} + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index fb6c6109f..f92f1a9c8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1595,6 +1595,10 @@ static inline bool kvm_arch_intc_initialized(struct kvm *kvm) #ifdef CONFIG_GUEST_PERF_EVENTS unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu); +unsigned long kvm_arch_vcpu_get_frame_pointer(struct kvm_vcpu *vcpu); +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, void *addr, void *dest, + unsigned int length); +bool kvm_arch_vcpu_is_64bit(struct kvm_vcpu *vcpu); void kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void)); void kvm_unregister_perf_callbacks(void); From patchwork Sun Oct 8 14:53:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 149756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1402368vqo; Sun, 8 Oct 2023 07:54:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGShk41X5KI2NblkVNF2m3JiBcKguC3brIQHERXrz13YvSHqvqbT96wd6AMdDwnecGfsvk9 X-Received: by 2002:a05:6a00:1390:b0:693:3d55:2ba6 with SMTP id t16-20020a056a00139000b006933d552ba6mr16915119pfg.9.1696776897394; Sun, 08 Oct 2023 07:54:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696776897; cv=pass; d=google.com; s=arc-20160816; b=WthON79ULxxLzbrcBwm5Eng7TQPsGfl5XIFQMNyNzVFRzKb8O+xFPRIfyVshZWDGbd 7euB1C72ePINFd+0I8qARgytHvgvofCIN2hc8W8+kpZQ9dChFX+ImiSJIbet11i8J7h9 emldOG0JgPE2hUt1MBN0qZ3tN/VwsTFUrh1lCVXIXHqGA2v/uCCqxvZgoTilyEmNs/Ly h7myealZGOY7IdxlGM9FHmsEkqzfY/SCRZqMMEoohwHpfI2Ub1o583yiyzARK/PT3p+r qwZL9uVWEGUgDzvls8m4LQJmElLC7isFV8OvxaJ2fn7gshtAxtObvh2H1DaLTesqqtG5 qxOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V4dan7kHVeyvxdy/3lD+tO9lH46m373g697XhVl5n5o=; fh=F5FYRTUV4xCU93BuG+U5i7IE8Bv2SgSTNGSJMbfAlmQ=; b=zdrhUIUu10hez1RqoBGTuWPGmZ04t7OwoXrd5RB8YmmyG9W8WxqzwajWaJC85BaQHT LGLLAgdoJVxO9HZ5I66FL7egURrUERe62zPf7wzIx3a/e3rI49osRe2q8stvsMFLAQbn aA5v7Sx/FBPpfMPUOCWVTIsErftSgGy115vYtBxKm/6DnfgW8flZN2EP76ONjFU2DrDC JjJeM6oYNkAR0ib+8KX61rj7dwGkbei4kRTicLuI7Z6G6AzOzgC4zOO/+tsKRdECvFIX nTCLUFhvtBeQRp7XeOcM4p8P8S9CjrLPu4Qn3nQnATzNtfbbxCQKEpK9XKzxnqJ8Nq3n 9bkg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=rStEOiy+; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u20-20020a634714000000b00578c9003932si7906478pga.808.2023.10.08.07.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 07:54:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=rStEOiy+; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 713AC8026838; Sun, 8 Oct 2023 07:54:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344903AbjJHOya (ORCPT + 18 others); Sun, 8 Oct 2023 10:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbjJHOy2 (ORCPT ); Sun, 8 Oct 2023 10:54:28 -0400 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2159.outbound.protection.outlook.com [40.92.63.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C935A4; Sun, 8 Oct 2023 07:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WMmJa60OL51BurQg+847fy5d+UwpqF8hHYXORAKjergNrx9iIH+btJ3YEp964hBfk+El3hpE6gD66QDs1ESHRlZ7MYomIoc6dOBY+aIqWJ/Z9+kzx/ogR10w1aW2asghTwhShggwIELA4DtE8BlMf4ImbFEHilOhx/214hR2+7EqrHQ+rP/LoSKcsrquh8jQ5E36JBVi++aDkOaJ424L6ICU7cPojB7M6Zv11xXOOehZudETj/TClqYp+XehiqHEcx6duz1lFHmdruVPXEX2S68+8DMxHuYwilvO2LbyyNJunE487Tzw9TqWzskuklF70iAL1fH+SLtUQeBDBdbI2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=V4dan7kHVeyvxdy/3lD+tO9lH46m373g697XhVl5n5o=; b=CvF8ss5hxHSZ2RFGh5rCoBTg3lL9UnWhZsnN6Hs3Zj+aGGDzTaDxX957O8SxkqcTwiLQmCmWyu+ZrOKJW/1Yd02/Z0t2CdLI3H7ii/LZjos14lDGGnn2VbrqXirx5SiHQLJ1ldSEP5/pwcaxjCIeHP5N9G/mXCD+7XDeQX2ZqBL8Rjt9r56NP9lF5d3c37ny/pNu8uCPKCxh4TaoooIQKNZxs70ZZtNCqtq9msO8cWguWpCpSQgFHHHEhyaN+r/h89TsiTI/nIqjKNTzH3pBd0dTvU/J/K7nnRy0GBa96hsDv7RnbGK8IZkwDCrLC18s0VZpv8ffh++ombsO/cKYAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=V4dan7kHVeyvxdy/3lD+tO9lH46m373g697XhVl5n5o=; b=rStEOiy+g2M3KYn0YHg6AG7GWqNO1I50nkUH5LbNIrlFbiglzFZOnswMfP9vy3NJzQC7o8oCfm/vZjSuI66fovGjn7h4rpNnwdd4evx+rAhmZCURhMH2sJzolZmFTN0t18Qfal/2Dup5BaJZGeQrtcT7kJHF4D5hzndObqU5erkvmktfdGufMWgIpEcOfm+sOHAEWH7jtUaGU9lDjuuXoa0n+oJRJgSvxv/V90skvyjBBCCdC6gKb6OgzI93zu69bFWjKN5VBlhtDODdaTyEjozKPY/G38eLmZeWE8tQqu7y46zyVmV0A9VUc7NHP0XgxLSWEHMQoiYtY+DIpPZX5A== Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) by SY4P282MB1371.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:a2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Sun, 8 Oct 2023 14:54:20 +0000 Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8]) by SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8%3]) with mapi id 15.20.6838.040; Sun, 8 Oct 2023 14:54:20 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains Date: Sun, 8 Oct 2023 22:53:59 +0800 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: X-TMN: [iekiAmTYnBBVvcmUmOfpwm9LbawksJQ1ZghS3+UOfjPumANR7m9DTQ==] X-ClientProxiedBy: PS2PR02CA0047.apcprd02.prod.outlook.com (2603:1096:300:59::35) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20231008145359.7269-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1084:EE_|SY4P282MB1371:EE_ X-MS-Office365-Filtering-Correlation-Id: 57133fc6-dd08-4e97-d9d1-08dbc80e738b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qf6odUHCy1AankStOFkVtSxY9m0Sq9VLW7IJw5hiqxXsrzkt7PL1Scln628kVsZSSXHO/iqBQQZ907wnHf2JgBr6KjcgOvxgVhK428UtgZAtuQa0b5ZdzckRixvRLR3RURwgMskQH88qIHFh11tV+V0OOhJMGcF5+UulU69Z9BliO7HkrzrCQQepOkazsylX29sfhDnrfrgvFs4rGkxMPC/qPbukOOjk9ohyaCd9r92Fb1pmLiifBz+VYvWKllwQ8az5fbLf+S0d2Kqz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JpyJ9UIEIq3L27+G0mU5IlVcGIjyYi8dnCbR5IQcnWAFGOnKyy8CzXYoonjCr1sunnBE7mXnJ36mttjDHJiBE2q5mjeGcGNKhdsVSP+thLeW4xp97AGuCbZhXNQjWQmTr8efodif3Ee3Rzhg0IGJsh1dDEJyMrzsQl8vtDLBEERSMRld9m5Rkg0p9hilVnXXMDD+yM5oe1xZvaBNqVgxIRgDve4hNZZJ175w8heD73g6Fhczp/s/DEjG8GbrUBXvTP4+SWOR6Y29P2c6BKnNqukmhjO6uP+Syo0tzooIN6VTGt81LIn7R1r55XFjA7Hob7sCRL8ncf1av1p9z5xQu2L1036Y4dyn+figMZWe3ofvi0gQKtaHVbkqRr+p2a0/b63Y1hpiYVxBU0vUT4vDSUKSIFkzRu+2lOsZcNzQfvrMeDnVAwChEkwoUptCi9nF1LX9R5R14fDAO2sZU8jbWzuGWDd2cURsyE2h5bVgvuXhu7V6WzGeSRz9Y7j88/1loyk0gMagYOtdtrN8bmDPuvheXphxi03sOKujb+HVCMaJAEnJTMesOKhber8BpAzsAI/kKlwc8EZRre3li2eCJcAekEHx1H3cW/I+/uNRekbXb5OtAD8ggw X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57133fc6-dd08-4e97-d9d1-08dbc80e738b X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2023 14:54:20.8541 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY4P282MB1371 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 08 Oct 2023 07:54:55 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779199531692599800 X-GMAIL-MSGID: 1779199531692599800 This patch introduces two callback interfaces used between perf and KVM: - get_frame_pointer: Return the frame pointer of the running vm. - read_virt: Read data from a virtual address of the running vm, used for reading the stack frames from the guest. This also introduces a new flag, `PERF_GUEST_64BIT`, to the `.state` callback interface, which indicates whether the vm is running in 64-bit mode. Signed-off-by: Tianyi Liu --- include/linux/perf_event.h | 15 +++++++++++++++ kernel/events/core.c | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index e85cd1c0e..d0f937a62 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -28,10 +28,13 @@ #define PERF_GUEST_ACTIVE 0x01 #define PERF_GUEST_USER 0x02 +#define PERF_GUEST_64BIT 0x04 struct perf_guest_info_callbacks { unsigned int (*state)(void); unsigned long (*get_ip)(void); + unsigned long (*get_frame_pointer)(void); + bool (*read_virt)(void *addr, void *dest, unsigned int len); unsigned int (*handle_intel_pt_intr)(void); }; @@ -1495,6 +1498,8 @@ extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs; DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state); DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip); +DECLARE_STATIC_CALL(__perf_guest_get_frame_pointer, *perf_guest_cbs->get_frame_pointer); +DECLARE_STATIC_CALL(__perf_guest_read_virt, *perf_guest_cbs->read_virt); DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr); static inline unsigned int perf_guest_state(void) @@ -1505,6 +1510,14 @@ static inline unsigned long perf_guest_get_ip(void) { return static_call(__perf_guest_get_ip)(); } +static inline unsigned long perf_guest_get_frame_pointer(void) +{ + return static_call(__perf_guest_get_frame_pointer)(); +} +static inline bool perf_guest_read_virt(void *addr, void *dest, unsigned int length) +{ + return static_call(__perf_guest_read_virt)(addr, dest, length); +} static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return static_call(__perf_guest_handle_intel_pt_intr)(); @@ -1514,6 +1527,8 @@ extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callback #else static inline unsigned int perf_guest_state(void) { return 0; } static inline unsigned long perf_guest_get_ip(void) { return 0; } +static inline unsigned long perf_guest_get_frame_pointer(void) { return 0; } +static inline bool perf_guest_read_virt(void*, void*, unsigned int) { return 0; } static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; } #endif /* CONFIG_GUEST_PERF_EVENTS */ diff --git a/kernel/events/core.c b/kernel/events/core.c index 4c72a41f1..eaba00ec2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6759,6 +6759,8 @@ struct perf_guest_info_callbacks __rcu *perf_guest_cbs; DEFINE_STATIC_CALL_RET0(__perf_guest_state, *perf_guest_cbs->state); DEFINE_STATIC_CALL_RET0(__perf_guest_get_ip, *perf_guest_cbs->get_ip); +DEFINE_STATIC_CALL_RET0(__perf_guest_get_frame_pointer, *perf_guest_cbs->get_frame_pointer); +DEFINE_STATIC_CALL_RET0(__perf_guest_read_virt, *perf_guest_cbs->read_virt); DEFINE_STATIC_CALL_RET0(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr); void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) @@ -6770,6 +6772,12 @@ void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) static_call_update(__perf_guest_state, cbs->state); static_call_update(__perf_guest_get_ip, cbs->get_ip); + if (cbs->get_frame_pointer) + static_call_update(__perf_guest_get_frame_pointer, cbs->get_frame_pointer); + + if (cbs->read_virt) + static_call_update(__perf_guest_read_virt, cbs->read_virt); + /* Implementing ->handle_intel_pt_intr is optional. */ if (cbs->handle_intel_pt_intr) static_call_update(__perf_guest_handle_intel_pt_intr, @@ -6785,6 +6793,8 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) rcu_assign_pointer(perf_guest_cbs, NULL); static_call_update(__perf_guest_state, (void *)&__static_call_return0); static_call_update(__perf_guest_get_ip, (void *)&__static_call_return0); + static_call_update(__perf_guest_get_frame_pointer, (void *)&__static_call_return0); + static_call_update(__perf_guest_read_virt, (void *)&__static_call_return0); static_call_update(__perf_guest_handle_intel_pt_intr, (void *)&__static_call_return0); synchronize_rcu(); From patchwork Sun Oct 8 14:57:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 149757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1403228vqo; Sun, 8 Oct 2023 07:57:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHb6on4rzppRJZKYLjGirzLkdTcnwqG6VGMY2sEYVcdxYP4wnleN3kPvlISIc8yKIB5YYEv X-Received: by 2002:a05:6358:7208:b0:141:3fd:2441 with SMTP id h8-20020a056358720800b0014103fd2441mr14641240rwa.30.1696777071236; Sun, 08 Oct 2023 07:57:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696777071; cv=pass; d=google.com; s=arc-20160816; b=vfzBL7sTfnMx94eu+kiKNWknjRGpwX71SuGkHnL5t3mH4hYLFsC226usSyt81b+os9 Fwc9AJ8g2AKV6/ioZ7L8dKrgTfP9juiXwIx445WWBuiyEdxeRzV7HjKCM9hqWh69TCqr wk7WCL3hC21ZQuN2XolNHk/7eR/1nBzkANAXc+PDxcDTVcKsI9YSC40oIkuESEZfIatw spMc6ngHfkwiKiFSa+sODDro2VFMi/Cigr2CJplSOCn206+rmyG51FPduplH3gD157QL jn8oeVbGzpMUr/nWThm+kFuajxVL303Qs3b2AC0FHDowgGpGt4tHXsOyWn/qMHTEE/It TfHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xaVtEI2qhZS1oaf1GD6pfFXb2t0VmkXD8ySWzedGCOg=; fh=F5FYRTUV4xCU93BuG+U5i7IE8Bv2SgSTNGSJMbfAlmQ=; b=yNEIqhBFDF5AeTkWwKSquzUI+8K4He2IqhGXQbsOoH+IVZQtDI6a1y0syj3M7mYo2/ Ea1iEmJMcsCOBKyB7Gppjppu/eLWrLDC0M2w5Nd4yQBcFUCa88Pn/Mq/CfdFswbZegVA igy47tWWPLc83Xv8NuwIRhIw5fsWvEc9PX+PTQPupuY78qNmCvyEAvWFE86DUGEwmKLq ufQhMAVjbVI4JiHHkYdBn9AkQaQS1W4LW4lFsBO9g6GbferkjBEEBUs+vi+mMnZrs9Z9 ilBx3XuTAhEeGtYZS+4l8rLLsvQ5ofi4AW79HA87EWTvESdKG41vf7sPJwacnt1T9kBQ eilA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=q8ZOJ0nG; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s20-20020a656454000000b00584e731e7fbsi7727957pgv.280.2023.10.08.07.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 07:57:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=q8ZOJ0nG; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7AF0D804BC17; Sun, 8 Oct 2023 07:57:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344829AbjJHO5b (ORCPT + 18 others); Sun, 8 Oct 2023 10:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234339AbjJHO5a (ORCPT ); Sun, 8 Oct 2023 10:57:30 -0400 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2140.outbound.protection.outlook.com [40.92.63.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F11EB6; Sun, 8 Oct 2023 07:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R2aHIwtqVtzsC3fIgp/rS6PKTqWp+BTjtAOOgH9G+lpZhq0W4COHrYAg2Tp1jMonhbuvguwOhKcCuNcQzkYyEVtrCAcccX5aj1sYWc4LW+m16ToJFk2BtwtuwMxQoOIA8faXO2R126DDPEGLMlITyVw+J+hudQXzhm97sXfL4i7f+uQQjH0Y0lgv+ev0sP8fkcoj3ieU7k7mjLSyRxNUUbtujfoFx4Tg+UnK51iyWawqGkvJ//5x7r2eDmZbuGzXSey3Sy8GbBPxS7PM/YdlLDhed7PYpuApU3FRAlAxcjpSt2pp9GIqF1nKXmfqHfAtXx/6CkRlLrByyoAq8DK+XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xaVtEI2qhZS1oaf1GD6pfFXb2t0VmkXD8ySWzedGCOg=; b=DD3LT+211aRgc/xu82MIVPJjxxRhS9lpm6BmYQra15ASapkmoNScC7KoPAuNFUEiRq+aXZD7fshPI+YZIloIwAZDfRmZdPZrq8Ff2N3icRtyovuhngzWEOoqg5hqInv29EcAENsefldGLE0qfNNq78VWiP6BGKdasLMEk3A4qtb9yt8RG981SzHx6/PO9N1cbPF4vFirHiWgsmMRWhVc+N0yVtCbD2gmrGDV6qwJCmVkImZXc2GMSBeiUN7QAJyWFwBeV2FRPBv0wlhRixnxNu13U7x4KXx64UoMHLv8kd8ZlJtCOrADuNh6NNAiMb4cPicdN67oHxzBc9zAiZ5Slg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xaVtEI2qhZS1oaf1GD6pfFXb2t0VmkXD8ySWzedGCOg=; b=q8ZOJ0nG9CezlFn/JA62IxEMYlsQ89/guLRN2hzSwLUR/jJr6Y86oRdzIaPfDj4EWbOcfydyrJ4BISs8oAt8q1zB67SiHR5TmqwxauvTHavqUT3EI4RfTlWu2MLcezScZNSUQ6etumDj27h62QA7vsyT+r3H2JYilFSUgZAlCzocfUbyXj/e3ofn+EUkWk3NH06iz458294Ie3xVgz2eiqdAUhULq57amQQALw1X0AVBczK2M3pK6D01kM3BbP7XS4F+ezHUChN1k+NTS9jmwJ5hCXpJWjjl9fA4eg+b1j1XNuylTtPKjC95r5/C4CHzi3nnIP4ZMo0G2spFdfGXyA== Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) by SY4P282MB1371.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:a2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Sun, 8 Oct 2023 14:57:21 +0000 Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8]) by SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8%3]) with mapi id 15.20.6838.040; Sun, 8 Oct 2023 14:57:21 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v2 4/5] perf kvm: Support sampling guest callchains Date: Sun, 8 Oct 2023 22:57:06 +0800 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: X-TMN: [mxPKa+D4OVm2IXQpeo58T38hSdmEF4oisq/ZqhpUqUk8kXqnb4yeoA==] X-ClientProxiedBy: SG2PR01CA0169.apcprd01.prod.exchangelabs.com (2603:1096:4:28::25) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20231008145706.7852-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1084:EE_|SY4P282MB1371:EE_ X-MS-Office365-Filtering-Correlation-Id: 22d375be-0d9b-4a9c-5446-08dbc80edf01 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S5HEydAcY269XC9TGJCQosaOfFgGHtCzYOydt41s6i3F6LHW06308AEma2GJO4qfscm3oEydZ7A7+J7RfQGV5Xv4q60kkyADqATVPggKRl3y4OVpIXAw05sH1eyeQ8Wu0245/47k4wR9+mdJ+Glyie1P8ZQ3n56TEt8IDzUdY4i562jGuELGLCnc6xyoYMD989cyuWOf13TNTpTF/M5ZoS5kYho9D1HYHOmmM7v09pHahdqdW+BQrJ/psq93wbjyNFBG8NDF1t2jW7rynGG3WvGMjOjqWkPRLmKFxZlHQBf0phPm/XGEzrg/Kp7PELB43zx9He0vFhKw9cA8p19CN4gH6+BP1fqsnlOAK/Erdyou57Aq7nh5pmmojUZSXRvcKec96rW2EBasiplQ7ZXCjZRXZYmIbvaeVzDkZSRfXIp438Z5r4mRg2NisRAgp+my3h5qt9u0GOzKxrdYj4PlhbE/GeDs9alTxbfcNBytFjIts9MaIQ7yZwIpghJKpgpz4OLiHemk8HvAZYCCgr4HSVQzPzHkPiJ5oDd54dPyKbkSCMepiSckSbAvw5qa0DAypvwVFAS2mPc9Rf5s91N4MU5x6/Frg3O2P/w8ozIsLTiU/s3zQ+dVoJAUfC6y2uQE X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UCxwr112mtbwbZKYgG+RF54xsB4PtQeS4trJk0rYIx4YJL53vGetv+qrOB9bSdHqyZVUe4ofdWK+EZiblOJvh4wzSY57Fj/L2cdxIp7jZqgg98b7uqiCsL5wI1W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5K8QPV9lD5mvkqiJEuWhsjkKScGlqoNMK4BeYmMKAe2KyDrd8r0MX8UvWEMKnKkpGQr93zJTxHjSAq3aEX3Di2 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22d375be-0d9b-4a9c-5446-08dbc80edf01 X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2023 14:57:21.1465 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY4P282MB1371 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 08 Oct 2023 07:57:48 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779199714587023622 X-GMAIL-MSGID: 1779199714587023622 This patch provides support for sampling guests' callchains. The signature of `get_perf_callchain` has been modified to explicitly specify whether it needs to sample the host or guest callchain. Based on the context, it will distribute the sampling request to one of `perf_callchain_user`, `perf_callchain_kernel`, or `perf_callchain_guest`. The reason for separately implementing `perf_callchain_user` and `perf_callchain_kernel` is that the kernel may utilize special unwinders such as `ORC`. However, for the guest, we only support stackframe-based unwinding, so the implementation is generic and only needs to be separately implemented for 32-bit and 64-bit. Signed-off-by: Tianyi Liu --- arch/x86/events/core.c | 56 +++++++++++++++++++++++++++++++------- include/linux/perf_event.h | 3 +- kernel/bpf/stackmap.c | 8 +++--- kernel/events/callchain.c | 27 +++++++++++++++++- kernel/events/core.c | 7 ++++- 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 185f902e5..ea4c86175 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2758,11 +2758,6 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re struct unwind_state state; unsigned long addr; - if (perf_guest_state()) { - /* TODO: We don't support guest os callchain now */ - return; - } - if (perf_callchain_store(entry, regs->ip)) return; @@ -2778,6 +2773,52 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re } } +static inline void +perf_callchain_guest32(struct perf_callchain_entry_ctx *entry) +{ + struct stack_frame_ia32 frame; + const struct stack_frame_ia32 *fp; + + fp = (void *)perf_guest_get_frame_pointer(); + while (fp && entry->nr < entry->max_stack) { + if (!perf_guest_read_virt(&fp->next_frame, &frame.next_frame, + sizeof(frame.next_frame))) + break; + if (!perf_guest_read_virt(&fp->return_address, &frame.return_address, + sizeof(frame.return_address))) + break; + perf_callchain_store(entry, frame.return_address); + fp = (void *)frame.next_frame; + } +} + +void +perf_callchain_guest(struct perf_callchain_entry_ctx *entry) +{ + struct stack_frame frame; + const struct stack_frame *fp; + unsigned int guest_state; + + guest_state = perf_guest_state(); + perf_callchain_store(entry, perf_guest_get_ip()); + + if (guest_state & PERF_GUEST_64BIT) { + fp = (void *)perf_guest_get_frame_pointer(); + while (fp && entry->nr < entry->max_stack) { + if (!perf_guest_read_virt(&fp->next_frame, &frame.next_frame, + sizeof(frame.next_frame))) + break; + if (!perf_guest_read_virt(&fp->return_address, &frame.return_address, + sizeof(frame.return_address))) + break; + perf_callchain_store(entry, frame.return_address); + fp = (void *)frame.next_frame; + } + } else { + perf_callchain_guest32(entry); + } +} + static inline int valid_user_frame(const void __user *fp, unsigned long size) { @@ -2861,11 +2902,6 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs struct stack_frame frame; const struct stack_frame __user *fp; - if (perf_guest_state()) { - /* TODO: We don't support guest os callchain now */ - return; - } - /* * We don't know what to do with VM86 stacks.. ignore them for now. */ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index d0f937a62..a2baf4856 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1545,9 +1545,10 @@ DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry); extern void perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs); extern void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs); +extern void perf_callchain_guest(struct perf_callchain_entry_ctx *entry); extern struct perf_callchain_entry * get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, - u32 max_stack, bool crosstask, bool add_mark); + bool host, bool guest, u32 max_stack, bool crosstask, bool add_mark); extern int get_callchain_buffers(int max_stack); extern void put_callchain_buffers(void); extern struct perf_callchain_entry *get_callchain_entry(int *rctx); diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 458bb80b1..2e88d4639 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -294,8 +294,8 @@ BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map, if (max_depth > sysctl_perf_event_max_stack) max_depth = sysctl_perf_event_max_stack; - trace = get_perf_callchain(regs, 0, kernel, user, max_depth, - false, false); + trace = get_perf_callchain(regs, 0, kernel, user, true, false, + max_depth, false, false); if (unlikely(!trace)) /* couldn't fetch the stack trace */ @@ -420,8 +420,8 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task, else if (kernel && task) trace = get_callchain_entry_for_task(task, max_depth); else - trace = get_perf_callchain(regs, 0, kernel, user, max_depth, - false, false); + trace = get_perf_callchain(regs, 0, kernel, user, true, false, + max_depth, false, false); if (unlikely(!trace)) goto err_fault; diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c index 1273be843..7e80729e9 100644 --- a/kernel/events/callchain.c +++ b/kernel/events/callchain.c @@ -45,6 +45,10 @@ __weak void perf_callchain_user(struct perf_callchain_entry_ctx *entry, { } +__weak void perf_callchain_guest(struct perf_callchain_entry_ctx *entry) +{ +} + static void release_callchain_buffers_rcu(struct rcu_head *head) { struct callchain_cpus_entries *entries; @@ -178,11 +182,12 @@ put_callchain_entry(int rctx) struct perf_callchain_entry * get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, - u32 max_stack, bool crosstask, bool add_mark) + bool host, bool guest, u32 max_stack, bool crosstask, bool add_mark) { struct perf_callchain_entry *entry; struct perf_callchain_entry_ctx ctx; int rctx; + unsigned int guest_state; entry = get_callchain_entry(&rctx); if (!entry) @@ -194,6 +199,26 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, ctx.contexts = 0; ctx.contexts_maxed = false; + guest_state = perf_guest_state(); + if (guest_state) { + if (!guest) + goto exit_put; + if (user && (guest_state & PERF_GUEST_USER)) { + if (add_mark) + perf_callchain_store_context(&ctx, PERF_CONTEXT_GUEST_USER); + perf_callchain_guest(&ctx); + } + if (kernel && !(guest_state & PERF_GUEST_USER)) { + if (add_mark) + perf_callchain_store_context(&ctx, PERF_CONTEXT_GUEST_KERNEL); + perf_callchain_guest(&ctx); + } + goto exit_put; + } + + if (unlikely(!host)) + goto exit_put; + if (kernel && !user_mode(regs)) { if (add_mark) perf_callchain_store_context(&ctx, PERF_CONTEXT_KERNEL); diff --git a/kernel/events/core.c b/kernel/events/core.c index eaba00ec2..b3401f403 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7559,6 +7559,8 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) { bool kernel = !event->attr.exclude_callchain_kernel; bool user = !event->attr.exclude_callchain_user; + bool host = !event->attr.exclude_host; + bool guest = !event->attr.exclude_guest; /* Disallow cross-task user callchains. */ bool crosstask = event->ctx->task && event->ctx->task != current; const u32 max_stack = event->attr.sample_max_stack; @@ -7567,7 +7569,10 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) if (!kernel && !user) return &__empty_callchain; - callchain = get_perf_callchain(regs, 0, kernel, user, + if (!host && !guest) + return &__empty_callchain; + + callchain = get_perf_callchain(regs, 0, kernel, user, host, guest, max_stack, crosstask, true); return callchain ?: &__empty_callchain; } From patchwork Sun Oct 8 14:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 149758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1403419vqo; Sun, 8 Oct 2023 07:58:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqOmiA6mZTK+ak2UndkaHbd5gG+WCN3PUcnceNmM6kwQj0hUMsVlC8ljyHK76jEV+0mhXU X-Received: by 2002:a17:90a:414d:b0:271:9e59:df28 with SMTP id m13-20020a17090a414d00b002719e59df28mr11562124pjg.29.1696777110808; Sun, 08 Oct 2023 07:58:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696777110; cv=pass; d=google.com; s=arc-20160816; b=V8NwmpDOQa3qgPwehG2QXGoibBoPZswg7BzF7s5M92sjgwfvlIn8NU4pe6FVHfMEvh oSPs44IabQyUNB5xO+XbVtELetbLox9Irc4U0kfrTBt2iVurOEp8kmjeH83iKUnh5ZYT XFitST87X9sQkTHsXaAKWfsKkNX0JW8ypAAIvvZdun20rPmVAgemmQIjHpYGsW6eTlAU vazQtH7ippKua0sxUBpIIaxKo9xKQkAUVnFR8r6yJy2xrvVi5i1SZCOwuiv8gmEeOZPI 9yqblRBEhlWMwSGHwljs30ZsnOojqWeVqyJzGz+fSp2AHy5qB5HbOB3hLzcXmUvc5qo6 KPAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I/lFtn/nLc2LrnucpQ3epHICG2GV9+ahNS6ImpVxMfc=; fh=F5FYRTUV4xCU93BuG+U5i7IE8Bv2SgSTNGSJMbfAlmQ=; b=mnCKJnKKhhkGhiHIfjHH9vGvQ6Zy/sUHlzb9onLenn9/RSdb7erqyLe3udaUsM+Q3f oi77kJxvQWjqXE6ZC+h985OXxCEkP1i3g0lqC/A7towN4Fd7hmuA8Rv0n4dt3ly26/Wf sIVPfen8C0EU+H1caf55Tht5OB1VQgUbOVv7CeucaQv9pmsZhsVwEOG2ddOFXOFUZ+de OqDliypDs6soZDuhmebhdVLqNCZrDiq1QsCDFrhWi0OHVvE1eSj2ooma4G/OKnfhCVG3 zx3vCrJRWzQ0UklZtGrcOhXxf1NGDnFl+bk+Zzb1H7UEArKMcrC5qRmwCUXxL0Xow1BN fEQA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=FKhXYTsr; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id kx5-20020a17090b228500b002766354b7b2si7768163pjb.153.2023.10.08.07.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 07:58:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=FKhXYTsr; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DDE2A8026830; Sun, 8 Oct 2023 07:58:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344866AbjJHO6R (ORCPT + 18 others); Sun, 8 Oct 2023 10:58:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbjJHO6P (ORCPT ); Sun, 8 Oct 2023 10:58:15 -0400 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2159.outbound.protection.outlook.com [40.92.63.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3FD6A4; Sun, 8 Oct 2023 07:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nYHA7nfuRuhvLMy72MpWJ4mK3Jm0xZBoL4TvC3AZpUGkObu3MqIGpPAdNq6CRxINikHisMUbFuSjGEW38COSqRnkdr0BS1DGvEQ9QHfyr/27lCyP6i6gPKQCOluAdUv1ijgPUhEDqzJLAC9iKs1IDbr2WB3w8TnEsncomocLtFx6xqk/qr1o+fQK5rVVpDVRLH/96fyWeprLL0SJ3+tT9CwDGbCS/lUcdfEAfR/vWTU+poS2FW3bG7UUM+j+xYxfelQ8Pgdnj2uWlolyIOXOqLALv9jxTtvHsmiwl++kzpAkfHeTjwFAW3ihnqKl6P9flpSLpTT5fbWlYXEbut82pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I/lFtn/nLc2LrnucpQ3epHICG2GV9+ahNS6ImpVxMfc=; b=TkGgw0cIwiupQksITQIn8jAh0E54fPLFY/XgrbEEwAiUI20Z6gsXfFk7YK+4wEdrVZL72hlU/UR232OEju1DszJGkUVQmkunHFUzz7KkntaX8a5aoUEO7zqby4cLCxW+HXdRO7Pad/Gvn0M+4ZuYe8LCLJhk+YC+Q6U6Eyaif01HL7FGbG2fsohqqdku4QU/1SLpVNOudvIvZgyIfhyZACRmNICa/tpfk7Rkgl72RDr4aJxRXNEuCWpwDQb73ydN6FaOPweVXebbg3OZCKHk+wXt0raryqspNrob9XxJxEfXA0nd/9/FmjLgXLq+Pw5NZiLUg4DDTgfLYnbGR2cpxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I/lFtn/nLc2LrnucpQ3epHICG2GV9+ahNS6ImpVxMfc=; b=FKhXYTsr2zTk/gvEePAaOzVmVfxlx3K2gXV4OWq4nlAeFmALWbAbOAA+tZ04CR1hcUeHcLj2mdGbmmqAreDA2dE+618R5jU2bbzf+QoxyJWx/66qtESsEu4rOyaKQFhwq/GXSqOHTkLpRHGQmVn4rD1N9hxla2jYhKfWdfHh2pUqVRoeydGjQnsEiQXYu2dP+RIP+P6c1wlRX5GU0442yW46ciOBVvrk1u7BRUW2swZmARqXG8E6k88WTItcfFuvjUyTkaXmxX/SSdLtB3nV3WJxiLTGxZgH0tNiWTISUgmt/o11x+nVcftwMJxEEYfgtu9MQcOdZRBR+HAMAu127Q== Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) by SYYP282MB1101.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:bf::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.36; Sun, 8 Oct 2023 14:58:06 +0000 Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8]) by SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::e39e:17fc:36d8:1ea8%3]) with mapi id 15.20.6838.040; Sun, 8 Oct 2023 14:58:06 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v2 5/5] perf tools: Support PERF_CONTEXT_GUEST_* flags Date: Sun, 8 Oct 2023 22:57:29 +0800 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: X-TMN: [brT8iFehEOwCNXRw/nHup347yUJJMi8XhYPK+wacExEAGNvB18G62w==] X-ClientProxiedBy: SG2PR06CA0235.apcprd06.prod.outlook.com (2603:1096:4:ac::19) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20231008145729.7886-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1084:EE_|SYYP282MB1101:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c550b0c-fb1d-492c-ce93-08dbc80efa0a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KHeHlcHDe59T0Nksh3RMSTCkhCHOh9vZsPg/95V2XqN0q2P2+7r29qRIwKl/SpRRUHFpxFWeQA2OWsl3JMvr98XswCt7ZZkNa0XhTUQ0576IDW9Op3WoUzC1o/mJyyyK0W/deJGGZPVKkVhCwNjrOqE3jGe6gSyG8LX2bDNDTjs0QzFexZvY5uR1Lkbm+Wsh6edF8mdkMeLkoCKC5X6ApUHQWFRB1KAr07rKdcQhVsZA8Kgahnj67XsmXCYq0BU7gTDm+AyCnG5SZtR6kxNaDTt1GGFW5xjcIu2ytfgs1OJ1vlHfHdE8pDgMpQUdsYERkTBpoJEr+I0ytXrwWQEOF3edIAvJdN7d1zfhwYxBJE6dyVgJQV7qEjE+9EZHflohxX2T59pgd3BYjKndmKiapv4okGjGKGgoCOdUoVRI/k0zerPYAyUuSwfa1z4zk4pqg/QFYVjN8YVEuSiAM2/F4UE0dc0sNQrrrP3c7d74zR8RkJAXfdzh5l5ntC6BlckEUA1z8MAob0rqQQQllxVmqMfM49i4BFAOix4tPTz/GNCWgWJsnDeOaBA1PXUaHzQlmmGyZIaA9oHGSjsW5FrZPg5jUtubzil3k5ZOXMbuZ3SJkvfFPOMe4BWGcQIE9vbG X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +73wY44Qoc4JgWLeOlFDx2MdotZXzfNBpG1vDLXXeAS77wHJ6rAV8Em7MIWp4wS4b5KEJOVr+TqtGtc/EnWLH8bxZwm2ECFoG2HC0eEFiMogpDhqWln19jDu7DCU52FlF8JD56pMvo8wj+j5XW163sn/Rex5gMh02odQ73H4z5OgQEcd1IcnRyysmTxC1JtdfBWtWWq4x9Ll+t60vEOldCa1nbBGo0GESV61Z4t1/Pa3G3JMaZ9V+A7G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b1d-492c-ce93-08dbc80efa0a X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2023 14:58:06.4846 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SYYP282MB1101 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 08 Oct 2023 07:58:28 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779199755919469843 X-GMAIL-MSGID: 1779199755919469843 The `perf` util currently has a incomplete implementation for the following event flags, that events with these flags will be dropped or be identified as unknown types: `PERF_CONTEXT_GUEST_KERNEL` `PERF_CONTEXT_GUEST_USER` This patch makes `perf script`, `perf timechart` and `perf data` to correctly identify these flags. Signed-off-by: Tianyi Liu --- tools/perf/builtin-timechart.c | 6 ++++++ tools/perf/util/data-convert-json.c | 6 ++++++ tools/perf/util/machine.c | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 19d4542ea..6a368b6a3 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -536,6 +536,12 @@ static const char *cat_backtrace(union perf_event *event, case PERF_CONTEXT_USER: cpumode = PERF_RECORD_MISC_USER; break; + case PERF_CONTEXT_GUEST_KERNEL: + cpumode = PERF_RECORD_MISC_GUEST_KERNEL; + break; + case PERF_CONTEXT_GUEST_USER: + cpumode = PERF_RECORD_MISC_GUEST_USER; + break; default: pr_debug("invalid callchain context: " "%"PRId64"\n", (s64) ip); diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 5bb3c2ba9..62686f78d 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -205,6 +205,12 @@ static int process_sample_event(struct perf_tool *tool, case PERF_CONTEXT_USER: cpumode = PERF_RECORD_MISC_USER; break; + case PERF_CONTEXT_GUEST_KERNEL: + cpumode = PERF_RECORD_MISC_GUEST_KERNEL; + break; + case PERF_CONTEXT_GUEST_USER: + cpumode = PERF_RECORD_MISC_GUEST_USER; + break; default: pr_debug("invalid callchain context: %" PRId64 "\n", (s64) ip); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 88f31b3a6..d88458c3b 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2346,6 +2346,12 @@ static int add_callchain_ip(struct thread *thread, case PERF_CONTEXT_USER: *cpumode = PERF_RECORD_MISC_USER; break; + case PERF_CONTEXT_GUEST_KERNEL: + *cpumode = PERF_RECORD_MISC_GUEST_KERNEL; + break; + case PERF_CONTEXT_GUEST_USER: + *cpumode = PERF_RECORD_MISC_GUEST_USER; + break; default: pr_debug("invalid callchain context: " "%"PRId64"\n", (s64) ip);