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=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 2BE70C12002 for ; Wed, 21 Jul 2021 15:56:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B759F6120D for ; Wed, 21 Jul 2021 15:56:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B759F6120D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 366B76B0081; Wed, 21 Jul 2021 11:56:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 317C46B0088; Wed, 21 Jul 2021 11:56:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DF046B0089; Wed, 21 Jul 2021 11:56:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 053806B0081 for ; Wed, 21 Jul 2021 11:56:14 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AC3E71C9B0 for ; Wed, 21 Jul 2021 15:56:14 +0000 (UTC) X-FDA: 78387046668.35.C3E5912 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf16.hostedemail.com (Postfix) with ESMTP id 735B0F0027AC for ; Wed, 21 Jul 2021 15:56:14 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id m83so2587125pfd.0 for ; Wed, 21 Jul 2021 08:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=z/3hbAsJ6hHRh2rV5PKBBKqWA8JlmZPRUnge7XIh/YQ=; b=ehQoWoN4b32AKEfbvzq/TqZJcLxqy2qFsIQziLzJY6uB8BoZ6VYVXo7jbfZA7sVLhS 8fwH8/fgfuxwV65KU8TnaTBtuJkomxvtsAn2CLr52BuqX6i4x557dh/zFbderYhUX1Df QDSSRw1+j/NyTogqgIsTFijnm02thPGW7FqPn2BBof24v+z2kXpV5f9hFCwJS0L1kAGk Y3/u7w7mpkBuq+fL9JkzBCLDmamQVNFhqZ+b/ZCY/RJgbAxBX/Zpy9smexy1YOE1lTZF 9OkteuG+A1w/N40tI8fQh95DzeFnb5Qg8mvr19ukAQtdgJtNvytkN1HA+jZWxrIVQU+/ +Pig== 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=z/3hbAsJ6hHRh2rV5PKBBKqWA8JlmZPRUnge7XIh/YQ=; b=k+G+7+tFohfI2ofbULEVUIv7pQCJeBZ3IqfvG2U4Au5y+an4108ZQUM/pwir61LotH e5cFXTnpWEWRKAk32x8ZF8sWGRP0GE0DljBA5r+9mu/BiidFnV6TQKWnDyYGCs5HgPtN 6ayHhuafFhn1Cb1PqKhRmjhItP+lS5AmH2vwmQ+lqvvl6Pw6lSeKZnCShPUt/EzY7DSY HA1/rIySJAlgFSapkSxrB4qm6BgH7fc5QHGCJq0LGFdYh2i/dsl0rV21RCif7MxbGeEz woN5360fyZ9sS6q7ORY2rU00r5TKiRrKLgLRv6tZ3I6lFv5eX9OOWRosb7h36nRzzuDo Nk6Q== X-Gm-Message-State: AOAM5334SM/kvBxlQoPkU71n4T2MJotPs+DUwjBLK/YB11jNn182iH0W ca2Fba1As4kG2hQZNX5iEodOqA== X-Google-Smtp-Source: ABdhPJyQd9ZxyuvcAtcCKZ9XQkD55IW0oavb0JRtrpoVXiY7PwyAKlaBAOyUgIFyn8iBMuitZ9cxjA== X-Received: by 2002:aa7:8d10:0:b029:303:8d17:7b8d with SMTP id j16-20020aa78d100000b02903038d177b8dmr36719282pfe.26.1626882973209; Wed, 21 Jul 2021 08:56:13 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id e23sm26592454pfd.26.2021.07.21.08.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:56:12 -0700 (PDT) Date: Wed, 21 Jul 2021 15:56:09 +0000 From: Sean Christopherson To: Will Deacon Cc: Alexandru Elisei , Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org, Matthew Wilcox , Paolo Bonzini , Quentin Perret , James Morse , Suzuki K Poulose , kernel-team@android.com Subject: Re: [PATCH 1/5] KVM: arm64: Walk userspace page tables to compute the THP mapping size Message-ID: References: <20210717095541.1486210-1-maz@kernel.org> <20210717095541.1486210-2-maz@kernel.org> <20210721145828.GA11003@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210721145828.GA11003@willie-the-truck> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 735B0F0027AC X-Stat-Signature: 3nb456jg8xpay95zuyutadgkdrz8hcii Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=ehQoWoN4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of seanjc@google.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=seanjc@google.com X-HE-Tag: 1626882974-100937 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, Jul 21, 2021, Will Deacon wrote: > > For the page tables liveliness, KVM implements mmu_notifier_ops.release, which is > > invoked at the beginning of exit_mmap(), before the page tables are freed. In > > its implementation, KVM takes mmu_lock and zaps all its shadow page tables, a.k.a. > > the stage2 tables in KVM arm64. The flow in question, get_user_mapping_size(), > > also runs under mmu_lock, and so effectively blocks exit_mmap() and thus is > > guaranteed to run with live userspace tables. > > Unless I missed a case, exit_mmap() only runs when mm_struct::mm_users drops > to zero, right? Yep. > The vCPU tasks should hold references to that afaict, so I don't think it > should be possible for exit_mmap() to run while there are vCPUs running with > the corresponding page-table. Ah, right, I was thinking of non-KVM code that operated on the page tables without holding a reference to mm_users. > > Looking at the arm64 code, one thing I'm not clear on is whether arm64 correctly > > handles the case where exit_mmap() wins the race. The invalidate_range hooks will > > still be called, so userspace page tables aren't a problem, but > > kvm_arch_flush_shadow_all() -> kvm_free_stage2_pgd() nullifies mmu->pgt without > > any additional notifications that I see. x86 deals with this by ensuring its > > top-level TDP entry (stage2 equivalent) is valid while the page fault handler is > > running. > > But the fact that x86 handles this race has me worried. What am I missing? I don't think you're missing anything. I forgot that KVM_RUN would require an elevated mm_users. x86 does handle the impossible race, but that's coincidental. The extra protections in x86 are to deal with other cases where a vCPU's top-level SPTE can be invalidated while the vCPU is running.