From patchwork Fri Jan 19 13:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 189553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp997709dyb; Fri, 19 Jan 2024 05:15:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuN9Rvr4u4imRSBwuDlsHf1GwFurwsUbPCFDEoqB5fHXC8ajeDNLQ/Ih10CW8VysPmMVAk X-Received: by 2002:a17:90b:19cf:b0:28e:7b6b:5d0 with SMTP id nm15-20020a17090b19cf00b0028e7b6b05d0mr1900838pjb.67.1705670115759; Fri, 19 Jan 2024 05:15:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705670115; cv=pass; d=google.com; s=arc-20160816; b=LPz/fnCfDQdgLTbbJC/8thcjwuRtrFehvyWkNuqnOZsEJxEExAcjbIGRyqXoFlx0Ko lQhJjallMFm9j//RquLOjrkTd1SSWP0oUJGyrgUB7sxlp7hK2s40mKJj/KshuoI0Y6P+ Wls8y8HRAGqb1gRAgNOL9CU4nkuhCF3N/mCvBXwemvRSP+vhtu+rP3fsBbJsL3ikHMeD 6gxVZusKxGD52Yqpvz02rVX/YKue7fKj9UqtqsBjDk9owVyfEkcaMDOUx02hKKeZWTvd /usKAIN4db8neaJshfLc7ZKNJ6qyofuFsx+h2UprQNVw1FN8zZnp5XokzMuMrUA27CaY U3Cg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=FMCcNkW+birNtx8xk197SfIjTJCrWWEkNPF60sBeOCI=; fh=ZPY9JeJLmTgS9LZKdhZ5ggio5HJ93IiZ6ENH9S+9zM0=; b=kD3jrzWt7u5JyrsQiK30Cmo5ZYam5xLUpKrNlhFDX5yWaL7xlfFIojlw/i28nAGimu hiR5bhfXKaNtLnLlotad7U9xcXqkArmdKNvgNadbHvWRmvvLZr3MzfGAuTzgF5VQHiLc WGIf1ixB/Nik3tmlqsu/+WClt5YuWufXES1qbRfdS4WJzjGcDkf3jHm4kt8hO5O9y5l4 ZNIeUgyKlM/nYYxp0VCO4D/CJPvAU8w6RJBuhHBVZ5HujtcwGnpq2Q+MNd/ia+2vN6jB Zy+nh2qLLRynGW7mBqmFCYQIakCsbd3UpNPwu1NlyWsj60i7aofm6YBTH4UE70XpV/VN bj8A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dSN1zpzZ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-31177-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31177-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h3-20020a17090acf0300b00290212b4c4dsi2987337pju.150.2024.01.19.05.15.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 05:15:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31177-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dSN1zpzZ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-31177-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31177-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 13BFFB22C67 for ; Fri, 19 Jan 2024 13:15:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A2C2537E1; Fri, 19 Jan 2024 13:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dSN1zpzZ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B28594F1FA for ; Fri, 19 Jan 2024 13:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670085; cv=none; b=KheXgn1MiYSZW1iGrUSfna+lNgIuEvQc4LfFl8s8J4xvFFr3PG1QXRbDudq/aaa2ugux2iXb7luVYTO9JIQb4zARn3PnsKETUEk7o0XzpziUPZittJgODDZStIdZtRBl0wjtmk9JU217NlgDqojzXeiIWMTl8Fn18qSEGgBbNXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670085; c=relaxed/simple; bh=Yd8Hfv3YoXkOkWdBGQbqAsfi6VWsPeqx8i7E6nlEngk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HvJtvAD/7Kw//kAoST7yrNWZJvZobviarKK0Xm6vXOdDN6IXZn/V50U6vigd65IpebptfMGJ1zQc1wDnjcMQvrQ9HK4qfCR1wxRh0FAuOHMLovlOTWbPEjOB+eFvqkpHSmRpQgYxuIbiK/Uug7RmhPFR/zEWpxAlApS2ThdL/og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=dSN1zpzZ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705670082; 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=FMCcNkW+birNtx8xk197SfIjTJCrWWEkNPF60sBeOCI=; b=dSN1zpzZtzCKSrtGs9JnvjylOLcsMpVeCS7xMCJn8VteixadiV66E25Q9YpufTBx72zwdh drGxPyQ2fFiuRvOJIa1IM6Ei5B6kOgYj5kTNaV/e0QoGcz0XkfbvsBzy3EK/NVKP0mbXO1 VRSV7dl+k+gq8KGOz+i3GM86y1RUuuU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217--TNxNdLxPgGuY0vHTURHIQ-1; Fri, 19 Jan 2024 08:14:39 -0500 X-MC-Unique: -TNxNdLxPgGuY0vHTURHIQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7F93185A788; Fri, 19 Jan 2024 13:14:38 +0000 (UTC) Received: from localhost.redhat.com (unknown [10.22.32.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6286C51D5; Fri, 19 Jan 2024 13:14:38 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org, shuah@kernel.org, donettom@linux.vnet.ibm.com Subject: [PATCH v2] selftests: mm: fix map_hugetlb failure on 64K page size systems Date: Fri, 19 Jan 2024 06:14:29 -0700 Message-ID: <20240119131429.172448-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788523764300505483 X-GMAIL-MSGID: 1788524746898471152 On systems with 64k page size and 512M huge page sizes, the allocation and test succeeds but errors out at the munmap. As the comment states, munmap will failure if its not HUGEPAGE aligned. This is due to the length of the mapping being 1/2 the size of the hugepage causing the munmap to not be hugepage aligned. Fix this by making the mapping length the full hugepage if the hugepage is larger than the length of the mapping. Signed-off-by: Nico Pache --- tools/testing/selftests/mm/map_hugetlb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/mm/map_hugetlb.c b/tools/testing/selftests/mm/map_hugetlb.c index 193281560b61..86e8f2048a40 100644 --- a/tools/testing/selftests/mm/map_hugetlb.c +++ b/tools/testing/selftests/mm/map_hugetlb.c @@ -15,6 +15,7 @@ #include #include #include +#include "vm_util.h" #define LENGTH (256UL*1024*1024) #define PROTECTION (PROT_READ | PROT_WRITE) @@ -58,10 +59,16 @@ int main(int argc, char **argv) { void *addr; int ret; + size_t hugepage_size; size_t length = LENGTH; int flags = FLAGS; int shift = 0; + hugepage_size = default_huge_page_size(); + /* munmap with fail if the length is not page aligned */ + if (hugepage_size > length) + length = hugepage_size; + if (argc > 1) length = atol(argv[1]) << 20; if (argc > 2) {