From patchwork Fri Dec 16 16:32:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13075197 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 67496C001B2 for ; Fri, 16 Dec 2022 16:32:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1EA18E0003; Fri, 16 Dec 2022 11:32:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DCE758E0002; Fri, 16 Dec 2022 11:32:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C96B98E0003; Fri, 16 Dec 2022 11:32:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BAB488E0002 for ; Fri, 16 Dec 2022 11:32:35 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 46EBDA114D for ; Fri, 16 Dec 2022 16:32:34 +0000 (UTC) X-FDA: 80248712628.20.02E79AD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf05.hostedemail.com (Postfix) with ESMTP id 38C4B100022 for ; Fri, 16 Dec 2022 16:32:30 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="G0OuXHi/"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yah1WAub; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671208351; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=ifpYR2PdESJAbvJefyXjW1EWj/1z2L0zImGtUVLVTog=; b=EC5Q5sBI+138K+EW1vs/UcYbg5Lfsalw7ymkwqxi6B6GpWoEENgGgbEHZQLCvUBxcvVVA5 vl+AtdtGuGDHmz7Hprf43drSZ8f8No2w7pf21LQ3YVIgPpLszNaN4LYcJPz8zFXGNpN32A ghSqSfR7f0CsNJZqDUrvO/7WXFvYKKo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="G0OuXHi/"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yah1WAub; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671208351; a=rsa-sha256; cv=none; b=5f9AiukULIv3oxojD1u415t3fiC8YB75sYO3z3uW/oqBNhDEFpGp1D+svjam1Q+zIhFrX6 /hrPdq+m9FtHexyBtCer9sdnruZ3l5TzCU9IRazC9Cr4F25M6LxEM6ceKxMNrTjdFYsnRS r8ST2ar81UzF6BeVH65zS/pY0NVQxRI= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 86A1A3454D; Fri, 16 Dec 2022 16:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671208349; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ifpYR2PdESJAbvJefyXjW1EWj/1z2L0zImGtUVLVTog=; b=G0OuXHi/vYNbH57ZVsfKkJHhPgNpbk73CrPzwAWNhyKC3Xh8oDQOLuRGpTKYCaTgy2aXzB k0KaxX3xKjrzsD+IFm28RtsBbuoo+JfPz565cOawN8pNgSC13NF9g2u/aUaZ1t/RcOUdug Qo9E/fq7nu67Auoe/CaI7a2LO2TRDg8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671208349; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ifpYR2PdESJAbvJefyXjW1EWj/1z2L0zImGtUVLVTog=; b=yah1WAubrE2ujAH04CMoJ6yYkHNQn4D1DQrpz87GR8v/vJCOlcD2/p8mCcKOkvRmP0v02E soZWIZ2/b5FHFHAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 580D0138F0; Fri, 16 Dec 2022 16:32:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /03PFJ2dnGOaKQAAMHmgww (envelope-from ); Fri, 16 Dec 2022 16:32:29 +0000 From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, Vlastimil Babka , Jiri Slaby , =?utf-8?q?Jakub_Mat=C4=9Bna?= , stable@vger.kernel.org, "Kirill A . Shutemov" , Liam Howlett , Matthew Wilcox , Mel Gorman , Michal Hocko Subject: [PATCH for v6.1 regression] mm, mremap: fix mremap() expanding vma with addr inside vma Date: Fri, 16 Dec 2022 17:32:27 +0100 Message-Id: <20221216163227.24648-1-vbabka@suse.cz> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 38C4B100022 X-Rspam-User: X-Stat-Signature: ar8kg6mu7qadxzwpz58bhb1jygg8ffbi X-HE-Tag: 1671208350-286639 X-HE-Meta: U2FsdGVkX1+Q/yd0ZlQu4yHryyRcGcVEZ/PiLMabVoCRrGvCD4pEfcjhexlT7nb1Pe30MolHqXA5cmEvFEwFzpEFfLb+etWhmhZ7j8m9qr78wwtzHDfmKxBnpQ0lnYKOKWzhvLsGiORTajBZfCBBxavCLG99x302np+kjvGGASXJM52+9TpkTjJ15IUxNOhJ8NWWPWA6fGmS8rh4gV2tUnccD3R/+A/Pyrrg9cM97QaJxxC5hGY0CQSsg6L0yT8CLFSL2F15XBrFHPYECoY3kCUFwOZGHBNfVNPSYIrm+i3Cq/p4ceZ8a2GC1Xc7Fpck3OYar69Pz91JgSN1dOBQ3s2hInG6IKKpHL8LmZDovnrCAoox2iEPRhpEKMophHgwbOd4e/nCRGf4MOqIEaP/khP3fcbqXemg5uPlZT/H58eI6DwuJP5NITk9hT4GznGiRZWF0ZJLIjhQ1YoYaNvJQAx13f5+FQJcYi16GA+gx7wewkgjHT7sKpLkqJBunVa4aBmBUJPCwLE1CRjXIx9vra8JpvxKMPahdx4/EjrFdZCdt55yDITKp8itvcWzwD90DiePBVxiS3dC6YmD7AEPw+Nbt4HhdGnP8vwJgCyuF8Ydal56Mrb2ZMeXOlih9X45M/qFPIwXL/uCqn7X4GAXqlFM/m1n3srqPj398D6BjA6cOMTPybODAnDtor/77UOVh5mYy06kN4KtpBI/KkoM7JfGu2QvMUKOfESxYUp0CD2zCnwaZiIRbu0oWviAGNhvx9X9PYWM51qyjjOPrlkjxIrvGG4Ovfv2OjPSbulO4UkyuQYZBWhWm0Xjd+XPshAFut0/HPgBVEHvijn2+5KbRxWBnmC/tFxD+6KLf/DEU7EneP24RusTteDeTK+U+rEw/gSiQttJMWmt+LoD5HtkaewhUNOtkRen 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: Since 6.1 we have noticed random rpm install failures that were tracked to mremap() returning -ENOMEM and to commit ca3d76b0aa80 ("mm: add merging after mremap resize"). The problem occurs when mremap() expands a VMA in place, but using an starting address that's not vma->vm_start, but somewhere in the middle. The extension_pgoff calculation introduced by the commit is wrong in that case, so vma_merge() fails due to pgoffs not being compatible. Fix the calculation. By the way it seems that the situations, where rpm now expands a vma from the middle, were made possible also due to that commit, thanks to the improved vma merging. Yet it should work just fine, except for the buggy calculation. Reported-by: Jiri Slaby Link: https://bugzilla.suse.com/show_bug.cgi?id=1206359 Fixes: ca3d76b0aa80 ("mm: add merging after mremap resize") Signed-off-by: Vlastimil Babka Cc: Jakub Matěna Cc: Cc: "Kirill A . Shutemov" Cc: Liam Howlett Cc: Matthew Wilcox Cc: Mel Gorman Cc: Michal Hocko --- Hi, this fixes a regression in 6.1 so please process ASAP so that stable 6.1.y can get the fix. mm/mremap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index e465ffe279bb..fe587c5d6591 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -1016,7 +1016,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, long pages = (new_len - old_len) >> PAGE_SHIFT; unsigned long extension_start = addr + old_len; unsigned long extension_end = addr + new_len; - pgoff_t extension_pgoff = vma->vm_pgoff + (old_len >> PAGE_SHIFT); + pgoff_t extension_pgoff = vma->vm_pgoff + + ((extension_start - vma->vm_start) >> PAGE_SHIFT); if (vma->vm_flags & VM_ACCOUNT) { if (security_vm_enough_memory_mm(mm, pages)) {