Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4469766ioa; Wed, 27 Apr 2022 04:41:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoQSLHMbi3CZ+jmRj7MZYsF6+IohPxW7flNkN/CVAv0Qeb2jtId4P+jvNcn0z3beJL92nL X-Received: by 2002:a17:90a:c246:b0:1d9:3a2e:5495 with SMTP id d6-20020a17090ac24600b001d93a2e5495mr24058975pjx.170.1651059708471; Wed, 27 Apr 2022 04:41:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1651059708; cv=pass; d=google.com; s=arc-20160816; b=vOrO0cVcRl4MbFxPyqbfXjUJJTDj6WD0JI2A/jOwsIdIlW9KpcHNkeKQ5/H+OvrHkm ZQIpOsXfE8+TC4a86a1etjhG2Ls+EuQWAuTsBGtZ/GK4J7gmsoM8p7y2lKxgKiWX73fh d8DwNx24QS5PaRGJbORzUscm6B5j8T2DPu8KrrZZAskQHCiMKCiu314vmM7AB+zafYeu t3EtQQzgISC5I+Nk7AE2erfpwHesXjIT498D55yIbaWVzEaCyi8xc7NLCfziySI5feTY yj/DHnHEbT+wenGxXadCVN4jxf2hXjAKN0qM7C9gVu84nj65ZRqLblOrl6OonhBfweb/ O+bw== 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 :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=tDKB8Z4a7W46ePFbduTiKosXT2435MHP5AAouTDENwI=; b=ydAxAn0SG+YenZz1xyK7+I4Gi7K4VWNmxKYg4mbjfjvFxAWb6oLT4iEhw/vxqOgrfz D4NruL54uhNCsPsxvrKp6C3BSDfBUwtyfWcqpxPjGj0aO+SG3ph9liwPEyE1xtmibaom TJFQspAoZ93mBdmLieS2Q4G7d8jF8rOC2+27b0u5ssO1nJGjfJobFwkFCpfxeqT1wdO0 IcDN+uZoWeOs7qal7rwXJHh6ah5/IjEZcqaZAQ5v6LgKSOMqkI5kVBqkQTPqwyaN9Gie NNUhRHdxkeXrBslXp23f8saO7hh4gJ2KQDDb8kt1yc9XylQo3NEdXxvDJzgYptoiP6v8 1QDw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=kM7TnBw3; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g29-20020aa796bd000000b0050ada4f33a0si1107742pfk.94.2022.04.27.04.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:41:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=kM7TnBw3; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7232C3833D8; Wed, 27 Apr 2022 03:40:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbiD0Kn1 (ORCPT + 99 others); Wed, 27 Apr 2022 06:43:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbiD0Kn0 (ORCPT ); Wed, 27 Apr 2022 06:43:26 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2077.outbound.protection.outlook.com [40.107.244.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9A953833C8; Wed, 27 Apr 2022 03:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GJMTSFKwUUd+PZ9wjXghCBUxzEDfTNR210OZ+6EW6uTAuMWnkJh+TxawjvcAxQx/zGcITwStpdoADwsXQ9OGagsXHXj0PWmPUT+mA3iiFrrxYXvqRdBNo1SbmRW1BWuZBE+wXdIweehyD0qqSt5T9dvqo0H5aO/EIOOb8pvILLN53pWPs13n+Aw839EXBHfMIqorm5goBu7v+/RDE4UgmNJ4Mcs8fngvDjN+BlwxbaOiXXdQkkbyUm+OfkpNF/YP+cXxLYiBTVguFzbXRebACei22neLjq48mk9Pxe1Fm9jNpkgcmFwihojPnW0Ezad7E9dEXxXTQbdHjYI9CNTDhA== 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=tDKB8Z4a7W46ePFbduTiKosXT2435MHP5AAouTDENwI=; b=Ku7ylRXxIq3soIDZavEk5M0nDqZlOk9YSVUv3Z69eedd/3LhGrRU0r1KMee1QKg5K2ixXeZP5xItaFjIK0g3OsKKMSL9JmLyx8bZHNT1Ru9ynaXIC7sPG0l8hdkCclRU7gpmR0kzwAV3Ch2LJf7dAoWU0eYbjuwqoI0Vk4F172DTdvWH1mZ85QlKkenJ6xp8ouORW20iAPDG0C02QipolEhfIWZu9YyzKxnkxWqtBdbNOGzIrTAnrp9SQdy87IxYKymTPNheNda12oQ6ZCXOTf+AAQUxaHiUAIdwMACh5P7DLrxcFPq6YudyPlPH+6rXYL+irIoF2lBVtPrDzydQKA== 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=tDKB8Z4a7W46ePFbduTiKosXT2435MHP5AAouTDENwI=; b=kM7TnBw3wiZBqorFLmSPZ7YzCzvdu0WErH80GwkrfgK7y7rbExi2cgIcm9ZW9KfEQDhFWr6E4CocQ8ySEmEgWPypP0LsRe8UOxaF+k8Ox0l2plykR0uvChanajBvNRlzKURfPp2BvSTCqLHth7hntSwCUkf9PFyt+X36m3EOvEw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN6PR1201MB0178.namprd12.prod.outlook.com (2603:10b6:405:55::20) by MN0PR12MB5738.namprd12.prod.outlook.com (2603:10b6:208:371::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Wed, 27 Apr 2022 09:52:17 +0000 Received: from BN6PR1201MB0178.namprd12.prod.outlook.com ([fe80::ed22:dd57:358b:9fb0]) by BN6PR1201MB0178.namprd12.prod.outlook.com ([fe80::ed22:dd57:358b:9fb0%10]) with mapi id 15.20.5206.013; Wed, 27 Apr 2022 09:52:17 +0000 Message-ID: <28329079-09f2-3ff2-4606-5ccd3831cf20@amd.com> Date: Wed, 27 Apr 2022 15:22:02 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v3 7/7] kvm: x86/cpuid: Fix CPUID leaf 0xA Content-Language: en-US To: Like Xu Cc: peterz@infradead.org, bp@alien8.de, dave.hansen@linux.intel.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, pbonzini@redhat.com, jmattson@google.com, eranian@google.com, puwen@hygon.cn, ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com, x86@kernel.org, linux-perf-users@vger.kernel.org, "linux-kernel@vger.kernel.org" , Vasant Hegde References: <476a0d6feef8016ed19e4911ac25abdd20aabeb3.1650977962.git.sandipan.das@amd.com> From: Sandipan Das In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PN3PR01CA0136.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:bf::23) To BN6PR1201MB0178.namprd12.prod.outlook.com (2603:10b6:405:55::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ee4d4647-c1b5-458d-b173-08da28339ccd X-MS-TrafficTypeDiagnostic: MN0PR12MB5738:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kq/1aXdHlm19FVrIROT3v8GfcY/39yk/AGXiDQsCVQWDC/r2JE5gJNywPR6i+FDynlteEfomphObYwpLfdnvTM7Ht/RkuNxcJjB69G6vqxgeDXEvD/BRAezCS/t6QklER0VdaCm2hBD78IzKW2BIAzgcylathpuHSscjsQVzQY+5MF409tj+xkybUe4ktRj9SWA6n6wQi828yuyOkXb8m/N6NLhDQc91ei8sPw8GefkDFgEU7/w6grCP2hAeoUBcwmbgCkqh2wPi8j22F/BFHXSCp/mP39iBGRxzHaSNDm7XFsYoOwgWDGIkO44pumeLCK/qGIe7zLhk+UUO5seYVXBtiZtONV/zznUeNeYZtoPwhzkKdqsGB4GdDqfNA+eCfHIwiVb0Zf92seE9L+HJe7YqfXBOAxcVJgIqILAiYl7IR7Ma7Vy7+IM2/B5PrXgpe4xsW8mO2fHQ9N0IUtmoieG33ZxrT1dJZBjpXi2YiM0YkDDCiy8ux5XeyaaFaRsRHk7cBCGuiVzC7KTmg1/tu6AV/D7x+kRSmP/VYAxq0B9DXbWSREoe6+2mNDkfGjrZxfMM1ljbz/Iuhvycs8+lcjXIucymiSfMv24so4s2Rn6kZ1ZMIiPYKhRSo38dx+j+//nGxq3lGlioSjN7fHXioAEdC5PBRCsXwvlds47v9ZkWJrMW/NTdV78wwK1mlURQkTGMBoTpA88eJojtQFVLCP2T9amGizis19G4nwsEmqw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR1201MB0178.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2616005)(83380400001)(7416002)(53546011)(2906002)(31696002)(6486002)(316002)(6666004)(5660300002)(31686004)(38100700002)(186003)(86362001)(508600001)(26005)(8936002)(6506007)(6916009)(36756003)(66476007)(44832011)(54906003)(66556008)(66946007)(4326008)(8676002)(6512007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?LzhzUHMzZ3dkNUhUbFlyRlBLU2ducVE4dVB5U2NOUGlma3VNZ3ZqRHRNZGMw?= =?utf-8?B?cTJCSDNPc0hzUkFpLzVWV1c5OXh6anV0OHdyTkwzVmRtZVlCMUUvWTRoZkpX?= =?utf-8?B?WmRISGJ1K1NUa1FLZ01Pb2NGKy8yMWdKMW8xOW1JdmZ3ME1FdmlMTVY2RHBl?= =?utf-8?B?L0ZUUzgyb0o2aGhqSUFDUG0yUDRPT2daRjFoV2pBY3REZTUwbG5wTGF2Z1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FnMFNuMnRjWGQrd2xxYkViRVlqc0tTV2hxeTJ6cno5RkZhL0xj?= =?utf-8?B?QXJBQ0gvSTdwT1lES1hLSnZCK1pPQldIK2ZPckpveHI5Y1pxeFpsUzVTZkV4?= =?utf-8?B?MHVHUlpUTG5Ea3FocVgvMzRTb3NjREJwdlZMekFXUDhOV21jS3EvaExsN1R6?= =?utf-8?B?QUFpNEsvdno2d1lzams3TlByczUwQmhqaGxsc3JGSlBXbWlMQmtsRTFYRWhQ?= =?utf-8?B?WDRQbnNRRUNSLzJ2UTZYVy9tVk5CejJMZHpXYVF5N0s1dFRYKzA5emNLak9u?= =?utf-8?B?dVFZS2F0STUwK25UemJaRG5IY1JiRjlmU0NvZmxpZWY0L1NyMkNwdz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee4d4647-c1b5-458d-b173-08da28339ccd X-MS-Exchange-CrossTenant-AuthSource: BN6PR1201MB0178.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2022 09:52:17.0046 (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: ZBV4uet1dmYINEIGhDe1D4wclnGeShT3LUvBRARkbE5ddAOzH2siTvhnr/rC4A8e9nVd6h0eCEq82Fwl19AL5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5738 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/27/2022 3:02 PM, Like Xu wrote: > On 26/4/2022 9:05 pm, Sandipan Das wrote: >> On some x86 processors, CPUID leaf 0xA provides information >> on Architectural Performance Monitoring features. It >> advertises a PMU version which Qemu uses to determine the >> availability of additional MSRs to manage the PMCs. >> >> Upon receiving a KVM_GET_SUPPORTED_CPUID ioctl request for >> the same, the kernel constructs return values based on the >> x86_pmu_capability irrespective of the vendor. >> >> This leaf and the additional MSRs are not supported on AMD >> and Hygon processors. If AMD PerfMonV2 is detected, the PMU > > So, why not: > >         if (!static_cpu_has(X86_FEATURE_ARCH_PERFMON)) >             break; > ? > That seems to be a better option. Thanks for the suggestion! Will change it in the next revision. >> version is set to 2 and guest startup breaks because of an >> attempt to access a non-existent MSR. Return zeros to avoid >> this. >> >> Fixes: a6c06ed1a60a ("KVM: Expose the architectural performance monitoring CPUID leaf") >> Reported-by: Vasant Hegde >> Signed-off-by: Sandipan Das >> --- >>   arch/x86/kvm/cpuid.c | 6 ++++++ >>   1 file changed, 6 insertions(+) >> >> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >> index 4b62d80bb22f..d27d6a8f601a 100644 >> --- a/arch/x86/kvm/cpuid.c >> +++ b/arch/x86/kvm/cpuid.c >> @@ -872,6 +872,12 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) >>           union cpuid10_eax eax; >>           union cpuid10_edx edx; >>   +        if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD || >> +            boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) { >> +            entry->eax = entry->ebx = entry->ecx = entry->edx = 0; >> +            break; >> +        } >> + >>           perf_get_x86_pmu_capability(&cap); >>             /*