Skip to content

Commit a11e67c

Browse files
author
Richard Kuo
committed
Hexagon: Signal and return path fixes
This fixes the return value of sigreturn and moves the work pending check into a c routine for readability and fixes the loop for multiple pending signals. Based on feedback from Al Viro. Signed-off-by: Richard Kuo <rkuo@codeaurora.org>
1 parent 60c4ba9 commit a11e67c

5 files changed

Lines changed: 84 additions & 88 deletions

File tree

‎arch/hexagon/include/uapi/asm/signal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
extern unsigned long __rt_sigtramp_template[2];
2323

24+
void do_signal(struct pt_regs *regs);
25+
2426
#include <asm-generic/signal.h>
2527

2628
#endif

‎arch/hexagon/kernel/process.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/tick.h>
2525
#include <linux/uaccess.h>
2626
#include <linux/slab.h>
27+
#include <linux/tracehook.h>
2728

2829
/*
2930
* Program thread launch. Often defined as a macro in processor.h,
@@ -202,3 +203,43 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
202203
{
203204
return 0;
204205
}
206+
207+
208+
/*
209+
* Called on the exit path of event entry; see vm_entry.S
210+
*
211+
* Interrupts will already be disabled.
212+
*
213+
* Returns 0 if there's no need to re-check for more work.
214+
*/
215+
216+
int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
217+
{
218+
if (!(thread_info_flags & _TIF_ALLWORK_MASK)) {
219+
return 0;
220+
} /* shortcut -- no work to be done */
221+
222+
local_irq_enable();
223+
224+
if (thread_info_flags & _TIF_NEED_RESCHED) {
225+
schedule();
226+
return 1;
227+
}
228+
229+
if (thread_info_flags & _TIF_SIGPENDING) {
230+
do_signal(regs);
231+
return 1;
232+
}
233+
234+
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
235+
clear_thread_flag(TIF_NOTIFY_RESUME);
236+
tracehook_notify_resume(regs);
237+
if (current->replacement_session_keyring)
238+
key_replace_session_keyring();
239+
return 1;
240+
}
241+
242+
/* Should not even reach here */
243+
panic("%s: bad thread_info flags 0x%08x\n", __func__,
244+
thread_info_flags);
245+
}

‎arch/hexagon/kernel/signal.c‎

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
199199
/*
200200
* Called from return-from-event code.
201201
*/
202-
static void do_signal(struct pt_regs *regs)
202+
void do_signal(struct pt_regs *regs)
203203
{
204204
struct k_sigaction sigact;
205205
siginfo_t info;
@@ -216,8 +216,9 @@ static void do_signal(struct pt_regs *regs)
216216
}
217217

218218
/*
219-
* If we came from a system call, handle the restart.
219+
* No (more) signals; if we came from a system call, handle the restart.
220220
*/
221+
221222
if (regs->syscall_nr >= 0) {
222223
switch (regs->r00) {
223224
case -ERESTARTNOHAND:
@@ -240,17 +241,6 @@ static void do_signal(struct pt_regs *regs)
240241
restore_saved_sigmask();
241242
}
242243

243-
void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
244-
{
245-
if (thread_info_flags & _TIF_SIGPENDING)
246-
do_signal(regs);
247-
248-
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
249-
clear_thread_flag(TIF_NOTIFY_RESUME);
250-
tracehook_notify_resume(regs);
251-
}
252-
}
253-
254244
/*
255245
* Architecture-specific wrappers for signal-related system calls
256246
*/
@@ -278,21 +268,12 @@ asmlinkage int sys_rt_sigreturn(void)
278268
/* Restore the user's stack as well */
279269
pt_psp(regs) = regs->r29;
280270

281-
/*
282-
* Leave a trace in the stack frame that this was a sigreturn.
283-
* If the system call is to replay, we've already restored the
284-
* number in the GPR slot and it will be regenerated on the
285-
* new system call trap entry. Note that if restore_sigcontext()
286-
* did something other than a bulk copy of the pt_regs struct,
287-
* we could avoid this assignment by simply not overwriting
288-
* regs->syscall_nr.
289-
*/
290-
regs->syscall_nr = __NR_rt_sigreturn;
271+
regs->syscall_nr = -1;
291272

292273
if (restore_altstack(&frame->uc.uc_stack))
293274
goto badframe;
294275

295-
return 0;
276+
return regs->r00;
296277

297278
badframe:
298279
force_sig(SIGSEGV, current);

‎arch/hexagon/kernel/traps.c‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ long sys_syscall(void)
356356

357357
void do_trap0(struct pt_regs *regs)
358358
{
359-
unsigned long syscallret = 0;
360359
syscall_fn syscall;
361360

362361
switch (pt_cause(regs)) {
@@ -396,21 +395,11 @@ void do_trap0(struct pt_regs *regs)
396395
} else {
397396
syscall = (syscall_fn)
398397
(sys_call_table[regs->syscall_nr]);
399-
syscallret = syscall(regs->r00, regs->r01,
398+
regs->r00 = syscall(regs->r00, regs->r01,
400399
regs->r02, regs->r03,
401400
regs->r04, regs->r05);
402401
}
403402

404-
/*
405-
* If it was a sigreturn system call, don't overwrite
406-
* r0 value in stack frame with return value.
407-
*
408-
* __NR_sigreturn doesn't seem to exist in new unistd.h
409-
*/
410-
411-
if (regs->syscall_nr != __NR_rt_sigreturn)
412-
regs->r00 = syscallret;
413-
414403
/* allow strace to get the syscall return state */
415404
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE)))
416405
tracehook_report_syscall_exit(regs, 0);

