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 87ABEC8303C for ; Mon, 7 Jul 2025 08:02:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C0776B03FD; Mon, 7 Jul 2025 04:02:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2709B6B03FE; Mon, 7 Jul 2025 04:02:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15F966B03FF; Mon, 7 Jul 2025 04:02:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 05E176B03FD for ; Mon, 7 Jul 2025 04:02:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B4D6210A841 for ; Mon, 7 Jul 2025 08:02:23 +0000 (UTC) X-FDA: 83636726166.12.525BBFF Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by imf07.hostedemail.com (Postfix) with ESMTP id F3D704000C for ; Mon, 7 Jul 2025 08:02:20 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=HNlsQzDW; spf=none (imf07.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 198.175.65.12) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751875341; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ucZIHc+V/gIQi/FUEY5sL8mbI+XUF5u7uhmg3qsnpLM=; b=TlZZtJnHqzC7rtDSdlVPfw2yOYilsWR4++1iypBeWka0RO60J59QQ7dSmM08ZiBpXl2bLY W21NkssLSYpl+ZmpL99ceaIe6bJVhZz7J5+xJMMvflATMtr73ykQcHmsJTCveNow1N95Et YjJticD31XOB+JDBg6gtLU/5DPDZUg4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=HNlsQzDW; spf=none (imf07.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 198.175.65.12) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751875341; a=rsa-sha256; cv=none; b=wANJ9NUigxUV8zi0wmhciqOX+NXEPcY5aJ8rEh0KuvvVI9MhfNVw/cWIWvKAcFvPyNYOpE 0oic1VZRd5/VQSomdY7oIobI+yIWISjFMvW7JxbaeRgabnOkb67Qa0NGQfIUHx1qKVKUj1 OcJVsKme9GnRZPGmemssQaJffKZLkuM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1751875341; x=1783411341; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=N7TeHc8uA+dRWRGg8sis7a69LSQxgrglsAuwm+wt4Co=; b=HNlsQzDWp5tsE7LtWubNoIuNC1AyC1OmNrnZO4F2l/Dm0bVUbVer4+VL GmQaw7DWnWH7DaOa1LpdAhiuKiUie02jBVBZ9tSaSCW8mrdwR0ErsmhzH 8MeXx1/I6M7owX/f4+hc3sNUYpON8egOqXW+XQLo1mSV2e7QK8Zc/UHtw wNsD2b8VobqObk46u3pZsFpDtLZkGuXwiYaWAb3trE29U183/z3QHM4uB IGWEcZJ1u6knOqqu+vJ1+6FX6g8knWemR3HFJI0VFj03nUgFMyIMRWXrL EIcppoox7cKJjc9E4/qOKYQ2GrGo/UtfImyXb73i89TkryyOrrsol4DPe Q==; X-CSE-ConnectionGUID: wDBlkBX0SlOqZ1N2ZqvZ8A== X-CSE-MsgGUID: /7Rbl/q4S8q9fGuLDb3zdA== X-IronPort-AV: E=McAfee;i="6800,10657,11486"; a="65541976" X-IronPort-AV: E=Sophos;i="6.16,293,1744095600"; d="scan'208";a="65541976" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jul 2025 01:02:20 -0700 X-CSE-ConnectionGUID: VSf3HB/2Qi+d4IAoxJBfJg== X-CSE-MsgGUID: rAXXNYSFSwmLSxUNL/u5dQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,293,1744095600"; d="scan'208";a="154565268" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa006.jf.intel.com with ESMTP; 07 Jul 2025 01:02:08 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 5DB11182; Mon, 07 Jul 2025 11:02:06 +0300 (EEST) Date: Mon, 7 Jul 2025 11:02:06 +0300 From: "Kirill A. Shutemov" To: David Laight Cc: Dave Hansen , 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: References: <20250701095849.2360685-1-kirill.shutemov@linux.intel.com> <20250701095849.2360685-3-kirill.shutemov@linux.intel.com> <49f7c370-1e28-494b-96a9-f45e06ed4631@intel.com> <20250706101342.069b5068@pumpkin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250706101342.069b5068@pumpkin> X-Stat-Signature: ftwum1z1ahrf7kpbqphzd9aeyugwsn8c X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: F3D704000C X-HE-Tag: 1751875340-662448 X-HE-Meta: U2FsdGVkX1+av8R4l2RxDLwGmTBQTgyvIsaByCUXlQTLKZa0FDi5YzW+DmCileNRTrET92YvZVkswaF0n8XJ9LN0M36SMQwUUrgWrzwBxGTO2w4ys4u7fiuRrtq1y9hZ+dOlKLjqYZQKZ0WAG3yeMfNR7XFI+8kTd1S+ywDlTZyZJW5rkrxX92Tv3GxGgQPJCWW9CbqrOYjjqo1nhyGchuB65DHMj9odYMG3A//D+TXcYfFt4MG4baBDMCAqe4JVq/Wo7iKrr5UOmermOKkXnd1biCDN2FjSuIrlPhq5majRw46Ie8gKAtwHBTsnMjEWamYqyXkafJH+ZeWILq0d6YHW8cZPDo//4aipbNl5USvuKC21H4DY2orinXXgCQ21LXEPCHzhz++ZtWq0m8gKQU77iQtLnCVwliWhVcj0l7OAAfAW3s3OPlxJWVYR17AiSlv8A/H3VknOSY5XYe8HZsqoU5R+N3JswPFWpHUpsucMSTizBBQ9WDUCXR8ZGcwDGD8F2ufENjeB5+VwIL5UFTiai3ex4a8P2RMPTPFBfw2mv+S4mt9r9N/JoiUq1WoiJZmkcyl+j2JxhUaATI4LIgQJYoezXMvbN3krBkvDlCvbT8FtWCiSmEvagu/VhA2amvIFYzhDD69EZ6jw+wDoqCi699YtrRAxrznfrlRPBdohUKm37mbOD6sVCvOp/2XSlDKMgDU2L8XGah5Lwbv4+HeNMvEF0S8x0LDUz1+8zp0/bjOabt8R+2gJg0z4cG2nVKQ2b47iKAlE6s/3u4BuCmGiPgTQMKGFS/je4rKSgI4rwkTR6Jrl0qKgaIRcWEvsb0c4ZOdyPqkvvk98c0P9V3GEbzkwQUSapz+Hh/t5pZj/V82AgEkf1wGiTh9+7oCcv6c1Y983pZLXZu2eakUI1tKXSH3oCBVcWtkfnBdZ9r8w31FPBE9zgbU0MiNDQ7gB9wldY0lBj+QcvJge18H 52oZKh9M r01nZ3A3nKpWl6JwncrpHh0JD7XWoxLWQb8aq6NAnK+7R4el7Elki5beDKi8WiY/eNNna4KNANg8VDLJC7fMGsPjAvM20oaT3a5JfpxBMvkXCudLdnQXEujrohrxkh1izYifOYT7PdL7cdEFa7ufdhwF+rcLzw2BRNzTirERrAWvfm2/Gv60AXG7ZsVlF9uUjPo8AZ7hKnAz1HyJSgVnyQqivrt1cWQpS4t54FB4eCRlGsAKD3278RhQNgo8XueMWMaAjwGhM0T+FB231jFiw6N76RqbjMC37Ai6SvSzEQ40mKlOzxYexIn2qKiJlaE4YBbDEoeYaesbB0Qk= 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 Sun, Jul 06, 2025 at 10:13:42AM +0100, David Laight wrote: > On Thu, 3 Jul 2025 10:13:44 -0700 > Dave Hansen wrote: > > > On 7/1/25 02:58, 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. > > > > Why are we messing with the normal user copy functions? Code reuse is > > great, but as you're discovering, the user copy code is highly > > specialized and not that easy to reuse for other things. > > > > Don't we just need a dirt simple chunk of code that does (logically): > > > > stac(); > > asm("rep stosq..."); > > clac(); > > > > Performance doesn't matter for text poking, right? It could be stosq or > > anything else that you can inline. It could be a for() loop for all I > > care as long as the compiler doesn't transform it into some out-of-line > > memset. Right? > > > > It doesn't even really matter if there is an out-of-line memset. > All you need to do is 'teach' objtool it isn't a problem. PeterZ was not fan of the idead; https://lore.kernel.org/all/20241029113611.GS14555@noisy.programming.kicks-ass.net/ > Is this for the boot-time asm-alternatives? Not only boot-time. static_branches are switchable at runtime. > In that case I wonder why a 'low' address is being used? > With LASS enabled using a low address on a life kernel would make it > harder for another cpu to leverage the writable code page, but > that isn't a requirement of LASS. Because kernel side of address space is shared across all CPU and we don't want kernel code to be writable to all CPUs > If it is being used for later instruction patching you need the > very careful instruction sequences and cpu synchronisation. > In that case I suspect you need to add conditional stac/clac > to the existing patching code (and teach objtool it is all ok). STAC/CLAC is conditional in text poke on LASS presence on the machine. -- Kiryl Shutsemau / Kirill A. Shutemov