License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-04-08 12:00:32 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/ext4/readpage.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, Linus Torvalds.
|
|
|
|
* Copyright (C) 2015, Google, Inc.
|
|
|
|
*
|
|
|
|
* This was originally taken from fs/mpage.c
|
|
|
|
*
|
2020-06-02 12:47:16 +08:00
|
|
|
* The ext4_mpage_readpages() function here is intended to
|
|
|
|
* replace mpage_readahead() in the general case, not just for
|
2015-04-08 12:00:32 +08:00
|
|
|
* encrypted files. It has some limitations (see below), where it
|
|
|
|
* will fall back to read_block_full_page(), but these limitations
|
|
|
|
* should only be hit when page_size != block_size.
|
|
|
|
*
|
|
|
|
* This will allow us to attach a callback function to support ext4
|
|
|
|
* encryption.
|
|
|
|
*
|
|
|
|
* If anything unusual happens, such as:
|
|
|
|
*
|
|
|
|
* - encountering a page which has buffers
|
|
|
|
* - encountering a page which has a non-hole after a hole
|
|
|
|
* - encountering a page with non-contiguous blocks
|
|
|
|
*
|
|
|
|
* then this code just gives up and calls the buffer_head-based read function.
|
|
|
|
* It does handle a page which has holes at the end - that is a common case:
|
2016-04-01 20:29:48 +08:00
|
|
|
* the end-of-file on blocksize < PAGE_SIZE setups.
|
2015-04-08 12:00:32 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/kdev_t.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/prefetch.h>
|
|
|
|
#include <linux/mpage.h>
|
|
|
|
#include <linux/writeback.h>
|
|
|
|
#include <linux/backing-dev.h>
|
|
|
|
#include <linux/pagevec.h>
|
|
|
|
|
|
|
|
#include "ext4.h"
|
|
|
|
|
2019-07-23 00:26:24 +08:00
|
|
|
#define NUM_PREALLOC_POST_READ_CTXS 128
|
|
|
|
|
|
|
|
static struct kmem_cache *bio_post_read_ctx_cache;
|
|
|
|
static mempool_t *bio_post_read_ctx_pool;
|
|
|
|
|
|
|
|
/* postprocessing steps for read bios */
|
|
|
|
enum bio_post_read_step {
|
|
|
|
STEP_INITIAL = 0,
|
|
|
|
STEP_DECRYPT,
|
|
|
|
STEP_VERITY,
|
2020-01-01 02:12:22 +08:00
|
|
|
STEP_MAX,
|
2019-07-23 00:26:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bio_post_read_ctx {
|
|
|
|
struct bio *bio;
|
|
|
|
struct work_struct work;
|
|
|
|
unsigned int cur_step;
|
|
|
|
unsigned int enabled_steps;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __read_end_io(struct bio *bio)
|
2015-04-12 12:56:10 +08:00
|
|
|
{
|
2023-03-25 02:01:26 +08:00
|
|
|
struct folio_iter fi;
|
2019-07-23 00:26:24 +08:00
|
|
|
|
2023-10-05 00:53:04 +08:00
|
|
|
bio_for_each_folio_all(fi, bio)
|
|
|
|
folio_end_read(fi.folio, bio->bi_status == 0);
|
2019-07-23 00:26:24 +08:00
|
|
|
if (bio->bi_private)
|
|
|
|
mempool_free(bio->bi_private, bio_post_read_ctx_pool);
|
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bio_post_read_processing(struct bio_post_read_ctx *ctx);
|
|
|
|
|
|
|
|
static void decrypt_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct bio_post_read_ctx *ctx =
|
|
|
|
container_of(work, struct bio_post_read_ctx, work);
|
2022-08-16 07:50:51 +08:00
|
|
|
struct bio *bio = ctx->bio;
|
2019-07-23 00:26:24 +08:00
|
|
|
|
2022-08-16 07:50:51 +08:00
|
|
|
if (fscrypt_decrypt_bio(bio))
|
|
|
|
bio_post_read_processing(ctx);
|
|
|
|
else
|
|
|
|
__read_end_io(bio);
|
2019-07-23 00:26:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void verity_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct bio_post_read_ctx *ctx =
|
|
|
|
container_of(work, struct bio_post_read_ctx, work);
|
2020-01-01 02:12:22 +08:00
|
|
|
struct bio *bio = ctx->bio;
|
2019-07-23 00:26:24 +08:00
|
|
|
|
2020-01-01 02:12:22 +08:00
|
|
|
/*
|
2022-03-24 09:29:04 +08:00
|
|
|
* fsverity_verify_bio() may call readahead() again, and although verity
|
2020-01-01 02:12:22 +08:00
|
|
|
* will be disabled for that, decryption may still be needed, causing
|
|
|
|
* another bio_post_read_ctx to be allocated. So to guarantee that
|
|
|
|
* mempool_alloc() never deadlocks we must free the current ctx first.
|
|
|
|
* This is safe because verity is the last post-read step.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(STEP_VERITY + 1 != STEP_MAX);
|
|
|
|
mempool_free(ctx, bio_post_read_ctx_pool);
|
|
|
|
bio->bi_private = NULL;
|
|
|
|
|
|
|
|
fsverity_verify_bio(bio);
|
|
|
|
|
|
|
|
__read_end_io(bio);
|
2019-07-23 00:26:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bio_post_read_processing(struct bio_post_read_ctx *ctx)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We use different work queues for decryption and for verity because
|
|
|
|
* verity may require reading metadata pages that need decryption, and
|
|
|
|
* we shouldn't recurse to the same workqueue.
|
|
|
|
*/
|
|
|
|
switch (++ctx->cur_step) {
|
|
|
|
case STEP_DECRYPT:
|
|
|
|
if (ctx->enabled_steps & (1 << STEP_DECRYPT)) {
|
|
|
|
INIT_WORK(&ctx->work, decrypt_work);
|
|
|
|
fscrypt_enqueue_decrypt_work(&ctx->work);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->cur_step++;
|
2020-08-10 19:44:35 +08:00
|
|
|
fallthrough;
|
2019-07-23 00:26:24 +08:00
|
|
|
case STEP_VERITY:
|
|
|
|
if (ctx->enabled_steps & (1 << STEP_VERITY)) {
|
|
|
|
INIT_WORK(&ctx->work, verity_work);
|
|
|
|
fsverity_enqueue_verify_work(&ctx->work);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->cur_step++;
|
2020-08-10 19:44:35 +08:00
|
|
|
fallthrough;
|
2019-07-23 00:26:24 +08:00
|
|
|
default:
|
|
|
|
__read_end_io(ctx->bio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bio_post_read_required(struct bio *bio)
|
|
|
|
{
|
|
|
|
return bio->bi_private && !bio->bi_status;
|
2015-04-12 12:56:10 +08:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:00:32 +08:00
|
|
|
/*
|
|
|
|
* I/O completion handler for multipage BIOs.
|
|
|
|
*
|
|
|
|
* The mpage code never puts partial pages into a BIO (except for end-of-file).
|
|
|
|
* If a page does not map to a contiguous run of blocks then it simply falls
|
2022-04-29 22:40:40 +08:00
|
|
|
* back to block_read_full_folio().
|
2015-04-08 12:00:32 +08:00
|
|
|
*
|
|
|
|
* Why is this? If a page's completion depends on a number of different BIOs
|
|
|
|
* which can complete in any order (or at the same time) then determining the
|
|
|
|
* status of that page is hard. See end_buffer_async_read() for the details.
|
|
|
|
* There is no point in duplicating all that complexity.
|
|
|
|
*/
|
2015-07-20 21:29:37 +08:00
|
|
|
static void mpage_end_io(struct bio *bio)
|
2015-04-08 12:00:32 +08:00
|
|
|
{
|
2019-07-23 00:26:24 +08:00
|
|
|
if (bio_post_read_required(bio)) {
|
|
|
|
struct bio_post_read_ctx *ctx = bio->bi_private;
|
2015-04-08 12:00:32 +08:00
|
|
|
|
2019-07-23 00:26:24 +08:00
|
|
|
ctx->cur_step = STEP_INITIAL;
|
|
|
|
bio_post_read_processing(ctx);
|
|
|
|
return;
|
2015-04-12 12:56:10 +08:00
|
|
|
}
|
2019-07-23 00:26:24 +08:00
|
|
|
__read_end_io(bio);
|
|
|
|
}
|
2015-04-08 12:00:32 +08:00
|
|
|
|
2019-07-23 00:26:24 +08:00
|
|
|
static inline bool ext4_need_verity(const struct inode *inode, pgoff_t idx)
|
|
|
|
{
|
|
|
|
return fsverity_active(inode) &&
|
|
|
|
idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
2020-01-01 02:12:56 +08:00
|
|
|
static void ext4_set_bio_post_read_ctx(struct bio *bio,
|
|
|
|
const struct inode *inode,
|
|
|
|
pgoff_t first_idx)
|
2019-07-23 00:26:24 +08:00
|
|
|
{
|
|
|
|
unsigned int post_read_steps = 0;
|
|
|
|
|
2020-07-02 09:56:07 +08:00
|
|
|
if (fscrypt_inode_uses_fs_layer_crypto(inode))
|
2019-07-23 00:26:24 +08:00
|
|
|
post_read_steps |= 1 << STEP_DECRYPT;
|
|
|
|
|
|
|
|
if (ext4_need_verity(inode, first_idx))
|
|
|
|
post_read_steps |= 1 << STEP_VERITY;
|
|
|
|
|
|
|
|
if (post_read_steps) {
|
2020-01-01 02:12:56 +08:00
|
|
|
/* Due to the mempool, this never fails. */
|
|
|
|
struct bio_post_read_ctx *ctx =
|
|
|
|
mempool_alloc(bio_post_read_ctx_pool, GFP_NOFS);
|
|
|
|
|
2019-07-23 00:26:24 +08:00
|
|
|
ctx->bio = bio;
|
|
|
|
ctx->enabled_steps = post_read_steps;
|
|
|
|
bio->bi_private = ctx;
|
2015-04-08 12:00:32 +08:00
|
|
|
}
|
2019-07-23 00:26:24 +08:00
|
|
|
}
|
2015-04-08 12:00:32 +08:00
|
|
|
|
2019-07-23 00:26:24 +08:00
|
|
|
static inline loff_t ext4_readpage_limit(struct inode *inode)
|
|
|
|
{
|
2022-12-24 04:36:35 +08:00
|
|
|
if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode))
|
2019-07-23 00:26:24 +08:00
|
|
|
return inode->i_sb->s_maxbytes;
|
|
|
|
|
|
|
|
return i_size_read(inode);
|
2015-04-08 12:00:32 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 12:47:20 +08:00
|
|
|
int ext4_mpage_readpages(struct inode *inode,
|
2023-03-25 02:01:23 +08:00
|
|
|
struct readahead_control *rac, struct folio *folio)
|
2015-04-08 12:00:32 +08:00
|
|
|
{
|
|
|
|
struct bio *bio = NULL;
|
|
|
|
sector_t last_block_in_bio = 0;
|
|
|
|
|
|
|
|
const unsigned blkbits = inode->i_blkbits;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
const unsigned blocks_per_page = PAGE_SIZE >> blkbits;
|
2015-04-08 12:00:32 +08:00
|
|
|
const unsigned blocksize = 1 << blkbits;
|
2020-07-02 09:56:07 +08:00
|
|
|
sector_t next_block;
|
2015-04-08 12:00:32 +08:00
|
|
|
sector_t block_in_file;
|
|
|
|
sector_t last_block;
|
|
|
|
sector_t last_block_in_file;
|
|
|
|
sector_t blocks[MAX_BUF_PER_PAGE];
|
|
|
|
unsigned page_block;
|
|
|
|
struct block_device *bdev = inode->i_sb->s_bdev;
|
|
|
|
int length;
|
|
|
|
unsigned relative_block = 0;
|
|
|
|
struct ext4_map_blocks map;
|
2020-06-02 12:47:16 +08:00
|
|
|
unsigned int nr_pages = rac ? readahead_count(rac) : 1;
|
2015-04-08 12:00:32 +08:00
|
|
|
|
|
|
|
map.m_pblk = 0;
|
|
|
|
map.m_lblk = 0;
|
|
|
|
map.m_len = 0;
|
|
|
|
map.m_flags = 0;
|
|
|
|
|
2016-07-06 04:32:32 +08:00
|
|
|
for (; nr_pages; nr_pages--) {
|
2015-04-08 12:00:32 +08:00
|
|
|
int fully_mapped = 1;
|
|
|
|
unsigned first_hole = blocks_per_page;
|
|
|
|
|
2023-03-25 02:01:23 +08:00
|
|
|
if (rac)
|
|
|
|
folio = readahead_folio(rac);
|
|
|
|
prefetchw(&folio->flags);
|
2015-04-08 12:00:32 +08:00
|
|
|
|
2023-03-25 02:01:23 +08:00
|
|
|
if (folio_buffers(folio))
|
2015-04-08 12:00:32 +08:00
|
|
|
goto confused;
|
|
|
|
|
2020-07-02 09:56:07 +08:00
|
|
|
block_in_file = next_block =
|
2023-03-25 02:01:23 +08:00
|
|
|
(sector_t)folio->index << (PAGE_SHIFT - blkbits);
|
2015-04-08 12:00:32 +08:00
|
|
|
last_block = block_in_file + nr_pages * blocks_per_page;
|
2019-07-23 00:26:24 +08:00
|
|
|
last_block_in_file = (ext4_readpage_limit(inode) +
|
|
|
|
blocksize - 1) >> blkbits;
|
2015-04-08 12:00:32 +08:00
|
|
|
if (last_block > last_block_in_file)
|
|
|
|
last_block = last_block_in_file;
|
|
|
|
page_block = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map blocks using the previous result first.
|
|
|
|
*/
|
|
|
|
if ((map.m_flags & EXT4_MAP_MAPPED) &&
|
|
|
|
block_in_file > map.m_lblk &&
|
|
|
|
block_in_file < (map.m_lblk + map.m_len)) {
|
|
|
|
unsigned map_offset = block_in_file - map.m_lblk;
|
|
|
|
unsigned last = map.m_len - map_offset;
|
|
|
|
|
|
|
|
for (relative_block = 0; ; relative_block++) {
|
|
|
|
if (relative_block == last) {
|
|
|
|
/* needed? */
|
|
|
|
map.m_flags &= ~EXT4_MAP_MAPPED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (page_block == blocks_per_page)
|
|
|
|
break;
|
|
|
|
blocks[page_block] = map.m_pblk + map_offset +
|
|
|
|
relative_block;
|
|
|
|
page_block++;
|
|
|
|
block_in_file++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Then do more ext4_map_blocks() calls until we are
|
2023-03-25 02:01:23 +08:00
|
|
|
* done with this folio.
|
2015-04-08 12:00:32 +08:00
|
|
|
*/
|
|
|
|
while (page_block < blocks_per_page) {
|
|
|
|
if (block_in_file < last_block) {
|
|
|
|
map.m_lblk = block_in_file;
|
|
|
|
map.m_len = last_block - block_in_file;
|
|
|
|
|
|
|
|
if (ext4_map_blocks(NULL, inode, &map, 0) < 0) {
|
|
|
|
set_error_page:
|
2023-03-25 02:01:23 +08:00
|
|
|
folio_set_error(folio);
|
|
|
|
folio_zero_segment(folio, 0,
|
|
|
|
folio_size(folio));
|
|
|
|
folio_unlock(folio);
|
2015-04-08 12:00:32 +08:00
|
|
|
goto next_page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((map.m_flags & EXT4_MAP_MAPPED) == 0) {
|
|
|
|
fully_mapped = 0;
|
|
|
|
if (first_hole == blocks_per_page)
|
|
|
|
first_hole = page_block;
|
|
|
|
page_block++;
|
|
|
|
block_in_file++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (first_hole != blocks_per_page)
|
|
|
|
goto confused; /* hole -> non-hole */
|
|
|
|
|
|
|
|
/* Contiguous blocks? */
|
|
|
|
if (page_block && blocks[page_block-1] != map.m_pblk-1)
|
|
|
|
goto confused;
|
|
|
|
for (relative_block = 0; ; relative_block++) {
|
|
|
|
if (relative_block == map.m_len) {
|
|
|
|
/* needed? */
|
|
|
|
map.m_flags &= ~EXT4_MAP_MAPPED;
|
|
|
|
break;
|
|
|
|
} else if (page_block == blocks_per_page)
|
|
|
|
break;
|
|
|
|
blocks[page_block] = map.m_pblk+relative_block;
|
|
|
|
page_block++;
|
|
|
|
block_in_file++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first_hole != blocks_per_page) {
|
2023-03-25 02:01:23 +08:00
|
|
|
folio_zero_segment(folio, first_hole << blkbits,
|
|
|
|
folio_size(folio));
|
2015-04-08 12:00:32 +08:00
|
|
|
if (first_hole == 0) {
|
2023-03-25 02:01:23 +08:00
|
|
|
if (ext4_need_verity(inode, folio->index) &&
|
2023-05-17 03:27:13 +08:00
|
|
|
!fsverity_verify_folio(folio))
|
2019-07-23 00:26:24 +08:00
|
|
|
goto set_error_page;
|
2023-10-05 00:53:04 +08:00
|
|
|
folio_end_read(folio, true);
|
2023-03-25 02:01:23 +08:00
|
|
|
continue;
|
2015-04-08 12:00:32 +08:00
|
|
|
}
|
|
|
|
} else if (fully_mapped) {
|
2023-03-25 02:01:23 +08:00
|
|
|
folio_set_mappedtodisk(folio);
|
2015-04-08 12:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2023-03-25 02:01:23 +08:00
|
|
|
* This folio will go to BIO. Do we need to send this
|
2015-04-08 12:00:32 +08:00
|
|
|
* BIO off first?
|
|
|
|
*/
|
2020-07-02 09:56:07 +08:00
|
|
|
if (bio && (last_block_in_bio != blocks[0] - 1 ||
|
|
|
|
!fscrypt_mergeable_bio(bio, inode, next_block))) {
|
2015-04-08 12:00:32 +08:00
|
|
|
submit_and_realloc:
|
2016-06-06 03:31:41 +08:00
|
|
|
submit_bio(bio);
|
2015-04-08 12:00:32 +08:00
|
|
|
bio = NULL;
|
|
|
|
}
|
|
|
|
if (bio == NULL) {
|
2019-10-31 17:23:15 +08:00
|
|
|
/*
|
|
|
|
* bio_alloc will _always_ be able to allocate a bio if
|
|
|
|
* __GFP_DIRECT_RECLAIM is set, see bio_alloc_bioset().
|
|
|
|
*/
|
2022-01-24 17:11:05 +08:00
|
|
|
bio = bio_alloc(bdev, bio_max_segs(nr_pages),
|
|
|
|
REQ_OP_READ, GFP_KERNEL);
|
2020-07-02 09:56:07 +08:00
|
|
|
fscrypt_set_bio_crypt_ctx(bio, inode, next_block,
|
|
|
|
GFP_KERNEL);
|
2023-03-25 02:01:23 +08:00
|
|
|
ext4_set_bio_post_read_ctx(bio, inode, folio->index);
|
2015-04-08 12:00:32 +08:00
|
|
|
bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9);
|
|
|
|
bio->bi_end_io = mpage_end_io;
|
2022-01-24 17:11:05 +08:00
|
|
|
if (rac)
|
|
|
|
bio->bi_opf |= REQ_RAHEAD;
|
2015-04-08 12:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
length = first_hole << blkbits;
|
2023-03-25 02:01:23 +08:00
|
|
|
if (!bio_add_folio(bio, folio, length, 0))
|
2015-04-08 12:00:32 +08:00
|
|
|
goto submit_and_realloc;
|
|
|
|
|
|
|
|
if (((map.m_flags & EXT4_MAP_BOUNDARY) &&
|
|
|
|
(relative_block == map.m_len)) ||
|
|
|
|
(first_hole != blocks_per_page)) {
|
2016-06-06 03:31:41 +08:00
|
|
|
submit_bio(bio);
|
2015-04-08 12:00:32 +08:00
|
|
|
bio = NULL;
|
|
|
|
} else
|
|
|
|
last_block_in_bio = blocks[blocks_per_page - 1];
|
2023-03-25 02:01:23 +08:00
|
|
|
continue;
|
2015-04-08 12:00:32 +08:00
|
|
|
confused:
|
|
|
|
if (bio) {
|
2016-06-06 03:31:41 +08:00
|
|
|
submit_bio(bio);
|
2015-04-08 12:00:32 +08:00
|
|
|
bio = NULL;
|
|
|
|
}
|
2023-03-25 02:01:23 +08:00
|
|
|
if (!folio_test_uptodate(folio))
|
|
|
|
block_read_full_folio(folio, ext4_get_block);
|
2015-04-08 12:00:32 +08:00
|
|
|
else
|
2023-03-25 02:01:23 +08:00
|
|
|
folio_unlock(folio);
|
|
|
|
next_page:
|
|
|
|
; /* A label shall be followed by a statement until C23 */
|
2015-04-08 12:00:32 +08:00
|
|
|
}
|
|
|
|
if (bio)
|
2016-06-06 03:31:41 +08:00
|
|
|
submit_bio(bio);
|
2015-04-08 12:00:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2019-07-23 00:26:24 +08:00
|
|
|
|
|
|
|
int __init ext4_init_post_read_processing(void)
|
|
|
|
{
|
2022-11-09 23:38:22 +08:00
|
|
|
bio_post_read_ctx_cache = KMEM_CACHE(bio_post_read_ctx, SLAB_RECLAIM_ACCOUNT);
|
|
|
|
|
2019-07-23 00:26:24 +08:00
|
|
|
if (!bio_post_read_ctx_cache)
|
|
|
|
goto fail;
|
|
|
|
bio_post_read_ctx_pool =
|
|
|
|
mempool_create_slab_pool(NUM_PREALLOC_POST_READ_CTXS,
|
|
|
|
bio_post_read_ctx_cache);
|
|
|
|
if (!bio_post_read_ctx_pool)
|
|
|
|
goto fail_free_cache;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_free_cache:
|
|
|
|
kmem_cache_destroy(bio_post_read_ctx_cache);
|
|
|
|
fail:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ext4_exit_post_read_processing(void)
|
|
|
|
{
|
|
|
|
mempool_destroy(bio_post_read_ctx_pool);
|
|
|
|
kmem_cache_destroy(bio_post_read_ctx_cache);
|
|
|
|
}
|