From: "Huang, Kai" <kai.huang@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Yan Zhao <yan.y.zhao@intel.com>,
"Isaku Yamahata" <isaku.yamahata@intel.com>,
Michael Roth <michael.roth@amd.com>,
"Yu Zhang" <yu.c.zhang@linux.intel.com>,
Chao Peng <chao.p.peng@linux.intel.com>,
Fuad Tabba <tabba@google.com>,
David Matlack <dmatlack@google.com>
Subject: Re: [PATCH 08/16] KVM: x86/mmu: WARN and skip MMIO cache on private, reserved page faults
Date: Fri, 1 Mar 2024 12:21:59 +1300 [thread overview]
Message-ID: <05449435-008c-4d51-b21f-03df1fa58e77@intel.com> (raw)
In-Reply-To: <ZeEOC0mo8C4GL708@google.com>
On 1/03/2024 12:06 pm, Sean Christopherson wrote:
> On Fri, Mar 01, 2024, Kai Huang wrote:
>>
>>
>> On 28/02/2024 3:41 pm, Sean Christopherson wrote:
>>> WARN and skip the emulated MMIO fastpath if a private, reserved page fault
>>> is encountered, as private+reserved should be an impossible combination
>>> (KVM should never create an MMIO SPTE for a private access).
>>>
>>> Signed-off-by: Sean Christopherson <seanjc@google.com>
>>> ---
>>> arch/x86/kvm/mmu/mmu.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
>>> index bd342ebd0809..9206cfa58feb 100644
>>> --- a/arch/x86/kvm/mmu/mmu.c
>>> +++ b/arch/x86/kvm/mmu/mmu.c
>>> @@ -5866,7 +5866,8 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err
>>> error_code |= PFERR_PRIVATE_ACCESS;
>>> r = RET_PF_INVALID;
>>> - if (unlikely(error_code & PFERR_RSVD_MASK)) {
>>> + if (unlikely((error_code & PFERR_RSVD_MASK) &&
>>> + !WARN_ON_ONCE(error_code & PFERR_PRIVATE_ACCESS))) {
>>> r = handle_mmio_page_fault(vcpu, cr2_or_gpa, direct);
>>> if (r == RET_PF_EMULATE)
>>> goto emulate;
>>
>> It seems this will make KVM continue to call kvm_mmu_do_page_fault() when
>> such private+reserve error code actually happens (e.g., due to bug), because
>> @r is still RET_PF_INVALID in such case.
>
> Yep.
>
>> Is it better to just return error, e.g., -EINVAL, and give up?
>
> As long as there is no obvious/immediate danger to the host, no obvious way for
> the "bad" behavior to cause data corruption for the guest, and continuing on has
> a plausible chance of working, then KVM should generally try to continue on and
> not terminate the VM.
Agreed. But I think sometimes it is hard to tell whether there's any
dangerous things waiting to happen, because that means we have to sanity
check a lot of code, and when new patches arrive we need to keep that in
mind too, which could be a nightmare in terms of maintenance.
>
> E.g. in this case, KVM will just skip various fast paths because of the RSVD flag,
> and treat the fault like a PRIVATE fault. Hmm, but page_fault_handle_page_track()
> would skip write tracking, which could theoretically cause data corruption, so I
> guess arguably it would be safer to bail?
>
> Anyone else have an opinion? This type of bug should never escape development,
> so I'm a-ok effectively killing the VM. Unless someone has a good argument for
> continuing on, I'll go with Kai's suggestion and squash this:
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index cedacb1b89c5..d796a162b2da 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -5892,8 +5892,10 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err
> error_code |= PFERR_PRIVATE_ACCESS;
>
> r = RET_PF_INVALID;
> - if (unlikely((error_code & PFERR_RSVD_MASK) &&
> - !WARN_ON_ONCE(error_code & PFERR_PRIVATE_ACCESS))) {
> + if (unlikely(error_code & PFERR_RSVD_MASK)) {
> + if (WARN_ON_ONCE(error_code & PFERR_PRIVATE_ACCESS))
> + return -EFAULT;
-EFAULT is part of guest_memfd() memory fault ABI. I didn't think over
this thoroughly but do you want to return -EFAULT here?
next prev parent reply other threads:[~2024-02-29 23:22 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 2:41 [PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups Sean Christopherson
2024-02-28 2:41 ` [PATCH 01/16] KVM: x86/mmu: Exit to userspace with -EFAULT if private fault hits emulation Sean Christopherson
2024-03-01 8:48 ` Xiaoyao Li
2024-03-07 12:52 ` Gupta, Pankaj
2024-03-12 2:59 ` Binbin Wu
2024-04-04 16:38 ` Sean Christopherson
2024-03-08 4:22 ` Yan Zhao
2024-04-04 16:45 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 02/16] KVM: x86: Remove separate "bit" defines for page fault error code masks Sean Christopherson
2024-02-29 12:44 ` Paolo Bonzini
2024-02-29 18:40 ` Sean Christopherson
2024-02-29 20:56 ` Paolo Bonzini
2024-02-29 13:43 ` Dongli Zhang
2024-02-29 15:25 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 03/16] KVM: x86: Define more SEV+ page fault error bits/flags for #NPF Sean Christopherson
2024-02-28 4:43 ` Dongli Zhang
2024-02-28 16:16 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 04/16] KVM: x86/mmu: Pass full 64-bit error code when handling page faults Sean Christopherson
2024-02-28 7:30 ` Dongli Zhang
2024-02-28 16:22 ` Sean Christopherson
2024-02-29 13:32 ` Dongli Zhang
2024-03-05 3:55 ` Xiaoyao Li
2024-02-28 2:41 ` [PATCH 05/16] KVM: x86/mmu: Use synthetic page fault error code to indicate private faults Sean Christopherson
2024-02-29 11:16 ` Huang, Kai
2024-02-29 15:17 ` Sean Christopherson
2024-03-06 9:43 ` Xu Yilun
2024-03-06 14:45 ` Sean Christopherson
2024-03-07 9:05 ` Xu Yilun
2024-03-07 14:36 ` Sean Christopherson
2024-03-12 5:34 ` Binbin Wu
2024-02-28 2:41 ` [PATCH 06/16] KVM: x86/mmu: WARN if upper 32 bits of legacy #PF error code are non-zero Sean Christopherson
2024-02-29 22:11 ` Huang, Kai
2024-02-29 23:07 ` Sean Christopherson
2024-03-12 5:44 ` Binbin Wu
2024-02-28 2:41 ` [PATCH 07/16] KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler Sean Christopherson
2024-02-29 22:19 ` Huang, Kai
2024-02-29 22:52 ` Sean Christopherson
2024-02-29 23:14 ` Huang, Kai
2024-03-12 9:44 ` Binbin Wu
2024-02-28 2:41 ` [PATCH 08/16] KVM: x86/mmu: WARN and skip MMIO cache on private, reserved page faults Sean Christopherson
2024-02-29 22:26 ` Huang, Kai
2024-02-29 23:06 ` Sean Christopherson
2024-02-29 23:21 ` Huang, Kai [this message]
2024-03-04 15:51 ` Sean Christopherson
2024-03-05 21:32 ` Huang, Kai
2024-03-06 0:25 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 09/16] KVM: x86/mmu: Move private vs. shared check above slot validity checks Sean Christopherson
2024-03-05 23:06 ` Huang, Kai
2024-03-06 0:38 ` Sean Christopherson
2024-03-06 1:22 ` Huang, Kai
2024-03-06 2:02 ` Sean Christopherson
2024-03-06 22:06 ` Huang, Kai
2024-03-06 23:49 ` Sean Christopherson
2024-03-07 0:28 ` Huang, Kai
2024-03-08 4:54 ` Xu Yilun
2024-03-08 23:28 ` Sean Christopherson
2024-03-11 4:43 ` Xu Yilun
2024-03-12 0:08 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 10/16] KVM: x86/mmu: Don't force emulation of L2 accesses to non-APIC internal slots Sean Christopherson
2024-03-07 0:03 ` Huang, Kai
2024-02-28 2:41 ` [PATCH 11/16] KVM: x86/mmu: Explicitly disallow private accesses to emulated MMIO Sean Christopherson
2024-03-06 22:35 ` Huang, Kai
2024-03-06 22:43 ` Sean Christopherson
2024-03-06 22:49 ` Huang, Kai
2024-03-06 23:01 ` Sean Christopherson
2024-03-06 23:20 ` Huang, Kai
2024-03-07 17:10 ` Kirill A. Shutemov
2024-03-08 0:09 ` Huang, Kai
2024-02-28 2:41 ` [PATCH 12/16] KVM: x86/mmu: Move slot checks from __kvm_faultin_pfn() to kvm_faultin_pfn() Sean Christopherson
2024-03-07 0:11 ` Huang, Kai
2024-02-28 2:41 ` [PATCH 13/16] KVM: x86/mmu: Handle no-slot faults at the beginning of kvm_faultin_pfn() Sean Christopherson
2024-03-07 0:48 ` Huang, Kai
2024-03-07 0:53 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 14/16] KVM: x86/mmu: Set kvm_page_fault.hva to KVM_HVA_ERR_BAD for "no slot" faults Sean Christopherson
2024-03-07 0:50 ` Huang, Kai
2024-03-07 1:01 ` Sean Christopherson
2024-02-28 2:41 ` [PATCH 15/16] KVM: x86/mmu: Initialize kvm_page_fault's pfn and hva to error values Sean Christopherson
2024-03-07 0:46 ` Huang, Kai
2024-02-28 2:41 ` [PATCH 16/16] KVM: x86/mmu: Sanity check that __kvm_faultin_pfn() doesn't create noslot pfns Sean Christopherson
2024-03-07 0:46 ` Huang, Kai
2024-04-17 12:48 ` [PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups Paolo Bonzini
2024-04-18 15:40 ` Sean Christopherson
2024-04-19 6:47 ` Xiaoyao Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=05449435-008c-4d51-b21f-03df1fa58e77@intel.com \
--to=kai.huang@intel.com \
--cc=chao.p.peng@linux.intel.com \
--cc=dmatlack@google.com \
--cc=isaku.yamahata@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tabba@google.com \
--cc=yan.y.zhao@intel.com \
--cc=yu.c.zhang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).