Skip to contentSkip to conversation

xen/pvh: prevent Dom0 from accessing reserved MMIO regions

PATCH Superseded Roger Pau Monne 4 participants 13 messages Jan 22, 2015 – Jan 23, 2015

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover xen/pvh: prevent Dom0 from accessing reserved MMIO regions

This series aims to prevent PVH Dom0 from accessing MMIO regions of devices that are used by Xen.

I know there are concerns with the way we build a PVH Dom0 right now, but addressing those requires a major rework of how construct_dom0 works. IMHO I don't think this should block this series, but I would understand otherwise.

Thanks for the review, Roger.

#1 lore raw

PATCH v3 1/3 xen: allow set_mmio_p2m_entry to specify access type

Preparatory change that allows setting the access type to set_mmio_p2m_entry.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Eddie Dong <[email protected]>
Cc Kevin Tian <[email protected]>
Cc Tim Deegan <[email protected]>

---
Changes since v2:
- Latch default access type prior to entering the loop.

---
 xen/arch/x86/domain_build.c |  4 +++-
 xen/arch/x86/hvm/vmx/vmx.c  |  2 +-
 xen/arch/x86/mm/p2m.c       | 15 +++++++++------
 xen/include/asm-x86/p2m.h   |  3 ++-
 4 files changed, 15 insertions(+), 9 deletions(-)
xen/arch/x86/domain_build.c +3 -1
index 7a912e9..01cfa58 100644
@@ -319,11 +319,13 @@ static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn,
                                        unsigned long mfn, unsigned long nr_mfns)
 {
     unsigned long i;
+    p2m_access_t a;
     int rc;
 
+    a = p2m_get_hostp2m(d)->default_access;
     for ( i = 0; i < nr_mfns; i++ )
     {
-        if ( (rc = set_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i))) )
+        if ( (rc = set_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i), a)) )
             panic("pvh_add_mem_mapping: gfn:%lx mfn:%lx i:%ld rc:%d\n",
                   gfn, mfn, i, rc);
         if ( !(i & 0xfffff) )
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index 522892f..ab4b1e5 100644
@@ -2173,7 +2173,7 @@ static int vmx_alloc_vlapic_mapping(struct domain *d)
     share_xen_page_with_guest(virt_to_page(apic_va), d, XENSHARE_writable);
     d->arch.hvm_domain.vmx.apic_access_mfn = virt_to_mfn(apic_va);
     set_mmio_p2m_entry(d, paddr_to_pfn(APIC_DEFAULT_PHYS_BASE),
-        _mfn(virt_to_mfn(apic_va)));
+        _mfn(virt_to_mfn(apic_va)), p2m_get_hostp2m(d)->default_access);
 
     return 0;
 }
xen/arch/x86/mm/p2m.c +9 -6
index efa49dd..c1b7545 100644
@@ -810,7 +810,7 @@ void p2m_change_type_range(struct domain *d,
 
 /* Returns: 0 for success, -errno for failure */
 static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
-                               p2m_type_t gfn_p2mt)
+                               p2m_type_t gfn_p2mt, p2m_access_t access)
 {
     int rc = 0;
     p2m_access_t a;
@@ -837,7 +837,7 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
 
     P2M_DEBUG("set %d %lx %lx\n", gfn_p2mt, gfn, mfn_x(mfn));
     rc = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, gfn_p2mt,
-                       p2m->default_access);
+                       access);
     gfn_unlock(p2m, gfn, 0);
     if ( rc )
         gdprintk(XENLOG_ERR,
@@ -850,12 +850,14 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
 static int set_foreign_p2m_entry(struct domain *d, unsigned long gfn,
                                  mfn_t mfn)
 {
-    return set_typed_p2m_entry(d, gfn, mfn, p2m_map_foreign);
+    return set_typed_p2m_entry(d, gfn, mfn, p2m_map_foreign,
+                               p2m_get_hostp2m(d)->default_access);
 }
 
-int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
+int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
+                       p2m_access_t access)
 {
-    return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct);
+    return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct, access);
 }
 
 /* Returns: 0 for success, -errno for failure */
