Browse Source

Porting IPC module to Linux 4.15 (#186)

This PR fixes the portability issues on Linux 4.11~4.15, due to 4 major changes:
(1) Adding a new argument uf to do_mmap(): https://elixir.bootlin.com/linux/v4.11/source/include/linux/mm.h#L2110
(2) Changing 4-level page table to 5-level: https://elixir.bootlin.com/linux/v4.11/source/include/asm-generic/5level-fixup.h#L12
(3) Renaming SLAB_DESTROY_BY_RCU to SLAB_TYPESAFE_BY_RCU (Linux 4.12+)
(4) signal_pending() moved to linux/sched/signal.h.
Chia-Che Tsai 6 years ago
parent
commit
6d84b4a06d
1 changed files with 45 additions and 1 deletions
  1. 45 1
      Pal/ipc/linux/graphene-ipc.c

+ 45 - 1
Pal/ipc/linux/graphene-ipc.c

@@ -13,6 +13,9 @@
 #include <linux/sched.h>
 #include <linux/pagemap.h>
 #include <linux/bitmap.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
+# include <linux/sched/signal.h>
+#endif
 #include <asm/mman.h>
 #include <asm/tlb.h>
 
@@ -50,7 +53,18 @@ struct kmem_cache *gipc_send_buffer_cachep;
 	do_mmap_pgoff((file), (addr), (len), (prot), (flags), (pgoff))
 # endif /* kernel_version < 3.9.0 */
 #else
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
+#  define MY_DO_MMAP
+#  define DO_MMAP_PGOFF(file, addr, len, prot, flags, pgoff)		\
+	({								\
+		unsigned long populate;					\
+		unsigned long rv;					\
+	 	rv = KSYM(do_mmap)((file), (addr), (len),		\
+				   (prot), (flags), 0, (pgoff),		\
+				   &populate, NULL);			\
+	rv; })
+
+# elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
 #  define MY_DO_MMAP
 #  define DO_MMAP_PGOFF(file, addr, len, prot, flags, pgoff)		\
 	({								\
@@ -234,6 +248,9 @@ inline int make_page_cow(struct mm_struct *mm, struct vm_area_struct *vma,
 			 unsigned long addr)
 {
 	pgd_t *pgd;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
+	p4d_t *p4d;
+#endif
 	pud_t *pud;
 	pmd_t *pmd;
 	pte_t *pte;
@@ -243,7 +260,15 @@ inline int make_page_cow(struct mm_struct *mm, struct vm_area_struct *vma,
 	if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
 		goto no_page;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
+	p4d = p4d_offset(pgd, addr);
+	if (p4d_none(*p4d) || unlikely(p4d_bad(*p4d)))
+		goto no_page;
+
+	pud = pud_offset(p4d, addr);
+#else
 	pud = pud_offset(pgd, addr);
+#endif
 	if (pud_none(*pud) || unlikely(pud_bad(*pud)))
 		goto no_page;
 
@@ -279,6 +304,9 @@ static void fill_page_bit_map(struct mm_struct *mm,
 	do {
 		struct vm_area_struct *vma;
 		pgd_t *pgd;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
+		p4d_t *p4d;
+#endif
 		pud_t *pud;
 		pmd_t *pmd;
 		pte_t *pte;
@@ -295,7 +323,15 @@ static void fill_page_bit_map(struct mm_struct *mm,
 		if (pgd_none(*pgd) || pgd_bad(*pgd))
 			goto next;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
+		p4d = p4d_offset(pgd, addr);
+		if (p4d_none(*p4d) || unlikely(p4d_bad(*p4d)))
+			goto next;
+
+		pud = pud_offset(p4d, addr);
+#else
 		pud = pud_offset(pgd, addr);
+#endif
 		if (pud_none(*pud) || pud_bad(*pud))
 			goto next;
 
@@ -950,7 +986,11 @@ static int __init gipc_init(void)
 					      sizeof(struct gipc_queue),
 					      0,
 					      SLAB_HWCACHE_ALIGN|
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+					      SLAB_TYPESAFE_BY_RCU,
+#else
 					      SLAB_DESTROY_BY_RCU,
+#endif
 					      NULL);
 	if (!gipc_queue_cachep) {
 		printk(KERN_ERR "Graphene error: "
@@ -962,7 +1002,11 @@ static int __init gipc_init(void)
 					    sizeof(struct gipc_send_buffer),
 					    0,
 					    SLAB_HWCACHE_ALIGN|
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
+					    SLAB_TYPESAFE_BY_RCU,
+#else
 					    SLAB_DESTROY_BY_RCU,
+#endif
 					    NULL);
 	if (!gipc_send_buffer_cachep) {
 		printk(KERN_ERR "Graphene error: "