Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965887AbcJ1C3C (ORCPT ); Thu, 27 Oct 2016 22:29:02 -0400 Received: from mail-co1nam03on0127.outbound.protection.outlook.com ([104.47.40.127]:24289 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S938630AbcJ1C3A (ORCPT ); Thu, 27 Oct 2016 22:29:00 -0400 From: "Boylston, Brian" To: Boaz Harrosh , "linux-nvdimm@lists.01.org" CC: "Moreno, Oliver" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , Ingo Molnar , Al Viro , "H. Peter Anvin" , Thomas Gleixner , "boylston@burromesa.net" Subject: RE: [PATCH v2 1/3] introduce memcpy_nocache() Thread-Topic: [PATCH v2 1/3] introduce memcpy_nocache() Thread-Index: AQHSL6D1lerMctkfoESlwuQONZJ2RqC7JYqAgAHydHA= Date: Fri, 28 Oct 2016 01:54:24 +0000 Message-ID: References: <20161026155021.20892-1-brian.boylston@hpe.com> <20161026155021.20892-2-brian.boylston@hpe.com> <58110959.90901@plexistor.com> In-Reply-To: <58110959.90901@plexistor.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=brian.boylston@hpe.com; x-originating-ip: [98.26.140.10] x-ms-office365-filtering-correlation-id: 41e7f331-81ed-43ae-53e0-08d3fed557bb x-microsoft-exchange-diagnostics: 1;CS1PR84MB0293;7:85MrRogsr4FO7mULvmhMY07HpwGvLh92ivWsNSKrZ1FZmowHAFawr3+HdP0pYxTCrD9/oYiY4wlZwHjBlIaCwcZNT4du8BgfYpo7YRVprkcfjXXUQaMlTNZ03wMJskq/Vv/coX4ZkmVP71kL51UZrCyTLNnT6NrnNuij94sYNJH+NYSli8Z0vi9KCPXRPjjpoNkfwgNYtRWj/onz/cfwaDCQm/6dIveFt9W0iOo2zYenV1ZizxRBFo+lz+ymSbuEJ4NNVSQrj6+siIzDBbdxlcNBDtBAFC2K678ZS18y1Ym5ELSS6XCJvI9/a8k9DVLxl946j29HaXOFA2JzKQTsPLaWjN/7foyrSdDb7M2GOB4= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CS1PR84MB0293; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026);SRVR:CS1PR84MB0293;BCL:0;PCL:0;RULEID:;SRVR:CS1PR84MB0293; x-forefront-prvs: 0109D382B0 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(199003)(377424004)(189002)(377454003)(24454002)(97736004)(122556002)(5001770100001)(3280700002)(305945005)(7736002)(4326007)(8936002)(7846002)(4001150100001)(11100500001)(92566002)(81166006)(101416001)(81156014)(106356001)(7696004)(2501003)(50986999)(76176999)(106116001)(2906002)(54356999)(6116002)(99286002)(105586002)(68736007)(74316002)(10400500002)(8676002)(5660300001)(87936001)(9686002)(102836003)(3846002)(33656002)(19580395003)(2900100001)(586003)(3660700001)(19580405001)(66066001)(2950100002)(189998001)(77096005)(5002640100001)(86362001);DIR:OUT;SFP:1102;SCL:1;SRVR:CS1PR84MB0293;H:CS1PR84MB0119.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Oct 2016 01:54:24.2085 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0293 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id u9S2Ugjh011808 Content-Length: 4527 Lines: 124 Boaz Harrosh wrote on 2016-10-26: > On 10/26/2016 06:50 PM, Brian Boylston wrote: >> Introduce memcpy_nocache() as a memcpy() that avoids the processor cache >> if possible. Without arch-specific support, this defaults to just >> memcpy(). For now, include arch-specific support for x86. >> >> Cc: Ross Zwisler >> Cc: Thomas Gleixner >> Cc: Ingo Molnar >> Cc: "H. Peter Anvin" >> Cc: >> Cc: Al Viro >> Cc: Dan Williams >> Signed-off-by: Brian Boylston >> Reviewed-by: Toshi Kani >> Reported-by: Oliver Moreno >> --- >> arch/x86/include/asm/string_32.h | 3 +++ >> arch/x86/include/asm/string_64.h | 3 +++ >> arch/x86/lib/misc.c | 12 ++++++++++++ >> include/linux/string.h | 15 +++++++++++++++ >> 4 files changed, 33 insertions(+) >> diff --git a/arch/x86/include/asm/string_32.h b/arch/x86/include/asm/string_32.h >> index 3d3e835..64f80c0 100644 >> --- a/arch/x86/include/asm/string_32.h >> +++ b/arch/x86/include/asm/string_32.h >> @@ -196,6 +196,9 @@ static inline void *__memcpy3d(void *to, const void *from, size_t len) >> >> #endif >> +#define __HAVE_ARCH_MEMCPY_NOCACHE >> +extern void *memcpy_nocache(void *dest, const void *src, size_t count); >> + >> #define __HAVE_ARCH_MEMMOVE >> void *memmove(void *dest, const void *src, size_t n); >> diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h >> index 90dbbd9..a8fdd55 100644 >> --- a/arch/x86/include/asm/string_64.h >> +++ b/arch/x86/include/asm/string_64.h >> @@ -51,6 +51,9 @@ extern void *__memcpy(void *to, const void *from, size_t len); >> #define memcpy(dst, src, len) __inline_memcpy((dst), (src), (len)) >> #endif >> +#define __HAVE_ARCH_MEMCPY_NOCACHE >> +extern void *memcpy_nocache(void *dest, const void *src, size_t count); >> + >> #define __HAVE_ARCH_MEMSET >> void *memset(void *s, int c, size_t n); >> void *__memset(void *s, int c, size_t n); >> diff --git a/arch/x86/lib/misc.c b/arch/x86/lib/misc.c >> index 76b373a..c993ab3 100644 >> --- a/arch/x86/lib/misc.c >> +++ b/arch/x86/lib/misc.c >> @@ -1,3 +1,6 @@ >> +#include >> +#include >> + >> /* >> * Count the digits of @val including a possible sign. >> * >> @@ -19,3 +22,12 @@ int num_digits(int val) >> } >> return d; >> } >> + >> +#ifdef __HAVE_ARCH_MEMCPY_NOCACHE >> +void *memcpy_nocache(void *dest, const void *src, size_t count) >> +{ >> + __copy_from_user_inatomic_nocache(dest, src, count); >> + return dest; >> +} >> +EXPORT_SYMBOL(memcpy_nocache); >> +#endif >> diff --git a/include/linux/string.h b/include/linux/string.h >> index 26b6f6a..7f40c41 100644 >> --- a/include/linux/string.h >> +++ b/include/linux/string.h >> @@ -102,6 +102,21 @@ extern void * memset(void *,int,__kernel_size_t); >> #ifndef __HAVE_ARCH_MEMCPY >> extern void * memcpy(void *,const void *,__kernel_size_t); >> #endif >> + >> +#ifndef __HAVE_ARCH_MEMCPY_NOCACHE >> +/** >> + * memcpy_nocache - Copy one area of memory to another, avoiding the >> + * processor cache if possible >> + * @dest: Where to copy to >> + * @src: Where to copy from >> + * @count: The size of the area. >> + */ >> +static inline void *memcpy_nocache(void *dest, const void *src, size_t count) >> +{ >> + return memcpy(dest, src, count); >> +} > > What about memcpy_to_pmem() in linux/pmem.h it already has all the arch switches. > > Feels bad to add yet just another arch switch over __copy_user_nocache > > Just feels like too many things that do the same thing. Sigh I agree that this looks like a nicer path. I had considered adjusting copy_from_iter_nocache() to use memcpy_to_pmem(), but lib/iov_iter.c doesn't currently #include linux/pmem.h. Would it be acceptable to add it? Also, I wasn't sure if memcpy_to_pmem() would always mean exactly "memcpy nocache". I had also considered adjusting copy_from_iter_pmem() (also in linux/pmem.h) to just use memcpy_to_pmem() directly, but then it can't use the goodness that is the iterate_and_advance() macro in iov_iter.c. So, I took a shot with a possibly ill-fated memcpy_nocache(). Thoughts on either of the above two? Are these even in line with what you were thinking? Thanks! Brian > > Boaz > >> +#endif >> + >> #ifndef __HAVE_ARCH_MEMMOVE >> extern void * memmove(void *,const void *,__kernel_size_t); >> #endif