From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F255277808 for ; Mon, 23 Jun 2025 16:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750697452; cv=none; b=AmIXaVf68eG6VyNx/r3Phe/DAQABpeZHowpHyH+5g1IVEESc2nRNqOEwKv6E/IQzIWr+ZWBojG8vQXdjflSwKrZmY3y1ZCV8NwKrbIBi2tUgAqzXokaKjr6c+ISqMRekuJDEUrp09s4q2HoD8pCHLGxBoMiSSMKOA1zgM33q1sw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750697452; c=relaxed/simple; bh=z9w5Jff+RJsOxoWNaAhQgJzKEZk6yp/f2YCK8XptQHc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=G41EzvHM5Dl+ifIMidUlprduuQfw/JfQYKhDeaiEqDcZCgh27kgHe3D6+33w+bVpFx3Q7tBDwGLuWkbCX21+4jjhRn3UZVeNJN6JVUT2+crDjJQFWEgi5pdCLt9OQGM/Z2m1j7EoJOjXdp0K15vr6nxS8f9QsqzVVCfkS0+nMGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NSbMngih; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NSbMngih" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750697449; 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=Ed4niKBqAAFAJdMUfcKk9bgf0mMY+ZjxjhYnZ9rFgsM=; b=NSbMngihVV0032IlfmuJTr6u3hKCa73CKZp84iGjwhdZ19sFR04jjroYexe2xindEnj5Hn LG10QIgyRqko03H38OMORhjPiPiQ/qiOFyKO/JE+ISh844KOhzvwkCatMjcRQLY9qbbpNL vA7wXWabCUJRy1JolRpn50kDBuR/AzE= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-hk3Q6vaFMsONZCJfM99AIw-1; Mon, 23 Jun 2025 12:50:46 -0400 X-MC-Unique: hk3Q6vaFMsONZCJfM99AIw-1 X-Mimecast-MFC-AGG-ID: hk3Q6vaFMsONZCJfM99AIw_1750697445 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a5058f9ef4so1671299f8f.2 for ; Mon, 23 Jun 2025 09:50:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750697445; x=1751302245; h=content-transfer-encoding:in-reply-to:organization: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=Ed4niKBqAAFAJdMUfcKk9bgf0mMY+ZjxjhYnZ9rFgsM=; b=oYv0n74CZBnL5m7gmOAbStjXeBWhcjDqISRyOUNgJgHSvZU+xCK04ZPsmMszeKLg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:3a3:7ba5:9618 with SMTP id ffacd0b85a97d-3a6d12da112mr10882039f8f.29.1750697445058; Mon, 23 Jun 2025 09:50:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOCWW7LmmKMRm1yEnHNd2WBIZ/Ne3pJxWlGyzN5KG6za4FEbOjWtLWcsmJ/nBd/OTszxhfTg== X-Received: by 2002:a05:6000:3c7:b0:3a3:7ba5:9618 with SMTP id ffacd0b85a97d-3a6d12da112mr10882005f8f.29.1750697444635; Mon, 23 Jun 2025 09:50:44 -0700 (PDT) Received: from ?IPV6:2003:d8:2f4e:fd00:8e13:e3b5:90c8:1159? (p200300d82f4efd008e13e3b590c81159.dip0.t-ipconnect.de. [2003:d8:2f4e:fd00:8e13:e3b5:90c8:1159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-453624554cfsm83316645e9.0.2025.06.23.09.50.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Jun 2025 09:50:44 -0700 (PDT) Message-ID: <0126fa5f-b5aa-4a17-80d6-d428105e45c7@redhat.com> Date: Mon, 23 Jun 2025 18:50:42 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/4] mm: Introduce vm_uffd_ops API To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nikita Kalyazin , Hugh Dickins , Oscar Salvador , Michal Hocko , Muchun Song , Andrea Arcangeli , Ujwal Kundur , Suren Baghdasaryan , Andrew Morton , Vlastimil Babka , "Liam R . Howlett" , James Houghton , Mike Rapoport , Lorenzo Stoakes , Axel Rasmussen References: <20250620190342.1780170-1-peterx@redhat.com> <20250620190342.1780170-2-peterx@redhat.com> <1e6fcebf-f74e-46ad-912b-d7df13527aea@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEA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TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 23.06.25 15:59, Peter Xu wrote: > On Mon, Jun 23, 2025 at 10:25:33AM +0200, David Hildenbrand wrote: >> On 20.06.25 21:03, Peter Xu wrote: >> >> Hi Peter, > > Hey David, > >> >>> Introduce a generic userfaultfd API for vm_operations_struct, so that one >>> vma, especially when as a module, can support userfaults without modifying >> >> The sentence is confusing ("vma ... as a module"). >> >> Did you mean something like ".. so that a vma that is backed by a >> special-purpose in-memory filesystem like shmem or hugetlb can support >> userfaultfd without modifying the uffd core; this is required when the >> in-memory filesystem is built as a module." > > I wanted to avoid mentioning of "in-memory file systems" here. I thought one of the challenges of supporting guest_memfd on anything that is not a special in-memory file system is also related to how the pagecache handles readahead. So ... > > How about an updated commit like this? > > Currently, most of the userfaultfd features are implemented directly in the > core mm. It will invoke VMA specific functions whenever necessary. So far > it is fine because it almost only interacts with shmem and hugetlbfs. > > This patch introduces a generic userfaultfd API for vm_operations_struct, > so that any type of file (including kernel modules that can be compiled > separately from the kernel core) can support userfaults without modifying > the core files. .... is it really "any file" ? I doubt it, but you likely have a better idea on how it all could just work with "any file". > > After this API applied, if a module wants to support userfaultfd, the > module should only need to touch its own file and properly define > vm_uffd_ops, instead of changing anything in core mm. > > ... Talking about files and modules is still confusing I'm afraid. It's really a special-purpose file (really, not any ordinary files on ordinary filesystems), no? > >> >>> the core files. More importantly, when the module can be compiled out of >>> the kernel. >>> >>> So, instead of having core mm referencing modules that may not ever exist, >>> we need to have modules opt-in on core mm hooks instead. >>> >>> After this API applied, if a module wants to support userfaultfd, the >>> module should only need to touch its own file and properly define >>> vm_uffd_ops, instead of changing anything in core mm. >> >> Talking about modules that much is a bit confusing. I think this is more >> about cleanly supporting in-memory filesystems, without the need to >> special-case each and every one of them; can be viewed a cleanup independent >> of the module requirement from guest_memfd. > > Yes. But if we don't need to support kernel modules actually we don't need > this.. IMHO it's so far really about cleanly support kernel modules, which > can even be out-of-tree (though that's not my purpose of the change..). > > Please help check if above updated commit message would be better. I agree that another special-purpose file (like implemented by guest_memfd) would need that. But if we could get rid of "hugetlb"/"shmem" special-casing in userfaultfd, it would be a rasonable independent cleanup. But I can spot in patch #3 now: "Hugetlbfs still has its own hard-coded handler in userfaultfd, due to limitations similar to vm_operations_struct.fault(). TODO: generalize it to use the API function." I would have hoped that we clean that up in one go instead. > >> >>> >>> Note that such API will not work for anonymous. Core mm will process >>> anonymous memory separately for userfault operations like before. >>> >>> This patch only introduces the API alone so that we can start to move >>> existing users over but without breaking them. >>> >>> Currently the uffd_copy() API is almost designed to be the simplistic with >>> minimum mm changes to move over to the API. >>> >> >> Is there a way to move part of the actual implementation (how this is all >> wired up) from patch #4 into this patch, to then only remove the old >> shmem/hugetlb hooks (that are effectively unused) in patch #4? > > Not much I really removed on the hooks, but I was trying to reuse almost > existing functions. Here hugetlb is almost untouched on hooks, then I > reused the shmem existing function for uffd_copy() rather than removing it > (I did need to remove the definition in the shmem header though becuse it's > not needed to be exported). > > The major thing got removed in patch 4 was some random checks over uffd ops > and vma flags. I intentionally made them all in patch 4 to make review > possible. Otherwise it can be slightly awkward to reason what got removed > without knowing what is protecting those checks. Agreed. It's a shame the new API is not a proper replacement for hugetlb special casing just yet ... -- Cheers, David / dhildenb