From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 72490576EDC for ; Wed, 30 Sep 2026 17:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789884; cv=none; b=WSMUnohoIVLl8hQSynbyhOfgHG/jbcNJyZLo7r4m2YXXeFSTkLzqfr3TnYr8ELACVfdyecmsbaALdcdREcjjUhHh7b4OPnY74UULcj94vLToDn84O1g5PSNVIk6XaENs0qUZ1xNmkqZFTQfu+mc2pHIhna3Zrd/PzTM0SfZegU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789884; c=relaxed/simple; bh=g2BA+vl0utX3S9H1OAahngfqYLulsVSCmy7FzWN9LWQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=N9jj7IlgAp9KOF+WGkdbiuZLBiu0PA4masPKDdnwcRO+DuJzp0zMk6kqfo1XXo8JA3b98poCjdknY17Yp1Irb9jrwNwgrMXcb/Xuy3T7VO/XYTHRL5t4O6MpTh96K5BUwDupZgs3NjVdR4bGpIk1gVvuzeAbp+9aW+OTgwNr6sI= 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=qgsE0k+0; arc=none smtp.client-ip=209.85.214.198 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="qgsE0k+0" Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2e2e0bc619fso9240825ad.0 for ; Wed, 30 Sep 2026 10:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790789883; x=1791394683; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=+KSR5jfW+XsgFGPTweoWflcNEAQOrH3D7IR4fXAZB1w=; b=qgsE0k+0TNtvn2ryiN3nxaWsnGWFg/3HO7iawAj3Nbt6iICTC7JO+KgWgI0PA+/qb5 R9ZPjvCTqorG/suTbcFNGyPVH9I9vBz6yXgD7QVwDCmNBqgIQLQLgaPipIHkG73kvG6o jhxa+M4yFp/hx4MWu2xcX8W4QJGxFailsnFPbNidu9x8WCqK7UqG6AjkHWZFgz5Km+TH qYtX24Jy9N+8Sp/GEW0YaiDiiuZD6RNa22t3gOYVLCmm9LBcJlm8OoT2upEGAALonduY SGyUjuZAN2nMf+qDZ4jQOwoZ/MXC1wFZpYqsfPnlQ6Q6bB7uwpE1pHK+8qPvU0Oll1Nd OyOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790789883; x=1791394683; h=content-type: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:content-type; bh=+KSR5jfW+XsgFGPTweoWflcNEAQOrH3D7IR4fXAZB1w=; b=Ydx0Sd+9ROcoKw5JcyAokpn1NOE4Jj3eV7f3qr/i7JsyW3DGmwdU009iFweeHl9beQ a9qY9JPT86qf3M7hoFVR4OFTf8mjUJU0bACq8IFjQIjCXG+B5OklBZ7k/oT/0YCjKqJn fN+HqLHcecejYBBKtROglmb7ieTNIFGt7gyl+VaDQ3DNQSrAgxSxuCVcw9t4Y1/JXk39 mhi0V+rO4uIm1b28D3JVRH8QpKHfyAhS/4syTbLhqSfXLULbEK7eBshRxbo7VFhiULnt MgcUi97377Wdmf5sFaK1j68v5BBqtSmpXc4od0XwQc9kTUrK9xxIl9TidURyQFIo+1Bt Tbig== X-Forwarded-Encrypted: i=1; AKwUvBwxEg+Q+8oPD4HVthZnqrdHcfok+Dfj4lMJ9zeyDcXlYIHWC++4Rc1j8CPdP93Us6kX1fe+8r3neKUqQu4=@vger.kernel.org X-Gm-Message-State: AFq9FYKuRGdAiPybqeofFTo7AZYoFhhCDJTbjoq2+wYxh0uAxsrh/kSX erlDTrrTkJwXh5myfvgIUKh0r2MPYuAwa2FMKi52wrn3U9DAA73Lj8Ciyx+dI7kcZ+3RfTGx8jp x6eOEiQ== X-Received: from plda10.prod.google.com ([2002:a17:902:ee8a:b0:2e2:cbb6:3b7d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:cf0f:b0:2dd:c100:424f with SMTP id d9443c01a7336-2e2e4ba6c68mr15266605ad.51.1790789882426; Wed, 30 Sep 2026 10:38:02 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 30 Sep 2026 10:36:33 -0700 In-Reply-To: <20260930173635.3362655-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: <20260930173635.3362655-1-seanjc@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20260930173635.3362655-20-seanjc@google.com> Subject: [PATCH v3 19/21] KVM: selftests: Randomize L2's TSC offset in the nested TSC scaling test From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Amirmohammad Eftekhar , Sashiko Bot Content-Type: text/plain; charset="UTF-8" Randomize L2's TSC offset in the nested TSC scaling test, not because it's all that interesting, but because hardcoding a copmletely arbitrary value is all kinds of silly. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86/nested_tsc_scaling_test.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c index 571fc214c925..be6246c20d7b 100644 --- a/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c +++ b/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c @@ -13,10 +13,9 @@ #include "svm_util.h" #include "kselftest.h" -/* L2's TSC multiplier, relative to L1. */ +/* L2's TSC multiplier and offset, relative to L1. */ static u64 l2_multiplier; - -#define TSC_OFFSET_L2 ((u64)-33125236320908) +static u64 l2_offset; enum { USLEEP, UCHECK_L1, UCHECK_L2 }; #define GUEST_SLEEP(sec) ucall(UCALL_SYNC, 2, USLEEP, sec) @@ -75,7 +74,7 @@ static void l1_svm_code(struct svm_test_data *svm) guest_check_tsc_freq(UCHECK_L1); generic_svm_setup(svm, l2_guest_code); - svm->vmcb->control.tsc_offset = TSC_OFFSET_L2; + svm->vmcb->control.tsc_offset = l2_offset; /* enable TSC scaling for L2 */ wrmsr(MSR_AMD64_TSC_RATIO, l2_multiplier); @@ -112,7 +111,7 @@ static void l1_vmx_code(struct vmx_pages *vmx_pages) control |= SECONDARY_EXEC_TSC_SCALING; vmwrite(SECONDARY_VM_EXEC_CONTROL, control); - vmwrite(TSC_OFFSET, TSC_OFFSET_L2); + vmwrite(TSC_OFFSET, l2_offset); vmwrite(TSC_MULTIPLIER, l2_multiplier); /* launch L2 */ @@ -145,6 +144,9 @@ static void test_tsc_scaling(u64 l0_tsc_freq, u64 l1_tsc_freq, u64 l2_tsc_freq, vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); + l2_offset = kvm_random_u64(&kvm_rng); + sync_global_to_guest(vm, l2_offset); + l2_multiplier = __l2_multiplier; sync_global_to_guest(vm, l2_multiplier); -- 2.56.0.rc1.315.gc6ed9934b7-goog