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 9D0D3CAC593 for ; Fri, 12 Sep 2025 08:04:29 +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=H5X75pHcHAnEM8zcD7ykTJjL5glq6wg6eQ+1uRSxWa4=; b=azHRgzM7C6TVYzTwoP//1XCSkx LvlvcEgg7QzauEeCpvgLF/knmCwY9UZY2Hy8kdyliznSPZzWFrbZeSEXWW5zkcFa+9qdTVrJ4ILbl nmOqkAAAP0JFNo2arjfOkZks0w97RK+ITGzHUAEDYybyO4u81A9NgM60Pp9Vpy8Pa3n1J6VwsRuqi 2olCmxBKuK44oV7c/DQAY3C7Z90Vk4YePRH2aLE00pYcipe8nLoixealm3sejUPvyHLnetTfKivTd 0ljkkyGRV8TDv3AV3zRAXJ5Ey9ib4fE3FoR6w2Pt/gOTyFsk3KxwXrzrUYL0WN/+ta1+aQFPWtgg8 Srr2kLug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uwylb-00000007nhB-1KDw; Fri, 12 Sep 2025 08:04:23 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uwylX-00000007ndx-26WH for linux-arm-kernel@lists.infradead.org; Fri, 12 Sep 2025 08:04:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757664258; h=from:from: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:autocrypt:autocrypt; bh=H5X75pHcHAnEM8zcD7ykTJjL5glq6wg6eQ+1uRSxWa4=; b=JWLssHX4qW8tqNmdJ0Re8GkPmmwfmtGaMeB+9CL2pPkPJFGyu7zvsYjs/fNA40vYSuImlT ttVsMX6HBjEv2//izNH32ex/Q3ZAE/dCHP8VUPUCGHnT7ew9drlQPAR8Sofo9agYQv9OHH VreKkhuOln9L5RM7ZJPR8WPs5FE3xio= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-1uUhiJgPPFiMVkHIZPMqeg-1; Fri, 12 Sep 2025 04:04:17 -0400 X-MC-Unique: 1uUhiJgPPFiMVkHIZPMqeg-1 X-Mimecast-MFC-AGG-ID: 1uUhiJgPPFiMVkHIZPMqeg_1757664256 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-45de27bf706so7653955e9.0 for ; Fri, 12 Sep 2025 01:04:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757664256; x=1758269056; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H5X75pHcHAnEM8zcD7ykTJjL5glq6wg6eQ+1uRSxWa4=; b=lQr2ilqowj6DIgvUYq2LV6uSxL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0x3Ws5fU1Y73bqtY02DEo7DvQjMoqFg1I= X-Received: by 2002:a05:600c:3b85:b0:45f:2207:ab2a with SMTP id 5b1f17b1804b1-45f25476d29mr269835e9.27.1757664255896; Fri, 12 Sep 2025 01:04:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6B4WHtwQniBOXl9TNxrOEZZoyaGGED6LI1RYVbwr7AHnntDCVEJCDe9m05fXcYWcUrUbEPw== X-Received: by 2002:a05:600c:3b85:b0:45f:2207:ab2a with SMTP id 5b1f17b1804b1-45f25476d29mr269475e9.27.1757664255404; Fri, 12 Sep 2025 01:04:15 -0700 (PDT) Received: from ?IPV6:2003:d8:2f20:da00:b70a:d502:3b51:1f2d? (p200300d82f20da00b70ad5023b511f2d.dip0.t-ipconnect.de. [2003:d8:2f20:da00:b70a:d502:3b51:1f2d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e0157619fsm55845035e9.7.2025.09.12.01.04.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Sep 2025 01:04:14 -0700 (PDT) Message-ID: <7953a735-6129-4d22-be65-ce736630d539@redhat.com> Date: Fri, 12 Sep 2025 10:04:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/7] mm: introduce local state for lazy_mmu sections To: Kevin Brodsky , Alexander Gordeev Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andreas Larsson , Andrew Morton , Boris Ostrovsky , Borislav Petkov , Catalin Marinas , Christophe Leroy , Dave Hansen , "David S. Miller" , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Juergen Gross , "Liam R. Howlett" , Lorenzo Stoakes , Madhavan Srinivasan , Michael Ellerman , Michal Hocko , Mike Rapoport , Nicholas Piggin , Peter Zijlstra , Ryan Roberts , Suren Baghdasaryan , Thomas Gleixner , Vlastimil Babka , Will Deacon , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, xen-devel@lists.xenproject.org, Mark Rutland References: <20250908073931.4159362-1-kevin.brodsky@arm.com> <20250908073931.4159362-3-kevin.brodsky@arm.com> <2fecfae7-1140-4a23-a352-9fd339fcbae5-agordeev@linux.ibm.com> <47ee1df7-1602-4200-af94-475f84ca8d80@arm.com> <29383ee2-d6d6-4435-9052-d75a263a5c45@redhat.com> <9de08024-adfc-421b-8799-62653468cf63@arm.com> <4b4971fd-0445-4d86-8f3a-6ba3d68d15b7@arm.com> <4aa28016-5678-4c66-8104-8dcc3fa2f5ce@redhat.com> <15d01c8b-5475-442e-9df5-ca37b0d5dc04@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA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AYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <15d01c8b-5475-442e-9df5-ca37b0d5dc04@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: U4PGwMNfg2tKVF7O8ysf9k2-ru7slkXcncV8RFn0_CE_1757664256 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250912_010419_608067_04DB9D71 X-CRM114-Status: GOOD ( 37.21 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org >> >> struct lazy_mmu_state { >>     uint8_t enabled_count; >>     bool paused; > > Looking at the arm64 implementation, I'm thinking: instead of the paused > member, how about a PF_LAZY_MMU task flag? It would be set when lazy_mmu > is actually enabled (i.e. inside an enter()/leave() section, and not > inside a pause()/resume() section). This way, architectures could use > that flag directly to tell if lazy_mmu is enabled instead of reinventing > the wheel, all in slightly different ways. Namely: > > * arm64 uses a thread flag (TIF_LAZY_MMU) - this is trivially replaced > with PF_LAZY_MMU > * powerpc and sparc use batch->active where batch is a per-CPU variable; > I expect this can also be replaced with PF_LAZY_MMU > * x86/xen is more complex as it has xen_lazy_mode which tracks both > LAZY_MMU and LAZY_CPU modes. I'd probably leave that one alone, unless a > Xen expert is motivated to refactor it. > > With that approach, the implementation of arch_enter() and arch_leave() > becomes very simple (no tracking of lazy_mmu status) on arm64, powerpc > and sparc. > > (Of course we could also have an "enabled" member in lazy_mmu_state > instead of PF_LAZY_MMU, there is no functional difference.) > No strong opinion, but to me it feels like PF_LAZY_MMU is rather "the effective state when combining nested+paused", and might complicate the code + sanity checks? So we could maintain that in addition fairly easily of course from the core instead of letting archs do that manually. I would probably have to see the end result to judge whether removing the "paused" bool makes things look more complicated or not. >> } >> >> c) With that config, common-code lazy_mmu_*() functions implement the >> updating of the lazy_mmu_state in task_struct and call into arch code >> on the transition from 0->1, 1->0 etc. > > Indeed, this is how I thought about it. There is actually quite a lot > that can be moved to the generic functions: > * Updating lazy_mmu_state > * Sanity checks on lazy_mmu_state (e.g. underflow/overflow) > * Bailing out if in_interrupt() (not done consistently across arch's at > the moment) > >> >> Maybe that can be done through exiting >> arch_enter_lazy_mmu_mode()/arch_leave_lazy_mmu_mode() callbacks, maybe >> we need more. I feel like >> we might be able to implement that through the existing helpers. > > We might want to rename them to align with the new generic helpers, but > yes otherwise the principle should remain unchanged. > > In fact, we will also need to revive arch_flush_lazy_mmu_mode(). That's okay if it's all hidden behaind a sane core API. > Indeed, > in the nested situation, we need the following arch calls: > > enter() -> arch_enter() >     enter() -> [nothing] >     leave() -> arch_flush() > leave() -> arch_leave() > > leave() must always flush whatever arch state was batched, as may be > expected by the caller. > > How does all that sound? I am no expert on the "always flush when leaving", but it sounds reasonable to me. Which arch operations would you call from pause() continue() ? >> And on top of the proposal above we will have some >> >> struct arch_lazy_mmu_state; >> >> define by the architecture (could be an empty struct on most). >> >> We can store that inside "struct lazy_mmu_state;" or if we ever have >> to, start returning only that from the enable/disable etc. functions. > > I'm not sure we'd want to mix those styles (task_struct member + local > variable), that's adding complexity without much upside... Also having a > local variable at every nesting level only makes sense if we have an > arch callback regardless of nesting level, which is unnecessary in this > proposed API. Yes, that was rather a "if we ever really run out of space we could look into that", I am not a fan of it obviously. -- Cheers David / dhildenb