From patchwork Mon Oct 28 16:07:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shishkin X-Patchwork-Id: 839420 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 EFA4F1DE8B4; Mon, 28 Oct 2024 16:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730131805; cv=none; b=CvddahfIfxqks4BaqKDWkmW88PS3M+VG1soRuOB5U5zD+PpC1Oz3BxXzcNioUTv0fDJJQyChke2/GlYrRqGHWJjJt5YjMmLPaIPGJKh+l6/CwamS6qMD4HxYVP1U81hZdGq3oGwZSTnF48jP1pPrLZyHOPjrRD9HBpOHsnHjKy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730131805; c=relaxed/simple; bh=T4m18ALGG4J3cKrkik1Jy+xt03Z4Z7JTblDpkh0f7Tc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bh76WWPp7ydZ5Lhk3nG6ZKkTfwvaYO9mVVGwoqgLei9Bh+eCmZxvEbF0aH+CRbZj9rpkQi1WKC39RHrSn7J5OKBqMYCLTunTUVGp/v+fD/cKmIsrH1syZpIRDwnQoHwqrYlUc4eJta2TsLDLLbDggBkmM068oeebMewrCtjPULA= 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=GlUOs2ad; arc=none smtp.client-ip=192.198.163.13 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="GlUOs2ad" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730131804; x=1761667804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T4m18ALGG4J3cKrkik1Jy+xt03Z4Z7JTblDpkh0f7Tc=; b=GlUOs2adEpUcwedvFLp81s8lTJ8leZ446gD/C9ttgJ5YkvC9cj2D0hns 94mVFPJcYljzvo7tCetvVqZsBAmxHluANnwFz8rt+hDA9EHjY8Nomcr2L ehEm280W5/2L1oa93C0lCh1PdnJ5XrmrUV2PvksW56CDse063HEXO31sn J1shv9JKwBG6dvWWjxMcdFhrSjGFaCn1WluTgeI/OKdtoC66iXN7+eeBY 8BcTnxWxFv356qE3DzOVYIKAD9cvauhgo8n2UjS01t3/wSJOWFPckbsih YxBDe1eNDiyf3LI1bJLa4SqjnZqHiRvkjVs12MIR0MPp8EQT2vWHN8At0 w==; X-CSE-ConnectionGUID: 6XHherLARpyAjodgf7JtZw== X-CSE-MsgGUID: iUiM124DQwCz1Ap+xiizmQ== X-IronPort-AV: E=McAfee;i="6700,10204,11239"; a="32593735" X-IronPort-AV: E=Sophos;i="6.11,239,1725346800"; d="scan'208";a="32593735" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 09:10:03 -0700 X-CSE-ConnectionGUID: If/wbgxpTReBBIBuv3Bdiw== X-CSE-MsgGUID: hWjtEhF4S7yhzDm8sAg4QQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,239,1725346800"; d="scan'208";a="112477831" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa002.jf.intel.com with ESMTP; 28 Oct 2024 09:09:51 -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 , 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 v5 02/16] x86/asm: Introduce inline memcpy and memset Date: Mon, 28 Oct 2024 18:07:50 +0200 Message-ID: <20241028160917.1380714-3-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241028160917.1380714-1-alexander.shishkin@linux.intel.com> References: <20241028160917.1380714-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. Originally-by: Peter Zijlstra Link: https://lore.kernel.org/lkml/Y759AJ%2F0N9fqwDED@hirez.programming.kicks-ass.net/ Signed-off-by: Peter Zijlstra (Intel) 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 */