Received: by 10.223.164.202 with SMTP id h10csp93184wrb; Mon, 13 Nov 2017 20:48:12 -0800 (PST) X-Google-Smtp-Source: AGs4zMaiiduyHCFkdygQn7Yl5s8SdhdxkKbq1C77X6+YnWWiceitUrp0eplOT/t+oniDadbeUuR8 X-Received: by 10.159.203.197 with SMTP id r5mr11138734plo.431.1510634892478; Mon, 13 Nov 2017 20:48:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510634892; cv=none; d=google.com; s=arc-20160816; b=FnatWg3OiG5p5UJoICMwAF76n0m+N+dEFH7uWjx84OQfB0zgJpGbV49n/XRpy62aOL hFVMyatO7eKYGwDRWWaZW1HmBsJZDXv41gqoHajNJwAyp+6QHCY4dOJ31WP7h96M415u D5uEtx8kbW2aZ/2yh2wA0vpp6hXmkI0rUZckFYnY3sHa/ILY/8EV+KrPE7XESZc02/mT yQVIvrQBtdPG5A4T+hrC5nQmC3n2eQQZ92517l5UsePGQYkGXRmSwjMYCNsKqO8joBRe q6DOK7TvjUxhlpj/NA+fxauLPsAhmDTSlms/OinTsPszvylijcShfrBvmsmtZAkacSsf Og7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=QvZifY+tBpZlC5ppv685KA4NrOk7WnZUHd2SsPXbykU=; b=RujJzocnvn2rek9hjMeEn07o1tCeu2M6CIm4men2LkRFX3xaY0hLSVBsi8A/86+gTJ PGwLQu53NhQWE6IbhleAZU7A3GuKBLBPqNyYk3o2OXHixHjcoN19wBo9OsvYWIA2GvgV 7GBxYOcsNOGoJHDIB1hlY28jJG5h4mmw078omuw76su80sEpzBMZj98E0bSf71Y39GZ2 0f93MJiMnOtZaL81VM6hlJfovXv03vkiG3ENLtO8OupblYbY2xq1hNmlv42ZecZbBLpX I1NekEs+EcVu7iVrVjGpDIzRE8GVq4MU+s6q6NcrsvT73NSlVjluZm1pKC11T0Nx58b9 hqXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fhFDxmyT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r63si15774412plb.638.2017.11.13.20.47.57; Mon, 13 Nov 2017 20:48:12 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=fhFDxmyT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754090AbdKNErQ (ORCPT + 89 others); Mon, 13 Nov 2017 23:47:16 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:50331 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753596AbdKNErF (ORCPT ); Mon, 13 Nov 2017 23:47:05 -0500 Received: by mail-io0-f193.google.com with SMTP id 71so7460812ior.7; Mon, 13 Nov 2017 20:47:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QvZifY+tBpZlC5ppv685KA4NrOk7WnZUHd2SsPXbykU=; b=fhFDxmyT68CmWE3R135ioRPdz1o7XEFZv27XXlyf+J3smbKV8v5A0cW7pIZgqTNuua dDIxCLP1pkislEBTX5GYGQEqCTgfjvZa1ElVSCCKVzgpfPaaOqfHkEmKhUhjDv1AYcd8 VMM6XsUctXc8DQWuDD1ceiSW40aU2GI4375y7qClm0/gTqO+7RJVZAdMzCrcsgzdvhPr R+EvXAAeXosZok9SR0cX+ltN13huU8D+Db5EgTmY8/ekJc3lH3C3oYlx0mrxjAunxBFG 9fJIh21C/ZfjfyYDTL5rJaWCby1HtFj0qp3OhBDwkuVE0p7gtw8IIRpLjON39Z16sW77 KK0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QvZifY+tBpZlC5ppv685KA4NrOk7WnZUHd2SsPXbykU=; b=Q1ClGLLcOxKRdpC7C+8S2BCOgRJvBLdoMZR5RlQoz28W+Qx+A/NAwWbF50Q4+LMMBz uU673hL7rVgFomkhnr78+sX3KoFLG0eZnJiLr9y+LUIZd69JQ+LhGpRfKxp0r/in+3PM dIJuQmbdfC9wOHNl5c8yErovmt63z+gq11lw9XNOPc/g2v61gYorBuRndNsC8fHxQI5Q Plc481iThJQg1kCqxRMKj3mc7vQx4Kq6hJhUyyxL2tU3gTSqzMtUEP3Xh7T4Kp7rZAkX q18XqlMTl/3Ymeds1IZmxG/Nr9724cz8yfu7QJMrRuhKJEe2EcwGOiXrAvXmE43dWnXR NlDQ== X-Gm-Message-State: AJaThX5IoEOoW+CFsKL3nm6L4s2TVvrw3M6rbYlb49kWwO749ilkN115 TgJyIzUZM58MjCdVYzNGTNhHG3HSO6XIxLwv12k= X-Received: by 10.107.38.79 with SMTP id m76mr13022281iom.187.1510634824774; Mon, 13 Nov 2017 20:47:04 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.62.213 with HTTP; Mon, 13 Nov 2017 20:47:04 -0800 (PST) In-Reply-To: References: <20171109004020.GX21978@ZenIV.linux.org.uk> From: Vincent Chen Date: Tue, 14 Nov 2017 12:47:04 +0800 Message-ID: Subject: Fwd: FW: [PATCH 18/31] nds32: Library functions To: viro@ftp.linux.org.uk Cc: greentime@andestech.com, Green Hu , linux-kernel@vger.kernel.org, Arnd Bergmann , linux-arch@vger.kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, netdev@vger.kernel.org, vincentc@andestech.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >>On Wed, Nov 08, 2017 at 01:55:06PM +0800, Greentime Hu wrote: > >> +#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs() >> +-size)) >> + >> +#define access_ok(type, addr, size) \ >> + __range_ok((unsigned long)addr, (unsigned long)size) > >> +#define __get_user_x(__r2,__p,__e,__s,__i...) \ >> + __asm__ __volatile__ ( \ >> + __asmeq("%0", "$r0") __asmeq("%1", "$r2") \ >> + "bal __get_user_" #__s \ > >... which does not check access_ok() or do any visible equivalents; OK... > >> +#define get_user(x,p) \ >> + ({ \ >> + const register typeof(*(p)) __user *__p asm("$r0") = (p);\ >> + register unsigned long __r2 asm("$r2"); \ >> + register int __e asm("$r0"); \ >> + switch (sizeof(*(__p))) { \ >> + case 1: \ >> + __get_user_x(__r2, __p, __e, 1, "$lp"); \ > >... and neither does this, which is almost certainly *not* OK. > >> +#define put_user(x,p) \ > >Same here, AFAICS. Thanks. I will add access_ok() in get_user/put_user >> +extern unsigned long __arch_copy_from_user(void *to, const void __user * from, >> + unsigned long n); > >> +static inline unsigned long raw_copy_from_user(void *to, >> + const void __user * from, >> + unsigned long n) >> +{ >> + return __arch_copy_from_user(to, from, n); } > >Er... Why not call your __arch_... raw_... and be done with that? Thanks. I will modify it in next patch version >> +#define INLINE_COPY_FROM_USER >> +#define INLINE_COPY_TO_USER > >Are those actually worth bothering? IOW, have you compared behaviour with and without them? We compared the assembly code of copy_from/to_user's caller function, and we think the performance is better by making copy_from/to_user as inline >> +ENTRY(__arch_copy_to_user) >> + push $r0 >> + push $r2 >> + beqz $r2, ctu_exit >> + srli $p0, $r2, #2 ! $p0 = number of word to clear >> + andi $r2, $r2, #3 ! Bytes less than a word to copy >> + beqz $p0, byte_ctu ! Only less than a word to copy >> +word_ctu: >> + lmw.bim $p1, [$r1], $p1 ! Load the next word >> +USER( smw.bim,$p1, [$r0], $p1) ! Store the next word > >Umm... It's that happy with unaligned loads and stores? Your memcpy seems to be trying to avoid those... Thanks. This should be aligned loads and stores, too. I will modify it in next version patch. >> +9001: >> + pop $p1 ! Original $r2, n >> + pop $p0 ! Original $r0, void *to >> + sub $r1, $r0, $p0 ! Bytes copied >> + sub $r2, $p1, $r1 ! Bytes left to copy >> + push $lp >> + move $r0, $p0 >> + bal memzero ! Clean up the memory > >Just what memory are you zeroing here? The one you had been unable to store into in the first place? > >> +ENTRY(__arch_copy_from_user) > >> +9001: >> + pop $p1 ! Original $r2, n >> + pop $p0 ! Original $r0, void *to >> + sub $r1, $r1, $p0 ! Bytes copied >> + sub $r2, $p1, $r1 ! Bytes left to copy >> + push $lp >> + bal memzero ! Clean up the memory > >Ditto, only this one is even worse - instead of just oopsing on you, it will quietly destroy data past the area you've copied into. raw_copy_..._user() MUST NOT ZERO ANYTHING. Ever. Thanks So, I should keep the area that we've copied into instead of zeroing the area even if unpredicted exception is happened. Right? Best regards Vincent From 1583546970971697714@xxx Thu Nov 09 00:41:15 +0000 2017 X-GM-THRID: 1583483345097010805 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread