Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp715257rdb; Thu, 22 Feb 2024 18:30:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW8hvggaz3Xq/mEoJVNWuz5EjLl2vkmYsYhy+KbSzRG7ecF9yT8kdCoioJnZaEZFZy3ro2OrG3hSG+47XoRfEc7cDWhHiezKCi2scEEOw== X-Google-Smtp-Source: AGHT+IEbGXSLEQao0BE04ROMeOfqmZNegjS3r6TPq9xsfSW1136fs7K5eEl8qpzQig4ICif+jITT X-Received: by 2002:a17:906:b2d9:b0:a3f:c61e:453a with SMTP id cf25-20020a170906b2d900b00a3fc61e453amr195380ejb.41.1708655453697; Thu, 22 Feb 2024 18:30:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708655453; cv=pass; d=google.com; s=arc-20160816; b=zghjMkkLH6XazKiDtMHhJ4rF1PN7Z9+0dVxHfrg3Mw/XnSw5CN5LDZxgCKfgRaTmt3 Id8jl6MLgojOxKnyqQvuNk+nPysoaQwx1xsOAaW94J5yCovR8nl3ZgzQn4EpPSHjzYgj RRB5ZFdAKH78mZ4Rlw9ArK9HKM3lgodOjsq+0A8Inf5M//5fbbKF1/RqqLvmtAldYaH5 kemDgE+5f6cONpCeeMJGWmPnz1gtS66SCI+xMbv0xZLzjTRG3h1tnKsLWNzCEbRBoWtT p6st8vpPcAEI9zZIwHzv12pm72/vJYQACs5xbun0/QNtnvNGQ/NwD17TXhaZB6n10SV7 T7uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=Dn0DwPHukXKXbPRCk/008A2MQ+iJBle+LqZeMHn+wVQ=; fh=hnKfTkTOwleGp117FVZL4OdnDtUQY4OLVQFODp/Kmmw=; b=lZXk9fpOJLoIv1sVPQpQXGO/1/5ivmZVL5t6fAKWUo8ZQ/a69bpspX/dwCpsZiXnlb vBKLnM/bPryyA59LGz+g4HEZga+wOI36VsbOU0kgGXSk1byON6mjyQ0hAeTiFv4nMcsG ebfiRGn9U0QKfWqZU7O40eP5cP1BnOpV54WH/sdT3ximI8CPbtBZ7VmseHeb+tXoqQkM otDZ+AR1hDo9l0S+IQzZ8sPYqIUN31ksK5mm/BvRF8pkDBXPbHokSwObRGASCzUrsxkn WotJKVrC884LuPapGjIH8M4SyeuvcKjO0ZawOx7Enmwh2nzvuGnLLM0leR+62YlWzJED cG0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RX5zaavS; 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-77680-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77680-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cs12-20020a170906dc8c00b00a3ec1f042d1si3649534ejc.389.2024.02.22.18.30.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 18:30:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77680-linux.lists.archive=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=RX5zaavS; 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-77680-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77680-linux.lists.archive=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 723071F24C76 for ; Fri, 23 Feb 2024 02:30:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C65CB665; Fri, 23 Feb 2024 02:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="RX5zaavS" Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 623B4372 for ; Fri, 23 Feb 2024 02:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708655444; cv=none; b=Cxz+IdoJZ33sxm/gog3Nd17qv3JFcga6l4Z2W8gFEotyImyBPSYwrsEntBgrgrfB7wN6q78LfXc5hThICNRE16IHueHVjbL6QdBharq+A2ewL9mWC4QxtBUdXBjdIGCbyfAGqgdvUQLqP/gRpb54GcDgBJr3aiJBitaLdbs1DoU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708655444; c=relaxed/simple; bh=73cz1+ZnwyITTeM7LH5Pf640GbLeYiiXss/FXfdry4A=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=bHwNmju7ND0uYGDQGvtWkx/b7e2Rx4OoHygZptUNrlfXdW8l6SfB1Bjyr8Rixc7204hT0XuAwT+uxcZWVcQ5S5zTrCOGth66DMld/MHcDmOym99LOsJZACBaajNVA69apdxfcSIvvDrFmD8Q8TU0tQt4UNzXIUWHwOiaDrJ7tUE= 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=RX5zaavS; arc=none smtp.client-ip=91.218.175.180 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 Message-ID: <7cc1952d-958f-3867-d9eb-fd70d41b29f3@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708655440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dn0DwPHukXKXbPRCk/008A2MQ+iJBle+LqZeMHn+wVQ=; b=RX5zaavSP806/U8b+yYYISEclwVh+Tr4o+XaPiXiO3bDMoeFU9jYmtlpeMvNIorn5lGraa pWNh/EPaXLh4fsR2LumXrp9VmSOfbtZ59tXQmdDqrWplHD58MOniyC/oN9NgcijlBOn5LK B1ylnjPMnHAlxl+97x0IeBD5eJvXdEI= Date: Fri, 23 Feb 2024 10:30:29 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/mmap: convert all mas except mas_detach to vma iterator Content-Language: en-US To: "Liam R. Howlett" , akpm@linux-foundation.org, vbabka@suse.cz, lstoakes@gmail.com, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240218023155.2684469-1-yajun.deng@linux.dev> <9f76ce23-67b1-ccbe-a722-1db0e8f0a408@linux.dev> <20240220180603.dhnthx2nk5455opm@revolver> <0ff93990-b8b6-89ce-0174-4023599059e7@linux.dev> <20240221143103.bkhewpq2wirsoyqw@revolver> <20240222150703.u55kpmdlog5hrld3@revolver> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng In-Reply-To: <20240222150703.u55kpmdlog5hrld3@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2024/2/22 23:07, Liam R. Howlett wrote: > * Yajun Deng [240222 03:56]: > ... > >>>>>>> @@ -1959,11 +1958,12 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address) >>>>>>> struct vm_area_struct *next; >>>>>>> unsigned long gap_addr; >>>>>>> int error = 0; >>>>>>> - MA_STATE(mas, &mm->mm_mt, vma->vm_start, address); >>>>>>> + VMA_ITERATOR(vmi, mm, 0); >>>>>>> if (!(vma->vm_flags & VM_GROWSUP)) >>>>>>> return -EFAULT; >>>>>>> + vma_iter_config(&vmi, vma->vm_start, address); >>>>> This is confusing. I think you are doing this so that the vma iterator >>>>> is set up the same as the maple state, and not what is logically >>>>> necessary? >>>> Yes, VMA_ITERATOR can only pass one address. >>>> >>>>>>> /* Guard against exceeding limits of the address space. */ >>>>>>> address &= PAGE_MASK; >>>>>>> if (address >= (TASK_SIZE & PAGE_MASK)) >>>>>>> @@ -1985,15 +1985,15 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address) >>>>>>> } >>>>>>> if (next) >>>>>>> - mas_prev_range(&mas, address); >>>>>>> + mas_prev_range(&vmi.mas, address); >>>>> This isn't really hiding the maple state. >>>> Okay,  I will create a new helper function for this in the mm/internal.h. >>>> >>>>>>> - __mas_set_range(&mas, vma->vm_start, address - 1); >>>>>>> - if (mas_preallocate(&mas, vma, GFP_KERNEL)) >>>>>>> + vma_iter_config(&vmi, vma->vm_start, address); >>>>> The above maple state changes is to get the maple state to point to the >>>>> correct area for the preallocation call below. This seems unnecessary >>>>> to me. >>>>> >>>>> We really should just set it up correctly. Unfortunately, with the VMA >>>>> iterator, that's not really possible on initialization. >>>>> >>>>> What we can do is use the vma->vm_start for the initialization, then use >>>>> vma_iter_config() here. That will not reset any state - but that's fine >>>>> because the preallocation is the first call that actually uses it >>>>> anyways. >>>>> >>>>> So we can initialize with vma->vm_start, don't call vma_iter_config >>>>> until here, and also drop the if (next) part. >>>>> >>>>> This is possible here because it's not optimised like the >>>>> expand_upwards() case, which uses the state to check prev and avoids an >>>>> extra walk. >>>>> >>>>> Please make sure to test with the ltp tests on the stack combining, etc >>>>> on a platform that expands down. >> >> It seems something wrong about this description. This change is in >> expand_upwards(), but not in >> >> expand_downwards(). So we should test it on a platform that expands up. > Oh, yes. Test on the platform that expands upwards would be best. > Sorry about the mix up. I didn't have a platform that expands up, so I can't test the expand_upwards(). >> And >> drop the if (next) part >> >> is unnecessary. Did I get that right? > Yes, I think the if (next) part is unnecessary because the maple > state/vma iterator has not actually moved - we use > find_vma_intersection() to locate next and not the iterator. This is > different than what we do in the expand_downwards. Yes. Since I can't test the expand_upwards(), I think it's safer to keep the if (next) part. > Note that, in the even that we reach the limit and cannot return a > usable address, these functions will call the counterpart and search in > the opposite direction. > >>>> Okay, I will test it. >>> Testing this can be tricky. Thanks for looking at it. >>> > ... > > > Thanks, > Liam >