From patchwork Wed Jun 15 11:37:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12882216 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 AC49AC43334 for ; Wed, 15 Jun 2022 11:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344921AbiFOLh4 (ORCPT ); Wed, 15 Jun 2022 07:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244420AbiFOLhx (ORCPT ); Wed, 15 Jun 2022 07:37:53 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA785DF52 for ; Wed, 15 Jun 2022 04:37:52 -0700 (PDT) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMcxu9026826 for ; Wed, 15 Jun 2022 04:37:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=AVjWiS5bok6GdHwvrHtDtEcPuI9GJl0o6PPco/WhOfM=; b=cMq2Y8/RV17S1LbaX3uzvTcUV8gbNsTS4Y7ZJpGYqYis7bfSa179pTxjAtDrEPAgaCZf 7k1UUyQIczdP5iUOP21PAio3tWi9ox7FfpggqgrwZyGtjhONFoJawdaBM7bG/68VEDWK zi5laWHFjcL2minSxCS+MSHYwK6/SjeRMbw= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gpgc2sht6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 15 Jun 2022 04:37:52 -0700 Received: from twshared25478.08.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 15 Jun 2022 04:37:50 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 0B7C71B0FD23; Wed, 15 Jun 2022 04:37:41 -0700 (PDT) From: Dylan Yudaken To: CC: , , , Dylan Yudaken Subject: [PATCH liburing] convert buf-ring nop test to use read Date: Wed, 15 Jun 2022 04:37:33 -0700 Message-ID: <20220615113733.1424472-1-dylany@fb.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: cLUtBfIJdDiiCnqxtl3gmv3dRvZSN0Cy X-Proofpoint-ORIG-GUID: cLUtBfIJdDiiCnqxtl3gmv3dRvZSN0Cy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-15_03,2022-06-13_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The NOP support for IOSQE_BUFFER_SELECT has been reverted, so use a supported function with read. This also allows verifying that the correct data has actually been read. Signed-off-by: Dylan Yudaken --- test/buf-ring.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) base-commit: d6f9e02f9c6a777010824341f14c994b11dfc8b1 diff --git a/test/buf-ring.c b/test/buf-ring.c index af1cac8..3d12ef6 100644 --- a/test/buf-ring.c +++ b/test/buf-ring.c @@ -206,7 +206,7 @@ static int test_reg_unreg(int bgid) return 0; } -static int test_one_nop(int bgid, struct io_uring *ring) +static int test_one_read(int fd, int bgid, struct io_uring *ring) { int ret; struct io_uring_cqe *cqe; @@ -218,21 +218,19 @@ static int test_one_nop(int bgid, struct io_uring *ring) return -1; } - io_uring_prep_nop(sqe); + io_uring_prep_read(sqe, fd, NULL, 1, 0); sqe->flags |= IOSQE_BUFFER_SELECT; sqe->buf_group = bgid; ret = io_uring_submit(ring); if (ret <= 0) { fprintf(stderr, "sqe submit failed: %d\n", ret); - ret = -1; - goto out; + return -1; } ret = io_uring_wait_cqe(ring, &cqe); if (ret < 0) { fprintf(stderr, "wait completion %d\n", ret); - ret = -1; - goto out; + return -1; } ret = cqe->res; io_uring_cqe_seen(ring, cqe); @@ -240,14 +238,12 @@ static int test_one_nop(int bgid, struct io_uring *ring) if (ret == -ENOBUFS) return ret; - if (ret != 0) { - fprintf(stderr, "nop result %d\n", ret); + if (ret != 1) { + fprintf(stderr, "read result %d\n", ret); return -1; } - ret = cqe->flags >> 16; -out: - return ret; + return cqe->flags >> 16; } static int test_running(int bgid, int entries, int loops) @@ -255,6 +251,7 @@ static int test_running(int bgid, int entries, int loops) struct io_uring_buf_reg reg = { }; struct io_uring ring; void *ptr; + char buffer[8]; int ret; int ring_size = (entries * sizeof(struct io_uring_buf) + 4095) & (~4095); int ring_mask = io_uring_buf_ring_mask(entries); @@ -262,6 +259,7 @@ static int test_running(int bgid, int entries, int loops) int loop, idx; bool *buffers; struct io_uring_buf_ring *br; + int read_fd; ret = t_create_ring(1, &ring, 0); if (ret == T_SETUP_SKIP) @@ -279,6 +277,10 @@ static int test_running(int bgid, int entries, int loops) if (!buffers) return 1; + read_fd = open("/dev/zero", O_RDONLY); + if (read_fd < 0) + return 1; + reg.ring_addr = (unsigned long) ptr; reg.ring_entries = entries; reg.bgid = bgid; @@ -293,11 +295,12 @@ static int test_running(int bgid, int entries, int loops) for (loop = 0; loop < loops; loop++) { memset(buffers, 0, sizeof(bool) * entries); for (idx = 0; idx < entries; idx++) - io_uring_buf_ring_add(br, ptr, 1, idx, ring_mask, idx); + io_uring_buf_ring_add(br, buffer, sizeof(buffer), idx, ring_mask, idx); io_uring_buf_ring_advance(br, entries); for (idx = 0; idx < entries; idx++) { - ret = test_one_nop(bgid, &ring); + memset(buffer, 1, sizeof(buffer)); + ret = test_one_read(read_fd, bgid, &ring); if (ret < 0) { fprintf(stderr, "bad run %d/%d = %d\n", loop, idx, ret); return ret; @@ -306,9 +309,19 @@ static int test_running(int bgid, int entries, int loops) fprintf(stderr, "reused buffer %d/%d = %d!\n", loop, idx, ret); return 1; } + if (buffer[0] != 0) { + fprintf(stderr, "unexpected read %d %d/%d = %d!\n", + (int)buffer[0], loop, idx, ret); + return 1; + } + if (buffer[1] != 1) { + fprintf(stderr, "unexpected spilled read %d %d/%d = %d!\n", + (int)buffer[1], loop, idx, ret); + return 1; + } buffers[ret] = true; } - ret = test_one_nop(bgid, &ring); + ret = test_one_read(read_fd, bgid, &ring); if (ret != -ENOBUFS) { fprintf(stderr, "expected enobufs run %d = %d\n", loop, ret); return 1; @@ -322,6 +335,7 @@ static int test_running(int bgid, int entries, int loops) return 1; } + close(read_fd); io_uring_queue_exit(&ring); free(buffers); return 0;