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=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 E3FF7C433E0 for ; Thu, 4 Feb 2021 20:33:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BB1564DDD for ; Thu, 4 Feb 2021 20:33:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BB1564DDD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C47966B0005; Thu, 4 Feb 2021 15:33:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF8216B0006; Thu, 4 Feb 2021 15:33:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE61E6B006E; Thu, 4 Feb 2021 15:33:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 959196B0005 for ; Thu, 4 Feb 2021 15:33:11 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 557AC8249980 for ; Thu, 4 Feb 2021 20:33:11 +0000 (UTC) X-FDA: 77781734982.19.men30_2a158c3275df Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 294381AD31E for ; Thu, 4 Feb 2021 20:33:11 +0000 (UTC) X-HE-Tag: men30_2a158c3275df X-Filterd-Recvd-Size: 5039 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 20:33:10 +0000 (UTC) Received: by mail-qk1-f180.google.com with SMTP id r77so4674594qka.12 for ; Thu, 04 Feb 2021 12:33:10 -0800 (PST) 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; bh=Dix9FkD7Q8YvsbhJky2+W/nmTrrOT5ZKalVOWF+tmA4=; b=cDReKReTwzY2tEy8CRJVdi8dW4eTpCWSFoK/DAgetsqmSkAE0SjhMtop0C+tzZyHXe ZFYbRiqB9GdxJTTYEmeOBWpGKktel0p5pbUaRtIDGCk+m8sDube/UYt33Kam9Ddu99Rh XNEMmYFFu6iuQeUbcrdhEx7OznZh9uhoyM8jgiTREGAgvh+5nx71ab66DUY4tkuZnAqu 1HYufMlNMn1JGPbP5rTAgd+3qzl8iN+HCJHLVB/lsb6Vo/AxFckEVcxuAqnlxODzIjFW 4vFH8nqfzRKapeKAUSaYJ+aEe6hmE6tockmkb8P0l3xdZ0GnpilcTZl9Xh6JhFd9TPwS KlGw== 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; bh=Dix9FkD7Q8YvsbhJky2+W/nmTrrOT5ZKalVOWF+tmA4=; b=XlyiPantnPOHcEUZWJN9VD6zbhGMwNZlnxbzoeulzPCRgZ6F5dB9hoz3PEUAI0CrFk ozKXQCVWQW2OzWy4+pFXB75TCpGYuXvjgOktSLi9CBlWsNl9Fslc0W3olzXc9LkIhy48 EBMOyVBW1dyiss+GN7hxurcCFfmbanZxfK5F9z4zEGR73N8xdiYhaquOniwYJqFpvhQX /16vnDQXDstXJMIgTfCF6L4UiSuBfDgPCPwOJ6w+k5OJwLAVXEc1FL1KuKzEGrBsX9R0 cTSAoMQVt8QQjS1UqQ5dvQoOWjDSx9/ns84JH/KqSBJLxBPdLQiY0kABr9Iv/wBoqUNQ wsWQ== X-Gm-Message-State: AOAM530P0MvxZ46wrlpuzDi8oknumHCqt5R5XUB0Wb5cYS0dBnrB6KnT D1NEvJghgFCvsPyfnVFycJptAQ== X-Google-Smtp-Source: ABdhPJyEtwuXXyB00lgRC7eM+25Sj3EPce7HrV9Mel8mQaMcAOrHGScwlSChOxTQiprPAv/ifQ3CSg== X-Received: by 2002:a37:9aca:: with SMTP id c193mr925374qke.91.1612470789613; Thu, 04 Feb 2021 12:33:09 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-115-133.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.115.133]) by smtp.gmail.com with ESMTPSA id h8sm5398309qtm.5.2021.02.04.12.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:33:08 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1l7lJM-003bYY-Dq; Thu, 04 Feb 2021 16:33:08 -0400 Date: Thu, 4 Feb 2021 16:33:08 -0400 From: Jason Gunthorpe To: Paolo Bonzini Cc: Sean Christopherson , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Stevens , Jann Horn , kvm@vger.kernel.org Subject: Re: [PATCH] mm: Export follow_pte() for KVM so that KVM can stop using follow_pfn() Message-ID: <20210204203308.GB4718@ziepe.ca> References: <20210204171619.3640084-1-seanjc@google.com> <42ac99c2-830e-e4b7-00b9-011d531a0dda@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42ac99c2-830e-e4b7-00b9-011d531a0dda@redhat.com> 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 Thu, Feb 04, 2021 at 06:19:13PM +0100, Paolo Bonzini wrote: > On 04/02/21 18:16, Sean Christopherson wrote: > > Export follow_pte() to fix build breakage when KVM is built as a module. > > An in-flight KVM fix switches from follow_pfn() to follow_pte() in order > > to grab the page protections along with the PFN. > > > > Fixes: bd2fae8da794 ("KVM: do not assume PTE is writable after follow_pfn") > > Cc: David Stevens > > Cc: Jann Horn > > Cc: Jason Gunthorpe > > Cc: Paolo Bonzini > > Cc: kvm@vger.kernel.org > > Signed-off-by: Sean Christopherson > > > > Paolo, maybe you can squash this with the appropriate acks? > > Indeed, you beat me by a minute. This change is why I hadn't sent out the > patch yet. > > Andrew or Jason, ok to squash this? I think usual process would be to put this in the patch/series/pr that needs it. Given how badly follow_pfn has been misused, I would greatly prefer to see you add a kdoc along with exporting it - making it clear about the rules. And it looks like we should remove the range argument for modular use And document the locking requirements, it does a lockless read of the page table: pgd = pgd_offset(mm, address); if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd))) goto out; p4d = p4d_offset(pgd, address); It doesn't do the trickery that fast GUP does, so it must require the mmap sem in read mode at least. Not sure I understand how fsdax is able to call it only under the i_mmap_lock_read lock? What prevents a page table level from being freed concurrently? And it is missing READ_ONCE's for the lockless page table walk.. :( Jason