From nobody Thu Dec 18 18:50:05 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2A1821D585 for ; Thu, 5 Dec 2024 15:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733411007; cv=none; b=XIm+vD+VTWMAn8Hg5S8b3LGY6wzX6dj7+b7ykDCAcFk1Z0dzEjBAfD8HarSFNfZczW7cQ+cg25LmVxU5OluMD+MSL+8MhYhER0diVBb+SiS9cZGXIKE4HI1vaiP52JpTxTEEiW9lZEVYWXFADb8BCROn2US09cOH5Vo3QW0TVHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733411007; c=relaxed/simple; bh=2iJ29fh1AWeIbKMcfJ3M2ftbDMnexR7YdF6JACF/QqY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Rj5YswRTKtGA52XnBMZM5E6Q/V3io98ffewYU1R1oFAcqn6xGSIk54RwkozUqm60GSOANiV9vQ2ew9PAr6PtrcGIOopwgdFfIBVQHptIdgBiVnmk0aQCY/oWURFe8gdrjQZ+uf8IbTwrP6cSZqFFhyMo7wDhx3orqbjDI1AmAug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=w9aVK67m; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="w9aVK67m" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-434941aa9c2so6434025e9.3 for ; Thu, 05 Dec 2024 07:03:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733411003; x=1734015803; darn=vger.kernel.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=adk2aH/4GDKjaqv21ityBwrpMTayAeXtNiToa+jV3u8=; b=w9aVK67mkW/RzvC6PkXUYXAZfSyyPrAHgnCtRkboUeALJmvQMZvCjXwEYYTBauqDBB EMuT3bKefu+hoeTX9i3+8jXdBGTL9Iw3VU00bXu77O9QOyqPEMwEjtlk6MnTaffeGtr8 APOI/43Vu+dnPA/A6oeobT6VO1bfxp29VZ/2hdysbkxWJraZJ3l3upfwD4+pbB3ZjU3y EAswsiGu8dREJX4wqu8Q1bWG6ylcn+vS5bfMoXCq591QzIYiGmEJXmuj/8nhUcCQGro6 FgE7jsLsb1SBMtvywwEZt/tnhMAPVY0KUcZ8sVqGR4afZbPDWAW/YCBeVsLHB4EDha/m pbOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733411003; x=1734015803; 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=adk2aH/4GDKjaqv21ityBwrpMTayAeXtNiToa+jV3u8=; b=mLXdz1miMAgA+7sNd7j5zLps6IsajNYr9CfiUrzgX2dXR/x6F3Xd7EpsfCtfZOSyCj iS6X4CtnWJuKjSjFSChcG8mTVBfauhyKDTIpGDpL7otw4Rfrojnhebojcn69BUuNIjHP adpBy3iooou62r3Nd6LohNGJSTGoo0bqx6r0Y2peK8SdYQG7wzz3f2anoIhzDcCirDlV XEcr5CxbyJ7xxLr6s8+CmPujLqVN/6QFkH+Nqv+cbP0TYjm+OqwAYH41d0AGiZT8w0KR /nt94t1tq3ole27oL3N0Q/mfiXfjgUvKV8Nm3Pxymo1GiEhBNBKmWOg3PV2qiK9HAEOC WKTQ== X-Gm-Message-State: AOJu0YxzYc358Xg7pMnwGPCxl4VJSll3VGhyWK5ndHw4EpDko4D5JtxY ftEAJ8jz4E3vKx+fUWZMsxPo9E4nBf3Bl6Su0XD9giTYH6sK5NXajvowmxU97DG4UEp95A== X-Google-Smtp-Source: AGHT+IF7/7yWatbx9m9EKm+cZ06mzA7cFMWteGbOArm8KBWUGs6ZGHFU/BgFWuC7Z2P10SoaWhuvRscf X-Received: from wmql16.prod.google.com ([2002:a05:600c:4f10:b0:434:a346:77e5]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:19ce:b0:431:5871:6c5d with SMTP id 5b1f17b1804b1-434d3f8e454mr83608715e9.3.1733411003473; Thu, 05 Dec 2024 07:03:23 -0800 (PST) Date: Thu, 5 Dec 2024 16:02:33 +0100 In-Reply-To: <20241205150229.3510177-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241205150229.3510177-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2178; i=ardb@kernel.org; h=from:subject; bh=k2Mzp/wMZGFRYdDSzEySynVgHnYysUYKKCSLnjGJFrc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT3wQBcD07YY/8JkFrHzO87lqd8rFWx/6/Ni8pHKSFe+E zmsocwdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMYEO4OAVgIofeMzIsro/PTHeecONt0M87 8/ayrVOX+HL/XP75ZUbHFnvqWThXMTKca5NMzX3+x+PBosBvlytrP655xf77i8p7/7u7TA9UaH/ gBgA= X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241205150229.3510177-11-ardb+git@google.com> Subject: [PATCH v2 3/6] arm64/kvm: Configure HYP TCR.PS/DS based on host stage1 From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , Quentin Perret , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel When the host stage1 is configured for LPA2, the value currently being programmed into TCR_EL2.T0SZ may be invalid unless LPA2 is configured at HYP as well. This means kvm_lpa2_is_enabled() is not the right condition to test when setting TCR_EL2.DS, as it will return false if LPA2 is only available for stage 1 but not for stage 2. Similary, programming TCR_EL2.PS based on a limited IPA range due to lack of stage2 LPA2 support could potentially result in problems. So use lpa2_is_enabled() instead, and set the PS field according to the host's IPS, which is capped at 48 bits if LPA2 support is absent or disabled. Whether or not we can make meaningful use of such a configuration is a different question. Cc: Signed-off-by: Ard Biesheuvel --- arch/arm64/kvm/arm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a102c3aebdbc..7b2735ad32e9 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1990,8 +1990,7 @@ static int kvm_init_vector_slots(void) static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits) { struct kvm_nvhe_init_params *params =3D per_cpu_ptr_nvhe_sym(kvm_init_par= ams, cpu); - u64 mmfr0 =3D read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); - unsigned long tcr; + unsigned long tcr, ips; =20 /* * Calculate the raw per-cpu offset without a translation from the @@ -2005,6 +2004,7 @@ static void __init cpu_prepare_hyp_mode(int cpu, u32 = hyp_va_bits) params->mair_el2 =3D read_sysreg(mair_el1); =20 tcr =3D read_sysreg(tcr_el1); + ips =3D FIELD_GET(TCR_IPS_MASK, tcr); if (cpus_have_final_cap(ARM64_KVM_HVHE)) { tcr |=3D TCR_EPD1_MASK; } else { @@ -2014,8 +2014,8 @@ static void __init cpu_prepare_hyp_mode(int cpu, u32 = hyp_va_bits) tcr &=3D ~TCR_T0SZ_MASK; tcr |=3D TCR_T0SZ(hyp_va_bits); tcr &=3D ~TCR_EL2_PS_MASK; - tcr |=3D FIELD_PREP(TCR_EL2_PS_MASK, kvm_get_parange(mmfr0)); - if (kvm_lpa2_is_enabled()) + tcr |=3D FIELD_PREP(TCR_EL2_PS_MASK, ips); + if (lpa2_is_enabled()) tcr |=3D TCR_EL2_DS; params->tcr_el2 =3D tcr; =20 --=20 2.47.0.338.g60cca15819-goog