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 65A73C4332F for ; Mon, 14 Nov 2022 17:52:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E754E6B0085; Mon, 14 Nov 2022 12:52:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E24BB8E0001; Mon, 14 Nov 2022 12:52:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D13996B0088; Mon, 14 Nov 2022 12:52:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BDDD16B0085 for ; Mon, 14 Nov 2022 12:52:30 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 80ADB1601CC for ; Mon, 14 Nov 2022 17:52:30 +0000 (UTC) X-FDA: 80132792460.22.D9277E8 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf21.hostedemail.com (Postfix) with ESMTP id D351B1C0008 for ; Mon, 14 Nov 2022 17:52:28 +0000 (UTC) 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-out2.suse.de (Postfix) with ESMTPS id 77AE6201F5; Mon, 14 Nov 2022 17:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668448347; 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=oz8YSs1KJVliL/2aW1xDmRDRza50VBN/mTm9YScVZfs=; b=Y7mniaueGfgQQjcdXcDLeViStkDPrq7bUWrxQ9o2ohcp0QX5wurHpemxDWEX/zyxIOdmm4 ahN5H42yYKyGTub1/teRDQiBDers0olzs/sQdNyHWyzegi4XILIzw9ztJ+U17DtAold1J9 mK8yFHRHrgIBlzzsXDf0DBt/EnYMRjI= 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 5BFF613A8C; Mon, 14 Nov 2022 17:52:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HmkyFFuAcmMmZgAAMHmgww (envelope-from ); Mon, 14 Nov 2022 17:52:27 +0000 Date: Mon, 14 Nov 2022 18:52:26 +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: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668448349; a=rsa-sha256; cv=none; b=wzfZCY0w+nCA6qAtscH6Oi0/5KQl2yElRiIBlfrCYNtdL7FcDgCyDT5/mNilsEL29x6Des Pfx376TSQURVsYHVFYqZu7AQ5iZQj+oQb6V+ArGa//a/4+C2s1pmwpuTcs8FXVi0ifM6fx WLni27CIoLoYwQ+UHSJGkrhQwdHIbEM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Y7mniaue; spf=pass (imf21.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668448349; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oz8YSs1KJVliL/2aW1xDmRDRza50VBN/mTm9YScVZfs=; b=nvd17d1n15rCu1xptX+nDTTZQAu+m5yMEr1FEKhdm5IiCofsww78yDnqebFGmq0jGwkDOT lnrkZ6EpFobtJPI7k6ovRwGeLVBq0Vv96a6sIBsxpwqCS25DFQmoQovfCdkNlv8Ml2SpE3 UUl/0gXNDgfoqMyo+hmRrA4dQA7lpu4= X-Stat-Signature: 5stqk6nszuudkwwfq7iehfoet8eiqrqj X-Rspamd-Queue-Id: D351B1C0008 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Y7mniaue; spf=pass (imf21.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1668448348-947077 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 Mon 14-11-22 12:46:53, Michal Hocko wrote: > 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. Scratch that. I've managed to confuse myself. Multi-threading doesn't play any role as the mempolicy changed by the syscall is per-task_struct so task_work context is indeed mutually exclusive with any in kernel use of the policy. I will need to think about it some more. -- Michal Hocko SUSE Labs