Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2315932ybl; Sun, 18 Aug 2019 23:32:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyJzwE4eb2tOHZ/pQ3jiIBY2EkALtVQZ2761k6ZWJ/hfOf2/xsS/q2lk1cEuZeU+bK1dDc X-Received: by 2002:a63:1918:: with SMTP id z24mr17741209pgl.94.1566196351070; Sun, 18 Aug 2019 23:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566196351; cv=none; d=google.com; s=arc-20160816; b=MQmqxY//ICZn/C4eMs7cWieLvoX6nzpryZiTa1Ko2r5kcV/1TFyfdQhKm+8aAirjNa TIwq+OVE0qJiLm27MBAuqnehVj9gNYebYGunAcVbyp28UHrYL3W6QuHDmKclpZMe6rVv Uvz1c4RjsAAk/nw85EQnjhio5NEIjp64649gNC5VK/3Ap2aCem1IDeMqvCxe0l/07kcY IyC0kxqhLhK0CpipKr/B7qWQdkcoKLm3RzB27oDojQlublmIkWngWmqS6h+q100GGkzr 5wEGC5CWS4JOeyjeRMaefW6FyRIyZOzZIg2sMIqWU6kmTfcgkzjSdhwTmlKBM4I3s3MW ownw== 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=AsbuCL5KX44Zc/fmI+dhU1r9ok078/v73DrYIRzV92I=; b=drEWURzYjRpaebHX5X2oyxcDP4Ry2eGRcMH2aJxOmTGW4A3QLUasknaMY/+bCGpSfo SrCnUaH25odRBWTB37kTp8X2elsrnttGeqyyDOLDr66dR14L+5LJZCxCLj+vGXwAsXtu VjWRUU81hwQniF4IoFNoVcQthMlTgxIrkS2FWvQEDM/XFPISakGkSnd0ANn91/QqHTOU bMbtb4I6nEmYUJkEXfaJKU3riST6KmaRB9vepY8Bf6Pp9GmLdbQvJHD6/ktRYzE8X+Fy My1ZDjNldQObDECIMp8xv5J+A7E+e8A0Q1DzuPgEYTDHdGWNssRsQbQW3IJD74yZwPmd p+Zw== 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 w3si5366495plb.51.2019.08.18.23.32.15; Sun, 18 Aug 2019 23:32:31 -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 S1726776AbfHSGaq (ORCPT + 99 others); Mon, 19 Aug 2019 02:30:46 -0400 Received: from 59-120-53-16.HINET-IP.hinet.net ([59.120.53.16]:24619 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726174AbfHSGaq (ORCPT ); Mon, 19 Aug 2019 02:30:46 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id x7J6HLhb095426; Mon, 19 Aug 2019 14:17:21 +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; Mon, 19 Aug 2019 14:29:18 +0800 Date: Mon, 19 Aug 2019 14:29:19 +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: <20190819062919.GA6480@andestech.com> References: <20190814032732.GA8989@andestech.com> <20190815031225.GA5666@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 x7J6HLhb095426 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, On Thu, Aug 15, 2019 at 11:27:51AM -0700, Paul Walmsley wrote: > On Thu, 15 Aug 2019, Nick Hu wrote: > > > On Wed, Aug 14, 2019 at 10:03:39AM -0700, Paul Walmsley wrote: > > > > > 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? > > > > 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. > > OK. Here is the problem for us as maintainers. You, Palmer, and I all > agree that a C-language version would be better. We'd rather not merge a > pure assembly-language version unless it had significant advantages, and > right now we're not anticipating that. So that suggests that a C-language > memmove() is the right way to go. > > But if we merge a C-language memmove() into arch/riscv, other kernel > developers would probably ask us why we're doing that, since there's > nothing RISC-V-specific about it. So do you think you might reconsider > sending patches to add a generic C-language memmove()? > > > - Paul About pushing mem*() generic, let's start with the reason why in the first place KASAN needs re-implement its own string operations: In mm/kasan/common.c: #undef memset void *memset(void *addr, int c, size_t len) { check_memory_region((unsigned long)addr, len, true, _RET_IP_); return __memset(addr, c, len); } KASAN would call the string operations with the prefix '__', which should be just an alias to the proper one. In the past, every architecture that supports KASAN does this in assembly. E.g. ARM64: In arch/arm64/lib/memset.S: ENTRY(__memset) ENTRY(memset) ... ... EXPORT_SYMBOL(memset) EXPORT_SYMBOL(__memset) // export this as an alias In arch/arm64/include/asm/string.h #define __HAVE_ARCH_MEMSET extern void *memset(void *, int, __kernel_size_t); extern void *__memset(void *, int, __kernel_size_t); Now, if we are going to replace the current string operations with newlib ones and let KASAN use them, we must provide something like this: In lib/string.c: void *___memset(...) { ... } In include/linux/string.h: #ifndef __HAVE_ARCH_MEMCPY #ifdef CONFIG_KASAN static inline void* __memset(...) { ___memset(...); } extern void memset(...); // force those who include this header uses the memset wrapped by KASAN #else static inline void *memset(...) { ___memset(...); } #endif #endif Does this look OK to you? Nick