Commit 0433ffc4 authored by Philippe Gerum's avatar Philippe Gerum
Browse files

arm64/ipipe: clarify mm switch helpers

parent 0e6c19a6
...@@ -112,23 +112,25 @@ extern void (*__ipipe_mach_hrtimer_debug)(unsigned irq); ...@@ -112,23 +112,25 @@ extern void (*__ipipe_mach_hrtimer_debug)(unsigned irq);
#ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH #ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH
#define ipipe_mm_switch_protect(flags) \ #define ipipe_mm_switch_protect(__flags) \
do { \ do { \
(void)(flags); \ (void)(__flags); \
} while(0) } while(0)
#define ipipe_mm_switch_unprotect(flags) \ #define ipipe_mm_switch_unprotect(__flags) \
do { \ do { \
(void)(flags); \ (void)(__flags); \
} while(0) } while(0)
#else /* !CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH */ #else /* !CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH */
#define ipipe_mm_switch_protect(flags) \ #define ipipe_mm_switch_protect(__flags) \
flags = hard_cond_local_irq_save() do { \
(__flags) = hard_cond_local_irq_save(); \
} while (0)
#define ipipe_mm_switch_unprotect(flags) \ #define ipipe_mm_switch_unprotect(__flags) \
hard_cond_local_irq_restore(flags) hard_cond_local_irq_restore(__flags)
#endif /* !CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH */ #endif /* !CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH */
......
...@@ -466,31 +466,32 @@ void __switch_mm_inner(struct mm_struct *prev, struct mm_struct *next, ...@@ -466,31 +466,32 @@ void __switch_mm_inner(struct mm_struct *prev, struct mm_struct *next,
{ {
struct mm_struct ** const active_mm = struct mm_struct ** const active_mm =
raw_cpu_ptr(&ipipe_percpu.active_mm); raw_cpu_ptr(&ipipe_percpu.active_mm);
int ret;
#ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH #ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH
struct thread_info *const tip = current_thread_info(); struct thread_info *const tip = current_thread_info();
unsigned long flags;
prev = *active_mm; prev = *active_mm;
clear_bit(TIF_MMSWITCH_INT, &tip->flags); clear_bit(TIF_MMSWITCH_INT, &tip->flags);
barrier(); barrier();
*active_mm = NULL; *active_mm = NULL;
barrier(); barrier();
for (;;) { for (;;) {
#endif ret = __do_switch_mm(prev, next, tsk, true);
int rc __maybe_unused = __do_switch_mm(prev, next, tsk, true);
#ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH
unsigned long flags;
/* /*
* Reading thread_info flags and setting active_mm * Reading thread_info flags and setting active_mm
* must be done atomically. * must be done atomically.
*/ */
flags = hard_local_irq_save(); flags = hard_local_irq_save();
if (__test_and_clear_bit(TIF_MMSWITCH_INT, &tip->flags) == 0) { if (__test_and_clear_bit(TIF_MMSWITCH_INT, &tip->flags) == 0) {
*active_mm = rc < 0 ? prev : next; *active_mm = ret < 0 ? prev : next;
hard_local_irq_restore(flags); hard_local_irq_restore(flags);
return; return;
} }
hard_local_irq_restore(flags); hard_local_irq_restore(flags);
if (rc < 0) if (ret < 0)
/* /*
* We were interrupted by head domain, which * We were interrupted by head domain, which
* may have changed the mm context, mm context * may have changed the mm context, mm context
...@@ -502,8 +503,9 @@ void __switch_mm_inner(struct mm_struct *prev, struct mm_struct *next, ...@@ -502,8 +503,9 @@ void __switch_mm_inner(struct mm_struct *prev, struct mm_struct *next,
prev = NULL; prev = NULL;
} }
#else #else
*active_mm = rc < 0 ? prev : next; ret = __do_switch_mm(prev, next, tsk, true);
#endif *active_mm = ret < 0 ? prev : next;
#endif /* CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH */
} }
#ifdef finish_arch_post_lock_switch #ifdef finish_arch_post_lock_switch
...@@ -514,16 +516,15 @@ void deferred_switch_mm(struct mm_struct *next) ...@@ -514,16 +516,15 @@ void deferred_switch_mm(struct mm_struct *next)
struct mm_struct *prev = *active_mm; struct mm_struct *prev = *active_mm;
#ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH #ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH
struct thread_info *const tip = current_thread_info(); struct thread_info *const tip = current_thread_info();
unsigned long flags;
clear_bit(TIF_MMSWITCH_INT, &tip->flags); clear_bit(TIF_MMSWITCH_INT, &tip->flags);
barrier(); barrier();
*active_mm = NULL; *active_mm = NULL;
barrier(); barrier();
for (;;) { for (;;) {
unsigned long __maybe_unused flags;
#endif
__do_switch_mm(prev, next, NULL, false); __do_switch_mm(prev, next, NULL, false);
#ifdef CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH
/* /*
* Reading thread_info flags and setting active_mm * Reading thread_info flags and setting active_mm
* must be done atomically. * must be done atomically.
...@@ -538,10 +539,11 @@ void deferred_switch_mm(struct mm_struct *next) ...@@ -538,10 +539,11 @@ void deferred_switch_mm(struct mm_struct *next)
prev = NULL; prev = NULL;
} }
#else #else
__do_switch_mm(prev, next, NULL, false);
*active_mm = next; *active_mm = next;
#endif #endif /* CONFIG_IPIPE_WANT_PREEMPTIBLE_SWITCH */
} }
#endif #endif /* finish_arch_post_lock_switch */
#endif /* CONFIG_MMU */ #endif /* CONFIG_MMU */
#ifndef CONFIG_IPIPE_ARM_KUSER_TSC #ifndef CONFIG_IPIPE_ARM_KUSER_TSC
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment