Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1192667lqt; Fri, 7 Jun 2024 10:27:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSS0WnnHyVd11YpbcRM2Yww2fxNjEu+58M8JSpYpLe7dJzkNNaD4Yb/eQbv1Aj0haoFMk3IygeEfRHx3au7b2e+kWpzDq+C3oMKiVhdA== X-Google-Smtp-Source: AGHT+IEaH2OBaNhztQ3E4aWoy2mspcczpMxfpkqgSi6HmAU2J0X6Yu4hMHLmUk3RDoemYZiRIlj7 X-Received: by 2002:a50:99d1:0:b0:579:c5d1:f171 with SMTP id 4fb4d7f45d1cf-57c5098f039mr1952768a12.40.1717781236834; Fri, 07 Jun 2024 10:27:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717781236; cv=pass; d=google.com; s=arc-20160816; b=TemelpwA3ZWktJPmiSPSPNg+tTTt0QbWM8TslPWaAcQNIwmGioUG/Gy7zOznI6Zyrd SL2M7uRRtkD7Kxj+AdzbTv5dUIwegP1ocujseWL7kUl4Ky50ErZ1fb+kHaq54NzhMprg W6foMryZgB6iVxscPGGM9FStzaOCommXhJ47OtIvZ850QqZbRpn0/iRaxukelhA8hB9F Ku/peF/Jkzub+WF2wfw4dlwUjo9Uj4JpyBXMqyi9IhWVrhm1KjU5ZJ452JhRcB4ePynB +FD9Nyps+jMg0UmBPylmDr0KQS3wlQP3t5L3QVv40MAOYBPFgbqBRNby1dA6i6P55SRC jobA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=JYYDgtTjpdJQWbBa/dr8LzdA49eSHC9v6AH4GoU5QDU=; fh=64diDZK/HU6pJu1RDUkzqwzWKLwVAQoQ0KAU5RMiRPo=; b=NdXlrkfZmBfVgpEOyDYL80MtRCsVWtyJ0+EK8B2sK0w1c7kq9EqvOIGomBSbw8WLN4 dj9lgnydg5ltSLuxXKvHbeiRLfSrN0ErTgMngcIYgcRh3SnUqtN7IMwZZ0IjmYA6S86C gIhgONKgKdRuEoHKv8X77ofv9pgpdRKHuwJbTKstwbkKI81jn+FnyzqkyENoAoumM9ge i4sxsqwMVYrC9LYNwhAOCxzC8sFK2rr/e5aFJ6EMs9iZrPjKrDPHkmbmEfyd3eczjlor nh4CMQA1/6xyZd8MLyP4XapsFHl1ahXX27gAthY/+KV8GUTPu3F7OgLsIeyGxjWjhwA9 fuQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NfgFH684; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-206542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c68bd1c5bsi101598a12.226.2024.06.07.10.27.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 10:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NfgFH684; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-206542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8C8371F236D1 for ; Fri, 7 Jun 2024 17:27:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DA3419AD95; Fri, 7 Jun 2024 17:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NfgFH684" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 0135719CCF3 for ; Fri, 7 Jun 2024 17:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717781180; cv=none; b=DHSjIi0hIi0tbqqv2bxo9jC5I2tTgsLF0dJAdVujh6XktDhmbYMAAd232hTZSdx3Xaanq2vx2MqmeDm94t7fhwJaTXjb5jR0p4dkzHJdIuH9rtK/hfj/sOUyFBYn8oZpUsWEThVTQqKjk1FGGznkyTs07qIGlq0e2MWnUaFSYWs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717781180; c=relaxed/simple; bh=MTqQFmVrRdyG7Np823VTm6J+yyKDKmP35dXc0YupBSg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ufld0mfeEdR/SbK6ej65QbHlqiujA7v17epTb4uWLWFjQLX09b55rF56cf0r7zGqvihV9xNdvslg3z+lhWLogJ9KTI7dT/D/NbAdtvILoZjmgAJSs2VbhBQLrWlEP4AIVvZqpwQN5uBtmsvL1hN0IKeNuG8QLTBCjH7m3Zsqne4= 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=NfgFH684; arc=none smtp.client-ip=209.85.219.201 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 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfa5743655eso4149460276.1 for ; Fri, 07 Jun 2024 10:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717781178; x=1718385978; 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=JYYDgtTjpdJQWbBa/dr8LzdA49eSHC9v6AH4GoU5QDU=; b=NfgFH684x+eCraapvFW3iwc8lOixsi02uCsT6l8EqJZNU1m6F4MlL3fwgRj3qOFeJz dHAZes6k9qIVZdwZwJSnYgw1PWU0Ako5Kcnxmeem31GfXrs2toI7SDEcgr53vbAKI8ro 74y3gkhj8GaauC2PVISa7rr1BK8SphEcjBMZxtx9WIyI0H+l5xFBFLFkdZHxz2pz0uZv lsZXwUPexlp1/JYHokLgtBKOsO5urh3N/0E0nb7jYO6TNV3qH7RV1UD9i6Lu5vUEm2Dr B/C51Q3cvTREmPm1hgLUNKMe4Whv0fRpnfU8wCeetSy+gxt5uiADnP7h1dG5x4uLC6KX eXAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717781178; x=1718385978; 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=JYYDgtTjpdJQWbBa/dr8LzdA49eSHC9v6AH4GoU5QDU=; b=QqVjLVJvjLYzjfOTtcAYwqFHXqACieX3P6ZJO1iL239om7FkaGGRe09pnxeuBHZw0k xZT23y/lwB1mH6AQDDtdDGE6KtDhZiE7x3WWtLpJU02VM8TQEyORAMUKmjvXtkC7HBdD +Om23cAwasRDbQsVNK0wkBgFcVR0MF8HvSHwAvGwlw1Rzp52veEafRRJuiThTEqktCOC SCUJTybeXOCYrRM2eZfJgQoL1P7bzCDdEv76fV3Tt1bWPR3+d4Jan+anL2sc7JSNFPgE njxthxVahIG1B1FtskJjARWj/KfnQdnfONjsP7xHLwuRRKUmU4xYCS3Mkv9BbIvnP0ez U26w== X-Forwarded-Encrypted: i=1; AJvYcCVSStDNX2yJUrHAgPYu9u5pU2GI9aGQlM+dQnSA9Qz/cG4tuAEzlgbdrPF90mKTYZ18UQp564TYFNIl7VF9jqwoyIIB1at7WaIEhS+2 X-Gm-Message-State: AOJu0YwhTqKBI1USgJtNap+j9N9uI77Rl5/QwbGIPhnNzRRHncKt+I+H l5kNcgFnimLDoB8ClAyQv+DLeIW5/Qqs+U2bc1mYuOv+XLuzWlWBJqX5axR3gc4j+/FD9jGN9Zv XmQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1007:b0:dfa:7282:d6d4 with SMTP id 3f1490d57ef6-dfaf64efa7dmr799974276.6.1717781177998; Fri, 07 Jun 2024 10:26:17 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 7 Jun 2024 10:26:06 -0700 In-Reply-To: <20240607172609.3205077-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: <20240607172609.3205077-1-seanjc@google.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240607172609.3205077-4-seanjc@google.com> Subject: [PATCH 3/6] KVM: VMX: Split out the non-virtualization part of vmx_interrupt_blocked() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky , Jim Mattson Content-Type: text/plain; charset="UTF-8" Move the non-VMX chunk of the "interrupt blocked" checks to a separate helper so that KVM can reuse the code to detect if interrupts are blocked for L2, e.g. to determine if a virtual interrupt _for L2_ is a valid wake event. If L1 disables HLT-exiting for L2, nested APICv is enabled, and L2 HLTs, then L2 virtual interrupts are valid wake events, but if and only if interrupts are unblocked for L2. Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 13 +++++++++---- arch/x86/kvm/vmx/vmx.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0e3aaf520db2..d8d9e1f6c340 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5050,16 +5050,21 @@ int vmx_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection) return !vmx_nmi_blocked(vcpu); } -bool vmx_interrupt_blocked(struct kvm_vcpu *vcpu) +bool __vmx_interrupt_blocked(struct kvm_vcpu *vcpu) { - if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) - return false; - return !(vmx_get_rflags(vcpu) & X86_EFLAGS_IF) || (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS)); } +bool vmx_interrupt_blocked(struct kvm_vcpu *vcpu) +{ + if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) + return false; + + return __vmx_interrupt_blocked(vcpu); +} + int vmx_interrupt_allowed(struct kvm_vcpu *vcpu, bool for_injection) { if (to_vmx(vcpu)->nested.nested_run_pending) diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 08d7d67fe760..42498fa63abb 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -406,6 +406,7 @@ u64 construct_eptp(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); bool vmx_guest_inject_ac(struct kvm_vcpu *vcpu); void vmx_update_exception_bitmap(struct kvm_vcpu *vcpu); bool vmx_nmi_blocked(struct kvm_vcpu *vcpu); +bool __vmx_interrupt_blocked(struct kvm_vcpu *vcpu); bool vmx_interrupt_blocked(struct kvm_vcpu *vcpu); bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu); void vmx_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked); -- 2.45.2.505.gda0bf45e8d-goog