From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 0B6B23EB7F8 for ; Mon, 18 May 2026 10:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779100207; cv=none; b=EHY/Wd/WfZH7lH6bTQ1F/dx7I2P9xhqCSn68DQHQ6Y4fCHJlVUJ3qFf34t7KfmGQbu+eiO32i5opnZ52aG+bdIYG5IGLMRnG7Y89BbeSUEQvKPGFhNBwvlsST4EbpVNUQir4IofZr3leX+dwF3r/8COed3qzwc1UG5CMSXi3+24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779100207; c=relaxed/simple; bh=FbvAJUBaJSoNOddpm6KcOlO9qRGB7h6zbd7g73ujdLc=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=BKSIC16KYoBRVo1bM4qudANmR14zLyPtqBr9R0NL/lblZeDqyJqm/ims756U+173bZxA8jKopp3/mS+9k/lOHwvyoVeEmLSlwgzYmoOt7DIglwzgAL1zqQ7tMCLcK9Qz5BMxAJvverLc1/Mf9wS3tcvGtOu9bsBE/7Tl6EbuK6Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AJQ4iM0Y; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AJQ4iM0Y" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-43eb05b1875so1060796f8f.3 for ; Mon, 18 May 2026 03:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779100196; x=1779704996; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=yBM/MqSlhfscJgewJTDJnR/WZOfF3ZaH9qUvK+mYr0I=; b=AJQ4iM0Y3atulw0PqPF8op4PRnWpRVYOty/GNjhKqmtpas6RAxpBy+PRn9KMn1Wno2 qjZPw+EhhE0hOFeMi5Jmm2umUnXHc9uHE6Sc4jCIy8Ms4gDmWbAja3yDgp1f0sakvIzo mND0MAlV95AGumFfzHSvL6fn/HmzZMpLelmMNL/OqSMvfJdhoE33lGksAXwRGKhpz9y3 MUxmm5rukKAQCGvtg3KEsHI7vG7ayeRK0NXm2lTRYxEUjs5WhyITg3Gsh7qemErQcLpo H/MeM/3buitXkpHJfEHCNh+4Lx9a+L/jbz0S914lIrMYWChf5levhxDB0NWAD/C8QyT9 dHrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779100196; x=1779704996; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yBM/MqSlhfscJgewJTDJnR/WZOfF3ZaH9qUvK+mYr0I=; b=CAfrPhmRTwKdtqvyOLAi1W0OPByb+qlezfEpAx7n52zKekYRq7IyJOKRgvXjaYil7Q MHJBo/ldMkCgSuAI7WPTdCVuXsriOW1ff3c/FcqO5RzV5KD6YNe1InoCoydIc+f+z2jk Vgn95ChF0aHqkxqAyy6wTTPQBxKhJPDayMtxFoDF2PW2a6lQAcGhhqnku7HTsJaRhsCY nRtquQezb1OLwVxAdWvM+c3HCc5eIwMivzi79N5uklVS/TOJIeek7efF+Sa7UNHzWX/z qxHZ8Y2+zGOaNoTPLjr+JsIZC6n+dsfJKDxv6Dyprz38knYhycZrj47iBFEQBJ23jEv2 wgsw== X-Forwarded-Encrypted: i=1; AFNElJ87Hdi8wZ0eMYlZQn6Quy+LQRr4dyTtDIhnOxTYNVHEEJaC/LCDMN2yyjPX37dAYmhw8q5EFtiA4kh528o=@vger.kernel.org X-Gm-Message-State: AOJu0YyRRQNOjCQbraInOklrJJqJJgrJh1cnTsyIZbOYvXI8wEEfhKAJ V4k1zDpWMWUqsxaK6DQ0aENI+G9xyNKJYJUastxzYXmpXA3oNMv6qkw51pJ6KQ== X-Gm-Gg: Acq92OFLB7JFHSX0TSOr0j3b+BarNXQJlVGRKc1oBlAy9H9nJsD6ijashGmIubWuU5g 0Kl7XgKxlK9B2TkdyzkPvUIRAum2opa+hahxhfecFIoMp4bvjUBT30v5ecPutgUvwHfqTkCEjeR qmxHJhDBcXoeCymwOEHtgiIL14/cexbEV0GJWUqTBq3iKNLAmG2Cvxvj5MM1DSpwyH9HwMSKUWg t7iw/gJmUw0dcCAiqzkM8u/5VCFNOTt9HPFfcSXObqLj8wo6KVVx8NVL3dWx2iNJFndJ9b4Yh9W RyoUf4I0+SPthpbM240622eKtgRlYclc1kVZPmjroNVXphm6PK3JHnOefxIp/a2rEA416tcMAbD 6fShFT6SyFrvazTljKoBO0ckp3MprXL29FC+Xvwt+us+Z9Cd4OzAhKUN8iKIO7GhR/DKTlQVZVa HLmHfrPziPSWlq1sYCGLBbo/G/jCXmRC3VWadQQn4Rg+Vj4pngi0+w3YdIJ0mmR+9o6n+CW1oWy PsQD10q+kPIaSSbky20QK9+10CVrZ41g7UYVDLlcY/9bsgaJ1rZcrtHyTs= X-Received: by 2002:a5d:5885:0:b0:43c:f7e5:817b with SMTP id ffacd0b85a97d-45e5c5cc2b5mr22613508f8f.19.1779100196106; Mon, 18 May 2026 03:29:56 -0700 (PDT) Received: from ?IPV6:2620:10d:c096:325:77fd:1068:74c8:af87? ([2620:10d:c092:600::1:ec20]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da15a6454sm36537426f8f.34.2026.05.18.03.29.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 May 2026 03:29:55 -0700 (PDT) Message-ID: <24833f76-2289-4859-86d1-9215b11a1258@gmail.com> Date: Mon, 18 May 2026 11:29:54 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Pavel Begunkov Subject: Re: [PATCH v3 04/10] block: introduce dma map backed bio type To: Christoph Hellwig Cc: Jens Axboe , Keith Busch , Sagi Grimberg , Alexander Viro , Christian Brauner , Andrew Morton , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Nitesh Shetty , Kanchan Joshi , Anuj Gupta , Tushar Gohad , William Power , Phil Cayton , Jason Gunthorpe References: <646ecd6fde8d9e146cb051efb514deb27ce3883e.1777475843.git.asml.silence@gmail.com> <20260513081929.GD5477@lst.de> Content-Language: en-US In-Reply-To: <20260513081929.GD5477@lst.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/13/26 09:19, Christoph Hellwig wrote: >> + if (!bio_flagged(bio_src, BIO_DMABUF_MAP)) { >> + bio->bi_io_vec = bio_src->bi_io_vec; >> + } else { >> + bio->dmabuf_map = bio_src->dmabuf_map; >> + bio_set_flag(bio, BIO_DMABUF_MAP); >> + } > > This is backwards, please avoid pointless negations: I can flip it, but compilers tend to prefer the true branch. E.g. this if (cond) A; else B; C; can get compiled into: jmpcc cond B A: ... C: return; B: ... jmp C; > > if (bio_flagged(bio_src, BIO_DMABUF_MAP)) { > bio->dmabuf_map = bio_src->dmabuf_map; > bio_set_flag(bio, BIO_DMABUF_MAP); > } else { > bio->bi_io_vec = bio_src->bi_io_vec; > } > >> + if (bio_flagged(bio, BIO_DMABUF_MAP)) { >> + nsegs = 1; >> + >> + if ((bio->bi_iter.bi_bvec_done & lim->dma_alignment) || >> + (bio->bi_iter.bi_size & len_align_mask)) >> + return -EINVAL; >> + if (bio->bi_iter.bi_size > max_bytes) { >> + bytes = max_bytes; >> + goto split; >> + } > > Please add a comment explaining why nsegs is always 1 here. > >> @@ -424,7 +424,8 @@ static inline struct bio *__bio_split_to_limits(struct bio *bio, >> switch (bio_op(bio)) { >> case REQ_OP_READ: >> case REQ_OP_WRITE: >> - if (bio_may_need_split(bio, lim)) >> + if (bio_may_need_split(bio, lim) || >> + bio_flagged(bio, BIO_DMABUF_MAP)) >> return bio_split_rw(bio, lim, nr_segs); > > The BIO_DMABUF_MAP check should go into bio_may_need_split. Ok >> +static inline void bio_advance_iter_dmabuf_map(struct bvec_iter *iter, >> + unsigned int bytes) >> +{ >> + iter->bi_bvec_done += bytes; >> + iter->bi_size -= bytes; >> +} >> + >> static inline void bio_advance_iter(const struct bio *bio, >> struct bvec_iter *iter, unsigned int bytes) >> { >> iter->bi_sector += bytes >> 9; >> >> - if (bio_no_advance_iter(bio)) >> + if (bio_no_advance_iter(bio)) { >> iter->bi_size -= bytes; >> - else >> + } else if (bio_flagged(bio, BIO_DMABUF_MAP)) { >> + bio_advance_iter_dmabuf_map(iter, bytes); > > This is a bit of a mess. You're using bi_bvec_done for something that > is not bvec_done, which makes the naming very confusing. That is even > more confusing than the existing usage, which isn't great. Also we > add yet another conditional to heavily inlined code. I'd suggest > the following: > > - add a prep patch to rename bi_bvec_done to bi_offset, as even for > the existing usage it is the offset into the current bio_vec as > much as it is the count of byes done, as those must be the same > and it is used both ways > - add a prep patch to also increase bi_offset for bio_no_advance_iter. > It is not actually use there, but incrementing it is harmless and > this will avoid a new special case > - please also documet this new usage in the commet in struct bvec_iter. > - then just add the dma buf mapping to the bio_no_advance_iter condition I'll take a look > - figure out what to do about dm_bio_rewind_iter, which pokes into these > things that really should be block layer internal Need to check what that is, but doesn't implement the interface and is not supposed to ever see the dmabuf iterator. >> } >> @@ -391,7 +403,7 @@ static inline void bio_wouldblock_error(struct bio *bio) >> */ >> static inline int bio_iov_vecs_to_alloc(struct iov_iter *iter, int max_segs) >> { >> - if (iov_iter_is_bvec(iter)) >> + if (iov_iter_is_bvec(iter) || iov_iter_is_dmabuf_map(iter)) >> return 0; >> return iov_iter_npages(iter, max_segs); >> } > > Please update the comment for this helper. > >> @@ -322,6 +327,7 @@ enum { >> BIO_REMAPPED, >> BIO_ZONE_WRITE_PLUGGING, /* bio handled through zone write plugging */ >> BIO_EMULATES_ZONE_APPEND, /* bio emulates a zone append operation */ >> + BIO_DMABUF_MAP, /* Using premmaped dma buffers */ > > Shouldn't this be a REQ_ flag as we should never mix and match bios with > and without this flag in a single request? Do you mean adding both and propagating it from bio to req? submit_bio() takes a bio, so we still need to set it there before it reaches blk-mq. And there might be bio-based drivers using it in the future. -- Pavel Begunkov