Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp808386rwi; Mon, 31 Oct 2022 07:49:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JXFpyD/0MH9Gcx0p6P0t+JaU0Ss3dcYbdqfqX97v/Qb2LxMK1MdIonwlAJ0dkGDG6/28z X-Received: by 2002:a17:90a:5a46:b0:213:cf6e:5f67 with SMTP id m6-20020a17090a5a4600b00213cf6e5f67mr8663441pji.93.1667227751184; Mon, 31 Oct 2022 07:49:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667227751; cv=pass; d=google.com; s=arc-20160816; b=nqZJnoy2Pxz2j/sha05/v+f459UZcD4nI8Jmp5dVGrZ+LsOucBeIIAVoum+75YRMjk m0ilffKlsqWxHMnV0xAggKvGh1jTfwet8SeG+X6MzgiQty7ry2443Wmy81cREgt+YK1y Nh3flc8tIpj21DeTcZAPq2+rPkk3nPHnOm+cczPPlYh7VmPF0DG3BVf2rDwjGK5iAgai 2LsdYix5Dw5dFfry+I+LjJHRIMSoi3IAJWnrQevG4bnHXyz8i2dN/je7DC4eNJtFZBQv bA8A1nR8w6co36W01KIALCYcTesmGeGD8wSAULAFiFXeUaX2x08oINJnixgNrbJVH8xs 7X+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 :in-reply-to:from:content-language:references:cc:to:subject :user-agent:date:message-id:dkim-signature; bh=o19NxFTuPFeUi8BgTHzQsmJVxOfTZ+APnH5VfeVQV5o=; b=hl7aQaxrXGVvWYBiiz5dwgueAzffuMIR2M57VNmzL9TiGj6uqV0SjDQV6estAjlb0W SMFMhlQAhW+qCwJJ2lG6g3G0+5etAPZkryBeFUHEhhl92AeBkpk14G6T32B5RpHPObIf YJRSRY+2oWtY81n6F7m6B5lsrQ3djJhhhNuoBBxpekyQMo1pQgdDBv2VoRFPtE5aeBiT t2mXOwdnTn+sJNJ5GQdpvq+Wo7kVblASZeG92LJp/I+qPibU6Euq1aZb3goGgbPqSURb FWMw/W2cbx8HmhyWnvLdjwyCRwRuJkG7lYdNb4P8XQmPCGRY6CEl3RpQJxYIn0Tg5atK tcmA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=jPHRMmhe; 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oj12-20020a17090b4d8c00b0020d4f2e056csi9888871pjb.151.2022.10.31.07.48.57; Mon, 31 Oct 2022 07:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=jPHRMmhe; 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231599AbiJaO2w (ORCPT + 98 others); Mon, 31 Oct 2022 10:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbiJaO2v (ORCPT ); Mon, 31 Oct 2022 10:28:51 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2070.outbound.protection.outlook.com [40.107.223.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248D0108C; Mon, 31 Oct 2022 07:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C+HwrpwjXenNlLan2SVYhgTVCnG7SFhBBmrJjaguv3gV0rFyPdeH+sbRjXFyxrGJ+nkpzsehU+dLcsZeGdvYHpCyXXAWezryNnAEZaDT3ClqaZcAm3/Ywe9SU18SU42Rn3v8YyVIsf+bVtW1bcnBIkscQ69UUvlGrqRu720qwGwb0VVGW5JdKzRqfC0dNxHJEk1ZF/6k8JvwhSOltJsV7XjC/gKy8Tf7zoxbOA8ckFVU90do7oesuwHkB5jp/PeedFiTxPvmn8wAW8/vMpqTWnTdTAE+mhrNB6PEp/cAGW58Myt7pWzdnLp2jhvnQawctuy1fBAyr3NAaRqwz8xpGg== 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=o19NxFTuPFeUi8BgTHzQsmJVxOfTZ+APnH5VfeVQV5o=; b=Dy52RIuhJMgKTzj3+hhjIXl6hgAhfyuIGKa8XN0DLqStJ8SzivcctJyCnNKQVUEQSGiVxlJwf5smH4P0HG3QC0O5vHWTOdgzisye3nzZMyaLhnGUewftY2MeV/PyzhPUOxbQRQYIdCmrZSgkGR5ptbSlOZ0/A5hESzhgozfXZmtoBFWScv+zSsmgbbfP5Ku5xqDcOwBw8g+Trj1zyxOv287wcJLxtYwcIwcVNAWvtU33PPqrSqbp8Wm//0bX/BwSMxz7munJgnViKZPsduRQD7ifTwwg1nLMg95b6hZxKdbB7nVZrn7Rbi8UGbw2rIecDLHaRz4dW9VoGwYlEvGYjQ== 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=o19NxFTuPFeUi8BgTHzQsmJVxOfTZ+APnH5VfeVQV5o=; b=jPHRMmheT9UHr6jMQp1/SZobHY9PYphWpNll54Gk0UcqrD5AkfNvdgcIk6DvrYMbPyjJCwzQ3nzpvCGyB6sZr+6rDXCjEye0b67oJdBd5MNzb4xzALrVVveyqaxUvc0XEYFXCjxGw70a5gVeR8g4DAv/GfKVivELQ2diKmNiDW8= 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 DM6PR12MB4338.namprd12.prod.outlook.com (2603:10b6:5:2a2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.15; Mon, 31 Oct 2022 14:28:47 +0000 Received: from PH7PR12MB5712.namprd12.prod.outlook.com ([fe80::a3b5:7bec:ebd7:b30c]) by PH7PR12MB5712.namprd12.prod.outlook.com ([fe80::a3b5:7bec:ebd7:b30c%5]) with mapi id 15.20.5769.016; Mon, 31 Oct 2022 14:28:47 +0000 Message-ID: Date: Mon, 31 Oct 2022 19:58:32 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] arch/x86/events/amd/core.c: Return -ENODEV when CPU does not have PERFCTL_CORE bit To: Peter Zijlstra , Liang Yan Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , Dave Hansen , Ravi Bangoria , x86@kernel.org, "H. Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org References: <20221027133511.161922-1-lyan@digtalocean.com> Content-Language: en-US From: Sandipan Das In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PN2PR01CA0210.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:e9::19) To PH7PR12MB5712.namprd12.prod.outlook.com (2603:10b6:510:1e3::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5712:EE_|DM6PR12MB4338:EE_ X-MS-Office365-Filtering-Correlation-Id: f1fe0971-ae24-413c-22e4-08dabb4c38dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S5+1SSMVtwGoZaTMLOe84AFATfyBFFr4ThKebEB54lpSVmgNbeTKHSzkaAqLLY8gfGBOAhenKl3ZJux/coS95QqJ7NToVUqOjZxTpiohYlgpoMR1vKna6Vvpu8S6eMNiLhf9lx5EGk9Sr386DbCloSoY+Bv/z3dUH06eSWUxf2ZEd7hHLrOCAfC1gDa7bErKTmnHY10x+rYcuYQmBPD7yRjhxuDeyxojCSHtwg0Qd9/NZ0wXyWLqVCn/DwEvkoVkWvXKjapSZaPPx/FqZbtw5uPVy+eEp0mDC7BT09/xKWMhBjhqabSGFVc+rCZ3FPPK7qnOkeoq4sPqGYhuCQVyYYQxmqlgY95PZzJ6YpYLwm9zTl+X3Y2lOg86+daxaYbdLtIQbMHDrAW3JTwlALnjDYyp3suq1BisEFwa3V+abA0ox1PzXpAmd18o7S+4PD3GoqJaUscp2AtlrLUP5aADAKqgZba4UKUT5bgrcttgrSAUp7scHrmqYSKuRIwfSZPRAM9oV6EjFs1iPWCmQH0t1DLtQpH9z4tQzk8rC2Fisb+dmVGKGvw4euIOZG+47BJaA/fuhPTZYcrmes3gQwYbcbY3FZj5mDwVWnGVjxmCakjrqz+iIXILyEwMzOCKpVCm80uabQMLQEv9pb1he/X38LYCtCZ7ZgxNtzhIaCohUUgZskNNsF8Ff33jTbJKyAdVn1vYPB+RbBpWTXD3EBTTF8mWZW3Qx4q1FMG93+VmJptvH3WftfIaTPMdxfzBmpyjBBVQqEvgdejumcaOehxjJA== 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:(13230022)(4636009)(136003)(396003)(376002)(346002)(366004)(39860400002)(451199015)(2616005)(6512007)(6666004)(44832011)(26005)(6506007)(53546011)(186003)(478600001)(83380400001)(2906002)(7416002)(54906003)(66946007)(6486002)(110136005)(4326008)(8676002)(5660300002)(66476007)(8936002)(41300700001)(66556008)(316002)(31696002)(86362001)(36756003)(38100700002)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bHA1MkdaVlh1eVh6Z2c3MGtJOTZKTFNzRngrbFBsaERBbzBVOUlOcUdKcCsy?= =?utf-8?B?U1g5SXh3WlZFbnJ4emc2eEhZZHY0b0hSTDgxS2FZcHJpRHhHQ0J2SnI1Wk9h?= =?utf-8?B?VmFTL2JLd1JKb3lXOGNzakNubXF1R2VtSlhmM09Tb0VZbUY0ZEJDMlRzRSt3?= =?utf-8?B?OGIybGpOenJnN1Bxa2FNUm5XdWJRc2ZUUzBtMlAvS1VRdjJpMUhnZlRwYW1J?= =?utf-8?B?UjZVdjBPYzdnL3B0SG92WkJrQzhVS2FkcnZOVW5KU0RsS0hGNWZBemVEdFdt?= =?utf-8?B?LzNkeFpRdVlaSUtzVjduSlBIVENmR1hXRXdYS3dGa0dROFNKelZhS1hHZTZZ?= =?utf-8?B?ZmZiaHJCTEEySXhNR2NTL3Z0OV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com X-MS-Exchange-CrossTenant-Network-Message-Id: f1fe0971-ae24-413c-22e4-08dabb4c38dc X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5712.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 14:28:47.6736 (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: bSX4y4QBdScbgbUzKeL45Sw41fZWXRba/qpYFS4Ax8rkoBDzef7KgSsOJH7vzZoKuLLJwhNYxF3VA20ofV92lw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4338 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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 Hi Liang, Peter, On 10/31/2022 6:29 PM, Peter Zijlstra wrote: > On Thu, Oct 27, 2022 at 09:35:11AM -0400, Liang Yan wrote: >> After disabling cpu.perfctr_core in qemu, I noticed that the guest kernel >> still loads the pmu driver while the cpuid does not have perfctl_core. >> >> The test is running on an EPYC Rome machine. >> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# lscpu | grep perfctl >> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# >> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# dmesg | grep PMU >> [ 0.732097] Performance Events: AMD PMU driver. >> >> By further looking, >> >> ==> init_hw_perf_events >> ==> amd_pmu_init >> ==> amd_core_pmu_init >> ==> >> if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE)) >> return 0; >> >> With returning 0, it will bypass amd_pmu_init and return 0 to >> init_hw_perf_events, and continue the initialization. >> >> I am not a perf expert and not sure if it is expected for AMD PMU, >> otherwise, it would be nice to return -ENODEV instead. >> >> New output after the change: >> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# dmesg | grep PMU >> [ 0.531609] Performance Events: no PMU driver, software events only. >> >> Signed-off-by: Liang Yan > > Looks about right, Ravi? > >> --- >> arch/x86/events/amd/core.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c >> index 8b70237c33f7..34d3d2944020 100644 >> --- a/arch/x86/events/amd/core.c >> +++ b/arch/x86/events/amd/core.c >> @@ -1335,7 +1335,7 @@ static int __init amd_core_pmu_init(void) >> int i; >> >> if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE)) >> - return 0; >> + return -ENODEV; >> There are four legacy counters that are always available even when PERFCTR_CORE is absent. This is why the code returns 0 here. I found this to be a bit confusing as well during PerfMonV2 development so I wrote the following patch but forgot to send it out. diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 262e39a85031..d3eb7b2f4dda 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -1345,6 +1345,14 @@ static int __init amd_core_pmu_init(void) u64 even_ctr_mask = 0ULL; int i; + /* + * All processors support four PMCs even when X86_FEATURE_PERFCTR_CORE + * is unavailable. They are programmable via the PERF_LEGACY_CTLx and + * PERF_LEGACY_CTRx registers which have the same address as that of + * MSR_K7_EVNTSELx and MSR_K7_PERFCTRx. For Family 17h+, these are + * legacy aliases of PERF_CTLx and PERF_CTRx respectively. Hence, not + * returning -ENODEV here. + */ if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE)) return 0; If this looks good to you, I will post it. - Sandipan