Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp78772pxf; Tue, 23 Mar 2021 22:50:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgmK3T3sV/d1BhIEUHx3D0acU9TqLY7jBVOak5LmdZTjUuvbGVX/VwASfLL67TT7OOtyCQ X-Received: by 2002:a05:6402:158d:: with SMTP id c13mr1505325edv.297.1616565050436; Tue, 23 Mar 2021 22:50:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616565050; cv=none; d=google.com; s=arc-20160816; b=m6S2JiMI/ZaIDGqk6IVqapM5X0i++aZh7O58O/a0FmjNqyZQoa9Xo49ZsExptWPpRz 5S/QwPcFS9mCzotci5q9mwaZxhwq8q8rMPEJyjU6rTJK2XzXM/LTu6d63AmcYOxhvhCG YKqnIaCkTLBecfooGbEPW9DqxIQVleDhbwCJ4CTMA2oYqHBLF0/8tRctRQhKhqjdHx2T JYJFlfsGLXQyItvlykaJqVyLoMbMwp8BRMNYU95pqLyeAqSTFFHOUZsvIw63qWXe4+mG ZeW4UqBS4uIK5gtfh4muiLT8uYUVg58C4oOZYj7qlhsw3INvAw87ISel4K1hmXxPQN4v hxFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=h1kYRY8AwyqIQ4kqqiLp5b/6u7yV7ANW049MKdfQVdg=; b=MvaPZtRX6NR+B8LNcuKFJT2+8aNWdcDFOanDpyAJKvlzgFslGKDGfCOT4c/9f/2Wx9 kibMmQhbPh0PWcr7RjraTRwKNKopY6ZglARn70zIFl2tjHjOV9Xvyzc6A+X7dnjqe4Tw tlANHAkGxS6dOgrFrxnX1EKJrWx0yBZrkXnVr9oyH37EqGjnvPCX+fqlcfuKjQTN01gJ FoYF/+5AiuIBh9buPiEhaCJH4mIv8xpqyD4km5lYcpk98nLsMLPk3f6w++SVO9JXJgyg HLym8A3dBu0MDioWSGxPltExMLHSZwBtpMKG9l6Z5e6V0yn8xNTAMKan4Ys8fZUJ2puV HLbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VdWRG2j7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u16si922817ejy.630.2021.03.23.22.50.28; Tue, 23 Mar 2021 22:50:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VdWRG2j7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233232AbhCWQ0w (ORCPT + 99 others); Tue, 23 Mar 2021 12:26:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233062AbhCWQ0V (ORCPT ); Tue, 23 Mar 2021 12:26:21 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D093C061574 for ; Tue, 23 Mar 2021 09:26:21 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b127so3112793ybc.13 for ; Tue, 23 Mar 2021 09:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=h1kYRY8AwyqIQ4kqqiLp5b/6u7yV7ANW049MKdfQVdg=; b=VdWRG2j7HcJm5QzBfljdapciRilN8CcW+XERsTmrqR+VQGLKfLF2WoSMukNI7OwrFn j+36dqfjjthvxuoyUTJHAn9mHRcSgOvKg2RisLZnyMZWV7n/SlTcDU+cMZr3vh+wb3T+ 9noHhOIqF4ip2WZlydmrsYRAsBCCwuochvPz97K5+dmWm9UpaCtkYlCH1OnuBeGQbTMg 7wr1FoVPCZqdhsWEqVnjlIxig62LtTxJilm4PPJmwIi4RS/3wDlZi3Lvhq3847voc4wZ ncRw5k6hpnuBgjy86YY475rOUC8usJH5ynYT6sRcd966LLAvTRZs+VP+NjogEFXqcEjz Y4ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=h1kYRY8AwyqIQ4kqqiLp5b/6u7yV7ANW049MKdfQVdg=; b=hSCwAJ1gNXjzOnOa9JUkTaJt1Yo95NSScBcv9p7cZ2mFm1DXHWFDwsja3FndlufNFY TcHQXpK0tBWllwrXzgiNaeuBooNBD2iJsnA3A6QDpeMLxxEt6MzXxbyWEpyQ8OR6Mxez kqA3nu7abmtfccggwTAGfmGEs4GQRJ6KxmDPFjC268gd5/HiFA/xet7nJ3BmI2C3pk7N GhcDEvuDwSOrOKNyAWJC7N5w5yNKFKAFK6U9KasDgKrOWkhPgGok0BK727HB2XBTQLiB CGuYzsOF1FrLEPZ/I2J23NJhrkP6H1pPIK5qXfmUZsHPCm/rx+167ktQwg0dh5NTdCN3 KLpg== X-Gm-Message-State: AOAM532LWIjVF6uX8cf1U3mFIpwpmRLO27PKxOCvkjfcLQpEWh4Hvh3G ej4WnuVN/QTF/qiLWECdv5QekYCMOuNr X-Received: from bg.sfo.corp.google.com ([2620:15c:8:10:b5cc:cacb:2875:ae6e]) (user=bgeffon job=sendgmr) by 2002:a25:e0d7:: with SMTP id x206mr6741316ybg.159.1616516780251; Tue, 23 Mar 2021 09:26:20 -0700 (PDT) Date: Tue, 23 Mar 2021 09:26:09 -0700 In-Reply-To: <20210323162611.2398613-1-bgeffon@google.com> Message-Id: <20210323162611.2398613-2-bgeffon@google.com> Mime-Version: 1.0 References: <20210303175235.3308220-1-bgeffon@google.com> <20210323162611.2398613-1-bgeffon@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v4 2/3] Revert "mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio" From: Brian Geffon To: Andrew Morton Cc: Axel Rasmussen , Lokesh Gidra , Mike Rapoport , Peter Xu , Hugh Dickins , "Michael S . Tsirkin" , Brian Geffon , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andy Lutomirski , Vlastimil Babka , Andrea Arcangeli , Sonny Rao , Minchan Kim , "Kirill A . Shutemov" , Dmitry Safonov , Michael Kerrisk , Alejandro Colomar Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This reverts commit cd544fd1dc9293c6702fab6effa63dac1cc67e99. As discussed in [1] this commit was a no-op because the mapping type was checked in vma_to_resize before move_vma is ever called. This meant that vm_ops->mremap() would never be called on such mappings. Furthermore, we've since expanded support of MREMAP_DONTUNMAP to non-anonymous mappings, and these special mappings are still protected by the existing check of !VM_DONTEXPAND and !VM_PFNMAP which will result in a -EFAULT. 1. https://lkml.org/lkml/2020/12/28/2340 Signed-off-by: Brian Geffon Acked-by: Hugh Dickins --- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- fs/aio.c | 5 +---- include/linux/mm.h | 2 +- mm/mmap.c | 6 +----- mm/mremap.c | 2 +- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index e916646adc69..0daf2f1cf7a8 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -1458,7 +1458,7 @@ static int pseudo_lock_dev_release(struct inode *inode, struct file *filp) return 0; } -static int pseudo_lock_dev_mremap(struct vm_area_struct *area, unsigned long flags) +static int pseudo_lock_dev_mremap(struct vm_area_struct *area) { /* Not supported */ return -EINVAL; diff --git a/fs/aio.c b/fs/aio.c index 1f32da13d39e..76ce0cc3ee4e 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -323,16 +323,13 @@ static void aio_free_ring(struct kioctx *ctx) } } -static int aio_ring_mremap(struct vm_area_struct *vma, unsigned long flags) +static int aio_ring_mremap(struct vm_area_struct *vma) { struct file *file = vma->vm_file; struct mm_struct *mm = vma->vm_mm; struct kioctx_table *table; int i, res = -EINVAL; - if (flags & MREMAP_DONTUNMAP) - return -EINVAL; - spin_lock(&mm->ioctx_lock); rcu_read_lock(); table = rcu_dereference(mm->ioctx_table); diff --git a/include/linux/mm.h b/include/linux/mm.h index 64a71bf20536..ecdc6e8dc5af 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -570,7 +570,7 @@ struct vm_operations_struct { void (*close)(struct vm_area_struct * area); /* Called any time before splitting to check if it's allowed */ int (*may_split)(struct vm_area_struct *area, unsigned long addr); - int (*mremap)(struct vm_area_struct *area, unsigned long flags); + int (*mremap)(struct vm_area_struct *area); /* * Called by mprotect() to make driver-specific permission * checks before mprotect() is finalised. The VMA must not diff --git a/mm/mmap.c b/mm/mmap.c index 3f287599a7a3..9d7651e4e1fe 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3403,14 +3403,10 @@ static const char *special_mapping_name(struct vm_area_struct *vma) return ((struct vm_special_mapping *)vma->vm_private_data)->name; } -static int special_mapping_mremap(struct vm_area_struct *new_vma, - unsigned long flags) +static int special_mapping_mremap(struct vm_area_struct *new_vma) { struct vm_special_mapping *sm = new_vma->vm_private_data; - if (flags & MREMAP_DONTUNMAP) - return -EINVAL; - if (WARN_ON_ONCE(current->mm != new_vma->vm_mm)) return -EFAULT; diff --git a/mm/mremap.c b/mm/mremap.c index db5b8b28c2dd..d22629ff8f3c 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -545,7 +545,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (moved_len < old_len) { err = -ENOMEM; } else if (vma->vm_ops && vma->vm_ops->mremap) { - err = vma->vm_ops->mremap(new_vma, flags); + err = vma->vm_ops->mremap(new_vma); } if (unlikely(err)) { -- 2.31.0.rc2.261.g7f71774620-goog