Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5367981imm; Sun, 26 Aug 2018 18:09:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYm6qqx9cKbjAzxWPldwlG3a+jrJ2FQQdOigEaz7sA0FYlC9xPgelu+Wh0xYkS17hPd/QRt X-Received: by 2002:a65:6243:: with SMTP id q3-v6mr10085218pgv.273.1535332179980; Sun, 26 Aug 2018 18:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535332179; cv=none; d=google.com; s=arc-20160816; b=C70obugwFzmIIQXVO/l64/UpS8Oh21ucTJaO0zZHmD+LHzfvFPywOaUWTLn+8ow2cS 7kq5ufc7qzlLWyIyKenIugC4sBepbZ6JGrF3OO245GrYCLmlS+jfEbTx+4h0XYZIfBgl euk95O7JV6kWjUB22TqquyTPzQecZL6reqDFkFjrSzXzl0yfaAxzCIMVnkT1HXN/VC7c jd7UZepqv4UHRMUH0dSU5BQ4masm8NwfTQxjDS4A2+ecmx7HR/LVAdJ66zeZcX/LO/yh vMl8T9aM3XOSBSPvH69iDWiaIGyB2+CZZhhcnD+n35z1IuHw4AxhSi1HT0dMKrHSUVGf 4wKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=7HGh6fpMxuqO4ONkVolSj9KuhU0Mw1hl2exd4vJaNNc=; b=Ze6rr0So9eO0msFjB2oF5OEKIgUZDT3wN900YjSQl2cyJHT6Qr5xPsy2kYQZUeR50b RR+4QOVbHrmMEsUs2XHvmibgMu4ZAwEXvvRnI4Fy9M+x0VVApf+2ITjKZVrkADQDXsOW D/lTMknaVLysfVqHCoN+4i6SS4oD9RcSPvOQoVSdhSgfJZeJ/76yLYK5L1LQd3wbCNwM Zy9e8MAGUOfY3r2zcGIIn0oFwU1nIJpxKEABdlnnp2xhGXEzcsQfD6dTJ8IkwtbUk/ze z3yQHTOMCuf6UOBv1+2/cyqBpC1dDpdK6e8+uAGSZO3YgOtphE9m7sH9mzD8DnIEEUu5 sjug== 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 o188-v6si12796865pga.132.2018.08.26.18.09.24; Sun, 26 Aug 2018 18:09:39 -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 S1727083AbeH0Ewi (ORCPT + 99 others); Mon, 27 Aug 2018 00:52:38 -0400 Received: from exmail.andestech.com ([59.124.169.137]:7545 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbeH0Ewi (ORCPT ); Mon, 27 Aug 2018 00:52:38 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w7R15nRk025330; Mon, 27 Aug 2018 09:05:49 +0800 (GMT-8) (envelope-from alankao@andestech.com) Received: from atcsqa06.andestech.com (10.0.1.85) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Mon, 27 Aug 2018 09:08:09 +0800 From: Alan Kao To: , , "Palmer Dabbelt" , Albert Ou , Christoph Hellwig , Andrew Waterman , Arnd Bergmann , Darius Rad CC: , , , , Alan Kao Subject: [PATCH 2/5] Refactor FPU code in signal setup/return procedures Date: Mon, 27 Aug 2018 09:07:52 +0800 Message-ID: <1535332075-5727-3-git-send-email-alankao@andestech.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535332075-5727-1-git-send-email-alankao@andestech.com> References: <1535332075-5727-1-git-send-email-alankao@andestech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.1.85] X-DNSRBL: X-MAIL: ATCSQR.andestech.com w7R15nRk025330 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org FPU-related logic is separated from normal signal handling path in this patch. Kernel can easily be configured to exclude those procedures for no-FPU systems. Signed-off-by: Alan Kao Cc: Greentime Hu Cc: Vincent Chen Cc: Zong Li Cc: Nick Hu Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/signal.c | 68 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 718d0c984ef0..6a18b9819ead 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -37,45 +37,63 @@ struct rt_sigframe { struct ucontext uc; }; -static long restore_d_state(struct pt_regs *regs, - struct __riscv_d_ext_state __user *state) +static long restore_fp_state(struct pt_regs *regs, + union __riscv_fp_state *sc_fpregs) { long err; + struct __riscv_d_ext_state __user *state = &sc_fpregs->d; + size_t i; + err = __copy_from_user(¤t->thread.fstate, state, sizeof(*state)); - if (likely(!err)) - fstate_restore(current, regs); + if (unlikely(err)) + return err; + + fstate_restore(current, regs); + + /* We support no other extension state at this time. */ + for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) { + u32 value; + + err = __get_user(value, &sc_fpregs->q.reserved[i]); + if (unlikely(err)) + break; + if (value != 0) + return -EINVAL; + } + return err; } -static long save_d_state(struct pt_regs *regs, - struct __riscv_d_ext_state __user *state) +static long save_fp_state(struct pt_regs *regs, + union __riscv_fp_state *sc_fpregs) { + long err; + struct __riscv_d_ext_state __user *state = &sc_fpregs->d; + size_t i; + fstate_save(current, regs); - return __copy_to_user(state, ¤t->thread.fstate, sizeof(*state)); + err = __copy_to_user(state, ¤t->thread.fstate, sizeof(*state)); + if (unlikely(err)) + return err; + + /* We support no other extension state at this time. */ + for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) { + err = __put_user(0, &sc_fpregs->q.reserved[i]); + if (unlikely(err)) + break; + } + + return err; } static long restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) { long err; - size_t i; /* sc_regs is structured the same as the start of pt_regs */ err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs)); - if (unlikely(err)) - return err; /* Restore the floating-point state. */ - err = restore_d_state(regs, &sc->sc_fpregs.d); - if (unlikely(err)) - return err; - /* We support no other extension state at this time. */ - for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) { - u32 value; - err = __get_user(value, &sc->sc_fpregs.q.reserved[i]); - if (unlikely(err)) - break; - if (value != 0) - return -EINVAL; - } + err |= restore_fp_state(regs, &sc->sc_fpregs); return err; } @@ -124,14 +142,10 @@ static long setup_sigcontext(struct rt_sigframe __user *frame, { struct sigcontext __user *sc = &frame->uc.uc_mcontext; long err; - size_t i; /* sc_regs is structured the same as the start of pt_regs */ err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs)); /* Save the floating-point state. */ - err |= save_d_state(regs, &sc->sc_fpregs.d); - /* We support no other extension state at this time. */ - for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) - err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]); + err |= save_fp_state(regs, &sc->sc_fpregs); return err; } -- 2.18.0