On 04/07/2017 06:33 AM, Borislav Petkov wrote:
On Thu, Apr 06, 2017 at 01:37:41PM -0500, Brijesh Singh wrote:
I did thought about prot idea but ran into another corner case which may require
us changing the signature of phys_pud_init and phys_pmd_init. The paddr_start
and paddr_end args into kernel_physical_mapping_init() should be aligned on PMD
level down (see comment [1]). So, if we encounter a case where our address range
is part of large page but we need to clear only one entry (i.e asked to clear just
one page into 2M region). In that case, now we need to pass additional arguments
into kernel_physical_mapping, phys_pud_init and phys_pmd_init to hint the splitting
code that it should use our prot for specific entries and all other entries will use
the old_prot.
Ok, but your !4K case:
+ /*
+ * virtual address is part of large page, create the page
+ * table mapping to use smaller pages (4K). The virtual and
+ * physical address must be aligned to PMD level.
+ */
+ kernel_physical_mapping_init(__pa(vaddr & PMD_MASK),
+ __pa((vaddr_end & PMD_MASK) + PMD_SIZE),
+ 0);
would map a 2M page as encrypted by default. What if we want to map a 2M page
frame as ~_PAGE_ENC?
Thanks for feedbacks, I will make sure that we cover all other cases in final patch.
Untested but something like this can be used to check whether we can change the large page
in one go or request the splitting.
+ psize = page_level_size(level);
+ pmask = page_level_mask(level);
+
+ /*
+ * Check, whether we can change the large page in one go.
+ * We request a split, when the address is not aligned and
+ * the number of pages to set or clear encryption bit is smaller
+ * than the number of pages in the large page.
+ */
+ if (vaddr == (vaddr & pmask) && ((vaddr_end - vaddr) >= psize)) {
+ /* UPDATE PMD HERE */
+ vaddr_next = (vaddr & pmask) + psize;
+ continue;
+ }
+
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>