From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (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 AC48C3BCD38 for ; Fri, 7 Aug 2026 16:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786121025; cv=none; b=VfBPjV5sWJI0pfyQ5GxI/prEoe1Aan6/ONVk/rHP2jFmZEMHcJZzJyln1sZMSvvfFYVkVPQ/fS70lsF8Nw7GTJ2RlDgniC5L4lxlpgpu4dMB1fGZZlz7NXCXZMIiHV6OvtEU9i1FnHebwbcHAIWv7QRZh2fI3+P7/vxrg6trTR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786121025; c=relaxed/simple; bh=fW4c7LYnBzLD1FiWd4akwgLLfkkoP/cLS3UvI0SBd6c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OyUn9HEWsylXOxuXZx28dCxrJD8d00hRBY48YlmZ11p1jN9qlqnrHnVlON6UwUMYwS1LTxPnc3MF1Wd2bxYoHtRK+qscjL2LERQswV1u9QZcQMkQCg+GyYfltrLb2HpY5eL+v1WzpAGdC2TU3Xva26OwZcBCpC/sudNC3zRHpGQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jokGr9Up; arc=none smtp.client-ip=209.85.128.69 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--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jokGr9Up" Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-49953abe51fso16094785e9.1 for ; Fri, 07 Aug 2026 09:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786121021; x=1786725821; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9LMvLSIyRJoS17MqrfOagB9BtwOQBhza88CokriU1a0=; b=jokGr9Up7dToVH5qX52cFxXfkk2YxCZS0/9PN+mNep7Z8Y2WVoul2FTwTGY7NHGzOW 1SseYfc1haoRlrIkVX4Cwp38+nXHz1QtAApt0Y7WQrQSENoJpuSAA7mzkfwzcY6MAsG7 pQq2jiC74PPdHGpLKQPwjiCACU+PB7ckw4cM5eTqGQnRzlsLfwEPm2k3ZlvIe0PzmWeq t7e96QCJi5sXV84pkO96ZBqifvk2MLVcfMl5K0ShYZjvwsOGuhwbrA91P+YKx65zgfvd 8ubGFEnDBkj0ucmQZp4EV4pqny2+VHFvvIE61s9hWgaiEdu1a+zdO8p47v5MczZlLx0n xT5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786121021; x=1786725821; h=content-type: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:content-type; bh=9LMvLSIyRJoS17MqrfOagB9BtwOQBhza88CokriU1a0=; b=j2Y85CbEkeL5r2fXAYgbRBFIaEEitsJbgdT6qQnK4Y2dN1p7c2QNnRZIULMLt7PFO9 1Iyzs+fRv742fvYV+A4S8Zv/xZ3dyREHYvbzeeysJudHmXfk/n4zz7cau94BBAkGld8b K2IwcKv1WXeJkQdRveNvfYJFLhmxWEDyz/nKRV5HRxxQR2hA7akW+E1SY9Cpoi+mKSIR MTTFnKp1Jf7mfW9XRy0/GbMQ52KvldRvD7aBQI8H+HVAIVdhwlUuqFnJzwFY+Pv/l67i qoyUbBLnaEyKo/B/7obGgGyAxkFUiFtAN08Ix5yrlKIWdg9HvYn+W3zplbh955jvt8Yl RIsA== X-Forwarded-Encrypted: i=1; AHgh+Rpc0js1BEuWIR6OegL7MdCt+cnCN/rctNhtH8LZPl1NiYYeBqgRyBmHBtjtrD04WjqR1CO6D1d8wmeN9Gg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx40C4X8Km/XJ0ymyoedljXEAu77LTUTUpYTZYeSx8eZxoRaq8o OeTMYY7Hawii7XddzTMfM698KkBL3t8wYbsHW6Tj8VKI8+kf5qGGtar9wRu1LIVAR5GR1zpnUZx 3BNGBOcBk2WF6sb0K11IvrqVvwY+trg== X-Received: from wrrq16.prod.google.com ([2002:adf:f950:0:b0:47f:8ed4:b07f]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e12:b0:499:61bb:6c78 with SMTP id 5b1f17b1804b1-49961bb71abmr15660795e9.14.1786121021370; Fri, 07 Aug 2026 09:43:41 -0700 (PDT) Date: Fri, 7 Aug 2026 16:43:12 +0000 In-Reply-To: <20260807164322.2970811-2-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260807164322.2970811-2-sebastianene@google.com> X-Mailer: git-send-email 2.55.0.654.g21b8a5bc05-goog Message-ID: <20260807164322.2970811-4-sebastianene@google.com> Subject: [PATCH v2 02/13] KVM: arm64: Track host-unmapped MMIO regions in a static array From: Sebastian Ene To: catalin.marinas@arm.com, fuad.tabba@linux.dev, joey.gouly@arm.com, mark.rutland@arm.com, maz@kernel.org, oupton@kernel.org, rananta@google.com, Sascha.Bischoff@arm.com, suzuki.poulose@arm.com, will@kernel.org Cc: kvmarm@lists.linux.dev, android-kvm@google.com, bgrzesik@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, nathan@kernel.org, perlarsen@google.com, sebastianene@google.com, seiden@linux.ibm.com, smostafa@google.com, tglx@kernel.org, vdonnefort@google.com, vladimir.murzin@arm.com, yuzenghui@huawei.com, zenghui.yu@linux.dev Content-Type: text/plain; charset="UTF-8" Introduce a registry to track protected MMIO regions that are unmapped from the host stage-2 page tables. These regions are stored in a fixed-size array and their ownership is donated to the hypervisor during initialization to ensure host-exclusion and persistent tracking. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/kvm_pkvm.h | 11 +++++++++++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 3 +++ arch/arm64/kvm/hyp/nvhe/setup.c | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/arch/arm64/include/asm/kvm_pkvm.h b/arch/arm64/include/asm/kvm_pkvm.h index 74fedd9c5ff0..ab26bec079d6 100644 --- a/arch/arm64/include/asm/kvm_pkvm.h +++ b/arch/arm64/include/asm/kvm_pkvm.h @@ -17,6 +17,17 @@ #define HYP_MEMBLOCK_REGIONS 128 +/* The maximum number of hypervisor protected regions from the host */ +#define PKVM_PROTECTED_REGS_NUM 8 + +struct pkvm_protected_reg { + u64 pfn; + u64 nr_pages; +}; + +extern struct pkvm_protected_reg kvm_nvhe_sym(pkvm_protected_regs)[]; +extern unsigned int kvm_nvhe_sym(num_protected_reg); + int pkvm_init_host_vm(struct kvm *kvm, unsigned long type); int pkvm_create_hyp_vm(struct kvm *kvm); bool pkvm_hyp_vm_is_created(struct kvm *kvm); diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 5cf7c4a0ed20..500c18c2fd48 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -28,6 +28,9 @@ struct host_mmu host_mmu; static struct hyp_pool host_s2_pool; +unsigned int num_protected_reg; +struct pkvm_protected_reg pkvm_protected_regs[PKVM_PROTECTED_REGS_NUM]; + static DEFINE_PER_CPU(struct pkvm_hyp_vm *, __current_vm); #define current_vm (*this_cpu_ptr(&__current_vm)) diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 75b00c323310..64c0290da888 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -284,6 +284,26 @@ static int fix_hyp_pgtable_refcnt(void) &walker); } +static int donate_protected_mmio_regions(void) +{ + int ret; + int i; + + for (i = 0; i < num_protected_reg; i++) { + ret = __pkvm_host_donate_hyp_mmio(hyp_pfn_to_phys(pkvm_protected_regs[i].pfn), + pkvm_protected_regs[i].nr_pages << PAGE_SHIFT); + if (ret) + goto err_setup; + } + + return 0; +err_setup: + while (--i >= 0) + __pkvm_hyp_donate_host_mmio(hyp_pfn_to_phys(pkvm_protected_regs[i].pfn), + pkvm_protected_regs[i].nr_pages << PAGE_SHIFT); + return ret; +} + void __noreturn __pkvm_init_finalise(void) { struct kvm_cpu_context *host_ctxt = host_data_ptr(host_ctxt); @@ -324,6 +344,10 @@ void __noreturn __pkvm_init_finalise(void) if (ret) goto out; + ret = donate_protected_mmio_regions(); + if (ret) + goto out; + ret = hyp_ffa_init(ffa_proxy_pages); if (ret) goto out; -- 2.55.0.654.g21b8a5bc05-goog