Re: [Intel-gfx] [PATCH 19/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-08-10 Thread Yan Zhao
On Thu, Aug 10, 2023 at 08:41:14AM -0700, Sean Christopherson wrote: > On Thu, Aug 10, 2023, Yan Zhao wrote: > > On Thu, Aug 10, 2023 at 07:21:03AM +0800, Yan Zhao wrote: > > > > Reading the value after acquiring mmu_lock ensures that both vCPUs will > > > > see w

Re: [Intel-gfx] [PATCH 19/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-08-09 Thread Yan Zhao
On Thu, Aug 10, 2023 at 07:21:03AM +0800, Yan Zhao wrote: > On Wed, Aug 09, 2023 at 07:33:45AM -0700, Sean Christopherson wrote: > > On Wed, Aug 09, 2023, Yan Zhao wrote: > > > On Mon, Aug 07, 2023 at 10:19:07AM -0700, Sean Christopherson wrote: > > > > On Mo

Re: [Intel-gfx] [PATCH 19/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-08-09 Thread Yan Zhao
On Wed, Aug 09, 2023 at 07:33:45AM -0700, Sean Christopherson wrote: > On Wed, Aug 09, 2023, Yan Zhao wrote: > > On Mon, Aug 07, 2023 at 10:19:07AM -0700, Sean Christopherson wrote: > > > On Mon, Aug 07, 2023, Like Xu wrote: > > > > On 23/12/2022 8:57

Re: [Intel-gfx] [PATCH 19/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-08-08 Thread Yan Zhao
On Mon, Aug 07, 2023 at 10:19:07AM -0700, Sean Christopherson wrote: > On Mon, Aug 07, 2023, Like Xu wrote: > > On 23/12/2022 8:57 am, Sean Christopherson wrote: > > > +static inline void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, > > > + const u8 *new, i

Re: [Intel-gfx] [PATCH v4.1] drm/i915/gvt: Explicitly check that vGPU is attached before shadowing

2023-08-01 Thread Yan Zhao
Reviewed-by: Yan Zhao Tested-by: Yan Zhao On Tue, Aug 01, 2023 at 04:05:21PM -0700, Sean Christopherson wrote: > Move the check that a vGPU is attached from is_2MB_gtt_possible() all the > way up to shadow_ppgtt_mm() to avoid unnecessary work, and to make it more > obvious that a futur

Re: [Intel-gfx] [PATCH v4 03/29] drm/i915/gvt: Verify hugepages are contiguous in physical address space

2023-07-31 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Jul 28, 2023 at 06:35:09PM -0700, Sean Christopherson wrote: > When shadowing a GTT entry with a 2M page, verify that the pfns are > contiguous, not just that the struct page pointers are contiguous. The > memory map is virtual contiguous if "CO

Re: [Intel-gfx] [PATCH v4 07/29] drm/i915/gvt: Error out on an attempt to shadowing an unknown GTT entry type

2023-07-31 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Jul 28, 2023 at 06:35:13PM -0700, Sean Christopherson wrote: > Bail from ppgtt_populate_shadow_entry() if an unexpected GTT entry type > is encountered instead of subtly falling through to the common "direct > shadow" path. Eliminating the d

Re: [Intel-gfx] [PATCH v4 06/29] drm/i915/gvt: Explicitly check that vGPU is attached before shadowing

2023-07-31 Thread Yan Zhao
On Fri, Jul 28, 2023 at 06:35:12PM -0700, Sean Christopherson wrote: > Move the check that a vGPU is attacked from is_2MB_gtt_possible() all the typo: "attacked" --> "attached" > way up to shadow_ppgtt_mm() to avoid unnecessary work, and to make it more This commit message does not match to what t

[Intel-gfx] [PATCH] drm/i915/gvt: Fix bug in getting msg length in AUX CH registers handler

2023-07-31 Thread Yan Zhao
low warning in intel_gvt_i2c_handle_aux_ch_write(): "i915 :00:02.0: drm_WARN_ON(msg_length != 4)". Fixes: 0cad796a2269 ("drm/i915: Use REG_BIT() & co. for AUX CH registers") Signed-off-by: Yan Zhao --- drivers/gpu/drm/i915/gvt/edid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -

Re: [Intel-gfx] [PATCH v3 03/28] drm/i915/gvt: Verify hugepages are contiguous in physical address space

2023-05-18 Thread Yan Zhao
On Thu, May 18, 2023 at 11:04:46AM -0700, Sean Christopherson wrote: > On Thu, May 18, 2023, Yan Zhao wrote: > > On Wed, May 17, 2023 at 07:50:26AM -0700, Sean Christopherson wrote: > > > On Tue, May 16, 2023, Yan Zhao wrote: > > > > hi Sean > > > > >

Re: [Intel-gfx] [PATCH v3 03/28] drm/i915/gvt: Verify hugepages are contiguous in physical address space

2023-05-18 Thread Yan Zhao
On Wed, May 17, 2023 at 07:50:26AM -0700, Sean Christopherson wrote: > On Tue, May 16, 2023, Yan Zhao wrote: > > hi Sean > > > > Do you think it's necessary to double check that struct page pointers > > are also contiguous? > > No, the virtual address space

Re: [Intel-gfx] [PATCH v3 21/28] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-05-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, May 12, 2023 at 05:35:53PM -0700, Sean Christopherson wrote: > Disable the page-track notifier code at compile time if there are no > external users, i.e. if CONFIG_KVM_EXTERNAL_WRITE_TRACKING=n. KVM itself > now hooks emulated writes directly instead of r

Re: [Intel-gfx] [PATCH v3 12/28] KVM: x86/mmu: Don't rely on page-track mechanism to flush on memslot change

2023-05-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, May 12, 2023 at 05:35:44PM -0700, Sean Christopherson wrote: > Call kvm_mmu_zap_all_fast() directly when flushing a memslot instead of > bouncing through the page-track mechanism. KVM (unfortunately) needs to > zap and flush all page tables on memslot DE

Re: [Intel-gfx] [PATCH v3 07/28] drm/i915/gvt: Don't rely on KVM's gfn_to_pfn() to query possible 2M GTT

2023-05-16 Thread Yan Zhao
Reviewed-by: Yan Zhao Tested-by: Yan Zhao On Fri, May 12, 2023 at 05:35:39PM -0700, Sean Christopherson wrote: > Now that gvt_pin_guest_page() explicitly verifies the pinned PFN is a > transparent hugepage page, don't use KVM's gfn_to_pfn() to pre-check if a > 2MiB GTT en

Re: [Intel-gfx] [PATCH v3 03/28] drm/i915/gvt: Verify hugepages are contiguous in physical address space

2023-05-16 Thread Yan Zhao
hi Sean Do you think it's necessary to double check that struct page pointers are also contiguous? And do you like to also include a fix as below, which is to remove the warning in vfio_device_container_unpin_pages() when npage is 0? @ -169,7 +173,8 @@ static int gvt_pin_guest_page(struct intel_

Re: [Intel-gfx] [PATCH v2 25/27] KVM: x86/mmu: Drop @slot param from exported/external page-track APIs

2023-05-11 Thread Yan Zhao
> > Hi Sean, > > After more thoughts, do you think checking KVM internal memslot is > > necessary? > > I don't think it's necessary per se, but I also can't think of any reason to > allow > it. > > > slot = gfn_to_memslot(kvm, gfn); > > if (!slot || slot->id >= KVM_USER_MEM_SLOTS) { > >

Re: [Intel-gfx] [PATCH v2 25/27] KVM: x86/mmu: Drop @slot param from exported/external page-track APIs

2023-05-07 Thread Yan Zhao
On Thu, May 04, 2023 at 10:17:20AM +0800, Yan Zhao wrote: > On Wed, May 03, 2023 at 04:16:10PM -0700, Sean Christopherson wrote: > > Finally getting back to this series... > > > > On Thu, Mar 23, 2023, Yan Zhao wrote: > > > On Fri, Mar 17, 2023 at 04:28:56PM +0800,

Re: [Intel-gfx] [PATCH v2 05/27] drm/i915/gvt: Verify VFIO-pinned page is THP when shadowing 2M gtt entry

2023-05-06 Thread Yan Zhao
On Sat, May 06, 2023 at 02:35:41PM +0800, Yan Zhao wrote: > > > Maybe the checking of PageTransHuge(cur_page) and bailing out is not > > > necessary. > > > If a page is not transparent huge, but there are 512 contigous 4K > > > pages, I think it's still g

Re: [Intel-gfx] [PATCH v2 05/27] drm/i915/gvt: Verify VFIO-pinned page is THP when shadowing 2M gtt entry

2023-05-06 Thread Yan Zhao
> > Maybe the checking of PageTransHuge(cur_page) and bailing out is not > > necessary. > > If a page is not transparent huge, but there are 512 contigous 4K > > pages, I think it's still good to map them in IOMMU in 2M. > > See vfio_pin_map_dma() who does similar things. > > I agree that bailing

Re: [Intel-gfx] [PATCH v2 20/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-05-05 Thread Yan Zhao
On Thu, May 04, 2023 at 12:54:40PM -0700, Sean Christopherson wrote: > On Wed, Mar 15, 2023, Sean Christopherson wrote: > > On Wed, Mar 15, 2023, Yan Zhao wrote: > > > On Fri, Mar 10, 2023 at 04:22:51PM -0800, Sean Christopherson wrote: > > > > Disable the page-track

Re: [Intel-gfx] [PATCH v2 25/27] KVM: x86/mmu: Drop @slot param from exported/external page-track APIs

2023-05-03 Thread Yan Zhao
On Wed, May 03, 2023 at 04:16:10PM -0700, Sean Christopherson wrote: > Finally getting back to this series... > > On Thu, Mar 23, 2023, Yan Zhao wrote: > > On Fri, Mar 17, 2023 at 04:28:56PM +0800, Yan Zhao wrote: > > > On Fri, Mar 10, 2023 at 04:22:56PM -0800, S

Re: [Intel-gfx] [PATCH v2 25/27] KVM: x86/mmu: Drop @slot param from exported/external page-track APIs

2023-03-23 Thread Yan Zhao
On Fri, Mar 17, 2023 at 04:28:56PM +0800, Yan Zhao wrote: > On Fri, Mar 10, 2023 at 04:22:56PM -0800, Sean Christopherson wrote: > ... > > +int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn) > > +{ > > + struct kvm_memory_slot *slot; > > + int idx; > >

Re: [Intel-gfx] [PATCH v2 27/27] drm/i915/gvt: Drop final dependencies on KVM internal details

2023-03-17 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:58PM -0800, Sean Christopherson wrote: > Open code gpa_to_gfn() in kvmgt_page_track_write() and drop KVMGT's > dependency on kvm_host.h, i.e. include only kvm_page_track.h. KVMGT > assumes "gfn == gpa >> PAGE_

Re: [Intel-gfx] [PATCH v2 26/27] KVM: x86/mmu: Handle KVM bookkeeping in page-track APIs, not callers

2023-03-17 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:57PM -0800, Sean Christopherson wrote: > Get/put references to KVM when a page-track notifier is (un)registered > instead of relying on the caller to do so. Forcing the caller to do the > bookkeeping is unnecessary and adds one more

Re: [Intel-gfx] [PATCH v2 25/27] KVM: x86/mmu: Drop @slot param from exported/external page-track APIs

2023-03-17 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:56PM -0800, Sean Christopherson wrote: ... > +int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn) > +{ > + struct kvm_memory_slot *slot; > + int idx; > + > + idx = srcu_read_lock(&kvm->srcu); > + > + slot = gfn_to_memslot(kvm, gfn); > + if (!slo

Re: [Intel-gfx] [PATCH v2 23/27] KVM: x86/mmu: Assert that correct locks are held for page write-tracking

2023-03-17 Thread Yan Zhao
Tested-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:54PM -0800, Sean Christopherson wrote: > When adding/removing gfns to/from write-tracking, assert that mmu_lock > is held for write, and that either slots_lock or kvm->srcu is held. > mmu_lock must be held for write to protect gfn_w

Re: [Intel-gfx] [PATCH v2 17/27] drm/i915/gvt: switch from ->track_flush_slot() to ->track_remove_region()

2023-03-17 Thread Yan Zhao
Tested-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:48PM -0800, Sean Christopherson wrote: > From: Yan Zhao > > Switch from the poorly named and flawed ->track_flush_slot() to the newly > introduced ->track_remove_region(). From KVMGT's perspective, the two > hooks a

Re: [Intel-gfx] [PATCH v2 16/27] KVM: x86: Add a new page-track hook to handle memslot deletion

2023-03-17 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:47PM -0800, Sean Christopherson wrote: > From: Yan Zhao > > Add a new page-track hook, track_remove_region(), that is called when a > memslot DELETE operation is about to be committed. The "remove" hook > will be used by KVMGT and wil

Re: [Intel-gfx] [PATCH v2 15/27] drm/i915/gvt: Don't bother removing write-protection on to-be-deleted slot

2023-03-17 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:46PM -0800, Sean Christopherson wrote: > When handling a slot "flush", don't call back into KVM to drop write > protection for gfns in the slot. Now that KVM rejects attempts to move > memory slots while KVMGT is attach

Re: [Intel-gfx] [PATCH v2 14/27] KVM: x86: Reject memslot MOVE operations if KVMGT is attached

2023-03-17 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:45PM -0800, Sean Christopherson wrote: > Disallow moving memslots if the VM has external page-track users, i.e. if > KVMGT is being used to expose a virtual GPU to the guest, as KVM doesn't > correctly handle moving memory regi

Re: [Intel-gfx] [PATCH v2 13/27] KVM: drm/i915/gvt: Drop @vcpu from KVM's ->track_write() hook

2023-03-17 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:44PM -0800, Sean Christopherson wrote: > Drop @vcpu from KVM's ->track_write() hook provided for external users of > the page-track APIs now that KVM itself doesn't use the page-track > mechanism. > > Signed

Re: [Intel-gfx] [PATCH v2 12/27] KVM: x86/mmu: Don't bounce through page-track mechanism for guest PTEs

2023-03-17 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:43PM -0800, Sean Christopherson wrote: > Don't use the generic page-track mechanism to handle writes to guest PTEs > in KVM's MMU. KVM's MMU needs access to information that should not be > exposed to external page-tra

Re: [Intel-gfx] [PATCH v2 10/27] drm/i915/gvt: Protect gfn hash table with vgpu_lock

2023-03-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:41PM -0800, Sean Christopherson wrote: > Use vgpu_lock instead of KVM's mmu_lock to protect accesses to the hash > table used to track which gfns are write-protected when shadowing the > guest's GTT, and hoist the acquisitio

Re: [Intel-gfx] [PATCH v2 09/27] drm/i915/gvt: Drop unused helper intel_vgpu_reset_gtt()

2023-03-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:40PM -0800, Sean Christopherson wrote: > Drop intel_vgpu_reset_gtt() as it no longer has any callers. In addition > to eliminating dead code, this eliminates the last possible scenario where > __kvmgt_protect_table_find() can b

Re: [Intel-gfx] [PATCH v2 08/27] drm/i915/gvt: Use an "unsigned long" to iterate over memslot gfns

2023-03-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:39PM -0800, Sean Christopherson wrote: > Use an "unsigned long" instead of an "int" when iterating over the gfns > in a memslot. The number of pages in the memslot is tracked as an > "unsigned long", e.

Re: [Intel-gfx] [PATCH v2 06/27] drm/i915/gvt: Put the page reference obtained by KVM's gfn_to_pfn()

2023-03-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:37PM -0800, Sean Christopherson wrote: > Put the struct page reference acquired by gfn_to_pfn(), KVM's API is that > the caller is ultimately responsible for dropping any reference. > > Note, kvm_release_pfn_clean() ensures th

Re: [Intel-gfx] [PATCH v2 07/27] drm/i915/gvt: Don't rely on KVM's gfn_to_pfn() to query possible 2M GTT

2023-03-16 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:38PM -0800, Sean Christopherson wrote: > /* > - * Check if can do 2M page > + * Try to map a 2M gtt entry. > * @vgpu: target vgpu > * @entry: target pfn's gtt entry > * > - * Return 1 if 2MB huge gtt shadowing is possible, 0 if miscondition, > - * negative if fo

Re: [Intel-gfx] [PATCH v2 05/27] drm/i915/gvt: Verify VFIO-pinned page is THP when shadowing 2M gtt entry

2023-03-16 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:36PM -0800, Sean Christopherson wrote: > When shadowing a GTT entry with a 2M page, explicitly verify that the > first page pinned by VFIO is a transparent hugepage instead of assuming > that page observed by is_2MB_gtt_possible() is the same page pinned by > vfio_pin_

Re: [Intel-gfx] [PATCH v2 03/27] drm/i915/gvt: remove interface intel_gvt_is_valid_gfn

2023-03-16 Thread Yan Zhao
Tested-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:34PM -0800, Sean Christopherson wrote: > From: Yan Zhao > > Currently intel_gvt_is_valid_gfn() is called in two places: > (1) shadowing guest GGTT entry > (2) shadowing guest PPGTT leaf entry, > which was introduced in c

Re: [Intel-gfx] [PATCH v2 01/27] drm/i915/gvt: Verify pfn is "valid" before dereferencing "struct page"

2023-03-16 Thread Yan Zhao
Reviewed-by: Yan Zhao On Fri, Mar 10, 2023 at 04:22:32PM -0800, Sean Christopherson wrote: > Check that the pfn found by gfn_to_pfn() is actually backed by "struct > page" memory prior to retrieving and dereferencing the page. KVM > supports backing guest memory with VM_PFNMA

Re: [Intel-gfx] [PATCH v2 20/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-03-16 Thread Yan Zhao
On Wed, Mar 15, 2023 at 09:21:34AM -0700, Sean Christopherson wrote: > On Wed, Mar 15, 2023, Yan Zhao wrote: > > Nit: there is a typo in the commit header: "iff" -> "if" > > > > > -void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, cons

Re: [Intel-gfx] [PATCH v2 14/27] KVM: x86: Reject memslot MOVE operations if KVMGT is attached

2023-03-16 Thread Yan Zhao
On Wed, Mar 15, 2023 at 08:43:54AM -0700, Sean Christopherson wrote: > > So, in theory, the new GFNs are not write tracked though the old ones are. > > > > Is that acceptable for the internal page-track user? > > It works because KVM zaps all SPTEs when a memslot is moved, i.e. the fact > that O

Re: [Intel-gfx] [PATCH v2 19/27] KVM: x86/mmu: Move KVM-only page-track declarations to internal header

2023-03-16 Thread Yan Zhao
On Wed, Mar 15, 2023 at 08:13:37AM -0700, Sean Christopherson wrote: > > A curious question: > > are arch/x86/include/asm/kvm_*.h all expected to be external accessible? > > Depends on what you mean by "expected". Currently, yes, everything in there > is > globally visible. But the vast majorit

Re: [Intel-gfx] [PATCH v2 20/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-03-15 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:51PM -0800, Sean Christopherson wrote: > Disable the page-track notifier code at compile time if there are no > external users, i.e. if CONFIG_KVM_EXTERNAL_WRITE_TRACKING=n. KVM itself > now hooks emulated writes directly instead of relying on the page-track > mechani

Re: [Intel-gfx] [PATCH v2 20/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2023-03-15 Thread Yan Zhao
Nit: there is a typo in the commit header: "iff" -> "if" > -void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new, > - int bytes) > +void __kvm_page_track_write(struct kvm *kvm, gpa_t gpa, const u8 *new, int > bytes) Line length is 81 characters. A little

Re: [Intel-gfx] [PATCH v2 19/27] KVM: x86/mmu: Move KVM-only page-track declarations to internal header

2023-03-15 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:50PM -0800, Sean Christopherson wrote: > Bury the declaration of the page-track helpers that are intended only for > internal KVM use in a "private" header. In addition to guarding against > unwanted usage of the internal-only helpers, dropping their definitions > avo

Re: [Intel-gfx] [PATCH v2 14/27] KVM: x86: Reject memslot MOVE operations if KVMGT is attached

2023-03-15 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:45PM -0800, Sean Christopherson wrote: > Disallow moving memslots if the VM has external page-track users, i.e. if > KVMGT is being used to expose a virtual GPU to the guest, as KVM doesn't > correctly handle moving memory regions. > > Note, this is potential ABI brea

Re: [Intel-gfx] [PATCH v2 11/27] KVM: x86/mmu: Don't rely on page-track mechanism to flush on memslot change

2023-03-14 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:42PM -0800, Sean Christopherson wrote: ... > -static void kvm_mmu_invalidate_zap_pages_in_memslot(struct kvm *kvm, > - struct kvm_memory_slot *slot, > - struct kvm_page_track_notifier_node *node) > -{ > - kvm_mmu_zap_all_fast

Re: [Intel-gfx] [PATCH v2 04/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-03-13 Thread Yan Zhao
ables are in a separated set of tables from EPT/NPT (which is the by default condition currently). [3] https://lore.kernel.org/all/y7%2ffzpizeyial...@yzhao56-desk.sh.intel.com/ So, I'm fine with exporting this kvm_page_track_max_mapping_level() interface, but I don't think KVMGT is a user

Re: [Intel-gfx] [PATCH v2 00/27] drm/i915/gvt: KVM: KVMGT fixes and page-track cleanups

2023-03-13 Thread Yan Zhao
On Fri, Mar 10, 2023 at 04:22:31PM -0800, Sean Christopherson wrote: > Fix a variety of found-by-inspection bugs in KVMGT, and overhaul KVM's > page-track APIs to provide a leaner and cleaner interface. The motivation > for this series is to (significantly) reduce the number of KVM APIs that > KVM

Re: [Intel-gfx] [PATCH v4 16/19] vfio: Add VFIO_DEVICE_BIND_IOMMUFD

2023-02-26 Thread Yan Zhao
On Fri, Feb 24, 2023 at 10:31:35AM -0400, Jason Gunthorpe wrote: > On Fri, Feb 24, 2023 at 12:58:22PM +0800, Yan Zhao wrote: > > On Wed, Feb 22, 2023 at 08:59:51AM -0400, Jason Gunthorpe wrote: > > > On Wed, Feb 22, 2023 at 07:44:12AM +, Liu, Yi L wrote: > >

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-02-23 Thread Yan Zhao
On Thu, Feb 23, 2023 at 12:41:28PM -0800, Sean Christopherson wrote: > Apologies for the super slow reply, I put this series on the backburner while > I > caught up on other stuff and completely missed your questions. > Never mind :) > On Thu, Jan 19, 2023, Yan Zhao wrote: >

Re: [Intel-gfx] [PATCH v4 16/19] vfio: Add VFIO_DEVICE_BIND_IOMMUFD

2023-02-23 Thread Yan Zhao
On Wed, Feb 22, 2023 at 08:59:51AM -0400, Jason Gunthorpe wrote: > On Wed, Feb 22, 2023 at 07:44:12AM +, Liu, Yi L wrote: > > > From: Tian, Kevin > > > Sent: Wednesday, February 22, 2023 3:40 PM > > > > > > > From: Liu, Yi L > > > > Sent: Tuesday, February 21, 2023 11:48 AM > > > > > > > > +

Re: [Intel-gfx] [PATCH v4 07/19] vfio: Block device access via device fd until device is opened

2023-02-22 Thread Yan Zhao
On Mon, Feb 20, 2023 at 07:48:00PM -0800, Yi Liu wrote: > Allow the vfio_device file to be in a state where the device FD is > opened but the device cannot be used by userspace (i.e. its .open_device() > hasn't been called). This inbetween state is not used when the device > FD is spawned from the

Re: [Intel-gfx] [PATCH v4 16/19] vfio: Add VFIO_DEVICE_BIND_IOMMUFD

2023-02-22 Thread Yan Zhao
On Mon, Feb 20, 2023 at 07:48:09PM -0800, Yi Liu wrote: > This adds ioctl for userspace to bind device cdev fd to iommufd. > > VFIO_DEVICE_BIND_IOMMUFD: bind device to an iommufd, hence gain DMA > control provided by the iommufd. open_device >

Re: [Intel-gfx] [PATCH v3 14/15] vfio: Add ioctls for device cdev using iommufd

2023-02-16 Thread Yan Zhao
On Thu, Feb 16, 2023 at 05:10:06PM +0800, Liu, Yi L wrote: > > From: Zhao, Yan Y > > Sent: Thursday, February 16, 2023 4:24 PM > > > > On Mon, Feb 13, 2023 at 07:13:47AM -0800, Yi Liu wrote: > > ... > > > > > +long vfio_device_ioctl_bind_iommufd(struct vfio_device_file *df, > > > +

Re: [Intel-gfx] [PATCH v3 14/15] vfio: Add ioctls for device cdev using iommufd

2023-02-16 Thread Yan Zhao
On Mon, Feb 13, 2023 at 07:13:47AM -0800, Yi Liu wrote: ... > +long vfio_device_ioctl_bind_iommufd(struct vfio_device_file *df, > + unsigned long arg) > +{ > + struct vfio_device *device = df->device; > + struct vfio_device_bind_iommufd bind; > + struct

Re: [Intel-gfx] [PATCH v3 14/15] vfio: Add ioctls for device cdev using iommufd

2023-02-14 Thread Yan Zhao
On Mon, Feb 13, 2023 at 07:13:47AM -0800, Yi Liu wrote: ... > +long vfio_device_ioctl_bind_iommufd(struct vfio_device_file *df, > + unsigned long arg) > +{ > + struct vfio_device *device = df->device; > + struct vfio_device_bind_iommufd bind; > + struct i

Re: [Intel-gfx] [PATCH v2 13/14] vfio: Add ioctls for device cdev using iommufd

2023-02-06 Thread Yan Zhao
On Mon, Feb 06, 2023 at 01:05:31AM -0800, Yi Liu wrote: ... > +void vfio_device_cdev_close(struct vfio_device_file *df) > +{ > + mutex_lock(&df->device->dev_set->lock); > + vfio_device_close(df); > + vfio_device_put_kvm(df->device); > + mutex_unlock(&df->device->dev_set->lock); > +

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-01-18 Thread Yan Zhao
On Thu, Jan 19, 2023 at 10:58:42AM +0800, Zhenyu Wang wrote: > On 2023.01.11 17:55:04 +, Sean Christopherson wrote: > > On Mon, Jan 09, 2023, Yan Zhao wrote: > > > On Fri, Jan 06, 2023 at 11:01:53PM +, Sean Christopherson wrote: > > > > On Fri, Jan 06, 2023

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-01-12 Thread Yan Zhao
> > > > Note, KVM may also restrict the mapping size for reasons that aren't > > > > relevant to KVMGT, e.g. for KVM's iTLB multi-hit workaround or if the > > > > gfn > > > Will iTLB multi-hit affect DMA? > > > > I highly doubt it, I can't imagine an IOMMU would have a dedicated > > instruction

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-01-09 Thread Yan Zhao
On Fri, Jan 06, 2023 at 11:01:53PM +, Sean Christopherson wrote: > On Fri, Jan 06, 2023, Yan Zhao wrote: > > On Thu, Jan 05, 2023 at 05:40:32PM +, Sean Christopherson wrote: > > > On Thu, Jan 05, 2023, Yan Zhao wrote: > > > I'm totally fine if KVMGT

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-01-05 Thread Yan Zhao
On Thu, Jan 05, 2023 at 05:40:32PM +, Sean Christopherson wrote: > On Thu, Jan 05, 2023, Yan Zhao wrote: > > On Tue, Jan 03, 2023 at 09:13:54PM +, Sean Christopherson wrote: > > > On Wed, Dec 28, 2022, Yan Zhao wrote: > > > > On Fri, Dec 23, 2022 at 12:57:1

Re: [Intel-gfx] [PATCH 00/27] drm/i915/gvt: KVM: KVMGT fixes and page-track cleanups

2023-01-04 Thread Yan Zhao
On Wed, Jan 04, 2023 at 01:01:13AM +, Sean Christopherson wrote: > On Fri, Dec 23, 2022, Yan Zhao wrote: > > On Fri, Dec 23, 2022 at 12:57:12AM +, Sean Christopherson wrote: > > > Fix a variety of found-by-inspection bugs in KVMGT, and overhaul KVM's > > &

Re: [Intel-gfx] [PATCH 26/27] KVM: x86/mmu: Add page-track API to query if a gfn is valid

2023-01-04 Thread Yan Zhao
On Tue, Jan 03, 2023 at 09:19:01PM +, Sean Christopherson wrote: > On Wed, Dec 28, 2022, Yan Zhao wrote: > > On Fri, Dec 23, 2022 at 12:57:38AM +, Sean Christopherson wrote: > > > +bool kvm_page_track_is_valid_gfn(struct kvm *kvm, gfn_t gfn) > > > +{ > &

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2023-01-04 Thread Yan Zhao
On Tue, Jan 03, 2023 at 09:13:54PM +, Sean Christopherson wrote: > On Wed, Dec 28, 2022, Yan Zhao wrote: > > On Fri, Dec 23, 2022 at 12:57:15AM +, Sean Christopherson wrote: > > > Honor KVM's max allowed page size when determining whether or not a 2MiB > > >

Re: [Intel-gfx] [PATCH 09/27] drm/i915/gvt: Protect gfn hash table with dedicated mutex

2023-01-04 Thread Yan Zhao
On Tue, Jan 03, 2023 at 08:43:17PM +, Sean Christopherson wrote: > On Wed, Dec 28, 2022, Yan Zhao wrote: > > On Fri, Dec 23, 2022 at 12:57:21AM +, Sean Christopherson wrote: > > > Add and use a new mutex, gfn_lock, to protect accesses to the hash table > > > u

Re: [Intel-gfx] [PATCH 26/27] KVM: x86/mmu: Add page-track API to query if a gfn is valid

2022-12-28 Thread Yan Zhao
On Fri, Dec 23, 2022 at 12:57:38AM +, Sean Christopherson wrote: > Add a page-track API to query if a gfn is "valid", i.e. is backed by a > memslot and is visible to the guest. This is one more step toward > removing KVM internal details from the page-track APIs. > > Add a FIXME to call out t

Re: [Intel-gfx] [PATCH 19/27] KVM: x86/mmu: Use page-track notifiers iff there are external users

2022-12-27 Thread Yan Zhao
On Fri, Dec 23, 2022 at 12:57:31AM +, Sean Christopherson wrote: > Disable the page-track notifier code at compile time if there are no > external users, i.e. if CONFIG_KVM_EXTERNAL_WRITE_TRACKING=n. KVM itself > now hooks emulated writes directly instead of relying on the page-track > mechani

Re: [Intel-gfx] [PATCH 03/27] drm/i915/gvt: Incorporate KVM memslot info into check for 2MiB GTT entry

2022-12-27 Thread Yan Zhao
On Fri, Dec 23, 2022 at 12:57:15AM +, Sean Christopherson wrote: > Honor KVM's max allowed page size when determining whether or not a 2MiB > GTT shadow page can be created for the guest. Querying KVM's max allowed > size is somewhat odd as there's no strict requirement that KVM's memslots > a

Re: [Intel-gfx] [PATCH 09/27] drm/i915/gvt: Protect gfn hash table with dedicated mutex

2022-12-27 Thread Yan Zhao
On Fri, Dec 23, 2022 at 12:57:21AM +, Sean Christopherson wrote: > Add and use a new mutex, gfn_lock, to protect accesses to the hash table > used to track which gfns are write-protected when shadowing the guest's > GTT. This fixes a bug where kvmgt_page_track_write(), which doesn't hold > kvm

Re: [Intel-gfx] [PATCH 00/27] drm/i915/gvt: KVM: KVMGT fixes and page-track cleanups

2022-12-23 Thread Yan Zhao
On Fri, Dec 23, 2022 at 12:57:12AM +, Sean Christopherson wrote: > Fix a variety of found-by-inspection bugs in KVMGT, and overhaul KVM's > page-track APIs to provide a leaner and cleaner interface. The motivation > for this series is to (significantly) reduce the number of KVM APIs that > KVM

Re: [Intel-gfx] [PATCH v2 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-14 Thread Yan Zhao
On Tue, Nov 15, 2022 at 12:55:42AM +, Sean Christopherson wrote: > On Tue, Nov 15, 2022, Yan Zhao wrote: > > On Mon, Nov 14, 2022 at 11:24:16PM +, Sean Christopherson wrote: > > > On Tue, Nov 15, 2022, Yan Zhao wrote: > > > > On Mon, Nov 14, 2022 at 04:32:3

Re: [Intel-gfx] [PATCH v2 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-14 Thread Yan Zhao
On Mon, Nov 14, 2022 at 11:24:16PM +, Sean Christopherson wrote: > On Tue, Nov 15, 2022, Yan Zhao wrote: > > On Mon, Nov 14, 2022 at 04:32:34PM +, Sean Christopherson wrote: > > > On Mon, Nov 14, 2022, Yan Zhao wrote: > > > > On Sat, Nov 12, 2022 at 12:43:0

Re: [Intel-gfx] [PATCH v2 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-14 Thread Yan Zhao
On Mon, Nov 14, 2022 at 04:32:34PM +, Sean Christopherson wrote: > On Mon, Nov 14, 2022, Yan Zhao wrote: > > On Sat, Nov 12, 2022 at 12:43:07AM +, Sean Christopherson wrote: > > > On Sat, Nov 12, 2022, Yan Zhao wrote: > > > > And I'm also not sure i

Re: [Intel-gfx] [PATCH v2 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-13 Thread Yan Zhao
On Sat, Nov 12, 2022 at 12:43:07AM +, Sean Christopherson wrote: > On Sat, Nov 12, 2022, Yan Zhao wrote: > > And I'm also not sure if a slots_arch_lock is required for > > kvm_slot_page_track_add_page() and kvm_slot_page_track_remove_page(). > > It's not requ

Re: [Intel-gfx] [PATCH v2 2/3] drm/i915/gvt: switch from track_flush_slot to track_remove_slot

2022-11-11 Thread Yan Zhao
On Fri, Nov 11, 2022 at 05:07:35PM +, Sean Christopherson wrote: > On Fri, Nov 11, 2022, Yan Zhao wrote: > > KVMGT only cares about when a slot is indeed removed. > > So switch to use track_remove_slot which is called when a slot is removed. > > This should capture th

Re: [Intel-gfx] [PATCH v2 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-11 Thread Yan Zhao
27;ll post patches next week if things go well (fingers crossed), and if not > I'll > give an update > > On Fri, Nov 11, 2022, Yan Zhao wrote: > > Page track hook track_remove_slot is used to notify users that a slot > > has been removed and is called when a slot DEL

[Intel-gfx] [PATCH v2 3/3] KVM: x86: Remove the unused page track hook track_flush_slot

2022-11-11 Thread Yan Zhao
There's no users of hook track_remove_slot any more and no external page tracker user cares about slot flush. So remove this hook. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao --- arch/x86/include/asm/kvm_page_track.h | 11 --- arch/x86/kv

[Intel-gfx] [PATCH v2 2/3] drm/i915/gvt: switch from track_flush_slot to track_remove_slot

2022-11-11 Thread Yan Zhao
KVMGT only cares about when a slot is indeed removed. So switch to use track_remove_slot which is called when a slot is removed. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao --- drivers/gpu/drm/i915/gvt/kvmgt.c | 6 +++--- 1 file changed, 3 insertions(+), 3

[Intel-gfx] [PATCH v2 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-11 Thread Yan Zhao
never been properly supported in the external page track user, we just use the hook track_remove_slot to notify users of the old slot being removed. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yan Zhao --- arch/x86/include/asm

[Intel-gfx] [PATCH v2 0/3] add track_remove_slot and remove track_flush_slot

2022-11-11 Thread Yan Zhao
GT to use the new hook .track_remove_slot. And as there are no users to .track_flush_slot any more, this hook is removed. v2: Corrected wrong email address of Sean. sorry. Yan Zhao (3): KVM: x86: add a new page track hook track_remove_slot drm/i915/gvt: switch from track_flush_sl

[Intel-gfx] [PATCH 3/3] KVM: x86: Remove the unused page track hook track_flush_slot

2022-11-11 Thread Yan Zhao
There's no users of hook track_remove_slot any more and no external page tracker user cares about slot flush. So remove this hook. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao --- arch/x86/include/asm/kvm_page_track.h | 11 --- arch/x86/kv

[Intel-gfx] [PATCH 2/3] drm/i915/gvt: switch from track_flush_slot to track_remove_slot

2022-11-11 Thread Yan Zhao
KVMGT only cares about when a slot is indeed removed. So switch to use track_remove_slot which is called when a slot is removed. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao --- drivers/gpu/drm/i915/gvt/kvmgt.c | 6 +++--- 1 file changed, 3 insertions(+), 3

[Intel-gfx] [PATCH 1/3] KVM: x86: add a new page track hook track_remove_slot

2022-11-11 Thread Yan Zhao
never been properly supported in the external page track user, we just use the hook track_remove_slot to notify users of the old slot being removed. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yan Zhao --- arch/x86/include/asm

[Intel-gfx] [PATCH 0/3] add track_remove_slot and remove track_flush_slot

2022-11-11 Thread Yan Zhao
GT to use the new hook .track_remove_slot. And as there are no users to .track_flush_slot any more, this hook is removed. Yan Zhao (3): KVM: x86: add a new page track hook track_remove_slot drm/i915/gvt: switch from track_flush_slot to track_remove_slot KVM: x86: Remove the unused page track

Re: [Intel-gfx] [PATCH] drm/i915/gt:fix raw-wakeref not held calltrace in vGPU

2020-08-11 Thread Yan Zhao
On Tue, Aug 11, 2020 at 09:26:11AM +0100, Chris Wilson wrote: > Quoting Yan Zhao (2020-08-11 04:02:09) > > UNCORE_HAS_FORCEWAKE is not turned on when intel_vgpu_active() returns > > true, so the guest mmio writes go to gen2_write32(). > > The vgpu writes are just memory trap

[Intel-gfx] [PATCH] drm/i915/gt:fix raw-wakeref not held calltrace in vGPU

2020-08-10 Thread Yan Zhao
7ffd2f2a3a00 ---[ end trace 110b629471bd16dd ]--- Signed-off-by: Yan Zhao --- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c index 699125928272..3fc3488c127f 100644 --- a/dri

Re: [Intel-gfx] [PATCH 2/6] i915/gvt/kvm: a NULL ->mm does not mean a thread is a kthread

2020-04-14 Thread Yan Zhao
On Tue, Apr 14, 2020 at 09:00:13AM +0200, Christoph Hellwig wrote: > On Mon, Apr 13, 2020 at 08:04:10PM -0400, Yan Zhao wrote: > > > I can't think of another way for a kernel thread to have a mm indeed. > > for example, before calling to vfio_dma_rw(), a kernel thread has al

Re: [Intel-gfx] [PATCH 2/6] i915/gvt/kvm: a NULL ->mm does not mean a thread is a kthread

2020-04-13 Thread Yan Zhao
On Mon, Apr 13, 2020 at 03:27:30PM +0200, Christoph Hellwig wrote: > On Mon, Apr 06, 2020 at 11:08:46PM -0400, Yan Zhao wrote: > > hi > > we were removing this code. see > > https://lore.kernel.org/kvm/20200313031109.7989-1-yan.y.z...@intel.com/ > > This didn

Re: [Intel-gfx] [PATCH 2/6] i915/gvt/kvm: a NULL ->mm does not mean a thread is a kthread

2020-04-06 Thread Yan Zhao
On Sat, Apr 04, 2020 at 11:40:57AM +0200, Christoph Hellwig wrote: > Use the proper API instead. > > Fixes: f440c8a572d7 ("drm/i915/gvt/kvmgt: read/write GPA via KVM API") > Signed-off-by: Christoph Hellwig > --- > drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +- > 1 file changed, 1 insertion(+), 1 dele