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 8CA59C4321E for ; Fri, 11 Nov 2022 19:27:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9964F8E000A; Fri, 11 Nov 2022 14:27:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91FB68E0008; Fri, 11 Nov 2022 14:27:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80DC18E000A; Fri, 11 Nov 2022 14:27:35 -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 6B1018E0008 for ; Fri, 11 Nov 2022 14:27:35 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1B6AE140801 for ; Fri, 11 Nov 2022 19:27:35 +0000 (UTC) X-FDA: 80122145670.16.181F049 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id A3480140005 for ; Fri, 11 Nov 2022 19:27:34 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5D94620AF; Fri, 11 Nov 2022 19:27:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC96DC433D6; Fri, 11 Nov 2022 19:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1668194853; bh=LO+ntQc0E3uXo6MFAX4vcf+t4RJhM/5JL5OOiHCwBxI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=COWKm3vj6cl9npbNuKbPrUnx5UMrRBXertuDg30dZNEbSJvJekEWKopjU0lQQXRkQ QD56X1LMulYF1qm3Z7TpP3nE3uTKnP4JX5G/t95lYuhn6gbETrMSzJsTBSnldT+V+f sT/afxaYJj1RDuzQ0lCIiXEOsNetsGWc2AgcPbkI= Date: Fri, 11 Nov 2022 11:27:32 -0800 From: Andrew Morton To: Zhongkun He Cc: corbet@lwn.net, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). Message-Id: <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> In-Reply-To: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> References: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=COWKm3vj; spf=pass (imf26.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668194854; a=rsa-sha256; cv=none; b=qNYW0oQrMEhi2W+Rl5JrW2VZQcFzroLeScu1ShYNOeWOj3s7HCr961+/Idtix+3lXx8W6A PwLmX1szRfqHpEW0zyiFZtd9/fARrlAkNjCZlyRyxDtiv54OQT//ogHh64gfBaADs840xU 9Bnq5R8TkRL7j5oRLS6jr17ilb/T5z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668194854; 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=6DDRAkjkKeJ4HiNFj7bmEiQoWB+I88gc6eF1MlqzeXU=; b=sSQwvkac/q7vypTN/aRURjJT+UYxTWefhKMxb3iwrfvB151eQqAPTCV6fSaZDgVnfjfrX5 DzXIAnyuiopBNiZV7SyrTXlWCOIawMp5SsYHKKILSihNM8RiG2KpGYR0FyySuFeSHw0JT2 Q1OOrFjQ7QMDtqndlxgBa2EoKup2UkQ= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A3480140005 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=COWKm3vj; spf=pass (imf26.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Stat-Signature: g114qttitm6axi7t4ginx5f9iqpepz3j X-HE-Tag: 1668194854-116892 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: On Fri, 11 Nov 2022 16:40:51 +0800 Zhongkun He wrote: > Page allocation usage of task or vma policy occurs in the fault > path where we hold the mmap_lock for read. because replacing the > task or vma policy requires that the mmap_lock be held for write, > the policy can't be freed out from under us while we're using > it for page allocation. But there are some corner cases(e.g. > alloc_pages()) which not acquire any lock for read during the > page allocation. For this reason, task_work is used in > mpol_put_async() to free mempolicy in pidfd_set_mempolicy(). > Thuse, it avoids into race conditions. This sounds a bit suspicious. Please share much more detail about these races. If we proced with this design then mpol_put_async() shouild have comments which fully describe the need for the async free. How do we *know* that these races are fully prevented with this approach? How do we know that mpol_put_async() won't free the data until the race window has fully passed? Also, in some situations mpol_put_async() will free the data synchronously anyway, so aren't these races still present? Secondly, why was the `flags' argument added? We might use it one day? For what purpose? I mean, every syscall could have a does-nothing `flags' arg, but we don't do that. What's the plan here?