From patchwork Thu Jan 10 21:09:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 10756879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6418D13B5 for ; Thu, 10 Jan 2019 21:10:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52FFC29BAF for ; Thu, 10 Jan 2019 21:10:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45F5229BCC; Thu, 10 Jan 2019 21:10:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C2FE29BBE for ; Thu, 10 Jan 2019 21:10:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 300928E0004; Thu, 10 Jan 2019 16:10:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2BCAD8E0001; Thu, 10 Jan 2019 16:10:25 -0500 (EST) 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 0B7508E0004; Thu, 10 Jan 2019 16:10:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id BA02C8E0001 for ; Thu, 10 Jan 2019 16:10:24 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id g12so6888151pll.22 for ; Thu, 10 Jan 2019 13:10:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:in-reply-to:references; bh=vioWdbeSIoR0OozY01KK0lWF78M6JuRfZl7Y5n70Vvw=; b=Nca8FaUcR32bGzkF9K7Gj/B9sdEX8VZPZNuhQYGmYVjcP/mXFz9Xi7nPT6WqrZfmAi uHk/f/I7bEPTv4pIzBWrkqecCzqSgomAu4HeDNsinaJTJ9oiPq/IC4wKv9bJ0G7pMfz6 V8vs3jFAcIF8il7V2VK7Ua6i5CEolI0atx8lrxOeFdTTYhca6/tT/PmncWxzZcvK+PLO ykcw7wyHWF9xckcmwrO66/ZL4zjCmghxgDpjuBugVrkYk6nlmEcImtkXrN6Itxc2dpjG rMrhFDuq06G9UKegcqXEJ3+7erZP8geUnQf5I6vGQMSZvu0LzmtaqgM5R3CZ2JjbvSq7 5L7g== X-Gm-Message-State: AJcUukfuepJtjH49sGPNnAruBgOb1w4x+reWEeu+V633CSalTIVJT5l/ qVgAATA7wpx9t86fkwwqKgdJACngecsJ9rBWxRmrnA9gBJe88g5k06FjpwKLVpYYPK2RpH61loG m76DtU/XLV2Ys2TEe86fayQKUfWy279cA/AwVrNTUri9aI1WVN7rzqmXDzt6PQvl+Ig== X-Received: by 2002:a63:8149:: with SMTP id t70mr11048919pgd.172.1547154624409; Thu, 10 Jan 2019 13:10:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN6e4VRQ9gjic1RQJzjsSQaRLhm2HE6KufWoD6EGGPIrmbLfWnqx0SsBaCZAG+qLBIYBbUII X-Received: by 2002:a63:8149:: with SMTP id t70mr11048887pgd.172.1547154623699; Thu, 10 Jan 2019 13:10:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547154623; cv=none; d=google.com; s=arc-20160816; b=CSDq3Ho6euQrWRId33YUx96rOTV4ff+PDnO8QkM9NA8B+E+kALPKW+u7f3iE+7htfD HqsDSNVMfnKxPCco9iPR4f0NVFIdCemxyq4NCzq75uxrWYrB+gFwrQ+pItO28zUqYifr Q0t2qIFZDisvi50WD14/PGTKu5buB7ck17PfRZ0KWSOBCmlwIGakfJlmQo0y3WXLl61K E62HboUuqQP+0dcoXtmddkn5H4x0LwmTjhA4HRNM21n16hb+vxNfmGVkEft8w4FPXcGW G7yj7snIZ1Md8dNEc/HCRxva4vZca/wvVOVZ/1l8CN6tWgYu9W6/QcQTM5zE3/OLPzoz dZHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=vioWdbeSIoR0OozY01KK0lWF78M6JuRfZl7Y5n70Vvw=; b=gv7MynUqyM7n6laQ2kQzWrC+xTSDqEwtp+N2f+I8vZuNmnzNNlNM1UdhgixMaAn8ky 49Eh1M92x9ZuH15Enewd+JvbdRZ+qbHIYVz2tMs7wOVa+zhxCc1gdeeGScMYYgtbaB2E uUFvarw/WQz4ib62Rbtx4XmyND5u82fahoFlJ5B02q9rQ98WtGj+ceI7zQSRQC43lWPm 2AC69bnP6qHZM7nW7u0PHSTmuTU89N5QrKzs0nmtP6x2qfLdG/W0pO+Izw+eyncVIu5G 5I35wpytT6ziBBJMxsaZUv5DFpR21bHx/Sj65WwMHeASiI8AqPhfWu0Qz9g918x6F3+G 34fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="5Zr/H/gs"; spf=pass (google.com: domain of khalid.aziz@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id w22si11275375plp.301.2019.01.10.13.10.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 13:10:23 -0800 (PST) Received-SPF: pass (google.com: domain of khalid.aziz@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="5Zr/H/gs"; spf=pass (google.com: domain of khalid.aziz@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0AL8wlv192939; Thu, 10 Jan 2019 21:10:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2018-07-02; bh=vioWdbeSIoR0OozY01KK0lWF78M6JuRfZl7Y5n70Vvw=; b=5Zr/H/gs7twRt1V1n7f/N4i72M7pDnfRyfW0SUEfU98nSjEVYXxaduRQfIFkOZ6eq9bE Wzu617vgw5kLC4psr9ydthh8fmY5vK4bwus1PBTaPdZF1pGR6WhU4lx60h3LxRUoEm/p F2MDs5KH7KdTR41o9aA93516uC8aal6RSREan5kxOy2iKlRKByWtG1L1NBJulWT8GgLu AY/LoTA2h3dnTJguFAfeS4rtoH1zSOtCclYaxScjEwsOKPC+aLTaafHAlgn74lP4SFxO OZ08qhM39REMSVoQ1McWy+qzIh1yhDGGBR6wbaHbcS7p15iZIaHqZKea3yWNhdfc5ov4 EA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2ptn7r9f32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Jan 2019 21:10:17 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0ALABba027157 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Jan 2019 21:10:11 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0ALAAui021114; Thu, 10 Jan 2019 21:10:10 GMT Received: from concerto.internal (/24.9.64.241) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 10 Jan 2019 13:10:10 -0800 From: Khalid Aziz To: juergh@gmail.com, tycho@tycho.ws, jsteckli@amazon.de, ak@linux.intel.com, torvalds@linux-foundation.org, liran.alon@oracle.com, keescook@google.com, konrad.wilk@oracle.com Cc: Tycho Andersen , deepa.srinivasan@oracle.com, chris.hyser@oracle.com, tyhicks@canonical.com, dwmw@amazon.co.uk, andrew.cooper3@citrix.com, jcm@redhat.com, boris.ostrovsky@oracle.com, kanth.ghatraju@oracle.com, joao.m.martins@oracle.com, jmattson@google.com, pradeep.vincent@oracle.com, john.haxby@oracle.com, tglx@linutronix.de, kirill.shutemov@linux.intel.com, hch@lst.de, steven.sistare@oracle.com, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Khalid Aziz Subject: [RFC PATCH v7 01/16] mm: add MAP_HUGETLB support to vm_mmap Date: Thu, 10 Jan 2019 14:09:33 -0700 Message-Id: <5b692498fde91fe22181cdb6ed20f058f598fb43.1547153058.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9132 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901100164 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Tycho Andersen vm_mmap is exported, which means kernel modules can use it. In particular, for testing XPFO support, we want to use it with the MAP_HUGETLB flag, so let's support it via vm_mmap. Signed-off-by: Tycho Andersen Tested-by: Marco Benatto Signed-off-by: Khalid Aziz --- include/linux/mm.h | 2 ++ mm/mmap.c | 19 +------------------ mm/util.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5411de93a363..30bddc7b3c75 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2361,6 +2361,8 @@ struct vm_unmapped_area_info { extern unsigned long unmapped_area(struct vm_unmapped_area_info *info); extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info); +struct file *map_hugetlb_setup(unsigned long *len, unsigned long flags); + /* * Search for an unmapped address range. * diff --git a/mm/mmap.c b/mm/mmap.c index 6c04292e16a7..c668d7d27c2b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1582,24 +1582,7 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len, if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file))) goto out_fput; } else if (flags & MAP_HUGETLB) { - struct user_struct *user = NULL; - struct hstate *hs; - - hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); - if (!hs) - return -EINVAL; - - len = ALIGN(len, huge_page_size(hs)); - /* - * VM_NORESERVE is used because the reservations will be - * taken when vm_ops->mmap() is called - * A dummy user value is used because we are not locking - * memory so no accounting is necessary - */ - file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, - VM_NORESERVE, - &user, HUGETLB_ANONHUGE_INODE, - (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); + file = map_hugetlb_setup(&len, flags); if (IS_ERR(file)) return PTR_ERR(file); } diff --git a/mm/util.c b/mm/util.c index 8bf08b5b5760..536c14cf88ba 100644 --- a/mm/util.c +++ b/mm/util.c @@ -357,6 +357,29 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, return ret; } +struct file *map_hugetlb_setup(unsigned long *len, unsigned long flags) +{ + struct user_struct *user = NULL; + struct hstate *hs; + + hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); + if (!hs) + return ERR_PTR(-EINVAL); + + *len = ALIGN(*len, huge_page_size(hs)); + + /* + * VM_NORESERVE is used because the reservations will be + * taken when vm_ops->mmap() is called + * A dummy user value is used because we are not locking + * memory so no accounting is necessary + */ + return hugetlb_file_setup(HUGETLB_ANON_FILE, *len, + VM_NORESERVE, + &user, HUGETLB_ANONHUGE_INODE, + (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); +} + unsigned long vm_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flag, unsigned long offset) @@ -366,6 +389,15 @@ unsigned long vm_mmap(struct file *file, unsigned long addr, if (unlikely(offset_in_page(offset))) return -EINVAL; + if (flag & MAP_HUGETLB) { + if (file) + return -EINVAL; + + file = map_hugetlb_setup(&len, flag); + if (IS_ERR(file)) + return PTR_ERR(file); + } + return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT); } EXPORT_SYMBOL(vm_mmap);