From nobody Tue Oct 7 21:38:32 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 36A7E22D4D3; Tue, 7 Oct 2025 06:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759820041; cv=none; b=HQx6qppgbTuxxjVY+y+r35qaEujKPRQfkBGLjf4LtBWHVPbl8QjwzRz1B2oRLCf8/IWexVmg3SjxgTILeItm9qWffvXtTORbax9JYw62fcCI+4L6XvYnJvn+5zrds3fAxcTP0Yz9wlQqckleJyPm8BENfvvqpa1+02nw85Iu5IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759820041; c=relaxed/simple; bh=B3Yt3zm5Pr0yTCY/kUb8onQVol3RsVdueR6rzjWl9/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PA06VBz/V7hCNvBxw7sTynlDlcBbIq2C/0j5fQpgDG7vo+6VJ1LQxkKmB2wC/FmO5WO0zXLetaglWMDnhykrTuz38ciOULDrWdFI4lVF2vvtiSe8/AB+gy7giKnBpqZnwSZToJgFKRWrJtM3tFFKNTI1KDcrJZhbC2ng6SEBgc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NB3kRr8V; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NB3kRr8V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1759820039; x=1791356039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B3Yt3zm5Pr0yTCY/kUb8onQVol3RsVdueR6rzjWl9/E=; b=NB3kRr8VOJ2rLxiCHkVTYcTDV3y0LbvS9K0AMGzi30RF5dHRojj7mpYQ Td/ilSa9Cqjk6h71zxb8zx9I++7qwxp1O2yj/MYDkIAbTFTvr17DkytdK yIG9mAuFHKWixIAhZj1hirOFTgTG4Ap7TlE5PPLPLiGlRQd80bETOwlt3 eIcrJqJ/t1APPD3DAKtpnrcLp7md78Z1UbuHaMrBj7uAGFIEk0XMBxLV2 frcqUiZFIZoR36nssIEQXrXETirjf1PRGnjg0uF1W4agp4N1dOv+c5Xyu c+JhqeZ0SFM4KqHVTcK33BaXJCMRqNoqJDUj0mkyEwJB1pp1/kyb8Y8rx A==; X-CSE-ConnectionGUID: zmXTtpuwQ5GslTn7QXNFgA== X-CSE-MsgGUID: pLGqOLpeTyaW1o/xNDJ2ag== X-IronPort-AV: E=McAfee;i="6800,10657,11574"; a="72254403" X-IronPort-AV: E=Sophos;i="6.18,321,1751266800"; d="scan'208";a="72254403" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2025 23:53:57 -0700 X-CSE-ConnectionGUID: rdbhJkAPQBCs6AfnmC+ESg== X-CSE-MsgGUID: 3Ih2UZGCRg6LfApYKm6GFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,321,1751266800"; d="scan'208";a="184354465" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by orviesa004.jf.intel.com with ESMTP; 06 Oct 2025 23:53:57 -0700 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , David Laight , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v10 02/15] x86/asm: Introduce inline memcpy and memset Date: Mon, 6 Oct 2025 23:51:06 -0700 Message-ID: <20251007065119.148605-3-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251007065119.148605-1-sohil.mehta@intel.com> References: <20251007065119.148605-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Peter Zijlstra (Intel)" Provide inline memcpy and memset functions that can be used instead of the GCC builtins when necessary. The immediate use case is for the text poking functions to avoid the standard memcpy()/memset() calls within an RFLAGS.AC=3D1 context. Some user copy functions such as copy_user_generic() and __clear_user() have similar rep_{movs,stos} usages. But, those are highly specialized and hard to combine/reuse for other things. Define these new helpers for all other usages that need a completely unoptimized, strictly inline version of memcpy() or memset(). Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Sohil Mehta --- v10: - Reintroduce the simpler inline patch (dropped in v8). --- 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, s= ize_t len) +{ + void *ret =3D 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 =3D s; + + asm volatile("rep stosb" + : "+D" (s), "+c" (n) + : "a" ((uint8_t)v) + : "memory"); + return ret; +} + +#endif /* _ASM_X86_STRING_H */ --=20 2.43.0