From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 B4369296BD2 for ; Fri, 17 Apr 2026 07:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776410505; cv=none; b=bKs2v5npS1lVF5J14q/EsIenqzSTFHlnmgJW8lh2cDvNtPAIqsEn7HSp0NASX+jf+GfenOXSTrbcftnjk6VITW1nUvMjWNOvhaVw0+W9P2Ujm17X5YWveqr2BHEQvBHew11SMKOIjod56rXRBBs/UcFlnYd6o/scwzBcbiHjXK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776410505; c=relaxed/simple; bh=OP88IxicJt8LfL+wqP/x1rGfulhGdrnO4IzjZLS1pmc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=lhw7iatojO4SuQEo70LcfGNyxvVjYyKO8Q4uSaDX8ihrbOyU4wX+ORmG+FT1VpKhUEukEp9HHH5CcCQBs+gnOn/XHrtSeJOp969T9LaAjcnjUfRgrpMdnLQM6uXFkn3OhLKQKrocGSag6UxbrkL5C1V+02wHZWyTQRjh3063Ris= 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=gZpCuBNf; arc=none smtp.client-ip=115.124.30.100 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="gZpCuBNf" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1776410494; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=93oxKOORlnBXcsnliXcH+HsS5Rt3NUtTsFQEOXV4lUw=; b=gZpCuBNf1cnhjIyGxD0NUfHO9DP7y3nZHXg1cVqNVHA8rj8rpQj7RgfrHCtHhPURft8ioT3FO/2AsQFaUI1Y6wtqkWvmph5aqqr66evEZrzT9FaWUMbXsu/R9K4mDgfho9a9TbI3jSvbNQz83Jg5oAvTX59IyzNh9xlZEVRUdGo= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=ying.huang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0X1AZ8vF_1776410492; Received: from DESKTOP-5N7EMDA(mailfrom:ying.huang@linux.alibaba.com fp:SMTPD_---0X1AZ8vF_1776410492 cluster:ay36) by smtp.aliyun-inc.com; Fri, 17 Apr 2026 15:21:33 +0800 From: "Huang, Ying" To: "David Hildenbrand (Arm)" Cc: Sunny Patel , Andrew Morton , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Alistair Popple , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/migrate_device: Cleanup up PMD Checks and warnings In-Reply-To: (David Hildenbrand's message of "Thu, 16 Apr 2026 21:44:15 +0200") References: <20260414141344.29949-1-nueralspacetech@gmail.com> Date: Fri, 17 Apr 2026 15:21:31 +0800 Message-ID: <87y0imhx1g.fsf@DESKTOP-5N7EMDA> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii "David Hildenbrand (Arm)" writes: > On 4/14/26 16:13, Sunny Patel wrote: >> Remove the odd VM_WARN_ON_FOLIO(!folio, folio) usage and replace it >> with a simpler VM_WARN_ON_ONCE(!folio) check. >> >> Drop the redundant VM_WARN_ON_ONCE(!pmd_none(*pmdp) && >> !is_huge_zero_pmd(*pmdp)). >> >> Refactor the PMD checks to use pmd_present(), making the control flow >> clearer and avoiding duplicate condition checks. >> >> Signed-off-by: Sunny Patel >> --- >> mm/migrate_device.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/mm/migrate_device.c b/mm/migrate_device.c >> index 8079676c8f1f..fe1c1999aa2d 100644 >> --- a/mm/migrate_device.c >> +++ b/mm/migrate_device.c >> @@ -807,8 +807,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, >> bool flush = false; >> unsigned long i; >> >> - VM_WARN_ON_FOLIO(!folio, folio); >> - VM_WARN_ON_ONCE(!pmd_none(*pmdp) && !is_huge_zero_pmd(*pmdp)); >> + VM_WARN_ON_ONCE(!folio); > > I'd test for "page" here instead. But it doesn't matter as of today. > >> >> if (!thp_vma_suitable_order(vma, addr, HPAGE_PMD_ORDER)) >> return -EINVAL; >> @@ -865,12 +864,13 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, >> if (userfaultfd_missing(vma)) >> goto unlock_abort; >> >> - if (!pmd_none(*pmdp)) { >> + if (pmd_present(*pmdp)) { >> if (!is_huge_zero_pmd(*pmdp)) >> goto unlock_abort; >> flush = true; >> - } else if (!pmd_none(*pmdp)) >> + } else if (!pmd_none(*pmdp)) { >> goto unlock_abort; >> + } >> >> add_mm_counter(vma->vm_mm, MM_ANONPAGES, HPAGE_PMD_NR); >> folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE); > > is_huge_zero_pmd() checks pmd_present(), so we didn't have a bug before. > > We could also do: > > if (is_huge_zero_pmd(*pmdp)) { > flush = true; > } else if (!pmd_none(*pmdp)) { > goto unlock_abort; > } I think that this is better. And because the patch is for code cleanup, why not do it better. > But I don't particularly care > > Acked-by: David Hildenbrand (Arm) --- Best Regards, Huang, Ying