Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2521652rdb; Fri, 22 Sep 2023 00:33:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHicwGM8LNFHl6IxH3P1clxycycDezzLQ+8DSxbtCkpJ24BN2EbQO7NmX/O45NWYcF+lwcI X-Received: by 2002:a05:6870:d620:b0:1d6:3d6a:fb37 with SMTP id a32-20020a056870d62000b001d63d6afb37mr8786391oaq.46.1695368029616; Fri, 22 Sep 2023 00:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695368029; cv=none; d=google.com; s=arc-20160816; b=v5coYdvH+DTwOmUpPTi97h4yIBXXDrit40B0I1gdzhI71OsGf8uQ6m4IMIcos4EUGV c2O253Pi3F+CjwwPPBXckn76XtP4QJ5j6RzX3nXSXJ5ft6tatEloYqxPq/ZfUg9kbMjT SrHWEj0LRT8Woqc9b2Znk+YSDgJgfqe34a3S+sIVcE6SaiQjzWE2tgFRme06t0rnbU8k AOZnCanXFpYqT9DvUeonTU5SuvrPm8LFBcSlgLhkVVa5HPTvQOWtwxoK7m3HDV/gdkSj OGqUh92rT1eybdqC4D/tIp45DCN/EY14ZFx8LQeHBd+WAvzGVtTnjmyxj6MdKVVrLWb0 HYYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=Ezr0+JdqWLObeUgH87ZU7ZI/AoX/QkG2cOlcCw4fJa4=; fh=ExzgeR2veghZmqJkhRxqZBcx7LEa/OcJbDFjboLz3I0=; b=u3KkTj+r6XTrhJz38eXY/GhWIDTwB9lpalAJBVvMaMyNEhwZ7cKcrq8TX1xJAEpf2L LdVyTDHEGftlJuCM/3ng2BMafVLYiCg1kGtwVg+p3g5ITb4j1y0qAiiWsCOQcOsDitu8 HujL5WiPwXyZ61DWWpbEdXskXtVF3fqzkpZKginPzPBjnm2a9qxeWRnGQI5z6ATivkQR 0schKpNM/WuxQ1qL+xt1XVf6lCElRntw/Ae2syNTn423amBbxfLgWSEEMOkKO/wpCkeu P7pk2Vp68NlUcKT0YMrHA3l1LQ7COvaoo/xxmKA4cG5nfekkyMcHj7/GreJDss9gYptT LBHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c87VRnF9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bg26-20020a056a02011a00b0057771e49c25si3148610pgb.693.2023.09.22.00.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:33:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c87VRnF9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D861E840FE06; Thu, 21 Sep 2023 13:02:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbjIUUCm (ORCPT + 99 others); Thu, 21 Sep 2023 16:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbjIUUCV (ORCPT ); Thu, 21 Sep 2023 16:02:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2B935A4 for ; Thu, 21 Sep 2023 10:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695317221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ezr0+JdqWLObeUgH87ZU7ZI/AoX/QkG2cOlcCw4fJa4=; b=c87VRnF9l5/513PkAAUPLQu2THUKUZ1pdUQsv+/Loce797Gp6yyj/FGbI7LkmtjcIwxBNU 9x5fuVXalelenTIXNKxIFnRjOaScwI8TLnN8Eyd6Bzaqi0xiuosyplr5zBvDYH/HPy8S1q eFtoaCp2nEdFIlhM6XhAs8MBqolJVvE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-PlYDha2cP0Cen4LznMc6qA-1; Thu, 21 Sep 2023 06:02:36 -0400 X-MC-Unique: PlYDha2cP0Cen4LznMc6qA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-320004980a2so499535f8f.1 for ; Thu, 21 Sep 2023 03:02:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695290555; x=1695895355; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ezr0+JdqWLObeUgH87ZU7ZI/AoX/QkG2cOlcCw4fJa4=; b=LXcSQca0IAOeThzuufBYU7+ltQHLCMcpuWFRGGYFAwQRkfZVTncQEMh7l9TG27daI8 lCKyAlsd6TBaZ1jh1FVnv7MBxygAvKafb/WznzAOTxp7DidkxwjIW3QPWKD9frM/cIqb 2UJBn0g4k5/iBgllPnn9QH1fIBe2aGQ4QaP+xp4Jeae9IjVQqFcwMhKqLdNtCrfr/uOf qgdn6ugOGoAuhWxt0nXgo6gy9hPVtDCD4erFxxyEGsI+ByWHwn44Fn3uhdY1Lo+fyueT ZZ3P/WekGKuL7Pu2cdGIlpcSj6ZruRkOByTj4L0+hfEh7MEcgf6thNZol83AB4JVo+wA 5u9Q== X-Gm-Message-State: AOJu0Yz9i/dd4SA9c89nKllSgR47T/pxP8Yu/ApXJeDKLkBDrEy5Vgno MVSbU9F+QM6s/K8tRjEbXuH6EEoPnlcntWI5IViL7Lo5CvDI7m8nDkjqrZht0B/VJ0hxVT491HI +G6MZ1xz9ugZZTF755S+8cu5R X-Received: by 2002:a5d:4fcd:0:b0:319:6327:6adb with SMTP id h13-20020a5d4fcd000000b0031963276adbmr4150482wrw.70.1695290555387; Thu, 21 Sep 2023 03:02:35 -0700 (PDT) X-Received: by 2002:a5d:4fcd:0:b0:319:6327:6adb with SMTP id h13-20020a5d4fcd000000b0031963276adbmr4150457wrw.70.1695290555045; Thu, 21 Sep 2023 03:02:35 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:9af8:e5f5:7516:fa89? ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.googlemail.com with ESMTPSA id p5-20020a5d4585000000b0031ad5470f89sm1311972wrq.18.2023.09.21.03.02.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Sep 2023 03:02:34 -0700 (PDT) Message-ID: <9ebf281f-7379-ba37-2867-8918da813c19@redhat.com> Date: Thu, 21 Sep 2023 12:02:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Pattara Teerapong , David Stevens , Yiwei Zhang , Paul Hsia References: <20230916003916.2545000-1-seanjc@google.com> <20230916003916.2545000-4-seanjc@google.com> From: Paolo Bonzini Subject: Re: [PATCH 3/3] KVM: x86/mmu: Stop zapping invalidated TDP MMU roots asynchronously In-Reply-To: <20230916003916.2545000-4-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:02:43 -0700 (PDT) On 9/16/23 02:39, Sean Christopherson wrote: > + if (!root->tdp_mmu_scheduled_root_to_zap) > + continue; > + > + root->tdp_mmu_scheduled_root_to_zap = false; This is protected by slots_lock... tricky. Worth squashing in a comment and also a small update to another comment: diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 93b9d50c24ad..decc1f153669 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -60,6 +60,8 @@ struct kvm_mmu_page { bool unsync; union { u8 mmu_valid_gen; + + /* Only accessed under slots_lock. */ bool tdp_mmu_scheduled_root_to_zap; }; diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index ca3304c2c00c..070ee5b2c271 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -246,7 +246,7 @@ hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(struct kvm_vcpu *vcpu) * by a memslot update or by the destruction of the VM. Initialize the * refcount to two; one reference for the vCPU, and one reference for * the TDP MMU itself, which is held until the root is invalidated and - * is ultimately put by tdp_mmu_zap_root_work(). + * is ultimately put by kvm_tdp_mmu_zap_invalidated_roots(). */ refcount_set(&root->tdp_mmu_root_count, 2); Paolo > + KVM_BUG_ON(!root->role.invalid, kvm);