Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3900425ybb; Mon, 23 Mar 2020 09:45:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtz7FjX8wQ7tQaFQ0/zc/+v5XWmSsKgY8LHZdKkqw59+ZCUhaw0P/UnhfnkxFT7bRhlphV9 X-Received: by 2002:aca:d44d:: with SMTP id l74mr145690oig.83.1584981911255; Mon, 23 Mar 2020 09:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584981911; cv=none; d=google.com; s=arc-20160816; b=e9ur4krKG+LekwHmErMTfftKWql99rZNxwmzMSFCrxX4wau+xFyyGJOZFVcwU6jdYD n+dyu4RbuLY82SRnrIXPcjQO4JOY4QDLPzRpn/YkApS3gAYsge73dBBqo5QML8NTm4lJ 1QRYjYt9zqAz+XAWPokcOwy5lxEkWEqVeUGDjv2eDmwaEnOSeUTwgXlJwEzfYLwIOyyQ arbqTnHlDnY4wY3rLiSdOWDdn6MHxsHnLRyyN7P02AFoTUFJvKoBIcZwUZ1JbUetQOxK JW+HD3TXIWpTSjUEodv6v/lStkKb+7q28k5qZKr1Eq0l6Hq6RCQp9swOT5ZzX8Pm5sqR MnyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gOqUZhrB3tbP37O07iZXzI++c1tt+580wf55GATS2SM=; b=tbTdRgI6ZycqtFb8Shv7ySSe4THOXZcgixalqxA6TMZsfQ7yf15OXqOzyC2UtWi7/Z nkimn1gv8Ti952b0oMy7h7V3cU4VqlMoeyeRcirw4MFKwEZ2KLMqH+3/46Jesat/qTga hS1xNu/lA71I0LhFim1MLSIYJW7dY5UTaOVh0MGvMmCPuVz7+Kx361N+ZhMezI/f+8Hp fHPzWxTPXhh2fWGsE1jm4AzHWAzbhJYZYZhkqyiHsvcNvDda70BpmFmzqJW+euKietjX YcxbxVxM4RWK4OedD6fnjLCQnYJK2wPhKc2LUmqgFHLFlXKHZt1HjbJH6voLb0DeNGOj 79Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=CHkzV0CU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g141si7887912oib.45.2020.03.23.09.44.57; Mon, 23 Mar 2020 09:45:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=CHkzV0CU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727545AbgCWQoG (ORCPT + 99 others); Mon, 23 Mar 2020 12:44:06 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:42440 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727458AbgCWQoG (ORCPT ); Mon, 23 Mar 2020 12:44:06 -0400 Received: by mail-qk1-f196.google.com with SMTP id e11so15928289qkg.9 for ; Mon, 23 Mar 2020 09:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gOqUZhrB3tbP37O07iZXzI++c1tt+580wf55GATS2SM=; b=CHkzV0CUaFfnHgtED9IRJD4ztA7/XKt6w3TMqe+emVP/CoIvuvXtYA2Rntt9fhIupT FDhFCWE3zOJ+1mdE4OhnqVBGkGJplnaoVMH6yWifoIndPxyJWU6t2TbUiHx+Fabkz4AU Bo6VUH5I/z+vdpQyLloUPnUFcyCsVgk/ZKOq7fZWdshq+tD1F2JqhgynUuOC9Clph639 oYUZtEi9XKMwwJh4wsqKYBmavQEBgUhAg1WuJMXTB5ek2FIUwDvyCE3rofJYHNfQbqHY 1ibApMJdvmmqRPne6+/xBnr+WdEY9aK5/EWxYtSutuEpgLnfjdVKLjxpd/vvow8QZIkD 0bzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=gOqUZhrB3tbP37O07iZXzI++c1tt+580wf55GATS2SM=; b=faGh7Gy2+xv3bRcI5SYV8dqyEpf4E2ykLzgVG/m2QIlJdK4uncxt4J/lZI3gy0cFf9 o09kI/FHbG+bYNZYkPnm8wYCUI8gjr8Zh5mBhVEOwQLnq6P4161dv0U9W3VjVye4240X P61RC9YCj0lcFelu37ENzjLdCcM6lEW7tm+8XdnQNpIA+mwIEg9STIW+Ejx/OO8pv7bE cEjKDuqU9MTGKVZAk66ZlaCFE1UghN+5C3OZ7YfvqZ+spmnau2K5K3e3/iPMDKQlT+8W qccJBOjmEs9CDqshiSt2w+FzA7JZKB5De15v2kD2+u2qfISfOR6MWF+BZ31x2gMPIFSQ 5C9w== X-Gm-Message-State: ANhLgQ2YptI3X84iXrRiVqDUHmC/gXlax7WPfz5P4PHj4Os6pA3GiJ2l xATeaN4o1jtTsejX8L0vQqud4A== X-Received: by 2002:a05:620a:84d:: with SMTP id u13mr21724625qku.94.1584981845232; Mon, 23 Mar 2020 09:44:05 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id f13sm12827393qte.53.2020.03.23.09.44.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Mar 2020 09:44:04 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jGQBH-0005fK-Aj; Mon, 23 Mar 2020 13:44:03 -0300 Date: Mon, 23 Mar 2020 13:44:03 -0300 From: Jason Gunthorpe To: Sean Christopherson Cc: Mike Kravetz , "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" , akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, arei.gonglei@huawei.com, weidong.huang@huawei.com, weifuqiang@huawei.com, kvm@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox , stable@vger.kernel.org Subject: Re: [PATCH v2] mm/hugetlb: fix a addressing exception caused by huge_pte_offset() Message-ID: <20200323164403.GZ20941@ziepe.ca> References: <1582342427-230392-1-git-send-email-longpeng2@huawei.com> <51a25d55-de49-4c0a-c994-bf1a8cfc8638@oracle.com> <5700f44e-9df9-1b12-bc29-68e0463c2860@huawei.com> <20200323144030.GA28711@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323144030.GA28711@linux.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 07:40:31AM -0700, Sean Christopherson wrote: > On Sun, Mar 22, 2020 at 07:54:32PM -0700, Mike Kravetz wrote: > > On 3/22/20 7:03 PM, Longpeng (Mike, Cloud Infrastructure Service Product Dept.) wrote: > > > > > > On 2020/3/22 7:38, Mike Kravetz wrote: > > >> On 2/21/20 7:33 PM, Longpeng(Mike) wrote: > > >>> From: Longpeng > > I have not looked closely at the generated code for lookup_address_in_pgd. > > It appears that it would dereference p4d, pud and pmd multiple times. Sean > > seemed to think there was something about the calling context that would > > make issues like those seen with huge_pte_offset less likely to happen. I > > do not know if this is accurate or not. > > Only for KVM's calls to lookup_address_in_mm(), I can't speak to other > calls that funnel into to lookup_address_in_pgd(). > > KVM uses a combination of tracking and blocking mmu_notifier calls to ensure > PTE changes/invalidations between gup() and lookup_address_in_pgd() cause a > restart of the faulting instruction, and that pending changes/invalidations > are blocked until installation of the pfn in KVM's secondary MMU completes. > > kvm_mmu_page_fault(): > > mmu_seq = kvm->mmu_notifier_seq; > smp_rmb(); > > pfn = gup(hva); > > spin_lock(&kvm->mmu_lock); > smp_rmb(); > if (kvm->mmu_notifier_seq != mmu_seq) > goto out_unlock: // Restart guest, i.e. retry the fault > > lookup_address_in_mm(hva, ...); It works because the mmu_lock spinlock is taken before and after any change to the page table via invalidate_range_start/end() callbacks. So if you are in the spinlock and mmu_notifier_count == 0, then nobody can be writing to the page tables. It is effectively a full page table lock, so any page table read under that lock do not need to worry about any data races. Jason