From nobody Wed Oct 1 21:27:13 2025 Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (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 4FE2C30DD3D for ; Wed, 1 Oct 2025 14:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330742; cv=none; b=VFIl4c8xxo04i7ujrbBR0EO7dUKSQMUCT2h7IJouUlkIj1bUQ0rzfXB5d/S97D4FvkWZjBfNaXPMPMPJqeBKTsY5QpESwDmUFi+Hnti78AE/7oqljkoqpKTmZJX4EKUz+NsvywXcK3VSGKs+bCPiidYatJd0gSSIZ667NdJc8tQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330742; c=relaxed/simple; bh=ThlnxXJnBzPguOtYLCHF06DSVYgTHIi41nnNBzqrW0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5DY1V2zCf5RH4KoHSZeGqFNbZ/Lfj0N2mQ9qrmr26bn8q2Cr09Bwf4GfDSXOBP55+jL095d03Re5pOHE0v27rs818+Zm/wfKtR45iTu4xzHEom54IZscMnjLSvMihiOBcw/sg9CKSP30E6bnUduuGRuBVwfSpCNGljZker/AEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=BveAUWQG; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="BveAUWQG" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1759330737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TQv4BWEKXzFdMwpyunqs9lX/Regx9S1cRjNZtX+om4M=; b=BveAUWQG1NY93jMjPhQYH2Qlm28DnNa78EPzh2GnhhBD3yfioVR4wuXpb4fH8X0NQBkg1i t9wEHvYsubJWeVgZU+5TojhiB6QjpgjlovyCaMJxTgHVcEOss0zGEbRh/Q7DqFM7Opdbo8 D2UFRL/4l+3ub/tWY0I9uIUxHy/ACrc= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Yosry Ahmed Subject: [PATCH 10/12] KVM: selftests: Move EPT-specific init outside nested_create_pte() Date: Wed, 1 Oct 2025 14:58:14 +0000 Message-ID: <20251001145816.1414855-11-yosry.ahmed@linux.dev> In-Reply-To: <20251001145816.1414855-1-yosry.ahmed@linux.dev> References: <20251001145816.1414855-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Yosry Ahmed Refactor the EPT specific initialization into nested_ept_create_pte(), in preparation for making nested_create_pte() NPT-friendly. Signed-off-by: Yosry Ahmed --- tools/testing/selftests/kvm/lib/x86/vmx.c | 71 ++++++++++++++--------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c b/tools/testing/self= tests/kvm/lib/x86/vmx.c index b0e6267eac806..eeacf42bf30b1 100644 --- a/tools/testing/selftests/kvm/lib/x86/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86/vmx.c @@ -365,46 +365,61 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_= rip, void *guest_rsp) init_vmcs_guest_state(guest_rip, guest_rsp); } =20 +static bool nested_ept_create_pte(struct kvm_vm *vm, + uint64_t *pte, + uint64_t paddr, + uint64_t *address, + bool *leaf) +{ + struct eptPageTableEntry *epte =3D (struct eptPageTableEntry *)pte; + + /* PTE already exists? */ + if (epte->readable) { + *leaf =3D epte->page_size; + *address =3D epte->address; + return false; + } + + epte->writable =3D true; + epte->readable =3D true; + epte->executable =3D true; + epte->page_size =3D *leaf; + + if (*leaf) + epte->address =3D paddr >> vm->page_shift; + else + epte->address =3D vm_alloc_page_table(vm) >> vm->page_shift; + + *address =3D epte->address; + + /* + * For now mark these as accessed and dirty because the only + * testcase we have needs that. Can be reconsidered later. + */ + epte->accessed =3D *leaf; + epte->dirty =3D *leaf; + return true; +} + static uint64_t nested_create_pte(struct kvm_vm *vm, uint64_t *pte, uint64_t nested_paddr, uint64_t paddr, int level, - bool leaf) + bool want_leaf) { - struct eptPageTableEntry *epte =3D (struct eptPageTableEntry *)pte; - - if (!epte->readable) { - epte->writable =3D true; - epte->readable =3D true; - epte->executable =3D true; - epte->page_size =3D leaf; + bool leaf =3D want_leaf; + uint64_t address; =20 - if (leaf) - epte->address =3D paddr >> vm->page_shift; - else - epte->address =3D vm_alloc_page_table(vm) >> vm->page_shift; - - /* - * For now mark these as accessed and dirty because the only - * testcase we have needs that. Can be reconsidered later. - */ - epte->accessed =3D leaf; - epte->dirty =3D leaf; - } else { - /* - * Entry already present. Assert that the caller doesn't want a - * leaf entry at this level, and that there isn't a leaf entry - * at this level. - */ - TEST_ASSERT(!leaf, + if (!nested_ept_create_pte(vm, pte, paddr, &address, &leaf)) { + TEST_ASSERT(!want_leaf, "Cannot create leaf entry at level: %u, nested_paddr: 0x%lx", level, nested_paddr); - TEST_ASSERT(!epte->page_size, + TEST_ASSERT(!leaf, "Leaf entry already exists at level: %u, nested_paddr: 0x%lx", level, nested_paddr); } - return epte->address; + return address; } =20 =20 --=20 2.51.0.618.g983fd99d29-goog