From nobody Fri Dec 19 04:31:00 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1744659101; cv=none; d=zohomail.com; s=zohoarc; b=GXWHrPugPqY83sRJK2mOPDfEVTqMxUmayZlpB7/7VoaXvbuU6lQNg86IEjbJ2bfPrrg4fJkVDfZK7Skf1B3NC5G8YQkEiaaViZtx44/tDw16cMMSi68lOcD6xwt5dsrcMA2r+QGI2MQzOfoVIZjdsNwkC8nHT5Tdm/HlcaA0o6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744659101; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lnPw6CQC/Rs6Gnzgq2fiqjMDcByg2P+791cufmNvCio=; b=Fefc6BH7jbE2MZ8cW1/lfV5elznT8827+lWQ4LXWeCeKiFFN8JPbWq2T5cmEklm6JlybyIT6lgkuXVPjtndRmVuJYPwNQnXiiIBk/D5OUuTHE5Esic8JM+a5MrMT1nKHDSNDxM2Iwha1THa5vxrTQP2JllkNBqRMQTRr3UX+vtI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1744659101767130.7229452623045; Mon, 14 Apr 2025 12:31:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u4PWH-0005vS-6b; Mon, 14 Apr 2025 15:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u4Owr-00027j-RA for qemu-devel@nongnu.org; Mon, 14 Apr 2025 14:54:25 -0400 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u4Owp-0006mq-9r for qemu-devel@nongnu.org; Mon, 14 Apr 2025 14:54:25 -0400 Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-6f0c30a1cf8so51004136d6.2 for ; Mon, 14 Apr 2025 11:54:20 -0700 (PDT) Received: from paper101.paper-domain.cs.uwaterloo.ca (paper-base.cs.uwaterloo.ca. [129.97.152.163]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6f0dea101aasm86688676d6.96.2025.04.14.11.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Apr 2025 11:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744656860; x=1745261660; darn=nongnu.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=lnPw6CQC/Rs6Gnzgq2fiqjMDcByg2P+791cufmNvCio=; b=jDZPpvQXVha9OPUscNn67A2pEPUDiVqWzvV+Grn17vFrtChhVFVw96Gsb88ArbJpHu 35a8FgMM/AmVNgUt63uvj+pip8SDu+3PPp7vlUm2z8VEWNO4hDwrYYP25JZye5FedacS 56q5CP5zVyq50AjuT251eAQlLrET32ThVB1u8OhHQptyE3vcXrweW12lcMCfrO+9pfhJ vdMsntKaat0t+VqnY+Hg8yJQCVZfggmgRZSb0R0Urn8kKQle3/dLKpuJFW9kQtbISTaO cQmNGOiTltyVk++SBJdGh0h2lmX7UEj7mO592sJotcSlS8K5MeHVi5h/NxxRR2P89DmO Yl2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744656860; x=1745261660; 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=lnPw6CQC/Rs6Gnzgq2fiqjMDcByg2P+791cufmNvCio=; b=oMQ2p2HH2alN3vgUQeji1nufnbDo+iReCZtfLCqWsoRG7F/xaTN0WgopqaIjf6M07Y ZLJXKrommnEDAO1wTV6f3wd2vsvZPhCI/0c1tJCVAIDCAhshtmtV4LJDlH46+VXrwRo+ pU32c/hRqLXMHqbQjRwYIhTW62JfCcJuq837AMMCCoFvkx8+ZDM2LqtnvUxMqvd9Yv25 pJdBYf6UHaCy42mWfnBj8x18iaNKLhoq0fsoM2ltcNPw5wcCanOflsw8Vd4cScVbwBay Y/gF2yID0uCbzSk+DDzaNiRBSTk/ambTp0SXYEtRPGqd003u8ULV9bporUxDSpnGfsEj +n5A== X-Gm-Message-State: AOJu0YxjlUUqZ2CTXRb7C2fxUHD7n9kt+PFBClVPpVX1x1OlUh3Vbt+v wj3//noKNkEWbDrGR6zxF+CdF7yiXVCGLjnR784tVlhcVQz54kRte+FLug== X-Gm-Gg: ASbGncu40KxkKRW0vv3Kv/5cWWUET6m8XgOweO7lEXpWULzEhR68O0NDu3Kg1P3e4cJ Lbm8HMX4xWxBO8A06JFq88llVNxuZtjZ2J5cPAT1uBTWq2WuYeK4Pvz4KZ85Ydr/0byWyNxrXWV cJYs9bb0PvNdPMrQyK3lfJY6DuwhKvrxL2fZd5EEZBTuy9JuexOjexHy/C2qWOKa39AKiv02LoS 9DFj/wKWHymLXil3wBF1KiaahSATdeUplhtRz038U95/Roqiclc2feusaQ6UMvQHTTyr7tyehgf QDNE4D4yuE+vQB6nSvBhWonUdXBGLJBDFKt0kklK21Z3j7iY3uFk7CgwJCAZqxUZfKp+ALTRyna Epd57tLbHKVwnmWXr+38F3Gb3hj+jRrWZj59itZI= X-Google-Smtp-Source: AGHT+IEUMRqwVOY1CeQxwvy0hy3bUAbhKim9/3Aj4Mg6L1b7y8FcscmBIplA7xK9XilG6y7V8Ne5fg== X-Received: by 2002:a05:6214:2601:b0:6e8:fabd:ddd with SMTP id 6a1803df08f44-6f230cc1354mr173178486d6.1.1744656859713; Mon, 14 Apr 2025 11:54:19 -0700 (PDT) From: Brian Song To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, Brian Song Subject: [RFC PATCH 1/1] This work adds support for registering block file descriptors to the io_uring instance and uses IOSQE_FIXED_FILE in I/O requests (SQEs) to avoid the cost of fdget() in the kernel. It is a basic implementation for testing, and does not yet handle cases where block devices are removed. Date: Mon, 14 Apr 2025 18:54:12 +0000 Message-ID: <20250414185414.2922845-2-hibriansong@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250414185414.2922845-1-hibriansong@gmail.com> References: <20250414185414.2922845-1-hibriansong@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=hibriansong@gmail.com; helo=mail-qv1-xf32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 14 Apr 2025 15:30:33 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1744659105062019100 Content-Type: text/plain; charset="utf-8" Suggested-by: Kevin Wolf Suggested-by: Stefan Hajnoczi Signed-off-by: Brian Song --- block/io_uring.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/block/io_uring.c b/block/io_uring.c index dd4f304910..94a875fbae 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -58,6 +58,11 @@ struct LuringState { LuringQueue io_q; =20 QEMUBH *completion_bh; + + /* fixed file support */ + int *registered_fds; + int nr_registered_fds; + int max_registered_fds; /* size of registered_fds */ }; =20 /** @@ -323,6 +328,41 @@ static void luring_deferred_fn(void *opaque) } } =20 +static int luring_register_fd(LuringState *s, int fd) +{ + int idx; + int *new_fds; + int ret; + + for (idx =3D 0; idx < s->nr_registered_fds; idx++) { + if (s->registered_fds[idx] =3D=3D fd) { + return idx; + } + } + + /* Grow the array if needed */ + if (s->nr_registered_fds >=3D s->max_registered_fds) { + int new_max =3D s->max_registered_fds * 2; + new_fds =3D g_realloc(s->registered_fds, sizeof(int) * new_max); + if (!new_fds) { + return -ENOMEM; + } + s->registered_fds =3D new_fds; + s->max_registered_fds =3D new_max; + } + + idx =3D s->nr_registered_fds++; + s->registered_fds[idx] =3D fd; + =20 + ret =3D io_uring_register_files(&s->ring, s->registered_fds, s->nr_reg= istered_fds); + if (ret < 0) { + s->nr_registered_fds--; + return ret; + } + + return idx; +} + /** * luring_do_submit: * @fd: file descriptor for I/O @@ -339,6 +379,15 @@ static int luring_do_submit(int fd, LuringAIOCB *lurin= gcb, LuringState *s, { int ret; struct io_uring_sqe *sqes =3D &luringcb->sqeq; + int fixed_fd_idx; + =20 + fixed_fd_idx =3D luring_register_fd(s, fd); + if (fixed_fd_idx < 0) { + return fixed_fd_idx; + } + =20 + sqes->flags |=3D IOSQE_FIXED_FILE; + sqes->fd =3D fixed_fd_idx; =20 switch (type) { case QEMU_AIO_WRITE: @@ -447,6 +496,11 @@ LuringState *luring_init(Error **errp) return NULL; } =20 + /* Initialize fixed file support */ + s->max_registered_fds =3D 1024; + s->registered_fds =3D g_new0(int, s->max_registered_fds); + s->nr_registered_fds =3D 0; + ioq_init(&s->io_q); return s; =20 @@ -454,6 +508,12 @@ LuringState *luring_init(Error **errp) =20 void luring_cleanup(LuringState *s) { + if (s->registered_fds) { + if (s->nr_registered_fds > 0) { + io_uring_unregister_files(&s->ring); + } + g_free(s->registered_fds); + } io_uring_queue_exit(&s->ring); trace_luring_cleanup_state(s); g_free(s); --=20 2.43.0