From nobody Mon Feb 9 08:56:10 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 E75A43271FB for ; Thu, 13 Nov 2025 22:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763074597; cv=none; b=MRCk+GtFo014f+7BTxED7/y/GAlrKVDhnGXBUfxiIiubN5LtRX9wfKOdcABQhp+2Zsk2na0++mn3S42QWCU4IioLAXWnhmlYKV2+YsyqLD0ToMElVLTbQiPM2/abGYKlucngndJDZOTAiylH+B4MBb/+/WG1IJgkyUn+WJtBDD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763074597; c=relaxed/simple; bh=3ZKH73v//RDZ3fRn2i/PSc16YVjKg39gkH1Xa11RzC8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WznjAkuO0pTTWOt2f3uGRl+M+UGuNtXcGg1ZDlDbwv+snBU8JaTI+0XlB1jYGOvd/aEw3xEIdcQrYO0+iXkpFBBIi43MWzQ47ZREmCf58hM8XnMSW81bxTaf+Z0FIgcxuEbU2xpf9kKcRkUWMvAf4PDmI5JiwoPqJffrFT1iFac= 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=bkrMYktg; arc=none smtp.client-ip=209.85.214.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bkrMYktg" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-29848363458so33092855ad.2 for ; Thu, 13 Nov 2025 14:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763074595; x=1763679395; 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=44sHkalx4c+buJJlySyLatvfmOk9JIz0iW1u4PfgOGQ=; b=bkrMYktguQLziZS8oZIiD2611kMJzuTmPUNSEk0JmR/GZ7jjvY4u9XSVlBNSVZxvTX IUTqURSqNPqBHZBKwH13iGTtOpIdl19ga9LzO2r857mHVF6c+ipQjC0StFkrQ6EKVuuw scPc0ewPzJywxNGeIQOLfpMuiTe+w4AbjU2ykKqAbbNURvMotvvATK6Q3kieGpWjjBDB PX5Rdx4khzyVx6rbLn+MDrolQ8UIE8Gbs2elfwThDqsE+QKz7Ni7hS4VR1vHF1jUw6By PUTDNpELRCKJSjNNpzhFYT+quA7/Qb+d+bi0ZE2IlEo2Iby+bXSx2l/uitKkpj0jtNOu GroA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763074595; x=1763679395; 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=44sHkalx4c+buJJlySyLatvfmOk9JIz0iW1u4PfgOGQ=; b=TnkCtiUXzgaZgdhzU6NSX5hAa4NiY8PvB4W3+5C7BzxGAUJ0j4QbiqsvS/2wWS4PMY I44ZAyysegr7H2yS0+0qYsdrcBtT7J4WtTHWsSzpG9zmaUSYsQXswV/w8Trgfg4iHWoT ap3XN9FgYYvIdWLnqvrQHu51MPtf2r2/ZqG57BlUylx+uD7iDqJn8QIZRbgMai+AiBdJ 5TqpoZq4HHkQSLdp/nqn0R6xY0QkAuKE/mfEhrQbCi50UKwjmA87+W8DAZMqmAcINHkr dRTu4TZRkpqhOuukSNMvm+57Q9wtZTULZ0H3MZkC9C+Aqbtm/auYwv9pYyNDCpsoQDy8 YbJA== X-Forwarded-Encrypted: i=1; AJvYcCW6aSaNfAEfIoY2bQMcyJUYu3cFU+m1m3IM0bsEfJff+JJTh4lBVofHdarUN3k081kihxHHNEfTiikDvIM=@vger.kernel.org X-Gm-Message-State: AOJu0YwWX9L3hrYEtge0YVMCoXS8VmKZR5MgNpXyyIDkw7O6KS3Xy3uN O12Q7sezqEEVMa7+ySO6lTeglSdV5iAVpKwyhnL4rk//Q4MK0H1x8KcJrgaHqYCa6lIPGUIXw24 NErYRZg== X-Google-Smtp-Source: AGHT+IGqAKWqFoUFyf2m0vap9g7gkzKL0KXcEIHMGW0cbM1JyDMMiT3yzbCUGWEfKZvzY/3IrvdaWAPUMuQ= X-Received: from pldr17.prod.google.com ([2002:a17:903:4111:b0:27e:dc53:d244]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f790:b0:297:f8dd:4d8e with SMTP id d9443c01a7336-2986a741b93mr7487325ad.30.1763074595173; Thu, 13 Nov 2025 14:56:35 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 13 Nov 2025 14:56:16 -0800 In-Reply-To: <20251113225621.1688428-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: <20251113225621.1688428-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251113225621.1688428-5-seanjc@google.com> Subject: [PATCH 4/9] KVM: SVM: Open code handling of unexpected exits in svm_invoke_exit_handler() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui Cc: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , Yosry Ahmed Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fold svm_check_exit_valid() and svm_handle_invalid_exit() into their sole caller, svm_invoke_exit_handler(), as having tiny single-use helpers makes the code unncessarily difficult to follow. This will also allow for additional cleanups in svm_invoke_exit_handler(). No functional change intended. Suggested-by: Yosry Ahmed Signed-off-by: Sean Christopherson Reviewed-by: Yosry Ahmed --- arch/x86/kvm/svm/svm.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 52b759408853..638a67ef0c37 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3433,23 +3433,13 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) sev_free_decrypted_vmsa(vcpu, save); } =20 -static bool svm_check_exit_valid(u64 exit_code) -{ - return (exit_code < ARRAY_SIZE(svm_exit_handlers) && - svm_exit_handlers[exit_code]); -} - -static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code) -{ - dump_vmcb(vcpu); - kvm_prepare_unexpected_reason_exit(vcpu, exit_code); - return 0; -} - int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 exit_code) { - if (!svm_check_exit_valid(exit_code)) - return svm_handle_invalid_exit(vcpu, exit_code); + if (exit_code >=3D ARRAY_SIZE(svm_exit_handlers)) + goto unexpected_vmexit; + + if (!svm_exit_handlers[exit_code]) + goto unexpected_vmexit; =20 #ifdef CONFIG_MITIGATION_RETPOLINE if (exit_code =3D=3D SVM_EXIT_MSR) @@ -3468,6 +3458,11 @@ int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u= 64 exit_code) #endif #endif return svm_exit_handlers[exit_code](vcpu); + +unexpected_vmexit: + dump_vmcb(vcpu); + kvm_prepare_unexpected_reason_exit(vcpu, exit_code); + return 0; } =20 static void svm_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, --=20 2.52.0.rc1.455.g30608eb744-goog