Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1575421ybl; Wed, 14 Aug 2019 20:17:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPU5jtGA8FVuJumv+Zln8zTYHCQbtVX2Iyi+cSHEK29Jk58L0tYvyfkEfo3mrPB4odImZG X-Received: by 2002:a17:90a:8b98:: with SMTP id z24mr330731pjn.77.1565839032480; Wed, 14 Aug 2019 20:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565839032; cv=none; d=google.com; s=arc-20160816; b=XOR853hsF+7SKjkOE+PCXGkviX5O+6R7mcTzO28ALkNT172dkmJzdkmw/3bgZ5R1Jn ADznziBWMr6K99+ZKf6GZ6v77DFDCxR3mGqvR7l3Mju1ZChj2uhbD7H6O61c5yAJCxNr NiiB+BqVdMBSkXCaJFGxz1ukb3WVB4i9OLbksFAmFkS4P3WdEwUe4M3T9Zv1GMiadgA8 Di9xk0K9LTMxGfEG1JaFEsudc/VXXjfRhPoWqwlvKRl6uZ2czK+HtIvhagPHGkbZ0AXp H+jZ2g+EAqOE1XcB8AshTrC8JcnKYAo5dVEdFdwBLvKOn9ajHFUYYSWrhoEdscQJ1OdY iEbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=IwdPDFaVkKZGYv++K0TGtHzcaXQv+wz/L9hg1+/F7aw=; b=g9AxbzMuUAA2+QfRlsIgIEaGaT5U9d3QQPg9r5C1aH8IVQ2paKRYGEtIjZMyTvc5jL 1fS2wwJeVxV0k6vnPlO8KzK9t3aLpezg1d4QDSmyw5RJ4NI93SlBv70ax/hKDaOk6d9Y FECQlXMvymi6pnNOACo9idRsVPAmF5NZ5E5H/MHfR530duVOgU8JHav7PDeSUKUmxfLM 4xGdklXqOyhYiMLlCGQ1VgS5OxtfRdBjVrLYgv6hlfQ4nua9Eko1qV6QZvZE5jQD+pnf yV428Ch4mLx+xRThWE6/KokJbJX2MD68x3ba5Lht6wTNRWEuWLiAmyQ0ur/AWr+ru/Ox jOag== 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 l69si1088942plb.302.2019.08.14.20.16.43; Wed, 14 Aug 2019 20:17:12 -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 S1729535AbfHODNg (ORCPT + 99 others); Wed, 14 Aug 2019 23:13:36 -0400 Received: from 59-120-53-16.HINET-IP.hinet.net ([59.120.53.16]:17867 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727217AbfHODNg (ORCPT ); Wed, 14 Aug 2019 23:13:36 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id x7F30l8x044401; Thu, 15 Aug 2019 11:00:47 +0800 (GMT-8) (envelope-from nickhu@andestech.com) Received: from andestech.com (10.0.15.65) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Thu, 15 Aug 2019 11:12:24 +0800 Date: Thu, 15 Aug 2019 11:12:25 +0800 From: Nick Hu To: Paul Walmsley CC: Palmer Dabbelt , Christoph Hellwig , Alan Quey-Liang =?utf-8?B?S2FvKOmrmOmtgeiJryk=?= , "aou@eecs.berkeley.edu" , "green.hu@gmail.com" , "deanbo422@gmail.com" , "tglx@linutronix.de" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "aryabinin@virtuozzo.com" , "glider@google.com" , "dvyukov@google.com" , Anup Patel , Greg KH , "alexios.zavras@intel.com" , Atish Patra , =?utf-8?B?6Zui6IG3Wm9uZyBab25nLVhpYW4gTGko5p2O5a6X5oayKQ==?= , "kasan-dev@googlegroups.com" Subject: Re: [PATCH 1/2] riscv: Add memmove string operation. Message-ID: <20190815031225.GA5666@andestech.com> References: <20190814032732.GA8989@andestech.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [10.0.15.65] X-DNSRBL: X-MAIL: ATCSQR.andestech.com x7F30l8x044401 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, On Wed, Aug 14, 2019 at 10:03:39AM -0700, Paul Walmsley wrote: > Hi Nick, > > On Wed, 14 Aug 2019, Nick Hu wrote: > > > On Wed, Aug 14, 2019 at 10:22:15AM +0800, Paul Walmsley wrote: > > > On Tue, 13 Aug 2019, Palmer Dabbelt wrote: > > > > > > > On Mon, 12 Aug 2019 08:04:46 PDT (-0700), Christoph Hellwig wrote: > > > > > On Wed, Aug 07, 2019 at 03:19:14PM +0800, Nick Hu wrote: > > > > > > There are some features which need this string operation for compilation, > > > > > > like KASAN. So the purpose of this porting is for the features like KASAN > > > > > > which cannot be compiled without it. > > > > > > > > > > > > KASAN's string operations would replace the original string operations and > > > > > > call for the architecture defined string operations. Since we don't have > > > > > > this in current kernel, this patch provides the implementation. > > > > > > > > > > > > This porting refers to the 'arch/nds32/lib/memmove.S'. > > > > > > > > > > This looks sensible to me, although my stringop asm is rather rusty, > > > > > so just an ack and not a real review-by: > > > > > > > > FWIW, we just write this in C everywhere else and rely on the compiler to > > > > unroll the loops. I always prefer C to assembly when possible, so I'd prefer > > > > if we just adopt the string code from newlib. We have a RISC-V-specific > > > > memcpy in there, but just use the generic memmove. > > > > > > > > Maybe the best bet here would be to adopt the newlib memcpy/memmove as generic > > > > Linux functions? They're both in C so they should be fine, and they both look > > > > faster than what's in lib/string.c. Then everyone would benefit and we don't > > > > need this tricky RISC-V assembly. Also, from the look of it the newlib code > > > > is faster because the inner loop is unrolled. > > > > > > There's a generic memmove implementation in the kernel already: > > > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/string.h#n362 > > > > > > Nick, could you tell us more about why the generic memmove() isn't > > > suitable? > > > > KASAN has its own string operations(memcpy/memmove/memset) because it needs to > > hook some code to check memory region. It would undefined the original string > > operations and called the string operations with the prefix '__'. But the > > generic string operations didn't declare with the prefix. Other archs with > > KASAN support like arm64 and xtensa all have their own string operations and > > defined with the prefix. > > Thanks for the explanation. What do you think about Palmer's idea to > define a generic C set of KASAN string operations, derived from the newlib > code? > > > - Paul That sounds good to me. But it should be another topic. We need to investigate it further about replacing something generic and fundamental in lib/string.c with newlib C functions. Some blind spots may exist. So I suggest, let's consider KASAN for now. Nick