Skip to contentSkip to conversation

Couple of trivial fixes for LAM vs. SVA interaction

PATCH In review Kirill A. Shutemov 4 participants 9 messages Apr 3, 2023 – Apr 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Couple of trivial fixes for LAM vs. SVA interaction

- Do not allow to set FORCE_TAGGED_SVA bit for other process;

- Use EINVAL instead of EINTR for LAM enabling failure due to SVA;

Kirill A. Shutemov (2):
x86/mm/iommu/sva: Fix error code for LAM enabling failure due to SVA x86/mm/iommu/sva: Do not allow to set FORCE_TAGGED_SVA bit from
outside

 arch/x86/kernel/process_64.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/2 x86/mm/iommu/sva: Fix error code for LAM enabling failure due to SVA

Normally, LAM and SVA are mutually exclusive. LAM enabling will fail if SVA is already in use.

Correct error code for the failure. EINTR is nonsensical there.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")
---
 arch/x86/kernel/process_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/process_64.c +1 -1
index 74c7e84a94d8..c7dfd727c9ec 100644
@@ -760,7 +760,7 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits)
 
 	if (mm_valid_pasid(mm) &&
 	    !test_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &mm->context.flags))
-		return -EINTR;
+		return -EINVAL;
 
 	if (mmap_write_lock_killable(mm))
 		return -EINTR;
Signature · 1 line
2.39.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] x86/mm/iommu/sva: Fix error code for LAM enabling failure due to SVA

Quoted 9 lines · Kirill A. Shutemov

Normally, LAM and SVA are mutually exclusive. LAM enabling will fail if SVA is already in use.

Correct error code for the failure. EINTR is nonsensical there.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")
Quoted 20 lines
---
 arch/x86/kernel/process_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/process_64.c +1 -2
index 74c7e84a94d8..c7dfd727c9ec 100644
@@ -760,7 +760,7 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits)
 
        if (mm_valid_pasid(mm) &&
            !test_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &mm->context.flags))
-               return -EINTR;
+               return -EINVAL;
 
        if (mmap_write_lock_killable(mm))
                return -EINTR;
--

2.39.2

#3 lore raw

Re: [PATCH 1/2] x86/mm/iommu/sva: Fix error code for LAM enabling failure due to SVA

In reply to Kirill A. Shutemov
Quoted 8 lines · Kirill A. Shutemov

Normally, LAM and SVA are mutually exclusive. LAM enabling will fail if SVA is already in use.

Correct error code for the failure. EINTR is nonsensical there.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")

Hi Kirill,

These look fine. But in the future, Link:'s for Reported-by's would be very appreciated if the discussion happened in public.

#4 lore raw

Re: [PATCH 1/2] x86/mm/iommu/sva: Fix error code for LAM enabling failure due to SVA

Quoted 6 lines · Dave Hansen
Quoted 5 lines · Kirill A. Shutemov

Normally, LAM and SVA are mutually exclusive. LAM enabling will fail if SVA is already in use.

Correct error code for the failure. EINTR is nonsensical there.

Quoted 8 lines
Quoted 3 lines
Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")

Hi Kirill,

These look fine. But in the future, Link:'s for Reported-by's would be very appreciated if the discussion happened in public.

Got it.

For this one it is:

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#5 lore raw

PATCH 2/2 x86/mm/iommu/sva: Do not allow to set FORCE_TAGGED_SVA bit from outside

In reply to Kirill A. Shutemov

arch_prctl(ARCH_FORCE_TAGGED_SVA) overrides the default and allows LAM and SVA to co-exist in the process. It is expected by called by the process when it knows what it is doing.

arch_prctl() operates on the current process, but the same code is reachable from ptrace where it can be called on arbitrary task.

Make it strict and only allow to set MM_CONTEXT_FORCE_TAGGED_SVA for the current process.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")
---
 arch/x86/kernel/process_64.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/process_64.c +2 -0
index c7dfd727c9ec..cefac2d3a9f6 100644
@@ -885,6 +885,8 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
 	case ARCH_ENABLE_TAGGED_ADDR:
 		return prctl_enable_tagged_addr(task->mm, arg2);
 	case ARCH_FORCE_TAGGED_SVA:
+		if (current != task)
+			return -EINVAL;
 		set_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &task->mm->context.flags);
 		return 0;
 	case ARCH_GET_MAX_TAG_BITS:
Signature · 1 line
2.39.2
#6 lore raw

Re: [PATCH 2/2] x86/mm/iommu/sva: Do not allow to set FORCE_TAGGED_SVA bit from outside

Quoted 23 lines · Kirill A. Shutemov

arch_prctl(ARCH_FORCE_TAGGED_SVA) overrides the default and allows LAM and SVA to co-exist in the process. It is expected by called by the process when it knows what it is doing.

arch_prctl() operates on the current process, but the same code is reachable from ptrace where it can be called on arbitrary task.

