From patchwork Thu Mar 21 14:44:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13598854 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 887D184A51 for ; Thu, 21 Mar 2024 14:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032521; cv=none; b=MQ1M/kY7MZP6ZcnMGmC4LRj/N6hfqE9xghb58yj9HXdVskDSEuWuGNDFXOvZpRFZoy5KwmIgsLfcvZVhb4FGQcd3h20WqveTTQw1jBfiXi8kx/sSmPi3HEUTY/19RsgnpPs2ZYMqWpmguov17WEBEVojtFfDynLhb/X+cjDGgxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032521; c=relaxed/simple; bh=tsk/vGy57WWlSJnklOHHVGV/6Lw/R39zrN40hMWm/cc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B4KY2wocdfWIWukjRVl+FIHg+xHCCS/oE91gw2N14gj2YRujBVzUur9Vxsei5pijpGPgwq4UN8QDoX6jYRr8/sZ965yIwdZ7N5cSfHifMXTyOf7INOrahEY3TxbvSvt++bAwmuKpr3tkRXK9bruwcP+z711auSbTdvJ2RPosjMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=CWa2g8g3; arc=none smtp.client-ip=209.85.166.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="CWa2g8g3" Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-7cc5e664d52so19312839f.0 for ; Thu, 21 Mar 2024 07:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711032516; x=1711637316; 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=k+0GTkS88F/9JgiF0E6fTaZaUJu28N1lKoEtmdHQlyU=; b=CWa2g8g3pIfIwOxzyPYKt0aowc+l5OnXqXo9ntEq+FsEnLz40xTt+tLIKbCeCLtuLq bLNcymaA/ibuDuf/zOGpZjzJL2BguYo3iLaedgEw+KQoPttw0FZBrvxkXqQodExNOyxZ pIrUd9qAp0IHQTJp7HE+uGCKJ5WuuEsYb6H5tOYTl4cmfFtp1WOpEm2z5cZS52JBaPcT URZ2giOG7r1j6xzkwaJRpvwkxl1gDTLa8pBnkKyLlV155mPk+3MpqqMZmLt9PzfpbHAb vwmclqLg5aSNQuUJUL9w9YWpzaId+Zfqs+QFzyz5ZQN+3NvgXLuxlVxnNWZ1KS6XhYVO SxOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032516; x=1711637316; 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=k+0GTkS88F/9JgiF0E6fTaZaUJu28N1lKoEtmdHQlyU=; b=Zo2hgbV2KKHdyutth/zrdSGwkTFfWlLtJpOqPMEqpeVn00AZU6jiAcWKfCKrANARl1 LcHe+3ibWUNomm0KsF+7n5ink7QPu68khMabAdIr0S95SejepI6KAqa9o/3g5O73beYh ib4DGwVvElKU+pSQ748M/9SwAtxTpb+7mjHpGOde5oyEyJJzMpbPT5eYZAo5eunDrlpx To+EJBrMsQi44hoUwzSjsLwc74hYo/Ais4qL3pem5Fyy1FHaqtnlt1xQtXsDPXcHhtVX eo0TKRxcE4LV3Ia8ASzJTXBetvBYKrNEg3WqmRTeOmYjRAkiISm+XtO8p3zrNWgtDuco g80g== X-Gm-Message-State: AOJu0YwjsSns6xTv4hKRei7mlt4aQnkyb8xcK0pnt8ewf+0mXOcN9oxu UcUWwU1OqKivXxUUbpqWY/Q/MR1yR5MTY07PDrjNj9WeEGXo9TVi/P311AFJG4i4GU2j1vsgUJA Q X-Google-Smtp-Source: AGHT+IHefxedIowEfxWxxi2/Wf6L9pf+zutV30Qwve5wyDE4itn3vmkYZ9OrHl+0vhwN2ApmzBRGCQ== X-Received: by 2002:a6b:5108:0:b0:7ce:f407:1edf with SMTP id f8-20020a6b5108000000b007cef4071edfmr8860480iob.0.1711032516263; Thu, 21 Mar 2024 07:48:36 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id q20-20020a02c8d4000000b0047bed9ff286sm250835jao.31.2024.03.21.07.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:48:34 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/6] io_uring/kbuf: get rid of lower BGID lists Date: Thu, 21 Mar 2024 08:44:56 -0600 Message-ID: <20240321144831.58602-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321144831.58602-1-axboe@kernel.dk> References: <20240321144831.58602-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Just rely on the xarray for any kind of bgid. This simplifies things, and it really doesn't bring us much, if anything. Signed-off-by: Jens Axboe --- include/linux/io_uring_types.h | 1 - io_uring/io_uring.c | 2 - io_uring/kbuf.c | 70 ++++------------------------------ 3 files changed, 8 insertions(+), 65 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index ea7e5488b3be..c9a1952a383a 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -295,7 +295,6 @@ struct io_ring_ctx { struct io_submit_state submit_state; - struct io_buffer_list *io_bl; struct xarray io_bl_xa; struct io_hash_table cancel_table_locked; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index de7f88df939c..5b80849fbb85 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -342,7 +342,6 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p) err: kfree(ctx->cancel_table.hbs); kfree(ctx->cancel_table_locked.hbs); - kfree(ctx->io_bl); xa_destroy(&ctx->io_bl_xa); kfree(ctx); return NULL; @@ -2849,7 +2848,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx) io_napi_free(ctx); kfree(ctx->cancel_table.hbs); kfree(ctx->cancel_table_locked.hbs); - kfree(ctx->io_bl); xa_destroy(&ctx->io_bl_xa); kfree(ctx); } diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 693c26da4ee1..8bf0121f00af 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -17,8 +17,6 @@ #define IO_BUFFER_LIST_BUF_PER_PAGE (PAGE_SIZE / sizeof(struct io_uring_buf)) -#define BGID_ARRAY 64 - /* BIDs are addressed by a 16-bit field in a CQE */ #define MAX_BIDS_PER_BGID (1 << 16) @@ -40,13 +38,9 @@ struct io_buf_free { int inuse; }; -static struct io_buffer_list *__io_buffer_get_list(struct io_ring_ctx *ctx, - struct io_buffer_list *bl, - unsigned int bgid) +static inline struct io_buffer_list *__io_buffer_get_list(struct io_ring_ctx *ctx, + unsigned int bgid) { - if (bl && bgid < BGID_ARRAY) - return &bl[bgid]; - return xa_load(&ctx->io_bl_xa, bgid); } @@ -55,7 +49,7 @@ static inline struct io_buffer_list *io_buffer_get_list(struct io_ring_ctx *ctx, { lockdep_assert_held(&ctx->uring_lock); - return __io_buffer_get_list(ctx, ctx->io_bl, bgid); + return __io_buffer_get_list(ctx, bgid); } static int io_buffer_add_list(struct io_ring_ctx *ctx, @@ -68,10 +62,6 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx, */ bl->bgid = bgid; smp_store_release(&bl->is_ready, 1); - - if (bgid < BGID_ARRAY) - return 0; - return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL)); } @@ -208,24 +198,6 @@ void __user *io_buffer_select(struct io_kiocb *req, size_t *len, return ret; } -static __cold int io_init_bl_list(struct io_ring_ctx *ctx) -{ - struct io_buffer_list *bl; - int i; - - bl = kcalloc(BGID_ARRAY, sizeof(struct io_buffer_list), GFP_KERNEL); - if (!bl) - return -ENOMEM; - - for (i = 0; i < BGID_ARRAY; i++) { - INIT_LIST_HEAD(&bl[i].buf_list); - bl[i].bgid = i; - } - - smp_store_release(&ctx->io_bl, bl); - return 0; -} - /* * Mark the given mapped range as free for reuse */ @@ -300,13 +272,6 @@ void io_destroy_buffers(struct io_ring_ctx *ctx) struct list_head *item, *tmp; struct io_buffer *buf; unsigned long index; - int i; - - for (i = 0; i < BGID_ARRAY; i++) { - if (!ctx->io_bl) - break; - __io_remove_buffers(ctx, &ctx->io_bl[i], -1U); - } xa_for_each(&ctx->io_bl_xa, index, bl) { xa_erase(&ctx->io_bl_xa, bl->bgid); @@ -489,12 +454,6 @@ int io_provide_buffers(struct io_kiocb *req, unsigned int issue_flags) io_ring_submit_lock(ctx, issue_flags); - if (unlikely(p->bgid < BGID_ARRAY && !ctx->io_bl)) { - ret = io_init_bl_list(ctx); - if (ret) - goto err; - } - bl = io_buffer_get_list(ctx, p->bgid); if (unlikely(!bl)) { bl = kzalloc(sizeof(*bl), GFP_KERNEL_ACCOUNT); @@ -507,14 +466,9 @@ int io_provide_buffers(struct io_kiocb *req, unsigned int issue_flags) if (ret) { /* * Doesn't need rcu free as it was never visible, but - * let's keep it consistent throughout. Also can't - * be a lower indexed array group, as adding one - * where lookup failed cannot happen. + * let's keep it consistent throughout. */ - if (p->bgid >= BGID_ARRAY) - kfree_rcu(bl, rcu); - else - WARN_ON_ONCE(1); + kfree_rcu(bl, rcu); goto err; } } @@ -679,12 +633,6 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg) if (reg.ring_entries >= 65536) return -EINVAL; - if (unlikely(reg.bgid < BGID_ARRAY && !ctx->io_bl)) { - int ret = io_init_bl_list(ctx); - if (ret) - return ret; - } - bl = io_buffer_get_list(ctx, reg.bgid); if (bl) { /* if mapped buffer ring OR classic exists, don't allow */ @@ -734,10 +682,8 @@ int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg) return -EINVAL; __io_remove_buffers(ctx, bl, -1U); - if (bl->bgid >= BGID_ARRAY) { - xa_erase(&ctx->io_bl_xa, bl->bgid); - kfree_rcu(bl, rcu); - } + xa_erase(&ctx->io_bl_xa, bl->bgid); + kfree_rcu(bl, rcu); return 0; } @@ -771,7 +717,7 @@ void *io_pbuf_get_address(struct io_ring_ctx *ctx, unsigned long bgid) { struct io_buffer_list *bl; - bl = __io_buffer_get_list(ctx, smp_load_acquire(&ctx->io_bl), bgid); + bl = __io_buffer_get_list(ctx, bgid); if (!bl || !bl->is_mmap) return NULL; From patchwork Thu Mar 21 14:44:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13598855 Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 7DFA584FC5 for ; Thu, 21 Mar 2024 14:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032522; cv=none; b=EAjdERRPZax+LoKaZsNXvMxe2tvlxXzCJk2XF27SZGojsoAE82/J4KjsFh5eVuaSqjSh5d4y0PMWdeLDEArMgKXVwF3SvCq8GYg3DOU65lB96Vxp0afNABUvDlWU8rXGpZhPyKJ9SC8sZCvK+VM568dVWtOXOPGG0St/XuJHuqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032522; c=relaxed/simple; bh=8G3QN6wuHYeuEtMo+UdWrxs8c//P5kJMH+4+MKrhbiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ixnm/JuPPZUjVCyGl/wXLSoGOJcwXC/bDGX8Lg4YYLcjKRoAPhePTeT5PFJqQO7cVCuFa9TxFKMi2Obl0rKEEA3pkLgtvh5hnWzHMhKPyTbpjoEH/vWc++Uie2AAwFhhZLbaqdmTZl/e1nVTLlW2sulkdjIRhLfOmh4eYTZDjPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=qN5uL6cq; arc=none smtp.client-ip=209.85.166.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="qN5uL6cq" Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-7cc0e831e11so13371439f.1 for ; Thu, 21 Mar 2024 07:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711032518; x=1711637318; 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=QtvzBKul3lnX4UwRp+DUDb1X15hTCGMb7+BkwEEbcgU=; b=qN5uL6cqpPCygyBrdkrd0q6bSxYhOOglaYFax5gxsKPNivjpmGZnuEwOYnepWsaL8y CZJ5roXhbvwCK73fdwkYHzjW5HHIy+vYIsrZQmfwIOo9H53wtq3a8FYRhVLvxUtmsX3w nllvq7KDZd48llscMqOe4904BJ0rwj1xQHLLmZ3NVRNKBNHILD/8mCoxoclWxD+SpFyC v6vZWExTokh6qFXSbjKY2r27WfULqHRXqtNj0pSfo5gy/m01Tkz88apcmCsNq/2QBsqL n3kFSlxXKlnExJk6vLl851VXvf/K+td/CyYNv8JNLX91S7KZxAWdYgmEZf2EkEkYa7Ka iIIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032518; x=1711637318; 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=QtvzBKul3lnX4UwRp+DUDb1X15hTCGMb7+BkwEEbcgU=; b=VJA0uU86Kp9dmKYgMtaxm1NhcBAqFnH13F+YgSUeaCPGXXMk2Oqjp6y/cT8qIs3n2+ ddXO1cm0CtoHpnN1+onz1CWceDUuXQHtTxGzXcuNqCezLvCKVSPa2HXgGEQr3Gy5BhXO DAM7TX8/HrIJQ3PWE2RGlbG6g27XixIZNhDiKTDB9kXYMqoZWh1aXdRPX48OnjQ5zLE1 cg+d+nMvbp1ARhlq4UI/crQWJrg1Fn277cN4TbYk8bmVF83DMAQ3xqep2021KR0QObkd gL5TYxHBt/JWyi93AhqZ9gneQfN0KsSzXt394BZHL49YAyCvy65pvrebhoVU+bJlDr9R TFhA== X-Gm-Message-State: AOJu0YypOh8Np0hecEDNTfd9Rr8+UY5jxt5iSwxEIWys8nXIodswTuHX hyURt/WKw1wMb4s4uiohu24LYAIPDuCTG1HIX72nPMWhsZMcnMOeNtnVbVueallolFNBrj8Kyun z X-Google-Smtp-Source: AGHT+IHS4aXAc4FzRfTRMxRpDOOku9f6Q0tfupcvPbyj5lHg/eCzBdEbVNE1o3Y5Qp0F5l84+dx9XA== X-Received: by 2002:a5d:9b87:0:b0:7cf:272f:a3af with SMTP id r7-20020a5d9b87000000b007cf272fa3afmr3125763iom.2.1711032518046; Thu, 21 Mar 2024 07:48:38 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id q20-20020a02c8d4000000b0047bed9ff286sm250835jao.31.2024.03.21.07.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:48:36 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/6] io_uring/kbuf: get rid of bl->is_ready Date: Thu, 21 Mar 2024 08:44:57 -0600 Message-ID: <20240321144831.58602-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321144831.58602-1-axboe@kernel.dk> References: <20240321144831.58602-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that xarray is being exclusively used for the buffer_list lookup, this check is no longer needed. Get rid of it and the is_ready member. Signed-off-by: Jens Axboe --- io_uring/kbuf.c | 8 -------- io_uring/kbuf.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 8bf0121f00af..011280d873e7 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -61,7 +61,6 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx, * always under the ->uring_lock, but the RCU lookup from mmap does. */ bl->bgid = bgid; - smp_store_release(&bl->is_ready, 1); return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL)); } @@ -721,13 +720,6 @@ void *io_pbuf_get_address(struct io_ring_ctx *ctx, unsigned long bgid) if (!bl || !bl->is_mmap) return NULL; - /* - * Ensure the list is fully setup. Only strictly needed for RCU lookup - * via mmap, and in that case only for the array indexed groups. For - * the xarray lookups, it's either visible and ready, or not at all. - */ - if (!smp_load_acquire(&bl->is_ready)) - return NULL; return bl->buf_ring; } diff --git a/io_uring/kbuf.h b/io_uring/kbuf.h index 1c7b654ee726..fdbb10449513 100644 --- a/io_uring/kbuf.h +++ b/io_uring/kbuf.h @@ -29,8 +29,6 @@ struct io_buffer_list { __u8 is_buf_ring; /* ring mapped provided buffers, but mmap'ed by application */ __u8 is_mmap; - /* bl is visible from an RCU point of view for lookup */ - __u8 is_ready; }; struct io_buffer { From patchwork Thu Mar 21 14:44:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13598856 Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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 587E51E534 for ; Thu, 21 Mar 2024 14:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032522; cv=none; b=MRbGxt9LF7m0ec9rCtg2ebBAUYQDWWsDFqJVCIrD4eLeLUGYvnxHU6WqLT3GKp51wkLprxn8stWidJY8PHfsAUjyuOkapGyy7haDmD6oj6b5ITyLyP215Erab4d20xCG1FTv0nb+Z5AEy38eDPP66V5/X+UozWBHzpiPvQMQhdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032522; c=relaxed/simple; bh=0W2obeekuSQdzZWXiQybp+acO7ke81Dc2YvaIvoTuQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f60vROyzG/GNPQPusgTaVBkuvp27nFv5MTc8zM20Ie5uTCR1W6fW0Ema1bMAWeU2XG6Tbry+99H9TVbXm566NOBum+Dq/mVGVg8QNInSqVyTSJxmPVNHnaowlAN1X0xyK0lmA31CHAFtXGHZ15ktF+UECyWxcbc04EJ8UzIkLMw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=iT4nHDET; arc=none smtp.client-ip=209.85.166.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="iT4nHDET" Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-7cc0e831e11so13372239f.1 for ; Thu, 21 Mar 2024 07:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711032519; x=1711637319; 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=IrcjwXvOlSphD9f4BvWGSMDrK92UD29qUBOBEFOPsVY=; b=iT4nHDETzfU9kFp8i+ayB9L08fvSkx1p7J1xPcMi5prXRrqwN7PP12Rr5aOJAX/74I AFWEK3oOd2PhqjXI/QUGDDcQkUBOoYkHaxsz0EI3pliRxEm7rzgon21TJFXmIG12kukz O1V4zqGR+KOgVVOqubsSqonh27io8wqordJXCkmc03djB/Tw/meM2mc/gS6CwND1dJ6d bUyf9p6jBvlADKPSx+QojFmgyMq6hx+dJEMEmfb/wg5lAe+ngcVxbfHD8YsAOCqh436l BdHouxeN6mfQutunRViM9ZqnYEfiWcmnp/1xrfZDBxViQjEsbSezAtOvR4E3aAn8pWjE YCog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032519; x=1711637319; 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=IrcjwXvOlSphD9f4BvWGSMDrK92UD29qUBOBEFOPsVY=; b=oIAFyVjQinJ3mokz/bRTvJb6hVc3htI7ngvaoeNINddhZ/Ud9w2eA6dmSzKbkYNprU yFe1YoY+/MNs8TA2U1RR30UzZvFNO7/kYTLyOiQaQ0kGA1JRdfdV6KemQnj24mghZFbs X/4CZcr/DJK0wX84um+z/PzaAbLqQ1UNBuCYxhITSJ9Nbjditf3xBQrov8mkTHJT5OM7 XOai7a5Av4qKo7T86/0xC4fVDlNIWjgeSZjYXJu2V9pNLvWIjqtr0JW2xpKw7yjZZD3Q a2iW7hFj7rPlVB/kYOwWdWt4uYJOVrOC5of/RqjNu2ggk3QGz3A1NxSxvJliijQendfC sSQQ== X-Gm-Message-State: AOJu0YxRiNpy8bknkh55Z4ITrA5kX1ljKaMq+JwC1Deg45HcsNkPP13T Nq8v82PXb4TgzBkPQ39w7DUM4/rMEKotk48weZx8dBWdN0pzuXcNmVbY33d+cfJoEVDuyEPK1fP 5 X-Google-Smtp-Source: AGHT+IEQdz+v6hyYI3bYsEYR/c3QIUBRO3AtGDfLjAiy3nRCKL0BKcQkP2MfmR5OUkZY16fSyaUsgQ== X-Received: by 2002:a5e:c10d:0:b0:7cf:28df:79e2 with SMTP id v13-20020a5ec10d000000b007cf28df79e2mr2731967iol.1.1711032519186; Thu, 21 Mar 2024 07:48:39 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id q20-20020a02c8d4000000b0047bed9ff286sm250835jao.31.2024.03.21.07.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:48:38 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/6] io_uring/kbuf: vmap pinned buffer ring Date: Thu, 21 Mar 2024 08:44:58 -0600 Message-ID: <20240321144831.58602-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321144831.58602-1-axboe@kernel.dk> References: <20240321144831.58602-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This avoids needing to care about HIGHMEM, and it makes the buffer indexing easier as both ring provided buffer methods are now virtually mapped in a contigious fashion. Signed-off-by: Jens Axboe --- io_uring/kbuf.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 011280d873e7..72c15dde34d3 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -145,15 +146,7 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len, req->flags |= REQ_F_BL_EMPTY; head &= bl->mask; - /* mmaped buffers are always contig */ - if (bl->is_mmap || head < IO_BUFFER_LIST_BUF_PER_PAGE) { - buf = &br->bufs[head]; - } else { - int off = head & (IO_BUFFER_LIST_BUF_PER_PAGE - 1); - int index = head / IO_BUFFER_LIST_BUF_PER_PAGE; - buf = page_address(bl->buf_pages[index]); - buf += off; - } + buf = &br->bufs[head]; if (*len == 0 || *len > buf->len) *len = buf->len; req->flags |= REQ_F_BUFFER_RING; @@ -240,6 +233,7 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx, for (j = 0; j < bl->buf_nr_pages; j++) unpin_user_page(bl->buf_pages[j]); kvfree(bl->buf_pages); + vunmap(bl->buf_ring); bl->buf_pages = NULL; bl->buf_nr_pages = 0; } @@ -490,9 +484,9 @@ int io_provide_buffers(struct io_kiocb *req, unsigned int issue_flags) static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg, struct io_buffer_list *bl) { - struct io_uring_buf_ring *br; + struct io_uring_buf_ring *br = NULL; + int nr_pages, ret, i; struct page **pages; - int i, nr_pages; pages = io_pin_pages(reg->ring_addr, flex_array_size(br, bufs, reg->ring_entries), @@ -500,18 +494,12 @@ static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg, if (IS_ERR(pages)) return PTR_ERR(pages); - /* - * Apparently some 32-bit boxes (ARM) will return highmem pages, - * which then need to be mapped. We could support that, but it'd - * complicate the code and slowdown the common cases quite a bit. - * So just error out, returning -EINVAL just like we did on kernels - * that didn't support mapped buffer rings. - */ - for (i = 0; i < nr_pages; i++) - if (PageHighMem(pages[i])) - goto error_unpin; + br = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL); + if (!br) { + ret = -ENOMEM; + goto error_unpin; + } - br = page_address(pages[0]); #ifdef SHM_COLOUR /* * On platforms that have specific aliasing requirements, SHM_COLOUR @@ -522,8 +510,10 @@ static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg, * should use IOU_PBUF_RING_MMAP instead, and liburing will handle * this transparently. */ - if ((reg->ring_addr | (unsigned long) br) & (SHM_COLOUR - 1)) + if ((reg->ring_addr | (unsigned long) br) & (SHM_COLOUR - 1)) { + ret = -EINVAL; goto error_unpin; + } #endif bl->buf_pages = pages; bl->buf_nr_pages = nr_pages; @@ -535,7 +525,8 @@ static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg, for (i = 0; i < nr_pages; i++) unpin_user_page(pages[i]); kvfree(pages); - return -EINVAL; + vunmap(br); + return ret; } /* From patchwork Thu Mar 21 14:44:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13598857 Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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 3E9E884A51 for ; Thu, 21 Mar 2024 14:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032524; cv=none; b=qtCfJTgeUNUI/Uqbd4WXWDWlmszbJ8bjIyKSNm2A+sLoKtaa0HE6oYUoU500Ao5qUnhmDoe+x6ZyYRTMksfUoPmQ1kIhUMo4ZG9I6Mu00boEXpBwDgYxED2Y8Om5FLs6KEBkpF6bvJQyal42szo9ALeWDUNg/wkAE4es18gEBvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032524; c=relaxed/simple; bh=5YqocHr5mxuGOr5Z0D+Jj5Z+RZ0wDYj67RIhWvHLoys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OBTJ/Mo/I/4LnHzRv9r3NFX/zpEJt+0olxVydN/dO915gi2NC5JkPlDf7S8hgh5wI+mvxzUL/PI5phdYIPrb5nwpHXNoadteJ3uWI1m5R+6HC6OZzHZEW6yepEm4M8BOl3rWQqeApFNraWai5HXemc92nuZp6nF9rNOw7flmOpE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=Noey6o7q; arc=none smtp.client-ip=209.85.166.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="Noey6o7q" Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-7cbf1751c8fso4618739f.0 for ; Thu, 21 Mar 2024 07:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711032521; x=1711637321; 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=dRbXBnmBssLCefthvGjqIke1i8J8DEDsrgn5OvhdPnw=; b=Noey6o7qlnScjTreK13c3Ghf4/1J12c4dDhWf0NHizfSc5Y9QpO1GbCycpkK1hOfEA OT+c12DoKqmD4D7aOTgf2eRq8I4kGko9GeP8CqK6JCDvkCJGgq4SFs1SrNne2OvvqVy2 qEM0nL3A2bTwUo03lGuZgm1ZGLxPDNATu7J4diHl9D6czHEvCL2vD/fLJyiApWXF/LAi Ioeznh6HttjMj56H6uuvsMgOIlfa3S4TZ+DP5EHk/+Durm5tMHJqVVMyt05+AQT0Oumq hDBr1Q/z+HpEmdzZTgV38z6paFvQ0LGtOUUczlXF02ac6txg/Y+wjYF8+D+wzpY3C665 wCBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032521; x=1711637321; 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=dRbXBnmBssLCefthvGjqIke1i8J8DEDsrgn5OvhdPnw=; b=gBFjM8mbM03cWahSOThoN8Slkm64hHzO+1Y3V7L1qIwt78Scmp72fipl4A0Wptisr7 oCwGwuUL2e6dtsLQ1hrySBAnLBe+OldmNM61aogk6esVbuwx1suiy747/SUF5qwPv182 LYIR75/qDcyMKAcAMSqX5kKe7BbpQ4YMmeEcfNkeBry0bnvPOZGBT6kcrNZqELJXxJCO pHhYfwRVFKIR2V2QfjqTUlCSlt3/EN60olOqCZP5RVH1ukbrwARzxSTXRHHFrY3715nM oAI2J5lW8wxUynL6yqsVBaDk+D5RWJa0PlopNKDbv+Z1TE0MQ5WczpeNlE9wFUbVUA5S VAtQ== X-Gm-Message-State: AOJu0YzPgCqDT+No8UX0n2vvM8yyirjgL2O4pM2lXdw6JaMtPCCfa3m7 1jk8wfN4oYHcO9omaPNnTsRZBj42NIYPlCs8+xwZU5MB1kREfl+UkgFMf4RLKxcKLqHFS4bgwuV t X-Google-Smtp-Source: AGHT+IGLr9ZRVq0bYPMZavk/itpNjmFngKhn1FK3E0kH3rTwb1+1/ZdzN3m7BdEOvV+YO0lzI5eXyw== X-Received: by 2002:a05:6602:5c2:b0:7ce:f921:6a42 with SMTP id w2-20020a05660205c200b007cef9216a42mr8072439iox.0.1711032521000; Thu, 21 Mar 2024 07:48:41 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id q20-20020a02c8d4000000b0047bed9ff286sm250835jao.31.2024.03.21.07.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:48:39 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/6] io_uring/kbuf: protect io_buffer_list teardown with a reference Date: Thu, 21 Mar 2024 08:44:59 -0600 Message-ID: <20240321144831.58602-5-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321144831.58602-1-axboe@kernel.dk> References: <20240321144831.58602-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 No functional changes in this patch, just in preparation for being able to keep the buffer list alive outside of the ctx->uring_lock. Signed-off-by: Jens Axboe --- io_uring/kbuf.c | 15 +++++++++++---- io_uring/kbuf.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 72c15dde34d3..206f4d352e15 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -62,6 +62,7 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx, * always under the ->uring_lock, but the RCU lookup from mmap does. */ bl->bgid = bgid; + atomic_set(&bl->refs, 1); return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL)); } @@ -259,6 +260,14 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx, return i; } +static void io_put_bl(struct io_ring_ctx *ctx, struct io_buffer_list *bl) +{ + if (atomic_dec_and_test(&bl->refs)) { + __io_remove_buffers(ctx, bl, -1U); + kfree_rcu(bl, rcu); + } +} + void io_destroy_buffers(struct io_ring_ctx *ctx) { struct io_buffer_list *bl; @@ -268,8 +277,7 @@ void io_destroy_buffers(struct io_ring_ctx *ctx) xa_for_each(&ctx->io_bl_xa, index, bl) { xa_erase(&ctx->io_bl_xa, bl->bgid); - __io_remove_buffers(ctx, bl, -1U); - kfree_rcu(bl, rcu); + io_put_bl(ctx, bl); } /* @@ -671,9 +679,8 @@ int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg) if (!bl->is_buf_ring) return -EINVAL; - __io_remove_buffers(ctx, bl, -1U); xa_erase(&ctx->io_bl_xa, bl->bgid); - kfree_rcu(bl, rcu); + io_put_bl(ctx, bl); return 0; } diff --git a/io_uring/kbuf.h b/io_uring/kbuf.h index fdbb10449513..8b868a1744e2 100644 --- a/io_uring/kbuf.h +++ b/io_uring/kbuf.h @@ -25,6 +25,8 @@ struct io_buffer_list { __u16 head; __u16 mask; + atomic_t refs; + /* ring mapped provided buffers */ __u8 is_buf_ring; /* ring mapped provided buffers, but mmap'ed by application */ From patchwork Thu Mar 21 14:45:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13598858 Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.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 395DE85624 for ; Thu, 21 Mar 2024 14:48:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032526; cv=none; b=cciR+2Bf1vpSd5Ai8Omq00rn7DKm7vfkuoy2ep0xFDVBT11GEsy/SjWoqzn2r/aExAn65cJvdpyZ4XfY1dDn+609fxi52XEy4kt+9AkYmDWqTva0JVI2pl2sx60kcCf6K9CEUSh8UZ1axCqTmAvUxKy7JyxhiQl8oWxbDSL7X5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032526; c=relaxed/simple; bh=IA363V3fu31t0PPCUsgoiiOfsNv8iW0Wnt/MjZXXrdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d+QX49AjPe0s3CUGGV4HjPvcueAwYkVhHDD6yDi+e2ndFPjDZO1qivNi6PAUcyeteNdO5jRRboRT1YEzPEvUzfnNkktZG/Gq2Ji/WvZ2U5o1yqH2J0MV7BdFdL4vy1oUKybbdTWSECNajFCxrt8TomBOkNgM6UkmMUJ2TRFkaLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=uRkJguXW; arc=none smtp.client-ip=209.85.166.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="uRkJguXW" Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7cb9dd46babso2710139f.1 for ; Thu, 21 Mar 2024 07:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711032523; x=1711637323; 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=wQ3pMD8RptEK8J/o1yry4PoQVSvIoeVGC8WVz8qkQnE=; b=uRkJguXWjVPerk0gkbML3C4GFLGiDu+dR1UL0axozbof4oi11TgZMXJZYfnU1msniK sGbf93kcB9jd0D9FXGTRF7jVIq8UYMajJ4l2432Bn3Gbr4HcakbUZ3ZYs/zHCREF/L+F iF73UP5epG/8Z3WRv5HE3CtoB/7NLCwn6X/xccgKRUPqKqPW72rimnU7BF1kqBfmHxzZ 3Qq3N1g1vX1360mDTTZar/v6oPQfSk2IXGzbjT0ttfeqKn86nt9rI2y4cokEOq2iGKO8 dHzdL1Ar2o/IsjLUWHxww9JGHktmpk3n68i6D44i1C46WOjC8k02f5jHzP5S2BtfgrSg Sp6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032523; x=1711637323; 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=wQ3pMD8RptEK8J/o1yry4PoQVSvIoeVGC8WVz8qkQnE=; b=KkBDNbClYJ6L/wjU1L9gLTrOgOnBUSLVYhl/O6l+YhSP6GXK/gaGUMW0JYspVv1RF5 NsIsXwXpxb5zCZvqOvvuyPgrTwVrRQ7cm09lfpqD5Pfn71CNRKYWK3VOIRlRojohdXtQ s/bLsCCnv+NhhgrDCKsPW8R+oZ/UPZyfvU1aVH23tzYrvc9Z4VsQhF98tNeMx1o/cvkL HLFlugHHH/JUS1OhablzR8mv3c8xscMN2fwVs9J3/rbk5QHrnw8LNRATZ03H3hEqI7Cz ZANkeZZbqoLGclZbOSm7oq2xhmmli+O97NyZdU5owDErait4prw3ox3U9eekeajPf6QU aKJw== X-Gm-Message-State: AOJu0YwHaWyRCFPZ/bYWgHObplr3Yjisq+rLjSPhalg1xP0ze84cSiLG Dl+a+M0JTKPCXzXLNDyF6aFPjidyjduYPRdhcjWTWURrVyqJeTz0tpYLQmIZYZeqeP0Kt19C8gN Q X-Google-Smtp-Source: AGHT+IFOaLpzd8HiSWYljU7nafFUixNYmHmcKCzBYZDf+bD0pKk0mO2N+mV1ZzmmVKfyA3UF/X5/EQ== X-Received: by 2002:a05:6602:5c2:b0:7ce:f921:6a42 with SMTP id w2-20020a05660205c200b007cef9216a42mr8072554iox.0.1711032522906; Thu, 21 Mar 2024 07:48:42 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id q20-20020a02c8d4000000b0047bed9ff286sm250835jao.31.2024.03.21.07.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:48:41 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/6] mm: add nommu variant of vm_insert_pages() Date: Thu, 21 Mar 2024 08:45:00 -0600 Message-ID: <20240321144831.58602-6-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321144831.58602-1-axboe@kernel.dk> References: <20240321144831.58602-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 An identical one exists for vm_insert_page(), add one for vm_insert_pages() to avoid needing to check for CONFIG_MMU in code using it. Signed-off-by: Jens Axboe --- mm/nommu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/nommu.c b/mm/nommu.c index 5ec8f44e7ce9..a34a0e376611 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -355,6 +355,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, } EXPORT_SYMBOL(vm_insert_page); +int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr, + struct page **pages, unsigned long *num) +{ + return -EINVAL; +} +EXPORT_SYMBOL(vm_insert_pages); + int vm_map_pages(struct vm_area_struct *vma, struct page **pages, unsigned long num) { From patchwork Thu Mar 21 14:45:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13598859 Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.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 1F8ED84A51 for ; Thu, 21 Mar 2024 14:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032528; cv=none; b=OhN6b3IZbbK2mgMT8l/oBg5NyI7GQGxnJxS1ON3YFa4hr0ZrnGbfmT/4UoIkVKwTdQDkCGiX7L/4v7Gu8L/k9j2X7vCGtfjW2jPXpphOvRyjhLA+M/YTvAIts9IR2QIJyQQPzTowzbnrEV//lVWjCYUuh5/goL7X4kNJbGlPhKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711032528; c=relaxed/simple; bh=K5JoFd7Og90ybtaBTukGSgpPfoqSN4r09nHOq3fQOsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uayqwrzIHdo8jST2mUlCF/w6r7nftI1qMaQwJ8DgjCw3FfPKGiuhIlbc+uG5sZ37YWuFZMqTWzrufpHQWrI0m+Vkj7ReN9iJ8a2D5eqsHzdD7E28wFxaCpfHs3f4dYQCsHG9peJASz6jMRZlNt9KLpuvpCFcRJDVmX9MrvWajfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=oKEgHwKZ; arc=none smtp.client-ip=209.85.166.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="oKEgHwKZ" Received: by mail-io1-f41.google.com with SMTP id ca18e2360f4ac-7cc5e664d52so19315139f.0 for ; Thu, 21 Mar 2024 07:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711032525; x=1711637325; 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=uFJX6lkI8QHF+Xl/UFObgDgE/sRh1i9l9Ro++WDjOMw=; b=oKEgHwKZh3M6rgAy5rQy0wbks06pfMB6Sd2oLASANowXC5Dpm+/XLpY9raAJPl37Tt Kx8011k8silHk7PayU6y/Jdb4eJbwoWbGbMUlZ3BATNz5Ia4n5vOVPe0jG7745YbJXdf ena68eAlJGW1A8E0JxhtfrrkzQJDUZEM3SkERZW+qXSbILKKFhavm1JrS/bfUpn4XHNn 4Hpj426tY8zqM9VsHqjnaAKJAsYeW9cw9KeIM9ukXvKZy/FK1E7zDXoM8Buhhbskil2+ 5VHT5seLfeLFw51GXmfKEutxQEEb0Oo/stMUxFzr67WALiE+U7mh190Bwbs0Anue1gMC di4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711032525; x=1711637325; 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=uFJX6lkI8QHF+Xl/UFObgDgE/sRh1i9l9Ro++WDjOMw=; b=mqsV68q+4N4/hItKGhPn6VmZZirKjNObqwSpXzHPAJJnpyfSdID6s3lrCZO2jKmGyC UYYGBe6Qaa6D+0DGkok9H8kZQ/oLrso3gs/O8pz7Y+rA975JPyf/yVBT0U4RflDoEQrL ieRRhCkjzAltevxFkztEQ/c3QdTojIt24Rb0veT01NTm6eXULR72TMtszczlUF2mWMg6 BYLwqkWVN/7ow/kK6PsZNcEfSXXiZzo3LXnsDdQAcT77KVDfvRnfJGe7GLQ6k0rPj+f1 xMQDd4TPALyXC2f1QvZd6sy4ijilbFtujK+FHavlXz4Qu4mKWvg/EiVp1fDDhzkX/A22 oGaw== X-Gm-Message-State: AOJu0YxaS64rqChsc5x3/cnnyln+3Abjn40CwA8j+oJlvVG2RFbgA3// tjhrWlbcf8Acf8niyQJRgAFGPNFyPG6qPadKrlN7/bH/QEnzRajuKqii91SnpG2p+fp9sC1qPqA P X-Google-Smtp-Source: AGHT+IH0KExpHY07ICCnKhtxwmQmcA3hjhkVKmKI2qnWKBun/Vq7dtXCWkcBUKqPW8ucXVQBpoRvdw== X-Received: by 2002:a6b:5108:0:b0:7ce:f407:1edf with SMTP id f8-20020a6b5108000000b007cef4071edfmr8860937iob.0.1711032524836; Thu, 21 Mar 2024 07:48:44 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id q20-20020a02c8d4000000b0047bed9ff286sm250835jao.31.2024.03.21.07.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 07:48:43 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/6] io_uring/kbuf: use vm_insert_pages() for mmap'ed pbuf ring Date: Thu, 21 Mar 2024 08:45:01 -0600 Message-ID: <20240321144831.58602-7-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321144831.58602-1-axboe@kernel.dk> References: <20240321144831.58602-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rather than use remap_pfn_range() for this and manually free later, switch to using vm_insert_page() and have it Just Work. This requires a bit of effort on the mmap lookup side, as the ctx uring_lock isn't held, which otherwise protects buffer_lists from being torn down, and it's not safe to grab from mmap context that would introduce an ABBA deadlock between the mmap lock and the ctx uring_lock. Instead, lookup the buffer_list under RCU, as the the list is RCU freed already. Use the existing reference count to determine whether it's possible to safely grab a reference to it (eg if it's not zero already), and drop that reference when done with the mapping. If the mmap reference is the last one, the buffer_list and the associated memory can go away, since the vma insertion has references to the inserted pages at that point. Signed-off-by: Jens Axboe --- include/linux/io_uring_types.h | 3 - io_uring/io_uring.c | 30 ++---- io_uring/io_uring.h | 3 - io_uring/kbuf.c | 178 +++++++++++++-------------------- io_uring/kbuf.h | 4 +- 5 files changed, 82 insertions(+), 136 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index c9a1952a383a..f37caff64d05 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -370,9 +370,6 @@ struct io_ring_ctx { struct list_head io_buffers_cache; - /* deferred free list, protected by ->uring_lock */ - struct hlist_head io_buf_list; - /* Keep this last, we don't need it for the fast path */ struct wait_queue_head poll_wq; struct io_restriction restrictions; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5b80849fbb85..8ce36c5a37c4 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -303,7 +303,6 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p) INIT_LIST_HEAD(&ctx->sqd_list); INIT_LIST_HEAD(&ctx->cq_overflow_list); INIT_LIST_HEAD(&ctx->io_buffers_cache); - INIT_HLIST_HEAD(&ctx->io_buf_list); io_alloc_cache_init(&ctx->rsrc_node_cache, IO_NODE_ALLOC_CACHE_MAX, sizeof(struct io_rsrc_node)); io_alloc_cache_init(&ctx->apoll_cache, IO_ALLOC_CACHE_MAX, @@ -2615,7 +2614,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, return READ_ONCE(rings->cq.head) == READ_ONCE(rings->cq.tail) ? ret : 0; } -void io_mem_free(void *ptr) +static void io_mem_free(void *ptr) { if (!ptr) return; @@ -2728,7 +2727,7 @@ static void io_rings_free(struct io_ring_ctx *ctx) ctx->sq_sqes = NULL; } -void *io_mem_alloc(size_t size) +static void *io_mem_alloc(size_t size) { gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP; void *ret; @@ -2838,7 +2837,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx) ctx->mm_account = NULL; } io_rings_free(ctx); - io_kbuf_mmap_list_free(ctx); percpu_ref_exit(&ctx->refs); free_uid(ctx->user); @@ -3307,11 +3305,9 @@ static void *io_uring_validate_mmap_request(struct file *file, loff_t pgoff, size_t sz) { struct io_ring_ctx *ctx = file->private_data; - loff_t offset = pgoff << PAGE_SHIFT; - struct page *page; void *ptr; - switch (offset & IORING_OFF_MMAP_MASK) { + switch ((pgoff << PAGE_SHIFT) & IORING_OFF_MMAP_MASK) { case IORING_OFF_SQ_RING: case IORING_OFF_CQ_RING: /* Don't allow mmap if the ring was setup without it */ @@ -3325,23 +3321,13 @@ static void *io_uring_validate_mmap_request(struct file *file, return ERR_PTR(-EINVAL); ptr = ctx->sq_sqes; break; - case IORING_OFF_PBUF_RING: { - unsigned int bgid; - - bgid = (offset & ~IORING_OFF_MMAP_MASK) >> IORING_OFF_PBUF_SHIFT; - rcu_read_lock(); - ptr = io_pbuf_get_address(ctx, bgid); - rcu_read_unlock(); - if (!ptr) - return ERR_PTR(-EINVAL); - break; - } + case IORING_OFF_PBUF_RING: + return 0; default: return ERR_PTR(-EINVAL); } - page = virt_to_head_page(ptr); - if (sz > page_size(page)) + if (sz > page_size(virt_to_head_page(ptr))) return ERR_PTR(-EINVAL); return ptr; @@ -3352,6 +3338,7 @@ static void *io_uring_validate_mmap_request(struct file *file, static __cold int io_uring_mmap(struct file *file, struct vm_area_struct *vma) { size_t sz = vma->vm_end - vma->vm_start; + long offset = vma->vm_pgoff << PAGE_SHIFT; unsigned long pfn; void *ptr; @@ -3359,6 +3346,9 @@ static __cold int io_uring_mmap(struct file *file, struct vm_area_struct *vma) if (IS_ERR(ptr)) return PTR_ERR(ptr); + if ((offset & IORING_OFF_MMAP_MASK) == IORING_OFF_PBUF_RING) + return io_pbuf_mmap(file, vma); + pfn = virt_to_phys(ptr) >> PAGE_SHIFT; return remap_pfn_range(vma, vma->vm_start, pfn, sz, vma->vm_page_prot); } diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index bae8c1e937c1..050efc3e7973 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -108,9 +108,6 @@ bool __io_alloc_req_refill(struct io_ring_ctx *ctx); bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task, bool cancel_all); -void *io_mem_alloc(size_t size); -void io_mem_free(void *ptr); - enum { IO_EVENTFD_OP_SIGNAL_BIT, IO_EVENTFD_OP_FREE_BIT, diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 206f4d352e15..52210772da2f 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -32,25 +32,12 @@ struct io_provide_buf { __u16 bid; }; -struct io_buf_free { - struct hlist_node list; - void *mem; - size_t size; - int inuse; -}; - -static inline struct io_buffer_list *__io_buffer_get_list(struct io_ring_ctx *ctx, - unsigned int bgid) -{ - return xa_load(&ctx->io_bl_xa, bgid); -} - static inline struct io_buffer_list *io_buffer_get_list(struct io_ring_ctx *ctx, unsigned int bgid) { lockdep_assert_held(&ctx->uring_lock); - return __io_buffer_get_list(ctx, bgid); + return xa_load(&ctx->io_bl_xa, bgid); } static int io_buffer_add_list(struct io_ring_ctx *ctx, @@ -191,24 +178,6 @@ void __user *io_buffer_select(struct io_kiocb *req, size_t *len, return ret; } -/* - * Mark the given mapped range as free for reuse - */ -static void io_kbuf_mark_free(struct io_ring_ctx *ctx, struct io_buffer_list *bl) -{ - struct io_buf_free *ibf; - - hlist_for_each_entry(ibf, &ctx->io_buf_list, list) { - if (bl->buf_ring == ibf->mem) { - ibf->inuse = 0; - return; - } - } - - /* can't happen... */ - WARN_ON_ONCE(1); -} - static int __io_remove_buffers(struct io_ring_ctx *ctx, struct io_buffer_list *bl, unsigned nbufs) { @@ -220,23 +189,20 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx, if (bl->is_buf_ring) { i = bl->buf_ring->tail - bl->head; - if (bl->is_mmap) { - /* - * io_kbuf_list_free() will free the page(s) at - * ->release() time. - */ - io_kbuf_mark_free(ctx, bl); - bl->buf_ring = NULL; - bl->is_mmap = 0; - } else if (bl->buf_nr_pages) { + if (bl->buf_nr_pages) { int j; - for (j = 0; j < bl->buf_nr_pages; j++) - unpin_user_page(bl->buf_pages[j]); + for (j = 0; j < bl->buf_nr_pages; j++) { + if (bl->is_mmap) + put_page(bl->buf_pages[j]); + else + unpin_user_page(bl->buf_pages[j]); + } kvfree(bl->buf_pages); vunmap(bl->buf_ring); bl->buf_pages = NULL; bl->buf_nr_pages = 0; + bl->is_mmap = 0; } /* make sure it's seen as empty */ INIT_LIST_HEAD(&bl->buf_list); @@ -537,63 +503,48 @@ static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg, return ret; } -/* - * See if we have a suitable region that we can reuse, rather than allocate - * both a new io_buf_free and mem region again. We leave it on the list as - * even a reused entry will need freeing at ring release. - */ -static struct io_buf_free *io_lookup_buf_free_entry(struct io_ring_ctx *ctx, - size_t ring_size) +static int io_alloc_map_pages(struct io_buffer_list *bl, size_t ring_size) { - struct io_buf_free *ibf, *best = NULL; - size_t best_dist; - - hlist_for_each_entry(ibf, &ctx->io_buf_list, list) { - size_t dist; - - if (ibf->inuse || ibf->size < ring_size) - continue; - dist = ibf->size - ring_size; - if (!best || dist < best_dist) { - best = ibf; - if (!dist) - break; - best_dist = dist; - } + int i, nr_pages; + + nr_pages = (ring_size + PAGE_SIZE - 1) >> PAGE_SHIFT; + bl->buf_pages = kvmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL); + if (!bl->buf_pages) + return -ENOMEM; + + for (i = 0; i < nr_pages; i++) { + bl->buf_pages[i] = alloc_page(GFP_KERNEL); + if (!bl->buf_pages[i]) + goto out_free; } - return best; + bl->buf_ring = vmap(bl->buf_pages, nr_pages, VM_MAP, PAGE_KERNEL); + if (bl->buf_ring) { + bl->buf_nr_pages = nr_pages; + return 0; + } +out_free: + while (i--) + put_page(bl->buf_pages[i]); + kvfree(bl->buf_pages); + bl->buf_pages = NULL; + bl->buf_nr_pages = 0; + return -ENOMEM; } static int io_alloc_pbuf_ring(struct io_ring_ctx *ctx, struct io_uring_buf_reg *reg, struct io_buffer_list *bl) { - struct io_buf_free *ibf; size_t ring_size; - void *ptr; + int ret; ring_size = reg->ring_entries * sizeof(struct io_uring_buf_ring); - /* Reuse existing entry, if we can */ - ibf = io_lookup_buf_free_entry(ctx, ring_size); - if (!ibf) { - ptr = io_mem_alloc(ring_size); - if (IS_ERR(ptr)) - return PTR_ERR(ptr); - - /* Allocate and store deferred free entry */ - ibf = kmalloc(sizeof(*ibf), GFP_KERNEL_ACCOUNT); - if (!ibf) { - io_mem_free(ptr); - return -ENOMEM; - } - ibf->mem = ptr; - ibf->size = ring_size; - hlist_add_head(&ibf->list, &ctx->io_buf_list); - } - ibf->inuse = 1; - bl->buf_ring = ibf->mem; + ret = io_alloc_map_pages(bl, ring_size); + if (ret) + return ret; + bl->is_buf_ring = 1; bl->is_mmap = 1; return 0; @@ -710,30 +661,43 @@ int io_register_pbuf_status(struct io_ring_ctx *ctx, void __user *arg) return 0; } -void *io_pbuf_get_address(struct io_ring_ctx *ctx, unsigned long bgid) +int io_pbuf_mmap(struct file *file, struct vm_area_struct *vma) { + struct io_ring_ctx *ctx = file->private_data; + loff_t pgoff = vma->vm_pgoff << PAGE_SHIFT; struct io_buffer_list *bl; + unsigned long npages; + int bgid, ret; - bl = __io_buffer_get_list(ctx, bgid); + bgid = (pgoff & ~IORING_OFF_MMAP_MASK) >> IORING_OFF_PBUF_SHIFT; - if (!bl || !bl->is_mmap) - return NULL; + /* + * We have to be a bit careful here - we're inside mmap and cannot + * grab the uring_lock. This means the buffer_list could be + * simultaneously going away, if someone is trying to be sneaky. + * Look it up under rcu so we now it's not going away, and attempt + * to grab a reference to it. If the ref is already zero, then fail + * the mapping. If successful, we'll drop the reference at at the end. + * This may then safely free the buffer_list (and drop the pages) at + * that point, vm_insert_pages() would've already grabbed the + * necessary vma references. + */ + ret = 0; + rcu_read_lock(); + bl = xa_load(&ctx->io_bl_xa, bgid); + /* must be a mmap'able buffer ring and have pages */ + if (bl && bl->is_mmap && bl->buf_nr_pages) + ret = atomic_inc_not_zero(&bl->refs); + rcu_read_unlock(); + + /* buffer list is invalid or being torn down, fail the mapping */ + if (!ret) + return -EINVAL; - return bl->buf_ring; -} + vm_flags_set(vma, VM_DONTEXPAND); -/* - * Called at or after ->release(), free the mmap'ed buffers that we used - * for memory mapped provided buffer rings. - */ -void io_kbuf_mmap_list_free(struct io_ring_ctx *ctx) -{ - struct io_buf_free *ibf; - struct hlist_node *tmp; - - hlist_for_each_entry_safe(ibf, tmp, &ctx->io_buf_list, list) { - hlist_del(&ibf->list); - io_mem_free(ibf->mem); - kfree(ibf); - } + npages = bl->buf_nr_pages; + ret = vm_insert_pages(vma, vma->vm_start, bl->buf_pages, &npages); + io_put_bl(ctx, bl); + return ret; } diff --git a/io_uring/kbuf.h b/io_uring/kbuf.h index 8b868a1744e2..0723a6ffe731 100644 --- a/io_uring/kbuf.h +++ b/io_uring/kbuf.h @@ -55,13 +55,11 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg); int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg); int io_register_pbuf_status(struct io_ring_ctx *ctx, void __user *arg); -void io_kbuf_mmap_list_free(struct io_ring_ctx *ctx); - void __io_put_kbuf(struct io_kiocb *req, unsigned issue_flags); bool io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags); -void *io_pbuf_get_address(struct io_ring_ctx *ctx, unsigned long bgid); +int io_pbuf_mmap(struct file *file, struct vm_area_struct *vma); static inline bool io_kbuf_recycle_ring(struct io_kiocb *req) {