From patchwork Wed Nov 16 11:25:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704506 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=q9QSncGW; 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 4NC1361bNDz23n9 for ; Wed, 16 Nov 2022 22:26:41 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 692FD3CD061 for ; Wed, 16 Nov 2022 12:26:38 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id F3D1A3CD02A for ; Wed, 16 Nov 2022 12:26:24 +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-6.smtp.seeweb.it (Postfix) with ESMTPS id 22AAC1400DC9 for ; Wed, 16 Nov 2022 12:26:23 +0100 (CET) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGAW0P9017426; Wed, 16 Nov 2022 11:26:22 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=LFewP6PuGGXhFXa01jN91gWDys0ZM1nkQM1Pbbh878g=; b=q9QSncGWL6TBqQ0v4LIQ2p5RdB22vLvdYJOA8sHmgQBnVN6xPgctgPARltnmDiVv2vqh dJDjO93jYTa0PGqRwPunR/c3xUiO/RfPeq3SuhBdCYBQRy20Ns0vXSNQdL41+DagR9fF uNHyahvT9VR3OtByFY4VKbm+n7d1K0fWRm0usKy99VWQnGVbOZjo7S5Xq8pKxj6S6aU8 YswoaET00SdDdrAZSeC4wH26q8UNkPqH3nUNPDjQLpzd9ofaYOpUA2M5KCTWcrOO7iHz j9umWjglvSR9atHn4kOuQwNDaM+jpq/68+A3UprX0Ld6GT22VxVzn4OHmO4sjzEL/gaR 4A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvx6q1gks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:22 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGAtTQn003210; Wed, 16 Nov 2022 11:26:21 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvx6q1gkd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:21 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBK9Du006078; Wed, 16 Nov 2022 11:26:20 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma01fra.de.ibm.com with ESMTP id 3ktbd9m1cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:19 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQGsY2884144 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:16 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B23DF42045; Wed, 16 Nov 2022 11:26:16 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73D0A4203F; Wed, 16 Nov 2022 11:26:14 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:14 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:10 +0530 Message-Id: <20221116112516.261535-2-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 8tD4Y3VoKr4qefmkME3ATM6Razjlz-CL X-Proofpoint-ORIG-GUID: wqJixYqUWE0dS49d3Io3GkZjy84hJZ0N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_02,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=895 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160074 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 v4 1/7] Hugetlb: Add new argument flags in tst_creat_unlinked 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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Some test requires custom flags for file opened by tst_creat_unlinked along with O_CREAT|O_EXCL|O_RDWR. This patch creates support to pass custom flags in tst_creat_unlinked. Signed-off-by: Tarun Sahu --- include/tst_test.h | 2 +- lib/tst_test.c | 19 ++++++++++++++----- .../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 2 +- .../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 2 +- .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/tst_test.h b/include/tst_test.h index acf2421de..a62515bfe 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -365,7 +365,7 @@ void tst_set_max_runtime(int max_runtime); * Create and open a random file inside the given dir path. * It unlinks the file after opening and return file descriptor. */ -int tst_creat_unlinked(const char *path); +int tst_creat_unlinked(const char *path, int flags); /* * Returns path to the test temporary directory in a newly allocated buffer. diff --git a/lib/tst_test.c b/lib/tst_test.c index b225ba082..d17b15ee8 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -1027,18 +1027,27 @@ static void prepare_and_mount_hugetlb_fs(void) mntpoint_mounted = 1; } -int tst_creat_unlinked(const char *path) +int tst_creat_unlinked(const char *path, int flags) { char template[PATH_MAX]; + int len, c, range; int fd; + int start[3] = {'0', 'a', 'A'}; snprintf(template, PATH_MAX, "%s/ltp_%.3sXXXXXX", path, tid); + len = strlen(template) - 1; + + srand(time(NULL)); + while (template[len] == 'X') { + c = rand() % 3; + range = start[c] == '0' ? 10 : 26; + c = start[c] + (rand() % range); + template[len--] = (char)c; + } - fd = mkstemp(template); - if (fd < 0) - tst_brk(TBROK | TERRNO, "mkstemp(%s) failed", template); - + flags |= O_CREAT|O_EXCL|O_RDWR; + fd = SAFE_OPEN(template, flags); SAFE_UNLINK(template); return fd; } diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c index bd0fb440a..3122d5b9d 100644 --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c @@ -113,7 +113,7 @@ cleanup: static void setup(void) { hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; - huge_fd = tst_creat_unlinked(MNTPOINT); + huge_fd = tst_creat_unlinked(MNTPOINT, 0); } static void cleanup(void) diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c index ce40e7b69..f66b331dc 100644 --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c @@ -118,7 +118,7 @@ static void run_test(unsigned int test_type) static void setup(void) { hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; - huge_fd = tst_creat_unlinked(MNTPOINT); + huge_fd = tst_creat_unlinked(MNTPOINT, 0); } static void cleanup(void) diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c index 1008395a4..ceb0f64a1 100644 --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c @@ -60,7 +60,7 @@ static void run_test(void) static void setup(void) { hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; - huge_fd = tst_creat_unlinked(MNTPOINT); + huge_fd = tst_creat_unlinked(MNTPOINT, 0); } static void cleanup(void) From patchwork Wed Nov 16 11:25:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704507 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=stDu8Y8C; 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 4NC13H0jzSz23n9 for ; Wed, 16 Nov 2022 22:26:51 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1B7D93CD03B for ; Wed, 16 Nov 2022 12:26:49 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 3DACF3CD047 for ; Wed, 16 Nov 2022 12:26:27 +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 F259A60042C for ; Wed, 16 Nov 2022 12:26:26 +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 2AGAp1qt015165; Wed, 16 Nov 2022 11:26:25 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=BpGAA/UZtoo5NDRggMJcFdUeQMojpgbdfMqLOhfvezc=; b=stDu8Y8CpMdkcA9Ly48LNobMPUCVdSDo1pNiBr4JtwvxoKrfYIDfMePI5ZQ2bAugHSeD PxBlFSu/tVKMDx5oIN21m941tNpbBqJx3PEo+X3uBUlngUJKwE8JhxwraaYhT4qns0Ef kyXkToVpNbbINQdYqxKZ8ypDAw7HKSt2u7x/FiBBhtc/phsAixImJn37O55fx6tJHivV Na8z2+zuA9oMyo9xf03/eyUE8Q8BB2OlKPp/f40wSmRSnLf8Wo1RG3H5XJ6AuIteO0z8 oltMj5rOSVwtMYSnZIWEpfwgL1wwODAgkMRHNlUYFzQYmj3fAkVJGzG81pek6WeK3RsI 4g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxfmgw06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:25 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGAxBNk015719; Wed, 16 Nov 2022 11:26:24 GMT 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 3kvxfmgvyn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:24 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBLgEO008349; Wed, 16 Nov 2022 11:26:22 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04ams.nl.ibm.com with ESMTP id 3kt348wt25-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:22 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQxXa40632596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:59 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69B6242041; Wed, 16 Nov 2022 11:26:19 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 214744203F; Wed, 16 Nov 2022 11:26:17 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:16 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:11 +0530 Message-Id: <20221116112516.261535-3-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: sNxNPnInZbydeCQGoezry2jjkJP8oy1G X-Proofpoint-GUID: vFXqvKRBG8Nx-0FIYPHfUgSXaRV1bpVK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_02,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 suspectscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160078 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 v4 2/7] Hugetlb: Migrating libhugetlbfs counters 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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/counters.c test Test Description: This Test perform mmap and unmap and write operation on hugetlb file based mapping. Mapping can be shared or private. and it checks for Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo and compare them with expected (calculated) value. if all checks are successful, the test passes. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap10.c | 462 ++++++++++++++++++ 3 files changed, 464 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c diff --git a/runtest/hugetlb b/runtest/hugetlb index e2ada7a97..8a56d52a3 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -6,6 +6,7 @@ hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 hugemmap09 hugemmap09 +hugemmap10 hugemmap10 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 1a242ffe0..e7def68cb 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -7,6 +7,7 @@ /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 /hugetlb/hugemmap/hugemmap09 +/hugetlb/hugemmap/hugemmap10 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file mode 100644 index 000000000..a77db660f --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c @@ -0,0 +1,462 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2007 IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * + * This Test perform mmap and unmap and write operation on hugetlb file + * based mapping. Mapping can be shared or private. and it checks for + * Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo and + * compare them with expected (calculated) value. if all checks are + * successful, the test passes. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" + +#define CHECK_(fun) \ + { \ + if (fun) \ + break; \ + } + +static long hpage_size; +static int private_resv; + +#define NR_SLOTS 2 +#define SL_SETUP 0 +#define SL_TEST 1 +static int map_fd[NR_SLOTS]; +static char *map_addr[NR_SLOTS]; +static unsigned long map_size[NR_SLOTS]; +static unsigned int touched[NR_SLOTS]; + +static long prev_total; +static long prev_free; +static long prev_resv; +static long prev_surp; + +static void read_meminfo_huge(long *total, long *free, long *resv, long *surp) +{ + *total = SAFE_READ_MEMINFO(MEMINFO_HPAGE_TOTAL); + *free = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + *resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + *surp = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SURP); +} + +static int kernel_has_private_reservations(void) +{ + int fd; + long t, f, r, s; + long nt, nf, nr, ns; + void *map; + + read_meminfo_huge(&t, &f, &r, &s); + fd = tst_creat_unlinked(MNTPOINT, 0); + + map = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + + read_meminfo_huge(&nt, &nf, &nr, &ns); + + SAFE_MUNMAP(map, hpage_size); + SAFE_CLOSE(fd); + + /* + * There are only three valid cases: + * 1) If a surplus page was allocated to create a reservation, all + * four pool counters increment + * 2) All counters remain the same except for Hugepages_Rsvd, then + * a reservation was created using an existing pool page. + * 3) All counters remain the same, indicates that no reservation has + * been created + */ + if ((nt == t + 1) && (nf == f + 1) && (ns == s + 1) && (nr == r + 1)) + return 1; + else if ((nt == t) && (nf == f) && (ns == s)) { + if (nr == r + 1) + return 1; + else if (nr == r) + return 0; + } + tst_brk(TCONF, "bad counter state - " + "T:%li F:%li R:%li S:%li -> T:%li F:%li R:%li S:%li", + t, f, r, s, nt, nf, nr, ns); + return -1; +} + +static int verify_counters(int line, char *desc, long et, long ef, long er, long es) +{ + long t, f, r, s; + long fail = 0; + + read_meminfo_huge(&t, &f, &r, &s); + + if (t != et) { + tst_res(TFAIL, "At Line %i:While %s: Bad "MEMINFO_HPAGE_TOTAL + " expected %li, actual %li", line, desc, et, t); + fail++; + } + if (f != ef) { + tst_res(TFAIL, "At Line %i:While %s: Bad "MEMINFO_HPAGE_FREE + " expected %li, actual %li", line, desc, ef, f); + fail++; + } + if (r != er) { + tst_res(TFAIL, "At Line %i:While %s: Bad "MEMINFO_HPAGE_RSVD + " expected %li, actual %li", line, desc, er, r); + fail++; + } + if (s != es) { + tst_res(TFAIL, "At Line %i:While %s: Bad "MEMINFO_HPAGE_SURP + " expected %li, actual %li", line, desc, es, s); + fail++; + } + + if (fail) + return -1; + + prev_total = t; + prev_free = f; + prev_resv = r; + prev_surp = s; + return 0; +} + +/* Memory operations: + * Each of these has a predefined effect on the counters + */ +static int set_nr_hugepages_(long count, char *desc, int line) +{ + long min_size; + long et, ef, er, es; + + SAFE_FILE_PRINTF(PATH_NR_HPAGES, "%lu", count); + + /* The code below is based on set_max_huge_pages in mm/hugetlb.c */ + es = prev_surp; + et = prev_total; + ef = prev_free; + er = prev_resv; + + /* + * Increase the pool size + * First take pages out of surplus state. Then make up the + * remaining difference by allocating fresh huge pages. + */ + while (es && count > et - es) + es--; + while (count > et - es) { + et++; + ef++; + } + if (count >= et - es) + goto out; + + /* + * Decrease the pool size + * First return free pages to the buddy allocator (being careful + * to keep enough around to satisfy reservations). Then place + * pages into surplus state as needed so the pool will shrink + * to the desired size as pages become free. + */ + min_size = MAX(count, er + et - ef); + while (min_size < et - es) { + ef--; + et--; + } + while (count < et - es) + es++; + +out: + return verify_counters(line, desc, et, ef, er, es); +} +#define set_nr_hugepages(c, d) CHECK_(set_nr_hugepages_(c, d, __LINE__)) + +static int map_(int s, int hpages, int flags, char *desc, int line) +{ + long et, ef, er, es; + + map_fd[s] = tst_creat_unlinked(MNTPOINT, 0); + map_size[s] = hpages * hpage_size; + map_addr[s] = SAFE_MMAP(NULL, map_size[s], PROT_READ|PROT_WRITE, flags, + map_fd[s], 0); + touched[s] = 0; + + et = prev_total; + ef = prev_free; + er = prev_resv; + es = prev_surp; + /* + * When using MAP_SHARED, a reservation will be created to guarantee + * pages to the process. If not enough pages are available to + * satisfy the reservation, surplus pages are added to the pool. + * NOTE: This code assumes that the whole mapping needs to be + * reserved and hence, will not work with partial reservations. + * + * If the kernel supports private reservations, then MAP_PRIVATE + * mappings behave like MAP_SHARED at mmap time. Otherwise, + * no counter updates will occur. + */ + if ((flags & MAP_SHARED) || private_resv) { + unsigned long shortfall = 0; + + if (hpages + prev_resv > prev_free) + shortfall = hpages - prev_free + prev_resv; + et += shortfall; + ef += shortfall; + er += hpages; + es += shortfall; + } + + return verify_counters(line, desc, et, ef, er, es); +} +#define map(s, h, f, d) CHECK_(map_(s, h, f, d, __LINE__)) + +static int unmap_(int s, int hpages, int flags, char *desc, int line) +{ + long et, ef, er, es; + unsigned long i; + + SAFE_MUNMAP(map_addr[s], map_size[s]); + SAFE_CLOSE(map_fd[s]); + map_addr[s] = NULL; + map_size[s] = 0; + + et = prev_total; + ef = prev_free; + er = prev_resv; + es = prev_surp; + + /* + * When a VMA is unmapped, the instantiated (touched) pages are + * freed. If the pool is in a surplus state, pages are freed to the + * buddy allocator, otherwise they go back into the hugetlb pool. + * NOTE: This code assumes touched pages have only one user. + */ + for (i = 0; i < touched[s]; i++) { + if (es) { + et--; + es--; + } else + ef++; + } + + /* + * mmap may have created some surplus pages to accommodate a + * reservation. If those pages were not touched, then they will + * not have been freed by the code above. Free them here. + */ + if ((flags & MAP_SHARED) || private_resv) { + int unused_surplus = MIN(hpages - touched[s], es); + + et -= unused_surplus; + ef -= unused_surplus; + er -= hpages - touched[s]; + es -= unused_surplus; + } + + return verify_counters(line, desc, et, ef, er, es); +} +#define unmap(s, h, f, d) CHECK_(unmap_(s, h, f, d, __LINE__)) + +static int touch_(int s, int hpages, int flags, char *desc, int line) +{ + long et, ef, er, es; + int nr; + char *c; + + for (c = map_addr[s], nr = hpages; + hpages && c < map_addr[s] + map_size[s]; + c += hpage_size, nr--) + *c = (char) (nr % 2); + /* + * Keep track of how many pages were touched since we can't easily + * detect that from user space. + * NOTE: Calling this function more than once for a mmap may yield + * results you don't expect. Be careful :) + */ + touched[s] = MAX(touched[s], hpages); + + /* + * Shared (and private when supported) mappings and consume resv pages + * that were previously allocated. Also deduct them from the free count. + * + * Unreserved private mappings may need to allocate surplus pages to + * satisfy the fault. The surplus pages become part of the pool + * which could elevate total, free, and surplus counts. resv is + * unchanged but free must be decreased. + */ + if (flags & MAP_SHARED || private_resv) { + et = prev_total; + ef = prev_free - hpages; + er = prev_resv - hpages; + es = prev_surp; + } else { + if (hpages + prev_resv > prev_free) + et = prev_total + (hpages - prev_free + prev_resv); + else + et = prev_total; + er = prev_resv; + es = prev_surp + et - prev_total; + ef = prev_free - hpages + et - prev_total; + } + return verify_counters(line, desc, et, ef, er, es); +} +#define touch(s, h, f, d) CHECK_(touch_(s, h, f, d, __LINE__)) + +static int test_counters_(char *desc, int base_nr) +{ + int fail = 1; + + tst_res(TINFO, "%s...", desc); + + do { + set_nr_hugepages(base_nr, "initializing hugepages pool"); + + /* untouched, shared mmap */ + map(SL_TEST, 1, MAP_SHARED, "doing mmap shared with no touch"); + unmap(SL_TEST, 1, MAP_SHARED, "doing munmap on shared with no touch"); + + /* untouched, private mmap */ + map(SL_TEST, 1, MAP_PRIVATE, "doing mmap private with no touch"); + unmap(SL_TEST, 1, MAP_PRIVATE, "doing munmap private with on touch"); + + /* touched, shared mmap */ + map(SL_TEST, 1, MAP_SHARED, "doing mmap shared followed by touch"); + touch(SL_TEST, 1, MAP_SHARED, "touching the addr after mmap shared"); + unmap(SL_TEST, 1, MAP_SHARED, "doing munmap shared after touch"); + + /* touched, private mmap */ + map(SL_TEST, 1, MAP_PRIVATE, "doing mmap private followed by touch"); + touch(SL_TEST, 1, MAP_PRIVATE, "touching the addr after mmap private"); + unmap(SL_TEST, 1, MAP_PRIVATE, "doing munmap private after touch"); + + /* Explicit resizing during outstanding surplus */ + /* Consume surplus when growing pool */ + map(SL_TEST, 2, MAP_SHARED, "doing mmap to consume surplus"); + set_nr_hugepages(MAX(base_nr, 1), "setting hugepages pool to consume surplus"); + + /* Add pages once surplus is consumed */ + set_nr_hugepages(MAX(base_nr, 3), "Adding more pages after consuming surplus"); + + /* Release free huge pages first */ + set_nr_hugepages(MAX(base_nr, 2), "Releasing free huge pages"); + + /* When shrinking beyond committed level, increase surplus */ + set_nr_hugepages(base_nr, "increasing surplus counts"); + + /* Upon releasing the reservation, reduce surplus counts */ + unmap(SL_TEST, 2, MAP_SHARED, "reducing surplus counts"); + fail = 0; + } while (0); + + if (fail) + return -1; + tst_res(TINFO, "OK"); + return 0; +} + +#define test_counters(a, b) CHECK_(test_counters_(a, b)) + +static void per_iteration_cleanup(void) +{ + int nr; + + prev_total = 0; + prev_free = 0; + prev_resv = 0; + prev_surp = 0; + for (nr = 0; nr < NR_SLOTS; nr++) { + if (map_addr[nr]) + SAFE_MUNMAP(map_addr[nr], map_size[nr]); + if (map_fd[nr] > 0) + SAFE_CLOSE(map_fd[nr]); + } +} + +static void run_test(void) +{ + int base_nr; + + for (base_nr = 0; base_nr <= 3; base_nr++) { + tst_res(TINFO, "Base pool size: %i", base_nr); + /* Run the tests with a clean slate */ + test_counters("Clean", base_nr); + + /* Now with a pre-existing untouched, shared mmap */ + map(SL_SETUP, 1, MAP_SHARED, + "doing mmap for running pre-existing untouched shared mapping test"); + test_counters("Untouched, shared", base_nr); + unmap(SL_SETUP, 1, MAP_SHARED, + "doing munmap after running pre-existing untouched shared mapping test"); + + /* Now with a pre-existing untouched, private mmap */ + map(SL_SETUP, 1, MAP_PRIVATE, + "doing mmap for running pre-existing untouched private mapping test"); + test_counters("Untouched, private", base_nr); + unmap(SL_SETUP, 1, MAP_PRIVATE, + "doing munmap after running pre-existing untouced private mapping test"); + + /* Now with a pre-existing touched, shared mmap */ + map(SL_SETUP, 1, MAP_SHARED, + "doing mmap for running pre-existing touched shared mapping test"); + touch(SL_SETUP, 1, MAP_SHARED, + "touching for running pre-existing touched shared mapping test"); + test_counters("Touched, shared", base_nr); + unmap(SL_SETUP, 1, MAP_SHARED, + "doing munmap after running pre-existing touched shared mapping test"); + + /* Now with a pre-existing touched, private mmap */ + map(SL_SETUP, 1, MAP_PRIVATE, + "doing mmap for running pre-existing touched private mapping test"); + touch(SL_SETUP, 1, MAP_PRIVATE, + "touching for running pre-existing touched private mapping test"); + test_counters("Touched, private", base_nr); + unmap(SL_SETUP, 1, MAP_PRIVATE, + "doing munmap after running pre-existing touched private mapping test"); + } + if (base_nr > 3) + tst_res(TPASS, "Hugepages Counters works as expected."); + per_iteration_cleanup(); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; + SAFE_FILE_PRINTF(PATH_OC_HPAGES, "%lu", tst_hugepages); + private_resv = kernel_has_private_reservations(); +} + +static void cleanup(void) +{ + per_iteration_cleanup(); +} + +static struct tst_test test = { + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .save_restore = (const struct tst_path_val[]) { + {PATH_OC_HPAGES, NULL}, + {PATH_NR_HPAGES, NULL}, + {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {3, TST_NEEDS}, +}; + From patchwork Wed Nov 16 11:25:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704508 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=DT0F5AHo; 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 4NC13X6sk9z23n9 for ; Wed, 16 Nov 2022 22:27:04 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8C7BD3CD03D for ; Wed, 16 Nov 2022 12:27:02 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id D05E53CD039 for ; Wed, 16 Nov 2022 12:26:30 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id D475B600858 for ; Wed, 16 Nov 2022 12:26:29 +0100 (CET) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGAqpQx019690; Wed, 16 Nov 2022 11:26:28 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=apJblzrnSjzSUKt9DaZ/XyfCn77rKnDIzBssBY3NdOE=; b=DT0F5AHoCeKSYCAR4slpIQGCnjsLlRwojwRZUFv0eWPQR8xsH4vNxhssyUPRipWSV5V8 2BBgcKmmCa+z3PQCNdIRJeim6+GBh09aBbcUJlj4kkOI+VywINv+nt+dVthc1673T3P0 1wogTNF12O1r+zMT0sl9dBC8OhzBzER1DgZpNGU/qFfs1pKScYGpIYlouk3rkXfzVT71 WncWh30o64b++XPlfMim5oVGuKKQa7tG4M3o1lfspOxkSiE0qv6yUjRBHA/GLmIK4OwJ CGplJBxPUUT/5B+00MXZZcjD12dHxE5+zQmx7p2dCJzg7g2Qi5INvkC3nwhMyU1Q4fhF zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxgggtx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:27 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGArYQn022244; Wed, 16 Nov 2022 11:26:27 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxgggtwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:27 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBKuKB016928; Wed, 16 Nov 2022 11:26:25 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03fra.de.ibm.com with ESMTP id 3kt348vb5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:25 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBKMlO49611244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:20:22 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E94942042; Wed, 16 Nov 2022 11:26:22 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C38764203F; Wed, 16 Nov 2022 11:26:19 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:19 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:12 +0530 Message-Id: <20221116112516.261535-4-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YavMdoXvnI2-qAM2B7V1tYS32TUWGViu X-Proofpoint-ORIG-GUID: 31dBArmQ2zaUSRUy0z7qUtuH41UyC5mG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_02,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 phishscore=0 mlxscore=0 priorityscore=1501 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160074 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 v4 3/7] Hugetlb: Migrating libhugetlbfs directio 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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/direct.c test Test Description: This Test perform Direct Write/Read from/To hugetlbfs file which is mapped to process address space. The test is checking if it succeeds and data written or read is not corrupted. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap11.c | 87 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 8a56d52a3..b9ee7227d 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -7,6 +7,7 @@ hugemmap07 hugemmap07 hugemmap08 hugemmap08 hugemmap09 hugemmap09 hugemmap10 hugemmap10 +hugemmap11 hugemmap11 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 e7def68cb..3e64b67be 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -8,6 +8,7 @@ /hugetlb/hugemmap/hugemmap08 /hugetlb/hugemmap/hugemmap09 /hugetlb/hugemmap/hugemmap10 +/hugetlb/hugemmap/hugemmap11 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file mode 100644 index 000000000..48ecfe9d8 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * + * This Test perform Direct Write/Read from/To hugetlbfs file + * which is mapped to process address space. The test is checking if it + * succeeds and data written or read is not corrupted. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define P0 "ffffffff" +#define IOSZ 4096 +#define NORMAL_PATH "" +#define MNTPOINT "hugetlbfs/" + +static long hpage_size; +static int fd = -1, nfd = -1; + +static void run_test(void) +{ + void *p; + char buf[IOSZ] __attribute__((aligned(IOSZ))); + + fd = tst_creat_unlinked(MNTPOINT, 0); + nfd = tst_creat_unlinked(NORMAL_PATH, O_DIRECT); + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + memcpy(p, P0, 8); + + SAFE_WRITE(1, nfd, p, IOSZ); + SAFE_LSEEK(nfd, 0, SEEK_SET); + + SAFE_READ(1, nfd, buf, IOSZ); + if (memcmp(P0, buf, 8)) { + tst_res(TFAIL, "Memory mismatch after Direct-IO write"); + goto cleanup; + } + SAFE_LSEEK(nfd, 0, SEEK_SET); + + memset(p, 0, IOSZ); + SAFE_READ(1, nfd, p, IOSZ); + + if (memcmp(p, P0, 8)) + tst_res(TFAIL, "Memory mismatch after Direct-IO read"); + else + tst_res(TPASS, "Direct-IO write and read from/to hugepages is successful"); +cleanup: + SAFE_MUNMAP(p, hpage_size); + SAFE_CLOSE(fd); + SAFE_CLOSE(nfd); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); + if (nfd > 0) + SAFE_CLOSE(nfd); +} + +static struct tst_test test = { + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1, TST_NEEDS}, +}; From patchwork Wed Nov 16 11:25:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704510 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=mRFrJLSD; 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 4NC13w4kBkz23n9 for ; Wed, 16 Nov 2022 22:27:24 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A80D93CD035 for ; Wed, 16 Nov 2022 12:27:21 +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 896773CD057 for ; Wed, 16 Nov 2022 12:26: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-3.smtp.seeweb.it (Postfix) with ESMTPS id C48631A00CB7 for ; Wed, 16 Nov 2022 12:26:34 +0100 (CET) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGAnCFA011004; Wed, 16 Nov 2022 11:26:31 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=0QzW5V4ba/Pbt8JqGXX3Wv8Kp1Z1TT/JGN6Dkc+6Rn4=; b=mRFrJLSDwRWbJquU2n8HJJum5MqZMjuqKZZmT66T38AoGUmePGmpr1cIkMjDriU+pIoK SA6e2jDtowii7hIUm52vFwbiOvWyiJsCV3mKa4rzOeCDKWS7R1MkS5OSGpQiisJ6LgOp vEleSCwcXkgKRGQrafgIgKMcVHVaknCC6cxBSi7rXYK+G1t4GTuuPPZPfPPEcwm/WrFr vL6oT51ivlzfE7kSuMEE8NwIhfDwAVd/gdUDG2jdV7DQjDMkhltwJsLOjtZw3Y0Hjlw+ LxWCVnTssYEZEHXUPH3+D72u7flC3jSvaYGQ9RjYTS6Hpr1JKHF/7Ep53ixRzfgRiNAh 9w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxeg0wyt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:31 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGAoTWT016121; Wed, 16 Nov 2022 11:26:30 GMT 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 3kvxeg0wxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:30 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBKuKC016928; Wed, 16 Nov 2022 11:26:28 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 3kt348vb5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:27 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQOps67043826 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:24 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AEFBE4203F; Wed, 16 Nov 2022 11:26:24 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7047742047; Wed, 16 Nov 2022 11:26:22 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:22 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:13 +0530 Message-Id: <20221116112516.261535-5-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: avecAY3KVn3PzV9Ym8CfjVEIGj-p0QCc X-Proofpoint-ORIG-GUID: edhq-wsAlQlPR9F--_s6YoQqYCa07S6Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_01,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=871 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 malwarescore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160074 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 v4 4/7] Hugetlb: Safe macro for posix_fadvise call 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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This patch adds SAFE_POSIX_FADVISE for posix_fadvise call. Signed-off-by: Tarun Sahu --- include/tst_safe_macros.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index 81c4b0844..4965e44d0 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -298,6 +298,23 @@ static inline int safe_ftruncate(const char *file, const int lineno, #define SAFE_FTRUNCATE(fd, length) \ safe_ftruncate(__FILE__, __LINE__, (fd), (length)) +static inline int safe_posix_fadvise(const char *file, const int lineno, + int fd, off_t offset, off_t len, int advice) +{ + int rval; + + rval = posix_fadvise(fd, offset, len, advice); + + if (rval) + tst_brk_(file, lineno, TBROK | TERRNO, + "posix_fadvise(%d,%ld,%ld,%d) failed", + fd, (long)offset, (long)len, advice); + + return rval; +} +#define SAFE_POSIX_FADVISE(fd, offset, len, advice) \ + safe_posix_fadvise(__FILE__, __LINE__, (fd), (offset), (len), (advice)) + static inline int safe_truncate(const char *file, const int lineno, const char *path, off_t length) { From patchwork Wed Nov 16 11:25:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704509 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=cHrF8cjc; 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 4NC13k6bP0z23n9 for ; Wed, 16 Nov 2022 22:27:14 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9BAA33CD052 for ; Wed, 16 Nov 2022 12:27:12 +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 [IPv6:2001:4b78:1:20::6]) (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 58A653CD049 for ; Wed, 16 Nov 2022 12:26:36 +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-6.smtp.seeweb.it (Postfix) with ESMTPS id 53A1F1400C6B for ; Wed, 16 Nov 2022 12:26:34 +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 2AGBLXbL021296; Wed, 16 Nov 2022 11:26:33 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=nts7f3jfAvZI9IV3ObuihBQCIoZ56vAo7u0fFVGhqwM=; b=cHrF8cjcyoLBwSbpXhZ59tm7t9OaXxQZuo8PAJxn6XLYZu3FLNzsjutrUMcCDOqEi+/U NshSF3T4m+Orc0j8XsaV/w0Y+IWXh/JlKO88/DReqBMFD0b4emmBeTJ46abzO7Ujd2g+ BSBfRrqFDMcwkCoyHrQdyybdDQeUui8QSDNqw95KQDA3urC3TcFA4N9pt6qfGgecUgO3 2n1zmadx67c2+6nLZr3BbaGjicUxqv/sUZUJb3OGqeL7uzkI1odJMg7da+EtUiYbyd3e AyFqNspxhT8nsNEgaJaaZqTEwi+2LqJ5a97dPIXtnMyzN8RFoS5YQwkIfR7gca35ZCu7 5Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxwrg3gb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:32 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGBLVbm021254; Wed, 16 Nov 2022 11:26:32 GMT 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 3kvxwrg3fq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:32 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBKJrx027935; Wed, 16 Nov 2022 11:26:30 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06fra.de.ibm.com with ESMTP id 3kt2rj4buk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:30 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQRvl32243972 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:27 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C75A42041; Wed, 16 Nov 2022 11:26:27 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DCB14203F; Wed, 16 Nov 2022 11:26:25 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:24 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:14 +0530 Message-Id: <20221116112516.261535-6-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: -2GJcv6myOziBsRzyBAdZRQiRR_Ud-b6 X-Proofpoint-ORIG-GUID: _ycn2IKdmD0tbGzQgvL1fiVBg6BXzP0O X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_02,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 impostorscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160074 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 v4 5/7] Hugetlb: Migrating libhugetlbfs fadvise_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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/fadvise_reserve.c test Test Description: fadvise() 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's fixed in kernel by 'commit f2deae9d4e70 ("Remove implementation of readpage from the hugetlbfs_aops")' Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap12.c | 84 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c diff --git a/runtest/hugetlb b/runtest/hugetlb index b9ee7227d..b019c4195 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -8,6 +8,7 @@ hugemmap08 hugemmap08 hugemmap09 hugemmap09 hugemmap10 hugemmap10 hugemmap11 hugemmap11 +hugemmap12 hugemmap12 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 3e64b67be..ec250592d 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -9,6 +9,7 @@ /hugetlb/hugemmap/hugemmap09 /hugetlb/hugemmap/hugemmap10 /hugetlb/hugemmap/hugemmap11 +/hugetlb/hugemmap/hugemmap12 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file mode 100644 index 000000000..ae132107c --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 IBM Corporation. + * Author: Mel Gorman + */ + +/*\ + * [Description] + * + * fadvise() 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's fixed in kernel + * by commit f2deae9d4e70793568ef9e85d227abb7bef5b622. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +static long hpage_size; +static int fd = -1; + +static void run_test(void) +{ + void *p; + unsigned long initial_rsvd, map_rsvd, fadvise_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); + + SAFE_POSIX_FADVISE(fd, 0, hpage_size, POSIX_FADV_WILLNEED); + fadvise_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD); + tst_res(TINFO, "Reserve count after fadvise: %lu", fadvise_rsvd); + + memset(p, 1, hpage_size); + + 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(MEMINFO_HPAGE_SIZE)*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, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1, TST_NEEDS}, +}; From patchwork Wed Nov 16 11:25:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704511 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=ac8QGAT6; 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 4NC1461Rd9z23n9 for ; Wed, 16 Nov 2022 22:27:34 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D8C7E3CD035 for ; Wed, 16 Nov 2022 12:27:31 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C1FE23CD034 for ; Wed, 16 Nov 2022 12:26:39 +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 B2FD210005BD for ; Wed, 16 Nov 2022 12:26:38 +0100 (CET) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGAn4GQ010363; Wed, 16 Nov 2022 11:26: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=rj+Yi3fllLCrVDCYzy0K1UM6Ats3OlmPjPgn2+W5O0k=; b=ac8QGAT6u/c95eLA/HouSrNiR/Vt/PxlHn1IxkdXrDOyWx6hCnQrMOCvYl6nyCyupRes AV4fRntbwr0Fr1lqHdZN3mS1qUKH6td8mXe/uMwpYD9aZFSaDdRhm6H36JjA/RcU+69F R6wyUjU3+/MR+JiYw0JplkSNxMtET4L55lazRrWCej7En1fRPcdSMIkOFgjzsmk0wxHf qNnB8w7Phz5leL7oW+AJ55AgkeSWbfDPZmjC0WLYQtPmiihO4kA2eDtlgs/6QU3uwk7O gl5vZBlvpdUZ7HLlz6JT9evycjGRgigteqZafi5T0tc6eoP7V3Df8a1lnpv/An7wLDw7 bQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxeg0x1e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:36 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGAo79D014387; Wed, 16 Nov 2022 11:26:35 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxeg0x0u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:35 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBKeif016555; Wed, 16 Nov 2022 11:26:33 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3kt2rjdtqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:33 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQU6g62128430 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:30 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 09EFA4203F; Wed, 16 Nov 2022 11:26:30 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF86642041; Wed, 16 Nov 2022 11:26:27 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:27 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:15 +0530 Message-Id: <20221116112516.261535-7-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mc5Xs5CIocp-AUvAqaGYV4SGGdnvv6WG X-Proofpoint-ORIG-GUID: 1j91RtOx1gfZU5rNeAXFHrg4bHRjMBph X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_01,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 malwarescore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160074 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 v4 6/7] Hugetlb: Migrating libhugetlbfs fallocate_align 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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/fallocate_align.c test Test Description: It tests alignment of fallocate arguments. fallocate will take non-huge page aligned offsets and addresses. However, operations are only performed on huge pages. This is different that than fallocate behavior in "normal" filesystems. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 2 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefallocate/Makefile | 10 ++ .../hugetlb/hugefallocate/hugefallocate01.c | 169 ++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c diff --git a/runtest/hugetlb b/runtest/hugetlb index b019c4195..ca92dfcff 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -1,3 +1,5 @@ +hugefallocate01 hugefallocate01 + hugemmap01 hugemmap01 hugemmap02 hugemmap02 hugemmap04 hugemmap04 diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index ec250592d..cafdb5259 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -1,4 +1,5 @@ /cpuset/cpuset01 +/hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04 diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/Makefile b/testcases/kernel/mem/hugetlb/hugefallocate/Makefile new file mode 100644 index 000000000..77ebb0aef --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugefallocate/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/hugefallocate/hugefallocate01.c b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c new file mode 100644 index 000000000..1ec0dd000 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2015 Oracle Corporation + * Author: Mike Kravetz + */ + +/*\ + * [Description] + * + * It tests alignment of fallocate arguments. fallocate will take non-huge + * page aligned offsets and addresses. However, operations are only + * performed on huge pages. This is different that than fallocate + * behavior in "normal" filesystems. + * + */ + +#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) +{ + int err; + unsigned long free_initial, free_after, free_after_delete; + + fd = tst_creat_unlinked(MNTPOINT, 0); + + free_initial = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + + /* + * First preallocate file with just 1 byte. Allocation sizes + * are rounded up, so we should get an entire huge page. + */ + err = fallocate(fd, 0, 0, 1); + if (err) { + if (errno == EOPNOTSUPP) + tst_brk(TCONF, "Operation Not Supported"); + tst_res(TFAIL|TERRNO, "fallocate()"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_initial - free_after != 1) { + tst_res(TFAIL, "fallocate 1 byte did not preallocate entire huge page"); + goto cleanup; + } + + /* + * Now punch a hole with just 1 byte. On hole punch, sizes are + * rounded down. So, this operation should not create a hole. + */ + err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, 1); + if (err) { + tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_after == free_initial) { + tst_res(TFAIL, "fallocate hole punch 1 byte free'ed a huge page"); + goto cleanup; + } + + /* + * Now punch a hole with of 2 * hpage_size - 1 byte. This size + * should be rounded down to a single huge page and the hole created. + */ + err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, (2 * hpage_size) - 1); + if (err) { + tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_after != free_initial) { + tst_res(TFAIL, "fallocate hole punch 2 * hpage_size - 1 byte did not" + " free huge page"); + goto cleanup; + } + + /* + * Perform a preallocate operation with offset 1 and size of + * hpage_size. The offset should be rounded down and the + * size rounded up to preallocate two huge pages. + */ + err = fallocate(fd, 0, 1, hpage_size); + if (err) { + tst_res(TFAIL, "fallocate()"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_initial - free_after != 2) { + tst_res(TFAIL, "fallocate 1 byte offset, huge page size did not" + " preallocate two huge pages"); + goto cleanup; + } + + /* + * The hole punch code will only delete 'whole' huge pags that are + * in the specified range. The offset is rounded up, and (offset + * + size) is rounded down to determine the huge pages to be deleted. + * In this case, after rounding the range is (hpage_size, hpage_size). + * So, no pages should be deleted. + */ + err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 1, hpage_size); + if (err) { + tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_initial - free_after != 2) { + tst_res(TFAIL, "fallocate hole punch 1 byte offset, huge page size" + " incorrectly deleted a huge page"); + goto cleanup; + } + + /* + * To delete both huge pages, the range passed to hole punch must + * overlap the allocated pages + */ + err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, 2 * hpage_size); + if (err) { + tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)"); + goto cleanup; + } + + free_after_delete = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + TST_EXP_EQ_LU(free_after_delete, free_initial); +cleanup: + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .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 Wed Nov 16 11:25:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704514 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=fVvJ4EZJ; 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 4NC14M1FjFz23nB for ; Wed, 16 Nov 2022 22:27:47 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2359F3CD049 for ; Wed, 16 Nov 2022 12:27:44 +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 8AD343CD054 for ; Wed, 16 Nov 2022 12:26:40 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id B50211A00CA3 for ; Wed, 16 Nov 2022 12:26:39 +0100 (CET) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGBPeOf009815; Wed, 16 Nov 2022 11:26:38 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=hODmIogkps+ugJWIu3ioUlJhvwA6UiPKws/CfZsx918=; b=fVvJ4EZJCQ+zuWdu1C2n5wUszBjCdG2g6IKh3qZNptxcBSNi4CtJ2kkwOccHF3xPHET7 QpSNWJcVKvNmEDWlwD/ox441QFduZH6Pfq1zyT9vkTLRZcCxdWllF1HkQM6b2DOeClpj bLCmqAA2UMw2SuIozHWqn2l0tbmcpcIx6rbXUBF6UfGjNjFQGTxmypZ2fouHmV7s07g/ 8mMTbEFY7fdeQvOaeUDB2nVD5ox+vvTQRy9A1X155lHQEvFxTujETrxYXiiJdmkzXfsv 5kV8NTJnXozmRGIj+pPKnsLbqPLXb78ymUI7TaQKdjy0yvX5ffIpLc+vziRcK/5R2zLl Tg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxygr0f7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:38 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGBQbe0012411; Wed, 16 Nov 2022 11:26:37 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxygr0ev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:37 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBKd0c016550; Wed, 16 Nov 2022 11:26:35 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3kt2rjdtqv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:35 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQW7f37814712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:32 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 930D742045; Wed, 16 Nov 2022 11:26:32 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D3FD4203F; Wed, 16 Nov 2022 11:26:30 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:30 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:16 +0530 Message-Id: <20221116112516.261535-8-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vOMpkc8GpksqmmL3ucPk1MdcQhJ5VQt- X-Proofpoint-ORIG-GUID: yeaNBZQy9oT7nN8MYwglCXicEZN39rIE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_02,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 impostorscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160078 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 v4 7/7] Hugetlb: Migrating libhugetlbfs fallocate_basic 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, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/fallocate_basic.c test Test Description: It tests basic fallocate functionality in hugetlbfs. Preallocate huge pages to a file in hugetlbfs, and then remove the pages via hole punch. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../hugetlb/hugefallocate/hugefallocate02.c | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c diff --git a/runtest/hugetlb b/runtest/hugetlb index ca92dfcff..ec1fc2515 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -1,4 +1,5 @@ hugefallocate01 hugefallocate01 +hugefallocate02 hugefallocate02 hugemmap01 hugemmap01 hugemmap02 hugemmap02 diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index cafdb5259..c0906f3d3 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -1,5 +1,6 @@ /cpuset/cpuset01 /hugetlb/hugefallocate/hugefallocate01 +/hugetlb/hugefallocate/hugefallocate02 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04 diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c new file mode 100644 index 000000000..d1e11dcbe --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2015 Oracle Corporation + * Author: Mike Kravetz + */ + +/*\ + * [Description] + * + * It tests basic fallocate functionality in hugetlbfs. Preallocate huge + * pages to a file in hugetlbfs, and then remove the pages via hole punch. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MAX_PAGES_TO_USE 5 +#define MNTPOINT "hugetlbfs/" + +static int fd = -1; +static long hpage_size; + +static void run_test(void) +{ + int err; + unsigned long max_iterations; + unsigned long free_initial, free_after, free_end; + + free_initial = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + max_iterations = MIN(free_initial, MAX_PAGES_TO_USE); + + fd = tst_creat_unlinked(MNTPOINT, 0); + + /* First preallocate file with max_iterations pages */ + err = fallocate(fd, 0, 0, hpage_size * max_iterations); + if (err) { + if (errno == EOPNOTSUPP) + tst_brk(TCONF, "fallocate() Operation is not supported"); + tst_res(TFAIL|TERRNO, "fallocate()"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_initial - free_after != max_iterations) { + tst_res(TFAIL, "fallocate did not preallocate %lu huge pages", + max_iterations); + goto cleanup; + } + + /* Now punch a hole of the same size */ + err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, hpage_size * max_iterations); + if (err) { + tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)"); + goto cleanup; + } + + free_end = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + TST_EXP_EQ_LU(free_end, free_initial); +cleanup: + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {3, TST_NEEDS}, +};