Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1416537rwl; Wed, 5 Apr 2023 17:18:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZB4b3YUfXsV1cBCsr86K0fSWo23INXKK0xTEZ2/njwHDRubChFCsF8KhuR4buLWjJ56wIf X-Received: by 2002:a17:907:70d:b0:949:7c14:d890 with SMTP id xb13-20020a170907070d00b009497c14d890mr3600567ejb.62.1680740306394; Wed, 05 Apr 2023 17:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680740306; cv=none; d=google.com; s=arc-20160816; b=D4g4ZHRjHfUARDrxqMWhd0JQ0ZTebIdIfzzvXN3FC98mAor6kfSfx5AI/VoQNqcyuH 7a0iH6VJmd/AXfrqOYqiwklUYiTeDWmPhvOvPbEKCTWV3iE4RPM4ByMh+1Tqi3eI4vCO h+C0m45XoClMJbSMwFSkR2XUHKRAs+/yEW9ZTpV9yuegKc066+DUURyCndqxC4eAxC4x ZZIKQmypARZxK4MFOmuWVkE1D2q+nwcJi26vTw9qt+ELpfGFYSz7nGJ5Fqnv7M4QadPh BY3tV/ZRm+VjDUE5s4KobZxqHrxU1UNN0vJVYNhf2Q5RmyOgBOhzTQzXVrlKBPwMa5DC QHUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=oIVv17QpIfjpv7NHijjNGS+xbKdk8/meE9TVNffXN1Y=; b=Qa5dyZGREaNVCzZiirvvcYh0KJJsmE1UlF0AdhoKUMgYeoRTeKkw83KVtJJkzdpUhX tiPw6/20y4mEsClPnxmxJ2UDM7xn+Pb5hqLdZhFTKm4zmUteuSHIfgeCyODTk8biomfs /ahY0qGWqhEJzXgl9VgJlbqt4ndH0dSpHuHFIxjEqZZ+SrZD1SjKe9Iwk36NLXmJ/s1T cCHN8IcuK7qn2fa4s9rr10ljd0br7aYXvobjr/ZIucmyGmaDNm8Fmms95cHk4nuSrC5i yCh70qcgObOw51eo6Fzf5/BOPDAtS0Afme6u0ue95tY24YUKWkvPpZ2IA70qnoMRhmlL 85zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PRY0RJTT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pv7-20020a170907208700b009372a2a6e7fsi59764ejb.563.2023.04.05.17.18.01; Wed, 05 Apr 2023 17:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PRY0RJTT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233501AbjDFANL (ORCPT + 99 others); Wed, 5 Apr 2023 20:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232656AbjDFANK (ORCPT ); Wed, 5 Apr 2023 20:13:10 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517896A4B for ; Wed, 5 Apr 2023 17:13:05 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54196bfcd5fso366961767b3.4 for ; Wed, 05 Apr 2023 17:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680739984; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oIVv17QpIfjpv7NHijjNGS+xbKdk8/meE9TVNffXN1Y=; b=PRY0RJTTBJ67UCBYkIEfsKRFyOT1gcdKU7mv/OeUzw1r1nHClV6TBceqcc2vjff2tA aPBnlafF5cZNOFZk7kkdgzedBzJszoOmZ6449L11iLZyzQBJwlpKdC0qaOZBJyWu8z4M P0QAQTHfWIZF22LNU5dHMgudihMSjpdbQg3y2CTSzwBJJolDcfkY5TLf8sy8EzVb1R/l mC3myJMNfjzT0D9U3rl0dzlL4Yb+k5D0GFie433PGG9ovD4mM2lE01EC7KeVSPHh3N39 58OrvOuOSTMsNWJGHY1yw7ar6BNckD+7YknVNuukTyYjrkODZjRDw55OF4eEDiSVle11 WAZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680739984; 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=oIVv17QpIfjpv7NHijjNGS+xbKdk8/meE9TVNffXN1Y=; b=K+x7hMjDC4fGNG1Y+1vrVLOWgdkKuunfM+hDTLMarQgCUNeKcMv++APSY/PdeUZhLw LflR3wK2jj+SNCKk2a2/INXvyJL9dZYQBBNtaWQS8is95DmeO1hXZs7YvL4orDy3e2b+ AdO53DztSxHL9d7cCLkPEJfejyo0s4W+cIUEfqr37gRzGmowfUrLSEgMjp/sXMuTpCkS xGaO/do9pmIZYKb+GyBsayUBuRhYyLA4Gw/JtuA8C4TNFj9dDVkQLnlyB04x+Y4bP1F/ 6VkfaHN4ryZBDz+jqvJI2RsxVoSZlSmfeWkLkIrhH697GgFqF1IikHabgez+kfXTKjav UXtA== X-Gm-Message-State: AAQBX9cXMwtJNP612H8XacM+C5GHsIoM0AkmtK1X/nk/muMIkLp2Pwyw vwS3g7Dud4OE+XbYv87UvCEVXDoeMK8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:df57:0:b0:b68:7b14:186b with SMTP id w84-20020a25df57000000b00b687b14186bmr751713ybg.1.1680739984384; Wed, 05 Apr 2023 17:13:04 -0700 (PDT) Date: Wed, 5 Apr 2023 17:13:02 -0700 In-Reply-To: <20230405101350.259000-1-gehao@kylinos.cn> Mime-Version: 1.0 References: <20230405101350.259000-1-gehao@kylinos.cn> Message-ID: Subject: Re: [RESEND PATCH] kvm/selftests: Close opened file descriptor in stable_tsc_check_supported() From: Sean Christopherson To: Hao Ge 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 Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > .../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; }