Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp341597imm; Tue, 7 Aug 2018 20:26:21 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyvoURu7okrfGFoWUtV4RYqPhO/oqM3UypdAoWVGeacuDDcvWELgqEzDjsRXJVDiqwWFPRC X-Received: by 2002:a17:902:9a47:: with SMTP id x7-v6mr887770plv.37.1533698781913; Tue, 07 Aug 2018 20:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533698781; cv=none; d=google.com; s=arc-20160816; b=UDxzLIK/bYcY0zI7QtS57iG90KO9dmxVLgrVRrCkaO5kVyllUC5E2y2c6aXvb22+DW F7AuRQE1XCVKeFOB4uYWthqI/JmGiw9nukqTJYiwVTj7c0RP+9PfHmALLNV9ZPGZQQxi QFoveO4Eo/PN83q0HZ58BvOCa3H/hl0BISWUZKwuP4vOHum+erHRE6JTBE8HuVufYOVg L02frf+Mj645v+F0vFBdq0umKx3x3sIIIPw8d1B/BaRs8cy2Fo3pP632vR1aoJCE3olS ijD8jLrJwegltY8pFeMGNGXbuiHNY6CWrO9ilBhgwUhDGQEdmTrOxJS6lAoAbAJnyx+W WlZg== 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=HkCB21+iIGdpTzBaEFyGRUSrm16MLJsMtU4I3rqF2M0gZneWEUrzxP5YVk+fyFcJRm dT4jMHJW0cGgIhCHzUHV9Thu6qGNL/wDtUjp2fW7823/4DLRgInUgIKWJcriJlWNshY6 1FjaIOyjJPbzpTvEZLR8OVunLDwJhRiUZngrCVNMXfm9tXqwMhzwTdw8mgaFJRO70jt+ j4yuWvXXVadVGlaOMhwdHUyy0BYP2IEGrcMyJv09rfvhQS1AyQSRwmsFKOmuewhPCnWc gGZojj12+rWR6+wWtJY/ATAIHIjyPyKdcR4Mp+2PL2pFbVSw4ICFh27i7OpBimhvzNFL r88Q== 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 63-v6si3373707pfg.67.2018.08.07.20.26.07; Tue, 07 Aug 2018 20:26:21 -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 S1727028AbeHHFmn (ORCPT + 99 others); Wed, 8 Aug 2018 01:42:43 -0400 Received: from exmail.andestech.com ([59.124.169.137]:57566 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726258AbeHHFmm (ORCPT ); Wed, 8 Aug 2018 01:42:42 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w783OEql083328; Wed, 8 Aug 2018 11:24:14 +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; Wed, 8 Aug 2018 11:25:04 +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 v4 2/5] Refactor FPU code in signal setup/return procedures Date: Wed, 8 Aug 2018 11:24:42 +0800 Message-ID: <1533698685-18022-3-git-send-email-alankao@andestech.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533698685-18022-1-git-send-email-alankao@andestech.com> References: <1533698685-18022-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 w783OEql083328 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