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 B5BC4C4167B for ; Wed, 29 Nov 2023 11:19:45 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=kgHtJVh5ILe8WXKhjfQfe0pD4Kd+eAEj992HB/9F2Og=; b=UbrHS+Hw8Sm+1qJDn2fRe3t0kF yLDPJbJjXkwFh1swzheu4LKu+ARcP3/EpMZvdom/NRnl2dbPVavnqTB2qHj4ta7dMxJGcG81bSv7j pep5owxwnw4lb8BI47zk8scGT3CYHDABrhENekElLTMrz+eYWf1QDFQ9SZdbosMC6FXL582m0VGtC x0RoSh9oiKE/y6rAe1FZy3d/ESTvv3IHpqUjo51Hw8AvHFSKHGPfPNh39Mlkefd9VXXi6+oD6o1eO HVIvPgKt2GzX4eJZdAJGfp2BKVmHhXNP21wRYyo4ES8wDMhKo7XFKM9ATb61ILWzlBQfMKFUqV9IY 2lXvHE+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8Ib3-0080ZJ-1O; Wed, 29 Nov 2023 11:19:13 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8Iad-0080Cl-0Y for linux-arm-kernel@bombadil.infradead.org; Wed, 29 Nov 2023 11:18:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7tzpQ8b3CvpcOPZPJVY8+PJI69jn1laficpNca8az1s=; b=Ff88tyx3FbloE6NS57GXSMiWPe iZnfWSEealf8uvbHPsvib2CvWLG1uQ3VwhDvg0gA2Mq31xVBikBLY0qpUBn+T376IslrOU6Z+TMbQ JLw33umtm5DCNgCZonflggQwsU905yJtLH1eDhyFJk+yat8DVdbHZoKfDZarnUZ7QsbWn1df6mQXa ifoc9l69b/IEWV6BNZG7qxx1mBhPxGjzXq2z83vGFxplPXKQLu4EAZgHBXNEqXVVBIO5RzwUvp2Mb 2yvEzAdRV4dOXRp/t/kyUWPoqgTCo9PX3eTj0VZqk+NuFalOn43e/EcqVdvS7j2zkPxrArY3qepyh NGmaXqKA==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8IaC-000KBk-15 for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 11:18:38 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-333127febb2so1264954f8f.2 for ; Wed, 29 Nov 2023 03:18:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701256697; x=1701861497; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7tzpQ8b3CvpcOPZPJVY8+PJI69jn1laficpNca8az1s=; b=D6HXHY4xWyoS7xT/RlmyG6uB+XZbzciO48RXAMhs/og+czONbncSfxh5Du7qKsLIgG QqPuiCo3IkrW6aN5pBBf3OcrFsPiG4yo7m9CgSXRLKyn0FcruOtdQkza38MJ5XFErBlH oy3EmImy43MyxPXP0LCC/3vUhfXYe9BOirDaCWVhv7jugC97u5Me5RPD756MRxtRiYEc JtfdlzpYn3oYc46SkqX9/NABkZd2hUJJybvOMRtQUJx+aFmr3VL2g8FbZE0GiVGun59A AZHzaK/IcRs9AkpypuF6H1eUIj+G6KYfj8+dXBaZv/8hlSKd++6zydMMHiug59b21UoV 3gCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701256697; x=1701861497; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7tzpQ8b3CvpcOPZPJVY8+PJI69jn1laficpNca8az1s=; b=eRHTxrqzwpc720eqh+7bqqY3ZMEziLkup/zYzkidRD8eXtBWDzbTWOI/EUJ/jD2eeR adDvXEMJv16C7cl+YYIULjkVWxudG95NhrqcemiMDFOV5VFBJYUmaLa4NUorJQUdACkS GzBUI46bJcKanZeYcyx4jOFGkPg0aVlIS2Bj+0VHTCcxLF/SYfVocxzQyNEXM4x7Icp2 aD/HI09S9uSNqFqbvviTlikj1pWuwCV0zSDZHvWt9qmsndebjOWgfy+0zDIyXDO0zmT8 I47z9xJj+Oyg+FraVi40+TrDnOVHJAUwvIW68U7hYFbAgdD1p14cZ8LDyACrf2i5jOZL J/3Q== X-Gm-Message-State: AOJu0YwtdAHHaIdiwFAfcabbsNPj6WYRHVEILKGqRuwnWdYzKKkRpwys lYFouw+tXrKan2Eazi+0TRs/2zSVDKFh0kfK0zpFfE9akXXU+RNrinaYP1TfvfdHIY8CFVJrbqM 2/Ba3vbby7ZnvDfndmsnnE/b7NnE+9U14yNmHTey2xYx3Lp3MZnLN+xfbpCT8/o3csXYYfrKPMG 4= X-Google-Smtp-Source: AGHT+IHgfYzD5O5EIIRxhDWTs64LWoPQi3KW2EOUqHcgBBKLajw95Jx739f3AVlpX27JR8eFxoHv2A5W X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:f6d1:0:b0:331:4466:d921 with SMTP id y17-20020adff6d1000000b003314466d921mr266777wrp.14.1701256697685; Wed, 29 Nov 2023 03:18:17 -0800 (PST) Date: Wed, 29 Nov 2023 12:16:23 +0100 In-Reply-To: <20231129111555.3594833-43-ardb@google.com> Mime-Version: 1.0 References: <20231129111555.3594833-43-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3273; i=ardb@kernel.org; h=from:subject; bh=M+8TEMjnFw2RuN6vaSsPLxEzSs3QtGUlythSA5tSr1Y=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JITVdtsu38P4lp/NfdmznOVey9fiz9Zpn+r89rbZ3cmzwi 04UqxHuKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNh52H4n3B0yjnGs5wXvl0S WPQvbP+K2k+rRQSm25u4bkvYqT7dVY2R4eML447KE8J1PrfCX9W23Lm5dn6M4uOu/JhljB/S03b a8AMA X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129111555.3594833-70-ardb@google.com> Subject: [PATCH v6 27/41] arm64: cpufeature: Add helper to test for CPU feature overrides From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_111824_256610_354F14A9 X-CRM114-Status: GOOD ( 18.94 ) 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 From: Ard Biesheuvel Add some helpers to extract and apply feature overrides to the bare idreg values. This involves inspecting the value and mask of the specific field that we are interested in, given that an override value/mask pair might be invalid for one field but valid for another. Then, wire up the new helper for the hVHE test - note that we can drop the sysreg test here, as the override will be invalid when trying to enable hVHE on non-VHE capable hardware. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 39 ++++++++++++++++++++ arch/arm64/kernel/cpufeature.c | 9 +---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index f6d416fe49b0..a41cb0bc220b 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -909,6 +909,45 @@ extern struct arm64_ftr_override id_aa64isar2_override; extern struct arm64_ftr_override arm64_sw_feature_override; +static inline +u64 arm64_apply_feature_override(u64 val, int feat, int width, + const struct arm64_ftr_override *override) +{ + u64 oval = override->val; + + /* + * When it encounters an invalid override (e.g., an override that + * cannot be honoured due to a missing CPU feature), the early idreg + * override code will set the mask to 0x0 and the value to non-zero for + * the field in question. In order to determine whether the override is + * valid or not for the field we are interested in, we first need to + * disregard bits belonging to other fields. + */ + oval &= GENMASK_ULL(feat + width - 1, feat); + + /* + * The override is valid if all value bits are accounted for in the + * mask. If so, replace the masked bits with the override value. + */ + if (oval == (oval & override->mask)) { + val &= ~override->mask; + val |= oval; + } + + /* Extract the field from the updated value */ + return cpuid_feature_extract_unsigned_field(val, feat); +} + +static inline bool arm64_test_sw_feature_override(int feat) +{ + /* + * Software features are pseudo CPU features that have no underlying + * CPUID system register value to apply the override to. + */ + return arm64_apply_feature_override(0, feat, 4, + &arm64_sw_feature_override); +} + u32 get_kvm_ipa_limit(void); void dump_cpu_features(void); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index b95374387946..889411f87e90 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2034,14 +2034,7 @@ static bool has_nested_virt_support(const struct arm64_cpu_capabilities *cap, static bool hvhe_possible(const struct arm64_cpu_capabilities *entry, int __unused) { - u64 val; - - val = read_sysreg(id_aa64mmfr1_el1); - if (!cpuid_feature_extract_unsigned_field(val, ID_AA64MMFR1_EL1_VH_SHIFT)) - return false; - - val = arm64_sw_feature_override.val & arm64_sw_feature_override.mask; - return cpuid_feature_extract_unsigned_field(val, ARM64_SW_FEATURE_OVERRIDE_HVHE); + return arm64_test_sw_feature_override(ARM64_SW_FEATURE_OVERRIDE_HVHE); } #ifdef CONFIG_ARM64_PAN -- 2.43.0.rc1.413.gea7ed67945-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel