Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4293487imm; Mon, 8 Oct 2018 19:20:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV60a/B84mhtnhEAy3kC/KLBO4b0V5QQ5zaESU9KOpea8VRs084wBZRUvb7doIt7LNLH/CfGq X-Received: by 2002:a65:5c81:: with SMTP id a1-v6mr19365193pgt.390.1539051657044; Mon, 08 Oct 2018 19:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539051657; cv=none; d=google.com; s=arc-20160816; b=VhNrUKxXRuvZz+kwQyHQytv2MhhqMoNM7TE6wp0hm/zXF+yHU2nsVCVpxnfJiue4TL QwveGES4w7zyJBPj+GpGHZEfzhzjwOjGFfUxs87zl5S3NVcCitSdCY+SehU0KOxSCGjb /lRn6cA362YBn9FAD944QBdibTtIAVjnQ2pe31IY9ByaLCKBC60zXTh3BAX8503KHQA4 QfeDeCSFYEJj+tKJXvS/iC23w403zlJM8SaAdueDBTB/+uNtC4T5+30tyNxN6QW2/RpO lSCWyFEklUeEVSHRjjEgY6O1pLy/EHjlH5QIY+0vwHWJj2Qkpk/loAbFTgV2GYa/2hm3 Qlsw== 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; bh=BBbOCF2VOF3Lv8cXpA44CZcv9JgIhqwSTxNy/TIBvPg=; b=qDM2Pr9KbnhwUVN2ZoiotLc2cTioWZRjG8IGzx8bIsS5VJJmAEet9awXCrU5REAr4a Qj2k07ybpeacg7uuT68KI+kxT+bRekUxde/F0qYF6ors+6MxW3VqKV5JyalSz4FSWcAd LgMIgwsOihIw2LeitJVX5lLIdEdj5blo9P11PAv2fADR1vcmXt+u0TYlMcpvvoc4xffL tKC/PwIRBMJrzfHjTFu65geyjADizYNfLLkGsIsTnGkEDELhOL/FXnGEyUlnZVLA49KR zdtraD2Am5u1gUTx/KutEoAjgOit4imgKtF7q8k8Bbhs7LYeqAsZDfNVx9ZBJDnrbXa6 5h7w== 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 207-v6si21897084pfu.273.2018.10.08.19.20.42; Mon, 08 Oct 2018 19:20:57 -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 S1726721AbeJIJeY (ORCPT + 99 others); Tue, 9 Oct 2018 05:34:24 -0400 Received: from 59-120-53-16.HINET-IP.hinet.net ([59.120.53.16]:10298 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725887AbeJIJeY (ORCPT ); Tue, 9 Oct 2018 05:34:24 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w992Lr5Q032591; Tue, 9 Oct 2018 10:21:53 +0800 (GMT-8) (envelope-from alankao@andestech.com) Received: from atcsqa06.andestech.com (10.0.15.65) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Tue, 9 Oct 2018 10:19:12 +0800 From: Alan Kao To: Palmer Dabbelt , , , Christoph Hellwig CC: Greentime Hu , Vincent Chen , Zong Li , Nick Hu , Alan Kao Subject: [PATCH v8 2/5] Refactor FPU code in signal setup/return procedures Date: Tue, 9 Oct 2018 10:18:31 +0800 Message-ID: <1539051514-3658-3-git-send-email-alankao@andestech.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1539051514-3658-1-git-send-email-alankao@andestech.com> References: <1539051514-3658-1-git-send-email-alankao@andestech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.15.65] X-DNSRBL: X-MAIL: ATCSQR.andestech.com w992Lr5Q032591 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 718d0c9..6a18b98 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.7.4