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 84067CD4F3D for ; Wed, 20 May 2026 21:29:25 +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=+FvKgT5pG95JgT3TscKBF5hGUKTEVSajCnC+nu0Y4WM=; b=tI3ghJrlJUqcBR+3tg8SPysxSb gFEZ3YKqB2rkEyh6Ws9bZ6gXfhTe9pNhMMfm28YqvJmAWl4IKWq/vij4moxFY5s5wYdTfcmtt9UzH ZLJjQQNHYtp/8IS6YYcvlC6w1Vj8LHQQ/6CuqgYdaSUKAKYV5tIqX1GJOfRT2cU90gZnaZrVxJzyn cgkTI1zB5pkmCKaxLFt/ZTVpuFsPH77o8IjpnxygcRVCjY+uSjmB1+dvRBQbxMaog5NtI0cxIZgEZ pJyB2otnUz4wiII8DXY3u/LUSd4bx/l8/sUEiipVGb4bD0Th31sdcanUeMbcVOxP21ImFjfyXfirT hQBJo+hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPoTf-00000005qgU-1w6u; Wed, 20 May 2026 21:29:19 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPoTd-00000005qg0-1JrN for linux-arm-kernel@lists.infradead.org; Wed, 20 May 2026 21:29:18 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 85ECA40178; Wed, 20 May 2026 21:29:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE26B1F000E9; Wed, 20 May 2026 21:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779312556; bh=+FvKgT5pG95JgT3TscKBF5hGUKTEVSajCnC+nu0Y4WM=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=XQc39hnvCdkTlJIa8y9YfgGkIJQb1cHVaoOkJ7pbNHFepqyzWDGV4Wxa5w7n7maGc X+b9cmNIXD1NNy46RiDLbrSNZKSvWZkVvzOf5pjYkd9GkeQ8uWitOK7rbabbOpRsMR cU2Dzy2Z/oHVXA1L7GHzimHqACLluo7QZV4M3RKQ0VSW0gAsm/ALa1Jg6hl3P+lCuJ 2OikXfZRe0W52IcmQMM/se/XYc5GpkRUpXmiQI7394jKgEDAK8kQbIZmBYmRb/oRNk R3bs2GEMBeAjc+i/0X3bVd97RkREIJ/H5nw8+YdfehKMnRuPgqE+f2PNVK0PTE1sZc eCBD5LIKuDCGA== Message-ID: <210d140d-c78a-47be-8046-caae359db6db@kernel.org> Date: Wed, 20 May 2026 23:29:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/8] mm: Add ptep_try_install() for lockless empty-slot installs To: Tejun Heo Cc: Alexei Starovoitov , David Vernet , Andrea Righi , Changwoo Min , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Kumar Kartikeya Dwivedi , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andrew Morton , Mike Rapoport , Emil Tsalapatis , sched-ext@lists.linux.dev, bpf , X86 ML , linux-arm-kernel , linux-mm , LKML References: <20260517211232.1670594-2-tj@kernel.org> <9ba50fd2-077e-4291-9276-9adb18186873@kernel.org> <2f02d90d-cdc9-48ef-abe3-99e00f22595f@kernel.org> <297658c4ae2d6e7103f5968efc936224@kernel.org> <04b03066-86d3-4c0b-b077-307fd0f3bc9c@kernel.org> <5590fd3d-dae1-4070-b52f-bc40982ac678@kernel.org> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; 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 B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzS5EYXZpZCBIaWxk ZW5icmFuZCAoQ3VycmVudCkgPGRhdmlkQGtlcm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3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260520_142917_403659_81275EFC X-CRM114-Status: GOOD ( 23.48 ) 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 On 5/20/26 20:38, Tejun Heo wrote: > On Wed, May 20, 2026 at 10:41:15AM +0200, David Hildenbrand (Arm) wrote: >> And that should be carefully documented. > > Will do. > >>> The fault handler has to install _some_ page and let kernel continue. >>> Scratch page or arena page doesn't matter. Potentially different CPUs >>> will see different page. It's not a concern at all. >>> bpf prog is buggy, but the kernel will continue to work without a glitch. >>> bpf runtime will disable and unload misbehaving prog. >> >> Having one page table walker overwrite a scratch page on race is just rather ... >> questionable locking design, that just screams for problems long-term, really. >> >> At least in apply_range_clear_cb() one could similarly switch to >> ptep_try_install() to at least have both these paths handle races in a >> reasonable way. (having to handle when ptep_try_install() is not really implemented) > > Hmm... wouldn't that be more confusing on apply_range_clear_cb() side? > Whether it maintains the current behavior (if collide with scratch, try > again with scratch as the original value) or flip the behavior (fail if > scratch), that extra logic is spurious, and those tend to confuse people as > they force asking why it has to be that specific way. If the goal is > documenting the subtlety, wouldn't a detailed comment serve the purpose > better? I would let all operations that can happen concurrently work with atomics, not just a single one. Alexei correctly concluded that ptep_get_and_clear() might be one option that should do on x86 and arm64 from a quick glimpse. > >> Anyhow, the documentation of ptep_try_install() must clearly spell out that this >> must be used very carefully, and only in special kernel page tables, never user >> page tables. There are likely other scenarios we should document (caller must >> prevent concurrent page table teardown somehow, and must be prepared to handle >> races if other code is not using atomics). >> >> To highlight that, we should likely consider adding a "kernel" in the name, like >> "ptep_try_install_kernel()". >> >> I am also not sure if "install" is the right terminology and whether it should >> instead be "ptep_try_set()". (set_pte_at is the non-atomic interface right now) > > So, ptep_try_set_kernel()? I guess we could do that, but we don't have a lot of existing functions that are specific to kernel page tables ... only pte_offset_kernel() and pte_alloc_one_kernel()/pte_free_kernel(). The most important part is getting the documentation right. We should probably document that code concurrently clearing PTEs should be using ptep_get_and_clear(). -- Cheers, David