From patchwork Thu Feb 22 19:38:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129316 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp956045lja; Thu, 22 Feb 2018 11:39:19 -0800 (PST) X-Google-Smtp-Source: AH8x225FiBxgf+LUIrWKJOUxsDUBkCxwbeiDLQ9qkePlfs8fov9FXiClELaCjLWa5x+mGBQlqQk0 X-Received: by 10.98.25.10 with SMTP id 10mr1472940pfz.136.1519328359315; Thu, 22 Feb 2018 11:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519328359; cv=none; d=google.com; s=arc-20160816; b=Yp6qvuEgye+hC4pCePx2te05em+li8tJsJuvukQXFP34WVzGg63quacs9784HNndPq EHO3EfWbBrlMNyurfj3Cang3MFaEVGIlcfWm84t+MltdatFewfG4theDoCbzB0T1jnBH m09kjqaeFkAi/VHft6tu86TX+zkLLWhIaJgkw5KXmwSQ4vAmzeLcjtOvju+sfVLfB3gy HfAhkzDy+jesv5VRDm1k4AMae/8AM+O9Zul572jRjEXy4Z74Huh9+WEoT2dmTGShetQ+ aZKRl4RmsZTYd45NG5jo8sX637in4vsE7c8CiFbwEzFL37/UNuH4YX+xyD4jzbtIuaoa iJYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=8KJ9CawKc8lzP97hQdiUR7LoMQyUjC6ETGJNNI/hDTs=; b=yUkc8FnwyVpgVmoykJQQFwbadlzusB2AK5eQ9grWAui7jsciBSh/YDXJnHB2CALqUb rSpfOjrM1RizH8K+wCZJqnILD6hokB4f43KV6asWFuSpEVrFIxfpQYmkiRHFfAwrzuRU Af5t8ur41ekKg6PtpAYUNHeeR3z1TfAB8ESQYXEGflez+Mi5hMoNiTWcJM/yoZ1cZVGW 1mlUb3rDsNeOD17r11tyKnEEWzuTANjknA/3W0fMMeE8FzNBpMx/z7rXrrua2QbsAhuZ eV0GwauwXYJco1aBx4RvQdTNZF380pK/s8N1CtYNmtvw7l1XxXnJUtqkBm6GFUDYYO41 f0mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=CmWFpI2Z; spf=pass (google.com: domain of libc-alpha-return-90498-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90498-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id bg3-v6si495661plb.28.2018.02.22.11.39.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 11:39:19 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90498-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=CmWFpI2Z; spf=pass (google.com: domain of libc-alpha-return-90498-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90498-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=uZeRc2QQpWHbxx9ySH+YJAAhxHqxPDiXsJpe0nasOGvSrS9SRjnni DZfE48VmxV8/QNK6VdDByT/ppKDiO6hWI8tH+Z2PQ8Vin5mXMQF/yZ/RABcaIiMU OW+GnJgCKKmiScSGHu5hY4jrQ/Ia0KNOZGEbbqc2Von776PcTqYPEA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=i0ghP3kz8MvcF+yHTX+oK/+knEs=; b=CmWFpI2ZvuQp+G7wgqbgjv23HixV IQ7CmfK15mPxGOugM+lg3VUfzO/pZIo3mviHh15O+TGtROYsOUYeMuhqb9lT8G2o W0quxNBlLfvmyGCGvpULzwC0Dr/UjpceQsIERxORf6D7mNAPTwnUO5iQXtjdp9TH BXO1cCdBtM+oh3Y= Received: (qmail 116728 invoked by alias); 22 Feb 2018 19:39:10 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116718 invoked by uid 89); 22 Feb 2018 19:39:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=700000 X-HELO: mail-qk0-f194.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=8KJ9CawKc8lzP97hQdiUR7LoMQyUjC6ETGJNNI/hDTs=; b=jf8wQmhfelDdxtU7r1BfQSe8zKKWiTs4xu4HnqqoV5MvxBWlsXyKD47pKIZ2CKj5QW 52CFmrgVyP772rpoCvBNodzAkBZFxITqC8PWy8CAB/5ycPwqAObG9g/d2HAkW/HzNT0J axSmrF4OrEbaLCKhS4+wzV9XZIF8YKXPJPGOxwJYg8KqxQs+nNWbYVUI2EMwPumX82jq a0STYG895auiY++svonwgsZm9/qMg5Nyd97kYXetgyxAUD2uMCBFX5RwGYmYCxSyG66a +/JPu++AY7CMVO7lArKGIy4XHqNyFsdV+gkSJDAIH5XdXB2tVvu8Hq0bZS0SbwHLDDmj Ocpg== X-Gm-Message-State: APf1xPD0YmAunOp3F1wlWq0lpMP/QasXBLPjGtVGMjYW9bGMRWTPnPSW E25H2yAYME2tobWmB1l+pla/I9GFbJM= X-Received: by 10.233.237.145 with SMTP id c139mr12774982qkg.78.1519328346207; Thu, 22 Feb 2018 11:39:06 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Fix tst-cancel4 sendto tests Date: Thu, 22 Feb 2018 16:38:59 -0300 Message-Id: <1519328339-25282-1-git-send-email-adhemerval.zanella@linaro.org> Now that send might be implemented calling sendto syscall on Linux, I am seeing some issue in some kernel configurations where tst-cancel4 sendto do not block as expected. The socket used to force the syscall blocking is used with default system configuration for buffer sending size, which might not be correct to force blocking. This patch fixes it by explicit setting buffer socket lower than the buffer size used. It also enabled sendto cancellation tests to work in both ways (since internally send is implemented routing to sendto on Linux kernel). The patch also removes unrequired make rules on some archictures for send/recv. The generic nptl Makefile already set the compiler flags required on some architectures for correct unwinding and libc object are not strictly required to support unwind (since pthread_cancel requires linking against libpthread). Checked on aarch64-linux-gnu and x86_64-linux-gnu. I also did a sniff test with tst-cancel{4,5} on a simulated mips64-linux-gnu. * nptl/tst-cancel4-common.h (set_socket_buffer): New function. * nptl/tst-cancel4-common.c (do_test): Call set_socket_buffer for socketpair endpoint. * nptl/tst-cancel4.c (tf_send): Call set_socket_buffer and use WRITE_BUFFER_SIZE as buffer size for sending socket. (tf_sendto): Use SOCK_STREAM instead of SOCK_DGRAM and fix an issue on system where send is implemented with sendto syscall. * sysdeps/unix/sysv/linux/mips/mips64/Makefile [$(subdir) = socket] (CFLAGS-recv.c, CFLAGS-send.c): Remove rules. [$(subdir) = nptl] (CFLAGS-recv.c, CFLAGS-send.c): Likewise. * sysdeps/unix/sysv/linux/riscv/rv64/Makefile: Remove file. --- ChangeLog | 14 +++++++++++ nptl/tst-cancel4-common.c | 18 +------------- nptl/tst-cancel4-common.h | 14 +++++++++++ nptl/tst-cancel4.c | 37 +++++++++++++++------------- sysdeps/unix/sysv/linux/mips/mips64/Makefile | 10 -------- sysdeps/unix/sysv/linux/riscv/rv64/Makefile | 4 --- 6 files changed, 49 insertions(+), 48 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/riscv/rv64/Makefile -- 2.7.4 diff --git a/nptl/tst-cancel4-common.c b/nptl/tst-cancel4-common.c index 5bc7e44..c6eee73 100644 --- a/nptl/tst-cancel4-common.c +++ b/nptl/tst-cancel4-common.c @@ -20,29 +20,13 @@ static int do_test (void) { - int val; - socklen_t len; - if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0) { perror ("socketpair"); exit (1); } - val = 1; - len = sizeof(val); - setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); - if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) - { - perror ("getsockopt"); - exit (1); - } - if (val >= WRITE_BUFFER_SIZE) - { - puts ("minimum write buffer size too large"); - exit (1); - } - setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); + set_socket_buffer (fds[1]); if (mktemp (fifoname) == NULL) { diff --git a/nptl/tst-cancel4-common.h b/nptl/tst-cancel4-common.h index a526c0c..10cc4f3 100644 --- a/nptl/tst-cancel4-common.h +++ b/nptl/tst-cancel4-common.h @@ -62,6 +62,20 @@ static pthread_barrier_t b2; #define WRITE_BUFFER_SIZE 16384 +/* Set the send buffer of socket S to 1 byte so any send operation + done with WRITE_BUFFER_SIZE bytes will force syscall blocking. */ +static void +set_socket_buffer (int s) +{ + int val = 1; + socklen_t len = sizeof(val); + + TEST_VERIFY_EXIT (setsockopt (s, SOL_SOCKET, SO_SNDBUF, &val, + sizeof(val)) == 0); + TEST_VERIFY_EXIT (getsockopt (s, SOL_SOCKET, SO_SNDBUF, &val, &len) == 0); + TEST_VERIFY_EXIT (val < WRITE_BUFFER_SIZE); +} + /* Cleanup handling test. */ static int cl_called; diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index 92a3d80..0532538 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -726,6 +726,8 @@ tf_send (void *arg) if (tempfd2 == -1) FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m"); + set_socket_buffer (tempfd2); + if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0) FAIL_EXIT1 ("connect: %m"); @@ -738,8 +740,7 @@ tf_send (void *arg) pthread_cleanup_push (cl, NULL); - /* Very large block, so that the send call blocks. */ - char mem[700000]; + char mem[WRITE_BUFFER_SIZE]; send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0); @@ -1230,16 +1231,11 @@ tf_msync (void *arg) static void * tf_sendto (void *arg) { - if (arg == NULL) - // XXX If somebody can provide a portable test case in which sendto() - // blocks we can enable this test to run in both rounds. - abort (); - struct sockaddr_un sun; - tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + tempfd = socket (AF_UNIX, SOCK_STREAM, 0); if (tempfd == -1) - FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m"); + FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m"); int tries = 0; do @@ -1254,23 +1250,30 @@ tf_sendto (void *arg) while (bind (tempfd, (struct sockaddr *) &sun, offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1) != 0); - tempfname = strdup (sun.sun_path); - tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + listen (tempfd, 5); + + tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0); if (tempfd2 == -1) - FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m"); + FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m"); - xpthread_barrier_wait (&b2); + set_socket_buffer (tempfd2); + + if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0) + FAIL_EXIT1 ("connect: %m"); + + unlink (sun.sun_path); xpthread_barrier_wait (&b2); + if (arg != NULL) + xpthread_barrier_wait (&b2); + pthread_cleanup_push (cl, NULL); - char mem[1]; + char mem[WRITE_BUFFER_SIZE]; - sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0, - (struct sockaddr *) &sun, - offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1); + sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0, NULL, 0); pthread_cleanup_pop (0); diff --git a/sysdeps/unix/sysv/linux/mips/mips64/Makefile b/sysdeps/unix/sysv/linux/mips/mips64/Makefile index b4fb190..fcb48c0 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/Makefile +++ b/sysdeps/unix/sysv/linux/mips/mips64/Makefile @@ -1,13 +1,3 @@ -ifeq ($(subdir),socket) -CFLAGS-recv.c += -fexceptions -CFLAGS-send.c += -fexceptions -endif - -ifeq ($(subdir),nptl) -CFLAGS-recv.c += -fexceptions -CFLAGS-send.c += -fexceptions -endif - ifeq ($(subdir),signal) # sigaction.c defines static functions in asms and refers to them from # C code, resulting in "'restore_rt' used but never defined" (which diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/Makefile b/sysdeps/unix/sysv/linux/riscv/rv64/Makefile deleted file mode 100644 index cb60d74..0000000 --- a/sysdeps/unix/sysv/linux/riscv/rv64/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -ifeq ($(subdir),socket) -CFLAGS-recv.c += -fexceptions -CFLAGS-send.c += -fexceptions -endif