Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1440950rdb; Sun, 8 Oct 2023 07:56:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3ew2jPl2O2TAE/2rCzivtE4OJkedUmfJ/avIhkWgbEavwyT9an2SxBSMwyD66o0BNB7kn X-Received: by 2002:a05:6808:15a6:b0:3ae:4ca9:cae5 with SMTP id t38-20020a05680815a600b003ae4ca9cae5mr17702452oiw.21.1696777019251; Sun, 08 Oct 2023 07:56:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696777019; cv=pass; d=google.com; s=arc-20160816; b=i8fKFvq7zOLwYjwcWrp5XhXG678eSv0GLjDkVdbQjrbjrTg+4Z0HG8+qiQkpwvtDqu hvYpnULg272+eZfAptgo7DjUgifbwqFEjE/xNb5X+u/Yr2i5gFkjm8wiKvR9QUcQS1HK D3nRrUV3xcsXkbK/M/a1rkhdNTLmup4Ih4ShJUCQvelBqJewmqyqwjppQFIkDgJcVKz3 l0xNjiwm1MIiLgbYqp0YZb/+hLEen2WlrExWnXwmDcyh8iA+QPmiYvhhvgBGFgZcLO5U zJqtKodJfcfyCDuHzvRmckleFZjR68BrasR/s/e2mX5STC+Jo1kiFPvhRlegrwjyWirh QY+g== 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=tApWIMZaO912qHnzgVfU6tDTZddSnki3baiHmbsKoeM=; fh=F5FYRTUV4xCU93BuG+U5i7IE8Bv2SgSTNGSJMbfAlmQ=; b=b2q9Fa3n2JcvNoniWyXs2FuyPcDBu4b/1gdurzUMYrEfm7WC5ai4j4J0YF9uG3oU1c 9v2dW8bs0g77ZFeHdTC/h0HVsXKOmqu1GOL0i9vFy2BRViM0NQBIHLWUsr3KAeUS+acI So9IUZLF8kc74ugoOHzQ0LE985aN7Lx/YBCCU+Ue7PDwfOsbKhvy+NSMISXc36r8mwVS fhJprrU5jtVCEaAi7vIhL7aQpI+H/vNKvPddH5vl/6m4X16CaSG+NAkXhevjELcxYiRb IckclKeWiT5gLKGZq4ZTcE3b/T74mCNlcuBwu4Hon+ZSDCdddlzXSOUrQhpTlXPWiFGP rxbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=PbdJ6mzn; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id i22-20020a056a00225600b0068fcccf5c79si5388312pfu.220.2023.10.08.07.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 07:56:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=PbdJ6mzn; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id C76778031D0C; Sun, 8 Oct 2023 07:56:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344886AbjJHO4n (ORCPT + 99 others); Sun, 8 Oct 2023 10:56:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234339AbjJHO4m (ORCPT ); Sun, 8 Oct 2023 10:56:42 -0400 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2148.outbound.protection.outlook.com [40.92.63.148]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 387AFB3; Sun, 8 Oct 2023 07:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k2w3skakuJlkm6qU94OPPsF2EVMYow5tcxyzOBqNC5KV3rsY4JsvwaymYrj9z0wi8OFq47UK4bx2JOW75lyO/1UFC3li0yn2G3MlZzFi6Tb68oQYHjCrVSLuv5mqDo9OA2u8TF6x9w2j8C2L+QktwCKzQESIeoFfFfPAOF8AX3S9WKcTJajXfJW6hPotpgUGsxUwjS8a8mAjnT2sNry7kIhUit5dr3GIho1AKm16fOjt8emdF/1Eb4woNR8YmX0vBcHLa2aYtiE2VxK0gTm3KPuogaUVUAmECLPgWK9ykdJP+XElPBHVX+LQgB0bppdHeQeyBfjYD5pwhqhpj397Hw== 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=tApWIMZaO912qHnzgVfU6tDTZddSnki3baiHmbsKoeM=; b=ORekvS5GsTwP/4nnk/ho5aR+VWwq1aIDyIATQRIf0UYNJt0fuTVeOKoWqx1wiUaPetqfg8IuL+GQi9gZ5rdY7wsB6QGMKwZDyRHOlST+0NBubvz33Pe2jJC/Y6YYheo8TT+NEEI/ORDJ/0Kn/9Y+6G/L9mR4xaawkfN8Ee3Xx/pXYvyCTXvwZ9It04xkic/2Q75dImb/0IFq0b2TvH4iT4OqSygyqB40w5FipxE3LDNGVR9kyEo4XNNDB901OJVR4VS75oVUmHwGiDSpvAf4IgIOagzPP7qn6JC1KmdNh6NhPqFu1qPj8C0FfzwfdeZlp6IEirBuxLTEBc2/XRbZ8Q== 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=tApWIMZaO912qHnzgVfU6tDTZddSnki3baiHmbsKoeM=; b=PbdJ6mzny3jLJ2WMRXRjX7nB4ZMaQ8Ew3FO7JQLtL1ZoiVFRBAsfWsR1fv1sGThN/0Rmnkhv5aJEgqgDzZz5oeQgvHmKkIB1hphQFTwPq9mlacGMMgK0y0x7GIo3/paLkko1D1danJwybUDKXOWrP46me/lNeKJKoTkRv0H/OTL54bqUKry9GuchWwlj1o9nbNDJ9HhR0PNISLY4iZb1NXx2I7vdj3l5VH9nnu0heJfGMzBxU0D/Zk1FbRSrC7dslJZ2vT57hXh7rHXX5m9FcAq7H44ABK88O5PJK23PM62v5AAbZyr19PyvCUKXeE14pqmWBXIrE4b3ZF2z0iRf8g== 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:56:35 +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:56:35 +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 3/5] KVM: implement new perf interfaces Date: Sun, 8 Oct 2023 22:56:10 +0800 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [xAU9EoBRPnMxN3DdhbNcR6zfJ7d1j812xI7i1Rqnz4Ym4NO0kHakmw==] X-ClientProxiedBy: SG2PR02CA0115.apcprd02.prod.outlook.com (2603:1096:4:92::31) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20231008145610.7786-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: 579365f9-de45-481a-6905-08dbc80ec3a4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2pLdw1fhNxjH2oJDI7HUaoka2KzQiAM8nDT1rptY4gsQ0pLrQnT8M9GV/QqoIexqrl/g/hMTxV1vfaGgZLtmuFr2npiPSHf71OrD67n9bx2zsfs12Jd5qg6iu77Vv9QkO2RQcSK+iSjCY7kVFMODbvdobHqSUGKtYjbGbcQ2yKqWEmCpbSFI8dMObD4Bnc3Wu9+Gap6KTDnJgk2MY3frRMR2Wwfrpwam3mTQQV5wqrw6TV/LN5mZflIigLNxqafBBKVYoaQVwfiKEU4yIkm5/DYH3jjzyFfEugINJ6ZGFOft/KRvodSATmMNkXU07f+u+M449j4rK92lo5fvDJ681aUcYfz5binCDZ/HX62vJWZ+C7ad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QohZ?= =?us-ascii?Q?+d74drTyo0NkHni8A8XkbmVSiPfBa6Zfw3/Z1sAiQrdRrG8etBs88EdBAnac?= =?us-ascii?Q?R9m9jNL3RXTLDdlJGi7F4crapL6t+A/fKYKBBcb9Hj6FlTzI6yZ8OMlq6Vwx?= =?us-ascii?Q?ia5SvSNtBJuENpKUN0MeH2lY/Qi+4yklcCmEp8DBjM51G39+NmD7h2sxg74Z?= =?us-ascii?Q?WU0Zxh19idkV953GH192/9jx32rSjjAYaqeunLaI3xZxGNISgppivfQScmdJ?= =?us-ascii?Q?YGebMvyluC3oVdUqRnk7zlsEtzKVKVWxvM2jPYMEJIFnmCWe6j2+xk8FN4da?= =?us-ascii?Q?kMSgDTvwm4EwBmmYRTm/77Ct0Ao36JvnhTzL6NfaS1N0huY+OMUoq8oWVD1W?= =?us-ascii?Q?Td0MgkK/VRL8r/a7TVLUZsdSXCa6r+h6DGkk0dDUPFpK8CM5d7rSLGbPILBq?= =?us-ascii?Q?ub4T2sxrI0IgR44SOznyZ9JmCVUKDPUTUwr8KYJ2LL8Vkejd1Mcovl3aY08d?= =?us-ascii?Q?lbKhME6qA00WG1NlP79srFRUB9zNpD7+nrss/b71zKuK/EzxiJvz7lLCwPPE?= =?us-ascii?Q?mw7f9PhTWikirWPNJaCN80B5Huc+T0LLcsuJ9ALXP6Vqyha9ss7+H3fNqHsi?= =?us-ascii?Q?BgtyHGC14hMbDa67U3hIkT4n7JvyxkZKnAXxGJJQarpK42+83zHR7icnXoXb?= =?us-ascii?Q?WHkdbYOOxQJwtbIN66IT?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 579365f9-de45-481a-6905-08dbc80ec3a4 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:56:35.1163 (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 fry.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 (fry.vger.email [0.0.0.0]); Sun, 08 Oct 2023 07:56:57 -0700 (PDT) X-Spam-Level: ** This patch provides two KVM implementations for the following new perf interfaces, just redirecting them to the arch-specific implementations: - get_frame_pointer: Return the frame pointer of the running vm. - read_virt: Read data from a virtual address of the running vm. Signed-off-by: Tianyi Liu --- virt/kvm/kvm_main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 486800a70..6fd6ee6c0 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -6018,6 +6018,9 @@ static unsigned int kvm_guest_state(void) if (!kvm_arch_vcpu_in_kernel(vcpu)) state |= PERF_GUEST_USER; + if (kvm_arch_vcpu_is_64bit(vcpu)) + state |= PERF_GUEST_64BIT; + return state; } @@ -6032,9 +6035,31 @@ static unsigned long kvm_guest_get_ip(void) return kvm_arch_vcpu_get_ip(vcpu); } +static unsigned long kvm_guest_get_frame_pointer(void) +{ + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + + if (WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu))) + return 0; + + return kvm_arch_vcpu_get_frame_pointer(vcpu); +} + +static bool kvm_guest_read_virt(void *addr, void *dest, unsigned int length) +{ + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + + if (WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu))) + return false; + + return kvm_arch_vcpu_read_virt(vcpu, addr, dest, length); +} + static struct perf_guest_info_callbacks kvm_guest_cbs = { .state = kvm_guest_state, .get_ip = kvm_guest_get_ip, + .get_frame_pointer = kvm_guest_get_frame_pointer, + .read_virt = kvm_guest_read_virt, .handle_intel_pt_intr = NULL, }; -- 2.42.0