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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 543CBC4332F for ; Mon, 14 Nov 2022 11:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236815AbiKNLvc (ORCPT ); Mon, 14 Nov 2022 06:51:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236634AbiKNLvN (ORCPT ); Mon, 14 Nov 2022 06:51:13 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A8F023BDB; Mon, 14 Nov 2022 03:46:54 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 00E3122921; Mon, 14 Nov 2022 11:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668426413; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yz5j0yLS60RhoozEN+4P1jT0Vz/W/dGC3w+wIvkQm60=; b=JqQA61DtYKzNUreBa21Ln2ee1u+Nnx3ICkr8BaOKN1saiEjcwA2jBOTq0n8NqAUZVCidL7 JpH0+hZ62Cja3fMW9DWOSUAStE2nyIg3wJaAsYseV4a7l34Scin4D5AEL2cBZhYft95Iq5 bsD5IlYSAPDifI2Kyze3U+Lo5IGCyak= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D7BB013A92; Mon, 14 Nov 2022 11:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wypfM6wqcmNzBAAAMHmgww (envelope-from ); Mon, 14 Nov 2022 11:46:52 +0000 Date: Mon, 14 Nov 2022 12:46:52 +0100 From: Michal Hocko To: Zhongkun He Cc: Andrew Morton , corbet@lwn.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). Message-ID: References: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 14-11-22 12:44:48, Michal Hocko wrote: > On Mon 14-11-22 00:41:21, Zhongkun He wrote: > > Hi Andrew, thanks for your replay. > > > > > 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? > > > > A mempolicy can be either associated with a process or with a VMA. > > All vma manipulation is somewhat protected by a down_read on > > mmap_lock.In process context there is no locking because only > > the process accesses its own state before. > > We shouldn't really rely on mmap_sem for this IMO. There is alloc_lock > (aka task lock) that makes sure the policy is stable so that caller can > atomically take a reference and hold on the policy. And we do not do > that consistently and this should be fixed. E.g. just looking at some > random places like allowed_mems_nr (relying on get_task_policy) is > completely lockless and some paths (like fadvise) do not use any of the > explicit (alloc_lock) or implicit (mmap_lock) locking. That means that > the task_work based approach cannot really work in this case, right? Just to be more explicit. Task work based approach still requires an additional synchronization among different threads unless I miss something so this is really fragile synchronization model. -- Michal Hocko SUSE Labs