From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 F3A1C318EC5 for ; Tue, 11 Aug 2026 13:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454714; cv=none; b=F/OMhvj5Tqv09nJlDJCTtmdyLOtUfJGEdGtDNa5kNiF1EIYvn045NDF50IX6nypMC9m+a3NvvQU065ncYVsO86JD93nMSBK43nGitibwwl7J32yC+drg2j2GEW3R6l+8HsOq4ylY4RFsML/HLp8SULtf10ApP+nhNdJr2OmVxlo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454714; c=relaxed/simple; bh=CJ25QsZC14Dq2xSASACZGaavy+QR/WSe/Ecg1RU88VU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FvYIRL6CXpArL1PY9zr1LZf3spfsIUqXWnH5KC5OfpoHoqJZ0/EhaHmwx1q4+S2Jlfde9XvwA8eKCBmo0EWi4fnFv1o5jP9xRD4spUTTXYSGEHplGLb3WQX0qd5IzwL49qQnuYkq9ce0qvh81IQkGCmIzHASs7gNsqnGhOCyZJU= 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=aVVjsB2J; arc=none smtp.client-ip=209.85.128.45 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="aVVjsB2J" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4957eefd361so23702975e9.1 for ; Tue, 11 Aug 2026 06:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786454710; x=1787059510; 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=HfUDfNxB65XZqovwWVBLkrKpJgUq3OtZ1XoJNMhjK1c=; b=aVVjsB2JYhGhdx99qCJ6JBZOmcxQMEmi9wWgnD6r+EUogwRcu1yy8YWNfKWgWPnnk4 PG0LxxqtTlbIcsUP+3sWkC5HfvgmW4/JCaUhOmj47vK1vUzIgtMdxM8lMYPwm5Wh93AG WJAbxCBoHdhfsuQfuLQPxHCQ4VDqnGdt8FEpbOlPmpKwyiQKvBWf1lrCOhhaA8qeJTjC 5eHMxdFBJgGbASMEm+lwxcqDZlugSJmfkUVptnoSty0lP9trrO4eY2AjBhGBGPCruQk/ 9TGR0qvomoxLIvxSPYD6Lk5FkWNaBemcKJ0aaVlMg4sTyOLCJXU6Ul98oY+Rk433dFdx 1crw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786454710; x=1787059510; 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=HfUDfNxB65XZqovwWVBLkrKpJgUq3OtZ1XoJNMhjK1c=; b=me6yTJTytLFr4pb9Od+kWMy8p3xcWgXApXyABr4XnHk0rexVYmepdgvC8szwOnie3r ddigamRIDLA5t5I6Ar5Ghtpg5DBLMuTSrbiTgjt+BuY1t2TNKrWbvNL2Wfggfys/oYBd S0TNsGzDWTni7C/tcvccv9VlNvuaZsfw9Y5b7CBsatavf2J+xESsSNwZnNJBAsnHV1q1 WhNgzpmAmv/k0BD/DHB6T1dgo0L4y1AlFMUlFuRMHF7aa7o0TUXhaUCvHKDa4mBXrFNH S0VyiU0o8/TzztxariWtQX/jKwt4/B/Ak+wKSEKUMtxzj3Z3BpzAIxWLe3o8NcafCeaw C7VA== X-Forwarded-Encrypted: i=1; AHgh+RpS3kMgcT8KbA5KCvLvefWxzPLphIkVgrkLvEcPvsf4DhItD2+czO44fGOr5DI55kBgkY+z5IK3ceB+zgU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv9gCqKKuUOiUNgIOfnzw3DWCk86/hNFGd0qjo7t8N0ptIT3UB Ofo1jLXXsl7t6NfXb9wnXeps2nudbb12yPg84B1QN+rm+30tYFT3dkYN X-Gm-Gg: AR+sD119qxkLZDbkyQcmnn6qdf4h1OjFPqjg7RUWSog3OI+LVY6ekGjJqQNsrt1NpXU ZfExBnqgc5M4EcDGosUMuUx2b0UK87eKHwyb7k87l0J6Mnx9cDJBTWo+b6EH2z8F+OR9WBhh9h0 6iuSNN9Q/h+J47EfDelcEnrWbjZGRsLCNcH8lCj82eFoc6B24s02DLBK1qgdjkoFHol78aErvkq URlk6Xpsz8TVNplyDg2XTjP50BFB9s+yArQsGQNPYBMEZstCv6DjyaisZ/S9MYSC3+FAFcLZdI9 MN3R8Db44wXpx2ZQUjQkNU+Eg9SmkmbSe8uzggVUEm1cnpaT1qYOwFtj1jT7HbAA0BoYeHfH0p/ mFEfdOoCjiFZYb9dpUJoG5xmtBptdEyE9z+rRturF8FacDply4l7D1yPeTbBY5ZSYVfWJOBY8kJ bLH6liP2RKhUxZnXbZD6Lhszefu8B1xN3yznS+s5sLL1b+zuunh6RQCRTJvNNL0bO5j6KkkepV6 AtL2VwF56Qd/7EixqtrQHyjT366RNUe2ggZ X-Received: by 2002:a05:600c:4513:b0:495:3e08:ad19 with SMTP id 5b1f17b1804b1-49978468c2bmr48261215e9.9.1786454709883; Tue, 11 Aug 2026 06:25:09 -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 5b1f17b1804b1-49977df9489sm83541285e9.1.2026.08.11.06.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 06:25:09 -0700 (PDT) Date: Tue, 11 Aug 2026 14:25:07 +0100 From: David Laight To: "Christophe Leroy (CS GROUP)" Cc: Kevin Brodsky , linux-mm@kvack.org, Andrew Morton , David Hildenbrand , 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: <20260811142507.4c6c760f@pumpkin> In-Reply-To: <01f07ea2-8bdd-4450-8a49-548f8b646cfd@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> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@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 Mon, 3 Aug 2026 15:59:35 +0200 "Christophe Leroy (CS GROUP)" wrote: > Le 14/07/2026 =C3=A0 16:03, Kevin Brodsky a =C3=A9crit=C2=A0: > > 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. > >=20 > > 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= =20 > critical memory handling functions. >=20 > init_mm is known at link time. Before your patch 08/22 there is just a=20 > comparison of mm (r3) with a constant (loaded in r10): >=20 > c0014048 : > c0014048: 3d 40 c1 09 lis r10,-16119 > c001404c: 39 4a 03 98 addi r10,r10,920 > c0014050: 7c 03 50 00 cmpw r3,r10 > c0014054: 4d 82 00 20 beqlr > ... >=20 > After patch 08/22 we have, it first checks that mm is not 0, then it=20 > loads the word located at mm+528 then AND it with 0x1. This load might=20 > be costly. >=20 > c0014048 : > c0014048: 2c 03 00 00 cmpwi r3,0 > c001404c: 7c 85 23 78 mr r5,r4 > c0014050: 41 82 00 10 beq c0014060 > c0014054: 81 23 02 10 lwz r9,528(r3) > c0014058: 71 29 00 01 andi. r9,r9,1 > c001405c: 4c 82 00 20 bnelr > ... Thought... Could the check be replaced by one that checks for kernel static data? That would require that other mm that represent part of the kernel address space be static (and probably not in modules). ISTR there is an address range check that can be used - and might be cheaper than the explicit test for init_mm on many 64bit archs. David