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 875A780031 for ; Thu, 26 Nov 2026 14:31:56 +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 6AQEUf8S019659; Thu, 26 Nov 2026 17:30:42 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQEUf8S019659 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="ZxrVqZ6y" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQEUR5J019594 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 26 Nov 2026 17:30:27 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQEUR5J019594 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6a615ab0c06so7844867a12.2 for ; Thu, 26 Nov 2026 06:30:27 -0800 (PST) X-Gm-Message-State: APuU4Z/ku4Q5ztz43b05LnmnSu8xT3+Mzy1NBxzgit/t0qe2Y9e4KcHq VghMTTmfkrOylh705yzFbqZH66Uo5YRIUoRydziYb3X6kScVPhhRefnv/1h1oxKC0DNJSMDVWD5 2rRlC8RWZjqz0bhnF+Oye2aF5VUawL2Pf0RermCZMOVNKc8dGydqklA== X-Gm-Gg: AZFdTZf/ZlYdKPtWd6EYUxhbjMXUmBIecvxgTTMymGy9OzCJn9Ss4rcHjqcine+MMIc PONNd3SWOhogVVs2R/rGQPxq9Hcrj8Qg11FfzPtPMbs5v5tta8Tus7BSlFA8mI+VeaKun5D4sHA JMEhHp4IonhOScE0h3phwT3QsrH6xMpKQ1gXHAR+cXd5Tl9XxxKHaY+Xc60Hc7XxlTxNsxbP69M FUxWb+g6dt4kF0pw6YT5J+cu0tjU/W1ER6ooCQpOTknOMJ0d+72w0xSXM1hhkTT2mWYg3LhFJ27 HCupizcNh+ATKDYGhhMrYbNLncWncqeUSF9iwjt+oWUUCJLomf0pFg9s+T856Pi60EeGGQGpzuM sjqY0nAAucmYKMrKn0Q== X-Received: by 2002:a05:6402:234b:b0:6ba:6f67:b56a with SMTP id 4fb4d7f45d1cf-6ba6f67b80cmr12219930a12.16.1795703426873; Thu, 26 Nov 2026 06:30:26 -0800 (PST) X-Received: by 2002:a05:6402:234b:b0:6ba:6f67:b56a with SMTP id 4fb4d7f45d1cf-6ba6f67b80cmr12219908a12.16.1795703426246; Thu, 26 Nov 2026 06:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795703426; cv=none; d=google.com; s=arc-20260327; b=bm+neO3UvjX7JUUIcrSfl/IZBwUJ3Bf7iN+xWOLOAhbcunD8/YxWCMDnqywReV3PV2 yVlgJkkChnejPaxRTSKG5IL/yTTJQW/CBNryHiYiLFLDXujXq6jgc90RavkGQifKDagO 2l0VI1W+JQYeB3ZXEf/vOatuJsYfzEewH8OrUs7z/l3TZ+kcDyBPvUwrVXwHUat67XeF X2E5Emzht5shYE9RhjAMXTNr4RHFxC8ROTUWFQiFJSwh7aveuAjQvCSGBjbPaGuUR+/l OQWIXviIiTVKDDRrgTAj9RK/s8ZeqEwjf8vLkyyJfrK8sC5nHX3QsgksGY/R39F0llz5 MbaA== 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=yuyHIXl6Ml4RY8hEwBCHvdNSgHPgTuvL/kuRn0RdWFE=; fh=Qsi53PdKzYUvWZSiHi9J8uTgTupZPnYodD0rm/IZBSM=; b=A4zJL83AgmRyiAHyx7VRWiUEY8nuDCM88jvP1LhK5k/K/Hf3v9ouW7u+mfhk3ZXC1Z aloLoZ6jxOuo7GMbWyW6OnK0HZnJPtBgNCLQJ/uVI6n5e7YR+aWQVaJOkgAnfGTzjfg2 2zCHRMWSFRq6gl50pFHKo1x7peNRVJwDgM/xk6OWuIOlHWes8wpRpoOd4rCBq8QRFHg9 gvj2IGHrshKltTtP08OXK23CbO/D61FFoCCcuzKug/+/eUrlO6Zp2q1LC7aEAuXn1NZW lnEv9bR7TzRhVfQUNjOUxReZ/KE16TwExK3R3/Z1xK7G2h78v2OCe4JADatBGZT8Zof+ 7R/w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ZxrVqZ6y; 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 4fb4d7f45d1cf-6ba3709927fsi17766255a12.20.2026.11.26.06.30.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2026 06:30:26 -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=ZxrVqZ6y; 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=yuyHIXl6Ml4RY8hEwBCHvdNSgHPgTuvL/kuRn0RdWFE=; b=ZxrVqZ6y6u89PtDkYQQ csGQbOLYMk+XbuSNW/i4+05pjfkpUEHKFvA7OmmskRB1ttME9ROq2n6/ohucZuDP7Xsd3p3N9TWa8 pyLt1EQIG+EToXevr0gXU+PsHHDOAF9pqJJc1RDC4v+sPeyB12GeSObXTQifY4Rr7QE+fikVzAcEr +p1dSNEfYcCCL3xddFlDQV3bB0CujRgLwsK3jKsrLqA0e9EOo8zhF77RiKC/0RcxQ9ukHrg3YqgRo iZUitjZP2gT8gwJVB5CCrCPG1riNWGLAHmsQX64tCxM2rw+gQRF+w0t45Om0td3flcHYTXWmvL+WZ lHSsOYtqm8mi12A==; 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 1xWaUG-00GkQd-3D; Thu, 26 Nov 2026 15:30:23 +0100 From: Konstantin Khorenko Date: Thu, 26 Nov 2026 15:30:18 +0100 MIME-Version: 1.0 Message-Id: <20261126-khorenko-vstor-157133-klp-and-kvm-fixes-v1-5-0ec8eaadf1bc@virtuozzo.com> References: <20261126-khorenko-vstor-157133-klp-and-kvm-fixes-v1-0-0ec8eaadf1bc@virtuozzo.com> In-Reply-To: <20261126-khorenko-vstor-157133-klp-and-kvm-fixes-v1-0-0ec8eaadf1bc@virtuozzo.com> To: Pavel Tikhomirov X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4119; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=x1k6nvusreUhxAZ0PjCXaXl3+nYP4U3XLpZKRnD/IkY=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBrCEJ9W2KBauObqCmK+V+mbpcGkFhsSaEerDxWg swvmZDaV0OJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCawhCfQAKCRBRlgpH+WFc KqAcEACgsxE9rUICDugP29GSfJnjJREwfcPr0xHs7nD8lWr90Wcw7i9vYu554LabTW/CQOOymBB Zbf0joSMHHune5TJjUnQl0eU/87izw52LTYgSmt72oeqAfDIB7vW4iZbApS203ziPHIdXIcsUqK CjC7VuTRl5q4IOsygwB5jDTPN/NnhN6XMVxfhOL4YdJgfTH9Wbi3XvLE5GZpiJjHPIMkUqMrBp1 9vfjQgXiZ0YithimoRclr8l6Vh/oJBXGiv2Z7bVP31aS5/g1Gs21V+nSpu8LsOyB2kNgdP/RUk4 I4GeodCEAmaqnZ+HFfIbyEK4BNLT+V7lga0nVnYQU/U1FSOoSL5PNaLh2Dyb2i+Bhxo/tZ2QYvw JRbvIYPY7/6wnH243GI1pazeuT1Jjhw79F8D7DbsrQtiKlrOV4DFHv7RRu8uu1mh4o11HnZkhqE W1LQCiIjSJSv6Gw3mpPjFqIuT+WHkUGt/8y2U6yy5iU54gAj4LLU3tfLob1WzCyFRXL4hPZMHFM TLDLX7qhDG35/fz4Ps4QEy5m4tGY/czR8JjUp+X4CPecYy1PJh7e6Ed2WXF/ekSEyMoEEq/x6sa nu2+kE5qgHdajj+JT4zkatGxmACa1xexSTQDYAb3qrK+rQo3BE3bQSdxuen3SB48YaNV5/NZphg 8NGq/4To+IUq+Eg== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 05/14] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT 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 c7c288d178cb0b78d3464a616b16b1aa0b316049 ] Force an MMU reset when emulating an INIT even if paging was already disabled, as the MMU page role includes guest_mode (L2), i.e. an INIT while L2 is running with CR0.PG=0 will result in KVM running L1 with a stale MMU context. Alternatively, the reset could be scoped strictly to paging being enabled or L2 being active, but SMM is also encoded in the page role. Even though it _should_ be impossible for the vCPU to be INIT'd while SMM is active, there's zero value in not handling SMM. At that point, the only scenario where KVM _doesn't_ need to reset the MMU context is on an INIT with the vCPU running in Real Mode or Unpaged Protect Mode, and while INIT in those modes is somewhat common, it's far from a hot path and re-initializing the MMU is not expensive, especially when the role isn't changing (KVM elides most of the re-configuration in that case). Note, like the Fixes commit, this bug only affects nested SVM as INIT is an unconditional intercept on VMX, i.e. it's impossible to emulate INIT while L2 is active. Temporarily keep the guest TLB flush when CR0.PG is being cleared even though it is fully redundant with the flush that is emitted on all INIT events (KVM itself only does RESET when a vCPU is being created, i.e. when CR0.PG must be '0'). Fixes: ed129ec9057f ("KVM: x86: forcibly leave nested mode on vCPU reset") Reported-by: Stefan Teodorescu Reported-by: Oren Yomtov Reported-by: Chris Mason Cc: stable@vger.kernel.org Cc: Yosry Ahmed Signed-off-by: Sean Christopherson Message-ID: <20261022015407.279870-2-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin (cherry picked from commit f55a3e4e08dc004b4bab7c1e9323d7e7e96e266a) https://virtuozzo.atlassian.net/browse/VSTOR-157389 Feature: fix ms/kvm Signed-off-by: Konstantin Khorenko --- arch/x86/kvm/x86.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e0f575bc67f47..a825a48093ae1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12596,18 +12596,23 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_x86_call(set_efer)(vcpu, 0); kvm_x86_call(update_exception_bitmap)(vcpu); + if (old_cr0 & X86_CR0_PG) + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + /* - * On the standard CR0/CR4/EFER modification paths, there are several - * complex conditions determining whether the MMU has to be reset and/or - * which PCIDs have to be flushed. However, CR0.WP and the paging-related - * bits in CR4 and EFER are irrelevant if CR0.PG was '0'; and a reset+flush - * is needed anyway if CR0.PG was '1' (which can only happen for INIT, as - * CR0 will be '0' prior to RESET). So we only need to check CR0.PG here. + * Unconditionally reset the MMU, even though super strictly speaking, + * a MMU reset is only necessary if and only one of the page role bits + * is changing. All of the CR0/CR4/EFER bits effectively get covered + * by checking CR0.PG=1, as CR0.WP and the paging-related bits in CR4 + * and EFER are irrelevant if CR0.PG was '0'. Subtly, if the vCPU was + * in guest mode (L2) or SMM (although emulating INIT in SMM _should_ + * be impossible), an MMU reset is also necessary as "guest mode" and + * "smm" are both encoded in the shadow page role. As a result, the + * only scenarios where an MMU reset is *not* needed is if the vCPU is + * in Real Mode or Unpaged Protected Mode, and micro-optimizing those + * paths are not worth the risk of running with a stale MMU context. */ - if (old_cr0 & X86_CR0_PG) { - kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); - kvm_mmu_reset_context(vcpu); - } + kvm_mmu_reset_context(vcpu); /* * Intel's SDM states that all TLB entries are flushed on INIT. AMD's -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel