From patchwork Fri Aug 2 06:13:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geetika X-Patchwork-Id: 1968163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=sn9DVHT1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZwX41spyz1yZl for ; Fri, 2 Aug 2024 16:14:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E95443D1F47 for ; Fri, 2 Aug 2024 08:14:08 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it 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 283993D1F41 for ; Fri, 2 Aug 2024 08:13:59 +0200 (CEST) Authentication-Results: in-4.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=geetika@linux.ibm.com; receiver=lists.linux.it) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 64BE61000D3D for ; Fri, 2 Aug 2024 08:13:57 +0200 (CEST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 472604kh015897 for ; Fri, 2 Aug 2024 06:13:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:content-type :content-transfer-encoding:mime-version; s=pp1; bh=mWm4QPRjvA2LW 6mJvSQedp3yE9s5I9Rs9pXG+7cc2O0=; b=sn9DVHT1Sd81Wa/RRn8EyTWdcdbAZ i86e3d8LWl3fV0u+54Zvop+gYRDJA6Ti6JajGs5MO7a4DMS/OJPele6UscB0bd4P 7lS1Bib4tAHIDJEXbgZ2pAYxBprc9vud41YqvbL1qZh7MkwKQZIzUVgJOY65VG7K c4U5ofCn+FkwQjZJiNtOPjBxEE0jDcp1KbeZmrDddUIp5VLgupfiaSdXthPQSFm2 /w9CuXiIbg+TFcb3rU9oKchNAFBTlOxLh1O9Y+ywjCxjD7bQrLIyaiJkIYnXH4mX 4/2MAXUOcahJc1gV8Fr9XvPsC2wtCjQHqkRg6qUeB+2LdiQNo9kQPZ9eg== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40rssc00wy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2024 06:13:55 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4722UKwl011129 for ; Fri, 2 Aug 2024 06:13:54 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 40ncqn5qhe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 02 Aug 2024 06:13:54 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4726DmfJ34865914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2024 06:13:50 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87443201BA; Fri, 2 Aug 2024 06:13:48 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 75A7920138; Fri, 2 Aug 2024 06:13:47 +0000 (GMT) Received: from localhost.localdomain (unknown [9.43.22.205]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTPS; Fri, 2 Aug 2024 06:13:47 +0000 (GMT) From: Geetika To: ltp@lists.linux.it Date: Fri, 2 Aug 2024 11:43:42 +0530 Message-Id: <20240802061342.8540-1-geetika@linux.ibm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: cnGFE7G1JRm065kE_z8CGZcyBymY6gS- X-Proofpoint-GUID: cnGFE7G1JRm065kE_z8CGZcyBymY6gS- X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-02_02,2024-08-01_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 impostorscore=0 clxscore=1015 bulkscore=0 mlxlogscore=756 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408020039 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-4.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3] Hugetlb: Migrating libhugetlbfs test truncate_reserve_wraparound.c 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: donettom@linux.ibm.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Test Description: Test to verify the Hugepages_Rsvd before and after mmap, truncate and sigbus operations. At one stage, improper handling of tests against i_size could mess up accounting of reserved hugepages on certain truncate operations. Tested and verified that test passes for iterations: i2, i5 and i10 Signed-off-by: Geetika --- Changes in v3: - Fixed the indentation - Corrected all the tst_res() format string --- Changes in v2: - Modified the Description section of test - Removed definition of unsued RANDOM_CONSTANT - Fixed warning: unused parameter ‘signum’ [-Wunused-parameter] - Fixed warning: unused parameter ‘si’ [-Wunused-parameter] - Fixed warning: unused parameter ‘uc’ [-Wunused-parameter] --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap38.c | 122 ++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap38.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 299c07ac9..2ffd35aec 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -35,6 +35,7 @@ hugemmap29 hugemmap29 hugemmap30 hugemmap30 hugemmap31 hugemmap31 hugemmap32 hugemmap32 +hugemmap38 hugemmap38 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 c96fe8bfc..dd0c59e98 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -34,6 +34,7 @@ /hugetlb/hugemmap/hugemmap30 /hugetlb/hugemmap/hugemmap31 /hugetlb/hugemmap/hugemmap32 +/hugetlb/hugemmap/hugemmap38 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap38.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap38.c new file mode 100644 index 000000000..20845b946 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap38.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + */ + +/*\ + *[Descripiton] + * + * Origin: https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/truncate_reserve_wraparound.c + * + * At one stage, improper handling of tests against i_size could mess + * up accounting of reserved hugepages on certain truncate + * operations. + * + */ + +#include +#include +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" + +static long hpage_size; +static int fd = -1; +static int sigbus_count; +static unsigned long initial_rsvd, after_map_rsvd, after_touch_rsvd; +static unsigned long after_trunc_rsvd, after_unmap_rsvd, after_sigbus_rsvd; +static volatile unsigned int *q; + +static sigjmp_buf sig_escape; + +static void sigbus_handler(int signum LTP_ATTRIBUTE_UNUSED, siginfo_t *si LTP_ATTRIBUTE_UNUSED, void *uc LTP_ATTRIBUTE_UNUSED) +{ + siglongjmp(sig_escape, 17); +} + +static void run_test(void) +{ + void *p; + struct sigaction sa = { + .sa_sigaction = sigbus_handler, + .sa_flags = SA_SIGINFO, + }; + + sigbus_count = 0; + + initial_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd); + + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, + fd, 0); + q = p; + + after_map_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after map: %lu", after_map_rsvd); + + *q = 0; + after_touch_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after touch: %lu", after_touch_rsvd); + + SAFE_FTRUNCATE(fd, 0); + after_trunc_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after truncate: %lu", after_trunc_rsvd); + + if (after_trunc_rsvd != initial_rsvd) { + tst_res(TFAIL, "Reserved count is not restored after truncate: %lu instead of %lu", after_trunc_rsvd, initial_rsvd); + goto windup; + } + + SAFE_SIGACTION(SIGBUS, &sa, NULL); + if (sigsetjmp(sig_escape, 1) == 0) + *q; /* Fault, triggering a SIGBUS */ + else + sigbus_count++; + + if (sigbus_count != 1) { + tst_res(TFAIL, "Didn't SIGBUS after truncate"); + goto windup; + } + + after_sigbus_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after sigbus: %lu", after_sigbus_rsvd); + + if (after_trunc_rsvd != initial_rsvd) { + tst_res(TFAIL, "Reserved count is altered by SIGBUS fault: %lu instead of %lu", after_sigbus_rsvd, initial_rsvd); + goto windup; + } + + tst_res(TPASS, "Test passed!"); + +windup: + SAFE_MUNMAP(p, hpage_size); + after_unmap_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after munmap: %lu", after_unmap_rsvd); + +} + +static void setup(void) +{ + hpage_size = tst_get_hugepage_size(); + fd = tst_creat_unlinked(MNTPOINT, 0); +} + +static void cleanup(void) +{ + if (fd >= 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag[]) { + {"linux-git", "ebed4bfc8da8"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .hugepages = {4, TST_NEEDS}, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, +};