Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4723641pxv; Tue, 6 Jul 2021 07:42:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysRH8vjADOqqox8j0sbUPDVS/FP2tlt8oOxfUVhLXUPpoX5eEE+ApRbpGQ1IBoVuCS8xrV X-Received: by 2002:a05:6402:1357:: with SMTP id y23mr21558193edw.244.1625582572022; Tue, 06 Jul 2021 07:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625582572; cv=none; d=google.com; s=arc-20160816; b=XjcF8AJoSgz0yPbGs7ZGy64nikXZGOv0uIcMRwjJ70SDylI/ylfsOIKjB9CGRzG92c V5/YILuREYVywkxy44VYiMOZ62qhQ6o7MFPYs5dG4++FsiA0BT8K9J8ZJHiuq8uZEckC CqQEkquM1u0yjDZZFbX46L3QkLv3paNdhBSmyDs9eVg8A2NTgPUAed5Ojvk1u77ZuoeP RlpOKp4sUprtbMPCi3MCfBSLwpdAe+HFuQehC+MYQ7S4EIG/Q5KGefUn1PLlFPVW6yE2 GFFtKKv8U92ebpmRTDHVAygH8oSUDUVSvH6VEy2PhyFXATqV7qczAIGLVP+UFj+koWXv lUTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=0dw2C24IYhsTlppTrcEqtz5YCldeKMDuVEIPmvao1so=; b=MHxljLRyV9G+cXrSIvsu7ZAfjY7C5orHSMROyRMaWrKM/ZeO0r8Li0H90F8lM1k1yh qzXZKIdkSnd364ABdKb4hkpbYl3xERBHROF8LJ4h9+Zy0+Lcv+k9dBuJT3C9Jmt7KqWB v8lzbRY4e/C6ol4hFUCeewX+wlj+WiBpxuQbOq29rlzfuUK+noywf2pon6OCTbKIHpXo Qz8zQnnSNlxq1pRrhxrwyn1zDAMp7QKVPljeF2u/eMU4qlciwVCQglTRnv6Gzty3+zUC KO+8gk/ZyjvEjmxL9cyYwFuxIZKGCHTS7bKVfaC22CrZm4MFL7nMTXffX6tqNr/QfIxZ rCwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AsHxm1d1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p21si6135104eds.590.2021.07.06.07.42.28; Tue, 06 Jul 2021 07:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AsHxm1d1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbhGFOjj (ORCPT + 99 others); Tue, 6 Jul 2021 10:39:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50653 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232484AbhGFOjg (ORCPT ); Tue, 6 Jul 2021 10:39:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625582217; 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=0dw2C24IYhsTlppTrcEqtz5YCldeKMDuVEIPmvao1so=; b=AsHxm1d1VplMxjrOkk0ac15pL02nZ2CTpqodoVHJbG0okngO9wSJwe/vORiz9C0RFXbsps W9AmaUCx73QmnRuAv06n8p0DHtUgp2J/iYYXE/cTCPn0jvmOQ2cU652D4C46N/sF0bk6lS qulcKJtxWAb/OKPDNoISjT0zRv6U22o= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-hT9jvLTGOHCg_TWPpGjg8Q-1; Tue, 06 Jul 2021 09:44:26 -0400 X-MC-Unique: hT9jvLTGOHCg_TWPpGjg8Q-1 Received: by mail-ej1-f72.google.com with SMTP id hy7-20020a1709068a67b02904cdf8737a75so5000635ejc.9 for ; Tue, 06 Jul 2021 06:44:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=0dw2C24IYhsTlppTrcEqtz5YCldeKMDuVEIPmvao1so=; b=CFG3CETzEMn4CoOrZdQ5a27KTCFPQ64HeMQ8IsdDUx91HMpPHY1Zy6QfL6jvtR73cd 8xIl7mxqlb9v5jzvxU3QnR033+1r1dCmX3z2zHR3gj+RF/XTdnuhXAzG7cgOujoGgqU9 JT7aA+v+8rDWXITbwG169xWINW+Yhbaa2txK2L8LYTMXOqknHqXlMKl1SI/swAr8KCUZ REAqorq+zcdhWoDanMDrN5hOmFJCJm84TsniRTg3pDN+2L5TzhSvahQ0/fnQIN5QckmQ C6/1+30WM42Eb5HaV0xoEDDIHKU9uEhM0BYg7awqb5QYycrbLRfESCsD/g9StDkK3Xid cqpg== X-Gm-Message-State: AOAM533laJTMBFZW6bH2/Pu2LpaLmCTESSzge4p4wUqbMhgweRyuCent lr7ZBwPi0giFTY2g154GRd9bKnQMeeRF893X9q7I0v0lP9Ztn71ek3mBJRKVvg3akmAJA/vbu77 eyF8eLQE8Q+MTRlA1m34Du4pe X-Received: by 2002:a17:907:9491:: with SMTP id dm17mr16092045ejc.520.1625579064817; Tue, 06 Jul 2021 06:44:24 -0700 (PDT) X-Received: by 2002:a17:907:9491:: with SMTP id dm17mr16092007ejc.520.1625579064580; Tue, 06 Jul 2021 06:44:24 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p8sm1167072eds.15.2021.07.06.06.44.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jul 2021 06:44:24 -0700 (PDT) Subject: Re: [RFC PATCH v2 16/69] KVM: x86/mmu: Zap only leaf SPTEs for deleted/moved memslot by default To: isaku.yamahata@intel.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@gmail.com, Sean Christopherson References: <78d02fee3a21741cc26f6b6b2fba258cd52f2c3c.1625186503.git.isaku.yamahata@intel.com> From: Paolo Bonzini Message-ID: <3ef7f4e7-cfda-98fe-dd3e-1b084ef86bd4@redhat.com> Date: Tue, 6 Jul 2021 15:44:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <78d02fee3a21741cc26f6b6b2fba258cd52f2c3c.1625186503.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/07/21 00:04, isaku.yamahata@intel.com wrote: > From: Sean Christopherson > > Zap only leaf SPTEs when deleting/moving a memslot by default, and add a > module param to allow reverting to the old behavior of zapping all SPTEs > at all levels and memslots when any memslot is updated. > > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > --- > arch/x86/kvm/mmu/mmu.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 8d5876dfc6b7..5b8a640f8042 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -85,6 +85,9 @@ __MODULE_PARM_TYPE(nx_huge_pages_recovery_ratio, "uint"); > static bool __read_mostly force_flush_and_sync_on_reuse; > module_param_named(flush_on_reuse, force_flush_and_sync_on_reuse, bool, 0644); > > +static bool __read_mostly memslot_update_zap_all; > +module_param(memslot_update_zap_all, bool, 0444); > + > /* > * When setting this variable to true it enables Two-Dimensional-Paging > * where the hardware walks 2 page tables: > @@ -5480,11 +5483,27 @@ static bool kvm_has_zapped_obsolete_pages(struct kvm *kvm) > return unlikely(!list_empty_careful(&kvm->arch.zapped_obsolete_pages)); > } > > +static void kvm_mmu_zap_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) > +{ > + /* > + * Zapping non-leaf SPTEs, a.k.a. not-last SPTEs, isn't required, worst > + * case scenario we'll have unused shadow pages lying around until they > + * are recycled due to age or when the VM is destroyed. > + */ > + write_lock(&kvm->mmu_lock); > + slot_handle_level(kvm, slot, kvm_zap_rmapp, PG_LEVEL_4K, > + KVM_MAX_HUGEPAGE_LEVEL, true); > + write_unlock(&kvm->mmu_lock); > +} > + > static void kvm_mmu_invalidate_zap_pages_in_memslot(struct kvm *kvm, > struct kvm_memory_slot *slot, > struct kvm_page_track_notifier_node *node) > { > - kvm_mmu_zap_all_fast(kvm); > + if (memslot_update_zap_all) > + kvm_mmu_zap_all_fast(kvm); > + else > + kvm_mmu_zap_memslot(kvm, slot); > } > > void kvm_mmu_init_vm(struct kvm *kvm) > This is the old patch that broke VFIO for some unknown reason. The commit message should at least say why memslot_update_zap_all is not true by default. Also, IIUC the bug still there with NX hugepage splits disabled, but what if the TDP MMU is enabled? Paolo