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 A999780031 for ; Thu, 26 Nov 2026 21:54:32 +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 6AQLrKIh031519; Fri, 27 Nov 2026 00:53:21 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQLrKIh031519 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="qSq3tpt1" Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQLr6n7031431 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Fri, 27 Nov 2026 00:53:06 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQLr6n7031431 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-6babdfe377cso4602859a12.0 for ; Thu, 26 Nov 2026 13:53:06 -0800 (PST) X-Gm-Message-State: APuU4Z8hQmSpz9Nzt8MpOmCkmSAnplLzEaf3qEO38WM7clBlRCdpLiEt moLMGXsAqZFD5LvkVQyNyySftipCgP5SZTn7ucU8/jtXjVYImfYgQvZ6tVVwHwtYy/rF9pW7SSn YsiPTaVANqz+Am39n0UHOn4r8pXbWQrzOSVEk5m26qBhbAvJy5W1CXQ== X-Gm-Gg: AZFdTZftbap9Tk1Ms0Xw8Whwvxyx3NViGaRVnZ1ks1ZifahIVfmW8rRb47xs1cp7C+h TDpwIHzO2/1UutO7tMWlDukl8KwFQVOb732HUrxn30ucMBOPRDtLIXpSep0kshzT1VJDLbToM+d TCP9sqZjmZTQJVo6JU/BAZBRkVY3Z1MU3bY1EmNxUVfndosUFj6qFB3UiCFXIlGezu4NFKNUZH4 NHpMCKSfSRwwyhJhb+OAt/HQvLfG88FGamKqzsti6pPfMHzAdS32abB89zI1GcYxM6+TdgqHjPg V7WyWjNGROhB7UrYGt6cWX2fIiM0obucvpcPEm0KgKH2YgEEWJ7XKD1gtCPBWktiBKxJPYfr/Sh cl9T6bRP+Jb+9k+7xMg== X-Received: by 2002:aa7:db4d:0:b0:6b9:2910:423a with SMTP id 4fb4d7f45d1cf-6ba37c7bbfcmr12410061a12.2.1795729985760; Thu, 26 Nov 2026 13:53:05 -0800 (PST) X-Received: by 2002:aa7:db4d:0:b0:6b9:2910:423a with SMTP id 4fb4d7f45d1cf-6ba37c7bbfcmr12410054a12.2.1795729985266; 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=MsvpMK7nkULoilg0wciIe/tM8JtCkpUkAb+wB0WNmYuFXLO1ly1zWUxJpw1xiw4nil nxY3ATJK+i/dT95SHVfbO3ltH+YNLo3a7z0yXSBwHm2iEvcs5AIdgZLozvOu0wlG39Em 4E7gFT7pAV0aqpKh/1Sg7vk1TZXC5ZHG+Lz3DAeWUX4Vc+xz6aKfO5VV8D2Wg5EEW36c WH8Wz3SiCFXu2gpzPWCUhS6Wi/wR4UIAj6WYMUJzbTgwC05u4KImNadkelx56qY/Yc7f 1u2LcDwVpSMcZXiQHRfiYqoB29OImGWiK911p8dFoZUJQNtG7GZN/k1+PmxOd4ZaWf3q cqFA== 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=C1AbElE30fi2W0TszLkgcoX9TC2I5iw9flzmSdgVhA8=; fh=oOZACxR4KP+1I9I4VayNBZ4FD/hXMXJDAvznfQ9uKaU=; b=VyFYcn5Gda/y8puxkDkRktNJLpjBDm53cL3LE6ajM6DiIok5cgoIEyF8j5I4BcbBPj no04H3mv7Sdv4hulBncnCchFN6rkt0+I7vhw8GDGkHUrnryx1Q7F6pVLWcvtaGty7qrF 3htp9S7iW0f/G7UQcWPaSu36sNCCVgJD2ptX/Rm3Wao5OMuHxC7nt9pKAcZ0rJQWVpK7 eCxVPDphofn17hRv7J4wLaUnfjFBfS8XYaOlRBV+pZblE2OXSCWzZe+iJl13mrJ+E3cH Apl3vrkfNc/x8/u6H7jkA07XUhbZ1JB3hm38GBKgnXiVLRxjZNRE0HomG21A410A0SHW YnRQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=qSq3tpt1; 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-6ba371585bbsi18786662a12.87.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=qSq3tpt1; 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=C1AbElE30fi2W0TszLkgcoX9TC2I5iw9flzmSdgVhA8=; b=qSq3tpt1Cm0GwiUW+R2 wDc5Pi5qTE4VMmek3nTz/pH9Ls3HoLrzjrb5yAJeyB1Ettqh9lWmsp8eoNdY5fvd18QvEoPTqQo7/ KsvB15YfaAOuAZhfsXKkS3BoyYhffrF2W+J3cKEz6Q0DX9cHfpMa7yUK9NBg2wVTm47BzQ+IB/nqh 7qD9DOf0li4y7xHAWM8qq2k3w91sV2ycNzOhe6+2NYzQP14JEGwlpyQ37I6iO3HjWpJGrBamErSaw dl13M3rLJtGSnvUJ7FlJn+7cf0HTWr8iKoIs3s+jmbWoKCGtPHNykyYrz5cA9v0e1wFJZYnrW+May 8V+s2MCGDNKvGyw==; 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-1s; Thu, 26 Nov 2026 22:53:02 +0100 From: Konstantin Khorenko Date: Thu, 26 Nov 2026 22:53:03 +0100 MIME-Version: 1.0 Message-Id: <20261126-khorenko-vstor-157390-kvm-fixes-v1-5-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=4119; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=FXoh9KWL/BSEdrMNoK84MjnfQAHRxh1kaHhpcT0qciA=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBrCKo+VrhE77prXqz9Wdx2y0q5HyWuY2Wbl4/HA vD+fPa6PR+JAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCawiqPgAKCRBRlgpH+WFc Kj3JD/wPX5Gl3kkm4Vk28a9Ro6oI1rKD3BkLb1L98R6IIiNBWVEldI1d+LRvz7QNzx01C74G7eE h8IleStoLkAXwWKvK5XzMien7Bqx9rL3DKX8vvp5R4orDPBLjS4mkZoQBsdk/OLYKFVVCRR+Pv3 HP/ztJVDnYln8wGBnzYkrD0BCseszq7VqNQw6FeQ5Cm9+J+fQz+YPcxWye4rLxwvA5l7DtsPQk2 kkx6t+HBaqLumfcjXOjRmDiw6/vhhff8T4qhccS9fyUPaMwwd5R3gKchftqaCYKEG0neSMiBh4Y xXupXates9cNmZUD7XoKn1e5aTX6B5PsC56qbkqoPqde6vvoaT9uODOQSnV5chs88ZwruYDSRmc hmEgzWZ/RWE/fSBk5OKvmaCyzO18Jn/i7cyCFadbixPHlJ50DV4L2A0NbJ/hfqGDeqJMDNJBD6L 14oGC0SeGfoEN+93mfvk9aHkPW2B7XCgoyEvuorhren4rAtmDpVtI2y9jVvd1403CE1WhUGXdfD UlbrG8A7M4stNzNV54CQLbkJTShlY9KBIJ/MfBF0/7UboWxLNTagVfBletdkcJjRo7AqViHybgI i7t1cuDTscigIHqr/lxBU2iv552TXJNwEC2ctCuxRkvdQCfLTHle+J7I2KcnMfhap9K3ZN/HU6R D2xbqoId4fuI91w== 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 5/7] 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-157390 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