Skip to content

Commit 82f4f66

Browse files
committed
MIPS: Remove open-coded cmpxchg() in set_pte()
set_pte() contains an open coded version of cmpxchg() - it atomically replaces the buddy pte's value if it is currently zero. Simplify the code considerably by just using cmpxchg() instead of reinventing it. Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: linux-mips@vger.kernel.org
1 parent c8790d6 commit 82f4f66

File tree

1 file changed

+2
-43
lines changed

1 file changed

+2
-43
lines changed

arch/mips/include/asm/pgtable.h

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <asm/pgtable-64.h>
1818
#endif
1919

20+
#include <asm/cmpxchg.h>
2021
#include <asm/io.h>
2122
#include <asm/pgtable-bits.h>
2223

@@ -204,49 +205,7 @@ static inline void set_pte(pte_t *ptep, pte_t pteval)
204205
* Make sure the buddy is global too (if it's !none,
205206
* it better already be global)
206207
*/
207-
#ifdef CONFIG_SMP
208-
/*
209-
* For SMP, multiple CPUs can race, so we need to do
210-
* this atomically.
211-
*/
212-
unsigned long page_global = _PAGE_GLOBAL;
213-
unsigned long tmp;
214-
215-
if (kernel_uses_llsc && R10000_LLSC_WAR) {
216-
__asm__ __volatile__ (
217-
" .set push \n"
218-
" .set arch=r4000 \n"
219-
" .set noreorder \n"
220-
"1:" __LL "%[tmp], %[buddy] \n"
221-
" bnez %[tmp], 2f \n"
222-
" or %[tmp], %[tmp], %[global] \n"
223-
__SC "%[tmp], %[buddy] \n"
224-
" beqzl %[tmp], 1b \n"
225-
" nop \n"
226-
"2: \n"
227-
" .set pop \n"
228-
: [buddy] "+m" (buddy->pte), [tmp] "=&r" (tmp)
229-
: [global] "r" (page_global));
230-
} else if (kernel_uses_llsc) {
231-
__asm__ __volatile__ (
232-
" .set push \n"
233-
" .set "MIPS_ISA_ARCH_LEVEL" \n"
234-
" .set noreorder \n"
235-
"1:" __LL "%[tmp], %[buddy] \n"
236-
" bnez %[tmp], 2f \n"
237-
" or %[tmp], %[tmp], %[global] \n"
238-
__SC "%[tmp], %[buddy] \n"
239-
" beqz %[tmp], 1b \n"
240-
" nop \n"
241-
"2: \n"
242-
" .set pop \n"
243-
: [buddy] "+m" (buddy->pte), [tmp] "=&r" (tmp)
244-
: [global] "r" (page_global));
245-
}
246-
#else /* !CONFIG_SMP */
247-
if (pte_none(*buddy))
248-
pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
249-
#endif /* CONFIG_SMP */
208+
cmpxchg(&buddy->pte, 0, _PAGE_GLOBAL);
250209
}
251210
#endif
252211
}

0 commit comments

Comments
 (0)