Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Fenghua Yu
Hi, Baolu, On Thu, Sep 23, 2021 at 01:43:32PM +0800, Lu Baolu wrote: > On 9/21/21 3:23 AM, Fenghua Yu wrote: > > +void pasid_put(struct task_struct *tsk, struct mm_struct *mm) > > +{ > > + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) > > + return; > > + > > + /* > > +* Nothing t

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Thomas Gleixner
On Wed, Sep 29 2021 at 11:31, Tony Luck wrote: > diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c > index a58800973aed..5a3c87fd65de 100644 > --- a/arch/x86/kernel/traps.c > +++ b/arch/x86/kernel/traps.c > @@ -528,6 +528,32 @@ static enum kernel_gp_hint get_kernel_gp_address(struct >

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Luck, Tony
On Wed, Sep 29, 2021 at 06:07:22PM +, Fenghua Yu wrote: > Add > +#ifdef CONFIG_IOMMU_SUPPORT > because mm->pasid and current-pasid_activated are defined only if > CONFIG_IOMMU_SUPPORT is defined. > > > + if (user_mode(regs) && current->mm->pasid && !current->pasid_activated) > > { > > Mayb

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Fenghua Yu
Hi, Tony, On Wed, Sep 29, 2021 at 10:41:42AM -0700, Luck, Tony wrote: > On Wed, Sep 29, 2021 at 07:15:53PM +0200, Thomas Gleixner wrote: > > On Wed, Sep 29 2021 at 09:59, Andy Lutomirski wrote: > > > On 9/29/21 05:28, Thomas Gleixner wrote: > > >> Looking at that patch again, none of this muck in

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Andy Lutomirski
On Wed, Sep 29, 2021, at 10:41 AM, Luck, Tony wrote: > On Wed, Sep 29, 2021 at 07:15:53PM +0200, Thomas Gleixner wrote: >> On Wed, Sep 29 2021 at 09:59, Andy Lutomirski wrote: >> > On 9/29/21 05:28, Thomas Gleixner wrote: >> >> Looking at that patch again, none of this muck in fpu__pasid_write()

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Luck, Tony
On Wed, Sep 29, 2021 at 07:15:53PM +0200, Thomas Gleixner wrote: > On Wed, Sep 29 2021 at 09:59, Andy Lutomirski wrote: > > On 9/29/21 05:28, Thomas Gleixner wrote: > >> Looking at that patch again, none of this muck in fpu__pasid_write() is > >> required at all. The whole exception fixup is: > >>

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Thomas Gleixner
On Wed, Sep 29 2021 at 09:59, Andy Lutomirski wrote: > On 9/29/21 05:28, Thomas Gleixner wrote: >> Looking at that patch again, none of this muck in fpu__pasid_write() is >> required at all. The whole exception fixup is: >> >> if (!user_mode(regs)) >> return false; >> >> i

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Fenghua Yu
Hi, Thomas, On Wed, Sep 29, 2021 at 09:51:15AM -0700, Luck, Tony wrote: > > There is zero requirement to look at TIF_NEED_FPU_LOAD or > > fpregs_state_valid() simply because the #GP comes straight from user > > space which means the FPU registers contain the current tasks user space > > state. >

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Andy Lutomirski
On 9/29/21 05:28, Thomas Gleixner wrote: On Wed, Sep 29 2021 at 11:54, Peter Zijlstra wrote: On Fri, Sep 24, 2021 at 04:03:53PM -0700, Andy Lutomirski wrote: I think the perfect and the good are a bit confused here. If we go for "good", then we have an mm owning a PASID for its entire lifetime.

RE: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Luck, Tony
> There is zero requirement to look at TIF_NEED_FPU_LOAD or > fpregs_state_valid() simply because the #GP comes straight from user > space which means the FPU registers contain the current tasks user space > state. Just to double confirm ... there is no point in the #GP handler up to this point wh

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Thomas Gleixner
On Wed, Sep 29 2021 at 11:54, Peter Zijlstra wrote: > On Fri, Sep 24, 2021 at 04:03:53PM -0700, Andy Lutomirski wrote: >> I think the perfect and the good are a bit confused here. If we go for >> "good", then we have an mm owning a PASID for its entire lifetime. If >> we want "perfect", then we sh

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-29 Thread Peter Zijlstra
On Fri, Sep 24, 2021 at 04:03:53PM -0700, Andy Lutomirski wrote: > I think the perfect and the good are a bit confused here. If we go for > "good", then we have an mm owning a PASID for its entire lifetime. If > we want "perfect", then we should actually do it right: teach the > kernel to update a

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-28 Thread Fenghua Yu
Hi, Thomas, On Sun, Sep 26, 2021 at 01:13:50AM +0200, Thomas Gleixner wrote: > Fenghua, > > On Fri, Sep 24 2021 at 16:12, Fenghua Yu wrote: > > On Fri, Sep 24, 2021 at 03:18:12PM +0200, Thomas Gleixner wrote: > >> But OTOH why do you need a per task reference count on the PASID at all? > >> > >>

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-25 Thread Thomas Gleixner
Fenghua, On Fri, Sep 24 2021 at 16:12, Fenghua Yu wrote: > On Fri, Sep 24, 2021 at 03:18:12PM +0200, Thomas Gleixner wrote: >> But OTOH why do you need a per task reference count on the PASID at all? >> >> The PASID is fundamentaly tied to the mm and the mm can't go away before >> the threads hav

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-24 Thread Luck, Tony
On Fri, Sep 24, 2021 at 04:03:53PM -0700, Andy Lutomirski wrote: > 1. The context switch code needs to resync PASID. Unfortunately, this adds > some overhead to every context switch, although a static_branch could > minimize it for non-PASID users. Any solution that adds to context switch time

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-24 Thread Andy Lutomirski
On Fri, Sep 24, 2021, at 9:12 AM, Luck, Tony wrote: > On Fri, Sep 24, 2021 at 03:18:12PM +0200, Thomas Gleixner wrote: >> On Thu, Sep 23 2021 at 19:48, Thomas Gleixner wrote: >> > On Thu, Sep 23 2021 at 09:40, Tony Luck wrote: >> > >> > fpu_write_task_pasid() can just grab the pasid from current

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-24 Thread Fenghua Yu
Hi, Thomas, On Fri, Sep 24, 2021 at 03:18:12PM +0200, Thomas Gleixner wrote: > On Thu, Sep 23 2021 at 19:48, Thomas Gleixner wrote: > > On Thu, Sep 23 2021 at 09:40, Tony Luck wrote: > > > > fpu_write_task_pasid() can just grab the pasid from current->mm->pasid > > and be done with it. > > > > The

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-24 Thread Luck, Tony
On Fri, Sep 24, 2021 at 03:18:12PM +0200, Thomas Gleixner wrote: > On Thu, Sep 23 2021 at 19:48, Thomas Gleixner wrote: > > On Thu, Sep 23 2021 at 09:40, Tony Luck wrote: > > > > fpu_write_task_pasid() can just grab the pasid from current->mm->pasid > > and be done with it. > > > > The task exit co

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-24 Thread Thomas Gleixner
On Thu, Sep 23 2021 at 19:48, Thomas Gleixner wrote: > On Thu, Sep 23 2021 at 09:40, Tony Luck wrote: > > fpu_write_task_pasid() can just grab the pasid from current->mm->pasid > and be done with it. > > The task exit code can just call iommu_pasid_put_task_ref() from the > generic code and not fro

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-23 Thread Andy Lutomirski
On Thu, Sep 23, 2021, at 4:22 PM, Luck, Tony wrote: > On Thu, Sep 23, 2021 at 04:09:18PM -0700, Andy Lutomirski wrote: >> On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > >> I think this is unnecessarily complicated because it's buying in to the >> existing ISA misconception that PASID has

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-23 Thread Luck, Tony
On Thu, Sep 23, 2021 at 04:09:18PM -0700, Andy Lutomirski wrote: > On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > I think this is unnecessarily complicated because it's buying in to the > existing ISA misconception that PASID has anything to do with a task. > A PASID belongs to an mm, full

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-23 Thread Andy Lutomirski
On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > PASIDs are fundamentally hardware resources in a shared address space. > There is a limited number of them to use ENQCMD on shared workqueue. > They must be shared and managed. They can not, for instance, be > statically allocated to processes.

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-23 Thread Thomas Gleixner
On Thu, Sep 23 2021 at 09:40, Tony Luck wrote: > On Thu, Sep 23, 2021 at 04:36:50PM +0200, Thomas Gleixner wrote: >> This code is again defining that PASID is entirely restricted to >> INTEL. It's true, that no other vendor supports this, but PASID is >> a non-vendor specific concept. >> >> Sticki

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-23 Thread Luck, Tony
On Thu, Sep 23, 2021 at 04:36:50PM +0200, Thomas Gleixner wrote: > On Mon, Sep 20 2021 at 19:23, Fenghua Yu wrote: > > > > +#ifdef CONFIG_INTEL_IOMMU_SVM > > +void pasid_put(struct task_struct *tsk, struct mm_struct *mm); > > +#else > > +static inline void pasid_put(struct task_struct *tsk, struc

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-23 Thread Thomas Gleixner
On Mon, Sep 20 2021 at 19:23, Fenghua Yu wrote: > > +#ifdef CONFIG_INTEL_IOMMU_SVM > +void pasid_put(struct task_struct *tsk, struct mm_struct *mm); > +#else > +static inline void pasid_put(struct task_struct *tsk, struct mm_struct *mm) > { } > +#endif This code is again defining that PASID is

Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-22 Thread Lu Baolu
Hi Fenghua, On 9/21/21 3:23 AM, Fenghua Yu wrote: PASIDs are fundamentally hardware resources in a shared address space. There is a limited number of them to use ENQCMD on shared workqueue. They must be shared and managed. They can not, for instance, be statically allocated to processes. Free P

[PATCH 5/8] x86/mmu: Add mm-based PASID refcounting

2021-09-20 Thread Fenghua Yu
PASIDs are fundamentally hardware resources in a shared address space. There is a limited number of them to use ENQCMD on shared workqueue. They must be shared and managed. They can not, for instance, be statically allocated to processes. Free PASID eagerly by sending IPIs in unbind was disabled d