Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3838398pxv; Mon, 28 Jun 2021 14:19:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuKd9E5PAz2Syvqpgvgujvz9Mf2ofiJsfrE3uoQFt3C8VvXD2g3/KGzbct2urCPnJzBRbz X-Received: by 2002:a05:6602:2287:: with SMTP id d7mr1184847iod.172.1624915152505; Mon, 28 Jun 2021 14:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624915152; cv=none; d=google.com; s=arc-20160816; b=usv1QLBgO2WkOFP32aJdBdkwDwtWacoAnO9sEm+AvnjiY3rf2mvI8VvXn2u7vSwJAu PZAquLDU8+9R6sAMtSiSoTrTzvOxG1yUgK+f9neI6xGI9FtLLwZXPnSxtTQ5zLbaDqyq JqQRHmFI/7mmIBJn3f3RRuPjz/nCDn81xGlGx4iVU8XkPSgcLN+4EpAwFPIWmDHERcAN eul5CviY+5XQ2iwszPcLzp/ixek2d1KddvWEcN3NBTw8yx875fEvq+0na9BAaqTQR4Vm TJRdMwVxPdkeUBDdPhOFH6PewGdJsGZqxnjm30RC0sXK8qjoI4JfecLyskuj80Kl9Grq xP+Q== 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=dcQWVD3pulCjVgHOOkoSyz2EutJlEkWEu4hssD54eJk=; b=elK4CAXt0J5VxVQ8+pIG2WT15joG9HzdGoxX9OH2/KPfs6Lo9WLBhrrvASM39ftzAC 1OhTHckKuoqvJ9O+gq6kgTSbLSHBBql4Cz8FbIFw7YzLDoo/8YuZaC5TzyhVDfdp1t4N mg0FcZ3H2zl7TbMRtyYjI6jgeSgnHGOJnXJMrIFcdqtNUTqHCg/hMqymNSWoQeAQkPKc PgB+0Nx3NdRcOLN8BEDIeZfHE3hwIdnvwuH3Yf2+oBxsX4xlkjR0a46O5gk/1kv52sz9 dq4VG3k+/CL+NZDlXiGN4hdM7vHTtGpi6qccSVEvT4CNrSBGN1PjA1Swupt+oNamTAR8 KR6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dHAsBRbS; 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 y6si17892060jai.101.2021.06.28.14.18.58; Mon, 28 Jun 2021 14:19:12 -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=dHAsBRbS; 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 S236299AbhF1PXN (ORCPT + 99 others); Mon, 28 Jun 2021 11:23:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:37004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235777AbhF1O7t (ORCPT ); Mon, 28 Jun 2021 10:59:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1AACA61D5F; Mon, 28 Jun 2021 14:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891241; bh=pA3Ej2bXy7VOSZdAPAdNmdAiYf6WQPSOAgU+739phfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dHAsBRbSRRm6E4ddZ6E3+fzLeIFPz4L3riC21oaiqBPRiLhr8xgeuEdHzPdeXuk+A htMBHTtjiDYvVfeqhSqYDAWlFz+nZbeIJSngcJw8I7PI9W870Bdlg/owbCGAzDOAat wybRFd8kJYMdrUaZOMhKzauxD8EoClMDUkaKwhA+hZrgnWLDRI+b0U81tSxjlV1etK LEINJXIGVXF3OaDkexN22P1+vN9+qtlDUksjE4t5hzo2kLQHaUIZ1QVJ7Qv9IDp7Hw TOYzDiqF49hwZUXVIiZUz7RaTKGyaMjOwA4PJFa8eN+nEf05DIoi58s+qfh7AtO2HP FohPS5fgkvVeQ== 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.9 42/71] ARCv2: save ABI registers across signal handling Date: Mon, 28 Jun 2021 10:39:34 -0400 Message-Id: <20210628144003.34260-43-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144003.34260-1-sashal@kernel.org> References: <20210628144003.34260-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:39+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 9678a11fc158..446259ec7431 100644 --- a/arch/arc/include/uapi/asm/sigcontext.h +++ b/arch/arc/include/uapi/asm/sigcontext.h @@ -17,6 +17,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 16cdb471d3db..27750b806776 100644 --- a/arch/arc/kernel/signal.c +++ b/arch/arc/kernel/signal.c @@ -62,6 +62,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) @@ -95,6 +130,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; @@ -110,6 +149,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