From patchwork Wed Jun 21 01:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 13286535 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 3BE65EB64D7 for ; Wed, 21 Jun 2023 01:40:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qBmp2-0002lx-GG; Tue, 20 Jun 2023 21:39:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBmow-0002ky-Su for qemu-devel@nongnu.org; Tue, 20 Jun 2023 21:39:42 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBmos-0002Ha-Bz for qemu-devel@nongnu.org; Tue, 20 Jun 2023 21:39:41 -0400 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KLYDDo025936; Wed, 21 Jun 2023 01:39:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=iAdDFB8J0UJSnGaqk23VK+eckCBr9BJp9Ww9tZvUYTA=; b=am1OE5lX2lJ667ff68i7mKnsYu7Grx3RcuiRz6x9ncpRhSUxMB71Sc7JNCNcnKKw0eiF olc4cc4dvkBjpoJij9wftB+IZfTMQe3Nw3ALmPRPEUvOyWwinHCJLpyrGEIqRgmXsdSb kbRQVZo2UVlDIwuVJhlOfDI8arzG1MvI1gXjllxZdIWbIFG4NL21dGz6CY5qjMbvBJtg Aushh9kLSHuSiCG5iu9B4jYmbMVBt1mHH+3ujfXYAdFg3tlS1Mc0Pd9sJ5DE3fDZ8W6/ eF1KwNjiZ6WxwQJ+0Gsd20p8WadDqO7JFZ3wt1SspLOYcdGDjo59CMJbUodE61+/oXUC vA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3r93rbp7qg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 01:39:01 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 35L1KBiN005872; Wed, 21 Jun 2023 01:38:59 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3r93955fq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 01:38:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZcOc3m5AMWEYoT6ct1bJxabNu4gGQkOaY5Lr4u8wSF1TnUbBjuOFyEEjy2eMQN30YHpDmGgqOuqq+4XlHhUHKplXvXtZDtgWS5wLDjVY7hWTbpx3Gk2tQWm4nglZG+iC4IsEsdSZVEBSxkLa/S71CnDaLzfb6qbT/ODq+P7n1/drIkUKSS1RjWrRh2Q1I0Hv7MWsFX8CeydqWpE8MjQmpF9BYmJYxpZlz7hFKPg9ayZ9Pi1DHn6Lt39NiT+2h3WJMkzUNaaM81NS43YjXhAoyRDiDeE27BIRHYuZx6y9+bOo3bRzjVK53aNj1ALjCybSERomGroWx3Im9Usm5qc6Og== 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=iAdDFB8J0UJSnGaqk23VK+eckCBr9BJp9Ww9tZvUYTA=; b=DztO4u2VGU/ba6qKXQYghImD73sMCuB7QlkvY5RAVcYnASyAZUTlLrvdidRQJJS0Pv2F5gaVVJfXe4NoWywL4m/j4bck0/zRcq5OlaB7NTZbB1pBmKzwFZ2m//AunagIGmamRrNZAmy6AYLJ0GmWe4lL/2dGNRGwJhLE7VhRGfvw/jJdg4S53iAgmO+XWmjozZeEzgDZyPgJY6805K1MVWix/WE3ZynxY5d8Hzs3z5iTH5ZgWsAohw+DRrGBsgH3MfWHi2pAGR8jcAFUA74ECp60lQJYsO84UHCdnxX140Yk3FIl4YujQM5Iz3A84zFCqeeFCDUYKoJrEX3SEaNq3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iAdDFB8J0UJSnGaqk23VK+eckCBr9BJp9Ww9tZvUYTA=; b=fhs3lD3dILoQLRoig4q0rz1NBKPia9nmoH85wAgQb7gPHrF3nEVV+tSYv+pqnmbtY9baXQLMWwPjz/1zFAW6FK2PsEvOk/xJDlzRDmTExpiFGo1PxGFs8ympTVt5T4SlppRLPREojrIH0qQh/0+UjwVuzcu/tIE6B7aR25aVCfU= Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by IA1PR10MB6783.namprd10.prod.outlook.com (2603:10b6:208:429::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Wed, 21 Jun 2023 01:38:57 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::96aa:8e73:85a9:98b9]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::96aa:8e73:85a9:98b9%4]) with mapi id 15.20.6521.020; Wed, 21 Jun 2023 01:38:57 +0000 From: Dongli Zhang To: qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: pbonzini@redhat.com, mtosatti@redhat.com, joe.jin@oracle.com, likexu@tencent.com, like.xu.linux@gmail.com, zhenyuw@linux.intel.com, groug@kaod.org, lyan@digitalocean.com Subject: [PATCH RESEND v2 1/2] target/i386/kvm: introduce 'pmu-cap-disabled' to set KVM_PMU_CAP_DISABLE Date: Tue, 20 Jun 2023 18:38:20 -0700 Message-Id: <20230621013821.6874-2-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621013821.6874-1-dongli.zhang@oracle.com> References: <20230621013821.6874-1-dongli.zhang@oracle.com> X-ClientProxiedBy: SA1P222CA0030.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::6) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2663:EE_|IA1PR10MB6783:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e9a0d65-f17b-4d35-a7bb-08db71f847a5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V89G9nB0c937q01oeiqr0K0N8i80lAjxGtQVs7Wc7De0eJdFQ8489rM6rcJD0pKdZcp+D3MHwkyx8EwSzM1T2Uw/wXtgXOXNJdWCejVcQEO+e5pyRDuHNHT94MTSGCtgzSMWUmFYiLgYnbsquffJf3sFrjbdiNxdt6DD9uCUOV36BMIs3pvJvlCceyuloSwtLJMn1oey1BjMtMHTyYE2H/xID84l7AwPVu/qjlNJ0nK06nSB94A75B2SMJMzogrIm+wz16Rez9Befb9ikUkj9CkQSp3oIbXBBoimKitYFZ63lX6uYUxOt98p4jCo6VQG5j+w2dKjntfiIuJncq5/XM3EVD7sv0xcLxUfoYAuJj4B5iv94akn7kKMjrPe4t+Hn8/DIOvO5VYAldAMDhtYhdHD/SNoIp1SPt+/gQo3TxpZR6ysHAOf3WXBixHG06xzCREzS+zAEImpYS2rmTxe13qFP/+ydYRXK3bBidFdEgjCjBPYuwV509syd0cY5qPZnW12ZPfpUhnqYbP47Xw+yGzVV/jAMophK2YOX37oZXh+f9HcLrY5tN4jmwT3TdEk X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2663.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39860400002)(136003)(376002)(346002)(366004)(396003)(451199021)(2906002)(41300700001)(5660300002)(44832011)(8676002)(36756003)(8936002)(86362001)(478600001)(26005)(6506007)(1076003)(6512007)(186003)(6666004)(6486002)(66946007)(66476007)(66556008)(83380400001)(4326008)(316002)(38100700002)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8VBn98GGCg5X/eOM5cspfcyUYkw+5Ei71Ry/BOXqBNP6dhGHseHG2MeFBoYNqQ8aBbDstUcX/dlnAlbESyY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4Y6LvEgraWgYyuUufjXONp8EIz4I9QEoj8IhOb5R53+pc9qkjeG1GocXvgNSS/0dGb8g13G5a6mA0j/HK6R/kLhZd/E8hFO+Hkx6ifmamaVAsYkERxkx4QE2epH3pPCyYYohUXiwMRcULxp4FCYvkdQAWn29FUH48Fp6n/rWl+u7nJGoIHn2RII7sVpamh9o2DcTOIOsQdp3DTk23si1h86L8oqIZ6f67FstxbJU/SoqhFFuvAjDLXiXs9NufyZczS7AsJ+jdTjtyfqCEVItE5n29EP62gwNVySDmwV+cwXpoyt2ou1HuxLKMX7INvnKyGjzZeH2OGXrCxZt8Z0uSt5E1/e6k/ibhQG5WlD0MiJxDrmxjrGKif4Wgf2gtt1DvRV2CqVn4AmOpKiq4L6rCNhGZIA+lOeqcpd4ykvwKNCUZylcPoNOs1JE6FM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e9a0d65-f17b-4d35-a7bb-08db71f847a5 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 01:38:57.2975 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dkT1GhHszlUYSaJrHGSzUm00DYoHayJpQm7gRoDvfKBuBSqK5I34WOe+C9hC/Jh0I+j8NQi9VS5g//C4/bXuFQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB6783 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_01,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210012 X-Proofpoint-ORIG-GUID: 5G8uJScsKhy3f6MUOVB7LYIvXVb_jGAD X-Proofpoint-GUID: 5G8uJScsKhy3f6MUOVB7LYIvXVb_jGAD Received-SPF: pass client-ip=205.220.165.32; envelope-from=dongli.zhang@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The "perf stat" at the VM side still works even we set "-cpu host,-pmu" in the QEMU command line. That is, neither "-cpu host,-pmu" nor "-cpu EPYC" could disable the pmu virtualization in an AMD environment. We still see below at VM kernel side ... [ 0.510611] Performance Events: Fam17h+ core perfctr, AMD PMU driver. ... although we expect something like below. [ 0.596381] Performance Events: PMU not available due to virtualization, using software events only. [ 0.600972] NMI watchdog: Perf NMI watchdog permanently disabled This is because the AMD pmu (v1) does not rely on cpuid to decide if the pmu virtualization is supported. We introduce a new property 'pmu-cap-disabled' for KVM accel to set KVM_PMU_CAP_DISABLE if KVM_CAP_PMU_CAPABILITY is supported. Only x86 host is supported because currently KVM uses KVM_CAP_PMU_CAPABILITY only for x86. Cc: Joe Jin Cc: Like Xu Signed-off-by: Dongli Zhang --- Changed since v1: - In version 1 we did not introduce the new property. We ioctl KVM_PMU_CAP_DISABLE only before the creation of the 1st vcpu. We had introduced a helpfer function to do this job before creating the 1st KVM vcpu in v1. accel/kvm/kvm-all.c | 1 + include/sysemu/kvm_int.h | 1 + qemu-options.hx | 7 ++++++ target/i386/kvm/kvm.c | 46 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 7679f397ae..238098e991 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3763,6 +3763,7 @@ static void kvm_accel_instance_init(Object *obj) s->xen_version = 0; s->xen_gnttab_max_frames = 64; s->xen_evtchn_max_pirq = 256; + s->pmu_cap_disabled = false; } /** diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 511b42bde5..cbbe08ec54 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -123,6 +123,7 @@ struct KVMState uint32_t xen_caps; uint16_t xen_gnttab_max_frames; uint16_t xen_evtchn_max_pirq; + bool pmu_cap_disabled; }; void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, diff --git a/qemu-options.hx b/qemu-options.hx index b57489d7ca..1976c0ca3e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -187,6 +187,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, " tb-size=n (TCG translation block cache size)\n" " dirty-ring-size=n (KVM dirty ring GFN count, default 0)\n" " notify-vmexit=run|internal-error|disable,notify-window=n (enable notify VM exit and set notify window, x86 only)\n" + " pmu-cap-disabled=true|false (disable KVM_CAP_PMU_CAPABILITY, x86 only, default false)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) SRST ``-accel name[,prop=value[,...]]`` @@ -254,6 +255,12 @@ SRST open up for a specified of time (i.e. notify-window). Default: notify-vmexit=run,notify-window=0. + ``pmu-cap-disabled=true|false`` + When the KVM accelerator is used, it controls whether to disable the + KVM_CAP_PMU_CAPABILITY via KVM_PMU_CAP_DISABLE. When disabled, the + PMU virtualization is disabled at the KVM module side. This is for + x86 host only. + ERST DEF("smp", HAS_ARG, QEMU_OPTION_smp, diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index de531842f6..bf4136fa1b 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -129,6 +129,7 @@ static bool has_msr_ucode_rev; static bool has_msr_vmx_procbased_ctls2; static bool has_msr_perf_capabs; static bool has_msr_pkrs; +static bool has_pmu_cap; static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; @@ -2767,6 +2768,23 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } + has_pmu_cap = kvm_check_extension(s, KVM_CAP_PMU_CAPABILITY); + + if (s->pmu_cap_disabled) { + if (has_pmu_cap) { + ret = kvm_vm_enable_cap(s, KVM_CAP_PMU_CAPABILITY, 0, + KVM_PMU_CAP_DISABLE); + if (ret < 0) { + s->pmu_cap_disabled = false; + error_report("kvm: Failed to disable pmu cap: %s", + strerror(-ret)); + } + } else { + s->pmu_cap_disabled = false; + error_report("kvm: KVM_CAP_PMU_CAPABILITY is not supported"); + } + } + return 0; } @@ -5951,6 +5969,28 @@ static void kvm_arch_set_xen_evtchn_max_pirq(Object *obj, Visitor *v, s->xen_evtchn_max_pirq = value; } +static void kvm_set_pmu_cap_disabled(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + bool pmu_cap_disabled; + Error *error = NULL; + + if (s->fd != -1) { + error_setg(errp, "Cannot set properties after the accelerator has been initialized"); + return; + } + + visit_type_bool(v, name, &pmu_cap_disabled, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->pmu_cap_disabled = pmu_cap_disabled; +} + void kvm_arch_accel_class_init(ObjectClass *oc) { object_class_property_add_enum(oc, "notify-vmexit", "NotifyVMexitOption", @@ -5990,6 +6030,12 @@ void kvm_arch_accel_class_init(ObjectClass *oc) NULL, NULL); object_class_property_set_description(oc, "xen-evtchn-max-pirq", "Maximum number of Xen PIRQs"); + + object_class_property_add(oc, "pmu-cap-disabled", "bool", + NULL, kvm_set_pmu_cap_disabled, + NULL, NULL); + object_class_property_set_description(oc, "pmu-cap-disabled", + "Disable KVM_CAP_PMU_CAPABILITY"); } void kvm_set_max_apic_id(uint32_t max_apic_id)