@@ -1858,7 +1860,8 @@ int map_mmio_regions(struct domain *d,
 
     for ( i = 0; !ret && i < nr; i++ )
     {
-        ret = set_mmio_p2m_entry(d, start_gfn + i, _mfn(mfn + i));
+        ret = set_mmio_p2m_entry(d, start_gfn + i, _mfn(mfn + i),
+                                 p2m_get_hostp2m(d)->default_access);
         if ( ret )
         {
             unmap_mmio_regions(d, start_gfn, i, mfn);
xen/include/asm-x86/p2m.h +2 -1
index 2cf73ca..e86e26f 100644
@@ -513,7 +513,8 @@ int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start,
                           unsigned long end);
 
 /* Set mmio addresses in the p2m table (for pass-through) */
-int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
+int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
+                       p2m_access_t access);
 int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 
 /* Add foreign mapping to the guest's p2m table. */
Signature · 7 lines
1.9.3 (Apple Git-50)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] xen: allow set_mmio_p2m_entry to specify access type

Quoted 9 lines · Roger Pau Monne

Preparatory change that allows setting the access type to set_mmio_p2m_entry.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Eddie Dong <[email protected]>
Cc Kevin Tian <[email protected]>
#3 lore raw

PATCH v3 2/3 xen/pvh: check permissions when adding MMIO regions

In reply to Roger Pau Monne

Check that MMIO regions added to PVH Dom0 are allowed. Previously a PVH Dom0 would have access to the full MMIO range.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---
Changes since v2:
- Fix coding style.

Changes since v1:
- Use the newly introduced p2m_access_t to set the access type.
- Don't add a next label.

---
 xen/arch/x86/domain_build.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
xen/arch/x86/domain_build.c +14 -1
index 01cfa58..76722f7 100644
@@ -320,11 +320,24 @@ static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn,
 {
     unsigned long i;
     p2m_access_t a;
+    mfn_t omfn;
+    p2m_type_t t;
     int rc;
 
-    a = p2m_get_hostp2m(d)->default_access;
     for ( i = 0; i < nr_mfns; i++ )
     {
+        if ( !iomem_access_permitted(d, mfn + i, mfn + i) )
+        {
+            omfn = get_gfn_query_unlocked(d, gfn + i, &t);
+            guest_physmap_remove_page(d, gfn + i, mfn_x(omfn), PAGE_ORDER_4K);
+            continue;
+        }
+
+        if ( rangeset_contains_singleton(mmio_ro_ranges, mfn + i) )
+            a = p2m_access_r;
+        else
+            a = p2m_access_rw;
+
         if ( (rc = set_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i), a)) )
             panic("pvh_add_mem_mapping: gfn:%lx mfn:%lx i:%ld rc:%d\n",
                   gfn, mfn, i, rc);
