Skip to content

Commit 66cb895

Browse files
vineetgarconettboots
authored andcommitted
ARC: mm: do_page_fault refactor #7: fold the various error handling
- single up_read() call vs. 4 - so much easier on eyes Technically it seems like @bad_area label moved up, but even in old regime, it was a special case of delivering SIGSEGV unconditionally which we now do as well, although with checks. Also note that @fault needs to be initialized since we can land in @bad_area (which reads it) without setting it up with return value of handle_mm_fault() - failing to do so did bite us although as a side effect of different patch: see [1] [1]: http://lists.infradead.org/pipermail/linux-snps-arc/2019-May/005803.html Change-Id: I0964d9868efc0add93878ee57a54631604fcd42c Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Signed-off-by: onettboots <blackcocopet@gmail.com>
1 parent b569cd2 commit 66cb895

1 file changed

Lines changed: 16 additions & 39 deletions

File tree

arch/arc/mm/fault.c

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
6666
struct task_struct *tsk = current;
6767
struct mm_struct *mm = tsk->mm;
6868
siginfo_t info;
69+
int sig, si_code = SEGV_MAPERR;
6970
unsigned int write = 0, exec = 0, mask;
70-
int fault; /* handle_mm_fault() output */
71+
int fault = VM_FAULT_SIGSEGV; /* handle_mm_fault() output */
7172
unsigned int flags; /* handle_mm_fault() input */
7273

7374
/*
@@ -176,55 +177,31 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
176177
return;
177178
}
178179

179-
if (fault & VM_FAULT_OOM)
180-
goto out_of_memory;
181-
else if (fault & VM_FAULT_SIGSEGV)
182-
goto bad_area;
183-
else if (fault & VM_FAULT_SIGBUS)
184-
goto do_sigbus;
185-
186-
/* no man's land */
187-
BUG();
188-
189-
/*
190-
* Something tried to access memory that isn't in our memory map..
191-
* Fix it, but check if it's kernel or user first..
192-
*/
193180
bad_area:
194181
up_read(&mm->mmap_sem);
195182

196183
if (!user_mode(regs))
197184
goto no_context;
198185

199-
tsk->thread.fault_address = address;
200-
info.si_signo = SIGSEGV;
201-
info.si_errno = 0;
202-
/* info.si_code has been set above */
203-
info.si_addr = (void __user *)address;
204-
force_sig_info(SIGSEGV, &info, tsk);
205-
return;
206-
207-
out_of_memory:
208-
up_read(&mm->mmap_sem);
209-
210-
if (!user_mode(regs))
211-
goto no_context;
212-
213-
pagefault_out_of_memory();
214-
return;
215-
216-
do_sigbus:
217-
up_read(&mm->mmap_sem);
186+
if (fault & VM_FAULT_OOM) {
187+
pagefault_out_of_memory();
188+
return;
189+
}
218190

219-
if (!user_mode(regs))
220-
goto no_context;
191+
if (fault & VM_FAULT_SIGBUS) {
192+
sig = SIGBUS;
193+
si_code = BUS_ADRERR;
194+
}
195+
else {
196+
sig = SIGSEGV;
197+
}
221198

222199
tsk->thread.fault_address = address;
223-
info.si_signo = SIGBUS;
200+
info.si_signo = sig;
224201
info.si_errno = 0;
225-
info.si_code = BUS_ADRERR;
202+
info.si_code = si_code;
226203
info.si_addr = (void __user *)address;
227-
force_sig_info(SIGBUS, &info, tsk);
204+
force_sig_info(sig, &info, tsk);
228205
return;
229206

230207
no_context:

0 commit comments

Comments
 (0)