From patchwork Mon Oct 9 20:53:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13414429 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 77593CD612F for ; Mon, 9 Oct 2023 20:53:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB73A8D008E; Mon, 9 Oct 2023 16:53:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A670F8D0089; Mon, 9 Oct 2023 16:53:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E12D8D008E; Mon, 9 Oct 2023 16:53: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 799578D0089 for ; Mon, 9 Oct 2023 16:53:38 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4EFBB40370 for ; Mon, 9 Oct 2023 20:53:38 +0000 (UTC) X-FDA: 81327124116.27.4AEA5E8 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by imf11.hostedemail.com (Postfix) with ESMTP id 65B7D40012 for ; Mon, 9 Oct 2023 20:53:36 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="FvjSx/EW"; spf=pass (imf11.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.50 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=1696884816; 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=jochmgf2oxyHl1Fdsf6/Z0vhz675AmN7EMJ3Y7JXYH0=; b=Z5sMADaY/y6q9YZZSYTcCNyuvjU1G0AUR3TO3P3LYaSrTsL2UgM8BGQbseAdFXfBvaJPrO Gxnx2DME1kmNjDb37n4UC6cHTjHm4SQavYPMA9aCAmdKK4IT+qJrjoK01ypTef4sHOnSyQ fIXux4UcWJ6nQwqB5iemN/yrJQiXxLU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696884816; a=rsa-sha256; cv=none; b=5abdAew3eRyLljVHbJ86ioDblqpkBoxiMkUoomWX/A+vPpr4NY84CkZnkwc4vX4dJREioR 2rzmi/bOfaLBYavW/hwdqtgZcefBnE2LD3becn2uvQDVgjIWgYqW/gL6ISdaUNqUUM4xQF GWGbK0t/8vv9WQTlfcyrLFNWGfUkM7o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="FvjSx/EW"; spf=pass (imf11.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-40535597f01so46921615e9.3 for ; Mon, 09 Oct 2023 13:53:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696884815; x=1697489615; 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=jochmgf2oxyHl1Fdsf6/Z0vhz675AmN7EMJ3Y7JXYH0=; b=FvjSx/EWYS+QbnuGEZJhBTNQ1XAkMQ2Kqx26RhH1rx5Vq3CUYs42oIrEksHE/UfIfP AmfRUGDgPpTIoSdiX9H5RFLeynrb4seUz7bJuAXEH+bkgMESVeBFSyRRxfcL+dwnFvPN gXmXrY0fT90WjGhkun80Ug67ySCLQHtB10bgWiDHMWj1SjKMwoTgbyntSYTmaLynx+Vj 0/uMHlXGHN2fgLGQfZpY3PguK/OznllvOjGzAOjwY3djSvNHQkG2UKmd3phhrpBP9ef3 4fJNX2FHsXbKVa0G97vAq0gHhMHbEBuxpJrXU0am68KBqpYek7QvM0yCkiGESZaVycQ4 1Zsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696884815; x=1697489615; 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=jochmgf2oxyHl1Fdsf6/Z0vhz675AmN7EMJ3Y7JXYH0=; b=JQXCph4Qo/FfwBr8ILeGK/OpqnEtWhnsDI3yonicLd+2tWK+zR65ajDLxl7Z2l8TPP MnV1cHE/A3KStx3d/6j8JHx0uoyv4s63EHL9nq61/9/vZ8ukrH24jFYet4g1BF1rX7dT iO1qvD3mpNT8yyRC+/jjPb0QmVWQMQhmhXgM1DbDbUDZ1h39zza/CIV8AnRePzWZ9nmA 48nUMX9KjlWII4lOx6KsqW9pw/nHxMjHs+lrUCZdYNntHCOGB2kyeC2nXLiJRuqg1lta BowOU43ZlohdfBqMVj5YhgfTzwEtCC8OAG+4lGBGAa1e2jFIvcUY2E8p4THMDFF5mfeH M46Q== X-Gm-Message-State: AOJu0YxPE0k+Kn3oH3Bw6jP+cPBXNrZJIURFJl+GNeQO+dBEyJOSu4ax TcJcJ7ePWQtS0NoxrJvYcojiQWjXcBA= X-Google-Smtp-Source: AGHT+IEili6yjcpf1CIpTHpX1KIvbP9i7YisloKuaIxOeqWIbartUF3HE3nQKw8VeOEZ+cxXGxy9ng== X-Received: by 2002:a5d:4dcc:0:b0:321:62b0:7ad8 with SMTP id f12-20020a5d4dcc000000b0032162b07ad8mr14148854wru.16.1696884814438; Mon, 09 Oct 2023 13:53:34 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id l2-20020a5d4802000000b0031fe0576460sm10578130wrq.11.2023.10.09.13.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:53:33 -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 v2 1/5] mm: move vma_policy() and anon_vma_name() decls to mm_types.h Date: Mon, 9 Oct 2023 21:53:16 +0100 Message-ID: <4f1063f9c0e05ada89458083476e03434498e81e.1696884493.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 1aybyh6jqhcqkkrehzajtn6pqw77c5xi X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 65B7D40012 X-Rspam-User: X-HE-Tag: 1696884816-376705 X-HE-Meta: U2FsdGVkX18QiP3uNd3zNLoF8KxNfocNZlGdWub2q5xy37dxdHSQhr07GKjwhgOeDBIOJioneqDPmcpmBKJeKc/3eB0/qeO7UFGrxG6fWoVPBAmeciUwKyvYNP4LO+pLh65I/vVzSs2pIqDfjWuZ3s8TOwnuA0EysDCMhqYOWDY28IH5sIl+36DiDR0Nu0qy5eOFInYhAR/eCRXd0ko/UqQR6w2uabv2Vxh4AVL3L6eVhdJA2M26oWp8vEUWiKVzDAy9GOVzcfOxq/WGGKLdJjBOvDmwIpNDfd01pe4OHON+mHX3w/k/i4k45kHxJJnIg/UYZX317euXQvJt9K17KF2Yjwm9WmLs6rk6Xc6EOVMwuWmxfJQQ4Q3OQA7GnvP4ZrYmHeS6RDaqq0uZC9tPrNaR7U897GOxzhFEUcfKH/K7ib3yOWPUMhbh5os/sYxyjT2EyNnlqtUF+NajKZfWteH5LmGmh01MABiFACqf4/9x6oFiXHzORgpea1MFnIOG1u1lJXfWJftba+NxuUh8U/oPTGr6N7zUFkYcykjGzEJHHd6F+T0La/USSDz6QR3mgmxjs8xiz0T4DjBWGAGzHWSUlWOy+2zD5TrwqJZu38p22R+qKqssG2gPS/3mF5TqtGNEZ2of8gGqT6MH1pe1QuRzH+ts7ftwQrIcaz2GRmisoOQksDGsQYAJhFahrjszfq1/8LBgsnm6ccTb0XezZh7gW6AdQ96GhsJwYaMCipmpx5ElWMcmWB0gELDzdfF433O3w67VqVNKi89Cs/3nOUhC3RslsabfNdJ4h1e0obWl+jLtxeEzk3Z3hibU4XOmkRUyBFpNAaTwFJ3QAz85kUHb/cPANhFSLNN7e94NFXi7ivZOo3qH7klvW7Dp/d4AS7V/mbTUYmCV1BjD9s663XUwN0GSk5d4a/3MTtg+RMG3r3uKAC22BbL5dKk9nAAHcT1qfOODn8HNbQExABr dvSw/v0D OhJmWhljjjNfRGcSjVyzf+SKA1NSVgTiJNuIP5MKo8ZwdGsaBaV5M1a+E3IyDxsHRR9KmF5t3IsPNjoLDIzp8wacs0jmqX7QWY/7KAYIVUWimo4bkeol6wnLIjCIWXAK5edzQf1jsrNekTownejLFFGbMLvKghullr/5xBXCR/EQhhxMUWKA1Eb2eI2iMOo0Ur+R0oIra3a06CWthyaRl7JuHsdOrC46XUuS35vvWZsDQvylru4vICfewRek3pLPh3e+TiLkQH0LKaYX4R5ME+WKWaViIvkzjhUZdDWflQlxuerEsB/MMQ44khvS85mVpVnfmtUxqq051bD4FqbuKG3RlK2u+mPdolJvl1/ESTAwRD8Df2onoNVEPU6n+H3rKNKuHSuXCmrmyUEXhi0+oiAnB7R7CEUlYgyIoijnH/9VI461Ljw+WW150LGWNfXVAoAvZcQurss96hzahc07q+s1YRUDxOXapmPKxoMnbQrggQS20IULFB1ZkSJ1ve09oQCjh 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: 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. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- 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 Mon Oct 9 20:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13414430 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 54084CD6136 for ; Mon, 9 Oct 2023 20:53:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4014B8D008F; Mon, 9 Oct 2023 16:53:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B1AC8D0089; Mon, 9 Oct 2023 16:53:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 204C98D008F; Mon, 9 Oct 2023 16:53:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 01D3F8D0089 for ; Mon, 9 Oct 2023 16:53:39 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C857440368 for ; Mon, 9 Oct 2023 20:53:39 +0000 (UTC) X-FDA: 81327124158.19.84D607D Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by imf20.hostedemail.com (Postfix) with ESMTP id D518B1C000D for ; Mon, 9 Oct 2023 20:53:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cNG18EQF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.42 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=1696884818; 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=VKLx1ja8HeC2i05aZCboTLTuiLTHyhLExxAZQjBx8ig=; b=3jErtNmHAYatKCLwt3n4lh5vR1MTdNmGm/GxRBXxfGX5UCnEcjumCv88KkmBxhgqJ9ryNf nLjsb5UbrhrUzxkZqKLmGwOeESo8wpB8Ljoj3cvQT5oQ1dG99LMKCnp9iLmrd8ny4P+FBQ hqaJwINQPcCPN7wSTjlv80G4YKXTzo0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cNG18EQF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696884818; a=rsa-sha256; cv=none; b=S1qytA+nH4p4G5ZFb6WkyQgWUUxClxZaw9ShBXFW/YdgzMI2TCh8IRY87qsjxhcvzJVIVY HqSpz43EiqoJqM8GxdBV7h7s0uoHlCTpRhiIYLaek2fN3LsPnc7zGkpwUwNKAyd86YQHhJ 1UXW8JG+E/gBqE+bYXa4IVHnJcpiGAQ= Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3247cefa13aso4580261f8f.1 for ; Mon, 09 Oct 2023 13:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696884816; x=1697489616; 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=VKLx1ja8HeC2i05aZCboTLTuiLTHyhLExxAZQjBx8ig=; b=cNG18EQFCaA5n4Pc0+J1eDpK77Z/TlUSub3+VFcddGqaLihRYaWuqMaUx8oPBtKNmO wd1nogA2W50QnQ2J10QTQKDKxugzAQAkX/m/JSUxQgrNlkqmCEorqAV4MsrxSaW6OzD5 aYQWKUH/NLAg8bdvspiewZDxkCVqpEcPXL2yHcdE7GW3MU6YDn9KcSOQrmH9v45bQ5rQ kRFEXvplnG43/cebIPVdnn4RrCx2izOwWIaBcP4uXep/1QzpkSEG+p4s7mu7j4pcTKCt Zhqi2QE99BZ4iF7sGGTuo7hW/xptB5sD6Lsd+TT+cMbJ81+qv0DSPlMadHpVbk4cQyBO q0QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696884816; x=1697489616; 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=VKLx1ja8HeC2i05aZCboTLTuiLTHyhLExxAZQjBx8ig=; b=exYYE0ZaGC+yBPFUbCI0INDrmiZPjBtT+1W/ij48RQKDwGQsiIRvv8O9FmKHcafAuq iQWdaiUD/5tNZW+odSDf/+6v6o2L5tJR0ZbdG0vQ5dzakOQkxQeQ4E9cVvczSafyb41b 80J7XxeN038yUynvlZW4wB7MU1e4lJRQbKP/51XTt83bG4wxAcUHSXZt2XfOzO3YsiZi 2Qlug2uM5vwH6W5PEV75wgIU6yFnuDId6/ykQyGn2zxfpuhb/HuLgQwEdRNC1shKZSjT jGTXNzAyABgCers/npOvxQ4CBDYcV6+EvYLAvRxA11pIIasyasBrn9hsyuKmNugwyWBK /CjA== X-Gm-Message-State: AOJu0Yw2xJy0l1fy8k4pES9Uxx+SakDHTDoPGPpyAwb1Qc/YQKjoxktY hKVY6gizflfBPaGxHYHjlJ0oWs3mjyw= X-Google-Smtp-Source: AGHT+IE9EsWvW05b+ffVnXE+d0/62Zwj6srI+4rcsUf3IhmIEVtijSpGOd4JlWGDSz6OraG+tmIFYA== X-Received: by 2002:adf:f74f:0:b0:319:68ba:7c8e with SMTP id z15-20020adff74f000000b0031968ba7c8emr14458485wrp.38.1696884815913; Mon, 09 Oct 2023 13:53:35 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id l2-20020a5d4802000000b0031fe0576460sm10578130wrq.11.2023.10.09.13.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:53:34 -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 v2 2/5] mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al. Date: Mon, 9 Oct 2023 21:53:17 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D518B1C000D X-Stat-Signature: t8cbqmauxd4pngoiq1b5hq7qm99733qr X-Rspam-User: X-HE-Tag: 1696884817-318710 X-HE-Meta: U2FsdGVkX19CHmvY3RQhp6Kk+JtNh6q+PjWvNcF3NWvC60NAi76gT1AoU7SsC74NXOj4pTsIdsVI8vq3Kn+KIuGM5shTvZMKFtbHqBD2KqdpkfVtaYuWOF1izPgpXYqVcZt4Vs0YI08e1Byb5iloBHb9jTXS6r0TC+VH517jI/QTe5fnpmY6aYAuGeYLOO9Q4KldBe2l0dEbZD4WeJVB7jFeS4Uytlsu7J6xCLBXfpW5y59kqcMre/hyTIFGWhb+DEvGY6IpkS7Jvfe5FPJ672u85ZEZfm+VWzyBaPBkAFp43m9iw0Sz5usLybp0rnIVUm9w+BSt7T/x08+M7qRr9H7G6+I6qZjh6ML6yN7CvEmrqM9I8UJLEE8Ey3WeOlcvq2UP3lQ0gxUPt0+7npxC37Q6Yvf7qmZPl05mHlRJGpOgSIMuo3iwvOyBH7oaT06q/+tA56YlCttFDopx0NslK7A4vD58LFq968144X6IDQ1NZGzogviE8HQpA08wUUsdbci2F8s7CeYUQA6Qvt6cJB4SjgYBXiUvAna8vMyF5bPdGrcrjC32rjLru1/q4MAmPH+eW5XSUUM/WO/+tCxCg2kR5RuwAvDQ8BWNvLgSGV10aze739ZuIH220e4kZtXoyPgSp1tHXgKSat+cUTm1Ja+wfUlyJjHl27D3KNC5b2dUvfrLbhhwkoZDXbbm17EIBIlasjD0ULgKMx2NRcnUvyr6b60o6X7QKLubegMbeStqVXQ2Pp3/m0LnSPgVUfVqymMnrWeC9lo94FXeQANLEvhP19ZMcKHB7MxpxthLYr2K0MVYQfjEhYUbN6HmqA/nVCToEBsSCjZ1u5sqB3oIL0M+Lsbm+eEYpM7KBDWCxbJ8lT+EmcJYjS0Uhx5Wnhyq6DZBSzpjWHKpJ1dr1kb4sqFsZLybjKjAt5xmtEkcnZA96GkIzkzm5XQuFgm4hvlcIW3SXIegOiUd5GRcluq jq1JgBnR Hmfq0O5/oDp3DZBRw9wH3M5JLfOxpSZEfUh+df6ybTNIG8Kykt/lOuxLMrDOmlc6eIMQQbfZnBbPvdVmg/iriFLXYEo3FBRGMh4wP1zwHbS1m5Woc64x42La9GPJ9KVQp07V2IZVJtrTxoNsfHwdLNJaTcuJ9CWp9j5Ma60xx/vSsuhSsMjPRbzFKyld6DDjGXEVVb7qbRrFdhHQ1ToCwsTmTbOzEpXRrLEvFp/6vhfbQeQjelWQJfVzd3XobS9MStOn8odtrc7qYT07lfHFJ2k+SFxPqlkVIgf99wcg96kTiu7J9hAkHlvW4ZU3z7UHOStnViTTImP+Hlc0BAq1t3PVD642zECjJh1JHOfXQxRKdNL9R6XC+VZoNLm0/C2v/oZwnShWZvd+mfL5aUk9ZzzRp2TkD/DUyISUSsHsOy2rusMEZDGhO4KOqvzavkkay+HHKGzOHqvO5Od9F92CMzAt34CZTIw1C9ojB 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. 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. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- fs/userfaultfd.c | 69 +++++++++++++++------------------------------- include/linux/mm.h | 60 ++++++++++++++++++++++++++++++++++++++++ mm/madvise.c | 32 ++++++--------------- mm/mempolicy.c | 22 +++------------ mm/mlock.c | 27 +++++------------- mm/mmap.c | 45 ++++++++++++++++++++++++++++++ mm/mprotect.c | 35 +++++++---------------- 7 files changed, 157 insertions(+), 133 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index a7c6ef764e63..ba44a67a0a34 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -927,11 +927,10 @@ 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)); + prev = vma_modify_flags_uffd(&vmi, prev, vma, vma->vm_start, + vma->vm_end, new_flags, + NULL_VM_UFFD_CTX); + if (prev) { vma = prev; } else { @@ -1331,7 +1330,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 +1482,17 @@ 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; + prev = vma_modify_flags_uffd(&vmi, prev, vma, start, vma_end, + new_flags, + (struct vm_userfaultfd_ctx){ctx}); + if (IS_ERR(prev)) { + ret = PTR_ERR(prev); + break; } - next: + + if (prev) + vma = prev; /* vma_merge() invalidated the mas */ + /* * In the vma_merge() successful mprotect-like case 8: * the next vma was merged into the current one and @@ -1568,7 +1555,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 +1657,15 @@ 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; + prev = vma_modify_flags_uffd(&vmi, prev, vma, start, vma_end, + new_flags, NULL_VM_UFFD_CTX); + if (IS_ERR(prev)) { + ret = PTR_ERR(prev); + break; } - next: + + if (prev) + vma = prev; /* * 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..801d3c1bb7b3 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -141,7 +141,7 @@ static int madvise_update_vma(struct vm_area_struct *vma, { struct mm_struct *mm = vma->vm_mm; int error; - pgoff_t pgoff; + struct vm_area_struct *merged; VMA_ITERATOR(vmi, mm, start); if (new_flags == vma->vm_flags && anon_vma_name_eq(anon_vma_name(vma), anon_name)) { @@ -149,30 +149,16 @@ 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; - } - - *prev = vma; - - if (start != vma->vm_start) { - error = split_vma(&vmi, vma, start, 1); - if (error) - return error; - } + merged = vma_modify_flags_name(&vmi, *prev, vma, start, end, new_flags, + anon_name); + if (IS_ERR(merged)) + return PTR_ERR(merged); - if (end != vma->vm_end) { - error = split_vma(&vmi, vma, end, 0); - if (error) - return error; - } + if (merged) + vma = *prev = merged; + else + *prev = vma; -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..6b2e99db6dd5 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -786,8 +786,6 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma, { 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,27 +800,15 @@ 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)); + merged = vma_modify_policy(vmi, *prev, vma, vmstart, vmend, new_pol); + if (IS_ERR(merged)) + return PTR_ERR(merged); + 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; - } - *prev = vma; return vma_replace_policy(vma, new_pol); } diff --git a/mm/mlock.c b/mm/mlock.c index 42b6865f8f82..ae83a33c387e 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -476,10 +476,10 @@ 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; + struct vm_area_struct *merged; if (newflags == oldflags || (oldflags & VM_SPECIAL) || is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm) || @@ -487,28 +487,15 @@ 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; + merged = vma_modify_flags(vmi, *prev, vma, start, end, newflags); + if (IS_ERR(merged)) { + ret = PTR_ERR(merged); + goto out; } - if (end != vma->vm_end) { - ret = split_vma(vmi, vma, end, 0); - if (ret) - goto out; - } + if (merged) + vma = *prev = merged; -success: /* * Keep track of amount of locked VM. */ diff --git a/mm/mmap.c b/mm/mmap.c index 673429ee8a9e..22d968affc07 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2437,6 +2437,51 @@ 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. + */ +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 NULL; +} + /* * 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..6f85d99682ab 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -581,7 +581,7 @@ 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; + struct vm_area_struct *merged; int error; if (newflags == oldflags) { @@ -625,34 +625,19 @@ 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; + merged = vma_modify_flags(vmi, *pprev, vma, start, end, newflags); + if (IS_ERR(merged)) { + error = PTR_ERR(merged); + 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; + if (merged) { + vma = *pprev = merged; + VM_WARN_ON((vma->vm_flags ^ newflags) & ~VM_SOFTDIRTY); + } else { + *pprev = vma; } -success: /* * vm_flags and vm_page_prot are protected by the mmap_lock * held in write mode. From patchwork Mon Oct 9 20:53:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13414431 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 AC7B7CD613A for ; Mon, 9 Oct 2023 20:53:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 786178D0090; Mon, 9 Oct 2023 16:53:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 732AB8D0089; Mon, 9 Oct 2023 16:53:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AC6D8D0090; Mon, 9 Oct 2023 16:53:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4866E8D0089 for ; Mon, 9 Oct 2023 16:53:41 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1AF241402FE for ; Mon, 9 Oct 2023 20:53:41 +0000 (UTC) X-FDA: 81327124242.03.95C4146 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by imf05.hostedemail.com (Postfix) with ESMTP id 43582100018 for ; Mon, 9 Oct 2023 20:53:38 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Am52EhsE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.42 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=1696884819; 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=TNmdoeRWtzhEBIdrRfXv8hL/K0SAgSJWqJyZUiMnE00=; b=U70YFR1Z87fErOemcSyKIWvgm6fn+4nsejE4dY166h0vDOsUwp81ajnVfF46bQq4rS8/w3 5SBrzqPK+QWpmLQ/sTd3hQ/SX0gZQ38sdW9DCO1OunZgp1SCw2b3GDTZAZ44Q4+paJ76Io mY7z+q28I27veGMRhHQTKHIfbLZZszA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Am52EhsE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696884819; a=rsa-sha256; cv=none; b=uQ/vIwgdujAL+mpSFqs0EZ2ttXyROqogCswghB9/jwmzrKrYMx7uaNf0cl/g0CtXnyQxYE TP6n4nY55VfzZmrVnaJ6OaeTCP4fnps7fSWuearzOWw8Y/uiwt/lnDo8sa2YDdHABeSSWy x3eZzIOZyazSOIUy7vQwQVFJNEnq9uo= Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-32003aae100so3661800f8f.0 for ; Mon, 09 Oct 2023 13:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696884817; x=1697489617; 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=TNmdoeRWtzhEBIdrRfXv8hL/K0SAgSJWqJyZUiMnE00=; b=Am52EhsEjr/GrcQMMkJNf/pYEzi5thVH8hrUpyPTGD5geSEq0Qi5cQZPVJamwyRkZ1 W8ZwtRY9pFMTYCJ8z1VViJUI0LdCc2FpEbM7cqkkMbpnvFM2vUVrppAf6fX8mMd1qhE5 0ptSk4z2oWG4/wtcMDMj1BOGsXimGBkBOBs+P9XzN8tc8VadEJCRs6jvLI/Rl2VSZ2pF h9NmoOlh0cf6t2JyNMDi7TAKJgRiy1bpX0pl34qmBcLlIC/HiKPyeTgPxNJlZaBt69I3 QSofNHo0jDUb73XN0BH8XjX6ZBI7S8u6hXkXCP99+i6Vv7p4XFsaLO4i3yLPZ3aAd6Ye Sikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696884817; x=1697489617; 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=TNmdoeRWtzhEBIdrRfXv8hL/K0SAgSJWqJyZUiMnE00=; b=eAidOqR5U2QXzqERQfVZT1MaYSWuiU9bSdf1pDCdBIECSA2bxj+u7q1OpW+tokrIAB M2RC2vh/bq5CZ/FMMHOKWQNM6GJGo+/gUVJ+3QOj8koncJAWtExN34Td/qjajJGc2Wwe 34SPXV2HyNWV2Xzq+MfLQG46WFjywgMwuQVDjqB2D8gHt9v6vnqaxlnuKoT8MYQ7KoL3 bYWQMfiy5salp4CDNZA1FXAG51JTOCKjpBIm6x8QLTDGeqFtVNfT0RA5LcYo3IryUZHR UsW+Qo4oceNQ6E4Xw2aCFr4FOUOP3LFmQ74mKe7RKD/i5hImSLkkt1p7u64wwdNbJ6bA yLVA== X-Gm-Message-State: AOJu0YxxbHHkU0QPHQN0VZbIQlFn8/Ao486qGGuzAQ6MjtvECjKfHvCD byAH9ZA6VBcdJ1muzL8fKFT0yYsqbKM= X-Google-Smtp-Source: AGHT+IGxaxbfOsmbWfYeIketHcaygFp0L6cqjHa1Rm6inszqpIbIyR7FdF/1P3t2wIMfyeWkX0LuMQ== X-Received: by 2002:a05:6000:3c3:b0:32c:d29c:2f77 with SMTP id b3-20020a05600003c300b0032cd29c2f77mr40326wrg.1.1696884817261; Mon, 09 Oct 2023 13:53:37 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id l2-20020a5d4802000000b0031fe0576460sm10578130wrq.11.2023.10.09.13.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:53:36 -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 v2 3/5] mm: make vma_merge() and split_vma() internal Date: Mon, 9 Oct 2023 21:53:18 +0100 Message-ID: <31d2c79f7a3bca03d4a4c95e98d9a27cb1f99bf1.1696884493.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hok9s47pfjzd84xnyd5z57443b5ygamj X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 43582100018 X-HE-Tag: 1696884818-567262 X-HE-Meta: U2FsdGVkX19SlmEVeXDjsBje2sv8qAJdydQ5xse0ns6lch9hNM1QPpZJL+NF1Bt/p45dzq/NROuPX95z9xYrzarGVij80AKVzeTbfzbfR3MbEjs974g4I3GRgE2YcpWBhfjBby3SzAZ5DPy9VTNWDPgLV4md1RAiutWRH+ufA6UzXyiukMiHca1AKRdmomqFeuoRqLPce+0RrSj3u8uBh67gk5oSlKdsvMd8p0pq9aoRDp6Am2oGr0Hc82JTkefU3eVGqa7o8EjwqXr+uA4we259EPokArJ3VrlWt6ZltQGIWw5e4YHCREkQEEEfSiumhQp2CUMT3P5fc/2xYKUue9UgRUvXKnfBaGN2H+DEn+M22clpzc3duhsOVO+/pb1xAjteeyS6M1f2/rNyo3CPM9gto5R0KC8mUqnFuGCId3WcYe+Chot+BF1nrjNlEykIsvfg0S/FD2/iaZ586f4F8+aQY3essqMp1Imv9W31gUSkZysZEc8xbjw+ydfGqORgYK3HAsqDl0duJz7hyaxTGxv7TKRwKUJdYmSkIDBDS8KQVtWnwSnMaj780vO/RR5X5ogCDxJr2brY4W+O2WOCC5RIoyDEwuQLOkDifwIEfueCoEB6Q8JYZ5WeqffrP8JNnv1/5Fqva0F9TiqHx/gxr9DeCwdy53jxQsej5A25grtYcA4dtvNKRYWqTCVUSOCg2iVB8rW1Hp6igXSNFWqAuRaXct7ZzWoCaROUDdcVOO4isXUhy38pmOaFI3EfsW4j48V1wdBi6SYJlRk7+WMhDtEVu5nmBQlLR2KMG7Zek627txejPzo9gpZ8XdGvHuvGkhn7JXqBQkqyujRmTqX/TiEUXzGl1k+jSDXKrwGzhRiDUKinAETDyE1EM+7vhMNi1lvluP7lbwgTtCCNW5wizjUxW0XQgPfT48eT/xs79nfXoblQtBHAr4Zb0KzZEuY2/fgJwzQpuQL9J7d69HT C0VQ623t SUP9OuqeEUVkjvG6AVPlE4ONxy7ydHitD4yCP3Wtz0oK/nWZIcrTU+GE4iNTfndDhPVUFP5UDQ1Sl++sbf20FG7W/TeuwBmXE8agOU6OBjrmV1Ro/e9qUOYL2kCJ7mV8wA7z+4BMPSHFoSV/O89LNMVmGThgss8ntdYE+zJZFeTx5yCMSTOPfDTDMwgoPvpllOF6t25MG1jka2J07IE2jsc6Tu85QybcZRj843UfnjfF7g5IgInEEWd1y+SvidsKIjxPdzTQjcxhKA4GKcAtBkdwt30CefgyrLRTSMNQE4+eRpPbva931pAJJZTWIwCtsHE1c9f7YbJwRVCf9+280yypinik8xrQ8XvG1r4Cjoqz1+Kke9vukOJbbHh+raqFVycri4NwlVo3m9hfxSwaSfrybNzs9T6dqiQkFJ2A2v2SBUHaM4FWXSMNdPBV6LqElRcWN1ppRJCQtq5fWNerPTOIcWgh344B261P4MucqN1J+tMcqK1IvEIEEZ6aRgyLTWQaI4lBw3NSbE6Q= 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 22d968affc07..17c0dcfb1527 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 Mon Oct 9 20:53:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13414432 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 42ACDCD6136 for ; Mon, 9 Oct 2023 20:53:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D019A8D0091; Mon, 9 Oct 2023 16:53:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C62668D0089; Mon, 9 Oct 2023 16:53:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB4A88D0091; Mon, 9 Oct 2023 16:53:42 -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 942548D0089 for ; Mon, 9 Oct 2023 16:53:42 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 650C0B4B20 for ; Mon, 9 Oct 2023 20:53:42 +0000 (UTC) X-FDA: 81327124284.23.9F010F0 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf19.hostedemail.com (Postfix) with ESMTP id 699F51A0004 for ; Mon, 9 Oct 2023 20:53:40 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l0SYogZ9; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.42 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=1696884820; 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=peKTa5JCQROacC2rkKD/EMjKt2/PWD6RJuctYYclWYk=; b=BXEWHN+x+7YQCfalGJ+SDLJu2lj/GoeNIq8YQsuCxt7NjhlvFWJzvJUZ2653bo5E5nKpIf 1o5gNi2mxs9834w7tE8sL/euf/OUlKveUSN2MFGsvs454s8zbjmYcjvsAeJpEY2Ly5CJQU M7zIR/8HJpKLunK4rB9dcfLQEOzv5oE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l0SYogZ9; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696884820; a=rsa-sha256; cv=none; b=vAdOEMjGl57eJxWbpPt/GnH7JaQoAJKnX/Ph99CpIJieVpT3vXDt5AmPUvwkFz5v+MZfEr p4oJk5mnDlScUVjhdHpvqtiQS50LbesvtANED36g3sw8bhN05BlChIBK9NS1ceE/FZ4oO0 5KC4Gamxjo5T1y/cR3epiV06Eb7EyRk= Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-405524e6768so48373485e9.2 for ; Mon, 09 Oct 2023 13:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696884819; x=1697489619; 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=peKTa5JCQROacC2rkKD/EMjKt2/PWD6RJuctYYclWYk=; b=l0SYogZ9nlka6YqCNtDpXmHIaib3U4wzj3GYln7IG9z5XQnfevl0VYZvKQ8a1ZpDO6 pWOAeVAd9VyOWCdI2UVRBL69Rf0cEBcd7ZhOV98DmwbnbG1bay5VJdvl3NmgXKPInb3C ywOlW/6R2NY0llltwqKCQ3nWQQaHOTzpwnFd/bGOseBJ8QMmIbGqHoPMk+zZmr6DbmIr zObcnoWvSB5IIHagKUhAaeJ2mu4R62MC3Es9in1Xl3B15ysAcB60pBb7egMjnKo9LABD r0SiuWmo6yjqv1hLCYoKZeNhHtg9eypK6zgIQ9tTLksxPEu3ZlpUJDzDc5Fwb09hHVcu EH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696884819; x=1697489619; 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=peKTa5JCQROacC2rkKD/EMjKt2/PWD6RJuctYYclWYk=; b=R8Fm7pv67eISKwBr5ojT3XI3LWRTCdnmQZ80RO7WT9tqm5TtOy9bFv12OJKYLpb/9w mJALLiFoRJY7hytQExrbKleHvEHYCXZitZgknIAVBYl2CwtdNfmbLejhda5TqbJs5R8L aDssfUbMrDHpRXXEm2caJg6W6CrXyCgKt+1VS9ldfce/Yukx2oo4AU9lS24yqhkIjDQX uz0Es1FOdPxcqCKati81XJq7gwMUi2Vw5BPItSr2G5BJHWcOZvkdDzNAl/0a0pABfls1 3O/f0i3ycnuHB5zCqT9UXmByn6twr9QwNAI6MZX0s5hZd6pQNhGITF9i7FxXIJ+J7JMd BfxQ== X-Gm-Message-State: AOJu0YyM+bbgxaWHIuXfdBCzhky6WN6ZG+x6qD+7Os8hjTR7CGbgTmqe 7EgALGZb3EEqdTeLgrkOFbti6IrLQm0= X-Google-Smtp-Source: AGHT+IECOr/NuIGQT0xwu1GNnQ3mzgM7UNNwWg6rN1KgZwpIM+meh3t/4/xhAlA92IoCFh4rHNSa8g== X-Received: by 2002:adf:a4c1:0:b0:32c:a9ac:2bc1 with SMTP id h1-20020adfa4c1000000b0032ca9ac2bc1mr216695wrb.63.1696884818605; Mon, 09 Oct 2023 13:53:38 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id l2-20020a5d4802000000b0031fe0576460sm10578130wrq.11.2023.10.09.13.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:53:37 -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 v2 4/5] mm: abstract merge for new VMAs into vma_merge_new_vma() Date: Mon, 9 Oct 2023 21:53:19 +0100 Message-ID: <8525290591267805ffabf8a31b53f0290a6a4276.1696884493.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 918gy8gpf7u8o5rchrht3amtdyb8rpmu X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 699F51A0004 X-HE-Tag: 1696884820-754089 X-HE-Meta: U2FsdGVkX1/A2XV/A3Ea5PMiTniBpMcW7/ZzAsHR7cSOztEn/6jFjFRy42hmDGTist1ou9k5iDcgrxol5WHGvssDHaktYgXhn56OxQL3mqOifCYNEyd5H40UiM4X8IlbpyUzGi98U+m1F0Mdmgl8M+TTXIdPvpXjwPnDWL/tJIUBmQDiJ4iN+XSWtwqE3Vam0frI2CcjtjaumFTvriI3fwyjihAiffCsienLCO1nIvr7uXVIuj5TrzLeKGI9F4yfhUDLoBkQKM1so002NpDwGLKWi01kdG2gIbNO8VYzyhYRfxVebVdi3EEHIzk+p3WlW1040+8CZoxD19wyLESBWoQwrafVjfX7fYu/SyXNGtVhIHXUZvfPv8ZrrIxmHWiN3/bS1QR8m2biyWFnIuUaeIVegaQilzX2bAJ3ZO7PD8AghbpzO+4+aXVdu4zGOPKNGiXeF6ewv1zCVCpb1tqomhc+VcbErAMeZUAPWILcC6Ko22+eB4vwVGmhTJSpN5Ubly/hoVeAGdU0RB8xgobg+USEIVqX2h3vrPmmVdYVIpf5nqBx5q6CrqXaayNiBeRqXK0LzM1Bb2CsWozsngffEyCrfIrPGbQcj4Eljv09av/Fb4YlvqlEL6fYOzkQ6zbYw4seNOGEaQoPtkNsC5vADUaRvATtGyoeLbOeU5azewiEm3LU2v0KtsQTEJVJkP+6zb2skmeUaXaiCbxzo7zjIE6yPmvnNmQ1CEmRXMGju+bJM4/mp5p2P+8hCpzsLqcCF51zgwiFsdKsy51LFTshPiDRMG0n5PzTJXLj7Wvy/6YN2eqUt+dtJc5mOpqWmgYaCxei6KKUltplfka2xpIiUvZpM4+8boHoeut9lP/Az3Ei5eb8FYdfkY3jMRn8NWw/veW3kVl85ercPuGh1N4EHFOqpqUKM1fAmehVd8A0qyfXiOI0OLSME8w3qx8yFiUM2GQSfrHRmnP7BsM9ND5 gapYPUSJ duDfypfwKle8Tp61J630tlIvU6o62+0DihKoG+k4yhPGF4zeGnONPwmMscES7Z7jIHOIWBUFDZ7singxg7PHdT1IN40wxQQJ+aerSszhCqTjccwyeOQWJF6wDS5umj1SEJXx7qBuZgCjXi4+cjR2LxDoBbNRUloev7taV748ZjP9WwvSl1t65o3U7bnkgtm5t6mdL8VwMcK4SFHPjKhFHCNaA5FEdDhcAu7/ZlvdDTFdf0eZ0PDCsrilzqVDEb2RNxJxdCdVer33D2QnWCkl5AUukCWAEw12VSQOW66aWNjt8o8ICv//2QfK8Ku5fXskJJdd9cxu8w/X4isH8kk6sTvoXE0EP9NkkyYZZWE4QOe4CtXVBhtANaDEvAHpG6i+ToLC9ZOZvKOpYJUtHYN5EWwCbcNxKXylbW6HMWWYbgSplxy1/+SK46lXkuvRmuNuS8bvj2Ih9AnciwXM44FP2y9kJH03Yzv4Fet6WIJ/u9V7o1NM6W18O3rX9G3X07sQTezK9 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 17c0dcfb1527..33aafd23823b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2482,6 +2482,22 @@ struct vm_area_struct *vma_modify(struct vma_iterator *vmi, return NULL; } +/* + * 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 @@ -2837,10 +2853,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 @@ -3382,9 +3397,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 Mon Oct 9 20:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13414433 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 AF6CDCD612F for ; Mon, 9 Oct 2023 20:53:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B68F8D0092; Mon, 9 Oct 2023 16:53:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 168528D0089; Mon, 9 Oct 2023 16:53:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 006598D0092; Mon, 9 Oct 2023 16:53:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E34138D0089 for ; Mon, 9 Oct 2023 16:53:43 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B18641203AF for ; Mon, 9 Oct 2023 20:53:43 +0000 (UTC) X-FDA: 81327124326.08.0BFCBF3 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf26.hostedemail.com (Postfix) with ESMTP id CD68C140008 for ; Mon, 9 Oct 2023 20:53:41 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=F3DSM57D; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.52 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=1696884821; 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=xL574zJuwTg3rbZ38h4Jjm16YvUMoLxu5gzcSq0qQog=; b=0vcgMvtp/sfGL6yyrFdgZs8LFCNf7k5RcKbvtaCX/f7lHGvfUSxVMl3Fa3pMG2veIQBMjQ X2iNj68NBrSHDsRqUy9KFpEm77FBrZuzAFTVkdOrCzsf6CC9afJudcMJUbPVwnEULdf3po Ruk1OoqeT4IXFRV7dFwZoC1FAWRraL0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696884821; a=rsa-sha256; cv=none; b=CBP64kPoDwN56I4V7gtoqdlszo4rdkyv1PfHFs2Rg3cjGXqGzlfBRLJEv9qtt4YQkDtiPy Y8XKSMjEWfYzcwaXA/kz8QyKn/PVi9J5zNI+tnOuQ1HtrqR8zhpeNPuLdWwXRTLbuS+PnT P23SIYzgVaXDF1iAhIyoFWRmATiA3VY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=F3DSM57D; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-327be5fe4beso4567197f8f.3 for ; Mon, 09 Oct 2023 13:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696884820; x=1697489620; 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=xL574zJuwTg3rbZ38h4Jjm16YvUMoLxu5gzcSq0qQog=; b=F3DSM57DrnIKfRwOzB0B3uGklGhxr1DIOO6P3t9FxfHe72KB7cTj269WKQwKwhzPEr GYAbJxPXayYYRgkVohjzdIxGrN5P/mXA+j012XFCXTuD4Wly2/v5vq2uAoeQqS6BOqeT suGuAUIIDpmJvjhx2rKmCUXNbD8v1IjUqe7J2COMoUgTjcntmrEaBNcYk3Ec+PYA3gOZ AyPhbm4J1nCJ8rFk0CoLW0uosewRGKi1hqQLLq+sTHwvIc2QwAkyRWmDrXlD/jauW9I1 t28T2Ygftv3NliJglwGWA5M/IjlwQ3y53etdWjSnPb4nD2xHTvIbs+edTu8HD6bWhP3X 3sfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696884820; x=1697489620; 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=xL574zJuwTg3rbZ38h4Jjm16YvUMoLxu5gzcSq0qQog=; b=Gttz+5Uwu0HCFEPUQGfWwz8NtwUCUQICX4hbiKoqGtyJzC37ruzfNd+p80ZhylA/Ym sWKvpOlLmJ+iiEWr451qIlPzJwPB2J8XXi8opt640AmX9EkGDa1+WuISUgguH0gXDBOq B3p+ujZz77veL9rPWo/9rtqsuGTPYakajWO/8NifC6cXa9YzZrZ7KN81hojmoyVyTici afiQLo7bsUmNcfqmAcr2MxRhKHcI5INp7TuVJN4TehT3kiNN1/3I9LXsyV1B8yjaP78l 9uDO1d5ovPdl9x+S2CRuZbwshGBDoNov+QV5VxKeBih+Oai8A7m4so30BxzjKRXK0El3 MrpA== X-Gm-Message-State: AOJu0YxsYFG2JSEGTtY1M3VlNQTcuxZy00X/gNdjPzp1JF3kFdil5RNP yiVPLsKHN2XyAgoVsGH9tl3Lv39OUlY= X-Google-Smtp-Source: AGHT+IEZcDJXfUk/m4asVym6HC8MzhKstd/QCfQCxF3CdaRPkCYRP2UAGVNJPPmMrmT3c3m/Jt2IXw== X-Received: by 2002:adf:e6ce:0:b0:31f:b7b2:d4e1 with SMTP id y14-20020adfe6ce000000b0031fb7b2d4e1mr14332666wrm.20.1696884819954; Mon, 09 Oct 2023 13:53:39 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id l2-20020a5d4802000000b0031fe0576460sm10578130wrq.11.2023.10.09.13.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:53:39 -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 v2 5/5] mm: abstract VMA merge and extend into vma_merge_extend() helper Date: Mon, 9 Oct 2023 21:53:20 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: CD68C140008 X-Rspam-User: X-Stat-Signature: q43zr1xzcpo17gsoaeqxbjd1dfmod5xz X-Rspamd-Server: rspam03 X-HE-Tag: 1696884821-724163 X-HE-Meta: U2FsdGVkX18G1j4ufzAhhHVAsJluJXvd7ZreD5V2HxY4mJwwK78VRqhmZ/Mi4KSX7H/fnhovfrJZfQqBzq5mofT6OQDwC82IdFEdVB07H5MglSj5Jq77kwph79DsoauYzFbhgQGEaxOo4DwvtbY6uCw5Na9pBxlcTY5mjHjGuXNMRN0ZkViFBstx7GEgA1cXCkoqDeegreEzvzud2tIIlqRT5vVChDnGxrI/mKFuAcdcXWiMPfkhGJjEloNuXSHyRJBR2DJDGN9rXLaRjzSn391gfpPtNzo2D4r6GXwbSabxX/DnBglkDyzW6UfrHkxfI+UMZ2vouqpW3fYbXWDCrB5jiOf9O7hhneT/PcQ6KbWVNt20clVMFxl+9X0oEFL6Mso7RL3FfYeqxkxl5RMosf8OOrvEDAzmU5mFj3l+5H/MPa5U26ahlApKgDeJ7iKFY4Vq0OdHXTCrSHTnhMjSug+BTQ/SHGYRuBPwZlAEb53i5+6PevvM3Z/WlJWFDRbD7inSnIqRruGjnJlyBmUV4IrHPw8eTzi1EEXtIk3+JDg5e+kp5AVsyLF+xaVXChn0XXZY/wHiV4MXALYLeWKQbD1dyRL7V5/GqXVD5XBETM+Y5a7TXv1BgbxwE03VhfGLxBe+YVt1IY0M9jpuG4bmeW090B2VxW0DMRET+REenB4a9IxpFbYXI9bRL+5yIfFshe8PzDgczQs77A+yK0Vy/u3/MdiYR0pn/xQ2iVfzSfQY+CX99PJEIX2WdZSsc+s+FqQYivJ9NqYohEJ9zFRQjzaBesjFMZdz2ru037ksF8Q++XLQlOkazHTk5Pwmnu7DSveKPraJDyH7edJ+muWjb8/QCzuhUsWVOzo66u3pELcpuKSl0VC0RBIuG9NfiPKKs6JLW/saPIy934o0GMGGqXUEH0EdmpFyCtC6gxeDtRL8d8tngAOdiF2eni33J42wCJ+ZjwX7C8z8B1Zm18h 7oCbjT54 L6dii3q0fpuMwR7pY4YKYBQzI9Fcl6fFo4jrA5rsBP/H8c3OjfRKw7ZhLmMELD0+DgUm8uP3eu+DD2dS2Gdfa+4dRLdTRLTyHLXKcaityMtAnI6FSIQorDXr+W5aNyd+OsFdVUgjeUUFC/hhC35X0P7BN4wzPf+b29YQdZOPyUxAZ0GWARZl/ka5iKWIFJmmWWQnkGaNOF4V/RbmIBF3Hsh8v4c8dL5WtdUCWnFjjAgZnYo3ORhlfGkAzV0jabwcMRxb6nt75AQK5+AdPcfDsTYpB+Q5K/UP6/U6DufdAVSMt4o7Pf0ZCgd2n497MqYbZMhiwyHjW16VQ6BXDuDJH9FbWHpHJIvGLu+7zi9D3VDO5a/ShH8LzOh/nBCcVSPFNsRMNSjSEjQN+P07xVxv3fBzFnaW6lRKGyM8ySKVXpvZ8IGoNAGhbcQT7PRbDBMMgeZ3LbfulnImERnsEJ3v2ZQEn82z9hMet5yjw 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 33aafd23823b..200319bf3292 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; @@ -2498,6 +2498,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;