From patchwork Thu Jan 25 03:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 191830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1405141dyi; Wed, 24 Jan 2024 19:54:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGN90onmpJfuf+nGJvWgvMlpzY3dajsYrotlKVC/Ap9btOqU8Y+nocAEiah3djH5RqNRQ7n X-Received: by 2002:a92:cad1:0:b0:362:907a:1f6f with SMTP id m17-20020a92cad1000000b00362907a1f6fmr489498ilq.37.1706154888127; Wed, 24 Jan 2024 19:54:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706154888; cv=pass; d=google.com; s=arc-20160816; b=B8N1SFJSkEs82GtPJy09FYDcEZQSfc0E2LA1yln2gyRiGT/DV+uJvLTTh0X7ZG3W9r QN6yObvZ1+m8r0M8uXQAsi9VRjxZIXUf7dEDFieCHvdRHbspK5Zhj/lXqXYJUX94q+YB z5NcFYS1k4aZREeXYE1Xw8SE0W5qTLPHl2Ky0sTHnRRduL1TR+VmUJ7Kt1tQPRR/2DuZ hudwmC2i5rNGeXpxEE0kO+JJ/eZabaIsYcGHJCFw4KsIZ/5YpInoRDSNeyXApog/bwrz FKqbbHfsiInq5m8HdHGdSQGWl2uvx9BMPBzdAVboVB8nfR00Mg1O3D0fhZYb/jmz3lFM sxzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ts12caryezrugH79moklhax9deIOA6cUraDxKWjHyX4=; fh=DK6aj2bwtzLHLwtNGHpxLhefcc6QrCP7kxmDTjdZAkE=; b=xmZJEasrPJrhGc0rFSAzFpBfqscl1kkkXw0AElIyX5s6hrzW0B+f72fPhReoEd8jPS 9sOLQXZSjYnXeGbqSAcQF/xyNTEgehxG3RKtfIk9ZlSr0SUm8Ykv3NTLYQiObPRYAxqN M+8+dNNqHz9ChX5JUDQZycYIFFZXKju6fNtUfwwbPFBjjLJmZm5d0I37NGgT4YXN7Jgo ICQYIWiyYuEnWwu8FuDxicfcPJnoyATDKZ0RlAJwR0bMSZM+1m//Qk1JtjjpJ17azgQU +DU2/T/VKtL7aPZd9K6c6yP9lPzPWBoZy1vwZdqKhORAJh/PagccbsfRIettg0i94nEY WRWQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="p8fd/qFX"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-37935-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37935-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x27-20020a634a1b000000b005b95ee3edc6si12817510pga.628.2024.01.24.19.54.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 19:54:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37935-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="p8fd/qFX"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-37935-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37935-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3D2D2B25EA8 for ; Thu, 25 Jan 2024 03:50:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D62510971; Thu, 25 Jan 2024 03:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="p8fd/qFX" Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB0F8882E for ; Thu, 25 Jan 2024 03:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706154590; cv=none; b=NWQBi7AyG4li9yqND1q9KFTryclZYpDxswMKbz6gk/LbPr/Wg3HlKxQTlWmqj0BJMB+cORnwf6ODBKT6TtNLeYOJfz7LDiwGud+U5tfjJeIty58mN/znArd5i1kwlyEATNrxWhvVamli71CVjOsqA2CCfMlwL4WHtscL8KhjLF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706154590; c=relaxed/simple; bh=jqlAvAkCgpat+VhHEUnKov5cONdf0wTY+vdjPpgtDi0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q+LeLxb0csl3wDvUZwvtMnDTIpGcpxhZHnsMc9NXMzEah2AgaeA9SMB4B1Rhwye0W+iHOpSMiaHxSiztl9AjuECp9hClbG5qEy5lRUxQJQgjYAbSFNckymOOusMEsd4dXzb3Ec0obAGEUmeDajwtsHzFfmS9iHylMrCsw+Z8Tt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=p8fd/qFX; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706154586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ts12caryezrugH79moklhax9deIOA6cUraDxKWjHyX4=; b=p8fd/qFXbNb5rBgoPLFoGR6NCbbshJlD0+cYlLoGs8vIHLRmyWEM85qkUf/nFenBz431YK UKhMzanl0wWopcVuoGaImlIUche5F8QlbRuSDEYvXQbSXp2FohGUwTlbgDXqyYHP61M8Sg S72oK8dNwlb+edx/SDwQbO5p9YNepik= From: Yajun Deng To: akpm@linux-foundation.org Cc: Liam.Howlett@Oracle.com, lstoakes@gmail.com, viro@zeniv.linux.org.uk, brauner@kernel.org, vbabka@suse.cz, willy@infradead.org, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH v2 1/2] mm/mmap: pass vma to vma_merge() Date: Thu, 25 Jan 2024 11:49:21 +0800 Message-Id: <20240125034922.1004671-2-yajun.deng@linux.dev> In-Reply-To: <20240125034922.1004671-1-yajun.deng@linux.dev> References: <20240125034922.1004671-1-yajun.deng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789033067541498991 X-GMAIL-MSGID: 1789033067541498991 These vma_merge() callers will pass mm, anon_vma and file, they all from the same vma. There is no need to pass three parameters at the same time. Pass vma instead of mm, anon_vma and file to vma_merge(), so that it can save two parameters. Signed-off-by: Yajun Deng Reviewed-by: Liam R. Howlett --- mm/mmap.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 49d25172eac8..f19bc53bc08e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -860,13 +860,15 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, * area is returned, or the function will return NULL */ 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, +*vma_merge(struct vma_iterator *vmi, struct vm_area_struct *prev, + struct vm_area_struct *src, unsigned long addr, unsigned long end, + unsigned long vm_flags, pgoff_t pgoff, struct mempolicy *policy, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, struct anon_vma_name *anon_name) { + struct mm_struct *mm = src->vm_mm; + struct anon_vma *anon_vma = src->anon_vma; + struct file *file = src->vm_file; struct vm_area_struct *curr, *next, *res; struct vm_area_struct *vma, *adjust, *remove, *remove2; struct vm_area_struct *anon_dup = NULL; @@ -2424,9 +2426,8 @@ struct vm_area_struct *vma_modify(struct vma_iterator *vmi, 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); + merged = vma_merge(vmi, prev, vma, start, end, vm_flags, + pgoff, policy, uffd_ctx, anon_name); if (merged) return merged; @@ -2456,9 +2457,8 @@ static struct vm_area_struct 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)); + return vma_merge(vmi, prev, vma, start, end, vma->vm_flags, pgoff, + vma_policy(vma), vma->vm_userfaultfd_ctx, anon_vma_name(vma)); } /* @@ -2472,10 +2472,9 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, 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)); + return vma_merge(vmi, vma, vma, vma->vm_end, vma->vm_end + delta, + vma->vm_flags, pgoff, vma_policy(vma), + vma->vm_userfaultfd_ctx, anon_vma_name(vma)); } /* From patchwork Thu Jan 25 03:49:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 191829 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1403935dyi; Wed, 24 Jan 2024 19:50:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBCEWh6nhQzVmLhngt14tBM/G/8pC8UtT7oAgBeg1emdl7dQKp2mPS+BkW1SZxjKFfKGvH X-Received: by 2002:a05:6402:3097:b0:55c:cc55:5199 with SMTP id de23-20020a056402309700b0055ccc555199mr191134edb.7.1706154629648; Wed, 24 Jan 2024 19:50:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706154629; cv=pass; d=google.com; s=arc-20160816; b=UmJibgiEHkEjZsdxwNr6JJmr4M0JWKF4ed/Utc/GbvuWyLuMihCvQp86M+S6VhlCzn 1bQ1/pkmqD2h2jNO4HVBmLuxNHriB1sUaHhlsZaWw/ihZYgmNXJT3NtxlI6WPULSKzzU wwlzAdTqMHBW2jmXV/xTiqfMVkmvLQvBOQyoAMqfcEvU85r63YeohLrNZ69Fn7kM3N9C OyGpBmA2yOgc9wlhdm5o75xgRrgKyuWtlIQAFRKYR0YF2uB2EIsQzHbdMFhOUk5OJiia d2GG9g95WPQohgssulinYwnAhAEkf+Su52xpKN5o0noubK3a+GStLOrI1jgL4In21/KG MeaA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=i6+UflKme2rdjDNdZ2iFhopxIKTWi9f4kjyYutjoOt0=; fh=DK6aj2bwtzLHLwtNGHpxLhefcc6QrCP7kxmDTjdZAkE=; b=lm4m2hOgjttqzsv2ykmNnoxeufAMR8Ge5+rtDlh3EoSeTn+ZZtIK9AC3RlGgPe0F3H WJqxNiWhT5DqIk91yhatT0bPPN4fh3ndbZnsAXs1GlFrePYMVJQflSkZeYap8JqgKngZ XHYHG1gRscwxgPobMHkGSaCFhxTnJMqImPPeuc0MiGBxipsJKKrSwD5L9qBQ7NY1SRoL tdMAphJcVnEjqIumYBfWv3iBb0kcwVhuRpZXZQbCK0Atf0GPxkVz20rjJf1SpSUpYe/G VpaRMxDOhQxkss9SKuYk2+q8gG72pfk4pA8gdd5ax9OSKGtedGyJDeTVEFZxk+WGjXAT 1mww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TP9P8j4w; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-37936-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37936-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i5-20020a0564020f0500b0055c054d3afesi5201888eda.639.2024.01.24.19.50.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 19:50:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37936-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TP9P8j4w; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-37936-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37936-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 46F391F218FC for ; Thu, 25 Jan 2024 03:50:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80BA710A31; Thu, 25 Jan 2024 03:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="TP9P8j4w" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54A7610A01 for ; Thu, 25 Jan 2024 03:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706154596; cv=none; b=Xj3WV4TvD+aHxHTeNt/uNVPOHJqA2inZf3tE83o8Roa453J3wg9mvPZolMOUqAu726hxWnqAt8o/UYKx8jNObvhCEMP1Nn7HkmnlIAdqBql67kvdmHxuInO+GnxLhQ93HHytPBJDszBfJlngwEj8ccEDIyk1zRHKgFvcAVKrGak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706154596; c=relaxed/simple; bh=73ZPNorBDGeZQoqSY1zb/FAA9ykzNR/xXGUzku/jFWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WVsXgrETX8NE/qyOEkaZT5V9BMJ3Gxr1/+mGzrvEjrlJW51hx/mmkYr6YMt6yBNWE2hY1hixqJ41malozHzkZQHyYYwD7RuchFvgO403WnTAUpMhiANHGRMkSzE7G/+ppBfLoL1It9mW/2Vafj9yEzYFgBUHrQUV1A91Bak43X4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=TP9P8j4w; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706154593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i6+UflKme2rdjDNdZ2iFhopxIKTWi9f4kjyYutjoOt0=; b=TP9P8j4wYgzgj1xUO6g20xYqDXcVPDuvlJavt38IgPULE49lOg/3PDgmY31WgxvkrWC0OB zPmTNvyIyMZ2SPNVR06ETZJgsvj+dyVvmkfsvGAoKXc+s3tSZ4zq7dnfUVn4gLjT1aG2nI 2vTQC2TNOTx5zN5/dz4JuMv46KNioxI= From: Yajun Deng To: akpm@linux-foundation.org Cc: Liam.Howlett@Oracle.com, lstoakes@gmail.com, viro@zeniv.linux.org.uk, brauner@kernel.org, vbabka@suse.cz, willy@infradead.org, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH v2 2/2] mm/mmap: remove find_vma_intersection() in vma_merge() Date: Thu, 25 Jan 2024 11:49:22 +0800 Message-Id: <20240125034922.1004671-3-yajun.deng@linux.dev> In-Reply-To: <20240125034922.1004671-1-yajun.deng@linux.dev> References: <20240125034922.1004671-1-yajun.deng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789032797351475339 X-GMAIL-MSGID: 1789032797351475339 We need to find the current vma by find_vma_intersection() in vma_merge(). Since the src vma was passed, we can add a check to figure out if the current vma is NULL or the src vma directly. Remove find_vma_intersection() in vma_merge(). And initialize the next to NULL when defining it. Signed-off-by: Yajun Deng Reviewed-by: Liam R. Howlett --- mm/mmap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index f19bc53bc08e..ea02fdc91aa2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -869,7 +869,7 @@ static struct vm_area_struct struct mm_struct *mm = src->vm_mm; struct anon_vma *anon_vma = src->anon_vma; struct file *file = src->vm_file; - struct vm_area_struct *curr, *next, *res; + struct vm_area_struct *curr = src, *next = NULL, *res; struct vm_area_struct *vma, *adjust, *remove, *remove2; struct vm_area_struct *anon_dup = NULL; struct vma_prepare vp; @@ -890,14 +890,18 @@ static struct vm_area_struct if (vm_flags & VM_SPECIAL) return NULL; - /* Does the input range span an existing VMA? (cases 5 - 8) */ - curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end); + /* + * If the current vma and the prev vma are the same vma, it + * means the current vma is NULL. + * Does the input range span an existing VMA? (cases 5 - 8) + */ + if (prev == curr || addr != curr->vm_start || end > curr->vm_end) + curr = NULL; if (!curr || /* cases 1 - 4 */ end == curr->vm_end) /* cases 6 - 8, adjacent VMA */ next = vma_lookup(mm, end); - else - next = NULL; /* case 5 */ + /* case 5 set to NULL above */ if (prev) { vma_start = prev->vm_start; @@ -921,7 +925,6 @@ static struct vm_area_struct /* Verify some invariant that must be enforced by the caller. */ VM_WARN_ON(prev && addr <= prev->vm_start); - VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end)); VM_WARN_ON(addr >= end); if (!merge_prev && !merge_next)