From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (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 429D82F5485 for ; Wed, 13 May 2026 00:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778633813; cv=none; b=ACBMv3H3F59vfESUgxoPc9dUpaYQlYjv5XDmHkAzVro52grumoDAdDLHIla/qDQNpjSfYoh3TsZ4UtCQWzNJDoTDBv/oZAFmVJHc7JItOLTzrzUsPsEdHlOCDQBxXYHalHoc4EwF6B5h2m+tOI5B4QFZrVbq/IJKiSKaOAPdSis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778633813; c=relaxed/simple; bh=knSt5JAG5pRYYH9+21VL0SsN2sOVaaBqx+McVeuQeRE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XZNt1rpRdh9doi9MIxg1+W7x52WOo+2111scUev01JZiOZkQ5jgY2F1crd7QG8eho5LnG1aYRUfXk0ZfDLtPTQ9+KTRBpTWo/UaY1JKmmvm8Wgju8L1eWp/P2DblST0cQJBQ1yTItZ4u5sn9BIo+LZjbXYc1OQzvlx1qjr2I5e8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=omqfniWS; arc=none smtp.client-ip=115.124.30.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="omqfniWS" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1778633803; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=mM0vO/AvK2Bp1hK4zVKQ38RPnN+CVga1M/wtwQNY/64=; b=omqfniWS/xg/KkVZSr4XyUrQytAk7jD8JLI+EuqD4qWtwbckB+njzUNBIPppP9ktulU89biRT5K2WduUVzFazISh9HD6NLTiKzYiNjt9QybJsJEVm/ypN/2XEqA1D1YaMoM3opQsWnGdhrFp8iO02p+yUgo7zA1VdcSCxikl/X8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0X2rsF.1_1778633801; Received: from 30.74.144.119(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X2rsF.1_1778633801 cluster:ay36) by smtp.aliyun-inc.com; Wed, 13 May 2026 08:56:41 +0800 Message-ID: Date: Wed, 13 May 2026 08:56:40 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] mm/khugepaged: fix inconsistent MMF_VM_HUGEPAGE flag due to allocation failure order To: Ye Liu , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Xin Hao Cc: Ye Liu , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260511025408.54035-1-ye.liu@linux.dev> From: Baolin Wang In-Reply-To: <20260511025408.54035-1-ye.liu@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/11/26 10:54 AM, Ye Liu wrote: > From: Ye Liu > > __khugepaged_enter() sets MMF_VM_HUGEPAGE before allocating the > corresponding mm_slot. If mm_slot_alloc() fails, the function > returns with the flag set but without inserting the mm into the > khugepaged tracking structures, leaving the mm in an inconsistent > state where future registration attempts are skipped. > > Fix this by reordering: allocate the mm_slot first, then check and > set the flag. If the flag is already set, free the allocated slot > and return. This ensures the flag is only set when the mm is > successfully registered in the khugepaged tracking structures. > > Fixes: 16618670276a ("mm: khugepaged: avoid pointless allocation for "struct mm_slot"") > Suggested-by: David Hildenbrand > Signed-off-by: Ye Liu > --- LGTM. Reviewed-by: Baolin Wang