]> xenbits.xensource.com Git - mini-os.git/commitdiff
Save/Restore Support: Add suspend/restore support for Grant Tables.
authorBruno Alvisio <bruno.alvisio@gmail.com>
Mon, 11 Dec 2017 16:12:47 +0000 (08:12 -0800)
committerWei Liu <wei.liu2@citrix.com>
Wed, 21 Mar 2018 09:16:49 +0000 (09:16 +0000)
Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
arch/x86/mm.c
gnttab.c
include/gnttab.h
kernel.c

index 003f9e165089bcfa949957147cf099c9f15e7d0d..ea584441400e8f73ef18beed2d19ca21c87f0484 100644 (file)
@@ -917,6 +917,40 @@ grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames)
     return map_frames(frames, nr_grant_frames);
 }
 
+void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames)
+{
+#ifdef CONFIG_PARAVIRT
+    int i;
+
+    for (i = 0; i < nr_grant_frames; i++) {
+        HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i),
+                (pte_t){0x0<<PAGE_SHIFT}, UVMF_INVLPG);
+    }
+#endif
+    return;
+}
+
+void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames)
+{
+    struct gnttab_setup_table setup;
+    unsigned long frames[nr_grant_frames];
+#ifdef CONFIG_PARAVIRT
+    int i;
+#endif
+    setup.dom = DOMID_SELF;
+    setup.nr_frames = nr_grant_frames;
+    set_xen_guest_handle(setup.frame_list, frames);
+
+    HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
+
+#ifdef CONFIG_PARAVIRT
+    for (i = 0; i < nr_grant_frames; i++) {
+        HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i),
+                (pte_t){(frames[i] << PAGE_SHIFT) | L1_PROT}, UVMF_INVLPG);
+    }
+#endif
+}
+
 unsigned long alloc_virt_kernel(unsigned n_pages)
 {
     unsigned long addr;
index 3f0e35f044802ae93be3c05e3f35e6bacd99612d..6978a9bc05af1f26c6136e2c2545ddb07c8d8792 100644 (file)
--- a/gnttab.c
+++ b/gnttab.c
@@ -194,3 +194,13 @@ fini_gnttab(void)
 
     HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
 }
+
+void suspend_gnttab(void)
+{
+    arch_suspend_gnttab(gnttab_table, NR_GRANT_FRAMES);
+}
+
+void resume_gnttab(void)
+{
+    arch_resume_gnttab(gnttab_table, NR_GRANT_FRAMES);
+}
index a9d8e09d051d682d638cb931b5541784cd8ba24b..974cb89dd72c95ddc2b2661fe8c0af1f88e2242e 100644 (file)
@@ -12,6 +12,10 @@ unsigned long gnttab_end_transfer(grant_ref_t gref);
 int gnttab_end_access(grant_ref_t ref);
 const char *gnttabop_error(int16_t status);
 void fini_gnttab(void);
+void suspend_gnttab(void);
+void resume_gnttab(void);
 grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames);
+void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames);
+void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames);
 
 #endif /* !__GNTTAB_H__ */
index d078e0a88c0cff36abbf68e47fe5b7fd2c1c62bd..933cbcd7f346b26918b5dd86e706a60166d2c6cf 100644 (file)
--- a/kernel.c
+++ b/kernel.c
@@ -121,6 +121,8 @@ void pre_suspend(void)
 {
     local_irq_disable();
 
+    suspend_gnttab();
+
     fini_time();
 
     suspend_console();
@@ -134,6 +136,8 @@ void post_suspend(int canceled)
 
     init_time();
 
+    resume_gnttab();
+
     local_irq_enable();
 }