Skip to content

Commit 8f25e47

Browse files
Kirill TkhaiNagarathnam Muthusamy
authored andcommitted
locking/arch, x86: Add __down_read_killable()
Similar to __down_write_killable(), add read killable primitive: extract current __down_read() code to macros and teach it to get different functions as slow_path argument: store ax register to ret, and add sp register and preserve its value. Add call_rwsem_down_read_failed_killable() assembly entry similar to call_rwsem_down_read_failed(): push dx register to stack in additional to common registers, as it's not declarated as modifiable in ____down_read(). Signed-off-by: Kirill Tkhai <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/150670118802.23930.1316107715255410256.stgit@localhost.localdomain Signed-off-by: Ingo Molnar <[email protected]> (cherry picked from commit 19c6092) Orabug: 28900385 Signed-off-by: Nagarathnam Muthusamy <[email protected]> Reviewed-by: Darren Kenny <[email protected]>
1 parent 466c7b2 commit 8f25e47

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

arch/x86/include/asm/rwsem.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,33 @@
6161
/*
6262
* lock for reading
6363
*/
64+
#define ____down_read(sem, slow_path) \
65+
({ \
66+
struct rw_semaphore* ret; \
67+
asm volatile("# beginning down_read\n\t" \
68+
LOCK_PREFIX _ASM_INC "(%[sem])\n\t" \
69+
/* adds 0x00000001 */ \
70+
" jns 1f\n" \
71+
" call " slow_path "\n" \
72+
"1:\n\t" \
73+
"# ending down_read\n\t" \
74+
: "+m" (sem->count), "=a" (ret), \
75+
ASM_CALL_CONSTRAINT \
76+
: [sem] "a" (sem) \
77+
: "memory", "cc"); \
78+
ret; \
79+
})
80+
6481
static inline void __down_read(struct rw_semaphore *sem)
6582
{
66-
asm volatile("# beginning down_read\n\t"
67-
LOCK_PREFIX _ASM_INC "(%[sem])\n\t"
68-
/* adds 0x00000001 */
69-
" jns 1f\n"
70-
" call call_rwsem_down_read_failed\n"
71-
"1:\n\t"
72-
"# ending down_read\n\t"
73-
: "+m" (sem->count)
74-
: [sem] "a" (sem)
75-
: "memory", "cc");
83+
____down_read(sem, "call_rwsem_down_read_failed");
84+
}
85+
86+
static inline int __down_read_killable(struct rw_semaphore *sem)
87+
{
88+
if (IS_ERR(____down_read(sem, "call_rwsem_down_read_failed_killable")))
89+
return -EINTR;
90+
return 0;
7691
}
7792

7893
/*

arch/x86/lib/rwsem.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ ENTRY(call_rwsem_down_read_failed)
9898
ret
9999
ENDPROC(call_rwsem_down_read_failed)
100100

101+
ENTRY(call_rwsem_down_read_failed_killable)
102+
FRAME_BEGIN
103+
save_common_regs
104+
__ASM_SIZE(push,) %__ASM_REG(dx)
105+
movq %rax,%rdi
106+
call rwsem_down_read_failed_killable
107+
__ASM_SIZE(pop,) %__ASM_REG(dx)
108+
restore_common_regs
109+
FRAME_END
110+
ret
111+
ENDPROC(call_rwsem_down_read_failed_killable)
112+
101113
ENTRY(call_rwsem_down_write_failed)
102114
FRAME_BEGIN
103115
save_common_regs

0 commit comments

Comments
 (0)