From 7df8bd69fbe59afba0a43fe19e7a5b1d2c3fd115 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Wed, 8 Feb 2023 14:01:24 -0500 Subject: [PATCH] LU-13805 llite: add mm to dio struct When copying to or from userspace, we must use the mm from the userspace thread. This can be done either by running in that thread or borrowing its mm. Unaligned DIO does some memory movement to userspace in ptlrpcd threads, so it requires the user mm be stored in the sub dio. This will be used by the main unaligned DIO patch and has been split out for reviewability. Signed-off-by: Patrick Farrell Change-Id: I419cb9f1899b8c8f9790ce25b3aba1d6f07397aa Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49947 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: Zhenyu Xu Reviewed-by: Qian Yingjin --- lustre/autoconf/lustre-core.m4 | 26 ++++++++++++++++++++++++++ lustre/include/cl_object.h | 6 ++++++ lustre/obdclass/cl_io.c | 3 +++ 3 files changed, 35 insertions(+) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 8f7e78f..9a57e4d 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -2893,6 +2893,26 @@ AC_DEFUN([LC_FSCRYPT_DUMMY_CONTEXT_ENABLED], [ ]) # LC_FSCRYPT_DUMMY_CONTEXT_ENABLED # +# LC_HAVE_KTHREAD_USE_MM +# +# kernel 5.8 commit f5678e7f2ac31c270334b936352f0ef2fe7dd2b3 +# kernel: better document the use_mm/unuse_mm API contract +# +AC_DEFUN([LC_SRC_HAVE_KTHREAD_USE_MM], [ + LB2_LINUX_TEST_SRC([kthread_use_mm], [ + #include + ],[ + kthread_use_mm(NULL); + ]) +]) +AC_DEFUN([LC_HAVE_KTHREAD_USE_MM], [ + AC_MSG_CHECKING([if have kthread_use_mm]) + LB2_LINUX_TEST_RESULT([kthread_use_mm], [ + AC_DEFINE(HAVE_KTHREAD_USE_MM, 1, ['kthread_use_mm' exists]) + ]) +]) # LC_HAVE_KTHREAD_USE_MM + +# # LC_FSCRYPT_FNAME_ALLOC_BUFFER # # Kernel 5.9-rc4 8b10fe68985278de4926daa56ad6af701839e40a @@ -4066,6 +4086,9 @@ AC_DEFUN([LC_PROG_LINUX_SRC], [ # 5.7 LC_SRC_FSCRYPT_DUMMY_CONTEXT_ENABLED + # 5.8 + LC_SRC_HAVE_KTHREAD_USE_MM + # 5.9 LC_SRC_FSCRYPT_FNAME_ALLOC_BUFFER LC_SRC_FSCRYPT_SET_CONTEXT @@ -4327,6 +4350,9 @@ AC_DEFUN([LC_PROG_LINUX_RESULTS], [ # 5.7 LC_FSCRYPT_DUMMY_CONTEXT_ENABLED + # 5.8 + LC_HAVE_KTHREAD_USE_MM + # 5.9 LC_HAVE_ITER_FILE_SPLICE_WRITE diff --git a/lustre/include/cl_object.h b/lustre/include/cl_object.h index c21aea8..2dc43b1 100644 --- a/lustre/include/cl_object.h +++ b/lustre/include/cl_object.h @@ -2563,6 +2563,7 @@ struct cl_dio_aio { struct cl_object *cda_obj; struct kiocb *cda_iocb; ssize_t cda_bytes; + struct mm_struct *cda_mm; unsigned cda_no_aio_complete:1, cda_creator_free:1; }; @@ -2587,6 +2588,11 @@ struct cl_sub_dio { void ll_release_user_pages(struct page **pages, int npages); +#ifndef HAVE_KTHREAD_USE_MM +#define kthread_use_mm(mm) use_mm(mm) +#define kthread_unuse_mm(mm) unuse_mm(mm) +#endif + /** @} cl_sync_io */ /** \defgroup cl_env cl_env diff --git a/lustre/obdclass/cl_io.c b/lustre/obdclass/cl_io.c index bae22ca..9d7f68f 100644 --- a/lustre/obdclass/cl_io.c +++ b/lustre/obdclass/cl_io.c @@ -1238,6 +1238,7 @@ struct cl_dio_aio *cl_dio_aio_alloc(struct kiocb *iocb, struct cl_object *obj, cl_object_get(obj); aio->cda_obj = obj; + aio->cda_mm = get_task_mm(current); } return aio; } @@ -1290,6 +1291,8 @@ EXPORT_SYMBOL(cl_sub_dio_alloc); void cl_dio_aio_free(const struct lu_env *env, struct cl_dio_aio *aio) { if (aio) { + if (aio->cda_mm) + mmput(aio->cda_mm); cl_object_put(env, aio->cda_obj); OBD_SLAB_FREE_PTR(aio, cl_dio_aio_kmem); } -- 1.8.3.1