From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 7D8E341B360 for ; Mon, 2 Mar 2026 15:52:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772466725; cv=none; b=JdhJSDkopKJDVd7lFItEVOh+l7AJU6ALQ25gMOUDgAVw/h4zChWoSCV5ajRzMtU8UWoWCAamQGUEkmNwsOMBtGVeLbf92AjWB9Hg33kTpfgJJ5kcagD8yAfAMK8bWuYNKF5PAT8puaowceVItQVJCIfdWyqPObxYMFtvKzxPmSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772466725; c=relaxed/simple; bh=B+o1rsb8OmzJfPsA0gPC6Soareqf1xfasJ2vFgutzvU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mx6p7exoGgv1RF3dj+cVBBKsSRBCKY7iH2QCkuw+PYmGFy9IVVb3LxsAw0l73ox5twUsbVxJ3GLrcXkC8eh7lBl+ucn0EIDew16fmPL0JJcK4267naHfJ6ihnagZl55ua2T5IgyzsJ3cNXOXT31nnzuaAOaJ5f4qz5jZp2Ki1YI= 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=JiB3Loky; arc=none smtp.client-ip=209.85.216.74 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="JiB3Loky" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-354490889b6so17267506a91.3 for ; Mon, 02 Mar 2026 07:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772466722; x=1773071522; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RyUPIfgfZZduoActvTOHlc6gVP0traggxHBpX3oyJGg=; b=JiB3Loky2/vtrfS2kXtT+xEucbyUyOu0Nr8OwRU6mqMtz5pjmKkTqFk/W7Y7xOFKAE 3rRMfNkD8zgpwyqSWKffEoqg7CjNALpM9MuYCffTI+I/6/C2iXzI9Yn2bD32PjJnyfe9 fS1YV7CFKWBgNPyooUmaMSxMaiKl0p2ITPHbQSKaOY7xHL6QBP03UX4r4nheh+2Rddlz GpcDxtZm6EZn07QxiewcWGJ6hqytZKC2bMW4m0Q1oxWmvqI2MSNLTHcw8o8AJGrooiIX ktazh8MpKkxSfiEYWy6AE4wXe+5aY3awI5c5Eupa2iFXm4ZReu4kzJeVdYn/YEb59iL+ 5FfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772466722; x=1773071522; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RyUPIfgfZZduoActvTOHlc6gVP0traggxHBpX3oyJGg=; b=gkdAMhugHMTY4TqmW+RJJ4DOGTTxQjj0WT/Dkkby2VUx+THLAZWHL+UDcJZaxJJOOF 64RloGHb/TlyAM5bCdUF5GwuoeXCSS70RzuMu0fUy1n1tlqJBx+pYSNppxHnbAaI+W7f MLC0aBstNaK4z5s0tWh2FqBZCcCKGpU4joQEfqXR+ZgEhvGYhkAR2CKfVA7RAjSBj1H2 P9eIgCeYhVRK+Z+BJizE6n1kC+W7Ac24Pc0IpGno9TMtz5fY6NTWqHuWf/Y5zB+5UxGS g6OFMfueS5pAUZwEQDbxzYkb5VDKb5cctSLOjY/srh4LVWYpKDHGwpjnont9z4Hxygnx DlUA== X-Forwarded-Encrypted: i=1; AJvYcCWc5jDj2nd724ZV1MocP7s4RNZ7bvCC86MlcHnsAB1wLEL9J+/BqSy/tHM/5gI5axM7q3SPyMF4I/5rGNE=@vger.kernel.org X-Gm-Message-State: AOJu0YyMKfmMK8FEVdNe/9nn9QVXED4Th9zGBHnPLVBMvIoco/Z8niHs 6XXmVSWAhPpP9lV8m96Xr1M6fYFdk0DcXFgQbRcodECAvPuO3ldiCoTR6P5bt0X+Mz9e1oLp5iZ gXxuR9A== X-Received: from pjbch12.prod.google.com ([2002:a17:90a:f40c:b0:359:7dba:bdec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:f950:b0:349:9d63:8511 with SMTP id 98e67ed59e1d1-35965cc5566mr9935398a91.25.1772466721474; Mon, 02 Mar 2026 07:52:01 -0800 (PST) Date: Mon, 2 Mar 2026 07:51:59 -0800 In-Reply-To: <20260302154249.784529-1-yosry@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260302154249.784529-1-yosry@kernel.org> Message-ID: Subject: Re: [PATCH] KVM: x86: Drop redundant call to kvm_deliver_exception_payload() From: Sean Christopherson To: Yosry Ahmed Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Mon, Mar 02, 2026, Yosry Ahmed wrote: > In kvm_check_and_inject_events(), kvm_deliver_exception_payload() is > called for pending #DB exceptions. However, shortly after, the > per-vendor inject_exception callbacks are made. Both > vmx_inject_exception() and svm_inject_exception() unconditionally call > kvm_deliver_exception_payload(), so the call in > kvm_check_and_inject_events() is redundant. > > Note that the extra call for pending #DB exceptions is harmless, as > kvm_deliver_exception_payload() clears exception.has_payload after the > first call. > > The call in kvm_check_and_inject_events() was added in commit > f10c729ff965 ("kvm: vmx: Defer setting of DR6 until #DB delivery"). At > that point, the call was likely needed because svm_queue_exception() > checked whether an exception for L2 is intercepted by L1 before calling > kvm_deliver_exception_payload(), as SVM did not have a > check_nested_events callback. Since DR6 is updated before the #DB > intercept in SVM (unlike VMX), it was necessary to deliver the DR6 > payload before calling svm_queue_exception(). > > After that, commit 7c86663b68ba ("KVM: nSVM: inject exceptions via > svm_check_nested_events") added a check_nested_events callback for SVM, > which checked for L1 intercepts for L2's exceptions, and delivered the > the payload appropriately before the intercept. At that point, > svm_queue_exception() started calling kvm_deliver_exception_payload() > unconditionally, and the call to kvm_deliver_exception_payload() from > its caller became redundant. Nice! I vaguely remember staring at this code when working on 5623f751bd9c ("KVM: x86: Treat #DBs from the emulator as fault-like (code and DR7.GD=1)"), but never pieced together that it was redundant.