Re: iommu_sva_bind_device question

2022-06-25 Thread Fenghua Yu
Hi, Jerry and Baolu, On Fri, Jun 24, 2022 at 07:47:30AM -0700, Jerry Snitselaar wrote: > > > > > > Hi Baolu & Dave, > > > > fails. > > > > > > > > You also will get the following warning if you don't have scalable > > > > mode enabled (either not enabled by default, or if enabled by default > >

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-29 Thread Fenghua Yu
Hi, Jean and Baolu, On Fri, Apr 29, 2022 at 03:34:36PM +0100, Jean-Philippe Brucker wrote: > On Fri, Apr 29, 2022 at 06:51:17AM -0700, Fenghua Yu wrote: > > Hi, Baolu, > > > > On Fri, Apr 29, 2022 at 03:53:57PM +0800, Baolu Lu wrote: > > > On 2022/4/28 16:3

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-29 Thread Fenghua Yu
Hi, Baolu, On Fri, Apr 29, 2022 at 03:53:57PM +0800, Baolu Lu wrote: > On 2022/4/28 16:39, Jean-Philippe Brucker wrote: > > > The address space is what the OOM killer is after. That gets refcounted > > > with mmget()/mmput()/mm->mm_users. The OOM killer is satiated by the > > > page freeing

[PATCH v2] iommu/sva: Fix PASID use-after-free issue

