Received: by 10.192.165.148 with SMTP id m20csp1545412imm; Sat, 21 Apr 2018 10:25:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx484MkZ8Y/7VaV5vMK2ea+zY4NrQmv/ZCCOQUenRPILeWE+ssiMjYAEP3EBKtdCOjEMhAOWf X-Received: by 2002:a17:902:7d92:: with SMTP id a18-v6mr14501469plm.331.1524331559721; Sat, 21 Apr 2018 10:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524331559; cv=none; d=google.com; s=arc-20160816; b=ehZ8gHEDgJIQnm2ioCPIkurKFUqQIFKh+1lXJ1zTlRjirOicEt83BinvjE5kTIrPV0 yqGfgvpY/dk4IZG6Z4+dmHqRv7CHY11R+uB7UhgQIGuO8kxLCjE0q6wQLMiXRuhnahQF Z5iByM6Xu+RTx8nvyanH33oKvnE+xu3mRue0ZaTJ2EGceC+5g8tvsK9Cm+vszcqSXrWC 8xaqiVHOaXJ8lZoeMQ1+Hzqd4TPWpxOaGP/bPgJucBSv8EIh2w2fIXiX9Orv3CSWj8va d0pL1g9V/4ypFUTMUnPoZw3K9SngSz82OW3Juz3wDyUv4A1NAk9n6eyaj8aucfMW5qdo awUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=W/js8MDwV7JVHHSUj0we907JVl6ftxlkocJEVSOvinI=; b=jQzfAS2zE9vbKI9eQ063CDW4Tc75enCEFEYQLbyWrFXseLjbuGJtbKoy2aJEGVfB+l dddV7Y+b6ng1qcTlR+1RsL6Dx3VTDxzuFy70t5UjSjEYd5qpqM1SuJQ03pjxpxfmo0ZW L4oEJM1y9tPBEjjdVrGb+3yVg0GnwgwHKuy34/WxtKZx84fNj0QH2lBuToErgx5SAePC UH4OQOMP5XFmiQgiYkP6mPPaXonzQ6K/qNVLw83xwu4SwjZgYxxFRxV1H6zotL8unMbF LvaMHobbVtikML7lq4eIi9tR/Yk9cJgmreIf6qL+VSNWak4EDvk4mXz+MTW/vNF0xcca b22g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63si6047640pga.397.2018.04.21.10.25.44; Sat, 21 Apr 2018 10:25:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753239AbeDURYe (ORCPT + 99 others); Sat, 21 Apr 2018 13:24:34 -0400 Received: from mout.gmx.net ([212.227.17.20]:48391 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753077AbeDURYc (ORCPT ); Sat, 21 Apr 2018 13:24:32 -0400 Received: from [192.168.20.60] ([46.142.76.178]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LbR3e-1egtoL3OtG-00kuTK; Sat, 21 Apr 2018 19:24:07 +0200 Subject: Re: [REVIEW][PATCH 13/22] signal/parisc: Use force_sig_fault where appropriate To: "Eric W. Biederman" , linux-arch@vger.kernel.org Cc: linux-kernel@vger.kernel.org, James Bottomley , linux-parisc@vger.kernel.org References: <87604mhrnb.fsf@xmission.com> <20180420143811.9994-13-ebiederm@xmission.com> From: Helge Deller Message-ID: <0c19d397-57d2-9b39-19f3-f989b34e1580@gmx.de> Date: Sat, 21 Apr 2018 19:24:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180420143811.9994-13-ebiederm@xmission.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:GEpNsfYKqzJVb5/fpVWmJoPdKKlc8L4z/KNDv+owY7w8VoNdiL0 bykMpIzeGfxY2tO68apHw3QazBQG1SPS6AzCmTSPAfAq17Ek4UCL8Rm/YxuvUcJM0YNSlBA dka7olN8P+Ko2G3wxoaSvasLX7M/Of9A156NOLElNMoshra+dqs7UWMJdCdtli6InN/DPRA B8k3DC664vopZpTKfNHrA== X-UI-Out-Filterresults: notjunk:1;V01:K0://QKuX/HVSM=:E4icsDoOjXZn3EHb+bkNv4 +4DX5Ip4lOwu1curLOIZZa/Ivx83qivGwsH8GDZTtKFlkVoJxiQyWIUaGwc6eO9Ytzm/6WAC5 +d3a7DzBZnRoX4Yi2TNs7ZA1CBDklm1uNlc48pv8IbHuDATwcp++Finkm9Jyk8uR4fO5i7iDn iYVcxmZ5yiUHZiQCxrCww3MDTWdV8ixbl0AXjj7GgcCe8CWqqzyoJvXIdi9vhzTcRGDeIrv3R hll2w1MD+DsRZ6dGwK7Pbyss9fyjsQ0pPAklCpwvkttaQCvsKbpwGynD3crpLp/V3+lMLzKO5 ctLiVQt6Grgbd83fvqq8kundzW8Gg0SiJhNe28qV1T7uYapp9sj40WjDNpEkAbC2DmAVuMLYa sMRf+Llu2920i26RpAp5Iz0vyyv1Nk9YdN2/LIe55dNNTpYHwQWCvkDFHh+RMJJOx2MpJI5Yw /5xcNe5sSmNbag4Cm8YyC4MVwT7TThqzEQuTILqf5Ksd3Px6SWivmTyE2gdYyl0cDIiQ/jzOf NRogUB4h/cv4iYUcQSo3kMTuS2DxBP2xIB1rqstaPlzvbo7kh2PEghUERkzlDxhAdUocOo7nV 1z3hghUBFoWl5EiFHREpdZLVWFDdVZLbT7HBaYm39PqShUtrbxlN5AI2J/aGAVHlh+J2jfR0a F/r/RV0Ak6Cb4ZV5DunyNaxY3NO4qMM2LMDc3JOSItXYUuYCTgE2k1eeXnTmpA6DcAOdMJ+j2 Fh+TScXrA4en/T6xGYvvkTZd/i5tWLsPFQgOid15MaV+aH7h96R/3lgv1yfGKBXWOQFomfyO6 Wq1WGmgqEZgTTBSsaSxM/Lx7RreNFCl71Iz8HuSkbjexXLvrpBt78fAA6Yt4pedekDJ3z6vd5 XGEL0dvVX6REegK5KpdsKqH2ftthVR0J162ojuG+h6YeXhycrKSyj5we/DyFB5sm+cuW73kAo jT/909z0MpdhMjYlSAratCdrWdJkKVtaTdqDX5srL2Ydir34Cn0QGVPbWxLA31XzC5UTyDA5Q hg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20.04.2018 16:38, Eric W. Biederman wrote: > Filling in struct siginfo before calling force_sig_info a tedious and > error prone process, where once in a great while the wrong fields > are filled out, and siginfo has been inconsistently cleared. > > Simplify this process by using the helper force_sig_fault. Which > takes as a parameters all of the information it needs, ensures > all of the fiddly bits of filling in struct siginfo are done properly > and then calls force_sig_info. > > In short about a 5 line reduction in code for every time force_sig_info > is called, which makes the calling function clearer. > > Cc: James Bottomley > Cc: Helge Deller > Cc: linux-parisc@vger.kernel.org > Signed-off-by: "Eric W. Biederman" I pulled this whole patch series from your git tree and booted it on 32- and 64-bit parisc kernels. Acked-by: Helge Deller # parisc Thanks! Helge > --- > arch/parisc/kernel/ptrace.c | 11 ++------ > arch/parisc/kernel/traps.c | 63 ++++++++++++++---------------------------- > arch/parisc/kernel/unaligned.c | 16 +++-------- > arch/parisc/math-emu/driver.c | 9 ++---- > arch/parisc/mm/fault.c | 25 +++++++---------- > 5 files changed, 39 insertions(+), 85 deletions(-) > > diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c > index b1c12ceb1c88..7aa1d4d0d444 100644 > --- a/arch/parisc/kernel/ptrace.c > +++ b/arch/parisc/kernel/ptrace.c > @@ -76,8 +76,6 @@ void user_enable_single_step(struct task_struct *task) > set_tsk_thread_flag(task, TIF_SINGLESTEP); > > if (pa_psw(task)->n) { > - struct siginfo si; > - > /* Nullified, just crank over the queue. */ > task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1]; > task_regs(task)->iasq[0] = task_regs(task)->iasq[1]; > @@ -90,12 +88,9 @@ void user_enable_single_step(struct task_struct *task) > ptrace_disable(task); > /* Don't wake up the task, but let the > parent know something happened. */ > - clear_siginfo(&si); > - si.si_code = TRAP_TRACE; > - si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3); > - si.si_signo = SIGTRAP; > - si.si_errno = 0; > - force_sig_info(SIGTRAP, &si, task); > + force_sig_fault(SIGTRAP, TRAP_TRACE, > + (void __user *) (task_regs(task)->iaoq[0] & ~3), > + task); > /* notify_parent(task, SIGCHLD); */ > return; > } > diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c > index 98f9f2f85940..132b09c657ff 100644 > --- a/arch/parisc/kernel/traps.c > +++ b/arch/parisc/kernel/traps.c > @@ -297,14 +297,8 @@ void die_if_kernel(char *str, struct pt_regs *regs, long err) > #define GDB_BREAK_INSN 0x10004 > static void handle_gdb_break(struct pt_regs *regs, int wot) > { > - struct siginfo si; > - > - clear_siginfo(&si); > - si.si_signo = SIGTRAP; > - si.si_errno = 0; > - si.si_code = wot; > - si.si_addr = (void __user *) (regs->iaoq[0] & ~3); > - force_sig_info(SIGTRAP, &si, current); > + force_sig_fault(SIGTRAP, wot, > + (void __user *) (regs->iaoq[0] & ~3), current); > } > > static void handle_break(struct pt_regs *regs) > @@ -488,9 +482,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > { > unsigned long fault_address = 0; > unsigned long fault_space = 0; > - struct siginfo si; > + int si_code; > > - clear_siginfo(&si); > if (code == 1) > pdc_console_restart(); /* switch back to pdc if HPMC */ > else > @@ -573,7 +566,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > case 8: > /* Illegal instruction trap */ > die_if_kernel("Illegal instruction", regs, code); > - si.si_code = ILL_ILLOPC; > + si_code = ILL_ILLOPC; > goto give_sigill; > > case 9: > @@ -584,7 +577,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > case 10: > /* Privileged operation trap */ > die_if_kernel("Privileged operation", regs, code); > - si.si_code = ILL_PRVOPC; > + si_code = ILL_PRVOPC; > goto give_sigill; > > case 11: > @@ -607,20 +600,16 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > } > > die_if_kernel("Privileged register usage", regs, code); > - si.si_code = ILL_PRVREG; > + si_code = ILL_PRVREG; > give_sigill: > - si.si_signo = SIGILL; > - si.si_errno = 0; > - si.si_addr = (void __user *) regs->iaoq[0]; > - force_sig_info(SIGILL, &si, current); > + force_sig_fault(SIGILL, si_code, > + (void __user *) regs->iaoq[0], current); > return; > > case 12: > /* Overflow Trap, let the userland signal handler do the cleanup */ > - si.si_signo = SIGFPE; > - si.si_code = FPE_INTOVF; > - si.si_addr = (void __user *) regs->iaoq[0]; > - force_sig_info(SIGFPE, &si, current); > + force_sig_fault(SIGFPE, FPE_INTOVF, > + (void __user *) regs->iaoq[0], current); > return; > > case 13: > @@ -628,13 +617,11 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > The condition succeeds in an instruction which traps > on condition */ > if(user_mode(regs)){ > - si.si_signo = SIGFPE; > /* Let userspace app figure it out from the insn pointed > * to by si_addr. > */ > - si.si_code = FPE_CONDTRAP; > - si.si_addr = (void __user *) regs->iaoq[0]; > - force_sig_info(SIGFPE, &si, current); > + force_sig_fault(SIGFPE, FPE_CONDTRAP, > + (void __user *) regs->iaoq[0], current); > return; > } > /* The kernel doesn't want to handle condition codes */ > @@ -743,14 +730,10 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > return; > > die_if_kernel("Protection id trap", regs, code); > - si.si_code = SEGV_MAPERR; > - si.si_signo = SIGSEGV; > - si.si_errno = 0; > - if (code == 7) > - si.si_addr = (void __user *) regs->iaoq[0]; > - else > - si.si_addr = (void __user *) regs->ior; > - force_sig_info(SIGSEGV, &si, current); > + force_sig_fault(SIGSEGV, SEGV_MAPERR, > + (code == 7)? > + ((void __user *) regs->iaoq[0]) : > + ((void __user *) regs->ior), current); > return; > > case 28: > @@ -764,11 +747,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > "handle_interruption() pid=%d command='%s'\n", > task_pid_nr(current), current->comm); > /* SIGBUS, for lack of a better one. */ > - si.si_signo = SIGBUS; > - si.si_code = BUS_OBJERR; > - si.si_errno = 0; > - si.si_addr = (void __user *) regs->ior; > - force_sig_info(SIGBUS, &si, current); > + force_sig_fault(SIGBUS, BUS_OBJERR, > + (void __user *)regs->ior, current); > return; > } > pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC); > @@ -783,11 +763,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs) > "User fault %d on space 0x%08lx, pid=%d command='%s'\n", > code, fault_space, > task_pid_nr(current), current->comm); > - si.si_signo = SIGSEGV; > - si.si_errno = 0; > - si.si_code = SEGV_MAPERR; > - si.si_addr = (void __user *) regs->ior; > - force_sig_info(SIGSEGV, &si, current); > + force_sig_fault(SIGSEGV, SEGV_MAPERR, > + (void __user *)regs->ior, current); > return; > } > } > diff --git a/arch/parisc/kernel/unaligned.c b/arch/parisc/kernel/unaligned.c > index 30b7c7f6c471..932bfc0b7cd8 100644 > --- a/arch/parisc/kernel/unaligned.c > +++ b/arch/parisc/kernel/unaligned.c > @@ -452,10 +452,8 @@ void handle_unaligned(struct pt_regs *regs) > unsigned long newbase = R1(regs->iir)?regs->gr[R1(regs->iir)]:0; > int modify = 0; > int ret = ERR_NOTHANDLED; > - struct siginfo si; > register int flop=0; /* true if this is a flop */ > > - clear_siginfo(&si); > __inc_irq_stat(irq_unaligned_count); > > /* log a message with pacing */ > @@ -691,21 +689,15 @@ void handle_unaligned(struct pt_regs *regs) > > if (ret == ERR_PAGEFAULT) > { > - si.si_signo = SIGSEGV; > - si.si_errno = 0; > - si.si_code = SEGV_MAPERR; > - si.si_addr = (void __user *)regs->ior; > - force_sig_info(SIGSEGV, &si, current); > + force_sig_fault(SIGSEGV, SEGV_MAPERR, > + (void __user *)regs->ior, current); > } > else > { > force_sigbus: > /* couldn't handle it ... */ > - si.si_signo = SIGBUS; > - si.si_errno = 0; > - si.si_code = BUS_ADRALN; > - si.si_addr = (void __user *)regs->ior; > - force_sig_info(SIGBUS, &si, current); > + force_sig_fault(SIGBUS, BUS_ADRALN, > + (void __user *)regs->ior, current); > } > > return; > diff --git a/arch/parisc/math-emu/driver.c b/arch/parisc/math-emu/driver.c > index 0d10efb53361..0590e05571d1 100644 > --- a/arch/parisc/math-emu/driver.c > +++ b/arch/parisc/math-emu/driver.c > @@ -81,7 +81,6 @@ int > handle_fpe(struct pt_regs *regs) > { > extern void printbinary(unsigned long x, int nbits); > - struct siginfo si; > unsigned int orig_sw, sw; > int signalcode; > /* need an intermediate copy of float regs because FPU emulation > @@ -93,7 +92,6 @@ handle_fpe(struct pt_regs *regs) > */ > __u64 frcopy[36]; > > - clear_siginfo(&si); > memcpy(frcopy, regs->fr, sizeof regs->fr); > frcopy[32] = 0; > > @@ -118,11 +116,8 @@ handle_fpe(struct pt_regs *regs) > > memcpy(regs->fr, frcopy, sizeof regs->fr); > if (signalcode != 0) { > - si.si_signo = signalcode >> 24; > - si.si_errno = 0; > - si.si_code = signalcode & 0xffffff; > - si.si_addr = (void __user *) regs->iaoq[0]; > - force_sig_info(si.si_signo, &si, current); > + force_sig_fault(signalcode >> 24, signalcode & 0xffffff, > + (void __user *) regs->iaoq[0], current); > return -1; > } > > diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c > index 51215b0048ef..a80117980fc2 100644 > --- a/arch/parisc/mm/fault.c > +++ b/arch/parisc/mm/fault.c > @@ -353,23 +353,22 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, > up_read(&mm->mmap_sem); > > if (user_mode(regs)) { > - struct siginfo si; > + int signo, si_code; > > - clear_siginfo(&si); > switch (code) { > case 15: /* Data TLB miss fault/Data page fault */ > /* send SIGSEGV when outside of vma */ > if (!vma || > address < vma->vm_start || address >= vma->vm_end) { > - si.si_signo = SIGSEGV; > - si.si_code = SEGV_MAPERR; > + signo = SIGSEGV; > + si_code = SEGV_MAPERR; > break; > } > > /* send SIGSEGV for wrong permissions */ > if ((vma->vm_flags & acc_type) != acc_type) { > - si.si_signo = SIGSEGV; > - si.si_code = SEGV_ACCERR; > + signo = SIGSEGV; > + si_code = SEGV_ACCERR; > break; > } > > @@ -377,17 +376,16 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, > /* fall through */ > case 17: /* NA data TLB miss / page fault */ > case 18: /* Unaligned access - PCXS only */ > - si.si_signo = SIGBUS; > - si.si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR; > + signo = SIGBUS; > + si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR; > break; > case 16: /* Non-access instruction TLB miss fault */ > case 26: /* PCXL: Data memory access rights trap */ > default: > - si.si_signo = SIGSEGV; > - si.si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR; > + signo = SIGSEGV; > + si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR; > break; > } > - > #ifdef CONFIG_MEMORY_FAILURE > if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) { > unsigned int lsb = 0; > @@ -409,12 +407,9 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, > return; > } > #endif > - > show_signal_msg(regs, code, address, tsk, vma); > > - si.si_errno = 0; > - si.si_addr = (void __user *) address; > - force_sig_info(si.si_signo, &si, current); > + force_sig_fault(signo, si_code, (void __user *) address, current); > return; > } > >