Received: by 10.223.164.202 with SMTP id h10csp573087wrb; Wed, 22 Nov 2017 11:39:25 -0800 (PST) X-Google-Smtp-Source: AGs4zMYpBaNCa6827eZI9CHxyshW6F0ngUdsRZrY11vQfoFxdm1YuC5pSwOOkgbt5hw6ebIDI3Hi X-Received: by 10.98.158.139 with SMTP id f11mr9740818pfk.216.1511379565820; Wed, 22 Nov 2017 11:39:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511379565; cv=none; d=google.com; s=arc-20160816; b=wJAHS5Hwq0WvapmvYpiXjFlGg9NXaIgq658QWjHWA1KIewSTua5FGXjdX4J9FKdYJq ZirIPfALuUCKOpdGGSEGEz5+qGOwa20K30t2/CIosvsKhDuskpcYxcsGdwpP456FuZ6s pmkWHQWPGQatME+Ama+GxTw94mWrY8EqI/M97+6kMW7MJQeE8WNUo1360c9oFH/H6EEK Mh6l/XCuw7h/c1ZdQVYkLdN8CU7TMPRgBruLCEcn/rs4TR60ZqwF1yp6FsvEPXsl48Y2 MBfZL/UlrrOvSrzK0X2FOVE03RL1R5Yi0ZHSPpkfkEY0vVqNJZG0L5MZLCmPQz7tCpLK xOxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=k4moUODumWrB2uUNXsDkigu8b7TOXeGj6R8HhrZ5PWY=; b=UO87xkQS7N103IYfQNif8Zofw8L4aq5SZDOEFIWN8MslqdUCWOXgqJnZSZjJThhLGd rbGNO96LjpCDBBEaCU2cPBk7WNyc2aQ0EPMNbnwpDZ3RYZ2OJuL5ql+MHeBDVX4zL/QE VzwR3XSysNNq00vgW/E7kAPsJpMNfd5pnMewvql+yc1NodDiovKopqkw/YZ0ODbo8URq KexYY8moAHHAUZfHDxs7hyAZnK9NH+YhcGkfUYSFzSTlv1W2ytNNAiETZ6DeRpexBqnc tqUQJ8UaA3YzUVBju0JOrj6t3sh7o34JdVYhlCTPL3Rp3AkVer2VnjkMsmi1NklKhSIr ma4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si14192624plb.632.2017.11.22.11.39.14; Wed, 22 Nov 2017 11:39:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751911AbdKVTiO (ORCPT + 77 others); Wed, 22 Nov 2017 14:38:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50862 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751860AbdKVThz (ORCPT ); Wed, 22 Nov 2017 14:37:55 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAMJaLZ7146278 for ; Wed, 22 Nov 2017 14:37:55 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2edd5y7utd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Nov 2017 14:37:55 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 19:37:52 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 19:37:48 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAMJblY129163666; Wed, 22 Nov 2017 19:37:47 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3EECC11C04A; Wed, 22 Nov 2017 19:32:28 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6F2611C050; Wed, 22 Nov 2017 19:32:25 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.204.194]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 22 Nov 2017 19:32:25 +0000 (GMT) Received: by rapoport-lnx (sSMTP sendmail emulation); Wed, 22 Nov 2017 21:37:44 +0200 From: Mike Rapoport To: Andrew Morton , Alexander Viro Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, criu@openvz.org, Arnd Bergmann , Pavel Emelyanov , Michael Kerrisk , Thomas Gleixner , Josh Triplett , Jann Horn , Andrei Vagin Subject: [PATCH v3 4/4] test: add a test for the process_vmsplice syscall Date: Wed, 22 Nov 2017 21:36:31 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511379391-988-1-git-send-email-rppt@linux.vnet.ibm.com> References: <1511379391-988-1-git-send-email-rppt@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112219-0016-0000-0000-000005047AE6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112219-0017-0000-0000-000028404D16 Message-Id: <1511379391-988-5-git-send-email-rppt@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711220258 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Vagin This test checks that process_vmsplice() can splice pages from a remote process and returns EFAULT, if process_vmsplice() tries to splice pages by an unaccessiable address. Signed-off-by: Andrei Vagin --- tools/testing/selftests/process_vmsplice/Makefile | 5 + .../process_vmsplice/process_vmsplice_test.c | 188 +++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 tools/testing/selftests/process_vmsplice/Makefile create mode 100644 tools/testing/selftests/process_vmsplice/process_vmsplice_test.c diff --git a/tools/testing/selftests/process_vmsplice/Makefile b/tools/testing/selftests/process_vmsplice/Makefile new file mode 100644 index 0000000..246d5a7 --- /dev/null +++ b/tools/testing/selftests/process_vmsplice/Makefile @@ -0,0 +1,5 @@ +CFLAGS += -I../../../../usr/include/ + +TEST_GEN_PROGS := process_vmsplice_test + +include ../lib.mk diff --git a/tools/testing/selftests/process_vmsplice/process_vmsplice_test.c b/tools/testing/selftests/process_vmsplice/process_vmsplice_test.c new file mode 100644 index 0000000..8abf59b --- /dev/null +++ b/tools/testing/selftests/process_vmsplice/process_vmsplice_test.c @@ -0,0 +1,188 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest.h" + +#ifndef __NR_process_vmsplice +#define __NR_process_vmsplice 333 +#endif + +#define pr_err(fmt, ...) \ + ({ \ + fprintf(stderr, "%s:%d:" fmt, \ + __func__, __LINE__, ##__VA_ARGS__); \ + KSFT_FAIL; \ + }) +#define pr_perror(fmt, ...) pr_err(fmt ": %m\n", ##__VA_ARGS__) +#define fail(fmt, ...) pr_err("FAIL:" fmt, ##__VA_ARGS__) + +static ssize_t process_vmsplice(pid_t pid, int fd, const struct iovec *iov, + unsigned long nr_segs, unsigned int flags) +{ + return syscall(__NR_process_vmsplice, pid, fd, iov, nr_segs, flags); + +} + +#define MEM_SIZE (4096 * 100) +#define MEM_WRONLY_SIZE (4096 * 10) + +int main(int argc, char **argv) +{ + char *addr, *addr_wronly; + int p[2]; + struct iovec iov[2]; + char buf[4096]; + int status, ret; + pid_t pid; + + ksft_print_header(); + + addr = mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (addr == MAP_FAILED) + return pr_perror("Unable to create a mapping"); + + addr_wronly = mmap(0, MEM_WRONLY_SIZE, PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (addr_wronly == MAP_FAILED) + return pr_perror("Unable to create a write-only mapping"); + + if (pipe(p)) + return pr_perror("Unable to create a pipe"); + + pid = fork(); + if (pid < 0) + return pr_perror("Unable to fork"); + + if (pid == 0) { + addr[0] = 'C'; + addr[4096 + 128] = 'A'; + addr[4096 + 128 + 4096 - 1] = 'B'; + + if (prctl(PR_SET_PDEATHSIG, SIGKILL)) + return pr_perror("Unable to set PR_SET_PDEATHSIG"); + if (write(p[1], "c", 1) != 1) + return pr_perror("Unable to write data into pipe"); + + while (1) + sleep(1); + return 1; + } + if (read(p[0], buf, 1) != 1) { + pr_perror("Unable to read data from pipe"); + kill(pid, SIGKILL); + wait(&status); + return 1; + } + + munmap(addr, MEM_SIZE); + munmap(addr_wronly, MEM_WRONLY_SIZE); + + iov[0].iov_base = addr; + iov[0].iov_len = 1; + + iov[1].iov_base = addr + 4096 + 128; + iov[1].iov_len = 4096; + + /* check one iovec */ + if (process_vmsplice(pid, p[1], iov, 1, SPLICE_F_GIFT) != 1) + return pr_perror("Unable to splice pages"); + + if (read(p[0], buf, 1) != 1) + return pr_perror("Unable to read from pipe"); + + if (buf[0] != 'C') + ksft_test_result_fail("Get wrong data\n"); + else + ksft_test_result_pass("Check process_vmsplice with one vec\n"); + + /* check two iovec-s */ + if (process_vmsplice(pid, p[1], iov, 2, SPLICE_F_GIFT) != 4097) + return pr_perror("Unable to spice pages\n"); + + if (read(p[0], buf, 1) != 1) + return pr_perror("Unable to read from pipe\n"); + + if (buf[0] != 'C') + ksft_test_result_fail("Get wrong data\n"); + + if (read(p[0], buf, 4096) != 4096) + return pr_perror("Unable to read from pipe\n"); + + if (buf[0] != 'A' || buf[4095] != 'B') + ksft_test_result_fail("Get wrong data\n"); + else + ksft_test_result_pass("check process_vmsplice with two vecs\n"); + + /* check how an unreadable region in a second vec is handled */ + iov[0].iov_base = addr; + iov[0].iov_len = 1; + + iov[1].iov_base = addr_wronly + 5; + iov[1].iov_len = 1; + + if (process_vmsplice(pid, p[1], iov, 2, SPLICE_F_GIFT) != 1) + return pr_perror("Unable to splice data"); + + if (read(p[0], buf, 1) != 1) + return pr_perror("Unable to read form pipe"); + + if (buf[0] != 'C') + ksft_test_result_fail("Get wrong data\n"); + else + ksft_test_result_pass("unreadable region in a second vec\n"); + + /* check how an unreadable region in a first vec is handled */ + errno = 0; + if (process_vmsplice(pid, p[1], iov + 1, 1, SPLICE_F_GIFT) != -1 || + errno != EFAULT) + ksft_test_result_fail("Got anexpected errno %d\n", errno); + else + ksft_test_result_pass("splice as much as possible\n"); + + iov[0].iov_base = addr; + iov[0].iov_len = 1; + + iov[1].iov_base = addr; + iov[1].iov_len = MEM_SIZE; + + /* splice as much as possible */ + ret = process_vmsplice(pid, p[1], iov, 2, + SPLICE_F_GIFT | SPLICE_F_NONBLOCK); + if (ret != 4096 * 15 + 1) /* by default a pipe can fit 16 pages */ + return pr_perror("Unable to splice pages"); + + while (ret > 0) { + int len; + + len = read(p[0], buf, 4096); + if (len < 0) + return pr_perror("Unable to read data"); + if (len > ret) + return pr_err("Read more than expected\n"); + ret -= len; + } + ksft_test_result_pass("splice as much as possible\n"); + + if (kill(pid, SIGTERM)) + return pr_perror("Unable to kill a child process"); + status = -1; + if (wait(&status) < 0) + return pr_perror("Unable to wait a child process"); + if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGTERM) + return pr_err("The child exited with an unexpected code %d\n", + status); + + if (ksft_get_fail_cnt()) + return ksft_exit_fail(); + return ksft_exit_pass(); +} -- 2.7.4 From 1584999210831141636@xxx Sat Nov 25 01:23:58 +0000 2017 X-GM-THRID: 1584815247132834352 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread