fscrypt, pfk, ice: cover ICE-related data structures in CONFIG_PFK
This patch makes CONFIG_PFK cover all the per-file key structures.
Otherwise, for example, f2fs will set DUN, resulting in IO fragmentation,
even if PFK is not set.
Bug: 68721442
Change-Id: I93808db0b00feae53888fd9ae6c91fc2727ffca9
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Signed-off-by: Neeraj Soni <neersoni@codeaurora.org>
diff --git a/block/bio.c b/block/bio.c
index 91b6462..6546a6b 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -570,8 +570,8 @@
#ifdef CONFIG_PFK
dst->bi_crypt_key = src->bi_crypt_key;
dst->bi_iter.bi_dun = src->bi_iter.bi_dun;
-#endif
dst->bi_dio_inode = src->bi_dio_inode;
+#endif
}
/**
@@ -598,7 +598,9 @@
bio->bi_opf = bio_src->bi_opf;
bio->bi_iter = bio_src->bi_iter;
bio->bi_io_vec = bio_src->bi_io_vec;
+#ifdef CONFIG_PFK
bio->bi_dio_inode = bio_src->bi_dio_inode;
+#endif
bio_clone_crypt_key(bio, bio_src);
bio_clone_blkcg_association(bio, bio_src);
}
diff --git a/block/blk-core.c b/block/blk-core.c
index ff2e4fd..68ec55a 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1529,7 +1529,9 @@
bio->bi_next = req->bio;
req->bio = bio;
+#ifdef CONFIG_PFK
WARN_ON(req->__dun || bio->bi_iter.bi_dun);
+#endif
req->__sector = bio->bi_iter.bi_sector;
req->__data_len += bio->bi_iter.bi_size;
req->ioprio = ioprio_best(req->ioprio, bio_prio(bio));
@@ -1645,7 +1647,9 @@
req->errors = 0;
req->__sector = bio->bi_iter.bi_sector;
+#ifdef CONFIG_PFK
req->__dun = bio->bi_iter.bi_dun;
+#endif
req->ioprio = bio_prio(bio);
blk_rq_bio_prep(req->q, req, bio);
}
@@ -2650,8 +2654,10 @@
/* update sector only for requests with clear definition of sector */
if (req->cmd_type == REQ_TYPE_FS) {
req->__sector += total_bytes >> 9;
+#ifdef CONFIG_PFK
if (req->__dun)
req->__dun += total_bytes >> 12;
+#endif
}
/* mixed attributes always follow the first bio */
@@ -3053,7 +3059,9 @@
(src->cmd_flags & REQ_CLONE_MASK) | REQ_NOMERGE);
dst->cmd_type = src->cmd_type;
dst->__sector = blk_rq_pos(src);
+#ifdef CONFIG_PFK
dst->__dun = blk_rq_dun(src);
+#endif
dst->__data_len = blk_rq_bytes(src);
dst->nr_phys_segments = src->nr_phys_segments;
dst->ioprio = src->ioprio;
diff --git a/block/blk-merge.c b/block/blk-merge.c
index c71d1cb..8e730d1 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -876,8 +876,10 @@
int blk_try_merge(struct request *rq, struct bio *bio)
{
+#ifdef CONFIG_PFK
if (blk_rq_dun(rq) || bio_dun(bio))
return ELEVATOR_NO_MERGE;
+#endif
if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
return ELEVATOR_BACK_MERGE;
else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector)
diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index 4dfd8d3..a44c988 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2017, Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2018, Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@@ -900,6 +900,7 @@
/* Use request LBA or given dun as the DUN value */
if (req->bio) {
+#ifdef CONFIG_PFK
if (bio_dun(req->bio)) {
/* dun @bio can be split, so we have to adjust offset */
*dun = bio_dun(req->bio);
@@ -907,6 +908,10 @@
*dun = req->bio->bi_iter.bi_sector;
*dun >>= UFS_QCOM_ICE_TR_DATA_UNIT_4_KB;
}
+#else
+ *dun = req->bio->bi_iter.bi_sector;
+ *dun >>= UFS_QCOM_ICE_TR_DATA_UNIT_4_KB;
+#endif
}
ret = ufs_qcom_ice_req_setup(host, lrbp->cmd, cc_index, enable);
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 081e539..7f5d2e3 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -392,6 +392,7 @@
sdio->logical_offset_in_bio = sdio->cur_page_fs_offset;
}
+#ifdef CONFIG_PFK
static bool is_inode_filesystem_type(const struct inode *inode,
const char *fs_type)
{
@@ -406,6 +407,7 @@
return (strcmp(inode->i_sb->s_type->name, fs_type) == 0);
}
+#endif
/*
* In the AIO read case we speculatively dirty the pages before starting IO.
@@ -428,6 +430,7 @@
if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty)
bio_set_pages_dirty(bio);
+#ifdef CONFIG_PFK
bio->bi_dio_inode = dio->inode;
/* iv sector for security/pfe/pfk_fscrypt.c and f2fs in fs/f2fs/f2fs.h.*/
@@ -437,6 +440,7 @@
if (is_inode_filesystem_type(dio->inode, "f2fs"))
fscrypt_set_ice_dun(dio->inode, bio, PG_DUN_NEW(dio->inode,
(sdio->logical_offset_in_bio >> PAGE_SHIFT)));
+#endif
dio->bio_bdev = bio->bi_bdev;
if (sdio->submit_io) {
@@ -457,7 +461,9 @@
if (bio == NULL)
return NULL;
+#ifdef CONFIG_PFK
inode = bio->bi_dio_inode;
+#endif
return inode;
}
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 5a3712c..42ad6b5 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -66,9 +66,17 @@
struct bio_integrity_payload *bi_integrity; /* data integrity */
#endif
};
+
#ifdef CONFIG_PFK
/* Encryption key to use (NULL if none) */
const struct blk_encryption_key *bi_crypt_key;
+
+ /*
+ * When using dircet-io (O_DIRECT), we can't get the inode from a bio
+ * by walking bio->bi_io_vec->bv_page->mapping->host
+ * since the page is anon.
+ */
+ struct inode *bi_dio_inode;
#endif
unsigned short bi_vcnt; /* how many bio_vec's */
@@ -86,12 +94,6 @@
struct bio_set *bi_pool;
/*
- * When using dircet-io (O_DIRECT), we can't get the inode from a bio
- * by walking bio->bi_io_vec->bv_page->mapping->host
- * since the page is anon.
- */
- struct inode *bi_dio_inode;
- /*
* We can inline a number of vecs at the end of the bio, to avoid
* double allocations for a small number of bio_vecs. This member
* MUST obviously be kept at the very end of the bio.
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index dbf1f2c..2425374 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -41,7 +41,9 @@
unsigned int bi_bvec_done; /* number of bytes completed in
current bvec */
+#ifdef CONFIG_PFK
u64 bi_dun; /* DUN setting for bio */
+#endif
};
/*
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index 7a7fce9..1e03614 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -252,4 +252,29 @@
return 0;
}
+/* fscrypt_ice.c */
+#ifdef CONFIG_PFK
+extern int fscrypt_using_hardware_encryption(const struct inode *inode);
+extern void fscrypt_set_ice_dun(const struct inode *inode,
+ struct bio *bio, u64 dun);
+extern bool fscrypt_mergeable_bio(struct bio *bio, u64 dun, bool bio_encrypted);
+#else
+static inline int fscrypt_using_hardware_encryption(const struct inode *inode)
+{
+ return 0;
+}
+
+static inline void fscrypt_set_ice_dun(const struct inode *inode,
+ struct bio *bio, u64 dun)
+{
+ return;
+}
+
+static inline bool fscrypt_mergeable_bio(struct bio *bio,
+ u64 dun, bool bio_encrypted)
+{
+ return true;
+}
+#endif
+
#endif /* _LINUX_FSCRYPT_H */
diff --git a/include/linux/fscrypt_notsupp.h b/include/linux/fscrypt_notsupp.h
index ce4df7a..172d418 100644
--- a/include/linux/fscrypt_notsupp.h
+++ b/include/linux/fscrypt_notsupp.h
@@ -183,23 +183,7 @@
return -EOPNOTSUPP;
}
-/* fscrypt_ice.c */
-static inline int fscrypt_using_hardware_encryption(const struct inode *inode)
-{
- return 0;
-}
-
-static inline void fscrypt_set_ice_dun(const struct inode *inode,
- struct bio *bio, u64 dun){}
-
-static inline bool fscrypt_mergeable_bio(struct bio *bio,
- sector_t iv_block, bool bio_encrypted)
-{
- return true;
-}
-
/* hooks.c */
-
static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
{
if (IS_ENCRYPTED(inode))
diff --git a/include/linux/fscrypt_supp.h b/include/linux/fscrypt_supp.h
index 2f62d5b..1ed79ee 100644
--- a/include/linux/fscrypt_supp.h
+++ b/include/linux/fscrypt_supp.h
@@ -195,13 +195,6 @@
extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
unsigned int);
-/* fscrypt_ice.c */
-extern int fscrypt_using_hardware_encryption(const struct inode *inode);
-extern void fscrypt_set_ice_dun(const struct inode *inode,
- struct bio *bio, u64 dun);
-extern bool fscrypt_mergeable_bio(struct bio *bio, u64 dun, bool bio_encrypted);
-
-
/* hooks.c */
extern int fscrypt_file_open(struct inode *inode, struct file *filp);
extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);