From patchwork Mon Mar 20 16:39:25 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: 72287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1321976wrt; Mon, 20 Mar 2023 09:53:49 -0700 (PDT) X-Google-Smtp-Source: AK7set/Omv6qC/cLOP7zLOyqeaWKCLzFISDOkKjoMIB2IBnv5jszST+NMABzzOtxn+BVUDCRtMNZ X-Received: by 2002:aa7:9ecf:0:b0:626:2ab1:19a8 with SMTP id r15-20020aa79ecf000000b006262ab119a8mr11417179pfq.25.1679331229548; Mon, 20 Mar 2023 09:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679331229; cv=none; d=google.com; s=arc-20160816; b=cuGgU8tFKqJCvH5RCdbtWMIRCiGmPIH70qlxS4yae2DUTyM6480fbu+DPdmh7YYZrp HNM1WQh2UyqSs3P2G7FnbNBQmtkWwmrQNJMRTyAcPQIZ+SSj6HniahgoKAR35xpMhiai D0+vslHsdsdXgRIuQQcpkS9URx7Y21MaubEnKVqUSGbY9oWIKYmJJeIb/wCqblfNm56x nQiKQS4lVooYKupO/6xDOvQF8+IVmC8TY/Gt+T6C29rPbyOf+sKgTOAnuZOq3rr5U45e K1zaWTID804cT4I9jnLD8qtC/qN5XUN+R6s41Z8c8+y29pYt1BqLM12dGhXYHKUvtjOJ YmCg== 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=laeci0KkKtnqR+mjGV4D1/Gz76DvqkQGVaIfInGPqts=; b=qKfpD/DneNoGXakqOpS7QlW3Ihaf7BuoLe+guPvw+EzotBHUm9IUUSauiMdYZPK7EO hGxU4O+ICL4T1kkiC4DY22UqYzBZ+BtGJ+F+pHjcqI6EOHSQLeVe3wMDe7gFwK0CvPP7 gIZ547oOxLMgNWNARmvSPumj+gZYSlMkzZnwaYsdFnEsNYqjE0hpD4sPz5JdXY8//GQH xGuIwOwh/eOyZRuBkV0NSA0EZEzR5586iNgKO7JK1cyI81vMAW6PNyFr9TNJZmFrXwDo HO9n5LCSg9Y1DEoh+IAUiZ6MROUlwhMsEbWIFeYGw9bIGPP77cu6lskHIyY/0mkXoOup K+YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YEXAy2Ol; dkim=neutral (no key) header.i=@linutronix.de; 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 w185-20020a6362c2000000b004fbc2116e0esi11702950pgb.205.2023.03.20.09.53.35; Mon, 20 Mar 2023 09:53:49 -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=YEXAy2Ol; dkim=neutral (no key) header.i=@linutronix.de; 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 S232127AbjCTQrn (ORCPT + 99 others); Mon, 20 Mar 2023 12:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbjCTQrN (ORCPT ); Mon, 20 Mar 2023 12:47:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2BF635269; Mon, 20 Mar 2023 09:40:53 -0700 (PDT) Date: Mon, 20 Mar 2023 16:39:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679330365; 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=laeci0KkKtnqR+mjGV4D1/Gz76DvqkQGVaIfInGPqts=; b=YEXAy2Ole/EMbixIeuGsJLk8tmIL6EApEEsfaiOX+8rX99vmV1rGoNaxgue5lz6Z+TWg8U E1CknIcWVM9/qpZaFA9Pw7eMcBCj2OZE7IThe2i9duc1YWkhVEEPol8rnESc3ttyIKdRmC 4kisxqhuZcwB1LgzfvfLEhsinHv7BYpBV17E3KaXuZr0cgwFOfG6cHBZh7/WZl8JRbEwdP yMDHGLDJ2UZPKWmfHakjDoCLovHJU4j1IIOEumEmhWXWgqOcW1ocfBJPp1eLZLQR+QgDKK 031cth1BEr7tejPPOkd6/EZf0imOU7zrLjEpu2AMRIjs7p6ObiayFtwGXSWcVw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679330365; 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=laeci0KkKtnqR+mjGV4D1/Gz76DvqkQGVaIfInGPqts=; b=dmTjXRlOhVV5gTeo4M0KNyM+8TGrSLGmvSssfD/iutWsiPlwnHP6GqvSKJtUi2Ag9bBpUC CMUsxa59D6n+fCAQ== 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" , "Mike Rapoport (IBM)" , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <167933036502.5837.16822365499771501704.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 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?1760906423260916637?= X-GMAIL-MSGID: =?utf-8?q?1760906423260916637?= The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 0cac1da5886c58d3d2a855baa9dab8775f3bd592 Gitweb: https://git.kernel.org/tip/0cac1da5886c58d3d2a855baa9dab8775f3bd592 Author: Yu-cheng Yu AuthorDate: Sat, 18 Mar 2023 17:15:18 -07:00 Committer: Dave Hansen CommitterDate: Mon, 20 Mar 2023 09:01:10 -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 Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230319001535.23210-24-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 d09fbe9..d389198 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3043,7 +3043,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 740b54b..e2c8e8e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1191,11 +1191,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); @@ -1256,7 +1256,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) @@ -2829,7 +2829,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 57ba243..f6ddd08 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 b8ed9db..a93e832 100644 --- a/mm/util.c +++ b/mm/util.c @@ -539,7 +539,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);