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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FA48C02192 for ; Wed, 5 Feb 2025 07:40:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 450E9280004; Wed, 5 Feb 2025 02:40:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FF83280003; Wed, 5 Feb 2025 02:40:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27A77280004; Wed, 5 Feb 2025 02:40:53 -0500 (EST) 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 04FBB280003 for ; Wed, 5 Feb 2025 02:40:52 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 309CBA0639 for ; Wed, 5 Feb 2025 07:40:52 +0000 (UTC) X-FDA: 83085094344.15.91F42F8 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf05.hostedemail.com (Postfix) with ESMTP id 040BA100005 for ; Wed, 5 Feb 2025 07:40:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=ffwll.ch header.s=google header.b=Tnou0cwu; spf=none (imf05.hostedemail.com: domain of simona.vetter@ffwll.ch has no SPF policy when checking 209.85.128.42) smtp.mailfrom=simona.vetter@ffwll.ch; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738741250; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ckp9FvO1OYcctyJmH0f9RK1zPC2wKkspGKnecKorEdQ=; b=PE8fC2X/VOBGWj09lrG1vZV6StGWsN/qp6nGdHlOjjFLgWOzku2gAxxdpjFk9u4W6Vhad9 BRYmWqDJTE2NwV2HYafSncWH/eBhOPsah9zjwm5oJb7/VClw8FyRjuxNdgaPuNiwF52xg3 D/bchBKwdsUpQLphONY8Bt4jg8QoXhU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738741250; a=rsa-sha256; cv=none; b=q+JsAitjNIVyCOmntTVIFI01p11lnVAuL/pG2Ye2/shj0913vEMFdsVviMPrRC/e2Mf7L7 SQQhizyxe8fF7ZbMREQb3SewTIOUhG2cJobk/4i6D5U+/RMODsfL5C7dQlov/G0tExjsjK L8aJdR4aJZPJqfjtkO62n8Z7tb9mjeo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=ffwll.ch header.s=google header.b=Tnou0cwu; spf=none (imf05.hostedemail.com: domain of simona.vetter@ffwll.ch has no SPF policy when checking 209.85.128.42) smtp.mailfrom=simona.vetter@ffwll.ch; dmarc=none Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4361815b96cso44564895e9.1 for ; Tue, 04 Feb 2025 23:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1738741248; x=1739346048; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=Ckp9FvO1OYcctyJmH0f9RK1zPC2wKkspGKnecKorEdQ=; b=Tnou0cwuGLf8/CVWvo0sQsWRcjj2o+1/q1iiTDdOKZFC9+faen/EZpQSqnUcL0dGE3 s2vthGjergWEX1trPHUolhqzI7EG27NDnCWw73QZRHZlQbBpb38TyqxyyNlkIwc7xZl+ gCBo0ug1tfiWK6v4BTJMN7gqZ0KdZA09sPRpY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738741248; x=1739346048; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ckp9FvO1OYcctyJmH0f9RK1zPC2wKkspGKnecKorEdQ=; b=dJ6he2ZH+krL1FFEiPWAracTINkH47OrD2rr3MUm3N5LhtGB/0Qq8GhErY38zpzE+x eo+mTr+1MzEN68ecYqeWu27um3jmXZfzOAzNj3J/Lq1u/qU+19YNI+EWNdqSangtukcc CGaK6fyxwi8TG2yqN37cB6z5xhBLtmd9NBTBE+rlYp0QeM47658JREEQiMIzD51uVdZC VnTH2pyexjO5gAADS2Qa4fv74ttPIsckO/EPrEb2DkS6VaEchQ8r9VX8jWp3IlvUflX9 CUFrMtZpcr3y+lHLlLNfCrA1eUooB5MMB/ij5rIumuB3ODuARWXfdrfmuWMWxFDUBJOE +3Dg== X-Forwarded-Encrypted: i=1; AJvYcCVkY2UmK3wDA6W/UQCWNPvZFGJXwpkClpVj0Ogar7mxla2NW+ALrkzcx5CVuuzjexh1NP0YPmFdeg==@kvack.org X-Gm-Message-State: AOJu0YwVejB9VgECD4tRV5eR/oF3pTrRyMRtljwd8y3rLjgdIjzJcR97 Oi45wOt2+h5MWzzsria//rCwlLObeHL+rNow90mFX2d25kiAqGxoTXNQvede3J0= X-Gm-Gg: ASbGnct5DtmOCkH4j30/JO6Hx9zR7TJGCdnJ+5QaMjVS4Pg2WSeZ1spCATUiIlipVuM KKDx3pFzv2gVMsZW2tsAtL4id9MeYIVqvC4ZIezd7nPRpO6tQUmEuywYd/Z1vI3vYq74kFBlKif XPAb+6ivZsGmP7rIyUwkiCMA9Xdyts1TJWjQcAjiw2YxN9u1YHDzM6bGraQriae2gWxpEyvzsCx SNjxOzVjyuiZ/cwNzczxPyNsAxTNrH3EYd+SsT/HDjUpiuGNFz51DI4xi/rpKJ59daeUSm3vnvM MEieGpbunxEn24QwBp8wR7Vx9mI= X-Google-Smtp-Source: AGHT+IG9wKRslTcLxM9q7tpMRQI/mhbwKzUGyEOxhppyXztbkL0YRlXLXEUw54yO2pT5NLjqWPcDZQ== X-Received: by 2002:a05:600c:1d1e:b0:436:faeb:2a1b with SMTP id 5b1f17b1804b1-4390d43e579mr9940605e9.13.1738741247972; Tue, 04 Feb 2025 23:40:47 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:5485:d4b2:c087:b497]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4390d933a4bsm12876465e9.6.2025.02.04.23.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 23:40:47 -0800 (PST) Date: Wed, 5 Feb 2025 08:40:45 +0100 From: Simona Vetter To: David Hildenbrand Cc: Asahi Lina , Zi Yan , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= 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 Subject: Re: [PATCH 0/6] rust: page: Support borrowing `struct page` and physaddr conversion Message-ID: Mail-Followup-To: David Hildenbrand , Asahi Lina , Zi Yan , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <026c1a0c-e53a-4a5e-92da-6e4f18ce0fee@redhat.com> X-Operating-System: Linux phenom 6.12.11-amd64 X-Rspamd-Queue-Id: 040BA100005 X-Stat-Signature: k4q9s71r7314ybnxdezjy565abu3irfo X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1738741249-751179 X-HE-Meta: U2FsdGVkX1/4hhwfV6cGxhtiL5tmf8XgyjMZ5mHXYSgiOz9uPY2HJujyjc/sqMa6l2+AhVVGAlIFb6mCMch16SEKPUQtstESRyv2K6jyGAtnARZKTf7aTEmnN+tPNORUFhGNFk1xLj5FPjkWS7v9uYaGSZ9dh4Xg/WlXAD/6TdJbfnjCKRWySi77O5gWetwDBlkNVzkaXJcmHrOmfVU0w98k8YNAFwzRE1Bl9lxcaVKsc6U4LN5EXnt/ISsR7mH6CnZs3rtZTpdzjHfUtAn/jvk8hhSUXl5a6hNM/6p0TMRwy7ctcV9YAerlW3mmVnD89F9/XUyqZcrFKOsVm2yxgsFtC6CrjnIMNlyRr72Auy/pKBgDikcChAxjtZ0CmHNH6dYdFiWSfCtilnbP40H1MEQkK8pq0h9Me5c8vabszA/pu4hl0XLCcwXoMCkraDvF9bGxOg2IjNo2/mKj6zuQl+jVwgCPVlWGsptVAXVPk2DW6dqpr0U+ZDTlL4oInM277C87sYVBSOnjbAoobJVADyuo8Q24rY37KYJ/MKY3oim6yry/80kU4iwIVU4WrQ+zR2WKIY9LHE3qu+9jJSlcPEoTkZx6uiIU3eRo5/tuw6/plVK7qZyQv3pmWjCfytdsAos8SbiXzHW+kexoLZpubkhWiDMubCtUK4GvSUVrPqlPaJQ82XBxWfZPpWG/8tFq3d8iFtS57S1p+YhFcKDG+vsyVfOi26I7B3c8DhhNBlSwHMIMSBwY57qmuwFXezOJt1EduKaHWyPY6yhhOt44zygIN3DQtrPn9y7yKv0HBTGJycDLs4ELEVgHj6weVUvAEk4cGeH2ePTs4lE/useWpBRVzWhCE657OGy1zGwbe6mSH56IPoakcXdZQ5Q26+/mfwWBLZNo5BbBNfjhNEKzGqckEHQ/1y9MRtclYLCViy60RrtIY+NAtzL6ChDyoWgL5FT/KGZqJ8ERcr8jiAq vaXGqpkd FwSlw1mqnVoUcY5OAPtcZC/ak4HQCYxHVT+o0Gh0WxWgWxtohW35HD/uD1T3D5DijHSuL+a62sEjtHqIULgMOSRoqWaBGu14rmED3AkADcjNYSXX2I/URUmINe8pB1y535Otx/YDwpRlavI+/pRWTNkVoxtDreAFUhZmYk98l7alpEzCdJ3at5NSMLIPDoOMghA6S/5KHoHcq9ItN7E7L4vkNsRkyqoVCVtz1UpV4xt7mpbxUgKxK7FWviBuXWk8O36PM9XnkLTb2VSQq3s7Nqjatem6VAIQ41Dn4tGXA518YqF6i7W0VmMuiJPn1M1B9Ty6FbWBpjj9HDbVq9Qr3pcSN1810a6Rj0BKq2X/8XlpnXb0= X-Bogosity: Unsure, tests=bogofilter, spamicity=0.500000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. 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. Cheers, Sima -- Simona Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch