From nobody Fri Oct 3 11:22:29 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 EE854322743 for ; Tue, 2 Sep 2025 16:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756830350; cv=none; b=cV1ME7snFfRvAYdJGe2is6ca+XujBni0hM0fuGkAIpG89hmcTdtUDx0eEfBZnpkVbHaCSx/Ms0vmw6/wY8PQg870A1o/7V1/E/QTgTQQ/9KDr7Ym5/wjzg2KlLFySGq7q4OOBVrGFoeyct88KBwEwVTUiBPWj9Dz0ZJp0fUFJPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756830350; c=relaxed/simple; bh=ASh/x9X/3Itsj4Qm1O67fkentIoPBZyLTFXa8/VaSzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sW7WvA7PkWPNZnZaNOiKhvf51IW82lCqv+U+2QaNkjTmd2JfGkhwOCPwLCR59oAJWPMAI5BRXwDn94slSy4omUN10d7ah5KC5TiI0UPnw+sh9ZVv0sFWjQD9YAtGjEGMtb1RfDUm45Guewsu4Rd7QlqXoD2VruzZIPXubJJjOOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GdeUAVBj; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GdeUAVBj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756830347; 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: in-reply-to:in-reply-to:references:references; bh=fGt+rfAZPqOpC/usLmyRdPXY0e3SkpciH6+5LLOoAzw=; b=GdeUAVBjl8Ug8XnFKEuz5Zr+tF7n6A37q21Qg5blB099uX9wDEEaPCjksmvOkbdHjBspUU vvQx0LbveEwRfSrLDaakvi3zauB9Z+EBrnYVgzeye0anZCox1CUPqZhfRCKNGMHurmk2GR kONsnc4UaOsTBJYaiXi4pKSDlvW0MN4= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-bSUXBqyPNWqsMD_lkbXvuA-1; Tue, 02 Sep 2025 12:25:46 -0400 X-MC-Unique: bSUXBqyPNWqsMD_lkbXvuA-1 X-Mimecast-MFC-AGG-ID: bSUXBqyPNWqsMD_lkbXvuA_1756830345 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 983FE19560AD; Tue, 2 Sep 2025 16:25:45 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.80.27]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D482230001A7; Tue, 2 Sep 2025 16:25:43 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand Subject: [PATCH v2 1/2] selftests/mm: split_huge_page_test: fix occasional is_backed_by_folio() wrong results Date: Tue, 2 Sep 2025 18:25:35 +0200 Message-ID: <20250902162536.956465-2-david@redhat.com> In-Reply-To: <20250902162536.956465-1-david@redhat.com> References: <20250902162536.956465-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" When checking for actual tail or head pages of a folio, we must make sure that the KPF_COMPOUND_HEAD/KPF_COMPOUND_TAIL flag is paired with KPF_THP. For example, if we have another large folio after our large folio in physical memory, our "pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL" would trigger even though it's actually a head page of the next folio. If is_backed_by_folio() returns a wrong result, split_pte_mapped_thp() can fail with "Some THPs are missing during mremap". Fix it by checking for head/tail pages of folios properly. Add folio_tail_flags/folio_head_flags to improve readability and use these masks also when just testing for any compound page. Fixes: 169b456b0162 ("selftests/mm: reimplement is_backed_by_thp() with mor= e precise check") Signed-off-by: David Hildenbrand Reviewed-by: Wei Yang --- tools/testing/selftests/mm/split_huge_page_test.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index 10ae65ea032f6..72d6d8bb329ed 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -44,6 +44,8 @@ int kpageflags_fd; static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd, int kpageflags_fd) { + const uint64_t folio_head_flags =3D KPF_THP | KPF_COMPOUND_HEAD; + const uint64_t folio_tail_flags =3D KPF_THP | KPF_COMPOUND_TAIL; const unsigned long nr_pages =3D 1UL << order; unsigned long pfn_head; uint64_t pfn_flags; @@ -61,7 +63,7 @@ static bool is_backed_by_folio(char *vaddr, int order, in= t pagemap_fd, =20 /* check for order-0 pages */ if (!order) { - if (pfn_flags & (KPF_THP | KPF_COMPOUND_HEAD | KPF_COMPOUND_TAIL)) + if (pfn_flags & (folio_head_flags | folio_tail_flags)) return false; return true; } @@ -76,14 +78,14 @@ static bool is_backed_by_folio(char *vaddr, int order, = int pagemap_fd, goto fail; =20 /* head PFN has no compound_head flag set */ - if (!(pfn_flags & (KPF_THP | KPF_COMPOUND_HEAD))) + if ((pfn_flags & folio_head_flags) !=3D folio_head_flags) return false; =20 /* check all tail PFN flags */ for (i =3D 1; i < nr_pages; i++) { if (pageflags_get(pfn_head + i, kpageflags_fd, &pfn_flags)) goto fail; - if (!(pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL))) + if ((pfn_flags & folio_tail_flags) !=3D folio_tail_flags) return false; } =20 @@ -94,11 +96,8 @@ static bool is_backed_by_folio(char *vaddr, int order, i= nt pagemap_fd, if (pageflags_get(pfn_head + nr_pages, kpageflags_fd, &pfn_flags)) return true; =20 - /* this folio is bigger than the given order */ - if (pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL)) - return false; - - return true; + /* If we find another tail page, then the folio is larger. */ + return (pfn_flags & folio_tail_flags) !=3D folio_tail_flags; fail: ksft_exit_fail_msg("Failed to get folio info\n"); return false; --=20 2.50.1