Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1673120imm; Wed, 8 Aug 2018 23:28:17 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxOSRDm1PK+6g1UfiygoM+JJi0ix4zA9HMF4bRKKwMVwuqRRzcjtP3CzctEcbS2HjB5fnK+ X-Received: by 2002:a17:902:7803:: with SMTP id p3-v6mr806291pll.119.1533796097330; Wed, 08 Aug 2018 23:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533796097; cv=none; d=google.com; s=arc-20160816; b=hGA7DjlzyEjJwtrH6DBOqQjo0rO9PDxT/zm+/2TEd0v+UkrL9pTlnagGwuocqqZxGe ZxsFAh7ffmYWxc1RMWOhQyryoACP9ihC0lUgbHSnYmohSf7CeG5rTjwGlFjE2n7GzvTL wbUIms3MJmxKtNrgusuwvgfB1lClKqFnjCWX9kyqW1qoh5bCxHy2J/MnVTxuM/N0FqVf 9Nx2wDY3h9mMAyKxYOlDx02jCC7wWiPho7UpsRwkOWOevmggwOjVzYK5L0ZKfUyzH4kj 15Gp+JQE6MohbQbtJCQyHER9kGp0ip5ju6hYrW+VFB0suDPk1BlEAEM5jfBX0kke2M90 G6gw== 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=chNkMJm/BDfRLJc576EkyoMpSvqCFtByqqutHhL3ziKYkSADIDUcDnvtgNqbbNo+oz Y0UBaCTBOXFbJiNXce8GWUQOWwDsFlZwdUErYXN3zyJPFOpzfB+5fqhyersO/x02+zHX F4XoEH20yCSWrApHfLcsLoWtSklLPRG6dApI7N6Ab/idb8rZSqgIV8UJM9RZPnL0Jcuv J6gZFV79Mq08YhJIQ4wGHWfHYMKV60K4yNMn3AhswGD1GAQ+sTLBlrL80OoEmQ3r2vwD ON4Gu7hF1w1ZZj7aKrBpKVZYDVJVAxRFdCMJthEbzBNOwc723kBmHuu95EI3ZdNudo8K Knqw== 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 29-v6si5537101pgv.292.2018.08.08.23.28.03; Wed, 08 Aug 2018 23:28:17 -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 S1728108AbeHIIu2 (ORCPT + 99 others); Thu, 9 Aug 2018 04:50:28 -0400 Received: from exmail.andestech.com ([59.124.169.137]:7791 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727237AbeHIIu2 (ORCPT ); Thu, 9 Aug 2018 04:50:28 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w796Q4mM087866; Thu, 9 Aug 2018 14:26:04 +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, 9 Aug 2018 14:26:59 +0800 From: Alan Kao To: , , "Palmer Dabbelt" , Albert Ou , Christoph Hellwig , Andrew Waterman , Arnd Bergmann , Darius Rad CC: , , , , Alan Kao Subject: [PATCH v5 2/5] Refactor FPU code in signal setup/return procedures Date: Thu, 9 Aug 2018 14:26:40 +0800 Message-ID: <1533796003-680-3-git-send-email-alankao@andestech.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533796003-680-1-git-send-email-alankao@andestech.com> References: <1533796003-680-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 w796Q4mM087866 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