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 37C36C636CA for ; Wed, 21 Jul 2021 15:56:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F31F61221 for ; Wed, 21 Jul 2021 15:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240006AbhGUPPi (ORCPT ); Wed, 21 Jul 2021 11:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239930AbhGUPPi (ORCPT ); Wed, 21 Jul 2021 11:15:38 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4C14C061575 for ; Wed, 21 Jul 2021 08:56:13 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id i16so2288927pgi.9 for ; Wed, 21 Jul 2021 08:56:13 -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=amvRLu9uVezdI7V9LLeBzjYdFE+S7haR/vx3dGEMKlRAYGgEn226srUKfg5+TWr1cX sn+boGmKYM2F+YTtyA8Ivu7mEunXYWqxAdNMB3QtdGyglAjyxT1lPt0vcO6n7ayG0Z5V aq0TOfmkHdtQrTlociLuw2Sv44l5aY5tj4dKxr8HXGkGP1TmHSVzYz2hEYKCxW/JUUjw W/OXm3Yf0mZ/qQ2sNfD4PbzH1l8mEL2IGyNOmFvzeWNKXDi01g7fbinRWjyNNB20bxHc rYaucmS7Vg40dluj8AUsR9+Q9Vmd+VU+hWPRSeH9MSODKk2PNlJ9lsaDJMeCx7JZ+KTG M/bQ== X-Gm-Message-State: AOAM533eBaGVBf+iyI7RCXkEGol5s0vG1ZG9vag3rJG9+SnvLwvtZNwt vrcVlPFK5NBM7I0M0TyVbPTPgA== 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> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. 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=-1.9 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FSL_HELO_FAKE,HEADER_FROM_DIFFERENT_DOMAINS, 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 E430AC12002 for ; Wed, 21 Jul 2021 16:13:24 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 6E702608FC for ; Wed, 21 Jul 2021 16:13:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E702608FC Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id B56D44B10A; Wed, 21 Jul 2021 12:13:23 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YPREoPJLcFMk; Wed, 21 Jul 2021 12:13:22 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A45574B111; Wed, 21 Jul 2021 12:13:22 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 87F5C4B0B2 for ; Wed, 21 Jul 2021 11:56:15 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KOc8GZBKgNHd for ; Wed, 21 Jul 2021 11:56:14 -0400 (EDT) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 650544B0AD for ; Wed, 21 Jul 2021 11:56:14 -0400 (EDT) Received: by mail-pg1-f177.google.com with SMTP id a6so2314558pgw.3 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=GJeqjFRYdFYq+BDo/dFkYh0WQUI5Jo8WHQHu8HU7h8gDMZk3zz5fmCou83/05Ci1Jb t0HctktDsKmwYD4VH4Sj+tqsvH0EHccayA+qJ6OUrSveRQ4YOX+9H8hMAwlEDw8KSt0n PutQgpEXVnAdja5FDj6CFDHyIlHYZ/iVvGkQBURimQ+UJ3D0biD8XCQnXH1IuCGXLrPK 5EM7caYCPuASMY2Ndx80WwYSEomDG+ea+YKD+IVZW2iBa0y1rhGJXef6UkyPvzyoL2Fj jRUVt2WjWAnjz0x5PWeJX6cXzh+yBRcvxKRjwJRx4JnjrdoylX7XBC+tXVJ/cSOx0I+Q zmBQ== X-Gm-Message-State: AOAM533CWGaqz7NpeeBvAsJ6HYeOYSwSAaFXvfmNnR161F00rwPlPIIF g9LThTkgfDPiq1m4RLokYhZr7Q== 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 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-Disposition: inline In-Reply-To: <20210721145828.GA11003@willie-the-truck> X-Mailman-Approved-At: Wed, 21 Jul 2021 12:13:21 -0400 Cc: kernel-team@android.com, kvm@vger.kernel.org, Marc Zyngier , Matthew Wilcox , linux-mm@kvack.org, Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu 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. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-3.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,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 DB192C12002 for ; Wed, 21 Jul 2021 15:57:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB94560C3E for ; Wed, 21 Jul 2021 15:57:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB94560C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Kk5gPBOntA2Ml0CrYmbO/CYac0aWL92Yr9on/cKuH5A=; b=Qv0jlSozVLZss5 mqG+Vts8W3jjanFMEFX6mCzCZimqUn37GTFbjgEM8fB4S8L8Dcw9ZM/WZlw0jrVkZnGpbDCshkL1Z mg+K2KlVtpuo/Hk/RiereP60Te6MWsHD0mJzDOQJwC02GeY3wnyo/DKaXUSJXrCgjrgLVk8RXJuCt gEwkhKqky/5he7gMrME3p0AOs2Y56R7t7gVOKGezY2HCYfsraGLnA8k11UXW5iaiB1sfH+nThoXkI QjhSXCnWw0almDITGGxpu03tQgwJMz0+cFSpHB/JEocrO9wJuEI3u5NOOh92TfHuh1MeT7OPWROqd OMoIw1Xi2HCNUKwpBMYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Ea2-00GSFO-5G; Wed, 21 Jul 2021 15:56:18 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6EZy-00GSDr-FG for linux-arm-kernel@lists.infradead.org; Wed, 21 Jul 2021 15:56:15 +0000 Received: by mail-pg1-x52d.google.com with SMTP id k20so2298710pgg.7 for ; Wed, 21 Jul 2021 08:56:13 -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=PstMgoa3L6EETa0brusBQAIFg9RHKzNv8fUB/MWNuGUN1+gE8pQzzKV18vR2atj9Qt JBPdB18yGWZdcJyvMKCBgEHjuZKpw3wQbn8L/+ibjaXAS4Cs9wrsS0CXwOeuJudYyKG3 BWzVsqFA6goa4IFuDeClOTMZRozVtlGTYwg0Z+z4a9j0ySpuq+GviIo+zwZdN2I6yRFE vvd3Pk9Y23ekBg70qCEy0UDZ3HVxd9bEz4fh0UEmIv+MycbLJl4C74saZtuRG1lQ0hUf jgAW+Sv6mGXyrJHZVDdvaPGeEg46ESiex8I2oeFdyjrJXa//MskchlHSWEvL5Di1uydV Xn0g== X-Gm-Message-State: AOAM531EuiMpYVV6ZHm8VEEy+TQ6kyJnVLlKLnLKjdqp1tCYxg5h+IBh ekYltZ1pbx5w490Q9cjeXgF3vpcg+Vdx1Q== 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-Disposition: inline In-Reply-To: <20210721145828.GA11003@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210721_085614_578758_46875442 X-CRM114-Status: GOOD ( 20.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel