Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3921461pxj; Mon, 21 Jun 2021 09:25:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNHj9UvDEHSgXvqrrqmH83oSrmic598IPwCiMm6DT1Ni0LYIirsaakI5eYMawY0PSWNG51 X-Received: by 2002:a17:906:dbc9:: with SMTP id yc9mr7742590ejb.233.1624292705311; Mon, 21 Jun 2021 09:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292705; cv=none; d=google.com; s=arc-20160816; b=oGyIaG1xxsthosHGad7tzQrW4YLkaKXba10dYQ9nvsw8ME2Pr3D4wHZSoeTsu1ejdw /kwkxJmK1Kc2CmMX80fZmT9uEJhoKlzZr+oLvHJpw+KcX0OWVkbodwHhHSaNAqzZGU9K EGZ9E68cqHCLReNAsE6ed9DIg8Yg4nWK4j4LmM8qSSAGnm0o2rRrgPd+LKyJ0p3nxZXf ++DW7UVKvX87lxZrV9TZZDgRnnL91Zv7zvlR0MGJBy1yinvXldoZ0bbI4vk+x4HUnYFA kdlULZf1rm668xtxYO4yYIBIuC33AtssapW3M1KZcP2wUohMv9VXeC1QipaMvWgTo4fE 24Lg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E6HrB2D6ukiRlr5hP3NRdgOFudy4Nz2C/FX3Dx1Mkpo=; b=G8A1WqHZgzq3aYRvkUf3PdLMvd4jPSbo4OMWZJCCFml3qdKLG6FJtSg2tpIZqoN/8G MWFS/caj3vwKEznIbm/pdEu2OHCC4UcUfmqG6/YrBaOQHplffQy4fOHnHOIoNu7x6sWl MRr62O2GrKY7MeQcoepEKM5GPDAFSRakTR98yyX5kMxBfNvJbxCajibNdasx4La0FoDj VESG2YjB5aRFp+iu8W7jfNtgXYBLRKZblvz6lTpYONStgwdgQcvGaIEj9HVU+6s0yDZ/ LRXFt9wUNaVSlFrx02E4Bn0T+jNsPm8l1Qp5T6lLJ6f8B5UCUvNCKwaqBbaMqF3ydsKj K/aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m/osPGmx"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si11136180ejs.573.2021.06.21.09.24.42; Mon, 21 Jun 2021 09:25:05 -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=@linuxfoundation.org header.s=korg header.b="m/osPGmx"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbhFUQXK (ORCPT + 99 others); Mon, 21 Jun 2021 12:23:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:41818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbhFUQV4 (ORCPT ); Mon, 21 Jun 2021 12:21:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C44B961361; Mon, 21 Jun 2021 16:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292371; bh=jypisFtS2T5AuEse6LX+tOnwzhhUTeKbeHc8WA6noSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m/osPGmxbuRSku9l+yCa7ObHoHhZGvVfoI1PRq8Sz0kAx2K82g/yht5aCl0ToojQm o/QMMXirRBsbJ0VvwYkxsUc1o+00YHJDPOlocuM0XuAP7uGpCNJs5UaOelYw8Pcywi w5nZ+DzprDYhBWt4Lzy1rUwag8xKVjLgonyrL10o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Vladimir Isaev , Vineet Gupta Subject: [PATCH 5.4 65/90] ARCv2: save ABI registers across signal handling Date: Mon, 21 Jun 2021 18:15:40 +0200 Message-Id: <20210621154906.362363975@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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(+) --- 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 */ --- a/arch/arc/kernel/signal.c +++ b/arch/arc/kernel/signal.c @@ -61,6 +61,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) @@ -94,6 +129,10 @@ stash_usr_regs(struct rt_sigframe __user 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; @@ -109,6 +148,10 @@ static int restore_usr_regs(struct pt_re 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;