From patchwork Tue May 28 20:53:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13677446 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 95092C25B78 for ; Tue, 28 May 2024 20:53:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DC196B00AA; Tue, 28 May 2024 16:53:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 265976B00AB; Tue, 28 May 2024 16:53:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DF006B00AC; Tue, 28 May 2024 16:53:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E167A6B00AA for ; Tue, 28 May 2024 16:53:34 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 90A39803CE for ; Tue, 28 May 2024 20:53:34 +0000 (UTC) X-FDA: 82169005548.03.FE060A8 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf19.hostedemail.com (Postfix) with ESMTP id 698C31A0014 for ; Tue, 28 May 2024 20:53:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=SMDNGdD2; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="pHenuFy/"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="mJq/oUDs"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cE0EMu7N; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716929611; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=nPM8/5iyaxn91F5FasQwKg49PMvS+vUFJtBXhbVxWmg=; b=j+B1zC58r4JsWhEAtfS42aMwGCpbi7j8cKZqTEROSOYsngFh6S4H742tNxlDrbRt7ftQaA X9YHYbqCcxVC/ileJFOTp6soejItE5q3y1lIs1p2S0fE8dI+ZY27CQQ8HR/he81ILOLTbv mOFHjSZdxP0dhPrsPpR6Ou8cK4uvNj8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716929611; a=rsa-sha256; cv=none; b=oliFhCSnqs2jm1d2Delg4//RQpGADtD2gSpCMn0aDLh93mGN2Fgqo5nzXyXnpCe3PNfqDU nVIcGUPiIO1Ey2lqb+ArbZLYnQCI5iAcOHzJfEWjnsI0GAX8cje+piR7y9hPTFyi7PvuIN 3j3vABKtNyy2fPbPEdPHP+S8Mm5EHaQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=SMDNGdD2; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="pHenuFy/"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="mJq/oUDs"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=cE0EMu7N; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 73DD921DFF; Tue, 28 May 2024 20:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716929609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nPM8/5iyaxn91F5FasQwKg49PMvS+vUFJtBXhbVxWmg=; b=SMDNGdD22P0C4uH2aqVY1PLOLm287seK9UMiCyzjsHZET0/c1fn9c/t0J9cNok7tfNY22X LTh6ie0iT7ksJQKjxWjlWbPF54lpWifpRTn7WhtVDs/ztYNqW/Qp8WMza+dgTIDZX2DrKl bxnfV35KnUolkpveqAR+493DHB2dHBY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716929609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nPM8/5iyaxn91F5FasQwKg49PMvS+vUFJtBXhbVxWmg=; b=pHenuFy/l0U7a3ZJtt248LPOzMdQ7X2uXabie+KXo/j+Wd3fiVxMIkaSgguj4opRm6MIz8 euoVLf0D7Ki2eqAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716929608; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nPM8/5iyaxn91F5FasQwKg49PMvS+vUFJtBXhbVxWmg=; b=mJq/oUDs9jaUsxIRgP/bGB0xFqDKVyajM7HTMMwXNPs34PCaqeM2N44FHojNPmM8krgYWC EsGAncgBp+cApro51J6FO7qAr7JP2ccOlQc/72ObKhlOZ7dfSk0iO7qLX4YueHDlq3rVrA f3DKapoogQlZpPE5j0LyIc1sdzYcCBQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716929608; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nPM8/5iyaxn91F5FasQwKg49PMvS+vUFJtBXhbVxWmg=; b=cE0EMu7NbAKf1Se3PxBJLKSYA+UZzGv79MBqPqvHCqw/0sslaproiBoFzXuLERizxvtk2z XIt5r4oN7l01jbCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 09C1413A6B; Tue, 28 May 2024 20:53:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id e2PSOkdEVmY2cAAAD6G6ig (envelope-from ); Tue, 28 May 2024 20:53:27 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , Breno Leitao , Oscar Salvador , syzbot+d3fe2dc5ffe9380b714b@syzkaller.appspotmail.com Subject: [PATCH] mm/hugetlb: Do not call vma_add_reservation upon ENOMEM Date: Tue, 28 May 2024 22:53:23 +0200 Message-ID: <20240528205323.20439-1-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 698C31A0014 X-Rspam-User: X-Stat-Signature: kc5icpxc8qhbiuepnazxgcjxnteg3w1f X-HE-Tag: 1716929611-93419 X-HE-Meta: U2FsdGVkX18QK7QQALm6dFsCDIndTgGKDxAOOsytzeRMHMDussoOdtug2BToSkyTJYrX9iGI2uulzgSMqLJTdWBegw/mPbPukfGy5/Dwg8ZIoGKAdoY9fUPW4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Tr/la1k6X7jgx0vex/1HwSJSRRsqledaaTQteK/laV3B3RtRWu1bjsuZKU2UOxggk1Cyk021ZFklQb86B9wm+GLMw1cJs6sNnFWvDGKBOhNdFrbOQrxPe7FoJrHPhDGtIcznDudk5kfF6+1PZiAzjRdklNpP7BI+QFrnBIOuLQQMPj85ymYfDL4xf4h/a+Kp2bH5S9jrBFlINrTn7oSe9PjkxuxwK1kFPklmOoNlWuM/1kIjYACRjBejIUoNKPMVoIqIvsvZ0sRhxaTSStB6mHw9yeBxiQioHXigXh5FzeAglAJa4w++c3SE1xM= 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: sysbot reported a splat [1] on __unmap_hugepage_range(). This is because vma_needs_reservation() can return -ENOMEM if allocate_file_region_entries() fails to allocate the file_region struct for the reservation. Check for that and do not call vma_add_reservation() if that is the case, otherwise region_abort() and region_del() will see that we do not have any file_regions. If we detect that vma_needs_reservation() returned -ENOMEM, we clear the hugetlb_restore_reserve flag as if this reservation was still consumed, so free_huge_folio() will not increment the resv count. [1] https://lore.kernel.org/linux-mm/0000000000004096100617c58d54@google.com/T/#ma5983bc1ab18a54910da83416b3f89f3c7ee43aa Fixes: df7a6d1f6405 ("mm/hugetlb: restore the reservation if needed") Reported-and-tested-by: syzbot+d3fe2dc5ffe9380b714b@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-mm/0000000000004096100617c58d54@google.com/ Signed-off-by: Oscar Salvador Reviewed-by: Breno Leitao --- mm/hugetlb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6be78e7d4f6e..f35abff8be60 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5768,8 +5768,20 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, * do_exit() will not see it, and will keep the reservation * forever. */ - if (adjust_reservation && vma_needs_reservation(h, vma, address)) - vma_add_reservation(h, vma, address); + if (adjust_reservation) { + int rc = vma_needs_reservation(h, vma, address); + + if (rc < 0) + /* Pressumably allocate_file_region_entries failed + * to allocate a file_region struct. Clear + * hugetlb_restore_reserve so that global reserve + * count will not be incremented by free_huge_folio. + * Act as if we consumed the reservation. + */ + folio_clear_hugetlb_restore_reserve(page_folio(page)); + else if (rc) + vma_add_reservation(h, vma, address); + } tlb_remove_page_size(tlb, page, huge_page_size(h)); /*