From patchwork Mon Apr 8 14:24:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13621241 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 D0C6E128370 for ; Mon, 8 Apr 2024 14:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712586279; cv=none; b=McZ7SnNwCf0DWiMfK8cF+iQ6hOx1x/oO5k0EWYaoGLUIahawq8Lg89rx3idV08CgHyql5o71XDkAJdQFN4y2qbff4N9FiNILmivK3Q2z1JGKCiApF4xiQ5ZofIP4ip8oHlRNUmxq63qqa948yVV7MU2R3plnGIRdp2pVEOpBC0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712586279; c=relaxed/simple; bh=M4ATQ1sbm2RL2eHgaaohsbvVU5PBOypORZjR9K/TtHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QJX/RhmTSIpMB52Dq1PwnsCVFpVTBV3w7OIEMCi3aBnpoL0wRdJeU37c3bjmzNHHXbsG9H6hesIfZikfOKuwtdJ5K7WfsCkcn3TEUT92gPcZGZnMMCRiWou5PED0UkUPFslu0EXWiwgBIIvq7mAsdxylxzCbWG9AdmsZci3L9do= 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=Lwm9Ioub; arc=none smtp.client-ip=209.85.208.41 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="Lwm9Ioub" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-56e6affdd21so194418a12.3 for ; Mon, 08 Apr 2024 07:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712586276; x=1713191076; 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=Lwm9Ioub9a3ZiuZW8E74w+gIVcd/53f/+NyqujbBS9fH932HqBNkI/zujXgr4Mmoe/ RiPLnel2wEPmzlirWKz8Ckr0wOfhXK/2wx5Lz3z80r96vzbrxgSyVU+Vjy8Kdk+dEZ7r 7dSX9RfinN9gnH8P2vVwaFCpymJCW7RyWzf2mL/V1Xs4aV/fTtJ8d/FlzJv9vf1jW85n giLWmhi6P13QhY+j2rpObJLukzHfZRhetu1K9D1+HOgoOC0GWdZ6Vr/VoOVk7LNB2r9s sKRupiQ0knvcdjkKVyNlpRrrzk6AfMd1orhEtKOzNNZqXoADtvG8IzOZlDYcPcl5C/DO DHCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712586276; x=1713191076; 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=T91zJMtKUJHqBNOqGI7RZvXet3MYW4EBWYiYSdlXrc4jxgBmHD3A3iLJRiLfd1Aow5 of42kTO01bfRLMPwaQPej/niv7O1aAx70cWre9Ovi7voRTgjePeJg8u6MbkLVC3zPdmC 3ughhbytKsMbUpykGvbtRuctfHo86Mv7FFzyAhsevyk/TEAK68tnHAvb9Gjeik7KraXw /MTWrC7UmqvARGS7n3fa51ksqbwdxl+A15yWGsqXdTpxePy37bZd/9H8I5+f1vBONm49 +i+E9FSOV8In2G6Rg23UTd+OaVI6rS/vWJtReU3VmF6rQ31SW51P5xdWmsSRtd1GRRvv S2KA== X-Gm-Message-State: AOJu0Yz4eebsZNBFNPTQ6LoAcQ5Uv5wh7QjmkOUTBrw1yCwvB115XcQg QnCwhyQPWIxwmMd+dgGOZBa5Ka1q60x5YYuqHfgNkLd6h9Un6aHfHO+wlXUO X-Google-Smtp-Source: AGHT+IGb1XMPOE0p1jXQsJqqnnqD0IUMOgcDCDRgxB3+uXTkg5UtCmaN98XSMloodbEHhESSwGNAOA== X-Received: by 2002:a50:9313:0:b0:568:abe3:52b2 with SMTP id m19-20020a509313000000b00568abe352b2mr8998275eda.23.1712586275767; Mon, 08 Apr 2024 07:24:35 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id p2-20020a056402500200b0056c051e59bfsm4215931eda.9.2024.04.08.07.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:24:31 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 1/3] test: handle test_send_faults()'s cases one by one Date: Mon, 8 Apr 2024 15:24:20 +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 14:24:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13621242 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 40F05128826 for ; Mon, 8 Apr 2024 14:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712586281; cv=none; b=mbzM6pyACx6WdxN+luhFrd1+HnTJ+ya+caZscUS82xfkWGP9YskP73yJmC/wtr/ooYQ6uTRvtUGEiRONbcWJ6/khBhNkxO5wWiYcbMHpSGIpyHqmN82RORN2k1OMQuxLSfbz8WJEaNfwcrBbDiI7GdqgUrAhLk4VxR1P5mGe8uY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712586281; c=relaxed/simple; bh=6sxvctNB1MFWCMZ3AEMKNrkwAGhQkYQk5pwhhPQSNdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NbmWDC1YIz0hQay1OINyuIl1j9SeUO4zV9AAxvOuqDnItOC5OYANNoDgGzfbKDyx5QLgu/RvQUtZr14E4CE79eO+9b0+DrmH4em/3j09Hg6jF9XTXoTEGXLgSRx0b1ucVrQmJsWx8+++GWHLZ0AswCP+LLjXrdeIK/BCKiKoy7I= 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=mbQM54uk; arc=none smtp.client-ip=209.85.208.52 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="mbQM54uk" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-56e346224bdso2596841a12.1 for ; Mon, 08 Apr 2024 07:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712586277; x=1713191077; 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=mbQM54ukhs1g2qvC38ksKeUKVZz4W1egkT6M1Ayn/TR50smdFZQVfGj4gMAT0XLdKE R6X7awPwtn7uR2qzMJDujvbmfyd84+BkMZmDQ8vh4AzZw7tEw+mgjhDcqd3HlrWC+PEK pua2qAN0jIGVa6sSBCfcUqb2PzXm88zfEOLBm/RvKY3Gob7kQreSZ4nuhyanPvBBNTRJ PQpNgH229dYv5CL3cqO4Fy7GMDpy2TzNSjuz1Sa3HCvu8fVYIzpKK7iQYzp4VMEjeT9G p14RY4y/KCW5hmXLdFlEJ/SnULUVsi2EdzEC9XjjQPLIzmcM9TkC7u2UxoW6n4NqOdpQ z69w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712586277; x=1713191077; 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=IfU45ZDbZQuKs0xBOlm3Tz8wUWdpLi9LCZoO7C+M/hT/fl6S7TcOWNf85hBxyy2j24 ZmpcOFOhYoYJKuUj8MC5pRUkY/GVWvk5Ut/QLUmVXLznX+NFUDs0W/CFLYWCLFzLc1WL 9PsN5VOunbTQeueOPUsAakB1mLN3K9EB5feiNfx7nzJNaZiphiMScUQw6gpi4UGFOxC6 EfYqFSyqHJcm4ZleCE6nkcIsOp/UtLuAq8s/Wz1vPx4sqIyQKj0Em6TO+6S/FFihjknL OZAM8FT0Hoc608r/FTO+qKXwN33bGVJ/1K9lnVykb0I/Skgr0TIyjY1eqXXopBn5WL3/ tZpg== X-Gm-Message-State: AOJu0YyPLnQxpAnx8P1VduA8LvV93Mls5awOJF+p+YBdupF8PCPKpU7c Om0CLEXQV2bOuhvlj7GCLNwkoyGwJXlhxEOj+UowcMdKXUkbV9U25zXQlPq5 X-Google-Smtp-Source: AGHT+IGScGV9yT6oO9zqiCGwAEL1q2gQf9TaRyM11k9DOkQ0+1qFC1aw8KBGW81XZNnFF5Gr2WU+8g== X-Received: by 2002:a50:8d50:0:b0:56d:c548:6af8 with SMTP id t16-20020a508d50000000b0056dc5486af8mr6524128edt.9.1712586276836; Mon, 08 Apr 2024 07:24:36 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id p2-20020a056402500200b0056c051e59bfsm4215931eda.9.2024.04.08.07.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:24:36 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 2/3] test/sendzc: improve zc support probing Date: Mon, 8 Apr 2024 15:24:21 +0100 Message-ID: <03c9abafbf8d00d8f5f44fb61ce990cac0960121.1712585927.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 14:24:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13621243 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 198341292D5 for ; Mon, 8 Apr 2024 14:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712586282; cv=none; b=FfLxOEqd6EGDVpONaY7exbbdEwtTCGNntk1pgcAngw8aEZQTX6dkZ8CsL8GTKXKgjh79pRZPBolpUoaNXXQg21tC1vo4VfVNRyiTXaEAjHRBYEUoIcGzz0VQ4+hejdyp2QrIuzTeUWK7xLtj0SPpSzF+S3liR5ZM6+i6l5aZNZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712586282; c=relaxed/simple; bh=zeM9kKKhN8rNtMO2kXk/RwlTqwIP9ZTfeJJZ+c69srk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hZrPMRAbh0QrqP7R8+JiodXocYSUJSPv9nfU9oYmmDbBSKrPEK5RjVpg2Jk8xQDO3oJyR/++Onuuu9lG/35YLsiW8DMeNGL9QvgrHJ1R6U3vIDkKyC1NlKwhLgrQxpLDh4dYM9oYiKmOwVQnEKhd99azLGDbAHvLVRs9snuY3UM= 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=jpP9HoXT; arc=none smtp.client-ip=209.85.208.46 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="jpP9HoXT" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5684db9147dso6065479a12.2 for ; Mon, 08 Apr 2024 07:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712586278; x=1713191078; 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=Lr4O3znenP67qTm2+G0rxhUamOBYj7bHIbNbdowf5Uw=; b=jpP9HoXTrQQPXWHah3F8yI84UQQW+aQzrDkc8Fh6UXjeUoa7AePmvMXS0QUTWHK0ws 5F2IHudzgM02ZXYV1u7z0+Y0ZrBlM8jjCxOZSVyozS1cLSlKYqEHwRX8p+Bxj6xr4Udg LQyyPZgEDaruwf4HpoNlg2Up+QMZ5OKBRqkZCUecX87QCaISJpdpY6Htr3HmKYOF1wnk opvof/QMmP43Hr3a7jQOuooUJIRBPfQqULYfj4T4leh8svZOh6tVfDnuDVARMDlSBdie hca3wrZpuJmL0iKbyXg2JX2SE5srOgQbbs1wOvGw2HnX7+f2AVXUKGhegy5kVKUB0knb coQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712586278; x=1713191078; 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=Lr4O3znenP67qTm2+G0rxhUamOBYj7bHIbNbdowf5Uw=; b=OXu5vtEaxLHyJLr1y57RR3t1UJYigD3wBOjjc2SMqdfNZOC0HH2PFfRd+DSeV7/AY1 rnhABL+J49VjbVDZDxrGAhjLdW/O6VSlwJb2Q2EWdjSfnX6K6QxLAOPcc9Kc7T8IKXUc LgFF3vrsV+eGXWQZ+NtPv06zNG4RjSvYdDSOk8oVuxV88QBkLJoMAXwVSONEr8yysv1e tTocW334nFRpQhGq7RtVChpNZG4oLZoNQJT11phJwOWd0YY1wx8TkoBSyzRnohvA1k/+ KVPoHN6bmlshITQeO6tMWFh4XownpfKetOH/kzWefLK7FxZ0Cpf+aj7dkFa+V1ZCq6SE zxTQ== X-Gm-Message-State: AOJu0YxUmbPUoBMdEHN1/2re3OIZZPOwAacUUBRHtc9HiRY4kBUhgr5l zJGnSTmNK7TqZZmbo4EOVOHS2oz7zeYbAWYg4Bi8s1vbqK/xtQCVkXcx6NiZ X-Google-Smtp-Source: AGHT+IG/iicnjVO7F9SaSDiGEbAGS39P3t0u2Zz38ia6o8yiNekIsdyip8KR/mqMzc+UQ8N+W1JX9Q== X-Received: by 2002:a50:d691:0:b0:56c:3b74:ea4 with SMTP id r17-20020a50d691000000b0056c3b740ea4mr6076227edi.21.1712586278241; Mon, 08 Apr 2024 07:24:38 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id p2-20020a056402500200b0056c051e59bfsm4215931eda.9.2024.04.08.07.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:24:37 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 3/3] io_uring/sendzc: add DEFER_TASKRUN testing Date: Mon, 8 Apr 2024 15:24:22 +0100 Message-ID: <83567247122f6b3d4206dcd8f874651703184792.1712585927.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 Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 166 +++++++++++++++++++++++++++---------------- 1 file changed, 106 insertions(+), 60 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index bfb15d2..4699cf6 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,61 @@ 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_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; }