Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16754059rwd; Mon, 26 Jun 2023 14:50:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47rd1vpJC9oUurfQEyOh0tBSCfv8ckcrPVPiLlZiNCuURfl2iycUShymuk3VmzboxxyOMh X-Received: by 2002:a2e:9846:0:b0:2b4:737c:e316 with SMTP id e6-20020a2e9846000000b002b4737ce316mr19289907ljj.14.1687816256302; Mon, 26 Jun 2023 14:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687816256; cv=none; d=google.com; s=arc-20160816; b=owJbWe0qLZcQUP9vaJs/RuIv0nmxTKMievwEiybl1ITNWAyEjKtHiP7XzcbMRAwTey YxzfHJVmWHM459cHPWx+Wi0ZYhYqQE0IR0W3FxYD8Ot4VwqM3VongleP0XfP7Ke2kj/o Yfuj6vLq6j622QkAGYkhMG9CBfupEDGeJMHSYtGscu7WXxoJyDON7nsgQ873wyrywADL o15oOlPAyhnAuJBYyrG0cHmeE4ylJ+GcCxu/5GRffSd/c4M8Z20YeDvDAQDqDSXJI0Ii vcfP9s+d8abLI2dm9338HhIUMY7vfUjbQr6TJZNU9zof+LXAb9J2OshYsSq/uRmFfe6L 2iPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2hJTnGKaVBQkg0yz+eVOgG/0uK7zEDVVCQ+nLV5omt0=; fh=PW+LX1Kr1iYDxCMtzrXBCk6vVo4mpUBzt8Nw5G+N1Yc=; b=iLf5ZOsAPOs+XAYHS1fN1s4NO8e2eYsbQh3nuQALsjtfYRQusQBHLV+Cvwqu+/v3OW w9EhKI+Vm/GeHXIWUnzRwy+sNKUfg5V/slGWq7Fj0XYyhbLfF/2ykXlbI59TaaA5Zixe SmJgYOsBXOPqkjFUhRfToIfzJBdxjhyxUD9l8pd0vJxDfklAgVZRPmZwNfVzLK9s1SJp WmvXtHb3NzdYdEMYvEq5r22A2gu+1PighHcVO6j/n8b4Wt2HczZJPco6Nhqdc8Laktej wDIGLBc+K3YcLNy7mi5CS+D2BSGurjqZTfa2xLEpVDnyMZvdtsOaxaXwav35RYAFCnjq BuZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=pztYkiPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020a056402128800b0051c57bea395si2966907edv.653.2023.06.26.14.50.31; Mon, 26 Jun 2023 14:50:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=pztYkiPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229516AbjFZVhr (ORCPT + 99 others); Mon, 26 Jun 2023 17:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjFZVho (ORCPT ); Mon, 26 Jun 2023 17:37:44 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F02B116 for ; Mon, 26 Jun 2023 14:37:43 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-57325434999so52302327b3.1 for ; Mon, 26 Jun 2023 14:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687815462; x=1690407462; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2hJTnGKaVBQkg0yz+eVOgG/0uK7zEDVVCQ+nLV5omt0=; b=pztYkiPL+Pja+QCn3bFgtqogw6fqAMuWeFWbIIMS5Rj9GDe2aa/AXa6mU5VjTQuFNT kGltwz4rKfXYPBP0V/suvXthJtqL23UOZ9I1kC2ChQ2UqCleP5jw6y4Zro6zDTTiKKiJ baH1iafxFDqTYS3Pg3RFmhHq/zni5MwsfmOFJaABmwgj0cG2Odcapj4vEa3Ec5/hCI3k IsjwRNGKD6lQsQ9yQzKrrpCUVjkcaeqjI4hPVx2/Pt/K5BHDt8YOq/N9PbyhCUnzpiOB mrtwGyU06SekKaDzW4z+lXgjDl9On2xsIE2YrMuPyoask0r7Tbqw+HeDqGgkVksZJ//l oUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687815462; x=1690407462; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2hJTnGKaVBQkg0yz+eVOgG/0uK7zEDVVCQ+nLV5omt0=; b=KrWqtwJ3X/UFI5FujB0Ggtq3V0s62BYZ4cHNXYCkinBdAcUg6+fxVVsjfRyrWOw8lq YIISvNSS/Fx7KK0cWewj3h4ejQ6Y3uKwv3hyB1wpkQoSvO5K2ap7SQSDOuwun1y09n+K PbLg5Y402PlZMn5kHg6XFytTkWlam03RbQi+qx/NhOhx/xiCoSrC8CRkn4v65Eou8Qts oS5Hfma4RlstHzCa9tpNXAF1Cffs8VMxl6LyGh03mpYzT0umO9fgc/DhZr5wWF7qhLWU j0JC2aTgLPbwdjN9L6kjS3j44j9wK4LURh103Cky6te3vaa6NcUUUA3AVRM75F4UWlAY rEgg== X-Gm-Message-State: AC+VfDw5NSzG37uLGKn+l44TP719EQm/XFTpM/DW1hhWxyLqoigMVwok YSmlCR5HiLVrG41WFvrm0uvNFPcvG6c= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:b710:0:b0:565:9f59:664f with SMTP id v16-20020a81b710000000b005659f59664fmr12998654ywh.6.1687815462579; Mon, 26 Jun 2023 14:37:42 -0700 (PDT) Date: Mon, 26 Jun 2023 14:37:40 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230321220021.2119033-1-seanjc@google.com> <20230321220021.2119033-7-seanjc@google.com> Message-ID: Subject: Re: [PATCH v4 06/13] KVM: x86/mmu: Bypass __handle_changed_spte() when clearing TDP MMU dirty bits From: Sean Christopherson To: Like Xu Cc: Vipin Sharma , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Ben Gardon , Paolo Bonzini Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 On Sun, Jun 25, 2023, Like Xu wrote: > On 22/3/2023 6:00 am, Sean Christopherson wrote: > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > > index 950c5d23ecee..467931c43968 100644 > > --- a/arch/x86/kvm/mmu/tdp_mmu.c > > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > > @@ -517,7 +517,6 @@ static void handle_removed_pt(struct kvm *kvm, tdp_ptep_t pt, bool shared) > > * threads that might be modifying SPTEs. > > * > > * Handle bookkeeping that might result from the modification of a SPTE. > > - * This function must be called for all TDP SPTE modifications. > > */ > > static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, > > u64 old_spte, u64 new_spte, int level, > > @@ -1689,8 +1688,10 @@ static void clear_dirty_pt_masked(struct kvm *kvm, struct kvm_mmu_page *root, > > iter.old_spte, dbit, > > iter.level); > > - __handle_changed_spte(kvm, iter.as_id, iter.gfn, iter.old_spte, > > - iter.old_spte & ~dbit, iter.level, false); > > + trace_kvm_tdp_mmu_spte_changed(iter.as_id, iter.gfn, iter.level, > > Here the first parameter "kvm" is no longer used in this context. > > Please help confirm that for clear_dirty_pt_masked(), should the "struct kvm > *kvm" parameter be cleared from the list of incoming parameters ? Hmm, there's only one caller, so keeping @kvm around "just in case" probably doesn't make sense, e.g. adding it back so that we could do KVM_BUG_ON() in the future wouldn't require much churn. That said, I'm tempted to move the lockdep so that it's more obvious why it's safe for clear_dirty_pt_masked() to use the non-atomic (for non-volatile SPTEs) tdp_mmu_clear_spte_bits() helper. for_each_tdp_mmu_root() does its own lockdep, so the only "loss" in lockdep coverage is if the list is completely empty. diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 512163d52194..0b4f03bef70e 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1600,6 +1600,8 @@ static void clear_dirty_pt_masked(struct kvm *kvm, struct kvm_mmu_page *root, shadow_dirty_mask; struct tdp_iter iter; + lockdep_assert_held_write(&kvm->mmu_lock); + rcu_read_lock(); tdp_root_for_each_leaf_pte(iter, root, gfn + __ffs(mask), @@ -1646,7 +1648,6 @@ void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm, { struct kvm_mmu_page *root; - lockdep_assert_held_write(&kvm->mmu_lock); for_each_tdp_mmu_root(kvm, root, slot->as_id) clear_dirty_pt_masked(kvm, root, gfn, mask, wrprot); }