summaryrefslogtreecommitdiffstats
path: root/fs/ntfs/bdev-io.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2026-09-14 22:12:34 -1000
committerTejun Heo <tj@kernel.org>2026-09-15 06:57:20 -1000
commita9e3760b0838299649c0d57cca44daaf40ba3c33 (patch)
tree95807ff0e511c05602ef34808cfc660303309057 /fs/ntfs/bdev-io.c
downloadlinux-stable-a9e3760b0838299649c0d57cca44daaf40ba3c33.tar.gz
linux-stable-a9e3760b0838299649c0d57cca44daaf40ba3c33.zip
sched_ext: Maintain an online cid mask in the scheduler arenagrafted
Schedulers on the default cid mapping treat [0, nr_online_cids) as the online set and restart on hotplug. Schedulers that install their own mapping with scx_bpf_cid_override() have no way to learn which cids are online: the count no longer identifies members and the CPU-form cpumask is unusable from cid programs. This is an obvious hole in the cid API. Add scx_bpf_online_cmask(), a kernel-maintained cmask in the scheduler's arena, allocated alongside the per-CPU scratch masks and populated after the cid mapping is finalized and before ops.init(), for child schedulers too. The pointer stays valid through ops.exit() with no reference to take. It is the arena offset as a void pointer, the same form struct_ops arena arguments arrive in. The verifier types the void return as a scalar for the program's arena cast. The mask follows the SCX hotplug notifications: seeded from cpu_active_mask and updated before ops.cid_online/offline() runs, so it lags cpu_online_mask only inside a hotplug transition. Updates walk the scheduler list under the lock that also serializes unlinking. Reads are live, not atomic snapshots. Root initialization excludes hotplug. v2: Reworded the getter kerneldoc (Andrea Righi). Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Andrea Righi <arighi@nvidia.com>
Diffstat (limited to 'fs/ntfs/bdev-io.c')
-rw-r--r--fs/ntfs/bdev-io.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/fs/ntfs/bdev-io.c b/fs/ntfs/bdev-io.c
new file mode 100644
index 000000000..27d7c2767
--- /dev/null
+++ b/fs/ntfs/bdev-io.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * NTFS block device I/O.
+ *
+ * Copyright (c) 2026 LG Electronics Co., Ltd.
+ */
+
+#include <linux/blkdev.h>
+
+#include "ntfs.h"
+
+/*
+ * ntfs_bdev_read - Read data directly from block device using bio
+ * @bdev: block device to read from
+ * @data: destination buffer
+ * @start: starting byte offset on the block device
+ * @size: number of bytes to read
+ *
+ * Reads @size bytes starting from byte offset @start directly from the block
+ * device using one or more BIOs. This function bypasses the page cache
+ * completely and performs synchronous I/O with REQ_META | REQ_SYNC flags set.
+ *
+ * The @start offset must be sector-aligned (512 bytes). If it is not aligned,
+ * the function will return -EINVAL.
+ *
+ * If the destination buffer @data is not a vmalloc address, it falls back
+ * to the more efficient bdev_rw_virt() helper.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int ntfs_bdev_read(struct block_device *bdev, char *data, loff_t start, size_t size)
+{
+ unsigned int done = 0, added;
+ int error;
+ struct bio *bio;
+ enum req_op op;
+ sector_t sector = start >> SECTOR_SHIFT;
+
+ if (start & (SECTOR_SIZE - 1))
+ return -EINVAL;
+
+ op = REQ_OP_READ | REQ_META | REQ_SYNC;
+ if (!is_vmalloc_addr(data))
+ return bdev_rw_virt(bdev, sector, data, size, op);
+
+ bio = bio_alloc(bdev,
+ bio_max_segs(DIV_ROUND_UP(size, PAGE_SIZE)),
+ op, GFP_KERNEL);
+ bio->bi_iter.bi_sector = sector;
+
+ do {
+ added = bio_add_vmalloc_chunk(bio, data + done, size - done);
+ if (!added) {
+ struct bio *prev = bio;
+
+ bio = bio_alloc(prev->bi_bdev,
+ bio_max_segs(DIV_ROUND_UP(size - done, PAGE_SIZE)),
+ prev->bi_opf, GFP_KERNEL);
+ bio->bi_iter.bi_sector = bio_end_sector(prev);
+ bio_chain(prev, bio);
+ submit_bio(prev);
+ }
+ done += added;
+ } while (done < size);
+
+ error = submit_bio_wait(bio);
+ bio_put(bio);
+
+ if (op == REQ_OP_READ)
+ invalidate_kernel_vmap_range(data, size);
+ return error;
+}
+
+/*
+ * ntfs_bdev_write - Update block device contents via page cache
+ * @sb: super block of the mounted NTFS filesystem
+ * @buf: source buffer containing data to write
+ * @start: starting byte offset on the block device
+ * @size: number of bytes to write
+ *
+ * Writes @size bytes from @buf to the block device (sb->s_bdev) starting
+ * at byte offset @start. The write is performed entirely through the page
+ * cache of the block device's address space.
+ */
+int ntfs_bdev_write(struct super_block *sb, void *buf, loff_t start, size_t size)
+{
+ pgoff_t idx, idx_end;
+ loff_t offset, end = start + size;
+ u32 from, to, buf_off = 0;
+ struct folio *folio;
+
+ idx = start >> PAGE_SHIFT;
+ idx_end = end >> PAGE_SHIFT;
+ from = start & ~PAGE_MASK;
+
+ if (idx == idx_end)
+ idx_end++;
+
+ for (; idx < idx_end; idx++, from = 0) {
+ u32 len;
+
+ folio = read_mapping_folio(sb->s_bdev->bd_mapping, idx, NULL);
+ if (IS_ERR(folio)) {
+ ntfs_error(sb, "Unable to read %ld page", idx);
+ return PTR_ERR(folio);
+ }
+
+ offset = (loff_t)idx << PAGE_SHIFT;
+ to = min_t(u32, end - offset, PAGE_SIZE);
+ len = to - from;
+
+ memcpy_to_folio(folio, from, buf + buf_off, len);
+ buf_off += len;
+ folio_mark_uptodate(folio);
+ folio_mark_dirty(folio);
+ folio_put(folio);
+ }
+
+ return 0;
+}