Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3814452pxv; Mon, 28 Jun 2021 13:36:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK2BWPISZ1nQFhGUOCtQTXKQWwGZw1eTL9I8gOlL5rowaBIpHfxrvMlQ5AzoirRM7XlINj X-Received: by 2002:a6b:e916:: with SMTP id u22mr997648iof.155.1624912615508; Mon, 28 Jun 2021 13:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624912615; cv=none; d=google.com; s=arc-20160816; b=AAVVC0pIQcVXsyyG4bdSes7wtdXTdt0QGQgeKXvz6Yy2O13AkERgjMm3K6TDabPnny iyGkTjAVjoIWqmiBoeTZnpl42BX4opEtCknsr/8Icg2t28BQCkk8VchhB2EUO/zImNGj pvYzjvA+IjEePRvnYCMQggOwIDlpkuXvW1ksj5dUDiib2Ovqd5EJWNp6DhoZs4SnXPNA 6zGsIS6225kbXd7AEKa1pg3oUdlPGjEeiykRyiPqoEx92WCYKLhyDHMpTcRf5NluAWtc rMw0r4PwJ5HqkgYbasD3uFnHjahvamOQhA5xbP1liYtbXSXHK8kMmtW44xsVVz0fmK4L XQow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Va7Xce/DjlPRDcdfpvzb1+iv9j99EuwVWxnbmXUzLCQ=; b=TWFfR0ZVNk/lkbhCb9CML5YcEGUx05CexB58KKw5N5kx0bLF7JIYASbRYcgfmTQKls JOBrZpgwBZSHOZ8hL4Sm2WkvbilfNdpCzvrbEEqGHeLb4xNDmXooNnkCJBwRWSwX1zmN rhosxj78TQn8pO7rFMsBeVk+IeYOYV/v9XKmuJtEUP1LlEM2q6wyaYHyB5JfR7PbjTyx eXU8Y9haU+Uu23AjPy1pLL6eMBo3BZwHq3lhjY9je8bGqhkeywH+2SO+HNC4DIsRQB8f F2r/A3D9Hj6/MpuD1y9sk23hkkQhOdpV4TglCM9n28s5+tBqb4NQ9E/GtHRzshnBnqCU YxwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YD3Vwulq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si16113565ioh.93.2021.06.28.13.36.43; Mon, 28 Jun 2021 13:36:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YD3Vwulq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237194AbhF1PNu (ORCPT + 99 others); Mon, 28 Jun 2021 11:13:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:55610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235447AbhF1OwZ (ORCPT ); Mon, 28 Jun 2021 10:52:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 61B2E61CA0; Mon, 28 Jun 2021 14:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891036; bh=AMRNq82L8/VQmA8YXlo0+swCoNiRblO7beLYo6e9MzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YD3VwulqNBEUZrw+sF+ohVDONywBbnv7XGoG4tagp+pt9qE1HWeLMIo/lkgZHNuz9 Um77OFdpyDciOdBBmbmpwCDRx3vXPTTyr/viSNYbRuTaStyUuMyJLjGreLUy+TC1+7 ZREReKNACwN2ujHX5kKHc6MnBcKoyvxlcDkorLJoDE3GXpaa0hjHLfn02YaPMEHXMJ MeTFsX06frhcD81V5rYcZNjudieXhK7zLiqBdBHU4ki2UNXHkxIbqZeCwrMt1b+Q/N XsLK3/1iCebaOva4KR9/nEOKlbcAy7mhLQvD+vGbLs4hex/10yF/G/s1obynUjsnS2 P3g6aBij6VcSg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vineet Gupta , kernel test robot , Vladimir Isaev , Greg Kroah-Hartman Subject: [PATCH 4.14 53/88] ARCv2: save ABI registers across signal handling Date: Mon, 28 Jun 2021 10:35:53 -0400 Message-Id: <20210628143628.33342-54-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineet Gupta commit 96f1b00138cb8f04c742c82d0a7c460b2202e887 upstream. ARCv2 has some configuration dependent registers (r30, r58, r59) which could be targetted by the compiler. To keep the ABI stable, these were unconditionally part of the glibc ABI (sysdeps/unix/sysv/linux/arc/sys/ucontext.h:mcontext_t) however we missed populating them (by saving/restoring them across signal handling). This patch fixes the issue by - adding arcv2 ABI regs to kernel struct sigcontext - populating them during signal handling Change to struct sigcontext might seem like a glibc ABI change (although it primarily uses ucontext_t:mcontext_t) but the fact is - it has only been extended (existing fields are not touched) - the old sigcontext was ABI incomplete to begin with anyways Fixes: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/53 Cc: Tested-by: kernel test robot Reported-by: Vladimir Isaev Signed-off-by: Vineet Gupta Signed-off-by: Greg Kroah-Hartman --- arch/arc/include/uapi/asm/sigcontext.h | 1 + arch/arc/kernel/signal.c | 43 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/arch/arc/include/uapi/asm/sigcontext.h b/arch/arc/include/uapi/asm/sigcontext.h index 95f8a4380e11..7a5449dfcb29 100644 --- a/arch/arc/include/uapi/asm/sigcontext.h +++ b/arch/arc/include/uapi/asm/sigcontext.h @@ -18,6 +18,7 @@ */ struct sigcontext { struct user_regs_struct regs; + struct user_regs_arcv2 v2abi; }; #endif /* _ASM_ARC_SIGCONTEXT_H */ diff --git a/arch/arc/kernel/signal.c b/arch/arc/kernel/signal.c index da243420bcb5..68901f6f18ba 100644 --- a/arch/arc/kernel/signal.c +++ b/arch/arc/kernel/signal.c @@ -64,6 +64,41 @@ struct rt_sigframe { unsigned int sigret_magic; }; +static int save_arcv2_regs(struct sigcontext *mctx, struct pt_regs *regs) +{ + int err = 0; +#ifndef CONFIG_ISA_ARCOMPACT + struct user_regs_arcv2 v2abi; + + v2abi.r30 = regs->r30; +#ifdef CONFIG_ARC_HAS_ACCL_REGS + v2abi.r58 = regs->r58; + v2abi.r59 = regs->r59; +#else + v2abi.r58 = v2abi.r59 = 0; +#endif + err = __copy_to_user(&mctx->v2abi, &v2abi, sizeof(v2abi)); +#endif + return err; +} + +static int restore_arcv2_regs(struct sigcontext *mctx, struct pt_regs *regs) +{ + int err = 0; +#ifndef CONFIG_ISA_ARCOMPACT + struct user_regs_arcv2 v2abi; + + err = __copy_from_user(&v2abi, &mctx->v2abi, sizeof(v2abi)); + + regs->r30 = v2abi.r30; +#ifdef CONFIG_ARC_HAS_ACCL_REGS + regs->r58 = v2abi.r58; + regs->r59 = v2abi.r59; +#endif +#endif + return err; +} + static int stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs *regs, sigset_t *set) @@ -97,6 +132,10 @@ stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs *regs, err = __copy_to_user(&(sf->uc.uc_mcontext.regs.scratch), &uregs.scratch, sizeof(sf->uc.uc_mcontext.regs.scratch)); + + if (is_isa_arcv2()) + err |= save_arcv2_regs(&(sf->uc.uc_mcontext), regs); + err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(sigset_t)); return err ? -EFAULT : 0; @@ -112,6 +151,10 @@ static int restore_usr_regs(struct pt_regs *regs, struct rt_sigframe __user *sf) err |= __copy_from_user(&uregs.scratch, &(sf->uc.uc_mcontext.regs.scratch), sizeof(sf->uc.uc_mcontext.regs.scratch)); + + if (is_isa_arcv2()) + err |= restore_arcv2_regs(&(sf->uc.uc_mcontext), regs); + if (err) return -EFAULT; -- 2.30.2