Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp493729rwe; Thu, 25 Aug 2022 04:19:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR4TA8OfjuG+FDZ/YeMRuAHEHNID5WDe4qZKCluYUi5IaumXuU1a8cW2IfERoDIdZf6WUlqH X-Received: by 2002:a17:902:f609:b0:168:dcbe:7c4d with SMTP id n9-20020a170902f60900b00168dcbe7c4dmr3399720plg.169.1661426376247; Thu, 25 Aug 2022 04:19:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1661426376; cv=pass; d=google.com; s=arc-20160816; b=Ew4oHBTihqvkLZIi84eRtoXSrQ2NWYOeANwjUkEcJQZRWbvIzT0uviBBxmJBg77l5X 0ntyktiT8tHfnWsd2pShlPgOXr0ymPlulfXCXbz9xQ4BdbAv5gUJIUKt//woArRirtO8 OL0nI8GXPRpIowtfjcEHyWecoCS2P6F17/Pe1GV4jfyTgy15/9MzZxzT6sAIbC601EFH Xiznmte/HTuGol/B5xGOYOizcX0uiQyJVtMQqyqfxKqnlD0b22eB1DkpyXl557+M4FLN P05TCeUm2Kff2UeavLyK6w4szm8kKtIHDlRJ2dYMaslJkCbu8L7VjCczbnLiyJWwajs/ Rczw== 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:content-language:references:cc:to:subject:from :user-agent:date:message-id:dkim-signature; bh=xYOQwAcwIkeb1EHXSYC4vAbLSSSuP04wfDdIY2XG1rw=; b=MRSvRciUpH/CTkhhBGLPbpgoD2Bkm0CGE5Q2cilM0TxPW9TDqciCF0GeVhPukrmoDh Bi9RpUlMOZFHCRgjcuTwtTUUy9N2VsJVrG44Xiv164Q3Sz1OGd9scwiEAloiY9bdS777 +ESeSIsvZuy7+9AJld75qdG7WqfWRqO2ACCmsgj84JCphY1yEXyWIAI62F4VUB6z6pg/ X7bsOa0DQ6dVPM9pwK2cgtkzffJ4dlKEocwaIomoWPMlki1X3919DNUctyxGHt/XLOZm yy1OLvh1zdcwamCZY19CrFSojFAKjk54dmiU3Mp2IO2z4zeH8y0kOt9G1GdS0l+D64CE ntNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=avSGn8Eg; 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 pf14-20020a17090b1d8e00b001fa63199641si4040096pjb.181.2022.08.25.04.19.23; Thu, 25 Aug 2022 04:19:36 -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=avSGn8Eg; 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 S240835AbiHYLEP (ORCPT + 99 others); Thu, 25 Aug 2022 07:04:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbiHYLEN (ORCPT ); Thu, 25 Aug 2022 07:04:13 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2076.outbound.protection.outlook.com [40.107.93.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B16B3AD9BB for ; Thu, 25 Aug 2022 04:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CXrqVUP4GteciTUVSTLM734LVCGiU9j/k2+6ZxHfvR6SIoSohMCw0ZEMma1WUWKdfRy+yxp3Xzy70FLAzcJVbIvQaZPv+k/ncSljgkyT2aBOfwTFmolBPqCVEeYUTBIcyuTcU/QOmKk2WdN25ZIVdUKsndp0Ss+hyB7yKU9ZnvBBGsaOI1hCN//UNyQQMhIA8K/vEoXbU8eo2e5aKdUyRmaBQEuT9KuBL5fbw1/NvLG8eTR8DSKm+JWb4LjsZ+li5zGGBT5rI9UjsEC6I2E3aP12UtRb0MqJqJSSL9VR/yzgNBpsglh2ZEDeRnzZq5U9s7Z9zFGbI09rwfEJocd0ig== 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=xYOQwAcwIkeb1EHXSYC4vAbLSSSuP04wfDdIY2XG1rw=; b=eEccZvpKwvMzSwjMfLqelSPYNK6SbVO4yPZ+BBRbZikFv48AQRRO5srZPjD6EkdhykAjbxgJMuUCbNVFxHjD30epL/goSsCTH5onhW8Pr4n56vGrWRHx1F5Q9Q8FBLNULq8Rd63hCArQ6wEdUpp9MzSkximUtuEOZq07JnAhg+LE6kKtk7fpy29OAOOPCk+kPlmJINPynSpCTIeWwzGSnjx5YIFG8NSX3ij/+gpFM4xhxcmwJmw/mlmmh5508nHT1FEuAIh4nZylJHNztGs8kEpjT6EiLj27QkYTI84LkvOS78gPoCZLIJ5/2zJjhx9aR1EG5YcfEP0D+/rp5IbUwA== 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=xYOQwAcwIkeb1EHXSYC4vAbLSSSuP04wfDdIY2XG1rw=; b=avSGn8EgxyFt71Eief/3Z9CqF90T/mC8uzc2MR7dmb7rWdkZLh2kKTOPxunqED1k+KqRcyPt2jW21pysSGg7TRRFgqvtzNg/U/teLEej4sxrYXTJMW3+ihQh/Ey2dZq592iZgw4tR2z4XXgozFC6BNg7tu6H5KSCv6spFcEMQMA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB6588.namprd12.prod.outlook.com (2603:10b6:510:210::10) by MN2PR12MB3552.namprd12.prod.outlook.com (2603:10b6:208:ab::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Thu, 25 Aug 2022 11:04:06 +0000 Received: from PH7PR12MB6588.namprd12.prod.outlook.com ([fe80::6958:4b1d:7283:edbd]) by PH7PR12MB6588.namprd12.prod.outlook.com ([fe80::6958:4b1d:7283:edbd%3]) with mapi id 15.20.5566.015; Thu, 25 Aug 2022 11:04:06 +0000 Message-ID: <05ba363d-12e4-83ca-fb20-203c93a27f3d@amd.com> Date: Thu, 25 Aug 2022 16:33:51 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 From: Ravi Bangoria Subject: Re: [RFC v2] perf: Rewrite core context handling To: Peter Zijlstra Cc: acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, songliubraving@fb.com, eranian@google.com, alexey.budankov@linux.intel.com, ak@linux.intel.com, mark.rutland@arm.com, megha.dey@intel.com, frederic@kernel.org, maddy@linux.ibm.com, irogers@google.com, kim.phillips@amd.com, linux-kernel@vger.kernel.org, santosh.shukla@amd.com, ravi.bangoria@amd.com References: <20220113134743.1292-1-ravi.bangoria@amd.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PN3PR01CA0051.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:98::13) To PH7PR12MB6588.namprd12.prod.outlook.com (2603:10b6:510:210::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d97b6911-af4f-496c-4534-08da868986f6 X-MS-TrafficTypeDiagnostic: MN2PR12MB3552:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SrF9gmalA4BDT6YN8E0MqamUzp2d+Vqa6cISrRllLASMA+8fIC8WMb6NvaDiT/k/ZT9nn9QR3pnERxw8/OAPX6Iwh1H62YJYMW3wWsL9CLFRoOoEsKze9Q8y8snpxoopq+PvPG6DA0Camzk/cbELWuAneC/vqhtOwpBuJXllz64lwNidEWT7dDGGE4jJXsn4B4I0p4UdIGgkHDmfZzO5WXTCnTb+aMe+if9fxDmA/+1Y5YKxBTT+3ejpT5MFRWHKfStZqFU6BIc1sHkkusT9D7aRlZAg1hzTCae8+8itE4gBoZTO9uV15wxf8CX5OT6apMlMeHy2e2/PWfUHVynQWYWgyB43NsvZXgpWv/6moj64jXWVIEZrA2J7yxKaIoENaTCGb+wJAnBFt7F09CBY996U2D35UEIFfKVCKxy9msTd2Ax9KiEDdixNJMYKyGViu6yOVZmi/gclsasuapnvdoh43ss2rel7c6DnZPUmhSzJVI88fVm2pUuoNiHWmHpluyVm0m1UbHOygd2r15I0j/5vWa/3qCgA4hmFa4YPw3ox80XeNzK/XKqJYKnKhaW++aiFBfvQej88q10KFK5rBjxPkzc6Nk00YrHBLwbwWzN7eXM7qVq1srdvcrIONbLEzzbIjbcR5BKYmef2KoLxU7esQxqDrmpja6PW9qxG+QLHkbmP1hG52moIev+nvPea67eqzo8r5za6pLIY5nFt5mNcj6X3lJet9+6AA+N+sUu3f+OCHM+ybaCIO8fDGPZW/LSVyFwmYr48CEp5D31BMoGuSjRcVo6QCw53zG3BmvNJv9joFiV/qQnrWl5U6PHE X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB6588.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(396003)(39860400002)(136003)(366004)(346002)(5660300002)(4326008)(8676002)(66476007)(66946007)(66556008)(478600001)(6486002)(83380400001)(86362001)(31696002)(26005)(38100700002)(6666004)(53546011)(6506007)(6512007)(8936002)(7416002)(41300700001)(44832011)(2906002)(6916009)(31686004)(2616005)(316002)(36756003)(186003)(21314003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bHc0U2xoUzg3L291NTZnTzkwVk5ISFVPMHI3MVhOUk5VQWg0OHo3cGU3WlE1?= =?utf-8?B?Mnk4OXNZbVdxV1ZhS01FTU1nbm9WeG8rcmZjYzJ3Z21sdGJBSnFxSHAvdU5q?= =?utf-8?B?cUtwVGYvWlBiTGwxRk5vaXhpZ3dJNmJIYS8rM2tJbXN6TVJHT3VVOGZLTHNX?= =?utf-8?B?THNETkVVelI3UnMvSmkxK3VTcG44THYzVC9ocFJ5NVJRNmRJYnFaUngrbHpT?= =?utf-8?B?S29JUytQM0xIb29GUkdqZ3hlS3NHYkZ4Q2FVcldFRzZ1TEZQZGx6bDJBcTM1?= =?utf-8?B?VDdQUU1sWFBHYTRVRS91dnpuVnZtZkpsVm9qcnhVbUVtelJ6V2VYZHZOeWNw?= =?ut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pssVITA4hA1qI8I/sYHQnkM?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d97b6911-af4f-496c-4534-08da868986f6 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB6588.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2022 11:04:06.2568 (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: 9eyRCQG+uzfZI/8+6oEZJqBAkv9CobPKtmFllgYEGrVbb4PQ0IOFBxSUVmjiePvmXDKwERlWaB3qEYhfuROK0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3552 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,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 On 24-Aug-22 8:29 PM, Peter Zijlstra wrote: > On Wed, Aug 24, 2022 at 02:15:13PM +0200, Peter Zijlstra wrote: >> On Mon, Jun 13, 2022 at 04:35:11PM +0200, Peter Zijlstra wrote: >>> void x86_pmu_update_cpu_context(struct pmu *pmu, int cpu) >>> { >>> - struct perf_cpu_context *cpuctx; >>> + /* XXX: Don't need this quirk anymore */ >>> + /*struct perf_cpu_context *cpuctx; >>> >>> if (!pmu->pmu_cpu_context) >>> return; >>> >>> cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu); >>> - cpuctx->ctx.pmu = pmu; >>> + cpuctx->ctx.pmu = pmu;*/ >>> } >> >> Confirmed; my ADL seems to work fine without all that. > > Additionally; this doesn't insta crash. While collating this I came across armv8pmu_start() which does: struct perf_event_context *task_ctx = this_cpu_ptr(cpu_pmu->pmu.pmu_cpu_context)->task_ctx; if (sysctl_perf_user_access && task_ctx && task_ctx->nr_user) Not sure why it does not lock task_ctx. Should it be changed to something like below? Untested: --- diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 016072a89f8f..747415a5f2b2 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -806,10 +806,19 @@ static void armv8pmu_disable_event(struct perf_event *event) static void armv8pmu_start(struct arm_pmu *cpu_pmu) { - struct perf_event_context *task_ctx = - this_cpu_ptr(cpu_pmu->pmu.pmu_cpu_context)->task_ctx; + struct perf_event_context *ctx; + int nr_user = 0; + + rcu_read_lock(); + ctx = rcu_dereference(current->perf_event_ctxp); + if (ctx) { + raw_spin_lock(&ctx->lock); + nr_user = ctx->nr_user; + raw_spin_unlock(&ctx->lock); + } + rcu_read_unlock(); - if (sysctl_perf_user_access && task_ctx && task_ctx->nr_user) + if (sysctl_perf_user_access && nr_user) armv8pmu_enable_user_access(cpu_pmu); else armv8pmu_disable_user_access(); --- Thanks, Ravi