From patchwork Mon Jul 24 18:54:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13325265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1DABC00528 for ; Mon, 24 Jul 2023 18:54:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7085F6B0081; Mon, 24 Jul 2023 14:54:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6913D6B0082; Mon, 24 Jul 2023 14:54:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 559448E0001; Mon, 24 Jul 2023 14:54:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 470E36B0081 for ; Mon, 24 Jul 2023 14:54:38 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2410B160B1F for ; Mon, 24 Jul 2023 18:54:38 +0000 (UTC) X-FDA: 81047406636.21.FBBDCAD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 7F9F240011 for ; Mon, 24 Jul 2023 18:54:36 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=T5WZLqos; spf=none (imf04.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690224876; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3AerkyW6jQd6y4z+nJVqv9X/P9KyvfBPmyU8zyX0gIY=; b=6/DbNWXhdYWLlPf5cW1TfcsqhlXy1E0MyUV4/AowFp9+NgYSEb6u9z11vniH6Ye+5Eq82k IRXoxl3Z7csqiakDo5kse9HFk52/ydwnufSvUWLTPvX2IAGWVhgY26S3iGQgjNeLine/6z 8gVoSx28c/e2h4RSpqTSge6lLyeVV5I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690224876; a=rsa-sha256; cv=none; b=fJeDHxCbOyka3Ca7r/Exgdvd+5xW2vcxYK4CqI0FYQd6dapoiFrMYYG1hLsfDdgSaXZ5QO 81H5SUUw+GzTDOq43/YUOtVPuYX0S5U31nD2AKG6zY/+/wRa4n/LfR/1AzoFPwb0KK0F8S hRi3qLTA4nhJuQVE69oWbVzA1qDWQGw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=T5WZLqos; spf=none (imf04.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=3AerkyW6jQd6y4z+nJVqv9X/P9KyvfBPmyU8zyX0gIY=; b=T5WZLqosM499I02fiX0L+Oh2WN UVgaWQNODE3toYL7Hkf9TqP02b83nLnWZK0d16D8E2EBKem+n5svfi/BWGCMHr9+JqGgq9wSB2cUZ Ul2RAEhjDKUkApuBDNwSO4vEr1GQ0rCAqJg/tEc/UP5d6/RpdIbRYVXtlvVBCJdZzViD0p6t3MFTR W2zX2H9kNr37fSa1DoYb3/SnNFsASa0KmyalF7lugxtR93Ykk3scERqFti65kmwu26eMSGo7evEHg ES2YTHDMR7hSv6+QZd3gF6jnzLamcbnFtqXQuCMCsUrYKjAotodfYGgMlts3LXVKYhDeRDybzsjUI 9t1fww6Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qO0hA-004iR3-4n; Mon, 24 Jul 2023 18:54:12 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Punit Agrawal , Suren Baghdasaryan , Arjun Roy , Eric Dumazet Subject: [PATCH v3 02/10] mm: Allow per-VMA locks on file-backed VMAs Date: Mon, 24 Jul 2023 19:54:02 +0100 Message-Id: <20230724185410.1124082-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230724185410.1124082-1-willy@infradead.org> References: <20230724185410.1124082-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7F9F240011 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: tjboagb6z4r98u85d1jnegrrendjp4th X-HE-Tag: 1690224876-282969 X-HE-Meta: U2FsdGVkX18HQ/PDKPnAMq08NNSjAu6vd4S2/9UIDni+u3UeiqNFuozIpkGZZWB0dSXCyg6aXVGeESbD9oGgDQhItjiq44kfkSBYXcXF10LqUd7D8YdOwnZmxdUHp9rZFXp9+w1WH4clzQI8bWsXD/HryPWR45x1Mcl4EZQWueN7p2Y6ZT5cHkFw2gOM2l+juHh/pLN/iXLfcwdUvvrXvP6MvkUdqkfwQtbXWz1aBxgnbqxSX/Kd5IpW+1Vpnqb7cbm90grlERSJni3nU6WohZx4r8hjaKP0ucXcdUHKqy/LeRTohEw+dYjK5VtjUN0HB8+RIfPQpeXa73rAFPomuJ8ZJd+zDQG0aNRaQErvFHHVJ3UaoUE78vk4kg+NYHxI8u4l0pAj1BNo7Z0jgXsNs2d52+qEHjuOXgsErUA26GS+Vcak4ZE+ycufJOLpH3Ueyw/IcxW2tOWzxJ1x9YXcTQav4Rd2CNcCPE6FSB0YcbBu5WC1IFZc7jCoc+WQUd/8/QW4GCwzkBxqwVnhxsB2G8Mk3OeLoB6UA3XB7LAKxnFYRZeAQIpp6etduQTHDPr6Q1AKc+LTrHLkyJlJKe4S0LE2rO7sryFrA/3pVD76mX/xNLqMTWu5g7YuzHu4biyg9/bSGtydr7Epavea31JYqebrm0uHIi81wOVvaN40P3x7U2vRrTfq9/VYXA+eAYTGrhXndfy16WPm9lXRVbTlI/HpOhB7gCux4GgR7+JqCXOOLKILFMbnI7qulI6i4ilzYzGiUIXHkuUMZF/T4L0s+mDu6yu6D/lq6OduhGWpnrMZ2p1tixsulWs3Osp/hUEfbNJCa10laYdAsOpTMa4wGalCFjvmpRJVcrLrevzpmw8AlSfo1GvJ7FLI4wkgIOYoJKJZ/tn2PruNfrKG6G7VjVb7QYlhRNAcoXrMlLdFugTObusadj/101CIstdBj/JraAcLaQnpBkdihz2ocwO V98w5ZQe 6QKJDHl7MdBuvkqOOWO0gN2u1Mrwx9G78rB5JPGLyWSFdjCIQrZ4SmZ/lh83inYKrMUvFM07aG/7U4HBu5a/ac3xLxFrB8yW9M4yjlcG9kARjMuNfty5nVOWPKBDpD016RD3D2HA6I20OJOjUDpmut66uIvTU+ZIhrfRTEMtXmgMaEh4j1OMGf8XW5l7jsFjf2H2OPb4nBeX+x6duQiQrp2UGFYsVbX4qdIQIphTgCrIk0qLFde/6h782BNzxVIVRAyhF7QjI1QERFos= 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: Remove the TCP layering violation by allowing per-VMA locks on all VMAs. The fault path will immediately fail in handle_mm_fault(). There may be a small performance reduction from this patch as a little unnecessary work will be done on each page fault. See later patches for the improvement. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Suren Baghdasaryan Cc: Arjun Roy Cc: Eric Dumazet --- MAINTAINERS | 1 - include/linux/net_mm.h | 17 ----------------- include/net/tcp.h | 1 - mm/memory.c | 12 ++++++------ net/ipv4/tcp.c | 11 ++++------- 5 files changed, 10 insertions(+), 32 deletions(-) delete mode 100644 include/linux/net_mm.h diff --git a/MAINTAINERS b/MAINTAINERS index 220566cd8da8..f5f5134219b4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14874,7 +14874,6 @@ NETWORKING [TCP] M: Eric Dumazet L: netdev@vger.kernel.org S: Maintained -F: include/linux/net_mm.h F: include/linux/tcp.h F: include/net/tcp.h F: include/trace/events/tcp.h diff --git a/include/linux/net_mm.h b/include/linux/net_mm.h deleted file mode 100644 index b298998bd5a0..000000000000 --- a/include/linux/net_mm.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -#ifdef CONFIG_MMU - -#ifdef CONFIG_INET -extern const struct vm_operations_struct tcp_vm_ops; -static inline bool vma_is_tcp(const struct vm_area_struct *vma) -{ - return vma->vm_ops == &tcp_vm_ops; -} -#else -static inline bool vma_is_tcp(const struct vm_area_struct *vma) -{ - return false; -} -#endif /* CONFIG_INET*/ - -#endif /* CONFIG_MMU */ diff --git a/include/net/tcp.h b/include/net/tcp.h index d17cb8ab4c48..9d1d312c90c2 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -45,7 +45,6 @@ #include #include #include -#include extern struct inet_hashinfo tcp_hashinfo; diff --git a/mm/memory.c b/mm/memory.c index 7ff73a197cce..c7ad754dd8ed 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -77,7 +77,6 @@ #include #include #include -#include #include @@ -5362,6 +5361,11 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, goto out; } + if ((flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vma)) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } + /* * Enable the memcg OOM handling for faults triggered in user * space. Kernel faults are handled more gracefully. @@ -5533,12 +5537,8 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, if (!vma) goto inval; - /* Only anonymous and tcp vmas are supported for now */ - if (!vma_is_anonymous(vma) && !vma_is_tcp(vma)) - goto inval; - /* find_mergeable_anon_vma uses adjacent vmas which are not locked */ - if (!vma->anon_vma && !vma_is_tcp(vma)) + if (vma_is_anonymous(vma) && !vma->anon_vma) goto inval; if (!vma_start_read(vma)) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index aca5620cf3ba..f7391d017c4c 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1740,7 +1740,7 @@ void tcp_update_recv_tstamps(struct sk_buff *skb, } #ifdef CONFIG_MMU -const struct vm_operations_struct tcp_vm_ops = { +static const struct vm_operations_struct tcp_vm_ops = { }; int tcp_mmap(struct file *file, struct socket *sock, @@ -2043,13 +2043,10 @@ static struct vm_area_struct *find_tcp_vma(struct mm_struct *mm, unsigned long address, bool *mmap_locked) { - struct vm_area_struct *vma = NULL; + struct vm_area_struct *vma = lock_vma_under_rcu(mm, address); -#ifdef CONFIG_PER_VMA_LOCK - vma = lock_vma_under_rcu(mm, address); -#endif if (vma) { - if (!vma_is_tcp(vma)) { + if (vma->vm_ops != &tcp_vm_ops) { vma_end_read(vma); return NULL; } @@ -2059,7 +2056,7 @@ static struct vm_area_struct *find_tcp_vma(struct mm_struct *mm, mmap_read_lock(mm); vma = vma_lookup(mm, address); - if (!vma || !vma_is_tcp(vma)) { + if (!vma || vma->vm_ops != &tcp_vm_ops) { mmap_read_unlock(mm); return NULL; }