From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 0FB48315D33 for ; Fri, 6 Mar 2026 01:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772761173; cv=none; b=CSQfOnDvNGmLsw6f7NyiybOB7ZX5V7ePn1Woi7ppJMFaHbMvJNjse9Ft0Q3dABIUus1ITFgLqvHvc/jCS1x36sqcZzxSeWGJlBrvWHIvKiR5mFxSU/rxhzubwFn+4kb08bWy+sVEbzR/dPXJMO73NjRDSXF8MUKMRNw1/JcoY+o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772761173; c=relaxed/simple; bh=M0JcElFdpqFtGRb/Zz+KHIh22rVtm6hjn2JxC2reo/E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T+ra9DxhxKKBabT8II9yf3AR5+TINBc1wu6yWk7YPZK4nDrrmUWh3n9I8BGAxJpkm5glxYbqEHOb3CbMhe0F/zZiLTkotmJJ3xk22Zjz0P1TEyhjP91UEoaiFlG6L6YmEP2B0KN6v9qXhIv4CGDQjTFrN6fwtD5OFVPkXUKFJXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=15paiwrm; arc=none smtp.client-ip=209.85.214.202 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="15paiwrm" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ae65d5cc57so144301245ad.2 for ; Thu, 05 Mar 2026 17:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772761171; x=1773365971; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=WF5GW9U8X6v9xtxyzDWC9k1yzZZMSQz6nKA9iuuryHw=; b=15paiwrmsxnnzxSTNEy5yPF8tdQXifvwAHwHvHBbq+n8ZwmRkRZr+wArUn5NPjBQ23 5vpuXChS0ZgtulC1aU/cIHJrzk3NCeD7jxmt8GRE4wTFnriOx4A9geMXI3PKEfqqCFWi ql1GnzB03EjBbcbfIKI0Ain4xTcfq2xvDARydl4I9muCLRO5Bgaia7aYT4UREQNye5sS 7yJUjSoCaFURuI5DqTghqdF1IG+ejRVUleDrtDsrtvj9W/k6taGgpKDa5W9qyt2CCIKg wanMbnG2qGeBS5M9bn6x/8V/CTcS/Vd7oMqHCuHBmqoSbyd6KnMnxiqr/7mrNLMhpoGW K50w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772761171; x=1773365971; h=content-transfer-encoding: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; bh=WF5GW9U8X6v9xtxyzDWC9k1yzZZMSQz6nKA9iuuryHw=; b=nNs/I49UyBYL5OPgvsRHyupvmA9JmAx2oxJ5Mezu7ZeVhSWURuugP2vQDM1Hje7rSY EYL/Ua7xuZy22ClD1yPkvXtSJHSaCTFS9cBMuUfosXsLZ06R6A+N+KfSI1D7z8IpKkJW hgIsqggjgXBnO9H6+yp5D/fBJ6xD42Qs+9g9zg95O1obIr4FEe2/WYl2a7khHEXXkm4v cAiql6cLA9CQRIkeucinUhlc6SqUnPBHMDQOWdtCROO75laVPIvHSwEJGu7gOKm4qKnx nGZtT/r28bTb4lVLcmOjT2f4fZ8qhvh69aIhPBEI6eapSG9dXEGl3iBMncU7iMNV2bCO FLPQ== X-Forwarded-Encrypted: i=1; AJvYcCUL57bJBSFAzATKbC6KoYMgzsMuT6XVq9qtKswpHUNUpUTBq8Iu5WMLZyrkdx2ed2oFx2Z2c1GlzR3oJ8Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzXs1anc3OQeqU7f5ycv/W8uQvSsSiYfW1h35jXOerHWxpSBSxm WWK4Dgt7U8vg7PIUwJKDoJiC4e2UiOk02XpsOeDJIWeXToSb/yB8h0yK/9bTktwAs2aIxFzPler WIG5AUA== X-Received: from plblh5.prod.google.com ([2002:a17:903:2905:b0:2ae:4060:2b13]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce12:b0:2aa:d67b:ef96 with SMTP id d9443c01a7336-2ae8243b2f7mr5225265ad.31.1772761171233; Thu, 05 Mar 2026 17:39:31 -0800 (PST) Date: Thu, 5 Mar 2026 17:39:29 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260303003421.2185681-1-yosry@kernel.org> <20260303003421.2185681-27-yosry@kernel.org> Message-ID: Subject: Re: [PATCH v7 26/26] KVM: selftest: Add a selftest for VMRUN/#VMEXIT with unmappable vmcb12 From: Sean Christopherson To: Jim Mattson Cc: Yosry Ahmed , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 05, 2026, Jim Mattson wrote: > On Thu, Mar 5, 2026 at 4:40=E2=80=AFPM Yosry Ahmed wro= te: > > > > On Thu, Mar 5, 2026 at 4:05=E2=80=AFPM Jim Mattson wrote: > > > > > > On Thu, Mar 5, 2026 at 2:52=E2=80=AFPM Yosry Ahmed = wrote: > > > > > > > > On Thu, Mar 5, 2026 at 2:30=E2=80=AFPM Jim Mattson wrote: > > > > > > > > > > On Mon, Mar 2, 2026 at 4:43=E2=80=AFPM Yosry Ahmed wrote: > > > > > > > > > > > > Add a test that verifies that KVM correctly injects a #GP for n= ested > > > > > > VMRUN and a shutdown for nested #VMEXIT, if the GPA of vmcb12 c= annot be > > > > > > mapped. > > > > > > > > > > > > Signed-off-by: Yosry Ahmed > > > > > > ... > > > > > > + /* > > > > > > + * Find the max legal GPA that is not backed by a memsl= ot (i.e. cannot > > > > > > + * be mapped by KVM). > > > > > > + */ > > > > > > + maxphyaddr =3D kvm_cpuid_property(vcpu->cpuid, X86_PROP= ERTY_MAX_PHY_ADDR); > > > > > > + max_legal_gpa =3D BIT_ULL(maxphyaddr) - PAGE_SIZE; > > > > > > + vcpu_alloc_svm(vm, &nested_gva); > > > > > > + vcpu_args_set(vcpu, 2, nested_gva, max_legal_gpa); > > > > > > + > > > > > > + /* VMRUN with max_legal_gpa, KVM injects a #GP */ > > > > > > + vcpu_run(vcpu); > > > > > > + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); > > > > > > + TEST_ASSERT_EQ(get_ucall(vcpu, &uc), UCALL_SYNC); > > > > > > + TEST_ASSERT_EQ(uc.args[1], SYNC_GP); > > > > > > > > > > Why would this raise #GP? That isn't architected behavior. > > > > > > > > I don't see architected behavior in the APM for what happens if VMR= UN > > > > fails to load the VMCB from memory. I guess it should be the same a= s > > > > what would happen if a PTE is pointing to a physical address that > > > > doesn't exist? Maybe #MC? > > > > > > Reads from non-existent memory return all 1's > > > > Today I learned :) Do all x86 CPUs do this? >=20 > Yes. If no device claims the address, reads return all 1s. I think you > can thank pull-up resistors for that. Ya, it's officially documented PCI behavior. Writes are dropped, reads ret= urn all 1s. > > > so I would expect a #VMEXIT with exitcode VMEXIT_INVALID. > > > > This would actually simplify the logic, as it would be the same > > failure mode as failed consistency checks. That being said, KVM has > > been injecting a #GP when it fails to map vmcb12 since the beginning. >=20 > KVM has never been known for its attention to detail. LOL, hey, we try. Sometimes we just forget things though :-) 7a35e515a705 ("KVM: VMX: Properly handle kvm_read/write_guest_virt*() resul= t") > > It also does the same thing for VMSAVE/VMLOAD, which seems to also not > > be architectural. This would be more annoying to handle correctly > > because we'll need to copy all 1's to the relevant fields in vmcb12 or > > vmcb01. >=20 > Or just exit to userspace with > KVM_EXIT_INTERNAL_ERROR/KVM_INTERNAL_ERROR_EMULATION. I think on the > VMX side, this sort of thing goes through kvm_handle_memory_failure(). Yep, I think this is the correct fixup: diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index b191c6cab57d..78a542c6ddf1 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1105,10 +1105,8 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) =20 vmcb12_gpa =3D svm->vmcb->save.rax; err =3D nested_svm_copy_vmcb12_to_cache(vcpu, vmcb12_gpa); - if (err =3D=3D -EFAULT) { - kvm_inject_gp(vcpu, 0); - return 1; - } + if (err =3D=3D -EFAULT) + return kvm_handle_memory_failure(vcpu, X86EMUL_UNHANDLEABLE= , NULL); =20 /* * Advance RIP if #GP or #UD are not injected, but otherwise stop i= f