Received: by 10.192.165.148 with SMTP id m20csp573821imm; Wed, 25 Apr 2018 04:30:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+IWDEzqmsO9H2jpd6hKxbQrBhsWSAwciLrHpUdQUlER5kHf+Z8X7XPSoNIfqJbrtlQGB0f X-Received: by 10.99.104.131 with SMTP id d125mr23782854pgc.9.1524655855286; Wed, 25 Apr 2018 04:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524655855; cv=none; d=google.com; s=arc-20160816; b=Ai8qiD+iBcdr3pF85+96UZsyiZvhjLga32tTRqonl/RGi/OSkjGYhmhDI26OFP7YCw KAdenypWYsCLVvOcVpwSSUb2bYtVviZmNPZ6EaRxubmQmV/SXCptVm9xZGDjF2gWkOzF tB9WdU1SrqmQBajmkrO5L2hBD6EKUUgIW7dsEncqSpFclf6TtVcdDcow3LQc4cPGZySn z6Gkq0ndSePHhw9x5AJ3ewKEGqlmd6A34s3c8dXZd2tDQgX5p7SXjHci/ELLzPzQKOet MQ9QGZpSqXqQ49qK7Ma38S6FUFu892yxByrnzToQy6YeG12G4UmIbwu89FF4poQW0LJT uQoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=7TGmhJ6N2E/4mIOojfVj7scbPFvNEid5YRP2hqzxI+s=; b=AV3sqJ/RbL4By8Unk1J2vkoEAFvcfsitGClAJlFiyJdNFjUAUI8W07OCvv39c80pMe MMaDuAm9GFbq8V2ynROdGMMe1KVOxozylzIMsqEtPzdRJcdOTiFkGxuYofMmt9AeRvgW weoxf6ZhsR3uPpdri6HhB0O8dpiiwnok1JREkqSA0URCdxHvJx6gAe8IkoE/G9Zh+OgC KQCa8y5dm2ALfqLIHdanC/EPQPazjXWzceXIeJ0kJzZmZ0FnaHAndxXLnSu33+J/96RT GCy99JtIrhaW3ukGwf80kKF46CppzF1rOXgQCvYr5HyIobPwFzsndQDTzgGUd2k2fX9k 63Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XMM5+vff; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4-v6si16696023pln.468.2018.04.25.04.30.40; Wed, 25 Apr 2018 04:30:55 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XMM5+vff; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753378AbeDYL3k (ORCPT + 99 others); Wed, 25 Apr 2018 07:29:40 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:34086 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752827AbeDYL3g (ORCPT ); Wed, 25 Apr 2018 07:29:36 -0400 Received: by mail-io0-f193.google.com with SMTP id p124-v6so1170352iod.1; Wed, 25 Apr 2018 04:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7TGmhJ6N2E/4mIOojfVj7scbPFvNEid5YRP2hqzxI+s=; b=XMM5+vffyvLXgnkULEfDGHfnKzHHWJzNv589PhVZ4I99pvXaArqwVGiRh10llC/7Jl NFoGgU2c37iUZkvnQAf5Qe9vsLtakIrnZLFbzn0chzX4GPg2nBVniZg1b69IVbGIsO2s tFr2SXRquPYXE26btdZxGD213WIfv7EF77AvDL9fj9oDw4D/d6oih6WmI4J+R3gjFwMs PFnip2gfTZJ6g6Gh1Js1ZHnXiydWZn1W2cXhbf/HF+sqmaUD78cBvW8LX32vaqWXwHD0 g3eUZbawzaEuDOZw+wStuDop3piB1TzSxcplpiwH6SYMfcUA8byuu4wqqFmDyRhJghUp 09Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7TGmhJ6N2E/4mIOojfVj7scbPFvNEid5YRP2hqzxI+s=; b=WGiK1jJODDLG4nJXjhv6vlaMnnl2isJNDxezH54ZLuD8uZSLYEZlBs8iEE6KRlwEOO aAKkx+fClChmI7L9wHv1KEy8XBuiCUH3QyND637WHzK+0AVCAgi9hJSOAsJGT8rX88om /HOHQ4phXG2WkTc8ZTakr1wLHXmXOOFgmAybuDOhjMnZyq8mMRBYRA22SEcme+RKpTlt 70EztwXUVrotNbJS6yTieZ/lDkBYiUweuczS0guVlJCJZMLUszO93/VGPDVO+D3M9lUB 5PCyEy85uu/5WIZ+p2RkHXgXVNodiNzx+eycnVSyCblz/34M9ZBaBhVx/QfsM9sVA6Dw renQ== X-Gm-Message-State: ALQs6tCanhAIpcOhcQ5Hj8mqAj0hv+zCkvE11wyIGgOthgZRdzT0EiOn ecEdMz1QMF0WkOzMsgLQ6ZY64RiFxDWxuO2u/VY= X-Received: by 2002:a6b:6f01:: with SMTP id k1-v6mr30433713ioc.221.1524655775139; Wed, 25 Apr 2018 04:29:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.29.132 with HTTP; Wed, 25 Apr 2018 04:29:34 -0700 (PDT) In-Reply-To: <20180420143811.9994-9-ebiederm@xmission.com> References: <87604mhrnb.fsf@xmission.com> <20180420143811.9994-9-ebiederm@xmission.com> From: Vincent Chen Date: Wed, 25 Apr 2018 19:29:34 +0800 Message-ID: Subject: Re: [REVIEW][PATCH 09/22] signal/nds32: Use force_sig_fault where appropriate To: "Eric W. Biederman" Cc: linux-arch , Linux Kernel Mailing List , Greentime Hu Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-04-20 22:37 GMT+08:00 Eric W. Biederman : > 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: Greentime Hu > Cc: Vincent Chen > Signed-off-by: "Eric W. Biederman" > --- > arch/nds32/kernel/traps.c | 20 ++++---------------- > arch/nds32/mm/fault.c | 19 +++++-------------- > 2 files changed, 9 insertions(+), 30 deletions(-) > > diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c > index 46911768f4b5..636d1c7aa895 100644 > --- a/arch/nds32/kernel/traps.c > +++ b/arch/nds32/kernel/traps.c > @@ -222,20 +222,13 @@ void die_if_kernel(const char *str, struct pt_regs *regs, int err) > > int bad_syscall(int n, struct pt_regs *regs) > { > - siginfo_t info; > - > if (current->personality != PER_LINUX) { > send_sig(SIGSEGV, current, 1); > return regs->uregs[0]; > } > > - clear_siginfo(&info); > - info.si_signo = SIGILL; > - info.si_errno = 0; > - info.si_code = ILL_ILLTRP; > - info.si_addr = (void __user *)instruction_pointer(regs) - 4; > - > - force_sig_info(SIGILL, &info, current); > + force_sig_fault(SIGILL, ILL_ILLTRP, > + (void __user *)instruction_pointer(regs) - 4, current); > die_if_kernel("Oops - bad syscall", regs, n); > return regs->uregs[0]; > } > @@ -288,16 +281,11 @@ void __init early_trap_init(void) > void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, > int error_code, int si_code) > { > - struct siginfo info; > - > tsk->thread.trap_no = ENTRY_DEBUG_RELATED; > tsk->thread.error_code = error_code; > > - clear_siginfo(&info); > - info.si_signo = SIGTRAP; > - info.si_code = si_code; > - info.si_addr = (void __user *)instruction_pointer(regs); > - force_sig_info(SIGTRAP, &info, tsk); > + force_sig_fault(SIGTRAP, si_code > + (void __user *)instruction_pointer(regs), tsk); > } > I found a comma is missing after argument si_code. > void do_debug_trap(unsigned long entry, unsigned long addr, > diff --git a/arch/nds32/mm/fault.c b/arch/nds32/mm/fault.c > index 876ee01ff80a..9bdb7c3ecbb6 100644 > --- a/arch/nds32/mm/fault.c > +++ b/arch/nds32/mm/fault.c > @@ -72,16 +72,15 @@ void do_page_fault(unsigned long entry, unsigned long addr, > struct task_struct *tsk; > struct mm_struct *mm; > struct vm_area_struct *vma; > - siginfo_t info; > + int si_code; > int fault; > unsigned int mask = VM_READ | VM_WRITE | VM_EXEC; > unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; > > - clear_siginfo(&info); > error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE); > tsk = current; > mm = tsk->mm; > - info.si_code = SEGV_MAPERR; > + si_code = SEGV_MAPERR; > /* > * We fault-in kernel-space virtual memory on-demand. The > * 'reference' page table is init_mm.pgd. > @@ -162,7 +161,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, > */ > > good_area: > - info.si_code = SEGV_ACCERR; > + si_code = SEGV_ACCERR; > > /* first do some preliminary protection checks */ > if (entry == ENTRY_PTE_NOT_PRESENT) { > @@ -267,11 +266,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, > tsk->thread.address = addr; > tsk->thread.error_code = error_code; > tsk->thread.trap_no = entry; > - info.si_signo = SIGSEGV; > - info.si_errno = 0; > - /* info.si_code has been set above */ > - info.si_addr = (void *)addr; > - force_sig_info(SIGSEGV, &info, tsk); > + force_sig_fault(SIGSEGV, si_code, (void __user *)addr, tsk); > return; > } > > @@ -340,11 +335,7 @@ void do_page_fault(unsigned long entry, unsigned long addr, > tsk->thread.address = addr; > tsk->thread.error_code = error_code; > tsk->thread.trap_no = entry; > - info.si_signo = SIGBUS; > - info.si_errno = 0; > - info.si_code = BUS_ADRERR; > - info.si_addr = (void *)addr; > - force_sig_info(SIGBUS, &info, tsk); > + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)addr, tsk); > > return; > > -- > 2.14.1 > Except the missing comma in send_sigtrap(), I think this patch for nds32 is OK. Vincent Chen