From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 2023B80064 for ; Thu, 26 Nov 2026 21:54:28 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQLrH6n031490; Fri, 27 Nov 2026 00:53:17 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQLrH6n031490 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="RfLwipff" Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQLr5XD031423 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Fri, 27 Nov 2026 00:53:05 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQLr5XD031423 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-c50b0de2139so519304866b.3 for ; Thu, 26 Nov 2026 13:53:05 -0800 (PST) X-Gm-Message-State: APuU4Z8o8U89IdeJ6mJBs63jHcrYuPVnuCxAj4IMYwaGZArlfLCAmsPH hOcaVo/g2X4Xuac8meulWeQfTTtef2U2b1MgKw8b795R/+RtK/EMXpcmRH5jfyFBXT+QB0/pWXt Ubq/8s8TpO3XXX0Jfj3kSfSdv14A0RIkEvKd5PIhACoeIsdj3S/3JfA== X-Gm-Gg: AZFdTZfVJIMw5mP3lAIipkkJMQlu/3WuQGHvQKjDeAJHaU8smddMqmORgBT+G5jbUsM y6q9gHjcjOJFgDvb6W0EN1l1rL7QcrBgPn2gzAKfvV4SO4VSwnIz61H8hxRhxvE131OMKy6LNpj L4odcIqUMfv8Rmd9Bzgbtw5pkBbaTCTaliCz9QlGsY06AdfZTa8noBj/3lU3V3u0MPCmml6fumk oBhlg5tH2FRrLVlUeX71/n/cZdR9cn7X+1cd2wGiDNL3QDWJcwhudjcN4zLg1FyVjqJllMs5TLk 7C8N6HA7ttQaQHFH5uj3ztIzLuxRtr/80h86mEBgG7FmumotUrcCQliQUalgIMhhK1PpbonuD7i OOMmvyKTfifHsnVdBvA== X-Received: by 2002:a17:906:da0e:b0:c46:a72:e0c3 with SMTP id a640c23a62f3a-c513a84dd04mr1528003466b.16.1795729985544; Thu, 26 Nov 2026 13:53:05 -0800 (PST) X-Received: by 2002:a17:906:da0e:b0:c46:a72:e0c3 with SMTP id a640c23a62f3a-c513a84dd04mr1528002266b.16.1795729985073; Thu, 26 Nov 2026 13:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795729985; cv=none; d=google.com; s=arc-20260327; b=s/k/JOS9irRmgkWkvwcZWliPhh/qxcr5/ZPVii0T2T1wFMih9xNzLc1nCQW8Au7qDU /gRbQcykMNfBcnf+uE1sAdpDZ/vCaDrhtVydwAeEA5bIKgJmOqNVsrgBz4iuEFgmTj3f KN/U6Sn+ZCmrumENR9o7pL90wFkzt58km6Vn7D9HYGAGoxIfRI7HXsE/NDy6UzONKgnE hfDqY/aDNV1M0U278CJO/w2J5CS2V0sjby7VQEykzwUweVw8Bhv5Hsbp+4r5oSsFYsk1 m73wXPBjjs3CIIqbZu+JXGx7hG/5hmKWAUTtTPvN9DsEfArD5p83s+hopxkObgHWFbfy 3E0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=cfjqP3/Lrd6AbLawpSaOYlnDKg5MFL+BbDG//ygTJpQ=; fh=oOZACxR4KP+1I9I4VayNBZ4FD/hXMXJDAvznfQ9uKaU=; b=N9eXdwW2BH3/wAFSuyg9WGGty/Ud2chVXHPJslygiXyBlHa1B6uSWtzgnWKJGRB4cb zOXajc2V7sgj7sQCSlqK2T3VLxzPyRlNVzAVtklO8qiBJoNBEEdUMuN61iwYIkOjHYih aFtq7eu9Z3D1Zokh9ohbRWTzoKKJ25mw3yokfTUxUo5MYxrSbRuRZUrQb0a2+YDlwpKb L1ZWsMMoGc39xAcx+awetNR99wVUate77oVvkx6VHgwm+P9GImoftDFmRZ6g4ApvAlJ0 Bn4M7VV1FswWOs/iRQsVlDycvgKdXsPxZFkxEOEegSnSJHKqTbfKvpjkBIaMUfeGM/yC l5TA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=RfLwipff; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513b0d441bsi1422144766b.339.2026.11.26.13.53.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2026 13:53:05 -0800 (PST) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=RfLwipff; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=cfjqP3/Lrd6AbLawpSaOYlnDKg5MFL+BbDG//ygTJpQ=; b=RfLwipffav52buZEtfB 3bApLtpaltjbFM9Xfh4F4zpg/H7sqhcWCOUwB9eZjks1lZQCYcEpilgsR/TlXDWD8zxswlqKvPZP/ JbtEwm1Afs0EF/XPS7ZNsTdbk6eP7p4dgrRnRRCxWJPZ71vNUqx6KErfCAHV4asSAcQkZKew4BrDN 3ijueUYAAnRif5y9kbXKovokDM4/oRDol/IuF4fi3yCpuYDVCUScHDDhe4jswzyhpxUE+DByr/VVd TldfGkg7qNxDSZBDUt6pl2N7wfqLchQtk/5zRsx+BpbBakowqTQTYF1eIDbe/F1HZByQFXYm4T+YK J2VPfmGj9XX3fFA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xWhOd-001XTU-1F; Thu, 26 Nov 2026 22:53:02 +0100 From: Konstantin Khorenko Date: Thu, 26 Nov 2026 22:53:02 +0100 MIME-Version: 1.0 Message-Id: <20261126-khorenko-vstor-157390-kvm-fixes-v1-4-ea4024e03c63@virtuozzo.com> References: <20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com> In-Reply-To: <20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com> To: Pavel Tikhomirov , Vasileios Almpanis X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3892; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=bwcKnYaQ41cnrHEG9UhLspxKnz0JVC3MlarmHJc91/w=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBrCKo+Z7zhhbg/RQMkV5nrMmozU7b3z4BdQaWNm ygXPp/XICiJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCawiqPgAKCRBRlgpH+WFc KjtsD/4s9O55kxsd7X5kW8F6Vi0rKSAtCvuWeIqhqmvGA082qSOJzd6Px/cxcCnDDzUQV6JSAct vliEa7aJlH9+Cwk8UKmfZ7eGZBpW102FVKP80nHmqmPa9v8PZoFnO1LTB9BqLRIlbVmT+GRGqkh DtV+T4iLY7f0CIGcPQvxLe12IGZubE7nIq/kPPAPHGCuDCAcKlxcQGCgAdgJo2hokCvA+Hqc+qe +SPSsLNaqrkEfyGy3K98Vyo0h7m911iwz5HVFliD/++8GF9utgeQzKSNQi89sqEzhaxWdCBjwuF czLewZB/1GDf87RuLqe1LNVjj3S5XtKBuR+iBUA/09P2iqqcboA42GcY8Z8sGRsQWNdQ1D+rYT0 ecBRUbTmd5Jueremi/cils4HHbGBrBhKcYPhf0Q4CgQ2FqpHM9W/+dIOfnwycgnNjiEeNC/S/VT +ZepOTd761gqYyCt8c1IwP4aUqQhyf8f6x0o2L+p6Y5sxA+0DoCtN+KZZlBoQuDV/O4vNrLmuEV pWIXlV3WBFTJKggUwuhRLqy8dCbrblIu1DRaMUJ7OJMQE8HHn6BLEbFqN5JUk+G6coJmVsJDHSA nXh7nAtDgec9UmL3lHEjuQ0phNgaZWXyfU+vVvkGSF5wrU08b93QZGNoCKypkKb9IttHzU/ESiL JQ0JGFwMDnV9LtA== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit) X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Sean Christopherson [ Upstream commit e4558c3d7198ed9a0adc3304681f561f4e4d80e1 ] When potentially reusing a shadow page, zap the shadow page if its number of parent PTEs exceeds KVM's (mostly) arbitrary rmap recycling threshold. Letting the guest create a (mostly) unbounded number of parent PTEs allows the guest to coerce KVM into creating lists containing millions of PTEs, effectively bounded only by the maximum number of shadow pages. Because PTE lists are simple singly linked lists, removal is O(n). Even worse, if a list is constructed just so, teardown can be O(n^2), e.g. if SPTEs are built such that zapping child SPTEs always zaps the last entry in the list. To cap things off, all paths that walk PTE lists do so while holding mmu_lock, without conditionally rescheduling. Using a doubly linked list would not address the issue, as removal would remain O(n) since KVM still wouldn't know where in the list to remove from. Removal could be made O(1) by storing a per-SPTE pointer, but that would largely defeat the purpose of reusing SPs, and would penalize well-behaved guests, especially for nested TDP where aliasing page tables is uncommon. So, cap the maximum number of parent PTEs at the rmap limit. In practice, well-behaved guests will likely never run afoul of the limit. E.g. when running Linux as L1 with TDP, the number of parent PTEs for a single SP tops out at under 200 (though undoubtedly obscure workloads can push it higher). Deliberately use a "greater than or equal" as opposed to rmap's strictly "greater than", as the rmap code checks the threshold immediately *after* inserting into the list, i.e. the limit is 1000 for rmaps, KVM just very briefly blows past it. Apply the check to both indirect and direct SPs, because while a fully direct MMU naturally limits the number of parent PTEs to '1', direct SPs in indirect MMUs have no such constraint. E.g. if the guest maps a huge PTE into many locations in its page tables, and KVM is backing the hugepage with a direct SP, i.e. with a series of smaller pages, then KVM could end up with a direct SP with many parents. Note, shadow_mmu_try_split_huge_pages() always restarts the rmap walk or bails entirely if it gets to the point where it tries to grab a SP, i.e. there is *no* pre-existing bug that would be tripped by zapping a SP and thus rmaps when getting a SP. Cc: Jim Mattson Cc: James Houghton Cc: Yosry Ahmed Cc: David Woodhouse Cc: stable@vger.kernel.org Reported-by: Stefan Teodorescu Signed-off-by: Sean Christopherson Message-ID: <20261027171518.1432557-1-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin (cherry picked from commit edf87e07376054eedcd5306e0794a26e3004d97b) https://virtuozzo.atlassian.net/browse/VSTOR-157287 Feature: fix ms/kvm Signed-off-by: Konstantin Khorenko --- arch/x86/kvm/mmu/mmu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 66bda34aeb7f6..d7527f2180e7a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2270,6 +2270,16 @@ static struct kvm_mmu_page *kvm_mmu_find_shadow_page(struct kvm *kvm, continue; } + /* + * Note! Unlike fully direct MMUs, direct SPs in indirect MMUs + * can have an arbitrary number of parents, e.g if the guest is + * mapping a huge PTE at many points in its page tables. + */ + if (pte_list_count(&sp->parent_ptes) >= RMAP_RECYCLE_THRESHOLD) { + kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list); + break; + } + /* unsync and write-flooding only apply to indirect SPs. */ if (sp->role.direct) goto out; -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel