From patchwork Mon Oct 21 21:24:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 11203015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19D70913 for ; Mon, 21 Oct 2019 21:24:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DA48E20873 for ; Mon, 21 Oct 2019 21:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="OTC8d3ZE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA48E20873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B05516B0006; Mon, 21 Oct 2019 17:24:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A8EA96B0007; Mon, 21 Oct 2019 17:24:40 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 958036B0008; Mon, 21 Oct 2019 17:24:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 65C886B0006 for ; Mon, 21 Oct 2019 17:24:40 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 213494FFA for ; Mon, 21 Oct 2019 21:24:40 +0000 (UTC) X-FDA: 76069071120.01.steam16_b9227d812d0d X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jhubbard@nvidia.com,:akpm@linux-foundation.org:keith.busch@intel.com:linux-kernel@vger.kernel.org::linux-kselftest@vger.kernel.org:jhubbard@nvidia.com,RULES_HIT:30036:30051:30054:30056:30064,0,RBL:216.228.121.65:@nvidia.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: steam16_b9227d812d0d X-Filterd-Recvd-Size: 4369 Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com [216.228.121.65]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Oct 2019 21:24:39 +0000 (UTC) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 21 Oct 2019 14:24:41 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 21 Oct 2019 14:24:37 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 21 Oct 2019 14:24:37 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 21 Oct 2019 21:24:37 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 21 Oct 2019 21:24:37 +0000 Received: from blueforge.nvidia.com (Not Verified[10.110.48.28]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 21 Oct 2019 14:24:37 -0700 From: John Hubbard To: Andrew Morton CC: Keith Busch , LKML , , , John Hubbard Subject: [PATCH 1/1] mm/gup_benchmark: fix MAP_HUGETLB case Date: Mon, 21 Oct 2019 14:24:35 -0700 Message-ID: <20191021212435.398153-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191021212435.398153-1-jhubbard@nvidia.com> References: <20191021212435.398153-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1571693081; bh=Ia7+yGVPadcQzuPA7gW008zSE+NH1nISNCbcuj3+bIA=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=OTC8d3ZE9fJ0Hb2v8pEfvXND3hp78cAKhSqr+KUCHRl9piPHKBIHMod7VkMRG/V07 YiSuKsdFJN/DtpDmHBNAjg0SY/+yw6EZVbEBBRcY5hKDPY2cwJi4Yy17qhEwozgbXp jD2oUyt7AENs2BEp1SMVn3lETH6pAEsDl/oDEcIUTKXYkUka0rUy3UXtxBZdCe2Fhs 9YL7rBPNlFbNtFy9br7US89E0IFpJiaTELl5vPfnQioCelddiyfHAyOHRjNZks6g4s lPQfDa1Mgyz+bDNtzAbOYex69TebqWe0OaW+5qZRnZrgQmhswsnaA2NIMik4bxbUW5 i3YmawSo4o7Hg== 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: 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 = -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. Cc: Keith Busch Signed-off-by: John Hubbard Reviewed-by: Jérôme Glisse --- tools/testing/selftests/vm/gup_benchmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/vm/gup_benchmark.c b/tools/testing/selftests/vm/gup_benchmark.c index cb3fc09645c4..485cf06ef013 100644 --- a/tools/testing/selftests/vm/gup_benchmark.c +++ b/tools/testing/selftests/vm/gup_benchmark.c @@ -71,7 +71,7 @@ int main(int argc, char **argv) flags |= MAP_SHARED; break; case 'H': - flags |= MAP_HUGETLB; + flags |= (MAP_HUGETLB | MAP_ANONYMOUS); break; default: return -1;