‎arch/hexagon/kernel/vm_entry.S‎

Lines changed: 35 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ event_dispatch:
274274
callr r1
275275

276276
/*
277+
* Coming back from the C-world, our thread info pointer
278+
* should be in the designated register (usually R19)
279+
*
277280
* If we were in kernel mode, we don't need to check scheduler
278281
* or signals if CONFIG_PREEMPT is not set. If set, then it has
279282
* to jump to a need_resched kind of block.
@@ -286,67 +289,43 @@ event_dispatch:
286289
#endif
287290

288291
/* "Nested control path" -- if the previous mode was kernel */
289-
R0 = memw(R29 + #_PT_ER_VMEST);
290292
{
291-
P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
292-
if (!P0.new) jump:nt restore_all;
293+
R0 = memw(R29 + #_PT_ER_VMEST);
294+
R16.L = #LO(do_work_pending);
293295
}
294-
/*
295-
* Returning from system call, normally coming back from user mode
296-
*/
297-
return_from_syscall:
298-
/* Disable interrupts while checking TIF */
299-
R0 = #VM_INT_DISABLE
300-
trap1(#HVM_TRAP1_VMSETIE)
301-
302-
/*
303-
* Coming back from the C-world, our thread info pointer
304-
* should be in the designated register (usually R19)
305-
*/
306-
#if CONFIG_HEXAGON_ARCH_VERSION < 4
307-
R1.L = #LO(_TIF_ALLWORK_MASK)
308296
{
309-
R1.H = #HI(_TIF_ALLWORK_MASK);
310-
R0 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
311-
}
312-
#else
313-
{
314-
R1 = ##_TIF_ALLWORK_MASK;
315-
R0 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
297+
P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
298+
if (!P0.new) jump:nt restore_all;
299+
R16.H = #HI(do_work_pending);
300+
R0 = #VM_INT_DISABLE;
316301
}
317-
#endif
318302

319303
/*
320-
* Compare against the "return to userspace" _TIF_WORK_MASK
304+
* Check also the return from fork/system call, normally coming back from
305+
* user mode
306+
*
307+
* R16 needs to have do_work_pending, and R0 should have VM_INT_DISABLE
321308
*/
322-
R1 = and(R1,R0);
323-
{ P0 = cmp.eq(R1,#0); if (!P0.new) jump:t work_pending;}
324-
jump restore_all; /* we're outta here! */
325309

326-
work_pending:
310+
check_work_pending:
311+
/* Disable interrupts while checking TIF */
312+
trap1(#HVM_TRAP1_VMSETIE)
327313
{
328-
P0 = tstbit(R1, #TIF_NEED_RESCHED);
329-
if (!P0.new) jump:nt work_notifysig;
314+
R0 = R29; /* regs should still be at top of stack */
315+
R1 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
316+
callr R16;
330317
}
331-
call schedule
332-
jump return_from_syscall; /* check for more work */
333318

334-
work_notifysig:
335-
/* this is the part that's kind of fuzzy. */
336-
R1 = and(R0, #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME));
337-
{
338-
P0 = cmp.eq(R1, #0);
339-
if P0.new jump:t restore_all;
340-
}
341319
{
342-
R1 = R0; /* unsigned long thread_info_flags */
343-
R0 = R29; /* regs should still be at top of stack */
320+
P0 = cmp.eq(R0, #0); if (!P0.new) jump:nt check_work_pending;
321+
R0 = #VM_INT_DISABLE;
344322
}
345-
call do_notify_resume
346323

347324
restore_all:
348-
/* Disable interrupts, if they weren't already, before reg restore. */
349-
R0 = #VM_INT_DISABLE
325+
/*
326+
* Disable interrupts, if they weren't already, before reg restore.
327+
* R0 gets preloaded with #VM_INT_DISABLE before we get here.
328+
*/
350329
trap1(#HVM_TRAP1_VMSETIE)
351330

352331
/* do the setregs here for VM 0.5 */
@@ -371,6 +350,7 @@ restore_all:
371350
trap1(#HVM_TRAP1_VMRTE)
372351
/* Notreached */
373352

353+
374354
.globl _K_enter_genex
375355
_K_enter_genex:
376356
vm_event_entry(do_genex)
@@ -390,9 +370,12 @@ _K_enter_machcheck:
390370

391371
.globl ret_from_fork
392372
ret_from_fork:
393-
call schedule_tail
394-
P0 = cmp.eq(R24, #0);
395-
if P0 jump return_from_syscall
396-
R0 = R25;
397-
callr R24
398-
jump return_from_syscall
373+
{
374+
call schedule_tail;
375+
R16.H = #HI(do_work_pending);
376+
}
377+
{
378+
R16.L = #LO(do_work_pending);
379+
R0 = #VM_INT_DISABLE;
380+
jump check_work_pending;
381+
}

0 commit comments

Comments
 (0)