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 49D2AC38142 for ; Mon, 23 Jan 2023 17:16:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE1D6B0074; Mon, 23 Jan 2023 12:16:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AAEDA6B0075; Mon, 23 Jan 2023 12:16:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94EE96B0078; Mon, 23 Jan 2023 12:16:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 865696B0074 for ; Mon, 23 Jan 2023 12:16:15 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D5CEB1C71A0 for ; Mon, 23 Jan 2023 17:16:14 +0000 (UTC) X-FDA: 80386717068.27.F81DFA9 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf15.hostedemail.com (Postfix) with ESMTP id 41E11A000A for ; Mon, 23 Jan 2023 17:16:10 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=AtlDpGDr; spf=pass (imf15.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 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=1674494171; 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=E3QyA5tV4ij54OKFg/BSxirkicwOIIF6CWUxZDpWF10=; b=C4gRWIfOXZ4sq2xKNqEx/9T0gX6jZgw8IoQrXk3ujN+C5AKLpNG2l5B8D3eNRzA74c66AP guwBmrhVzhVztM1cZHOXwRhX/FeLh/Aw8CaAlHzHCH3gahyQAcMl/pIDLaYjd2ttIy1xBt Sj3jDIVL25mT0Dshn2jgRksKiS8AC+U= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=AtlDpGDr; spf=pass (imf15.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674494171; a=rsa-sha256; cv=none; b=2shiv3JzopnGSF9HAayWVzFyyy30DzMA5G7Npj0iig7PbqeyaGpAGSdaCUCdWRg0giyWcE H1ByHQjymotd/71UPRLOYhhoMtNZx6kiuGZZQy+bkxY+KjxaQlNJ/Qm2KCeja9CNZlZenF ol7LDg/FL6bf7hVmkIFES0/7qA0jTmU= 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 C3D803368D; Mon, 23 Jan 2023 17:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674494169; 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=E3QyA5tV4ij54OKFg/BSxirkicwOIIF6CWUxZDpWF10=; b=AtlDpGDrQS1l2ngKwtZOdy5knRnagGprgIgeJGZtYrGHv/G2od26NO/Jhh/7oIBqPIt+AA XefbkiDdmsnw/lJQV+n5YOC0LH4k7estyyE+NkwdWuEjSwEqN7BvYH1bKZmG+856FRNra+ UPnPGPgvws6jda5Y10QPR9iVNdL1XGI= 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 99BA61357F; Mon, 23 Jan 2023 17:16:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pqYEJdnAzmNEFQAAMHmgww (envelope-from ); Mon, 23 Jan 2023 17:16:09 +0000 Date: Mon, 23 Jan 2023 18:16:08 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: Matthew Wilcox , "Liam R. Howlett" , akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 39/41] kernel/fork: throttle call_rcu() calls in vm_area_free Message-ID: References: <20230120170815.yuylbs27r6xcjpq5@revolver> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 41E11A000A X-Rspam-User: X-Stat-Signature: tmnadutgu14ncuit5doar9rikan54j9y X-HE-Tag: 1674494170-6413 X-HE-Meta: U2FsdGVkX19x9m+rFbcK79Wih+M1cOZCOT2O7oV8+pXMTYHNlWs4TO09DTY6GuCnw8kI8A51/zAOpPYTOb/NYa+P17P6jsZJf/tozBpdZxKM4ypAreAz4AzIWFUx2DXQtic/czC+/mqnKdemCM365WunbECw2RdsGdgYlrDlL2PQJoIjIxlkKzE5jvKa5UOpIMekKbl7qhUc2WZbXe1byugvesG1tS1nHrVtFl/f+7wtAk1Gnu/tNVmwsgzY6JQnCSKP+6v13nCOOFZFYPQaSQOp7NsalsuUmNiRDZP/ptJvqgnAJUouiScNWviMS/s6dwg/urclRSIG5RlRl6Yp+Q0oENLQsYZZpy+teTXSWefLdGzDYDxni3eIhHidn4/iOv+mlUrf7PppCqtFnp9IMVLFNbnGxv3nTpFPm/gtPAwrVCZQtak/X1IKOTjisIefmAhUjZCA+g5USgXeeQghTZ8enWxhsSYV4dBYDQ9gedXFe8OGMH3mhRTpd2cVafxBY7LMFX61yTYYRnmHvf+RrOnZnOm0FhTYHPIOTY2J5fHlvy/kD6Xn5/ChAfe8mC5qq0R3I6FGxJwxjQ76Ha+uZJRqOrjnQ+bb9RN61Chxx/IOM0PUkWu1p6b9CWSbjtQNZhwJ32mX4g1uj0yalvNmgttf5sJwePD0RsZJ1g6G/b6+pp8MlAITnurg8+jm7HYt2Eu6VV+FIby24mrj91QaM0UiupmFBKzoeuGGhIr+L9OtFwBuFI1YJr1Ez56IFu5h8w3mlImBOGXoJG0ukEcMMV+CrXNIB+eTprCayJaI+tHaVAePx6THnA9Vg3G5ExNUGd7YAuFRxBjf4iE/LWQ5i5dD8tf6c5f4pUuTrgF1lPjMfpHluGhBdhRFcUCe/HgJOKi0wHWTjoNDOVNorc5nuE1RdG9Ed84PzGlEU9wdYYmFrV4E8IfpB70BcXM2llt9rqM3OYqJJv4/R8olUTX 5P4EZd+I FNdwqJ4EjljH7NDNdG6IkUCcc7Abh/9vXsezFryXd2gz4huYFGTZXReTqs5m9GXMeeCODCSzk66dP5XTWJD68hck/JpJP3E1tuUdUz5fam1UEGFhVi4y+FJhg8x5KvLCg9M2lxxFTaORQMKQ3zdn+EHsZB/uRmtkWVgisq/n35XNQ6SPbFruox8Z73LfmP/0lzC5wxo0VdXCRssPCW4bKpLyw6QHlB0fNhS37rf8gUZJT7J3SKDQjx0XM+lnwG0tmzoE+3RiUAr1H41dmGE5xxsr5AMbsy5BH0kAOdApkNBGLy97d3MXKsOU9l6kkmemvswy00YLv/6UOmYA= 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 23-01-23 09:07:34, Suren Baghdasaryan wrote: > On Mon, Jan 23, 2023 at 8:55 AM Michal Hocko wrote: > > > > On Mon 23-01-23 08:22:53, Suren Baghdasaryan wrote: > > > On Mon, Jan 23, 2023 at 1:56 AM Michal Hocko wrote: > > > > > > > > On Fri 20-01-23 09:50:01, Suren Baghdasaryan wrote: > > > > > On Fri, Jan 20, 2023 at 9:32 AM Matthew Wilcox wrote: > > > > [...] > > > > > > The page fault handler (or whatever other reader -- ptrace, proc, etc) > > > > > > should have a refcount on the mm_struct, so we can't be in this path > > > > > > trying to free VMAs. Right? > > > > > > > > > > Hmm. That sounds right. I checked process_mrelease() as well, which > > > > > operated on mm with only mmgrab()+mmap_read_lock() but it only unmaps > > > > > VMAs without freeing them, so we are still good. Michal, do you agree > > > > > this is ok? > > > > > > > > Don't we need RCU procetions for the vma life time assurance? Jann has > > > > already shown how rwsem is not safe wrt to unlock and free without RCU. > > > > > > Jann's case requires a thread freeing the VMA to be blocked on vma > > > write lock waiting for the vma real lock to be released by a page > > > fault handler. However exit_mmap() means mm->mm_users==0, which in > > > turn suggests that there are no racing page fault handlers and no new > > > page fault handlers will appear. Is that a correct assumption? If so, > > > then races with page fault handlers can't happen while in exit_mmap(). > > > Any other path (other than page fault handlers), accesses vma->lock > > > under protection of mmap_lock (for read or write, does not matter). > > > One exception is when we operate on an isolated VMA, then we don't > > > need mmap_lock protection, but exit_mmap() does not deal with isolated > > > VMAs, so out of scope here. exit_mmap() frees vm_area_structs under > > > protection of mmap_lock in write mode, so races with anything other > > > than page fault handler should be safe as they are today. > > > > I do not see you talking about #PF (RCU + vma read lock protected) with > > munmap. It is my understanding that the latter will synchronize over per > > vma lock (along with mmap_lock exclusive locking). But then we are back > > to the lifetime guarantees, or do I miss anything. > > munmap() or any VMA-freeing operation other than exit_mmap() will free > using call_rcu(), as implemented today. The suggestion is to free VMAs > directly, without RCU grace period only when done from exit_mmap(). OK, I have clearly missed that. This makes more sense but it also adds some more complexity and assumptions - a harder to maintain code in the end. Whoever wants to touch this scheme in future would have to re-evaluate all of them. So, I would just avoid that special casing if that is feasible. Dealing with the flood of call_rcu during exit_mmap is a trivial thing to deal with as proposed elsewhere (just batch all of them in a single run). This will surely add some more code but at least the locking would consistent. -- Michal Hocko SUSE Labs