Skip to content

Commit beef560

Browse files
author
Martin Schwidefsky
committed
s390/uaccess: simplify control register updates
Always switch to the kernel ASCE in switch_mm. Load the secondary space ASCE in finish_arch_post_lock_switch after checking that any pending page table operations have completed. The primary ASCE is loaded in entry[64].S. With this the update_primary_asce call can be removed from the switch_to macro and from the start of switch_mm function. Remove the load_primary argument from update_user_asce/clear_user_asce, rename update_user_asce to set_user_asce and rename update_primary_asce to load_kernel_asce. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent f4192bf commit beef560

8 files changed

Lines changed: 33 additions & 43 deletions

File tree

‎arch/s390/include/asm/futex.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
2929
int cmparg = (encoded_op << 20) >> 20;
3030
int oldval = 0, newval, ret;
3131

32-
update_primary_asce(current);
32+
load_kernel_asce();
3333
if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
3434
oparg = 1 << oparg;
3535

@@ -79,7 +79,7 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
7979
{
8080
int ret;
8181

82-
update_primary_asce(current);
82+
load_kernel_asce();
8383
asm volatile(
8484
" sacf 256\n"
8585
"0: cs %1,%4,0(%5)\n"

‎arch/s390/include/asm/mmu_context.h‎

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,59 +30,49 @@ static inline int init_new_context(struct task_struct *tsk,
3030

3131
#define destroy_context(mm) do { } while (0)
3232

33-
static inline void update_user_asce(struct mm_struct *mm, int load_primary)
33+
static inline void set_user_asce(struct mm_struct *mm)
3434
{
3535
pgd_t *pgd = mm->pgd;
3636

3737
S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
38-
if (load_primary)
39-
__ctl_load(S390_lowcore.user_asce, 1, 1);
4038
set_fs(current->thread.mm_segment);
39+
set_thread_flag(TIF_ASCE);
4140
}
4241

43-
static inline void clear_user_asce(struct mm_struct *mm, int load_primary)
42+
static inline void clear_user_asce(void)
4443
{
4544
S390_lowcore.user_asce = S390_lowcore.kernel_asce;
4645

47-
if (load_primary)
48-
__ctl_load(S390_lowcore.user_asce, 1, 1);
46+
__ctl_load(S390_lowcore.user_asce, 1, 1);
4947
__ctl_load(S390_lowcore.user_asce, 7, 7);
5048
}
5149

52-
static inline void update_primary_asce(struct task_struct *tsk)
50+
static inline void load_kernel_asce(void)
5351
{
5452
unsigned long asce;
5553

5654
__ctl_store(asce, 1, 1);
5755
if (asce != S390_lowcore.kernel_asce)
5856
__ctl_load(S390_lowcore.kernel_asce, 1, 1);
59-
set_tsk_thread_flag(tsk, TIF_ASCE);
57+
set_thread_flag(TIF_ASCE);
6058
}
6159

6260
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
6361
struct task_struct *tsk)
6462
{
6563
int cpu = smp_processor_id();
6664

67-
update_primary_asce(tsk);
6865
if (prev == next)
6966
return;
7067
if (MACHINE_HAS_TLB_LC)
7168
cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
72-
if (atomic_inc_return(&next->context.attach_count) >> 16) {
73-
/* Delay update_user_asce until all TLB flushes are done. */
74-
set_tsk_thread_flag(tsk, TIF_TLB_WAIT);
75-
/* Clear old ASCE by loading the kernel ASCE. */
76-
clear_user_asce(next, 0);
77-
} else {
78-
cpumask_set_cpu(cpu, mm_cpumask(next));
79-
update_user_asce(next, 0);
80-
if (next->context.flush_mm)
81-
/* Flush pending TLBs */
82-
__tlb_flush_mm(next);
83-
}
69+
/* Clear old ASCE by loading the kernel ASCE. */
70+
__ctl_load(S390_lowcore.kernel_asce, 1, 1);
71+
__ctl_load(S390_lowcore.kernel_asce, 7, 7);
72+
/* Delay loading of the new ASCE to control registers CR1 & CR7 */
73+
set_thread_flag(TIF_ASCE);
74+
atomic_inc(&next->context.attach_count);
8475
atomic_dec(&prev->context.attach_count);
85-
WARN_ON(atomic_read(&prev->context.attach_count) < 0);
8676
if (MACHINE_HAS_TLB_LC)
8777
cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
8878
}
@@ -93,15 +83,14 @@ static inline void finish_arch_post_lock_switch(void)
9383
struct task_struct *tsk = current;
9484
struct mm_struct *mm = tsk->mm;
9585

96-
if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT))
86+
if (!mm)
9787
return;
9888
preempt_disable();
99-
clear_tsk_thread_flag(tsk, TIF_TLB_WAIT);
10089
while (atomic_read(&mm->context.attach_count) >> 16)
10190
cpu_relax();
10291

10392
cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
104-
update_user_asce(mm, 0);
93+
set_user_asce(mm);
10594
if (mm->context.flush_mm)
10695
__tlb_flush_mm(mm);
10796
preempt_enable();
@@ -113,7 +102,9 @@ static inline void finish_arch_post_lock_switch(void)
113102
static inline void activate_mm(struct mm_struct *prev,
114103
struct mm_struct *next)
115104
{
116-
switch_mm(prev, next, current);
105+
switch_mm(prev, next, current);
106+
cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
107+
set_user_asce(next);
117108
}
118109

