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 1CFA7D65552 for ; Tue, 26 Nov 2024 20:32:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A8CD6B0099; Tue, 26 Nov 2024 15:32:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9591F6B009A; Tue, 26 Nov 2024 15:32:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 847F86B009B; Tue, 26 Nov 2024 15:32:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 657666B0099 for ; Tue, 26 Nov 2024 15:32:26 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1B0DFC1440 for ; Tue, 26 Nov 2024 20:32:26 +0000 (UTC) X-FDA: 82829393598.09.EAE9D30 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by imf03.hostedemail.com (Postfix) with ESMTP id E6F692000D for ; Tue, 26 Nov 2024 20:32:21 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=qJEhg+ml; spf=pass (imf03.hostedemail.com: domain of jannh@google.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732653139; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UiouVvQy1ysSNzucyHX39VpOdsi6a4Dd/ylDP/YY+tM=; b=VEdsczb8DWToYi/NYCP7CQ5G+qYzw/7cBvDPixusa0rUTUfAvDvz/k2VkU+cd9C9bfhtgw U2bIi1pNDuLnL+DmHtjSPAYOhQpsWxRMoMgUU2T/t/VkssyPXy+M8HDGvFd3b+d/5VOmeE I8hQ6sFIDAXWWJr+C6ujfvcWarJvOGk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732653139; a=rsa-sha256; cv=none; b=xkS5mA/E0RszlMKEhXUpsdWZi9wbN9lk+t/92w7YldRSMc6VXYppejVreQC+xLEG9y+XpS kAYv4Co6iGWJV2TnWDcYV8BCTjJUws8K4k3FPZv09KMVc795846OykVD0JghzOvL1Ytnb0 206fNGwE4EQiQ0Ioq49Az51+flM4x9w= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=qJEhg+ml; spf=pass (imf03.hostedemail.com: domain of jannh@google.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5cfc264b8b6so2534a12.0 for ; Tue, 26 Nov 2024 12:32:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732653142; x=1733257942; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UiouVvQy1ysSNzucyHX39VpOdsi6a4Dd/ylDP/YY+tM=; b=qJEhg+ml+QLgKdNPC42kB+qd0Q7dZV/S83TQN62YizbxcfPwewRFt9WJKnf5p8ucMa 4pPfRxFSfJuOGDZGRr2uwydV9OZEbYvcGdH8JcWy8fab27S44elUrq39Gyv2DPUURGef 9T1PzidJBDyAerwb2FrefKUEcQRDBZivyOKBjFEfnKGm0BnHCHgwwPvcF4Ho9SoDzGNW UdKag0raIf0UpG/UM3mytu3tzMxgBMoJThhzIuRjrHl6uTav9SVkGmnuJXgoK8kdHXqS cVxMaCkZWN3Bc0gytTzkxWIPVOVbNQ5DPDCdL/kSVyX3+jJ3CyHcG6OgN+qdNkweHL+B yneQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732653142; x=1733257942; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UiouVvQy1ysSNzucyHX39VpOdsi6a4Dd/ylDP/YY+tM=; b=vwyIcYBpyRJ3DZBBF5axhdqcS/r0Ex4LGvB+Xaj9CQt/LQui6xglr9s2x6+D5ldrja uvXlXhrdgTtdofg7FP6wvYHWKogOpLNng55AfRqiVPNiSe7Mx2aNFLO9AqP1WygwNHe7 vH3F5B8SJYKEhpW6hLVsrR+RTI6PEgKxCRR5t6ZCezEin9v9VSNHD1mx2L4pWrGB7bgz G7VDiK+6/lLmFLFF+/LoxoQcAq/RKK8jR0Tp8QyPufpXpIwYOK3s0JUR8YO5Sj7tZ7rl EwvnyOI+0rN9r7CEgVfOWqn74LUlMYbkVk9kthmjBDWpMsKq4ZAgRXx00TqPd+P1Vute Gj4g== X-Forwarded-Encrypted: i=1; AJvYcCUimHAJ575Lj9CjRYMia9m8BpRsm6eQqfpfDi5Vk+2G6+7SlWfiBJheOYbGmfybChxWEMNfkCOXUw==@kvack.org X-Gm-Message-State: AOJu0YxUF/FmdGRpl+bMsSuhIprSIFO0bbx4jT7/0a2xLkUalotkl04L ThapI0wc1xiSy/4wSLnZdnZaRFCmsGJ6NMb0WKl4y7RQfbAC8nG5y1Kq+TeMZBN+H7Hnsfc7hSI oNjvZNVgH6HFTz30+xcK9iEe8rU72p3XN+lzd X-Gm-Gg: ASbGnctpk6VTC8qSC2UJGxD3wCRtAQH0OZYLlGVRU/Vd5yok0LBS3TDJWpqvJQQ/J0G G09Ud77KocrHdszC9fKzR07wytDJhe4E6baF7jxQgcyhG3spKT1bTJc1onIw= X-Google-Smtp-Source: AGHT+IFLGtY2k1/yQLTkkaMGF/8QTmikGJDbPMCtQvYW3IFdPIMrHqR0uhIysGxFKp0f4Ab0QhOn0doTUEbLkLZBzts= X-Received: by 2002:aa7:d80b:0:b0:5d0:3ddd:c773 with SMTP id 4fb4d7f45d1cf-5d0819b8bf8mr11824a12.4.1732653141887; Tue, 26 Nov 2024 12:32:21 -0800 (PST) MIME-Version: 1.0 References: <20241119112408.779243-1-abdiel.janulgue@gmail.com> In-Reply-To: From: Jann Horn Date: Tue, 26 Nov 2024 21:31:46 +0100 Message-ID: Subject: Re: [PATCH v3 0/2] rust: page: Add support for existing struct page mappings To: Matthew Wilcox Cc: Boqun Feng , Alice Ryhl , Abdiel Janulgue , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , open list , Andrew Morton , "open list:MEMORY MANAGEMENT" , airlied@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E6F692000D X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 8kcp5az8b8pr7kffyenqge8nnkpnahww X-HE-Tag: 1732653141-544523 X-HE-Meta: U2FsdGVkX1/0LsRjmsusmwi00N8sb6+VWlTawTvKH779XHTNdKbk68Kj/3O7aVRVr+QXdqlsmGgQsXbhqFYcGRz/Q3OXuQG9xZXWq8W9P+hFwmCilWboHXh2TequyZe1qTz4bp3tjbRW3w4G4QppJVCTRntfrSFWm39Skrd7nZ08N/I5ob+S9XVMccSo70CZgfynFAyAqrdsy7hcOcA4BpcqF4M/PkIpoGJwo4veizXFBmpPIkm6CVP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iM0IZAvihWLO1EuTE7OLfuv2wg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 Wed, Nov 20, 2024 at 6:02=E2=80=AFPM Matthew Wilcox wrote: > On Wed, Nov 20, 2024 at 08:20:16AM -0800, Boqun Feng wrote: > > On Wed, Nov 20, 2024 at 10:10:44AM +0100, Alice Ryhl wrote: > > > On Wed, Nov 20, 2024 at 5:57=E2=80=AFAM Matthew Wilcox wrote: > > > > We don't have a fully formed destination yet, so I can't give you a > > > > definite answer to a lot of questions. Obviously I don't want to h= old > > > > up the Rust project in any way, but I need to know that what we're = trying > > > > to do will be expressible in Rust. > > > > > > > > Can we avoid referring to a page's refcount? > > > > > > I don't think this patch needs the refcount at all, and the previous > > > version did not expose it. This came out of the advice to use put_pag= e > > > over free_page. Does this mean that we should switch to put_page but > > > not use get_page? > > Did I advise using put_page() over free_page()? I hope I didn't say > that. I don't see a reason why binder needs to refcount its pages (nor > use a mapcount on them), but I don't fully understand binder so maybe > it does need a refcount. I think that was me, at . Looking at the C binder version, binder_install_single_page() installs pages into userspace page tables in a VM_MIXEDMAP mapping using vm_insert_page(), and when you do that with pages from the page allocator, userspace can grab references to them through GUP-fast (and I think also through GUP). (See how vm_insert_page() and vm_get_page_prot() don't use pte_mkspecial(), which is pretty much the only thing that can stop GUP-fast on most architectures.) My understanding is that the combination VM_IO|VM_MIXEDMAP would stop normal GUP, but currently the only way to block GUP-fast is to use VM_PFNMAP. (Which, as far as I understand, is also why GPU drivers use VM_PFNMAP so much.) Maybe we should change that, so that VM_IO and/or VM_MIXEDMAP blocks GUP in the region and causes installed PTEs to be marked with pte_mkspecial()? I am not entirely sure about this stuff, but I was recently looking at net/packet/af_packet.c, and I tested that vmsplice() can grab references to the high-order compound pages that alloc_one_pg_vec_page() allocates with __get_free_pages(GFP_KERNEL | __GFP_COMP | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY, order), packet_mmap() inserts with vm_insert_page(), and free_pg_vec() drops with free_pages(). (But that all happens to actually work fine, free_pages() actually handles refcounted compound pages properly.)