From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F7B724886E for ; Fri, 15 May 2026 02:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778810532; cv=none; b=Jg+pFe+q/wmez0EKXZoYiSwteNfPxO4eCVKgEEPgMD3cNP4AkkJyroh4X0tpJKNuf+nPLmPKY56B6gzft6iIGWSaYQHPHRlYVVsqxIcGo2mS1PLASkmWmM9iDIBgj66WjJDD6nY8D5gvXQ+rCgmy+xUL4RWTBD3aps4L5gvSq0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778810532; c=relaxed/simple; bh=HwenIpwY7g+af9YwOAoBziHAOwggx3nZ2rvt4cyQ9EU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AVM0tCLvSQzteuOSyuqk0ds50GKKfGc8CHvkkVpR1UH4qW8Q7gKcmMh8HZl7QzSc4K/QQrebZTUsw8a8bwkAFKCO3XzkV5R4t2fXUpioAKF+rENLaV+V1UygpNzV80F7tEoyh2My5ruECYB7toXTnFTUVzbVL2Oj1EisAxTgD0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wbo7kjAx; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wbo7kjAx" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778810528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zNLJeNO+f9Rrpgd0tK7WrJ+7+se5J9d6U+663BWu6VQ=; b=wbo7kjAx4is6sAv32uJCEZiELl0HzcsiV5DpyE4Xh6uljQGHC40z95AJbrADDKMuVrtw1m P3+UJTIPgqVAvL9v8sMt/9uAtj4rJO82L40shz9VpJL64REfTFca2rQly8rYlfkSMoBlCS /anMXij7UWvE1Wc4esa6L//Lm0mO+nA= From: Ye Liu To: Miaohe Lin , Andrew Morton Cc: Ye Liu , Oscar Salvador , Naoya Horiguchi , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/memory-failure: remove hugetlb output parameter from try_memory_failure_hugetlb() Date: Fri, 15 May 2026 10:01:43 +0800 Message-ID: <20260515020144.164941-1-ye.liu@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Ye Liu Use -ENOENT return value to distinguish "not a hugetlb page" from "hugetlb handled", instead of carrying an extra output parameter. Suggested-by: Oscar Salvador Signed-off-by: Ye Liu --- Changes in v2: - Remove the 'hugetlb' output parameter from try_memory_failure_hugetlb() as suggested by Oscar Salvador. - Return -ENOENT for MF_HUGETLB_NON_HUGEPAGE case to let caller fall back to normal page handling. - Update memory_failure() to check res != -ENOENT instead of using a separate boolean variable. - Link: https://lore.kernel.org/all/20260513024853.65566-1-ye.liu@linux.dev/ mm/memory-failure.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 866c4428ac7e..e7cf952221df 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2026,13 +2026,14 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags, * So some of prechecks for hwpoison (pinning, and testing/setting * PageHWPoison) should be done in single hugetlb_lock range. * Returns: - * 0 - not hugetlb, or recovered + * 0 - recovered + * -ENOENT - no hugetlb page * -EBUSY - not recovered * -EOPNOTSUPP - hwpoison_filter'ed * -EHWPOISON - folio or exact page already poisoned * -EFAULT - kill_accessing_process finds current->mm null */ -static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb) +static int try_memory_failure_hugetlb(unsigned long pfn, int flags) { int res, rv; struct page *p = pfn_to_page(pfn); @@ -2040,13 +2041,11 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb unsigned long page_flags; bool migratable_cleared = false; - *hugetlb = 1; retry: res = get_huge_page_for_hwpoison(pfn, flags, &migratable_cleared); switch (res) { case MF_HUGETLB_NON_HUGEPAGE: /* fallback to normal page handling */ - *hugetlb = 0; - return 0; + return -ENOENT; case MF_HUGETLB_RETRY: if (!(flags & MF_NO_RETRY)) { flags |= MF_NO_RETRY; @@ -2107,9 +2106,9 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb } #else -static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb) +static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags) { - return 0; + return -ENOENT; } static inline unsigned long folio_free_raw_hwp(struct folio *folio, bool flag) @@ -2347,7 +2346,6 @@ int memory_failure(unsigned long pfn, int flags) int res = 0; unsigned long page_flags; bool retry = true; - int hugetlb = 0; if (!sysctl_memory_failure_recovery) panic("Memory failure on page %lx", pfn); @@ -2386,8 +2384,11 @@ int memory_failure(unsigned long pfn, int flags) } try_again: - res = try_memory_failure_hugetlb(pfn, flags, &hugetlb); - if (hugetlb) + res = try_memory_failure_hugetlb(pfn, flags); + /* + * -ENOENT means the page we found is not hugetlb, so proceed with normal page handling + */ + if (res != -ENOENT) goto unlock_mutex; if (TestSetPageHWPoison(p)) { -- 2.43.0