Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2633173rwb; Fri, 11 Nov 2022 12:15:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AHF8e3NE6uZFPvb7fk47DJd24RIQMUwkmzfco2A9JFXujbewnnUl13G9RMMnk9z5edKBH X-Received: by 2002:a17:90a:ba84:b0:213:b0e:ede8 with SMTP id t4-20020a17090aba8400b002130b0eede8mr3595067pjr.89.1668197702859; Fri, 11 Nov 2022 12:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668197702; cv=none; d=google.com; s=arc-20160816; b=fHHdWNXglyB9WiU8V1aVISlpPbMhUWoxmj5IKOAmKoyItIiqhU0FSvHy5BNQu0phoX 9fD9p7956vwq8zc1oKsUzg1nAll0DEYZWqWtcWZxaqi/36gGNGDdgsMsIcWPtDIdgVrZ R2qT2VhlQTaGvLoRjWa8AmW/toD03lBFFFKY6YLvTCUTH5ecdFsDOekh7SM402Xc+m/X vJFLH+s12tgUX3OLJUx3MxDff1HLU2iOeACpgyr//xqYqXsGUDlxHLVHcnCFuMmWLKZa /nWXFu8OXqjB4POPZyDHNv44GGi8O7myn9ppCKWNTcD41ngna/CX7PRQj1d/nPqbNFzL U/8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6DDRAkjkKeJ4HiNFj7bmEiQoWB+I88gc6eF1MlqzeXU=; b=Y70fIxpitN9LHPglocCIklJIdDOmalfxfCP8xh/CRBgI5HXy+6/KRJXWA+H2BaJItm rPfUfq9f2pFiRdM+tF1lpBemHH9Zz4vb4dWQ+PY4MxjKsxeZl3SgqjXzKhoJOyyZUIfP 7JnLTrjpYmxAAbd9w/ash8Tc9MrtSHZV2elthiAz0fXMaji84q9ElNz6wWH8pyyJ08JC qt3akdVTKK7IbmDc78QzOw9o9rCLPXxAyEIZAnnrT4QSBZos8FxUHabPiYXtjRcjnPO+ A64TzhZeatnzTf1ZYQKRrbo9rtSi5pGzoFv+5FQNP1QrYBrbOJoCEMk+LGdOlqqWCHsM QOhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=COWKm3vj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ja5-20020a170902efc500b0018870678209si2881940plb.257.2022.11.11.12.14.51; Fri, 11 Nov 2022 12:15:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=COWKm3vj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233551AbiKKT1g (ORCPT + 91 others); Fri, 11 Nov 2022 14:27:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbiKKT1e (ORCPT ); Fri, 11 Nov 2022 14:27:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 224FE67F4F; Fri, 11 Nov 2022 11:27:34 -0800 (PST) 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 ADBD9620BC; 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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?