Signature · 7 lines
1.9.3 (Apple Git-50)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH v3 2/3] xen/pvh: check permissions when adding MMIO regions

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn, · line 325

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 16:19, <[email protected]> wrote:
xen/arch/x86/domain_build.c +2 -1
@@ -320,11 +320,24 @@ static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn,
 {
     unsigned long i;
     p2m_access_t a;
+    mfn_t omfn;
+    p2m_type_t t;
     int rc;
 
-    a = p2m_get_hostp2m(d)->default_access;

Iirc this is rwx.

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn, · line 339

Quoted 13 lines
xen/arch/x86/domain_build.c +11 -0
     for ( i = 0; i < nr_mfns; i++ )
     {
+        if ( !iomem_access_permitted(d, mfn + i, mfn + i) )
+        {
+            omfn = get_gfn_query_unlocked(d, gfn + i, &t);
+            guest_physmap_remove_page(d, gfn + i, mfn_x(omfn), PAGE_ORDER_4K);
+            continue;
+        }
+
+        if ( rangeset_contains_singleton(mmio_ro_ranges, mfn + i) )
+            a = p2m_access_r;
+        else
+            a = p2m_access_rw;

Shouldn't these two therefore be rx and rwx respectively? Or even better ->default_access in the else case (albeit that doesn't really matter here since nothing can have changed that field from its default value)? I'm particularly thinking of ROMs that may be sitting in these areas.

Jan

#5 lore raw

Re: [PATCH v3 2/3] xen/pvh: check permissions when adding MMIO regions

El 22/01/15 a les 16.43, Jan Beulich ha escrit:

Quoted 29 lines

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn, · line 325

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 16:19, <[email protected]> wrote:
xen/arch/x86/domain_build.c +2 -1
@@ -320,11 +320,24 @@ static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn,
 {
     unsigned long i;
     p2m_access_t a;
+    mfn_t omfn;
+    p2m_type_t t;
     int rc;
 
-    a = p2m_get_hostp2m(d)->default_access;

Iirc this is rwx.

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn, · line 339

Quoted 13 lines
xen/arch/x86/domain_build.c +11 -0
     for ( i = 0; i < nr_mfns; i++ )
     {
+        if ( !iomem_access_permitted(d, mfn + i, mfn + i) )
+        {
+            omfn = get_gfn_query_unlocked(d, gfn + i, &t);
+            guest_physmap_remove_page(d, gfn + i, mfn_x(omfn), PAGE_ORDER_4K);
+            continue;
+        }
+
+        if ( rangeset_contains_singleton(mmio_ro_ranges, mfn + i) )
+            a = p2m_access_r;
+        else
+            a = p2m_access_rw;
Quoted 5 lines

Shouldn't these two therefore be rx and rwx respectively? Or even better ->default_access in the else case (albeit that doesn't really matter here since nothing can have changed that field from its default value)? I'm particularly thinking of ROMs that may be sitting in these areas.

Yes, it should be rx and rwx. I would prefer to use the explicit types. IMHO it's easier to understand to which access type it's set (without having to dig to what value p2m_get_hostp2m(d)->default_access is set).

Roger.

#6 lore raw

Re: [PATCH v3 2/3] xen/pvh: check permissions when adding MMIO regions

Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 12:29, <[email protected]> wrote:

El 22/01/15 a les 16.43, Jan Beulich ha escrit:

Quoted 4 lines

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 16:19, <[email protected]> wrote:
xen/arch/x86/domain_build.c +0 -0
@@ -320,11 +320,24 @@ static __init void pvh_add_mem_mapping(struct domain 

*d, unsigned long gfn,

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/domain_build.c +2 -0
 {
     unsigned long i;
     p2m_access_t a;
+    mfn_t omfn;
+    p2m_type_t t;
     int rc;
 
Quoted 10 lines

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn, · line 325

Quoted 1 line
xen/arch/x86/domain_build.c +0 -1
-    a = p2m_get_hostp2m(d)->default_access;

Iirc this is rwx.

Quoted 6 lines
xen/arch/x86/domain_build.c +4 -0
     for ( i = 0; i < nr_mfns; i++ )
     {
+        if ( !iomem_access_permitted(d, mfn + i, mfn + i) )
+        {
+            omfn = get_gfn_query_unlocked(d, gfn + i, &t);
+            guest_physmap_remove_page(d, gfn + i, mfn_x(omfn), 

PAGE_ORDER_4K);

Quoted 8 lines

xen/arch/x86/domain_build.c static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn, · line 339

Quoted 7 lines
xen/arch/x86/domain_build.c +7 -0
+            continue;
+        }
+
+        if ( rangeset_contains_singleton(mmio_ro_ranges, mfn + i) )
+            a = p2m_access_r;
+        else
+            a = p2m_access_rw;
Quoted 5 lines

Shouldn't these two therefore be rx and rwx respectively? Or even better ->default_access in the else case (albeit that doesn't really matter here since nothing can have changed that field from its default value)? I'm particularly thinking of ROMs that may be sitting in these areas.

Quoted 3 lines

Yes, it should be rx and rwx. I would prefer to use the explicit types. IMHO it's easier to understand to which access type it's set (without having to dig to what value p2m_get_hostp2m(d)->default_access is set).

That's fine then.

Jan

#7 lore raw

Re: [PATCH v3 2/3] xen/pvh: check permissions when adding MMIO regions

In reply to Roger Pau Monne
Quoted 2 lines · Roger Pau Monne

Check that MMIO regions added to PVH Dom0 are allowed. Previously a PVH Dom0 would have access to the full MMIO range.

How do we do this for normal PV dom0? Do we enforce the same restriction? If not, should we ?

Quoted 53 lines
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---
Changes since v2:
- Fix coding style.

Changes since v1:
- Use the newly introduced p2m_access_t to set the access type.
- Don't add a next label.

---
 xen/arch/x86/domain_build.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
xen/arch/x86/domain_build.c +14 -1
index 01cfa58..76722f7 100644
@@ -320,11 +320,24 @@ static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn,
 {
     unsigned long i;
     p2m_access_t a;
+    mfn_t omfn;
+    p2m_type_t t;
     int rc;
 
-    a = p2m_get_hostp2m(d)->default_access;
     for ( i = 0; i < nr_mfns; i++ )
     {
+        if ( !iomem_access_permitted(d, mfn + i, mfn + i) )
+        {
+            omfn = get_gfn_query_unlocked(d, gfn + i, &t);
+            guest_physmap_remove_page(d, gfn + i, mfn_x(omfn), PAGE_ORDER_4K);
+            continue;
+        }
+
+        if ( rangeset_contains_singleton(mmio_ro_ranges, mfn + i) )
+            a = p2m_access_r;
+        else
+            a = p2m_access_rw;
+
         if ( (rc = set_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i), a)) )
             panic("pvh_add_mem_mapping: gfn:%lx mfn:%lx i:%ld rc:%d\n",
                   gfn, mfn, i, rc);
Signature · 7 lines
1.9.3 (Apple Git-50)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#8 lore raw

Re: [PATCH v3 2/3] xen/pvh: check permissions when adding MMIO regions

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 21:28, <[email protected]> wrote:
Quoted 2 lines · Roger Pau Monne

Check that MMIO regions added to PVH Dom0 are allowed. Previously a PVH Dom0 would have access to the full MMIO range.

How do we do this for normal PV dom0? Do we enforce the same restriction?

We do, at the MMU level at least. Thing is (see an earlier reply, maybe on Elena's thread) that we may still be too lax.

Jan

#9 lore raw

Re: [PATCH v3 2/3] xen/pvh: check permissions when adding MMIO regions

Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 21:28, <[email protected]> wrote:
Quoted 2 lines · Roger Pau Monne

Check that MMIO regions added to PVH Dom0 are allowed. Previously a PVH Dom0 would have access to the full MMIO range.

How do we do this for normal PV dom0? Do we enforce the same restriction?

We do, at the MMU level at least. Thing is (see an earlier reply, maybe on Elena's thread) that we may still be too lax.

Looking at vtd_set_hwdom_mapping looks to be having quite simplified mechanism for PV. This is of course for those weird devices that do DMA operations behind the OS'es back.

If we go that route we would probablly need logic in there to change too - otherwise we have .. Ah, this is where Tim's idea of having a guest just having an flag of 'I_need_IOMMU' would be so nice and having only one code-path that could be used for both PV and PVH.

Quoted 3 lines

Jan

#10 lore raw

PATCH v3 3/3 xen: prevent access to HPET from Dom0

In reply to Roger Pau Monne

Prevent Dom0 from accessing HPET MMIO region by adding the HPET mfn to the list of forbiden memory regions (if ACPI_HPET_PAGE_PROTECT4 flag is set) or to the list of read-only regions.

Also provide an option that prevents adding the HPET to the read-only memory regions called ro-hpet, in case there are systems that put other stuff in the HPET page.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---
Changes since v2:
- Don't map the HPET page at all if ACPI_HPET_PAGE_PROTECT4 is found.
- Provide an option (ro-hpet) that prevents adding the HPET page to the list of read-only memory regions.

Changes since v1:
- Instead of completely blocking access to the HPET mfn, set it as read-only.

---
 docs/misc/xen-command-line.markdown |  8 ++++++++
 xen/arch/x86/acpi/boot.c            |  1 +
 xen/arch/x86/domain_build.c         | 14 ++++++++++++++
 xen/arch/x86/hpet.c                 |  1 +
 xen/include/asm-x86/hpet.h          |  1 +
 5 files changed, 25 insertions(+)
docs/misc/xen-command-line.markdown +8 -0
index a061aa4..e87eef4 100644
@@ -1380,3 +1380,11 @@ Use the x2apic physical apic driver.  The alternative is the x2apic cluster driv
 > Default: `true`
 
 Permit use of the `xsave/xrstor` instructions.
+
+### ro-hpet
+> `= <boolean>`
+
+> Default: `true`
+
+Map the HPET page as read only in Dom0. If disabled the page will be mapped
+with read and write permissions.
xen/arch/x86/acpi/boot.c +1 -0
index 903830b..9a8904b 100644
@@ -309,6 +309,7 @@ static int __init acpi_parse_hpet(struct acpi_table_header *table)
 
 	hpet_address = hpet_tbl->address.address;
 	hpet_blockid = hpet_tbl->sequence;
+	hpet_flags = hpet_tbl->flags;
 	printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
 	       hpet_tbl->id, hpet_address);
 
xen/arch/x86/domain_build.c +14 -0
index 76722f7..85c47cc 100644
@@ -36,6 +36,7 @@
 #include <asm/bzimage.h> /* for bzimage_parse */
 #include <asm/io_apic.h>
 #include <asm/hap.h>
+#include <asm/hpet.h> /* for hpet_address */
 
 #include <public/version.h>
 
@@ -134,6 +135,9 @@ boolean_param("dom0_shadow", opt_dom0_shadow);
 static char __initdata opt_dom0_ioports_disable[200] = "";
 string_param("dom0_ioports_disable", opt_dom0_ioports_disable);
 
+static bool_t __initdata ro_hpet = 1;
+boolean_param("ro-hpet", ro_hpet);
+
 /* Allow ring-3 access in long mode as guest cannot use ring 1 ... */
 #define BASE_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
 #define L1_PROT (BASE_PROT|_PAGE_GUEST_KERNEL)
@@ -1495,6 +1499,16 @@ int __init construct_dom0(
             rc |= iomem_deny_access(d, sfn, efn);
     }
 
+    /* Prevent access to HPET */
+    if ( hpet_address != 0 )
+    {
+        mfn = paddr_to_pfn(hpet_address);
+        if ( hpet_flags & ACPI_HPET_PAGE_PROTECT4 )
+            rc |= iomem_deny_access(d, mfn, mfn);
+        else if ( ro_hpet )
+            rc |= rangeset_add_singleton(mmio_ro_ranges, mfn);
+    }
+
     BUG_ON(rc != 0);
 
     if ( elf_check_broken(&elf) )
xen/arch/x86/hpet.c +1 -0
index 0b13f52..7aa740f 100644
@@ -52,6 +52,7 @@ DEFINE_PER_CPU(struct hpet_event_channel *, cpu_bc_channel);
 
 unsigned long __initdata hpet_address;
 u8 __initdata hpet_blockid;
+u8 __initdata hpet_flags;
 
 /*
  * force_hpet_broadcast: by default legacy hpet broadcast will be stopped
xen/include/asm-x86/hpet.h +1 -0
index 875f1de..10c4a56 100644
@@ -52,6 +52,7 @@
 
 extern unsigned long hpet_address;
 extern u8 hpet_blockid;
+extern u8 hpet_flags;
 
 /*
  * Detect and initialise HPET hardware: return counter update frequency.
Signature · 7 lines
1.9.3 (Apple Git-50)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH v3 3/3] xen: prevent access to HPET from Dom0

xen/arch/x86/domain_build.c line 39

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 16:19, <[email protected]> wrote:
xen/arch/x86/domain_build.c +1 -0
@@ -36,6 +36,7 @@
 #include <asm/bzimage.h> /* for bzimage_parse */
 #include <asm/io_apic.h>
 #include <asm/hap.h>
+#include <asm/hpet.h> /* for hpet_address */

Please drop the comment - with hpet_flags it's now stale

xen/arch/x86/domain_build.c int __init construct_dom0( · line 1506

Quoted 9 lines
xen/arch/x86/domain_build.c +5 -0
@@ -1495,6 +1499,16 @@ int __init construct_dom0(
             rc |= iomem_deny_access(d, sfn, efn);
     }
 
+    /* Prevent access to HPET */
+    if ( hpet_address != 0 )
+    {
+        mfn = paddr_to_pfn(hpet_address);
+        if ( hpet_flags & ACPI_HPET_PAGE_PROTECT4 )

The constant isn't a binary mask, you need to also use ACPI_HPET_PAGE_PROTECT_MASK. I further can't see why you wouldn't want to also handle ACPI_HPET_PAGE_PROTECT64.

Jan

#12 lore raw

Re: [PATCH v3 3/3] xen: prevent access to HPET from Dom0

El 22/01/15 a les 16.47, Jan Beulich ha escrit:

Quoted 15 lines

xen/arch/x86/domain_build.c line 39

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 16:19, <[email protected]> wrote:
xen/arch/x86/domain_build.c +1 -0
@@ -36,6 +36,7 @@
 #include <asm/bzimage.h> /* for bzimage_parse */
 #include <asm/io_apic.h>
 #include <asm/hap.h>
+#include <asm/hpet.h> /* for hpet_address */

Please drop the comment - with hpet_flags it's now stale

Quoted 4 lines
xen/arch/x86/domain_build.c +0 -0
@@ -1495,6 +1499,16 @@ int __init construct_dom0(
             rc |= iomem_deny_access(d, sfn, efn);
     }
 
Quoted 9 lines

xen/arch/x86/domain_build.c int __init construct_dom0( · line 1506

Quoted 5 lines
xen/arch/x86/domain_build.c +5 -0
+    /* Prevent access to HPET */
+    if ( hpet_address != 0 )
+    {
+        mfn = paddr_to_pfn(hpet_address);
+        if ( hpet_flags & ACPI_HPET_PAGE_PROTECT4 )

The constant isn't a binary mask, you need to also use ACPI_HPET_PAGE_PROTECT_MASK. I further can't see why you wouldn't want to also handle ACPI_HPET_PAGE_PROTECT64.

Right, for PAGE_PROTECT64 we can also block access to the adjacent 15 pages.

Roger.