Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp285194pxb; Thu, 25 Feb 2021 02:26:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTfjb+pJSWsEtZl8XOx5hwwfJcMDpzxLuy9kLFK0l2Iu1M2PGpJxbYqKajIwM3mNGcRkTO X-Received: by 2002:a50:bf47:: with SMTP id g7mr2085520edk.323.1614248778596; Thu, 25 Feb 2021 02:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614248778; cv=none; d=google.com; s=arc-20160816; b=wv0zQM8DAq3cuP1XlS32GsaUjsSWLA3RfL6OJ2Tjb9xtzTBl2zkguBoHbVvW4YeuSR r9Adt3CE3BGnkcpB9404oeqYzwUhcz00IXcTzacnXJWrEuCcGD4crvj3PNyz9yJuLwOk x1d7zxtmjxQqT4NvXgghKYfNOJHWEdHKhjepSVRNbbbA1X0EmVrVgdmSQBSVesF8TVId zWrSysjJ5X+1FT4btBnNyYFOcIoXsyXPRAenREsuVTSu8kypoOiNOe7LctaIl50a5cUj ZWF030UAnlqVRjTVtSVi0TDGcPtI4+D23554hCWZoxpfSwY44K8Bw5/kkGoG2afk4cLu 6stg== 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=kGHaBFW594zpOjITwkqTxYycQyR0L1yZ5LILit7bTrg=; b=iL2euaZ+fF/R1Vuj+hzeQwoqmv/HFm2woInDE6OMYVLMDn+/rmrIypsPsmafog83+r BP0BfRDyKr5gRkcXpsgt1vkmxg2IzoZi0w3XsNcE+/kjJsfg9VM/gCLnEqcK81bDUtl4 82s9bAmBwMiWg6ylb5hZRsnaOfd/2mdHzfHBm9cCZc1yysLGjdyOwT/GXFCIvYyUYP9b 7ngBYuOtags2v+7Etc6gWrvfH5mStFv4WKIVL/eWmP9XYw7qAHuHe/5jf94rlT/VVZfy T2w76vKCuvi7YM+MChvapfGNJqwBgqS5bUU0VYSZs6d6pKDEuNDZ0wCpqmKTikDZ+J7T LyCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QAQpATIr; 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 e13si2874998eds.140.2021.02.25.02.25.55; Thu, 25 Feb 2021 02:26:18 -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=QAQpATIr; 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 S235515AbhBYKXO (ORCPT + 99 others); Thu, 25 Feb 2021 05:23:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:35552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233242AbhBYKAr (ORCPT ); Thu, 25 Feb 2021 05:00:47 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A32F64F24; Thu, 25 Feb 2021 09:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614246937; bh=oqiyN2ScAinz7TTlGaA9INPUXIh/BHpEd3EzpD1fVZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QAQpATIr+GpZ7aLlHmMhGDpFdgfzoOMyJ7O/Qwyw7nWX9bdLBbJwgwoOz6h23g5F8 AaOQqChOxvqk9ySO0s3zCO8pY4sAZu9uhBSy/o+qB9eH9Sp1AcgqxYem/HKsrl1b2s 4Gz65gcIfdWHs5W7OqHTb7fqGijkGPx674w5bhlg= 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.10 12/23] KVM: x86: Zap the oldest MMU pages, not the newest Date: Thu, 25 Feb 2021 10:53:43 +0100 Message-Id: <20210225092517.119149578@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210225092516.531932232@linuxfoundation.org> References: <20210225092516.531932232@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 @@ -2409,7 +2409,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.