From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C56C77B7C for ; Thu, 3 Jul 2025 12:16:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80DF96B017D; Thu, 3 Jul 2025 08:16:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E5606B017F; Thu, 3 Jul 2025 08:16:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FB1D6B0180; Thu, 3 Jul 2025 08:16:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 610E26B017D for ; Thu, 3 Jul 2025 08:16:00 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 241AA122EB2 for ; Thu, 3 Jul 2025 12:16:00 +0000 (UTC) X-FDA: 83622850080.14.CF92374 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf04.hostedemail.com (Postfix) with ESMTP id 1AB6940018 for ; Thu, 3 Jul 2025 12:15:57 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hM08vU5C; spf=pass (imf04.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751544958; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fjMvLVJkG3DLR0pJeJMNsk2FIgKYYztGrqqpbhLJ8Vg=; b=pL0AafcPKC/CFh5ggUOdjp/6r98QRZSZvO7vqNGUnf4DktbhALOEESXDoVenPQq9PObywO AX8Vr7POT/Ytc2PCL4gRMvZIDupCthAeaqMcu1/S1hXS77BI1U31KUKaI+eeuc1d/6xAfh VHtUNR3IVfjc7MZTUeiIFWAdwEfq1wI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hM08vU5C; spf=pass (imf04.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751544958; a=rsa-sha256; cv=none; b=cpuNovxbvgJ0XmaQpqtS94cVjIwF+cU2gmLI4sgqKSgi7jzY1oqFratMpQ1xZ5zmhQmr46 R2JYe9CVRWpdGA7xkHYKTr8I9fySADFYD0xaGmsUpyi0ypXfHnjtacXCrilf8+AwBB7/kO gj+yIBpK4HNsmAsmHHzP3AHkgxIFjEA= Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4538bc1cffdso52677925e9.0 for ; Thu, 03 Jul 2025 05:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751544956; x=1752149756; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=fjMvLVJkG3DLR0pJeJMNsk2FIgKYYztGrqqpbhLJ8Vg=; b=hM08vU5Cesilbgv0w/2NrorjtqqFnwF+dbrUrvdQsyzkBsvh7OFWTOZ0WnEo9cxXaa 2j0KS4t5WcGis7AB6K0/vaIYAemRdhLHcg7SDK9xwqFlciVz5BKwlivsHaAPmfjmE2wS 5zcDEcdmMkH6MlA6vXzshu0V4igG1KE3UNSIH99ZVmW2+4+FFXHreyGmjm90NCYbl42Y MIskvZpArVivMrW+0SIkELK7wSb4HLb5MvHfCojJrixRtZ/JLyd6D0BEkgnSq9uMoHXJ mH7o8a1FWXEvOEWO1Nd+nV3lNEiXdHJGvtnIRuUHTU61oNhmYuiJVYn29r8uybL3wBVR 2FjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751544956; x=1752149756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fjMvLVJkG3DLR0pJeJMNsk2FIgKYYztGrqqpbhLJ8Vg=; b=wuQaueiFzNEIABGTkIuHpQKJyr/aHPoQCfvoaop/AC9FLtMJ26HYHubU05NHsvEgQU YtODeIBWw5MW90erLLHvlxGLnHpysfU+6l8LlQ5A4Kl9ocWWR4gqdnfV+Iya1vwd8Ji6 3SQKrP/+yw4GKjnDkcG28A9nPmpf3Ujt6XgDQbOqZmhRj2wLLj++wCH4q2FYLzv1sgAG 5uR4ZMznda72cjWjYRUbdYSxSzuyQPk5V/zvYwkC4iO/mhRnTlFSvR0wYSBkMJZ37o4q BKSdQtdjadc1m8g3Jxvo5iXVuDHMdU/enWzAbMjxyZRIJhql9YxI21Qxj60+uOJH1oit Df8w== X-Forwarded-Encrypted: i=1; AJvYcCW0NybjYmnJWbk67eFbd2rm1nlj5Qm8SVsZDcJQZUa2FkJeW3HRs4eB90oJ2rv3Ui+CA8UvfkP15Q==@kvack.org X-Gm-Message-State: AOJu0YzSQ0pdjGRGkVTTJexzSDcFM4dZJrl9t6Xhi6WubxQRmtEY+F/9 jrbZ0g19z2QJW7cn7R0XkrNmiQYfzU3DUaw0ckM1Jt3Nc32yQnK2JQhn X-Gm-Gg: ASbGncvhMSrqxiomUGIkAeNUbIOC3AwVFXAAMqa7ACi4MfbbnkXQu+aKH3Mgk632RRI OXDJwuNGkuYASbxEwHGQNHNcIr0wrENKlQCz0cLtfhVmM+uX+4BUm/XHeKnQKvvsbeWOazPDxkr v6xqBfi++hDgSUvu1rNCa3yUvyyKU3n8FIm8okC7x7iUYPHt9E9ABiqqFf+3HiPxj/Skr9Ky4NL GOWwLBIvpDAROiQpJHAs6+WZqYM5K/TJVKSg3DqWj7oOQai/aSQaAWWRfElPic+Ybd708JhVq7q yNfesCZxX/O3Q6Qv2JJoisjAxn/Y8Gs6k/I7Ix7KTAFq0b1bV7wDM/ooQO6GOQauWTbP2HUWGhL 0RXHjhXCeoVIX7aQdtw== X-Google-Smtp-Source: AGHT+IEbZue8yadMnQtopoEHxvAnbFuBwD4toLz97BG9bsjvN++9UjAqjnNo7mMwutXFoxmlxqUMSg== X-Received: by 2002:a05:600c:c085:b0:453:9bf:6f7c with SMTP id 5b1f17b1804b1-454a36e2a5fmr58086605e9.9.1751544956230; Thu, 03 Jul 2025 05:15:56 -0700 (PDT) Received: from pumpkin (host-92-21-58-28.as13285.net. [92.21.58.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a997b492sm25326485e9.13.2025.07.03.05.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 05:15:55 -0700 (PDT) Date: Thu, 3 Jul 2025 13:15:52 +0100 From: David Laight To: "Kirill A. Shutemov" Cc: 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 , Alexey Kardashevskiy , Alexander Shishkin , Jonathan Corbet , 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, linux-mm@kvack.org Subject: Re: [PATCHv8 02/17] x86/asm: Introduce inline memcpy and memset Message-ID: <20250703131552.32adf6b8@pumpkin> In-Reply-To: References: <20250701095849.2360685-1-kirill.shutemov@linux.intel.com> <20250701095849.2360685-3-kirill.shutemov@linux.intel.com> <20250703094417.165e5893@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1AB6940018 X-Stat-Signature: xw6co9h9chsb1bqk14bt36j4ytxn3he5 X-HE-Tag: 1751544957-340489 X-HE-Meta: U2FsdGVkX1/Pd4XVTQk344QfdI8sRgr+IZLYWs1Yag2dqQKtqtguHp2TOWqN57crzlIXpQXUj4T7D9mppouWmWgJLnPTcFHmqJ4mWGbH60iu9bfyo+gPouv7mcxcjqf6L9Zt58JstcfWW3Ixb/FjyJ894ksgLirgpIu0VrNsK8ntY6bHR5yTPIAuJbgshXZ3H6dMv2iQZqZdJzcGQf8busEBeIvuzqtjNsY4bHP5ZUbZkxP+UQaweAKvod96/cb3xIElAVqDqHWfENcE5m9r11IbFmEcYvggM93zc18pZcGRN1WtD0Jpm+muWcHM2IWoyqa327qk+x/lYlthkqMvZeVNqYDzStf3b6r/w+A8XpCZ9VQ45HR5y0fNBTSc4hiyU7VLx3csUiafZtIHiI89iFUllyLyo1sJ7v4kAhsEQB1gMaTI6JdJayFpjyOVRjl1yT2z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ueJpMeTZkFBdkU1Uw2I8t6uhY1ui5N065nev5FUCCPn5wx+wu0QGuNue3amp6bB8ViI95bXGjfzJA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, 3 Jul 2025 13:39:57 +0300 "Kirill A. Shutemov" wrote: > On Thu, Jul 03, 2025 at 09:44:17AM +0100, David Laight wrote: > > On Tue, 1 Jul 2025 12:58:31 +0300 > > "Kirill A. Shutemov" wrote: > > > > > Extract memcpy and memset functions from copy_user_generic() and > > > __clear_user(). > > > > > > They can be used as inline memcpy and memset instead of the GCC builtins > > > whenever necessary. LASS requires them to handle text_poke. > > > > Except they contain the fault handlers so aren't generic calls. > > That's true. I will add a comment to clarify it. They need renaming. ... > > > diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S > > > index a508e4a8c66a..47b613690f84 100644 > > > --- a/arch/x86/lib/clear_page_64.S > > > +++ b/arch/x86/lib/clear_page_64.S > > > @@ -55,17 +55,26 @@ SYM_FUNC_END(clear_page_erms) > > > EXPORT_SYMBOL_GPL(clear_page_erms) > > > > > > /* > > > - * Default clear user-space. > > > + * Default memset. > > > * Input: > > > * rdi destination > > > + * rsi scratch > > > * rcx count > > > - * rax is zero > > > + * al is value > > > * > > > * Output: > > > * rcx: uncleared bytes or 0 if successful. > > > + * rdx: clobbered > > > */ > > > SYM_FUNC_START(rep_stos_alternative) > > > ANNOTATE_NOENDBR > > > + > > > + movzbq %al, %rsi > > > + movabs $0x0101010101010101, %rax > > > + > > > + /* RDX:RAX = RAX * RSI */ > > > + mulq %rsi > > > > NAK - you can't do that here. > > Neither %rsi nor %rdx can be trashed. > > The function has a very explicit calling convention. > > What calling convention? We change the only caller to confirm to this. The one that is implicit in: > > > + asm volatile("1:\n\t" > > > + ALT_64("rep stosb", > > > + "call rep_stos_alternative", ALT_NOT(X86_FEATURE_FSRM)) > > > + "2:\n\t" > > > + _ASM_EXTABLE_UA(1b, 2b) > > > + : "+c" (len), "+D" (addr), ASM_CALL_CONSTRAINT > > > + : "a" ((uint8_t)v) The called function is only allowed to change the registers that 'rep stosb' uses - except it can access (but not change) all of %rax - not just %al. See: https://godbolt.org/z/3fnrT3x9r In particular note that 'do_mset' must not change %rax. This is very specific and is done so that the compiler can use all the registers. > > It is also almost certainly a waste of time. > > Pretty much all the calls will be for a constant 0x00. > > Rename it all memzero() ... > > text_poke_memset() is not limited to zeroing. But you don't want the overhead of extending the constant on all the calls - never mind reserving %rdx to do it. Maybe define a function that requires the caller to have done the 'dirty work' - so any code that wants memzero() just passes zero. Or do the multiply in the C code where it will get optimised away for constant zero. You do get the multiply for the 'rep stosb' case - but that is always going to be true unless you complicate things further. David