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 picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5E6FFED2D3 for ; Thu, 12 Mar 2026 05:56:04 +0000 (UTC) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 81D6E3E1FFA for ; Thu, 12 Mar 2026 06:56:02 +0100 (CET) Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 1EE193D0737 for ; Thu, 12 Mar 2026 06:55:45 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 in-4.smtp.seeweb.it (Postfix) with ESMTPS id 659DB100029D for ; Thu, 12 Mar 2026 06:55:42 +0100 (CET) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62BMWK2A2581582; Thu, 12 Mar 2026 05:55:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=Tejultf9T6J8TS77a7SkP+KctgpFzAS2ATWcx+RM9 /o=; b=FgukDy9QssAnnRMS8vvl9M7P9jcQqDsa1giTXmq5KI//534cuq1/M9rP5 NjeGM2PAKAHRCDeMsxyS10MDP7xQEyWT0I4EZBlnOmvwNeCSkS17u0NOQpCAY+ip VfqfHk0MSPaAe5yCN5HRPJL1pcrB69e6J0tGiivAT8J6SMQB01caZYCAfMReEpZT y5QpjFWUDzJFAfN0QSfLJGLihfTr6VEmDtHcuO30G9vgZY0LcTRQvM5HDRdNgwIU FJCMmDJw7BJeH8Pr0gAa8kHZi4Mzs+wYzZgSgz+EUnOQUl+2brTmvFuZkPdsBQKN UfJDXez1194gG0E6tKtNYRXLf5+FA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4cuh94s789-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Mar 2026 05:55:41 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62C4JKVY008972; Thu, 12 Mar 2026 05:55:39 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4cuha714rf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Mar 2026 05:55:39 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62C5tZJ041222600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Mar 2026 05:55:36 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D67912004D; Thu, 12 Mar 2026 05:55:35 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E29A12004B; Thu, 12 Mar 2026 05:55:34 +0000 (GMT) Received: from li-49acbccc-2994-11b2-a85c-d51b89e344f1.ibm.com.com (unknown [9.124.215.11]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 12 Mar 2026 05:55:34 +0000 (GMT) From: Pavithra To: ltp@lists.linux.it Date: Thu, 12 Mar 2026 11:25:31 +0530 Message-ID: <20260312055531.359885-1-pavrampu@linux.ibm.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=QKtlhwLL c=1 sm=1 tr=0 ts=69b2555d cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=npRE8wLiAAAA:8 a=V7HiF2tqQ_5XaP8Lp5YA:9 a=RAb4T5FLMvhYbp7Aw4eJ:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzEyMDA0MiBTYWx0ZWRfX0RDZQNvYaGS+ eSGNt9aIUHFZ/1hvZCWx6bZv4FdxcDY9gXwdhVgadEgXA72z/nT+K2XMpGlp4+A4Xxh1u4zSIzS 3BMFaPaDVmo1Lzh4f96Qi1/BPVSptQlo3LZwj+2ewet3wSe++T9QkbEEBRGM5xXLp7eywjnXs6F mt62SFsotl1GqPu5lcOagcmIx5bOCZYsk7FVIA6MaVhOTVNhAi5di8HhfH/2uTdTdvuIh9/piHW +8zzc/dSZTg2N3SU4Ta5v7IPr6dBtlizB6kSnsskR5YX00R9dWTQcC4xIF2KfhaslWRtIp2EIyF hVeA/IlSgeYeXhcQGozUz4Sof43wt/S6XVNCZlyipPqTtaqe5M7S751blCwooXUq5/HXZl9BOj0 nD3aNFg4Mk5KcWOiZfaHzh5utKS2kUHfoZJZ0utWjG79LUvLVvoHFQZR66WaHLjFu9H+bvJpmfm vSXYOj7ZEXrMCxTD3tA== X-Proofpoint-ORIG-GUID: Pi-FzC8V3_7Ruc4Q4GORGn1Vjv5dL0q4 X-Proofpoint-GUID: Pi-FzC8V3_7Ruc4Q4GORGn1Vjv5dL0q4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-11_02,2026-03-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 adultscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603120042 X-Virus-Scanned: clamav-milter 1.0.9 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] [PATCH v5] Migrating the libhugetlbfs/testcases/truncate_above_4GB.c test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pavrampu@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" Changes in v5: - Modified code to use FOURGIG instead of truncate_point. Signed-off-by: Pavithra --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap36.c | 150 ++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap36.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 0896d3c94..bd40a7a30 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -36,6 +36,7 @@ hugemmap30 hugemmap30 hugemmap31 hugemmap31 hugemmap32 hugemmap32 hugemmap34 hugemmap34 +hugemmap36 hugemmap36 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index b4455de51..2ddef6bf1 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -36,6 +36,7 @@ /hugetlb/hugemmap/hugemmap31 /hugetlb/hugemmap/hugemmap32 /hugetlb/hugemmap/hugemmap34 +/hugetlb/hugemmap/hugemmap36 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap36.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap36.c new file mode 100644 index 000000000..68ad2dcd0 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap36.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + * Copyright (C) 2006 Hugh Dickins + */ + +/*\ + *[Descripiton] + * + * At one stage, a misconversion of hugetlb_vmtruncate_list to a + * prio_tree meant that on 32-bit machines, truncates at or above 4GB + * could truncate lower pages, resulting in BUG_ON()s. + * + * WARNING: The offsets and addresses used within are specifically + * calculated to trigger the bug as it existed. Don't mess with them + * unless you *really* know what you're doing. + * + */ + +#define _GNU_SOURCE +#define _LARGEFILE64_SOURCE +#define FOURGIG ((off64_t)0x100000000ULL) +#define MNTPOINT "hugetlbfs/" + +#include +#include +#include "hugetlb.h" + +static int page_size; +static long hpage_size; +static int fd = -1; +static volatile int test_pass; +static sigjmp_buf sig_escape; + +static void sigbus_handler_fail(int signum, siginfo_t *si, void *uc) +{ + siglongjmp(sig_escape, 17); +} + +static void sigbus_handler_pass(int signum, siginfo_t *si, void *uc) +{ + test_pass = 1; + siglongjmp(sig_escape, 17); +} + +static void run_test(void) +{ + static long long buggy_offset; + void *p, *q; + volatile unsigned int *pi, *qi; + + struct sigaction sa_pass = { + .sa_sigaction = sigbus_handler_pass, + .sa_flags = SA_SIGINFO, + }; + + struct sigaction sa_fail = { + .sa_sigaction = sigbus_handler_fail, + .sa_flags = SA_SIGINFO, + }; + + test_pass = 0; + + buggy_offset = FOURGIG / (hpage_size / page_size); + buggy_offset = (long long)PALIGN(buggy_offset, hpage_size); + + /* First get arena of three hpages size, at file offset 4GB */ + q = SAFE_MMAP(NULL, 3*hpage_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fd, FOURGIG); + qi = q; + /* Touch the high page */ + *qi = 0; + + /* This part of the test makes the problem more obvious, but + * is not essential. It can't be done on segmented powerpc, where + * segment restrictions prohibit us from performing such a + * mapping, so skip it there. Similarly, ia64's address space + * restrictions prevent this. + */ +#if (defined(__powerpc__) && defined(PPC_NO_SEGMENTS)) || \ + !defined(__powerpc__) && !defined(__powerpc64__) && \ + !defined(__ia64__) + /* Replace middle hpage by tinypage mapping to trigger + * nr_ptes BUG + */ + p = SAFE_MMAP(q + hpage_size, hpage_size, PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0); + pi = p; + /* Touch one page to allocate its page table */ + *pi = 0; +#endif + + /* Replace top hpage by hpage mapping at confusing file offset */ + p = SAFE_MMAP(q + 2*hpage_size, hpage_size, PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_PRIVATE, fd, buggy_offset); + pi = p; + /* Touch the low page with something non-zero */ + *pi = 1; + + SAFE_FTRUNCATE(fd, FOURGIG); + + SAFE_SIGACTION(SIGBUS, &sa_fail, NULL); + if (sigsetjmp(sig_escape, 1) == 0) + if (*pi != 1) { + tst_res(TFAIL, "Data 1 has changed!"); + goto cleanup; + } + + SAFE_SIGACTION(SIGBUS, &sa_pass, NULL); + if (sigsetjmp(sig_escape, 1) == 0) { + *qi; + tst_res(TFAIL, "Didn't SIGBUS on truncated page."); + } + + if (test_pass) + tst_res(TPASS, "Expected SIGBUS"); + +cleanup: + SAFE_MUNMAP(q, 3*hpage_size); + SAFE_MUNMAP(p, hpage_size); +} + +static void setup(void) +{ + page_size = getpagesize(); + hpage_size = tst_get_hugepage_size(); + fd = tst_creat_unlinked(MNTPOINT, 0, 0600); + if (hpage_size > FOURGIG) + tst_brk(TCONF, "Huge page size is too large!"); +} + +static void cleanup(void) +{ + if (fd >= 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag[]) { + {"linux-git", "856fc2950555"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .hugepages = {4, TST_NEEDS}, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, +}; -- 2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp