Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp329494rdg; Tue, 10 Oct 2023 11:24:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyAnHGaQPsugYES3w2VUim/dfxi0YoGQAWP46jcHP92ohB/Qta29ICzD3o0NPgLr6W8/Lw X-Received: by 2002:a05:6808:24c:b0:3ae:4d0:7f06 with SMTP id m12-20020a056808024c00b003ae04d07f06mr19681345oie.16.1696962260112; Tue, 10 Oct 2023 11:24:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696962260; cv=none; d=google.com; s=arc-20160816; b=rAEh3ulunUcfC345I2r2l/TWPLM8mEp9LoGAl6wvkdoe+q58o2ab2ZoDQZFFMAQWOy Wo3Tb09cZMkcNHtvbtt23bGfwu5LsPgWDGgc6cawuAbeoePo1Q8TttBOS1P5MbEXjbgW lp7zpLnC6GklxMuseXOSqaiRpMx9jRkN425C2wGj+hNtUPzeGMjiA1um3eerZTKLinid 4AVpc+F83W7emj5t5lzueDiT8yi3FKKObIvsgyjgPuo/DneOWSDYcbnACe+bp4scFAHn +Ghn88dK2hgZU+KumvtwL2ylinroMzWiG6NgTndaqILuoZP6g3ExFU1R+3p9HZPS4G3K Vhqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vy50Imp7hsFcD9fQ9yun20NmSXPiCxJvkitJven0GZ0=; fh=t0e8hB1yztay3y0yczBzLM0YwGerH6s+dnvwo2ZuqJs=; b=I68ZM6Q14XMLNLtrUFvpBWory/huCCIGubIxJ6oaPafkdmIGS14CtIevlskGfWKF95 8uRsfHHVRHP+hAJOyP6ouma1XeVG10rJxB9nOKyJ3h1emi2kcIHZdDn7HMkcyzrC2Rjg vhohfXxQN9y0kOOrYjxpAdxkuXoqrPxPC4EdBvHtD84ygu6XvZc4I9JvXmWWglzDTpRw IWg85DluFyluiLgDsrWghFgKzoN7HBhrkzRcWrS2aTw19JKO9zLArYvsZD6uioEZBdoN 3wB14OGEDQGZJ3q1o4Pr4sXqdJyk2rr0uqPbsVyUFAflBtFCzPY0cU/2ZC4RoKeXAyAg O4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N7BDA+6L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 189-20020a6301c6000000b00573f8a5337esi12570824pgb.461.2023.10.10.11.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:24:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N7BDA+6L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 33D7D802C6B3; Tue, 10 Oct 2023 11:24:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343615AbjJJSYL (ORCPT + 99 others); Tue, 10 Oct 2023 14:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234252AbjJJSXe (ORCPT ); Tue, 10 Oct 2023 14:23:34 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A366ED3; Tue, 10 Oct 2023 11:23:26 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40666aa674fso56556985e9.0; Tue, 10 Oct 2023 11:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696962205; x=1697567005; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vy50Imp7hsFcD9fQ9yun20NmSXPiCxJvkitJven0GZ0=; b=N7BDA+6Li75fATy2x1o65jGpuOrb7lkdTK+F7gqjzZamZHmeA1/dJsFUaBTORtlF1p xSrGGWv9AQfvLbzgK92e+cL1Xu0DDcR1wK5+ZsS+Re/w2akiV0YF312CjhJkvMHNh6f7 L4psrlLf2eRerhGj7K8DXM6tQfatwe4NkZeIGpVam83zCnh8iQhQglNsKGHsWUwJ3AjG Tb/uZP3W75cuZfYXoXr/wiq9dDU6kNNwXWgk7Rqb6ysKkugZ3btyBkvrLtno7dL5g2Sd 6OvGPVGJDMKsw1FxWVE45H7JDDNZYdu5/J1VaXBFxYS+QVwWdT/FCmA5F0crrK/Iu69z rzYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696962205; x=1697567005; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vy50Imp7hsFcD9fQ9yun20NmSXPiCxJvkitJven0GZ0=; b=Uq6V6Cajz8i2tKJILlH3Tco2Z9syTKkHfuOnrbFqARUSkQYR5KvIm8m6j+tH6Jm/mo Pz15ofoMR2rcevDC0I9AYeCuPY/91NV5JlP/b/sAsVlI2T4cnmGhZD2jIz/pxhK2VflV 8mos1mkn5z+LEXjSvajiRJqqfqh0gGDfkyeeMEzhduhWrY6ckrH6tSP+7LJJporZispa sd5UxzlDrkgJWqIN8i9Lw2jSLfSiNealP2NXqAaJVjfEslNy9fcn1AICE6gRSSff8NVf uzFprY1s3M4PgD2An34XI7Zxk0BlgqnkQheIDlgkkz+lhqW2aLtXgioTVo5wllnKlli1 UpPg== X-Gm-Message-State: AOJu0YwPYENGMOFsb179UpW3z5FcblpSZdo7ESqqOEIo28xgp19GV3hr 5zckEN9nysCl2KnnXYPEbk0= X-Received: by 2002:a05:600c:ad0:b0:406:7029:7cc3 with SMTP id c16-20020a05600c0ad000b0040670297cc3mr15993235wmr.28.1696962204923; Tue, 10 Oct 2023 11:23:24 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id j16-20020a5d6190000000b003217cbab88bsm13225312wru.16.2023.10.10.11.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 11:23:22 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Alexander Viro , Christian Brauner Cc: "=Liam R . Howlett" , Vlastimil Babka , linux-fsdevel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v3 4/5] mm: abstract merge for new VMAs into vma_merge_new_vma() Date: Tue, 10 Oct 2023 19:23:07 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 10 Oct 2023 11:24:19 -0700 (PDT) Only in mmap_region() and copy_vma() do we attempt to merge VMAs which occupy entirely new regions of virtual memory. We can abstract this logic and make the intent of this invocations of it completely explicit, rather than invoking vma_merge() with an inscrutable wall of parameters. This also paves the way for a simplification of the core vma_merge() implementation, as we seek to make it entirely an implementation detail. Note that on mmap_region(), VMA fields are initialised to zero, so we can simply reference these rather than explicitly specifying NULL. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index a516f2412f79..db3842601a88 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2485,6 +2485,22 @@ struct vm_area_struct *vma_modify(struct vma_iterator *vmi, return vma; } +/* + * Attempt to merge a newly mapped VMA with those adjacent to it. The caller + * must ensure that [start, end) does not overlap any existing VMA. + */ +static struct vm_area_struct *vma_merge_new_vma(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, + unsigned long end, + pgoff_t pgoff) +{ + return vma_merge(vmi, vma->vm_mm, prev, start, end, vma->vm_flags, + vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), + vma->vm_userfaultfd_ctx, anon_vma_name(vma)); +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator @@ -2840,10 +2856,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && prev)) { - merge = vma_merge(&vmi, mm, prev, vma->vm_start, - vma->vm_end, vma->vm_flags, NULL, - vma->vm_file, vma->vm_pgoff, NULL, - NULL_VM_UFFD_CTX, NULL); + merge = vma_merge_new_vma(&vmi, prev, vma, + vma->vm_start, vma->vm_end, + pgoff); if (merge) { /* * ->mmap() can change vma->vm_file and fput @@ -3385,9 +3400,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, if (new_vma && new_vma->vm_start < addr + len) return NULL; /* should never get here */ - new_vma = vma_merge(&vmi, mm, prev, addr, addr + len, vma->vm_flags, - vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); + new_vma = vma_merge_new_vma(&vmi, prev, vma, addr, addr + len, pgoff); if (new_vma) { /* * Source vma may have been merged into new_vma -- 2.42.0