Re: [Xen-devel] [RFC XEN PATCH v3 08/39] xen/pmem: hide NFIT and deny access to PMEM from Dom0

2017-11-03 Thread Haozhong Zhang
On 11/03/17 14:51 +0800, Chao Peng wrote:
> On Mon, 2017-09-11 at 12:37 +0800, Haozhong Zhang wrote:
> > ... to avoid the inference with the PMEM driver and management
> > utilities in Dom0.
> > 
> > Signed-off-by: Haozhong Zhang 
> > ---
> > Cc: Jan Beulich 
> > Cc: Andrew Cooper 
> > Cc: Gang Wei 
> > Cc: Shane Wang 
> > ---
> >  xen/arch/x86/acpi/power.c |  7 +++
> >  xen/arch/x86/dom0_build.c |  5 +
> >  xen/arch/x86/shutdown.c   |  3 +++
> >  xen/arch/x86/tboot.c  |  4 
> >  xen/common/kexec.c|  3 +++
> >  xen/common/pmem.c | 21 +
> >  xen/drivers/acpi/nfit.c   | 21 +
> >  xen/include/xen/acpi.h|  2 ++
> >  xen/include/xen/pmem.h| 13 +
> >  9 files changed, 79 insertions(+)
> > 
> > diff --git a/xen/arch/x86/acpi/power.c b/xen/arch/x86/acpi/power.c
> > index 1e4e5680a7..d135715a49 100644
> > --- a/xen/arch/x86/acpi/power.c
> > +++ b/xen/arch/x86/acpi/power.c
> > @@ -178,6 +178,10 @@ static int enter_state(u32 state)
> >  
> >  freeze_domains();
> >  
> > +#ifdef CONFIG_NVDIMM_PMEM
> > +acpi_nfit_reinstate();
> > +#endif
> 
> I don't understand why reinstate is needed for NFIT table? Will it  be
> searched by firmware on shutdown / entering power state?

I added these acpi_nfit_reinstate()'s akin to acpi_dmar_reinstate().
There is not public documents stating NFIT is not rebuilt during power
state changes.

Haozhong

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [RFC XEN PATCH v3 08/39] xen/pmem: hide NFIT and deny access to PMEM from Dom0

2017-11-03 Thread Chao Peng
On Mon, 2017-09-11 at 12:37 +0800, Haozhong Zhang wrote:
> ... to avoid the inference with the PMEM driver and management
> utilities in Dom0.
> 
> Signed-off-by: Haozhong Zhang 
> ---
> Cc: Jan Beulich 
> Cc: Andrew Cooper 
> Cc: Gang Wei 
> Cc: Shane Wang 
> ---
>  xen/arch/x86/acpi/power.c |  7 +++
>  xen/arch/x86/dom0_build.c |  5 +
>  xen/arch/x86/shutdown.c   |  3 +++
>  xen/arch/x86/tboot.c  |  4 
>  xen/common/kexec.c|  3 +++
>  xen/common/pmem.c | 21 +
>  xen/drivers/acpi/nfit.c   | 21 +
>  xen/include/xen/acpi.h|  2 ++
>  xen/include/xen/pmem.h| 13 +
>  9 files changed, 79 insertions(+)
> 
> diff --git a/xen/arch/x86/acpi/power.c b/xen/arch/x86/acpi/power.c
> index 1e4e5680a7..d135715a49 100644
> --- a/xen/arch/x86/acpi/power.c
> +++ b/xen/arch/x86/acpi/power.c
> @@ -178,6 +178,10 @@ static int enter_state(u32 state)
>  
>  freeze_domains();
>  
> +#ifdef CONFIG_NVDIMM_PMEM
> +acpi_nfit_reinstate();
> +#endif

I don't understand why reinstate is needed for NFIT table? Will it  be
searched by firmware on shutdown / entering power state?

Chao

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC XEN PATCH v3 08/39] xen/pmem: hide NFIT and deny access to PMEM from Dom0

2017-09-10 Thread Haozhong Zhang
... to avoid the inference with the PMEM driver and management
utilities in Dom0.

Signed-off-by: Haozhong Zhang 
---
Cc: Jan Beulich 
Cc: Andrew Cooper 
Cc: Gang Wei 
Cc: Shane Wang 
---
 xen/arch/x86/acpi/power.c |  7 +++
 xen/arch/x86/dom0_build.c |  5 +
 xen/arch/x86/shutdown.c   |  3 +++
 xen/arch/x86/tboot.c  |  4 
 xen/common/kexec.c|  3 +++
 xen/common/pmem.c | 21 +
 xen/drivers/acpi/nfit.c   | 21 +
 xen/include/xen/acpi.h|  2 ++
 xen/include/xen/pmem.h| 13 +
 9 files changed, 79 insertions(+)

diff --git a/xen/arch/x86/acpi/power.c b/xen/arch/x86/acpi/power.c
index 1e4e5680a7..d135715a49 100644
--- a/xen/arch/x86/acpi/power.c
+++ b/xen/arch/x86/acpi/power.c
@@ -178,6 +178,10 @@ static int enter_state(u32 state)
 
 freeze_domains();
 
