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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D6834C5B572 for ; Tue, 11 Aug 2026 16:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DPBfDxKxUoGsTZQWDQK497a48XaoCti5RkP3xp/cBKo=; b=GgJHmhLfw6jC1qySBuYZIYBbz0 v9BzQz6NTfS1JKmZbcZ71M5MBNGFfJBQ+WaZz089Maez1m9p+l+Hbk5qZGGctadMe6GiG2x4OSUa/ PDyDhH9LwP2gBGLMzEjQt5yupyviSOl2r/sL0/UvMz8ZkyCpOgNaGsNpazWZp7ecPU//yK/Y1P7OO xgo1GY8SRT7LiapMYTMeZeNjgZUPhECgkbIdUir7CZxKWGSezoNybeusBaAMAmMlu4EbJiBLkuuDC 65bpQEulCWfYL01cDesaiLgUhLRyEnjkMH1SlNU+LIuxavSOhRuhhM1b+06GEIIvqL2xXyvLICPmX qa7fWH7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wtpds-0000000EY6u-3vA8; Tue, 11 Aug 2026 16:47:56 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wtpdp-0000000EY5Q-14Dt; Tue, 11 Aug 2026 16:47:54 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 392871516; Tue, 11 Aug 2026 09:47:45 -0700 (PDT) Received: from [10.57.5.246] (unknown [10.57.5.246]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CAF723F86F; Tue, 11 Aug 2026 09:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1786466869; bh=k6fuvdQDvEP8Vgz2PTv5lXUtwGGjwj2b08wkJAsWaVA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=gTV/2I8He3BRcDFubFelv3SAtZiIJOlWDCGYb/PqwlMmSJRZUV+SfPlIf2y0trfly nKQsPwWsI+/aVoYR5dV3ihriAWJ5e9TgHciz8Ikf7zi44esgAkNV9YyJAGhPOgjzVd dWAjOsQ/MfHlSTn8IGEVVhT1EzNUwNUvSRhbFuk4= Message-ID: Date: Tue, 11 Aug 2026 18:47:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 03/22] mm: introduce MMF_KERNEL flag and set it for init_mm To: David Laight , "Christophe Leroy (CS GROUP)" Cc: 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 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> <20260811142507.4c6c760f@pumpkin> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260811142507.4c6c760f@pumpkin> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260811_094753_461604_BB9591B9 X-CRM114-Status: GOOD ( 17.13 ) X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org On 11/08/2026 15:25, David Laight wrote: > On Mon, 3 Aug 2026 15:59:35 +0200 > "Christophe Leroy (CS GROUP)" wrote: > >> Le 14/07/2026 à 16:03, Kevin Brodsky a écrit : >>> 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. >> Did you consider performance impact ? This test is usually done in quite >> critical memory handling functions. >> >> 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): >> >> 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 >> ... >> >> After patch 08/22 we have, it first checks that mm is not 0, then it >> loads the word located at mm+528 then AND it with 0x1. This load might >> be costly. >> >> 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. That is actually an interesting idea. Finding those "kernel mms" boils down to looking for global mm_struct, so checking if mm points to global data would achieve essentially the same thing without a flag (and likely faster). I'm not sure we want to bake in the assumption that "kernel mm" is equivalent to "mm is global" though. - Kevin