Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2114.outbound.protection.outlook.com [40.107.220.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 959DE322A for ; Wed, 16 Aug 2023 03:31:27 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EHvq2hpkn/wHeEHsoFMy2ShuV/K2gH7aoA+7RI7cxkZEQny3sRdLpxO32vtpuIC9kKG6LODkEB4eVr0JgNkUJ02OKprz8U154NMU1gfdH5nhKLbPb3vJzwiTR4QI52OsTpztqpdhpPKhQcH5WkOqj2j1VoQWiEEXTE8xR8/b+q/ZBPjsEswBGfb03JHT19OFfBPI6nKcHfaf9CD48b13ecWgc/DaiwCfUNETj4LH9dCnNKCRu3N5bMuFs73cRtV9GWZoq/66d2TP46xqQgJUE+wZWttxWfgZ0DdOHbHu5HSmDtiCwxwIP2Z0QFc64qDbYnQ9/nNypDymIJtSmsc7VA== 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=MUX68QX/R4Qpazayrgd2WmfL9cMWPrKWZO7pmGEdogg=; b=Zm2V6pXNW9yfhT0aCLEEHJauJ1uvgphf+ZJCx8n4ghHN6O6LnmVLOWNjKwo4n9+bci5C1pWL2GeCfJtKx3n1LIadM5OPUMJW2+tfxYz4TSonFLD/DNSU/MCX+BR9uJtRk6k+FgOMkaePeyZzQNmANc+Ar+HKrLoB0o8hbxnJREhO8uLPHfpMG0CkG0olbLGkoT4Ss1rV7/fd538Cf/phZLjoflMWQ7neBuqOz8xc5mRyBngcZHh6P27lFO7SKvCXiZJts54UzDv67jczlPbvXAuiqNznAOULKdDC/YDC6xAiubtPUwgtJupm4pT/N7fzMKqSGm41cA85p9bAQ3v08A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=amperemail.onmicrosoft.com; dkim=pass header.d=amperemail.onmicrosoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-amperemail-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MUX68QX/R4Qpazayrgd2WmfL9cMWPrKWZO7pmGEdogg=; b=hH8MQ6qi9nupPUk9SOll9CENm7NhIhmWrhNPCSDWrupTrp5K2tx/Js1s1KBJje2fV7JEybGVIElaeyT36yeUEaTRq8GRKuQF7UmZqW3BycSZ/KwByGEXIx8QDr6NOYUG8PLMqTrrZoP/qvTsBY3IdmQhz+e8xEzYhPRUXLMMuio= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amperemail.onmicrosoft.com; Received: from DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) by PH0PR01MB6358.prod.exchangelabs.com (2603:10b6:510:12::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 16 Aug 2023 03:31:23 +0000 Received: from DM8PR01MB6824.prod.exchangelabs.com ([fe80::d62f:d774:15b0:4a40]) by DM8PR01MB6824.prod.exchangelabs.com ([fe80::d62f:d774:15b0:4a40%4]) with mapi id 15.20.6678.025; Wed, 16 Aug 2023 03:31:22 +0000 Message-ID: <71a7f15f-e81e-a529-b7fe-fb020ebeca91@amperemail.onmicrosoft.com> Date: Wed, 16 Aug 2023 11:31:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH] KVM: arm64: pmu: Resync EL0 state on counter rotation To: Leo Yan , Marc Zyngier Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Huang Shijie , Mark Rutland , Will Deacon References: <20230811180520.131727-1-maz@kernel.org> <20230814071627.GA3963214@leoy-huanghe> <87leecq0hj.wl-maz@kernel.org> <20230816030412.GB135657@leoy-huanghe.lan> From: Shijie Huang In-Reply-To: <20230816030412.GB135657@leoy-huanghe.lan> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: CH0PR04CA0089.namprd04.prod.outlook.com (2603:10b6:610:74::34) To DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM8PR01MB6824:EE_|PH0PR01MB6358:EE_ X-MS-Office365-Filtering-Correlation-Id: 41c3bde3-bb64-442e-a5c3-08db9e094359 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jahPFgXNu7EGUSwfQiwD/Ku/iX8WW4DEwVJJv2KUBnaPL+ts1YvUtJoCKjiWnRoZHKq0dYyucQjNXmIQE/ns5zLG2jKGCm3OJPAFPv2BOiu/ASObeqvaUuM6Wg45TribWJ7gDz/VwDIhwGm3OYJhXEd574NtjHgs7/w4y85aMcYIQukLFJG6rC3YVAM074U52W8GyfkFOwZJjTAwY4aQO92ZrjhFOAe1LJxK7gr41jEqC/va3jNEhgnuA4udDxMuW2Z5dynX2i2kBMiis+mZbEwJQ3PocT8B1ED1DxMiff5W54XPf4nACeTi0ue+H3UyZLkpfmOVW4wdtHagXPBs+l9rkPAxtjGODZmjVFpbTeD+ivHWmzozYkr3EsikyNQ2AO3os09B90PfLYsLZgURsCojpm+bRMqhkWQIff7Yj2sSH4qewARlU3767KTQ7s8qYlCyoB/nXdXCSqU5oNTTWlFgCX7qkVBRmWeCK0kQa/t8SdCpJiZfs/L9zpRIAUKKJDq8jg+kwM6F3HxU4PWWtD+DhXMPyntdwnKzADzB+aIZ1uqaGEpKyGGYHxdNsQCLZieihDGvDajBpthTzOQuE0hNv3Nd4CSIXdqrvztvqpgpW0i8UbuB88pMKPxfPuRxjj27ACTfMV6v8PYm9Y7eXA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM8PR01MB6824.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(366004)(396003)(39850400004)(346002)(136003)(1800799009)(451199024)(186009)(6666004)(54906003)(31686004)(42882007)(66476007)(66556008)(66946007)(6512007)(6486002)(6506007)(2906002)(478600001)(26005)(110136005)(7416002)(5660300002)(2616005)(83380400001)(41300700001)(316002)(52116002)(8936002)(4326008)(83170400001)(8676002)(38350700002)(38100700002)(31696002)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?a0tmcWFpMVpRbEltdzV6YXVZQUR4akR0UDNna2NaOFZ3TVN5QnBBYURGVDI0?= =?utf-8?B?amJ2Qkc5c2Q5ZXc1SVJyWi9iSElaQ0N5U1hMcHdUOGhQNFYyakJtRDI4dVY3?= =?utf-8?B?dE9hamhiNkpjZjR0RXluTk1qL2ZndzFhN2tGa3NEbzUwSWxjYXFlMEgyRWFq?= =?utf-8?B?cXYzUFJ1R2c2RXNUWkZxbksycmdUQndXejlDOEpERkptZnRFMFg4QkJhY0hj?= =?utf-8?B?WURrb2tGVDUzYmRBc3FibDFrd0FzWjJTZ0lVYSsxUVpSbjJ3UWw2S0c1Q2Vs?= =?utf-8?B?aDFCbVJFdzZKYmVqT0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1oNXBhS0ZDMXg4Y1BDS3hEaWRa?= =?utf-8?B?c2pMTjBwYm85SEVyL09HVDlGc3lTMWhVTEVwUHZlS1F2VDdHWlJmYmxmTU92?= =?utf-8?Q?qRAa5NJdPzREP4vET91Hi/0=3D?= X-OriginatorOrg: amperemail.onmicrosoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41c3bde3-bb64-442e-a5c3-08db9e094359 X-MS-Exchange-CrossTenant-AuthSource: DM8PR01MB6824.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 03:31:22.6683 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NnJNEqJ2Vj/iUxj1GFepStwNpn/Euotcytu+Sm+SivtS9EChFvDHC05Zf8zdAhvQQ3gOILsDtO9pL9Mfi2SqaJdBledDFxemcSc+SilhsR9Iz0q6C05pTpgF2aYVfmtA X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB6358 Hi Leo, 在 2023/8/16 11:04, Leo Yan 写道: > On Tue, Aug 15, 2023 at 07:32:40AM +0100, Marc Zyngier wrote: >> On Mon, 14 Aug 2023 08:16:27 +0100, >> Leo Yan wrote: >>> On Fri, Aug 11, 2023 at 07:05:20PM +0100, Marc Zyngier wrote: >>>> Huang Shijie reports that, when profiling a guest from the host >>>> with a number of events that exceeds the number of available >>>> counters, the reported counts are wildly inaccurate. Without >>>> the counter oversubscription, the reported counts are correct. >>>> >>>> Their investigation indicates that upon counter rotation (which >>>> takes place on the back of a timer interrupt), we fail to >>>> re-apply the guest EL0 enabling, leading to the counting of host >>>> events instead of guest events. >>> Seems to me, it's not clear for why the counter rotation will cause >>> the issue. >> Maybe unclear to you, but rather clear to me (and most people else on >> Cc). > I have to admit this it true. > >>> In the example shared by Shijie in [1], the cycle counter is enabled >>> for both host and guest >> No. You're misreading the example. We're profiling the guest from the >> host, and the guest has no PMU access. >> >>> and cycle counter is a dedicated event >>> which does not share counter with other events. Even there have >>> counter rotation, it should not impact the cycle counter. >> Who says that we're counting cycles using the cycle counter? This is >> an event like any other, and it can be counted on any counter. > Sorry for noise. > >>> I mean if we cannot explain clearly for this part, we don't find the >>> root cause, and this patch (and Shijie's patch) just walks around the >>> issue. >> We have the root cause. You just need to think a bit harder. > Let me elaborate a bit more for my concern. The question is how we can > know the exactly the host and the guest have the different counter > enabling? > > Shijie's patch relies on perf event rotation to trigger syncing for > PMU PMEVTYPER and PMCCFILTR registers. The perf event rotation will > enable and disable some events, but it doesn't mean the host and the > guest enable different counters. If we use the perf event rotation to In the event rotation, it does mean the host and guest use different counters. Please read my previoust email which shows an example. :) Thanks Huang Shijie > trigger syncing, there must introduce redundant operations. > >