From nobody Sat Feb 7 10:44:41 2026 Received: from mail-ua1-f98.google.com (mail-ua1-f98.google.com [209.85.222.98]) (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 289A142A569 for ; Thu, 8 Jan 2026 09:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767864008; cv=none; b=Y2W8MGZqiZHe4NKeGAZ5q+W+hxp35T0l/+q96/8ikqiw/wLYpuWnKRM5KRCoDJXG7iEC1OIOaPVBjZd+U7PLwkrrzIaFb9hNJ0XFSSHprTsQboGuN0HgmcvReRKXPz8uwkWNqVJnj15gFChd+Eu5zWdus4/EDGLx6GvetfVQTDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767864008; c=relaxed/simple; bh=9D4GyOJD6io8F4P0S/cxnoZEefdej4J2wab8Tdm/MgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=apaOFJr+rQL/pZNIxx8s7ExG70hktkIasfjAW4ItKHLr0XfVG4dquL6x9OEPTvFDsr27oTcgOk3CzbWO8u3IOwNTOjONBwAi37ux0aEa4e6mPWTsZPG5KLd0qBJj8D55bb2/1H6Nis8sl7qHGE30i8HJNrGNn/ILc1i/oEWurNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=BcIVmSXN; arc=none smtp.client-ip=209.85.222.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="BcIVmSXN" Received: by mail-ua1-f98.google.com with SMTP id a1e0cc1a2514c-93f5d55ee5aso78786241.2 for ; Thu, 08 Jan 2026 01:19:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1767863998; x=1768468798; 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=kSXckNgZ5ICG+taX3/Ya5CBeOAwOb38yMX5qmoedbkY=; b=BcIVmSXNyUBaHeqL02EgOVuVHgT7hFyN4ONyCGynpvDOUNGAlqMOAuNgdEzSubchl2 iA3bWN8vPKJ93x/i7UxzgbDQpZ0+MyLxN/mu+bGpfX+ZrzJ0YGKbP7n5x1JuihVOZIlJ x9kiuiKw8nKvAdAOcHzOU1z4aIGpe9DV+m4rt9kjFi6GZMyPLlO9SlmnQjUijXBQ/Xyc yXAkb76JQeHsgsv9KBkyJfICtEuZQrU2YnZCIeTQOIgk6eoZqdkS1AZGFuvtY76M9tOd YTjd8E6K+HHR74L/fol9G1ga0L4b9BLwFkhBwG2Ma272rptcGqha452DJ2w7EDP2eMcJ BeCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767863998; x=1768468798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kSXckNgZ5ICG+taX3/Ya5CBeOAwOb38yMX5qmoedbkY=; b=RU+OGT0ptJMg/jku5yMFzijTQ+A9u1x/AAe/suzlntp3ELJBNTJr5lTq9rMQTObPnC 2oVN/WE4dMe2q0N4nkDMR5gC6pttHmYWL4OrP1knoZK9ge92sAR6e3xr/96HWBUCk/lc Mux1fQZqC4H4YDPlYlbWZkwfEzsR3I/wY9TlIUwF82nPp2oYifWKcXX2VUpYGYPurJ3E JJeixF8pfdUbU301dieuh2YR1H+g6De+1DAw7B5iu3K8ViYsi2zec+Lh+kUA27xIkfev FZEzVBGnCT914uiyPF61PhtJC2CuxSq1orCTbIvQAVk1UhWzKUgCIMrMlQ5peIFOPJkh H/cg== X-Forwarded-Encrypted: i=1; AJvYcCVHICO1wNGItk/qkNg93cNGqwmA4PVl869+E3F/TsJj9WUZmSXqfBVfZpnx1SIw5NtBAr51PenBReecAeY=@vger.kernel.org X-Gm-Message-State: AOJu0YypJdY1LIyyO2OcpCSiltYB1kH7b06KZSb0e+oo6yivd5OfJROP 7FvnBcayh5bM26BPa50KTn0CxWfk7lQGmEpwNePP3CCHWEUvSC2acKdJTtdfJTurUrSlmVhXztW LkwszYL13jJRnLVAplr1ZEPTCnFRAZGwFyKg7 X-Gm-Gg: AY/fxX68s8x3zpurlyQQSlBB1XQ8j43ZqT1CweIye6odLcOBPtnTyiIjeSX6mVE+q+c 8qTIqZ2TOkiYgZNldOc9KDyXLVZXGeoCtz+sg8WOBWI8AN5nDIJaolFdxd3+RsblQ9mwiYQIRgP 2ZUzzpT69CFRNnB1MgZANJRsUdi93ad7hrnnyviQIvBjdNheHbemxdOPXVTfQ7eNIhnO2c8idy/ yZysyfHxdYb6h4MCv4eYqEVcIKDMBFgT/7Se6qSDlv2JsG3jg5Z7JgO3lsoFwa6RStHFa2i2oFn /VyMl+styO0UUkgf3nyNO/L/JHSgvY8Tn2lTnxHUyq97tWjeTk6PSsZX5IMQlQRAb8bTt5QDRic KPkiwmERoAEZasbvukgjbzAw3diAqsgJO1ekKJJGuZA== X-Google-Smtp-Source: AGHT+IE7Ge1AcENQX9O/MS5JVNja68MmFbDGu7d8jgtYr1HGUxQVFEkLjbdXGKK42kA/Gk87KY6YQpwurEsq X-Received: by 2002:a67:e701:0:b0:5db:e851:9386 with SMTP id ada2fe7eead31-5ecb1e75d6amr1271152137.2.1767863997587; Thu, 08 Jan 2026 01:19:57 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id ada2fe7eead31-5ec76e62f92sm1109185137.0.2026.01.08.01.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 01:19:57 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.6.120]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 9BCE6340794; Thu, 8 Jan 2026 02:19:56 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 95F68E42F2C; Thu, 8 Jan 2026 02:19:56 -0700 (MST) From: Caleb Sander Mateos To: Ming Lei , Jens Axboe , Shuah Khan Cc: linux-block@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Stanley Zhang , Uday Shankar , "Martin K . Petersen" , Caleb Sander Mateos Subject: [PATCH v4 11/19] ublk: optimize ublk_user_copy() on daemon task Date: Thu, 8 Jan 2026 02:19:39 -0700 Message-ID: <20260108091948.1099139-12-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260108091948.1099139-1-csander@purestorage.com> References: <20260108091948.1099139-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ublk user copy syscalls may be issued from any task, so they take a reference count on the struct ublk_io to check whether it is owned by the ublk server and prevent a concurrent UBLK_IO_COMMIT_AND_FETCH_REQ from completing the request. However, if the user copy syscall is issued on the io's daemon task, a concurrent UBLK_IO_COMMIT_AND_FETCH_REQ isn't possible, so the atomic reference count dance is unnecessary. Check for UBLK_IO_FLAG_OWNED_BY_SRV to ensure the request is dispatched to the sever and obtain the request from ublk_io's req field instead of looking it up on the tagset. Skip the reference count increment and decrement. Commit 8a8fe42d765b ("ublk: optimize UBLK_IO_REGISTER_IO_BUF on daemon task") made an analogous optimization for ublk zero copy buffer registration. Signed-off-by: Caleb Sander Mateos Reviewed-by: Ming Lei --- drivers/block/ublk_drv.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 08674c29cfdc..707a74ab083a 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -181,11 +181,11 @@ struct ublk_io { /* * The number of uses of this I/O by the ublk server * if user copy or zero copy are enabled: * - UBLK_REFCOUNT_INIT from dispatch to the server * until UBLK_IO_COMMIT_AND_FETCH_REQ - * - 1 for each inflight ublk_ch_{read,write}_iter() call + * - 1 for each inflight ublk_ch_{read,write}_iter() call not on task * - 1 for each io_uring registered buffer not registered on task * The I/O can only be completed once all references are dropped. * User copy and buffer registration operations are only permitted * if the reference count is nonzero. */ @@ -2689,10 +2689,11 @@ ublk_user_copy(struct kiocb *iocb, struct iov_iter = *iter, int dir) struct ublk_queue *ubq; struct request *req; struct ublk_io *io; unsigned data_len; bool is_integrity; + bool on_daemon; size_t buf_off; u16 tag, q_id; ssize_t ret; =20 if (!user_backed_iter(iter)) @@ -2718,13 +2719,24 @@ ublk_user_copy(struct kiocb *iocb, struct iov_iter = *iter, int dir) =20 if (tag >=3D ub->dev_info.queue_depth) return -EINVAL; =20 io =3D &ubq->ios[tag]; - req =3D __ublk_check_and_get_req(ub, q_id, tag, io); - if (!req) - return -EINVAL; + on_daemon =3D current =3D=3D READ_ONCE(io->task); + if (on_daemon) { + /* On daemon, io can't be completed concurrently, so skip ref */ + if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV)) + return -EINVAL; + + req =3D io->req; + if (!ublk_rq_has_data(req)) + return -EINVAL; + } else { + req =3D __ublk_check_and_get_req(ub, q_id, tag, io); + if (!req) + return -EINVAL; + } =20 if (is_integrity) { struct blk_integrity *bi =3D &req->q->limits.integrity; =20 data_len =3D bio_integrity_bytes(bi, blk_rq_sectors(req)); @@ -2745,11 +2757,12 @@ ublk_user_copy(struct kiocb *iocb, struct iov_iter = *iter, int dir) ret =3D ublk_copy_user_integrity(req, buf_off, iter, dir); else ret =3D ublk_copy_user_pages(req, buf_off, iter, dir); =20 out: - ublk_put_req_ref(io, req); + if (!on_daemon) + ublk_put_req_ref(io, req); return ret; } =20 static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to) { --=20 2.45.2