From nobody Sun May 24 19:34:49 2026 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 6B7933672A9 for ; Fri, 22 May 2026 17:35:31 +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=1779471333; cv=none; b=e6xdnmdu6CXhSR25m0ySwu2OKMlw2biC86u+jm/ABDUoC9qdm7KfwvokKnD+Wfz47Jdq+kMEXGunYJLfVCXUG9hiXus3LIy0nEg93mQfP34gQQgyJWsFuuOSVkP/ECyjSi04A3hjC98WzGW4z3/e1u/kuCErz2N3CumjL+g7HJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779471333; c=relaxed/simple; bh=ZWyfUAbg3NJNSjuuvqn9PMvk+OPEkmwTNwodEh8+pj0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ob18dZwIIJNNN18TBfxdUdKfKvCVYZxTKtFKVI2TRFVnK8yIeFKDNLz4V5BCMDMBMXyvH4z6bG76QYD5ARvuApgo8xgTEW89qElS8qQDF5FRa3FdH4WWmUCPxS89UjbsMwYoJ0Gn65V4ccsdtAy+6dgesp2vKoVyjQ9Di7ivxNw= 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=wml1LSb5; 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="wml1LSb5" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82f6e6a3a76so9582426b3a.0 for ; Fri, 22 May 2026 10:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779471331; x=1780076131; 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=zfgSaM1zsajAFbytYQkOZfo0cdlpb3GjOd+8W7CqHNI=; b=wml1LSb5qjFtTmHhdxIxJcJK9rOTOMaoMyy/q5EZX/sqXUVA+vTgs17XlsUHWukrtD TstuXcCJSB8YUOZyxhKuLQTvVVrQJbCeNvWfmCKTEuX423+thOYMZeu2J+f5lLvKtyfo 2EnXS24YbIqJ0Ap/7OLtnxo0mwmIMaSwCe1nNH4lNPBRP31dRIk0gXdq53Y1ATmB73Pl Fzt97QyO2W/AbMcsu6xZaJ9L6qcjkokD9pa5tMUBJPmyfx1DIZyK3Lw8W1la6IYZi5r5 /WTwwYzYTTvynpymoGqMWXvBZxCYFWfJGQubUHm3iZYmx37hfgQ+a3Fmvoqn4T4N6eR7 FAbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779471331; x=1780076131; 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=zfgSaM1zsajAFbytYQkOZfo0cdlpb3GjOd+8W7CqHNI=; b=dgQBYN3Sv8JowKFJU0sEaPEEUJ/Nk3As6rcvoLkN6ck7e/KLUWyuqYisqlAsHuv7uH mcT04XgiL/TtP3Ai5EkntkpVGUeeF1EBINa5hv8K9MTMoN5fDMEa9eC/5dIoRJDiCIOt MvKs/jkyH2/uMhxqJAfCcvkC2C21HbTS3PRSe+PGr75F/0prjT8XQr5laCZgCFFQ0cbU SRq2nNJir0dVkRmMFcOmBXof7jL3FmTBJWDbLyomE7wspTGog4BFRqRxSWxG6S8AsIGj ZE/75i+raWEBmpPaGYzibwYEfKnaNjZtZgIbjMALwsMpdwnZKO9VvyZ9RNBVD0qBNdD9 u6Fg== X-Forwarded-Encrypted: i=1; AFNElJ8cNIh5JMAfd78Vv2G8op5o4dLQWdmnQ6MFj6o19xn7KefdIAWcir46QRL9BQCrEKu7UTArgCVD1PfBUZE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4c6UcqRzcqVIFye0375pBluKy2VM24DmjhTWq4Zaq9U0oMYMW Ydrwp1L1IPgVwUEvXcQKDSp1o510pcoGsJbvYlncaijJ2BwYrBlVevNwCB14Bqv74CQuYI7SrNV 83UMpHw== X-Received: from pfff17.prod.google.com ([2002:a05:6a00:bd11:b0:82f:22c2:7af1]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1888:b0:82a:7aa3:a2fb with SMTP id d2e1a72fcca58-8415f63c1f2mr5112903b3a.37.1779471330435; Fri, 22 May 2026 10:35:30 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 22 May 2026 10:35:25 -0700 In-Reply-To: <20260522173526.3539407-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: <20260522173526.3539407-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.794.g4f17f83d09-goog Message-ID: <20260522173526.3539407-2-seanjc@google.com> Subject: [PATCH 1/2] KVM: x86: Return the VM's configured APIC bus frequency when queried From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Woodhouse Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When KVM_CAP_X86_APIC_BUS_CYCLES_NS is queried on a specific VM, return the VM's configured APIC bus frequency, not KVM's default. Aside from the fact that returning the default frequency is blatantly wrong if userspace has changed the frequency, returning the configured frequency means userspace can blindly trust the result, e.g. when filling PV CPUID information that communicates the APIC bus frequency to the guest. Fixes: 6fef518594bc ("KVM: x86: Add a capability to configure bus frequency= for APIC timer") Reported-by: David Woodhouse Closes: https://lore.kernel.org/all/ab84153e33fbe7c25667f595c56b310d4d5a93e= f.camel@infradead.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cecb2f84e5e0..7c5d99283be3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4885,7 +4885,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, lon= g ext) r =3D tdp_enabled; break; case KVM_CAP_X86_APIC_BUS_CYCLES_NS: - r =3D APIC_BUS_CYCLE_NS_DEFAULT; + r =3D kvm ? kvm->arch.apic_bus_cycle_ns : APIC_BUS_CYCLE_NS_DEFAULT; break; case KVM_CAP_EXIT_HYPERCALL: r =3D KVM_EXIT_HYPERCALL_VALID_MASK; --=20 2.54.0.794.g4f17f83d09-goog From nobody Sun May 24 19:34:49 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 9123736A366 for ; Fri, 22 May 2026 17:35:32 +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=1779471334; cv=none; b=jWFI1/zg/FhKrO1dosH8WFChUkZsT+0fP7Q3ETkDEGtPl2jfYFdy25KKSvz9XR1H7DUxhdspDOw3yAMJdu0fgys92acdaiN5tYzBgGX9gak1tIkOGBWe+rh/j327cP+SWANBhAy4uH6yWIK6q1lm9A+81CLqW71zOrsrsfl2sis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779471334; c=relaxed/simple; bh=9NVfYGCj0T9OiqBOL9PpYdCXo7lizBbmhOXkRI3cs0g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bn/C2Q5RaFbJl4YNMv7LKBVI/U3CO3QKbsHBhXTT4E7xeOXYno9eo3cWd3NyWVZ/z4EBcALu/DQ6juIRzTofCna4OSP97uD/vteAvUK2cywUd+SeGfPD440sJyrCfHW4eyxF1Ww3r3qct0SEuwQPbJfW/6HnWGp3Cj4kb75q8Ls= 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=bKXrDbJa; 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="bKXrDbJa" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2bd6aeb3637so183895425ad.2 for ; Fri, 22 May 2026 10:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779471332; x=1780076132; 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=bibhEOGKFiboYdCJy5SvZAlGLGr8/ODY4Bmd6evDc4E=; b=bKXrDbJaWdD4U79DQAiry2gdwmoptvc31EJTK4hLnRAS7sIUw8+BNV0u5yeAg8gele 9zIjZSaAhBuYMEQLLPcyfHuCUndK2E5zL3M86aCqZ7w4gq0JEfDntpS8WWWdqmWfdtdc EWUy6lTcRJ/xMPHUNYS0AZpbSVKev8yq8tebUaxlUw8jPRAXOLejMqb1Tcvdd2rdrmhM f7EF+H7WAGh+enI1FFwbgsmO2UtL/GfJ2Ks0Og4lAWUmtrONxdwkKrVNeyO1HPFvYOnM aXSiUfQK7SGkAb5Z+xEE+ACW/BrekjU07L+a2d2ekmiLUZLr4TwRWyNeh9T2F158kQ6Y DomA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779471332; x=1780076132; 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=bibhEOGKFiboYdCJy5SvZAlGLGr8/ODY4Bmd6evDc4E=; b=HBDULiFv8SjNfAzAgqWr4Ckj4NFSqL0aO3weaaT4b+oGl7pXIObUFoMOtZx+t3Ix97 MM+bxvuEuPuDEl8Zz+S6HYJgiUURaQV/eYiaHvRzCUSQZxdsDmKAaII8DtvafPSRHwv4 hdSSe3n7f8l0MVCCKxmqPTrlSEWwXe2wnHHy9N9Q2uTiG9XwLn4TPySmhMRGtJ/gvjv8 Qk+MKGr5TN6aUpvo6P0d+EIsqrbbu4QQb6e7N0Eyh0Ze/pckQKoaRzL1CcVjMCWWLupF kgCgyU9Pq25mSb6Sb3B0CjblSA2roCNe44+Pdda0rxgLAHoIXOOtnz2ZEFZumGvZtIyb jJxA== X-Forwarded-Encrypted: i=1; AFNElJ+278+JlgM2dQ13apk8k9P28s1LveKPnU4wPwePlgUiyp2zy9HRERDp5YfNGcQF1cdgsMgp05QTcYNgovw=@vger.kernel.org X-Gm-Message-State: AOJu0YxJbdxJwpy+4FV67nvmHDhty0vVkp/EQawfIteD5wxPz4YUZ73U RIEaR4bWrUFEz3Qw79rhq78qYYNYp3vX0St8xlzhuu7R8B/R8jk7bk+pafAfuoFEqsvaZXP+Kvq mvUo4oA== X-Received: from plbo8.prod.google.com ([2002:a17:903:c48:b0:2bd:9a1:9a05]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ebd2:b0:2bc:b141:8551 with SMTP id d9443c01a7336-2beb06f81f3mr50866535ad.19.1779471331628; Fri, 22 May 2026 10:35:31 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 22 May 2026 10:35:26 -0700 In-Reply-To: <20260522173526.3539407-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: <20260522173526.3539407-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.794.g4f17f83d09-goog Message-ID: <20260522173526.3539407-3-seanjc@google.com> Subject: [PATCH 2/2] KVM: selftests: Verify that KVM returns the configured APIC bus frequency From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Woodhouse Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add checks in the APIC bus clock test to verify that querying KVM_CAP_X86_APIC_BUS_CYCLES_NS on the VM after changing the frequency returns the VM's actual APIC bus frequency, not KVM's default. For giggles, verify that KVM still returns its default frequency for the system-scoped check. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86/apic_bus_clock_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/apic_bus_clock_test.c b/tools/= testing/selftests/kvm/x86/apic_bus_clock_test.c index 404f0028e110..0c84c27ea584 100644 --- a/tools/testing/selftests/kvm/x86/apic_bus_clock_test.c +++ b/tools/testing/selftests/kvm/x86/apic_bus_clock_test.c @@ -137,6 +137,10 @@ static void run_apic_bus_clock_test(u64 apic_hz, u64 d= elay_ms, vm_enable_cap(vm, KVM_CAP_X86_APIC_BUS_CYCLES_NS, NSEC_PER_SEC / apic_hz); =20 + TEST_ASSERT_EQ(kvm_check_cap(KVM_CAP_X86_APIC_BUS_CYCLES_NS), 1); + TEST_ASSERT_EQ(vm_check_cap(vm, KVM_CAP_X86_APIC_BUS_CYCLES_NS), + NSEC_PER_SEC / apic_hz); + vcpu =3D vm_vcpu_add(vm, 0, apic_guest_code); vcpu_args_set(vcpu, 2, apic_hz, delay_ms); =20 --=20 2.54.0.794.g4f17f83d09-goog