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", From patchwork Mon Nov 28 00:20:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 26442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5360214wrr; Sun, 27 Nov 2022 16:46:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6fkfPHXIGIQJWpF8Q7rE2wPTmX91lsZXLc/MdGPUTKtpvQJOwKPQbE7SSXghmnaJlywYOt X-Received: by 2002:a17:907:2a85:b0:7bc:a3c3:1ee with SMTP id fl5-20020a1709072a8500b007bca3c301eemr11795457ejc.304.1669596403693; Sun, 27 Nov 2022 16:46:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669596403; cv=none; d=google.com; s=arc-20160816; b=NmqrJVZaTyhdE6pyrgo8W3YIoIWP7MAeJhKlqzl6VA+nYcF4AVlRe9LjMeXkdrqPPa q0SRKZTMrSZbMWH9J4aSlNSZZORWfBp93I5CEh3MqA2bIeOAevbLFICRlyz8tBEMEepZ RiyqJZE/AnabKeSaEfqLeufahyUzL8m1A88wlkt3XbJpT9POsKAPjDz2skURRzepctNl gjYKbqDRaX5/34dADqQz56ziE5ASyuEjc2aAGvWFy0QElUSztHbmQ5J+ayHGwrVSBTsI XZK8gF6LAFLZ43cEVsoCc9qud6C5q74LkC9Ut312lo1/h+WEARy7h1sYGg6LR5FWeTj5 mOjw== 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=H/d/oQocVevk4kmXKYK3OFaeIddN2VYzbRh6TtN6NXs=; b=jO/+ltdnKrblxr6yjOJHcFti7rXbejEQNq7icgv5Y5e2adwcEpT467OWwmxhiSX/iT lsuL88+DCjuSpZcwDTQPfJjzj8oluFpGryqqE5WdWDLxlDUkY4nadPh5lgNw+pYxSafJ XqskOy5nmpTIJCVXfMrJnvgR2pmZc6rNtaoFqtJKLl/ESx1u8gqRyghX+iA5o6e9Q4DY VoCCTprWIK9Fqu284BYSVc8Wxiy1ZPLcEGVsW1/oU5G15lvBkJ1xcGeMBW5Jnas0Z0/7 ycHejzzz9bhY8jFTbIEkuHNKQ6Fg4C+CH7oJd/EwII+GbtKKsHM5Ztul4QaPGlRR7oVO xCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RYSaeGnD; 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 eq10-20020a056402298a00b00469e712cba8si8613553edb.558.2022.11.27.16.46.20; Sun, 27 Nov 2022 16:46:43 -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=RYSaeGnD; 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 S229695AbiK1AVF (ORCPT + 99 others); Sun, 27 Nov 2022 19:21:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbiK1AUx (ORCPT ); Sun, 27 Nov 2022 19:20:53 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F0210564 for ; Sun, 27 Nov 2022 16:20:51 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id b13-20020a056a000a8d00b0057348c50123so6960899pfl.18 for ; Sun, 27 Nov 2022 16:20:51 -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=H/d/oQocVevk4kmXKYK3OFaeIddN2VYzbRh6TtN6NXs=; b=RYSaeGnD1CFO5MQ+J96I9RF7NlYonxwfHL6CIt2WqTYaK4cGzpAXzP4/sMZ5U/O4kr Cj+72NFKKCQzdphG0akXy2FQoKO3VPj0rpsVOo4J8vDEBTh/0uCI3F0/t7+aC1/AT2l4 vAi6tToE0VuQnxEpqDxHXgr+iP77lS5LjGWPzcAuh2zBAYlrOc50HFpjY8kZLzUBOhBM 2RzeerZl34oU5H9OAK1wVzKUlbLkLiN6/n/Rvw0lpkCIMRekPFn59clteRzACq5L+8a0 PomoHd6qmoAXvpSEPVv7lEgG7Hw3VuR1NofbSkd+1aiT9bwKvxFqamiWT0Bkn9cdUy3h HvQg== 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=H/d/oQocVevk4kmXKYK3OFaeIddN2VYzbRh6TtN6NXs=; b=Ih7crnq72mPWHbcTa5kRHDvkPtLulx2s9oYVe2zkB41+HhNn+TYo4ONKLfenxGrxcb FA9MmJk+08qj/pt6S05i9oAMtuOuCIoFViODHgPcLHRdWdWnB334ceVnDSxt2HKRKqoD 19gS2RC1x8FnHlrbuh5gpObEtHGdSCBX6RXLy+flMvQkHDgty5qJVMWKyjDWHn4sVMWC buobNTaVfr3er2+JumrIqoh/zV/OuhBoVbuF4tuljHaqAnDHoGgJ45EcQwReDfps8HbI i5O2pwb76HSw/SphIRpUtneTqkDVBaX62bANWfN7TUkBFHeVc96cwukzenbOWhNM6+S4 ej1g== X-Gm-Message-State: ANoB5pmKzIoGS2ZMG/tv0LQlLPIqGpfcVSRl7JItS1/Jd0Y5sE2KF1/i DauOqlPrXX65QwjshBWY/RzQGgFKGW18 X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a62:ee0f:0:b0:56c:8dbc:f83e with SMTP id e15-20020a62ee0f000000b0056c8dbcf83emr28797392pfi.41.1669594851357; Sun, 27 Nov 2022 16:20:51 -0800 (PST) Reply-To: Mingwei Zhang Date: Mon, 28 Nov 2022 00:20:43 +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-3-mizhang@google.com> Subject: [RFC PATCH v3 2/2] KVM: x86/mmu: replace BUG() with KVM_BUG() in shadow mmu 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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750698718518487375?= X-GMAIL-MSGID: =?utf-8?q?1750698718518487375?= Replace BUG() in pte_list_remove() with KVM_BUG() to avoid crashing the host. MMU bug is difficult to discover due to various racing conditions and corner cases and thus it extremely hard to debug. The situation gets much worse when it triggers the shutdown of a host. Host machine crash eliminates everything including the potential clues for debugging. From cloud computing service perspective, BUG() or BUG_ON() is probably no longer appropriate as the host reliability is top priority. Crashing the physical machine is almost never a good option as it eliminates innocent VMs and cause service outage in a larger scope. Even worse, if attacker can reliably triggers this code by diverting the control flow or corrupting the memory, then this becomes vm-of-death attack. This is a huge attack vector to cloud providers, as the death of one single host machine is not the end of the story. Without manual interferences, a failed cloud job may be dispatched to other hosts and continue host crashes until all of them are dead. Because of the above reasons, shrink the scope of crash to the target VM only. KVM_BUG() and KVM_BUG_ON() requires a valid struct kvm which requires extra plumbing. Avoid it in this version by just using kvm_get_running_vcpu()->kvm instead. Cc: Nagareddy Reddy Cc: Jim Mattson Cc: David Matlack Signed-off-by: Mingwei Zhang --- arch/x86/kvm/mmu/mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b5a44b8f5f7b..e132d82ab4c0 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -956,12 +956,12 @@ static void pte_list_remove(struct kvm *kvm, u64 *spte, if (!rmap_head->val) { pr_err("%s: %p 0->BUG\n", __func__, spte); - BUG(); + KVM_BUG(true, kvm, ""); } else if (!(rmap_head->val & 1)) { rmap_printk("%p 1->0\n", spte); if ((u64 *)rmap_head->val != spte) { pr_err("%s: %p 1->BUG\n", __func__, spte); - BUG(); + KVM_BUG(true, kvm, ""); } rmap_head->val = 0; } else { @@ -980,7 +980,7 @@ static void pte_list_remove(struct kvm *kvm, u64 *spte, desc = desc->more; } pr_err("%s: %p many->many\n", __func__, spte); - BUG(); + KVM_BUG(true, kvm, ""); } }