From patchwork Wed Sep 15 21:28:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 12497513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76447C433FE for ; Wed, 15 Sep 2021 21:28:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FEA760E8B for ; Wed, 15 Sep 2021 21:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232392AbhIOV3d (ORCPT ); Wed, 15 Sep 2021 17:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232356AbhIOV3c (ORCPT ); Wed, 15 Sep 2021 17:29:32 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03374C061764 for ; Wed, 15 Sep 2021 14:28:13 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id i13so4483896ilm.4 for ; Wed, 15 Sep 2021 14:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5/05t+cft47v+XjdfjmqtyGwgO/Y9iAdxp4y0oub3sQ=; b=EM5CoyJnEhE01BEs479VfIK4jImJFA22maAiLWfX5Z5H5XLK6PeVPVtKY+6RzJT87g H2wcT9fOX9GB0dUitCiGG5KaaQ1Quna3ubgUKRq++A8LoyLlgRCHzrLG4Kr6Uzpa0s7/ a2HRzuRsOc5tj+nz+zso25WUH+s7WG+oOfKMg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5/05t+cft47v+XjdfjmqtyGwgO/Y9iAdxp4y0oub3sQ=; b=zyujyCHLFkMXo8HLN/KiQE8TuKZfRZGS3XcsVojmKBkwT9qRHauPa7OmCQBsR8nhxL yclCW3y6amT8YFX4SLqS7dV917PTg2CQLp7YWmM74VsQ33miXi2XlFPLVQsOxsjyg1LE Rw3cgCC3qPQYgG9LKlxxinQrmAaAmiMS85WC74UoZospqsSUPjE+njpFGsXQWkiJzDi4 i/MbpGrPcSqssDvEVFwI1SPMxP8H64I5x6pfBuK7WB2eOaYpAmgKlAWTkUzHLqETF+v3 n1KUOzcgdrHhn5mdDLDWtGGDuMR622q1eR4rPtJ7pzWQXLHAGDC7pdOvqjGOug1SNi2G AXHA== X-Gm-Message-State: AOAM533uzotVwa6vB0DcIPa7a0fAJJ6a6LVebwS5MxW5Xfx0r6aGrokB SKFBYWC/+huEZAUsdoVbjEC0yg== X-Google-Smtp-Source: ABdhPJzxwqX7gRE030Q48r8VOe+p/R3TO1zws/jz/AaNUPiJtQPKoSMaf/CgIE2QH4dRMm+QAjA+MQ== X-Received: by 2002:a92:bf0c:: with SMTP id z12mr1588379ilh.241.1631741292332; Wed, 15 Sep 2021 14:28:12 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f2sm622884ioz.14.2021.09.15.14.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 14:28:11 -0700 (PDT) From: Shuah Khan To: pbonzini@redhat.com, shuah@kernel.org Cc: Shuah Khan , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] selftests:kvm: fix get_warnings_count() ignoring fscanf() return warn Date: Wed, 15 Sep 2021 15:28:06 -0600 Message-Id: <9dfad43fb500a77f7a08e5e7b80dcb07172d6e44.1631737524.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fix get_warnings_count() to check fscanf() return value to get rid of the following warning: x86_64/mmio_warning_test.c: In function ‘get_warnings_count’: x86_64/mmio_warning_test.c:85:2: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 85 | fscanf(f, "%d", &warnings); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Shuah Khan --- tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c index e6480fd5c4bd..8039e1eff938 100644 --- a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +++ b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c @@ -82,7 +82,8 @@ int get_warnings_count(void) FILE *f; f = popen("dmesg | grep \"WARNING:\" | wc -l", "r"); - fscanf(f, "%d", &warnings); + if (fscanf(f, "%d", &warnings) < 1) + warnings = 0; fclose(f); return warnings; From patchwork Wed Sep 15 21:28:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 12497515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E31C2C4332F for ; Wed, 15 Sep 2021 21:28:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3CD161056 for ; Wed, 15 Sep 2021 21:28:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbhIOV3g (ORCPT ); Wed, 15 Sep 2021 17:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232356AbhIOV3d (ORCPT ); Wed, 15 Sep 2021 17:29:33 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C565C061764 for ; Wed, 15 Sep 2021 14:28:14 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id w1so4519878ilv.1 for ; Wed, 15 Sep 2021 14:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=abD5VjgZ8HXnpuGs79I/oeyTYUiv/nSNnMDhyKm1NjA=; b=bXMRAJ3lq0L4NKgfxfIXFaQn9y67r8KHq74UuKDIgdXW+9uuRAmhVD8N2FK5bKbc2i ltoEJ9nnz0+T1YqTUs12ARBolb2rV81YIAKfb/9mXz3/Yb7LUHJ/qENYOt0RNlbtVcid 7DarsEcQi4nmE7RYr91VbWjnBpMkV1/DhxULc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=abD5VjgZ8HXnpuGs79I/oeyTYUiv/nSNnMDhyKm1NjA=; b=EZ+XLPNAwyHufbNAkqoZKwQmTSPGfvD36I/81cg81TME80qwhm0sjt0q7eYdeXcFkR NG69nLqPmvLUfrQH3Gmbx6nuia/9MWFEemLmlCxK91EUu/wtc5UwL8pPmaGU6X1/VMOH tTvbMWv3VvBsqwLwY9mgB2Q6PVnN7x19qglopOCbe20PfY0SPY9dnd+uD+EjqwnYe2Q2 YFkD0Hq1dYSBjDjwrXEN+E1KC7awBG1YjvNh2xUDO/59SMF9EL9N8RWWGf5cK/m9OtTw RRGXhWaOwx3fuE1XVgnxbNv2LGXRIAXYuxEIK38U+JMr4j4l69yjFmv/UOec+QHatp1T Wf5Q== X-Gm-Message-State: AOAM531L9ftWE9sU/Z1xMBY+gCrKrlsljH3S2NMAW7u973VaUiVBz7hO f3lYrDe/N1mRy3wjx1pQTkfmB87aPSGWKA== X-Google-Smtp-Source: ABdhPJwyfCLdvAiMBlX3bMZgpmdcE88EYz+205FYgOhWU/DiM5nDofUhYa955dy+8nmOlsmstpxjLQ== X-Received: by 2002:a05:6e02:12a3:: with SMTP id f3mr1593954ilr.54.1631741293603; Wed, 15 Sep 2021 14:28:13 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f2sm622884ioz.14.2021.09.15.14.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 14:28:12 -0700 (PDT) From: Shuah Khan To: pbonzini@redhat.com, shuah@kernel.org Cc: Shuah Khan , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] selftests:kvm: fix get_trans_hugepagesz() ignoring fscanf() return warn Date: Wed, 15 Sep 2021 15:28:07 -0600 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fix get_trans_hugepagesz() to check fscanf() return value to get rid of the following warning: lib/test_util.c: In function ‘get_trans_hugepagesz’: lib/test_util.c:138:2: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 138 | fscanf(f, "%ld", &size); | ^~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Shuah Khan --- tools/testing/selftests/kvm/lib/test_util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index af1031fed97f..938cd423643e 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -129,13 +129,16 @@ size_t get_trans_hugepagesz(void) { size_t size; FILE *f; + int ret; TEST_ASSERT(thp_configured(), "THP is not configured in host kernel"); f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r"); TEST_ASSERT(f != NULL, "Error in opening transparent_hugepage/hpage_pmd_size"); - fscanf(f, "%ld", &size); + ret = fscanf(f, "%ld", &size); + ret = fscanf(f, "%ld", &size); + TEST_ASSERT(ret < 1, "Error reading transparent_hugepage/hpage_pmd_size"); fclose(f); return size; From patchwork Wed Sep 15 21:28:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 12497517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60970C433F5 for ; Wed, 15 Sep 2021 21:28:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49DAD61131 for ; Wed, 15 Sep 2021 21:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232653AbhIOV3j (ORCPT ); Wed, 15 Sep 2021 17:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232536AbhIOV3g (ORCPT ); Wed, 15 Sep 2021 17:29:36 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F942C061768 for ; Wed, 15 Sep 2021 14:28:16 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id n24so5319819ion.10 for ; Wed, 15 Sep 2021 14:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1h6fL4KefzmZ6oE2CqHJFkAoOlg/B4t8Zb8g1+TnN/A=; b=Vm8Hgnt6/p9PPFwKcr1rp22aZv6Zt0a3m+RrEo9q9okz9fRn/cFFLa7WmtD4AxrSl1 pzoGGzWRg/LF9HaR/g+dvJdAIe/yCxWvv9+J/SngoEQaFRpBIWGe2bq1/leCRpgZMKhX Wa3q37uuh702Q8hh6BdRd/D3vG4SE1kTJgNjc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1h6fL4KefzmZ6oE2CqHJFkAoOlg/B4t8Zb8g1+TnN/A=; b=MrMTncRo7ZvoUW1dJ+I1JKC6nn3lFfu3CLnxsiFBkG1VjjHTioqU9J3TjrUYasEAne WCCcdUIOmCX4VZYmSzXu4cPlXJLuj0+76Kxb9pM0UVPYy6CSYU7z/2bmE6kx1gTq+PHW 7CHfd9TMRxpGViYVHel7AJ2h7LOkhQvSKOfRzabJFVRv4FnYEyDEG5ZLpAtl+tMnGPhE 9KekDRiMRZMJxGy3lQPuX9RL/1wuQe+DwJLptbwFQYa7pUHOnqOSt0/I/4+1HOOrnZsb LNjrJU8ujY4NSAGm8wpnFQ7EzoRnsV98vKDa4nnxvRXFLKIA+QfzYPFzHDYdCLbeok8s VVWQ== X-Gm-Message-State: AOAM533qt4hW5iGbFeVdEIVfsRHP5OwCsQQ23KZLiQ2T1ETePYa0CAMg Om33MHioGg4an6t+zumYIp0mYQ== X-Google-Smtp-Source: ABdhPJyo+TZP5qJ5Ub0+Wu0uWwvNu+DsRL3w38oj6I4r7gEFh7ltLgQl49viQUWjUqZuBBgLlIqdcQ== X-Received: by 2002:a6b:6613:: with SMTP id a19mr1731994ioc.167.1631741295959; Wed, 15 Sep 2021 14:28:15 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f2sm622884ioz.14.2021.09.15.14.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 14:28:14 -0700 (PDT) From: Shuah Khan To: pbonzini@redhat.com, shuah@kernel.org Cc: Shuah Khan , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] selftests: kvm: move get_run_delay() into lib/test_util Date: Wed, 15 Sep 2021 15:28:08 -0600 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org get_run_delay() is defined static in xen_shinfo_test and steal_time test. Move it to lib and remove code duplication. Signed-off-by: Shuah Khan --- tools/testing/selftests/kvm/include/test_util.h | 1 + tools/testing/selftests/kvm/lib/test_util.c | 15 +++++++++++++++ tools/testing/selftests/kvm/steal_time.c | 15 --------------- .../selftests/kvm/x86_64/xen_shinfo_test.c | 15 --------------- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index d79be15dd3d2..c7409b9b4e5b 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -102,6 +102,7 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i); size_t get_backing_src_pagesz(uint32_t i); void backing_src_help(void); enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); +long get_run_delay(void); /* * Whether or not the given source type is shared memory (as opposed to diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 938cd423643e..f80dd38a38b2 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "linux/kernel.h" @@ -303,3 +304,17 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name) TEST_FAIL("Unknown backing src type: %s", type_name); return -1; } + +long get_run_delay(void) +{ + char path[64]; + long val[2]; + FILE *fp; + + sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid)); + fp = fopen(path, "r"); + fscanf(fp, "%ld %ld ", &val[0], &val[1]); + fclose(fp); + + return val[1]; +} diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index ecec30865a74..51fe95a5c36a 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -217,20 +216,6 @@ static void steal_time_dump(struct kvm_vm *vm, uint32_t vcpuid) #endif -static long get_run_delay(void) -{ - char path[64]; - long val[2]; - FILE *fp; - - sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid)); - fp = fopen(path, "r"); - fscanf(fp, "%ld %ld ", &val[0], &val[1]); - fclose(fp); - - return val[1]; -} - static void *do_steal_time(void *arg) { struct timespec ts, stop; diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c index 117bf49a3d79..eda0d2a51224 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -14,7 +14,6 @@ #include #include #include -#include #define VCPU_ID 5 @@ -98,20 +97,6 @@ static void guest_code(void) GUEST_DONE(); } -static long get_run_delay(void) -{ - char path[64]; - long val[2]; - FILE *fp; - - sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid)); - fp = fopen(path, "r"); - fscanf(fp, "%ld %ld ", &val[0], &val[1]); - fclose(fp); - - return val[1]; -} - static int cmp_timespec(struct timespec *a, struct timespec *b) { if (a->tv_sec > b->tv_sec) From patchwork Wed Sep 15 21:28:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 12497519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5687C433EF for ; Wed, 15 Sep 2021 21:28:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C303E610E8 for ; Wed, 15 Sep 2021 21:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232273AbhIOV3m (ORCPT ); Wed, 15 Sep 2021 17:29:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232481AbhIOV3i (ORCPT ); Wed, 15 Sep 2021 17:29:38 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ABEEC0613D9 for ; Wed, 15 Sep 2021 14:28:18 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id n24so5319893ion.10 for ; Wed, 15 Sep 2021 14:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WQkUPnYzyIj6imY2siHAssmMkcSFNpsLGyNs+c8n/bw=; b=JnjBCXkfoljTWoBOUnDg5Vh8CuSHnEFvjPkYN63ahVDLJ75Z55KcQrMVr1Upl7MOOk cpNiNqEZ6l0Ju6k2PLrOYQFjiNSlNki3UjEzt14EaCivli7ZnnGyar9KGDqVb3OxLyQ3 LAtbPUVkd08fC23fX077KsNd7hLN52tZZFoIQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WQkUPnYzyIj6imY2siHAssmMkcSFNpsLGyNs+c8n/bw=; b=5rbvWAw262yfYQNTAx/QpSy+qyr372UQrePigI1FtQ+VaBfD0N/nr/TDsP/RPnhfDE UK0Dc7XMqyQYlBWZGQPNnPfsL3ko9aQzpuPl+KhFhnSFNCDLUZQ+oYPar0BwB1XbhL1D i/F99PI81hVpg2V4N7ZyDOPAymO+xEKVG57KWnPj4hzmyqrSWfvW5Ntk6GO34NYDS7XE 6lddotNvf5iwl1ZJ2/JcJV7OcM/LkCEqH6SN1aSKuafNH8DAiElShGIW3A4JnUhsgycR 2BRH24ARMOdxa7kRSjczvxPEcsTnG2IOy2S8BRCDLF5F+TTU2xbbD22Gm99h+Ps2xP+j a4Pg== X-Gm-Message-State: AOAM532f/A183sqdRnjUsYTvDmEKPee1yfg1ILhXQzcYt1MxBlkG4xYX CODGPIUHQ6VkuTVLWhfx7rOrVA== X-Google-Smtp-Source: ABdhPJzjtcPBMtUHKJAWFKiFoS6ecKsz+u8ONbHYrQElJFVMLe6T1I0LuiCyK11t4QYYrKuwNRxzaQ== X-Received: by 2002:a05:6638:2109:: with SMTP id n9mr1748840jaj.17.1631741297845; Wed, 15 Sep 2021 14:28:17 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id f2sm622884ioz.14.2021.09.15.14.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 14:28:16 -0700 (PDT) From: Shuah Khan To: pbonzini@redhat.com, shuah@kernel.org Cc: Shuah Khan , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] selftests: kvm: fix get_run_delay() ignoring fscanf() return warn Date: Wed, 15 Sep 2021 15:28:09 -0600 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fix get_run_delay() to check fscanf() return value to get rid of the following warning. When fscanf() fails return MIN_RUN_DELAY_NS from get_run_delay(). Move MIN_RUN_DELAY_NS from steal_time.c to test_util.h so get_run_delay() and steal_time.c can use it. lib/test_util.c: In function ‘get_run_delay’: lib/test_util.c:316:2: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 316 | fscanf(fp, "%ld %ld ", &val[0], &val[1]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Shuah Khan --- tools/testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 4 +++- tools/testing/selftests/kvm/steal_time.c | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index c7409b9b4e5b..451fed5ce8e7 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -95,6 +95,8 @@ struct vm_mem_backing_src_alias { uint32_t flag; }; +#define MIN_RUN_DELAY_NS 200000UL + bool thp_configured(void); size_t get_trans_hugepagesz(void); size_t get_def_hugetlb_pagesz(void); diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index f80dd38a38b2..a9107bfae402 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -313,7 +313,9 @@ long get_run_delay(void) sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid)); fp = fopen(path, "r"); - fscanf(fp, "%ld %ld ", &val[0], &val[1]); + /* Return MIN_RUN_DELAY_NS upon failure just to be safe */ + if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) < 2) + val[1] = MIN_RUN_DELAY_NS; fclose(fp); return val[1]; diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index 51fe95a5c36a..2172d65b85e4 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -19,7 +19,6 @@ #define NR_VCPUS 4 #define ST_GPA_BASE (1 << 30) -#define MIN_RUN_DELAY_NS 200000UL static void *st_gva[NR_VCPUS]; static uint64_t guest_stolen_time[NR_VCPUS];