From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F832CD1296 for ; Wed, 10 Apr 2024 10:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:CC:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=y5hwIWPGRNVn7JoHYamSiFvjN9uuL1fNJR1Wc0ujKfQ=; b=Nt8MZQ2PDxgBf7BolA7uzSGH5j +X/s/qw4dzcuB5oJg+WBi2FKH0zbQqYbbSUnBFwGF73aoVPLXY9AZNwZQ7fhaiZh9sibQNxFbW7zx recSqjISQXajc8QpcrbpImu+aPF5kDSRnRXbMS+cer0cbL50JkEeDp3FnLMGWzXL03MxyKEQrX6Pc Jx77anjGAsCCaN0jhGNFt0JYGqOd3wRF5y+F7H8/eej2oZWHj6TvlqtXbl8KUIrbuKvQrlhWAr5uq c5cDOr9wImqiDgASnU0x3657PFKCXJPZg/hUF4h82aG/EFiVSfqnu9LtjU0NmqlOsbEILkSFf5MYq BV4MdA3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruUt1-00000006Jv3-375z; Wed, 10 Apr 2024 10:08:59 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruUsx-00000006JsT-45Cm for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 10:08:58 +0000 Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4VDz6K4H9Bz21kdn; Wed, 10 Apr 2024 18:07:53 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 0819114037E; Wed, 10 Apr 2024 18:08:49 +0800 (CST) Received: from [10.67.121.177] (10.67.121.177) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Wed, 10 Apr 2024 18:08:48 +0800 CC: , , , , , , , , Subject: Re: [PATCH] arm64: arm_pmuv3: Correctly extract and check the PMUVer To: Will Deacon References: <20240408081158.15291-1-yangyicong@huawei.com> <20240409160915.GA24004@willie-the-truck> From: Yicong Yang Message-ID: <19b6e749-15d7-e522-95ad-b1ae42f032df@huawei.com> Date: Wed, 10 Apr 2024 18:08:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20240409160915.GA24004@willie-the-truck> X-Originating-IP: [10.67.121.177] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_030856_401584_0391CCEA X-CRM114-Status: GOOD ( 19.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2024/4/10 0:09, Will Deacon wrote: > On Mon, Apr 08, 2024 at 04:11:58PM +0800, Yicong Yang wrote: >> From: Yicong Yang >> >> Currently we're using "sbfx" to extract the PMUVer from ID_AA64DFR0_EL1 >> and skip the init/reset if no PMU present when the extracted PMUVer is >> negative or is zero. However for PMUv3p8 the PMUVer will be 0b1000 and >> PMUVer extracted by "sbfx" will always be negative and we'll skip the >> init/reset in __init_el2_debug/reset_pmuserenr_el0 unexpectedly. >> >> So this patch use "ubfx" instead of "sbfx" to extract the PMUVer. If >> the PMUVer is implementation defined (0b1111) then reset it to zero >> and skip the reset/init. Previously we'll also skip the init/reset >> if the PMUVer is higher than the version we known (currently PMUv3p9), >> with this patch we'll only skip if the PMU is not implemented or >> implementation defined. This keeps consistence with how we probe >> the PMU in the driver with pmuv3_implemented(). >> >> Signed-off-by: Yicong Yang >> --- >> arch/arm64/include/asm/assembler.h | 5 ++++- >> arch/arm64/include/asm/el2_setup.h | 5 ++++- >> 2 files changed, 8 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h >> index ab8b396428da..3b7373d6c565 100644 >> --- a/arch/arm64/include/asm/assembler.h >> +++ b/arch/arm64/include/asm/assembler.h >> @@ -480,7 +480,10 @@ alternative_endif >> */ >> .macro reset_pmuserenr_el0, tmpreg >> mrs \tmpreg, id_aa64dfr0_el1 >> - sbfx \tmpreg, \tmpreg, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 >> + ubfx \tmpreg, \tmpreg, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 >> + cmp \tmpreg, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF >> + csel \tmpreg, xzr, \tmpreg, eq // If PMU's IMP_DEF, regard it >> + // as not implemented and skip >> cmp \tmpreg, #1 // Skip if no PMU present >> b.lt 9000f >> msr pmuserenr_el0, xzr // Disable PMU access from EL0 > > I think the cmp/csel/cmp/b.lt sequence might be a little tidier if you > reworked it to use ccmp. For example, something like (totally untested): > > cmp \tmpreg, ID_AA64DFR0_EL1_PMUVer_NI > ccmp \tmpreg, ID_AA64DFR0_EL1_PMUVer_IMP_DEF, #4, ne > > would then, I think, mean we could just b.eq 9000f. But please check > this because encoding nzcv as an immediate always catches me out. > ok. will have a test on my boards. Wrote a small demo for checking all the available versions with suggested code and seems work fine. >> diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h >> index b7afaa026842..2438e12b60c5 100644 >> --- a/arch/arm64/include/asm/el2_setup.h >> +++ b/arch/arm64/include/asm/el2_setup.h >> @@ -59,7 +59,10 @@ >> >> .macro __init_el2_debug >> mrs x1, id_aa64dfr0_el1 >> - sbfx x0, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 >> + ubfx x0, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 >> + cmp x0, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF >> + csel x0, xzr, x0, eq // If PMU's IMP_DEF, regard it >> + // as not implemented and skip >> cmp x0, #1 >> b.lt .Lskip_pmu_\@ // Skip if no PMU present >> mrs x0, pmcr_el0 // Disable debug access traps > > Similar sort of thing here. will also need to change the cond after the .Lskip_pmu_\@ like below: .macro __init_el2_debug mrs x1, id_aa64dfr0_el1 - sbfx x0, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 - cmp x0, #1 - b.lt .Lskip_pmu_\@ // Skip if no PMU present + ubfx x0, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 + cmp x0, #ID_AA64DFR0_EL1_PMUVer_NI + ccmp x0, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF, #4, ne + b.eq .Lskip_pmu_\@ // Skip if no PMU present or IMP_DEF mrs x0, pmcr_el0 // Disable debug access traps ubfx x0, x0, #11, #5 // to EL2 and allow access to .Lskip_pmu_\@: - csel x2, xzr, x0, lt // all PMU counters from EL1 + csel x2, xzr, x0, eq // all PMU counters from EL1 Will respin a v2 after tests. Thanks. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel