Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4863429imm; Fri, 18 May 2018 12:00:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqNf/IL4U5WGJ5CM8ocni85IpAxCB0JJwmdZZb6y6S4Q8eRta+elHlUxP9hT58/5aP5/jKm X-Received: by 2002:a65:4003:: with SMTP id f3-v6mr7264622pgp.130.1526670005341; Fri, 18 May 2018 12:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526670005; cv=none; d=google.com; s=arc-20160816; b=dXOi8yEtAbtpprg0hVA40kWfmJqWFMhbOdGhzOPh1v8hV8FuuzTb5273YMPFCWvjjI 2poZezruBvDG7ijiTfT5X3nCEwLb3JYZPHX0O7ES+7icfgm3Uaf+ZZhl5bX46z77jHMb TE2ouLF2BQaVqzAZEjtl0PThXBnIKdIgfW3tPbb4XEOVSCbmUPtGRXblfqdgHmQ6rqt9 S2p1HedXXFeljfUMFxtvmTuuRA7xyPMGvoTOWJXqTsKcRHvItte/MUbjhLUQsuIvKLc+ QT3B98rm3eVNnM5XkGBVK9OUQAHJ4mjYzNLCBdTKKbdw2UQK64pFZe29Nafhy2NCxqN/ /kkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature :arc-authentication-results; bh=lSCq0DVXTMNWbxdocRfFwpx+Pi11zZ38SjFEVMAeGLc=; b=b1/N0KuWOX7ZFdD2chM0b3QlJSaicAU4MqHZczFCsSMAvSxN8g37c1btVrxXi6lUUr v4xEwVU6O8in73e3Im9lHiFDsqbbZVCVM6fo9h/5Gl6ViKBiXKHeJUnFhINGcdsKE7wB WLgEYgpBT0mFuYjr0WERdE2p6qx8moEFoGry5+Y19JyfL9d7buiU3cd8TRCb/abuFkyg ltui0inClRwak6et7rLLhLYWFCnIDQUespDVwf8J1b7eOl5bg1MU5LqIYV7FcvdlOwsO e2C6i6d3vQundmmYEtYYnLXYymS9OgS/vO7lNN7ax5IhGBPvbTDARCIqAUN4VYPAHHrL Isbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=JjQXjKPb; 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 x11-v6si15064pgx.576.2018.05.18.11.59.50; Fri, 18 May 2018 12:00:05 -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; dkim=pass header.i=@sifive.com header.s=google header.b=JjQXjKPb; 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 S1751588AbeERS7l (ORCPT + 99 others); Fri, 18 May 2018 14:59:41 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:38663 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751320AbeERS7j (ORCPT ); Fri, 18 May 2018 14:59:39 -0400 Received: by mail-pg0-f66.google.com with SMTP id n9-v6so3689156pgq.5 for ; Fri, 18 May 2018 11:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=lSCq0DVXTMNWbxdocRfFwpx+Pi11zZ38SjFEVMAeGLc=; b=JjQXjKPbySQkeH/Zc4icxNgeIIPy0PpFfdEpe+yqz/Vim0bOdWY2HyZptqfCZOmU16 M0n0Sz2HcKIpHiV+rYa/rXgeJ4vgEUSX4bW9LzemqOwNlXN0RaRHc7LIOLzTz7nmXG/e G0YqsfZwf/qcg5Kcn/jozXy1LNyMZtTfqqOsHx0Funl/7BmcLxZdKPdEVDHvdHmfktwy Zek50qv6/pbofzZ626JcC2QQVKlF/L2nU7vX/xBvN7KLcASavWYp/hkPBOu2zJfZT1v4 +3B4DtFq7PjIHszA4Z/0bM4vC4Ydb/xFC99a9MBVuYMzcOmgmA8YYD8py6uBaJiURdym LpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=lSCq0DVXTMNWbxdocRfFwpx+Pi11zZ38SjFEVMAeGLc=; b=syTZoC1b8jmxa3cG0BR0f0UlMuj7AmphEea7ragGYOeXv4GnQlK7PQzr/l4DyY+fgT gb2S6dWhnnpWzPECfZbwTSKEtiHM5FDpSnQomHmnEiRdp4sCsh8ZBUWBiVSUMn18yEYo K70GZUMrCedujq6X+tP4lmeCHXmYcdlSzEE1gsSL56wI9nQXsYz4tlwKMgumMVWlaR7v eLd2Fct0sEWOVUX0oMdQv1pnglyqAZ3ld97WeavW8fXwigFJbYjzOF+3fF63MnZ4VaTU 9cSZV2YwujVdvW9QHviv+x9emgeNnGEGClQcfImL6+Hen3wKZFskqZqGYZ8xFp4twBI9 dZ9g== X-Gm-Message-State: ALKqPwe3gN0stpydTz2WLUiwfULpIDJ9RLv7qKkeJ/KqC7J9Cd0KWrp1 zLP5Hwk8uGUp7na+631aerxmSXaKdbY= X-Received: by 2002:a63:5f8b:: with SMTP id t133-v6mr2020693pgb.301.1526669979209; Fri, 18 May 2018 11:59:39 -0700 (PDT) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id k186-v6sm16266813pfc.142.2018.05.18.11.59.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 11:59:38 -0700 (PDT) Date: Fri, 18 May 2018 11:59:38 -0700 (PDT) X-Google-Original-Date: Fri, 18 May 2018 11:58:04 PDT (-0700) Subject: Re: [PATCH] riscv: Fix the bug in memory access fixup code In-Reply-To: <1525748373-3841-1-git-send-email-alankao@andestech.com> CC: albert@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, alankao@andestech.com, greentime@andestech.com, zong@andestech.com, vincentc@andestech.com From: Palmer Dabbelt To: alankao@andestech.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 07 May 2018 19:59:33 PDT (-0700), alankao@andestech.com wrote: > 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 Thanks!