From patchwork Mon Apr 8 16:38:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13621381 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D861142E9D for ; Mon, 8 Apr 2024 16:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712594299; cv=none; b=sriMkGsT7p2KCYy9THEZRXGgOXi6cZ59ab7Vi5HMN2MgSjb/QVQpYePyDj9IabFf06zIiFbzqUgJCwGOlvbEz6SyyIJJQpauWSOV6PMoCuHo4eLn3C06Hgj892URGU+czciMhsebIEdrG6bRVrV7SGlJg9u81Xby/3O/wYae8EQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712594299; c=relaxed/simple; bh=M4ATQ1sbm2RL2eHgaaohsbvVU5PBOypORZjR9K/TtHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XyQE7In+o4NvxXgedTUjbe1tZo7UlH4wGwkwsIri5hlLnevZQetkqG5zB8QkjtYq040U3J2hxsBNcIkKaQYIQm6T74dN85H+1SFyowWxbqHQTh39emWkiqRhQ7MAxcmmk5IHH4BZbbnHtHv0oeYGqpWbru7GMxws+bnpgPsebqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aAcBMAks; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aAcBMAks" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-56e2e09fc27so6247193a12.0 for ; Mon, 08 Apr 2024 09:38:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712594296; x=1713199096; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y65CuKMgg25XG0Xg3kbEUXjWah7bHKu3dyEjBXl47eo=; b=aAcBMAksT0x6pFJgWkXF7H6q8aYeseP02XJYlkF4pDKO8wg/oOduNUjpJ6a8UfYI4H zpBGGfySRMA8XPzzIUL4yA/8dh2PeAtVY/6/P/qpHRb7EVEL68AX3W30ZhlawIr0CAD5 Xn2GZqKlZtNoW/VaRqWINalD2RmtKwc4oqVH3IsDIyhUebjr9FoIUbJHMY7CP6ufozJk Smj5DuYaMO13MPDZXCbEaodbfcYRVguZAEID5U6bAdd3yVv65QuTX9SnbT9Vn/Qx9knB 3WXspx9PZ5aM6YT3iUQUmOX1CRlwUEgGFPBVuwAJ6MGzPFGtlBspfYDiL5EeFt7epzqd JOhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712594296; x=1713199096; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y65CuKMgg25XG0Xg3kbEUXjWah7bHKu3dyEjBXl47eo=; b=jsJx6pCpXO4XxF7u268VsBNcm/nc8AuwF3oicV8rM/jN0fkQkbiojxn8XHtrCwc23N u+Nb6Ly/EchBNebHAsxx64NmMqDZczOgF3yr2m7O1VRv+HhMFdImF5K8YAXv2BgWzYZe r2v9qlXFqzamXJMBmq7ndHWi+MGc4AOoZtMSbEgrCQ/JN9EH867nA98JpmOsxNLqXe/K Q/RgPRwNVtPLPahsE/XKL9KXPaYAQPYnADV3MqE6qaBNhYRMWsuzB7X/ei33NFQJdjjU SHrvW7SrnOKmrRfKPGEAXHaOcFsoVdOlsAgIQmivWKWU96BLK4F6R6BhdxboVxxXO7fz ZqaA== X-Gm-Message-State: AOJu0Yz9HkIz/uAkEJDkiixp3/HvXVbP9o0ozwiHNcO3Qr4kSwNKRPWi 5rKt9oi1VKKD026skcbBG01OEbRcuwSV07yTauoVX9y+t2dU/nLPRkpRdYWQ X-Google-Smtp-Source: AGHT+IHOo6mV3UqANtvy0yVQ38id5NBrahOHaW42Zw0+H0lOEMYY0uR1UPQDtpwQxSWAffC5RfiX3g== X-Received: by 2002:a50:f610:0:b0:56c:195d:b162 with SMTP id c16-20020a50f610000000b0056c195db162mr228486edn.6.1712594295567; Mon, 08 Apr 2024 09:38:15 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a9-20020a05640233c900b0056db8d09436sm4143363edc.94.2024.04.08.09.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 09:38:15 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing v2 1/3] test: handle test_send_faults()'s cases one by one Date: Mon, 8 Apr 2024 17:38:10 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are 3 different cases tested by test_send_faults(), requests for which are sent together. That's not too convenient, complicates CQEs checking and opens some space for error. Do them one at a time. Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 105 +++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 34 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index 1b6dd77..78ec3d7 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -122,17 +122,60 @@ static int test_basic_send(struct io_uring *ring, int sock_tx, int sock_rx) return T_EXIT_PASS; } +static int test_send_faults_check(struct io_uring *ring, int expected) +{ + struct io_uring_cqe *cqe; + int ret, nr_cqes = 0; + bool more = true; + + while (more) { + nr_cqes++; + ret = io_uring_wait_cqe(ring, &cqe); + assert(!ret); + assert(cqe->user_data == 1); + + if (nr_cqes == 1 && (cqe->flags & IORING_CQE_F_NOTIF)) { + fprintf(stderr, "test_send_faults_check notif came first\n"); + return -1; + } + + if (!(cqe->flags & IORING_CQE_F_NOTIF)) { + if (cqe->res != expected) { + fprintf(stderr, "invalid cqe res %i vs expected %i, " + "user_data %i\n", + cqe->res, expected, (int)cqe->user_data); + return -1; + } + } else { + if (cqe->res != 0 || cqe->flags != IORING_CQE_F_NOTIF) { + fprintf(stderr, "invalid notif cqe %i %i\n", + cqe->res, cqe->flags); + return -1; + } + } + + more = cqe->flags & IORING_CQE_F_MORE; + io_uring_cqe_seen(ring, cqe); + } + + if (nr_cqes > 2) { + fprintf(stderr, "test_send_faults_check() too many CQEs %i\n", + nr_cqes); + return -1; + } + assert(check_cq_empty(ring)); + return 0; +} + static int test_send_faults(int sock_tx, int sock_rx) { struct io_uring_sqe *sqe; - struct io_uring_cqe *cqe; int msg_flags = 0; unsigned zc_flags = 0; - int payload_size = 100; - int ret, i, nr_cqes, nr_reqs = 3; + int ret, payload_size = 100; struct io_uring ring; - ret = io_uring_queue_init(32, &ring, IORING_SETUP_SUBMIT_ALL); + ret = io_uring_queue_init(32, &ring, 0); if (ret) { fprintf(stderr, "queue init failed: %d\n", ret); return -1; @@ -143,6 +186,14 @@ static int test_send_faults(int sock_tx, int sock_rx) io_uring_prep_send_zc(sqe, sock_tx, (void *)1UL, payload_size, msg_flags, zc_flags); sqe->user_data = 1; + ret = io_uring_submit(&ring); + assert(ret == 1); + + ret = test_send_faults_check(&ring, -EFAULT); + if (ret) { + fprintf(stderr, "test_send_faults with invalid buf failed\n"); + return -1; + } /* invalid address */ sqe = io_uring_get_sqe(&ring); @@ -150,44 +201,30 @@ static int test_send_faults(int sock_tx, int sock_rx) msg_flags, zc_flags); io_uring_prep_send_set_addr(sqe, (const struct sockaddr *)1UL, sizeof(struct sockaddr_in6)); - sqe->user_data = 2; + sqe->user_data = 1; + ret = io_uring_submit(&ring); + assert(ret == 1); + + ret = test_send_faults_check(&ring, -EFAULT); + if (ret) { + fprintf(stderr, "test_send_faults with invalid addr failed\n"); + return -1; + } /* invalid send/recv flags */ sqe = io_uring_get_sqe(&ring); io_uring_prep_send_zc(sqe, sock_tx, tx_buffer, payload_size, msg_flags, ~0U); - sqe->user_data = 3; - + sqe->user_data = 1; ret = io_uring_submit(&ring); - assert(ret == nr_reqs); - - nr_cqes = nr_reqs; - for (i = 0; i < nr_cqes; i++) { - ret = io_uring_wait_cqe(&ring, &cqe); - assert(!ret); - assert(cqe->user_data <= nr_reqs); - - if (!(cqe->flags & IORING_CQE_F_NOTIF)) { - int expected = (cqe->user_data == 3) ? -EINVAL : -EFAULT; + assert(ret == 1); - if (cqe->res != expected) { - fprintf(stderr, "invalid cqe res %i vs expected %i, " - "user_data %i\n", - cqe->res, expected, (int)cqe->user_data); - return -1; - } - if (cqe->flags & IORING_CQE_F_MORE) - nr_cqes++; - } else { - if (cqe->res != 0 || cqe->flags != IORING_CQE_F_NOTIF) { - fprintf(stderr, "invalid notif cqe %i %i\n", - cqe->res, cqe->flags); - return -1; - } - } - io_uring_cqe_seen(&ring, cqe); + ret = test_send_faults_check(&ring, -EINVAL); + if (ret) { + fprintf(stderr, "test_send_faults with invalid flags failed\n"); + return -1; } - assert(check_cq_empty(&ring)); + return T_EXIT_PASS; } From patchwork Mon Apr 8 16:38:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13621382 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98823142645 for ; Mon, 8 Apr 2024 16:38:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712594300; cv=none; b=Glxh1mfHEfWrfXVKkRI8Uszj0ZE+Uhj76hSpMkcCzpuFPW750fKUT4NgEv5oUibWZUDMP9CUlias+jccK2M/vuOEapT8kneZTwezts0UFxUFBPnw78l0BLx9udfpdzruQEcGqSasLxWDnoykJ/4Dm0YiouirLBzXtsRYhkBgEJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712594300; c=relaxed/simple; bh=6sxvctNB1MFWCMZ3AEMKNrkwAGhQkYQk5pwhhPQSNdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MAmfYaa0BNzeSdiX/nOri+31mlMURu9PZE4SM+dfGg+xNpwrYmdojPIwefaCZpIp+b9eYYZ2PsALkrs0QcqQzx8UoVsdeN3ACmCXry1gtP7ACHG7PiZ5xVzg4mhUWnV3DeCAPCQczrDPowaGI9zdlOwZ3FtMH8JUT5E/n15Q+/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RABu6RwY; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RABu6RwY" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-563cb3ba9daso4666102a12.3 for ; Mon, 08 Apr 2024 09:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712594296; x=1713199096; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=56MtQnlxZ37Dx+mxQgx8+kGEzWzmbJcVyicBWxdegjM=; b=RABu6RwYchhX9FxlOgJpB07Bsah/KOwzIWK+V7dbwCtnXpIQStz0Bg0qjqjbIyWrVd jr7atcxy9KmLMqbmxNMQp12bc905pOKU5l8CHillOiijV1AVfHuuuDdMZ+1lSXNyPqD1 wAwZxhp2tuKlHuquuPx9s+fWGHL/gumT5iZNuH1B+E0ptzdQa71H5uDPktrpc0hKtd3d rpBmZtMtxguFu+3rO+4xLUDtN3FSTRadeG9iU4a8FZIPzMtCsXc4vP7xhQ+1tL8OxFwJ snuQR7flmgyMnPbqSB92+z7e75+5lmZ0e6zjN4kZ3sBZ/YbgOSFsXcnt4PFsH2Q4sd6t RWYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712594296; x=1713199096; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=56MtQnlxZ37Dx+mxQgx8+kGEzWzmbJcVyicBWxdegjM=; b=pwr2pxBrz2txWc/od26VfbqpsQKzaRnFBQNHkU6PemBSiHJ4GL8EToOlkg8f1TU/C+ 2mZ7oI87UkV7cl09GzzuqsLqIcc0rwi/g1LTsASza9gREhOpMVsve8znDTbmeBJ2uUPf 4R1wrN4ltXH+/kbi7OMAF4eAqYLvSM9gdcEFFRpF28YEovDpI8CZr0cTY3n0oXhY5A7d Q8vIjHRzmiJ/xaq3z6lEgIOLolT60Qvs19RxgFygs8lS0v0NeBGcaEswgGZDx3rJ1ctl 1XPlBAinJevRZrv9BJ5aMi8qgHg2UTs5gM9t2Mpg61zw9XcOYRP69aN50Eha8iCOtbq1 grxA== X-Gm-Message-State: AOJu0Yxsu3tWQqqGc4L3ETyJgYd/HTglfo93VZOez7KxMg3f4SEc+OSX Kt4CILVTmPM9h78wzq2DLX6aAyaTzL+SwuiLTuj+Nc0lWvmQ6xKtthYO7FBi X-Google-Smtp-Source: AGHT+IEgznayZtobV36B4buHkfIzz2mA+mxVlPH7s63dzHdwSvrlJP+ovciHbhb1rgU94tLtFUTIzw== X-Received: by 2002:a50:9e44:0:b0:56e:2d93:3f8a with SMTP id z62-20020a509e44000000b0056e2d933f8amr6674166ede.28.1712594295985; Mon, 08 Apr 2024 09:38:15 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a9-20020a05640233c900b0056db8d09436sm4143363edc.94.2024.04.08.09.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 09:38:15 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing v2 2/3] test/sendzc: improve zc support probing Date: Mon, 8 Apr 2024 17:38:11 +0100 Message-ID: <03c9abafbf8d00d8f5f44fb61ce990cac0960121.1712594147.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move probing whether we support zerocopy send or not to the beginning instead of relying on test_basic_send(). Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 64 +++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index 78ec3d7..bfb15d2 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -68,8 +68,37 @@ enum { static size_t page_sz; static char *tx_buffer, *rx_buffer; static struct iovec buffers_iov[__BUF_NR]; + +static bool has_sendzc; static bool has_sendmsg; +static int probe_zc_support(void) +{ + struct io_uring ring; + struct io_uring_probe *p; + int ret; + + has_sendzc = has_sendmsg = false; + + ret = io_uring_queue_init(1, &ring, 0); + if (ret) + return -1; + + p = t_calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op)); + if (!p) + return -1; + + ret = io_uring_register_probe(&ring, p, 256); + if (ret) + return -1; + + has_sendzc = p->ops_len > IORING_OP_SEND_ZC; + has_sendmsg = p->ops_len > IORING_OP_SENDMSG_ZC; + io_uring_queue_exit(&ring); + free(p); + return 0; +} + static bool check_cq_empty(struct io_uring *ring) { struct io_uring_cqe *cqe = NULL; @@ -98,10 +127,7 @@ static int test_basic_send(struct io_uring *ring, int sock_tx, int sock_rx) ret = io_uring_wait_cqe(ring, &cqe); assert(!ret && cqe->user_data == 1); - if (cqe->res == -EINVAL) { - assert(!(cqe->flags & IORING_CQE_F_MORE)); - return T_EXIT_SKIP; - } else if (cqe->res != payload_size) { + if (cqe->res != payload_size) { fprintf(stderr, "send failed %i\n", cqe->res); return T_EXIT_FAIL; } @@ -700,22 +726,6 @@ static int test_async_addr(struct io_uring *ring) return 0; } -static bool io_check_zc_sendmsg(struct io_uring *ring) -{ - struct io_uring_probe *p; - int ret; - - p = t_calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op)); - if (!p) { - fprintf(stderr, "probe allocation failed\n"); - return false; - } - ret = io_uring_register_probe(ring, p, 256); - if (ret) - return false; - return p->ops_len > IORING_OP_SENDMSG_ZC; -} - /* see also send_recv.c:test_invalid */ static int test_invalid_zc(int fds[2]) { @@ -769,6 +779,16 @@ int main(int argc, char *argv[]) if (argc > 1) return T_EXIT_SKIP; + ret = probe_zc_support(); + if (ret) { + printf("probe failed\n"); + return T_EXIT_FAIL; + } + if (!has_sendzc) { + printf("no IORING_OP_SEND_ZC support, skip\n"); + return T_EXIT_SKIP; + } + page_sz = sysconf(_SC_PAGESIZE); /* create TCP IPv6 pair */ @@ -834,15 +854,11 @@ int main(int argc, char *argv[]) } ret = test_basic_send(&ring, sp[0], sp[1]); - if (ret == T_EXIT_SKIP) - return ret; if (ret) { fprintf(stderr, "test_basic_send() failed\n"); return T_EXIT_FAIL; } - has_sendmsg = io_check_zc_sendmsg(&ring); - ret = test_send_faults(sp[0], sp[1]); if (ret) { fprintf(stderr, "test_send_faults() failed\n"); From patchwork Mon Apr 8 16:38:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13621383 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06B6714263A for ; Mon, 8 Apr 2024 16:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712594301; cv=none; b=LOjmY0Ce6u5JNmwhzUuJTwC4fTFZ4MIakZL+1a+EieWO4CrDC8Q55yAl7KSlXtgsTOnkQqxMZ8va0jv24PJrJS7m2VX/rwaTpudz7R7cXdem+XlxQS1TwTJT3v8wjQS35COeHgolms9zAJ0vQ1MNKGwP4XvCKxbjj2jO6DBHpiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712594301; c=relaxed/simple; bh=/xAzunz5QJb/gej6uMTzTd1gJw9R7sqb4Eg9a6v9Ris=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UDlFHFCKS+L2WXPjKjSI86IHCRneGtDqcKn40OfIK5S2SS28KiYpMvIJ15+A2GhntGH9gzUzZFF4ln5itbHU0XY/5SKLG+UOXJQ/P1DDZPPREbX5j9b6K94aaHz/qSWtruR+/LfwXlqEIR2G00KQq5nVOktcmrwmf39UvN5VzVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XlGf2/Ev; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XlGf2/Ev" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-56e6acb39d4so937632a12.1 for ; Mon, 08 Apr 2024 09:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712594297; x=1713199097; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/77+9xmRbUnNHDqDUdWfHJeRMdFLPAxJFhvezOU4KeI=; b=XlGf2/EvzdL9der7wA36htTtTeMSNM3eqT07nnxLiL2OY6oXJuJqEm6YSLNro428FS WqLlU+S654d+4Gj0jt03IGpTzGS3y+hYpe5PVrlL0McJZdF3LQl93J/J2O2CmvWhXTbg R18czlbJ7zKsXcQ+ocUAkSrhJjJeMkcAEMBN9vryVfDB+BdIq4yM1fKkuX2lXGsikq0C 4pQNGQiHk7/FQx//+AVyICB+icrQWcerUVhw9FOsFYwYqVPwmeKksTRu1XmaEkARa7fI iWlugO0twAHZXyYoA+BuSogaf6u4eFF7gxbam3NqqgHKLWU7UHbK3PU1jbNqc3G0D8NS u8fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712594297; x=1713199097; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/77+9xmRbUnNHDqDUdWfHJeRMdFLPAxJFhvezOU4KeI=; b=H/a2/BmAMw9W4v0a2W896m96sXhui+qN+bxzrpeErr4ISxL8z0qTdGi+ooKsLOdPll czNs6BUe4FJ/7b/+I0rTfxF2q9BGebRPeDLrtWH/4o/ffIzz+pAGddZ5sJzDwn5BcU/F tzth4tVsOcHaqIi5nDR0A9T4aWbz7uZZvisZHlkfHGV98stZ+1z4yUAL2NxLtp+bhJo1 jaYf1pGKOk7JjdML52Wgwb2QNc4j/R4hl9ecIxXUjnAj17vmRgzCOOJCFmzWit68CJqt 12WLn4F1lK6aj/RMZcfvTMKN7uJCxJDTNmJ6seTn3mj8lh9EGmCcssnpeFDxti8tk/q7 SxeQ== X-Gm-Message-State: AOJu0YwbHPuwAbEy9m2NR8PnZ03Obx2/j3bkdeYyTZ1woLI9YO6aECFG 9yZFa2sn1C72oxs9Lc9azUTRpdQZ4zAbF3zgw02lnyDvAdiUKbtn1HnjpX7c X-Google-Smtp-Source: AGHT+IFfRbGnKSsq9WvL+NczbHYBDLHeYUwmLthbyH2+Vj8plqy/Mg2xunYpLyxNDa04ammHtUi3PQ== X-Received: by 2002:a50:f69a:0:b0:56e:3034:1d4a with SMTP id d26-20020a50f69a000000b0056e30341d4amr6453451edn.9.1712594297508; Mon, 08 Apr 2024 09:38:17 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a9-20020a05640233c900b0056db8d09436sm4143363edc.94.2024.04.08.09.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 09:38:16 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing v2 3/3] io_uring/sendzc: add DEFER_TASKRUN testing Date: Mon, 8 Apr 2024 17:38:12 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 167 +++++++++++++++++++++++++++---------------- 1 file changed, 107 insertions(+), 60 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index bfb15d2..ad214bb 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -769,12 +769,69 @@ static int test_invalid_zc(int fds[2]) return 0; } -int main(int argc, char *argv[]) +static int run_basic_tests(void) { struct sockaddr_storage addr; - struct io_uring ring; - int i, ret, sp[2]; + int ret, i, sp[2]; + + /* create TCP IPv6 pair */ + ret = create_socketpair_ip(&addr, &sp[0], &sp[1], true, true, false, true); + if (ret) { + fprintf(stderr, "sock prep failed %d\n", ret); + return -1; + } + + for (i = 0; i < 2; i++) { + struct io_uring ring; + unsigned ring_flags = 0; + + if (i & 1) + ring_flags |= IORING_SETUP_DEFER_TASKRUN; + + ret = io_uring_queue_init(32, &ring, ring_flags); + if (ret) { + if (ret == -EINVAL) + continue; + fprintf(stderr, "queue init failed: %d\n", ret); + return -1; + } + + ret = test_basic_send(&ring, sp[0], sp[1]); + if (ret) { + fprintf(stderr, "test_basic_send() failed\n"); + return -1; + } + + ret = test_send_faults(sp[0], sp[1]); + if (ret) { + fprintf(stderr, "test_send_faults() failed\n"); + return -1; + } + + ret = test_invalid_zc(sp); + if (ret) { + fprintf(stderr, "test_invalid_zc() failed\n"); + return -1; + } + + ret = test_async_addr(&ring); + if (ret) { + fprintf(stderr, "test_async_addr() failed\n"); + return T_EXIT_FAIL; + } + + io_uring_queue_exit(&ring); + } + + close(sp[0]); + close(sp[1]); + return 0; +} + +int main(int argc, char *argv[]) +{ size_t len; + int ret, i; if (argc > 1) return T_EXIT_SKIP; @@ -791,13 +848,6 @@ int main(int argc, char *argv[]) page_sz = sysconf(_SC_PAGESIZE); - /* create TCP IPv6 pair */ - ret = create_socketpair_ip(&addr, &sp[0], &sp[1], true, true, false, true); - if (ret) { - fprintf(stderr, "sock prep failed %d\n", ret); - return T_EXIT_FAIL; - } - len = LARGE_BUF_SIZE; tx_buffer = aligned_alloc(page_sz, len); rx_buffer = aligned_alloc(page_sz, len); @@ -847,65 +897,62 @@ int main(int argc, char *argv[]) } } - ret = io_uring_queue_init(32, &ring, 0); - if (ret) { - fprintf(stderr, "queue init failed: %d\n", ret); + ret = run_basic_tests(); + if (ret) return T_EXIT_FAIL; - } - ret = test_basic_send(&ring, sp[0], sp[1]); - if (ret) { - fprintf(stderr, "test_basic_send() failed\n"); - return T_EXIT_FAIL; - } + for (i = 0; i < 2; i++) { + struct io_uring ring; + unsigned ring_flags = 0; - ret = test_send_faults(sp[0], sp[1]); - if (ret) { - fprintf(stderr, "test_send_faults() failed\n"); - return T_EXIT_FAIL; - } + if (i & 1) + ring_flags |= IORING_SETUP_SINGLE_ISSUER | + IORING_SETUP_DEFER_TASKRUN; - ret = test_invalid_zc(sp); - if (ret) { - fprintf(stderr, "test_invalid_zc() failed\n"); - return T_EXIT_FAIL; - } + ret = io_uring_queue_init(32, &ring, ring_flags); + if (ret) { + if (ret == -EINVAL) + continue; + fprintf(stderr, "queue init failed: %d\n", ret); + return -1; + } - close(sp[0]); - close(sp[1]); + ret = t_register_buffers(&ring, buffers_iov, ARRAY_SIZE(buffers_iov)); + if (ret == T_SETUP_SKIP) { + fprintf(stderr, "can't register bufs, skip\n"); + goto out; + } else if (ret != T_SETUP_OK) { + fprintf(stderr, "buffer registration failed %i\n", ret); + return T_EXIT_FAIL; + } - ret = test_async_addr(&ring); - if (ret) { - fprintf(stderr, "test_async_addr() failed\n"); - return T_EXIT_FAIL; - } + if (buffers_iov[BUF_T_HUGETLB].iov_base) { + buffers_iov[BUF_T_HUGETLB].iov_base += 13; + buffers_iov[BUF_T_HUGETLB].iov_len -= 26; + } + if (buffers_iov[BUF_T_LARGE].iov_base) { + buffers_iov[BUF_T_LARGE].iov_base += 13; + buffers_iov[BUF_T_LARGE].iov_len -= 26; + } - ret = t_register_buffers(&ring, buffers_iov, ARRAY_SIZE(buffers_iov)); - if (ret == T_SETUP_SKIP) { - fprintf(stderr, "can't register bufs, skip\n"); - goto out; - } else if (ret != T_SETUP_OK) { - fprintf(stderr, "buffer registration failed %i\n", ret); - return T_EXIT_FAIL; - } + ret = test_inet_send(&ring); + if (ret) { + fprintf(stderr, "test_inet_send() failed (defer_taskrun %i)\n", + ring_flags & IORING_SETUP_DEFER_TASKRUN); + return T_EXIT_FAIL; + } - if (buffers_iov[BUF_T_HUGETLB].iov_base) { - buffers_iov[BUF_T_HUGETLB].iov_base += 13; - buffers_iov[BUF_T_HUGETLB].iov_len -= 26; - } - if (buffers_iov[BUF_T_LARGE].iov_base) { - buffers_iov[BUF_T_LARGE].iov_base += 13; - buffers_iov[BUF_T_LARGE].iov_len -= 26; + if (buffers_iov[BUF_T_HUGETLB].iov_base) { + buffers_iov[BUF_T_HUGETLB].iov_base -= 13; + buffers_iov[BUF_T_HUGETLB].iov_len += 26; + } + if (buffers_iov[BUF_T_LARGE].iov_base) { + buffers_iov[BUF_T_LARGE].iov_base -= 13; + buffers_iov[BUF_T_LARGE].iov_len += 26; + } +out: + io_uring_queue_exit(&ring); } - ret = test_inet_send(&ring); - if (ret) { - fprintf(stderr, "test_inet_send() failed\n"); - return T_EXIT_FAIL; - } -out: - io_uring_queue_exit(&ring); - close(sp[0]); - close(sp[1]); return T_EXIT_PASS; }