From mboxrd@z Thu Jan 1 00:00:00 1970 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 421B3D63934 for ; Wed, 20 Nov 2024 12:32:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD10C6B0099; Wed, 20 Nov 2024 07:32:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C811D6B009A; Wed, 20 Nov 2024 07:32:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B717A6B009B; Wed, 20 Nov 2024 07:32:57 -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 9A6AA6B0099 for ; Wed, 20 Nov 2024 07:32:57 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 43DD080C08 for ; Wed, 20 Nov 2024 12:32:57 +0000 (UTC) X-FDA: 82806411282.24.7640FD3 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf01.hostedemail.com (Postfix) with ESMTP id 9CAB240015 for ; Wed, 20 Nov 2024 12:32:15 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=ifki3lrh; spf=pass (imf01.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732105772; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=89c7QmVX2synJiQi/174f0jggdlFnbdY/35aa26SO84=; b=b0tT1xB0YR5GIenIGSU33TXWmjxOj/TJHUR0PaOIKWEy7x7rPEUy+cto6jAhu/syJGiWdR CrlZZn9u7BcXQOt4BR3zqNHPiSuIbAxb0VfGfSmTpsszgmfV7n4i/CASleFwYGW98zbLQD tgPJnWihJSS+ZgsKj4BwL5dLsDnO8IY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=ifki3lrh; spf=pass (imf01.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732105772; a=rsa-sha256; cv=none; b=k/4Can3FTT5+fT4xU+i4OfadEWuwWL6q8LuZNOY9K2PBdUe1NMZNcu78gefV4zx0GRKjAn LndU2lnOgNR0fYnfHMjBrxFk2HBjwCSzEnMIeGXgX9TpbeLhqpQcYH/JHXLT2K+RQIav8O hXH3HMfD9hQASUttajJZXI5neT4Jt5I= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 55CA1A42EBE; Wed, 20 Nov 2024 12:31:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65C67C4CECD; Wed, 20 Nov 2024 12:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1732105974; bh=BORz0CF2IQbmXcz7O43m7nZi39ZyC2WsbFBh0jgAF0Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ifki3lrhQlZVPwe2jnQyj376Q5qQ+8rXgBboUtAMtC4UCWqVr2H17dMRQbS/v4gvJ ls8/EVH2agddzteywUb0iuAuWFdE7Ks5lnReoSNK+GepmfORFLrS+4LpZFeYf7ZaUD dSfPyxbOHZk5KzMmThPE9ZoLc99l6K671GQhDOZo= Date: Wed, 20 Nov 2024 13:32:29 +0100 From: Greg KH To: "Liam R. Howlett" Cc: stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Lorenzo Stoakes , Jann Horn , syzbot+bc6bfc25a68b7a020ee1@syzkaller.appspotmail.com, Vlastimil Babka Subject: Re: [PATCH 6.12.y v2] mm/mmap: fix __mmap_region() error handling in rare merge failure case Message-ID: <2024112019-skating-goofball-d2be@gregkh> References: <20241119175945.2600945-1-Liam.Howlett@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241119175945.2600945-1-Liam.Howlett@oracle.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9CAB240015 X-Stat-Signature: cj78k318ekmatke5cc9qfdkjozz7r7s1 X-Rspam-User: X-HE-Tag: 1732105935-295724 X-HE-Meta: U2FsdGVkX1+M2ZV1E2kD++DILcqpfAZsltD7gSYVhvvtYB5olijxcs8LapCnBCxJnjLKoirms16MaiiaOr36nMWwONZWR/Z1jXnvH0ManCiuSWlDQPJOwadOCQSO1tL1DOqCqo/jsHFQBQ1k5pIvKrfgm/n+FS7NVfwm39n1gxUM83LrW4Xsa67IibOXAuRsUXWpss8JdhaIIpScORmCsawbyURrc/xn7wNKSRlWZdqJL0ejULpmGQfE0U2mnNl0O7FtnEytj693pNc84/OUsraAVpkkxRBm67QcO8b0dHu+9EBCEY5AXDJfgcB2p8T0ZNIanxd28Yz5k+hLVDOMK7NVOReo+Szr8CfYqgFEAuDCvTQZUmZTZDVa388s3O//v1geUTZnjNzI32sT4bCDEirD9qe2JoAn/yQbuUWOHhi+ihKFBW3BYbe/+dRi+XtEKgypt/t9IEUeFB/7cajAJN2kqtcpbU+7ir3lws21mk02mbplA1X+0cYlnKQ+LW3Xyg/AxyicetV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ndRDFao48iRwUS1Vr2yuvOBCT2gN7cjN3B2GYPfh1KocLID8nVdbiJHMasg== 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: On Tue, Nov 19, 2024 at 12:59:45PM -0500, Liam R. Howlett wrote: > From: "Liam R. Howlett" > > The mmap_region() function tries to install a new vma, which requires a > pre-allocation for the maple tree write due to the complex locking > scenarios involved. > > Recent efforts to simplify the error recovery required the relocation of > the preallocation of the maple tree nodes (via vma_iter_prealloc() > calling mas_preallocate()) higher in the function. > > The relocation of the preallocation meant that, if there was a file > associated with the vma and the driver call (mmap_file()) modified the > vma flags, then a new merge of the new vma with existing vmas is > attempted. > > During the attempt to merge the existing vma with the new vma, the vma > iterator is used - the same iterator that would be used for the next > write attempt to the tree. In the event of needing a further allocation > and if the new allocations fails, the vma iterator (and contained maple > state) will cleaned up, including freeing all previous allocations and > will be reset internally. > > Upon returning to the __mmap_region() function, the error is available > in the vma_merge_struct and can be used to detect the -ENOMEM status. > > Hitting an -ENOMEM scenario after the driver callback leaves the system > in a state that undoing the mapping is worse than continuing by dipping > into the reserve. > > A preallocation should be performed in the case of an -ENOMEM and the > allocations were lost during the failure scenario. The __GFP_NOFAIL > flag is used in the allocation to ensure the allocation succeeds after > implicitly telling the driver that the mapping was happening. > > The range is already set in the vma_iter_store() call below, so it is > not necessary and is dropped. > > Reported-by: syzbot+bc6bfc25a68b7a020ee1@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/x/log.txt?x=17b0ace8580000 > Fixes: 5de195060b2e2 ("mm: resolve faulty mmap_region() error path behaviour") > Signed-off-by: Liam R. Howlett > Reviewed-by: Vlastimil Babka > Reviewed-by: Lorenzo Stoakes > Cc: Jann Horn > Cc: > --- > mm/mmap.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > Changes since v1: > - Don't bail out and force the allocation when the merge failure is > -ENOMEM - Thanks Lorenzo Now queued up, thanks. greg k-h