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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19AF1C5AC67 for ; Tue, 11 Aug 2026 09:00:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27B486B008A; Tue, 11 Aug 2026 05:00:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 252E86B008C; Tue, 11 Aug 2026 05:00:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1445A6B0092; Tue, 11 Aug 2026 05:00:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id ECD166B008A for ; Tue, 11 Aug 2026 05:00:33 -0400 (EDT) Received: from smtpin07.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 795AC40361 for ; Tue, 11 Aug 2026 09:00:33 +0000 (UTC) X-FDA: 85088392746.07.953E3B9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 8E6CC140008 for ; Tue, 11 Aug 2026 09:00:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=arm.com header.s=foss header.b=p0EklLMH; spf=pass (imf09.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1786438831; 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=QyeeOcqJB+URGAwRe+Og0D34yFM6sgFjPGvLOxK7FFo=; b=V2F/yDA4HyeVMK1fe234CdjkCNcX4LwY2BzBOPuq45WNEv620R4yT1oZhxZbasvUo3EOFB xq+AhuXXHa31u/scOVUIkwAtYz3ktTNWoIunyaTg+1KylIFhABjE3LA7CFcb0tvkPHr/Js UggjoHUEN+QWlF5Yk664f/0ceJklj48= ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1786438831; b=kwAYNOnADjjLKZY/zQgesNx8cSxI8r852v7QvynqKHUnhCGNgNKZ03x5ytJdku5aSGOrGY KJgDOzYs/17NEA3L57nVzojBQNq+2+4g04Ixoq11qQyAOjWc77KsqTywTl6rXPStoJv5QR v/wARlhGknNz8mFWaMtPuN566OLCS6k= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=arm.com header.s=foss header.b=p0EklLMH; spf=pass (imf09.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 7549F1516; Tue, 11 Aug 2026 02:00:26 -0700 (PDT) Received: from [10.57.5.193] (unknown [10.57.5.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3B19F3F86F; Tue, 11 Aug 2026 02:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1786438830; bh=tUiTGK9kLGJYJG38Hawj4v69yMlo3kmE+u/Tuup4Yg4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=p0EklLMHJGrKLnVqOINCl1ZfxhRZ+BNvpIRznN2rLsga1Dwdloi6U4xuE1VCQAm02 kBFiXP3tqlA3ARY2zoYWjzb5WjBU+6w3Cb3dcRQRjE/0+/SN3iB10dvAMI84fhbPXQ 52YnfLEkfwAxucsSI1ar27PS56iSCcvkFqLRrZM8= Message-ID: <643a624d-0106-44ed-a7f5-aaf9316f94fd@arm.com> Date: Tue, 11 Aug 2026 11:00:09 +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 , "David Hildenbrand (Arm)" Cc: "Christophe Leroy (CS GROUP)" , 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 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> <20260811091016.5ca67143@pumpkin> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260811091016.5ca67143@pumpkin> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspam-User: X-Stat-Signature: 53oz4ekdzh5c69zejgknmm1wy6speigr X-Rspamd-Queue-Id: 8E6CC140008 X-HE-Tag: 1786438831-635333 X-HE-Meta: U2FsdGVkX1+IZT/7i1NCwcAlVNZAuZqjR+aiHH4vaM9qPYLm0f2RbLP7LGFTf+aJ6jUuXEWLW/qNYxEFYxyBjP8MK4bXw5tOPYX3u3pLY9gQgMV2TV1ucL0xwvuF4pHve9I/TuW4DWc5bzX3Hhxdhv26/lf3ZN5EfvrcwUNSJ4LJa3Q7j+7tGpu5FIHpk49Y0tdz6tZ2yIOnl5/4xmeZX6cUUXhXCnPO0RELhz6ZqRIW42j0Svo1QsFBHcPREKAtbyMlD0cOQO0+nS7psqWy3VqvfXd0SFNkQAq53hJWbVIrZw8KfSiCFQMxb11k+gceRPbK1IJfjeCDlso2jhrWS1IDs/NXR30VA3SPixZQXMnz7TOORhiqtyCMsm94jYRJkWf1bED1f8+1N/F7nV1bbGvQ8qRoE9uYMC3+l/GYvqDNA5soqNhOj2VATEorfr3pCq1dTim56tLTdAw/Bm2ZmEQKZMVlPXNtHtpNX0bSjgOhsnLvez8n3dJlxpnNvN2ggErgu7dwMDajp0eYyfx4eDbWC7oeSyfZGq85kZ5iPTs3A/3QprmltNpfEN1Te4xuJmMtxghQmyUro9zYCU2dLGc1Oh3fxE6V3G8IKWJ38ucKTkNPDrrs7GifBfgc7TedLmTeg77CH8AkqQ5yNM41vf/GZFFSKaGNZmHBUjJTdkM8pCmkzNHZtiBr3qayLkVtRwRy/kAuG2L6lU2Q4Ic5lM2daH5dsVBSLeKN8dsI75eu4RtHC6L6GL+BJm5HaFH1RN+gvmrqRoyYUc3eLkNOOttot2owOK59vv9on7Jf2T6oJjk3Y3EFgxHIG0GcGM1QTuleNmlLYJvhFPIEnr3UHyon/ywF4xtwu/oEPjHXJ0qOCH8MaS9WE6++pvlWWdTM/TdPM61NGyK7o1Kpza4XrVdbLcY4n2NCz1GnnrWgTLYcPDrBGoaNefRIjN5m90a39Oyx062pItRBvExF5V1 +KgmV07g WtJ8zfjGSAFbW+7qUWgiH7lE1bZPtC6KeBdcfedBTjfOWZX263zd1TIs8lE/TkW/6nO5msi6O1GazQHQFp1ZneoneWFrdbwn0553bd7cXaCPyRXhdVwLVPPXmvL8xJZfdu9G0aOO8oXle2bPvi47BUYQfSQcheawuWUMMzaMXiFsy+u0b0Pnx8xD99NnzEmmhOHauT0u4KfQPknXekkgik09nQjwR/s2nEmLXieTYCAlAFpTkXGaYhyBRpYHAzR5wa22+cg2JwcbE4oLx0Fe0Qbl7HxgScq+Wx2djah8Z2Ff+8KOt9tBrRhDnV1McoIMpPhNMWX8fQujwTUoMu5BThv7ItpGDn829rsHlF+X7loFR1JAVeMxNazC5Fm7CwPn7+bCus7pRvFQY/gD5lYZW2J5g4qNAUFntOXCw3f4DhGc50vktuxU5C2+ra4PplU33rRUz Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 11/08/2026 10:10, David Laight wrote: > On Wed, 5 Aug 2026 14:07:01 +0200 > "David Hildenbrand (Arm)" wrote: > >> On 8/3/26 15:59, 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 >> Is that a real problem, though? > The cost of the read is likely to matter most if the branch gets mispredicted. > I'd also guess the mm isn't usually NULL - so that branch needs to statically > 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. You're right, I didn't think about this the right way round - in general it may not be easy to predict that mm points to init_mm, and an arbitrary user mm isn't guaranteed to be cached. Repeated calls to mm_is_kernel(mm) in the same function shouldn't cost much though. Would some (micro)benchmark be particularly relevant to measure the overhead, if any? - Kevin