Merge branches 'acpi-battery', 'acpi-video' and 'acpi-misc'
[sfrench/cifs-2.6.git] / arch / x86 / boot / compressed / ident_map_64.c
index f7213d0943b82e73ef0181a72def7c3815ab5c0e..44c350d627c79b4b13e29bfe74cbec1e5c69879f 100644 (file)
@@ -90,7 +90,7 @@ static struct x86_mapping_info mapping_info;
 /*
  * Adds the specified range to the identity mappings.
  */
-static void add_identity_map(unsigned long start, unsigned long end)
+void kernel_add_identity_map(unsigned long start, unsigned long end)
 {
        int ret;
 
@@ -157,14 +157,15 @@ void initialize_identity_maps(void *rmode)
         * explicitly here in case the compressed kernel does not touch them,
         * or does not touch all the pages covering them.
         */
-       add_identity_map((unsigned long)_head, (unsigned long)_end);
+       kernel_add_identity_map((unsigned long)_head, (unsigned long)_end);
        boot_params = rmode;
-       add_identity_map((unsigned long)boot_params, (unsigned long)(boot_params + 1));
+       kernel_add_identity_map((unsigned long)boot_params, (unsigned long)(boot_params + 1));
        cmdline = get_cmd_line_ptr();
-       add_identity_map(cmdline, cmdline + COMMAND_LINE_SIZE);
+       kernel_add_identity_map(cmdline, cmdline + COMMAND_LINE_SIZE);
+
+       sev_prep_identity_maps(top_level_pgt);
 
        /* Load the new page-table. */
-       sev_verify_cbit(top_level_pgt);
        write_cr3(top_level_pgt);
 }
 
@@ -246,10 +247,10 @@ static int set_clr_page_flags(struct x86_mapping_info *info,
         * It should already exist, but keep things generic.
         *
         * To map the page just read from it and fault it in if there is no
-        * mapping yet. add_identity_map() can't be called here because that
-        * would unconditionally map the address on PMD level, destroying any
-        * PTE-level mappings that might already exist. Use assembly here so
-        * the access won't be optimized away.
+        * mapping yet. kernel_add_identity_map() can't be called here because
+        * that would unconditionally map the address on PMD level, destroying
+        * any PTE-level mappings that might already exist. Use assembly here
+        * so the access won't be optimized away.
         */
        asm volatile("mov %[address], %%r9"
                     :: [address] "g" (*(unsigned long *)address)
@@ -275,15 +276,31 @@ static int set_clr_page_flags(struct x86_mapping_info *info,
         * Changing encryption attributes of a page requires to flush it from
         * the caches.
         */
-       if ((set | clr) & _PAGE_ENC)
+       if ((set | clr) & _PAGE_ENC) {
                clflush_page(address);
 
+               /*
+                * If the encryption attribute is being cleared, change the page state
+                * to shared in the RMP table.
+                */
+               if (clr)
+                       snp_set_page_shared(__pa(address & PAGE_MASK));
+       }
+
        /* Update PTE */
        pte = *ptep;
        pte = pte_set_flags(pte, set);
        pte = pte_clear_flags(pte, clr);
        set_pte(ptep, pte);
 
+       /*
+        * If the encryption attribute is being set, then change the page state to
+        * private in the RMP entry. The page state change must be done after the PTE
+        * is updated.
+        */
+       if (set & _PAGE_ENC)
+               snp_set_page_private(__pa(address & PAGE_MASK));
+
        /* Flush TLB after changing encryption attribute */
        write_cr3(top_level_pgt);
 
@@ -347,5 +364,5 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code)
         * Error code is sane - now identity map the 2M region around
         * the faulting address.
         */
-       add_identity_map(address, end);
+       kernel_add_identity_map(address, end);
 }