From: Sean Christopherson <seanjc@google.com>
To: Hao Ge <gehao@kylinos.cn>
Cc: pbonzini@redhat.com, shuah@kernel.org, dmatlack@google.com,
coltonlewis@google.com, vipinsh@google.com, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
gehao618@163.com
Subject: Re: [RESEND PATCH] kvm/selftests: Close opened file descriptor in stable_tsc_check_supported()
Date: Wed, 5 Apr 2023 17:13:02 -0700 [thread overview]
Message-ID: <ZC4OjuhPDlehRksi@google.com> (raw)
In-Reply-To: <20230405101350.259000-1-gehao@kylinos.cn>
On Wed, Apr 05, 2023, Hao Ge wrote:
> Close the "current_clocksource" file descriptor before
> returning or exiting from stable_tsc_check_supported()
> in vmx_nested_tsc_scaling_test
>
> Signed-off-by: Hao Ge <gehao@kylinos.cn>
> ---
> .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 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 d427eb146bc5..fa03c8d1ce4e 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
> @@ -126,12 +126,16 @@ static void stable_tsc_check_supported(void)
> goto skip_test;
>
> if (fgets(buf, sizeof(buf), fp) == NULL)
> - goto skip_test;
> + goto close_fp;
>
> if (strncmp(buf, "tsc", sizeof(buf)))
> - goto skip_test;
> + goto close_fp;
>
> + fclose(fp);
> return;
> +
> +close_fp:
> + fclose(fp);
> skip_test:
> print_skip("Kernel does not use TSC clocksource - assuming that host TSC is not stable");
> exit(KSFT_SKIP);
Actually, this can be streamlined by having the helper return a bool and punting
the skip logic to TEST_REQUIRE. I'll still apply this patch first, but I'll post
a patch on top to yield:
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;
}
next prev parent reply other threads:[~2023-04-06 0:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 10:13 [RESEND PATCH] kvm/selftests: Close opened file descriptor in stable_tsc_check_supported() Hao Ge
2023-04-05 14:46 ` Sean Christopherson
2023-04-06 2:56 ` gehao
2023-04-06 8:07 ` Hao Ge
2023-04-06 0:13 ` Sean Christopherson [this message]
2023-04-06 0:18 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZC4OjuhPDlehRksi@google.com \
--to=seanjc@google.com \
--cc=coltonlewis@google.com \
--cc=dmatlack@google.com \
--cc=gehao618@163.com \
--cc=gehao@kylinos.cn \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
--cc=vipinsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox