Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1980777rdb; Tue, 20 Feb 2024 13:02:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtUcAB8ucHAiHBARXU0K66Z2BRlhWtzI/iSjZ+ADvSbLL6Fz5QX1/kFIU3yOW9rBgW67jkqW6t4yb3fS1QSwO201aSE+7PlguEhYEkcQ== X-Google-Smtp-Source: AGHT+IEZFej1fMeJ7rCU4rslTmaGZ/Z5JIXHY2ZSG37SHKS/NNHnhtoZeBt+RVCwzNBY3OMxUYqP X-Received: by 2002:a17:90b:110e:b0:299:522d:9158 with SMTP id gi14-20020a17090b110e00b00299522d9158mr7319699pjb.13.1708462961327; Tue, 20 Feb 2024 13:02:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708462961; cv=pass; d=google.com; s=arc-20160816; b=gyosnEaG4KpvzuBT50hOvjVv2Dmvss38hlH9XWcgIvok6gQD9YAajbVzHt+AMflerC QozQkJ/3s49Mn3cnJ12UND0W5jnJsFLZVlGmsSmNuMs+AK544ox7SZMjbjSNaURIB4lx Avt5jHeVUXPZnK6UlAmgHEnu5WpOEUdd3Flf2jh8a9Ftbw/R4uGsTysxJnzSpNhzBxq9 aNLA+s0JvMGlJmn5rzEdDzP6yGbj4g1YK2PDgUddwCSeXgMxZxYurV0hTPE5qEpQ0u0c vMzjoPg04rK81011Wd1Qa0Ij5IFdMWIRUFOEO4rxg6iY3CDOcmpmYx7n08ltAWRnr54h D5Ww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vHk8B1G9ngPFWZyvzcJjpFnWjSLSm2alsXCknI8ZS8Y=; fh=6t9A00hVAaMT1rhuH+wi4In/7tV6MynJX7FHZONKLCU=; b=xozv9OUr6iVejnO5TJE2nVIXYc4aMdZL2aGJs2g6oyyG3L+Y8VoiWOcl9/iqXGAetf 0L2gzRQZ6KJbYS6beb0/38bRITB82ygJE5hKUC4JKz5mDmiCi6aEe3StbSPkGOfqcmWM NOO2gHlVb0E377pvxl3CQxCaioB0h3S6NHKORAZ7jWwOGtkliv+Y95VPhl4nGVXvOV2X gjJvXI384BSV9uyWAKCxQcY95bubA5xnQzA0ED3gFgqrER4fsnGNhnMltEbPa9qhe7On M/XR1k27bGAbyE0WJw64nnUR0tYgprswDOpVcej1EQho0hhlfC8gnj/fvW4Xwhklennr j04Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CyIB3vGE; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-73708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v6-20020a17090a6b0600b00299491faa0bsi6880794pjj.137.2024.02.20.13.02.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 13:02:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CyIB3vGE; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-73708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 071812835A7 for ; Tue, 20 Feb 2024 21:02:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 887FC151CC9; Tue, 20 Feb 2024 21:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CyIB3vGE" Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3BC114F9C8 for ; Tue, 20 Feb 2024 21:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708462955; cv=none; b=RxeFnfZifPhu8+1+JEYp9wY93XbPuCu4uDn6n6s7x/myHPuFt/MPx7XP5NIGYeQpHnU4ElFhuFmylhU6mVZsRF2wtpbartI4ZTQjQWuTiJEysvHsxAfaqkSBBH8aXyoJ5pOByvxkHFbWbGNGBjo3u7jBgwIHGkA6gbSZMtll5p4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708462955; c=relaxed/simple; bh=o6XPqB/8zxNHpvV0fHVJdWnCnt75Wb6tUvyGsRj0mEk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pPykxc+K+EuCtdP3u0byhsp4K+aJnm8g7HzDWcH+FXpQgLD03L9M5XjdHP93Ru1uzQ+KVZFZvZwYTqnnWlzJvnrjQDfXmFpaB/t5Si+7mriGjaZ45EfALbdMPwDm1tHE6VbkF5yhZuomC+v3nsoCfT+uWXNwkEgKTkejRQDcIA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CyIB3vGE; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-412748b183aso270705e9.1 for ; Tue, 20 Feb 2024 13:02:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708462952; x=1709067752; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vHk8B1G9ngPFWZyvzcJjpFnWjSLSm2alsXCknI8ZS8Y=; b=CyIB3vGE8eSTX9uWbtaob7o6JmuFZQ1x7nVLtjylPqvpzsK61iokku/uHoUHrFwvj4 +VmErEWnhSQfMz0UpEBg8rJXnqHgtSgVMBLV6CopJMOMFJ81T00o3DU/SSHx/tLe1yAy 10LjbjcfrVmBFyJtwuEL5zeCAbBlcMGdBwEYz9XQmRBDgkffK1nXg2tpTqbH59HDXAnl fSRDzNEc0oTEC7JV7MBhslLaJvF+ealBdxTa3zp3uRbLOBBkJMTo1jmmcgoofQmXvStO sFKqMotFp1xXCFWnrSfvr4+aLVqnPMi/13eJ/iVZqNZoIcRTWKG8CvVpC9mVU92vDatQ dcYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708462952; x=1709067752; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vHk8B1G9ngPFWZyvzcJjpFnWjSLSm2alsXCknI8ZS8Y=; b=oFc0V02DgKtzs8PjZQT4ecx+f5dSfMpII6A0rRVqxb4BNFT9ZJ0yw1HTRVV/6eYI9r fY2N2PuptcEIcfqJ4Y6uDkRjgQOBXyLoHnnVCcx+VHqJfuT8kdpL8RGM3FvNzKRPQ+y2 4QuCIJI/TOsNHy4bXDidE62IcYfp0SfT89E3O0dykG7jkqCc+IBGkQkp5rWaXaYEs0zj yW0GTRPnUjd3UjAbFHkcbvDXkqdPWdK3hv5n00vAMopJ3xfER3PP7EL1ZlaDarXpBLcS jcRv16XZVNoM8hgz+ZmTobLV0pjxjqFl4eHc1OJkUXZPNhBRPdGN7t1lvTm7eROjtEZj Aqyg== X-Forwarded-Encrypted: i=1; AJvYcCWCITd82Vg2AsFxjog+HA1NNpiuxUf6buYNOYH1VXXhxhsVMskLKlp3KpluOwESs7eyPKWKYq3IYeojm8GXqFkF0Hyv2377ItsaDkLo X-Gm-Message-State: AOJu0YwCyj5mj9p5DAQpFwOX6YGb6vg79jjkIsVhRsz2OsDcCRx7ihQS C32q7HXSmc8s3Qh9wz8RbLJivGdsxGaoSTBQSyDGy5jGPuoNdWp/Lrl7FP5J X-Received: by 2002:a05:600c:190c:b0:411:cb30:8e00 with SMTP id j12-20020a05600c190c00b00411cb308e00mr12141209wmq.3.1708462951917; Tue, 20 Feb 2024 13:02:31 -0800 (PST) Received: from localhost (host86-164-109-77.range86-164.btcentralplus.com. [86.164.109.77]) by smtp.gmail.com with ESMTPSA id t18-20020a05600c451200b0040fd1629443sm16087456wmo.18.2024.02.20.13.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 13:02:30 -0800 (PST) Date: Tue, 20 Feb 2024 21:00:15 +0000 From: Lorenzo Stoakes To: Yajun Deng Cc: akpm@linux-foundation.org, Liam.Howlett@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz Subject: Re: [PATCH] mm/mmap: Add case 9 in vma_merge() Message-ID: References: <20240218085028.3294332-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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Feb 20, 2024 at 11:00:30AM +0800, Yajun Deng wrote: > > On 2024/2/19 07:03, Lorenzo Stoakes wrote: [snip] > > Yes, it's not a merge case. I label this to make it easier to understand. OK, I guess I have to be more explicit + less soft here to avoid confusion as you seem not to be paying attention to what I have said - We can't have this in the patch, full stop. I (+ Liam) have already explained above as to why, but to emphasise - each case number refers to a merge case consistently throughout. Arbitrarily adding a new case label to describe one of the many early exit conditions proactively HURTS understanding. > > > > * PPNNNNNNNNNN PPPPPPPPPPCC > > > * mmap, brk or case 4 below case 5 below > > > * mremap move: > > > @@ -890,6 +890,9 @@ static struct vm_area_struct > > > if (vm_flags & VM_SPECIAL) > > > return NULL; > > > > > > + if (prev && end < prev->vm_end) /* case 9 */ > > > + return NULL; > > > + > > I need to get back into vma_merge() head space, but I don't actually think > > a caller that's behaving correctly should ever do this. I know the ASCII > > diagram above lists it as a thing that can happen, but I think we > > implicitly avoid this from the way we invoke callers. Either prev == vma as > > per vma_merge_extend(), or the loops that invoke vma_merge_new_vma() > > wouldn't permit this to occur. > No, it will actually happen. That's why I submitted this patch. You aren't explaining any situation where this would happen. As Liam says, this is something you have to provide. I have taken a moment to look into this and I am afraid I don't feel this patch makes sense. Firstly, let's assume you're right and we can reach this function with end < prev->vm_end: 1. curr will be NULL as find_vma_intersection(mm, prev->vm_end, end) will always find nothing since end < prev->vm_end. 2. We discover next by using vma_lookup(mm, end). This will always be NULL since no VMA starts at end (it is < prev->vm_end so within prev). 3. Therefore next will always be NULL. 4. Therefore the only situation in which the function would proceed is that checked in the 'if (prev)' block, but that checks whether addr == prev->vm_end, but since end < prev->vm_end, it can't [we explicitly check for addr >= end in a VM_WARN_ON()]. Therefore - we will always abort in this case, and your early check is really not that useful - it's not something that is likely to come up (actually I don't think that it can come up, we'll come on to that), and so being very slightly delayed in exiting is not a great gain. You are then also introducing a fairly useless branch for everybody else for - if it even exists - a very rare scenario. I do not think this is a good RoI. As to whether this can happen - I have dug a bit into callers: 1. vma_merge_extend() always specifies vma->vm_end as the start explicitly to extend the VMA so this scenario isn't possible. 2. Both callers of vma_merge_new_vma() are trying to insert a new VMA and explicitly look for a prev VMA and thus should never trigger this scenario. This leaves vma_modify(), and again I can't see a case where prev would not actually be the previous VMA, with start/end set accordingly. I am happy to be corrected/embarrassed if I'm missed something out here (vma_merge() is a great function for creating confusion + causing unlikely scenarios), so please do provide details of such a case if you can find one. TL;DR: - The case 9 stuff is completely wrong. - I do not think this patch is useful even if the scenario you describe arises. - I can't see how the scenario you describe could arise. So overall, unless you can provide compelling evidence for both this scenario actually occurring in practice AND the need for an early exit, this patch is a no-go. In addition, if you were to find such, you'd really really need to beef out the commit message, which is far too short, and frankly incorrect at this point - if you perform a branch which 99.9999% of the time is not taken, you are not 'reducing unnecessary operations' you are creating them. If you could find compelling evidence to support this patch and send this as a v2 then I'd consider it, but for the patch in its current form: NACK.