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 X-Spam-Level: X-Spam-Status: No, score=-6.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B393C433B4 for ; Wed, 28 Apr 2021 16:11:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 762476142A for ; Wed, 28 Apr 2021 16:11:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 762476142A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8287A6B00C8; Wed, 28 Apr 2021 12:11:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D7686B00C9; Wed, 28 Apr 2021 12:11:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62AA66B00CA; Wed, 28 Apr 2021 12:11:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 3FD186B00C8 for ; Wed, 28 Apr 2021 12:11:11 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E4C388249980 for ; Wed, 28 Apr 2021 16:11:10 +0000 (UTC) X-FDA: 78082265100.20.4234898 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP id 5AEFF600010A for ; Wed, 28 Apr 2021 16:11:03 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 2371D61407; Wed, 28 Apr 2021 16:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619626269; bh=1I9gQXY80qwKA6TumfD7Ydm/GIdUx7cZWoqKVciceg4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=UH3Z8WW0pbZYmpyctNRIhvTFCwIT2/3MNoyuyDrbmnqkFb6IEax+ZfFGgvgQRIGc7 Ehc9MO5lRF1ixSkMXLhKIyll9ZYJobiPY0THw7FCKuAheSkY4uhCjss8VXnAF1FMNb mF89JN7UbvzvCNTg1k8Pv3JnCeLOUIj0W+uS47BxF1uF4TQnetsJDI9Fm+x2QgdGr1 3YmmwAtlRUzZGCANL7yQNBGRsChfWCu3EYa172VaOtih4hPU7CSBdsDiGGqm0vJZ/3 zONS9Ll/Ltx/UWrTsSed5e2VOchEjvstVb8BxW8q4/g+MQqOv2tDhQWEuhL9Lyun4f PiRdQoGmnhDCQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id AF1FD5C0163; Wed, 28 Apr 2021 09:11:08 -0700 (PDT) Date: Wed, 28 Apr 2021 09:11:08 -0700 From: "Paul E. McKenney" To: Andy Lutomirski Cc: Michel Lespinasse , Linux-MM , Laurent Dufour , Peter Zijlstra , Michal Hocko , Matthew Wilcox , Rik van Riel , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Rom Lemarchand , Linux-Kernel Subject: Re: [RFC PATCH 13/37] mm: implement speculative handling in __handle_mm_fault(). Message-ID: <20210428161108.GP975577@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210407014502.24091-1-michel@lespinasse.org> <20210407014502.24091-14-michel@lespinasse.org> <20210428145823.GA856@lespinasse.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 5AEFF600010A X-Stat-Signature: hzso94ix3gew7nojrh43t7xgnpm8hdw8 X-Rspamd-Server: rspam02 Received-SPF: none (kernel.org>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619626263-23335 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 Wed, Apr 28, 2021 at 08:13:53AM -0700, Andy Lutomirski wrote: > On Wed, Apr 28, 2021 at 8:05 AM Michel Lespinasse wrote: > > > > On Wed, Apr 07, 2021 at 08:36:01AM -0700, Andy Lutomirski wrote: > > > On 4/6/21 6:44 PM, Michel Lespinasse wrote: > > > > The page table tree is walked with local irqs disabled, which prevents > > > > page table reclamation (similarly to what fast GUP does). The logic is > > > > otherwise similar to the non-speculative path, but with additional > > > > restrictions: in the speculative path, we do not handle huge pages or > > > > wiring new pages tables. > > > > > > Not on most architectures. Quoting the actual comment in mm/gup.c: > > > > > > > * Before activating this code, please be aware that the following assumptions > > > > * are currently made: > > > > * > > > > * *) Either MMU_GATHER_RCU_TABLE_FREE is enabled, and tlb_remove_table() is used to > > > > * free pages containing page tables or TLB flushing requires IPI broadcast. > > > > > > On MMU_GATHER_RCU_TABLE_FREE architectures, you cannot make the > > > assumption that it is safe to dereference a pointer in a page table just > > > because irqs are off. You need RCU protection, too. > > > > > > You have the same error in the cover letter. > > > > Hi Andy, > > > > Thanks for your comment. At first I thought did not matter, because we > > only enable ARCH_SUPPORTS_SPECULATIVE_PAGE_FAULT on selected > > architectures, and I thought MMU_GATHER_RCU_TABLE_FREE is not set on > > these. But I was wrong - MMU_GATHER_RCU_TABLE_FREE is enabled on X86 > > with paravirt. So I took another look at fast GUP to make sure I > > actually understand it. > > > > This brings a question about lockless_pages_from_mm() - I see it > > disabling interrupts, which it explains is necessary for disabling THP > > splitting IPIs, but I do not see it taking an RCU read lock as would > > be necessary for preventing paga table freeing on > > MMU_GATHER_RCU_TABLE_FREE configs. I figure local_irq_save() > > indirectly takes an rcu read lock somehow ? I think this is something > > I should also mention in my explanation, and I have not seen a good > > description of this on the fast GUP side... > > Sounds like a bug! That being said, based on my extremely limited > understanding of how the common RCU modes work, local_irq_save() > probably implies an RCU lock in at least some cases. Hi Paul! In modern kernels, local_irq_save() does have RCU reader semantics, meaning that synchronize_rcu() will wait for pre-exiting irq-disabled regions. It will also wait for pre-existing bh-disable, preempt-disable, and of course rcu_read_lock() sections of code. But don't try this in older kernels, that is not in kernel in which synchronize_sched() is defined! Thanx, Paul