From patchwork Fri Jun 17 14:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12885736 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA72CC433EF for ; Fri, 17 Jun 2022 14:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382226AbiFQOgP (ORCPT ); Fri, 17 Jun 2022 10:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbiFQOgO (ORCPT ); Fri, 17 Jun 2022 10:36:14 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5CE75251A for ; Fri, 17 Jun 2022 07:36:13 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1655476572; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=64bRr+iDqyfH1wO0tT7e5eLQdiOXDFN5WM+1JyA/3AQ=; b=b+ZvkFVIxmRaPMaPMTzqdZk7VEJAaxkw8tXvNBOZ3EmDhBQeeEaPEO3MfrmCei7CIfUPMX pJhAKwj3B8IUm8GRHErMZhXadBxf11Yqf6jJH1vXBn8GS41Moj9Avs/ccHpvClSo78hYkK h1qtCWU7mPXbJtdmMYDxzkK7J2WTQ98= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 1/3] Fix incorrect close in test for multishot accept Date: Fri, 17 Jun 2022 22:36:01 +0800 Message-Id: <20220617143603.179277-2-hao.xu@linux.dev> In-Reply-To: <20220617143603.179277-1-hao.xu@linux.dev> References: <20220617143603.179277-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Donald Hunter This fixes a bug in accept_conn handling in the accept tests that caused it to incorrectly skip the multishot tests and also lose the warning message to a closed stdout. This can be seen in the strace output below. close(1) = 0 io_uring_setup(32, { ... ... write(1, "Fixed Multishot Accept not suppo"..., 47) = -1 EINVAL Unfortunately this exposes a a bug with gcc -O2 where multishot_mask logic gets optimized incorrectly and "Fixed Multishot Accept misses events" is wrongly reported. I am investigating this separately. Fixes: 66cf84527c34 ("test/accept.c: add test for multishot mode accept") Signed-off-by: Donald Hunter --- test/accept.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/accept.c b/test/accept.c index 4e2f58767b3c..c6654baa3925 100644 --- a/test/accept.c +++ b/test/accept.c @@ -103,7 +103,7 @@ static void queue_accept_conn(struct io_uring *ring, int fd, } } -static int accept_conn(struct io_uring *ring, int fixed_idx) +static int accept_conn(struct io_uring *ring, int fixed_idx, bool multishot) { struct io_uring_cqe *cqe; int ret; @@ -115,8 +115,10 @@ static int accept_conn(struct io_uring *ring, int fixed_idx) if (fixed_idx >= 0) { if (ret > 0) { - close(ret); - return -EINVAL; + if (!multishot) { + close(ret); + return -EINVAL; + } } else if (!ret) { ret = fixed_idx; } @@ -208,7 +210,7 @@ static int test_loop(struct io_uring *ring, queue_accept_conn(ring, recv_s0, args); for (i = 0; i < MAX_FDS; i++) { - s_fd[i] = accept_conn(ring, args.fixed ? 0 : -1); + s_fd[i] = accept_conn(ring, args.fixed ? 0 : -1, multishot); if (s_fd[i] == -EINVAL) { if (args.accept_should_error) goto out; From patchwork Fri Jun 17 14:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12885737 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEEC4C433EF for ; Fri, 17 Jun 2022 14:36:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382540AbiFQOgR (ORCPT ); Fri, 17 Jun 2022 10:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382489AbiFQOgQ (ORCPT ); Fri, 17 Jun 2022 10:36:16 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A99052503 for ; Fri, 17 Jun 2022 07:36:16 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1655476574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RpRiEjMgcQKmsW3ofTJbI8Kbvqq/wtPru8rRbhucdFM=; b=mf31KgnDJefDddlY9SyG1eaf0/gbnsarP+OUYv48IKMnUyLJzCuScvNTlONk/xzlIckKpp ZnfIvPJ3CzPfq3cJgPz/mmXX4doXy443U+Ddj8GkfwmDaP0ypIz6bUO8de5RjL89VXLZKF S8FM3mDL/dCgnOdi+5tQQ3lX4VXLqrc= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 2/3] test/accept: fix minus one error when calculating multishot_mask Date: Fri, 17 Jun 2022 22:36:02 +0800 Message-Id: <20220617143603.179277-3-hao.xu@linux.dev> In-Reply-To: <20220617143603.179277-1-hao.xu@linux.dev> References: <20220617143603.179277-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu We don't need to minus one for the s_fd[i] since the returned cqe.res is already the fixed file table slot which is indexed from zero. Fixes: 66cf84527c34 ("test/accept.c: add test for multishot mode accept") Signed-off-by: Hao Xu --- test/accept.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/accept.c b/test/accept.c index c6654baa3925..b322c018c7a9 100644 --- a/test/accept.c +++ b/test/accept.c @@ -241,7 +241,7 @@ static int test_loop(struct io_uring *ring, i, s_fd[i]); goto err; } - multishot_mask |= (1 << (s_fd[i] - 1)); + multishot_mask |= (1U << s_fd[i]); } if (!multishot) break; From patchwork Fri Jun 17 14:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 12885738 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44321C433EF for ; Fri, 17 Jun 2022 14:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbiFQOgU (ORCPT ); Fri, 17 Jun 2022 10:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382489AbiFQOgT (ORCPT ); Fri, 17 Jun 2022 10:36:19 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D44855482 for ; Fri, 17 Jun 2022 07:36:18 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1655476577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zSkVl+4rPf4mNONh6RBRRAHUQaelVQxjdXobd53sQyE=; b=PTI3UJH3wCmBFQ0O4LSj02x6ExvafNZ2uyeWOumvMA2xd15tQuMxfJrOf4pZd/WWojFZmT mzTVcw9uHVA8yp9JeH5ZHsmemf2/s05RyQgZip2trebnqJyzWt/Mhn4FJk6rVkraSE6s/4 Dv38qAZQagTzgAcEZn9qMtKzn+GE1V8= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH 3/3] test/accept: clean code of accept test Date: Fri, 17 Jun 2022 22:36:03 +0800 Message-Id: <20220617143603.179277-4-hao.xu@linux.dev> In-Reply-To: <20220617143603.179277-1-hao.xu@linux.dev> References: <20220617143603.179277-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Hao Xu This does three things: - change multishot_mask from uint to uint32_t - change multishot_mask != UINT_MAX check to ~multishot_mask != 0 The above two avoid compiler and arch influence. Make the logic more robost. - other cleaning to make code clearer. Signed-off-by: Hao Xu --- test/accept.c | 66 +++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/test/accept.c b/test/accept.c index b322c018c7a9..78eba352a943 100644 --- a/test/accept.c +++ b/test/accept.c @@ -41,6 +41,21 @@ struct accept_test_args { int extra_loops; }; +static void close_fds(int fds[], int nr) +{ + int i; + + for (i = 0; i < nr; i++) + close(fds[i]); +} + +static void close_sock_fds(int s_fd[], int c_fd[], int nr, bool fixed) +{ + if (!fixed) + close_fds(s_fd, nr); + close_fds(c_fd, nr); +} + static void queue_send(struct io_uring *ring, int fd) { struct io_uring_sqe *sqe; @@ -198,19 +213,17 @@ static int test_loop(struct io_uring *ring, int i, ret, s_fd[MAX_FDS], c_fd[MAX_FDS], done = 0; bool fixed = args.fixed; bool multishot = args.multishot; - unsigned int multishot_mask = 0; + uint32_t multishot_mask = 0; + int nr_fds = multishot ? MAX_FDS : 1; - for (i = 0; i < MAX_FDS; i++) { + for (i = 0; i < nr_fds; i++) c_fd[i] = set_client_fd(addr); - if (!multishot) - break; - } if (!args.queue_accept_before_connect) queue_accept_conn(ring, recv_s0, args); - for (i = 0; i < MAX_FDS; i++) { - s_fd[i] = accept_conn(ring, args.fixed ? 0 : -1, multishot); + for (i = 0; i < nr_fds; i++) { + s_fd[i] = accept_conn(ring, fixed ? 0 : -1, multishot); if (s_fd[i] == -EINVAL) { if (args.accept_should_error) goto out; @@ -241,14 +254,17 @@ static int test_loop(struct io_uring *ring, i, s_fd[i]); goto err; } + /* + * for fixed multishot accept test, the file slots + * allocated are [0, 32), this means we finally end up + * with each bit of a u32 being 1. + */ multishot_mask |= (1U << s_fd[i]); } - if (!multishot) - break; } if (multishot) { - if (fixed && multishot_mask != UINT_MAX) { + if (fixed && (~multishot_mask != 0U)) { fprintf(stderr, "Fixed Multishot Accept misses events\n"); goto err; } @@ -256,7 +272,7 @@ static int test_loop(struct io_uring *ring, } queue_send(ring, c_fd[0]); - queue_recv(ring, s_fd[0], args.fixed); + queue_recv(ring, s_fd[0], fixed); ret = io_uring_submit_and_wait(ring, 2); assert(ret != -1); @@ -280,32 +296,10 @@ static int test_loop(struct io_uring *ring, } out: - if (!args.fixed) { - for (i = 0; i < MAX_FDS; i++) { - close(s_fd[i]); - if (!multishot) - break; - } - } - for (i = 0; i < MAX_FDS; i++) { - close(c_fd[i]); - if (!multishot) - break; - } + close_sock_fds(s_fd, c_fd, nr_fds, fixed); return 0; err: - if (!args.fixed) { - for (i = 0; i < MAX_FDS; i++) { - close(s_fd[i]); - if (!multishot) - break; - } - } - for (i = 0; i < MAX_FDS; i++) { - close(c_fd[i]); - if (!multishot) - break; - } + close_sock_fds(s_fd, c_fd, nr_fds, fixed); return 1; } @@ -627,7 +621,7 @@ static int test_accept_fixed(void) static int test_multishot_fixed_accept(void) { struct io_uring m_io_uring; - int ret, fd[100]; + int ret, fd[MAX_FDS]; struct accept_test_args args = { .fixed = true, .multishot = true