From patchwork Wed Nov 28 09:28:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1004300 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=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="csj7rB+1"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 434b1l0BRZz9s4s for ; Wed, 28 Nov 2018 20:28:41 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id F18A03E7946 for ; Wed, 28 Nov 2018 10:28:36 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 8921E3E791E for ; Wed, 28 Nov 2018 10:28:34 +0100 (CET) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 80ACC1400E6F for ; Wed, 28 Nov 2018 10:28:33 +0100 (CET) Received: by mail-wm1-x344.google.com with SMTP id q26so1778858wmf.5 for ; Wed, 28 Nov 2018 01:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=EURdEccqFT62yB+obEtZ/SaUmHPWAfMgumyOeFMdrTI=; b=csj7rB+1gn9Oj/i/VU6y/MQ5EguA82FJu9ymKiasJobt6s44TEoSoYRIP2J8GirK0I WnOlxYEhIsPm0BI+9NVth0IiyOiB9CueOGy2FgE0CuRmuRkIIN8zKn2cpekUKkocrPFp OE9EqZKHzomMKZAYPsGcMtrRfXkzQogQpr4RviO/8JcIn7ciyhCyVEvgz+WSsmCpnZZh 19nHHLQFHstUuELHisxFEYguj+5JtxR7JGUBY7eIl09BxWFm/XkHoPdqIYPWeG03VEsS rTpemyrR5JNgspac9dLljAZ0iPWXoGArvGnxM8X5YP0Vf6qzj4ub1hC88MvVKSBaO3Wk SIFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EURdEccqFT62yB+obEtZ/SaUmHPWAfMgumyOeFMdrTI=; b=j4arCktK+3RKVLBeheD64asnv5wd+VtxZ+MXvIRHfDct/7TC4BKxDBr/QCMiwweNwN vDaJZCk6bqeXaSpYWcw3xLN4HFi6qS8dEStOn2fymidG4EQmSbO+haQAmf8e2SJU2rrV gpES5Hsb2LGn9TT+foaA6KjJgOzoy8CGwDUfXX0GXdZ+Tq+JNx8r5oQypKon2bN3Xlbb X6JY/DDwdvWiysJRWUpkp3HeKZxJa7QmqoUP8BrpK+9eYCoYXNTvN8EL9hvyYplw51Hu C8+mYPFAI+prEVoyTkKa7ORMawlK06QqzP6clIjNmC1/QZZCFcK6GqWrpkMG2IA2hWgM GcsA== X-Gm-Message-State: AA+aEWZO4BnO8r1XyXL6vmjkldkrV8KE0nXgv3bRkEI/GLNXIpoC5QQU bdxfXLRknBzdlYCHHOnJke8= X-Google-Smtp-Source: AFSGD/XvrGpQoLnJW+Af6y//p47n1z/nbG2Bnlj9gEUa77vXmPHWPr80lgjbgIsJjg13XGB6JKN5Iw== X-Received: by 2002:a1c:e184:: with SMTP id y126mr2153716wmg.13.1543397312054; Wed, 28 Nov 2018 01:28:32 -0800 (PST) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id t5sm1800258wmd.15.2018.11.28.01.28.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 01:28:31 -0800 (PST) From: Amir Goldstein To: Cyril Hrubis Date: Wed, 28 Nov 2018 11:28:24 +0200 Message-Id: <20181128092824.2054-1-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: nixiaoming , Jan Kara , ltp@lists.linux.it Subject: [LTP] [PATCH v3] syscalls/fanotify11: new test for report thread id 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: nixiaoming Test fanotify_init with FAN_REPORT_TID - Verify that event->pid is pid of the thread that caused the event Test fanotify_init without FAN_REPORT_TID - Verify that event->pid is tgid of the process that caused the event Signed-off-by: nixiaoming Signed-off-by: Amir Goldstein --- Hi Cyril, This is a test for yet another new fanotify API that was introduced in kernel v4.20-rc1. The new API as well as this test were written by nixiaoming, but since I helped with review and final touches over v2 of the test, I promissed to post v3 when the time comes... Thanks, Amir. runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/Makefile | 2 +- testcases/kernel/syscalls/fanotify/fanotify.h | 4 + .../kernel/syscalls/fanotify/fanotify11.c | 109 ++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify11.c diff --git a/runtest/syscalls b/runtest/syscalls index 61865f8e0..ac1d2d2cd 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -508,6 +508,7 @@ fanotify07 fanotify07 fanotify08 fanotify08 fanotify09 fanotify09 fanotify10 fanotify10 +fanotify11 fanotify11 ioperm01 ioperm01 ioperm02 ioperm02 diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore index c26f2bd27..3818e241f 100644 --- a/testcases/kernel/syscalls/fanotify/.gitignore +++ b/testcases/kernel/syscalls/fanotify/.gitignore @@ -8,3 +8,4 @@ /fanotify08 /fanotify09 /fanotify10 +/fanotify11 diff --git a/testcases/kernel/syscalls/fanotify/Makefile b/testcases/kernel/syscalls/fanotify/Makefile index bb58878d7..5d01b4825 100644 --- a/testcases/kernel/syscalls/fanotify/Makefile +++ b/testcases/kernel/syscalls/fanotify/Makefile @@ -17,7 +17,7 @@ # top_srcdir ?= ../../../.. - +fanotify11: CFLAGS+=-pthread include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 535f1cef2..880dea534 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -54,6 +54,10 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #endif /* HAVE_SYS_FANOTIFY_H */ +#ifndef FAN_REPORT_TID +#define FAN_REPORT_TID 0x00000100 +#endif + #ifndef FAN_MARK_INODE #define FAN_MARK_INODE 0 #endif diff --git a/testcases/kernel/syscalls/fanotify/fanotify11.c b/testcases/kernel/syscalls/fanotify/fanotify11.c new file mode 100644 index 000000000..b62720d8a --- /dev/null +++ b/testcases/kernel/syscalls/fanotify/fanotify11.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Huawei. All Rights Reserved. + * + * Started by nixiaoming + * + * DESCRIPTION + * After fanotify_init adds flags FAN_REPORT_TID, + * check whether the program can accurately identify which thread id + * in the multithreaded program triggered the event. + * + */ +#define _GNU_SOURCE +#include "config.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "tst_safe_pthread.h" +#include "fanotify.h" + +#if defined(HAVE_SYS_FANOTIFY_H) +#include + +#define gettid() syscall(SYS_gettid) +static int tid; + +void *thread_create_file(void *arg LTP_ATTRIBUTE_UNUSED) +{ + char tid_file[64] = {0}; + + tid = gettid(); + snprintf(tid_file, sizeof(tid_file), "test_tid_%d", tid); + SAFE_FILE_PRINTF(tid_file, "1"); + + pthread_exit(0); +} + +static unsigned int tcases[] = { + FAN_CLASS_NOTIF, + FAN_CLASS_NOTIF | FAN_REPORT_TID +}; + +void test01(unsigned int i) +{ + int ret; + pthread_t p_id; + struct fanotify_event_metadata event; + int fd_notify; + int tgid = getpid(); + + fd_notify = fanotify_init(tcases[i], 0); + if (fd_notify < 0) { + if (errno == EINVAL && (tcases[i] & FAN_REPORT_TID)) { + tst_res(TCONF, + "FAN_REPORT_TID not supported in kernel?"); + return; + } + tst_brk(TBROK | TERRNO, "fanotify_init(0x%x, 0) failed", + tcases[i]); + } + + ret = fanotify_mark(fd_notify, FAN_MARK_ADD, + FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD, AT_FDCWD, "."); + if (ret != 0) + tst_brk(TBROK, "fanotify_mark FAN_MARK_ADD fail ret=%d", ret); + + SAFE_PTHREAD_CREATE(&p_id, NULL, thread_create_file, NULL); + + SAFE_READ(0, fd_notify, &event, sizeof(struct fanotify_event_metadata)); + tst_res(TINFO, "%s FAN_REPORT_TID: tgid=%d, tid=%d, event.pid=%d", + (tcases[i] & FAN_REPORT_TID) ? "with" : "without", + tgid, tid, event.pid); + if ((tcases[i] & FAN_REPORT_TID) && event.pid == tid) + tst_res(TPASS, "event.pid == tid"); + else if (!(tcases[i] & FAN_REPORT_TID) && event.pid == tgid) + tst_res(TPASS, "event.pid == tgid"); + else + tst_res(TFAIL, "unexpected event.pid value"); + + if (event.fd != FAN_NOFD) + SAFE_CLOSE(event.fd); + SAFE_CLOSE(fd_notify); + SAFE_PTHREAD_JOIN(p_id, NULL); +} + + +static struct tst_test test = { + .test = test01, + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .needs_root = 1, +}; + +#else +TST_TEST_TCONF("system doesn't have required fanotify support"); +#endif