From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83A0F449996 for ; Thu, 9 Jul 2026 18:58:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783623507; cv=none; b=qJy+wIwXGc771aGcxrYUahlm2CdgejAQNB8SRRQ2QdLXECz/be943Eqlut6vbMnPn+OoB8IoyeD7xmGOr36F7KOoBaQvfzHoo5ccUamOTQd7a411DUjIAXKROH2RuNPRv7a7BJ9aGBtt+4ua1iuR+cFN2eTsqzp/BLVcTlYReqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783623507; c=relaxed/simple; bh=l0bfIeSSjXxqCjA6gzU+5J92YPTfUTFH8DW2JDXuTrM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D+9BLrAEBdSQFYLAMLfolIqGEZ+E9heIIOe8/DUYCkUsV2NVxwfqfntKyRui7FlqABtt35Dgm2AhtilG8w9r9gQJ2CjEKyUNDindgVSftGn2ioOGk6ALIgD/7urjprd/bJFonKcx8OE1OXW2TvC1XYYIT/7kY1xssKUEjGNXg9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gPJKT1FB; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gPJKT1FB" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-7eb42a2f5feso103710a34.1 for ; Thu, 09 Jul 2026 11:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783623503; x=1784228303; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=v7H//saN3HUHN+i+S3SULFCinOHrdn1xh7S62KvKH1s=; b=gPJKT1FBKGhk7Nz4CN/yhEKcZxhSyjs1IwoRRoVjnTQ8C0NTEzEBPyD72hfI2eZyme LPqf7r0h/L9dfIvW90baZadsEMnloGaCF3UfUkGjegQlv/7XmB056dPDTeRLdNiwFpzl CcdzKGeSmF+pv3qLybCOerGnmIp63ZdLMTPcPg0Up/egvKIWEhbtX7VBTbqC6Jye3kQr Lt2a32nZBYLaloshw+puZPgtCAmT8FFeoXA54XOtwHEQmAlkyNiM4GYQF8CW5A6U5hru MQXXSgm8VaBNMen0bzAyxSN7Seqw6YJ3YKOm23kJVHW1pv8M3HPwXyvbxXZk8OGapbhE qPKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783623503; x=1784228303; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=v7H//saN3HUHN+i+S3SULFCinOHrdn1xh7S62KvKH1s=; b=I9weB+y13MQi4OTlUpXHnFB0c/EkZm9vEA4XzBFYuWbBYwhleAyUXiudNkfpJHUrz0 w/eURHa0Ksth6DdoV2uyIOp3thK6xu5Hhi2rO6IZnWYR0CKk+PLRF7od/BeTLDRKi4z3 VsTl8qZ9+Qn/dIGWPR0J7rUetgnQdZ+jKEofdkKqmnTiGw5p60YAyOwViLIwZMeDH579 h1Yk/03P2r3sgu7cPy/7OoKPEJ+ZY+o1TjXQABAcCmfNmlZ01lfAwxZUcSJ3BXL867hY 6+oMxb7EIzgem3VaT1NJTIT94HZOyJ9dRDDNY7KmPXUCvH4Vyp7u78I8toBo7DldqLhz Cs7g== X-Forwarded-Encrypted: i=1; AFNElJ+fX/DO+mubCYvFw+i0KUyN7pBKuvkLt6yGMMgyqDnBGvGu+fbcuoG0t/WLp3CPsaQI4W37yRH4lCDQKCc=@vger.kernel.org X-Gm-Message-State: AOJu0YwCxKeAH5i5Yl7eq5t6edVQONe7e6HVmr10jLUBYHIcDx7HakIf /QWAd7E8LDW/BzvnDZgfVrt9BVkqJXUpoqRjEM3yZnRy3aiu3fz+eUTp X-Gm-Gg: AfdE7ckZNGTJbALIuUsr01mIwJ/2uJrYcy3lfMHrd3CojsXbpnhbxs+dnvdXz3b+Q4Z mwjx0KEx3MOpYNbmLQmlTl98fieWsawIfIpqfIs2pBksn/bu0Otmx/h2Zc9XBca3eAeS9GwLRUJ rfBrDQLY9J6NBm9c4n6bKseUl5fncR+pAn5LVieSO5IHufNqD3rrYCyxvtRTyMYtSkQW3AIPe+j KHd26ldlc/a6CI8ALxFECt54ZHoN+C3vBghyAv9wb3J6RSUYYoDJhz76IqFnZqibjgXJulIPbIX D8mi90KjBhGWeIj0H1X39VGbvs4yLRRpVjqOp+Lg7X4tP375R2krRBDbx1AUuXmRbkPn8KEL+x8 BjCZBVaNTZub2Aqe6IihXOWaoO5vzaWfRWl+BOWTt0r1z3HEbexsOqUo+Rcf2/O0JJrYeremCai M7qJHH4sAcLyF4a1/yaBlks685/cu+ZIi+03zliGVOsGk0/1GZxrauMA== X-Received: by 2002:a05:6830:8388:b0:7e6:c9eb:535a with SMTP id 46e09a7af769-7ebcfe5414bmr6526626a34.6.1783623503381; Thu, 09 Jul 2026 11:58:23 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:55::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7ebcae177c5sm4885829a34.5.2026.07.09.11.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 11:58:23 -0700 (PDT) From: Joshua Hahn To: Joshua Hahn Cc: Ackerley Tng via B4 Relay , Muchun Song , Oscar Salvador , David Hildenbrand , Shakeel Butt , Nhat Pham , Andrew Morton , Peter Xu , Wupeng Ma , fvdl@google.com, rientjes@google.com, jthoughton@google.com, vannapurve@google.com, erdemaktas@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ackerley Tng , stable@vger.kernel.org Subject: Re: [PATCH v2 3/5] mm: hugetlb: Fix folio refcount mismatch on memcg charge failure Date: Thu, 9 Jul 2026 11:58:21 -0700 Message-ID: <20260709185821.1893061-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260709185456.1854151-1-joshua.hahnjy@gmail.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Thu, 9 Jul 2026 11:54:55 -0700 Joshua Hahn wrote: > On Wed, 08 Jul 2026 15:12:51 -0700 Ackerley Tng via B4 Relay wrote: > > Hi Ackerley, > > Thanks again for the fix. Thank you also for adding the reproducers, > they made testing this really easy for me! : -D > > > From: Ackerley Tng > > > > When mem_cgroup_charge_hugetlb(folio, gfp) returns -ENOMEM, the folio has > > its refcount set to 1 via folio_ref_unfreeze(folio, 1). > > > > The error path calls free_huge_folio(folio) directly, which expects a > > refcount of 0. Hence, VM_BUG_ON_FOLIO(folio_ref_count(folio), folio) is > > triggered. > > So yeah, I built mm-new (with your hugetlb open code series) and ran > reproducer #3, and got the following output: > > ... > [ 23.855813] Call Trace: > [ 23.855838] > [ 23.855877] hugetlb_alloc_folio+0x190/0x360 > [ 23.855930] alloc_hugetlb_folio+0xf9/0x310 > [ 23.855972] hugetlb_no_page+0x590/0xa00 > [ 23.856016] hugetlb_fault+0x194/0x770 > [ 23.856060] handle_mm_fault+0x29b/0x2c0 > [ 23.856103] do_user_addr_fault+0x208/0x6e0 > [ 23.856146] exc_page_fault+0x67/0x140 > [ 23.856191] asm_exc_page_fault+0x22/0x30 > [ 23.856234] RIP: 0033:0x401734 > ... > > Running it with your fix, I don't get a kernel crash. So this change > looks good to me, please feel free to add: > > Tested-by: Joshua Hahn > Reviewed-by: Joshua Hahn > > But..... > > It seems like fixing this bug actually surfaces a different bug. > I don't see a kernel crash anymore, but my kernel gets stuck in a > different loop: > > ... > [ 42.526726] pagefault_out_of_memory: 120780 callbacks suppressed > [ 42.526732] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > [ 42.526955] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > [ 42.527084] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > [ 42.527192] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > [ 42.527288] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > [ 42.527382] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > [ 42.527476] Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF > ... > > mem_cgroup_charge_hugetlb() fails > --> hugetlb_alloc_folio() returns ERR_PTR(-ENOMEM) > --> propagated to alloc_hugetlb_folio() > --> hugetlb_no_page converts it to vmf_error(PTR_ERROR(folio)) > --> propagates up to the pagefault handler.. > > But there's no OOM handler to resolve, I think. So it just keeps retrying > the fault and cycling over and over and over again... I think we need > to be returning ENOSPC instead of ENOMEM like the other failure paths > in alloc_hugetlb_folio (or hugetlb_alloc_folio... I think we should > change this name, it's a bit confusing). > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 288535838a48b..05214b1cd491a 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2903,7 +2903,7 @@ struct folio *hugetlb_alloc_folio(struct hstate *h, > * were committed to the folio and freeing the folio > * would have cleared those up. > */ > - return ERR_PTR(ret); > + return ERR_PTR(-ENOSPC); > } > > return folio; Ah, immediately as I sent this out and went to 4/5 to review it, I see that this is the exact change you have... oops, please disregard the message : -) I do think we should 3/5 and 4/5 together for bisectability purposes. Thanks again. Sorry for the noise! Joshua