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.129.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 DCDAE253B63 for ; Wed, 12 Feb 2025 19:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739387275; cv=none; b=ovDP6Z2wbyIeH/Orr3+CL/S6uvnuWQmcbHXxnLSywdjIWOWwRgHCajiqtsr1YfJGaqyq4rFHjizMcFV82grWTemE09DOXHIovmr0WaRE2xJtrB4eMTKCeS2hmgGqb9KfnM7y8O5Lj4nNdxYIDwvQm8R45uYv/9G5ig2GNN5rfN0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739387275; c=relaxed/simple; bh=uHysvwfy0YOcXr4Xow8BhFVHFTTibAfWz89EgwgT+6o=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=EY9g9lGzD3l6gxb+w/1aWwIArGufhO7rDIJGgfPoeySkBRQldtOo+d56XrfoukGDo3wL7iBxeemWp/DPyA70F1yGtG/cgPvzz8a0s2nQ7ofWeiEwBROc1a5wILt1cqtUHJ/fRMoDeOCsosoasBJ6Lwlo4xeKH6lO6lyOtEcnOPs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=CrbfUWei; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="CrbfUWei" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739387273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to: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=kjYE41T9eH6sBeVON8mdbKg+vcLjv+QgGNIcmpOCleo=; b=CrbfUWeib1U2ut0Ars1ijatW4HtiSWPlHsrkhC6HIW7R96H3F12mTtMSGyXlDRJzt+3dhz kT/Egjk5Mc2UgHGmDEa2wK61oztq+QpzGged0MQqshAZX9HTG6Ro9K24nEXSQ6HO7F2eNg Wdgq7EHGzcbfe33aokObqNtI07MJE0k= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-wNRHRg9hOtmjwejn7z-aLA-1; Wed, 12 Feb 2025 14:07:49 -0500 X-MC-Unique: wNRHRg9hOtmjwejn7z-aLA-1 X-Mimecast-MFC-AGG-ID: wNRHRg9hOtmjwejn7z-aLA Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4393b6763a3so304965e9.2 for ; Wed, 12 Feb 2025 11:07:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739387269; x=1739992069; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kjYE41T9eH6sBeVON8mdbKg+vcLjv+QgGNIcmpOCleo=; b=lTXWshyu+l+95kVPGjSW3r8PSAt1aV/Zfx59w3jeos8bkC2qHniSuBh3LXMRODueo6 uHMuo851XGzID9vfSxpOPhYXHzNGilc40qtZ5lcF29KIXP6eeTuReq565pkY6/mrcJiq r81cPN+IGSdoBaDlp1ekFRjMKurO0IKPQq1GuL9IGkpcmkovlsexC4liFtmOX+bcNvR1 g105tyKjHukS0pInS/b3KWnEoiw0veR76+hIP51mQP+aS22r64rpaNlou+jpiOAfBd2c FfHqBTbw4rxaB/wzwPHG5Li+qSTsryWKUPF7i+vd41qxIQ9EAyfYJDsvGO/wOBEX2mRO qmUA== X-Forwarded-Encrypted: i=1; AJvYcCVvipRN9VnSLkXUlIp5EShc6FCZtxVr5KFhMXXoydl8SjMEOFRxSZSpGjEghTxaRWLdd1ReTR5f+oseudzcLA==@vger.kernel.org X-Gm-Message-State: AOJu0Yz+QDWWRMXUiidlIezZco915Ye0fjAzJv2Arb6yIoLEgd2kRujG 2qKRil9G0aWSoNrgSJ3LgWmgzHNpkWqQA8Ys0oPpm1FZQqnV/Z7yadCce0gRrt8ldPks0akN6oE aMrDXRNb1XrPexjJbgVUEI90H6Z2+fFMc46+VcgsjtAiJE+8C+1X6WmCEWptihbJd X-Gm-Gg: ASbGncsrvUG8Jw0D11E5V4clCNGmNkNqHs8p2OlyD1A7xul/BZBCJsEhhitXp3sCyW4 p/Mabbxwii8SCPLnCY6vOOFxJ4fa6YDpgw+0ftQBJf5PKGWAuMTCvaZThjo3Qx7IPEXzXqM+lyQ hyXnnieLfdjRAPlW/pZr4dM+srwLoirdz+NnHEV08Q+DbwNdx7mNJfg7osiiD2iDqfgXaPxU0pc Plf9/PVYV+AepoOYJ5DOd08fS5fh7cs2vn8n/4pvrp/k4zyC1bqaPN7Xy567QQqU6KNx4cQjtEK suJGO7YxrJTyPGRnceE84OEqmb5+HwT+UAPNUngc6DpWBtOhVtV28PpQsdkDcpsfhWVoZKuKO6T iH+YV0ug9ugRMzZo0pR75xxQjBsUlwA== X-Received: by 2002:a05:600c:3ba7:b0:439:4696:c063 with SMTP id 5b1f17b1804b1-43959a8401cmr34041345e9.19.1739387268724; Wed, 12 Feb 2025 11:07:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqTIsCjYY4j8RDJFO1zTxybX0Qjo8xFUOB2V/U5twoI9Bd2ixKNNFZ9vuxKiE+nOJ2cIpEMA== X-Received: by 2002:a05:600c:3ba7:b0:439:4696:c063 with SMTP id 5b1f17b1804b1-43959a8401cmr34041135e9.19.1739387268298; Wed, 12 Feb 2025 11:07:48 -0800 (PST) Received: from ?IPV6:2003:cb:c70c:a600:1e3e:c75:d269:867a? (p200300cbc70ca6001e3e0c75d269867a.dip0.t-ipconnect.de. [2003:cb:c70c:a600:1e3e:c75:d269:867a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4395a06e309sm28144855e9.24.2025.02.12.11.07.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Feb 2025 11:07:47 -0800 (PST) Message-ID: Date: Wed, 12 Feb 2025 20:07:44 +0100 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/6] rust: page: Support borrowing `struct page` and physaddr conversion To: Asahi Lina , Zi Yan , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Jann Horn , Matthew Wilcox , Paolo Bonzini , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , Andrew Morton , linux-mm@kvack.org, airlied@redhat.com, Abdiel Janulgue , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, Oscar Salvador , Muchun Song References: <20250202-rust-page-v1-0-e3170d7fe55e@asahilina.net> <41ca3445-80cd-43c1-8f9e-634c195c9187@asahilina.net> <37A0729B-A711-4D45-B9F0-328FDB9ADD28@nvidia.com> <0e19e1c3-293b-4740-93f3-2c410893288b@redhat.com> <82047858-480a-45e3-b826-3a46fbebe842@asahilina.net> <1e9ae833-4293-4e48-83b2-c0af36cb3fdc@asahilina.net> <026c1a0c-e53a-4a5e-92da-6e4f18ce0fee@redhat.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 B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAl8Ox4kFCRKpKXgACgkQTd4Q 9wD/g1oHcA//a6Tj7SBNjFNM1iNhWUo1lxAja0lpSodSnB2g4FCZ4R61SBR4l/psBL73xktp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mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7BcMrbeg8spPZmI_Vc26mIP91qI5aJyMSfRG4_t4BAk_1739387269 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 05.02.25 08:40, Simona Vetter wrote: > On Tue, Feb 04, 2025 at 03:38:17PM +0100, David Hildenbrand wrote: >>>> It can still race with memory offlining, and it refuses ZONE_DEVICE >>>> pages. For the latter, we have a different way to check validity. See >>>> memory_failure() that first calls pfn_to_online_page() to then check >>>> get_dev_pagemap(). >>> >>> I'll give it a shot with these functions. If they work for my use case, >>> then it's good to have extra checks and I'll add them for v2. Thanks! >> >> Let me know if you run into any issues. >> >>> >>>> >>>>> >>>>> If the answer is "no" then that's fine. It's still an unsafe function >>>>> and we need to document in the safety section that it should only be >>>>> used for memory that is either known to be allocated and pinned and will >>>>> not be freed while the `struct page` is borrowed, or memory that is >>>>> reserved and not owned by the buddy allocator, so in practice correct >>>>> use would not be racy with memory hot-remove anyway. >>>>> >>>>> This is already the case for the drm/asahi use case, where the pfns >>>>> looked up will only ever be one of: >>>>> >>>>> - GEM objects that are mapped to the GPU and whose physical pages are >>>>> therefore pinned (and the VM is locked while this happens so the objects >>>>> cannot become unpinned out from under the running code), >>>> >>>> How exactly are these pages pinned/obtained? >>> >>> Under the hood it's shmem. For pinning, it winds up at >>> `drm_gem_get_pages()`, which I think does a `shmem_read_folio_gfp()` on >>> a mapping set as unevictable. >> >> Thanks. So we grab another folio reference via >> shmem_read_folio_gfp()->shmem_get_folio_gfp(). >> >> Hm, I wonder if we might end up holding folios residing in >> ZONE_MOVABLE/MIGRATE_CMA longer than we should. >> >> Compared to memfd_pin_folios(), which simulates FOLL_LONGTERM and makes sure >> to migrate pages out of ZONE_MOVABLE/MIGRATE_CMA. >> >> But that's a different discussion, just pointing it out, maybe I'm missing >> something :) > > Good GPU Drivers (tm) are supposed to have a shrinker so we can at least > nuke some of them again. Some folks even looked into hooking up a migrate > callback through the address_space (or wherever that hook was, this is > from memory) so we can make this somewhat reliable. So yeah we're hogging > ZONE_MOVEABLE unduly still. Hmmm, so we should really be migrating pages out of ZONE_MOVABLE/MIGRATE_CMA here, just like we now properly do in memfd_pin_folios(). > > The other side is that there's about 2-3 good drivers (msm, i915, xe > should have a shrinker now too but I didn't check). The others all fall > various levels of short, or still have 3 times cargo-culted versions of > i915's pin-as-a-lock design and get it completely wrong. :( > > So yeah I'm aware this isn't great, and we're at least glacially slowly > moving towards a common shrinker infrastructure that maybe in a glorious > future gets all this right. I mean it took us 15+ years to get to a > cgroups controller after all too, and that was also a well known issue of > just being able to hog memory with no controls and potentially cause > havoc. I guess that means job security for us, haha :) -- Cheers, David / dhildenb