From patchwork Tue Nov 8 19:52: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: 1701469 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=oQVx5T/2; 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 4N6Jfc2YQZz23lT for ; Wed, 9 Nov 2022 06:52:40 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AEABF3CD8D8 for ; Tue, 8 Nov 2022 20:52:37 +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 [217.194.8.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 1AF263CD936 for ; Tue, 8 Nov 2022 20:52:30 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id E6C84600A2A for ; Tue, 8 Nov 2022 20:52:28 +0100 (CET) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8Jm8EZ027639; Tue, 8 Nov 2022 19:52:26 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=EFZCoQlEfduAmcuYHBPdcgHuBjauBP7FDwfSt9uBHS4=; b=oQVx5T/2C+FO4kDOAF5KAteYLouUr/xPrK3zGpA9rMVCHwk9Ct6Z22omzeS1Bur2ouMq 0kkUhuK+524jsMmRJt6/VQAuk6cmgPEsZTbl3zoE8+SMxgBvvK6EcEulhpk0jmwGdTRV 7GCm8JkSa8tn0c1XxhMV6H1fXfylmc8acIAzQUkFw3HXgHT1lSoyAKKXYBcx1vXI92ms IpyPb0iXghFqkSFC3+fh2LE8FpRoq/Zqro4T8BhAq1I0QjpzOaKmdoKOdPtw0LkB9ydj 9cziYKOBcAVTZE9PE7weLC7XQxNg5J3ckDnMPIn6dpqe/M2jO+8GG35QZenVpjkbq/t9 7Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqwkd833m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:25 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2A8JnKCd002992; Tue, 8 Nov 2022 19:52:25 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 3kqwkd832y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:24 +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 2A8JqMS4012110; Tue, 8 Nov 2022 19:52:22 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 3kngp5kc86-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:22 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A8JqJZ6918174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Nov 2022 19:52:19 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51915A404D; Tue, 8 Nov 2022 19:52:19 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E04B9A4040; Tue, 8 Nov 2022 19:52:14 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.4.5]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Nov 2022 19:52:14 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 9 Nov 2022 01:22:03 +0530 Message-Id: <20221108195207.232115-2-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108195207.232115-1-tsahu@linux.ibm.com> References: <20221108195207.232115-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: GU6Qu0nuXZvAfqi9gnpYR8ytMC_vzZOK X-Proofpoint-GUID: m_ss48F3xC4K72SOt1VYXsplA8VL74vc 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-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 spamscore=0 clxscore=1015 phishscore=0 impostorscore=0 mlxscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080125 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 1/5] 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 | 438 ++++++++++++++++++ 3 files changed, 440 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..dacfee8ce --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c @@ -0,0 +1,438 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2007 IBM Corporation. + * Author: David Gibson & Adam Litke + */ + +/*\ + * [Description] + * + * Counters: + * 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 + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" + +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 jmp_buf buf; + +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); + + 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; + } else + tst_brk(TCONF, "bad counter state - " + "T:%li F:%li R:%li S:%li -> T:%li F:%li R:%li S:%li\n", + t, f, r, s, nt, nf, nr, ns); + return -1; +} + +static void verify_counters(int line, long et, long ef, long er, long es) +{ + long t, f, r, s; + long c, ec; + char *huge_info_name; + + read_meminfo_huge(&t, &f, &r, &s); + + if (t != et) { + c = t; + ec = et; + huge_info_name = MEMINFO_HPAGE_TOTAL; + } else if (f != ef) { + c = f; + ec = ef; + huge_info_name = MEMINFO_HPAGE_FREE; + } else if (r != er) { + c = r; + ec = er; + huge_info_name = MEMINFO_HPAGE_RSVD; + } else if (s != es) { + c = s; + ec = es; + huge_info_name = MEMINFO_HPAGE_SURP; + } else { + prev_total = t; + prev_free = f; + prev_resv = r; + prev_surp = s; + return; + } + + tst_res(TFAIL, "Failure Line %i: Bad %s expected %li, actual %li", + line, huge_info_name, ec, c); + longjmp(buf, 1); +} + +/* Memory operations: + * Each of these has a predefined effect on the counters + */ +static void set_nr_hugepages_(long count, 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: + verify_counters(line, et, ef, er, es); +} +#define set_nr_hugepages(c) set_nr_hugepages_(c, __LINE__) + +static void map_(int s, int hpages, int flags, int line) +{ + long et, ef, er, es; + + map_fd[s] = tst_creat_unlinked(MNTPOINT); + 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; + } + + verify_counters(line, et, ef, er, es); +} +#define map(s, h, f) map_(s, h, f, __LINE__) + +static void unmap_(int s, int hpages, int flags, 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; + } + + verify_counters(line, et, ef, er, es); +} +#define unmap(s, h, f) unmap_(s, h, f, __LINE__) + +static void touch_(int s, int hpages, int flags, 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; + } + verify_counters(line, et, ef, er, es); +} +#define touch(s, h, f) touch_(s, h, f, __LINE__) + +static void test_counters(char *desc, int base_nr) +{ + tst_res(TINFO, "%s...", desc); + set_nr_hugepages(base_nr); + + /* untouched, shared mmap */ + map(SL_TEST, 1, MAP_SHARED); + unmap(SL_TEST, 1, MAP_SHARED); + + /* untouched, private mmap */ + map(SL_TEST, 1, MAP_PRIVATE); + unmap(SL_TEST, 1, MAP_PRIVATE); + + /* touched, shared mmap */ + map(SL_TEST, 1, MAP_SHARED); + touch(SL_TEST, 1, MAP_SHARED); + unmap(SL_TEST, 1, MAP_SHARED); + + /* touched, private mmap */ + map(SL_TEST, 1, MAP_PRIVATE); + touch(SL_TEST, 1, MAP_PRIVATE); + unmap(SL_TEST, 1, MAP_PRIVATE); + + /* Explicit resizing during outstanding surplus */ + /* Consume surplus when growing pool */ + map(SL_TEST, 2, MAP_SHARED); + set_nr_hugepages(MAX(base_nr, 1)); + + /* Add pages once surplus is consumed */ + set_nr_hugepages(MAX(base_nr, 3)); + + /* Release free huge pages first */ + set_nr_hugepages(MAX(base_nr, 2)); + + /* When shrinking beyond committed level, increase surplus */ + set_nr_hugepages(base_nr); + + /* Upon releasing the reservation, reduce surplus counts */ + unmap(SL_TEST, 2, MAP_SHARED); + tst_res(TINFO, "OK"); +} + +static void per_iteration_cleanup(void) +{ + int nr = 0; + + prev_total = 0; + prev_free = 0; + prev_resv = 0; + prev_surp = 0; + for (; nr < NR_SLOTS; nr++) { + if (map_fd[nr] > 0) + SAFE_CLOSE(map_fd[nr]); + } +} + +static void run_test(void) +{ + int base_nr = 0; + + SAFE_FILE_PRINTF(PATH_OC_HPAGES, "%lu", tst_hugepages); + private_resv = kernel_has_private_reservations(); + + if (setjmp(buf)) + goto cleanup; + + 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); + test_counters("Untouched, shared", base_nr); + unmap(SL_SETUP, 1, MAP_SHARED); + + /* Now with a pre-existing untouched, private mmap */ + map(SL_SETUP, 1, MAP_PRIVATE); + test_counters("Untouched, private", base_nr); + unmap(SL_SETUP, 1, MAP_PRIVATE); + + /* Now with a pre-existing touched, shared mmap */ + map(SL_SETUP, 1, MAP_SHARED); + touch(SL_SETUP, 1, MAP_SHARED); + test_counters("Touched, shared", base_nr); + unmap(SL_SETUP, 1, MAP_SHARED); + + /* Now with a pre-existing touched, private mmap */ + map(SL_SETUP, 1, MAP_PRIVATE); + touch(SL_SETUP, 1, MAP_PRIVATE); + test_counters("Touched, private", base_nr); + unmap(SL_SETUP, 1, MAP_PRIVATE); + } + tst_res(TPASS, "Hugepages Counters works as expected."); +cleanup: + per_iteration_cleanup(); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; +} + +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 Tue Nov 8 19:52: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: 1701470 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=fIBMa/lc; 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 4N6Jfp6dxTz23lT for ; Wed, 9 Nov 2022 06:52:50 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 74B723CD900 for ; Tue, 8 Nov 2022 20:52:48 +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 049433CD92B for ; Tue, 8 Nov 2022 20:52:31 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id 2FA671000994 for ; Tue, 8 Nov 2022 20:52:30 +0100 (CET) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8JDPoo024339; Tue, 8 Nov 2022 19:52:29 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=pNDtVvT2C88e4L2TNyEx9G+OGZxydi6xaq2c4ERuXq0=; b=fIBMa/lcWeSKKS+gpGaC5I5wzVP8xzSdLrcvhUBH3Rp9uCJeythGbye1R1lIBX0A5RFy b+OWaiOgA02KWekhPecrgYl7oJg1pL1VvijRZpBwIOGe6tEGgZGEVR9wzkYZGRPs963S wIL2GBxyi3BcIwclY6VxCy+8uTh62Pa15acFND/6knelGErGvJ5gBdBLgTp5UdGXg2qg eVmIIZRDv/JtlZaRGqHU2sqGOH6s51FNSwHB2D5p5MscXviB/n73AkPNCA76NaObY4FZ KrYv0oSdT7CeXaLEjEIHnQ2uZ97/SfeAfOM9RemqlSKmiDqdwJ0uHbIEOrE6Dyq+ZZLc 6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqw2urxj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:28 +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 2A8JEV8U027404; Tue, 8 Nov 2022 19:52:28 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqw2urxhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:28 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2A8JpUv4005250; Tue, 8 Nov 2022 19:52:26 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma02fra.de.ibm.com with ESMTP id 3kngpgkbwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:26 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A8Jr1Y748890256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Nov 2022 19:53:01 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86DA7A404D; Tue, 8 Nov 2022 19:52:23 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA5B3A4040; Tue, 8 Nov 2022 19:52:19 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.4.5]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Nov 2022 19:52:19 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 9 Nov 2022 01:22:04 +0530 Message-Id: <20221108195207.232115-3-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108195207.232115-1-tsahu@linux.ibm.com> References: <20221108195207.232115-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 6FcJ0zNAkLe7WjjewWGRYzVTDE3mSiK9 X-Proofpoint-ORIG-GUID: _mLHFZRtB96MlpR-plZJrVnOQtIaMEcj 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-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080125 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 2/5] 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..357c61ab9 --- /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); + nfd = tst_creat_unlinked(NORMAL_PATH); + 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, "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 Tue Nov 8 19:52: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: 1701471 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=B8a8bhAp; 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 4N6Jg35N4zz23lT for ; Wed, 9 Nov 2022 06:53:03 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 905063CD926 for ; Tue, 8 Nov 2022 20:53:01 +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 [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 791543CD912 for ; Tue, 8 Nov 2022 20:52: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 A07A110009AF for ; Tue, 8 Nov 2022 20:52:35 +0100 (CET) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8JQL0a005524; Tue, 8 Nov 2022 19:52: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=FxzXIx2/eNYNpk7UzKcj96G8+H4zT7KLP7oZgCf8kDc=; b=B8a8bhApKjQto9HO6+tUtLAOj2kbt3PBVzS1x2GnLW6VN1Y1aLb7M1J1l/7X7+XVCbil nf0hHOTJRSOALHjzx0SRWzKhYvjxBO2rlnv1tXyO1fMV9JHeVymMEi24uXK6YJ8eu+kM dfGHorCsmCK2d3JscsQvvLQUc4UwG6wW8yBzu2TpA9bNt0pMN3i8dEZayCvqMgkDREOL sM4DCm1bzO0d+zBYxK5QbI+mrBNMxggSoqTN6RCK2LwkhP23gez0WiPMGP0rZVTP3D1x B+urrxf30pI/i/preadcXM4vetIoDYb3kDldR1/vNt/YtxI6f+cNA6YCUKTamA+DjMsF tQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqsrv0gnq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:33 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2A8JSiLa005410; Tue, 8 Nov 2022 19:52:32 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 3kqsrv0gmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:32 +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 2A8JoRS6011431; Tue, 8 Nov 2022 19:52:30 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3kngnccn4w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:30 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A8JqRdK27787920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Nov 2022 19:52:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44AB5A404D; Tue, 8 Nov 2022 19:52:27 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24B65A4040; Tue, 8 Nov 2022 19:52:24 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.4.5]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Nov 2022 19:52:23 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 9 Nov 2022 01:22:05 +0530 Message-Id: <20221108195207.232115-4-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108195207.232115-1-tsahu@linux.ibm.com> References: <20221108195207.232115-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: uGJwFS0tt-5KlJEzwgGOELaQYrgsvaTJ X-Proofpoint-GUID: lWVnfM9vZxDkh7yzglBFKgwcEhvXP38h 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-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 suspectscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080125 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 3/5] 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 | 93 +++++++++++++++++++ 3 files changed, 95 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..9dec80029 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c @@ -0,0 +1,93 @@ +// 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); + + 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 (posix_fadvise(fd, 0, hpage_size, POSIX_FADV_WILLNEED) == -1) { + tst_res(TFAIL|TERRNO, "fadvise()"); + goto cleanup; + } + 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); + p = NULL; + 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); +cleanup: + if (p) + SAFE_MUNMAP(p, hpage_size); + if (fd > 0) + 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 = { + .tags = (struct tst_tag[]) { + {"linux-git", "f2deae9d4e70793568ef9e85d227abb7bef5b622"}, + {} + }, + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1, TST_NEEDS}, +}; From patchwork Tue Nov 8 19:52: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: 1701472 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=OsBcNYiy; 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 4N6JgF4DbPz23lT for ; Wed, 9 Nov 2022 06:53:13 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E5F363CD907 for ; Tue, 8 Nov 2022 20:53:10 +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 D5D633CD8FD for ; Tue, 8 Nov 2022 20:52:41 +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 0F345100094A for ; Tue, 8 Nov 2022 20:52:40 +0100 (CET) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8JgXav024281; Tue, 8 Nov 2022 19:52:39 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=+8QPV5NGwpQFhMyRgy3iAboWO5PzokIj/K4rAE7g6gI=; b=OsBcNYiyDapINcKfkNQHZeQo/WjoQB9APc9Jyuc8QE45AvO29/edkHaq47RVePLeuUJI qF4Br17qnttdz63P9TiLniKKX6TICVSRmf780xKzyJKIwIPcALNCktuVpdNsk5pyS8gP r0cuTfDFGolJZXxQ6NzD1fn+BGSPcxMGOeyp8v0/iu5oyJacgapeJf5C/929aMCIShmU c/7E253lQX4YiqUyTF4igghLBrg/mCTd/iBj9TnsRck2yoaOZxlJ1X/WVTm5NCXqmZLd QkRa4f09lay7wskK2lfWHNMag90VB5fbgWzNI0W5e3ZaaSQ8J3fevt5TK4nwvPfCxJTX nQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqwggr85a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:38 +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 2A8Jj8Qt001080; Tue, 8 Nov 2022 19:52:38 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqwggr847-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:38 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2A8JpMD7005239; Tue, 8 Nov 2022 19:52:35 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma02fra.de.ibm.com with ESMTP id 3kngpgkbx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:35 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A8JqWgJ8258228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Nov 2022 19:52:32 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C275A4051; Tue, 8 Nov 2022 19:52:32 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA51BA4040; Tue, 8 Nov 2022 19:52:27 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.4.5]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Nov 2022 19:52:27 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 9 Nov 2022 01:22:06 +0530 Message-Id: <20221108195207.232115-5-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108195207.232115-1-tsahu@linux.ibm.com> References: <20221108195207.232115-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: rrhU8Ld5Mll6maXPoN4PUXVusGLPg0Bq X-Proofpoint-GUID: Ed_muLd3zju8q3-Wy3-mG7S-kve-rddL 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-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 priorityscore=1501 phishscore=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 impostorscore=0 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080125 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 4/5] 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..994abb770 --- /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); + + 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 Tue Nov 8 19:52: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: 1701473 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=QqwGvEHi; 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 4N6JgS0QvMz23lT for ; Wed, 9 Nov 2022 06:53:24 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CD57A3CD918 for ; Tue, 8 Nov 2022 20:53:21 +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 7C1433CD920 for ; Tue, 8 Nov 2022 20:52:44 +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 798E46005DA for ; Tue, 8 Nov 2022 20:52:42 +0100 (CET) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A8JQJXF029437; Tue, 8 Nov 2022 19:52:41 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=em25zatp276zcdjeIXx0EVdvJxORSfZpY7L4zsi2X0A=; b=QqwGvEHi5Bw203DUkHS2JJZkaGW3I+R1aJsFm3x6VIcz0My2P7Ml8qk5FYMNomntzbqx jULwJQRwsUfe489Uhs/vhgR42ILn6rCpy27UEBq/xn/jLaJD3iDW9gxSJF5ddX/2Lc2q 5Y3nIWq21rD5HSDq53hP+5vjo95ynWwevb1OebBOuENFz/IWAvnS5XnjZ1ZC6TeneC2F GCR7Dli6ZrDF+6ayJ9sCknuThS8pQVPcZiiEaYxsT3ir61EXXHUpnt4uMu3fPMN9Dd4B t9+PpPKAKiPcYEkLJYbz5q3/A6efxBX6J9JSN0Q9eopQWwP5LEzfIUEZ9NWrUWOVusBm TA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqth463e8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:41 +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 2A8JdQnJ024477; Tue, 8 Nov 2022 19:52:41 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kqth463dj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:41 +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 2A8JpLkf026723; Tue, 8 Nov 2022 19:52:39 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 3kngqdckmk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 19:52:39 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A8Jqa2L55509404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Nov 2022 19:52:36 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2DC2A4040; Tue, 8 Nov 2022 19:52:35 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9E67EA404D; Tue, 8 Nov 2022 19:52:32 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.4.5]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 8 Nov 2022 19:52:32 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 9 Nov 2022 01:22:07 +0530 Message-Id: <20221108195207.232115-6-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108195207.232115-1-tsahu@linux.ibm.com> References: <20221108195207.232115-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: WbRzpAAris-jf6rMrjwR00r5Ls1RNbxR X-Proofpoint-ORIG-GUID: Puce1K8ESKxwCn8LMYEkqG55dv-7KTib 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-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080125 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 5/5] 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..c8f8f87c9 --- /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); + + /* 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}, +};