Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1699153imm; Wed, 1 Aug 2018 22:41:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcmwnoAgoVnO5QbsdAwXg7SRAYBtijAGbT5NvBuPISDGrG9F5qUKr8nZ+K7RGRQFapzfqqT X-Received: by 2002:a62:d8c:: with SMTP id 12-v6mr1427018pfn.202.1533188493021; Wed, 01 Aug 2018 22:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533188493; cv=none; d=google.com; s=arc-20160816; b=kriRHFtZtIk+93WG4ghhtk+Hw2rIK5P3O/Z3/2jct5XOLMsyAVRqfwQMZeEDBLci4M CfoC7GsZOEmoRIpccNwecp7BtPSkla5CykKW9Nb+SvMYz3qiDc7PCLveHN2snX33vQQu yL8v1cK7A/1vJIAkNCnONO5QSrcCBtm/18njIgk6BHtUQSf0O6PYisBfXXTTo3ziliL5 UJDSfmVtxU7xUXTBhmzxUeCkga8PrSvMEPa8HFFPyaCWFHqwh02ELO9jwnUuNL1PHMae OrMrBQBi3qN/C1uQ32CGWO0pUJ3WBCnO0uTEx/GQi1+GmJduqNJRoU6lnQEob04PCcvd mdKw== 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=9lWb/CY8gcp+Ax/AE37uTAJY4q5AiX1icgnwTLIubr8=; b=PZODdGhgPWH6AOBnZYPorfqZCKcdA2/9TmTI1vzhqb7AxLyt/LySc1Ubf9AVtf69ja O9GtNpC9mffmJ/WpUwarWSuO2by4buuq6yQT7Dbfq+nXr0H4dOpbvLNVSFz6SsCuj593 i/MzE602D9o1NSiNhKGcumBDyhBZchs2MD++6p9PgbRLUTBTQ++OJLKULzLnL9fTO1Yx xTDvnaQC6NO1q4u7+sXFLfHeBFJPzyji2ARlL6IxW8/oBZoFLmJNq4mbCsQbaQIwhb7k rB4/euHnuDyWnenbpcF/DQ9XfqaThpy/3NXwve+K0SsY09u4BE/ACl7TVu2es+fO24WL Gftw== 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 d192-v6si1050130pga.207.2018.08.01.22.41.18; Wed, 01 Aug 2018 22:41:32 -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 S1726547AbeHBH3s (ORCPT + 99 others); Thu, 2 Aug 2018 03:29:48 -0400 Received: from exmail.andestech.com ([59.124.169.137]:35630 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbeHBH3s (ORCPT ); Thu, 2 Aug 2018 03:29:48 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w725dsth008402; Thu, 2 Aug 2018 13:39:54 +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; Thu, 2 Aug 2018 13:40:16 +0800 From: Alan Kao To: , , "Palmer Dabbelt" , Albert Ou , Christoph Hellwig , Andrew Waterman , Arnd Bergmann , Darius Rad CC: Alan Kao , Greentime Hu , Vincent Chen , Zong Li , Nick Hu Subject: [PATCH v3 2/4] Refactor FPU codes in signal setup/return procedures Date: Thu, 2 Aug 2018 13:39:49 +0800 Message-ID: <1533188391-5932-3-git-send-email-alankao@andestech.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533188391-5932-1-git-send-email-alankao@andestech.com> References: <1533188391-5932-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 w725dsth008402 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Alan Kao Cc: Greentime Hu Cc: Vincent Chen Cc: Zong Li Cc: Nick Hu --- 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..bfce852d5ddc 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