Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2798818pxk; Sun, 27 Sep 2020 23:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxafG3U99BZtsOjwjC56wyMkzr+kRAaZS9seA3k1cVY6WEMjYkYgOSF6Fn+y4skfrmeJ8TR X-Received: by 2002:a05:6402:1acf:: with SMTP id ba15mr51434edb.305.1601274232634; Sun, 27 Sep 2020 23:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601274232; cv=none; d=google.com; s=arc-20160816; b=0Bi4WHGEoDPm4YqSwt+6hglWiHcCBGmE3Wws9OEF2xV2e7RcHre/Xi96iLcho/spaC u55euQwoHdNde4YV//yYY+JS1Xzd0ZnbSOvm0iWElEkhxYB/7OQgPnZOCYBJaSbeE8dK DrOK9yZ0+nJWkMDlLoCoQ3i9RQdY2apOtk+alP54tzKeQsvTGRPwoS3ZH8vl3/uVUPjw OUr/0npuTjw85ZCVN9jigrI7tEuI39RodE9fKKEbQuBKAu/zVy5CWtk589OqyQ0pOrA6 4pir3GQDQ4CZRK6zD2GoGQe8B0nYcxlmuvv5ENt7HMlHm0d+a6/gCj88yzGpNElyNLm+ MmeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=xzG0NswHS5qQ6W+MqWObPXUxvjzoGYmrEjfnzKI66EY=; b=wWmwZpUdfZHP4xmd9UCk6vgEoe57P08TT9AtXIFa2z8tIOky+DyEW3bjGwhGkjoxNL lWjz2nG7l7FzqoHLOmFvJCPbZo0A56foLd0nhOE4VO/I2YJGWaocK/5OBk3aGBWeVNlb yRRTupBNsDud1B1OtgPdUubEZKfLB8ojIr+co0m3FWE93Xo5GQ6Egg6ZIpXgPZqkF0r1 xYuDOzGkbzAw8eBO4VE4ANjhYNRZh40plUdwtBhfKc6pw/h5yHFe6Bx0SBC2myeydx1W CmVBAjFxmtwjtqv1OpP7nu8lVpxohBG8Omi4pYNHPoRIwC+tSUCP+G06P+g5rOXxzmyu w7Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=cexyc+mE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si7451598edm.221.2020.09.27.23.23.29; Sun, 27 Sep 2020 23:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=cexyc+mE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbgI1GWW (ORCPT + 99 others); Mon, 28 Sep 2020 02:22:22 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:2564 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726652AbgI1GWE (ORCPT ); Mon, 28 Sep 2020 02:22:04 -0400 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 27 Sep 2020 23:21:13 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 28 Sep 2020 06:22:03 +0000 Received: from sandstorm.nvidia.com (10.124.1.5) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Mon, 28 Sep 2020 06:22:03 +0000 From: John Hubbard To: Andrew Morton CC: Jonathan Corbet , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Ralph Campbell , Shuah Khan , LKML , , , , , John Hubbard Subject: [PATCH 8/8] selftests/vm: hmm-tests: remove the libhugetlbfs dependency Date: Sun, 27 Sep 2020 23:21:59 -0700 Message-ID: <20200928062159.923212-9-jhubbard@nvidia.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928062159.923212-1-jhubbard@nvidia.com> References: <20200928062159.923212-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1601274073; bh=xzG0NswHS5qQ6W+MqWObPXUxvjzoGYmrEjfnzKI66EY=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=cexyc+mES/q0Ay4o6Z0cnL30CRDRPbKEb5j7DfORo/lQmTltKbCwDrMgr/VAbHn69 B+pTTuR6nfm1maaAK34c86+Hr1t2JsdNRD+0EPEfE9MPXFsdt9XfDNnIICXfD9JSu6 k+dRwSEbg9yNS3XN+maAYFnu9Atc8emC+BoS12+gvIIsZZX2b0Pq0w0jIDNELFeQJs YHwLOcrsRRINGQWVY5CgcRthycQ4PFRCIzM6qPgBSOZxehiA3Vr6nTpjfakCAZPRxJ av64aRmdADLS3XS7I0q6uWZynjTqpnqFigg/OBk5OpSJmtbqMXai65zpx5N9sH1LVp Vu5uLHyMbvVUw== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HMM selftests are incredibly useful, but they are only effective if people actually build and run them. All the other tests in selftests/vm can be built with very standard, always-available libraries: libpthread, librt. The hmm-tests.c program, on the other hand, requires something that is (much) less readily available: libhugetlbfs. And so the build will typically fail for many developers. A simple attempt to install libhugetlbfs will also run into complications on some common distros these days: Fedora and Arch Linux (yes, Arch AUR has it, but that's fragile, as always with AUR). The library is not maintained actively enough at the moment, for distros to deal with it. I had to build it from source, for Fedora, and that didn't go too smoothly either. It turns out that, out of 21 tests in hmm-tests.c, only 2 actually require functionality from libhugetlbfs. Therefore, if libhugetlbfs is missing, simply ifdef those two tests out and allow the developer to at least have the other 19 tests, if they don't want to pause to work through the above issues. Also issue a warning, so that it's clear that there is an imperfection in the build. In order to do that, a tiny shell script (check_config.sh) runs a quick compile (not link, that's too prone to false failures with library paths), and basically, if the compiler doesn't find hugetlbfs.h in its standard locations, then the script concludes that libhugetlbfs is not available. The output is in two files, one for inclusion in hmm-test.c (local_config.h), and one for inclusion in the Makefile (local_config.mk). Cc: Ralph Campbell Signed-off-by: John Hubbard --- tools/testing/selftests/vm/.gitignore | 1 + tools/testing/selftests/vm/Makefile | 24 +++++++++++++++-- tools/testing/selftests/vm/check_config.sh | 30 ++++++++++++++++++++++ tools/testing/selftests/vm/hmm-tests.c | 10 +++++++- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/vm/check_config.sh diff --git a/tools/testing/selftests/vm/.gitignore b/tools/testing/selftest= s/vm/.gitignore index 2c8ddcf41c0e..e90d28bcd518 100644 --- a/tools/testing/selftests/vm/.gitignore +++ b/tools/testing/selftests/vm/.gitignore @@ -20,3 +20,4 @@ va_128TBswitch map_fixed_noreplace write_to_hugetlbfs hmm-tests +local_config.* diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/= vm/Makefile index 2579242386ac..986a90fa9653 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for vm selftests + +include local_config.mk + uname_M :=3D $(shell uname -m 2>/dev/null || echo not) MACHINE ?=3D $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/') =20 @@ -76,8 +79,6 @@ TEST_FILES :=3D test_vmalloc.sh KSFT_KHDR_INSTALL :=3D 1 include ../lib.mk =20 -$(OUTPUT)/hmm-tests: LDLIBS +=3D -lhugetlbfs - ifeq ($(ARCH),x86_64) BINARIES_32 :=3D $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) BINARIES_64 :=3D $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) @@ -130,3 +131,22 @@ endif $(OUTPUT)/mlock-random-test: LDLIBS +=3D -lcap =20 $(OUTPUT)/gup_test: ../../../../mm/gup_test.h + +$(OUTPUT)/hmm-tests: local_config.h + +# HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. +$(OUTPUT)/hmm-tests: LDLIBS +=3D $(HMM_EXTRA_LIBS) + +local_config.mk local_config.h: check_config.sh + ./check_config.sh + +EXTRA_CLEAN +=3D local_config.mk local_config.h + +ifeq ($(HMM_EXTRA_LIBS),) +all: warn_missing_hugelibs + +warn_missing_hugelibs: + @echo ; \ + echo "Warning: missing libhugetlbfs support. Some HMM tests will be skipp= ed." ; \ + echo +endif diff --git a/tools/testing/selftests/vm/check_config.sh b/tools/testing/sel= ftests/vm/check_config.sh new file mode 100755 index 000000000000..651a4b192479 --- /dev/null +++ b/tools/testing/selftests/vm/check_config.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Probe for libraries and create header files to record the results. Both = C +# header files and Makefile include fragments are created. + +OUTPUT_H_FILE=3Dlocal_config.h +OUTPUT_MKFILE=3Dlocal_config.mk + +# libhugetlbfs +tmpname=3D$(mktemp) +tmpfile_c=3D${tmpname}.c +tmpfile_o=3D${tmpname}.o + +echo "#include " > $tmpfile_c +echo "#include " >> $tmpfile_c +echo "int func(void) { return 0; }" >> $tmpfile_c + +gcc -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1 + +if [ -f $tmpfile_o ]; then + echo "#define LOCAL_CONFIG_HAVE_LIBHUGETLBFS 1" > $OUTPUT_H_FILE + echo "HMM_EXTRA_LIBS =3D -lhugetlbfs" > $OUTPUT_MKFILE +else + echo "// No libhugetlbfs support found" > $OUTPUT_H_FILE + echo "# No libhugetlbfs support found, so:" > $OUTPUT_MKFILE + echo "HMM_EXTRA_LIBS =3D " >> $OUTPUT_MKFILE +fi + +rm ${tmpname}.* diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftes= ts/vm/hmm-tests.c index 0a28a6a29581..6b79723d7dc6 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -21,12 +21,16 @@ #include #include #include -#include #include #include #include #include =20 +#include "./local_config.h" +#ifdef LOCAL_CONFIG_HAVE_LIBHUGETLBFS +#include +#endif + /* * This is a private UAPI to the kernel test module so it isn't exported * in the usual include/uapi/... directory. @@ -662,6 +666,7 @@ TEST_F(hmm, anon_write_huge) hmm_buffer_free(buffer); } =20 +#ifdef LOCAL_CONFIG_HAVE_LIBHUGETLBFS /* * Write huge TLBFS page. */ @@ -720,6 +725,7 @@ TEST_F(hmm, anon_write_hugetlbfs) buffer->ptr =3D NULL; hmm_buffer_free(buffer); } +#endif /* LOCAL_CONFIG_HAVE_LIBHUGETLBFS */ =20 /* * Read mmap'ed file memory. @@ -1336,6 +1342,7 @@ TEST_F(hmm2, snapshot) hmm_buffer_free(buffer); } =20 +#ifdef LOCAL_CONFIG_HAVE_LIBHUGETLBFS /* * Test the hmm_range_fault() HMM_PFN_PMD flag for large pages that * should be mapped by a large page table entry. @@ -1411,6 +1418,7 @@ TEST_F(hmm, compound) buffer->ptr =3D NULL; hmm_buffer_free(buffer); } +#endif /* LOCAL_CONFIG_HAVE_LIBHUGETLBFS */ =20 /* * Test two devices reading the same memory (double mapped). --=20 2.28.0