+#ifdef CONFIG_NVDIMM_PMEM
+acpi_nfit_reinstate();
+#endif
+
 acpi_dmar_reinstate();
 
 if ( (error = disable_nonboot_cpus()) )
@@ -260,6 +264,9 @@ static int enter_state(u32 state)
 mtrr_aps_sync_end();
 adjust_vtd_irq_affinities();
 acpi_dmar_zap();
+#ifdef CONFIG_NVDIMM_PMEM
+acpi_nfit_zap();
+#endif
 thaw_domains();
 system_state = SYS_STATE_active;
 spin_unlock(_lock);
diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c
index f616b99ddc..10741e865a 100644
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -452,6 +453,10 @@ int __init dom0_setup_permissions(struct domain *d)
 rc |= rangeset_add_singleton(mmio_ro_ranges, mfn);
 }
 
+#ifdef CONFIG_NVDIMM_PMEM
+rc |= pmem_dom0_setup_permission(d);
+#endif
+
 return rc;
 }
 
diff --git a/xen/arch/x86/shutdown.c b/xen/arch/x86/shutdown.c
index a87aa60add..1902dfe73e 100644
--- a/xen/arch/x86/shutdown.c
+++ b/xen/arch/x86/shutdown.c
@@ -550,6 +550,9 @@ void machine_restart(unsigned int delay_millisecs)
 
 if ( tboot_in_measured_env() )
 {
+#ifdef CONFIG_NVDIMM_PMEM
+acpi_nfit_reinstate();
+#endif
 acpi_dmar_reinstate();
 tboot_shutdown(TB_SHUTDOWN_REBOOT);
 }
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index 59d7c477f4..24e3b81ff1 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -488,6 +488,10 @@ int __init tboot_parse_dmar_table(acpi_table_handler 
dmar_handler)
 /* but dom0 will read real table, so must zap it there too */
 acpi_dmar_zap();
 
+#ifdef CONFIG_NVDIMM_PMEM
+acpi_nfit_zap();
+#endif
+
 return rc;
 }
 
diff --git a/xen/common/kexec.c b/xen/common/kexec.c
index fcc68bd4d8..c8c6138e71 100644
--- a/xen/common/kexec.c
+++ b/xen/common/kexec.c
@@ -366,6 +366,9 @@ static int kexec_common_shutdown(void)
 watchdog_disable();
 console_start_sync();
 spin_debug_disable();
+#ifdef CONFIG_NVDIMM_PMEM
+acpi_nfit_reinstate();
+#endif
 acpi_dmar_reinstate();
 
 return 0;
diff --git a/xen/common/pmem.c b/xen/common/pmem.c
index 49648222a6..c9f5f6e904 100644
--- a/xen/common/pmem.c
+++ b/xen/common/pmem.c
@@ -18,6 +18,8 @@
 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 /*
@@ -128,3 +130,22 @@ int pmem_register(unsigned long smfn, unsigned long emfn, 
unsigned int pxm)
 
 return rc;
 }
+
+#ifdef CONFIG_X86
+
+int __init pmem_dom0_setup_permission(struct domain *d)
+{
+struct list_head *cur;
+struct pmem *pmem;
+int rc = 0;
+
+list_for_each(cur, _raw_regions)
+{
+pmem = list_entry(cur, struct pmem, link);
+rc |= iomem_deny_access(d, pmem->smfn, pmem->emfn - 1);
+}
+
+return rc;
+}
+
+#endif /* CONFIG_X86 */
diff --git a/xen/drivers/acpi/nfit.c b/xen/drivers/acpi/nfit.c
index 68750c2edc..5f34cf2464 100644
--- a/xen/drivers/acpi/nfit.c
+++ b/xen/drivers/acpi/nfit.c
@@ -179,6 +179,24 @@ static void __init acpi_nfit_register_pmem(struct 
acpi_nfit_desc *desc)
 }
 }
 
+void acpi_nfit_zap(void)
+{
+uint32_t sig = 0x4e494654; /* "TFIN" */
+
+if ( nfit_desc.acpi_table )
+write_atomic((uint32_t *)_desc.acpi_table->header.signature[0],
+ sig);
+}
+
+void acpi_nfit_reinstate(void)
+{
+uint32_t sig = 0x5449464e; /* "NFIT" */
+
+if ( nfit_desc.acpi_table )
+write_atomic((uint32_t *)_desc.acpi_table->header.signature[0],
+ sig);
+}
+
 void __init acpi_nfit_boot_init(void)
 {
 acpi_status status;
@@ -193,6 +211,9 @@ void __init acpi_nfit_boot_init(void)
 map_pages_to_xen((unsigned long)nfit_desc.acpi_table, PFN_DOWN(nfit_addr),
  PFN_UP(nfit_addr + nfit_len) - PFN_DOWN(nfit_addr),
  PAGE_HYPERVISOR);
+
+/* Hide NFIT from Dom0. */
+acpi_nfit_zap();
 }
 
 void __init acpi_nfit_init(void)
diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h
index