From 6a80615addc24fa6a91e072779e262db625f5f15 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 4 Nov 2018 04:13:35 +0000 Subject: [PATCH] Merge r7426 from trunk git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/3.3.x@7679 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 3c0173272..532496e73 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -2579,6 +2579,24 @@ static int __init init_scst(void) (p); \ }) +/* + * Used for structures with fast path write access accessed from user space. + * See also commit 8eb8284b4129 ("usercopy: Prepare for usercopy whitelisting"). + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) +#define INIT_CACHEP_ALIGN_USERCOPY(p, s) ({ \ + (p) = kmem_cache_create_usercopy(#s, sizeof(struct s), \ + __alignof__(struct s), \ + SCST_SLAB_FLAGS | SLAB_HWCACHE_ALIGN, \ + 0, sizeof(struct s), NULL); \ + TRACE_MEM("Slab create: %s at %p size %zd", #s, (p), \ + sizeof(struct s)); \ + (p); \ + }) +#else +#define INIT_CACHEP_ALIGN_USERCOPY(p, s) INIT_CACHEP_ALIGN(p, s) +#endif + res = -ENOMEM; if (!INIT_CACHEP(scst_mgmt_cachep, scst_mgmt_cmd)) goto out_lib_exit; @@ -2593,7 +2611,7 @@ static int __init init_scst(void) } if (!INIT_CACHEP(scst_aen_cachep, scst_aen)) /* read-mostly */ goto out_destroy_sense_cache; - if (!INIT_CACHEP_ALIGN(scst_cmd_cachep, scst_cmd)) + if (!INIT_CACHEP_ALIGN_USERCOPY(scst_cmd_cachep, scst_cmd)) goto out_destroy_aen_cache; #ifdef CONFIG_SCST_MEASURE_LATENCY if (!INIT_CACHEP_ALIGN(scst_sess_cachep, scst_session))