Skip to content

Commit

Permalink
Merge tag 'sched_urgent_for_v6.9_rc5' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/linux/kernel/git/tip/tip

Pull scheduler fix from Borislav Petkov:

 - Add a missing memory barrier in the concurrency ID mm switching

* tag 'sched_urgent_for_v6.9_rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  sched: Add missing memory barrier in switch_mm_cid
  • Loading branch information
Linus Torvalds committed Apr 21, 2024
2 parents d07a0b8 + fe90f39 commit 3b68086
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions arch/x86/include/asm/barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ do { \
#define __smp_mb__before_atomic() do { } while (0)
#define __smp_mb__after_atomic() do { } while (0)

/* Writing to CR3 provides a full memory barrier in switch_mm(). */
#define smp_mb__after_switch_mm() do { } while (0)

#include <asm-generic/barrier.h>

#endif /* _ASM_X86_BARRIER_H */
8 changes: 8 additions & 0 deletions include/asm-generic/barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,13 @@ do { \
#define io_stop_wc() do { } while (0)
#endif

/*
* Architectures that guarantee an implicit smp_mb() in switch_mm()
* can override smp_mb__after_switch_mm.
*/
#ifndef smp_mb__after_switch_mm
# define smp_mb__after_switch_mm() smp_mb()
#endif

#endif /* !__ASSEMBLY__ */
#endif /* __ASM_GENERIC_BARRIER_H */
20 changes: 14 additions & 6 deletions kernel/sched/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
# include <asm/paravirt_api_clock.h>
#endif

#include <asm/barrier.h>

#include "cpupri.h"
#include "cpudeadline.h"

Expand Down Expand Up @@ -3445,13 +3447,19 @@ static inline void switch_mm_cid(struct rq *rq,
* between rq->curr store and load of {prev,next}->mm->pcpu_cid[cpu].
* Provide it here.
*/
if (!prev->mm) // from kernel
if (!prev->mm) { // from kernel
smp_mb();
/*
* user -> user transition guarantees a memory barrier through
* switch_mm() when current->mm changes. If current->mm is
* unchanged, no barrier is needed.
*/
} else { // from user
/*
* user->user transition relies on an implicit
* memory barrier in switch_mm() when
* current->mm changes. If the architecture
* switch_mm() does not have an implicit memory
* barrier, it is emitted here. If current->mm
* is unchanged, no barrier is needed.
*/
smp_mb__after_switch_mm();
}
}
if (prev->mm_cid_active) {
mm_cid_snapshot_time(rq, prev->mm);
Expand Down

0 comments on commit 3b68086

Please sign in to comment.