From patchwork Mon Sep 9 12:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2o5pmT?= X-Patchwork-Id: 13796993 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 9D4F4ECE57A for ; Mon, 9 Sep 2024 12:56:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E25136B00BC; Mon, 9 Sep 2024 08:56:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD52D6B00BE; Mon, 9 Sep 2024 08:56:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9CC36B00C0; Mon, 9 Sep 2024 08:56:42 -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 AAA156B00BC for ; Mon, 9 Sep 2024 08:56:42 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5F0B0A821C for ; Mon, 9 Sep 2024 12:56:42 +0000 (UTC) X-FDA: 82545199044.22.EC82FF6 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) by imf11.hostedemail.com (Postfix) with ESMTP id 2849840010 for ; Mon, 9 Sep 2024 12:56:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=nqqDcqUc; spf=pass (imf11.hostedemail.com: domain of ice_yangxiao@163.com designates 117.135.210.2 as permitted sender) smtp.mailfrom=ice_yangxiao@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725886500; 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:references:dkim-signature; bh=WwFKI+bxvE/sH0jt32LyN7fO/Tl860tFmSw7h6gPV2U=; b=4gnUH2LQ90nxOvsTCyIxPQ8CFVRppBxOupyEGuYt53cP4b1ZaXdtsivfouTGgFuTOJGZTg +CbNu+xV65CT3SQEK+K5TzpUsuN5unugX9u+nijAiL7bBT4F4Q9GUqz+mT51YgqhnH7U2Q YHvA/CCiUxMuXkjBbJeVB02atjKKf8Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725886500; a=rsa-sha256; cv=none; b=JLitTqpEJ0EA2SrmYKgJSf6cIMIcQPavzM96WfkBEZW0eF6h6JuXmqMCH83jPHVos/gCTj qmBenEAzuwG2fgXmuSQ0329eYchbawUzezse74I1TmGz28KX6t2fTD5b5qquc0iGfxFand Aa/x4zdotjxHkV0uib3ageQyZDpc5Qc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=nqqDcqUc; spf=pass (imf11.hostedemail.com: domain of ice_yangxiao@163.com designates 117.135.210.2 as permitted sender) smtp.mailfrom=ice_yangxiao@163.com; dmarc=pass (policy=none) header.from=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=WwFKI +bxvE/sH0jt32LyN7fO/Tl860tFmSw7h6gPV2U=; b=nqqDcqUclCM9m94XLC8a6 fBVJ4W6RknZd6ElHvyedVV8+Ns4nOVZbcwMZiQa/rraX4q1VMbnpqXE32JBkgXyV 4vNzYTPI/Zeqos6Xa5B12b2GpePETHvtT3zgSC7DocOjEk9xM0tmOOwO7J4hAqmH i3Vz/KKrZlz5yCbq/KQwTE= Received: from fedora40-vm.. (unknown [160.86.227.247]) by gzga-smtp-mta-g0-0 (Coremail) with SMTP id _____wDnT2B38N5mBtdlGQ--.6710S2; Mon, 09 Sep 2024 20:56:26 +0800 (CST) From: Xiao Yang To: lorenzo.stoakes@oracle.com, akpm@linux-foundation.org, vbabka@suse.cz, Liam.Howlett@oracle.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ltp@lists.linux.it, oliver.sang@intel.com, Xiao Yang Subject: [PATCH v2] mm/vma: Return the exact errno in vms_gather_munmap_vmas() Date: Mon, 9 Sep 2024 21:56:21 +0900 Message-ID: <20240909125621.1994-1-ice_yangxiao@163.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-CM-TRANSID: _____wDnT2B38N5mBtdlGQ--.6710S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFWkXryfJrW8Zw1DJw45GFg_yoW5ZF4xpF 93W3s8WFWxXr4xW3Wagayjvw1Yva4rGa1jyrWUGF1Sv3ZIqwsIqryrJFyFvr9rKrZ7Ar9a qr4UG3WfW3W5taDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pZg46tUUUUU= X-Originating-IP: [160.86.227.247] X-CM-SenderInfo: 5lfhs5xdqj5xldr6il2tof0z/1tbiMx5VXmXAnvb-xQAAsR X-Rspamd-Queue-Id: 2849840010 X-Stat-Signature: fuzccb4h7p139o89ejyu6ttnbdpaw9wh X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725886599-311742 X-HE-Meta: U2FsdGVkX1/QPIo7eEIVkGmrSNu5DFWyWPMVYnkRNYvjlt55PVQ2cCNilsUhNCHlKkEyCb8+x8wHoXQTOr55vwBn8zaf8kv/SQAulcg8d7Q8rr3kjUKeCOCpWgFsDAEsBsHxpk6ZRn0m/fM4PuEfTCBkruXetWBG010VUpNzfgJp0+ZtV5xmG+oRlPGCGpl7x80066f8eP57rlnZmYXx4Fbkevk8ZtW7a1XJ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BBU/TTywLorZ2n5XA2/L2HdaUP+ey9Bue+orV2t1i4qgxLJvfV6jWK0xPldyE6didYgNf6DmiRN7tLUTVQG6vmH4z/6cweKpGV4Vq0zRdWCIAYxoVHdXe4ABclUnTa/8Om9EJO+7jl0O09d7+BEg5vzLGdsw/33ZS4BpPvqyBoOOunYH+Egyp8ZiEuUQa/SzUU4QrLoKSfBuPLio/neMxBbYYD+ZcYAWjBwnikExR6HixbT6E= 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: List-Subscribe: List-Unsubscribe: __split_vma() and mas_store_gfp() returns several types of errno on failure so don't ignore them in vms_gather_munmap_vmas(). For example, __split_vma() returns -EINVAL when an unaligned huge page is unmapped. This issue is reproduced by ltp memfd_create03 test. Don't initialise the error variable and assign it when a failure actually occurs. Fixes: 6898c9039bc8 ("mm/vma: extract the gathering of vmas from do_vmi_align_munmap()") Signed-off-by: Xiao Yang Suggested-by: Lorenzo Stoakes Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202409081536.d283a0fb-oliver.sang@intel.com --- mm/vma.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 8d1686fc8d5a..dc5355d99a18 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1171,13 +1171,13 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, * @vms: The vma munmap struct * @mas_detach: The maple state tracking the detached tree * - * Return: 0 on success, -EPERM on mseal vmas, -ENOMEM otherwise + * Return: 0 on success, error otherwise */ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *next = NULL; - int error = -ENOMEM; + int error; /* * If we need to split any vma, do it now to save pain later. @@ -1191,8 +1191,10 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, * its limit temporarily, to help free resources as expected. */ if (vms->end < vms->vma->vm_end && - vms->vma->vm_mm->map_count >= sysctl_max_map_count) + vms->vma->vm_mm->map_count >= sysctl_max_map_count) { + error = -ENOMEM; goto map_count_exceeded; + } /* Don't bother splitting the VMA if we can't unmap it anyway */ if (!can_modify_vma(vms->vma)) { @@ -1200,7 +1202,8 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, goto start_split_failed; } - if (__split_vma(vms->vmi, vms->vma, vms->start, 1)) + error = __split_vma(vms->vmi, vms->vma, vms->start, 1); + if (error) goto start_split_failed; } vms->prev = vma_prev(vms->vmi); @@ -1220,12 +1223,14 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, } /* Does it split the end? */ if (next->vm_end > vms->end) { - if (__split_vma(vms->vmi, next, vms->end, 0)) + error = __split_vma(vms->vmi, next, vms->end, 0); + if (error) goto end_split_failed; } vma_start_write(next); mas_set(mas_detach, vms->vma_count++); - if (mas_store_gfp(mas_detach, next, GFP_KERNEL)) + error = mas_store_gfp(mas_detach, next, GFP_KERNEL); + if (error) goto munmap_gather_failed; vma_mark_detached(next, true); @@ -1255,8 +1260,8 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, * split, despite we could. This is unlikely enough * failure that it's not worth optimizing it for. */ - if (userfaultfd_unmap_prep(next, vms->start, vms->end, - vms->uf)) + error = userfaultfd_unmap_prep(next, vms->start, vms->end, vms->uf); + if (error) goto userfaultfd_error; } #ifdef CONFIG_DEBUG_VM_MAPLE_TREE