Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5455661rdb; Wed, 13 Dec 2023 09:06:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHT75Fu2Vuv+U/H0zg7n7/xhkI1OiZ8rzf55cOSLFdUqwEX8ZDPvB2UYBG8snibSP1+VPKA X-Received: by 2002:aa7:88c6:0:b0:6ce:7a8f:af81 with SMTP id k6-20020aa788c6000000b006ce7a8faf81mr10754630pff.28.1702487176585; Wed, 13 Dec 2023 09:06:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702487176; cv=none; d=google.com; s=arc-20160816; b=PryLMrAGOPdjactZbgRyjdEZNVWCcydtsSur9VqCLLn8qAPhJpGvi3ePxzFCoPc+L7 WtN9fl+wIapRk8ENnxf4lDu+HvKr+HqGIPBLuL6e22RjRy43EudU9zvb2lp+mfbF0U3x jxsVwxfuWFf/7JkSUov0Hlg6uvfBuuM1M46STIs24yPSU8+0mRndJHDWNqcv93aJDOu5 LVR1bPyL1P1qeCPNQVi/fDoOd3QeAP3Aqota52aapyn7QhpqU8jwehLkw73M2ALhd8dC gLJ4Nl9AhWWQ/5+4AU2PYd/mlD3YNAv9sa2LU2zX4U+Elr2iMlGG8P3+u6rv71/LtXGZ 733Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=zaZOg6uPTywifNeWY/lhqitjb+T4PmJ5HvOYe4JLoEc=; fh=yD4ZIz0U/AoAJqml8OWOI2KZ81o4hDUeiX2hF2bWSJA=; b=HyQyTvLmvHE2+D9fi486uOTMuC4OStUhVf7K9rsnlCmgc4MLJsnTrAhiN4R8Ay8RJS OeuALkQOCltbUq6V9raKc6iDtxJUQmoHN5wViJFGwR89BQrhppcBx3wYQpKzlTTHAMlL uyYYaMWu6sevxj/yoTRxalFgqt4lvH9tuzdhURVFDsjOOeVMNwDRY7jtlCmlf94f6YsH LyuZnLKazS5u9J4PyNk5TJ9zqoxicMMegkTEKd6s9kbnDQBTgRtFawYFDe9QQfMewnNp kAc185PZnMWWurcCGHwkvRfmCBPXENG1C3SitcOJpa66Rg9+1GmOixKz28gRK75f1bw/ /zsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fAN56HnY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h20-20020a056a00231400b006cef68cfbdbsi7580851pfh.189.2023.12.13.09.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:06:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fAN56HnY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7D7B58089859; Wed, 13 Dec 2023 09:05:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229458AbjLMRFe (ORCPT + 99 others); Wed, 13 Dec 2023 12:05:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233736AbjLMRFa (ORCPT ); Wed, 13 Dec 2023 12:05:30 -0500 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25477D0; Wed, 13 Dec 2023 09:05:36 -0800 (PST) Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-425952708afso50251451cf.0; Wed, 13 Dec 2023 09:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702487135; x=1703091935; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=zaZOg6uPTywifNeWY/lhqitjb+T4PmJ5HvOYe4JLoEc=; b=fAN56HnYVTBYv89mKu8lHU6DwDhRB0utUi4cTovqijKV0NCXjiJoCaJSbAeV0iwCyy dN7ccgDcXzOYJwpEmCii0HuHUqCc/ugge5ZihV9JVGnmy1w6SPYUuoPh5lzrrIhRCKaS NOo+AthpA0VcfEz91ViHiTyP3G0jwBfVF6LNa/lhDDBDm+cD0ufX4PjX6C4ZNYU4QKYc 4wOSUwOwi+j2vb9MzbnQPV756KNoI2JqdvBfvkWBIJdPjXVjhr08ltVm6QBa/6VveiJ6 I2JLjdIhRQDVWURTtggZTXY7WQCCkEyR3bSk95Su4DbohnyLA2chyEKIrbHF6fPQMQZO xcgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702487135; x=1703091935; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zaZOg6uPTywifNeWY/lhqitjb+T4PmJ5HvOYe4JLoEc=; b=Ae+0TbIoyZMYjWVW3I8Or6P41RsrTs+vlkpzk9VK00RLaFach9GOE9rx8rq/eHfwga v5/e9JFcbYWHeU5AR2BoA6uJgo8Fj81R3qhTJwUz8+lbhTUTAYhBWbCeC3Y9xOz6uozU uv7KtcS+p2jTth/nM0E50nfYnBWx04dP1G+zmoXgggXlmI3Cw17L2bAUxx9SHks1DrfB zafLRrjDRQUFSV1BT4CR/jWos0R4i5HBgSIxNOK/nQT1HFfNHQ4aUYhk6OxrN7lYnEUX CAeXPbSfeF1mscoKM1ak+npYXhQ6wf6x86dt3A2ckSNNOLZcNSFOg9UBgSOBYc6xE8uc pllQ== X-Gm-Message-State: AOJu0Ywzgou4diBG0rSnkfGpPerO9uabmlAf+g56ZCT7wyDPTeLEo8zo XKGm7AiIuRiGSNuyTZ/AHmQ= X-Received: by 2002:a05:622a:252:b0:425:88fc:8abb with SMTP id c18-20020a05622a025200b0042588fc8abbmr12875357qtx.12.1702487135165; Wed, 13 Dec 2023 09:05:35 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id e18-20020ac85992000000b004254b465059sm4890154qte.47.2023.12.13.09.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:05:34 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 1088027C0054; Wed, 13 Dec 2023 12:05:34 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 13 Dec 2023 12:05:34 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeljedgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtrodttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeeitdefvefhteeklefgtefhgeelkeefffelvdevhfehueektdevhfettddv teevvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Dec 2023 12:05:31 -0500 (EST) Date: Wed, 13 Dec 2023 09:05:30 -0800 From: Boqun Feng To: Benno Lossin Cc: Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Kees Cook , Matthew Wilcox , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 7/7] rust: file: add abstraction for `poll_table` Message-ID: References: <20231206-alice-file-v2-0-af617c0d9d94@google.com> <20231206-alice-file-v2-7-af617c0d9d94@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 09:05:49 -0800 (PST) On Wed, Dec 13, 2023 at 09:12:45AM +0000, Benno Lossin wrote: [...] > > > > Actually, there is an implied safety requirement here, it's about how > > qproc is implemented. As we can see, PollCondVar::drop() will wait for a > > RCU grace period, that means the waiter (a file or something) has to use > > RCU to access the cv.wait_list, otherwise, the synchronize_rcu() in > > PollCondVar::drop() won't help. > > Good catch, this is rather important. I did not find the implementation > of `qproc`, since it is a function pointer. Since this pattern is > common, what is the way to find the implementation of those in general? > Actually I don't find any. Ping vfs ;-) Personally, it took me a while to get a rough understanding of the API: it's similar to `Future::poll` (or at least the registering waker part), it basically should registers a waiter, so that when an event happens later, the waiter gets notified. Also the waiter registration can have a (optional?) cancel mechanism (like an async drop of Future ;-)), and that's what gives us headache here: cancellation needs to remove the waiter from the wait_queue_head, which means wait_queue_head must be valid during the removal, and that means the kfree of wait_queue_head must be delayed to a state where no one can access it in waiter removal. > I imagine that the pattern is used to enable dynamic selection of the > concrete implementation, but there must be some general specification of > what the function does, is this documented somewhere? > > > To phrase it, it's more like: > > > > (in the safety requirement of `PollTable::from_ptr` and the type > > invariant of `PollTable`): > > > > ", further, if the qproc function in poll_table publishs the pointer of > > the wait_queue_head, it must publish it in a way that reads on the > > published pointer have to be in an RCU read-side critical section." > > What do you mean by `publish`? > Publishing a pointer is like `Send`ing a `&T` (or put pointer in a global variable), so that other threads can access it. Note that since the cancel mechanism is optional (best to my knowledge), so a qproc call may not pushlish the pointer. Regards, Boqun