From patchwork Mon Nov 28 00:20:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 26441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5359979wrr; Sun, 27 Nov 2022 16:46:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6tY8eyRBCIB7Mwy3vQLjf+9r2WQ8SkqlUC3E5X48flSwyZafC1i4r8np4ZnQVf9eOUt7Su X-Received: by 2002:a17:906:198d:b0:7a5:f8a5:6f84 with SMTP id g13-20020a170906198d00b007a5f8a56f84mr23348473ejd.569.1669596360680; Sun, 27 Nov 2022 16:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669596360; cv=none; d=google.com; s=arc-20160816; b=ISXcYYvFQXFz3Rqpoin+mSamt1SjvVupDFpqdzfv1bJ4poWhhYBiMCs4Vw0ezRh34g Itd9XvkelnAaid93IcP+Kx3xetW3bAC6G/z4Mfwv/T0wfzLV2PHW7Lfq0AtU1eO7V/hX x91RpGGTntlqVhT8Vqred4Ngl0fF3t7ePOFInPunrN83OwLclHSOoFJ5FU2bLBTmO3RA REFQb1gaZRMZvv9KCrr/yYH0MwIwOuTp7z4MRGPNhhNC58i12ps98syX05MVZSTlOgYk YrpG12OjSiyLDKX8f2t12IWwa2fZqANPoxLJ1aVTohNXU5M8m1gHA1F+AuWy5CyrOsrm QQAw== 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:reply-to:dkim-signature; bh=Os4PbJiT3Ld5Lv/LgXTKbRpBhRE17eV3B/ireIkXlSU=; b=H3kajtYTy6Rifo1lqIjKVlTJMqhaA0qVzud77dUWigERuFZbaFDqH4B/zSNE21vm5r B2fjP8QH0zoKHClwOVJc0jcc/gNHofV00tx14djVnsXR4qOA3a7e+S3RDFwAVDWHnC7Y ugLzABS0ca+J5NXHnWiONoqWv/mXmjcnYkwMh2UhYwx1cGgjd8LOsgS5QEYCCh3ZJKZR BnxgFvgRMevmVcMMdaeODI1R22yAuc92G6pTeogqorHKWQKhytPtZQXW/YWD15kdaqqb IPNm/PuoGaxVH8m7X+zjrG0wnaFLwIk7DsYDaFNvW86ZieGVqDfI9S7Ngjz9ExRCoD6o FzzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Yw6awvyf; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc36-20020a1709071c2400b007b8b7da648dsi8469646ejc.658.2022.11.27.16.45.30; Sun, 27 Nov 2022 16:46:00 -0800 (PST) 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=20210112 header.b=Yw6awvyf; 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 S229504AbiK1AUy (ORCPT + 99 others); Sun, 27 Nov 2022 19:20:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiK1AUu (ORCPT ); Sun, 27 Nov 2022 19:20:50 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 386561054C for ; Sun, 27 Nov 2022 16:20:50 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id mh8-20020a17090b4ac800b0021348e084a0so10075405pjb.8 for ; Sun, 27 Nov 2022 16:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=Os4PbJiT3Ld5Lv/LgXTKbRpBhRE17eV3B/ireIkXlSU=; b=Yw6awvyfFd70dz2eGE3TO9tcdtiZk2uLIz6rLJthelDJ04p8SaSLYnDjroBs8ybbPr tQXvkGKkWaT4z2w73UiYpjaiTAHYDKPboGUDfqGjvx0tX54MxPZChE06wTV1Tzqfs7oP EwM8upLQQHy6TM+ooZ7eRsZEnVWWmDmRxa+AiSk1bkyhqgWCb04LfTU2A58eAQhZIWpV kw/5VtbyHvecKZdXPuEcYOKuTCbC80TbHXmG2U9hKYc8O5rPYp2ZHq7OCfNJujMauUV9 K99wJ/xF8ObZxrgDPayK8it24+q2VE9VeIz2HJ2VH2iw/ac55J1BEgOvq9QNI81716Ca s0Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Os4PbJiT3Ld5Lv/LgXTKbRpBhRE17eV3B/ireIkXlSU=; b=6DyHkja9YuJKvvJHm8yU0PBqu+JadbE+NGSNyj8PNu23OVURXdigsJ76tFpekCgDED QkrHGAGyZHRH6pWyKnXvjdEFrRF8su0FmlW8yLLOnS3tlsTeKy1+3qioXJ8DPxZCogJY SYCKbRIsEBWpuEVbqbPTKj2mmM7vojNtoie5XL0iRyg9CyRmND1ovQUjna22TaSI88X2 +u2eNKe4HlbbPVStGBYg+RrXYOBM+fkagj/KkcBJL/NiZ6pVR6Nodxm7wb0nL2+uWLSZ 628B4TUd2lWmOjUTLGmG7PdHEbrD7iebLlSw+cQ6bs+s6xD5YScsWbyKLoQ3PPn/o7uj vXQA== X-Gm-Message-State: ANoB5pmm/Ww1NguidU5DtMDoTdXrxDnSgVMGb9XgP/ZNw63cLvqlTZfc kYQIefyVu2RRbZmh6fQefCiGjvMEOaig X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a17:90a:d086:b0:219:227d:d91f with SMTP id k6-20020a17090ad08600b00219227dd91fmr702999pju.0.1669594849468; Sun, 27 Nov 2022 16:20:49 -0800 (PST) Reply-To: Mingwei Zhang Date: Mon, 28 Nov 2022 00:20:42 +0000 In-Reply-To: <20221128002043.1555543-1-mizhang@google.com> Mime-Version: 1.0 References: <20221128002043.1555543-1-mizhang@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221128002043.1555543-2-mizhang@google.com> Subject: [RFC PATCH v3 1/2] KVM: x86/mmu: plumb struct kvm all the way to pte_list_remove() From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini Cc: "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , Nagareddy Reddy , Jim Mattson , David Matlack 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,USER_IN_DEF_DKIM_WL 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750698673132779374?= X-GMAIL-MSGID: =?utf-8?q?1750698673132779374?= Plumb struct kvm all the way to pte_list_remove() to allow the usage of KVM_BUG() and/or KVM_BUG_ON(). This is the prepration step to depricate the usage of BUG() in pte_list_remove() in shadow mmu. Signed-off-by: Mingwei Zhang --- arch/x86/kvm/mmu/mmu.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4736d7849c60..b5a44b8f5f7b 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -947,7 +947,8 @@ pte_list_desc_remove_entry(struct kvm_rmap_head *rmap_head, mmu_free_pte_list_desc(desc); } -static void pte_list_remove(u64 *spte, struct kvm_rmap_head *rmap_head) +static void pte_list_remove(struct kvm *kvm, u64 *spte, + struct kvm_rmap_head *rmap_head) { struct pte_list_desc *desc; struct pte_list_desc *prev_desc; @@ -987,7 +988,7 @@ static void kvm_zap_one_rmap_spte(struct kvm *kvm, struct kvm_rmap_head *rmap_head, u64 *sptep) { mmu_spte_clear_track_bits(kvm, sptep); - pte_list_remove(sptep, rmap_head); + pte_list_remove(kvm, sptep, rmap_head); } /* Return true if at least one SPTE was zapped, false otherwise */ @@ -1077,7 +1078,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte) slot = __gfn_to_memslot(slots, gfn); rmap_head = gfn_to_rmap(gfn, sp->role.level, slot); - pte_list_remove(spte, rmap_head); + pte_list_remove(kvm, spte, rmap_head); } /* @@ -1730,16 +1731,16 @@ static void mmu_page_add_parent_pte(struct kvm_mmu_memory_cache *cache, pte_list_add(cache, parent_pte, &sp->parent_ptes); } -static void mmu_page_remove_parent_pte(struct kvm_mmu_page *sp, +static void mmu_page_remove_parent_pte(struct kvm *kvm, struct kvm_mmu_page *sp, u64 *parent_pte) { - pte_list_remove(parent_pte, &sp->parent_ptes); + pte_list_remove(kvm, parent_pte, &sp->parent_ptes); } -static void drop_parent_pte(struct kvm_mmu_page *sp, +static void drop_parent_pte(struct kvm *kvm, struct kvm_mmu_page *sp, u64 *parent_pte) { - mmu_page_remove_parent_pte(sp, parent_pte); + mmu_page_remove_parent_pte(kvm, sp, parent_pte); mmu_spte_clear_no_track(parent_pte); } @@ -2382,7 +2383,7 @@ static void validate_direct_spte(struct kvm_vcpu *vcpu, u64 *sptep, if (child->role.access == direct_access) return; - drop_parent_pte(child, sptep); + drop_parent_pte(vcpu->kvm, child, sptep); kvm_flush_remote_tlbs_with_address(vcpu->kvm, child->gfn, 1); } } @@ -2400,7 +2401,7 @@ static int mmu_page_zap_pte(struct kvm *kvm, struct kvm_mmu_page *sp, drop_spte(kvm, spte); } else { child = spte_to_child_sp(pte); - drop_parent_pte(child, spte); + drop_parent_pte(kvm, child, spte); /* * Recursively zap nested TDP SPs, parentless SPs are @@ -2431,13 +2432,13 @@ static int kvm_mmu_page_unlink_children(struct kvm *kvm, return zapped; } -static void kvm_mmu_unlink_parents(struct kvm_mmu_page *sp) +static void kvm_mmu_unlink_parents(struct kvm *kvm, struct kvm_mmu_page *sp) { u64 *sptep; struct rmap_iterator iter; while ((sptep = rmap_get_first(&sp->parent_ptes, &iter))) - drop_parent_pte(sp, sptep); + drop_parent_pte(kvm, sp, sptep); } static int mmu_zap_unsync_children(struct kvm *kvm, @@ -2475,7 +2476,7 @@ static bool __kvm_mmu_prepare_zap_page(struct kvm *kvm, ++kvm->stat.mmu_shadow_zapped; *nr_zapped = mmu_zap_unsync_children(kvm, sp, invalid_list); *nr_zapped += kvm_mmu_page_unlink_children(kvm, sp, invalid_list); - kvm_mmu_unlink_parents(sp); + kvm_mmu_unlink_parents(kvm, sp); /* Zapping children means active_mmu_pages has become unstable. */ list_unstable = *nr_zapped; @@ -2839,7 +2840,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, u64 pte = *sptep; child = spte_to_child_sp(pte); - drop_parent_pte(child, sptep); + drop_parent_pte(vcpu->kvm, child, sptep); flush = true; } else if (pfn != spte_to_pfn(*sptep)) { pgprintk("hfn old %llx new %llx\n",