Whamcloud - gitweb
LU-13805 llite: add mm to dio struct 47/49947/31
authorPatrick Farrell <pfarrell@whamcloud.com>
Wed, 8 Feb 2023 19:01:24 +0000 (14:01 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 6 Sep 2023 06:14:53 +0000 (06:14 +0000)
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 <pfarrell@whamcloud.com>
Change-Id: I419cb9f1899b8c8f9790ce25b3aba1d6f07397aa
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49947
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Zhenyu Xu <bobijam@hotmail.com>
Reviewed-by: Qian Yingjin <qian@ddn.com>
lustre/autoconf/lustre-core.m4
lustre/include/cl_object.h
lustre/obdclass/cl_io.c

index 8f7e78f..9a57e4d 100644 (file)
@@ -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 <linux/kthread.h>
+       ],[
+               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
 
index c21aea8..2dc43b1 100644 (file)
@@ -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
index bae22ca..9d7f68f 100644 (file)
@@ -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);
        }