Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2495287imu; Thu, 10 Jan 2019 15:25:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN7YPugrEO9GyOvflw/7/MLFA2rgfWUX3apweN8t1MUsxf/TVtRY31hvVPZ7tMWk19Uwyv2J X-Received: by 2002:a63:4926:: with SMTP id w38mr10731349pga.353.1547162721980; Thu, 10 Jan 2019 15:25:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547162721; cv=none; d=google.com; s=arc-20160816; b=tlIvubljUeXmcUN9/nTqXSYz5csB3yrZsLowwt4eHG6/UghJqjhGS2wrSyeSbkHP/z CeFnkZrW8UCSw1SSrWLF5WqJW81d6ya+eq/lhdFG4d3ZAUkc5yj4LFWoIvXsAXRH80aZ KLLQAOCbAKE8Yat/+X2NxGZuMZwuRx9JF1vo5rEhTBNmBRogJEC5osUkNvqu8hkWL9O0 9z+7AURB0CsLrDrNU2JCKPQLNblmxXn7dWP4uAU0G4Ig8JkxcCrV1z1t6DTIrxE9PntX acwVmwopUTBsz64efOhZhgw5CpcBfB92/FA/hCzH0kYf9miS+IK1LNX1nhmZSxVntKgA AhLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=vioWdbeSIoR0OozY01KK0lWF78M6JuRfZl7Y5n70Vvw=; b=b/1Caeh194V2tVwsAdOvnoGljj4kBhwW5OXmHqIymDOuaNig8rGHoMnyf6+SofMpp0 O7K/Josql5VC40hBw6FnGzxdyGG++EhNsSdy59zUrlxnuf9NaEKVvSgfM5478H8u15cX JAdbeoipCNSNLQ6YPC65w9q7T3PuocGTur0NcYRoxYSvQ5yLTLZxy5NvDGEoWtthF20f 7M4fnegt3jYp2Nr1/C4mP+im/kvDrKPQoggiEgLIIKEkfuEuZhtmq3CliQe0SoLwKe4V LxmYd7qnriXhT4Itm/qZPYn1bGhJCZGIGgpXnPkkO1onpMC7iyXkU57xZ573Xr3DBBYD mGHg== 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: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si66876852pgm.21.2019.01.10.15.25.05; Thu, 10 Jan 2019 15:25:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; 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: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730349AbfAJVKz (ORCPT + 99 others); Thu, 10 Jan 2019 16:10:55 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:50710 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729343AbfAJVKz (ORCPT ); Thu, 10 Jan 2019 16:10:55 -0500 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1