Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3931046pxj; Mon, 21 Jun 2021 09:37:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0wRp2XoAYLkTQ8Nu7gALvtn2pgA6OvUr19dAzwYgYvvgnQT8ObvQxBJaSve7A8609Pdmh X-Received: by 2002:a6b:f815:: with SMTP id o21mr20719834ioh.137.1624293434960; Mon, 21 Jun 2021 09:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293434; cv=none; d=google.com; s=arc-20160816; b=nHTkIx9Jl+Ye7kLeYcN88Z1rz2NGtiGA0M5r53c4e5n1sEsnfyEkAYcG6MfwT7DGND 1yjm928xFXMMmuH5+Hd4Vph4/71tLFs9Az+1r7EJLpNZw0zQY6GdT/vZJAdUQrqneRss OTfTH2Bzno/XDUiAHJ0PEvU0KSJ1nPXjGnEh4Ts3Ie6jR9GOXCVobWDL421r/e2OYGV1 c+FJohh9x/3Y3kWh9NBX5h1s0nY/416MX3ZU+lUqXjbgu7N522WbzIZsYTG3VkKWoCpd r6Bqpka+ZvwgG2CnOqTabn3n5Yh0qksl5sOidVIFzLZ2+hJdr1JG+sEH2mfQtYVzVJL8 xBsw== 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=yHHeQtk/U+59yuXeam3hzsnBttveB7NKpHmpJsiclWsF7+xBE1O+vO4Pbugn6dF9W7 WbgBuHAMjgU5lf0OsL+mAttFBIPpaJTSETvuJeywkPwwc2FIDFbTZxWay2fuia8uY3e5 HQM5qTYl997Wh19JuvIIy9TBO1EvqNDciMZXcVhvuhzHXy8FvVkAWZT8mL5TBieFE9K7 QmEe6gzuriIxB0k7mAQs1OrQPqXFO+mRprkLN0891npgOor7cJIgGbbzcHl/avfhE6uR iMD8vq21Si1aDuoQC4SFePFa/+yL9jY7s/gfanRqFEm7n2HE5lamZELrN2vjNgAJvpMu YxUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=unTJIPn8; 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 i17si11930462ilk.46.2021.06.21.09.37.02; Mon, 21 Jun 2021 09:37:14 -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=unTJIPn8; 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 S232802AbhFUQhl (ORCPT + 99 others); Mon, 21 Jun 2021 12:37:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232443AbhFUQdv (ORCPT ); Mon, 21 Jun 2021 12:33:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C59B61405; Mon, 21 Jun 2021 16:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292798; bh=jypisFtS2T5AuEse6LX+tOnwzhhUTeKbeHc8WA6noSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=unTJIPn8PdQEPNV6+jEJ9M1pdJj1hQZw8aA3VD2st0lfhblkm+2oSTJPMd7neY4tC SpXlh4ZwhTu51R3u6DXFStmQ8UToZDKTEQX2IMMWVVb3o0GxIALKP6ZCE76PfuqQDb 8iPzdZYWgMU4uCTYrnYYZDxaPpbFMRN7g9w/YVow= 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.10 117/146] ARCv2: save ABI registers across signal handling Date: Mon, 21 Jun 2021 18:15:47 +0200 Message-Id: <20210621154918.831182622@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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;