lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240226180626.GE177224@ls.amr.corp.intel.com>
Date: Mon, 26 Feb 2024 10:06:26 -0800
From: Isaku Yamahata <isaku.yamahata@...ux.intel.com>
To: Paolo Bonzini <pbonzini@...hat.com>
Cc: isaku.yamahata@...el.com, kvm@...r.kernel.org,
	linux-kernel@...r.kernel.org, isaku.yamahata@...il.com,
	erdemaktas@...gle.com, Sean Christopherson <seanjc@...gle.com>,
	Sagi Shahar <sagis@...gle.com>, Kai Huang <kai.huang@...el.com>,
	chen.bo@...el.com, hang.yuan@...el.com, tina.zhang@...el.com,
	Chao Gao <chao.gao@...el.com>, isaku.yamahata@...ux.intel.com
Subject: Re: [PATCH v18 044/121] KVM: x86/mmu: Assume guest MMIOs are shared

On Mon, Feb 12, 2024 at 11:29:51AM +0100,
Paolo Bonzini <pbonzini@...hat.com> wrote:

> On Tue, Jan 23, 2024 at 12:55 AM <isaku.yamahata@...el.com> wrote:
> >
> > From: Chao Gao <chao.gao@...el.com>
> >
> > Guest TD doesn't necessarily invoke MAP_GPA to convert the virtual MMIO
> > range to shared before accessing it.  When TD tries to access the virtual
> > device's MMIO as shared, an EPT violation is raised first.
> > kvm_mem_is_private() checks whether the GFN is shared or private.  If
> > MAP_GPA is not called for the GPA, KVM thinks the GPA is private and
> > refuses shared access, and doesn't set up shared EPT entry.  The guest
> > can't make progress.
> >
> > Instead of requiring the guest to invoke MAP_GPA for regions of virtual
> > MMIOs assume regions of virtual MMIOs are shared in KVM as well (i.e., GPAs
> > either have no kvm_memory_slot or are backed by host MMIOs). So that guests
> > can access those MMIO regions.
> 
> I'm not sure how the patch below deals with host MMIOs?

It falls back to shared case to hit KVM_PFN_NOSLOT. It will be handled as
MMIO.

Anyway I found it breaks SW_PROTECTED case.  So I came up with the following.
I think we'd like to handle as
  - SW_PROTECTED => KVM_EXIT_MEMORY_FAULT
  - SNP, TDX => MMIO.
  


-       if (fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) {
+       /*
+        * !fault->slot means MMIO for SNP and TDX.  Don't require explicit GPA
+        * conversion for MMIO because MMIO is assigned at the boot time.  Fall
+        * to !is_private case to get pfn = KVM_PFN_NOSLOT.
+        */
+       force_mmio = !slot &&
+               vcpu->kvm->arch.vm_type != KVM_X86_DEFAULT_VM &&
+               vcpu->kvm->arch.vm_type != KVM_X86_SW_PROTECTED_VM;
+       if (!force_mmio &&
+           fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) {
                kvm_mmu_prepare_memory_fault_exit(vcpu, fault);
                return -EFAULT;
        }
 
-       if (fault->is_private)
+       if (!force_mmio && fault->is_private)
                return kvm_faultin_pfn_private(vcpu, fault);

-- 
Isaku Yamahata <isaku.yamahata@...ux.intel.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