From patchwork Wed Jul 10 16:06:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shishkin X-Patchwork-Id: 812372 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 774881953AB; Wed, 10 Jul 2024 16:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720627745; cv=none; b=sUVxPiluZyCVOdh+PPMsJsf72LnOod4cLcpg1xEdMOrIzrQDz8EikVFTxkxatsuY0ivvuofchPySkSywJdojo9gbwugTldT6F2TccZRY36nNp18iuTjFNhsQBvG3u62NHV37StZih1L36JTRQsW2VAGlyrEUuc8RPPqdasIamK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720627745; c=relaxed/simple; bh=aQM7UGNlzhF9E1k1zSnMggUBQ/pMVuwT5GMhaakkhzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JlzAvhlOexMtNkEsoKAeNcsi/zoSJO1BrLLeryOScgyHgmT3xJD5PPAm3sbbYVAexOkt6R2QSuOCnasHS1gAl+GAPk3jY0JMB33Vh/9s1aDWXtQZUoMhjEgy+C7y801kG7HpR5ygSsTXYCX690KK1Z4883ayEO/YIIPwlbV6R8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XEuIfEtn; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XEuIfEtn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720627743; x=1752163743; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aQM7UGNlzhF9E1k1zSnMggUBQ/pMVuwT5GMhaakkhzU=; b=XEuIfEtnbAMzgjwbaI7Z70Wy+W90Sn2PA8N5P6VluxBv2s+lWHml63aE rXSpMZXeUg25Z0WIPhJO9YMRFRr1hJ8B2TTt5RWuAGk95WH+BQCu4XYtv UYnSuPWeieGmXSwkwSUH+8BLBCbyEgiG7UfLVs+Bp9X+NS90d2qMRDZ8V 3uVlr6fnpgsDp66HlWRp3ylC1gfISzggF7fxSG+t5XRQBpQWAnk4hDazz FmEDm6SR47jfBF5hCCzfF7WkYGmgRm0fGYGH6b3/2Qwl/26lZ8vslDRjM WNi5c18StnUnnA1C05oPFCtlpMSBBnJ8UqHCiT3LN2Fu+xVOMiSGon9Fw A==; X-CSE-ConnectionGUID: +2HufQqwQmubnJJyz3QZpA== X-CSE-MsgGUID: jmfpaIzLRJiPa8Z7eqPFUw== X-IronPort-AV: E=McAfee;i="6700,10204,11129"; a="29364718" X-IronPort-AV: E=Sophos;i="6.09,198,1716274800"; d="scan'208";a="29364718" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2024 09:08:49 -0700 X-CSE-ConnectionGUID: VZzz2cXJRLiEWNo7FBsKfQ== X-CSE-MsgGUID: JYLrfBCIQnOkuVNz8AxnCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,198,1716274800"; d="scan'208";a="53084504" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 10 Jul 2024 09:08:36 -0700 From: Alexander Shishkin To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Ard Biesheuvel , "Paul E. McKenney" , Josh Poimboeuf , Xiongwei Song , Xin Li , "Mike Rapoport (IBM)" , Brijesh Singh , Michael Roth , Tony Luck , "Kirill A. Shutemov" , Alexey Kardashevskiy Cc: Jonathan Corbet , Alexander Shishkin , Sohil Mehta , Ingo Molnar , Pawan Gupta , Daniel Sneddon , Kai Huang , Sandipan Das , Breno Leitao , Rick Edgecombe , Yian Chen , Alexei Starovoitov , Hou Tao , Juergen Gross , Vegard Nossum , Kees Cook , Eric Biggers , Jason Gunthorpe , "Masami Hiramatsu (Google)" , Andrew Morton , Luis Chamberlain , Yuntao Wang , Rasmus Villemoes , Christophe Leroy , Tejun Heo , Changbin Du , Huang Shijie , Geert Uytterhoeven , Namhyung Kim , Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 02/16] x86/asm: Introduce inline memcpy and memset Date: Wed, 10 Jul 2024 19:06:38 +0300 Message-ID: <20240710160655.3402786-3-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240710160655.3402786-1-alexander.shishkin@linux.intel.com> References: <20240710160655.3402786-1-alexander.shishkin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Peter Zijlstra Provide inline memcpy and memset functions that can be used instead of the GCC builtins whenever necessary. Code posted by Peter Zijlstra . Link: https://lore.kernel.org/lkml/Y759AJ%2F0N9fqwDED@hirez.programming.kicks-ass.net/ [Missing Signed-off-by from PeterZ] Signed-off-by: Sohil Mehta Signed-off-by: Alexander Shishkin --- arch/x86/include/asm/string.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h index c3c2c1914d65..9cb5aae7fba9 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -1,6 +1,32 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_STRING_H +#define _ASM_X86_STRING_H + #ifdef CONFIG_X86_32 # include #else # include #endif + +static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len) +{ + void *ret = to; + + asm volatile("rep movsb" + : "+D" (to), "+S" (from), "+c" (len) + : : "memory"); + return ret; +} + +static __always_inline void *__inline_memset(void *s, int v, size_t n) +{ + void *ret = s; + + asm volatile("rep stosb" + : "+D" (s), "+c" (n) + : "a" ((uint8_t)v) + : "memory"); + return ret; +} + +#endif /* _ASM_X86_STRING_H */