From patchwork Thu Jun 30 09:13:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12901473 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 48D7FC43334 for ; Thu, 30 Jun 2022 09:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234136AbiF3JRU (ORCPT ); Thu, 30 Jun 2022 05:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234070AbiF3JQy (ORCPT ); Thu, 30 Jun 2022 05:16:54 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8084242A34 for ; Thu, 30 Jun 2022 02:15:45 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id h23so37664081ejj.12 for ; Thu, 30 Jun 2022 02:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XxjPxsaxC4InhhQuR77UkgiYJHDnnofimUEVznPbP7s=; b=cE0U6q+DLO34bJNmaAKT/CGxJk89gONR7vHiSaS17D1nPmPgqbn5JxwjZ1LbBaNfpA OE85W5XI/0wfS9ETXKxpcU64reLBlKVGXQBEUkSDKIAsKrnLZybwr+NkV03EOM7VdrjE n5d69GitDamCqGLHn4EEIaWXl613jkOQz03QpOLzgZm8ND/Cqi3nm/rgIeERGHvkkevc dZTc83ntwq5Kk0F/qt7t/vjBvrCo08OTHPGN/pA2Q9JDiJnX7qk97MjRG1sXpqR9xcdn xAqBYj6yenr2FdF9ZBi/d3wgzNE6zOcSVmbNSKfS0exESDftmwpdEviy7N4VmAioexDk czwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XxjPxsaxC4InhhQuR77UkgiYJHDnnofimUEVznPbP7s=; b=yJS+mxoDo2vwCjwxdLH11sdJoLxfDX83RVB131ktw8ZonjTUidt6y0Yl9f4FgQG60I 7VuDLIlb8Jmiluwc/Udb1k6I/pU7bnCmEb8pmGdxTjjpoqBPADcXiyaxSfeQTrxeutYq vS4cP74gB7Q0eZYHmXlPB+zQc/JwuSZYlzBZu+PMMV8TbwQfb5d8Y8qrTi9JJgUaNOTY zlo+gnj8ObA37NIBWCj9UFss49C3ywXTX16pJf7UKEnQENtPubQ5/liAfHJJARMvOc5h oyhT6KL+3xyQqWS0c+3dyhNrE2t1nWKt2rYLl0LTC1R1RAr/lGKBNimcJr09UKG1NKDG xVTw== X-Gm-Message-State: AJIora/yuhXKko4nfpW03ScFh1qqDbeWXtkBCNbLqwRvexnXT+hWTfE9 CwKDcsArxjMAhj3nbYTKLYbPHy/SBt7ymg== X-Google-Smtp-Source: AGRyM1srdEEjoSm9BDQ/eR4Vr2DlDTACcDyiQSaZOOUZhzNPkTEXBPhnJDwL+88yNhNnvhawFSS8tg== X-Received: by 2002:a17:906:9754:b0:722:e5e6:1675 with SMTP id o20-20020a170906975400b00722e5e61675mr7715419ejy.102.1656580543647; Thu, 30 Jun 2022 02:15:43 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a3ae]) by smtp.gmail.com with ESMTPSA id s10-20020a1709060c0a00b0070beb9401d9sm8884925ejf.171.2022.06.30.02.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 02:15:43 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 1/3] update io_uring.h with file slot alloc ranges Date: Thu, 30 Jun 2022 10:13:37 +0100 Message-Id: <8f98bd6d014b9e8b1d86d04aa165b6d36cfb0ed5.1656580293.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Signed-off-by: Pavel Begunkov --- src/include/liburing/io_uring.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 0fd1f98..c01c5a3 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -414,6 +414,9 @@ enum { /* sync cancelation API */ IORING_REGISTER_SYNC_CANCEL = 24, + /* register a range of fixed file slots for automatic slot allocation */ + IORING_REGISTER_FILE_ALLOC_RANGE = 25, + /* this goes last */ IORING_REGISTER_LAST }; @@ -558,6 +561,13 @@ struct io_uring_getevents_arg { __u64 ts; }; +struct io_uring_file_index_range { + /* [off, off + len) */ + __u32 off; + __u32 len; + __u64 resv; +}; + /* * accept flags stored in sqe->ioprio */ From patchwork Thu Jun 30 09:13:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12901474 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 5B7F5CCA47B for ; Thu, 30 Jun 2022 09:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234283AbiF3JRV (ORCPT ); Thu, 30 Jun 2022 05:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234246AbiF3JQz (ORCPT ); Thu, 30 Jun 2022 05:16:55 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B124205DA for ; Thu, 30 Jun 2022 02:15:46 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id fi2so37687256ejb.9 for ; Thu, 30 Jun 2022 02:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QrDJbv7hodxTmOkHyYFWVJ4gHQ4HcCzGLPo//xF4i0I=; b=HWEaI/HGZOPZ3J1/ERd4jeXVU3l1DButGaxeCiP7RCpwXoHbRlKqhio/yp8XwrZ8Cr pRRueFjvosPJ9EPL4bhl7TwCOUq4QJkyjCtVZsv0Z+7EQZcJxyX4iwVEhX9TzxAAC5hB lcLU7BopUKDYcjyBCcYQKW/I9ns1/jJSvxtdfnzsS4PpxvxfJTmtBRWg9VSxYqayw8B0 O6Nj0wjh+ex5CQ/u/mXpBO6Zt3rfwjXjWRfiwtO5o+PlRt48HxedAZpHOMJ8PeqbYSxt kfQpWCAp4GtSHRGuhVXCTY+sCxbZ2iiKuYO7C7Orw/1A9J7H1vNJBOU4fEtvtAkg1AsT mULA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QrDJbv7hodxTmOkHyYFWVJ4gHQ4HcCzGLPo//xF4i0I=; b=k02m1Hx6KpXH4ZjXyZlqBCpuWINv4n/tLAdOVqiecQnfi1QI8vLYwbejL90wkZfHat zPAp8PQ+S4IKswBj+8RlCigIwM7pAa82LMI9GMOAG5OOBWPFqeqflwZsmXWQyYoF0vDu poFqdhe6hs+76IyguwjQthptvi5avXD8hpTu1aGJHpxk2hBbqjtF8J3653KQzUK62Ejo KqEXB3T/3J9cREFHJqDbpEvqYDkW5NVX5FXrBamd9+VWtL5/87rv5hKVSf7gJkEuXE3C rdldZ3xE7DW44HFT+jdkRzxER7PzwsOj8ziQhyrP/nlVCjQWugGim99XQq7ruVdvZAaV Fdww== X-Gm-Message-State: AJIora/fBlZwDtB0XnEC7F1PIg9wGwb55Z0hYKSrm2ozyEa5/G3z97WE VzcwzCBvBjqAviPiKbLkexxk+1ydLaSUyw== X-Google-Smtp-Source: AGRyM1vGVimGeoRHt6aY8qkrZs/FqNJ4l+8QN+Rmn0Y3YRwzh/CMwXC+fQ5MymVFUWFLgboSQ5Q+CA== X-Received: by 2002:a17:907:7f90:b0:726:e8ed:3c28 with SMTP id qk16-20020a1709077f9000b00726e8ed3c28mr7971031ejc.63.1656580544526; Thu, 30 Jun 2022 02:15:44 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a3ae]) by smtp.gmail.com with ESMTPSA id s10-20020a1709060c0a00b0070beb9401d9sm8884925ejf.171.2022.06.30.02.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 02:15:44 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 2/3] alloc range helpers Date: Thu, 30 Jun 2022 10:13:38 +0100 Message-Id: <218118e4343c04010e9142e14627a7f580f7bca5.1656580293.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Signed-off-by: Pavel Begunkov --- src/include/liburing.h | 3 +++ src/register.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/include/liburing.h b/src/include/liburing.h index bb2fb87..45b4da0 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -186,6 +186,9 @@ int io_uring_unregister_buf_ring(struct io_uring *ring, int bgid); int io_uring_register_sync_cancel(struct io_uring *ring, struct io_uring_sync_cancel_reg *reg); +int io_uring_register_file_alloc_range(struct io_uring *ring, + unsigned off, unsigned len); + /* * Helper for the peek/wait single cqe functions. Exported because of that, * but probably shouldn't be used directly in an application. diff --git a/src/register.c b/src/register.c index f2b1026..ee370d6 100644 --- a/src/register.c +++ b/src/register.c @@ -352,3 +352,17 @@ int io_uring_register_sync_cancel(struct io_uring *ring, return ____sys_io_uring_register(ring->ring_fd, IORING_REGISTER_SYNC_CANCEL, reg, 1); } + +int io_uring_register_file_alloc_range(struct io_uring *ring, + unsigned off, unsigned len) +{ + struct io_uring_file_index_range range; + + memset(&range, 0, sizeof(range)); + range.off = off; + range.len = len; + + return ____sys_io_uring_register(ring->ring_fd, + IORING_REGISTER_FILE_ALLOC_RANGE, + &range, 0); +} From patchwork Thu Jun 30 09:13:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12901475 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 1CF22C433EF for ; Thu, 30 Jun 2022 09:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234104AbiF3JRe (ORCPT ); Thu, 30 Jun 2022 05:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234230AbiF3JQ4 (ORCPT ); Thu, 30 Jun 2022 05:16:56 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EDF82317A for ; Thu, 30 Jun 2022 02:15:47 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id pk21so37787459ejb.2 for ; Thu, 30 Jun 2022 02:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dMzrJltt3Iz1UQO1HIChWcMGE5HPP4FS9fPwzQNrQwY=; b=SGAL+LN/L3JR8BXM7p3OAcInVNg4Qc1jCESDnbDFZ5CNRjvvl6rpNo7F9eTTIL1aMN Qpi0Fv1oMjIMKTaP+CDFp/cn0U2YeCB5BB0eap8Z55aH7UWq0swBHN0xwB7yPlcs7QYI nshwE+NlLHRyr05iXT/LaEmxcb2mQStbl25q5gAsnacb2Nsh3F3GlnNUK2i7+YtzJRwr h6l4jS9oQyDqifXHWW3CBc39S+7PW/BQyR6wQ+MTPu3r3OkiWly+ssLF79bj24LslWvm lMLT8K1kov18j9VD+8Rgp1exJ/yoE5kU/+/rACuxS3iI2WxwT3UFLOHU4s4X1oVJ3KvO p75A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dMzrJltt3Iz1UQO1HIChWcMGE5HPP4FS9fPwzQNrQwY=; b=WE5hcGaVvuzMYuyc6v/DTQTEfoAARuIzPd8913H2MsPZ/KkU0/CwOiF76mIXBpo44k c3JVLNU7wckU6k1tFhg76s/iLb6RvaehjpnpoeQAsJEzeZKNmwbzn1QSBwMrcny+KjjM 0gJVge1uyCFzxz0NKE4LMmk1j0c+gwByiVqJmIWLsm9xuzEvIrzU1oRvxLm07t3gye+N wr2Snnu+pOZFOMj6Pr1asAFzEGBIea/bkcIF0jXPQJUUPBQsZq1jnc+oVUDmGqgBiOeb +G4einj3R2OWuDbQC8RB8C0YWZQ1DyD4davEQsHdU7zkQcXet68nufrAOpmB9RMtZUJN M49w== X-Gm-Message-State: AJIora+bJXaRZO10xP9INfgHZokC74skwlikxfDftaowoi1FMneCWrlF CXnFkD3/vPQESl7q99QUYW9kIOHcrbmu1A== X-Google-Smtp-Source: AGRyM1v/x5wi6H1wjEEkbJmqa93I2UtLoIDvDNqBaJIPdJ32Nf/Dj7c5OL0RKYbUCDKTXSXD2BdxjA== X-Received: by 2002:a17:907:86a7:b0:726:317f:aee0 with SMTP id qa39-20020a17090786a700b00726317faee0mr7887996ejc.229.1656580545645; Thu, 30 Jun 2022 02:15:45 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a3ae]) by smtp.gmail.com with ESMTPSA id s10-20020a1709060c0a00b0070beb9401d9sm8884925ejf.171.2022.06.30.02.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 02:15:45 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 3/3] test range file alloc Date: Thu, 30 Jun 2022 10:13:39 +0100 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Signed-off-by: Pavel Begunkov --- test/file-register.c | 171 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/test/file-register.c b/test/file-register.c index cd00a90..dc4e685 100644 --- a/test/file-register.c +++ b/test/file-register.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "helpers.h" @@ -830,6 +831,170 @@ static int test_partial_register_fail(void) return 0; } +static int file_update_alloc(struct io_uring *ring, int *fd) +{ + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + int ret; + + sqe = io_uring_get_sqe(ring); + io_uring_prep_files_update(sqe, fd, 1, IORING_FILE_INDEX_ALLOC); + + ret = io_uring_submit(ring); + if (ret != 1) { + fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret); + return -1; + } + + ret = io_uring_wait_cqe(ring, &cqe); + if (ret < 0) { + fprintf(stderr, "%s: io_uring_wait_cqe=%d\n", __FUNCTION__, ret); + return -1; + } + ret = cqe->res; + io_uring_cqe_seen(ring, cqe); + return ret; +} + +static int test_out_of_range_file_ranges(struct io_uring *ring) +{ + int ret; + + ret = io_uring_register_file_alloc_range(ring, 8, 3); + if (ret != -EINVAL) { + fprintf(stderr, "overlapping range %i\n", ret); + return 1; + } + + ret = io_uring_register_file_alloc_range(ring, 10, 1); + if (ret != -EINVAL) { + fprintf(stderr, "out of range index %i\n", ret); + return 1; + } + + ret = io_uring_register_file_alloc_range(ring, 7, ~1U); + if (ret != -EOVERFLOW) { + fprintf(stderr, "overflow %i\n", ret); + return 1; + } + + return 0; +} + +static int test_overallocating_file_range(struct io_uring *ring, int fds[2]) +{ + int roff = 7, rlen = 2; + int ret, i, fd; + + ret = io_uring_register_file_alloc_range(ring, roff, rlen); + if (ret) { + fprintf(stderr, "io_uring_register_file_alloc_range %i\n", ret); + return 1; + } + + for (i = 0; i < rlen; i++) { + fd = fds[0]; + ret = file_update_alloc(ring, &fd); + if (ret != 1) { + fprintf(stderr, "file_update_alloc\n"); + return 1; + } + + if (fd < roff || fd >= roff + rlen) { + fprintf(stderr, "invalid off result %i\n", fd); + return 1; + } + } + + fd = fds[0]; + ret = file_update_alloc(ring, &fd); + if (ret != -ENFILE) { + fprintf(stderr, "overallocated %i, off %i\n", ret, fd); + return 1; + } + + return 0; +} + +static int test_zero_range_alloc(struct io_uring *ring, int fds[2]) +{ + int ret, fd; + + ret = io_uring_register_file_alloc_range(ring, 7, 0); + if (ret) { + fprintf(stderr, "io_uring_register_file_alloc_range failed %i\n", ret); + return 1; + } + + fd = fds[0]; + ret = file_update_alloc(ring, &fd); + if (ret != -ENFILE) { + fprintf(stderr, "zero alloc %i\n", ret); + return 1; + } + return 0; +} + +static int test_file_alloc_ranges(void) +{ + struct io_uring ring; + int ret, pipe_fds[2]; + + if (pipe(pipe_fds)) { + fprintf(stderr, "pipes\n"); + return 1; + } + ret = io_uring_queue_init(8, &ring, 0); + if (ret) { + fprintf(stderr, "queue_init: %d\n", ret); + return 1; + } + + ret = io_uring_register_files_sparse(&ring, 10); + if (ret == -EINVAL) { +not_supported: + close(pipe_fds[0]); + close(pipe_fds[1]); + io_uring_queue_exit(&ring); + printf("file alloc ranges are not supported, skip\n"); + return 0; + } else if (ret) { + fprintf(stderr, "io_uring_register_files_sparse %i\n", ret); + return ret; + } + + ret = io_uring_register_file_alloc_range(&ring, 0, 1); + if (ret) { + if (ret == -EINVAL) + goto not_supported; + fprintf(stderr, "io_uring_register_file_alloc_range %i\n", ret); + return 1; + } + + ret = test_overallocating_file_range(&ring, pipe_fds); + if (ret) { + fprintf(stderr, "test_overallocating_file_range() failed\n"); + return 1; + } + + ret = test_out_of_range_file_ranges(&ring); + if (ret) { + fprintf(stderr, "test_out_of_range_file_ranges() failed\n"); + return 1; + } + + ret = test_zero_range_alloc(&ring, pipe_fds); + if (ret) { + fprintf(stderr, "test_zero_range_alloc() failed\n"); + return 1; + } + + close(pipe_fds[0]); + close(pipe_fds[1]); + io_uring_queue_exit(&ring); + return 0; +} + int main(int argc, char *argv[]) { struct io_uring ring; @@ -949,5 +1114,11 @@ int main(int argc, char *argv[]) return ret; } + ret = test_file_alloc_ranges(); + if (ret) { + printf("test_partial_register_fail failed\n"); + return ret; + } + return T_EXIT_PASS; }