From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 9B69EC5DF62 for ; Wed, 6 Nov 2019 05:16:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A966206A3 for ; Wed, 6 Nov 2019 05:16:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="xm73wNtX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A966206A3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0FA7D6B026A; Wed, 6 Nov 2019 00:16:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AB7A6B026B; Wed, 6 Nov 2019 00:16:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F035E6B026C; Wed, 6 Nov 2019 00:16:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id DB1906B026A for ; Wed, 6 Nov 2019 00:16:26 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 38534180AD817 for ; Wed, 6 Nov 2019 05:16:26 +0000 (UTC) X-FDA: 76124691972.07.river78_3828dc440b60a X-HE-Tag: river78_3828dc440b60a X-Filterd-Recvd-Size: 3383 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Nov 2019 05:16:25 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 78D4721882; Wed, 6 Nov 2019 05:16:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573017384; bh=zAERiXKmMRx/TRsIN7Jcr7ADe37v/DvY6Bw5+uHaPfg=; h=Date:From:To:Subject:From; b=xm73wNtX1k9mKKXl3snRl2/h0vrMr/9zRXXDH5wKBcEFlmUOF7Re53nds+PqIk9ID bERqUW95z6GFsE5pez7mFXYx84MMgBQ3xk9YIl0um1HztwWV771kIwyapvtv/BvktP +LlDkTMefoenfkWwSn/Rw/ovPDMeN9fgRGZQ8D7k= Date: Tue, 05 Nov 2019 21:16:24 -0800 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, jglisse@redhat.com, jhubbard@nvidia.com, keith.busch@intel.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 02/17] mm/gup_benchmark: fix MAP_HUGETLB case Message-ID: <20191106051624.K0OGr88gF%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: =46rom: John Hubbard Subject: mm/gup_benchmark: fix MAP_HUGETLB case The MAP_HUGETLB ("-H" option) of gup_benchmark fails: $ sudo ./gup_benchmark -H mmap: Invalid argument This is because gup_benchmark.c is passing in a file descriptor to mmap(), but the fd came from opening up the /dev/zero file. This confuses the mmap syscall implementation, which thinks that, if the caller did not specify MAP_ANONYMOUS, then the file must be a huge page file. So it attempts to verify that the file really is a huge page file, as you can see here: ksys_mmap_pgoff() { if (!(flags & MAP_ANONYMOUS)) { retval =3D -EINVAL; if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file))) goto out_fput; /* THIS IS WHERE WE END UP */ else if (flags & MAP_HUGETLB) { ...proceed normally, /dev/zero is ok here... ...and of course is_file_hugepages() returns "false" for the /dev/zero file. The problem is that the user space program, gup_benchmark.c, really just wants anonymous memory here. The simplest way to get that is to pass MAP_ANONYMOUS whenever MAP_HUGETLB is specified, so that's what this patch does. Link: http://lkml.kernel.org/r/20191021212435.398153-2-jhubbard@nvidia.com Signed-off-by: John Hubbard Reviewed-by: Andrew Morton Reviewed-by: J=C3=A9r=C3=B4me Glisse Cc: Keith Busch Signed-off-by: Andrew Morton --- tools/testing/selftests/vm/gup_benchmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/tools/testing/selftests/vm/gup_benchmark.c~mm-gup_benchmark-fix-map_h= ugetlb-case +++ a/tools/testing/selftests/vm/gup_benchmark.c @@ -71,7 +71,7 @@ int main(int argc, char **argv) flags |=3D MAP_SHARED; break; case 'H': - flags |=3D MAP_HUGETLB; + flags |=3D (MAP_HUGETLB | MAP_ANONYMOUS); break; default: return -1; _