From patchwork Tue Jan 9 14:11:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 186408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp133882dyi; Tue, 9 Jan 2024 06:12:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE4RsE3Pjrmq4oJhy2KMZ82xtsE5XIuY/IM2QF85c6gtP7XuiTOCGUiGtgp9EBpAyMIrNR X-Received: by 2002:a05:622a:647:b0:429:7c06:ddf4 with SMTP id a7-20020a05622a064700b004297c06ddf4mr7413258qtb.25.1704809548608; Tue, 09 Jan 2024 06:12:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704809548; cv=none; d=google.com; s=arc-20160816; b=fwAaGAIsJjLjweIjqb1X8smT0th9gUmpVDf8M0RqMtGdxhalh03ydevHvfPS3/R6cX bVf++O7Dj9e7498k7g3FqrsxgOk+DhCcdisH+jJZxuJ9Z/YXxclRYMJeV08tX60Uxmcq zp2mxzFIwuQAh75u2x4HguRZOUET2G/lIRlikfa8Kh/0aHSGh2dPufrtXwqTv9dNedgj O+RKOR/wE1sTSWrUSfxNqmfFTLmgkpJk7sJKM9Sw6nsv9P+PsMieVBOUkwbgzUdoUrfy YhyXnXCBkkiNozq7q1ePohDx8wSKWrF5AQS5ofXxiLe3u3YkdWlqpHLp4gUJ6QYfMCjW ierw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=e8e5dGjcFFUnzEKI3zb4LdS0a99YnvNh3UNoPZfhRwo=; fh=56b0f9amB/d14Cru5+rTzdvRVvg1qsHx+cb1CsaZSXE=; b=0FWVXOyv0UQTssEiKfjJvdDBJlZswSVUNJU4z+KvPbQaLOadXIut54Popy+U+4WwqY 8i44ZVTTMzC+wk5Qbz6OdgPQs7/OimkN2xKJotuxAmmRPUey2wKGvD3+24c1txlym5h6 HV24RNXWav+3YOphGCcskfBOBZuQYnqcq+IOZ2v5itqWL8aWznFWdmQVjNyghqWQQXSg 7VM5JRJWZhXrifcQzO01SZCUkz8l0rPc1b+AD7StK5uFkLma41MDs2CNRmyoNVnXUOQt jTDr4NCvAqupAdvnBXJlxf/W7UVpVmSLGtqL1xRNasGTO6X2TfQdCYPe0jZkhiVXlKcr CBPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fMGogbIh; spf=pass (google.com: domain of linux-kernel+bounces-20958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20958-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t9-20020ac85889000000b00427f03fbdafsi2223654qta.712.2024.01.09.06.12.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:12:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fMGogbIh; spf=pass (google.com: domain of linux-kernel+bounces-20958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20958-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5AACF1C23D55 for ; Tue, 9 Jan 2024 14:12:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A32C73A1A9; Tue, 9 Jan 2024 14:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fMGogbIh" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 459A439AC2 for ; Tue, 9 Jan 2024 14:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704809488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e8e5dGjcFFUnzEKI3zb4LdS0a99YnvNh3UNoPZfhRwo=; b=fMGogbIh5JtADm718UnApmHCXunXDY2gPA8gJBSBvAscaUTnGF/k7jvCrUQ+eVZz8D7s1J NhZyWrpkxK0SvZHEEkSJKAhjTtqQM4dTsw+MVOmDCH/3TaXPuzEB1leaTmm+goD9pyjdTq z4qlDFoSHvcm/lTpAZyGdPa0UyQP7fI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-XKcBf3IMMg6UFizvp1kOgQ-1; Tue, 09 Jan 2024 09:11:24 -0500 X-MC-Unique: XKcBf3IMMg6UFizvp1kOgQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6CF05102F223; Tue, 9 Jan 2024 14:11:24 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8057551E3; Tue, 9 Jan 2024 14:11:23 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Oliver Upton , linux-kernel@vger.kernel.org Subject: [PATCH 1/5] KVM: selftests: Generalize check_clocksource() from kvm_clock_test Date: Tue, 9 Jan 2024 15:11:17 +0100 Message-ID: <20240109141121.1619463-2-vkuznets@redhat.com> In-Reply-To: <20240109141121.1619463-1-vkuznets@redhat.com> References: <20240109141121.1619463-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787622376939814883 X-GMAIL-MSGID: 1787622376939814883 Several existing x86 selftests need to check that the underlying system clocksource is TSC or based on TSC but every test implements its own check. As a first step towards unification, extract check_clocksource() from kvm_clock_test and split it into two functions: arch-neutral 'sys_get_cur_clocksource()' and x86-specific 'sys_clocksource_is_tsc()'. Fix a couple of pre-existing issues in kvm_clock_test: memory leakage in check_clocksource() and using TEST_ASSERT() instead of TEST_REQUIRE(). The change also makes the test fail when system clocksource can't be read from sysfs. Signed-off-by: Vitaly Kuznetsov --- .../testing/selftests/kvm/include/test_util.h | 2 + .../selftests/kvm/include/x86_64/processor.h | 2 + tools/testing/selftests/kvm/lib/test_util.c | 25 ++++++++++++ .../selftests/kvm/lib/x86_64/processor.c | 13 +++++++ .../selftests/kvm/x86_64/kvm_clock_test.c | 38 +------------------ 5 files changed, 43 insertions(+), 37 deletions(-) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 71a41fa924b7..50a5e31ba8da 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -195,4 +195,6 @@ __printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...); char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1))); +char *sys_get_cur_clocksource(void); + #endif /* SELFTEST_KVM_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index a84863503fcb..01eec72e0d3e 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1271,4 +1271,6 @@ void virt_map_level(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, #define PFERR_GUEST_PAGE_MASK BIT_ULL(PFERR_GUEST_PAGE_BIT) #define PFERR_IMPLICIT_ACCESS BIT_ULL(PFERR_IMPLICIT_ACCESS_BIT) +bool sys_clocksource_is_tsc(void); + #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 5d7f28b02d73..b8cb20cf61e9 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -392,3 +392,28 @@ char *strdup_printf(const char *fmt, ...) return str; } + +#define CLOCKSOURCE_PATH "/sys/devices/system/clocksource/clocksource0/current_clocksource" + +char *sys_get_cur_clocksource(void) +{ + char *clk_name; + struct stat st; + FILE *fp; + + fp = fopen(CLOCKSOURCE_PATH, "r"); + TEST_ASSERT(fp, "failed to open clocksource file, errno: %d", errno); + + TEST_ASSERT(!fstat(fileno(fp), &st), "failed to stat clocksource file, errno: %d", + errno); + + clk_name = malloc(st.st_size); + TEST_ASSERT(clk_name, "failed to allocate buffer to read file\n"); + + TEST_ASSERT(fgets(clk_name, st.st_size, fp), "failed to read clocksource file: %d", + ferror(fp)); + + fclose(fp); + + return clk_name; +} diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index d8288374078e..b0c64667803d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1299,3 +1299,16 @@ void kvm_selftest_arch_init(void) host_cpu_is_intel = this_cpu_is_intel(); host_cpu_is_amd = this_cpu_is_amd(); } + +bool sys_clocksource_is_tsc(void) +{ + char *clk_name = sys_get_cur_clocksource(); + bool ret = false; + + if (!strcmp(clk_name, "tsc\n")) + ret = true; + + free(clk_name); + + return ret; +} diff --git a/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c b/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c index 1778704360a6..9deee8556b5c 100644 --- a/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c +++ b/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c @@ -132,42 +132,6 @@ static void enter_guest(struct kvm_vcpu *vcpu) } } -#define CLOCKSOURCE_PATH "/sys/devices/system/clocksource/clocksource0/current_clocksource" - -static void check_clocksource(void) -{ - char *clk_name; - struct stat st; - FILE *fp; - - fp = fopen(CLOCKSOURCE_PATH, "r"); - if (!fp) { - pr_info("failed to open clocksource file: %d; assuming TSC.\n", - errno); - return; - } - - if (fstat(fileno(fp), &st)) { - pr_info("failed to stat clocksource file: %d; assuming TSC.\n", - errno); - goto out; - } - - clk_name = malloc(st.st_size); - TEST_ASSERT(clk_name, "failed to allocate buffer to read file\n"); - - if (!fgets(clk_name, st.st_size, fp)) { - pr_info("failed to read clocksource file: %d; assuming TSC.\n", - ferror(fp)); - goto out; - } - - TEST_ASSERT(!strncmp(clk_name, "tsc\n", st.st_size), - "clocksource not supported: %s", clk_name); -out: - fclose(fp); -} - int main(void) { struct kvm_vcpu *vcpu; @@ -179,7 +143,7 @@ int main(void) flags = kvm_check_cap(KVM_CAP_ADJUST_CLOCK); TEST_REQUIRE(flags & KVM_CLOCK_REALTIME); - check_clocksource(); + TEST_REQUIRE(sys_clocksource_is_tsc()); vm = vm_create_with_one_vcpu(&vcpu, guest_main); From patchwork Tue Jan 9 14:11:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 186409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp134134dyi; Tue, 9 Jan 2024 06:12:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbe3gmNn6Lq8iGOztI3gcoU6C0OpN0+pPPy6Bk8lApn1v61SyN6in6p1xzIOkAFkMzT1oT X-Received: by 2002:a17:906:945:b0:a2a:4a9e:6bfe with SMTP id j5-20020a170906094500b00a2a4a9e6bfemr601903ejd.81.1704809572723; Tue, 09 Jan 2024 06:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704809572; cv=none; d=google.com; s=arc-20160816; b=iwSnYfrY0YRPcYsw3vpU+X/oOB+N+h2GKJ6dGLLfdSAbYgcP8PPGngCr2dFMEWz/+m +tGHJhKZRBJwQwNiFKqXAjiuFCLwyJFbFoIXbaff/lXqAXajInv8pliarSgixGwmCYiK +dIrgMkdSpP+/1Yv5R0kn2yUJGjjLIAqmu37yz/5VHj0Y7i601/CSbl3zKPCgmFbl9Bp WMaV4rGWuaqfmd5vQD0al09hCASLkxEcNmJRShHVk3MrituDITt0YKxVPSF14BRG6/fv tKvotSCbUMsGTgBJQVnptlmXEwIrn9/dRaB6vf7qciEdsgD0oG4Gmt8d7Y3wuXK4ZKiq JSSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZaLjeKjKaXvkCYG3XZyStpbWPQkFTJ1s4eXSvcd81Xc=; fh=56b0f9amB/d14Cru5+rTzdvRVvg1qsHx+cb1CsaZSXE=; b=P/93rMGDsomBcnQ38frnzNGCabkiebPP2tS6r02L1a7daVW4yJqrk7Y4MFTUujDDmd 16CM7xCSRRPDAOKE+SIE1cJh4fd8AmTlm0wiMJ+h4kZEZcGxn/lLzo9VT7w9lDjuDgMy CrDXCtfW39z3UiHsToD6ywXGTQXzqA8jQzAQHIULyL72r7AxsPJn65zUXpDK0pr5Vow9 4El94uPuz82f5jcSeBynM52N71EXJclA6NlMSqRnNfzMZ6zELiRv3WPuW6XXEMwcYUeR FV/iRBfJWc4njc//Lw21TgyELUqL3XuSPMhO4H1zNwuqGPAyMaQzvep6c00ysU7Xd2x5 vv2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hpbQntHn; spf=pass (google.com: domain of linux-kernel+bounces-20959-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a26-20020a1709066d5a00b00a2ae6bc2944si776334ejt.476.2024.01.09.06.12.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:12:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20959-ouuuleilei=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=@redhat.com header.s=mimecast20190719 header.b=hpbQntHn; spf=pass (google.com: domain of linux-kernel+bounces-20959-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 52ADA1F24AA7 for ; Tue, 9 Jan 2024 14:12:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A94B3A1D7; Tue, 9 Jan 2024 14:11:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hpbQntHn" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A17239AEC for ; Tue, 9 Jan 2024 14:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704809490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZaLjeKjKaXvkCYG3XZyStpbWPQkFTJ1s4eXSvcd81Xc=; b=hpbQntHnEXYV5hdjYqIYMAhiRI6+UGgz7S3VANIIirlKpgozJjeR2avJ4rTFCIuRgLckk5 bVTUTtk0dM1+G8dFxsy1g5eg1WKd21nVs3CSI+UeYg/RzBjpepwX0LV86a6BfD580zfPPk NEnXixEbuyR4QZLU4XCRpq9P6HLK1Fk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-6aYvM4ATNmqCQSQLTwRDlg-1; Tue, 09 Jan 2024 09:11:26 -0500 X-MC-Unique: 6aYvM4ATNmqCQSQLTwRDlg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8DEA386C049; Tue, 9 Jan 2024 14:11:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id A22CE51E3; Tue, 9 Jan 2024 14:11:24 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Oliver Upton , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] KVM: selftests: Use generic sys_clocksource_is_tsc() in vmx_nested_tsc_scaling_test Date: Tue, 9 Jan 2024 15:11:18 +0100 Message-ID: <20240109141121.1619463-3-vkuznets@redhat.com> In-Reply-To: <20240109141121.1619463-1-vkuznets@redhat.com> References: <20240109141121.1619463-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787622402425946022 X-GMAIL-MSGID: 1787622402425946022 Despite its name, system_has_stable_tsc() just checks that system clocksource is 'tsc'; this can now be done with generic sys_clocksource_is_tsc(). No functional change intended. Signed-off-by: Vitaly Kuznetsov --- .../kvm/x86_64/vmx_nested_tsc_scaling_test.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c index e710b6e7fb38..93b0a850a240 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c @@ -116,23 +116,6 @@ static void l1_guest_code(struct vmx_pages *vmx_pages) GUEST_DONE(); } -static bool system_has_stable_tsc(void) -{ - bool tsc_is_stable; - FILE *fp; - char buf[4]; - - fp = fopen("/sys/devices/system/clocksource/clocksource0/current_clocksource", "r"); - if (fp == NULL) - return false; - - tsc_is_stable = fgets(buf, sizeof(buf), fp) && - !strncmp(buf, "tsc", sizeof(buf)); - - fclose(fp); - return tsc_is_stable; -} - int main(int argc, char *argv[]) { struct kvm_vcpu *vcpu; @@ -148,7 +131,7 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL)); - TEST_REQUIRE(system_has_stable_tsc()); + TEST_REQUIRE(sys_clocksource_is_tsc()); /* * We set L1's scale factor to be a random number from 2 to 10. From patchwork Tue Jan 9 14:11:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 186410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp134148dyi; Tue, 9 Jan 2024 06:12:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeH2z4X2+gEHzIO8gsNgWsin3viJodrbW+m8O/YP7Lz0bhT9pF9ynVX0qTYYpPowdQFxqf X-Received: by 2002:ac8:5cd0:0:b0:429:96e2:8790 with SMTP id s16-20020ac85cd0000000b0042996e28790mr3349191qta.89.1704809574095; Tue, 09 Jan 2024 06:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704809574; cv=none; d=google.com; s=arc-20160816; b=ivi7IAQ1r1S4NJx+M6nONUq0ehoH3p+vxSjfWjRyVwTqcnbs8oATLF8b30z81PLDMu jxBV/Yoay5eaDHOtxC19wC5hLglpaDr0OJofPeoTDCDtWPFCuhNftR6rdrybG98UGLD2 QUDf2Ue/QTnSX2yXPae7cZiIV/eX82w4q40h43wtAgmjPdwvinxx0eiGL2Zsuajr941V PwJyUoRct+2dQGYkLEW+UzECyCMxhnEE7YeG1fYxDd8SkELA4AaP/Vs/W/d/oiMvEhCT haMA9Yi/h5wa3GvhtJV0yxVjmsqAS3ttmrMlw/XNIw/pGYPPqjQHQbu/7MXL+UDgPLzt FeIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3z7Ios2RLTqNDhiGxMSBIYzmjVKHnGKYSDng29XTGO8=; fh=56b0f9amB/d14Cru5+rTzdvRVvg1qsHx+cb1CsaZSXE=; b=mIm9A6eF6dNQd2lJwspvj/S44zj4N2trw933aOWL270a64JGhLKq6zNFBbJHdJrXgz 2KGqU+II7acnEoKnDfJez0Txzbl5RBPD1+7w97sEyTpEdL/rDH8PAbEY4K3sXLw7M+ZE AwiVtQvKVRiVqWlB6nV4qbTjsMjQJzUkwg8xrKabwUYjgjIHrzHlxYECG+4B09IDuRDn NLFXH1RSeKXDRfaXKWz7WUXfxC+gdUkzQVBrE9oxKDDq9DmiZXPZ6QJiw8AYwHOj4KjO cqZpoafKzqjpYO0OL+AMRb/1byL7LIS/fEYzedzpfoHWkccsgqTSuG8m+ZxHyjhVgJQh 3XkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Bcu/2lPW"; spf=pass (google.com: domain of linux-kernel+bounces-20960-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t9-20020ac85889000000b00427f03fbdafsi2223654qta.712.2024.01.09.06.12.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:12:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20960-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Bcu/2lPW"; spf=pass (google.com: domain of linux-kernel+bounces-20960-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DE2031C242B3 for ; Tue, 9 Jan 2024 14:12:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DBB03A1DC; Tue, 9 Jan 2024 14:11:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bcu/2lPW" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6407539AF1 for ; Tue, 9 Jan 2024 14:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704809490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3z7Ios2RLTqNDhiGxMSBIYzmjVKHnGKYSDng29XTGO8=; b=Bcu/2lPWW+j+yBmjyhhmoGQ3n1bpOUE/HXdiW3pHuK0/BfwIt5SQNxBDAoAYRcGgjmoG/6 W5sRENhH8y9ubNC8/Ycliq0Z/VGU/XWKHtVxfma8txmX+UsUnk8RKKQjDwQN6bsiboerUd DlV86JtQW3ME3zQdlw76riLFkMA+oH0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-5AxgFswUMSqJXA5Cfp2EuQ-1; Tue, 09 Jan 2024 09:11:27 -0500 X-MC-Unique: 5AxgFswUMSqJXA5Cfp2EuQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF588185A781; Tue, 9 Jan 2024 14:11:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id C376A5012; Tue, 9 Jan 2024 14:11:25 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Oliver Upton , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] KVM: selftests: Run clocksource dependent tests with hyperv_clocksource_tsc_page too Date: Tue, 9 Jan 2024 15:11:19 +0100 Message-ID: <20240109141121.1619463-4-vkuznets@redhat.com> In-Reply-To: <20240109141121.1619463-1-vkuznets@redhat.com> References: <20240109141121.1619463-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787622404282447400 X-GMAIL-MSGID: 1787622404282447400 KVM's 'gtod_is_based_on_tsc()' recognizes two clocksources: 'tsc' and 'hyperv_clocksource_tsc_page' and enables kvmclock in 'masterclock' mode when either is in use. Transform 'sys_clocksource_is_tsc()' into 'sys_clocksource_is_based_on_tsc()' to support the later. This affects two tests: kvm_clock_test and vmx_nested_tsc_scaling_test, both seem to work well when system clocksource is 'hyperv_clocksource_tsc_page'. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/include/x86_64/processor.h | 2 +- tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 +++- tools/testing/selftests/kvm/x86_64/kvm_clock_test.c | 2 +- .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 01eec72e0d3e..5bca8c947c82 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1271,6 +1271,6 @@ void virt_map_level(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, #define PFERR_GUEST_PAGE_MASK BIT_ULL(PFERR_GUEST_PAGE_BIT) #define PFERR_IMPLICIT_ACCESS BIT_ULL(PFERR_IMPLICIT_ACCESS_BIT) -bool sys_clocksource_is_tsc(void); +bool sys_clocksource_is_based_on_tsc(void); #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index b0c64667803d..70969d374e5b 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1300,13 +1300,15 @@ void kvm_selftest_arch_init(void) host_cpu_is_amd = this_cpu_is_amd(); } -bool sys_clocksource_is_tsc(void) +bool sys_clocksource_is_based_on_tsc(void) { char *clk_name = sys_get_cur_clocksource(); bool ret = false; if (!strcmp(clk_name, "tsc\n")) ret = true; + else if (!strcmp(clk_name, "hyperv_clocksource_tsc_page\n")) + ret = true; free(clk_name); diff --git a/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c b/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c index 9deee8556b5c..eb1c12fb7656 100644 --- a/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c +++ b/tools/testing/selftests/kvm/x86_64/kvm_clock_test.c @@ -143,7 +143,7 @@ int main(void) flags = kvm_check_cap(KVM_CAP_ADJUST_CLOCK); TEST_REQUIRE(flags & KVM_CLOCK_REALTIME); - TEST_REQUIRE(sys_clocksource_is_tsc()); + TEST_REQUIRE(sys_clocksource_is_based_on_tsc()); vm = vm_create_with_one_vcpu(&vcpu, guest_main); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c index 93b0a850a240..1759fa5cb3f2 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL)); - TEST_REQUIRE(sys_clocksource_is_tsc()); + TEST_REQUIRE(sys_clocksource_is_based_on_tsc()); /* * We set L1's scale factor to be a random number from 2 to 10. From patchwork Tue Jan 9 14:11:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 186412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp134700dyi; Tue, 9 Jan 2024 06:13:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCLkKl+BAftkABQ7euVobaFT/fsVh31GMNJVj8pl0lQMw0kXjT0pFdkcwbreqo3MLVADpk X-Received: by 2002:a17:906:7007:b0:a28:4bf8:a16f with SMTP id n7-20020a170906700700b00a284bf8a16fmr493938ejj.136.1704809621251; Tue, 09 Jan 2024 06:13:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704809621; cv=none; d=google.com; s=arc-20160816; b=gwiVamS0sKUJUubW2JNT87hio1tmK8pKPht0dV4k5P31m+Ya5Jju4kz4SAzl17z70s N2ua+5VA8nuA27wqjmqML7h4HQecqhh7m2O1vnQgOH3xEPsqfiFowg2sSwb/ZDakzTuC RGdsyWBGo13QLqaG0V8Uz8MPPWENo/jbIcTU/JVpWcgAHjF/V/5nRYzHjMnJE7d4usnn VN/XZQ2f5c35Et5rIUQJZR+fn+PwsbqgwhhLzsUXVoIxREamt/xN47uvyaJ8sNcM7Ffg 4nbXB9X6axOgpYqE0KWr8iZTtf1iyF5feodbkY1q+ZmCc+VXifrR1ro5ZxY08YopVZL7 /5eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UKkzI2CsoNgX1WJTht9BzlNFsx76EWCSrLu3KlKlb+c=; fh=56b0f9amB/d14Cru5+rTzdvRVvg1qsHx+cb1CsaZSXE=; b=diqMH+udnxjF0AIiD2t3eOPKLIz8KHTuHPED75daNfTrcMv+STfcHnr0bn+cRFjWJ4 OUMdC6JwTZFSUUaZOUmRN1ajMNXWXNDKDpGnl33cIyUHmXP99d0qdW0/Q8o9/CirW5lb jw8pjpUICZunkjwMkCetSyC1N4Qgj6MyoCKv89tk8NbP6rTST+6GDUzye5FmXJG1ZYbu zt17amEivyGlQr5Uj81YeNYos+s6cFFeOFMMOK+jH9XqW4e1IVZX8gz243mkIYD6o5iD N3wSKaUkxTNyF/UHyMnEpYBcBL+uICcxL3W2OrfgApfwfXruSW/sC7+Lq79FkSz74qTF Yr3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E4SuWMQM; spf=pass (google.com: domain of linux-kernel+bounces-20962-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b16-20020a170906491000b00a27e113a2b1si808765ejq.966.2024.01.09.06.13.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:13:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20962-ouuuleilei=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=@redhat.com header.s=mimecast20190719 header.b=E4SuWMQM; spf=pass (google.com: domain of linux-kernel+bounces-20962-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 D6D7B1F253C9 for ; Tue, 9 Jan 2024 14:13:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 813B93B189; Tue, 9 Jan 2024 14:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E4SuWMQM" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A69943A8E7 for ; Tue, 9 Jan 2024 14:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704809496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UKkzI2CsoNgX1WJTht9BzlNFsx76EWCSrLu3KlKlb+c=; b=E4SuWMQM8HS7JqSVfUGGGlnnleNjvf/aXGwk7JfjTO3EBz3uhl6v+HUpylpRQfPcRinvie +A4tUlN4/QLLFEbk/c0meccJeGWcrIHiFQoz1b3xEA1/fNQRdOa33H3/VV//HQMsJ40Wb7 SbcV5EkwO5fU6wHYn46gp5yetGykggw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-laJp76qrNlyENke7orJW9w-1; Tue, 09 Jan 2024 09:11:28 -0500 X-MC-Unique: laJp76qrNlyENke7orJW9w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D8C01185A781; Tue, 9 Jan 2024 14:11:27 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC87D51E3; Tue, 9 Jan 2024 14:11:26 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Oliver Upton , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] KVM: selftests: Make hyperv_clock require TSC based system clocksource Date: Tue, 9 Jan 2024 15:11:20 +0100 Message-ID: <20240109141121.1619463-5-vkuznets@redhat.com> In-Reply-To: <20240109141121.1619463-1-vkuznets@redhat.com> References: <20240109141121.1619463-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787622453400544230 X-GMAIL-MSGID: 1787622453400544230 KVM sets up Hyper-V TSC page clocksource for its guests when system clocksource is 'based on TSC' (see gtod_is_based_on_tsc()), running hyperv_clock with any other clocksource leads to imminent failure. Add the missing requirement to make the test skip gracefully. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/x86_64/hyperv_clock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_clock.c b/tools/testing/selftests/kvm/x86_64/hyperv_clock.c index f5e1e98f04f9..02cc3c560566 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_clock.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_clock.c @@ -212,6 +212,7 @@ int main(void) int stage; TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_TIME)); + TEST_REQUIRE(sys_clocksource_is_based_on_tsc()); vm = vm_create_with_one_vcpu(&vcpu, guest_main); From patchwork Tue Jan 9 14:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 186411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp134462dyi; Tue, 9 Jan 2024 06:13:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoXdvECtOJkFKaiswNbQI+UI9UdF+i1KR+P+q/eXN/jFmT6QIO+wYFKEs6OuaWireOvhFK X-Received: by 2002:a2e:9c4f:0:b0:2cd:11f9:a616 with SMTP id t15-20020a2e9c4f000000b002cd11f9a616mr2428848ljj.53.1704809600605; Tue, 09 Jan 2024 06:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704809600; cv=none; d=google.com; s=arc-20160816; b=MdP6EB66+FfUrffO2JgYahWf+31ffytutN9NyK1VGKYjjlklCsebP3OCcQEkiCJZnH FSFfSBmCpr5W60/DD0xO8Warsf+2iJWafOw2VtjaYSjEg5whxhICfs1PeZSeqLx1DY22 6yO9veWOIf6/JWo3YNd1VUN16MaAaRF+OUy/WycX5mh+/Yp261n9T+rbcPvgZl09Hs9T IOZ2OmcoEEJpXLJrr8ushQO3UdQMbKVs/oFUJ3KR3PjQsK3l6gJ6RgxpBKga0ZBE8Ip6 OmAJzmOOcshQCD0jQ0Ai9h8pLDZDNRLpNiQ5fbyWn2vQRTs/2iCjTdaBk5teU0R5SW0z BnWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iDgGk9AqkfdB9KmMB1EEQzESiWoQzRB9G8la+60J3pw=; fh=56b0f9amB/d14Cru5+rTzdvRVvg1qsHx+cb1CsaZSXE=; b=Iq8xHwh62egi1kKgDiENdRR8yJtLmeMeB92xvtjMljeenx80Qy2Q6NY8vO/VMYXF77 s2fpG1goZdix6hZBqIurVhKF8b/Ex1Wo0JwvnYwIr6dbBzP3g1gn9J/4rz8gRz/cbt2p ez08URzQiRnVp2zk95t+EgtCtdN4Ey/PzKHEgkIy41cRdOcjO+xAFrliiC4/iqb+mIuD KVynxkYnCi63bK+djwPj3IUrg1eikHZD2c1IFV/4DqA3DcbIiNbHBjE+wPomDwElMxHn EEFR2jKA5VVdasju4Tu3J2R06frL702xzUN2aE0koIqwZp8tqTow4tajIzWl9D60vbbv b05w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YIPWLvkA; spf=pass (google.com: domain of linux-kernel+bounces-20961-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20961-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w5-20020a05640234c500b00557c1791121si815881edc.439.2024.01.09.06.13.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20961-ouuuleilei=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=@redhat.com header.s=mimecast20190719 header.b=YIPWLvkA; spf=pass (google.com: domain of linux-kernel+bounces-20961-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20961-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 373581F25187 for ; Tue, 9 Jan 2024 14:13:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85DB23A8E3; Tue, 9 Jan 2024 14:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YIPWLvkA" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5AB03A1AA for ; Tue, 9 Jan 2024 14:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704809492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iDgGk9AqkfdB9KmMB1EEQzESiWoQzRB9G8la+60J3pw=; b=YIPWLvkAeSYtUJyT7jWBdJO0U5+J0cZ2u6l5e1ioGuQYwJ3mhmBs6RmWyK+a6E19Rqfhyu yu4l+begTAv5VeAnM8Rj0E7NrVvBMSZP8tl8PEjxOJHjRHhnW+yw35IfALetISa0KvnC7Q 3lxclUYkuE+UyM0dPvCQTyVreWwtfjI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-wnYQVk-1M2mfovKXhcdi5A-1; Tue, 09 Jan 2024 09:11:29 -0500 X-MC-Unique: wnYQVk-1M2mfovKXhcdi5A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0632338425A4; Tue, 9 Jan 2024 14:11:29 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19A4151E3; Tue, 9 Jan 2024 14:11:27 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Oliver Upton , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] KVM: x86: Make gtod_is_based_on_tsc() return 'bool' Date: Tue, 9 Jan 2024 15:11:21 +0100 Message-ID: <20240109141121.1619463-6-vkuznets@redhat.com> In-Reply-To: <20240109141121.1619463-1-vkuznets@redhat.com> References: <20240109141121.1619463-1-vkuznets@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787622431781896736 X-GMAIL-MSGID: 1787622431781896736 gtod_is_based_on_tsc() is boolean in nature, i.e. it returns '1' for good clocksources and '0' otherwise. Moreover, its result is used raw by kvm_get_time_and_clockread()/kvm_get_walltime_and_clockread() which are 'bool'. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- 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 27e23714e960..2aba11eb58ac 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2507,7 +2507,7 @@ static u64 compute_guest_tsc(struct kvm_vcpu *vcpu, s64 kernel_ns) } #ifdef CONFIG_X86_64 -static inline int gtod_is_based_on_tsc(int mode) +static inline bool gtod_is_based_on_tsc(int mode) { return mode == VDSO_CLOCKMODE_TSC || mode == VDSO_CLOCKMODE_HVCLOCK; }