From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (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 BD7DC4A0924 for ; Mon, 21 Sep 2026 13:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789997981; cv=none; b=uTlE7Y9UDpy5lSLaEDq0qkCxsStis6d306WNLw2k6j3BITP24I4fT5LkNneH+cK2R375QeWVR10us2fAj68Eblj4Id4wkzumPQ3rZLoye1fnI9bGXK/UdFFO0hfwl7UJttF96//M8gXjimLZTkrOMCTVGnqSR7ofUMyvqFGTObY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789997981; c=relaxed/simple; bh=4botMd0JRxgaa+oDvZMUZvvmXYyk4mBy6faGFHabX+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=embdUTtFRC6FHW1euFfGshcw13DiVwST/Jzv0qAESo9SrtLNn3VYKlteeBvJDVINRuCWS49EzWX9ip1GuSotRRSYNTPenrzYiv/rYkHw4JqJ8cnTftcyIt/pchQCD9a1WWPEqDdwD2S2RiBqckkd4GTDX8mZIKqqFDXeTGtfoPE= 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=AvtWke4Q; arc=none smtp.client-ip=74.125.225.141 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="AvtWke4Q" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49e721b5503so29858255e9.0 for ; Mon, 21 Sep 2026 06:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789997977; x=1790602777; 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=LfiQtDTMXplRc+HRsAYVyvIssf+oWzUZ0qqIFwpPEw8=; b=AvtWke4QL/CX8yeQjGnGXUT6cnsoMNLqIBwXjteSRY5/9bQPHev7G54OANcwmJx1AB 4nGDMQSYF0qcecwqD6CnHNlluEYCkX0XRx6/pnrXiOcrmNBO+M0k2I5cNYMDZcCBHJ29 hTW4MhkrM9St39NWbtNbza7M+MEZnHfoPgqfYT6l8jZzY+4mcFfeWBkkkds+ZC+aqbR6 zGIAWHsrL/7dgqZoMOZtCRKDerTwe4+VAbavp/NrQvl32oeo5K2Xxq2S+ULOS6S/92Mb ajEM+77gXhDuQOD3ol75VXsDZd+oaIslcCtSVxKcguq3mA1FMVlWvVCHuY3BeAZyaDBo z5mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789997977; x=1790602777; 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=LfiQtDTMXplRc+HRsAYVyvIssf+oWzUZ0qqIFwpPEw8=; b=nkvOzkZLyTsUHHi6NW47N5TL6STqkBCND4sDrkjkRZoUyg+aP6Dmh0zgDY00hD87yT ngKz2w4/RVTOL+3VcmuvARQ2I0uTKAbm3oz7HLtP+dcpb7NYGa79x4FgCntbiRTJgmHh bY2kwbAfn+ZK+AKz5MbAtpBaLdBrpR+j9FgEZjVLcRZOVOhSZlJlfSZ9esVZPQnrfCl3 MYZeNAHJT2D9NBKyzn9JAE/QvLSISJifYHNZRrCchKioUTG2GExi2NG7TfLN3cHVWett BmfxYZfn8F5iMOGnruDJ9uALH4WtQVb6SVV32VTQyOinf2Xxqb2y2Ol6+wlppGz2DUJv t7bw== X-Forwarded-Encrypted: i=1; AKwUvBwEQUEjjIj98SVqOlmH03gMR9fcDOxZop/maFaKiAwcP3iaP7Ia4NvsZc+k1hNi245G5HxsX//e2g==@vger.kernel.org X-Gm-Message-State: AFuF++lMggnUiLIqg78mNbewTGJm/xQ+D1i2Y7+9Rb5BIN81+PhFuOVG XtxAt0qZc/8pzj1UbrsgSLrWFyrlAke/gO3suU/AM1Yw/bifltKPvKOv X-Gm-Gg: AYBFou2IuD8n3cf27YY1i9LrK926QrS/ysH1QVFrXhw/7HW/552YmlDya/+A2S4nRpl i1SzLWeN77kkskrh8GpcxYo23GJn3KFwbOdAZO2tPYhZ4WFU+zLtBIO1UsptKCJZdPxAEDSXpK1 hkt9O3WrveRCoCdaRoe6OprG40yfbpt3vsh3ekSF4PPgUN9iJ38CcQiTc/cJDpHbM2wakNdHMci lqM4ImQPua2/6Ki+oLPv1iExyQUjxwNyg8MCy8rVMEthADrs5RYBvS+B2bpYvdo8wV3RbIX/Ye+ LYByL1YGlp952FbyFoVYgmtT/eqcP4iF0lJRQjf1CxiySCrujLpmHPZEfkbUmgyfaI8bGj/CaLf k8Yh5g8g29HDTDH797j+YpQFZzpT4J7dJ/q6r9Adh5HvcHo0r4FoanY5Swi/IeX7A3GcUIGmqm4 XYrJYXrL2dY9djs47w61zxDsg9R8iLEdoAjyvoTSdjSCbiDAaSap6HXZgeAhCPHDYkYLAbG5qDc NOgHQZzE0sKcEUfqhSwz2V4OKM4bZMGnpzPm5SiK36yVDDrV/dII3oFN1dMZrW4VSYUtBvNbFw1 3Udl5lYeBn7F+6CSn/Nz8in1lKVPsPVI5y95wIsM X-Received: by 2002:a05:600c:c493:b0:49e:74b6:740f with SMTP id 5b1f17b1804b1-49fc573603amr145209165e9.17.1789997977065; Mon, 21 Sep 2026 06:39:37 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-213-26.dab.02.net. [82.132.213.26]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc585920fsm617171605e9.4.2026.09.21.06.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2026 06:39:35 -0700 (PDT) From: Pavel Begunkov To: linux-block@vger.kernel.org Cc: asml.silence@gmail.com, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Christoph Hellwig , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Keith Busch , Sagi Grimberg , Alexander Viro , Christian Brauner , Jan Kara , Andrew Morton , Jens Axboe , Nitesh Shetty , Kanchan Joshi , Anuj Gupta , Tushar Gohad , William Power , Phil Cayton , Matthew Brost , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski , dm-devel@lists.linux.dev Subject: [PATCH v6 05/13] block: add dma-buf support for raw bdev Date: Mon, 21 Sep 2026 14:38:49 +0100 Message-ID: X-Mailer: git-send-email 2.54.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a simple proxy implementation of init_dma_buf_io_ctx() forwarding the call to a new struct block_device_operations operation. Also reject dma-buf backed iterators for buffered IO. Reviewed-by: Christoph Hellwig [pavel: reject dma-buf without O_DIRECT] Signed-off-by: Pavel Begunkov --- block/fops.c | 22 +++++++++++++++++++++- include/linux/blkdev.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index 09fa42f8d8fa..0252d26969a4 100644 --- a/block/fops.c +++ b/block/fops.c @@ -782,7 +782,8 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_flags & IOCB_DIRECT) { ret = blkdev_direct_write(iocb, from); - if (ret >= 0 && iov_iter_count(from)) { + if (ret >= 0 && iov_iter_count(from) && + !iov_iter_is_dmabuf_map(from)) { ret = direct_write_fallback(iocb, from, ret, blkdev_buffered_write(iocb, from)); need_sync = true; @@ -795,6 +796,9 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) need_sync = true; } } else { + if (unlikely(iov_iter_is_dmabuf_map(from))) + return -EOPNOTSUPP; + /* * Take i_rwsem and invalidate_lock to avoid racing with * set_blocksize changing i_blkbits/folio order and punching @@ -850,6 +854,8 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) if (ret < 0 || !count) goto reexpand; } + if (unlikely(iov_iter_is_dmabuf_map(to))) + return -EOPNOTSUPP; /* * Take i_rwsem and invalidate_lock to avoid racing with set_blocksize @@ -953,6 +959,19 @@ static int blkdev_mmap_prepare(struct vm_area_desc *desc) return generic_file_mmap_prepare(desc); } +static int blkdev_init_dma_buf_io_ctx(struct file *file, + struct dma_buf_io_ctx *ctx) +{ + struct block_device *bdev = file_bdev(file); + struct gendisk *disk = bdev->bd_disk; + + if (!(file->f_flags & O_DIRECT)) + return -EINVAL; + if (!disk->fops->init_dma_buf_io_ctx) + return -EOPNOTSUPP; + return disk->fops->init_dma_buf_io_ctx(bdev, ctx); +} + const struct file_operations def_blk_fops = { .open = blkdev_open, .release = blkdev_release, @@ -971,6 +990,7 @@ const struct file_operations def_blk_fops = { .fallocate = blkdev_fallocate, .uring_cmd = blkdev_uring_cmd, .fop_flags = FOP_BUFFER_RASYNC | FOP_DONTCACHE, + .init_dma_buf_io_ctx = blkdev_init_dma_buf_io_ctx, }; static __init int blkdev_init(void) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d003a9d2d1f6..2d5c30823aab 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1599,6 +1599,8 @@ struct block_device_operations { /* returns the length of the identifier or a negative errno: */ int (*get_unique_id)(struct gendisk *disk, u8 id[16], enum blk_unique_id id_type); + int (*init_dma_buf_io_ctx)(struct block_device *, + struct dma_buf_io_ctx *); struct module *owner; const struct pr_ops *pr_ops; -- 2.54.0