Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1290456pxb; Fri, 22 Jan 2021 11:39:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOZoCMNo98WWypA+yMzgd8l9R9oQxE6I5iY9TKTdJ2Opo66d4yJOODSlTqaBzeGfvEbHYY X-Received: by 2002:aa7:ca55:: with SMTP id j21mr955392edt.172.1611344365288; Fri, 22 Jan 2021 11:39:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611344365; cv=none; d=google.com; s=arc-20160816; b=u+wu5iHcQUkysbL5DqaQK1YHADPJpIEbMuzDxKUmGyCEW0TM/kRhTn0hhOe4GvYE3o RsWt672X3L11vYfhnhbz3oS6H41FWIbpDXkbC54LkCk0Smp9ICUsd2c6Ytk6CzzaOPDq YbRNYD2Wm/OsxfHG2W/Fg+m/wvwq8fYFfOLxMT1qZvnwSYtP6BIaLr4zGNfrIwTycy70 xotGNXImguMDUFE888UF+ggrXPgoBFjpL07wd6blcyuD1mOQC62UjxghbaiCYqOtLpv+ NU7McOrpvaYg107Lc2DlLiktEgJe+W1TMz/W4/FOQEZdLSJ3OMePY3xBhtgALk9bt32w o2bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=XJlxfS/rnX/20LRIRb1BhgiO0di3Z2rrF6HhhWdk2zQ=; b=j2+ZKX3Q6G1wP/pVD0U54dmYX6Ldjlf2XOkd+Le4Cb68E/6YamIB/Z6VqOp7rlWZwB bWdPL9ma6i7EUYlZXrmCBVyFO88R8W1Un1MzvRvhyvqOut1myWDeucqHYRreqUoWzykg Kt62X6pwgNMetV+G4Jz+hIa5iYoNSl9XbKAoOY7dGKFr0tAz7IXoxV0ywbAmvftnBG4L K/AohpEVYZkNBW6XFrnF+yCChH/X7cerL3ebEu6u7rJsKMHgHm2sZExcYDkJ1sT3m21b gDSjM5Pjn9NOVpEq7/xbca42yKoEh+2QWbIqFd2hmoaotwCXcP6+pjJCU9jwPpyOBr30 TEnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si3403146eje.398.2021.01.22.11.39.01; Fri, 22 Jan 2021 11:39:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730525AbhAVT0E (ORCPT + 99 others); Fri, 22 Jan 2021 14:26:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:40884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730408AbhAVSyb (ORCPT ); Fri, 22 Jan 2021 13:54:31 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0B8F623AC1; Fri, 22 Jan 2021 18:53:47 +0000 (UTC) Date: Fri, 22 Jan 2021 18:53:45 +0000 From: Catalin Marinas To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , David Brazdil , Alexandru Elisei , Ard Biesheuvel , Jing Zhang , Ajay Patil , Prasad Sodagudi , Srinivas Ramana , James Morse , Julien Thierry , Suzuki K Poulose , kernel-team@android.com Subject: Re: [PATCH v4 10/21] arm64: cpufeature: Use IDreg override in __read_sysreg_by_encoding() Message-ID: <20210122185344.GH8567@gaia> References: <20210118094533.2874082-1-maz@kernel.org> <20210118094533.2874082-11-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210118094533.2874082-11-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 09:45:22AM +0000, Marc Zyngier wrote: > __read_sysreg_by_encoding() is used by a bunch of cpufeature helpers, > which should take the feature override into account. Let's do that. > > For a good measure (and because we are likely to need to further > down the line), make this helper available to the rest of the > non-modular kernel. > > Code that needs to know the *real* features of a CPU can still > use read_sysreg_s(), and find the bare, ugly truth. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/cpufeature.h | 1 + > arch/arm64/kernel/cpufeature.c | 15 +++++++++++++-- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 465d2cb63bfc..fe0130d6c0ff 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -602,6 +602,7 @@ void __init setup_cpu_features(void); > void check_local_cpu_capabilities(void); > > u64 read_sanitised_ftr_reg(u32 id); > +u64 __read_sysreg_by_encoding(u32 sys_id); > > static inline bool cpu_supports_mixed_endian_el0(void) > { > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index aaa075c6f029..48a011935d8c 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -1149,14 +1149,17 @@ u64 read_sanitised_ftr_reg(u32 id) > EXPORT_SYMBOL_GPL(read_sanitised_ftr_reg); > > #define read_sysreg_case(r) \ > - case r: return read_sysreg_s(r) > + case r: val = read_sysreg_s(r); break; > > /* > * __read_sysreg_by_encoding() - Used by a STARTING cpu before cpuinfo is populated. > * Read the system register on the current CPU > */ > -static u64 __read_sysreg_by_encoding(u32 sys_id) > +u64 __read_sysreg_by_encoding(u32 sys_id) > { > + struct arm64_ftr_reg *regp; > + u64 val; > + > switch (sys_id) { > read_sysreg_case(SYS_ID_PFR0_EL1); > read_sysreg_case(SYS_ID_PFR1_EL1); > @@ -1199,6 +1202,14 @@ static u64 __read_sysreg_by_encoding(u32 sys_id) > BUG(); > return 0; > } > + > + regp = get_arm64_ftr_reg(sys_id); > + if (regp && regp->override_mask && regp->override_val) { > + val &= ~*regp->override_mask; > + val |= (*regp->override_val & *regp->override_mask); > + } > + > + return val; Ah, now the previous patch makes more sense. I don't particularly like this but I can't tell how to work around it. I was hoping that the overriding feature behaves more like a secondary CPU that limits all the overridden features. However, this approach would fail for FTR_EXACT cases (like PAC, though I wonder whether it fails already with your previous patch since the boot CPU value won't match the override, hence dropping to the safe one). -- Catalin