From nobody Sun Nov 24 21:52:05 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C4FF1CF2BB for ; Fri, 1 Nov 2024 19:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488495; cv=none; b=aHieeO0B/ZTj3nzMe3vk98gBsn9N97KqZdJd3X3LiEurmlDecJm13M/ZmO+je4k2LCuS4IiObeVnrch8zAGJxRHfRsCg8zEFBZJFdeZpfYDcLjiyGxmzKbrWNr0j+v70H31SB5JR5pHj3Q9CXzTCp4aWCDl7zMooENMFJar0lfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488495; c=relaxed/simple; bh=Z8EXJQg9J+JbZJ5bvHzBnxb9K+Y/SuxFmaizU8r2hCI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V8GmrlFFKP58gGdUtiH2UvFaOoyy8m7gKQGVEPS59bTVPTxtLRam+Om/ZoqNFi9UbzNfSJuqbqpA6w11Uv6vOb6BETrsWnCil4ZlI1EE8dUgihcOLDm9UVMR/rXZfxF/juUJOKWVM2MgErKC43V8A/W1Tn+QJ4TkINUTQqo2mdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mHqfa68k; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mHqfa68k" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e35199eb2bso45483127b3.3 for ; Fri, 01 Nov 2024 12:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730488493; x=1731093293; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=v92SLkTXXGmBr8w3sJwcuNbutcUF6pT1F5wULmisia4=; b=mHqfa68k4YVgtjNxcRjK4FimwkmvqdSf8tPCHiWUcQT6J9Hz6br/o2Duf5TgFXAUjE UiAk5qy/xoVNPhBcFqPe+a2qYdwcjpHXT4RDJEGQylr51J2hHJNiDk5pRhhiWeU5FbUR FYwcS6fcHgX5YmU4KyTaVms4V1BCVAEifYMEpyq2IaYdM6GsyCnm5CGlLZJ3fbwk44Up qp6ru5VhtXHK0PDLB0VfgDbXeGIbxwWHVz0Lbsy3RfYyB3l/IlIpwu1LVKS26kA3ob7n V8uINeOuTFgAJYumJX3lCDsoszyhGj+fxbr2ClZRaS2g7/Rf5cB5qNI9eiM/W3bbUsrY bOIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730488493; x=1731093293; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v92SLkTXXGmBr8w3sJwcuNbutcUF6pT1F5wULmisia4=; b=iG6ikav2udEHqDLnS5OvcRwizxApKcwsMHQTANxY7+cNMIWJ8GJdzAK59GvonGkfEe CDyPh38kRna0m0RWcQGQgsP4aXTQLL+NnlEgYjJXTFv1muAZiLBNecM7dLNXluDCKEdF b1zRMNl1jysk9adLFts5n9RX5UKnd6clLPP0QAj5HAa3S+kT0H5IXVY0zDfYN6fBboJl ajoLvAh71+s283dMLMWN2d5dehUDs5rNpNHNYNXbjh3A8s8utTMyzx5XMJ+0lctbtker cMSwkngxs/WrH+cEecCo16NeMq07Q8z0gGDKH3i4DCcLB0p4IemX9wBDvih5l4GNHRfG EM9g== X-Forwarded-Encrypted: i=1; AJvYcCVy9BSPssHs6W6QdRMSVlhPZpazJ09g8DPW+IFzc5iW6yMzHbaW9c+pM5lwUSf+2JVAQHmdk0+wmXVPPz8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+atWmRwtIqba6RdX8x8Lan3znwwq1sO+2k3yH1JTL0K1JjN1O ycUwyH/PosIy6G7sU8SJRxKPxSmfHqLnevXrThoFT2YOruEkE9640IkeKrEvv/EHEbGIv8LiP6N GXw== X-Google-Smtp-Source: AGHT+IF9r8zl08wY2gD7V1mrRcKyxB0hLcWTnA85ohgz9qnHRR8D6x/+fevO5rXxbmNY/LHUGAaznvSD3qo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:680a:b0:6db:c34f:9e4f with SMTP id 00721157ae682-6ea64c2d414mr803537b3.8.1730488493198; Fri, 01 Nov 2024 12:14:53 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 1 Nov 2024 12:14:43 -0700 In-Reply-To: <20241101191447.1807602-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101191447.1807602-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101191447.1807602-2-seanjc@google.com> Subject: [PATCH 1/5] KVM: nVMX: Explicitly update vPPR on successful nested VM-Enter From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Always request pending event evaluation after successful nested VM-Enter if L1 has a pending IRQ, as KVM will effectively do so anyways when APICv is enabled, by way of vmx_has_apicv_interrupt(). This will allow dropping the aforementioned APICv check, and will also allow handling nested Posted Interrupt processing entirely within vmx_check_nested_events(), which is necessary to honor priority between concurrent events. Note, checking for pending IRQs has a subtle side effect, as it results in a PPR update for L1's vAPIC (PPR virtualization does happen at VM-Enter, but for nested VM-Enter that affects L2's vAPIC, not L1's vAPIC). However, KVM updates PPR _constantly_, even when PPR technically shouldn't be refreshed, e.g. kvm_vcpu_has_events() re-evaluates PPR if IRQs are unblocked, by way of the same kvm_apic_has_interrupt() check. Ditto for nested VM-Enter itself, when nested posted interrupts are enabled. Thus, trying to avoid a PPR update on VM-Enter just to be pedantically accurate is ridiculous, given the behavior elsewhere in KVM. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 746cb41c5b98..84386329474b 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3604,7 +3604,8 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, * effectively unblock various events, e.g. INIT/SIPI cause VM-Exit * unconditionally. */ - if (unlikely(evaluate_pending_interrupts)) + if (unlikely(evaluate_pending_interrupts) || + kvm_apic_has_interrupt(vcpu)) kvm_make_request(KVM_REQ_EVENT, vcpu); =20 /* --=20 2.47.0.163.g1226f6d8fa-goog From nobody Sun Nov 24 21:52:05 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E334B1CF5DD for ; Fri, 1 Nov 2024 19:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488497; cv=none; b=fl6auj9cQzPVSEcPW9hF3378bEuz8KwJCBrF5c81v0Kw07NQAhGIgO/26astsEDzzBQpgz7xgyPj+E6NRuwJ3OHMutpN2UwScMhwBdEgL9o1BQDVAyMCG3efucdg4EFT/tiUHC+Q3yTAuG7jS0FEzuyvdO2QPehLu2wUvncAqgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488497; c=relaxed/simple; bh=AW20RPSqHiDv3fdCFx5HqXZFyAEwbL8305AAGXtmtFc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FBzE4U/Ac1LZZh/DaBHwA6fe3IJ6/WwhKEp6zkJn2c9n9fCd8zryq3Nk2QFfHOECUyfM7guL2nnGLdJKYUvH+U7HcdlQJDG3QHdF/Faa3y8BIjgeRyJ2J7eRgojMm/3z6cdlS8d29YPV8tUbFZEvD9apJRUHrgsdnCcmZdvyhmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AK22g6er; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AK22g6er" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e33152c8225so724823276.0 for ; Fri, 01 Nov 2024 12:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730488495; x=1731093295; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=eKpbimIHH00sjHL9LmhMqa7Xx8rmdKzGFtZAWYFdii8=; b=AK22g6er8cxh5A75erKAuaBUdWuN2b/rKANfBJi36YWc9723cQ9QGkVWckkNKOzvan PaQ+Zi0jOMDAVdB4S8wzPOb6kzp0jWRWDD8U0+GjtbpHPEcFQWvcCaL5oDAeyp7Bmdbm SN/TXzSAlE6kOrVZ6BMtc9tlscvEMpijaNiBOl1J5+a9OcBXqScs2jYPO8B6t1SZmrXL KUtRrb6nnc9IiuRvncAwAiAUfRfHGdmEwj/05UGN2swVfJlJh2C7T6qmqKSpyQaNQ3Op mJVhqubIryAw0/O33WBZzaI9r+V/cbIljBc9s4DFqKHYcohhq6sE9KReGjqZPjeFC/gf euRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730488495; x=1731093295; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eKpbimIHH00sjHL9LmhMqa7Xx8rmdKzGFtZAWYFdii8=; b=enRW+zzeMa82XJy+LD0qYtMJyz2VL4WcFdjutV+yRAp628AsSJvddQ+1taf/4q8aLb 17mT+L5d6LWxvWAYbhrnHm4BRtOw2JraUVNFdhuZRXVaSvWJPPRxzbCzPASnFWw3btNH APmfO0SHrJW0O5T2QY3re87a09q/ig7qrgIlNObxSXWIuxHPvNpY+qa3cfmXv4ofGRsr gBBLbx9aUQiQ40KnPa4yZZAc6ECtWWvmrvN3MzoClGV+VY7EWNiO4DLyVu15Y4fOYdRE NVRWB8A9HQ9FXk8JrTaIRPmYzogCCmA4OZxcisIqp//jc94D4GPoNOu+EctUjSgvVbXt vHlA== X-Forwarded-Encrypted: i=1; AJvYcCVLKfIapHUSWuYcReQQ8inP3ifvwz16/DvOrJxyWWfGxaAqHZo0+XTR1ow74PxuxdW+VspIl5N0dJqW8CY=@vger.kernel.org X-Gm-Message-State: AOJu0YwI+9F2JqTbJbHE3PUFteQdFJkiVrR6CMRxrEK7Gauf2LbwKztd I5l/ifBQJFmGDm4rRWtTtFEFsJ9au9I+PJ2nc4hbOxKMoujiYJxUMZ9x5VZp3MZiJmY1cw+zOb5 QrA== X-Google-Smtp-Source: AGHT+IEg0O0AegMc5HJlVs59TSZ96+d/qrSdvFRy5uOr2T1xkt+bIsh/JxfUJG2zkmVqY/VivVCoVROYj0o= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:aa89:0:b0:e2b:e955:d58a with SMTP id 3f1490d57ef6-e330268d946mr2445276.7.1730488495007; Fri, 01 Nov 2024 12:14:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 1 Nov 2024 12:14:44 -0700 In-Reply-To: <20241101191447.1807602-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101191447.1807602-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101191447.1807602-3-seanjc@google.com> Subject: [PATCH 2/5] KVM: nVMX: Check for pending INIT/SIPI after entering non-root mode From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Explicitly check for a pending INIT or SIPI after entering non-root mode during nested VM-Enter emulation, as no VMCS information is quered as part of the check, i.e. there is no need to check for INIT/SIPI while vmcs01 is still loaded. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 84386329474b..781da9fe979f 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3517,8 +3517,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, (CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING); if (likely(!evaluate_pending_interrupts) && kvm_vcpu_apicv_active(vcpu)) evaluate_pending_interrupts |=3D vmx_has_apicv_interrupt(vcpu); - if (!evaluate_pending_interrupts) - evaluate_pending_interrupts |=3D kvm_apic_has_pending_init_or_sipi(vcpu); =20 if (!vmx->nested.nested_run_pending || !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) @@ -3605,6 +3603,7 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, * unconditionally. */ if (unlikely(evaluate_pending_interrupts) || + kvm_apic_has_pending_init_or_sipi(vcpu) || kvm_apic_has_interrupt(vcpu)) kvm_make_request(KVM_REQ_EVENT, vcpu); =20 --=20 2.47.0.163.g1226f6d8fa-goog From nobody Sun Nov 24 21:52:05 2024 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 701251CF7B4 for ; Fri, 1 Nov 2024 19:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488498; cv=none; b=JbqYvdrbmtcBBj4bpfzu2YP9QTjPdXjr6YBLYrKfcV7eybcSipzmqqnL5g1IVpBGjOZTY6kwn8/wDyB+iu4TghZVv9OqcuJAyLpEwaHzDR8NhpfS9q085C/9X6sJB8wXcPBUQ+xlpTUq86pwhGK8GDjkX4wIfx7liwa1AwRjlmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488498; c=relaxed/simple; bh=3THyAOFYqGiZ3re11pAzXOzUv5U2Kh6KiITyIgCJ00s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ON6CAiE1x6cYXQC2XKcK5beuexgphgyqLxQmJhpWvJ3PI81FpQh5j0VxY20h4IhfGGndn5P1pvMtF60eV9CjqrYRrHiDGp57TjWHalZECL5FV3cj2rqZKzj+3tJsmlPnk+3aEqtZQU4YFCGGpQc7/1+PN1UNkE3UjqhxYI13wfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KU3G66rB; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KU3G66rB" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-20c94f450c7so29833055ad.3 for ; Fri, 01 Nov 2024 12:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730488497; x=1731093297; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=Bty8Xxmjy9aCwGBD+Q77bQvQCPqX0/VPBlC1IcBrLWY=; b=KU3G66rB+VR9FlcNZPXrJyW7UatY6PQwCm6jN2mbZv3x32fEKCBCU5n1Whsso0D4ac oI4TfaLIs2quzReBMtsX0+9GntEzK5DWQ1HZr29PT63piwfv2pMKwVUfS7Jl2SxZAU0d Y1C1PvU4Qi2/dSHjPGYA25xluQx7rEWezTpcJLcPhDUJZOIXOrrmE2tIsv3ijb3GAbZx 6YpL8N5P+dYSy+jqPavNaTJHfl1lUD/ydAmr1jdYtB014wYcozgQBFyDfo1MUVSuFYn4 kHqSJFynoWqeymufDXa24UyiV7100AHccnY2KrD+u487o9D0SZIS7bpHeatRIW7ody5+ datA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730488497; x=1731093297; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Bty8Xxmjy9aCwGBD+Q77bQvQCPqX0/VPBlC1IcBrLWY=; b=PSSOYX9yzk4ivp0jgydFJfYIghq+fIqaBTC3XB8f6d407C+Ucf2ThE08ldVz5Y68T3 5Zc2TlODjY17QUjYeFXyNyhhp1KRwN5IaE1cGKY9zwUatow59YnablyNKWHghaGciFr1 CZbzdr7+JtzW93o4/Fj5f5syVJFdMufuXep278Twrw9GMWd1jNSdG93UmU74oi24LdQZ /UFOUesUuIpAe3hgYHaof6TzdB78gJYS7aygIeTK0rWD2KEFEo4aM9450UOCAPP5PvfR Tg/XOr0OWiNH8AMmBLEhq10y5+LLB1gwcYilDSD+eUnRoOFEQta4LJ/HiVQxJMiX2XMi dWNQ== X-Forwarded-Encrypted: i=1; AJvYcCX8ZgpUbX4lTPnyOB4yJz+IKkMnbGfDRMSfNMe/C1bldE/BT14SFc4LMSyVOtQR9lRi0yr0Emtg9/OXNE0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywp1JZHQCZDyOMp7CkinFLZeoWYH3kiD6BybT894NF8fQNngNOS m8RWyJswjtSDlwts3ig+U7J5hDs+BleXGT19rHWHYBr16nOLG1kbUv53eqXDCqwn17uhuhxB9Z2 4tw== X-Google-Smtp-Source: AGHT+IFk3TV3aGBmDsau6FclKYwuGA5/t2XABMgaAJqdgPRwBHX0/QyxzgqbmL+hpK/UfwTGUXOB8E7yWFk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:902:e745:b0:20c:9821:69a7 with SMTP id d9443c01a7336-210f763beb7mr1927395ad.6.1730488496835; Fri, 01 Nov 2024 12:14:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 1 Nov 2024 12:14:45 -0700 In-Reply-To: <20241101191447.1807602-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101191447.1807602-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101191447.1807602-4-seanjc@google.com> Subject: [PATCH 3/5] KVM: nVMX: Drop manual vmcs01.GUEST_INTERRUPT_STATUS.RVI check at VM-Enter From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop the manual check for a pending IRQ in vmcs01's RVI field during nested VM-Enter, as the recently added call to kvm_apic_has_interrupt() when checking for pending events after successful VM-Enter is a superset of the RVI check (IRQs that are pending in RVI are also pending in L1's IRR). Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 781da9fe979f..4d20ab647876 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3467,14 +3467,6 @@ static int nested_vmx_check_permission(struct kvm_vc= pu *vcpu) return 1; } =20 -static u8 vmx_has_apicv_interrupt(struct kvm_vcpu *vcpu) -{ - u8 rvi =3D vmx_get_rvi(); - u8 vppr =3D kvm_lapic_get_reg(vcpu->arch.apic, APIC_PROCPRI); - - return ((rvi & 0xf0) > (vppr & 0xf0)); -} - static void load_vmcs12_host_state(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12); =20 @@ -3515,8 +3507,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, =20 evaluate_pending_interrupts =3D exec_controls_get(vmx) & (CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING); - if (likely(!evaluate_pending_interrupts) && kvm_vcpu_apicv_active(vcpu)) - evaluate_pending_interrupts |=3D vmx_has_apicv_interrupt(vcpu); =20 if (!vmx->nested.nested_run_pending || !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Sun Nov 24 21:52:05 2024 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C79A1D0141 for ; Fri, 1 Nov 2024 19:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488500; cv=none; b=FTZHEF4z1qdWTnkNDkdFutIRqIcL90pR1t49GXnMSdhENu53VLwYKariOmrp62niNE8rw7r6e1uxfdsnW86BKhWi1UoIqKTGsDRxz+QmoEcaWFynveo9NNb+G7iMlPhqFAjFvMg3e7XdssBgkENXfUby1WHqKDymLdweUQ7Fi6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488500; c=relaxed/simple; bh=jxo9Um4MNyRp6WJPIZhGVnb1qXFxFmLRqxQh0eevjEE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z9OXNF8FtTFmBMksrCPMqEoOKLiQgZZHJl574eRsMl/7EIhFiAlmceyEgGvbNISbnJVfv7l9RSH8QfF5PrUP3/kyGFgbxmtLX6Grra6lYg/2ejLpI76Yt4XrweAnQAYI0yJUhMcYHwgI1o4a/RCTs5GwCZgGs3JYeycJSjmvz9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cpP66Lqc; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cpP66Lqc" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-71e6241c002so2293644b3a.1 for ; Fri, 01 Nov 2024 12:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730488498; x=1731093298; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=EBjQChsQkGdvyBMJ4mZedLs9/EtB6ki+0LIpNzc1JfM=; b=cpP66Lqcvzu6DgaQMrk4QQb6+98To8U76187ywYqr9RGdt7fsA/cM7IT7RfVgJCIXK UiVrcWkYxZhyqf7+gJKnqtD57IMtItXARBUfMThyGlvVm8a5tA9xMBkOuSv5vrpSqUPb jZ0UZKBMDj1o5NGKFRkbHV55XdRSYCtWxtJ9Ky9P3WkMcZcZu8LLyt2A+T6iSYyk64fy bNLsZMQSRcr4V//ZQmHETXw5TEzxdSHebqq2ORLhkFMMNuVbM63qJcMHsT3p8YUj5sYX GKCPEna8u3gQgYyxf1hwUXwcQqQxfBB7iR44DgUYjS44KZI4FIoRroP5twW6emen5u3w l1lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730488498; x=1731093298; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EBjQChsQkGdvyBMJ4mZedLs9/EtB6ki+0LIpNzc1JfM=; b=kfn1O2/qxOyQWmIqaTTFeaRsY/jJb120hkgAs4lVCIswfvuPlIEAZ1t1WB5YyAk62b ML0WE88TO2QMPhtySO1VtXqqlahKtA6O0eDLSEhBWlU4bIzb/Ou8tvG3C6wfqVEBvLjh oMBd6BUOsMoGpXUeZcepyeirdd8qlzBBDw/JCSHmKtpmM25y/7fWa5aqbuGgRSJeoI07 j7XDtKW2AXhbbHpQQPf7anT8PlnOyhy9hhNz2X2UuIzF8ux0ytQnXve64orW6duOkG6u DGVIDAB4m/eInlmvL/MOQkWjDkJ1VJ2gJckfwnOKppDiqgZxU89Znq5e352OBvNt40PQ zO2g== X-Forwarded-Encrypted: i=1; AJvYcCU4JwTJ6Ln+gPvsDYCmk6+B8SV7sRpSL4jLAfHB+Zb5gAJTN4vCnoCQ67VSfENjPt1/LGEv3VGQVyCK1cM=@vger.kernel.org X-Gm-Message-State: AOJu0YyJJ2WDoRIXv3M57ZbxeQtSEZeKxr+rglLmit7McXKk9dxiKDg3 DHwhkgtouy9fGLxGBTMY7J2HH4KtIUPk+0WyhyE2bz+d7Tv/7r4eA8DPNW4E3dd7Nu0Jwu6SECS cPQ== X-Google-Smtp-Source: AGHT+IHfw1GQRMnZPA8VfH9+KSaVs33bq1UNe4WX1/RW4FnvMArjWdJh1n6jjxhCzBGh/CGN8O4meR5kuDc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:aa7:8183:0:b0:71e:4df8:a3e7 with SMTP id d2e1a72fcca58-720bc86b580mr19190b3a.2.1730488498550; Fri, 01 Nov 2024 12:14:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 1 Nov 2024 12:14:46 -0700 In-Reply-To: <20241101191447.1807602-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101191447.1807602-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101191447.1807602-5-seanjc@google.com> Subject: [PATCH 4/5] KVM: nVMX: Use vmcs01's controls shadow to check for IRQ/NMI windows at VM-Enter From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use vmcs01's execution controls shadow to check for IRQ/NMI windows after a successful nested VM-Enter, instead of snapshotting the information prior to emulating VM-Enter. It's quite difficult to see that the entire reason controls are snapshot prior nested VM-Enter is to read them from vmcs01 (vmcs02 is loaded if nested VM-Enter is successful). That could be solved with a comment, but explicitly using vmcs01's shadow makes the code self-documenting to a certain extent. No functional change intended (vmcs01's execution controls must not be modified during emulation of nested VM-Enter). Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 4d20ab647876..0540faef0c85 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3486,7 +3486,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, struct vcpu_vmx *vmx =3D to_vmx(vcpu); struct vmcs12 *vmcs12 =3D get_vmcs12(vcpu); enum vm_entry_failure_code entry_failure_code; - bool evaluate_pending_interrupts; union vmx_exit_reason exit_reason =3D { .basic =3D EXIT_REASON_INVALID_STATE, .failed_vmentry =3D 1, @@ -3505,9 +3504,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, =20 kvm_service_local_tlb_flush_requests(vcpu); =20 - evaluate_pending_interrupts =3D exec_controls_get(vmx) & - (CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING); - if (!vmx->nested.nested_run_pending || !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) vmx->nested.pre_vmenter_debugctl =3D vmcs_read64(GUEST_IA32_DEBUGCTL); @@ -3590,9 +3586,11 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_m= ode(struct kvm_vcpu *vcpu, * Re-evaluate pending events if L1 had a pending IRQ/NMI/INIT/SIPI * when it executed VMLAUNCH/VMRESUME, as entering non-root mode can * effectively unblock various events, e.g. INIT/SIPI cause VM-Exit - * unconditionally. + * unconditionally. Take care to pull data from vmcs01 as appropriate, + * e.g. when checking for interrupt windows, as vmcs02 is now loaded. */ - if (unlikely(evaluate_pending_interrupts) || + if ((__exec_controls_get(&vmx->vmcs01) & (CPU_BASED_INTR_WINDOW_EXITING | + CPU_BASED_NMI_WINDOW_EXITING)) || kvm_apic_has_pending_init_or_sipi(vcpu) || kvm_apic_has_interrupt(vcpu)) kvm_make_request(KVM_REQ_EVENT, vcpu); --=20 2.47.0.163.g1226f6d8fa-goog From nobody Sun Nov 24 21:52:05 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CA371D0438 for ; Fri, 1 Nov 2024 19:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488502; cv=none; b=iDFgOjAKuqSiYgrELpl7rSBlOUkKE6AywxzuhwrKP8a2PkGy8MZOc8GbTf8Rm+qts0yPSR6IyxIDHdpout/abQ4/HkptHakC0aQ24nWuGtCE2aOaxrlGTYxNTsN2vTAn4nf1HtYCuDebKfVhB7FhSwki8Wag04fjwkS7gQREwX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730488502; c=relaxed/simple; bh=8JHdaYM0xXhzHuPv71pVBdeyV3cel6FJgdk6+9WWaVA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fP9b1HsVC9gCiJ2XmDJbhpd3wrTqsIXwtiU+sdT9YFiUEaEjsmb2HzCxyG3cZ2dYRfcFxsO1d3lI0WhVO1pus0ntSby/BjVFqzs1ak+o2QyW4BACbb7xs30I66r0wPTsoWSPsDLYBmWdy3XI1I96QsApgm1IlfI91LGFIN3lrC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=y/OQUvXV; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="y/OQUvXV" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30d7b4205eso4474255276.2 for ; Fri, 01 Nov 2024 12:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730488500; x=1731093300; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=wVNlWehVR99hr0dhSgfmMBMjHWaw56c/QaGVUiFdMnE=; b=y/OQUvXVmBoZpB9GM80tjlwh9YHuL9VajNcnKoRh7V9JIZOhEay3nC0EQHox0n03pL ivC95imijxI8qZS9vBuCndliju2eaXvBTzLqSHPdJzWWKkjmnccO81+w7kzZB2TW665I ibzXIpCodmYTkjt4e/6qWrcMUd/NJKLD3PEOwuGVJ3Gr3zkCukfLieRWH4uQ02uS4C6y evDDJSPAw5ynF7K0MSq5Md6fE/iCmAEvEp855k6lUMiaHpY1ctWBULrj+Aj0WN3aBgZL 493IG2B8tK5st8XnXlYMz6TClqHwNj9aW5ZxWITwhbC+NOZwu6sJMqtJ6Bem4KwyF7iT IDFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730488500; x=1731093300; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wVNlWehVR99hr0dhSgfmMBMjHWaw56c/QaGVUiFdMnE=; b=CGaPni1+m9yjh0DT+blPplhIQHhj6+ZHW8AnbyqxBFv5gDcFPXVbomjQt17RIVaWbo 89rF88GM5tLPLYcIVc6acSDXNXrERaMU1pl7ei6AzfBtUAI+eUfYPxxG7oolj7L6a8ue v2p3rvXmVqp5PGevWybORbDKt77ks3dWZ7zqzNOCDTzOvWqPLqfbBYIjds+bf8HMI4SR MGHjyS6shk75SOy81ZWGX5ilgeWu0VTh+NY4MAwNJTSJLTfcxReyQTsFp5WNdiz9Nl0R afadKMqFAv8pA9VpnhVG0YnWARTRYxMRnLTpHVVuwlX3NTrVZ9vcmAF9AMCs6dN0Vdsy FwlQ== X-Forwarded-Encrypted: i=1; AJvYcCWlekgZoVHWwXDGZLfMbJVkwKBMvD778QYBuhQoGhL9RiDQUdGPVptvbDqK6bBUZBFP+CYV3fVfsuKtQxo=@vger.kernel.org X-Gm-Message-State: AOJu0YykGExPiHuoH27htS6bSAkQ6A5ASA1sMaSeFK3vNeZGFSqUZTfh PDTbZfMR5dlfYtU4oB6Ril6vwXo7U66d9wLM8cArpm3BtlzCCJV1z3DRMJRJd/T6H379T6E34QN T8A== X-Google-Smtp-Source: AGHT+IE0pt6vhmwVNHvx7nlyxdB88wq01HOL2kongx16D3PnuLsTZ3nsV3jgWijzqVurWsp/OrsYYOQXUfE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:8241:0:b0:e29:7cfa:9fbc with SMTP id 3f1490d57ef6-e30e5b678ffmr4451276.11.1730488500431; Fri, 01 Nov 2024 12:15:00 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 1 Nov 2024 12:14:47 -0700 In-Reply-To: <20241101191447.1807602-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101191447.1807602-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101191447.1807602-6-seanjc@google.com> Subject: [PATCH 5/5] KVM: nVMX: Honor event priority when emulating PI delivery during VM-Enter From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the handling of a nested posted interrupt notification that is unblocked by nested VM-Enter (unblocks L1 IRQs when ack-on-exit is enabled by L1) from VM-Enter emulation to vmx_check_nested_events(). To avoid a pointless forced immediate exit, i.e. to not regress IRQ delivery latency when a nested posted interrupt is pending at VM-Enter, block processing of the notification IRQ if and only if KVM must block _all_ events. Unlike injected events, KVM doesn't need to actually enter L2 before updating the vIRR and vmcs02.GUEST_INTR_STATUS, as the resulting L2 IRQ will be blocked by hardware itself, until VM-Enter to L2 completes. Note, very strictly speaking, moving the IRQ from L2's PIR to IRR before entering L2 is still technically wrong. But, practically speaking, only a userspace that is deliberately checking KVM_STATE_NESTED_RUN_PENDING against PIR and IRR can even notice; L2 will see architecturally correct behavior, as KVM ensure the VM-Enter is finished before doing anything that would effectively preempt the PIR=3D>IRR movement. Reported-by: Chao Gao Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 53 ++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 0540faef0c85..0c6c0aeaddc2 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3725,14 +3725,6 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, boo= l launch) if (unlikely(status !=3D NVMX_VMENTRY_SUCCESS)) goto vmentry_failed; =20 - /* Emulate processing of posted interrupts on VM-Enter. */ - if (nested_cpu_has_posted_intr(vmcs12) && - kvm_apic_has_interrupt(vcpu) =3D=3D vmx->nested.posted_intr_nv) { - vmx->nested.pi_pending =3D true; - kvm_make_request(KVM_REQ_EVENT, vcpu); - kvm_apic_clear_irr(vcpu, vmx->nested.posted_intr_nv); - } - /* Hide L1D cache contents from the nested guest. */ vmx->vcpu.arch.l1tf_flush_l1d =3D true; =20 @@ -4194,13 +4186,25 @@ static int vmx_check_nested_events(struct kvm_vcpu = *vcpu) */ bool block_nested_exceptions =3D vmx->nested.nested_run_pending; /* - * New events (not exceptions) are only recognized at instruction + * Events that don't require injection, i.e. that are virtualized by + * hardware, aren't blocked by a pending VM-Enter as KVM doesn't need + * to regain control in order to deliver the event, and hardware will + * handle event ordering, e.g. with respect to injected exceptions. + * + * But, new events (not exceptions) are only recognized at instruction * boundaries. If an event needs reinjection, then KVM is handling a - * VM-Exit that occurred _during_ instruction execution; new events are - * blocked until the instruction completes. + * VM-Exit that occurred _during_ instruction execution; new events, + * irrespective of whether or not they're injected, are blocked until + * the instruction completes. + */ + bool block_non_injected_events =3D kvm_event_needs_reinjection(vcpu); + /* + * Inject events are blocked by nested VM-Enter, as KVM is responsible + * for managing priority between concurrent events, i.e. KVM needs to + * wait until after VM-Enter completes to deliver injected events. */ bool block_nested_events =3D block_nested_exceptions || - kvm_event_needs_reinjection(vcpu); + block_non_injected_events; =20 if (lapic_in_kernel(vcpu) && test_bit(KVM_APIC_INIT, &apic->pending_events)) { @@ -4312,18 +4316,26 @@ static int vmx_check_nested_events(struct kvm_vcpu = *vcpu) if (kvm_cpu_has_interrupt(vcpu) && !vmx_interrupt_blocked(vcpu)) { int irq; =20 - if (block_nested_events) - return -EBUSY; - if (!nested_exit_on_intr(vcpu)) + if (!nested_exit_on_intr(vcpu)) { + if (block_nested_events) + return -EBUSY; + goto no_vmexit; + } =20 if (!nested_exit_intr_ack_set(vcpu)) { + if (block_nested_events) + return -EBUSY; + nested_vmx_vmexit(vcpu, EXIT_REASON_EXTERNAL_INTERRUPT, 0, 0); return 0; } =20 irq =3D kvm_cpu_get_extint(vcpu); if (irq !=3D -1) { + if (block_nested_events) + return -EBUSY; + nested_vmx_vmexit(vcpu, EXIT_REASON_EXTERNAL_INTERRUPT, INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR | irq, 0); return 0; @@ -4342,11 +4354,22 @@ static int vmx_check_nested_events(struct kvm_vcpu = *vcpu) * and enabling posted interrupts requires ACK-on-exit. */ if (irq =3D=3D vmx->nested.posted_intr_nv) { + /* + * Nested posted interrupts are delivered via RVI, i.e. + * aren't injected by KVM, and so can be queued even if + * manual event injection is disallowed. + */ + if (block_non_injected_events) + return -EBUSY; + vmx->nested.pi_pending =3D true; kvm_apic_clear_irr(vcpu, irq); goto no_vmexit; } =20 + if (block_nested_events) + return -EBUSY; + nested_vmx_vmexit(vcpu, EXIT_REASON_EXTERNAL_INTERRUPT, INTR_INFO_VALID_MASK | INTR_TYPE_EXT_INTR | irq, 0); =20 --=20 2.47.0.163.g1226f6d8fa-goog