From nobody Sun Feb 8 04:57:33 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 0270734AAEB for ; Tue, 23 Dec 2025 19:37:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766518668; cv=none; b=orUzHfO6ijOpYL6+RElqjOjjO/0FV2Gh/EXc6gj0jjlOn0vCUdilAhEdDeJNxXIkNfb94j6nmkUisH0VwA2XVpba/vnqiSPXEV+JsIZtxMe+xhwSaO+PW9ZW27dtobnDhf7vG1um/yRxXYrQHlOx2O+l+/zTZROwlc4Hd3cvqLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766518668; c=relaxed/simple; bh=P0bttLFLFuRh+QxOVIGbbBLN7a1dGQScl6lQT1zbSfg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WTJz4E42yxkMqrBJL47UQfKbxzdmdVANNL5HRnA63fMFPHYiNGOS3U0vcPOorWslb7R3bAk1MhcMzyR79wZdkPwRW+aewsqU/cL/0675Tlh9zUyc4x0mZ4cn/bx/dLH6EPMQ3ebFXPz8sQWqtZkyi9C3DgSIEZ1u9CyqhM2eCw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pekangas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IoQW/rNO; arc=none smtp.client-ip=209.85.214.201 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--pekangas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IoQW/rNO" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-29f177f4d02so117796335ad.2 for ; Tue, 23 Dec 2025 11:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766518666; x=1767123466; 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=f+/9YLEDg3kvIVJ8uIdd0LLUvUHitQ7YUX6eQO1NlK0=; b=IoQW/rNOeyt+W1LSEImL2ZhJwVaLMNy9xc8ep2ctlhGtj9z0CezI0OmtJesad/j1CN drU01VJhdAvazHIn4VQYbXaYfQnC1w8gk69o7sJOmOWj+n6Z5N2kXd+JYCYxzi3blxoz Udak0XsywrdyvC4XDQV5Ov2rXgbU8p+SKy95FG5ZuIcMtA9NjB5aKm4ikr9spGLSYVSj 0j9yB6GakIM6QxZp49c7jLfXebyVQv6n5VzshwoFi/LlHXmNTklLHWMC7QFx/axIRxa2 k8gwTtAyjMhtcs3sdV27HsJr2c9kA7pVDyp0t+t+0itQk1pk+jTaBVql3IcBZko6oYCB w1GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766518666; x=1767123466; 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=f+/9YLEDg3kvIVJ8uIdd0LLUvUHitQ7YUX6eQO1NlK0=; b=T+ExMbqsYQGQgbeoo5jVP4b2b7HjPdsiUcXNaDAZywpIF2IwJyzGGoF01kYmoOWhes nCxdhPD+DpKDFVm1KAVQRFCKmun2vriNjJF96HQre+HLWVC6+7B9qgt6PR81Hnu8TT95 m2ermf5o0USbCE2zhNRcPlQuSqKxZ34Ku2mT03gfAxn5BR8oghCBeFbghdkFGAlv2WDJ gvMuqKUU0wBYRezAbwOUtS6QadiMYd//zeqIpW9O4fkWMi4g++UzR/2lk8xlh2ZLKwDi kWmfXsHWS8/jh/liUgGrZfIVPk9oUOWeq1pBm7PuN8Y+8ItZkfO2GfDdTPuSSnRHWLpV 3utQ== X-Forwarded-Encrypted: i=1; AJvYcCXiTm2+wrmakXUAg8+cQgOxLM/kp5R9iz8fm33gTmrGoTStHUGupzyq888PkmwwBryydjIB3Lb9rDEO5iM=@vger.kernel.org X-Gm-Message-State: AOJu0YwlRx+RTH+cUkqNrWPl9DRqE6SvTP2WJTq2TEQ/Skunh2Yas5mh 1kZhyfnM89HwE9uPEnZvcXLAx0MbEKgmg/NkwaUXE/kqcccpNFPw4UXsPypPtoi5y2gBf1qjtB/ eXTLDHICbRmaeQw== X-Google-Smtp-Source: AGHT+IFdQ0xv1ECz+S2fE4SGRa/G62rXTSK/YhtqO7PYzVPbTpr6YHYABHt3naOEamVpBBjQGWHJo2312jteHA== X-Received: from dlbps8.prod.google.com ([2002:a05:7023:888:b0:120:5def:9544]) (user=pekangas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6199:b0:11f:1e59:4c2d with SMTP id a92af1059eb24-121721acb6dmr15174419c88.7.1766518666308; Tue, 23 Dec 2025 11:37:46 -0800 (PST) Date: Tue, 23 Dec 2025 19:34:40 +0000 In-Reply-To: <20251223193440.1441657-1-pekangas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251223193440.1441657-1-pekangas@google.com> X-Mailer: git-send-email 2.52.0.351.gbe84eed79e-goog Message-ID: <20251223193440.1441657-2-pekangas@google.com> Subject: [PATCH 1/1] KVM: arm64: Fix hyp VA size between layout and MMU From: Petteri Kangaslampi To: kvmarm@lists.linux.dev Cc: Marc Zyngier , Oliver Upton , Vincent Donnefort , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Petteri Kangaslampi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use a consistent hypervisor VA size between memory layout and MMU initialization logic when the kernel is configured for less than IDMAP_VA_BITS of VA space. Signed-off-by: Petteri Kangaslampi --- arch/arm64/kvm/va_layout.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c index f6ca0193a96f..76cdd62550e1 100644 --- a/arch/arm64/kvm/va_layout.c +++ b/arch/arm64/kvm/va_layout.c @@ -49,7 +49,7 @@ static void init_hyp_physvirt_offset(void) =20 /* * We want to generate a hyp VA with the following format (with V =3D=3D - * vabits_actual): + * hypervisor VA bits): * * 63 ... V | V-1 | V-2 .. tag_lsb | tag_lsb - 1 .. 0 * --------------------------------------------------------- @@ -62,10 +62,17 @@ __init void kvm_compute_layout(void) { phys_addr_t idmap_addr =3D __pa_symbol(__hyp_idmap_text_start); u64 hyp_va_msb; + u32 hyp_va_bits; + + /* + * We use the bigger of IDMAP_VA_BITS and kernel VA size as the + * hypervisor VA address space size. See mmu.c. + */ + hyp_va_bits =3D max(IDMAP_VA_BITS, vabits_actual); =20 /* Where is my RAM region? */ - hyp_va_msb =3D idmap_addr & BIT(vabits_actual - 1); - hyp_va_msb ^=3D BIT(vabits_actual - 1); + hyp_va_msb =3D idmap_addr & BIT(hyp_va_bits - 1); + hyp_va_msb ^=3D BIT(hyp_va_bits - 1); =20 tag_lsb =3D fls64((u64)phys_to_virt(memblock_start_of_DRAM()) ^ (u64)(high_memory - 1)); @@ -73,9 +80,9 @@ __init void kvm_compute_layout(void) va_mask =3D GENMASK_ULL(tag_lsb - 1, 0); tag_val =3D hyp_va_msb; =20 - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && tag_lsb !=3D (vabits_actual - 1)= ) { + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && tag_lsb !=3D (hyp_va_bits - 1)) { /* We have some free bits to insert a random tag. */ - tag_val |=3D get_random_long() & GENMASK_ULL(vabits_actual - 2, tag_lsb); + tag_val |=3D get_random_long() & GENMASK_ULL(hyp_va_bits - 2, tag_lsb); } tag_val >>=3D tag_lsb; =20 --=20 2.52.0.351.gbe84eed79e-goog