Make it strict and only allow to set MM_CONTEXT_FORCE_TAGGED_SVA for the current process.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")
---
 arch/x86/kernel/process_64.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/process_64.c +0 -0
index c7dfd727c9ec..cefac2d3a9f6 100644

arch/x86/kernel/process_64.c long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) · line 889

Quoted 5 lines
arch/x86/kernel/process_64.c +2 -0
@@ -885,6 +885,8 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
        case ARCH_ENABLE_TAGGED_ADDR:
                return prctl_enable_tagged_addr(task->mm, arg2);
        case ARCH_FORCE_TAGGED_SVA:
+               if (current != task)
+                       return -EINVAL;

prctl_enable_tagged_addr() checks "task->mm != current->mm". Should we check the same here for consistency? Or also change the check in prctl_enable_tagged_addr().

arch_prctl() can only do task==current, so I guess "current != task" is a more reasonable check for prctl_enable_tagged_addr() as well.

Quoted 6 lines
arch/x86/kernel/process_64.c +0 -1
                set_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &task->mm->context.flags);
                return 0;
        case ARCH_GET_MAX_TAG_BITS:
--

2.39.2

#7 lore raw

Re: [PATCH 2/2] x86/mm/iommu/sva: Do not allow to set FORCE_TAGGED_SVA bit from outside

Quoted 35 lines · Dmitry Vyukov
Quoted 23 lines · Kirill A. Shutemov

arch_prctl(ARCH_FORCE_TAGGED_SVA) overrides the default and allows LAM and SVA to co-exist in the process. It is expected by called by the process when it knows what it is doing.

arch_prctl() operates on the current process, but the same code is reachable from ptrace where it can be called on arbitrary task.

Make it strict and only allow to set MM_CONTEXT_FORCE_TAGGED_SVA for the current process.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")
---
 arch/x86/kernel/process_64.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/process_64.c +0 -0
index c7dfd727c9ec..cefac2d3a9f6 100644

arch/x86/kernel/process_64.c long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) · line 889

Quoted 5 lines
arch/x86/kernel/process_64.c +2 -0
@@ -885,6 +885,8 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
        case ARCH_ENABLE_TAGGED_ADDR:
                return prctl_enable_tagged_addr(task->mm, arg2);
        case ARCH_FORCE_TAGGED_SVA:
+               if (current != task)
+                       return -EINVAL;

prctl_enable_tagged_addr() checks "task->mm != current->mm". Should we check the same here for consistency? Or also change the check in prctl_enable_tagged_addr().

Quoted 2 lines

arch_prctl() can only do task==current, so I guess "current != task" is a more reasonable check for prctl_enable_tagged_addr() as well.

As of now, prctl_enable_tagged_addr() doesn't have the task on hands. It gets mm as input, so it cannot check the task directly. But functionally it is the same check.

I would prefer to keep it this way. Unless anyone feels strongly about it.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
Reviewed-by
#8 lore raw

Re: [PATCH 2/2] x86/mm/iommu/sva: Do not allow to set FORCE_TAGGED_SVA bit from outside

Quoted 37 lines · Kirill A. Shutemov
Quoted 35 lines · Dmitry Vyukov
Quoted 23 lines · Kirill A. Shutemov

arch_prctl(ARCH_FORCE_TAGGED_SVA) overrides the default and allows LAM and SVA to co-exist in the process. It is expected by called by the process when it knows what it is doing.

arch_prctl() operates on the current process, but the same code is reachable from ptrace where it can be called on arbitrary task.

Make it strict and only allow to set MM_CONTEXT_FORCE_TAGGED_SVA for the current process.

Fixes 23e5d9ec2bab ("x86/mm/iommu/sva: Make LAM and SVA mutually exclusive")
---
 arch/x86/kernel/process_64.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/process_64.c +0 -0
index c7dfd727c9ec..cefac2d3a9f6 100644

arch/x86/kernel/process_64.c long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) · line 889

Quoted 5 lines
arch/x86/kernel/process_64.c +2 -0
@@ -885,6 +885,8 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
        case ARCH_ENABLE_TAGGED_ADDR:
                return prctl_enable_tagged_addr(task->mm, arg2);
        case ARCH_FORCE_TAGGED_SVA:
+               if (current != task)
+                       return -EINVAL;

prctl_enable_tagged_addr() checks "task->mm != current->mm". Should we check the same here for consistency? Or also change the check in prctl_enable_tagged_addr().

Quoted 8 lines
Quoted 2 lines

arch_prctl() can only do task==current, so I guess "current != task" is a more reasonable check for prctl_enable_tagged_addr() as well.

As of now, prctl_enable_tagged_addr() doesn't have the task on hands. It gets mm as input, so it cannot check the task directly. But functionally it is the same check.

I would prefer to keep it this way. Unless anyone feels strongly about it.

Fine with me.