From patchwork Fri Jun 16 19:17:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 109331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1567951vqr; Fri, 16 Jun 2023 12:29:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AYBjQWoOvTBRCj9oa2IkqE2CoXKQJWhM+cNQB11cSu7big1glp21gNonndI2LGim/85sn X-Received: by 2002:a05:6a00:24cd:b0:64d:1451:8233 with SMTP id d13-20020a056a0024cd00b0064d14518233mr3272231pfv.21.1686943787842; Fri, 16 Jun 2023 12:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686943787; cv=none; d=google.com; s=arc-20160816; b=KqiQ5zZmeh1NtL16Ws0wfrd/fuVuaErOttkqoDg99Qvhymu80R8m2/hXltxUrnVQS1 zdZUIfGbFntJ5K/vNU/olKQQBBdSKHrd4ZBX3fLBb1qyWJIUamRwJhLwGOwVL21bTv+p EeTFmxjpzNwV4t/unK1oyHHA3pbxchz3Gu86bsw1DEGG+Z0HWkEMHtFLIQ03Bsx8+gT2 1LFSJbDNxaZ9vkmc7lEhwR/U+mGpR3Hx57+7BaT1RLuSx/LFmxSHuytdH9nU/bijptyh tWgaTVJR7BTFLiwjPUayJDINXVRxmPfZzmeV226bknBbrC/bNtdli2xyxI9qu/T6fyvr kFvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=3qIsA3KzVuUjGLhAx9GQVwkb/1qkVdZ7BJRtY1JfcOg=; b=gkiWUrqf1iOVLVckftmi5rs9T3KZ4wCXFqPdNBiFRP25bVEocHo4w2PV3MyArxz3yP BInyue4aRjfKNLh9Y9Z/dW2o8+k/mIFpNXJvtUkGTJSz8JcY/vgfYrcTRxxN1mR+AGms R+oNldvWsjnEI2ZdvhEFShGJhbeg0ttZMyp9kLjo/gBHmDiTf0BQ3PVFvxPO8UypOTaT XBW5XBPw5+FZvDQgkuBltRUJh98+OztIfQ3akIwSwvHFxAoijCOXJOx+Z6yCdxKurvPs wNzzL7JXjqiGCHDyVrQ9sxNh4pSOOUpXL7Vnrla9dM+h4Eh590xMw9qAF6ic23aFtBoW oM+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AnMCeSF6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=1IUucDc0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d10-20020a63734a000000b005347aba7376si15578645pgn.297.2023.06.16.12.29.28; Fri, 16 Jun 2023 12:29:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AnMCeSF6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=1IUucDc0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346211AbjFPTTp (ORCPT + 99 others); Fri, 16 Jun 2023 15:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjFPTRV (ORCPT ); Fri, 16 Jun 2023 15:17:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE0B3C11; Fri, 16 Jun 2023 12:17:08 -0700 (PDT) Date: Fri, 16 Jun 2023 19:17:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686943026; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3qIsA3KzVuUjGLhAx9GQVwkb/1qkVdZ7BJRtY1JfcOg=; b=AnMCeSF6EI8A0/Tm87/g7iNwSmDe5q3MknFe1eO4bhNNw9Kci0QvY3hhGuA/3RkIeW+9YM OkPATMhCUChZjBzvhxeSjYUn7rbrKvABmpihxBnnaST64LGUcy+y1EI5/PmxqzRCfTkC41 3TZa8q+AMVXr6pJQNP+3UTX92K4WbLHjDCTQihagZ9KCO3jrCVKXN098zCcJNEG1JwpdCm VOiBwvXo29vTh4v9C1tsSGUhyDPpLUkiOL1dLaFD1cc72rQL0LuxfXq08SeKx84SDPGooL ZMwnT7o6B9paQmOGRmrhMYlmz6/KqHl9NiOL2OSElAVVwk0OQdFKMUFzcl7NxQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686943026; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3qIsA3KzVuUjGLhAx9GQVwkb/1qkVdZ7BJRtY1JfcOg=; b=1IUucDc0OV/fzjXHGAZi0UgYGfE4pnde7aLpt60qaHd/t9M3Dp4yZ1LXtJRJQBqHu8Lcw/ ta7EOsYx7AqQVmDg== From: "tip-bot2 for Yu-cheng Yu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] mm: Re-introduce vm_flags to do_mmap() Cc: "Yu-cheng Yu" , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Peter Collingbourne , Kees Cook , "Kirill A. Shutemov" , Mark Brown , "Mike Rapoport (IBM)" , David Hildenbrand , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168694302617.404.12391899174093801532.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768888769224666302?= X-GMAIL-MSGID: =?utf-8?q?1768888769224666302?= The following commit has been merged into the x86/shstk branch of tip: Commit-ID: c971cc5fba31171ca6c34c88b7689dc9743b9cc3 Gitweb: https://git.kernel.org/tip/c971cc5fba31171ca6c34c88b7689dc9743b9cc3 Author: Yu-cheng Yu AuthorDate: Mon, 12 Jun 2023 17:10:30 -07:00 Committer: Dave Hansen CommitterDate: Thu, 15 Jun 2023 16:31:00 -07:00 mm: Re-introduce vm_flags to do_mmap() 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(). Co-developed-by: Rick Edgecombe Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Reviewed-by: Mark Brown Acked-by: Mike Rapoport (IBM) Acked-by: David Hildenbrand Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Tested-by: Mark Brown Link: https://lore.kernel.org/all/20230613001108.3040476-5-rick.p.edgecombe%40intel.com --- 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 b0b17bd..4a75769 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -558,7 +558,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ctx->mmap_base = 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 = 0; diff --git a/include/linux/mm.h b/include/linux/mm.h index 43701bf..9ec20cb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3133,7 +3133,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_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool downgrade); diff --git a/ipc/shm.c b/ipc/shm.c index 60e45e7..576a543 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1662,7 +1662,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, goto invalid; } - addr = do_mmap(file, addr, size, prot, flags, 0, &populate, NULL); + addr = do_mmap(file, addr, size, prot, flags, 0, 0, &populate, NULL); *raddr = addr; err = 0; if (IS_ERR_VALUE(addr)) diff --git a/mm/mmap.c b/mm/mmap.c index 13678ed..afdf5f7 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1221,11 +1221,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 = current->mm; - vm_flags_t vm_flags; int pkey = 0; validate_mm(mm); @@ -1286,7 +1286,7 @@ unsigned long do_mmap(struct file *file, unsigned long 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 = calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | + vm_flags |= calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; if (flags & MAP_LOCKED) @@ -2903,7 +2903,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, file = get_file(vma->vm_file); ret = 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 f670d99..138826c 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1002,6 +1002,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) @@ -1009,7 +1010,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; VMA_ITERATOR(vmi, current->mm, 0); @@ -1029,7 +1029,7 @@ unsigned long do_mmap(struct file *file, /* we've determined that we can make the mapping, now translate what we * now know into VMA flags */ - vm_flags = determine_vm_flags(file, prot, flags, capabilities); + vm_flags |= determine_vm_flags(file, prot, flags, capabilities); /* we're going to need to record the mapping */ diff --git a/mm/util.c b/mm/util.c index dd12b95..8e7fc6c 100644 --- a/mm/util.c +++ b/mm/util.c @@ -540,7 +540,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, if (!ret) { if (mmap_write_lock_killable(mm)) return -EINTR; - ret = do_mmap(file, addr, len, prot, flag, pgoff, &populate, + ret = do_mmap(file, addr, len, prot, flag, 0, pgoff, &populate, &uf); mmap_write_unlock(mm); userfaultfd_unmap_complete(mm, &uf);