From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 CA6E7274B23 for ; Tue, 10 Feb 2026 00:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684925; cv=none; b=nz3PEliAX4xrdEfmFnxYBOwr4OeuHL5WbG3L+vRSizf2B/e52qDZOisLTBQF3vSwPT6FvaTUnwKrh57z29f3l3MSJZPME8UgfNj7Y6B6uYhIhGGl3aIz7baK3WApK2H1R6QqDY5s2O0YlgyKzrEcTyvJkwXr/mMyyvTbq3+690Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684925; c=relaxed/simple; bh=cwG/NMskJD4ybURXDROCS0IewPftFdK1QqvbrL5qXhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NRXCDsJUN7J9h9hsA00pyCs6yR8/TyAun4w3ulpwo/fJbUcqrK38LniMtNgsbcNT1g2Hq59CKFxVQYiAIIYW++5aj6YOYc9bvp1aI1VdvaxbR0tDpldw86QVbBBzNK3bKXoVVmUUraLv89IEqmZq56nKOMXEhxNWCsYPYbhbTx8= 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=GC5JiMwk; arc=none smtp.client-ip=95.215.58.187 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="GC5JiMwk" 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=1770684922; 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=vNfLu8p+LHceCLGq3Bp6+ezRZl+1WypRkVGHyFCfSwA=; b=GC5JiMwktNZbPOwY39KefserrlFxIO3WYhQKbvMR2hhSyU4b5RXF28p9RzQNOPNtdNfuB6 FFJq1FRkWclEs+jclg9AUziSu/75ox53XuOApV2RSlMO3kQOiEsrw2d0T9vcTkJS8Gm62j xSzkKfMaRBCZ84c9HIKW18GrE2vQu1M= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH 4/4] KVM: selftests: Extend state_test to check next_rip Date: Tue, 10 Feb 2026 00:54:49 +0000 Message-ID: <20260210005449.3125133-5-yosry.ahmed@linux.dev> In-Reply-To: <20260210005449.3125133-1-yosry.ahmed@linux.dev> References: <20260210005449.3125133-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: 8bit X-Migadu-Flow: FLOW_OUT Similar to vGIF, extend state_test to make sure that next_rip is saved correctly in nested state. GUEST_SYNC() in L2 causes IO emulation by KVM, which advances the RIP to the value of next_rip. Hence, if next_rip is saved correctly, its value should match the saved RIP value. Signed-off-by: Yosry Ahmed --- tools/testing/selftests/kvm/x86/state_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/state_test.c b/tools/testing/selftests/kvm/x86/state_test.c index 57c7546f3d7c..992a52504a4a 100644 --- a/tools/testing/selftests/kvm/x86/state_test.c +++ b/tools/testing/selftests/kvm/x86/state_test.c @@ -236,6 +236,17 @@ void svm_check_nested_state(int stage, struct kvm_x86_state *state) if (stage == 6) TEST_ASSERT_EQ(!!(vmcb->control.int_ctl & V_GIF_MASK), 0); } + + if (kvm_cpu_has(X86_FEATURE_NRIPS)) { + /* + * GUEST_SYNC() causes IO emulation in KVM, in which case the + * RIP is advanced before exiting to userspace. Hence, the RIP + * in the saved state should be the same as nRIP saved by the + * CPU in the VMCB. + */ + if (stage == 6) + TEST_ASSERT_EQ(vmcb->control.next_rip, state->regs.rip); + } } void check_nested_state(int stage, struct kvm_x86_state *state) -- 2.53.0.rc2.204.g2597b5adb4-goog