From patchwork Tue Dec 20 06:31:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=aW2xVgCC; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nbmv60WWPz1ydZ for ; Tue, 20 Dec 2022 17:31:46 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7D81E3CBA68 for ; Tue, 20 Dec 2022 07:31:43 +0100 (CET) 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 [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 55A7E3CBA55 for ; Tue, 20 Dec 2022 07:31:36 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 2066410007B3 for ; Tue, 20 Dec 2022 07:31:34 +0100 (CET) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6PZ9m024362; Tue, 20 Dec 2022 06:31:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=hxGic49S7UHfr5ZpfSoiexBAGJi4QvrlXTB9VO7HOa4=; b=aW2xVgCCkTqv8s35tr4qP5Q3cxpEHOA45bkUwc0HSKAx2rAGqfnx7vBjepJH97FL49Kj 2sKWoolmixTSL/WbjeuFFJPHGU4WhGXcr4Q7RbLcFWdLbOpg3NgX9TNO0Bfwag+8/EQ9 GrDjlNTwdQ89bL7YKPRfM88ozDA5BAHSYy5n6I+xytVhtIkwz5mJPmEV5ivddY2AEvTq XCZTg43ILO0531sjU/fpqYlG/sWaiqUyWX7rEBJSRzoY2CXorWGU3phIghQ0d0L7vKrI pZn2bjx9UwKtwuvnn9zF7AdtfUnhRMMU2RzKOa4WPATiG2XlbCuWrNQX+WI9QY3/Phax 2g== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7s7049m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:32 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJLeTXY015566; Tue, 20 Dec 2022 06:31:30 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3mh6yy2j40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:30 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VQMF23200054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:26 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8A46520040; Tue, 20 Dec 2022 06:31:26 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A9D320043; Tue, 20 Dec 2022 06:31:23 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:22 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:02 +0530 Message-Id: <20221220063109.279007-2-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: CrsUJs1iRvRd3VtOb_p6ANt2MQ5yFx7h X-Proofpoint-ORIG-GUID: CrsUJs1iRvRd3VtOb_p6ANt2MQ5yFx7h X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 malwarescore=0 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200054 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/8] Hugetlb: Migrating libhugetlbfs fork-cow 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/fork-cow.c test Test Description: This checks copy-on-write semantics, specifically the semantics of a MAP_PRIVATE mapping across a fork(). Some versions of the powerpc kernel had a bug in huge_ptep_set_wrprotect() which would fail to flush the hash table after setting the write protect bit in the parent's page tables, thus allowing the parent to pollute the child's mapping. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 2 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/Makefile | 10 ++ .../kernel/mem/hugetlb/hugefork/hugefork01.c | 92 +++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c diff --git a/runtest/hugetlb b/runtest/hugetlb index ec1fc2515..4c16e1e7c 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -1,6 +1,8 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 +hugefork01 hugefork01 + hugemmap01 hugemmap01 hugemmap02 hugemmap02 hugemmap04 hugemmap04 diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index c0906f3d3..adea760c7 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -1,6 +1,7 @@ /cpuset/cpuset01 /hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugefallocate/hugefallocate02 +/hugetlb/hugefork/hugefork01 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04 diff --git a/testcases/kernel/mem/hugetlb/hugefork/Makefile b/testcases/kernel/mem/hugetlb/hugefork/Makefile new file mode 100644 index 000000000..77ebb0aef --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugefork/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Ngie Cooper, July 2009 + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../Makefile.inc +include $(top_srcdir)/include/mk/generic_leaf_target.mk + diff --git a/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c b/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file mode 100644 index 000000000..90cefdba2 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2008 David Gibson, IBM Corporation. + * Author: David Gibson + */ + +/*\ + * [Description] + * + * This checks copy-on-write semantics, specifically the semantics of a + * MAP_PRIVATE mapping across a fork(). Some versions of the powerpc + * kernel had a bug in huge_ptep_set_wrprotect() which would fail to + * flush the hash table after setting the write protect bit in the parent's + * page tables, thus allowing the parent to pollute the child's mapping. + * + */ + +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define C1 0x1234ABCD +#define C2 ~0x1234ABCD +#define C3 0xfeef5678 +#define MNTPOINT "hugetlbfs/" +static int fd = -1; +static long hpage_size; + +static void run_test(void) +{ + volatile unsigned int *p; + int parent_readback; + pid_t pid; + + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + *p = C1; + + pid = SAFE_FORK(); + if (pid != 0) { + *p = C2; + TST_CHECKPOINT_WAKE_AND_WAIT(0); + parent_readback = *p; + TST_CHECKPOINT_WAKE(0); + } else { + unsigned int child_readback = 0; + + TST_CHECKPOINT_WAIT(0); + child_readback = *p; + *p = C3; + TST_CHECKPOINT_WAKE_AND_WAIT(0); + TST_EXP_EXPR(child_readback == C1, "0x%x == child_readback (0x%x)", + C1, child_readback); + exit(0); + } + tst_reap_children(); + TST_EXP_EXPR(parent_readback == C2, "0x%x == parent_readback (0x%x)", + C2, parent_readback); + + SAFE_MUNMAP((void *)p, hpage_size); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + 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", "86df86424939"}, + {} + }, + .needs_root = 1, + .needs_checkpoints = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .forks_child = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717687 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=tBTkwo3P; dkim-atps=neutral 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NbmvJ35FCz1ydZ for ; Tue, 20 Dec 2022 17:31:56 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3F85C3CBA7A for ; Tue, 20 Dec 2022 07:31:54 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6076F3CBA77 for ; Tue, 20 Dec 2022 07:31:39 +0100 (CET) Received: from mx0a-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-5.smtp.seeweb.it (Postfix) with ESMTPS id 47684600705 for ; Tue, 20 Dec 2022 07:31:37 +0100 (CET) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6DWWh014778; Tue, 20 Dec 2022 06:31:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=REXeVKxv2twkKm89f6QQg83csY6BZEBNMQPqCuKht20=; b=tBTkwo3PNO4wBsGKpSXFuRcxoT18Ot8ss6Z6zzl/1owsvbfvxDcDhnf0voizBXsBDqK1 IwZMmUpTjQXo8rN+YOAeMX5kL59FT3Sndi9Q5//9x1gWbEOGhtBTlhcTWkWbscR+ZFk6 fbAWKGt26/d+bPd6Yqh8qF91vqKFyVYQSSCgJfRup9glP+sGszdA/xkptowHeX8SHwad +d6jQ2UV7sbzKjn8HQwHS0cMY0BVPV8++VhDNm3iI8l2N+useODCmHhPykQeD3fQKRo2 6d523yKRKldPJGBCshb8Uq5botvXKrzaYyelCJcduQhsgWuahOJGnyhphnjVZfRo5Lse 8g== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7kb0e8f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:36 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJEQ9YX014051; Tue, 20 Dec 2022 06:31:34 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3mh6yw3j32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:34 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VUTe48497034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:30 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 75BC320040; Tue, 20 Dec 2022 06:31:30 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2929820049; Tue, 20 Dec 2022 06:31:27 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:26 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:03 +0530 Message-Id: <20221220063109.279007-3-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 6QqajqsqHGQNHFqnD0ezTEYMsCwSjM4z X-Proofpoint-ORIG-GUID: 6QqajqsqHGQNHFqnD0ezTEYMsCwSjM4z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 phishscore=0 adultscore=0 mlxlogscore=886 mlxscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200051 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/8] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/huge_at_4GB_normal_below.c test Test Description: On some old ppc64 kernel, when hpage is mmaped on 32 bit boundary and normal page below it, it triggers the bug caused by off-by-one error. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap13.c | 126 ++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 4c16e1e7c..2029ee4b3 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -14,6 +14,7 @@ hugemmap09 hugemmap09 hugemmap10 hugemmap10 hugemmap11 hugemmap11 hugemmap12 hugemmap12 +hugemmap13 hugemmap13 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 adea760c7..5955ed613 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -13,6 +13,7 @@ /hugetlb/hugemmap/hugemmap10 /hugetlb/hugemmap/hugemmap11 /hugetlb/hugemmap/hugemmap12 +/hugetlb/hugemmap/hugemmap13 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file mode 100644 index 000000000..7235c55ac --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * + * On some old ppc64 kernel, when hpage is mmaped on 32 bit boundary and + * normal page below it, it triggers the bug caused by off-by-one error. + * + * 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 +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define FOURGB (1UL << 32) +#define MNTPOINT "hugetlbfs/" +static int fd = -1; +static unsigned long hpage_size; +static int page_size; + +static void run_test(void) +{ + void *p, *q = NULL; + unsigned long lowaddr; + unsigned long below_start; + unsigned long above_end; + + p = mmap((void *)FOURGB, hpage_size, PROT_READ|PROT_WRITE, + MAP_SHARED | MAP_FIXED, fd, 0); + if (p == MAP_FAILED) { + /* slice 0 (high) spans from 4G-1T */ + below_start = FOURGB; + above_end = 1024L*1024*1024*1024; + + if (range_is_mapped(below_start, above_end) == 1) { + tst_res(TINFO|TERRNO, "region 4G-IT is not free & " + "mmap() failed expected"); + tst_res(TPASS, "Successful but inconclusive"); + } else + tst_res(TFAIL|TERRNO, "mmap() huge failed unexpected"); + goto cleanup; + } + if (p != (void *)FOURGB) { + tst_res(TFAIL, "Wrong address with MAP_FIXED huge"); + goto cleanup; + } + + tst_res(TINFO, "Mapped hugetlb at %p", p); + + memset(p, 0, hpage_size); + + /* Test just below 4GB to check for off-by-one errors */ + lowaddr = FOURGB - page_size; + q = mmap((void *)lowaddr, page_size, PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0); + if (q == MAP_FAILED) { + below_start = FOURGB - page_size; + above_end = FOURGB; + + if (range_is_mapped(below_start, above_end) == 1) { + tst_res(TINFO|TERRNO, "region (4G-page)-4G is not free & " + "mmap() failed expected"); + tst_res(TPASS, "Successful but inconclusive"); + } else + tst_res(TFAIL|TERRNO, "mmap() normal failed unexpected"); + goto cleanup; + } + if (q != (void *)lowaddr) { + tst_res(TFAIL, "Wrong address with MAP_FIXED normal"); + goto cleanup; + } + + memset(q, 0, page_size); + tst_res(TPASS, "Successful"); + +cleanup: + if (p && p != MAP_FAILED) + SAFE_MUNMAP(p, hpage_size); + if (q && q != MAP_FAILED) + SAFE_MUNMAP(q, page_size); +} + +static void setup(void) +{ + page_size = getpagesize(); + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + + if (sizeof(void *) <= 4) + tst_brk(TCONF, "Machine must be >32 bit"); + if (hpage_size > FOURGB) + tst_brk(TCONF, "Huge page size is too large"); + 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", "9a94c5793a7b"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) 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=bSXPyOAn; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NbmvV5PpRz1ydZ for ; Tue, 20 Dec 2022 17:32:06 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 39C803CBA5D for ; Tue, 20 Dec 2022 07:32:03 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A50D33CBA64 for ; Tue, 20 Dec 2022 07:31:43 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id D5BFE6006D8 for ; Tue, 20 Dec 2022 07:31:42 +0100 (CET) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6C8sf020385; Tue, 20 Dec 2022 06:31:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=TjJuy81hZnuh++RsdxD0s9JaFGWhRjD+A/wrEJZVqfw=; b=bSXPyOAnAQgsNwU310xlLUfqnv6kdOR43zKZ9LGgcJEY10u0BwMi6MEzdueCDQG5KQBE rsiwCg3QMJu0x/Ta3CeAuRKgRh+eMocplLWpSf4iaCWl//O6oDp4zmE8o+wWnUY9viYV MtIMpOiI06f9PRqDkvb73OhXW4SzWnhWXhp03uYokYcI2WsRu1ZMmxMGR6MBR3jUqzxv quQm05Vs0vsHyHj2Ue9speeq81OhaUl+egJIyfnb6SVxjH+KbYQAtTuFVJ1UPhbwMatT HSvfAKUI2GxwwmUODpdL0PYdDyc9S+6r4fTtg5v7snK8eXNMGN9yn4toRfOYzBvLtmRd 9w== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7jnrfcu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:40 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJLg1ao014508; Tue, 20 Dec 2022 06:31:38 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3mh6yxjjq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:38 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VYrd28508478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:34 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 870B020043; Tue, 20 Dec 2022 06:31:34 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F49B20040; Tue, 20 Dec 2022 06:31:31 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:30 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:04 +0530 Message-Id: <20221220063109.279007-4-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: YpVO8-Lfy0BvVajTZarc7Hf5SmmhXuG4 X-Proofpoint-GUID: YpVO8-Lfy0BvVajTZarc7Hf5SmmhXuG4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200054 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/8] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/huge_below_4GB_normal_above.c test Test Description: On some old ppc64 kernel, when huge page is mapped at below touching 32 bit boundary (4GB - hpage_size), and normal page is mmaped at just above it, it triggers a bug caused by off-by-one error. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap14.c | 159 ++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 2029ee4b3..796ebe7fa 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -15,6 +15,7 @@ hugemmap10 hugemmap10 hugemmap11 hugemmap11 hugemmap12 hugemmap12 hugemmap13 hugemmap13 +hugemmap14 hugemmap14 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 5955ed613..3106579ce 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -14,6 +14,7 @@ /hugetlb/hugemmap/hugemmap11 /hugetlb/hugemmap/hugemmap12 /hugetlb/hugemmap/hugemmap13 +/hugetlb/hugemmap/hugemmap14 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file mode 100644 index 000000000..13068e5b6 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * On some old ppc64 kernel, when huge page is mapped at below touching + * 32 bit boundary (4GB - hpage_size), and normal page is mmaped + * at just above it, it triggers a bug caused by off-by-one error. + * + * 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 +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define FOURGB (1UL << 32) +#define MNTPOINT "hugetlbfs/" +static int fd = -1; +static unsigned long hpage_size; +static int page_size; + +static void run_test(void) +{ + void *p, *q = NULL, *r = NULL; + unsigned long lowaddr, highaddr; + unsigned long below_start; + unsigned long above_end; + + /* + * We use a low address right below 4GB so we can test for + * off-by-one errors + */ + lowaddr = FOURGB - hpage_size; + tst_res(TINFO, "Mapping hugepage at %lx...", lowaddr); + p = mmap((void *)lowaddr, hpage_size, PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FIXED, fd, 0); + if (p == MAP_FAILED) { + /* This is last low slice - 256M just before 4G */ + below_start = FOURGB - 256L*1024*1024; + above_end = FOURGB; + + if (range_is_mapped(below_start, above_end) == 1) { + tst_res(TINFO|TERRNO, "region (4G-256M)-4G is not free & " + "mmap() failed expected"); + tst_res(TPASS, "Successful but inconclusive"); + } else + tst_res(TFAIL|TERRNO, "mmap() huge failed unexpected"); + goto cleanup; + } + if (p != (void *)lowaddr) { + tst_res(TFAIL, "Wrong address with MAP_FIXED huge"); + goto cleanup; + } + memset(p, 0, hpage_size); + + /* Test for off by one errors */ + highaddr = FOURGB; + tst_res(TINFO, "Mapping normal page at %lx...", highaddr); + q = mmap((void *)highaddr, page_size, PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0); + if (q == MAP_FAILED) { + below_start = FOURGB; + above_end = FOURGB + page_size; + + if (range_is_mapped(below_start, above_end) == 1) { + tst_res(TINFO|TERRNO, "region 4G-(4G+page) is not free & " + "mmap() failed expected"); + tst_res(TPASS, "Successful but inconclusive"); + } else + tst_res(TFAIL|TERRNO, "mmap() normal 1 failed unexpected"); + goto cleanup; + } + if (q != (void *)highaddr) { + tst_res(TFAIL, "Wrong address with MAP_FIXED normal 1"); + goto cleanup; + } + memset(q, 0, page_size); + + /* + * Why this address? Well on ppc64, we're working with 256MB + * segment numbers, hence >>28. In practice the shift + * instructions only start wrapping around with shifts 128 or + * greater. + */ + highaddr = ((lowaddr >> 28) + 128) << 28; + tst_res(TINFO, "Mapping normal page at %lx...", highaddr); + r = mmap((void *)highaddr, page_size, PROT_READ|PROT_WRITE, + MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0); + if (r == MAP_FAILED) { + below_start = highaddr; + above_end = highaddr + page_size; + + if (range_is_mapped(below_start, above_end) == 1) { + tst_res(TINFO|TERRNO, "region haddr-(haddr+page) not free & " + "mmap() failed unexpected"); + tst_res(TPASS, "Successful but inconclusive"); + } + tst_res(TFAIL|TERRNO, "mmap() normal 2 failed unexpected"); + goto cleanup; + } + if (r != (void *)highaddr) { + tst_res(TFAIL, "Wrong address with MAP_FIXED normal 2"); + goto cleanup; + } + memset(r, 0, page_size); + tst_res(TPASS, "Successful"); + +cleanup: + if (p && p != MAP_FAILED) + SAFE_MUNMAP(p, hpage_size); + if (q && q != MAP_FAILED) + SAFE_MUNMAP(q, page_size); + if (r && r != MAP_FAILED) + SAFE_MUNMAP(r, page_size); +} + +static void setup(void) +{ + page_size = getpagesize(); + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + + if (sizeof(void *) <= 4) + tst_brk(TCONF, "Machine must be >32 bit"); + if (hpage_size > FOURGB) + tst_brk(TCONF, "Huge page size is too large"); + 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", "9a94c5793a7b"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=QqZrNzj6; dkim-atps=neutral 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nbmvm5DRSz1ydZ for ; Tue, 20 Dec 2022 17:32:20 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A03DD3CBA60 for ; Tue, 20 Dec 2022 07:32:18 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6A5033CBA6A for ; Tue, 20 Dec 2022 07:31:48 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 0DDE61400554 for ; Tue, 20 Dec 2022 07:31:46 +0100 (CET) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6C6bD020264; Tue, 20 Dec 2022 06:31:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=CfhFTAGarxIZE6bcvT6QKDH/HzVdVBH0mH07fbxzTsI=; b=QqZrNzj6puGqMpd/TpeiPUNMxuLw2nWLoxVXJnfEsVb8fXKVL6WmN4q7tYFErdTy+F+O R6GjIZ8/RhNyURW69dPJBD6voD24vhCk9Dmfylo3ECZNjwRQzBqIRFH2oXO4vcQd5P7J 1QNTxoYZTM0xO0l/Ny41uSW1fed1J1SlcFoi+9fUgp40LE+Y6kqSUNPWil4dcSOf/RbL yl4S32kOnCf4JMO1GQlX9DNxuNXAd+O8Cp1tUD7XCtA+R8oOBocbckKn+dQCJQlKKqdX yRijoczpaJ/WiTWMY+Dgg2q9LEDLTZY9QaNJebuYzEwfPHpwjTNydAz2iCV87GeqUo6V vA== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7jnrfew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:44 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJBx558025070; Tue, 20 Dec 2022 06:31:42 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3mh6yy2j42-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:42 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VcTd47055300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:38 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B9D1020049; Tue, 20 Dec 2022 06:31:38 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 240CA20040; Tue, 20 Dec 2022 06:31:35 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:34 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:05 +0530 Message-Id: <20221220063109.279007-5-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lFFzPsg6rCYFMlz1_6z6-FMZCNMZs949 X-Proofpoint-GUID: lFFzPsg6rCYFMlz1_6z6-FMZCNMZs949 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=978 phishscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200054 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/8] Hugetlb: Migrating libhugetlbfs icache-hygiene 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/icache-hygiene.c test Test Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug. This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/Makefile | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap15.c | 243 ++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 796ebe7fa..0714ed34c 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -16,6 +16,7 @@ hugemmap11 hugemmap11 hugemmap12 hugemmap12 hugemmap13 hugemmap13 hugemmap14 hugemmap14 +hugemmap15 hugemmap15 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 3106579ce..d59b60fd4 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -15,6 +15,7 @@ /hugetlb/hugemmap/hugemmap12 /hugetlb/hugemmap/hugemmap13 /hugetlb/hugemmap/hugemmap14 +/hugetlb/hugemmap/hugemmap15 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile b/testcases/kernel/mem/hugetlb/hugemmap/Makefile index 2d651b4aa..6f10807cd 100644 --- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile +++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile @@ -8,4 +8,5 @@ include $(top_srcdir)/include/mk/testcases.mk include $(abs_srcdir)/../Makefile.inc include $(top_srcdir)/include/mk/generic_leaf_target.mk +hugemmap15: CFLAGS+=-O0 hugemmap06: CFLAGS+=-pthread diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file mode 100644 index 000000000..4730d8d18 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * + * Older ppc64 kernels don't properly flush dcache to icache before + * giving a cleared page to userspace. With some exceedingly + * hairy code, this attempts to test for this bug. + * + * This test will never trigger (obviously) on machines with coherent + * icache and dcache (including x86 and POWER5). On any given run, + * even on a buggy kernel there's a chance the bug won't trigger - + * either because we don't get the same physical page back when we + * remap, or because the icache happens to get flushed in the interim. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define SUCC_JMP 1 +#define FAIL_JMP 2 +#define COPY_SIZE 128 + +/* Seems to be enough to trigger reliably */ +#define NUM_REPETITIONS 64 +#define MNTPOINT "hugetlbfs/" +static long hpage_size; +static int fd = -1; + +static void cacheflush(void *p) +{ +#if defined(__powerpc__) + asm volatile("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r"(p)); +#elif defined(__arm__) || defined(__aarch64__) + __clear_cache(p, p + COPY_SIZE); +#else + (void)p; +#endif +} + +static void jumpfunc(int copy, void *p) +{ + /* + * gcc bug workaround: if there is exactly one &&label + * construct in the function, gcc assumes the computed goto + * goes there, leading to the complete elision of the goto in + * this case + */ + void *l = &&dummy; + + l = &&jumplabel; + + if (copy) { + memcpy(p, l, COPY_SIZE); + cacheflush(p); + } + + goto *p; + dummy: + tst_res(TWARN, "unreachable?"); + + jumplabel: + return; +} + +static sigjmp_buf sig_escape; +static void *sig_expected; + +static void sig_handler(int signum, siginfo_t *si, void *uc) +{ +#if defined(__powerpc__) || defined(__powerpc64__) || defined(__ia64__) || \ + defined(__s390__) || defined(__s390x__) || defined(__sparc__) || \ + defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) + /* On powerpc, ia64, s390 and Aarch64, 0 bytes are an illegal + * instruction, so, if the icache is cleared properly, we SIGILL + * as soon as we jump into the cleared page + */ + if (signum == SIGILL) { + tst_res(TINFO, "SIGILL at %p (sig_expected=%p)", si->si_addr, + sig_expected); + if (si->si_addr == sig_expected) + siglongjmp(sig_escape, SUCC_JMP); + siglongjmp(sig_escape, FAIL_JMP + SIGILL); + } +#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) + /* On x86, zero bytes form a valid instruction: + * add %al,(%eax) (i386) + * or add %al,(%rax) (x86_64) + * + * So, behaviour depends on the contents of [ER]AX, which in + * turn depends on the details of code generation. If [ER]AX + * contains a valid pointer, we will execute the instruction + * repeatedly until we run off that hugepage and get a SIGBUS + * on the second, truncated page. If [ER]AX does not contain + * a valid pointer, we will SEGV on the first instruction in + * the cleared page. We check for both possibilities + * below. + * + * On 32 bit ARM, zero bytes are interpreted as follows: + * andeq r0, r0, r0 (ARM state, 4 bytes) + * movs r0, r0 (Thumb state, 2 bytes) + * + * So, we only expect to run off the end of the huge page and + * generate a SIGBUS. + */ + if (signum == SIGBUS) { + tst_res(TINFO, "SIGBUS at %p (sig_expected=%p)", si->si_addr, + sig_expected); + if (sig_expected + && (PALIGN(sig_expected, hpage_size) + == si->si_addr)) { + siglongjmp(sig_escape, SUCC_JMP); + } + siglongjmp(sig_escape, FAIL_JMP + SIGBUS); + } +#if defined(__x86_64__) || defined(__i386__) + if (signum == SIGSEGV) { +#ifdef __x86_64__ + void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_RIP]; +#else + void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_EIP]; +#endif + tst_res(TINFO, "SIGSEGV at %p, PC=%p (sig_expected=%p)", + si->si_addr, pc, sig_expected); + if (sig_expected == pc) + siglongjmp(sig_escape, SUCC_JMP); + siglongjmp(sig_escape, FAIL_JMP + SIGSEGV); + } +#endif +#else +#error "Need to setup signal conditions for this arch" +#endif +} + +static int test_once(int fd) +{ + void *p, *q; + + SAFE_FTRUNCATE(fd, 0); + + switch (sigsetjmp(sig_escape, 1)) { + case SUCC_JMP: + sig_expected = NULL; + SAFE_FTRUNCATE(fd, 0); + return 0; + case FAIL_JMP + SIGILL: + tst_res(TFAIL, "SIGILL somewhere unexpected"); + return -1; + case FAIL_JMP + SIGBUS: + tst_res(TFAIL, "SIGBUS somewhere unexpected"); + return -1; + case FAIL_JMP + SIGSEGV: + tst_res(TFAIL, "SIGSEGV somewhere unexpected"); + return -1; + default: + break; + } + p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_SHARED, fd, 0); + + SAFE_FTRUNCATE(fd, hpage_size); + + q = p + hpage_size - COPY_SIZE; + + jumpfunc(1, q); + + SAFE_FTRUNCATE(fd, 0); + p = SAFE_MMAP(p, hpage_size, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_SHARED|MAP_FIXED, fd, 0); + + q = p + hpage_size - COPY_SIZE; + sig_expected = q; + + jumpfunc(0, q); /* This should blow up */ + + tst_res(TFAIL, "icache unclean"); + return -1; +} + +static void run_test(void) +{ + int i; + + struct sigaction sa = { + .sa_sigaction = sig_handler, + .sa_flags = SA_SIGINFO, + }; + + SAFE_SIGACTION(SIGILL, &sa, NULL); + SAFE_SIGACTION(SIGBUS, &sa, NULL); + SAFE_SIGACTION(SIGSEGV, &sa, NULL); + + fd = tst_creat_unlinked(MNTPOINT, 0); + + for (i = 0; i < NUM_REPETITIONS; i++) + if (test_once(fd)) + goto cleanup; + + tst_res(TPASS, "Successfully tested dcache to icache flush"); +cleanup: + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag[]) { + {"linux-git", "cbf52afdc0eb"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {3, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=Ax9w33e+; dkim-atps=neutral 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NbnRd5Vn6z1ydd for ; Tue, 20 Dec 2022 17:56:27 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1DC6D3CBA60 for ; Tue, 20 Dec 2022 07:56:25 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 84AFD3CBA51 for ; Tue, 20 Dec 2022 07:56:23 +0100 (CET) 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-3.smtp.seeweb.it (Postfix) with ESMTPS id B5A5D1A00E40 for ; Tue, 20 Dec 2022 07:56:22 +0100 (CET) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6jD0R003916; Tue, 20 Dec 2022 06:56:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=0hE6VyGErrKwi3Kd3Bn/88NyA67PWoPW05ULqZyRz3E=; b=Ax9w33e+XOwMQXpgRQ/J2tUEy8MBmO/oiIBC8VqHesAgcK4D/ehnOy6ILW0H7VKbg7NA dAE2rTLTZcE8wEZzoEY1iD11tlWfdMS+pt1Qi+kQdv2PVi5vv8THQDeAurdZCQeUPkzk yFosMVfWm4sjBC4WxIEyF8G3TZZ7Kuz7xfr0VtsdJY8JOSuzq3YzjRVTw5BC5aV1EtbR 3P4TdnbdIPvUDhJwwHaLb6lhTsHEKlpr5g5EArIShvL4/dAKwiUWO9xvqTGNCKHEMda+ BNO7m9LfK1ZlojD6AtL8unf6sJGlrd5IuHls/gkpbyDjrrPffaA9iduAdN/6iINnY66+ AQ== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk82708ae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:56:20 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK2bQJr002636; Tue, 20 Dec 2022 06:31:46 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3mh6yvahu1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:45 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VgR918219698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:42 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 423CF20043; Tue, 20 Dec 2022 06:31:42 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D87320040; Tue, 20 Dec 2022 06:31:39 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:39 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:06 +0530 Message-Id: <20221220063109.279007-6-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: T0u8ZUqwyZ3gQ8Lb2VWKpZC_Q1b3u6IG X-Proofpoint-ORIG-GUID: T0u8ZUqwyZ3gQ8Lb2VWKpZC_Q1b3u6IG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-20_01,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 impostorscore=0 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200054 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 5/8] Hugetlb: Migrating libhugetlbfs madvise_reserve 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/madvise_reserve.c test Test Description: madvise() on some kernels can cause the reservation counter to get corrupted. The problem is that the patches are allocated for the reservation but not faulted in at the time of allocation. The counters do not get updated and effectively "leak". This test identifies whether the kernel is vulnerable to the problem or not. It is fixed in kernel by 'commit f2deae9d4e70 ("Remove implementation of readpage from the hugetlbfs_aops")'. Signed-off-by: Tarun Sahu Reviewed-by: Richard Palethorpe --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap16.c | 83 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 0714ed34c..1691ce37d 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -17,6 +17,7 @@ hugemmap12 hugemmap12 hugemmap13 hugemmap13 hugemmap14 hugemmap14 hugemmap15 hugemmap15 +hugemmap16 hugemmap16 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 d59b60fd4..eb8e87c40 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -16,6 +16,7 @@ /hugetlb/hugemmap/hugemmap13 /hugetlb/hugemmap/hugemmap14 /hugetlb/hugemmap/hugemmap15 +/hugetlb/hugemmap/hugemmap16 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c new file mode 100644 index 000000000..2003e7013 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 IBM Corporation. + * Author: Eric B Munson and Mel Gorman + */ + +/*\ + * [Description] + * + * madvise() on some kernels can cause the reservation counter to get + * corrupted. The problem is that the patches are allocated + * for the reservation but not faulted in at the time of allocation. The + * counters do not get updated and effectively "leak". This test + * identifies whether the kernel is vulnerable to the problem or not. + * It is fixed in kernel by commit f2deae9d4e70 + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +static int fd = -1; +static long hpage_size; + +static void run_test(void) +{ + void *p; + unsigned long initial_rsvd, map_rsvd, madvise_rsvd, end_rsvd; + + fd = tst_creat_unlinked(MNTPOINT, 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); + map_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after map: %lu", map_rsvd); + + if (madvise(p, hpage_size, MADV_WILLNEED) == -1) + tst_brk(TBROK|TERRNO, "madvise()"); + madvise_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after madvise: %lu", madvise_rsvd); + + SAFE_MUNMAP(p, hpage_size); + SAFE_CLOSE(fd); + end_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after close(): %lu", end_rsvd); + + TST_EXP_EQ_LU(end_rsvd, initial_rsvd); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; +} + +static void cleanup(void) +{ + if (fd >= 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag[]) { + {"linux-git", "f2deae9d4e70"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=cQJlxoBy; dkim-atps=neutral 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nbmvz2Qd9z1ydZ for ; Tue, 20 Dec 2022 17:32:31 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 99F333CBA6B for ; Tue, 20 Dec 2022 07:32:28 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5CBDD3CBA6B for ; Tue, 20 Dec 2022 07:31:54 +0100 (CET) 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-7.smtp.seeweb.it (Postfix) with ESMTPS id 61088200967 for ; Tue, 20 Dec 2022 07:31:52 +0100 (CET) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6DU9Z025634; Tue, 20 Dec 2022 06:31:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=otLR21U7rsJPAClBrPkyaDyBhsgJObVU5JMb1267uXs=; b=cQJlxoByc+kDP4J3+VQNc9MAYCGDsuoyDKGeZRAEyD9aDNYAH5bIqUdenhPVDrsY5VAi 4GskxS3f1b8xpgEr0tLvyr8NwNGmSjDHPdbZbLznnDwCWljzX9DyTpLV2UeJKgqFMB2V WqBiAMYkdgCevdi3/6t12NCTEpYLRBXnbU/WWLvO0yph6/WjStNeh7/Mig0QvPL7oloV Iq1i7++UnI4OdzH5eDGszYSldQwLmEgP6iniSPORskpwCMRNNAq+bHYw1YMB+fDgqE3y Tkb9aGYkPgEmySHWv2Y64wJLYOfDnHxO4+tF1dVIHipMz99bdbe/GHIencDVHPFfMt6c LQ== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7ke0ds5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:51 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6OZv9024486; Tue, 20 Dec 2022 06:31:49 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3mh6ywkhr0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VksE45613478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:46 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E1EB72004B; Tue, 20 Dec 2022 06:31:45 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C79F820040; Tue, 20 Dec 2022 06:31:42 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:42 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:07 +0530 Message-Id: <20221220063109.279007-7-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: prs1uIQpldTgoVsn9boLLcxavJKqAfE4 X-Proofpoint-ORIG-GUID: prs1uIQpldTgoVsn9boLLcxavJKqAfE4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 impostorscore=0 spamscore=0 priorityscore=1501 adultscore=0 mlxlogscore=957 malwarescore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200051 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 6/8] Hugetlb: Migrating libhugetlbfs map_high_truncate_2 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/map_high_truncate_2.c test Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, certain combinations of mapping and truncations could truncate incorrect pages, or overwrite pmds from other VMAs, triggering BUG_ON()s or other wierdness. Test adapted from an example by Kenneth Chen 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. The kernel bug in question was fixed with 'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'. Signed-off-by: Tarun Sahu Reviewed-by: Richard Palethorpe --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap17.c | 103 ++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 1691ce37d..5fac3481c 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -18,6 +18,7 @@ hugemmap13 hugemmap13 hugemmap14 hugemmap14 hugemmap15 hugemmap15 hugemmap16 hugemmap16 +hugemmap17 hugemmap17 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 eb8e87c40..6aa54f902 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -17,6 +17,7 @@ /hugetlb/hugemmap/hugemmap14 /hugetlb/hugemmap/hugemmap15 /hugetlb/hugemmap/hugemmap16 +/hugetlb/hugemmap/hugemmap17 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c new file mode 100644 index 000000000..b8105bbf3 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Descriptiom] + * + * At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree + * meant that on 32-bit machines, certain combinations of mapping and + * truncations could truncate incorrect pages, or overwrite pmds from + * other VMAs, triggering BUG_ON()s or other wierdness. + * + * Test adapted from an example by Kenneth Chen + * + * 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. + * + * The kernel bug in question was fixed with commit + * 856fc2950555. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +#define MAP_LENGTH (4UL * hpage_size) +#if defined(__s390__) && __WORDSIZE == 32 +#define TRUNCATE_POINT 0x20000000UL +#else +#define TRUNCATE_POINT 0x60000000UL +#endif +#define HIGH_ADDR 0xa0000000UL +#define FOURGIG ((off64_t)0x100000000ULL) + +static unsigned long hpage_size; +static int fd = -1; + +static void run_test(void) +{ + char *p, *q; + unsigned long i; + + p = SAFE_MMAP(0, MAP_LENGTH + TRUNCATE_POINT, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_NORESERVE, fd, 0); + + SAFE_MUNMAP(p, MAP_LENGTH + TRUNCATE_POINT); + + q = SAFE_MMAP((void *)HIGH_ADDR, MAP_LENGTH, PROT_READ | PROT_WRITE, + MAP_PRIVATE, fd, 0); + tst_res(TINFO, "High map at %p", q); + + for (i = 0; i < MAP_LENGTH; i += hpage_size) + q[i] = 1; + + SAFE_FTRUNCATE(fd, TRUNCATE_POINT); + + if (q[0] != 1) + tst_res(TFAIL, "data mismatch"); + else + tst_res(TPASS, "Successful"); + + SAFE_MUNMAP(q, MAP_LENGTH); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + + if (hpage_size > TRUNCATE_POINT) + tst_brk(TCONF, "Huge page size is too large"); + if (TRUNCATE_POINT % hpage_size) + tst_brk(TCONF, "Truncation point is not aligned to huge page 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", "856fc2950555"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {4, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) 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=nzPFk+JE; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nbn1D3Bfwz23dC for ; Tue, 20 Dec 2022 17:37:04 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7F0003CBA65 for ; Tue, 20 Dec 2022 07:37:01 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BC37F3CBA52 for ; Tue, 20 Dec 2022 07:36:58 +0100 (CET) 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-2.smtp.seeweb.it (Postfix) with ESMTPS id 782FA6002C4 for ; Tue, 20 Dec 2022 07:36:56 +0100 (CET) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6XUDC001838; Tue, 20 Dec 2022 06:36:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=xyYb59dUMot3HW8CottvSREdJqFx2khHKBtmis2I97A=; b=nzPFk+JEPfmSmEPP5INOxSAh1fLNAm66NNTbZ4h/Ez6HRm8JVntGUsqu4/kbPS7glxAl Sxjx5a/FSja3up7nujOkdss+hxWzeoot/veAfoTkodqSVJGy8stmwEz0ITU9Du1xBUqD 9smG9Xty4mfsa9D8lh2q8itXkxbx4Lg1y+ZCHDWn7Re1jaaFX4lICEW3jD7te7oa0o3Q wNeR+ucjCnN+KJuqCTWK1tNUYcQ0rrO36+EZl8xsjte+rqpu9RuZ7vUdgCYh3e61pxrH kxIgPt10HVhA+ZoGlnOCuke9xh53ufAaWuZKsaTgO5s6a1SD/c6JuCatuyf5RG1EgUfi Og== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7vvr2jy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:36:55 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJG0bfH027745; Tue, 20 Dec 2022 06:31:53 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3mh6yy2j49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:53 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VnDj16974416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AB72B2004B; Tue, 20 Dec 2022 06:31:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 770D220043; Tue, 20 Dec 2022 06:31:46 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:46 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:08 +0530 Message-Id: <20221220063109.279007-8-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: _mshodQ_bSh_dfvWtNkUMS469WSwgQyx X-Proofpoint-ORIG-GUID: _mshodQ_bSh_dfvWtNkUMS469WSwgQyx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200051 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 7/8] Hugetlb: Migrating libhugetlbfs misalign 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/misalign.c test Test Description: Just as normal mmap()s can't have an address, length or offset which is not page aligned, so hugepage mmap()s can't have an address, length or offset with is not hugepage aligned. However, from time to time when the various mmap() / get_unmapped_area() paths are updated, somebody misses one of the necessary checks for the hugepage paths. This testcase ensures that attempted hugepage mappings with parameters which are not correctly hugepage aligned are rejected. However starting with 3.10-rc1, length passed in mmap() doesn't need to be aligned because 'commit af73e4d9506d ("hugetlbfs: fix mmap failure in unaligned size request")' added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page files. Signed-off-by: Tarun Sahu Reviewed-by: Richard Palethorpe --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap18.c | 153 ++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 5fac3481c..de76cdaf2 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -19,6 +19,7 @@ hugemmap14 hugemmap14 hugemmap15 hugemmap15 hugemmap16 hugemmap16 hugemmap17 hugemmap17 +hugemmap18 hugemmap18 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 6aa54f902..daee70586 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -18,6 +18,7 @@ /hugetlb/hugemmap/hugemmap15 /hugetlb/hugemmap/hugemmap16 /hugetlb/hugemmap/hugemmap17 +/hugetlb/hugemmap/hugemmap18 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c new file mode 100644 index 000000000..607072937 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2007 David Gibson & Adam Litke, IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * + * Just as normal mmap()s can't have an address, length or offset which + * is not page aligned, so hugepage mmap()s can't have an address, length + * or offset with is not hugepage aligned. + * + * However, from time to time when the various mmap() / + * get_unmapped_area() paths are updated, somebody misses one of the + * necessary checks for the hugepage paths. This testcase ensures + * that attempted hugepage mappings with parameters which are not + * correctly hugepage aligned are rejected. + * + * However starting with 3.10-rc1, length passed in mmap() doesn't need + * to be aligned because commit af73e4d9506d3b797509f3c030e7dcd554f7d9c4 + * added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page + * files. + */ + +#define _GNU_SOURCE +#include +#include +#include + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +static long hpage_size; +static int fd = -1; +static long page_size; + +static void run_test(void) +{ + void *p, *q; + + /* + * First see what an ok mapping looks like, as a basis for our + * bad addresses and so forth + */ + p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + if (p == MAP_FAILED) { + tst_res(TFAIL|TERRNO, "mmap() without hint failed"); + return; + } + if (((unsigned long)p % hpage_size) != 0) { + tst_res(TFAIL, "mmap() without hint at misaligned address"); + goto cleanup1; + } + + tst_res(TINFO, "Mapped at %p, length 0x%lx", p, hpage_size); + + SAFE_MUNMAP(p, hpage_size); + + /* 1) Try a misaligned hint address */ + q = mmap(p + page_size, hpage_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fd, 0); + if (q == MAP_FAILED) { + /* Bad hint shouldn't fail, just ignore the hint */ + tst_res(TFAIL|TERRNO, "mmap() with hint failed"); + return; + } + if (((unsigned long)q % hpage_size) != 0) { + tst_res(TFAIL, "mmap() with hint at misaligned address"); + goto cleanup2; + } + SAFE_MUNMAP(q, hpage_size); + + /* 2) Try a misaligned address with MAP_FIXED */ + q = mmap(p + page_size, hpage_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_FIXED, fd, 0); + if (q != MAP_FAILED) { + tst_res(TFAIL, "mmap() MAP_FIXED at misaligned address succeeded"); + goto cleanup2; + } + + /* 3) Try a misaligned length */ + q = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + if (q == MAP_FAILED) { + tst_res(TFAIL, "mmap() with misaligned length 0x%lx failed", + page_size); + return; + } + SAFE_MUNMAP(q, hpage_size); + + /* 4) Try a misaligned length with MAP_FIXED */ + q = mmap(p, page_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_FIXED, fd, 0); + if (q == MAP_FAILED) { + tst_res(TFAIL, "mmap() MAP_FIXED with misaligned length 0x%lx " + "failed", page_size); + return; + } + SAFE_MUNMAP(q, hpage_size); + + /* 5) Try a misaligned offset */ + q = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fd, page_size); + if (q != MAP_FAILED) { + tst_res(TFAIL, "mmap() with misaligned offset 0x%lx succeeded", + page_size); + goto cleanup2; + } + + /* 6) Try a misaligned offset with MAP_FIXED*/ + q = mmap(p, hpage_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_FIXED, fd, page_size); + if (q != MAP_FAILED) { + tst_res(TFAIL, "mmap() MAP_FIXED with misaligned offset 0x%lx succeeded", + page_size); + goto cleanup2; + } + + tst_res(TPASS, "mmap worked as expected with misaligned addr and length"); + return; +cleanup2: + SAFE_MUNMAP(q, hpage_size); + return; +cleanup1: + SAFE_MUNMAP(p, hpage_size); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + page_size = getpagesize(); + 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", "af73e4d9506d"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {4, TST_NEEDS}, +}; From patchwork Tue Dec 20 06:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1717691 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=Fr8vK5TX; dkim-atps=neutral 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nbmw82CsCz1ydZ for ; Tue, 20 Dec 2022 17:32:40 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 31AEA3CBA79 for ; Tue, 20 Dec 2022 07:32:38 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5DE683CBA64 for ; Tue, 20 Dec 2022 07:32:03 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 50CEA200231 for ; Tue, 20 Dec 2022 07:32:01 +0100 (CET) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6PepO024576; Tue, 20 Dec 2022 06:32:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=rTlWhaFZqA6YeI+GEUo/nzI/qMEEjqvmXToPPXLbAlY=; b=Fr8vK5TXWrIQ9+8jh6vmQesWqfoAKEQIsExa8OEtt5vUdF7IZtOVN18lXRcxNnaKi37Y eOxLkCsjVNk7cqdDGDBKaiBQ01P01mNVDPDwWio20wOXQ5eE4d7cK6kD67YCUbBHlCcO Hmp0o2ZRh28MIAHT44HJKINtgmUgeqKwOBmorKxs6xJdNhQq5pf5tM4Plj7iD0YkQnAg XGR6PIjgupKqw4H3NMUcO1zd+exLCSR2lNkFPjve8HYgyt+Pvy+xJJBx9e+n/tf8H5f4 KHjU15esO8cfnDB0oyhh98qI0rYkhthy2BRfS1imGtQbhXAV4/8DTXwpDi5Dk5J5aFJT Mw== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mk7s704p5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:59 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BK6T267014025; Tue, 20 Dec 2022 06:31:57 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3mh6yw3j3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 06:31:57 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BK6VrJV44433794 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Dec 2022 06:31:53 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9058720040; Tue, 20 Dec 2022 06:31:53 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5EA2920043; Tue, 20 Dec 2022 06:31:50 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.119.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Dec 2022 06:31:50 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Tue, 20 Dec 2022 12:01:09 +0530 Message-Id: <20221220063109.279007-9-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221220063109.279007-1-tsahu@linux.ibm.com> References: <20221220063109.279007-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OOebQ9efHCso-IYK4Pp5HYLqoq_lzgBY X-Proofpoint-ORIG-GUID: OOebQ9efHCso-IYK4Pp5HYLqoq_lzgBY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-19_05,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 malwarescore=0 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212200054 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 8/8] Hugetlb: Migrating libhugetlbfs misaligned_offset 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: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/misaligned_offset.c test Test Name: Misaligned offset Test Description: 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. The kernel bug in question was fixed with 'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'. Signed-off-by: Tarun Sahu Reviewed-by: Richard Palethorpe --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap19.c | 147 ++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c diff --git a/runtest/hugetlb b/runtest/hugetlb index de76cdaf2..4da1525a7 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -20,6 +20,7 @@ hugemmap15 hugemmap15 hugemmap16 hugemmap16 hugemmap17 hugemmap17 hugemmap18 hugemmap18 +hugemmap19 hugemmap19 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 daee70586..b6b3e5ddd 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -19,6 +19,7 @@ /hugetlb/hugemmap/hugemmap16 /hugetlb/hugemmap/hugemmap17 /hugetlb/hugemmap/hugemmap18 +/hugetlb/hugemmap/hugemmap19 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c new file mode 100644 index 000000000..11060125b --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + * Copyright (C) 2006 Hugh Dickins + * Author: David Gibson & Adam Litke + */ + +/*\ + * [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. + * + * The kernel bug in question was fixed with commit + * 856fc2950555. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define RANDOM_CONSTANT 0x1234ABCD +#define MNTPOINT "hugetlbfs/" +static int page_size; +static long hpage_size; +static int fd = -1; + +static void run_test(void) +{ + off_t buggy_offset; + void *p, *q; + volatile int *pi; + int err; + + /* + * First, we make a 2 page sane hugepage mapping. Then we + * memset() it to ensure that the ptes are instantiated for + * it. Then we attempt to replace the second half of the map + * with one at a bogus offset. We leave the first page of + * sane mapping in place to ensure that the corresponding + * pud/pmd/whatever entries aren't cleaned away. It's those + * bad entries which can trigger bad_pud() checks if the + * backout path for the bogus mapping is buggy, which it was + * in some kernels. + */ + tst_res(TINFO, "Initial free hugepages: %lu", + SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE)); + + /* First get arena of three hpages size, at file offset 4GB */ + p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + + tst_res(TINFO, "After Mapping reference map, Free hugepages: %lu", + SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE)); + tst_res(TINFO, "Mapped Address Range: %p-%p", p, p+2*hpage_size-1); + + memset(p, 0, 2*hpage_size); + pi = p; + *pi = RANDOM_CONSTANT; + + tst_res(TINFO, "After instantiate the pages, Free hugepages: %lu", + SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE)); + + /* + * Toggle the permissions on the first page. This forces TLB + * entries (including hash page table on powerpc) to be + * flushed, so that the page tables must be accessed for the + * test further down. In the buggy case, those page tables + * can get thrown away by a pud_clear() + */ + err = mprotect(p, hpage_size, PROT_READ); + if (err) + tst_brk(TBROK|TERRNO, "mprotect(%p, 0x%lx, PROT_READ)", p, hpage_size); + + /* Replace top hpage by hpage mapping at confusing file offset */ + buggy_offset = page_size; + tst_res(TINFO, "Replacing map at %p with map from offset 0x%lx...", + p + hpage_size, (unsigned long)buggy_offset); + q = mmap(p + hpage_size, hpage_size, PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_PRIVATE, fd, buggy_offset); + if (q != MAP_FAILED) { + tst_res(TFAIL|TERRNO, "bogus offset mmap() succeeded at %p", q); + goto cleanup; + } + if (errno != EINVAL) { + tst_res(TFAIL|TERRNO, "bogus mmap() failed should be \"%s\" but it is", + tst_strerrno(EINVAL)); + goto cleanup; + } + + tst_res(TINFO, "After Mapping with buggy offset, Free hugepages: %lu", + SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE)); + + if (*pi != RANDOM_CONSTANT) { + tst_res(TFAIL, "Pre-existing mapping clobbered: %x instead of %x", + *pi, RANDOM_CONSTANT); + goto cleanup; + } + + /* + * The real test is whether we got a bad_pud() or similar + * during the run. The check above, combined with the earlier + * mprotect()s to flush the TLB are supposed to catch it, but + * it's hard to be certain. Once bad_pud() is called + * behaviour can be very strange. + */ + + tst_res(TPASS, "Successful but inconclusive"); +cleanup: + SAFE_MUNMAP(p, 2*hpage_size); +} + +static void setup(void) +{ + page_size = getpagesize(); + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + 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", "856fc2950555"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {4, TST_NEEDS}, +};