From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f100.google.com (mail-oo1-f100.google.com [209.85.161.100]) (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 8EAE72E03EA for ; Wed, 29 Jul 2026 01:30:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785288616; cv=none; b=tJy628ScMz2uSTpGryHnmT7+z2fdrmV1/AhVDMA1qv24J7q2BA/AUjNHGahFsSChazaDphe+Y7QU9TGAFqBnIX4hqMlO50F2Ejz2tDtyVHXdbYUqSnR4F/u8yWITf6rJAvcR3F33vmDz+T0jIlq7JnMtjf/FnaChO7N/K5kKM+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785288616; c=relaxed/simple; bh=NpcohaBcnv6za/GmbnYrzhV0FADG4UeMPd9+mSNyaLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZAMmKllHhHqvq0NqqQ+K09mNglAGvB4tF32ZsZH/QGTKTihgfSojdJr3Y5ED/hXoFXKMXdzr/0ZUemPZKLULOkep+Juu7x2m0hsib0+FsLbHE+72nafBfigC643tAbTZjhrnoAf3FdDQnCYNP5Uet/tsDtXpwSRf/RzfN5xg6j8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=cBmFyDoS; arc=none smtp.client-ip=209.85.161.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass 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="cBmFyDoS" Received: by mail-oo1-f100.google.com with SMTP id 006d021491bc7-6aae25a5d4aso4917eaf.3 for ; Tue, 28 Jul 2026 18:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1785288605; x=1785893405; 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:content-type; bh=bd5xrrTHMzBUsh09hEvUsjiaV1Fjs8/c6t/6k06PFx4=; b=cBmFyDoShvA9jUdBMCQ8AATNt9kVOjSyxCo8vlz61kEdnxDZB9uR+LwoqKednBZxg2 tqBR8QPYrw19xLMe2bcK0mMJ3RxWLcvzA2GriKYdY8z+Y11m1xqod1jPpXFHn60jn2gd 7bx7y7THB54T+D5W5UntIcGdIeBnFu3snamKuVmD4qP7ND8RDHsflLnwoSK5OLlzyozf JWuuN+ihnmEi8bVkS1IpRm9dMedXFSRHdPabIV738OPmGm3ffNeXkJ5dQF3sjJwgjtXb iMkK6oRzOin0ncv2xC+PdZRBzNyUWTsegh6zgVUmheL405OaV5DPwggk4A74OR3zaclz bJXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785288605; x=1785893405; 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:content-type; bh=bd5xrrTHMzBUsh09hEvUsjiaV1Fjs8/c6t/6k06PFx4=; b=nJzNP54ByBpdtkaA8rzJj+sW7gKYcqvnt7jJ3vNP2JWiEig7A4Thz6eXVCaMhGn+Uc yYFxDx3fnDl4OY2tmdfWs24KCJD/jwQ+PkpHCfTNGIIVY+ZW4qnPBaQM6G1sRTnHwKKp hw8wTQqvHHS7CfYp2HLN2nTHAILEpUCNNM/gLYs/VeaK9XUJnpr2xxqwtjz5WQW5YOnM r/KLA1Hpoof75xlS5snphZlxFStAubxbh6phgGrjrjzFWBLbdILF5Zyi3AbnzYTVcApO Ap5H1uBn611AF5quUbM9QyevyDN7/gfnWIFtYRrz0mHexNJxtvJ1JZlsiYjjsjoYN9SU JMvg== X-Forwarded-Encrypted: i=1; AHgh+Ro5v6oRMKkb6tQOYEE76/EyKCuWdqLQm0EyiIvO9zAPeXRwtAZpO3sNZEGbfXqNO9XpIiXyCrXLCXLKyKo=@vger.kernel.org X-Gm-Message-State: AOJu0YyWVnvUhZrHAfILCr90pHHLhIYFo0A6n58nHsYzEs4977TmO/Iw kmYyeRQ8KcowxQMpGyKGOsMCcKBtk2jiJMdUdV6tXUUgDQhK0hSbRtV6shV9lb6oXl7OmSLmI9l x67MIzLPZB/FFUWRh449e42StjRR8UXgbJdPSAOKUhbVPQG0RMhAl X-Gm-Gg: AR+sD13fXLzekO4V9jaXNMHBncjzqmqh7uhys4lm0OiHxZ+qiHmLsXgEL1FLlKPDdc0 XBdf4Uf2qnFHnn+fyo2XUOSvFuJd+yCb9o4R6EetvXuAWGxAEfkZgjmkiLcmL/VLw6VVg6EMc1y tW/XlyYHyBd/0956Kj6OjJeqwDDmsTGzD1GUX8D5++Zt4nAYQADoXfei8hUaJTLkPo+eBNffYj0 y09OoGqYpLDMHdmWM2i8o6mYeW7X3lQVpSmU0DQPmxu2Z5V5TAWwOzrMSK/jy5tYtEtSq4ugRcm g1Jo43clPwHkUKDobrDzrsbR/ulWzUVmsEML93teo2fFtmt+rUg6J4YNUqOkUHaX45qBjaimy2p NU1Z7nOFIMbLwvERMlQ== X-Received: by 2002:a05:6820:c2c1:20b0:6a3:6bb0:e58d with SMTP id 006d021491bc7-6ac965bc96amr1300552eaf.0.1785288605436; Tue, 28 Jul 2026 18:30:05 -0700 (PDT) Received: from c7-smtp-2026.dev.purestorage.com ([2620:125:9017:12:36:3:6:0]) by smtp-relay.gmail.com with ESMTPS id 006d021491bc7-6aca5202389sm63637eaf.6.2026.07.28.18.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 18:30:05 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (bond0.slc5-n17m28-k8s.dev.purestorage.com [IPv6:2620:125:9025:20::a31:41f]) by c7-smtp-2026.dev.purestorage.com (Postfix) with ESMTP id F19DF40443; Tue, 28 Jul 2026 19:30:04 -0600 (MDT) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id ECF73E40442; Tue, 28 Jul 2026 19:30:04 -0600 (MDT) From: Caleb Sander Mateos To: Ming Lei , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH 6/6] ublk: lift need_map check out of ublk_{,un}map_io() Date: Tue, 28 Jul 2026 19:29:51 -0600 Message-ID: <20260729012951.3744582-7-csander@purestorage.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260729012951.3744582-1-csander@purestorage.com> References: <20260729012951.3744582-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: 8bit ublk_map_io() and ublk_unmap_io() are no-ops for ublk devices that enable user copy or zero copy. However, the implementation is a bit convoluted, returning the full request data length and relying on the caller to check the return value against the request length. UBLK_F_SHMEM_ZC recently added branches to skip the ublk_{,un}map_io() call for I/Os using a shared-memory buffer. This is a more logical place for the need_map check, so move it there from ublk_{,un}map_io(). Checking need_map early also avoids the expensive pointer-chasing for the ublk_iod_is_shmem_zc() check in __ublk_complete_rq() in the common case of a ublk device using user copy or zero copy. Signed-off-by: Caleb Sander Mateos --- drivers/block/ublk_drv.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 1da45e382253..d4443a43229e 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1464,19 +1464,15 @@ static inline bool ublk_need_unmap_req(const struct request *req) { return blk_rq_has_data(req) && (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_DRV_IN); } -static unsigned int ublk_map_io(const struct ublk_queue *ubq, - const struct request *req, +static unsigned int ublk_map_io(const struct request *req, const struct ublk_io *io) { const unsigned int rq_bytes = blk_rq_bytes(req); - if (!ublk_need_map_io(ubq)) - return rq_bytes; - /* * no zero copy, we delay copy WRITE request data into ublksrv * context and the big benefit is that pinning pages in current * context is pretty fast, see ublk_pin_user_pages */ @@ -1488,19 +1484,15 @@ static unsigned int ublk_map_io(const struct ublk_queue *ubq, return ublk_copy_user_pages(req, 0, &iter, dir); } return rq_bytes; } -static unsigned int ublk_unmap_io(bool need_map, - const struct request *req, +static unsigned int ublk_unmap_io(const struct request *req, const struct ublk_io *io) { const unsigned int rq_bytes = blk_rq_bytes(req); - if (!need_map) - return rq_bytes; - if (ublk_need_unmap_req(req)) { struct iov_iter iter; const int dir = ITER_SOURCE; import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter); @@ -1591,15 +1583,16 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE && req_op(req) != REQ_OP_DRV_IN) goto exit; /* shmem zero copy: no data to unmap, pages already shared */ - if (ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag)) + if (!need_map || + ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag)) goto exit; /* for READ request, writing data in iod->addr to rq buffers */ - unmapped_bytes = ublk_unmap_io(need_map, req, io); + unmapped_bytes = ublk_unmap_io(req, io); /* * Extremely impossible since we got data filled in just before * * Re-read simply for this unlikely case. @@ -1755,14 +1748,14 @@ static bool ublk_start_io(const struct ublk_queue *ubq, struct request *req, struct ublk_io *io) { unsigned mapped_bytes; /* shmem zero copy: skip data copy, pages already shared */ - if (ublk_iod_is_shmem_zc(ubq, req->tag)) + if (!ublk_need_map_io(ubq) || ublk_iod_is_shmem_zc(ubq, req->tag)) return true; - mapped_bytes = ublk_map_io(ubq, req, io); + mapped_bytes = ublk_map_io(req, io); /* partially mapped, update io descriptor */ if (unlikely(mapped_bytes != blk_rq_bytes(req))) { /* * Nothing mapped, retry until we succeed. -- 2.54.0