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: 13523775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD41AC4725D for ; Fri, 19 Jan 2024 13:14:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51A7B6B0085; Fri, 19 Jan 2024 08:14:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CA916B0087; Fri, 19 Jan 2024 08:14:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3922C6B0088; Fri, 19 Jan 2024 08:14:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 29B996B0085 for ; Fri, 19 Jan 2024 08:14:44 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9B1B01C17EC for ; Fri, 19 Jan 2024 13:14:43 +0000 (UTC) X-FDA: 81696105246.21.9332D20 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id EC8D080005 for ; Fri, 19 Jan 2024 13:14:41 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vl60JGDM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705670082; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=FMCcNkW+birNtx8xk197SfIjTJCrWWEkNPF60sBeOCI=; b=uFZEISls2OauJRrOlisMtKfnLdqWxn9TqqMBhws2C5qjBwFa6oNtdyBb+h9ioqEOP8lg52 TaovqB3o4A/4aEF5BTE6CCDZl88UZvqIIQRJ6NMuBWq9wjOZHbGSluzJCV90Otd4Jp6i2e 5J1F92tuGcxC776534zNNpLjfNnJLno= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vl60JGDM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705670082; a=rsa-sha256; cv=none; b=iK5a2zmcrwmrLZa1Ra5PUZzPF47pP4DcNehw6CexdtOiaphLT79X48Fyx91gvT4f69stxO hxEVchCT8ReOVt1qjR6kKp2MYBQRh5fNLLFgum+AsS8PiybbXXSYL00kSUI1vPCP8cq5WI hCyykIR3JYw4KMA9M9G8EepaXL96/rY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705670081; 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=Vl60JGDMGhbFTpd58adC0Ndg/Ps1WwlD0d9RYiquykgJzgARSAkUTVsbeqvP8jl/3apt4f y/6g9hzYs3/7uCw0VhMlcd1Ytdme8E6ttb0GwJV8CpVyKHIla+hCSlwSqmoNanOaja1iTL p51B0c2nw8LPgBzG/uuJ64LpXodbQ9g= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Queue-Id: EC8D080005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: m43cdoxskroehddgp7hzaqkmfooftzdj X-HE-Tag: 1705670081-287471 X-HE-Meta: U2FsdGVkX1/RtOJ6LvroXS7NISIwggoeoxlzPJPsLKYxEwhz1oIyNa8lu5Ow7tmYbxfgpjpO+yPGwsz/vhJfoE/fZv/jXzhmrMjiHgdXXvK3Ylto5qNFT5ImsLsabv1gc73i7+ScEcTcNfVNfkQMjL2fo/1I7+SgKtXGy43v5Qtg62OI84+O4dyxxP1by6l3m7N1pKqBqGJm8ChoMJlryxv6EVHN1KNUoS7JEYUsSWqQYwMVZbD0RjW1Fp8C4joK6uErlz+K5+t4bQXviNPASTCrT+Xemya94eq4jzZqQEMLadj9HsqcNSFJXZFy3IwdtN56i+1IJjvl4LcMr8dmngnoJFzzewLak6AZqC3oaWzvC6tHlvyLFWiIZi5zMd9JaY5cz4xGLAPhXLNfNz1KBAC0XnBJbJz4vePpvRfWgl/PIfBMoCl97VMNo/NahWNW6G4aP8RvVUoXXTc4sdxVY5rbD1bTFcER/gBeMLJhabOYwGqWZdh7BMC9H3j45XGG4UV6+9MPSAZW2edBNZnTMFfD8Ru3HeuddRsjra5GtMxWOnHbWuH3ubH61kpmbPIVHCqy8Fc2HURIm5cLWALWCl1bSEjCHyY5ZVrNZvOHXu9KYHLfNBgdOKu8HCiURooY5Cjv/uM4g9sZqA+VESSy00lwwwCdaBYlYh/OtLMzIjvmCYO9hUYtOLAgC9ODt9yDFlQL/Z8xpkJdB2HV4+kimgm25h6tSD3dqZifWrxksA2U8+X4LHv6uxUNoNCzWGwVZwwtkohBLSEwUZi/kUDAmcPKVsw9lTmQRaMS23cysPxyLrZH/Z31LTqY74vSEFRs5r6TgylBiW6DipNRGuCdlngiznvKgZuIlktdlepTqWUzj1nDPub6vaBE3ZFGm3ku05JBt5sRgf3Y6NbdmICseOxNlw4I3esfXMTmprI7jHm3SNAMlDx6tkfH671aUiIqB8lqZyjM+OWi8PZPHVN lAsjYxWW mYMS+hZ1gAnWSxmiirebOZo4SF11dorzYZfMywIGfAVR64oCq/qrkH+75ParwzkyRNhriphziBZHt2C97aEcBs4ARCvCIolue3/rB7ortwM6lcVgs6Zb2Cz5w0qzNEiHU7r1RMr09qRcAKdchjLo+1GhAPoFVhucPkezn8BGDv5v/EdeGuBwHeV1QGI60qI0LLhWFUndYFLkCTFR4nLWfGOwHgQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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) {