Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp275674pxb; Thu, 25 Feb 2021 02:06:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMixgmwhrCwKZENHDcg/QA1Jq1L/PGMcWTKJBRFPcMSraaHLRMnjooFie8jTnpErt/iFPC X-Received: by 2002:aa7:df0a:: with SMTP id c10mr2107138edy.12.1614247563945; Thu, 25 Feb 2021 02:06:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614247563; cv=none; d=google.com; s=arc-20160816; b=agocK4AgzUiiTptO2X1kh9QY2NdEa6rXcTBesbTuC33A6djgqvbAxV1CMyF57cbfX7 yyCWa1UStJrKHLVbpUXDDBAGe9Zw8yvq7T6vZXL2+pD7tSBgh87ZY8XQGVSpyC8DYqNC FtOxpdl3K6OG3FOIwf02c1+IhdT6/RqLXvQtXC7OiVl/erCBc5QZJ6HofQ13UYucz00I 4hxqNiDB19yBHiU29bkxJ7hUArMYzLnhGO4MAiu6Bnv2na5V2CBIygLVCOb/OkAXR08K 2TdxOpeQb7yHGffbcyWtAPoFmsMKrh2U5dT7Mx3oT88Rq2a1cf8hKgY32c4V6NDhPURC Jn3g== 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=WKqNgVY6k44VRHVfwP88RA9RK3K8J8q6v3cS5pZNaVE=; b=T/RmibsyXaXJDTYgqAd6F1dT0/IuzzIn/hjgeFfHA1fDZcVV815dm2IP7Tw3D/ZIjA Ci+Gy7jHSxjVxkqd9jBFvxZMkvIxMu59Z0mejq5HALS/lIEqP4nZ8Gi+WjRW/GVaJb+p ZPpriXlPweTM32ZSC9+zdWDHSFeh7Aram0f5JNKj2skiXE2gtWJBH18Sy6eMNdGplR2W vUJZ6y4udAUNOR2JZKRcG5Bsx75iav7/SjDJH2EgdEqYsexhkZDtEow8/acSczCSaLyt E3wKJ0NtM4Moj8BPFlVsawIqAPXGhakRPmHUv+HPKvQZYaDO5hAwjcCCSc0tDx/hBi1k Jlow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1LbII0DN; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o26si2994624edw.74.2021.02.25.02.05.41; Thu, 25 Feb 2021 02:06:03 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=1LbII0DN; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235469AbhBYKDi (ORCPT + 99 others); Thu, 25 Feb 2021 05:03:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:34226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235601AbhBYJ4q (ORCPT ); Thu, 25 Feb 2021 04:56:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 048B664F12; Thu, 25 Feb 2021 09:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614246867; bh=UEDpM2iNq1Jh298bEQH9lI2lZIkdVnRfLGHTU/RCeyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1LbII0DNa6xFsmVvp8/WvfEadQvdCuoC0KdqHPR4W03PmfI3340uIzyCp7ZHfmeYL 6wMAZmYdO2d42VYC8SiWihflvW1tSIPRFhUX5q/OlToAxI52BJn4nXBPa++RuLqrmi tA//1ZEBt5NmCOu6l4pqbICXcMIBaJ4xUhBLC5lE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zdenek Kaspar , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.11 09/12] KVM: x86: Zap the oldest MMU pages, not the newest Date: Thu, 25 Feb 2021 10:53:43 +0100 Message-Id: <20210225092515.434032433@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210225092515.015261674@linuxfoundation.org> References: <20210225092515.015261674@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 8fc517267fb28576dfca2380cc2497a2454b8fae upstream. Walk the list of MMU pages in reverse in kvm_mmu_zap_oldest_mmu_pages(). The list is FIFO, meaning new pages are inserted at the head and thus the oldest pages are at the tail. Using a "forward" iterator causes KVM to zap MMU pages that were just added, which obliterates guest performance once the max number of shadow MMU pages is reached. Fixes: 6b82ef2c9cf1 ("KVM: x86/mmu: Batch zap MMU pages when recycling oldest pages") Reported-by: Zdenek Kaspar Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20210113205030.3481307-1-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2417,7 +2417,7 @@ static unsigned long kvm_mmu_zap_oldest_ return 0; restart: - list_for_each_entry_safe(sp, tmp, &kvm->arch.active_mmu_pages, link) { + list_for_each_entry_safe_reverse(sp, tmp, &kvm->arch.active_mmu_pages, link) { /* * Don't zap active root pages, the page itself can't be freed * and zapping it will just force vCPUs to realloc and reload.