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 B7E74C88E4C for ; Fri, 11 Sep 2026 09:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oxmQxrsMeqRHqVktx/UJ3IdFFga7UWvSUavLJ9XkLmA=; b=H0n3bYiJJGG3Q73V1tQ79snB9h IhlKXWRY/osIGPg7oQchm1qwmgOfR9SczIc6Llcara9hX+TDG03GMTcNv2Bacz2XHFJdoXmLta546 u0n0x7vJ0qoMzyh/QoXA8QHhhUKIXiYTHnLXNU9Z9btk6SiQ3vUKstZ3Nrw6rn86/iNWHo+hYVK0I 6V6Y3YSJBZipCtAVcuKHnzlo95ry9aP0A/diyccK7cPL8FrOJF+fGWbXtgd9ubs9lO0jNl+l21utG dTD87yCYma4NPGnlKgIn90/iu4tXVGjyUQF7+Dou8AF2FgMe0LiVaA1uXL+qHJTFCYo2tTbNnxRui mUjBSG3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x4xRp-0000000GFoo-0yNO; Fri, 11 Sep 2026 09:21:29 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x4xRo-0000000GFn4-0EXy for linux-arm-kernel@lists.infradead.org; Fri, 11 Sep 2026 09:21:28 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3F270404DD; Fri, 11 Sep 2026 09:21:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18FD41F000FF; Fri, 11 Sep 2026 09:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789118486; bh=oxmQxrsMeqRHqVktx/UJ3IdFFga7UWvSUavLJ9XkLmA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=a33dLmzYgclcf+h0y1zqNlrGUlx91lz83YB4ZqpgXrK6Ah+8Nfvau6tKK5KdEeuXd Dfux531lNaQrUZMYOx9mE3Xt+SJyYT3Pwf9INrmJCjVcmS7PtuCuEgssXaoy11URi7 c+LKdnXUxnNCN5p/xbRkldiKd+FCoUjVVSduevBHRfHWphQ8t8yFEh4xouPXLw8FpX 2qWA0Te2CVaU90nRBs5wkVVdMm9L249BMMjiauBEXlRIY4oo8tsN/QABKSQLOHUcAh GqOfOlHIhfM6MquRJ5kSTkCwA4s/52KTfnhDM1/pqee+JhU+Vr4vdo4VVRuVcauEpS S9SKCJgqbS/mg== Date: Fri, 11 Sep 2026 10:21:17 +0100 From: "Lorenzo Stoakes (ARM)" To: Fuad Tabba Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Paolo Bonzini , Jonathan Corbet , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Jack Thomson , Jack Thomson , Alexandru Elisei , Vincent Donnefort , "Aneesh Kumar K.V" , Sean Christopherson , Claudio Imbrenda , Leo Soares Passos Subject: Re: [PATCH 8/8] KVM: selftests: Add nested pre-fault test for arm64 Message-ID: References: <20260825-kvm-arm-prefault-v1-0-befe8947702e@kernel.org> <20260825-kvm-arm-prefault-v1-8-befe8947702e@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 10, 2026 at 07:57:03PM +0100, Fuad Tabba wrote: > Hi, > > On Tue, 25 Aug 2026 at 17:02, Lorenzo Stoakes (ARM) wrote: > .. > > +int main(void) > > +{ > > + struct nested_s2_state s2; > > + struct kvm_vcpu_init init; > > + struct kvm_vcpu *vcpu; > > + struct kvm_vm *vm; > > + struct ucall uc; > > + u64 npages; > > + > > + TEST_REQUIRE(kvm_check_cap(KVM_CAP_ARM_EL2)); > > Would test_supports_el2() work better here? It honours the NV=0 > opt-out, and since HAS_EL2 is set unconditionally below, NV=0 doesn't > disable this test as things stand. That sounds sensible :) Will fix on respin. > > Cheers, > /fuad > > > + TEST_REQUIRE(kvm_check_cap(KVM_CAP_PRE_FAULT_MEMORY)); > > + > > + vm = vm_create(1); > > + > > + kvm_get_default_vcpu_target(vm, &init); > > + init.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2); > > + vcpu = aarch64_vcpu_add(vm, 0, &init, guest_code); > > + kvm_arch_vm_finalize_vcpus(vm); > > + > > + npages = TEST_MEM_SIZE / vm->page_size; > > + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, TEST_MEM_GPA, > > + TEST_MEM_SLOT, npages, 0); > > + virt_map(vm, TEST_MEM_GPA, TEST_MEM_GPA, npages); > > + > > + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, > > + NESTED_S2_ROOT_GPA, NESTED_S2_ROOT_SLOT, > > + vm_adjust_num_guest_pages(vm->mode, 1), 0); > > + > > + /* Run the guest until it has ERET'd from vEL2 to vEL1. */ > > + vcpu_run(vcpu); > > + switch (get_ucall(vcpu, &uc)) { > > + case UCALL_SYNC: > > + TEST_ASSERT_EQ(uc.args[1], 1); > > + break; > > + case UCALL_ABORT: > > + REPORT_GUEST_ASSERT(uc); > > + break; > > + default: > > + TEST_FAIL("Unhandled ucall: %ld", uc.cmd); > > + } > > + > > + /* > > + * The vCPU's last-run context is vEL1, backed by a shadow stage-2 > > + * MMU. Enable nested stage-2 with an empty root so that the ioctl > > + * fails if it tries to interpret the userspace GPA as an L2 IPA. > > + * > > + * Prefault in two halves so that the second ioctl exercises a > > + * repeated shadow-MMU attach and canonical stage-2 swap. > > + * > > + * (Note that an implementation that wrongly populates shadow > > + * stage-2 page tables would not be caught as userland can't > > + * inspect these.) > > + */ > > + s2 = enable_empty_nested_s2(vcpu); > > + pre_fault(vcpu, TEST_MEM_GPA, TEST_MEM_SIZE / 2); > > + pre_fault(vcpu, TEST_MEM_GPA + TEST_MEM_SIZE / 2, TEST_MEM_SIZE / 2); > > + restore_nested_s2(vcpu, &s2); > > + > > + /* Resume at vEL1 and touch the prefaulted range. */ > > + vcpu_run(vcpu); > > + switch (get_ucall(vcpu, &uc)) { > > + case UCALL_DONE: > > + break; > > + case UCALL_ABORT: > > + REPORT_GUEST_ASSERT(uc); > > + break; > > + default: > > + TEST_FAIL("Unhandled ucall: %ld", uc.cmd); > > + } > > + > > + kvm_vm_free(vm); > > + return 0; > > +} > > > > -- > > 2.55.0 > > -- Cheers, Lorenzo