Skip to content

Commit 19c6092

Browse files
Kirill TkhaiIngo Molnar
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]>
1 parent a61ba2c commit 19c6092

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
@@ -60,18 +60,33 @@
6060
/*
6161
* lock for reading
6262
*/
63+
#define ____down_read(sem, slow_path) \
64+
({ \
65+
struct rw_semaphore* ret; \
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 " slow_path "\n" \
71+
"1:\n\t" \
72+
"# ending down_read\n\t" \
73+
: "+m" (sem->count), "=a" (ret), \
74+
ASM_CALL_CONSTRAINT \
75+
: [sem] "a" (sem) \
76+
: "memory", "cc"); \
77+
ret; \
78+
})
79+
6380
static inline void __down_read(struct rw_semaphore *sem)
6481
{
65-
asm volatile("# beginning down_read\n\t"
66-
LOCK_PREFIX _ASM_INC "(%[sem])\n\t"
67-
/* adds 0x00000001 */
68-
" jns 1f\n"
69-
" call call_rwsem_down_read_failed\n"
70-
"1:\n\t"
71-
"# ending down_read\n\t"
72-
: "+m" (sem->count)
73-
: [sem] "a" (sem)
74-
: "memory", "cc");
82+
____down_read(sem, "call_rwsem_down_read_failed");
83+
}
84+
85+
static inline int __down_read_killable(struct rw_semaphore *sem)
86+
{
87+
if (IS_ERR(____down_read(sem, "call_rwsem_down_read_failed_killable")))
88+
return -EINTR;
89+
return 0;
7590
}
7691

7792
/*

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)