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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CF37C74A4B for ; Mon, 13 Mar 2023 10:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbjCMK50 (ORCPT ); Mon, 13 Mar 2023 06:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjCMK5W (ORCPT ); Mon, 13 Mar 2023 06:57:22 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2070.outbound.protection.outlook.com [40.107.220.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A17D5F6FD; Mon, 13 Mar 2023 03:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SqzpG0Dqotzwo4OLKzXzLGBzD0qCKWT2qC7Z5cvZC4hOX0LwcNCrU5/ezD+AKOILj3B7mV/ZZWfl989ceSSt00jr7lAmQ8G0+lVoGa1rwcBgPsjG72YuQUYSLf3U3iyFKn1/gQKXy7eStC7kKXtRG4ikkTNFMK4uggB7yViegKOdGso2Hys96iZsUPJdKzEBVg4/1pHkjYt2G0VPWO8evIPpaDEk3N2J7XrC8pSiduh4p429OXMJSC04tlQ/T1L6H+akuaZndZlJIILFP6IAlqX8ctg6GrliMAB6fRpKQUFqoQl5IRbPL4hkk3AASkk6SyG4rLsSPG5zNom+JvG7Nw== 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=gAqZw+yue5lZLefqokK15pK9470MSOyUf1NKyGPgbow=; b=OmFA9XkBBclFNMf92JsLJqmWqdHe8aqcvBugH8U8s8GOA702t8BBw1th00IUmk7eSbxtRTIjriKYQsuQHh7GmZ1O+oQpxWefnzYIBd8PzO3bMk3Tpt9LBQZ/yLgRZZkThnLIJfcbndAWNgtrJu1Ii9u/QRmYqfpUYdcqG2bCvrCoqlzVU8QPvAtZ+chlF0eVrHwMoGU7yLF1SQ4oDcKS4kLdAkDN4fB5KxqAwpZLRei1kBX4ZAvUgeHLTX+9HhdSmD7Ej3cvQ3MT/Dy/O/aWWNa7geKjsW1xgdbGOIN9XyV1CCEFzA1pGOL24XXx9/Hx878vQWoq9iVVDe1bgkm/Ww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gAqZw+yue5lZLefqokK15pK9470MSOyUf1NKyGPgbow=; b=PAxaAGeEyLpPuiKpMvcLAfTHQ310DY7DTV0PLjiAfvwlmI9e2Cq+2D6KlZIIT0Z54N48bb2ekRqIwM0OPOFS5Alby87R/6JAj0ZOBTTDj8x088MOe6CNxUYt7EKSbxfW+ZXuRTWZoIeHZADhcLyIliQqBpY64LmGbeZ8GZYwm94= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB5712.namprd12.prod.outlook.com (2603:10b6:510:1e3::13) by PH8PR12MB7253.namprd12.prod.outlook.com (2603:10b6:510:226::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 10:57:18 +0000 Received: from PH7PR12MB5712.namprd12.prod.outlook.com ([fe80::68c:afbc:72ac:54af]) by PH7PR12MB5712.namprd12.prod.outlook.com ([fe80::68c:afbc:72ac:54af%9]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 10:57:17 +0000 Message-ID: Date: Mon, 13 Mar 2023 16:27:04 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 From: Sandipan Das Subject: Re: [PATCH 0/5] KVM: x86/pmu: Hide guest counter updates from the VMRUN instruction To: Like Xu Cc: Paolo Bonzini , Sean Christopherson , Ravi Bangoria , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Santosh Shukla , Tom Lendacky , Ananth Narayan References: <20230310105346.12302-1-likexu@tencent.com> X-Mozilla-News-Host: news://nntp.lore.kernel.org Content-Language: en-US In-Reply-To: <20230310105346.12302-1-likexu@tencent.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PN3PR01CA0028.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:97::7) To PH7PR12MB5712.namprd12.prod.outlook.com (2603:10b6:510:1e3::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5712:EE_|PH8PR12MB7253:EE_ X-MS-Office365-Filtering-Correlation-Id: 3396222e-f3f0-44bc-61fb-08db23b1b60c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rgBFCOlW/QbM6/EEhcBTg93MRsm5L0dTuwChWP04eZbaSXA977Zb2JOrhVJVJz9ckal8RFaIX6bPR+QGMAmGUDwbaET8md/P5hxIorJO5n7hUS2M6CQYSSh3WX5XepLtuGcCjqkoRnJhYOWlsbnfPtIzmFnvVsu4xcm0aat3NOONpoNSBq/4Ze0NuGQ5LYluIAGxrIQ7XKm3ePrUpmyp41icK9ndE2xAwLLUKay0EL5kxH3vN5MyB75t7L1nCzzSYPZvzOeD6KJYxITTtc65wU/b0SZpLSztRnT65NPssfgnhRjtH7a4BhGcbd6mWfy8VMQlVmwpCwK4Obpafi5J48c7YSWROht5v/PaymviOuX1NtQWZ8KAIS+4gY9vBH69jTHztam4X+mdXq4otP5gr0EajewBUA53QsMW1MP/Uvp0//h24Xdhukd/Dpb6duzi69iBp4CmlHYPmiIcURCV/pLbHpOsSSk06RN37ppD+PYv7HaiZNyrYN5X9qCVb9kXKaEuZCglItQ7QEEHBk4k0YbdCrLlQloBnNFZ5tIKANSH/Ra5R5QNhMzG9qrc5QpQKZ9uwIRPRyauJqH/F1ox9q66sH7ELIlJwcMpm9ohgf454hOvUDPu87rqjl2geOAwgitdoFKIYjH9neNxCRUKMTR02755VHAoEsJmDN++lJ4bZfi1i88tkjArPCrkNXc+aqkYVKXN/JjfS123jDyU+UTF+fl3GG771CggYq6PYNg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB5712.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(366004)(376002)(39860400002)(346002)(136003)(451199018)(38100700002)(2906002)(41300700001)(8676002)(66556008)(66476007)(4326008)(478600001)(316002)(36756003)(66946007)(6916009)(86362001)(54906003)(31696002)(6486002)(5660300002)(44832011)(53546011)(26005)(6512007)(6506007)(2616005)(31686004)(186003)(6666004)(8936002)(83380400001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Z1N5bnVrNDhCdGRmMWVLR2tjSk1RdGRaaTlJVGlaNzAxQUlEdVdlUmlJOGxs?= =?utf-8?B?RGE3WlpNWEdyTzdtQnB5bDFLSVVrdWp0RXlac1UzZ2x0MFEwNVdoVmtWcDdU?= =?utf-8?B?Q2xBZU4vRE5taDFHRStlYU1US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dl?= =?utf-8?B?cUVHM3lyZDNHTkZqWFJjUVFYbE5CN3lHRk9RRFV2MjJsQjNaek1POWdXSWUx?= =?utf-8?B?OVllL3M1U1BYcFR2R1lzYXBuUWIvZlRnNU5VUlRZMmxIKzFkUWEzc25LSVhG?= =?utf-8?B?QnF4QVliVUdJaWRSUGZrenhSZW5YZVZvNzBjUHAvaFg3cklEb0QvSktjcS8x?= =?utf-8?Q?4akfRNwvclgS3CkLJGJlPgIek?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3396222e-f3f0-44bc-61fb-08db23b1b60c X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5712.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 10:57:17.7879 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EFVNTTUYW7vdUwMNWVurtBUCVP7S45j+wnymMMUCXSFw4yGssaoNr8JqWGhViEJLBMEzMWIVpvEBrR5cwUrvLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7253 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +CC: Santosh, Tom, Ananth Hi Like, On 3/10/2023 4:23 PM, Like Xu wrote: > Considering that developers are more likely to have access to AMD VMs > and use vPMU inside guest, there's a dark cloud that needs to rain. > The x86_64/pmu_event_filter_test always fails on Zen3 boxes: > > test_amd_deny_list: Branch instructions retired = 43 (expected 42) > test_without_filter: Branch instructions retired = 43 (expected 42) > test_member_allow_list: Branch instructions retired = 43 (expected 42) > test_not_member_deny_list: Branch instructions retired = 43 (expected 42) > > ,which is not caused by the event_filter feature (otherwise it's zero). > > After some dubious guessing and microtesting on Zen3+ pmu hardware, > we found that VMRUN or one of the instructions in __svm_vcpu_run() > causes a guest-only enabled counter for counting guest instruction (in the > pmu_event_filter case, the branch instruction) to always increase by one > right after each vm_entry. > > This creates an inconsistency with the AMD64_EVENTSEL_GUESTONLY, > where the vPMU user in the VM does not expect to see any counter > changes due to the SVM transaction at all. This patch set provides a low > overhead software fix until HW change arrives or simply no fix planned. > Yes, VMRUNs do get counted as retired branches in the guest context. My understanding is that this behaviour applies to all generations of Zen and even some older ones too, not just Zen 3 and later. I also do not expect this to change in the near future. - Sandipan