From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A493411F9E for ; Tue, 11 Aug 2026 08:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786435822; cv=none; b=sgORy7iUvi77+BYThQbNJ86zxuQ6cDS7Osz9ViNbudDp2OcBHtk2mHDUXM+S5hAkgrlLDKcGOTX+c0dCgtu45hGulqK2tTOAIugKbje8DghO0q17+6wb6PdoVBRHVHbwYKnRWL6C9HFPG+V4CbFzapwbRN7qYdXmGrJ70H37M4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786435822; c=relaxed/simple; bh=G1i7Hmp3x4MyiNkQbU9uiF4+QFCGLyrU0CXxtzNpVh0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tzc+4eXSO3hSGxoZp2N2lInJCoMad2olb1y9IkJ8h0besJFWayM0SDijGS7EFVFSwyX31tSPniTZhAWkPni05d7vjjpPP+6iWAI94Zbe/LB18bI80ISMOUeqBmhmIQv5oazv83hKOZlcQbXZuE7PMO+YyjOK7pZibmakgsKLMbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DTKbOcyD; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DTKbOcyD" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-498028b3d5eso31419715e9.1 for ; Tue, 11 Aug 2026 01:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786435819; x=1787040619; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=kRDEH2ssIQhIkVPOR6PkKFR0aBPP8ALbaUyGO3LvVVE=; b=DTKbOcyDMWHb4HoKjhv/LiJSlKcwrGHUJk+pyU3g9T7LB4SHddJnam+zm/RVr4OHVi JmRza0TF3LeijHjPurRsnhis019jAxqy914rzb79tBPQiPUFYYVcQhIVfEjMhLnahSP9 QdoYf4FK0tiz9lQ66/pwZR3SjMyaDMXLAF3lr85IiCDuJ64jysV3XJUjsKMVPp3yT9Su lzVuFGzCT/VFdQ0LCb7YMDBF7SnSGYxmBxYUtkVggOlQrMmpkjX0Vo6KyQ/xil3uxyVI e/kugHsi4X7tcVITCTGS2Ap7GVzZ1FJ2dIUx4oSDR74XtpjavFlQRlL+zGHCLTFdrbHs BrvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786435819; x=1787040619; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kRDEH2ssIQhIkVPOR6PkKFR0aBPP8ALbaUyGO3LvVVE=; b=SuxSz8XsjN6+AXck+EED7R2YxVIMI9jQN6Oef0JB/9hTiJJI4Ej2NlREzGziJSLyoQ LBHuVn/qYxzMkMDw/QTbUt1pxaAZxgVth0WpieaG6ForY95wcXge1hS6zPHBIU+iEzKu En+BQyNpKQDahr8bVU0mVVe3aXugUxyyD5Xwpxww9OV+BYKyw2mTRqTOkrGI8kwP/AtP l3gv2rpWsWFv5R7479MMfCVEaedkyBS3tew3z/siMFLqesdWrNtEnUC89G6vygleZQx7 UIPSA26SpIZzpsuyB/5h0HRovU2nJmsSpVljCq+TMAZ5xvkBj/jzoJuABbZor1by+3gs KpdQ== X-Forwarded-Encrypted: i=1; AHgh+Ro/+/2GBst4v0nXYNZhEiUSu2rz+89dPsWk2DRQSMBIl9Oy6OrvM07+RBbWz5L0U2tXOv5VhJK3UK97@vger.kernel.org X-Gm-Message-State: AOJu0Yy4fLehWb/3urS1RQLiwoFS5NOaehMTC4s2/Fo9LXvV1upxnQaj PSYEH+Y0NqGpILiHBqh8yNokyI1CpE99DpF+iK9hAsItsWJdTfP//jg6 X-Gm-Gg: AR+sD11glrF0jtFeVqboLV0pX7AttgJnoRa+EMGGd81LhSkbhRaH9hHRSG50juVrZR6 ioikx+cWTjNfMSloBwvHIsxAtlqtRIw8fbxsLvj7z9TOB3vzZovJVuMsv28XFnrLHW3mOIDOTEB d85S8Z0vBguEqKYAhDHG8o2CCd0yhMDcK8gR6j+gpohD+nh0l8MqU+46xQk+TNITQWSYuOUTEk0 cMjWKh89XQCnkA0ftj7fOw07cgGQKOXbYKVRQMQpcYXskGkrcEIrhiBQQPbJZCSelD3qiNFZ2dV 3yG5Zpd3QcYlYwLCbPwpg2UVvvANjcLEwnRezbYbsv/8CcP7eG8RZzU35TQwpyFmMZy4vzeiJ13 LzoLBgWNil4Z3l2+GGeXdon/A6BcqoV3jCt8/0m2XovUJPh5eh6qu3cBnPuQCcdEm3Pr7jGuzBd LPlqApksOQcPP0UJYjj832tCqkRVBRwnN8lOKLwBdIk07hNyprgciuwF50hsEkBmzvxAAUdVBa2 I5RFo0RC/MHjF98nxG96Fx2qNoVJUiFRn4= X-Received: by 2002:a05:600c:821b:b0:499:6a92:fff1 with SMTP id 5b1f17b1804b1-4997847e9b5mr25827975e9.18.1786435818734; Tue, 11 Aug 2026 01:10:18 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4814a5ac6e6sm2454288f8f.6.2026.08.11.01.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 01:10:18 -0700 (PDT) Date: Tue, 11 Aug 2026 09:10:16 +0100 From: David Laight To: "David Hildenbrand (Arm)" Cc: "Christophe Leroy (CS GROUP)" , Kevin Brodsky , linux-mm@kvack.org, Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Pasha Tatashin , Russell King , Catalin Marinas , Will Deacon , Ryan Roberts , linux-arm-kernel@lists.infradead.org, Huacai Chen , loongarch@lists.linux.dev, "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Gerald Schaefer , linux-s390@vger.kernel.org, "David S. Miller" , Andreas Larsson , sparclinux@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Ning Sun , x86@kernel.org, tboot-devel@lists.sourceforge.net, Ard Biesheuvel , Ilias Apalodimas , linux-efi@vger.kernel.org, Vishal Moola , Alistair Popple , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [PATCH 03/22] mm: introduce MMF_KERNEL flag and set it for init_mm Message-ID: <20260811091016.5ca67143@pumpkin> In-Reply-To: <33fc9d31-2866-4315-9510-0004deb93994@kernel.org> References: <20260714-remove_pgtable_cdtor-v1-0-44be8a7685d7@arm.com> <20260714-remove_pgtable_cdtor-v1-3-44be8a7685d7@arm.com> <01f07ea2-8bdd-4450-8a49-548f8b646cfd@kernel.org> <33fc9d31-2866-4315-9510-0004deb93994@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 5 Aug 2026 14:07:01 +0200 "David Hildenbrand (Arm)" wrote: > On 8/3/26 15:59, Christophe Leroy (CS GROUP) wrote: > >=20 > >=20 > > Le 14/07/2026 =C3=A0 16:03, Kevin Brodsky a =C3=A9crit=C2=A0: =20 > >> mm code often needs to know whether some mm represents a kernel or > >> user address space. This is currently done by comparing the mm > >> pointer with &init_mm; besides not being particularly elegant, this > >> ignores the fact that other mm's (e.g. efi_mm) may also represent > >> parts of the kernel address space. > >> > >> Introduce a new mm flag MMF_KERNEL and set it for init_mm. > >> Subsequent patches will use this flag to replace comparisons with > >> &init_mm. No functional change is introduced for now. =20 > >=20 > > Did you consider performance impact ? This test is usually done in quite > > critical memory handling functions. > >=20 > > init_mm is known at link time. Before your patch 08/22 there is just a > > comparison of mm (r3) with a constant (loaded in r10): > >=20 > > c0014048 : > > c0014048:=C2=A0=C2=A0=C2=A0 3d 40 c1 09=C2=A0=C2=A0=C2=A0=C2=A0 lis=C2= =A0=C2=A0=C2=A0=C2=A0 r10,-16119 > > c001404c:=C2=A0=C2=A0=C2=A0 39 4a 03 98=C2=A0=C2=A0=C2=A0=C2=A0 addi=C2= =A0=C2=A0=C2=A0 r10,r10,920 > > c0014050:=C2=A0=C2=A0=C2=A0 7c 03 50 00=C2=A0=C2=A0=C2=A0=C2=A0 cmpw=C2= =A0=C2=A0=C2=A0 r3,r10 > > c0014054:=C2=A0=C2=A0=C2=A0 4d 82 00 20=C2=A0=C2=A0=C2=A0=C2=A0 beqlr > > ... > >=20 > > After patch 08/22 we have, it first checks that mm is not 0, then it lo= ads the > > word located at mm+528 then AND it with 0x1. This load might be costly. > >=20 > > c0014048 : > > c0014048:=C2=A0=C2=A0=C2=A0 2c 03 00 00=C2=A0=C2=A0=C2=A0=C2=A0 cmpwi= =C2=A0=C2=A0 r3,0 > > c001404c:=C2=A0=C2=A0=C2=A0 7c 85 23 78=C2=A0=C2=A0=C2=A0=C2=A0 mr=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 r5,r4 > > c0014050:=C2=A0=C2=A0=C2=A0 41 82 00 10=C2=A0=C2=A0=C2=A0=C2=A0 beq=C2= =A0=C2=A0=C2=A0=C2=A0 c0014060 > > c0014054:=C2=A0=C2=A0=C2=A0 81 23 02 10=C2=A0=C2=A0=C2=A0=C2=A0 lwz=C2= =A0=C2=A0=C2=A0=C2=A0 r9,528(r3) > > c0014058:=C2=A0=C2=A0=C2=A0 71 29 00 01=C2=A0=C2=A0=C2=A0=C2=A0 andi.= =C2=A0=C2=A0 r9,r9,1 > > c001405c:=C2=A0=C2=A0=C2=A0 4c 82 00 20=C2=A0=C2=A0=C2=A0=C2=A0 bnelr = =20 >=20 > Is that a real problem, though? The cost of the read is likely to matter most if the branch gets mispredict= ed. I'd also guess the mm isn't usually NULL - so that branch needs to statical= ly predicted correctly as well. I'd also not assume that the mm is in the cache (unless the surrounding code has already accessed it), the L1 data caches are small. David >=20 > What we could do is to just keep the =3D=3D &init_mm check internally on = configs > where we know that there is only a single such MM context. >=20 > Just a thought. >=20