From patchwork Wed Oct 11 17:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13417644 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 56177CDB46B for ; Wed, 11 Oct 2023 17:04:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A80B8D00CD; Wed, 11 Oct 2023 13:04:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 957C38D0050; Wed, 11 Oct 2023 13:04:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 783288D00CD; Wed, 11 Oct 2023 13:04:40 -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 5497B8D0050 for ; Wed, 11 Oct 2023 13:04:40 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1C04714031F for ; Wed, 11 Oct 2023 17:04:40 +0000 (UTC) X-FDA: 81333804720.07.4CCF63B Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf11.hostedemail.com (Postfix) with ESMTP id 4105740015 for ; Wed, 11 Oct 2023 17:04:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dgLM0lvf; spf=pass (imf11.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.42 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=1697043878; 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=p2uoKaYburNa08ww8sTaHRIXtP2MTKhH/wupSHrxFQ1JNWoLu2eBLDSXBnk/a+O/xwnJ+p h7XqBneIoK1aEpSKWCxGEHA6t/xFf/Q8bcnw0R7OJrNApq69gnx0pnEQg5EgzW8I/cMx1Y NLRIL5Eq4OX3ni4MyjiRIK9oh40sUB0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697043878; a=rsa-sha256; cv=none; b=omqWuTmq/rEEhZDg5BzS+RvkbSvv1Vxt3ca+NPP7c3SUjBp6QQLFANv6LE+B2mbUqpsu9N n9I6wZJ5Uvq3vv5Aa4dGhXoUBSEwCR0gNL8ZzrofAdrFYuEssfn7t0hQTw39KVcBfFPzId T51JQ/5CdpuujVStWcCiXuqgckSS5BY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dgLM0lvf; spf=pass (imf11.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-406609df1a6so1099895e9.3 for ; Wed, 11 Oct 2023 10:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697043876; x=1697648676; 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=dgLM0lvfH4DFGNxvtlvVKuYFs5Lncs7zw0Qt8cDZbp0mjm2r2zrAMBZCHTWm+Eiq+/ PwA4rrrPaq/qewPnmAqj16TRvxkMx9c+j3WmtQXhAskkUw6qvY8NrRtGCtHW2KWxJwKo DzuNXSSWNAM4Emc0ERlb+T3rCyZg160Mwcqzu7kSBManCYEM01QRTQe0h7QcQ4CV4/cR n1+dsG01ruioqLvhtBjansB5mdQxWStWbS+FQdGLi/dK7fTn051NtRNZXWMeWRecWy8w qXVk8XV605BjVeJu4YrF1lagbrzs7BBPmw7BW91ruNdBRldd6uGyr7wQG93ZnGrHC3LN 1Uvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697043876; x=1697648676; 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=jvtZEl/woeqJsxFtwquox4qiOYBoVWAUbuAKeu1Wwapyvndx5o794jftZUF7hj85dB rFJyKYRq4+XlToSKEVCzckqHMMJGKUT+5MD7wFqpURrIXGHbNuKunF1VaG2MfhLxkgr6 1PCoG6HYWmOJVc8j26I14XgR+KCEU8veECyqf8QIFktcJSprq4lST/4Y2UCie1t0zlt4 EG8WoWDFoiGBx48soSqijYBdDXxVIW4JPfhxHHHjjAtuOI/moK0u8hsEp0s8rWCqxEpy lV2OfMCLvWVN/28S/lfDsndtSma8FaQ5Tsx6EophizU5BSD1e2ly1YNPoZYUi39Y1+jk uIQw== X-Gm-Message-State: AOJu0Yxhjcue0pU1VK8YK3C7yOok6u/sw9epvLsZW20YIDAnRLtdvR3d F8bt4MV4wXpMLGmw21Zcy5F/zG33RRw= X-Google-Smtp-Source: AGHT+IErZXTtH6zFvN1YNb1XZ/7m0+WPZUjiChhxsbzC3LcbueadZBZSk23ANxe1fU5f210E6eRSvQ== X-Received: by 2002:a5d:4fd2:0:b0:31f:f829:49aa with SMTP id h18-20020a5d4fd2000000b0031ff82949aamr17193935wrw.23.1697043876067; Wed, 11 Oct 2023 10:04:36 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id y19-20020a05600c20d300b004075b3ce03asm3834495wmm.6.2023.10.11.10.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 10:04: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 v4 1/5] mm: move vma_policy() and anon_vma_name() decls to mm_types.h Date: Wed, 11 Oct 2023 18:04:27 +0100 Message-ID: <24bfc6c9e382fffbcb0ea8d424392c27d56cc8ca.1697043508.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 11sab31ycadqxjtioscp9bogmb85dbxc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4105740015 X-Rspam-User: X-HE-Tag: 1697043877-842585 X-HE-Meta: U2FsdGVkX19m/7SoOqGfR+Bk6XRLtGKM+mmLbuSxnN35RPs8+BOZaqfD92Th93LpnXiOjTl58S9Zo6mXXsseMadlkG/3YiTRTay/8dFCAIDs7ijmk+Vn52l/Qe60KIYthc+t7OMjQ2aqTjSnbzT9btJGbBcGGfApyMFs2H3Z7yxpCp4h4neqUIsKc9Q8wE/tC/ET2KqB5F1C8jQ7wJBvX+8dPOYKRpIheClV75zJ/SlNhpvM7nR2tZjBbqbaUyEE1agk5TESkh8XTNBHVJp1JVtd4fWf8fVKUV1SCN86qJHDrY3AHJFL7VeCXGE+FuyfevGkHuEPA5eK5tXLenVEF2mqapYv5aAMAyVWksM5lf2KxeHxUNeFD9hw/eAxLD+cXLKFhQvTpcuAsBS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0zXB0EBsWkNPOED8CQ51DnD73V+PVFnRb5Dwz0TbB0Kup7xj5PECWCqUfqJ6BcfNOgJb+xbSshh47ec2RPEaBxHO4GNWjXvNIurGeRA== 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. 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 Wed Oct 11 17:04:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13417645 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 00D1CCDB46E for ; Wed, 11 Oct 2023 17:04:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAE518D00CE; Wed, 11 Oct 2023 13:04:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E38E18D0050; Wed, 11 Oct 2023 13:04:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF07F8D00CE; Wed, 11 Oct 2023 13:04:41 -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 A111D8D0050 for ; Wed, 11 Oct 2023 13:04:41 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6A20CC0360 for ; Wed, 11 Oct 2023 17:04:41 +0000 (UTC) X-FDA: 81333804762.21.3C88C2E Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf23.hostedemail.com (Postfix) with ESMTP id 5837C140028 for ; Wed, 11 Oct 2023 17:04:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Yt/lfs94"; spf=pass (imf23.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697043879; a=rsa-sha256; cv=none; b=DNb1jcuYqGl2tiWBM/Gfv3NV4MTzkHmw4rzkg95Nr7wIos+JCrBBgvehdKl8IlSSKPtMzh eW+mVaqcaNXRi1QtpKIQNyX02gEVr+tYdRQLE1l0dGl2iojEVFCg9LlIHN0RL3JZHuvvUM X/hrDSMFHITxBnmyfDb6U/TAMJ51jUQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Yt/lfs94"; spf=pass (imf23.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 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=1697043879; 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=JbrHmb7+pjIK0hQxBBJ9IhzQZydFs2ChsPIAgakuSVk=; b=l9sf0UQhjkyq1hW9REYZVGVPsEh7NakdE73WAQcyOIOv7sJQdN46nXaKA8NaGFWHpxELpd HGch4ksXvfQWQ7KMVuKhpDkb52bJ8VkBCYn+4bziWq1n76c3JKJrLHAm7O/PdeCk6WmMMx 6oVIhqWojaKl94P5+94+1gVY3uBkI/0= Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so1027065e9.2 for ; Wed, 11 Oct 2023 10:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697043877; x=1697648677; 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=JbrHmb7+pjIK0hQxBBJ9IhzQZydFs2ChsPIAgakuSVk=; b=Yt/lfs94/3ESlzlatknpjdJezK+AiAZ2lnNiG4LbZRACdp0R+6tpktDZWW0tbe2eAx xCG3RaFEz1xro3hHxVmbUYu8mOzNaM/swqw6m2Lt1n+sjx85cHdVRIwyNXqpLImmLMfJ TZKvDkk1JqFC7AjQZIAAsmUbPWMESdQqg4zopiFzzyabkEZ+z8I7HbTUgT7m7u/IZ0Ap 8FE6wEVPh3tscti2C4aAYsW7/RuHt5it9bFdL4LLWEPpbRjbkENVTPwALcZxgVK8iWqK 7iPNA8iOu2qzuTJfc8JspweHwBnEJG0wUseiT0UE2edBkSA7HYAZITV+SpUq7eo/ksgx ZX1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697043877; x=1697648677; 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=JbrHmb7+pjIK0hQxBBJ9IhzQZydFs2ChsPIAgakuSVk=; b=mnFDzcg+mABteuFeCnov2H/wJawisXWVz7/U/vDxC1Hao7DZsoJOeP8SqPlz9R32BE XQ8ZMyLSTzKo0oG9QAUfWD2S04sueu2Ti4LCEHaOdQDU00c0iwvsnzzCqXLr1fgC4glT 94KtTXTF1HXvxswM6DfoaNAxZ+bfhhUwNdAoijkjpqYv3qr3VBgOMPY0kEYTEEB2FAG7 fu2egRpmb0f5XvqsIyEWid5Pl7nbscOY2ySS33JHuNu5KzNmEhX++YhaX1dXVvZHB2Zt 598HhmjLqu+JMt3zf3FFyuzpqbLwhQeQotD8L2E/WxknRKAcLIJYtrKPP0/eeXOB6MPX 9jGQ== X-Gm-Message-State: AOJu0YxHFFkwzlSZJz/uGFd1XOco0nRQFpV9ip/zYlnNFLVOvUtJhk7/ oUQRRcrnIkRvu5mEKYNohKY0RejLduE= X-Google-Smtp-Source: AGHT+IHW7VlW4caZL7jgUx6V96QPSxLJ6wWlmykp4QL4Dwal5qZUOT9MuJyw92bo0I5OpKpEQwIIuw== X-Received: by 2002:a7b:ce98:0:b0:401:d2cb:e6f2 with SMTP id q24-20020a7bce98000000b00401d2cbe6f2mr18195397wmj.32.1697043877497; Wed, 11 Oct 2023 10:04:37 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id y19-20020a05600c20d300b004075b3ce03asm3834495wmm.6.2023.10.11.10.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 10:04: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 v4 2/5] mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al. Date: Wed, 11 Oct 2023 18:04:28 +0100 Message-ID: <0dfa9368f37199a423674bf0ee312e8ea0619044.1697043508.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5837C140028 X-Stat-Signature: k6orhqio55r616nrtfb9zrxm7t67buco X-Rspam-User: X-HE-Tag: 1697043879-458864 X-HE-Meta: U2FsdGVkX1/F53hCdgAJ7V1yzDa2BOcUSp62wpRcjkN6nSkr5b/bHpFiemBslJ7HJQvUoDsJorF9w8F9MPebwkZ4kCS7cswN+q+nNHW4OiX9gBCooEtNU/8t8HOF+5wBUsJE8v1pwi+LvpiE4FhhIronsANR0ErgMGqhqj3SmF526vBEj3msAecDH6ZndF26fhS4D1LXGjZkbLS6xXUJGFaGZCgwCDQmg/A2QIMbLDvcHlnFZTa2OjUJnq+G7P7Ihr27FsTE4kJNU/E5GWKgLIOjIXp7eRvVkE1NugLORoD7OI3ifn2gU8LxmlPU9gdfBe4bzA2AMXKfORLNajN1Msgzbyx+HIux1rzMLTO0m4OupVPjSrSJZTLgh5kRk/j4ozeWnxP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38jMgUW+EuW2S 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 | 70 ++++++++++++---------------------------------- 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, 141 insertions(+), 143 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index a7c6ef764e63..ac616cfbacf5 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,14 @@ 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 +1548,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 +1650,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(vma); + 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 Wed Oct 11 17:04:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13417646 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 4E4F9CDB46B for ; Wed, 11 Oct 2023 17:04:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAF328D00CF; Wed, 11 Oct 2023 13:04:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5E918D0050; Wed, 11 Oct 2023 13:04:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFED08D00CF; Wed, 11 Oct 2023 13:04:42 -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 BDA628D0050 for ; Wed, 11 Oct 2023 13:04:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 94839160363 for ; Wed, 11 Oct 2023 17:04:42 +0000 (UTC) X-FDA: 81333804804.02.0EFB5C0 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf27.hostedemail.com (Postfix) with ESMTP id 92AE340018 for ; Wed, 11 Oct 2023 17:04:40 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XVgdC9aK; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 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=1697043880; 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=GAU93HqsYIpLiVpwaSK+T31e5O/ZS8cTQUfXlQjVJrl5p7UyLOYsz+Otw3OHGiuRbtegLx EU+erBEzATCscEjsWO5CvrZf+WHjXnWJeJEMr/D+j06UWwGOsMpsTOyHergkjYc9VDTBvA OSo6Zj9n64qeVLpQ3yuoCQtRa+MJs4E= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XVgdC9aK; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697043880; a=rsa-sha256; cv=none; b=xJw/rf7DMTGmuaO5+afNtK0K4y/m8yY7splaATVTJ2HTMVezZ5wO4ymhW0yTM3HPvm3Zrz /04D/cEGjfKR1yWcAiHv+qBziCcBNOvHTMMVgGtYuMU7+dTMSX3N1BY373UUPdWq45Sysv Rijaox3I2bo/NKDnhL4tsL/N1dZzKlM= Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-405505b07dfso7908215e9.0 for ; Wed, 11 Oct 2023 10:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697043879; x=1697648679; 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=XVgdC9aKEnHVJRi5hM+KV37DwrQDajYrSMtyAacK7Ai0AZ5WIGVXQKjAhej9tPp6To H5yJ/hI7lPHhJrthp7K9c0uYR8d3z0vOVPA/hnDf+1+eHJHk548m1yeVekmu3S9TTchI Uq0q6nOkMkB1TwsmvDb3sfKIO9ov5qqH6gixcIg2gdMehFoCM88aqOAVALXFwfeHnR// +ETS1PVgdP90eJjkR0po+ImrhRWSikbP/j6L1pJbHGSxtJ/L7Z16Yv3J4DWPGkBexM8F LWW648CflF7NRh8+rtnHspEU9tPN+VAWChUjGPSc8Yv9Hulzbj7E0Cb+DS7m32L3XH8M ZerA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697043879; x=1697648679; 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=MY3tZrgnHgnr6eRxFTFubp5FZIJhMxaNkJWIEOM6M37B2AHTSXSIxCTea/LLuCE7EY 8Urke+aejaDYQBxJFUDvXzMoPGJIIhbSSWYY+Wgf87xA2Wt9tRh6Pn4BKHDkRwmIBBOk x8d4diekOtKtAjdreObhiwIndT3kUnCyf8uBvXIuQuOc8F74QIsxUKyvNQcbOqMtXsaT 0ss6fc6QP/VQboSKTPYM4OSwwrez1Ms95nEnNVVq2bqXgktOYXIsLbzWQal/GMfUbKcD SIZjth1h2rzykF4rhSSFdoJhIlBsgu+TXis8YFus9jvZyCbEaFUhgwKISrDekkVPEUuI TtZA== X-Gm-Message-State: AOJu0Yx1wmqfYYgUddqL/Hlpevw7fYZKek8xaOSano2Hw1sKp4x1edxv FPtHKyxKJh9D5T2XVxOYHAyOg82VdRM= X-Google-Smtp-Source: AGHT+IEaxDcfzdWylWTP/iaHYGj0U8wM+RJx9S2LL73muVEhfzeVRfiR500cRLgmK2tkV/LbvoV7OQ== X-Received: by 2002:a05:600c:205a:b0:405:784a:d53e with SMTP id p26-20020a05600c205a00b00405784ad53emr14090015wmg.20.1697043878737; Wed, 11 Oct 2023 10:04:38 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id y19-20020a05600c20d300b004075b3ce03asm3834495wmm.6.2023.10.11.10.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 10:04: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 v4 3/5] mm: make vma_merge() and split_vma() internal Date: Wed, 11 Oct 2023 18:04:29 +0100 Message-ID: <405f2be10e20c4e9fbcc9fe6b2dfea105f6642e0.1697043508.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: 92AE340018 X-Stat-Signature: a9ccx6xr9p916abcte6xms5qqjzq4y7z X-Rspam-User: X-HE-Tag: 1697043880-698466 X-HE-Meta: U2FsdGVkX19/xzTCC6iXWm05yZhYhTwlZb/lIIHx0XMwZONqNyn/ivoJdunuzUwheyQsR1S95epdVsrUAYEG52qadpbX5hEkUF2ldv0BlrlfptIzspAMbWl9/2ARE8wnKiHBhEAgdiauugin94gyL6E61Jl86UtBPaXbtBKrTayfLT+V0syS8hE+078bBT/0vDjGk1gpZrA3/MAVXFO4Tcq8NPZet5cMFZePF9ythK3MxraCOSLbrfQLY17K10eMSX3oTfuS2rnROrcnH9OTnP9TgLXP5S8E+UPCn5jDkJefFHN83gQaudRNlRk+7KO6h5iVMMu/iU0u35+nR7Pfv8kZPh6NiX8AuRsllT7bS8cYufo4rhZrUsmZ7dNahkryJkanbDNFOxrOmLTZ0Rq76zLbGufKanNZFKYBPF5aZbP9haUjqA0OZXnmGSxiVSqNSGf8JrhIZo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puSK3Qj2GMUJXM9pGC8GOC+XGHVZ/BCTNI+mhPcUJzb4VhjOgZRZsMi8u/Q+tqc065SB86/YY7/Y+tsqJJ 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 Wed Oct 11 17:04:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13417647 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 C8554CDB467 for ; Wed, 11 Oct 2023 17:04:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69A0B8D0111; Wed, 11 Oct 2023 13:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64C268D0050; Wed, 11 Oct 2023 13:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2A78D0111; Wed, 11 Oct 2023 13:04:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 37F548D0050 for ; Wed, 11 Oct 2023 13:04:44 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DBA9F140148 for ; Wed, 11 Oct 2023 17:04:43 +0000 (UTC) X-FDA: 81333804846.03.2E6A92C Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf20.hostedemail.com (Postfix) with ESMTP id E8C9B1C0017 for ; Wed, 11 Oct 2023 17:04:41 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="m0AeNt/H"; spf=pass (imf20.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697043882; a=rsa-sha256; cv=none; b=s5SNA5ccGKWitNkArPM6hKPEwphr5bV/gUrpXFbM9qzyA0PXE6CwF77bIsmBde5ix41R+d Iwj/IuadKdWeb9o8g+I3yUH3rcIqdZsVKjpQLWWs091eImevvg+VbHiGSJy6uawLK0h3vA FqrGV07Ok6NMw0ncJazLFmVfMmY6840= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="m0AeNt/H"; spf=pass (imf20.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.45 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=1697043882; 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=BbhnCY2fikQ1AinIqQxLBb8QCAx728H2FEqV7zZ9MYo=; b=ctsIvukNUVYLjYgsl49NpLNEX0bFgN7Ovj72FHGM0cnxHVAwxXaSJA/glkdc7P9hRLfmq6 YTLju1HnyKmq/EElKKhe3YWl0DNL0AmeN0yH13A8EIY6qpabPLnP8Erh6X41jB+VYQp42X iptLHWSBIFT0GcNe406buXpBJnGfkKc= Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3226cc3e324so20732f8f.3 for ; Wed, 11 Oct 2023 10:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697043880; x=1697648680; 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=BbhnCY2fikQ1AinIqQxLBb8QCAx728H2FEqV7zZ9MYo=; b=m0AeNt/Hv0NziLo9vaXeXZUQW575rJoPEKmTU3lipO7nOgvqXv+m1gO7OKJmpmKNth oKvQQU/TprFV+4UHA8DcrIX+tjWuGJOugeA+LFhaGd/N/ixVN38NiQpmmQ8re4YlWIEX Ztar7rUPJJ2R/x7xESKntPO+4kPb/8OBGwGWfan4duxYT/zDps0U/Vr0xZ7pwoG7Tfpc 6mHWnqXkBZZAz/KCiJaXChv8QwHuhop0DQL5QQ/JJFoyDVY0Ba2G6+LA2Fg0CCIadqoh Iu5ZQSE/ZNQeeiScguSgdboNIfA5Dq6cHH2bDuxB+NeBY58EikDxDpr2NqNUcN5yH94j r/HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697043880; x=1697648680; 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=BbhnCY2fikQ1AinIqQxLBb8QCAx728H2FEqV7zZ9MYo=; b=pnfWGgIUYquJkS0BJGwymGmdR7LOvoCIhbGmHb5oCMezRROx+GrLyq6+jcfTkhCCbb a1SswHxakagiuziqirV7x0wv1xgoqjyktDNPwLSSsI96qUqTYPfl5xCP7JzVnHjrUlXr rrDHSA5Ra+ysv/fKJO3uMWIcSFzMn+UL93Jv4dTWRHcJDKOFKHOk41V7ViquJZNdQbDY mXm6EroYBiwz6dsznu0t09WAkKDN+HNiwiDi6ne3HkKwGJ7RGcCemDhrR7fH3QqvIFHM GFdbEtuRYkuZEcVE64N0pPOs+AchalEMAq33BQ4kGOVu4Zbfa5W34DHIEUUGnLrkRePj aBvQ== X-Gm-Message-State: AOJu0Yxr9BInrQEpY6VLERduwrgUe8OYw320VeIgDhydDsVRDLwzMJ5t hxcYLpezI/t5lFdmhMhSMML5m/dvPls= X-Google-Smtp-Source: AGHT+IEZR2imRCe8uWt+o6P/wYTRJDWFEcZxMj9hpzpBcSeF+EKooItwoY41EIhLesMznrp4x8QUKQ== X-Received: by 2002:a5d:62c6:0:b0:31f:d52a:82b3 with SMTP id o6-20020a5d62c6000000b0031fd52a82b3mr17821191wrv.46.1697043880104; Wed, 11 Oct 2023 10:04:40 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id y19-20020a05600c20d300b004075b3ce03asm3834495wmm.6.2023.10.11.10.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 10:04: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 v4 4/5] mm: abstract merge for new VMAs into vma_merge_new_vma() Date: Wed, 11 Oct 2023 18:04:30 +0100 Message-ID: <3dc71d17e307756a54781d4a4ce7315cf8b18bea.1697043508.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E8C9B1C0017 X-Stat-Signature: tb1knu5mjsxz7niu6pidt1gyspfqoefd X-Rspam-User: X-HE-Tag: 1697043881-738908 X-HE-Meta: U2FsdGVkX19aOUo1t/9s+DeOw9ifbUARyVF7aY0+Be9BmovUFwE4JrrcH2j/xLbFPqCbzt/Li+xv1Oc+1ZZXGGnTb6g5SvuT9IJFfiTx2iMw18ujb2YeX/fxn8AUX/kiumgVS1fR9L3fdDHw4u9tAUJNnb3vuYPJx+ZxBzVMYfsBiUVsGb7a4J4elNI1hgimxhvdUiBehaeu5cwPnYimLmV2JjtMMnBTUXMrJLRJtOEDw93VKECktZZD764Pf4GxveaQaoyViXLK7xdVmJdlhMZpm1+QN8Z7DttwQXuFZEUz1ccBtHucl36xNmyee3ApunP319zJUJLN04LJ29dHYs4GzJUbxCXd+5Kke4Bkrd3LRWrHh27py41Tlo8qxy+bdwYHddW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nmvdIhdhNkucd6wr4bhvqcjiTbKaK 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. The VMA merge call in mmap_region() occurs only for file-backed mappings, where each of the parameters previously specified as NULL are defaulted to NULL in vma_init() (called by vm_area_alloc()). This matches the previous behaviour of specifying NULL for a number of fields, however note that prior to this call we pass the VMA to the file system driver via call_mmap(), which may in theory adjust fields that we pass in to vma_merge_new_vma(). Therefore we actually resolve an oversight here by allowing for the fact that the driver may have done this. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index a516f2412f79..e5e50e547ebf 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2485,6 +2485,20 @@ 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 +2854,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, + vma->vm_pgoff); if (merge) { /* * ->mmap() can change vma->vm_file and fput @@ -3385,9 +3398,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 Wed Oct 11 17:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13417648 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 3F37BCDB46A for ; Wed, 11 Oct 2023 17:04:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DF3E8D0112; Wed, 11 Oct 2023 13:04:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 168C48D0050; Wed, 11 Oct 2023 13:04:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E852A8D0112; Wed, 11 Oct 2023 13:04:45 -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 CCFF18D0050 for ; Wed, 11 Oct 2023 13:04:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 82A9C1A035E for ; Wed, 11 Oct 2023 17:04:45 +0000 (UTC) X-FDA: 81333804930.02.1229685 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf01.hostedemail.com (Postfix) with ESMTP id 7FC4C40028 for ; Wed, 11 Oct 2023 17:04:43 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aPP4pq2R; 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=1697043883; 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=BvzEZsVg5isoEN6IAS+eP4mzWmRlP3jKSau9yDceX7A=; b=QDcz37sKs3F2kP/7VN2kVfTQt+4oyH4E2Rae7pEbb8kHIvLJLHBx8kW6oBUQwid9VRdoEc QlUX128H7ry/O9bMSK6XcGKlVwKeM/IXd4HlZU2g3nZH8A2zNtvrPQ67kIkRXf97QQaN+E D6wxXgRAHklLyW//oskcKogfX0L/tMc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aPP4pq2R; 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=1697043883; a=rsa-sha256; cv=none; b=6PRIaz9DIIDMFQZ5oO33jNHuD7PzZFgM3Sk7ASLKhp7rZUJX5AofbDwiLWZDONHl1aK8WN dPcoKC6kdeEAIC2Vs6Xd42FVlWazQIs+wlcaU75ZdxHvNYUiFqhPeSuLhvlGZupVsj6eqe OtkP0mB7nbfRV1r48GdVVAXZs8t4TYw= Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-40566f8a093so955495e9.3 for ; Wed, 11 Oct 2023 10:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697043881; x=1697648681; 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=BvzEZsVg5isoEN6IAS+eP4mzWmRlP3jKSau9yDceX7A=; b=aPP4pq2RfcRoS8ZxhB9HkN4qbJ3J7GkvXsddnGdnGGj5famDXPmw3jha3wDLOs6UF/ iGVIYho6jEN6GNILp2yHfq0tSN7qIeQAumaayFrCcyTxSr4ieRWGmtSSQ4C+jM7+/k+i W/l/C5koFQ1z1UAn0SUQmaO87xDfsMZwxRyYYiVoCNA2XCz6gt+qA6+v2NbU27E+sws9 1x5EGLTBK+8zmnOi/xtvYfN3KdG2ooLL8iyW9H/7P4bCJSj+kRa/hHCred4+82oJGp9W Izs9J/y2H4XWDBcMZy+h1HbtSI+7H2GrZxJZFylqnGdhQOtmQ3JqE6XGitTHgCqRU2by x/Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697043881; x=1697648681; 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=BvzEZsVg5isoEN6IAS+eP4mzWmRlP3jKSau9yDceX7A=; b=MwcO557DZXQ2gVZIBCXPYcHCSInRgnYzw3htzUcxn9dhy27nm3NeVOPp1z8Q1WL7ko yEidnvx9eDKlwgWNjLQzh7WPg9C9aWwWSmCjgQADoXg/0k9ucR1SwRYw0eeGw5N5MyLf MfK+CZjS9nBzN7mNPnpB5QE4xrmBwP/9VynpzAtPXGfwjmb5/Bu/5kovONTL1D2paxVu v/B7i5pBKjg1lYbyTyt7k4MZxoxRn2z9s93nvQd7OjEx8Em7LIgtjaIaby+5/urSbwRu 9DldeD9GtDa6ZNs4KP+YY0eFklj+qSxp8uLF/PZM/9Zi2H0Y5FM4dfe/V62R99Mjx8pS jf7g== X-Gm-Message-State: AOJu0YxRLVIft8aVZYo2zdhLN51KXkTva9mX+3I7JLwBXAQ7DJQsdKDn +9FtV1XI7Sfx3P7ZbVjBOL7OtJDCJqw= X-Google-Smtp-Source: AGHT+IGrlRJzT4WiuJiYQVl4Nooi7hmIa8OfY69qFoOPIJKNCAos7O7P28vtT2EcH8CnCemJHwPBzQ== X-Received: by 2002:a7b:c394:0:b0:403:31a:77b9 with SMTP id s20-20020a7bc394000000b00403031a77b9mr19163325wmj.37.1697043881511; Wed, 11 Oct 2023 10:04:41 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id y19-20020a05600c20d300b004075b3ce03asm3834495wmm.6.2023.10.11.10.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 10:04:40 -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 v4 5/5] mm: abstract VMA merge and extend into vma_merge_extend() helper Date: Wed, 11 Oct 2023 18:04:31 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 7FC4C40028 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: e8c4bz86qd9mwt5gansu88aksmi6oxek X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o7DOMW0BUvGWordcROXpFxvum3mGT/pWcrjV2bD2yJTL7Y/hubnpLCZ63GnnvYjdjriwe7RinNDZYNyxjaYTgVvmVxNLsk1k2s/H7QsK3DXtHTWd6oiaE+ah2xj0I62q3k7BfU6NrtSHhw9r+yR3aiIfceagQtLoXt4QVerPpfBkC+NhheqlIgAwdCMD5sGxhDJ3EIoB2LB61LMKGVJB1+BcmedJu0iakFRwN2mKPott5170NpzL2IgwC9q3oIRxXGRyEN/Tgg9OcdBRymwfeNkHyU0Sg+azhBFigd55jVNfh6r9ADqrYvWgrNjAS1ZmUrDSfHwn+kd+WgRfFRF0WuPB8jyVzmMMeCPVNqXaiflaRDUMuKHo4wxVDmg+YUfdWfwVieuoIaAn2J5TK9NjQhFoo8xpADjPZuBMThN1e2sK21Wr7lK3YWkwghPSQsisEFQg0le0d2YJ2U+KY9kJgYEJESbtDZ5Jn2CSdSrVNZKcrDakiIgs= 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 e5e50e547ebf..3ea52451623b 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; @@ -2499,6 +2499,23 @@ static struct vm_area_struct 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;