From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 2559B2AD2E for ; Sat, 1 Aug 2026 15:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785599383; cv=none; b=c7TTOGc50jBidBHmBCt/cbMXr98JpfsTkHNWRxSMoOY/3qIjaN0lmhjs15PClHatsy9ngSlWd434SSM+ezd9ZGISZtJ8nG7RPW32l5MGhXNlVWTzhHOpNvQt2FzK6e4CbWZDGlvjx84x5o/3Kkr1RSWQWdGJYIB67XWnn11TAVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785599383; c=relaxed/simple; bh=g0r+cM2oJU8p0aW6ejF1reDF155X4adWxCLLoLHu2uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CDeiCOIfXbuxJi9Uz5Pa1kuKX7cXLfME4VjaRPYnu32mQNGXnH/Ko3e5VWBz9eGq+LDTzQUtKE6C/vp7Rmbm3l08EC6jnuiqzGVTLJouI5yqPqE8z1gOpNrS6CLjJi4sVuhmObdELQsID6QtTJbvlEM1n91pItWs7hYSr++5e+c= 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=Phykw574; arc=none smtp.client-ip=209.85.214.178 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="Phykw574" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2d01663d816so15299835ad.1 for ; Sat, 01 Aug 2026 08:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785599381; x=1786204181; 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=XTGwQGVc0bqlcGV09Qbia8ah/Xj1ofLPkaifBOkmHiQ=; b=Phykw574YQXrFOsxNwwUAuKFs97gDWG/x7biAdTYNgmBmxuHcAoz8mYAokHEBqiEQ9 CDk8ydDMzaSdwlmktajb3Js/dgO6pOjiVb6rCrJLLWnPvQn530GyjGo6bWqXfns7sy4K SIy/ncATqOp1kmsB2cpn5bZkIeJSu4/+fMz8JBCr14qSRz6S3a+i/XXknL3WLz2ogeuq Jn/br9Op2rMlMvzLg1TZrj+S0mngigDj2OLcKfYHeC1vXPy1i71TBGDL79FWylg/yU18 BJbtBRhV0oU2RC94desVnsFnNHzKwbyH9k8khD3hojHwuF+4pN1bcRiM4NVhrw8s9piA 6Jpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785599381; x=1786204181; 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=XTGwQGVc0bqlcGV09Qbia8ah/Xj1ofLPkaifBOkmHiQ=; b=WN5aAoniRCFSS9l4VAIwU059YTkXabSMaJsMtWYfwTL0ztzfIjos+5JibaXZDssa+g 9XC+5zwTQpazb+9GsLmoCwN5KLgVvwv6o6k40CInplX+L8J3Ocv9hUsJiL9trzp1kn/V tiP9Ro2yDlUYunUcStTUQRYXm/Mvf2rB7MgbdemgOTHucS+zdX49Lezd/rr2ckSOeYV5 DMy/y0WUFs468lMYtMNvDhzAirGE/5FUUGGE3LoXzyYfthCD38NHAKB5dfUUroQNPF1Z lv9XxnwckgZvqy7KLUxrhIPh4u9qwHTMQhq5mf39wrUwSP92R6a3O3XkjfWfdUDjLIX1 aAqg== X-Forwarded-Encrypted: i=1; AHgh+RpScyNOJ77PeYOtU9aZzbGWIWMrNVMY/yLfsRDIN0RIDeDY2ujjrmgQIUbWcFIrtakavz3bc9ovHg==@vger.kernel.org X-Gm-Message-State: AOJu0YzXZAh3I7LMI+9pBtVHuyVjic4B+HHkNHZdSATdg0HgYvj0ps7q yVE8o82PP/Z8NgU1Pj2iUUl6dCcBWCB8lqEkuCpVrCQotFZcrxjzCo+C X-Gm-Gg: AR+sD1000+x7Twye9pxZPPwNw8wcSyToBUgzuMI0ASt6NLxSy8h1CmKZR/g6TBsrYfS nmcC/cSMGYiV2bXbEPkr23Z1567HbvdbWSLr+UddHTQXRdyvW0E/2PRT0NyVuLKAj4+kTyxp0gm +wKW8xj2IATLVys6sMAqXZVJiaoT+Vb7gGzVIDPZHVCnnRSaYpGijdQm7Jh3WiNmw/QFJpXZ29E uUdTUpnjjpzpbSgwfELNFZCPdvao9fdGPFYFqVCy9C0blLcSsOWpYGKRq+9LDU+Ckad6nqEuJo8 brHtrzLqqhgvNGEiLAsB6whHLooIjuNP8VYNtTEr+qu8wQDRcsR3g3YMJOCCNO0pjQQemNtas7c DI/XMBfHVQR472igzSwoZhU1FgYsclrmwRsH+bdSwhUI9Hc2VfA+VaxWGGZkH9Vgl0xsCS2i2Z/ ipzXbdupOO6a6JosKoFGlpj7t21X5Tt36CviudqmKfXgkCC19fkidy9CJrUOa/FYhEUrnHM4vyh mLNvaAHDZ+MKjkqG7X/4xX1KYle1oodIkdG5QeWPimfIs4= X-Received: by 2002:a17:903:2450:b0:2cf:9347:f445 with SMTP id d9443c01a7336-2d05219f5c9mr36286255ad.10.1785599381195; Sat, 01 Aug 2026 08:49:41 -0700 (PDT) Received: from 127.net ([2620:10d:c092:600::1:61d0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d04b12202bsm18287605ad.66.2026.08.01.08.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 08:49:40 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , Keith Busch , Christoph Hellwig , Sagi Grimberg , 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 Cc: asml.silence@gmail.com, Alexander Viro , Christian Brauner , Andrew Morton , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Nitesh Shetty , Kanchan Joshi , Anuj Gupta , Tushar Gohad , William Power , Phil Cayton , Jason Gunthorpe , Damien Le Moal , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski , Vishal Verma , David Sterba , Ilya Dryomov , dm-devel@lists.linux.dev, nvdimm@lists.linux.dev, linux-btrfs@vger.kernel.org, ceph-devel@vger.kernel.org Subject: [PATCH v5 08/16] block: add dma-buf support for raw bdev Date: Sat, 1 Aug 2026 16:46:20 +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 | 19 +++++++++++++++++++ include/linux/blkdev.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/block/fops.c b/block/fops.c index 56bbacf6e317..3c403afb0f64 100644 --- a/block/fops.c +++ b/block/fops.c @@ -767,6 +767,9 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) ret = direct_write_fallback(iocb, from, ret, blkdev_buffered_write(iocb, from)); } 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 @@ -821,6 +824,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 @@ -924,6 +929,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 -EINVAL; + return disk->fops->init_dma_buf_io_ctx(bdev, ctx); +} + const struct file_operations def_blk_fops = { .open = blkdev_open, .release = blkdev_release, @@ -942,6 +960,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 9213a5716f95..9f4c92e51dc9 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1682,6 +1682,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