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 CDC05E6918E for ; Fri, 22 Nov 2024 19:17:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 186426B0082; Fri, 22 Nov 2024 14:17:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 137476B0083; Fri, 22 Nov 2024 14:17:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F18976B0085; Fri, 22 Nov 2024 14:17:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D60616B0082 for ; Fri, 22 Nov 2024 14:17:22 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8E3951A14F9 for ; Fri, 22 Nov 2024 19:17:22 +0000 (UTC) X-FDA: 82814688432.16.069CAC3 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf16.hostedemail.com (Postfix) with ESMTP id 2464F180011 for ; Fri, 22 Nov 2024 19:16:25 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="PR/VjFhj"; spf=pass (imf16.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732302946; 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=0Epssg2UejcAoGOvobTdJvf0gOa9HRphNulF2J5a7SI=; b=e0mUW/J2If/pi4j7R7bhhblEQt+kzrny8b5Z94obfVV8v9ZOaMqtiB3/aJfu7xDHwXLRJK yWHzicmmKE4ZgRZxY01WS7p05ANZ11BHTZI8vN5ko+jzIjTq/sOAfYgsyzi2m6nqXAD0TD uFGn7mXVHvKa1lXDDKYeYAS+G2VeulI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732302946; a=rsa-sha256; cv=none; b=C2pI8I7CbiClmHCGN21w33vSolm60zttTIepQQAaGdT64wADKH6Gnj4xHn+FxEp8liQz1h Vw7BDdFA0/0f2nv1MhHEUiVmmrnlfwVIv1cg/xCyzuo3i6IVpC7GiObZ8AzvY2LtUbnXP6 EHPId1WCAnT2EmNyk9X8Lxd/Nc/vHLk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="PR/VjFhj"; spf=pass (imf16.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-460ad0440ddso14959101cf.3 for ; Fri, 22 Nov 2024 11:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732303039; x=1732907839; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:subject:cc:to:from:date:feedback-id :message-id:from:to:cc:subject:date:message-id:reply-to; bh=0Epssg2UejcAoGOvobTdJvf0gOa9HRphNulF2J5a7SI=; b=PR/VjFhjPoNOz+cgy/QK7knar1I78oYcgReAcNkNVuqIiFtx36jPgVtOsqm64kMnkD su4QCcE/qNGfRdC4JnUj5h5gzVvarpTJQCuj02wvnX7xXpY+9GCXM4nmNIvvxYtaQfnu bgTC9CXo7an7iSEbaReugeoq61l3odtueXW1+6fbISuBo3OZmq8hZPwm4+5XTapgrfr2 HWrVu6iixNjgtir5f5Ohg3aT56VCcO6FGIO9Ym9Ulne3cHG2MBlJulqWPhcoPmoWeYbh 7tD9oGC7NiJJ9jyXOLvMCH3y7Z3Zsj2w6e5clRMzsZL49sYHMwqkNjFfbzf4zzQ0BC/x fBgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732303039; x=1732907839; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:subject:cc:to:from:date:feedback-id :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0Epssg2UejcAoGOvobTdJvf0gOa9HRphNulF2J5a7SI=; b=YyjceTJpsKwGH+J3Eminir+MeyghDC7yys2UkDCFdHdtzkdtsrAtNDuDQQXmyvBzic 7nYDLpF4C2okx57GEcgEE1OKOTsxXunDn//Fqn/d+yxitShELgJQKnAk/zHeU7aag/zX HDWkVil74uFSS6WDCTYI/bsqKTczYbFaLEwus5YJRi8Baisg36Nwpj32DkO1MlWyHkrW S1C+CeFEOyzEGcYjJCOo+nZdRmwZzTt/kSxuGJC61/IqBrXYUz0Kx1BUMNbxwU/4sjJP AE9JDiW3IaPexcgEpc92p1Tue2YYmGyE+vj27qmv0Sm+eygK5za95eD+fpcklROgtbgF ukzA== X-Forwarded-Encrypted: i=1; AJvYcCWtwdmCc9wCkZKiW6E0BCARdtNq16OIZAWUHeOlSJW48BDNUjWnuHrSQ9R6w3Do0O7EIM+k3O4MTg==@kvack.org X-Gm-Message-State: AOJu0Yzf2bF5fTOI9BAHJIGy0YxOSvr16ls7O7Nqs7H8K6Oiy0eTJ04w Rh0B0Pq7f1oksi5w04UToZFtQocRQezbXNCRXrec6MMQsl7Ullns X-Gm-Gg: ASbGnctJQVZW3O2zoTrE1wJM2NycOse06Vnx5sgiv3p2FrKg+WbQ6yDQQ10eUA1tLvj sc7Lmgj6YV0M1fdAgw6xI+crspKOGTPmF1VEK6UfnObP43rOmhwy7tvNxlzTvujY7ycZO4MUnSH mPffiBhaZ+zpO7l0fqVJsxDKsklZAdCnZ+gxTgHnHKxCxT0FHe5Nsj4srtDbwo4MXFV9/K2KyXw StfyqRP70YPUmSQxm1dpq1hv9qwEUk8dhoXLal3djr2CXhoomhGHRaZKYjomelU+99PtR0SUzW/ pfPuEthmAFyPfLxZS332wAO+uuwERTdYNf2LTm9h X-Google-Smtp-Source: AGHT+IEXXmkmiV/IARZzBCM/RUYMbge0XmQ5IKPMwVUZ/euEELlOMiYB0fF0xQSOST8Tf1/a8m2nxg== X-Received: by 2002:ad4:5aa7:0:b0:6d4:f14:eb99 with SMTP id 6a1803df08f44-6d45137933fmr56465506d6.45.1732303039166; Fri, 22 Nov 2024 11:17:19 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d451b61c88sm13228766d6.121.2024.11.22.11.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 11:17:18 -0800 (PST) Message-ID: <6740d8be.050a0220.30b282.4f2e@mx.google.com> X-Google-Original-Message-ID: Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id 0B142120006D; Fri, 22 Nov 2024 14:17:18 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Fri, 22 Nov 2024 14:17:18 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrfeelgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtjeen ucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrd gtohhmqeenucggtffrrghtthgvrhhnpeevueeuteeifeekhedtveelgfevheeuhfduffej jeffudeihfevffefleeuffefgeenucffohhmrghinhepmhhmihhfmhhmrdhishenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhm vghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekhe ehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghm vgdpnhgspghrtghpthhtohepvddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope grlhhitggvrhihhhhlsehgohhoghhlvgdrtghomhdprhgtphhtthhopehojhgvuggrsehk vghrnhgvlhdrohhrghdprhgtphhtthhopeifihhllhihsehinhhfrhgruggvrggurdhorh hgpdhrtghpthhtoheplhhorhgvnhiiohdrshhtohgrkhgvshesohhrrggtlhgvrdgtohhm pdhrtghpthhtohepvhgsrggskhgrsehsuhhsvgdrtgiipdhrtghpthhtohepjhhhuhgssg grrhgusehnvhhiughirgdrtghomhdprhgtphhtthhopehlihgrmhdrhhhofihlvghtthes ohhrrggtlhgvrdgtohhmpdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunhgurg htihhonhdrohhrghdprhgtphhtthhopehgrhgvghhkhheslhhinhhugihfohhunhgurght ihhonhdrohhrgh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Nov 2024 14:17:17 -0500 (EST) Date: Fri, 22 Nov 2024 11:17:15 -0800 From: Boqun Feng To: Alice Ryhl Cc: Miguel Ojeda , Matthew Wilcox , Lorenzo Stoakes , Vlastimil Babka , John Hubbard , "Liam R. Howlett" , Andrew Morton , Greg Kroah-Hartman , Arnd Bergmann , Christian Brauner , Jann Horn , Suren Baghdasaryan , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org, Andreas Hindborg Subject: Re: [PATCH v9 8/8] task: rust: rework how current is accessed References: <20241122-vma-v9-0-7127bfcdd54e@google.com> <20241122-vma-v9-8-7127bfcdd54e@google.com> <6740c786.050a0220.31315a.5363@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam10 X-Stat-Signature: 75drge8myf8sajd5eh49p9t8jkcko1mq X-Rspamd-Queue-Id: 2464F180011 X-Rspam-User: X-HE-Tag: 1732302985-707854 X-HE-Meta: U2FsdGVkX19gBr+w2H5YqHUO61RgDZ1XMG/UYvhltDYHrViBae3XAI1BPkwqcPfTj8PJnQLe0DxP951GzUfKS3rMzK4ddrozgCv596rXTUkrE51MS4vtpardaTphRIAxL141bVUAduWxZnlVnMZPbrSwCkTxb+6M32UJ39Rl93emzMJXCPjwk1BHBZcDjSLKMLQ2G0JmfeKOKWlvVnSzO2L+xJvCFAug3l/Z5RMblk7D9qtE0QQR5x37y6qAixX4qOgcSKVTQ+rYqUfYqZovSQ37BDky8bN20UyY3k6emk7SWaVet3hvux44C/lRWHEDv6/XsZX4nBcpZVYs7LzDL/dSxabn6HyPSUg6v8VNfFjqwVgalF34X9Vj2fhuNnYsgML8VJyMg9d++nbF2/Y92SgA6l8A5QHgSUk1fPPs9aWWu0HDw5S2DUt8wjjI8xyiO8gV9lH6NtkL0B0b7hyGiF+w4iEYdcfABkzZQl+BOv5MZWE08LxmFqWSc+RgcXMCZCYnpzW9MFDXWGHbZu7jUdWkHweHsIMRlQVa1+U/w9jcoMQOzxqSpYDtqPKJXZeKM+wNrlD2nRec5bSdzFeqehteejugqRJ7lEkTcQMDGxcYOzkuj34x+oEejwSko6BqGvoh57wk0W7n+enabUK54PtFITQ2XJWN0JdDWR3O2FgWko8kc04fbTZX7LPmAgODlMZRaSkV8AmFkd43pxayzATASlDA9dtlhMT44rzcqNUwibbSlFOzu8jATSpWA2uZtK1suguodtzFWSKY7XTTAVVwekNieRiS7mzcw0RRx4kEvWn9gkzikUbl0z/FNjBMbil49Bnv4I6q7cNaokG8MzdgXENEB6+9/3bt2y7IPUsDRqPTsPIbGm6acfdFnathUVLBoquhh4X5rS760uWruFitW/WgObkD4+Tg39ZFN9gbOhQ7/+AHbJWg/H2rJ9/8bgbRQ/5OK0Wklxmb+GR Bx/Au6Zb lR8czlnR6PpXwf7wQXMQ+YnJKLknIF+ISonnV16PNogsOuPLsIv+qUL4c0Oku97pZqGhki3jYuWdeJxYPyFH6/uNknVnB4HhQl4OfHyTI3txal2KxhaqSSamXN0Nvxf7odf6qrr8CrSRtSSXRsfVp5lh06eGEob1sdZLv0IKqlS3ew1UmFucQ/QYtIlaYlQekn8oYci+oIWtg1t4Ookn2JKztVExsrGJ8KY5O9zKtdpC8ofx4L16IZgaDIJLqjhP5LpygTOPhR/cnHIqlkryo/QyEXdy8R+po5Nb1QS91cAWTglnQltAcuARWOsCs5NgWPYhtd1TV08EPLBptIUJLMqcalboZKT3enNG4tSC/hN2chRr5bfdQOcW60uzaXoawxoK60Ce0neo7bwBQCqyuA9XY+hMXbEAB8wXJz4FaLiCD3TtAmCiHfbFE0oJwy8akBKgaXYK3nWae4jsVCGPrgwGw983MRZMfnJEKgtkR7OwCgDNoGWVQuHnzEg== 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 Fri, Nov 22, 2024 at 07:48:16PM +0100, Alice Ryhl wrote: > On Fri, Nov 22, 2024 at 7:03 PM Boqun Feng wrote: > > > > On Fri, Nov 22, 2024 at 03:40:33PM +0000, Alice Ryhl wrote: > > > +/// Represents a [`Task`] obtained from the `current` global. > > > +/// > > > +/// This type exists to provide more efficient operations that are only valid on the current task. > > > +/// For example, to retrieve the pid-namespace of a task, you must use rcu protection unless it is > > > +/// the current task. > > > +/// > > > +/// # Invariants > > > +/// > > > +/// Must be equal to `current` of some thread that is currently running somewhere. > > > +pub struct CurrentTask(Task); > > > + > > > > I think you need to make `CurrentTask` `!Sync`, right? Otherwise, other > > threads can access the shared reference of a `CurrentTask` and the ->mm > > field. I'm thinking if we have a scoped thread/workqueue support in the > > future: > > > > let task = current!(); > > Workqueue::scoped(|s| { > > s.spawn(|| { > > let mm = task.mm(); > > // do something with the mm > > }); > > }); > > I don't think this is a problem? As long as a thread exists somewhere > with `current` being equal to the task, we should be fine? > I think I had a misunderstanding on what you meant by "operations that are only valid on the current task", you mean these operations can be run by other threads, but it has to be *on* a task_struct that's "currently running", right? BTW, you probably want to reword a bit, because the "current" task may be blocked, so technically it's not "running". Basically, the operations that `CurrentTask` have are the methods that are safe to call (even on a different thread) for the "current" task, as long as it exists (not dead or exited). In that definition, not being `Sync` is fine. But I have to admit I'm a bit worried that people may be confused, and add new methods that can be only run by the current thread in the future. > > > +impl CurrentTask { > > > + /// Access the address space of this task. > > > + /// > > > + /// To increment the refcount of the referenced `mm`, you can use `ARef::from`. > > > + #[inline] > > > + pub fn mm(&self) -> Option<&MmWithUser> { > > > > Hmm... similar issue, `MmWithUser` is `Sync`. > > What is the problem with that? > It should be no problem under your definition of `CurrentTask`. Regards, Boqun > > > + let mm = unsafe { (*self.as_ptr()).mm }; > > > + > > > + if mm.is_null() { > > > + None > > > + } else { > > > + // SAFETY: If `current->mm` is non-null, then it references a valid mm with a non-zero > > > + // value of `mm_users`. The returned `&MmWithUser` borrows from `CurrentTask`, so the > > > + // `&MmWithUser` cannot escape the current task, meaning `mm_users` can't reach zero > > > + // while the reference is still live. > > > > Regards, > > Boqun > > > > > + Some(unsafe { MmWithUser::from_raw(mm) }) > > > + } > > > + } > > > +} > > > + > > > // SAFETY: The type invariants guarantee that `Task` is always refcounted. > > > unsafe impl crate::types::AlwaysRefCounted for Task { > > > fn inc_ref(&self) { > > > > > > -- > > > 2.47.0.371.ga323438b13-goog > > >