From patchwork Tue Aug 21 09:38:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 960174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41vlxy73R1z9s7X for ; Tue, 21 Aug 2018 19:39:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 358993E7641 for ; Tue, 21 Aug 2018 11:39:32 +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]) by picard.linux.it (Postfix) with ESMTP id 88CDE3E63EB for ; Tue, 21 Aug 2018 11:39:20 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 20FFC600ECC for ; Tue, 21 Aug 2018 11:39:17 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43735939" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2018 17:39:07 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 065C54B6AE02 for ; Tue, 21 Aug 2018 17:39:06 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 21 Aug 2018 17:39:07 +0800 From: Xiao Yang To: Date: Tue, 21 Aug 2018 17:38:56 +0800 Message-ID: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 065C54B6AE02.A7FA5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for mlock2 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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" Signed-off-by: Xiao Yang --- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+) diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index 2c8c589..9ac7f99 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -256,5 +256,6 @@ sendmmsg 269 kcmp 272 getrandom 278 memfd_create 279 +mlock2 284 copy_file_range 285 _sysctl 1078 diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in index c44adcd..774e1c7 100644 --- a/include/lapi/syscalls/arm.in +++ b/include/lapi/syscalls/arm.in @@ -341,4 +341,5 @@ renameat2 (__NR_SYSCALL_BASE+382) getrandom (__NR_SYSCALL_BASE+384) memfd_create (__NR_SYSCALL_BASE+385) execveat (__NR_SYSCALL_BASE+387) +mlock2 (__NR_SYSCALL_BASE+390) copy_file_range (__NR_SYSCALL_BASE+391) diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index 92aee9f..3db9780 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -17,4 +17,5 @@ splice 291 tee 293 vmsplice 294 memfd_create 340 +mlock2 345 copy_file_range 346 diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in index 19f0148..6a72b43 100644 --- a/include/lapi/syscalls/i386.in +++ b/include/lapi/syscalls/i386.in @@ -341,4 +341,5 @@ renameat2 354 getrandom 355 memfd_create 356 execveat 358 +mlock2 376 copy_file_range 377 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index a3abc99..2788193 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -296,4 +296,5 @@ prlimit64 1325 renameat2 1338 getrandom 1339 memfd_create 1340 +mlock2 1346 copy_file_range 1347 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index 11ddca3..54c1941 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -347,4 +347,5 @@ sched_getattr 356 renameat2 357 getrandom 359 memfd_create 360 +mlock2 378 copy_file_range 379 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index 11ddca3..54c1941 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -347,4 +347,5 @@ sched_getattr 356 renameat2 357 getrandom 359 memfd_create 360 +mlock2 378 copy_file_range 379 diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in index d95b282..47a04de 100644 --- a/include/lapi/syscalls/s390.in +++ b/include/lapi/syscalls/s390.in @@ -332,4 +332,5 @@ renameat2 347 getrandom 349 memfd_create 350 execveat 354 +mlock2 374 copy_file_range 375 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index 98c861f..83732ff 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -331,4 +331,5 @@ sched_getattr 346 renameat2 347 getrandom 349 memfd_create 350 +mlock2 374 copy_file_range 375 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index c605b14..407be7a 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -364,4 +364,5 @@ fanotify_mark 368 prlimit64 369 kcmp 378 memfd_create 385 +mlock2 390 copy_file_range 391 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index 296d694..2b06a79 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -336,4 +336,5 @@ kcmp 341 renameat2 345 getrandom 347 memfd_create 348 +mlock2 356 copy_file_range 357 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index 169347a..8c8a866 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -312,4 +312,5 @@ kcmp 341 renameat2 345 getrandom 347 memfd_create 348 +mlock2 356 copy_file_range 357 diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in index 7907c31..dec9d3b 100644 --- a/include/lapi/syscalls/x86_64.in +++ b/include/lapi/syscalls/x86_64.in @@ -308,4 +308,5 @@ renameat2 316 getrandom 318 memfd_create 319 execveat 322 +mlock2 325 copy_file_range 326 From patchwork Tue Aug 21 09:38:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 960173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41vlxt34cmz9s5c for ; Tue, 21 Aug 2018 19:39:30 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 429673E63D8 for ; Tue, 21 Aug 2018 11:39:27 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id B9F243E63E1 for ; Tue, 21 Aug 2018 11:39:19 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 31EC11000C19 for ; Tue, 21 Aug 2018 11:39:16 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43735940" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2018 17:39:07 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id AE57B4B6AE0B for ; Tue, 21 Aug 2018 17:39:06 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 21 Aug 2018 17:39:08 +0800 From: Xiao Yang To: Date: Tue, 21 Aug 2018 17:38:57 +0800 Message-ID: <1534844339-8655-2-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> References: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: AE57B4B6AE0B.AB8B0 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 2/4] safe_macros: Add SAFE_MLOCK() and SAFE_MUNLOCK() macros X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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" Signed-off-by: Xiao Yang --- include/tst_safe_macros.h | 8 ++++++++ lib/safe_macros.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index a754399..dc6c1f7 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -482,6 +482,14 @@ int safe_mknod(const char *file, const int lineno, const char *pathname, #define SAFE_MKNOD(pathname, mode, dev) \ safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev)) +int safe_mlock(const char *file, const int lineno, const char *addr, + size_t len); +#define SAFE_MLOCK(addr, len) safe_mlock(__FILE__, __LINE__, (addr), (len)) + +int safe_munlock(const char *file, const int lineno, const char *addr, + size_t len); +#define SAFE_MUNLOCK(addr, len) safe_munlock(__FILE__, __LINE__, (addr), (len)) + int safe_fanotify_init(const char *file, const int lineno, unsigned int flags, unsigned int event_f_flags); #define SAFE_FANOTIFY_INIT(fan, mode) \ diff --git a/lib/safe_macros.c b/lib/safe_macros.c index 03bd7aa..fa92a6f 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -1006,3 +1006,31 @@ int safe_mknod(const char *file, const int lineno, const char *pathname, return rval; } + +int safe_mlock(const char *file, const int lineno, const void *addr, + size_t len) +{ + int rval; + + rval = mlock(addr, len); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, NULL, + "%s:%d: mlock() failed", file, lineno); + } + + return rval; +} + +int safe_munlock(const char *file, const int lineno, const void *addr, + size_t len) +{ + int rval; + + rval = munlock(addr, len); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, NULL, + "%s:%d: munlock() failed", file, lineno); + } + + return rval; +} From patchwork Tue Aug 21 09:38:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 960172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41vlxq41nTz9s5c for ; Tue, 21 Aug 2018 19:39:25 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 15D083E63D7 for ; Tue, 21 Aug 2018 11:39:20 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 2520D3E63C6 for ; Tue, 21 Aug 2018 11:39:16 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 1DDE61000C1B for ; Tue, 21 Aug 2018 11:39:14 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43735938" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2018 17:39:07 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 476C84B6AE10 for ; Tue, 21 Aug 2018 17:39:07 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 21 Aug 2018 17:39:08 +0800 From: Xiao Yang To: Date: Tue, 21 Aug 2018 17:38:58 +0800 Message-ID: <1534844339-8655-3-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> References: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 476C84B6AE10.AA737 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 3/4] syscalls/mlock201: Add new testcase X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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" Check the basic functionality of mlock2(2) since kernel v2.6.9. Signed-off-by: Xiao Yang --- include/lapi/mlock2.h | 16 +++++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 2 + testcases/kernel/syscalls/mlock2/.gitignore | 1 + testcases/kernel/syscalls/mlock2/Makefile | 8 +++ testcases/kernel/syscalls/mlock2/mlock201.c | 103 ++++++++++++++++++++++++++++ 7 files changed, 134 insertions(+) create mode 100644 include/lapi/mlock2.h create mode 100644 testcases/kernel/syscalls/mlock2/.gitignore create mode 100644 testcases/kernel/syscalls/mlock2/Makefile create mode 100644 testcases/kernel/syscalls/mlock2/mlock201.c diff --git a/include/lapi/mlock2.h b/include/lapi/mlock2.h new file mode 100644 index 0000000..fa2b2de --- /dev/null +++ b/include/lapi/mlock2.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang + */ + +#ifndef LAPI_MLOCK2_H__ +# define LAPI_MLOCK2_H__ + +#include + +#ifndef MLOCK_ONFAULT +# define MLOCK_ONFAULT 0x01 +#endif + +#endif /* LAPI_MLOCK2_H__ */ diff --git a/runtest/ltplite b/runtest/ltplite index 9ca6c42..270c649 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -443,6 +443,8 @@ mknod09 mknod09 mlock01 mlock01 mlock02 mlock02 +mlock201 mlock201 + qmm01 mmap001 -m 1 mmap01 mmap01 mmap02 mmap02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index ec18dcf..6850572 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -369,6 +369,8 @@ mknod09 mknod09 mlock01 mlock01 mlock02 mlock02 +mlock201 mlock201 + qmm01 mmap001 -m 1 mmap01 mmap01 mmap02 mmap02 diff --git a/runtest/syscalls b/runtest/syscalls index 3161d91..5d84d48 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -633,6 +633,8 @@ mlock02 mlock02 mlock03 mlock03 -i 20 mlock04 mlock04 +mlock201 mlock201 + qmm01 mmap001 -m 1 mmap01 mmap01 mmap02 mmap02 diff --git a/testcases/kernel/syscalls/mlock2/.gitignore b/testcases/kernel/syscalls/mlock2/.gitignore new file mode 100644 index 0000000..431eff8 --- /dev/null +++ b/testcases/kernel/syscalls/mlock2/.gitignore @@ -0,0 +1 @@ +/mlock201 diff --git a/testcases/kernel/syscalls/mlock2/Makefile b/testcases/kernel/syscalls/mlock2/Makefile new file mode 100644 index 0000000..427df06 --- /dev/null +++ b/testcases/kernel/syscalls/mlock2/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/mlock2/mlock201.c b/testcases/kernel/syscalls/mlock2/mlock201.c new file mode 100644 index 0000000..e0517e1 --- /dev/null +++ b/testcases/kernel/syscalls/mlock2/mlock201.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang + */ +/* + * Description: + * Check the basic functionality of the mlock2(2) since kernel v2.6.9: + * 1) Use mlock2(2) without MLOCK_ONFAULT to lock memory in the specified + * range that is multiples of page size or not, and the VmLck from + * /proc/PID/status shows correct size of memory that is locked by PID. + * 2) Use mlock2(2) with MLOCK_ONFAULT to lock memory in the specified + * range that is multiples of page size or not, and the VmLck from + * /proc/PID/status show correct size of memory that is locked by PID. + */ +#include +#include +#include +#include + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "lapi/mlock2.h" + +#define PAGES 8 + +static unsigned long pgsz; +static char *addr; + +static struct tcase { + unsigned long mlock_pgs; + long len_off; + unsigned long exp_pgs; + int flag; +} tcases[] = { + {1, 0, 1, 0}, + {PAGES, 0, PAGES, 0}, + /* mlock2() locks 3 pages if the specified + * range is little more than 2 pages. + */ + {2, 1, 3, 0}, + /* mlock2() locks 2 pages if the specified + * range is little less than 2 pages. + */ + {2, -1, 2, 0}, + {1, 0, 1, MLOCK_ONFAULT}, + {PAGES, 0, PAGES, MLOCK_ONFAULT}, + {2, 1, 3, MLOCK_ONFAULT}, + {2, -1, 2, MLOCK_ONFAULT}, +}; + +static void verify_mlock2(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + unsigned long bsize, asize, act_pgs; + + SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %lu", &bsize); + + TEST(tst_syscall(__NR_mlock2, addr, tc->mlock_pgs * pgsz + tc->len_off, + tc->flag)); + if (TST_RET != 0) { + if (tc->flag && TST_ERR == EINVAL) + tst_res(TCONF, "mlock2() didn't support MLOCK_ONFAULT"); + else + tst_res(TFAIL | TTERRNO, "mlock2() failed"); + return; + } + + SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %lu", &asize); + + act_pgs = (asize - bsize) * 1024 / pgsz; + if (tc->exp_pgs != act_pgs) { + tst_res(TFAIL, "mlock2() locked %lu pages, expected %lu", + tc->exp_pgs, act_pgs); + } else { + tst_res(TPASS, "mlock2() succeeded in locking %lu pages", + tc->exp_pgs); + } + + SAFE_MUNLOCK(addr, tc->mlock_pgs * pgsz + tc->len_off); +} + +static void setup(void) +{ + pgsz = getpagesize(); + addr = SAFE_MMAP(NULL, PAGES * pgsz, PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); +} + +static void cleanup(void) +{ + if (addr) + SAFE_MUNMAP(addr, PAGES * pgsz); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = verify_mlock2, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .min_kver = "2.6.9", +}; From patchwork Tue Aug 21 09:38:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 960175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41vly23Rwrz9s78 for ; Tue, 21 Aug 2018 19:39:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B7DF53E7594 for ; Tue, 21 Aug 2018 11:39:35 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 703873E63FF for ; Tue, 21 Aug 2018 11:39:23 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 56C821000C00 for ; Tue, 21 Aug 2018 11:39:21 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43735943" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2018 17:39:13 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 0BE1C4B6AE02 for ; Tue, 21 Aug 2018 17:39:08 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 21 Aug 2018 17:39:09 +0800 From: Xiao Yang To: Date: Tue, 21 Aug 2018 17:38:59 +0800 Message-ID: <1534844339-8655-4-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> References: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 0BE1C4B6AE02.A9BCF X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 4/4] syscalls/mlock202: Add new testcase X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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" Check various errnos for mlock2(2) since kernel v2.6.9. Signed-off-by: Xiao Yang --- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/mlock2/.gitignore | 1 + testcases/kernel/syscalls/mlock2/mlock202.c | 110 ++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 testcases/kernel/syscalls/mlock2/mlock202.c diff --git a/runtest/ltplite b/runtest/ltplite index 270c649..7ebe632 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -444,6 +444,7 @@ mlock01 mlock01 mlock02 mlock02 mlock201 mlock201 +mlock202 mlock202 qmm01 mmap001 -m 1 mmap01 mmap01 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 6850572..0804172 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -370,6 +370,7 @@ mlock01 mlock01 mlock02 mlock02 mlock201 mlock201 +mlock202 mlock202 qmm01 mmap001 -m 1 mmap01 mmap01 diff --git a/runtest/syscalls b/runtest/syscalls index 5d84d48..2615254 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -634,6 +634,7 @@ mlock03 mlock03 -i 20 mlock04 mlock04 mlock201 mlock201 +mlock202 mlock202 qmm01 mmap001 -m 1 mmap01 mmap01 diff --git a/testcases/kernel/syscalls/mlock2/.gitignore b/testcases/kernel/syscalls/mlock2/.gitignore index 431eff8..8daf0f9 100644 --- a/testcases/kernel/syscalls/mlock2/.gitignore +++ b/testcases/kernel/syscalls/mlock2/.gitignore @@ -1 +1,2 @@ /mlock201 +/mlock202 diff --git a/testcases/kernel/syscalls/mlock2/mlock202.c b/testcases/kernel/syscalls/mlock2/mlock202.c new file mode 100644 index 0000000..61dd29d --- /dev/null +++ b/testcases/kernel/syscalls/mlock2/mlock202.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang + */ +/* + * Description: + * Check various errnos for mlock2(2) since kernel v2.6.9: + * 1) mlock(2) fails and returns EINVAL if unknown flag is specified. + * 2) mlock(2) fails and returns ENOMEM if the caller is not + * privileged(CAP_IPC_LOCK) and tries to lock more memory than the + * RLIMIT_MEMLOCK limit. + * 3) mlock(2) fails and returns EPERM if the caller is not + * privileged(CAP_IPC_LOCK) and its RLIMIT_MEMLOCK limit is 0. + * 4) mlock(2) fails and returns ENOMEM if some of the specified address + * range does not correspond to mapped pages in the address space + * of the caller. + */ +#include +#include +#include +#include +#include +#include + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static unsigned long pgsz; +static unsigned long max_sz1, max_sz2; +static char *addr, *unmapped_addr; +static struct passwd *nobody; + +static struct tcase { + char **taddr; + int flag; + unsigned long *max_size; + /* 1: nobody expected 0: root expected */ + int exp_user; + int exp_err; +} tcases[] = { + {&addr, -1, NULL, 0, EINVAL}, + {&addr, 0, &max_sz1, 1, ENOMEM}, + {&addr, 0, &max_sz2, 1, EPERM}, + {&unmapped_addr, 0, NULL, 0, ENOMEM}, +}; + +static void verify_mlock2(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + struct rlimit orig_limit, new_limit; + + if (tc->exp_user) { + SAFE_GETRLIMIT(RLIMIT_MEMLOCK, &orig_limit); + new_limit.rlim_cur = *tc->max_size; + new_limit.rlim_max = *tc->max_size; + SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &new_limit); + SAFE_SETEUID(nobody->pw_uid); + } + + TEST(tst_syscall(__NR_mlock2, *tc->taddr, pgsz, tc->flag)); + if (TST_RET != -1) { + tst_res(TFAIL, "mlock2() succeeded"); + SAFE_MUNLOCK(*tc->taddr, pgsz); + goto end; + } + + if (TST_ERR != tc->exp_err) { + tst_res(TFAIL | TTERRNO, + "mlock2() failed unexpectedly, expected %s", + tst_strerrno(tc->exp_err)); + } else { + tst_res(TPASS | TTERRNO, "mlock2() failed as expected"); + } + +end: + if (tc->exp_user) { + SAFE_SETEUID(0); + SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &orig_limit); + } +} + +static void setup(void) +{ + pgsz = getpagesize(); + nobody = SAFE_GETPWNAM("nobody"); + + addr = SAFE_MMAP(NULL, pgsz, PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + unmapped_addr = SAFE_MMAP(NULL, pgsz, PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + SAFE_MUNMAP(unmapped_addr, pgsz); + + max_sz1 = pgsz - 1; +} + +static void cleanup(void) +{ + if (addr) + SAFE_MUNMAP(addr, pgsz); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = verify_mlock2, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .min_kver = "2.6.9", +};