Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2265178pxb; Mon, 11 Jan 2021 05:32:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmxVNzHulJQ5NHPp5MExRvf9XIGYYG9Q14iZIwLqaGIkVR+ZFcP7mDV6BBMbZEL5dLyJKs X-Received: by 2002:a17:906:3ac3:: with SMTP id z3mr10743575ejd.449.1610371975925; Mon, 11 Jan 2021 05:32:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610371975; cv=none; d=google.com; s=arc-20160816; b=iNKijuNBBsVthqXWs8y5iGbLMHC1R9lwJ2+GFrI6gKoueknF3N+0CL7r9tnorpzOQ2 TPsDCqfeO/XHDt/Fh32Nw9h1YzBjBrbo6OYb2TF0VuQWwPmmlg+Q4e5FCnwaIz9VqKxQ 9KDlbljFDm97w1353bEsTbL+fm6ZymqjjAzXyjhi7hMer5ENnMrw7Kt5FKzu7g8acMne LzqJZK7HFjZRjQhQWs1ffTwBsE34pMKC9QQZo39l4catz7jjAVRJ9kOx9muRXPokoqtA X7fYSrwzKzPx+fKnj0KdLCSPd6hhC5I6++rz7gzGgGUFZ0i9R51G09J+mOOb7NtLwQ1U OfkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Acea7BgqRJ7A7hHBbF2bEsvEvFk73xM04Vu43xKKD8g=; b=udHZ7fXbhwuADsKJDHl/cFWJNEjPROGt1ZUuOSEVS714r69Pow+RKPwoh34cD4sH6I QIJ9srVRlNUnzrDChX84LRijhNy20sGcY54rwlRTLwVRORWWJHn6/a4MLifRKHvnO55o MUmymbuEvGS84pvo9/cCooCXWF+E+7rkDkDM9zeAAyjpUYpFKHmAwtgCrGh9iZQ3OYc1 yYYFVgYXIGyI94B2KO7Rjyg/sYNhstqP0TiK9Q6fv1MYQ9NeyRf1uV9Vr8RPTbssMFa3 aajt3OQ70pPwzAUyRF6QibHtt7mOTpiqMFF2zPgH7Mz6Sn5/bqmpVRUPSAAUQl5Knf3Z n40Q== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si6558615edk.605.2021.01.11.05.32.30; Mon, 11 Jan 2021 05:32:55 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726743AbhAKN3w (ORCPT + 99 others); Mon, 11 Jan 2021 08:29:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:42420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732761AbhAKN3p (ORCPT ); Mon, 11 Jan 2021 08:29:45 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1307C223E8; Mon, 11 Jan 2021 13:28:29 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kyxFD-006gPD-CK; Mon, 11 Jan 2021 13:28:27 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Cc: Catalin Marinas , 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: [PATCH v3 09/21] arm64: cpufeature: Add global feature override facility Date: Mon, 11 Jan 2021 13:27:59 +0000 Message-Id: <20210111132811.2455113-10-maz@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210111132811.2455113-1-maz@kernel.org> References: <20210111132811.2455113-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, dbrazdil@google.com, alexandru.elisei@arm.com, ardb@kernel.org, jingzhangos@google.com, pajay@qti.qualcomm.com, psodagud@codeaurora.org, sramana@codeaurora.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a facility to globally override a feature, no matter what the HW says. Yes, this is dangerous. Nothing uses this yet, so we are pretty safe. For now. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/cpufeature.h | 2 ++ arch/arm64/kernel/cpufeature.c | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 9a555809b89c..465d2cb63bfc 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -75,6 +75,8 @@ struct arm64_ftr_reg { u64 sys_val; u64 user_val; const struct arm64_ftr_bits *ftr_bits; + u64 *override_val; + u64 *override_mask; }; extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0; diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index e99eddec0a46..492321054bd5 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -544,13 +544,17 @@ static const struct arm64_ftr_bits ftr_raz[] = { ARM64_FTR_END, }; -#define ARM64_FTR_REG(id, table) { \ - .sys_id = id, \ - .reg = &(struct arm64_ftr_reg){ \ - .name = #id, \ - .ftr_bits = &((table)[0]), \ +#define ARM64_FTR_REG_OVERRIDE(id, table, v, m) { \ + .sys_id = id, \ + .reg = &(struct arm64_ftr_reg){ \ + .name = #id, \ + .ftr_bits = &((table)[0]), \ + .override_val = v, \ + .override_mask = m, \ }} +#define ARM64_FTR_REG(id, table) ARM64_FTR_REG_OVERRIDE(id, table, NULL, NULL) + static const struct __ftr_reg_entry { u32 sys_id; struct arm64_ftr_reg *reg; @@ -786,6 +790,18 @@ static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new) val &= valid_mask; + if (reg->override_mask && reg->override_val) { + u64 override = val; + override &= ~*reg->override_mask; + override |= (*reg->override_val & *reg->override_mask); + + if (val != override) + pr_warn("%s: forced from %016llx to %016llx\n", + reg->name, val, override); + + val = override; + } + reg->sys_val = val; reg->strict_mask = strict_mask; reg->user_mask = user_mask; -- 2.29.2