Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2996988pxb; Sun, 23 Jan 2022 23:14:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnE1welZprAxtjQ3AuqVT7S4per3ChSMgcRUg2BTTD4lJ88oJd82G5oQHXScuK+cJmzU8Q X-Received: by 2002:a62:e803:0:b0:4c9:ef34:1adb with SMTP id c3-20020a62e803000000b004c9ef341adbmr1190652pfi.76.1643008495287; Sun, 23 Jan 2022 23:14:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643008495; cv=none; d=google.com; s=arc-20160816; b=Qut47yZz42RP8uHa5Ky8LzWXBttBTiZto8dLwkHjoSLmTKwBm1jwyAkR99FdOr1YXb S5oId9ySLYJfAplLqC2lWGRDNOM/33pJbb6IczFo5fVp0TFlqrxxCDlk6t2/MXTTafaj onqItfhqY1xU8pd9pJJQ0tFNdMQ1OLWDzSYIQe+taN9uz8EIrUO0dMZlyvTRGjZq7/Pk HeR4YMtIxa1ke8hgjhEkn7S5pjjsCbrJdWfasWrtaWgQpkcnEeYSctPjKq5choVrftqd cY95jRok+F0aam8kdTnIohpfnwfjv5IKMBgoE2yt9kDp3tXjKNtsdxl99ZsU0i3M9zYl 5F/g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=RsSkxPoCzhxEr9wMCAvQmMVDh4vd6OmESJJX1LzjTd0=; b=jXcNh4URbg/o+RVXkcc63TLBQXOz4rg8/GriuuYKWOK7+CvrCay7KRQpJBT+G67+Z1 gyvfj6RtKEHu4ANZj6iHg5qRNdqkbrc30RERJdpbfo5rFrZHIF0EyuyUck62Ql12s/pd R4lqG+6ALwfADiN34sfh1WgKS/V2CCqywG7IVDs5eKNF4i8QCs+RCUoMKCcktjMBMtoV jlhM6o26WHJhCeTX9TUZ37yDRIMyNN8/ddBDJ+66U0zHnR1miBUJvs/Zh2k28xPLjJ48 Q2zno4I3Ci4IINQEH0SEa6y/SVG3mVzMgDZ5xFfcXdg9r7/PJ5WPSMcDZjTWw59QO28q jF5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SoOM7DOL; 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 w125si11763293pfw.250.2022.01.23.23.14.43; Sun, 23 Jan 2022 23:14:55 -0800 (PST) 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=SoOM7DOL; 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 S236044AbiAWJLz (ORCPT + 99 others); Sun, 23 Jan 2022 04:11:55 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:56536 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230401AbiAWJLy (ORCPT ); Sun, 23 Jan 2022 04:11:54 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 593FAB80B1C for ; Sun, 23 Jan 2022 09:11:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69046C340E2; Sun, 23 Jan 2022 09:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642929111; bh=GY0mrEgMOzSKYYtrDyOe4VtoCDIItsAvJ4mvQZEWyBI=; h=From:To:Cc:Subject:Date:From; b=SoOM7DOLAc8e2q4paRwbWH5vQRJmAtFLeiIUtAM/OJHlSBDEhHN7uaKaVNuK2UU2Z kihXg33VqYjwC7QEB6PvPxNVljrkq1Rp/TRPDuY4I+biTsUj1+YY34avXYVLp7bbS8 j3FrOhSJG1VCiwVskW0NoS875dTKJULRElPrWfKfhop7QwI1LoSqfMCgxN58oCXExO 1oj9u5LVhNN5vqmmjlF7Fq7JpEtYib77mNto90LUOHsTNU28L71f+2rlteCxKj1SL2 asgr2iRzhCrLWVbrC6rjacE7xZ/jPIuhjSZOvJEdRLC2t+YhOYpoUPUQZeGG9mPSWW bWSmt5MLx3hxA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Mayuresh Chitale Subject: [PATCH] riscv: extable: fix err reg writing in dedicated uaccess handler Date: Sun, 23 Jan 2022 17:04:17 +0800 Message-Id: <20220123090417.630-1-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mayuresh reported commit 20802d8d477d ("riscv: extable: add a dedicated uaccess handler") breaks the writev02 test case in LTP. This is due to the err reg isn't correctly set with the errno(-EFAULT in writev02 case). First of all, the err and zero regs are reg numbers rather than reg offsets in struct pt_regs; Secondly, regs_set_gpr() should write the regs when offset isn't zero(zero means epc) Fix it by correcting regs_set_gpr() logic and passing the correct reg offset to it. Reported-by: Mayuresh Chitale Fixes: 20802d8d477d ("riscv: extable: add a dedicated uaccess handler") Signed-off-by: Jisheng Zhang --- arch/riscv/mm/extable.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/mm/extable.c b/arch/riscv/mm/extable.c index 05978f78579f..35484d830fd6 100644 --- a/arch/riscv/mm/extable.c +++ b/arch/riscv/mm/extable.c @@ -33,7 +33,7 @@ static inline void regs_set_gpr(struct pt_regs *regs, unsigned int offset, if (unlikely(offset > MAX_REG_OFFSET)) return; - if (!offset) + if (offset) *(unsigned long *)((unsigned long)regs + offset) = val; } @@ -43,8 +43,8 @@ static bool ex_handler_uaccess_err_zero(const struct exception_table_entry *ex, int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data); int reg_zero = FIELD_GET(EX_DATA_REG_ZERO, ex->data); - regs_set_gpr(regs, reg_err, -EFAULT); - regs_set_gpr(regs, reg_zero, 0); + regs_set_gpr(regs, reg_err * sizeof(unsigned long), -EFAULT); + regs_set_gpr(regs, reg_zero * sizeof(unsigned long), 0); regs->epc = get_ex_fixup(ex); return true; -- 2.34.1