2022-04-28 Thread Fenghua Yu
eviewed-by: Jean-Philippe Brucker Signed-off-by: Fenghua Yu --- v2: - Dave Hansen rewrites the change log. - Add Tested-by: Zhangfei Gao - Add Reviewed-by: Jean-Philippe Brucker The original patch was posted and discussed in: https://lore.kernel.org/lkml/ymdzffx7fn586...@fyu1.sc.intel.com/ k

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-28 Thread Fenghua Yu
Hi, Dave, On Thu, Apr 28, 2022 at 08:09:04AM -0700, Dave Hansen wrote: > On 4/25/22 21:20, Fenghua Yu wrote: > >>From 84aa68f6174439d863c40cdc2db0e1b89d620dd0 Mon Sep 17 00:00:00 2001 > > From: Fenghua Yu > > Date: Fri, 15 Apr 2022 00:51:33 -0700 > > Subject: [P

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-27 Thread Fenghua Yu
Hi, Dave and Jean, On Tue, Apr 26, 2022 at 01:04:45PM +0800, Zhangfei Gao wrote: > > > On 2022/4/26 下午12:20, Fenghua Yu wrote: > > Hi, Jean and Zhangfei, > > > > On Mon, Apr 25, 2022 at 05:13:02PM +0100, Jean-Philippe Brucker wrote: > > > Could we move m

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-25 Thread Fenghua Yu
On Tue, Apr 26, 2022 at 12:28:00PM +0800, Zhangfei Gao wrote: > Hi, Jean > > On 2022/4/26 上午12:13, Jean-Philippe Brucker wrote: > > Hi Jacob, > > > > On Mon, Apr 25, 2022 at 08:34:44AM -0700, Jacob Pan wrote: > > > Hi Jean-Philippe, > > > > > > On Mon, 25 Apr 2022 15:26:40 +0100, Jean-Philippe

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-25 Thread Fenghua Yu
s a right fix for the issue? Could you please test it on ARM? I don't have an ARM machine. Thanks. -Fenghua >From 84aa68f6174439d863c40cdc2db0e1b89d620dd0 Mon Sep 17 00:00:00 2001 From: Fenghua Yu Date: Fri, 15 Apr 2022 00:51:33 -0700 Subject: [PATCH] iommu/sva: Fix PASID use-after-free issue A

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-15 Thread Fenghua Yu
Hi, Zhangfei, On Fri, Apr 15, 2022 at 07:52:03PM +0800, zhangfei@foxmail.com wrote: > > On my X86 machine, nginx doesn't trigger the kernel sva binding function > > to allocate ioasid. I tried pre- nstalled nginx/openssl and also tried my > > built > > a few versions of nginx/openssl. nginx

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-15 Thread Fenghua Yu
Hi, Zhangfei, On Fri, Apr 15, 2022 at 07:52:03PM +0800, zhangfei@foxmail.com wrote: > > > On 2022/4/15 下午6:50, Fenghua Yu wrote: > > Hi, Zhangfei, > > > > On Fri, Apr 15, 2022 at 06:14:09PM +0800, zhangfei@foxmail.com wrote: > > I download this patch

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-15 Thread Fenghua Yu
Hi, Zhangfei, On Fri, Apr 15, 2022 at 06:14:09PM +0800, zhangfei@foxmail.com wrote: > > > On 2022/4/15 下午5:51, Fenghua Yu wrote: > > On Thu, Apr 14, 2022 at 06:08:09PM +0800, zhangfei@foxmail.com wrote: > > > On 2022/4/12 下午11:35, zhangfei@foxmail.com wr

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-15 Thread Fenghua Yu
Hi, Dave, On Tue, Apr 12, 2022 at 07:39:10AM -0700, Dave Hansen wrote: > On 4/12/22 06:41, Fenghua Yu wrote: > >> master process quit, mmput ->  mm_pasid_drop->ioasid_free > >> But this ignore driver's iommu_sva_unbind_device function, > >> iommu_sva_bin

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-15 Thread Fenghua Yu
On Thu, Apr 14, 2022 at 06:08:09PM +0800, zhangfei@foxmail.com wrote: > > On 2022/4/12 下午11:35, zhangfei@foxmail.com wrote: > > Hi, Fenghua > > > > On 2022/4/12 下午9:41, Fenghua Yu wrote: > > > Hi, Zhangfei, > > > > > > On Tue, Apr 12,

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-04-12 Thread Fenghua Yu
Hi, Zhangfei, On Tue, Apr 12, 2022 at 03:04:09PM +0800, zhangfei@foxmail.com wrote: > > > On 2022/4/11 下午10:52, Dave Hansen wrote: > > On 4/11/22 07:44, zhangfei@foxmail.com wrote: > > > On 2022/4/11 下午10:36, Dave Hansen wrote: > > > > On 4/11/22 07:20, zhangfei@foxmail.com wrote: >

Re: [PATCH v4 00/11] Re-enable ENQCMD and PASID MSR

2022-02-11 Thread Fenghua Yu
Hi, Thomas, On Mon, Feb 07, 2022 at 03:02:43PM -0800, Fenghua Yu wrote: > Problems in the old code to manage SVM (Shared Virtual Memory) devices > and the PASID (Process Address Space ID) led to that code being > disabled. > > Subsequent discussions resulted in a far simpler a

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-10 Thread Fenghua Yu
Hi, Tony, On Thu, Feb 10, 2022 at 10:31:42AM -0800, Fenghua Yu wrote: > > On Thu, Feb 10, 2022 at 09:24:50AM -0800, Luck, Tony wrote: > > On Thu, Feb 10, 2022 at 08:27:50AM -0800, Fenghua Yu wrote: > > > Hi, Jacob, > > > > > > On Wed, Feb 09, 20

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-10 Thread Fenghua Yu
On Thu, Feb 10, 2022 at 10:49:04AM -0800, Jacob Pan wrote: > > On Wed, 9 Feb 2022 19:16:14 -0800, Jacob Pan > wrote: > > > Hi Fenghua, > > > > On Mon, 7 Feb 2022 15:02:48 -0800, Fenghua Yu > > wrote: > > > > > @@ -1047,8 +1040,6 @@ struct

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-10 Thread Fenghua Yu
Hi, Tony, On Thu, Feb 10, 2022 at 09:24:50AM -0800, Luck, Tony wrote: > On Thu, Feb 10, 2022 at 08:27:50AM -0800, Fenghua Yu wrote: > > Hi, Jacob, > > > > On Wed, Feb 09, 2022 at 07:16:14PM -0800, Jacob Pan wrote: > > > Hi Fenghua, > > > > > >

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-10 Thread Fenghua Yu
Hi, Jacob, On Wed, Feb 09, 2022 at 07:16:14PM -0800, Jacob Pan wrote: > Hi Fenghua, > > On Mon, 7 Feb 2022 15:02:48 -0800, Fenghua Yu wrote: > > > @@ -1047,8 +1040,6 @@ struct iommu_sva *intel_svm_bind(struct device > > *dev, struct mm_struct *mm, void } > > &

Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-08 Thread Fenghua Yu
On Tue, Feb 08, 2022 at 10:41:39AM +0800, Lu Baolu wrote: > On 2/8/22 7:02 AM, Fenghua Yu wrote: > > PASIDs are process wide. It was attempted to use refcounted PASIDs to > > free them when the last thread drops the refcount. This turned out to > > be complex and error

[PATCH v4 08/11] x86/traps: Demand-populate PASID MSR via #GP

2022-02-07 Thread Fenghua Yu
_PASID MSR. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Reviewed-by: Thomas Gleixner --- v4: - Add "Reviewed-by: Thomas Gleixner " (Thomas). v2: - Directly write IA32_PASID MSR in fixup while local IRQ is still disabled (Thomas) - Move #ifdef over to CONFIG_IOMMU_SVA since it

[PATCH v4 07/11] sched: Define and initialize a flag to identify valid PASID in the task

2022-02-07 Thread Fenghua Yu
From: Peter Zijlstra Add a new single bit field to the task structure to track whether this task has initialized the IA32_PASID MSR to the mm's PASID. Initialize the field to zero when creating a new task with fork/clone. Signed-off-by: Peter Zijlstra Co-developed-by: Fenghua Yu Signed-off

[PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-07 Thread Fenghua Yu
and replace/rename the interfaces to reflect this new approach. Suggested-by: Dave Hansen Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v4: - Update the commit message (Thomas). v3: - Rename mm_pasid_get() to mm_pasid_set() (Thomas). - Remove ioasid_get() because it's not used any more when

[PATCH v4 01/11] iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA

2022-02-07 Thread Fenghua Yu
This CONFIG option originally only referred to the Shared Virtual Address (SVA) library. But it is now also used for non-library portions of code. Drop the "_LIB" suffix so that there is just one configuration options for all code relating to SVA. Signed-off-by: Fenghua Yu Reviewe

[PATCH v4 10/11] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2022-02-07 Thread Fenghua Yu
accelerators must always use the ENQCMDS instruction which does not access the PASID_MSR. Check for use of the ENQCMD instruction in the kernel and warn on its usage. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Acked-by: Josh Poimboeuf --- v3: - Add Acked-by: Josh Poimboeuf v2: - Simplify handling

[PATCH v4 00/11] Re-enable ENQCMD and PASID MSR

2022-02-07 Thread Fenghua Yu
nghua...@intel.com/T/#md6d542091da1d1159eda0a44a16e57d0c0dfb209 Fenghua Yu (10): iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA mm: Change CONFIG option for mm->pasid field iommu/ioasid: Introduce a helper to check for valid PASIDs kernel/fork: Initialize mm's PASID iommu/sva: Assign a PASID to mm on PA

[PATCH v4 06/11] x86/fpu: Clear PASID when copying fpstate

2022-02-07 Thread Fenghua Yu
ave PASID support. It is virtually zero overhead because 'dst_fpu' was just written and the whole thing is cache hot. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Reviewed-by: Thomas Gleixner --- v4: - Add "Reviewed-by: Thomas Gleixner " (Thomas). v2: - Rewrite changelog (Dave Ha

[PATCH v4 11/11] docs: x86: Change documentation for SVA (Shared Virtual Addressing)

2022-02-07 Thread Fenghua Yu
Since allocating, freeing and fixing up PASID are changed, the documentation is updated to reflect the changes. Originally-by: Ashok Raj Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v3: - Remove PASID refcount description (Thomas). v2: - Update life cycle info (Tony and Thomas

[PATCH v4 09/11] x86/cpufeatures: Re-enable ENQCMD

2022-02-07 Thread Fenghua Yu
Since ENQCMD is handled by #GP fix up, it can be re-enabled. The ENQCMD feature can only be used if CONFIG_INTEL_IOMMU_SVM is set. Add X86_FEATURE_ENQCMD to the disabled features mask as appropriate so that cpu_feature_enabled() can be used to check the feature. Signed-off-by: Fenghua Yu

[PATCH v4 03/11] iommu/ioasid: Introduce a helper to check for valid PASIDs

2022-02-07 Thread Fenghua Yu
pasid_valid() is defined to check if a given PASID is valid. Suggested-by: Ashok Raj Suggested-by: Jacob Pan Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Reviewed-by: Thomas Gleixner --- v4: - Add "Reviewed-by: Thomas Gleixner " (Thomas). v2: - Define a helper pasid_vali

[PATCH v4 04/11] kernel/fork: Initialize mm's PASID

2022-02-07 Thread Fenghua Yu
) to keep these all together. Suggested-by: Dave Hansen Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v4: - Update the commit message to explain why init pasid to -1 and why define mm_pasid_init() (Thomas) v2: - Change condition to more accurate CONFIG_IOMMU_SVA (Jacob) include/linux

[PATCH v4 02/11] mm: Change CONFIG option for mm->pasid field

2022-02-07 Thread Fenghua Yu
This currently depends on CONFIG_IOMMU_SUPPORT. But it is only needed when CONFIG_IOMMU_SVA option is enabled. Change the CONFIG guards around definition and initialization of mm->pasid field. Suggested-by: Jacob Pan Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Reviewed-by: Tho

Re: [PATCH v3 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-04 Thread Fenghua Yu
Hi, Baolu, On Sat, Feb 05, 2022 at 11:50:59AM +0800, Lu Baolu wrote: > Hi Fenghua, > > On 2022/1/29 4:28, Fenghua Yu wrote: > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > > index 92fea3fbbb11..ef03b2176bbd 100644 > > --- a/drivers/io

Re: [PATCH v3 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-02-04 Thread Fenghua Yu
On Sat, Feb 05, 2022 at 12:56:00AM +0100, Thomas Gleixner wrote: > On Fri, Jan 28 2022 at 12:28, Fenghua Yu wrote: > > To avoid complexity of updating each thread's PASID status (e.g. sending > > IPI to update IA32_PASID MSR) on allocating and freeing PASID, once > > a

Re: [PATCH v3 04/11] kernel/fork: Initialize mm's PASID

2022-02-04 Thread Fenghua Yu
Hi, Thomas, On Sat, Feb 05, 2022 at 12:22:12AM +0100, Thomas Gleixner wrote: > On Fri, Jan 28 2022 at 12:28, Fenghua Yu wrote: > > A new mm doesn't have a PASID yet when it's created. Initialize > > the mm's PASID on fork() or for init_mm to INVALID_IOASID (-1). > > I must

[PATCH v3 10/11] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2022-01-28 Thread Fenghua Yu
accelerators must always use the ENQCMDS instruction which does not access the PASID_MSR. Check for use of the ENQCMD instruction in the kernel and warn on its usage. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Acked-by: Josh Poimboeuf --- v3: - Add Acked-by: Josh Poimboeuf v2: - Simplify handling

[PATCH v3 03/11] iommu/ioasid: Introduce a helper to check for valid PASIDs

2022-01-28 Thread Fenghua Yu
pasid_valid() is defined to check if a given PASID is valid. Suggested-by: Ashok Raj Suggested-by: Jacob Pan Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Define a helper pasid_valid() (Ashok, Jacob, Thomas, Tony) include/linux/ioasid.h | 9 + 1 file changed, 9

[PATCH v3 11/11] docs: x86: Change documentation for SVA (Shared Virtual Addressing)

2022-01-28 Thread Fenghua Yu
Since allocating, freeing and fixing up PASID are changed, the documentation is updated to reflect the changes. Originally-by: Ashok Raj Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v3: - Remove PASID refcount description (Thomas). v2: - Update life cycle info (Tony and Thomas

[PATCH v3 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-01-28 Thread Fenghua Yu
creation, the limited number of PASIDs is not a realistic issue for lazy PASID free. Suggested-by: Dave Hansen Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v3: - Rename mm_pasid_get() to mm_pasid_set() (Thomas). - Remove ioasid_get() because it's not used any more when the IOASID

[PATCH v3 08/11] x86/traps: Demand-populate PASID MSR via #GP

2022-01-28 Thread Fenghua Yu
_PASID MSR. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Directly write IA32_PASID MSR in fixup while local IRQ is still disabled (Thomas) - Move #ifdef over to CONFIG_IOMMU_SVA since it is what defines mm->pasid and ->pasid_activated (Dave Hansen). - Rename

[PATCH v3 01/11] iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA

2022-01-28 Thread Fenghua Yu
This CONFIG option originally only referred to the Shared Virtual Address (SVA) library. But it is now also used for non-library portions of code. Drop the "_LIB" suffix so that there is just one configuration options for all code relating to SVA. Signed-off-by: Fenghua Yu Reviewe

[PATCH v3 07/11] sched: Define and initialize a flag to identify valid PASID in the task

2022-01-28 Thread Fenghua Yu
From: Peter Zijlstra Add a new single bit field to the task structure to track whether this task has initialized the IA32_PASID MSR to the mm's PASID. Initialize the field to zero when creating a new task with fork/clone. Signed-off-by: Peter Zijlstra Co-developed-by: Fenghua Yu Signed-off

[PATCH v3 09/11] x86/cpufeatures: Re-enable ENQCMD

2022-01-28 Thread Fenghua Yu
Since ENQCMD is handled by #GP fix up, it can be re-enabled. The ENQCMD feature can only be used if CONFIG_INTEL_IOMMU_SVM is set. Add X86_FEATURE_ENQCMD to the disabled features mask as appropriate so that cpu_feature_enabled() can be used to check the feature. Signed-off-by: Fenghua Yu

[PATCH v3 04/11] kernel/fork: Initialize mm's PASID

2022-01-28 Thread Fenghua Yu
A new mm doesn't have a PASID yet when it's created. Initialize the mm's PASID on fork() or for init_mm to INVALID_IOASID (-1). Suggested-by: Dave Hansen Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Change condition to more accurate CONFIG_IOMMU_SVA (Jacob) include/linux/sched

[PATCH v3 06/11] x86/fpu: Clear PASID when copying fpstate

2022-01-28 Thread Fenghua Yu
ave PASID support. It is virtually zero overhead because 'dst_fpu' was just written and the whole thing is cache hot. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Rewrite changelog (Dave Hansen). - Move xfeature tweaking into fpu_clone() and make it unconditional if XSAVE is suppor

[PATCH v3 00/11] Re-enable ENQCMD and PASID MSR

2022-01-28 Thread Fenghua Yu
now (commit: 00ecd5401349 "iommu/vt-d: Clean up unused PASID updating functions") and therefore it's removed from this version. v1 can be found at https://lore.kernel.org/lkml/20210920192349.2602141-1-fenghua...@intel.com/T/#md6d542091da1d1159eda0a44a16e57d0c0dfb209 Fenghua Yu (10):

[PATCH v3 02/11] mm: Change CONFIG option for mm->pasid field

2022-01-28 Thread Fenghua Yu
This currently depends on CONFIG_IOMMU_SUPPORT. But it is only needed when CONFIG_IOMMU_SVA option is enabled. Change the CONFIG guards around definition and initialization of mm->pasid field. Suggested-by: Jacob Pan Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Change condit

Re: [PATCH v2 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-01-27 Thread Fenghua Yu
Hi, Thomas, On Wed, Jan 26, 2022 at 10:38:04PM +0100, Thomas Gleixner wrote: > On Wed, Jan 26 2022 at 09:36, Fenghua Yu wrote: > > On Wed, Jan 26, 2022 at 03:23:42PM +0100, Thomas Gleixner wrote: > >> On Tue, Jan 25 2022 at 07:18, Fenghua Yu wrote: > >> While look

Re: [PATCH v2 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-01-26 Thread Fenghua Yu
Hi, Thomas, On Wed, Jan 26, 2022 at 03:23:42PM +0100, Thomas Gleixner wrote: > On Tue, Jan 25 2022 at 07:18, Fenghua Yu wrote: > > On Mon, Jan 24, 2022 at 09:55:56PM +0100, Thomas Gleixner wrote: > > /** > > * ioasid_put - Release a reference to an ioasid > >

Re: [PATCH v2 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-01-25 Thread Fenghua Yu
Hi, Thomas, On Mon, Jan 24, 2022 at 09:55:56PM +0100, Thomas Gleixner wrote: > On Mon, Jan 24 2022 at 12:52, Fenghua Yu wrote: > > On Mon, Jan 24, 2022 at 09:36:00PM +0100, Thomas Gleixner wrote: > >> On Mon, Jan 24 2022 at 21:21, Thomas Gleixner wrote: > > Ah. This patch

Re: [PATCH v2 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-01-24 Thread Fenghua Yu
Hi, Thomas, On Mon, Jan 24, 2022 at 09:36:00PM +0100, Thomas Gleixner wrote: > On Mon, Jan 24 2022 at 21:21, Thomas Gleixner wrote: > > > > Hrm. This is odd. > > > >> +/* Associate a PASID with an mm_struct: */ > >> +static inline void mm_pasid_get(struct mm_struct *mm, u32 pasid) > >> +{ > >> +

Re: [PATCH v2 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2022-01-24 Thread Fenghua Yu
Hi, Thomas, On Mon, Jan 24, 2022 at 09:21:24PM +0100, Thomas Gleixner wrote: > On Fri, Dec 17 2021 at 22:01, Fenghua Yu wrote: > > diff --git a/drivers/iommu/iommu-sva-lib.c b/drivers/iommu/iommu-sva-lib.c > > index bd41405d34e9..ee2294e02716 100644 > > --- a/drivers/

Re: [PATCH v2 00/11] Re-enable ENQCMD and PASID MSR

2021-12-27 Thread Fenghua Yu
Hi, Dear Maintainers, On Fri, Dec 17, 2021 at 10:01:25PM +, Fenghua Yu wrote: > Problems in the old code to manage SVM (Shared Virtual Memory) devices > and the PASID (Process Address Space ID) led to that code being > disabled. > > Subsequent discussions resulted in a far s

Re: [PATCH v2 10/11] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2021-12-27 Thread Fenghua Yu
Hi, Josh, On Fri, Dec 17, 2021 at 02:57:06PM -0800, Josh Poimboeuf wrote: > On Fri, Dec 17, 2021 at 10:01:35PM +0000, Fenghua Yu wrote: > > The ENQCMD implicitly accesses the PASID_MSR to fill in the pasid field > > of the descriptor being submitted to an accelerator. But there is

[PATCH v2 01/11] iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA

2021-12-17 Thread Fenghua Yu
This CONFIG option originally only referred to the Shared Virtual Address (SVA) library. But it is now also used for non-library portions of code. Drop the "_LIB" suffix so that there is just one configuration options for all code relating to SVA. Signed-off-by: Fenghua Yu Reviewe

[PATCH v2 08/11] x86/traps: Demand-populate PASID MSR via #GP

2021-12-17 Thread Fenghua Yu
_PASID MSR. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Directly write IA32_PASID MSR in fixup while local IRQ is still disabled (Thomas) - Move #ifdef over to CONFIG_IOMMU_SVA since it is what defines mm->pasid and ->pasid_activated (Dave Hansen). - Rename

[PATCH v2 09/11] x86/cpufeatures: Re-enable ENQCMD

2021-12-17 Thread Fenghua Yu
Since ENQCMD is handled by #GP fix up, it can be re-enabled. The ENQCMD feature can only be used if CONFIG_INTEL_IOMMU_SVM is set. Add X86_FEATURE_ENQCMD to the disabled features mask as appropriate so that cpu_feature_enabled() can be used to check the feature. Signed-off-by: Fenghua Yu

[PATCH v2 10/11] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2021-12-17 Thread Fenghua Yu
accelerators must always use the ENQCMDS instruction which does not access the PASID_MSR. Check for use of the ENQCMD instruction in the kernel and warn on its usage. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Simplify handling ENQCMD (PeterZ and Josh) tools/objtool/arch/x86/decode.c

[PATCH v2 07/11] sched: Define and initialize a flag to identify valid PASID in the task

2021-12-17 Thread Fenghua Yu
From: Peter Zijlstra Add a new single bit field to the task structure to track whether this task has initialized the IA32_PASID MSR to the mm's PASID. Initialize the field to zero when creating a new task with fork/clone. Signed-off-by: Peter Zijlstra Co-developed-by: Fenghua Yu Signed-off

[PATCH v2 03/11] iommu/ioasid: Introduce a helper to check for valid PASIDs

2021-12-17 Thread Fenghua Yu
pasid_valid() is defined to check if a given PASID is valid. Suggested-by: Ashok Raj Suggested-by: Jacob Pan Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Define a helper pasid_valid() (Ashok, Jacob, Thomas, Tony) include/linux/ioasid.h | 9 + 1 file changed, 9

[PATCH v2 06/11] x86/fpu: Clear PASID when copying fpstate

2021-12-17 Thread Fenghua Yu
ave PASID support. It is virtually zero overhead because 'dst_fpu' was just written and the whole thing is cache hot. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Rewrite changelog (Dave Hansen). - Move xfeature tweaking into fpu_clone() and make it unconditional if XSAVE is suppor

[PATCH v2 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit

2021-12-17 Thread Fenghua Yu
allows up to 1M processes bound to PASIDs at the same time. With cgroups and other controls that might limit the number of process creation, the limited number of PASIDs is not a realistic issue for lazy PASID free. Suggested-by: Dave Hansen Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2

[PATCH v2 11/11] docs: x86: Change documentation for SVA (Shared Virtual Addressing)

2021-12-17 Thread Fenghua Yu
Since allocating, freeing and fixing up PASID are changed, the documentation is updated to reflect the changes. Originally-by: Ashok Raj Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Update life cycle info (Tony and Thomas). - Update initial PASID value to INVALID_IOASID on fork

[PATCH v2 04/11] kernel/fork: Initialize mm's PASID

2021-12-17 Thread Fenghua Yu
A new mm doesn't have a PASID yet when it's created. Initialize the mm's PASID on fork() or for init_mm to INVALID_IOASID (-1). Suggested-by: Dave Hansen Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Change condition to more accurate CONFIG_IOMMU_SVA (Jacob) include/linux/sched

[PATCH v2 00/11] Re-enable ENQCMD and PASID MSR

2021-12-17 Thread Fenghua Yu
n be found at https://lore.kernel.org/lkml/20210920192349.2602141-1-fenghua...@intel.com/T/#md6d542091da1d1159eda0a44a16e57d0c0dfb209 Fenghua Yu (10): iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA mm: Change CONFIG option for mm->pasid field iommu/ioasid: Introduce a helper to ch

[PATCH v2 02/11] mm: Change CONFIG option for mm->pasid field

2021-12-17 Thread Fenghua Yu
This currently depends on CONFIG_IOMMU_SUPPORT. But it is only needed when CONFIG_IOMMU_SVA option is enabled. Change the CONFIG guards around definition and initialization of mm->pasid field. Suggested-by: Jacob Pan Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Change condit

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; > >

Re: [PATCH 1/8] iommu/vt-d: Clean up unused PASID updating functions

2021-09-29 Thread Fenghua Yu
Hi, Baolu, On Wed, Sep 29, 2021 at 03:34:51PM +0800, Lu Baolu wrote: > On 2021/9/21 3:23, Fenghua Yu wrote: > > update_pasid() and its call chain are currently unused in the tree because > > Thomas disabled the ENQCMD feature. The feature will be re-enabled shortly > > using

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 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 4/8] x86/traps: Demand-populate PASID MSR via #GP

2021-09-28 Thread Fenghua Yu
Hi, Tony, On Tue, Sep 28, 2021 at 06:06:52PM -0700, Luck, Tony wrote: > >>fpregs_lock(); > > > > I'm afraid we may hit the same locking issue when we send IPI to notify > > another task to modify its > > PASID state. Here the API is called to modify another running task's PASID > > state as

Re: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP

2021-09-28 Thread Fenghua Yu
Hi, Tony, On Tue, Sep 28, 2021 at 04:10:39PM -0700, Luck, Tony wrote: > Moving beyond pseudo-code and into compiles-but-probably-broken-code. > > > The intent of the functions below is that Fenghua should be able to > do: > > void fpu__pasid_write(u32 pasid) > { > u64 msr_val = pasid |

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 c

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. > > > >

Re: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP

2021-09-23 Thread Fenghua Yu
Hi, Andy, On Thu, Sep 23, 2021 at 04:17:05PM -0700, Andy Lutomirski wrote: > On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > > ENQCMD requires the IA32_PASID MSR has a valid PASID value which was > > allocated to the process during bind. The MSR could be populated eagerl

Re: [PATCH 7/8] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2021-09-23 Thread Fenghua Yu
Hi, Josh, On Thu, Sep 23, 2021 at 05:55:40PM -0700, Josh Poimboeuf wrote: > On Thu, Sep 23, 2021 at 03:26:14PM +0000, Fenghua Yu wrote: > > > > + } else if (op2 == 0x38 && op3 == 0xf8) { > > > > +

Re: [PATCH 7/8] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2021-09-23 Thread Fenghua Yu
Hi, Peter, On Thu, Sep 23, 2021 at 09:17:01AM +0200, Peter Zijlstra wrote: > On Wed, Sep 22, 2021 at 11:44:41PM +0000, Fenghua Yu wrote: > > > > Since you're making it a fatal error, before doing much of anything > > > else, you might at well fail decode and keep it

Re: [PATCH 7/8] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2021-09-22 Thread Fenghua Yu
Hi, Peter, On Wed, Sep 22, 2021 at 11:03:43PM +0200, Peter Zijlstra wrote: > On Mon, Sep 20, 2021 at 07:23:48PM +0000, Fenghua Yu wrote: > > + ret = validate_enqcmd(file); > > + if (ret < 0) > > + goto out; > > + warnings += ret; > > +

Re: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP

2021-09-22 Thread Fenghua Yu
Hi, Peter, On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > On Mon, Sep 20, 2021 at 07:23:45PM +0000, Fenghua Yu wrote: > > > > + if (user_mode(regs) && fixup_pasid_exception()) > > + goto exit; > > + > >

Re: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP

2021-09-22 Thread Fenghua Yu
Hi, Peter, On Wed, Sep 22, 2021 at 11:11:45PM +0200, Peter Zijlstra wrote: > On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > > +static bool fixup_pasid_exception(void) > > > +{ >

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

2021-09-20 Thread Fenghua Yu
count as it exits. When the reference count is dropped to 0 in either task exit or unbind, the PASID will be freed. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- arch/x86/include/asm/iommu.h | 6 + arch/x86/include/asm/mmu_context.h | 2 ++ drivers/iommu/

[PATCH 3/8] sched: Define and initialize a flag to identify valid PASID in the task

2021-09-20 Thread Fenghua Yu
-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- include/linux/sched.h | 4 kernel/fork.c | 4 2 files changed, 8 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 39039ce8ac4c..21a8cff9155c 100644 --- a/include/linux

[PATCH 1/8] iommu/vt-d: Clean up unused PASID updating functions

2021-09-20 Thread Fenghua Yu
-by: Fenghua Yu Reviewed-by: Tony Luck --- arch/x86/include/asm/fpu/api.h | 2 -- drivers/iommu/intel/svm.c | 24 +--- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index 23bef08a8388

[PATCH 8/8] docs: x86: Change documentation for SVA (Shared Virtual Addressing)

2021-09-20 Thread Fenghua Yu
Since allocating, freeing and fixing up PASID are changed, the documentation is updated to reflect the changes. Originally-by: Ashok Raj Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- Documentation/x86/sva.rst | 81 +++ 1 file changed, 74 insertions

[PATCH 7/8] tools/objtool: Check for use of the ENQCMD instruction in the kernel

2021-09-20 Thread Fenghua Yu
accelerators must always use the ENQCMDS instruction which does not access the PASID_MSR. Check for use of the ENQCMD instruction in the kernel and warn on its usage. Checking the invalid instruction is a relatively new use of objtool and I'm open to feedback about the approach. Signed-off-by: Fenghua Yu

[PATCH 2/8] x86/process: Clear PASID state for a newly forked/cloned thread

2021-09-20 Thread Fenghua Yu
istent way. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- arch/x86/kernel/process.c | 8 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 1d9463e3096b..c713986ef7d7 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel

[PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP

2021-09-20 Thread Fenghua Yu
GP handler is not an elegant solution. But it has the least complexity that fits with h/w behavior. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- arch/x86/include/asm/fpu/api.h | 6 arch/x86/include/asm/iommu.h | 2 ++ arch/x86/kernel/fpu/xstate.c | 59 ++

[PATCH 0/8] Re-enable ENQCMD and PASID MSR

2021-09-20 Thread Fenghua Yu
to serious issues: https://lore.kernel.org/linux-iommu/87mtsd6gr9@nanos.tec.linutronix.de/ 2. #GP fix up PASID MSR: https://lore.kernel.org/linux-iommu/1594684087-61184-1-git-send-email-fenghua...@intel.com/ Fenghua Yu (7): iommu/vt-d: Clean up unused PASID updating functions x86/process: Clear

[PATCH 6/8] x86/cpufeatures: Re-enable ENQCMD

2021-09-20 Thread Fenghua Yu
Since ENQCMD is handled by #GP fix up, it can be re-enabled. The ENQCMD feature cannot be used if CONFIG_INTEL_IOMMU_SVM is not set. Add X86_FEATURE_ENQCMD to the disabled features mask as appropriate and use cpu_feature_enabled() to check the feature. Signed-off-by: Fenghua Yu Reviewed

[PATCH 2/2] iommu/vt-d: Fix a deadlock in SVM

2021-08-26 Thread Fenghua Yu
pasid and svm data mapping data. It's unnecessary to hold pasid_mutex while flushing the workqueue. To fix the deadlock issue, unlock pasid_pasid during flushing the workqueue to allow the works to be handled. Fixes: d5b9e4bfe0d8 ("iommu/vt-d: Report prq to io-pgfault framework") Reported-and-t

[PATCH 1/2] iommu/vt-d: Fix PASID leak

2021-08-26 Thread Fenghua Yu
ng ENQCMD series. Fixes: 62ef907a045e ("iommu/vt-d: Fix PASID reference leak") Reported-and-tested-by: Dave Jiang Co-developed-by: Jacob Pan Signed-off-by: Jacob Pan Signed-off-by: Fenghua Yu --- drivers/iommu/intel/svm.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/

[PATCH] iommu/vt-d: Fix PASID reference leak

2021-08-13 Thread Fenghua Yu
the device by calling intel_svm_free_pasid() . Signed-off-by: Fenghua Yu --- drivers/iommu/intel/svm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 9b0f22bc0514..4b9b3f35ba0e 100644 --- a/drivers/iommu/intel

Re: [PATCH v6 08/12] fork: Clear PASID for new mm

2021-02-25 Thread Fenghua Yu
Hi, Jean, On Wed, Feb 24, 2021 at 11:19:27AM +0100, Jean-Philippe Brucker wrote: > Hi Fenghua, > > [Trimmed the Cc list] > > On Mon, Jul 13, 2020 at 04:48:03PM -0700, Fenghua Yu wrote: > > When a new mm is created, its PASID should be cleared, i.e. the PASID is > > in

Re: [PATCH v10 01/13] mm: Define pasid in mm

2020-09-28 Thread Fenghua Yu
Hi, Will and Jean, On Mon, Sep 28, 2020 at 11:22:51PM +0100, Will Deacon wrote: > On Fri, Sep 18, 2020 at 12:18:41PM +0200, Jean-Philippe Brucker wrote: > > From: Fenghua Yu > > > > PASID is shared by all threads in a process. So the logical place to keep > > track

Re: [PATCH v8 3/9] Documentation/x86: Add documentation for SVA (Shared Virtual Addressing)

2020-09-18 Thread Fenghua Yu
On Thu, Sep 17, 2020 at 07:30:41PM +0200, Borislav Petkov wrote: > On Thu, Sep 17, 2020 at 10:22:39AM -0700, Raj, Ashok wrote: > > s/translation again/translation > > Ok, last one. Now stop looking at that text because you'll find more. > > :-))) Thank you very much for taking care of the

Re: [PATCH v8 0/9] x86: tag application address space for devices

2020-09-17 Thread Fenghua Yu
Hi, Joerg, On Wed, Sep 16, 2020 at 10:06:02AM +0200, Joerg Roedel wrote: > On Tue, Sep 15, 2020 at 09:30:04AM -0700, Fenghua Yu wrote: > > Ashok Raj (1): > > Documentation/x86: Add documentation for SVA (Shared Virtual > > Addressing) > > > > Fenghua Yu (

[PATCH v8 6/9] x86/msr-index: Define IA32_PASID MSR

2020-09-15 Thread Fenghua Yu
The IA32_PASID MSR (0xd93) contains the Process Address Space Identifier (PASID), a 20-bit value. Bit 31 must be set to indicate the value programmed in the MSR is valid. Hardware uses PASID to identify process address space and direct responses to the right address space. Signed-off-by: Fenghua

[PATCH v8 2/9] iommu/vt-d: Change flags type to unsigned int in binding mm

2020-09-15 Thread Fenghua Yu
"flags" passed to intel_svm_bind_mm() is a bit mask and should be defined as "unsigned int" instead of "int". Change its type to "unsigned int". Suggested-by: Thomas Gleixner Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck Reviewed-by: Lu Baolu -

[PATCH v8 3/9] Documentation/x86: Add documentation for SVA (Shared Virtual Addressing)

2020-09-15 Thread Fenghua Yu
From: Ashok Raj ENQCMD and Data Streaming Accelerator (DSA) and all of their associated features are a complicated stack with lots of interconnected pieces. This documentation provides a big picture overview for all of the features. Signed-off-by: Ashok Raj Co-developed-by: Fenghua Yu Signed

[PATCH v8 4/9] x86/cpufeatures: Enumerate ENQCMD and ENQCMDS instructions

2020-09-15 Thread Fenghua Yu
in ENQCMDS. There isn't any usage of ENQCMD in the kernel as of now. The CPU feature flag is shown as "enqcmd" in /proc/cpuinfo. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v2: - Re-write commit message (Thomas) arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/cp

  1   2   3   >