2022-06-12 16:10:17

by Joe Damato

[permalink] [raw]
Subject: [RFC,iov_iter v2 2/8] iov_iter: Introduce iter_copy_type

struct iov_iter has a new member: iter_copy_type. This field holds a value
designating which type of copy to use: a regular temporal copy (ITER_COPY)
or a non-temporal copy (ITER_NOCACHE_COPY).

iov_iter initializers have been updated to set the default ITER_COPY
type.

Signed-off-by: Joe Damato <[email protected]>
---
include/linux/uio.h | 17 +++++++++++++++++
lib/iov_iter.c | 6 ++++++
2 files changed, 23 insertions(+)

diff --git a/include/linux/uio.h b/include/linux/uio.h
index 739285f..59573ee 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -28,6 +28,12 @@ enum iter_type {
ITER_DISCARD,
};

+enum iter_copy_type {
+ /* iter copy types */
+ ITER_COPY,
+ ITER_NOCACHE_COPY,
+};
+
struct iov_iter_state {
size_t iov_offset;
size_t count;
@@ -35,6 +41,7 @@ struct iov_iter_state {
};

struct iov_iter {
+ u8 iter_copy_type;
u8 iter_type;
bool nofault;
bool data_source;
@@ -62,6 +69,11 @@ static inline enum iter_type iov_iter_type(const struct iov_iter *i)
return i->iter_type;
}

+static inline enum iter_copy_type iov_iter_copy_type(const struct iov_iter *i)
+{
+ return i->iter_copy_type;
+}
+
static inline void iov_iter_save_state(struct iov_iter *iter,
struct iov_iter_state *state)
{
@@ -95,6 +107,11 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)
return iov_iter_type(i) == ITER_DISCARD;
}

+static inline bool iov_iter_copy_is_nt(const struct iov_iter *i)
+{
+ return iov_iter_copy_type(i) == ITER_NOCACHE_COPY;
+}
+
static inline bool iov_iter_is_xarray(const struct iov_iter *i)
{
return iov_iter_type(i) == ITER_XARRAY;
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 6dd5330..d32d7e5 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -511,6 +511,7 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction,
{
WARN_ON(direction & ~(READ | WRITE));
*i = (struct iov_iter) {
+ .iter_copy_type = ITER_COPY,
.iter_type = ITER_IOVEC,
.nofault = false,
.data_source = direction,
@@ -1175,6 +1176,7 @@ void iov_iter_kvec(struct iov_iter *i, unsigned int direction,
{
WARN_ON(direction & ~(READ | WRITE));
*i = (struct iov_iter){
+ .iter_copy_type = ITER_COPY,
.iter_type = ITER_KVEC,
.data_source = direction,
.kvec = kvec,
@@ -1191,6 +1193,7 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction,
{
WARN_ON(direction & ~(READ | WRITE));
*i = (struct iov_iter){
+ .iter_copy_type = ITER_COPY,
.iter_type = ITER_BVEC,
.data_source = direction,
.bvec = bvec,
@@ -1208,6 +1211,7 @@ void iov_iter_pipe(struct iov_iter *i, unsigned int direction,
BUG_ON(direction != READ);
WARN_ON(pipe_full(pipe->head, pipe->tail, pipe->ring_size));
*i = (struct iov_iter){
+ .iter_copy_type = ITER_COPY,
.iter_type = ITER_PIPE,
.data_source = false,
.pipe = pipe,
@@ -1237,6 +1241,7 @@ void iov_iter_xarray(struct iov_iter *i, unsigned int direction,
{
BUG_ON(direction & ~1);
*i = (struct iov_iter) {
+ .iter_copy_type = ITER_COPY,
.iter_type = ITER_XARRAY,
.data_source = direction,
.xarray = xarray,
@@ -1260,6 +1265,7 @@ void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count)
{
BUG_ON(direction != READ);
*i = (struct iov_iter){
+ .iter_copy_type = ITER_COPY,
.iter_type = ITER_DISCARD,
.data_source = false,
.count = count,
--
2.7.4