From patchwork Tue Oct 10 18:23:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13415850 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 E1C15CD8CAF for ; Tue, 10 Oct 2023 18:23:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EAE18D00D8; Tue, 10 Oct 2023 14:23:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74CAC8D0002; Tue, 10 Oct 2023 14:23:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C5E28D00D8; Tue, 10 Oct 2023 14:23:21 -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 4E2348D0002 for ; Tue, 10 Oct 2023 14:23:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 206A012014D for ; Tue, 10 Oct 2023 18:23:21 +0000 (UTC) X-FDA: 81330374202.03.3AFA27A Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf26.hostedemail.com (Postfix) with ESMTP id 455A0140015 for ; Tue, 10 Oct 2023 18:23:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mZ2Lq0L5; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696962199; 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=LMA7kWpWolO6o46k4syPx6Ijzen7WBJLxGU37wBIQCk=; b=n7S4lggcY10SmR5xwA0+Cy7ogEejXIsQA3iMxXT1V1m2kMk34FSb10wiG3p9lfilGcPrwG BC9Ak0bAnDSUqiYs8POHGTj3/ctQjSmKzSCPqv9NAgKV75m8w6awLk9kkdXPAWeBwLGL/x llqGN5KXuLcKjIl9g4vCGsgMoWI+E8M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696962199; a=rsa-sha256; cv=none; b=RP7slVywrVKlJqav+xTmtz1SV1HQfDy44BALp5HbNG46+2XznLAsb5d3jND1Y+i9269j3R JhSDryQmJpbpoYXk2WdcDMpsr5E/lS0vCeMO5QRI+ZJvknUbvqGeIPYCsWkE2vFD5y162S owIgtTxnAYH2R9HV9NZUPnh9dYNgY8I= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mZ2Lq0L5; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4066241289bso56205825e9.0 for ; Tue, 10 Oct 2023 11:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696962197; x=1697566997; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LMA7kWpWolO6o46k4syPx6Ijzen7WBJLxGU37wBIQCk=; b=mZ2Lq0L5DNYL7rb919rrNl9dlvM9sUQ1CMiQomJgdh6oO2KfH7TR1H9uPnfvuhxM8i 2mI7zJmB5aXGyyBD/waZmNpaCHm8zUgg07cYOtn980S3/4plD+Lf/GS3jtcYgc4ucJm8 kjbodBsooQRGiRn/yers34e4WeCsrw9p532gbR/N3i73z1nthCheVC3cdqWkp3m4qbnL 84eB/yL8tUOeNcQGu+2FtB1x2y/FSj9zsDIL/Hs9QNU0w19MREk19RcZHvu4xDaAuf68 8pv8XM+ztpdeSjgvEyZVuiu9MSaPjNNXXO3SjS4+3KgzXcLSgxqAEKsYziT3cVsdooWI LL8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696962197; x=1697566997; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LMA7kWpWolO6o46k4syPx6Ijzen7WBJLxGU37wBIQCk=; b=W8DmnBFrG7yN/baUF0Ea/aFAWuQI0o6pkmlIB8ZY+yVRBWAoICV+dTpncfgDpm+ZK2 dieYr3unE+yzuY8+YYRPKUb/RDjQh4NLFA2ujV6a7hEJ2NyBn/qvklKFeNZW555rJk4Z VxMY39ZC1hcQgu8QyALzt8h0inVk6yMm7rEE55TsJXNSbD/5pLu68IM9SPg7As3dCWem 7jiCu+UtCeuBn6z0K4Gc+dejRBxGNtDOfKIicixbCsNyjwDoMy7m2A/YjXTGztOGEk4v FEp+mlAK4q50rCoVSqzIlNLUVrAY5p2JooeoXjG4cRldg+ZFIKWi+uAZFErBhIPBFJ8Z 8vPQ== X-Gm-Message-State: AOJu0Yxt4C6fwe3Ih+9SG0CvCb5MNgznKUotW6zqk4O69FbXMZVr+Ufa 1igk0xQJETpWHSrav9HOYWHsWqL7OCM= X-Google-Smtp-Source: AGHT+IGLDXNqqFWzIJ3E5UNJ3YGOQGfTcbbOw8jJXvvcOCrF/m9VHiUs0OpxJ5FyKLoXpbpIYlkq4w== X-Received: by 2002:adf:8b95:0:b0:32d:81f7:d6f2 with SMTP id o21-20020adf8b95000000b0032d81f7d6f2mr464917wra.30.1696962197081; Tue, 10 Oct 2023 11:23:17 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j16-20020a5d6190000000b003217cbab88bsm13225312wru.16.2023.10.10.11.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:23:15 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , Vlastimil Babka , linux-fsdevel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v3 1/5] mm: move vma_policy() and anon_vma_name() decls to mm_types.h Date: Tue, 10 Oct 2023 19:23:04 +0100 Message-ID: <24bfc6c9e382fffbcb0ea8d424392c27d56cc8ca.1696929425.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: wkopki1er8d9okcrijohsttghgwc76sg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 455A0140015 X-Rspam-User: X-HE-Tag: 1696962198-684618 X-HE-Meta: U2FsdGVkX1+JJZWS4MnZQ7edo/DS5vFTNfYYAV6CiUZlSZnO4S7UaoS1Fpq/NS5Rz5F5fnXz7ixUcOXSxsZ9XKGMt44Yq1wHDMO884xq5ucA+8nH5fjpiv4779tLBxXQNPe160cMQoP4fBV0wH03gvuhvPL5YvXjN/z2wllu1QHgKoATohzM9zw83pWE66JINscw0+2KpGysnuJV8DxlA/ZC9Bd3vm6YSd4oDdYvxhmiSrS3K0+07qsBnCyzxPdQ6nMzfP1TrHz1iEQqFUds7CjFXBqRb571QoRl+LMaIXft82MsTbuL4WDEZYnI94u+z190d/rJydDMpN4n5pNmh3VA6x9A5dLB5b0IIPnvJDb6GmMsDCkcNMSt4iW4Lslyq0zbH52S2NYpN8K03GQv5FEk12vb+YjHg6Yt9XZg6GEviiT5mfbhhWXHIKX+MTY/z7Nd9YPmtHC/HROeaMFzjbna36mspTtqVhwbTVa0yzuHnJbIjLGng3pmW9NOsmiLi88uYtSlrrLDlmoESkHFr8TKXLyfTZjFQdExkcvaz4wixQZRIjiwxd9/rMwn/UYa9lRLbnRn7vvJqEiCXCru9YK/gFSTs0U9xNzG9u3fbCr30rIC2gIhNm2vIaCnrD9b1J0W75kogGAseWOQ7en/8NnPFiD+yHIeQmY8Xzjax0Fqpn3YPLLDwLIa2KfZ6M6nevSrfl86ZCbFFHWzmH+j/wxWqFlzo4ScoXxpBJ8nwMN/E7Abihs7GXFcjn098nqsDri0kTiyIkNyIQZS6txWGEPeiSQiSrKvywZ7DrZvEKZiODzKq1qaOPQlf3iU10LSmI47tXjlLE9k6esBuQ0CcyKfdG2EEMsYsuPmOx1H2XWpo2yl4FHZ6QyXr67KGg0wK+x8v2DI7oIGY9BXme4eBEAUqQhqjzCJ12Dks+xBpkfiO3If7RZPj6lIvBKSRCJsfPdGPQbhasvZQ5IrkKP avw/yt3o G+3Ld21MFiNmoCnopJja+ovuxDTwfGjrahfd1jB1yKxjRH0MBV4436yd1Z3tplJrWG++yfvB2OKnWBvmYChEZHYZY7TknQlPuf8OamrupesT/Ssn9FIYWU62dfX69d1uwiz/3mAS3eGFWGEr+UmxcEklwHf4xLRh/j8+7DCevbhVoEZpztDBz+QAcCfkdwUo9Gssi443D+QhoC0J+IlkkE9NdmE/C/D9f8wjTvvQJir6vA2VYB6CZBdUIWtXhN/qb7NZwTTwq5LTa4LinFNvD4raSw7RTLwuW0XZcVuYtz/ThmaDreoRn1OIQ87UKBjR7h4YlqY4yYJnpLlyrWxsuGuOHAffFuS2EIS7efTJjx73QRrMYrHbFjoB86qrPDZDe27Vf8ca5EInJ3pXlny/0ewVnpQ2XNdc6+6C8COLq8WpGrdHPuFyFKKRtShx2oKriVygRDPVPh20rIs7KFZHsUY0hFXB1Sd1wA9kKh2XvzXOyWWPbL36QRdlo7PY18S6edgxy X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The vma_policy() define is a helper specifically for a VMA field so it makes sense to host it in the memory management types header. The anon_vma_name(), anon_vma_name_alloc() and anon_vma_name_free() functions are a little out of place in mm_inline.h as they define external functions, and so it makes sense to locate them in mm_types.h. The purpose of these relocations is to make it possible to abstract static inline wrappers which invoke both of these helpers. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- include/linux/mempolicy.h | 4 ---- include/linux/mm_inline.h | 20 +------------------- include/linux/mm_types.h | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index 3c208d4f0ee9..2801d5b0a4e9 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -89,8 +89,6 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol) return pol; } -#define vma_policy(vma) ((vma)->vm_policy) - static inline void mpol_get(struct mempolicy *pol) { if (pol) @@ -222,8 +220,6 @@ static inline struct mempolicy *get_vma_policy(struct vm_area_struct *vma, return NULL; } -#define vma_policy(vma) NULL - static inline int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst) { diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 8148b30a9df1..9ae7def16cb2 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -352,15 +353,6 @@ void lruvec_del_folio(struct lruvec *lruvec, struct folio *folio) } #ifdef CONFIG_ANON_VMA_NAME -/* - * mmap_lock should be read-locked when calling anon_vma_name(). Caller should - * either keep holding the lock while using the returned pointer or it should - * raise anon_vma_name refcount before releasing the lock. - */ -extern struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma); -extern struct anon_vma_name *anon_vma_name_alloc(const char *name); -extern void anon_vma_name_free(struct kref *kref); - /* mmap_lock should be read-locked */ static inline void anon_vma_name_get(struct anon_vma_name *anon_name) { @@ -415,16 +407,6 @@ static inline bool anon_vma_name_eq(struct anon_vma_name *anon_name1, } #else /* CONFIG_ANON_VMA_NAME */ -static inline struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma) -{ - return NULL; -} - -static inline struct anon_vma_name *anon_vma_name_alloc(const char *name) -{ - return NULL; -} - static inline void anon_vma_name_get(struct anon_vma_name *anon_name) {} static inline void anon_vma_name_put(struct anon_vma_name *anon_name) {} static inline void dup_anon_vma_name(struct vm_area_struct *orig_vma, diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 36c5b43999e6..21eb56145f57 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -546,6 +546,27 @@ struct anon_vma_name { char name[]; }; +#ifdef CONFIG_ANON_VMA_NAME +/* + * mmap_lock should be read-locked when calling anon_vma_name(). Caller should + * either keep holding the lock while using the returned pointer or it should + * raise anon_vma_name refcount before releasing the lock. + */ +struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma); +struct anon_vma_name *anon_vma_name_alloc(const char *name); +void anon_vma_name_free(struct kref *kref); +#else /* CONFIG_ANON_VMA_NAME */ +static inline struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma) +{ + return NULL; +} + +static inline struct anon_vma_name *anon_vma_name_alloc(const char *name) +{ + return NULL; +} +#endif + struct vma_lock { struct rw_semaphore lock; }; @@ -662,6 +683,12 @@ struct vm_area_struct { struct vm_userfaultfd_ctx vm_userfaultfd_ctx; } __randomize_layout; +#ifdef CONFIG_NUMA +#define vma_policy(vma) ((vma)->vm_policy) +#else +#define vma_policy(vma) NULL +#endif + #ifdef CONFIG_SCHED_MM_CID struct mm_cid { u64 time; From patchwork Tue Oct 10 18:23:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13415851 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 B0C69CD8CAE for ; Tue, 10 Oct 2023 18:23:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B8188D00D9; Tue, 10 Oct 2023 14:23:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 465A08D0002; Tue, 10 Oct 2023 14:23:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B9D98D00D9; Tue, 10 Oct 2023 14:23:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1BFA98D0002 for ; Tue, 10 Oct 2023 14:23:24 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E67ED403BC for ; Tue, 10 Oct 2023 18:23:23 +0000 (UTC) X-FDA: 81330374286.02.25CDB12 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf25.hostedemail.com (Postfix) with ESMTP id E10A6A000A for ; Tue, 10 Oct 2023 18:23:21 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=E4+O+TDg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696962202; 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=1Rialj8ADFaCg3xdv2v1kNXYXLbJfZzfEK+fdxuLQ6U=; b=JV/fvPSJV43D2yxrVSgaNJwC8JIuXveGohFYW/LVsr4KuU5Dd3rHdSRuhklyybj1YlPsCF MFpURC013IIsZj7gH0DQW8Ezn7GB+C1Z+7KVGnq02GNtIdayp15PhUGkeE5oN85UaO6t7Z w6IXwFdVtxgcn9sU93k4rmq8FBPVEms= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=E4+O+TDg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696962202; a=rsa-sha256; cv=none; b=FV3/gziS5pQqXNtip7+vEB8S2nI6Q/w3fw569s/ErxEX3nYkZvv5U22VCT/OxNwYQB6paV QB56vyOEhLuRz0+bQgB7gMgNRGsQh/wI7U8QJkjJiaN1eepPlU3PcZv2LFYwp49qz6oadv gVNyd6gYSz0jALqIPngLhRsFIx8JNHE= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40684f53ef3so58483415e9.3 for ; Tue, 10 Oct 2023 11:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696962200; x=1697567000; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1Rialj8ADFaCg3xdv2v1kNXYXLbJfZzfEK+fdxuLQ6U=; b=E4+O+TDgXCI/hzmgciIbJGTyS4EyuPvIGBa/6i2qlrnaVMQ/gwnCcz03gwMavx9A/2 gl7ys33zCGAAtUnpKSyRpGFbkwWAJVq3LHeg7zCVreNOdwtQL8R8/PsXzz63aa8B/0d9 0uxqIT8DBrQjZTwbakWEy7rFMN8UHJudHyxBdU83Y/Jl77Wbeq0ucdi72usxW17W4nHA OATMdypEl/nw/64rfj3Su8VqjoWVdMS8+B/MA8pwCKE8A0xTm+VlfxusJAdVVEwkzIdG n5+G3zXdepZXK1ZIXi+su28cQJlb2ybiI/qraGZSDy8iyVUdDW+IJrP0YxYDagCptAnq 7CuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696962200; x=1697567000; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Rialj8ADFaCg3xdv2v1kNXYXLbJfZzfEK+fdxuLQ6U=; b=A1QCqQRRLWafrBZu7uqnfpAcqrbcJu++E6o6JRd4n4iJvgToDqbA0qxTK9YD/3r7t2 Ir5BTVAr/UGqiiNLgVBaFtGjxg5jk3IOg5Jgu4XsMrjsnwgbqElM5DVhKbRh78RZHHaY /glT1sZif8PZd7CFakL36YgoSzX6LIt/7jtwsF2jj0sWl/XXJn4dh9OhG92CSkiIe1d+ v5EeRwoyVY+aa0JTQ2DwDNHagdrmjcLC0zDvolTsnnaVVZoR95GoE8L3+PsVdlpc0PRk MWKsRoANbOAfpGn9Kq+OnGdLmbj/iYjhWQY0zb/in5u7lHVk70xcXsck7cwO6Ur81zMS y0TA== X-Gm-Message-State: AOJu0YzR7CP685q1eYzgxDa6WujjktYP1qn3ZqBdT000eVcpiz8NfUvr +6cDA+Zo4nrSjYTvlAdqEaMpQPtM5sE= X-Google-Smtp-Source: AGHT+IHnMgoSu/R4VgCTN02zrhjixwNCjRip1Pgt8cght2sWfBxZXivuxhSMpR9o4lus030E1cXrkA== X-Received: by 2002:adf:ec4d:0:b0:31f:e86f:cc12 with SMTP id w13-20020adfec4d000000b0031fe86fcc12mr17084146wrn.41.1696962200069; Tue, 10 Oct 2023 11:23:20 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j16-20020a5d6190000000b003217cbab88bsm13225312wru.16.2023.10.10.11.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:23:17 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , Vlastimil Babka , linux-fsdevel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v3 2/5] mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al. Date: Tue, 10 Oct 2023 19:23:05 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: E10A6A000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: i87wt31h4qtb3g1kde6sipsdkud998nh X-HE-Tag: 1696962201-811327 X-HE-Meta: U2FsdGVkX19SqugZe0yvP5pQidfMlk6YX9mJ/AEOXPbdNYApPtSsozlTdmIWnRXCZQd6ipibyDrsKuCtbkJKaPG3IqYQzoB4dBvsXzKILOmkjVfZy/3vpY71245wS+wRzoPbWg4QS1VIFd5ghj2WQev7ECP54NkQ77WxMyDiHBjz7ql2uCHwx/qfLllA4Qd2D0AhrF/C0Vt/AyFMITgmvziX5EySq60fmReW2gzINLFDMcywHs+qt7B+7RQbMSWBpme4rvLw/d/1azkDGU5uN745NyzotX4nO7jIDVQcQGtRKm6fgBa4X8M7bqkDbxaMCsxy+6YB+6Ef0iJG1GcsLfxa4pfRfSvqsKX31UUIrYXz/u2sRTz8Ihck+r2ZguBGAYCuEwUtgAFXPcBkqSckc0GQ59MAbbk0ll7xNJqaeMorQJCk57seADkY6Bs0Zuudyw+RGJEy+m+o9KwT22b6OwKCG27jYYgU3OMfnHBRQt+ld8PqW/EmBT5G5M0rX0YL95ah20Z2nLpZ1VlEnl8YI+mPTa/bt2cgdrQIu0ltTyL4V6h3j37ak7Zqja/LVHsLdG9cY4bwePETEPj6C6sDJMxzWbD06Emnyzg16u1BpiMh1qDS/YekSVDExDh33GiUVgiXCNEVSpeoqxicU72P/ZYAuZr++lVqGJwvk+2D51Fb76Jq8yypyvHzsbotm1aa0zW128PyGXyc5bLXkAj+3lf9pBvnktnuTpklYOB5FujPb+QYmyxbd3soVBk6O05GtTRdv3pqzy1tW2+P8TF5bKEQfOa2i7G5q8z2gviWaNlKiIGNoVEVC3rehVpBPnhwTmXK29Op7/x3TZ+zryKMP5Sg4KJmBlYxOeT4ObymY9vhiuqt9hTxOPq1Dc1NAQfiJpaFgu4zA7N8LY2HWeZVuYskYjMPQQuUp76aVXmhco+TSRVCDS37bMR+ckxr9NS3EhBAL93FJJ+OXt2gOyw 01imKyyH FtGu09IQP6ndfNg7Zm2qJ7LNIDrrE1ztxpx8wCC67d6u1zrIeqErd5wn1MwGWBxIHGA5OSQd2XKYRECr1IVEGqHMJV4bYbQ2kn0ZcFnJX1R2dPjiDTngr1SOidTfL+d29KBs9R8MY92CPgfrwL/14H+XD7EAE4XMRJfpCnUQtayO4YrW4FfnFl4DyEUT9S/Dlx7mYYWMnC3VMJGPVdXW0KdUWJ+7D2bMGa7Mff8Djn6rQFv0IhnTSQOveh8wadscLqm0NkoTK+yKj6e0CZjXz2ZJfDrTiZKO59qP6YYq9DepxED1tYPWd908T4QO5/gRAguH9zuXBpS78ewWBbzGCrsrlQtmaOiyazOP/TwxAE8L2UwHDHANQo6IavBjrRmcNpMpauRQiAM8fAF9p/0bznFLm13iaDhweMJWB+zVnejg35/Rj24whd3h0tzes00ruNO4IQHejUBDLSpayIsrw16IZz3FfumCldca+ 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: mprotect() and other functions which change VMA parameters over a range each employ a pattern of:- 1. Attempt to merge the range with adjacent VMAs. 2. If this fails, and the range spans a subset of the VMA, split it accordingly. This is open-coded and duplicated in each case. Also in each case most of the parameters passed to vma_merge() remain the same. Create a new function, vma_modify(), which abstracts this operation, accepting only those parameters which can be changed. To avoid the mess of invoking each function call with unnecessary parameters, create inline wrapper functions for each of the modify operations, parameterised only by what is required to perform the action. We can also significantly simplify the logic - by returning the VMA if we split (or merged VMA if we do not) we no longer need specific handling for merge/split cases in any of the call sites. Note that the userfaultfd_release() case works even though it does not split VMAs - since start is set to vma->vm_start and end is set to vma->vm_end, the split logic does not trigger. In addition, since we calculate pgoff to be equal to vma->vm_pgoff + (start - vma->vm_start) >> PAGE_SHIFT, and start - vma->vm_start will be 0 in this instance, this invocation will remain unchanged. We eliminate a VM_WARN_ON() in mprotect_fixup() as this simply asserts that vma_merge() correctly ensures that flags remain the same, something that is already checked in is_mergeable_vma() and elsewhere, and in any case is not specific to mprotect(). Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- fs/userfaultfd.c | 71 +++++++++++++--------------------------------- include/linux/mm.h | 60 +++++++++++++++++++++++++++++++++++++++ mm/madvise.c | 26 +++-------------- mm/mempolicy.c | 26 ++--------------- mm/mlock.c | 25 +++------------- mm/mmap.c | 48 +++++++++++++++++++++++++++++++ mm/mprotect.c | 29 +++---------------- 7 files changed, 142 insertions(+), 143 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index a7c6ef764e63..911ab5740a52 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -927,20 +927,15 @@ static int userfaultfd_release(struct inode *inode, struct file *file) continue; } new_flags = vma->vm_flags & ~__VM_UFFD_FLAGS; - prev = vma_merge(&vmi, mm, prev, vma->vm_start, vma->vm_end, - new_flags, vma->anon_vma, - vma->vm_file, vma->vm_pgoff, - vma_policy(vma), - NULL_VM_UFFD_CTX, anon_vma_name(vma)); - if (prev) { - vma = prev; - } else { - prev = vma; - } + vma = vma_modify_flags_uffd(&vmi, prev, vma, vma->vm_start, + vma->vm_end, new_flags, + NULL_VM_UFFD_CTX); vma_start_write(vma); userfaultfd_set_vm_flags(vma, new_flags); vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; + + prev = vma; } mmap_write_unlock(mm); mmput(mm); @@ -1331,7 +1326,6 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, unsigned long start, end, vma_end; struct vma_iterator vmi; bool wp_async = userfaultfd_wp_async_ctx(ctx); - pgoff_t pgoff; user_uffdio_register = (struct uffdio_register __user *) arg; @@ -1484,28 +1478,15 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, vma_end = min(end, vma->vm_end); new_flags = (vma->vm_flags & ~__VM_UFFD_FLAGS) | vm_flags; - pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); - prev = vma_merge(&vmi, mm, prev, start, vma_end, new_flags, - vma->anon_vma, vma->vm_file, pgoff, - vma_policy(vma), - ((struct vm_userfaultfd_ctx){ ctx }), - anon_vma_name(vma)); - if (prev) { - /* vma_merge() invalidated the mas */ - vma = prev; - goto next; - } - if (vma->vm_start < start) { - ret = split_vma(&vmi, vma, start, 1); - if (ret) - break; - } - if (vma->vm_end > end) { - ret = split_vma(&vmi, vma, end, 0); - if (ret) - break; + + vma = vma_modify_flags_uffd(&vmi, prev, vma, start, vma_end, + new_flags, + (struct vm_userfaultfd_ctx){ctx}); + if (IS_ERR(vma)) { + ret = PTR_ERR(vma); + break; } - next: + /* * In the vma_merge() successful mprotect-like case 8: * the next vma was merged into the current one and @@ -1568,7 +1549,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, const void __user *buf = (void __user *)arg; struct vma_iterator vmi; bool wp_async = userfaultfd_wp_async_ctx(ctx); - pgoff_t pgoff; ret = -EFAULT; if (copy_from_user(&uffdio_unregister, buf, sizeof(uffdio_unregister))) @@ -1671,26 +1651,13 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, uffd_wp_range(vma, start, vma_end - start, false); new_flags = vma->vm_flags & ~__VM_UFFD_FLAGS; - pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); - prev = vma_merge(&vmi, mm, prev, start, vma_end, new_flags, - vma->anon_vma, vma->vm_file, pgoff, - vma_policy(vma), - NULL_VM_UFFD_CTX, anon_vma_name(vma)); - if (prev) { - vma = prev; - goto next; - } - if (vma->vm_start < start) { - ret = split_vma(&vmi, vma, start, 1); - if (ret) - break; - } - if (vma->vm_end > end) { - ret = split_vma(&vmi, vma, end, 0); - if (ret) - break; + vma = vma_modify_flags_uffd(&vmi, prev, vma, start, vma_end, + new_flags, NULL_VM_UFFD_CTX); + if (IS_ERR(vma)) { + ret = PTR_ERR(prev); + break; } - next: + /* * In the vma_merge() successful mprotect-like case 8: * the next vma was merged into the current one and diff --git a/include/linux/mm.h b/include/linux/mm.h index a7b667786cde..83ee1f35febe 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3253,6 +3253,66 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **, unsigned long addr, unsigned long len, pgoff_t pgoff, bool *need_rmap_locks); extern void exit_mmap(struct mm_struct *); +struct vm_area_struct *vma_modify(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + unsigned long vm_flags, + struct mempolicy *policy, + struct vm_userfaultfd_ctx uffd_ctx, + struct anon_vma_name *anon_name); + +/* We are about to modify the VMA's flags. */ +static inline struct vm_area_struct +*vma_modify_flags(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + unsigned long new_flags) +{ + return vma_modify(vmi, prev, vma, start, end, new_flags, + vma_policy(vma), vma->vm_userfaultfd_ctx, + anon_vma_name(vma)); +} + +/* We are about to modify the VMA's flags and/or anon_name. */ +static inline struct vm_area_struct +*vma_modify_flags_name(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, + unsigned long end, + unsigned long new_flags, + struct anon_vma_name *new_name) +{ + return vma_modify(vmi, prev, vma, start, end, new_flags, + vma_policy(vma), vma->vm_userfaultfd_ctx, new_name); +} + +/* We are about to modify the VMA's memory policy. */ +static inline struct vm_area_struct +*vma_modify_policy(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + struct mempolicy *new_pol) +{ + return vma_modify(vmi, prev, vma, start, end, vma->vm_flags, + new_pol, vma->vm_userfaultfd_ctx, anon_vma_name(vma)); +} + +/* We are about to modify the VMA's flags and/or uffd context. */ +static inline struct vm_area_struct +*vma_modify_flags_uffd(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + unsigned long new_flags, + struct vm_userfaultfd_ctx new_ctx) +{ + return vma_modify(vmi, prev, vma, start, end, new_flags, + vma_policy(vma), new_ctx, anon_vma_name(vma)); +} static inline int check_data_rlimit(unsigned long rlim, unsigned long new, diff --git a/mm/madvise.c b/mm/madvise.c index a4a20de50494..70dafc99ff1e 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -141,7 +141,6 @@ static int madvise_update_vma(struct vm_area_struct *vma, { struct mm_struct *mm = vma->vm_mm; int error; - pgoff_t pgoff; VMA_ITERATOR(vmi, mm, start); if (new_flags == vma->vm_flags && anon_vma_name_eq(anon_vma_name(vma), anon_name)) { @@ -149,30 +148,13 @@ static int madvise_update_vma(struct vm_area_struct *vma, return 0; } - pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); - *prev = vma_merge(&vmi, mm, *prev, start, end, new_flags, - vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_name); - if (*prev) { - vma = *prev; - goto success; - } + vma = vma_modify_flags_name(&vmi, *prev, vma, start, end, new_flags, + anon_name); + if (IS_ERR(vma)) + return PTR_ERR(vma); *prev = vma; - if (start != vma->vm_start) { - error = split_vma(&vmi, vma, start, 1); - if (error) - return error; - } - - if (end != vma->vm_end) { - error = split_vma(&vmi, vma, end, 0); - if (error) - return error; - } - -success: /* vm_flags is protected by the mmap_lock held in write mode. */ vma_start_write(vma); vm_flags_reset(vma, new_flags); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b01922e88548..898ee2e3c85b 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -784,10 +784,7 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start, unsigned long end, struct mempolicy *new_pol) { - struct vm_area_struct *merged; unsigned long vmstart, vmend; - pgoff_t pgoff; - int err; vmend = min(end, vma->vm_end); if (start > vma->vm_start) { @@ -802,26 +799,9 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma, return 0; } - pgoff = vma->vm_pgoff + ((vmstart - vma->vm_start) >> PAGE_SHIFT); - merged = vma_merge(vmi, vma->vm_mm, *prev, vmstart, vmend, vma->vm_flags, - vma->anon_vma, vma->vm_file, pgoff, new_pol, - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); - if (merged) { - *prev = merged; - return vma_replace_policy(merged, new_pol); - } - - if (vma->vm_start != vmstart) { - err = split_vma(vmi, vma, vmstart, 1); - if (err) - return err; - } - - if (vma->vm_end != vmend) { - err = split_vma(vmi, vma, vmend, 0); - if (err) - return err; - } + vma = vma_modify_policy(vmi, *prev, vma, vmstart, vmend, new_pol); + if (IS_ERR(vma)) + return PTR_ERR(vma); *prev = vma; return vma_replace_policy(vma, new_pol); diff --git a/mm/mlock.c b/mm/mlock.c index 42b6865f8f82..aa44456200e3 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -476,7 +476,6 @@ static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long end, vm_flags_t newflags) { struct mm_struct *mm = vma->vm_mm; - pgoff_t pgoff; int nr_pages; int ret = 0; vm_flags_t oldflags = vma->vm_flags; @@ -487,28 +486,12 @@ static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma, /* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */ goto out; - pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); - *prev = vma_merge(vmi, mm, *prev, start, end, newflags, - vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); - if (*prev) { - vma = *prev; - goto success; - } - - if (start != vma->vm_start) { - ret = split_vma(vmi, vma, start, 1); - if (ret) - goto out; - } - - if (end != vma->vm_end) { - ret = split_vma(vmi, vma, end, 0); - if (ret) - goto out; + vma = vma_modify_flags(vmi, *prev, vma, start, end, newflags); + if (IS_ERR(vma)) { + ret = PTR_ERR(vma); + goto out; } -success: /* * Keep track of amount of locked VM. */ diff --git a/mm/mmap.c b/mm/mmap.c index 673429ee8a9e..bca685820763 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2437,6 +2437,54 @@ int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, return __split_vma(vmi, vma, addr, new_below); } +/* + * We are about to modify one or multiple of a VMA's flags, policy, userfaultfd + * context and anonymous VMA name within the range [start, end). + * + * As a result, we might be able to merge the newly modified VMA range with an + * adjacent VMA with identical properties. + * + * If no merge is possible and the range does not span the entirety of the VMA, + * we then need to split the VMA to accommodate the change. + * + * The function returns either the merged VMA, the original VMA if a split was + * required instead, or an error if the split failed. + */ +struct vm_area_struct *vma_modify(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + unsigned long vm_flags, + struct mempolicy *policy, + struct vm_userfaultfd_ctx uffd_ctx, + struct anon_vma_name *anon_name) +{ + pgoff_t pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); + struct vm_area_struct *merged; + + merged = vma_merge(vmi, vma->vm_mm, prev, start, end, vm_flags, + vma->anon_vma, vma->vm_file, pgoff, policy, + uffd_ctx, anon_name); + if (merged) + return merged; + + if (vma->vm_start < start) { + int err = split_vma(vmi, vma, start, 1); + + if (err) + return ERR_PTR(err); + } + + if (vma->vm_end > end) { + int err = split_vma(vmi, vma, end, 0); + + if (err) + return ERR_PTR(err); + } + + return vma; +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator diff --git a/mm/mprotect.c b/mm/mprotect.c index b94fbb45d5c7..f6f4a4bca059 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -581,7 +581,6 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb, long nrpages = (end - start) >> PAGE_SHIFT; unsigned int mm_cp_flags = 0; unsigned long charged = 0; - pgoff_t pgoff; int error; if (newflags == oldflags) { @@ -625,34 +624,14 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb, } } - /* - * First try to merge with previous and/or next vma. - */ - pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); - *pprev = vma_merge(vmi, mm, *pprev, start, end, newflags, - vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); - if (*pprev) { - vma = *pprev; - VM_WARN_ON((vma->vm_flags ^ newflags) & ~VM_SOFTDIRTY); - goto success; + vma = vma_modify_flags(vmi, *pprev, vma, start, end, newflags); + if (IS_ERR(vma)) { + error = PTR_ERR(vma); + goto fail; } *pprev = vma; - if (start != vma->vm_start) { - error = split_vma(vmi, vma, start, 1); - if (error) - goto fail; - } - - if (end != vma->vm_end) { - error = split_vma(vmi, vma, end, 0); - if (error) - goto fail; - } - -success: /* * vm_flags and vm_page_prot are protected by the mmap_lock * held in write mode. From patchwork Tue Oct 10 18:23:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13415852 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 83472CD8CAF for ; Tue, 10 Oct 2023 18:23:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 183148D00DA; Tue, 10 Oct 2023 14:23:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 096C18D0002; Tue, 10 Oct 2023 14:23:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDBF88D00DA; Tue, 10 Oct 2023 14:23:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CCCE38D0002 for ; Tue, 10 Oct 2023 14:23:25 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9D115B4C4F for ; Tue, 10 Oct 2023 18:23:25 +0000 (UTC) X-FDA: 81330374370.10.C1C1C5E Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf01.hostedemail.com (Postfix) with ESMTP id AA6EC40014 for ; Tue, 10 Oct 2023 18:23:23 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OO5aATj6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696962203; 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=xYZtGWQnk+qTSD3PTRtexwtcvMKng8mprQW/gWAvlII=; b=pOEQ2CcJObzteNK/bC5f61eGPVhK0ZHEGgkVkSmHHteiADORJAkJeXiXtGlp+zo4MZE1b8 yGbqKqMJM0xHhhyYn19L4TmHV8bFm93ImOw3OqGYbQNwt+4T878+CQP9/mXOFM22SsoULl NAvM6igpspCwwBRM1iNxE3Gd/sNQvEU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OO5aATj6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696962203; a=rsa-sha256; cv=none; b=lBoG0J5bFtCguJFCTE4SJVf29mfyMQG3RyS7q+BTgON6d7mMnuvfI1AdwgnBHCjSnYAsZp oOWTGf4DzgG3sumTl0S6VjZq7cB1WC7hi/hvWNjzrnGC2gc1ens1qN0ZIjGyZLoQsF2ar0 NMWu/9TsJ0i0htnU1Uow7Z3Gho7Ge+0= Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-406619b53caso55636925e9.1 for ; Tue, 10 Oct 2023 11:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696962202; x=1697567002; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xYZtGWQnk+qTSD3PTRtexwtcvMKng8mprQW/gWAvlII=; b=OO5aATj6ljK8XZf3lNXKL4gC6MN1BrmBo4bFr/d5hc+ByUjANMquaQmuq/yGR3u+Gj 2/wBIw912OT3QKDTVlrG2PmwifJsxU4YZO1CFym+kRWe/EDos9/HXPjgYEWXRRipRVee /RTxoZimmCsinbpM5U1+iKgDQ6Cft2N8ADLFCgLaHDmb3yiH71Y0GfKBkc3YxcScySkN 7YrxcunskoDn2Q2VMt6OqL+mu0QKkYMS+krYcqlP03DHV9iGwRZ86AzEJx5vrLU2UY4K 9I55E6NVUNooIsoJeQ6Oa2z2kLb1NB5qgkwFKKpzf2F/9eH1JeQdPYfDZhEr6P71PlrD cYnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696962202; x=1697567002; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xYZtGWQnk+qTSD3PTRtexwtcvMKng8mprQW/gWAvlII=; b=gTOubGnlNFfZmTW3uHN+n9/gjg92XKtpHq/TljWqEyRpK/aJy6Mixxxb/Zc/A1gmRK wp97dQWUahbEyj7Ny7ydZ63mW/7lRgtt49R+ot9nXS52VSv2vSN5pYxFsrFQNiFQypvM z3vSAmcQwJ5AJHkfnp1zru/GuTNW2TR4746ifmJkUQia3NtSbosO8QOL6WJTmqZTdG3C BC0L6kTRehpDzTGD4eZ4A+PvIEZcFiXyuG5Q5cP6lWBeuNndoM2ycUcGFu4wyk7LaeSO lvZ9hm2Y57JzPX+LI0asrnV243034TTFUwA3ng/PpACoqsvrpp0Dt4mrhogtSjcFav5O kZWQ== X-Gm-Message-State: AOJu0YxspWMrVkgIokagoLqv5LcWfQ90FAi4WZGwSjLGSzS/i4oIuJHJ 0dAv2WlWehOKNu5+7a8cg3xmZmNaaMQ= X-Google-Smtp-Source: AGHT+IFeSuY+leWpp9QNGQShZwfaneWw9EVs9ggK3b4usECxkab1t01uZ2nxvXac8yGuffFvBzg59A== X-Received: by 2002:a05:600c:2298:b0:406:513d:7373 with SMTP id 24-20020a05600c229800b00406513d7373mr17049867wmf.11.1696962201906; Tue, 10 Oct 2023 11:23:21 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j16-20020a5d6190000000b003217cbab88bsm13225312wru.16.2023.10.10.11.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:23:20 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , Vlastimil Babka , linux-fsdevel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v3 3/5] mm: make vma_merge() and split_vma() internal Date: Tue, 10 Oct 2023 19:23:06 +0100 Message-ID: <188659ab3a8efc58a26fbd64b735ebbb88a65aa0.1696929425.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: AA6EC40014 X-Stat-Signature: xjwtzsfu7dc9wzdgiu6t4ohpbt8pdtkr X-Rspam-User: X-HE-Tag: 1696962203-648503 X-HE-Meta: U2FsdGVkX1+tEU7tOnBZ0B8rLdHQYONTI+nwq392+LMR75+qX+AJBGLh69yG0QQcKcbSGs6XFqvc5QvA3BvKxtfhxjupqUhslT7SyQ/rbnC7FNWUnswl7nqXghSq2Vg0b9bJ2+Rp73gdIMOgq1iJw3n+/3KUEJCiTtTB7+YkyCZo9Cup8Ww4HaKkU8DD2RiZEW/w4+b6Um4mPmnS7Cdhl3g7ULZGT3pbOGPNMCe/3fS05g7oqvZYLxSHhna4iI4Mv/EGL+Fi2Kv4FUv80S3EpYdsA1YurXKUiYv+DSAv28KWZNBa8wkbyyzQySBL7z6cmcBjWUkAQT2wIsMAlJW9CDBZVNL2qQa+ztjTj/zjMrt+5fhYrcTABf0+RpisvwXGFCC7nXZ5j1QMFDMIPRFYV/OJMfs6PbYUdaq4PbdLwJLSdM4i5stsimG7jfYwsDzJ2Vu7bLDrX/I5btNNCwuTFVp5WuAZbvOP+J3TEVGz/JbnTRMz/K3EjozoPMP9IY1l1yqOG92VUGdSw35HRvay4xfID70wYVUwReL2/oHgbEidwt1MOq+BwQUlrI/on2ltHVk9Mz6DL1JfMkBAuzrAzidiNWo1nOLfeDZqsBblbswYOY2LKKQdNxKPxOOlcJZY+TU+lyY5kkOxj0GkGgelU4d4bNdSNBYr+DXEUwvzLPm/Ruioi9OhZUWIBsU3G4WjueZpKAkhA22/HNyiDDzfTx1t54ICoBTfld/XwSar9Ubq4ype8i2FdrbEnNyaD9o7FM1Cj/i6ORLOK8dBhpRR+iS5OBoL+CSOxoQ0eOfsnBzkzRqeQoGo6XP15JA4TQwPkn4lyhPkd8DA5E7gkKTT2nTb13HMrBs9DIRfJ23izxy4ssmN4THGw+JRM03Q+3g1TwZNs+bYQAqnuWGv7Q8HWX0YUtCadjuDsTab5Ew+kV5t9lx91ErjfsDXqqAMcAAz76/9vWE+djo38dIyOc7 aoedl43X /uepk8hn1ulEUyNXxv0BIFTcGC2TUUpykdwnJOSPy1iFCnE8mh35CaaXcBIsJeLPYEDy8vfrIf01gnSLJQum4DWPM+/5l1K+YITraAkIS7q9qfRQaQUMT4KIfpsNvWBwfVKvG/PE6Zw9x2pEMJnWmO/Xx7rFhdFWyMQeNvkp/xOt0ttcxtnipvdLgUeeo5mX6XURUcaYHPTroEHHjIVfI4wgD0MD5v3q9FFLx9U+kHs97kri7UmCUpfz2vXWyrIA2n0vjuVegXa5sCTmi4eBTFCiafk6uBiXtFLNDUFaoH902XeSe93J1XR7ZvXA3dK8P9/StacwxqlfjVHbK3gzV48bTpfweiU6IWIDIQALXVAnSrVi6HwKMnXUjUU/Fzm9RU9IkGvy7I7PP+8cHBfsrA/wNJr7Kltpk9ZKjqiqpJkAX3IYRiH8/4A9wVMHtFIq+gVchenqiPZkarfHGzwsAJUzar4nIs6YrOkzYtpmSn/7fX1qY475q5GKtze2zRAmNs5Ky8NvoIkNA34A= 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: Now the common pattern of - attempting a merge via vma_merge() and should this fail splitting VMAs via split_vma() - has been abstracted, the former can be placed into mm/internal.h and the latter made static. In addition, the split_vma() nommu variant also need not be exported. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- include/linux/mm.h | 9 --------- mm/internal.h | 9 +++++++++ mm/mmap.c | 8 ++++---- mm/nommu.c | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 83ee1f35febe..74d7547ffb70 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3237,16 +3237,7 @@ extern int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, struct vm_area_struct *next); extern int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long start, unsigned long end, pgoff_t pgoff); -extern struct vm_area_struct *vma_merge(struct vma_iterator *vmi, - struct mm_struct *, struct vm_area_struct *prev, unsigned long addr, - unsigned long end, unsigned long vm_flags, struct anon_vma *, - struct file *, pgoff_t, struct mempolicy *, struct vm_userfaultfd_ctx, - struct anon_vma_name *); extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *); -extern int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *, - unsigned long addr, int new_below); -extern int split_vma(struct vma_iterator *vmi, struct vm_area_struct *, - unsigned long addr, int new_below); extern int insert_vm_struct(struct mm_struct *, struct vm_area_struct *); extern void unlink_file_vma(struct vm_area_struct *); extern struct vm_area_struct *copy_vma(struct vm_area_struct **, diff --git a/mm/internal.h b/mm/internal.h index 3a72975425bb..ddaeb9f2d9d7 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1011,6 +1011,15 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd, unsigned int flags); +/* + * mm/mmap.c + */ +struct vm_area_struct *vma_merge(struct vma_iterator *vmi, + struct mm_struct *, struct vm_area_struct *prev, unsigned long addr, + unsigned long end, unsigned long vm_flags, struct anon_vma *, + struct file *, pgoff_t, struct mempolicy *, struct vm_userfaultfd_ctx, + struct anon_vma_name *); + enum { /* mark page accessed */ FOLL_TOUCH = 1 << 16, diff --git a/mm/mmap.c b/mm/mmap.c index bca685820763..a516f2412f79 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2346,8 +2346,8 @@ static void unmap_region(struct mm_struct *mm, struct ma_state *mas, * has already been checked or doesn't make sense to fail. * VMA Iterator will point to the end VMA. */ -int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long addr, int new_below) +static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long addr, int new_below) { struct vma_prepare vp; struct vm_area_struct *new; @@ -2428,8 +2428,8 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, * Split a vma into two pieces at address 'addr', a new vma is allocated * either for the first part or the tail. */ -int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long addr, int new_below) +static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long addr, int new_below) { if (vma->vm_mm->map_count >= sysctl_max_map_count) return -ENOMEM; diff --git a/mm/nommu.c b/mm/nommu.c index f9553579389b..fc4afe924ad5 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1305,8 +1305,8 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg) * split a vma into two pieces at address 'addr', a new vma is allocated either * for the first part or the tail. */ -int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long addr, int new_below) +static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long addr, int new_below) { struct vm_area_struct *new; struct vm_region *region; From patchwork Tue Oct 10 18:23:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13415853 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 94FE0CD8CB0 for ; Tue, 10 Oct 2023 18:23:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A1888D00DB; Tue, 10 Oct 2023 14:23:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F88E8D0002; Tue, 10 Oct 2023 14:23:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07A4D8D00DB; Tue, 10 Oct 2023 14:23:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E6AD68D0002 for ; Tue, 10 Oct 2023 14:23:28 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F7AB1202C4 for ; Tue, 10 Oct 2023 18:23:28 +0000 (UTC) X-FDA: 81330374496.07.CD0AB24 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf09.hostedemail.com (Postfix) with ESMTP id C07CD140009 for ; Tue, 10 Oct 2023 18:23:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FmNYxWtb; spf=pass (imf09.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696962206; 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=vy50Imp7hsFcD9fQ9yun20NmSXPiCxJvkitJven0GZ0=; b=L+KNzVwFf9wmNcf1cAu0VlfDCeBR1oKAWPs0zHdqRlpihQkjaGppLbMeexjVls2tb80chQ SzO1kdXDpTXz1AtIpEabDQLsVnRHkc/hgXJMWs//EpqMDL5kFL69m/T7JefwkQiJnqhfLc UvM4yzIOs1IKH/+YmS5GD9fYc/kjSA8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696962206; a=rsa-sha256; cv=none; b=PxelSxZjI+0U88UB26DOKQRRKoGDyIm88z9WKtB/gTBHhykWXTt2HI0072HNaUOUG9vAGo KqQEB6FRtIVF6YP6QfQiK2GmyhlIaXxmNOzbpiOyeGeDxfx8M/jjrzw37nalzHCnVKCPms XuAs3JW2j8gXe+pzQ7g2THva0/tNbEY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FmNYxWtb; spf=pass (imf09.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40535597f01so56318115e9.3 for ; Tue, 10 Oct 2023 11:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696962205; x=1697567005; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vy50Imp7hsFcD9fQ9yun20NmSXPiCxJvkitJven0GZ0=; b=FmNYxWtb0x1bKIuep3Lvf9kS76nUTCfVthDvOCtxMw2FbrDMUnBXZhqjy8rSmHpzVi XpZT9g4pKs4XEorXH2uOMH8U0HJERHxG33Ts+qAWJGVKc1zBjlHiv37Dy45veesQafPF OIkl1PmoTNVHMyw7I6qeZnbBQmhqLxsWolifOIrT5vKzLic3sBD2a48j+a5tFv6PfzU7 coxs/9AQCD8581vOoSv+/ygaap8krUKqlDrAPuOpLWztyf0rFzxwCDz0LTd95yHAlnnj lil28o3oKTxRegz6evtxK2GMd5C9kVK8mtRXRHmvRcsNNNtTSZB+yQg7tHDPluz6UGqA p1Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696962205; x=1697567005; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vy50Imp7hsFcD9fQ9yun20NmSXPiCxJvkitJven0GZ0=; b=lTAaW0L6aEEqlftYhos974ivWURzJtmLUc2C7nvtfjioJXYfUuNvY7ZDwrJWJHGkub Gck03oQzMyA7GBtKy8PxVvSqCMpdOlJu0nvzDSOqpu9gP4V/DrduUAgIIYM9zqZELUbU 9QZ65avmW5B3zdWKZNsvcZDm+JudDJ1M3xeSjYX+0SVJKPi5hULIeZJeZY7wrZAAFKZm PMpGYM3HWCdmIlT4yVCTC+1Z5xqv5OYyl3OIuE12Fp/b2duYfMAeAXYTrs0Dxp+wbY/J aeGQVChk5vqXN50cdMe6sA2GLZ0OoES7+bOejTEQs3kY1K5CNYZtPmFMULTALEhw/840 UbbA== X-Gm-Message-State: AOJu0YzaLTpPqtMxRxoEe+dNvs1o0MAvBjm8kGy6wBIWNemgo0xbAYf4 7aUfthBK5e/4Cjxe3ZsdkNiHCjTvvvQ= X-Google-Smtp-Source: AGHT+IESkqPmjjAOvbILmnJkd4RsbqA/GSj+EQxsInZHrckbIauEIItGkohtMZgNuXuLytwtz90QZQ== X-Received: by 2002:a05:600c:ad0:b0:406:7029:7cc3 with SMTP id c16-20020a05600c0ad000b0040670297cc3mr15993235wmr.28.1696962204923; Tue, 10 Oct 2023 11:23:24 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j16-20020a5d6190000000b003217cbab88bsm13225312wru.16.2023.10.10.11.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:23:22 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , Vlastimil Babka , linux-fsdevel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v3 4/5] mm: abstract merge for new VMAs into vma_merge_new_vma() Date: Tue, 10 Oct 2023 19:23:07 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: C07CD140009 X-Rspam-User: X-Stat-Signature: dfj4c77zxdjuuhfm3y95j5mci37uqfuq X-Rspamd-Server: rspam03 X-HE-Tag: 1696962206-711202 X-HE-Meta: U2FsdGVkX19GO9FQuYcIAw+60+clYPLC7TesCcG7czVAn81P1aGXi2ZMS3Aq/dY6dl7BfrvQdAjUN/gdhB5agrAvoyh1vu8VQN2g4l7rNTiduaU+I+TdRdZtIt5PXeure181I8uQzYW7yOE7EsDWd13BIDsiGYClkZSE1Fbu/RhfMW8y5s/jsq4cds/BmdmehBpJgHmRk/t9xEg9ye2kaQus17xk3z60cPlTGxVdMSe9XPiUHyjxH4OFaTkFUpELn5D1xTBXf/2h5KnGtvA/+1yeJOdWppIzGRW5mujrr8WTJMoV09AlA3DyquuwFmrzH/Sp6j/ZkAPbj4pcOxrWEh1jYRztcoTypT0FU3RKsMpdNeky2h9zIL5/PrgNBWwn3QGYUaQqZ99w3dLNTNdylGB/UP8INry50bzPNfa5Z/WhnUZt1q+u40wSppD5Tz9zQZu2EsYdrpQx/KqPT2IUwgKVgngsVeard6LfedAWxsLoue2k+wnruF+p4S8DYKyqIQs35q9IXGwU0RC15ltIMPu56xRBSHsUoS/IBesjAN0ztFD0TSlBs2P/hV7XTkIXfCMGiPw36+4Eg9rh+0F1r0BPQ2eKEqmL0USAjlWwODXOGt3Z58pNePePMJU92QtbL3eLz6/BEGYCmGjRhu9Ow58YIZhHpsDAL3CA/xolN1JhbyPquHblZ7AEDRAiRsk0rg2Zc7XRciiyyfMOjCmTKB1P1E5gFLeWnbQo37X/16uFQNoTCUBJwy1XAd17ogVO5tLxSVGIk/LDihg+QS+maQSSLFQfoTfhfKcqDZ02/PelkEw2OfV1Ao1IiJZZLEMaz4988Z2wIWAepJ3dlGwMJovfPZw+EaKfaVdxg0sRQ8u3IzBLi2JTfz37pn4CqyhAYkl4zHA6ZrlPeNV2CBm55kl7lLwiItcwz8iA8QDqB1dpOWlr9GW6Ch50/c6Od7X1Oj7oEymbB1iJWAPM3x/ iozpr4VJ qGx5ebZg7T7QsbbSdr3CnF8nFCuHfRQhKCyW2jmosX5QjwjlioTNUjGPK5JbOQMnQUBELdQuNwuwCiGbxaYPKwG1DRwuaZ7p0i+4KjtRI2zvKE/WIHfBa4SzHlvVO1LmmH+UbUOT1+KOtM5iMxj61HousWIlcPGM7VJzYr6ble15DOls2LCcmONsEwyaqqRdo+lo1zBBnI0VgB7LUORnWxi3DsECZDHnUR+kXKMs8lmw1l2ScG9qWkEDMTcYnFD19eJPwGdtVjHkTgn50sqN9XNQz2MjTMvpp5ZBrh2hvoAHFjn1BLmCZnWsemPKEthqc/5gvHiYcoe5tlVAXuHsKPM27q9IcqMeMigR2QDQlfdL0+xhvNxdFCLVW+APDpMgA2tD1M1NytiRSijGbR594wcNEDBERprx0vIFWN2ZyaAFRM7iSuQgi122lk/KRXkNvuwXnPob+5vOsKQb47AtZTfOg9scZB3vAWSGSIv9ezv/gCeJ7z0FvS3PG/CMP2kY0UsE5 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: Only in mmap_region() and copy_vma() do we attempt to merge VMAs which occupy entirely new regions of virtual memory. We can abstract this logic and make the intent of this invocations of it completely explicit, rather than invoking vma_merge() with an inscrutable wall of parameters. This also paves the way for a simplification of the core vma_merge() implementation, as we seek to make it entirely an implementation detail. Note that on mmap_region(), VMA fields are initialised to zero, so we can simply reference these rather than explicitly specifying NULL. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index a516f2412f79..db3842601a88 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2485,6 +2485,22 @@ struct vm_area_struct *vma_modify(struct vma_iterator *vmi, return vma; } +/* + * Attempt to merge a newly mapped VMA with those adjacent to it. The caller + * must ensure that [start, end) does not overlap any existing VMA. + */ +static struct vm_area_struct *vma_merge_new_vma(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, + unsigned long end, + pgoff_t pgoff) +{ + return vma_merge(vmi, vma->vm_mm, prev, start, end, vma->vm_flags, + vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), + vma->vm_userfaultfd_ctx, anon_vma_name(vma)); +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator @@ -2840,10 +2856,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && prev)) { - merge = vma_merge(&vmi, mm, prev, vma->vm_start, - vma->vm_end, vma->vm_flags, NULL, - vma->vm_file, vma->vm_pgoff, NULL, - NULL_VM_UFFD_CTX, NULL); + merge = vma_merge_new_vma(&vmi, prev, vma, + vma->vm_start, vma->vm_end, + pgoff); if (merge) { /* * ->mmap() can change vma->vm_file and fput @@ -3385,9 +3400,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, if (new_vma && new_vma->vm_start < addr + len) return NULL; /* should never get here */ - new_vma = vma_merge(&vmi, mm, prev, addr, addr + len, vma->vm_flags, - vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); + new_vma = vma_merge_new_vma(&vmi, prev, vma, addr, addr + len, pgoff); if (new_vma) { /* * Source vma may have been merged into new_vma From patchwork Tue Oct 10 18:23:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13415854 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 CD3CECD8CAF for ; Tue, 10 Oct 2023 18:23:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B8408D00DC; Tue, 10 Oct 2023 14:23:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 467E88D0002; Tue, 10 Oct 2023 14:23:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E2458D00DC; Tue, 10 Oct 2023 14:23:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1A8388D0002 for ; Tue, 10 Oct 2023 14:23:31 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C28C6C02D2 for ; Tue, 10 Oct 2023 18:23:30 +0000 (UTC) X-FDA: 81330374580.06.8670913 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by imf01.hostedemail.com (Postfix) with ESMTP id CCC444001D for ; Tue, 10 Oct 2023 18:23:28 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l2rkSSdC; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696962208; 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=tFbKpQ6SsRHnWdu3vxpCFtAo2jAJKsxmAumC1+QExjY=; b=C8LShBusb6BJPeTBWSPV49xO8+9DnJ3gZpdC2n7eRteOJa45sMHdiChvyrUEIKQoESxcy3 yTN4pkmJGvQWATPN4NSEw4up7I+MTLAETJpsoRlc7DDY2GXoOf8LeqK+6Jw/3NS3KEt4RE mfcIPtKRufI2/Zua7NlR0g9QMkNj70U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696962208; a=rsa-sha256; cv=none; b=k0+w7ZG3FtKZWG7b5Wcr+448dBiwWyDqbpmiKT6mRRNOTm+Bu6Ba8IliK9B/hjqOBmLwk6 MR2yRjSHXiJUXGtdklRpXSUPKcx5d5QplYpTMqMSmmwknPsX9u+8n0eyty98NqOvysbdV5 6khx0fhFYtSHxlgEIur2fOIsq1OsG/s= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l2rkSSdC; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40535597f01so56318375e9.3 for ; Tue, 10 Oct 2023 11:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696962207; x=1697567007; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tFbKpQ6SsRHnWdu3vxpCFtAo2jAJKsxmAumC1+QExjY=; b=l2rkSSdCCrzm6UePc3kIaE3aCV6sTRzfkUW1EOHZ/i+/mGYVl2/ogfJSUW/pVjqsKf PXTJQxK9nTpppZvosuJvzRnsTA+te1xuyP3pibXNC1LhKB5fs6nt0nus5pthprMfL+KB l++D+t+mJ/7KYkeTUjrWoB1ppfvpNPPitpm8qyVT5pmvTGXUrCGGCnx6wjeWCduIQAeg zy/BtKzG72wTgsRhbWY1VhPxqmmQqbqZYTpYWxNjTcfW4kCnwb5pll76UNZ2Pk9P4z+j 8XTumwcjhycTCRHpkZ0IAGYkydLizPOXnnAbt3l6zelhB8/WTB8zMengUZehODD4QqQk lt4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696962207; x=1697567007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tFbKpQ6SsRHnWdu3vxpCFtAo2jAJKsxmAumC1+QExjY=; b=ioFBvB/NggRDkmLo/a4ygP9sXpsd0cPHnk1UFZXHBhgz/4U8gkDSd0Tw+CJTqwwSeG zWR3WC3Nl87Z8EC+WCovMJfAK816WKr6wsmrSgFNkaePHmE6b3qcjF6cbAS6lcTmlq6w wYB5B600Y4nf/AUz/VVB3qOG7S1uN2tn7Lu6P5UOaGSuoNZXLDHj/9PGXdZ24XI+Po39 stlN00JmWGYJasaIaubAZvIK/+ped6oRRBeg8ckFaRO6uArPa8X/VKB4OFsDfz2DxJgY lX6x0noOAYdQ1IBMNd9xWelg19+vx07df7EZhT9AkKLn6vHmPM/VuvmkYGJ0ZiZeHVRR iwgg== X-Gm-Message-State: AOJu0YxCThr3DoT5RGUBr3maSsO1roxcJDJaz7NF7CEP7VdP2dubn4Zc ILg7ZCbQY03LQHE+kLstG04nt3l9xGA= X-Google-Smtp-Source: AGHT+IHv1LOl5HKi62e1HGQi+SAntjdzxRBlNr+hjRg05MokHXX/rE8OMoNY9iwhCLEYBLbo73Wz5A== X-Received: by 2002:a05:6000:1cca:b0:320:8d6:74f5 with SMTP id bf10-20020a0560001cca00b0032008d674f5mr15754499wrb.28.1696962207032; Tue, 10 Oct 2023 11:23:27 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j16-20020a5d6190000000b003217cbab88bsm13225312wru.16.2023.10.10.11.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:23:25 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , Vlastimil Babka , linux-fsdevel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v3 5/5] mm: abstract VMA merge and extend into vma_merge_extend() helper Date: Tue, 10 Oct 2023 19:23:08 +0100 Message-ID: <8134bfa4b1accb98645be3e8cb2af8ac5a92c469.1696929425.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: grsbb73hiqwo1x5wzeipisp1uqwiw6os X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: CCC444001D X-Rspam-User: X-HE-Tag: 1696962208-624960 X-HE-Meta: U2FsdGVkX18Rj/ENkQREW+xpNTdyOk8zsAdXOJPDLSzgHwzyINu+lQXB9d8vl9Aui7a3uGSEqQSdC8qStQt/+6JZq2T/0Jq5pWycxzVdZlClcUGF8GoJzc5V/RAojeV23lJxrJ4AZYBCMAMm0f19sSfNyijrvzb1T/HG6GKDDZpBHJhc6u3IPuSCZFxZgS2XLZLoWym2FMtBZ35r/wHxuBQgX/pfruR4QyyAn7yZC7a8ggSHVW93njA0M+SP9l0f0bxo5+DbOUd9jDCAcwIvbSprvp/TywbR+ocXqE+X988ILJRt8HnrNf3bf1ZPTuzHme/4TqweaVzWGJgCnYkRwA6JqcBKRkLqrymU63G/yQhkMj7RT5kL0J/k8CI2Nle6/QGTIW4INZr4d4Lv9EIcXIN12O2LNA4SL749gBF+5qUh1EvKaDdmLWd+IUObwJXS5i0ZgDrqkc8K08PBteMEReXSioB6NlU0SG9zZbPw4NRiiJrtapJPR7sqgUmNyP2zQ2bBtSx+SuG5kvdxjVQ16ifCFqpFE4JTX6kLD6g6E/2UsJki6P3y/jLvL4RXfBt+dzSHJDaGLoK6bj7Xo9ikcN3083BE9UHQMOgRFsksRWlTaexYSKZw8pwF+TWq7ZiJD/VYjOSHBhIZ7Ow9dnxPJxML3cPlRh6YONOllzHQ3OaXBE6TWKy/zejb9LWwIvfO0RssmEaS7cRs1sPfr4UDXqh/vSo7GSpLRI7QH8vOsAwka3S0IXskXeZ4utnQ4F8sGRdQbJv0ubZhKs7Ri+Zv39NQePYS3hwOsct+Y1HQeyiY0d9S5wPN1wuY+E34Xx9ukKpcHJplCZmsT/eIyCEF6ZOVMgoFLU/LaSUFU7r9ZLJKeR5qRs9XVIocNT/8n59jCJjMPgeBRxGSPFo1oDmEMeHr/F1hAcNr6qCwhIOyQAqhXzvqq6fVISjJXdeUXv9LJk3bipVr8IvdjwhBcJM CPQrxQH6 V80ad6llzFsrExdfIv3afxlHbGhf0oBiYlC3GfgnryG3/JJlUeauNep/s8oknf8VhHBI+okcHvOddMH0mHOQ+yjJpJ/tNIoHCHplTfsY4BigT8Zc7ImkqG8lNjAlOGZ0qltJBjkTwPQdU4UGNCPJ9Rm/FRhz1H9ajIpCTGKZX30Y501YUegO12JJdH9w7q7G//H/PmHCmZzQOYuVjGTBFCdReUTqi4RsjcWLjmXGl425+vuw71pHWd6Rb4Q22SBtvlrhxernM8cdEA4ddiJxADvqPYkpHgEjcQxK7UNFdOPdP4XlTC6UthA73FXsInqssd8dFTZ1vF0UEnzIsx5fRpEyuFPoL21g/BDAHJEez/ego2J8YGKEuz7xevAFzBDb5eUrW6WaY99nPJ47EIWrqGD7EOKzLCqAmjh/pn7KteZYz1L8jaiX4kHUmOl8ry2xsQ3BPiTX+EHqHyLahNJ26CASWKcNc1zHaBC7wYgsoU01N5EIEHVMzDqKVpDSa0xXLiZNK4+8wYjtsYOfp3qY3jDXpzHDA737Qf1JR2Kq772vis4w= 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: mremap uses vma_merge() in the case where a VMA needs to be extended. This can be significantly simplified and abstracted. This makes it far easier to understand what the actual function is doing, avoids future mistakes in use of the confusing vma_merge() function and importantly allows us to make future changes to how vma_merge() is implemented by knowing explicitly which merge cases each invocation uses. Note that in the mremap() extend case, we perform this merge only when old_len == vma->vm_end - addr. The extension_start, i.e. the start of the extended portion of the VMA is equal to addr + old_len, i.e. vma->vm_end. With this refactoring, vma_merge() is no longer required anywhere except mm/mmap.c, so mark it static. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 8 +++----- mm/mmap.c | 31 ++++++++++++++++++++++++------- mm/mremap.c | 30 +++++++++++++----------------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index ddaeb9f2d9d7..6fa722b07a94 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1014,11 +1014,9 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma, /* * mm/mmap.c */ -struct vm_area_struct *vma_merge(struct vma_iterator *vmi, - struct mm_struct *, struct vm_area_struct *prev, unsigned long addr, - unsigned long end, unsigned long vm_flags, struct anon_vma *, - struct file *, pgoff_t, struct mempolicy *, struct vm_userfaultfd_ctx, - struct anon_vma_name *); +struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, + struct vm_area_struct *vma, + unsigned long delta); enum { /* mark page accessed */ diff --git a/mm/mmap.c b/mm/mmap.c index db3842601a88..fb0b8f2b8010 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -860,13 +860,13 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, * **** is not represented - it will be merged and the vma containing the * area is returned, or the function will return NULL */ -struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, - struct vm_area_struct *prev, unsigned long addr, - unsigned long end, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t pgoff, struct mempolicy *policy, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) +static struct vm_area_struct +*vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, + struct vm_area_struct *prev, unsigned long addr, unsigned long end, + unsigned long vm_flags, struct anon_vma *anon_vma, struct file *file, + pgoff_t pgoff, struct mempolicy *policy, + struct vm_userfaultfd_ctx vm_userfaultfd_ctx, + struct anon_vma_name *anon_name) { struct vm_area_struct *curr, *next, *res; struct vm_area_struct *vma, *adjust, *remove, *remove2; @@ -2501,6 +2501,23 @@ static struct vm_area_struct *vma_merge_new_vma(struct vma_iterator *vmi, vma->vm_userfaultfd_ctx, anon_vma_name(vma)); } +/* + * Expand vma by delta bytes, potentially merging with an immediately adjacent + * VMA with identical properties. + */ +struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, + struct vm_area_struct *vma, + unsigned long delta) +{ + pgoff_t pgoff = vma->vm_pgoff + vma_pages(vma); + + /* vma is specified as prev, so case 1 or 2 will apply. */ + return vma_merge(vmi, vma->vm_mm, vma, vma->vm_end, vma->vm_end + delta, + vma->vm_flags, vma->anon_vma, vma->vm_file, pgoff, + vma_policy(vma), vma->vm_userfaultfd_ctx, + anon_vma_name(vma)); +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator diff --git a/mm/mremap.c b/mm/mremap.c index ce8a23ef325a..38d98465f3d8 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -1096,14 +1096,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, /* old_len exactly to the end of the area.. */ if (old_len == vma->vm_end - addr) { + unsigned long delta = new_len - old_len; + /* can we just expand the current mapping? */ - if (vma_expandable(vma, new_len - old_len)) { - long pages = (new_len - old_len) >> PAGE_SHIFT; - unsigned long extension_start = addr + old_len; - unsigned long extension_end = addr + new_len; - pgoff_t extension_pgoff = vma->vm_pgoff + - ((extension_start - vma->vm_start) >> PAGE_SHIFT); - VMA_ITERATOR(vmi, mm, extension_start); + if (vma_expandable(vma, delta)) { + long pages = delta >> PAGE_SHIFT; + VMA_ITERATOR(vmi, mm, vma->vm_end); long charged = 0; if (vma->vm_flags & VM_ACCOUNT) { @@ -1115,17 +1113,15 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, } /* - * Function vma_merge() is called on the extension we - * are adding to the already existing vma, vma_merge() - * will merge this extension with the already existing - * vma (expand operation itself) and possibly also with - * the next vma if it becomes adjacent to the expanded - * vma and otherwise compatible. + * Function vma_merge_extend() is called on the + * extension we are adding to the already existing vma, + * vma_merge_extend() will merge this extension with the + * already existing vma (expand operation itself) and + * possibly also with the next vma if it becomes + * adjacent to the expanded vma and otherwise + * compatible. */ - vma = vma_merge(&vmi, mm, vma, extension_start, - extension_end, vma->vm_flags, vma->anon_vma, - vma->vm_file, extension_pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); + vma = vma_merge_extend(&vmi, vma, delta); if (!vma) { vm_unacct_memory(charged); ret = -ENOMEM;