forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/block/brd.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Ram backed block device driver.
34 *
....@@ -153,6 +154,12 @@
153154 pos++;
154155
155156 /*
157
+ * It takes 3.4 seconds to remove 80GiB ramdisk.
158
+ * So, we need cond_resched to avoid stalling the CPU.
159
+ */
160
+ cond_resched();
161
+
162
+ /*
156163 * This assumes radix_tree_gang_lookup always returns as
157164 * many pages as possible. If the radix-tree code changes,
158165 * so will this have to.
....@@ -275,7 +282,7 @@
275282 return err;
276283 }
277284
278
-static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
285
+static blk_qc_t brd_submit_bio(struct bio *bio)
279286 {
280287 struct brd_device *brd = bio->bi_disk->private_data;
281288 struct bio_vec bvec;
....@@ -289,6 +296,10 @@
289296 bio_for_each_segment(bvec, bio, iter) {
290297 unsigned int len = bvec.bv_len;
291298 int err;
299
+
300
+ /* Don't support un-aligned buffer */
301
+ WARN_ON_ONCE((bvec.bv_offset & (SECTOR_SIZE - 1)) ||
302
+ (len & (SECTOR_SIZE - 1)));
292303
293304 err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset,
294305 bio_op(bio), sector);
....@@ -319,6 +330,7 @@
319330
320331 static const struct block_device_operations brd_fops = {
321332 .owner = THIS_MODULE,
333
+ .submit_bio = brd_submit_bio,
322334 .rw_page = brd_rw_page,
323335 };
324336
....@@ -370,12 +382,9 @@
370382 spin_lock_init(&brd->brd_lock);
371383 INIT_RADIX_TREE(&brd->brd_pages, GFP_ATOMIC);
372384
373
- brd->brd_queue = blk_alloc_queue(GFP_KERNEL);
385
+ brd->brd_queue = blk_alloc_queue(NUMA_NO_NODE);
374386 if (!brd->brd_queue)
375387 goto out_free_dev;
376
-
377
- blk_queue_make_request(brd->brd_queue, brd_make_request);
378
- blk_queue_max_hw_sectors(brd->brd_queue, 1024);
379388
380389 /* This is so fdisk will align partitions on 4k, because of
381390 * direct_access API needing 4k alignment, returning a PFN
....@@ -394,7 +403,6 @@
394403 disk->flags = GENHD_FL_EXT_DEVT;
395404 sprintf(disk->disk_name, "ram%d", i);
396405 set_capacity(disk, rd_size * 2);
397
- brd->brd_queue->backing_dev_info->capabilities |= BDI_CAP_SYNCHRONOUS_IO;
398406
399407 /* Tell the block layer that this is not a rotational device */
400408 blk_queue_flag_set(QUEUE_FLAG_NONROT, brd->brd_queue);