Received: by 10.213.65.68 with SMTP id h4csp1470574imn; Thu, 29 Mar 2018 05:25:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+fQn8Y2FAcdnoanv9XdHDQeV2PfP9vJuDVGwgHO5YF8LNjw6qAcC8ojDkCGJwaeS4c5ILp X-Received: by 2002:a17:902:8c88:: with SMTP id t8-v6mr8032976plo.329.1522326347707; Thu, 29 Mar 2018 05:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522326347; cv=none; d=google.com; s=arc-20160816; b=FGYtKEFA7iqpcgxd3/h+0NFQ6ZXfL9DhwI92hsEpbRU97ijjoJMKlliYMBbOqgx7fJ 33o3DEMGCmEraeNIYwOvBg/hMtJZE1rEVZFQBKf8H3vB2IbaxVyxa+MXUIUORI0LasJw NSX3BgKD8p0E0UDxQabNKhwMBREML5wq8xDHxLsDIqPbuKjV/zidyfghJUx/2clKdwLZ 6UXLfyNXiVOlPxpdwCZDUEi/1RQjpHhhE0CZmCFE5P3BSK7S7PN5xKcNehaDEP8LDxTx Ew3+yzRvubuI+CFdSoHkZHNTzl6tot6w1ZuO3NqQ462n2jLxDwsJ+Gr0mB9yngbT7Nya 9ysA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=3mcftkEeFO/3DNUPqGwS6ahdSwGFhNiqdhLs3jH3THg=; b=1Do6y2pQj7IR6ax8iYcMUkla6Wl/MK7F889neZGwTH8J6qtXVsiQTdStgsuL9dXfQC 2SzD92poaBBaSnX02nJqzH8r/deYh21vFrKcKQcvS6OSxrId47oiMeiZcwXdmnFx/yRH 9NuP8UaAY4jXdqQVLzvgcuiw/eJ5WPMMmoU0T3mwRKWnm4P/P7S3oH3bUu+VUUqwb+U5 oRQg4QR3aRfHQzn/iwkFGOVmg4i6+c1iecVBdf2e1Efs+bklGQRYhiR63zLa+cA7vxm4 A0CIbjYMNU9vnrpqhqQhWgkqjCWjKfv2TyD+nG+JnWf5vm4aNamSMUl9JC6y7AuAyTz4 bDLQ== 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 n1-v6si5791182pld.692.2018.03.29.05.25.33; Thu, 29 Mar 2018 05:25:47 -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 S1752843AbeC2MYC (ORCPT + 99 others); Thu, 29 Mar 2018 08:24:02 -0400 Received: from 9pmail.ess.barracuda.com ([64.235.150.225]:59516 "EHLO 9pmail.ess.barracuda.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752256AbeC2MX7 (ORCPT ); Thu, 29 Mar 2018 08:23:59 -0400 Received: from MIPSMAIL01.mipstec.com (mailrelay.mips.com [12.201.5.28]) by mx3.ess.sfj.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Thu, 29 Mar 2018 12:23:50 +0000 Received: from mredfearn-linux.mipstec.com (192.168.155.41) by MIPSMAIL01.mipstec.com (10.20.43.31) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 29 Mar 2018 02:28:39 -0700 From: Matt Redfearn To: James Hogan , Ralf Baechle CC: , Matt Redfearn , , Subject: [PATCH 1/2] MIPS: memset.S: EVA & fault support for small_memset Date: Thu, 29 Mar 2018 10:28:23 +0100 Message-ID: <1522315704-31641-2-git-send-email-matt.redfearn@mips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522315704-31641-1-git-send-email-matt.redfearn@mips.com> References: <1522315704-31641-1-git-send-email-matt.redfearn@mips.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.155.41] X-BESS-ID: 1522326229-298554-12353-54470-2 X-BESS-VER: 2018.3-r1803262126 X-BESS-Apparent-Source-IP: 12.201.5.28 X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.191512 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The MIPS kernel memset / bzero implementation includes a small_memset branch which is used when the region to be set is smaller than a long (4 bytes on 32bit, 8 bytes on 64bit). The current small_memset implementation uses a simple store byte loop to write the destination. There are 2 issues with this implementation: 1. When EVA mode is active, user and kernel address spaces may overlap. Currently the use of the sb instruction means kernel mode addressing is always used and an intended write to userspace may actually overwrite some critical kernel data. 2. If the write triggers a page fault, for example by calling __clear_user(NULL, 2), instead of gracefully handling the fault, an OOPS is triggered. Fix these issues by replacing the sb instruction with the EX() macro, which will emit EVA compatible instuctions as required. Additionally implement a fault fixup for small_memset which sets a2 to the number of bytes that could not be cleared (as defined by __clear_user). Reported-by: Chuanhua Lei Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Matt Redfearn --- arch/mips/lib/memset.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/mips/lib/memset.S b/arch/mips/lib/memset.S index a1456664d6c2..90bcdf1224ee 100644 --- a/arch/mips/lib/memset.S +++ b/arch/mips/lib/memset.S @@ -219,7 +219,7 @@ 1: PTR_ADDIU a0, 1 /* fill bytewise */ R10KCBARRIER(0(ra)) bne t1, a0, 1b - sb a1, -1(a0) + EX(sb, a1, -1(a0), .Lsmall_fixup\@) 2: jr ra /* done */ move a2, zero @@ -260,6 +260,11 @@ jr ra andi v1, a2, STORMASK +.Lsmall_fixup\@: + PTR_SUBU a2, t1, a0 + jr ra + PTR_ADDIU a2, 1 + .endm /* -- 2.7.4