Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1554412rdb; Sun, 8 Oct 2023 13:23:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmxwhFOTHVEvJvBLh7Vgo1aFt0GJFNn155wsh5VJjmpoOGZbffAOPyXuqVdwZdxvY5i1r2 X-Received: by 2002:aca:1719:0:b0:3a8:432a:ea13 with SMTP id j25-20020aca1719000000b003a8432aea13mr14155409oii.46.1696796639291; Sun, 08 Oct 2023 13:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696796639; cv=none; d=google.com; s=arc-20160816; b=z7lGpDkio4BKfDDGCvmyj9GyLHXo7EjvR6HgZrizwufVHYS864zctl5vEuCCK3YX8k qEbY9RfbTLWW7ECWnvhXXZTottlp/HWhE/wnEStreL6OZOYK7+Q7zBxgp5ze7+zFQ0tB L57gJXQlw8grWXQsRzt9TJuKOLILks7j6SerdmRWjEJDseoRbrabggcdi+NdL2GycuDR GGsGhlGK53uzx9NEojFh6K1TNlnLq8JC6Q8i2WTQ4ltakK1w7kY4dNvEZIbjZYKe49+z 9wBQRv9vKq+hfDTd+PBjRZUUDlSI52SS4lVe2OTd6FCc7E6GTfMzUqHYhPdOpCcyM/Wc wO6g== 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=GphpI5imAra4MlTQiZu1du23bwIkT93dz+Vpq/IpRZ4=; fh=t0e8hB1yztay3y0yczBzLM0YwGerH6s+dnvwo2ZuqJs=; b=dfUJCmLNHISwPe1rWQzBhfdjYIBGViWAlVG9Bz5BTNom+P6q45EWLyeZjpSKF1Afig W2KbBJxMHc1yWU2Rr8DZWgDeePpQHROHPvoIVFirq3QolSNOzE5QdAM57o9pcyWXjLeA NlbIZvso9FFi0n3QVaIIIkDPo6aaQDCBhRzBrNOLJG4q9Y/WECu5SK+Ug0AiNCtk1Gh2 cd2XV7UUn7zhtzlMlybN0iIz11vFvkpDnibDHmw/eag0loO2aRaAEyyUhyH6PCCtesH3 zQo8gr8b2JqKdiEqdvOO+TpKczIi18eu/QEDVciNRP2lLUML4XeYeuxWC55l6I+A0Evm nNjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dJeejiTl; 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 b130-20020a633488000000b00584b6af3b9fsi5872608pga.524.2023.10.08.13.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 13:23:59 -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=dJeejiTl; 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 22E8980AEB22; Sun, 8 Oct 2023 13:23:58 -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 S1344669AbjJHUXg (ORCPT + 99 others); Sun, 8 Oct 2023 16:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344591AbjJHUX1 (ORCPT ); Sun, 8 Oct 2023 16:23:27 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 637BCB3; Sun, 8 Oct 2023 13:23:26 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-405417465aaso37143845e9.1; Sun, 08 Oct 2023 13:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696796605; x=1697401405; 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=GphpI5imAra4MlTQiZu1du23bwIkT93dz+Vpq/IpRZ4=; b=dJeejiTlN2rSU8/13wSBo3lCjs5gBiYvdZ2wK7HBOIaVej5ngX8a9iPP9efRePrr3b N3Lps3KuZx2/IZGiFul0a/Vz/6sC53RcmradDR0u65nv0f94EOsQCHAkmpMSfSoQ8hRH Q/w57OmODJXsMognI3u4BgEQY2GjvpIwiJmFFpanbznzM09ANdutv3MkMN+3oJuQAnlY vHz0cwFFpvDGR16Ude7QdCkAMEiEluBCKcrrtvEmkKxSt/aFPEW0Vmdk8hkeLItZU8U0 rThfQjujFlHTvi7jGmDnRIvg++pDo4QQdNzSklM9OhvICiOlxDzXaPJHHcblMT6wNqYT yotw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696796605; x=1697401405; 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=GphpI5imAra4MlTQiZu1du23bwIkT93dz+Vpq/IpRZ4=; b=iLhoc0iiFrPDabilk9OKrXYtN4vNId7AYnpnwy4dA46ULCNrIyifZwX/SmjJZV0p88 mkVVBLnWgbzd0umK5jAzx9QXURk/fS6YAV1O+EYEzdoxEeukGLVQVLLnpbIRGu8D2QV2 Y5pqoo4nuA74XLZPdDa0tadneb4ejmpYk3f8ecGQfhUD9EzggvL1Lye1plaHL05DW88u zQgGI2iMkoEenZZq4OL9t17tnT0KhMoi1co5E1ZJcm7BxC40wNzd4eHNof30/dQItj5e n13xe7HFrpHGz9m+crIonPkzNKlE99lUpPJDGWiO0oQdEdFcHLVxtsSvZOqFVs8eAuPb vcPQ== X-Gm-Message-State: AOJu0Yxa0cz7Zw2MGEdwyvc/DjOo1+9vQeHLnV5TZzNW3QNSI/EZupau K9zVRite35RZLMyTlFh4774= X-Received: by 2002:a05:600c:204f:b0:3fe:3004:1ffd with SMTP id p15-20020a05600c204f00b003fe30041ffdmr12585263wmg.4.1696796604593; Sun, 08 Oct 2023 13:23:24 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id c5-20020a05600c0ac500b0040586360a36sm11474879wmr.17.2023.10.08.13.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 13:23:23 -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 3/4] mm: abstract merge for new VMAs into vma_merge_new_vma() Date: Sun, 8 Oct 2023 21:23:15 +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]); Sun, 08 Oct 2023 13:23:58 -0700 (PDT) Only in mmap_region() and copy_vma() do we add VMAs which occupy entirely new regions of virtual memory. We can share the logic between these invocations and make it absolutely explici to reduce confusion around the rather inscrutible parameters possessed by vma_merge(). This also paves the way for a simplification of the core vma_merge() implementation, as we seek to make the function 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. 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 58d71f84e917..51be864b876b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2530,6 +2530,22 @@ struct vm_area_struct *vma_modify_uffd(struct vma_iterator *vmi, vma_policy(vma), new_ctx, anon_vma_name(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 @@ -2885,10 +2901,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 @@ -3430,9 +3445,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