From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 759A0C4332F for ; Thu, 3 Nov 2022 05:44:30 +0000 (UTC) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2354A3CACB4 for ; Thu, 3 Nov 2022 06:44:29 +0100 (CET) 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 BCED33CACBD for ; Thu, 3 Nov 2022 06:43:49 +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 EB6CC100099D for ; Thu, 3 Nov 2022 06:43:48 +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 2A34r1OO027739; Thu, 3 Nov 2022 05:43:47 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=jkLhgDCpqGHKriygFCTxqeNOT4Yu5XLEvVo8KYF/Yww=; b=XUL8iHBsMaQ/K2AM0BSN5y58oscq3iKJymtDhbmvk1neJw+zbiI5uJuD+wGRrfGNb3YT FK6ltDcp5okl1q7sipC7bM9d8mpdYeO4uxvoBBzqExnhAzMaAXufy0SB3IyZ0JP2n/2e tDbxpP3fX030Kqv2Il0zrrJ0zYPJFaJ9cNMEC5drr0VsjcMPYPRyQLoXWCT2N+0ic6/2 Hfv2f+WakB4qlzFnZr2v5YEdpjJiaWPlqsnKJExF3b66IUisb5MOXH/LqJXew1+hvKfZ RvgaTtRne7+A6F/IW87oodzLQG3jR/FXjgXg2+QBBM0/FB4srUwnCaKByuatLtbfZix6 uQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3km70s1g00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Nov 2022 05:43:46 +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 2A35SDHV003906; Thu, 3 Nov 2022 05:43:46 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 3km70s1fxn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Nov 2022 05:43:45 +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 2A35ZZUI010964; Thu, 3 Nov 2022 05:43:43 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 3kguej05bs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Nov 2022 05:43:43 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A35iHIx45482262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Nov 2022 05:44:17 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88BE44C040; Thu, 3 Nov 2022 05:43:40 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 03D334C044; Thu, 3 Nov 2022 05:43:37 +0000 (GMT) Received: from tarunpc.ibmuc.com (unknown [9.43.64.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 3 Nov 2022 05:43:36 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Thu, 3 Nov 2022 11:13:17 +0530 Message-Id: <20221103054317.499221-5-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221103054317.499221-1-tsahu@linux.ibm.com> References: <20221103054317.499221-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 1nZBsVUbX0I92Qeikpa3kwwrSu8bUCm9 X-Proofpoint-ORIG-GUID: IwI9MKKr9B_d5RCIfyAJ_P6APdCbmITA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-02_15,2022-11-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxlogscore=964 suspectscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211030039 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v6 4/4] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, rpalethorpe@suse.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/corrupt-by-cow-opt.c test Test Description: Test sanity of cow optimization on page cache. If a page in page cache has only 1 ref count, it is mapped for a private mapping directly and is overwritten freely, so next time we access the page, we can see corrupt data. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c diff --git a/runtest/hugetlb b/runtest/hugetlb index 664f18827..e2ada7a97 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -5,6 +5,7 @@ hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 +hugemmap09 hugemmap09 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 003ce422b..1a242ffe0 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -6,6 +6,7 @@ /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 +/hugetlb/hugemmap/hugemmap09 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03 diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file mode 100644 index 000000000..df7c9edcb --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2013 Joonsoo Kim, LG Electronics. + * Author: Joonsoo Kim + */ + +/*\ + * [Description] + * + * Corrupt by COW optimization: + * Test sanity of cow optimization on page cache. If a page in page cache + * has only 1 ref count, it is mapped for a private mapping directly and + * is overwritten freely, so next time we access the page, we can see + * corrupt data. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +static long hpage_size; +static int huge_fd = -1; + +static void run_test(void) +{ + char *p; + char c; + + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, + huge_fd, 0); + *p = 's'; + tst_res(TINFO, "Write %c to %p via shared mapping", *p, p); + SAFE_MUNMAP(p, hpage_size); + + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, + huge_fd, 0); + *p = 'p'; + tst_res(TINFO, "Write %c to %p via private mapping", *p, p); + SAFE_MUNMAP(p, hpage_size); + + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, + huge_fd, 0); + c = *p; + tst_res(TINFO, "Read %c from %p via shared mapping", *p, p); + SAFE_MUNMAP(p, hpage_size); + + /* Direct write from huge page */ + if (c != 's') + tst_res(TFAIL, "Data got corrupted."); + else + tst_res(TPASS, "Successful"); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; + huge_fd = tst_creat_unlinked(MNTPOINT); +} + +static void cleanup(void) +{ + SAFE_CLOSE(huge_fd); +} + +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}, +}; -- 2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp