From patchwork Mon Jan 27 07:55:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13951050 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 D04E3C0218F for ; Mon, 27 Jan 2025 07:55:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 224D9280110; Mon, 27 Jan 2025 02:55:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D31B2800E8; Mon, 27 Jan 2025 02:55:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07381280110; Mon, 27 Jan 2025 02:55:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C66702800E8 for ; Mon, 27 Jan 2025 02:55:56 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 49FEEC2002 for ; Mon, 27 Jan 2025 07:55:56 +0000 (UTC) X-FDA: 83052473112.28.0B8D5A6 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf10.hostedemail.com (Postfix) with ESMTP id 7E041C0004 for ; Mon, 27 Jan 2025 07:55:54 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DeEfX2PF; spf=pass (imf10.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737964554; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=ADd5QPXGRb0ZUjBZ78cLndx1ZBrU1KrHUZpnVuQhnKU=; b=OS2mtyonIjrQNxyX8iaNkysOUd02DLX4rpCYIn1SAsmRhhJ/TrKEyr+FJZuQ+cQ65KK6HY hP51n7aDOawHQ4h+EoUpeLiIgfEnXJ0p9OXu3JNbkXU6UGu/nR9x9Nnq5fyfy8dllZFKCC P6FGLMdc3xZDNPp5DgyQKCLEt2SWwfQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DeEfX2PF; spf=pass (imf10.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737964554; a=rsa-sha256; cv=none; b=IMXvGASssbbl8HwnmEKga32jRJV4d7joPvlsXSLdcvSyynANaKMhdHI2+3dSJjTQQ8BxWq 0KmI5xf9nuD9x8hRloFHuSBhBrqCCC4bxmoKHkbLz3Cy6SuDcZyfa8rMyTDmhCy+dTp6v2 IXZdjCaQlluh1UChmRPLcWL2QWTGXiA= Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-aab925654d9so797481166b.2 for ; Sun, 26 Jan 2025 23:55:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737964553; x=1738569353; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=ADd5QPXGRb0ZUjBZ78cLndx1ZBrU1KrHUZpnVuQhnKU=; b=DeEfX2PF4rtoybTRuR43y7e0cXs7LeAasFPXSHZgv80zxevJqY4ReZeF6rPIbbz7Ea 0zTs+3EG7OoqxafuyAzFuAI8f67fHV/ZIlTcNmRQPLtlh4sxMeZjyS4vOfyDa7ty5kY0 L0S9rjvNY2rBVdSfALUU5xpvDJow/NNObjoAIadTGLTjKfEs3PoikzRr9suKEiN4nwBg RVjKkyGX7TUZBvuhb53WN20hKdqa+2ZR8ZytsP0JxEQvprJ8dV5U30/cdwz9nFOD/CXe hLCH7avnk6py8JJben75aHp8UbHG2cCM66s1gOs16N/kxHK/MUpO3LjCNr3BfZVTSeIk l4Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737964553; x=1738569353; h=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=ADd5QPXGRb0ZUjBZ78cLndx1ZBrU1KrHUZpnVuQhnKU=; b=cBW1SLDMAxYFsZOGFt2Lrqr95qom/n0IDtn68sLZfoOQ2NzGLUXF7N3WQO1dIBnM5R CqWi2afMhJwJfciRucn1Sf8UE85D57ujyzPDY/8YLotSCEG6rYEgDFRN4g8pdGB2IogW 8xWsWIUqyF1/6+cQXG3nX6E9WRjg0P6fCWuxEO2VhsZNlXPJ5o2NUtm7Y/15RzTZ7Ga6 ckopaZD6BgiSBD6LjptmnkCuyEsib/REH3uiONX5MSqCOAkeioveOetYE7ITyreBaOna nky+dGtk9IIDq2I+VoV0gKdW3wC+Kv2fyj1hLiO8e5dFU26j+jrUzEOGrWQ+zuL/jhD4 fAYQ== X-Gm-Message-State: AOJu0YzH12/8pPF+keo/Z4jQbK8zGocCint0OK4HRsep1ajMvkt8rUlF wQm3Ttl/F1Fi3kwoBWcA4n6W8jccsr30D0FTzdE2oGoW80+8aImxoIsGBI9Q X-Gm-Gg: ASbGncs28NbZkJhN9+oHcR1x6+g0u1ETvJSfWkrqVMpBCyFFXhIwHVi9hjGqTOlyktl Tj+xLvS753QnsnR4MbcPSEL7P1W9+J7sg/QnHXxCg08iY6Lr/etsFMwdn5wcVQ/7+cw3vWaylbp tZZss9rzpHVTeGz2QrBBOsexAkER40F7WYAsM8iBctgA1nr9uPa6PZRnyDasvq5fMKzLfTNiyCv XSD4SztP6Wd1/4VhTr0RYN3Da9hE2UDT12XdEexBX7DW+NwCtQN58U3P3geB537kQUXUHTxexUQ ZWd9 X-Google-Smtp-Source: AGHT+IHlscf9pv6r0jiLUseqKU8ejlUSjBA5cQSqFQEHoIoA5Djzp67orLWMyS93LOOrQKsWadji5A== X-Received: by 2002:a17:907:940e:b0:aae:bd36:b198 with SMTP id a640c23a62f3a-ab38b4c6a1emr3326207366b.47.1737964552729; Sun, 26 Jan 2025 23:55:52 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab675e11ec2sm542120066b.35.2025.01.26.23.55.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 Jan 2025 23:55:51 -0800 (PST) From: Wei Yang To: akpm@linux-foundation.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com Cc: linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Rick Edgecombe , stable@vger.kernel.org Subject: [PATCH 1/2] mm/vma: fix gap check for unmapped_area with VM_GROWSDOWN Date: Mon, 27 Jan 2025 07:55:26 +0000 Message-Id: <20250127075527.16614-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20250127075527.16614-1-richard.weiyang@gmail.com> References: <20250127075527.16614-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7E041C0004 X-Stat-Signature: mmhnhpkx1ippsoebkyoaaw1pjdwzjwob X-Rspam-User: X-HE-Tag: 1737964554-684643 X-HE-Meta: U2FsdGVkX19WfWqrbt5fx+4KS2Rv7KGVGs46seze142Cw6X2UonpETfT4vcUQE4qCEJBBLijMd1Buhr1WKmTqsSnyiGlKzlyThZH5IhRe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JJvlmCmbVwDyw5YMk8oLEtUuxXdCsstRxtFrM/AE4dJsbQdZLSycL52SMZfUwUZ321ANleh73HXzhIhSV7CWk7RO1qCyOTkJqbyiKiJtSB8MCHEd5XtFXYZKS02uX0abWMTg+C7oWS+TFH3CJ+HmmBWoLqmfWqW1olOOf0LoDP2TIfbm490wcXfW9T7NLLYaEKCRuQLEgOCywMBa/ceT+rDpDtsUW+Hjg1STBpBpN6I3hPxBF+T1qihLbdvLLTuqbOZv9cakk70hrjAAS/tzCobGGzXT0fgSQpqfRyjMEYVwn+Jde1LwOtPgE9DQEzrjjsn2n8VInExxxxvCZb4Mns3eeXCUnGrQr5pRrAkFEX+BedxvE/diMJ6GgftJIPDPUs6svsEhWIK3M+wYE+eG57ZkmoAZj8VE0M2a0ng1i41p1ZBgG31w9Uve3g== 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: Current unmapped_area() may fail to get the available area. For example, we have a vma range like below: 0123456789abcdef m m A m m Let's assume start_gap is 0x2000 and stack_guard_gap is 0x1000. And now we are looking for free area with size 0x1000 within [0x2000, 0xd000]. The unmapped_area_topdown() could find address at 0x8000, while unmapped_area() fails. In original code before commit 3499a13168da ("mm/mmap: use maple tree for unmapped_area{_topdown}"), the logic is: * find a gap with total length, including alignment * adjust start address with alignment What we do now is: * find a gap with total length, including alignment * adjust start address with alignment * then compare the left range with total length This is not necessary to compare with total length again after start address adjusted. Also, it is not correct to minus 1 here. This may not trigger an issue in real world, since address are usually aligned with page size. Fixes: 58c5d0d6d522 ("mm/mmap: regression fix for unmapped_area{_topdown}") Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Lorenzo Stoakes CC: Vlastimil Babka CC: Jann Horn CC: Rick Edgecombe Cc: --- mm/vma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vma.c b/mm/vma.c index 3f45a245e31b..d82fdbc710b0 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2668,7 +2668,7 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info) gap += (info->align_offset - gap) & info->align_mask; tmp = vma_next(&vmi); if (tmp && (tmp->vm_flags & VM_STARTGAP_FLAGS)) { /* Avoid prev check if possible */ - if (vm_start_gap(tmp) < gap + length - 1) { + if (vm_start_gap(tmp) < gap + info->length) { low_limit = tmp->vm_end; vma_iter_reset(&vmi); goto retry;