From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12F8A3DB623 for ; Fri, 5 Jun 2026 11:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780658430; cv=none; b=UaIIoJRoMja+mN+rcXyKf+Za+Zzs2V8crXXlc+Wz/Mv6Lkrr5fIX/m8UeYQoM972e7kCSJXCX32MuBtpbsYv8KQyOKSZrZl3Qu2d4H/h0x2dxCnJViYyBVaEEF+XuKZgr1yWEDO5l73DPrFxJOWBD/RXzyo745r/62Slk8bjaCM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780658430; c=relaxed/simple; bh=x0UYxgYNv6TD6Wlw2FfxY0+ckKC90VlYJ2Ty2LB51yU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iDF0XJ9cnNjcp4znHTpwtEou1pDAXruzOwrnn1sKQmkOknOyX1KM4Q7RoKRF1lRAbViL3AworePHPq1/z2rG9O5oJEv6tyyB68vArnO38ab5ZUBkwG9afmz8Gib5EqmsQ6n9iB3wq62YrTa4s39cTx9jebS4ZGJyYlwxr6M/b90= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NQst+ned; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=VzlfZwYc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NQst+ned"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="VzlfZwYc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780658428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M+dHNKFMVBkDdICjg2Muej8aIFbwcMiW4DpFYR49CkI=; b=NQst+nedkCx5EBACavuTEYwl5fdcsVCvHNGRmBOs2S5+QnDNwUfcjHxgxAV6aLpCTpAkAo 155lKHETS6LRBxfRI9+0xO9qctfZxPVbGUV9IKmQtI4NRu4IHw/K7NLSJuerZQTt01NtCe 3JPteZmSK5LlE4UceS6v+KUDh0LQy7s= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-PuQ4FdQ0OX2uAGZGT_lbHQ-1; Fri, 05 Jun 2026 07:20:27 -0400 X-MC-Unique: PuQ4FdQ0OX2uAGZGT_lbHQ-1 X-Mimecast-MFC-AGG-ID: PuQ4FdQ0OX2uAGZGT_lbHQ_1780658426 Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8423f544944so1361855b3a.3 for ; Fri, 05 Jun 2026 04:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780658426; x=1781263226; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=M+dHNKFMVBkDdICjg2Muej8aIFbwcMiW4DpFYR49CkI=; b=VzlfZwYcPzu6rIDqmG3VRkK7Khwpjqg083mF+7HPhZNc8sh3ELnj+PCrnZfWXKrdQa zvoDmQX93HuDpaGdw0Xb2bgyn4VhBgu2sXERD0KxLZCihjXUAYH551TZ4ul9Oolu3PGk BIEzvpq3JnaoNoHym7GBEPeR+54KSSW2bX5EK92bwHjsV1VvB/KU0qJbwMmLK6S8aAcj BA368dKsPVDMJWrvEe5XLVJhJohqteghL+vDBJL7I/UxX36HU2LbOOSYeJGB07fjBWzR FrIIZQEtKbOOQltgkOnwmFyiWpOr+cQlkft3eZ1SfzaZm2s4gy4XjuZn/s0qjK09rxKL pL3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780658426; x=1781263226; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=M+dHNKFMVBkDdICjg2Muej8aIFbwcMiW4DpFYR49CkI=; b=XHa8wKWkc2bBKCoHsu/UB08LHIObHZZFOST1NYUAAW3QDrfbRo7K3cC3/TkzGJeNr8 qN4wD3eAgAVtAYZpTgaWUR97Hi0gnWhIb2kBlec9bzwtf4KUTv5jZMwahJi75aUoRiNm uwiFg3KHR3ET9IH1xiUYSM3we+Ru9RPCutRDbMkD9VgDOQ/vtxal4VgsPNDsMk/F/r7G HPh+VaUQ0N3neqfMNdauMnJJD4GEgyou6gddDvxpgHerBWASNZRlpTmIlff73sbuCMx3 aJ5NLTyEVI60+exIini93uFvb85BnDU3/Da0OYK9iFv5sFkg6JcZWkY6jdG4m2GBuxGi hsdQ== X-Forwarded-Encrypted: i=1; AFNElJ9IuGkcjn37s8dLLa16z/1M0kevezZFKLE9VFFwfqYjvYdPT8wNY5fLsLrDNNlUqzNdtuPR6edVwdy91eo=@vger.kernel.org X-Gm-Message-State: AOJu0YzTfBMVJX6p4tsA745U327NIi21KfrUQCHitgmIeMJqpB72qHo5 RzaZwuqArW2rOrg9LUWY/4ZN6qLvGqL2fNGmizX6FBfLE3net3sPIIZaBJ/Oad6oeytWyzWpe2g Hp74/hdXyh5hvAUo6ET4rawn2JlApaKxd3hRl/jRowUTe0dBx2nrC+ciolNt/TNrESw== X-Gm-Gg: Acq92OGjfP5qQwnNz0fsVPWzD3LhxXkygia5vN8UxMQV54mwl2vippHx3lcf3niXySx PE/MiT9WNaT75GVs77CTAnWmXCWr3VAgfJC+72I40TxfZKRPD9tyn+naQLAPoEkj71fTyl68qm9 b93KOZ0E8QflldpiQwNv+vC3VXi5r2A+P7+svVIX5W5oIto7xNAN9H6v7qNMX7gy5AeJZxLo7QY iarHxsY6mAAQpzHqsqGGZ7YUxqH4VVLotJrZk7s5fRIIC/9bMVnBuFQ+rZkl5vNa7bgbnWDHvBr wtiap9wCHDKXfUq3U8Xs6bfuRVzU2uPlAzDQfKCDUP/w+aaMjYPIK55JInDFOO2eduwSZ9AJBKR o4pmm6yV2ivXnnYW9viU9GNkcnmwfrXf0+oVXWcIJGPyge/18bTnfaEceckZ5NuAbWn1nFEnLSQ M= X-Received: by 2002:a05:6a00:2351:b0:835:3949:3c22 with SMTP id d2e1a72fcca58-842b0f52eefmr3355883b3a.27.1780658425891; Fri, 05 Jun 2026 04:20:25 -0700 (PDT) X-Received: by 2002:a05:6a00:2351:b0:835:3949:3c22 with SMTP id d2e1a72fcca58-842b0f52eefmr3355817b3a.27.1780658425323; Fri, 05 Jun 2026 04:20:25 -0700 (PDT) Received: from [192.168.68.51] (n175-34-8-244.mrk21.qld.optusnet.com.au. [175.34.8.244]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84282880050sm8756478b3a.29.2026.06.05.04.20.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jun 2026 04:20:24 -0700 (PDT) Message-ID: Date: Fri, 5 Jun 2026 21:20:14 +1000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v14 29/44] arm64: RMI: Runtime faulting of memory To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo.Pieralisi2@arm.com References: <20260513131757.116630-1-steven.price@arm.com> <20260513131757.116630-30-steven.price@arm.com> Content-Language: en-US From: Gavin Shan In-Reply-To: <20260513131757.116630-30-steven.price@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Steve, On 5/13/26 11:17 PM, Steven Price wrote: > At runtime if the realm guest accesses memory which hasn't yet been > mapped then KVM needs to either populate the region or fault the guest. > > For memory in the lower (protected) region of IPA a fresh page is > provided to the RMM which will zero the contents. For memory in the > upper (shared) region of IPA, the memory from the memslot is mapped > into the realm VM non secure. > > Signed-off-by: Steven Price > --- > Changes since v13: > * Numerous changes due to rebasing. > * Fix addr_range_desc() to encode the correct block size. > Changes since v12: > * Switch to RMM v2.0 range based APIs. > Changes since v11: > * Adapt to upstream changes. > Changes since v10: > * RME->RMI renaming. > * Adapt to upstream gmem changes. > Changes since v9: > * Fix call to kvm_stage2_unmap_range() in kvm_free_stage2_pgd() to set > may_block to avoid stall warnings. > * Minor coding style fixes. > Changes since v8: > * Propagate the may_block flag. > * Minor comments and coding style changes. > Changes since v7: > * Remove redundant WARN_ONs for realm_create_rtt_levels() - it will > internally WARN when necessary. > Changes since v6: > * Handle PAGE_SIZE being larger than RMM granule size. > * Some minor renaming following review comments. > Changes since v5: > * Reduce use of struct page in preparation for supporting the RMM > having a different page size to the host. > * Handle a race when delegating a page where another CPU has faulted on > a the same page (and already delegated the physical page) but not yet > mapped it. In this case simply return to the guest to either use the > mapping from the other CPU (or refault if the race is lost). > * The changes to populate_par_region() are moved into the previous > patch where they belong. > Changes since v4: > * Code cleanup following review feedback. > * Drop the PTE_SHARED bit when creating unprotected page table entries. > This is now set by the RMM and the host has no control of it and the > spec requires the bit to be set to zero. > Changes since v2: > * Avoid leaking memory if failing to map it in the realm. > * Correctly mask RTT based on LPA2 flag (see rtt_get_phys()). > * Adapt to changes in previous patches. > --- > arch/arm64/include/asm/kvm_emulate.h | 8 ++ > arch/arm64/include/asm/kvm_rmi.h | 12 ++ > arch/arm64/kvm/mmu.c | 128 ++++++++++++++++---- > arch/arm64/kvm/rmi.c | 173 +++++++++++++++++++++++++++ > 4 files changed, 301 insertions(+), 20 deletions(-) > [...] > @@ -1604,27 +1641,52 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd) > bool write_fault, exec_fault; > enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_SHARED; > enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; > - struct kvm_pgtable *pgt = s2fd->vcpu->arch.hw_mmu->pgt; > + struct kvm_vcpu *vcpu = s2fd->vcpu; > + struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt; > + gpa_t gpa = kvm_gpa_from_fault(vcpu->kvm, s2fd->fault_ipa); > unsigned long mmu_seq; > struct page *page; > - struct kvm *kvm = s2fd->vcpu->kvm; > + struct kvm *kvm = vcpu->kvm; > void *memcache; > kvm_pfn_t pfn; > gfn_t gfn; > int ret; > > - memcache = get_mmu_memcache(s2fd->vcpu); > - ret = topup_mmu_memcache(s2fd->vcpu, memcache); > + if (kvm_is_realm(vcpu->kvm)) { > + /* check for memory attribute mismatch */ > + bool is_priv_gfn = kvm_mem_is_private(kvm, gpa >> PAGE_SHIFT); > + /* > + * For Realms, the shared address is an alias of the private > + * PA with the top bit set. Thus if the fault address matches > + * the GPA then it is the private alias. > + */ > + bool is_priv_fault = (gpa == s2fd->fault_ipa); > + > + if (is_priv_gfn != is_priv_fault) { > + kvm_prepare_memory_fault_exit(vcpu, gpa, PAGE_SIZE, > + kvm_is_write_fault(vcpu), > + false, > + is_priv_fault); > + /* > + * KVM_EXIT_MEMORY_FAULT requires an return code of > + * -EFAULT, see the API documentation > + */ > + return -EFAULT; > + } > + } > + For a Realm, gmem_abort() is called by kvm_handle_guest_abort() only when we're faulting in the private (protected) space. if (kvm_slot_has_gmem(memslot) && !shared_ipa_fault(vcpu->kvm, fault_ipa)) ret = gmem_abort(&s2fd); else ret = user_mem_abort(&s2fd); With the condition, this block of code can be simplied to handle conversion (shared -> private) instead of both directions. /* Convert the shared address to the private adress for Realm */ if (kvm_is_realm(vcpu->kvm) && !kvm_mem_is_private(kvm, gpa >> PAGE_SHIFT)) { /* * KVM_EXIT_MEMORY_FAULT requires an return code of * -EFAULT, see the API documentation */ kvm_prepare_memory_fault_exit(vcpu, gpa, PAGE_SIZE, kvm_is_write_fault(vcpu), false, true); return -EFAULT; } [...] > @@ -2396,7 +2475,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) > !write_fault && > !kvm_vcpu_trap_is_exec_fault(vcpu)); > > - if (kvm_slot_has_gmem(memslot)) > + if (kvm_slot_has_gmem(memslot) && !shared_ipa_fault(vcpu->kvm, fault_ipa)) > ret = gmem_abort(&s2fd); > else > ret = user_mem_abort(&s2fd); gmem_abort() is only called for faults in the protected (private) space. Thanks, Gavin