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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 AF146C432BE for ; Fri, 20 Aug 2021 18:19:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62FCF61278 for ; Fri, 20 Aug 2021 18:19:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 62FCF61278 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 054D58D0002; Fri, 20 Aug 2021 14:18:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7F68D000F; Fri, 20 Aug 2021 14:18:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4CB98D0002; Fri, 20 Aug 2021 14:18:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id A7A788D000F for ; Fri, 20 Aug 2021 14:18:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5C27D2DD80 for ; Fri, 20 Aug 2021 18:18:53 +0000 (UTC) X-FDA: 78496270146.01.5009761 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf27.hostedemail.com (Postfix) with ESMTP id 8DCAE7000091 for ; Fri, 20 Aug 2021 18:18:52 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10082"; a="197075213" X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="197075213" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:50 -0700 X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="533074758" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:50 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , Rick P Edgecombe Cc: Yu-cheng Yu , Peter Collingbourne , "Kirill A . Shutemov" , Andrew Morton Subject: [PATCH v29 22/32] mm: Re-introduce vm_flags to do_mmap() Date: Fri, 20 Aug 2021 11:11:51 -0700 Message-Id: <20210820181201.31490-23-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210820181201.31490-1-yu-cheng.yu@intel.com> References: <20210820181201.31490-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf27.hostedemail.com: domain of yu-cheng.yu@intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=yu-cheng.yu@intel.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8DCAE7000091 X-Stat-Signature: th71kn9nmw6mizdcmh6enmt96oiyzq1a X-HE-Tag: 1629483532-423726 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: There was no more caller passing vm_flags to do_mmap(), and vm_flags was removed from the function's input by: commit 45e55300f114 ("mm: remove unnecessary wrapper function do_mmap= _pgoff()"). There is a new user now. Shadow stack allocation passes VM_SHADOW_STACK = to do_mmap(). Thus, re-introduce vm_flags to do_mmap(). Signed-off-by: Yu-cheng Yu Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Cc: Andrew Morton Cc: Oleg Nesterov Cc: linux-mm@kvack.org --- fs/aio.c | 2 +- include/linux/mm.h | 3 ++- ipc/shm.c | 2 +- mm/mmap.c | 10 +++++----- mm/nommu.c | 4 ++-- mm/util.c | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 76ce0cc3ee4e..92e09b0863ad 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -526,7 +526,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigne= d int nr_events) =20 ctx->mmap_base =3D do_mmap(ctx->aio_ring_file, 0, ctx->mmap_size, PROT_READ | PROT_WRITE, - MAP_SHARED, 0, &unused, NULL); + MAP_SHARED, 0, 0, &unused, NULL); mmap_write_unlock(mm); if (IS_ERR((void *)ctx->mmap_base)) { ctx->mmap_size =3D 0; diff --git a/include/linux/mm.h b/include/linux/mm.h index 354f38d21eed..07e642af59d3 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2617,7 +2617,8 @@ extern unsigned long mmap_region(struct file *file,= unsigned long addr, struct list_head *uf); extern unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, - unsigned long pgoff, unsigned long *populate, struct list_head *uf); + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, + struct list_head *uf); extern int __do_munmap(struct mm_struct *, unsigned long, size_t, struct list_head *uf, bool downgrade); extern int do_munmap(struct mm_struct *, unsigned long, size_t, diff --git a/ipc/shm.c b/ipc/shm.c index 748933e376ca..fb7a3a230b79 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1556,7 +1556,7 @@ long do_shmat(int shmid, char __user *shmaddr, int = shmflg, goto invalid; } =20 - addr =3D do_mmap(file, addr, size, prot, flags, 0, &populate, NULL); + addr =3D do_mmap(file, addr, size, prot, flags, 0, 0, &populate, NULL); *raddr =3D addr; err =3D 0; if (IS_ERR_VALUE(addr)) diff --git a/mm/mmap.c b/mm/mmap.c index 6be9ff4007ab..100db6e46831 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1406,11 +1406,11 @@ static inline bool file_mmap_ok(struct file *file= , struct inode *inode, */ unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, - unsigned long flags, unsigned long pgoff, - unsigned long *populate, struct list_head *uf) + unsigned long flags, vm_flags_t vm_flags, + unsigned long pgoff, unsigned long *populate, + struct list_head *uf) { struct mm_struct *mm =3D current->mm; - vm_flags_t vm_flags; int pkey =3D 0; =20 *populate =3D 0; @@ -1470,7 +1470,7 @@ unsigned long do_mmap(struct file *file, unsigned l= ong addr, * to. we assume access permissions have been handled by the open * of the memory object, so we don't do any here. */ - vm_flags =3D calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | + vm_flags |=3D calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) = | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; =20 if (flags & MAP_LOCKED) @@ -3036,7 +3036,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, st= art, unsigned long, size, =20 file =3D get_file(vma->vm_file); ret =3D do_mmap(vma->vm_file, start, size, - prot, flags, pgoff, &populate, NULL); + prot, flags, 0, pgoff, &populate, NULL); fput(file); out: mmap_write_unlock(mm); diff --git a/mm/nommu.c b/mm/nommu.c index 3a93d4054810..5b6dcf42659a 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1061,6 +1061,7 @@ unsigned long do_mmap(struct file *file, unsigned long len, unsigned long prot, unsigned long flags, + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, struct list_head *uf) @@ -1068,7 +1069,6 @@ unsigned long do_mmap(struct file *file, struct vm_area_struct *vma; struct vm_region *region; struct rb_node *rb; - vm_flags_t vm_flags; unsigned long capabilities, result; int ret; =20 @@ -1087,7 +1087,7 @@ unsigned long do_mmap(struct file *file, =20 /* we've determined that we can make the mapping, now translate what we * now know into VMA flags */ - vm_flags =3D determine_vm_flags(file, prot, flags, capabilities); + vm_flags |=3D determine_vm_flags(file, prot, flags, capabilities); =20 /* we're going to need to record the mapping */ region =3D kmem_cache_zalloc(vm_region_jar, GFP_KERNEL); diff --git a/mm/util.c b/mm/util.c index 9043d03750a7..9db194fc2030 100644 --- a/mm/util.c +++ b/mm/util.c @@ -516,7 +516,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsign= ed long addr, if (!ret) { if (mmap_write_lock_killable(mm)) return -EINTR; - ret =3D do_mmap(file, addr, len, prot, flag, pgoff, &populate, + ret =3D do_mmap(file, addr, len, prot, flag, 0, pgoff, &populate, &uf); mmap_write_unlock(mm); userfaultfd_unmap_complete(mm, &uf); --=20 2.21.0