Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp623698pxy; Wed, 28 Apr 2021 10:41:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0w6Lb6ba+fk7FaGaUhdbx7AewORe9T2j/PYd/674dXsgHHh6uGPe8wbpbOztZfiNG6ZHi X-Received: by 2002:a17:906:11d4:: with SMTP id o20mr2920798eja.247.1619631659834; Wed, 28 Apr 2021 10:40:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619631659; cv=none; d=google.com; s=arc-20160816; b=rvxJpa1LvTwmqEs48KH9aPjzu14J4Mzf3c0NYuR9qOHwCA9d1xfEFZ5PAzW0SS2718 /1lO6fafer2i0BaaoBi1vdQax8KLQM6EXQ5Zj5Erb3Q1PqsRGLdJTbyz8RmX4xVuF5D4 VQGDCB7ufu+2eniXewo2QzNXpdlqYFa38KmHwdUcqr0LR1vgJeHXouZ3i0d4PbWMOyV1 sXnAKmOFhAKhVsvEq/ajmWZ5IbwYeNOhEKv/EODnHB+rTBoqKXkts8S6kBwvVCq3E2RW ax/D7GT8PIAKmKY6bdwvmOJQOYh0JP/L3BDXn7N8PkBncawrSbOT12f+0dPQPUi691nZ Nl3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=v2mKR3EfiNHIMREt3mcsTTtqdI8I7w5F9I72RrHavS8=; b=YW5QCvvHRNiHjDJisuAhH3q1JPov3FkKl9DKcOnq+3PhPIJ2LPU4VJq8jpaMlJTcUv 4umpjn1kNLpJcvY0fHQOOJ9t+pIhNX8jDZ272ACzhed4ciz572R20JLjwWbyh1iocD+y t428dgM3ah863Ifipusj03OljEuwdyUpCY5xKwtInD6cXwR3mQNpWDl4GjnyZ3HdJV1e Z+efrla87AuSPSK9JRHmzkP64/OzRUZUk0zWZ50b4gZPxcnQ2B4qyswGVyE/5rZp7Fqj kCNuqDkGALW8boBGRiT49RmI60UJRmVKl3/Rggs+2MrzD9q4F33U9Y+kVfnzb6jF0/7i jaIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UH3Z8WW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m22si625502ejc.433.2021.04.28.10.40.35; Wed, 28 Apr 2021 10:40:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UH3Z8WW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240164AbhD1QLy (ORCPT + 99 others); Wed, 28 Apr 2021 12:11:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:58792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232024AbhD1QLy (ORCPT ); Wed, 28 Apr 2021 12:11:54 -0400 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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