119110
static inline void arch_dup_mmap(struct mm_struct *oldmm,

‎arch/s390/include/asm/switch_to.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ static inline void restore_access_regs(unsigned int *acrs)
132132
update_cr_regs(next); \
133133
} \
134134
prev = __switch_to(prev,next); \
135-
update_primary_asce(current); \
136135
} while (0)
137136

138137
#define finish_arch_switch(prev) do { \

‎arch/s390/include/asm/thread_info.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ static inline struct thread_info *current_thread_info(void)
8181
#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
8282
#define TIF_SIGPENDING 2 /* signal pending */
8383
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
84-
#define TIF_TLB_WAIT 4 /* wait for TLB flush completion */
85-
#define TIF_ASCE 5 /* primary asce needs fixup / uaccess */
84+
#define TIF_ASCE 5 /* user asce needs fixup / uaccess */
8685
#define TIF_PER_TRAP 6 /* deliver sigtrap on return to user */
8786
#define TIF_MCCK_PENDING 7 /* machine check handling is pending */
8887
#define TIF_SYSCALL_TRACE 8 /* syscall trace active */
@@ -99,7 +98,6 @@ static inline struct thread_info *current_thread_info(void)
9998
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
10099
#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
101100
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
102-
#define _TIF_TLB_WAIT (1<<TIF_TLB_WAIT)
103101
#define _TIF_ASCE (1<<TIF_ASCE)
104102
#define _TIF_PER_TRAP (1<<TIF_PER_TRAP)
105103
#define _TIF_MCCK_PENDING (1<<TIF_MCCK_PENDING)

‎arch/s390/kernel/entry.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
4343
_TIF_MCCK_PENDING | _TIF_ASCE)
4444
_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
4545
_TIF_SYSCALL_TRACEPOINT)
46-
_TIF_TRANSFER = (_TIF_MCCK_PENDING | _TIF_TLB_WAIT)
46+
_TIF_TRANSFER = (_TIF_MCCK_PENDING | _TIF_ASCE)
4747

4848
STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
4949
STACK_SIZE = 1 << STACK_SHIFT

‎arch/s390/kernel/entry64.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
4848
_TIF_MCCK_PENDING | _TIF_ASCE)
4949
_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
5050
_TIF_SYSCALL_TRACEPOINT)
51-
_TIF_TRANSFER = (_TIF_MCCK_PENDING | _TIF_TLB_WAIT)
51+
_TIF_TRANSFER = (_TIF_MCCK_PENDING | _TIF_ASCE)
5252

5353
#define BASED(name) name-system_call(%r13)
5454

‎arch/s390/lib/uaccess.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static inline unsigned long copy_from_user_mvcp(void *x, const void __user *ptr,
7676
{
7777
unsigned long tmp1, tmp2;
7878

79-
update_primary_asce(current);
79+
load_kernel_asce();
8080
tmp1 = -256UL;
8181
asm volatile(
8282
" sacf 0\n"
@@ -159,7 +159,7 @@ static inline unsigned long copy_to_user_mvcs(void __user *ptr, const void *x,
159159
{
160160
unsigned long tmp1, tmp2;
161161

162-
update_primary_asce(current);
162+
load_kernel_asce();
163163
tmp1 = -256UL;
164164
asm volatile(
165165
" sacf 0\n"
@@ -225,7 +225,7 @@ static inline unsigned long copy_in_user_mvc(void __user *to, const void __user
225225
{
226226
unsigned long tmp1;
227227

228-
update_primary_asce(current);
228+
load_kernel_asce();
229229
asm volatile(
230230
" sacf 256\n"
231231
" "AHI" %0,-1\n"
@@ -292,7 +292,7 @@ static inline unsigned long clear_user_xc(void __user *to, unsigned long size)
292292
{
293293
unsigned long tmp1, tmp2;
294294

295-
update_primary_asce(current);
295+
load_kernel_asce();
296296
asm volatile(
297297
" sacf 256\n"
298298
" "AHI" %0,-1\n"
@@ -358,7 +358,7 @@ unsigned long __strnlen_user(const char __user *src, unsigned long size)
358358
{
359359
if (unlikely(!size))
360360
return 0;
361-
update_primary_asce(current);
361+
load_kernel_asce();
362362
return strnlen_user_srst(src, size);
363363
}
364364
EXPORT_SYMBOL(__strnlen_user);

‎arch/s390/mm/pgtable.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ static void __crst_table_upgrade(void *arg)
5353
{
5454
struct mm_struct *mm = arg;
5555

56-
if (current->active_mm == mm)
57-
update_user_asce(mm, 1);
56+
if (current->active_mm == mm) {
57+
clear_user_asce();
58+
set_user_asce(mm);
59+
}
5860
__tlb_flush_local();
5961
}
6062

@@ -108,7 +110,7 @@ void crst_table_downgrade(struct mm_struct *mm, unsigned long limit)
108110
pgd_t *pgd;
109111

110112
if (current->active_mm == mm) {
111-
clear_user_asce(mm, 1);
113+
clear_user_asce();
112114
__tlb_flush_mm(mm);
113115
}
114116
while (mm->context.asce_limit > limit) {
@@ -134,7 +136,7 @@ void crst_table_downgrade(struct mm_struct *mm, unsigned long limit)
134136
crst_table_free(mm, (unsigned long *) pgd);
135137
}
136138
if (current->active_mm == mm)
137-
update_user_asce(mm, 1);
139+
set_user_asce(mm);
138140
}
139141
#endif
140142

0 commit comments

Comments
 (0)