From patchwork Sun Apr 21 10:24:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geetika X-Patchwork-Id: 1925896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=D8RNXASj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VMkyp4JzGz1yZP for ; Sun, 21 Apr 2024 20:24:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3D06F3CFA2F for ; Sun, 21 Apr 2024 12:24:39 +0200 (CEST) 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 (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C4F8E3C0F50 for ; Sun, 21 Apr 2024 12:24:36 +0200 (CEST) Authentication-Results: in-2.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=geetika@linux.ibm.com; receiver=lists.linux.it) 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 EF970600ECF for ; Sun, 21 Apr 2024 12:24:34 +0200 (CEST) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43LAFFDH002700 for ; Sun, 21 Apr 2024 10:24:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=pp1; bh=CkAF9UAH+TYyPvQ512C9KvLQuTnIP3Xw9GCXBJkZzIE=; b=D8RNXASj9lGaq7S4pSQppHrKpGqVumhyeC8RLs6/RnXoo7YFZ1HQFjgy+sBNJEZZ3Ymq lqhRfLDBbo9ZyGgxDMfdPHlirwTmpK1eoay3juvIajGfgRw1igfliWGEi2g98ssSZXpj igeJpK4QbFctLoK7byoDtWehGmeq04DiemnXZdZvgWSRrftBzJ5awLur4WStyCk/AjOl +Ne0Ne4wTmy4ZFiLdspx5beWivMBdboUN64LRPKFtJ1wYfxuQYbwo0yYTey4eLakTxVP 207tt9uNUgwo7tF+y/QapSNdeuo1lLz0BjCik30o0fBmT2CKNFziQerviVmUuokQidKe LA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xn0u880au-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 21 Apr 2024 10:24:31 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43L7QH2D028740 for ; Sun, 21 Apr 2024 10:24:31 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xmtr21gjc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 21 Apr 2024 10:24:30 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43LAOPBU49218000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 21 Apr 2024 10:24:27 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6AD920043; Sun, 21 Apr 2024 10:24:25 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A815820040; Sun, 21 Apr 2024 10:24:24 +0000 (GMT) Received: from localhost.localdomain (unknown [9.43.123.5]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTPS; Sun, 21 Apr 2024 10:24:24 +0000 (GMT) From: Geetika To: ltp@lists.linux.it Date: Sun, 21 Apr 2024 15:54:20 +0530 Message-Id: <20240421102420.97060-1-geetika@linux.ibm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 1DZN24_555JX8Yq0G7CzeUzIdARR7uuF X-Proofpoint-ORIG-GUID: 1DZN24_555JX8Yq0G7CzeUzIdARR7uuF X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-21_10,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404210066 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DMARC_PASS,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-2.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] Add hugeshmmisc01, migrated shm-getraw.c from libhugetlbfs 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This test is migrated from : https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/shm-getraw.c The test creates a shared memory segment, then attaches it to the process’s address space. It writes a string to the shared memory from raw device and detaches the shared memory segment and finally removes it. The purpose of this test is to ensure that the shared memory subsystem is working correctly with hugepages. It checks that shared memory segments can be created, attached, written to, read from, detached, and removed without errors. Signed-off-by: Geetika --- runtest/hugetlb | 2 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugeshmmisc/Makefile | 9 ++ .../mem/hugetlb/hugeshmmisc/hugeshmmisc01.c | 134 ++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugeshmmisc/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugeshmmisc/hugeshmmisc01.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 299c07ac9..ea18f6ef6 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -55,3 +55,5 @@ hugeshmget01 hugeshmget01 -i 10 hugeshmget02 hugeshmget02 -i 10 hugeshmget03 hugeshmget03 -i 10 hugeshmget05 hugeshmget05 -i 10 + +hugeshmmisc01 hugeshmmisc01 diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index c96fe8bfc..493679ae6 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -47,6 +47,7 @@ /hugetlb/hugeshmget/hugeshmget02 /hugetlb/hugeshmget/hugeshmget03 /hugetlb/hugeshmget/hugeshmget05 +/hugetlb/hugeshmmisc/hugeshmmisc01 /ksm/ksm01 /ksm/ksm02 /ksm/ksm03 diff --git a/testcases/kernel/mem/hugetlb/hugeshmmisc/Makefile b/testcases/kernel/mem/hugetlb/hugeshmmisc/Makefile new file mode 100644 index 000000000..84715c7b5 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugeshmmisc/Makefile @@ -0,0 +1,9 @@ +# 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/hugeshmmisc/hugeshmmisc01.c b/testcases/kernel/mem/hugetlb/hugeshmmisc/hugeshmmisc01.c new file mode 100644 index 000000000..15867f251 --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugeshmmisc/hugeshmmisc01.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. + */ + +/*\ + *[Descripiton] + * + * Origin: https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/shm-getraw.c + * + * The test creates a shared memory segment, then attaches it to the process’s address space. + * It writes a string to the shared memory from raw device and detaches the shared memory + * segment and finally removes it. + * The purpose of this test is to ensure that the shared memory subsystem is working correctly + * with hugepages. It checks that shared memory segments can be created, attached, written to, + * read from, detached, and removed without errors + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hugetlb.h" +#include "tst_safe_sysv_ipc.h" + +#define MNTPOINT "hugetlbfs/" +#define SAFE_FREE(p) { if (p) { free(p); (p) = NULL; } } +#define NR_HUGEPAGES 2 + +static int shmid = -1; +static size_t size; +static size_t i; +static size_t ret; + +static volatile char *shmaddr; +static char *buffer; +static int raw_fd; +static long hpage_size; +static int fd; + +static void setup(void) +{ + hpage_size = tst_get_hugepage_size(); + fd = tst_creat_unlinked(MNTPOINT, 0); +} + +static void cleanup(void) +{ + if (shmid >= 0) + SAFE_SHMCTL(shmid, IPC_RMID, NULL); + if (fd > 0) + SAFE_CLOSE(fd); +} + +static void check_hugetlb_shm_group(void) +{ + char gid_buffer[64] = {0}; + gid_t hugetlb_shm_group; + gid_t gid = getgid(); + uid_t uid = getuid(); + + /* root is an exception */ + if (uid == 0) + return; + + fd = SAFE_OPEN("/proc/sys/vm/hugetlb_shm_group", O_RDONLY); + ret = SAFE_READ(0, fd, &gid_buffer, sizeof(gid_buffer)); + hugetlb_shm_group = atoi(gid_buffer); + SAFE_CLOSE(fd); + if (hugetlb_shm_group != gid) + tst_brk(TCONF, "Do not have permission to use SHM_HUGETLB"); +} + +static void run_test(void) +{ + check_hugetlb_shm_group(); + buffer = SAFE_MALLOC(hpage_size*sizeof(char)); + raw_fd = SAFE_OPEN("/dev/full", O_RDONLY); + size = hpage_size * NR_HUGEPAGES; + tst_res(TINFO, "Requesting %zu bytes\n", size); + + shmid = shmget(2, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W); + if (shmid < 0) { + tst_res(TFAIL | TERRNO, "shmget() failed with error "); + goto windup; + } else + tst_res(TINFO, "shmid: 0x%x\n", shmid); + + shmaddr = shmat(shmid, 0, SHM_RND); + if (shmaddr == MAP_FAILED) { + tst_res(TFAIL | TERRNO, "shmat() failed with error "); + goto windup; + } else + tst_res(TINFO, "shmaddr: %p\n", shmaddr); + + /* Read a page from device and write to shm segment */ + for (i = 0; i < size; i += hpage_size) { + if (!read(raw_fd, buffer, hpage_size)) { + tst_res(TFAIL | TERRNO, "Can't read from raw device!"); + goto windup; + } + memcpy((char *)(shmaddr + i), buffer, hpage_size); + } + + if (shmdt((const void *)shmaddr) != 0) { + tst_res(TFAIL | TERRNO, "shmdt() failed"); + goto windup; + } + + tst_res(TPASS, "Test Passed!"); +windup: + SAFE_FREE(buffer); +} + +static struct tst_test test = { + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2, TST_NEEDS}, +};