Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3689208lfo; Mon, 23 May 2022 11:30:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUHO2EMd8NtkRFa2NS8Rwhb/PgGS2U2pVJKX3gH6yKiGtmTN4pv80fNbdHwNaZS1RqJjKO X-Received: by 2002:a63:8aca:0:b0:3f9:f9ed:7426 with SMTP id y193-20020a638aca000000b003f9f9ed7426mr10145492pgd.176.1653330657774; Mon, 23 May 2022 11:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330657; cv=none; d=google.com; s=arc-20160816; b=iGRJ0i5aDQlw1QNP/qnNtsJ7VkmH70UDMp3OUjxcy0ZUZeKrCqwuvdwMpSPtHLdf+J OnNco4hSeeM1OJn2wgjAWO+aAdJm9wMYDAIMETOQDcJuLY+9Ikbr+LooaG6EnOQ2ZaIP XSa87eJwPQZ53snU5qWCY3dFEDpt8u7tLUdyNGaqPcl1srwl45H5NPUw4WmMKBcfA1Sb V+uriIAlzLfHc1fk0qpaVO4iUN1/9alY8FdRQ3UnzGYyROKJhU+2M5Q0U4h6lwr5kgFa ByJbwvBwDqnXcAk4st0JsO9rX1GYQsttsnQNDq2q8CoEU9cOJxM80lsYA5Cu6Q7h/hrW YIQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QTyNxjsN5UwtMhyGAIuMwiT0jtxOUPV8ruW5MU4bPfc=; b=XgaZ7FqjSpL+jL3hfqAicINqUaKl/noJag8ERVKojLMN+0tYrGMxRfsX0I0yfpSp1O H8yxGEJ9YWsnVPJ5t73asSye2sZnEmKZMrjBzPg7HMi/pisINyf1Mx2W3UyIZAX2bpaP dzqD0mG2j8QBKoWaRf+zHS7n91qHl+MYB8rL3MHMXwvKDtuNfLXrRlhku7yNuJ/o4EBa 8J2EW8H2+xqUcKK3Wm07LC3QYCSVrMc4TT6zdNFfwZ0ZR6j1q+sAsGP/LmVJLgFxd104 ObFrHMBm2WWT4s20T4Kp8OxBgsoN4UWS9626Jzo71/iVThWYrqEmqD3wPSsU9fEhe20n naSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jf3bEr1a; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s17-20020a63f051000000b003f5d5bbf0b1si11639367pgj.245.2022.05.23.11.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:30:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jf3bEr1a; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B943213C1FF; Mon, 23 May 2022 11:30:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243598AbiEWRmO (ORCPT + 99 others); Mon, 23 May 2022 13:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242572AbiEWR1r (ORCPT ); Mon, 23 May 2022 13:27:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BADF47E1DF; Mon, 23 May 2022 10:23:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D573F6153D; Mon, 23 May 2022 17:15:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAE6EC34116; Mon, 23 May 2022 17:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326121; bh=fakn5Rm/GpuLorMbdsgU93zZ0IMk8qoD2rIuHMzIoGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jf3bEr1a+TfbsPJHWtcPy8Nsv9qFASFQ/6ZCIBXpw9s/L0BETQ97pZImDE971g3/V lisVfPBk9ZhB2dmo92NcaQO+7HhZHArHreI8uSXNw/0s0D3Tmf0jll08nVaLDmEdfL mlWZ4LJt/1bgDOGApI4h8niNApDc3dAfxZMVnirE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Matlack , Ben Gardon , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.4 30/68] KVM: x86/mmu: Update number of zapped pages even if page list is stable Date: Mon, 23 May 2022 19:04:57 +0200 Message-Id: <20220523165807.581079944@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Sean Christopherson commit b28cb0cd2c5e80a8c0feb408a0e4b0dbb6d132c5 upstream. When zapping obsolete pages, update the running count of zapped pages regardless of whether or not the list has become unstable due to zapping a shadow page with its own child shadow pages. If the VM is backed by mostly 4kb pages, KVM can zap an absurd number of SPTEs without bumping the batch count and thus without yielding. In the worst case scenario, this can cause a soft lokcup. watchdog: BUG: soft lockup - CPU#12 stuck for 22s! [dirty_log_perf_:13020] RIP: 0010:workingset_activation+0x19/0x130 mark_page_accessed+0x266/0x2e0 kvm_set_pfn_accessed+0x31/0x40 mmu_spte_clear_track_bits+0x136/0x1c0 drop_spte+0x1a/0xc0 mmu_page_zap_pte+0xef/0x120 __kvm_mmu_prepare_zap_page+0x205/0x5e0 kvm_mmu_zap_all_fast+0xd7/0x190 kvm_mmu_invalidate_zap_pages_in_memslot+0xe/0x10 kvm_page_track_flush_slot+0x5c/0x80 kvm_arch_flush_shadow_memslot+0xe/0x10 kvm_set_memslot+0x1a8/0x5d0 __kvm_set_memory_region+0x337/0x590 kvm_vm_ioctl+0xb08/0x1040 Fixes: fbb158cb88b6 ("KVM: x86/mmu: Revert "Revert "KVM: MMU: zap pages in batch""") Reported-by: David Matlack Reviewed-by: Ben Gardon Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20220511145122.3133334-1-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5821,6 +5821,7 @@ static void kvm_zap_obsolete_pages(struc { struct kvm_mmu_page *sp, *node; int nr_zapped, batch = 0; + bool unstable; restart: list_for_each_entry_safe_reverse(sp, node, @@ -5853,11 +5854,12 @@ restart: goto restart; } - if (__kvm_mmu_prepare_zap_page(kvm, sp, - &kvm->arch.zapped_obsolete_pages, &nr_zapped)) { - batch += nr_zapped; + unstable = __kvm_mmu_prepare_zap_page(kvm, sp, + &kvm->arch.zapped_obsolete_pages, &nr_zapped); + batch += nr_zapped; + + if (unstable) goto restart; - } } /*