Received: by 10.192.165.148 with SMTP id m20csp3792715imm; Mon, 7 May 2018 20:01:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqA6okmz1U1t06rAPKjCXAfjMLPFQGkqGSl6oLxjMiJENc2bb0A+6i/kRwhfxervFVLTy3Z X-Received: by 2002:a65:4907:: with SMTP id p7-v6mr31323282pgs.139.1525748467486; Mon, 07 May 2018 20:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525748467; cv=none; d=google.com; s=arc-20160816; b=J1NHkjFn3x5Tfym2bEBVzoWFuK1jQtz0oUNtjN2ecF9oIoYa2rko8I61hDfxxnSdlC 8ZDJKpnySvxTnjy02cM0Q82gOlV97H4SdL1/gUsVfOC+PSsi2bivvwhe96VC3qO1tXbv yh4/kj3CU6e1yo4FY1njYFg2jHUZ+0E8/J+cU27vFIvaUT2yKQCQWPxyJf6S7u2odovG nFSla0Sga8Oach39tzOoYTQEa02sXBmRZsVyKKOGJhPmkgzLwCcJhD1G5i+JhFuwPu1E aSa+LIdcpStQ0DxELFI5ETsc7Y9SCLl/Ae7VqAFDYaXeUikkmCjVUAwGB6f659oNdP+f vEPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=3zNKopHyBVFdO1v7vMb5hyAsoK3k/xeUyWAbkv6OSJw=; b=TW1yFW8+282KFwBllFkKxmFnPEUh/3yhDiBeXrXsI/Iw3YPnyQz+1Kdm5OMKAnt4zU tOsOo++/HiYWHNsA6dEWpqMq3C/MWQDyBviv9o8LljseKCiYfSbF1EyLc8Lsa232Qujd 1CQzGC0Qdr1cb9+wjCqYuzQzDCPzo3z2JWzehtRd3r+rq4eePuyBDr41Qzdlzw7Bhzvk Mpt+s8aP1gdEL/1cqHnVKRS6Hx7XqByGvzbAbv5IhbcYi6Z+lUIkfcLn1tUBVb4OZRdA RhIltbE3hmSz3dd0ewizHe688jpDamsylXiAzyP7fGZK3G4mhQfLFXl7TnhA4matM7SW J0NA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u131-v6si18853515pgc.11.2018.05.07.20.00.52; Mon, 07 May 2018 20:01:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753946AbeEHDAk (ORCPT + 99 others); Mon, 7 May 2018 23:00:40 -0400 Received: from exmail.andestech.com ([59.124.169.137]:21712 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753869AbeEHDAj (ORCPT ); Mon, 7 May 2018 23:00:39 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w482pw5H020985; Tue, 8 May 2018 10:51:58 +0800 (GMT-8) (envelope-from alankao@andestech.com) Received: from atcsqa06.andestech.com (10.0.1.85) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Tue, 8 May 2018 10:59:51 +0800 From: Alan Kao To: Palmer Dabbelt , Albert Ou , , CC: Alan Kao , Greentime Hu , Zong Li , Vincent Chen Subject: [PATCH] riscv: Fix the bug in memory access fixup code Date: Tue, 8 May 2018 10:59:33 +0800 Message-ID: <1525748373-3841-1-git-send-email-alankao@andestech.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.1.85] X-DNSRBL: X-MAIL: ATCSQR.andestech.com w482pw5H020985 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A piece of fixup code is currently shared by __copy_user and __clear_user. It first disables the access to user-space memory and then returns the "n" argument, which represents #(bytes not processed). However,__copy_user's "n" is in register a2, while __clear_user's in a1, and thus it causes errors for programs like setdomainname02 testcase in LTP. This patch fixes this issue by separating their fixup code and returning the right value for the kernel to handle a relative fault properly. Signed-off-by: Alan Kao Cc: Greentime Hu Cc: Zong Li Cc: Vincent Chen --- arch/riscv/lib/uaccess.S | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/riscv/lib/uaccess.S b/arch/riscv/lib/uaccess.S index 58fb2877c865..0173ea296baa 100644 --- a/arch/riscv/lib/uaccess.S +++ b/arch/riscv/lib/uaccess.S @@ -84,7 +84,7 @@ ENTRY(__clear_user) bgeu t0, t1, 2f bltu a0, t0, 4f 1: - fixup REG_S, zero, (a0), 10f + fixup REG_S, zero, (a0), 11f addi a0, a0, SZREG bltu a0, t1, 1b 2: @@ -96,12 +96,12 @@ ENTRY(__clear_user) li a0, 0 ret 4: /* Edge case: unalignment */ - fixup sb, zero, (a0), 10f + fixup sb, zero, (a0), 11f addi a0, a0, 1 bltu a0, t0, 4b j 1b 5: /* Edge case: remainder */ - fixup sb, zero, (a0), 10f + fixup sb, zero, (a0), 11f addi a0, a0, 1 bltu a0, a3, 5b j 3b @@ -109,9 +109,14 @@ ENDPROC(__clear_user) .section .fixup,"ax" .balign 4 + /* Fixup code for __copy_user(10) and __clear_user(11) */ 10: /* Disable access to user memory */ csrs sstatus, t6 - sub a0, a3, a0 + mv a0, a2 + ret +11: + csrs sstatus, t6 + mv a0, a1 ret .previous -- 2.17.0