From patchwork Fri Feb 9 22:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13551951 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 E9AA03984F for ; Fri, 9 Feb 2024 22:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517027; cv=none; b=kXOJ5BFLHPNqtPI37CZWP7jLFRfk+PS+2Fslrd98F/A4Q79crR95Jeks8eSqcalhO9UGL5fGr0ILKB5cTrPfdpcwV4L4LvHRnsqRiQHjeubg4qQ9FM+f6x7E+qjJbmR8cltFcmnoX4ST7m1/mVsQx7/7M3atbrVObxGLVoFRwss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517027; c=relaxed/simple; bh=vCfMinZ3ioVa697wfHhRMUGC7BJ9VIJaAEWf+LUoN7M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t496lmJYm2fvbPyZ4Z4eizIdMm64dLp9tJzzrfgsm2LRfE1spmtq62ZTekHm5tjtSn5cXKDjxVVyR3YwJT9OLMeilMTc5r3pUgS2S4G/OmdmDLdcSaM6kypKYEOjVvYVEAepdLSizCgzBXtHNRXDBDK2Ej1t9M7Qh6h5fpUKkQc= 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=UVTnGWNa; arc=none smtp.client-ip=209.85.128.201 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="UVTnGWNa" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5fc6463b0edso27935837b3.0 for ; Fri, 09 Feb 2024 14:17:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517025; x=1708121825; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=EtUmW5C5jIEQG3Xq+wKcQPGgTDr9KsPcRaFSmsaaMus=; b=UVTnGWNapPTQj7nVfFqDl2/bgfSHmwVxHNZhcFzxA7vYkFq6lwX/jZfACJPcurBRyg G38buWkRMSGsiWw6iPjl00sFZCNjYdBw19qdBJirxaBRWiGkMrDdfdxYFOLq57XcR3IF 8ChRKcGDg/p9t6pK63ROYdf3j4ONq3rMZmtkvy34ZBib+CApXxppob4U2rJyNYbb5aGj eiaryjW9OKAynLTd4KE4FN9i2al6maxDaASNJVhK+mKEj1fqoc9HD5gxrb4+C1u4Vyoi ORgjK3PoDp870ie4tpIeSUEscuo4ThiwZe9AEH0Ls03wGUbnEzO+8PrgbuRJrmWbfFuC UrpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517025; x=1708121825; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EtUmW5C5jIEQG3Xq+wKcQPGgTDr9KsPcRaFSmsaaMus=; b=k31yRNg6/8r1yjM3WnEGd+fcIQVhrxjhwUfHM0StE/q9IDfRjhTbttCwh5DYDbLfye C0mOa6T8tYdPzCF4UOAjoUbBKEalSJ5N0XSSEIV/HFRFxDGQQHORHDDloDFHNryI3uVj t4sQGM6RSX312o4wM5VeuubgLpKqBqQciOTtZCh7jgpSPAWYdvpMXqh25T1CfM5+Y67M vqpS1cmOa9xKseqi7O3msTrm68zD50QB1sQJKV+7bTpWuXgmqixaWQX+Mjfl0t2GXKGO 1XDCQgjUlp5bJVqEKaqBgdIyZSWc4ry13P1RHO/X8ikdcpF23QlA0RsG5lPX+1wsmjZU pIUg== X-Gm-Message-State: AOJu0YynfxfCw5VoKmNhGVGCYD0YZuGGLwz5tLel/rtfzg1S/+dCZMEQ Q4BNFZld7375BTOZWfAjGR30B+c1C7vucQLwV8Do18MTmUCgFSqweNnunvMxXrSJwCKD7NhUNbi vRA== X-Google-Smtp-Source: AGHT+IHoLzDO4enoLF12MipFfYOPxOqptTuIhXlXrM241lI+t+J+ZGQWc0jkfgWHk3zIV3gHAlO69Fo9B00= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:e6cb:0:b0:604:4073:66ca with SMTP id p194-20020a0de6cb000000b00604407366camr98778ywe.3.1707517024940; Fri, 09 Feb 2024 14:17:04 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:16:58 -0800 In-Reply-To: <20240209221700.393189-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240209221700.393189-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209221700.393189-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: nVMX: Clear EXIT_QUALIFICATION when injecting an EPT Misconfig From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Explicitly clear the EXIT_QUALIFCATION field when injecting an EPT misconfig into L1, as required by the VMX architecture. Per the SDM: This field is saved for VM exits due to the following causes: debug exceptions; page-fault exceptions; start-up IPIs (SIPIs); system-management interrupts (SMIs) that arrive immediately after the execution of I/O instructions; task switches; INVEPT; INVLPG; INVPCID; INVVPID; LGDT; LIDT; LLDT; LTR; SGDT; SIDT; SLDT; STR; VMCLEAR; VMPTRLD; VMPTRST; VMREAD; VMWRITE; VMXON; WBINVD; WBNOINVD; XRSTORS; XSAVES; control-register accesses; MOV DR; I/O instructions; MWAIT; accesses to the APIC-access page; EPT violations; EOI virtualization; APIC-write emulation; page-modification log full; SPP-related events; and instruction timeout. For all other VM exits, this field is cleared. Generating EXIT_QUALIFICATION from vcpu->arch.exit_qualification is wrong for all (two) paths that lead to nested_ept_inject_page_fault(). For EPT violations (the common case), vcpu->arch.exit_qualification will have been set by handle_ept_violation() to vmcs02.EXIT_QUALIFICATION, i.e. contains the information of a EPT violation and thus is likely non-zero. For an EPT misconfig, which can reach FNAME(walk_addr_generic) and thus inject a nEPT misconfig if KVM created an MMIO SPTE that became stale, vcpu->arch.exit_qualification will hold the information from the last EPT violation VM-Exit, as vcpu->arch.exit_qualification is _only_ written by handle_ept_violation(). Fixes: 4704d0befb07 ("KVM: nVMX: Exiting from L2 to L1") Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 994e014f8a50..1eebed84bb65 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -417,10 +417,12 @@ static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu, vmx->nested.pml_full = false; exit_qualification &= INTR_INFO_UNBLOCK_NMI; } else { - if (fault->error_code & PFERR_RSVD_MASK) + if (fault->error_code & PFERR_RSVD_MASK) { vm_exit_reason = EXIT_REASON_EPT_MISCONFIG; - else + exit_qualification = 0; + } else { vm_exit_reason = EXIT_REASON_EPT_VIOLATION; + } /* * Although the caller (kvm_inject_emulated_page_fault) would From patchwork Fri Feb 9 22:16:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13551952 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 D83663B19C for ; Fri, 9 Feb 2024 22:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517029; cv=none; b=c/6gBb+WK/TBJEwn2pdgoCL01490meVlu1RH9B8AwHzncFImtTQnBwfAMRgsQAbRHM2E8JOc+P7OX0GPGRctEC277jjLF6dFsQ3Qt9rx05tF+mjiRwaV4IdKK1XLa15alr5CJpL2jWwFso2d5pAighMiuNZmRDbpTEzj2V14hUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517029; c=relaxed/simple; bh=m+yWYZl+6lZDOPSuIdLV5f59M0wUnPDZJiBRg1Mk2Ys=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R6zCFa8dJww8L49sRNOr/GQKlB70hdsdAoXEi22U7XCiylf5xe9MUwRzbziGP9yLTfY8NLbM28Ggjj7M6/GJSpccm5atRAgjV2JHCWZdfLwu/1d94aGwRFgo3yF3Ge9yY5hOUOFTmdfaxsp5RaEvkqbkLUqQm5IuKPl0Micm7hg= 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=OsOg8o9F; arc=none smtp.client-ip=209.85.219.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="OsOg8o9F" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbe9e13775aso2291810276.1 for ; Fri, 09 Feb 2024 14:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517027; x=1708121827; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=mZnCItuDvbZkdQunBsA68aRkk/hge2O9/C7d+7lVbaA=; b=OsOg8o9FSAY+COwOunvTqVB6HEDwfvnuw8wuVq1CNyCzrkFAkyG2t6bPpkls2pIz02 UjxPu9U/BKE6D4sHuQR1l0HJ7VxlDMatJtxZXvPKN0KkdiDUbLSjKBaUGVk3Nvx0LIPP X4JdP8Q0PW307h7lmZaUo7oSrHmmL3Rbl11K3Xm8PSiBE4MBl9InqIH0yCqP3fNleDvc cGZptsW2xIX5shNynInYQFwIYPPdLbGQfwUJAMQy6LFMjfdWSmCq9XshcrbYsKmck+Rc uthntkNCGsNAnhIV8wy8PdqUGL3mapKcnnTS5YRrU2cVclK2hJWgi66A43psmAAV2Cl+ gKYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517027; x=1708121827; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mZnCItuDvbZkdQunBsA68aRkk/hge2O9/C7d+7lVbaA=; b=FzAoEL8ePP1vEepVT69RkWpjRAy6g8i8x9+1LI7/hpSKjKewsaJvUgeY1IAoIygp8O d4e/HYXqwpnYhEegmNS8glF/q+cMnWpB+cBG5fgndMXnNFAczAq/HlGQ9btu335yccNM 5IB6AZ/x1bxVjGCYXyF3N/vUs52WIZUxuIHbYwCHxngpoZ37ddYc4jpPRB8Wa0fihKLp mqWq3VJOeFGh6nGEWMOggAvJ2auJdhbvTux0d0rn9EAWlrFMG78qLlXHtTU1TUoqQ4kw qDGsnfgtCLPIamfq5stAU4H2Z1sbjU0KVDY3dibhbz5WaAvtidpDG5kOH0MvCR1wUYMF 6rdQ== X-Gm-Message-State: AOJu0YxA7b1zOGGGZO79i2T7BLIAsiLRXwl2sPhJ7ltMQT92AfJEtVux kMogMVulbFp16PWlm2T3tQwac7ZfVLC0aTsZNP5zUUOmomaB63Gc5PozcfIu4f5tXDgwTv36Y3A 2xg== X-Google-Smtp-Source: AGHT+IG7SXxnosYhngfLQSClff0kUEyE2VzBUkFxPSnvX7G5Tmbn2tgydx2K3G2DqXoPQ1DqOxXgJo1dEk4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:9c08:0:b0:dc6:f21f:64ac with SMTP id c8-20020a259c08000000b00dc6f21f64acmr114763ybo.12.1707517026937; Fri, 09 Feb 2024 14:17:06 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:16:59 -0800 In-Reply-To: <20240209221700.393189-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240209221700.393189-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209221700.393189-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: x86: Move nEPT exit_qualification field from kvm_vcpu_arch to x86_exception From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Move the exit_qualification field that is used to track information about in-flight nEPT violations from "struct kvm_vcpu_arch" to "x86_exception", i.e. associate the information with the actual nEPT violation instead of the vCPU. To handle bits that are pulled from vmcs.EXIT_QUALIFICATION, i.e. that are propagated from the "original" EPT violation VM-Exit, simply grab them from the VMCS on-demand when injecting a nEPT Violation or a PML Full VM-exit. Aside from being ugly, having an exit_qualification field in kvm_vcpu_arch is outright dangerous, e.g. see commit d7f0a00e438d ("KVM: VMX: Report up-to-date exit qualification to userspace"). Opportunstically add a comment to call out that PML Full and EPT Violation VM-Exits use the same bit to report NMI blocking information. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 3 --- arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/mmu/paging_tmpl.h | 14 +++++++------- arch/x86/kvm/vmx/nested.c | 14 ++++++++++++-- arch/x86/kvm/vmx/vmx.c | 2 -- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index ad5319a503f0..7ef4715d43d6 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -993,9 +993,6 @@ struct kvm_vcpu_arch { u64 msr_kvm_poll_control; - /* set at EPT violation at this point */ - unsigned long exit_qualification; - /* pv related host specific info */ struct { bool pv_unhalted; diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index 4351149484fb..b5791a66637e 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -26,6 +26,7 @@ struct x86_exception { bool nested_page_fault; u64 address; /* cr2 or nested page fault gpa */ u8 async_page_fault; + unsigned long exit_qualification; }; /* diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 4d4e98fe4f35..7a87097cb45b 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -497,21 +497,21 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, * The other bits are set to 0. */ if (!(errcode & PFERR_RSVD_MASK)) { - vcpu->arch.exit_qualification &= (EPT_VIOLATION_GVA_IS_VALID | - EPT_VIOLATION_GVA_TRANSLATED); + walker->fault.exit_qualification = 0; + if (write_fault) - vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_WRITE; + walker->fault.exit_qualification |= EPT_VIOLATION_ACC_WRITE; if (user_fault) - vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_READ; + walker->fault.exit_qualification |= EPT_VIOLATION_ACC_READ; if (fetch_fault) - vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_INSTR; + walker->fault.exit_qualification |= EPT_VIOLATION_ACC_INSTR; /* * Note, pte_access holds the raw RWX bits from the EPTE, not * ACC_*_MASK flags! */ - vcpu->arch.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) << - EPT_VIOLATION_RWX_SHIFT; + walker->fault.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) << + EPT_VIOLATION_RWX_SHIFT; } #endif walker->fault.address = addr; diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1eebed84bb65..4d0561136e70 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -409,18 +409,28 @@ static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu, { struct vmcs12 *vmcs12 = get_vmcs12(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); + unsigned long exit_qualification; u32 vm_exit_reason; - unsigned long exit_qualification = vcpu->arch.exit_qualification; if (vmx->nested.pml_full) { vm_exit_reason = EXIT_REASON_PML_FULL; vmx->nested.pml_full = false; - exit_qualification &= INTR_INFO_UNBLOCK_NMI; + + /* + * PML Full and EPT Violation VM-Exits both use bit 12 to report + * "NMI unblocking due to IRET", i.e. the bit can be propagated + * as-is from the original EXIT_QUALIFICATION. + */ + exit_qualification = vmx_get_exit_qual(vcpu) & INTR_INFO_UNBLOCK_NMI; } else { if (fault->error_code & PFERR_RSVD_MASK) { vm_exit_reason = EXIT_REASON_EPT_MISCONFIG; exit_qualification = 0; } else { + exit_qualification = fault->exit_qualification; + exit_qualification |= vmx_get_exit_qual(vcpu) & + (EPT_VIOLATION_GVA_IS_VALID | + EPT_VIOLATION_GVA_TRANSLATED); vm_exit_reason = EXIT_REASON_EPT_VIOLATION; } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d4e6625e0a9a..a24fba6b7741 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5771,8 +5771,6 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ? PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; - vcpu->arch.exit_qualification = exit_qualification; - /* * Check that the GPA doesn't exceed physical memory limits, as that is * a guest page fault. We have to emulate the instruction here, because From patchwork Fri Feb 9 22:17:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13551953 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 C4D863BB30 for ; Fri, 9 Feb 2024 22:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517031; cv=none; b=ezZLHTNklCsx4g4uCuG/L/OKX0/QB9DU+Il36oD+c6/Yf5f2jVv+9gMqGEXhCn6llXm5igoAXganN+JdDlO4PNMHYW9zwaggSJQcohbYfV01OLrgukl/qVYZnmmiqLGTk+Trim+0Gy8fIMRcfWbAC9DDW0tc/ZrkuVlhjjOe2kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517031; c=relaxed/simple; bh=5ROcmTVvSgXvIbGuiN/CZtA5rWbe5pIknCwUED8ic5c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vCdEF5RxzvS7gnFtFUaDSFak9s203S36V+m1xoOBKh9dn+x9VXqUikaCFn3t7Ufm2P3Z5OwDw/JKzvjOgVR5NDL5jH3021dEr5h5hg6WMf2aAGAwNU/008cj4ZC5oNuaXTlZRAxu0u6iuGCB/hwSqMLK4Kd+Q6i2FPw90Rxr9eM= 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=GLAyxBTW; arc=none smtp.client-ip=209.85.128.201 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="GLAyxBTW" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-604a1a44b56so22449537b3.2 for ; Fri, 09 Feb 2024 14:17:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517028; x=1708121828; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=xriXj5ETw+SM6HIrjBhtRYR+FpAUxlK2qVu7eV3/IuU=; b=GLAyxBTWGWdBIiHRzZZ2cDdHVFRWzPWB0gVp6BnC9IrZBal8Uom1oqFhpI+RXcY6cX I+iz04yAbfy9jFA7RMYaSJMP1h1uw1jE+d3N/zVMVfFoh2yV0WL5zJw+vBIhc9XANZvb zT1igYLPYy1oqbKNCf9NNkTNTyRBJRtVONL7AVmLMNS4UGi1Pxhq77N9UEzHsyeey99s 5oIuiN2nilmffCHvWblbG2yfFPopqqu7XgCaYn8QcjEdnQqwuj1Jf62Fg20DMP2iW9tN ZK5gNr+mZbtg9/HAKOuiCBkd6qR0G0gTT02qUbRcfV1IQRIocC0UfDTJJt9GPN2pbzeJ 3Mhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517028; x=1708121828; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xriXj5ETw+SM6HIrjBhtRYR+FpAUxlK2qVu7eV3/IuU=; b=xATNLTwv5i2KBnecxf76DyKhyWNx3Foz1yZaO+pjdrexfV5Dxbl5HRtF8oLnp1ymiB uxHoxfb2eLoSRN66Ar1jlC8pVkU8i/P9yS5W77JVaZXdCBz7umV9PeYtrwbi2fTrNgXc +pSoUFIJ1Km5Fwp08qXZm3QaCUNYBS9RQrYoANFuxIQFQM/wdgJIRNRUE5vAzXY1C0Ff bc4PLJjcjtfOXWDdHlr/4tfOyNFCM/l17bOseGd3OSpwyxa5TjQ7CwzpZlhO5mWL4VcN bjW2R1uW+fP7fO4ZCKov0NoiG/q/1cKt7IsQb12B82DU7oNPv2725ra2XALnF2yCmOs9 KKqQ== X-Gm-Message-State: AOJu0Yzv3WJKwhuI+iC4dGAc9DOzEDbZfu95Vtaw+LJHULhJVodGgBQK CzWpOSQj87Gjri7WovrOYpnNFbnoGaltRO+UQ2xqh/4ox2Cogkgi9Ap7tElYQzAeFnsmHMFT8GE GVw== X-Google-Smtp-Source: AGHT+IFBb4C7Le8Uy1i1H/KekvmVJQcT8a1e7ObuqcVXCQx3MQ2cKGmrti4S38CyLF4p9XbPUBMPk0eKB5o= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:d82:b0:604:ac3b:75d5 with SMTP id da2-20020a05690c0d8200b00604ac3b75d5mr123597ywb.7.1707517028741; Fri, 09 Feb 2024 14:17:08 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:17:00 -0800 In-Reply-To: <20240209221700.393189-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240209221700.393189-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209221700.393189-4-seanjc@google.com> Subject: [PATCH 3/3] KVM: nVMX: Add a sanity check that nested PML Full stems from EPT Violations From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Add a WARN_ON_ONCE() sanity check to verify that a nested PML Full VM-Exit is only synthesized when the original VM-Exit from L2 was an EPT Violation. While KVM can fallthrough to kvm_mmu_do_page_fault() if an EPT Misconfig occurs on a stale MMIO SPTE, KVM should not treat the access as a write (there isn't enough information to know *what* the access was), i.e. KVM should never try to insert a PML entry in that case. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 4d0561136e70..29df186dac84 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -416,6 +416,16 @@ static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu, vm_exit_reason = EXIT_REASON_PML_FULL; vmx->nested.pml_full = false; + /* + * It should be impossible to trigger a nested PML Full VM-Exit + * for anything other than an EPT Violation from L2. KVM *can* + * trigger nEPT page fault injection in response to an EPT + * Misconfig, e.g. if the MMIO SPTE was stale and L1's EPT + * tables also changed, but KVM should not treat EPT Misconfig + * VM-Exits as writes. + */ + WARN_ON_ONCE(vmx->exit_reason.basic != EXIT_REASON_EPT_VIOLATION); + /* * PML Full and EPT Violation VM-Exits both use bit 12 to report * "NMI unblocking due to IRET", i.e. the bit can be propagated