Skip to contentSkip to conversation

PVH VCPU hotplug support

PATCH Superseded Boris Ostrovsky 7 participants 37 messages Nov 6, 2016 – Nov 8, 2016

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover PVH VCPU hotplug support

This series adds support for ACPI-based VCPU hotplug for unprivileged PVH guests.

New XEN_DOMCTL_set_avail_vcpus is introduced and is called during guest creation and in response to 'xl vcpu-set' command. This domctl updates GPE0's status and enable registers and sends an SCI to the guest using (newly added) VIRQ_SCI.

Boris Ostrovsky (10):
x86/domctl: Add XEN_DOMCTL_set_avail_vcpus
acpi: Define ACPI IO registers for PVH guests
pvh: Set online VCPU map to avail_vcpus
acpi: Power and Sleep ACPI buttons are not emulated
acpi: Make pmtimer optional in FADT
acpi: PVH guests need _E02 method
pvh/ioreq: Install handlers for ACPI-related PVH IO accesses pvh/acpi: Handle ACPI accesses for PVH guests events/x86: Define SCI virtual interrupt
pvh: Send an SCI on VCPU hotplug event

 tools/firmware/hvmloader/util.c       |  3 +-
 tools/flask/policy/modules/dom0.te    |  2 +-
 tools/flask/policy/modules/xen.if     |  4 +-
 tools/libacpi/build.c                 |  5 +++
 tools/libacpi/libacpi.h               |  1 +
 tools/libacpi/mk_dsdt.c               | 10 ++---
 tools/libacpi/static_tables.c         | 31 ++++++-------
 tools/libxc/include/xenctrl.h         |  5 +++
 tools/libxc/xc_dom_x86.c              | 14 ++++++
 tools/libxl/libxl.c                   | 10 ++++-
 tools/libxl/libxl_arch.h              |  4 ++
 tools/libxl/libxl_arm.c               |  6 +++
 tools/libxl/libxl_dom.c               |  7 +++
 tools/libxl/libxl_x86.c               |  6 +++
 tools/libxl/libxl_x86_acpi.c          |  6 +--
 xen/arch/x86/domctl.c                 | 25 +++++++++++
 xen/arch/x86/hvm/hvm.c                | 13 ++++--
 xen/arch/x86/hvm/ioreq.c              | 83 +++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/domain.h          |  6 +++
 xen/include/asm-x86/event.h           |  3 +-
 xen/include/asm-x86/hvm/domain.h      |  6 +++
 xen/include/asm-x86/hvm/ioreq.h       |  1 +
 xen/include/public/arch-x86/xen-mca.h |  2 -
 xen/include/public/arch-x86/xen.h     |  3 ++
 xen/include/public/domctl.h           |  9 ++++
 xen/include/public/hvm/ioreq.h        |  3 ++
 xen/xsm/flask/hooks.c                 |  3 ++
 xen/xsm/flask/policy/access_vectors   |  2 +
 28 files changed, 235 insertions(+), 38 deletions(-)
Signature · 7 lines
2.7.4


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

PATCH 1/10 x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

This domctl is called when a VCPU is hot-(un)plugged to a guest (via 'xl vcpu-set'). While this currently is only intended to be needed by PVH guests we will call this domctl for all (x86) guests for consistency.

---
CC: Daniel De Graaf <[email protected]>

---
 tools/flask/policy/modules/dom0.te  |  2 +-
 tools/flask/policy/modules/xen.if   |  4 ++--
 tools/libxc/include/xenctrl.h       |  5 +++++
 tools/libxc/xc_dom_x86.c            | 11 +++++++++++
 tools/libxl/libxl.c                 | 10 +++++++++-
 tools/libxl/libxl_arch.h            |  4 ++++
 tools/libxl/libxl_arm.c             |  6 ++++++
 tools/libxl/libxl_dom.c             |  7 +++++++
 tools/libxl/libxl_x86.c             |  6 ++++++
 xen/arch/x86/domctl.c               | 13 +++++++++++++
 xen/include/asm-x86/domain.h        |  6 ++++++
 xen/include/public/domctl.h         |  9 +++++++++
 xen/xsm/flask/hooks.c               |  3 +++
 xen/xsm/flask/policy/access_vectors |  2 ++
 14 files changed, 84 insertions(+), 4 deletions(-)
tools/flask/policy/modules/dom0.te +1 -1
index 2d982d9..fd60c39 100644
@@ -38,7 +38,7 @@ allow dom0_t dom0_t:domain {
 };
 allow dom0_t dom0_t:domain2 {
 	set_cpuid gettsc settsc setscheduler set_max_evtchn set_vnumainfo
-	get_vnumainfo psr_cmt_op psr_cat_op
+	get_vnumainfo psr_cmt_op psr_cat_op set_avail_vcpus
 };
 allow dom0_t dom0_t:resource { add remove };
 
tools/flask/policy/modules/xen.if +2 -2
index d83f031..0ac4c5b 100644
@@ -52,7 +52,7 @@ define(`create_domain_common', `
 			settime setdomainhandle };
 	allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim
 			set_max_evtchn set_vnumainfo get_vnumainfo cacheflush
-			psr_cmt_op psr_cat_op soft_reset };
+			psr_cmt_op psr_cat_op soft_reset set_avail_vcpus};
 	allow $1 $2:security check_context;
 	allow $1 $2:shadow enable;
 	allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };
@@ -85,7 +85,7 @@ define(`manage_domain', `
 			getaddrsize pause unpause trigger shutdown destroy
 			setaffinity setdomainmaxmem getscheduler resume
 			setpodtarget getpodtarget };
-    allow $1 $2:domain2 set_vnumainfo;
+    allow $1 $2:domain2 { set_vnumainfo set_avail_vcpus };
 ')
 
 # migrate_domain_out(priv, target)
tools/libxc/include/xenctrl.h +5 -0
index 2c83544..49e9b9f 100644
@@ -1256,6 +1256,11 @@ int xc_domain_getvnuma(xc_interface *xch,
 int xc_domain_soft_reset(xc_interface *xch,
                          uint32_t domid);
 
+int xc_domain_set_avail_vcpus(xc_interface *xch,
+                              uint32_t domid,
+                              unsigned int num_vcpus);
+
+
 #if defined(__i386__) || defined(__x86_64__)
 /*
  * PC BIOS standard E820 types and structure.
tools/libxc/xc_dom_x86.c +11 -0
index 0eab8a7..7fcdee1 100644
@@ -125,6 +125,17 @@ const char *xc_domain_get_native_protocol(xc_interface *xch,
     return protocol;
 }
 
+int xc_domain_set_avail_vcpus(xc_interface *xch,
+                              uint32_t domid,
+                              unsigned int num_vcpus)
+{
+    DECLARE_DOMCTL;
+    domctl.cmd = XEN_DOMCTL_set_avail_vcpus;
+    domctl.domain = (domid_t)domid;
+    domctl.u.avail_vcpus.num = num_vcpus;
+    return do_domctl(xch, &domctl);
+}
+
 static int count_pgtables(struct xc_dom_image *dom, xen_vaddr_t from,
                           xen_vaddr_t to, xen_pfn_t pfn)
 {
tools/libxl/libxl.c +9 -1
index 33c5e4c..9b94413 100644
@@ -5148,11 +5148,12 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)
     case LIBXL_DOMAIN_TYPE_HVM:
         switch (libxl__device_model_version_running(gc, domid)) {
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
-        case LIBXL_DEVICE_MODEL_VERSION_NONE:
             rc = libxl__set_vcpuonline_xenstore(gc, domid, cpumap, &info);
             break;
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
             rc = libxl__set_vcpuonline_qmp(gc, domid, cpumap, &info);
+            /* fallthrough */
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
             break;
         default:
             rc = ERROR_INVAL;
@@ -5164,6 +5165,13 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)
     default:
         rc = ERROR_INVAL;
     }
+
+    if (!rc) {
+        rc = libxl__arch_set_vcpuonline(ctx, domid, maxcpus);
+        if (rc)
+            LOG(ERROR, "Couldn't set available vcpu count");
+    }
+
 out:
     libxl_dominfo_dispose(&info);
     GC_FREE;
tools/libxl/libxl_arch.h +4 -0
index 5e1fc60..33b5e12 100644
@@ -71,6 +71,10 @@ int libxl__arch_extra_memory(libxl__gc *gc,
                              const libxl_domain_build_info *info,
                              uint64_t *out);
 
+_hidden
+int libxl__arch_set_vcpuonline(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int vcpu_num);
+
 #if defined(__i386__) || defined(__x86_64__)
 
 #define LAPIC_BASE_ADDRESS  0xfee00000
tools/libxl/libxl_arm.c +6 -0
index d842d88..18c79b0 100644
@@ -1065,6 +1065,12 @@ void libxl__arch_domain_build_info_acpi_setdefault(
     libxl_defbool_setdefault(&b_info->acpi, false);
 }
 
+int libxl__arch_set_vcpuonline(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int vcpu_num)
+{
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_dom.c +7 -0
index d519c8d..e6e94bb 100644
@@ -309,6 +309,13 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
         return ERROR_FAIL;
     }
 
+    rc = libxl__arch_set_vcpuonline(ctx, domid,
+                                    libxl_bitmap_count_set(&info->avail_vcpus));
+    if (rc) {
+        LOG(ERROR, "Couldn't set available vcpu count (error %d)", rc);
+        return ERROR_FAIL;
+    }
+
     /*
      * Check if the domain has any CPU or node affinity already. If not, try
      * to build up the latter via automatic NUMA placement. In fact, in case
tools/libxl/libxl_x86.c +6 -0
index e1844c8..3a5264d 100644
@@ -588,6 +588,12 @@ void libxl__arch_domain_build_info_acpi_setdefault(
     libxl_defbool_setdefault(&b_info->acpi, true);
 }
 
+int libxl__arch_set_vcpuonline(libxl_ctx *ctx, uint32_t domid,
+                               unsigned int vcpu_num)
+{
+    return xc_domain_set_avail_vcpus(ctx->xch, domid, vcpu_num);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/domctl.c +13 -0
index 2a2fe04..78b7d4b 100644
@@ -1430,6 +1430,19 @@ long arch_do_domctl(
         }
         break;
 
+    case XEN_DOMCTL_set_avail_vcpus:
+    {
+        unsigned int num = domctl->u.avail_vcpus.num;
+
+        ret = -EINVAL;
+        if ( num > d->max_vcpus )
+            break;
+
+        d->arch.avail_vcpus = num;
+        ret = 0;
+        break;
+    }
+
     default:
         ret = iommu_do_domctl(domctl, d, u_domctl);
         break;
xen/include/asm-x86/domain.h +6 -0
index f6a40eb..a279e4a 100644
@@ -414,6 +414,12 @@ struct arch_domain
 
     /* Emulated devices enabled bitmap. */
     uint32_t emulation_flags;
+
+    /*
+     * Number of VCPUs that were online during guest creation
+     * plus/minus any hot-(un)plugged VCPUs.
+     */
+    unsigned int     avail_vcpus;
 } __cacheline_aligned;
 
 #define has_vlapic(d)      (!!((d)->arch.emulation_flags & XEN_X86_EMU_LAPIC))
xen/include/public/domctl.h +9 -0
index 177319d..f114645 100644
@@ -1010,6 +1010,13 @@ struct xen_domctl_vcpu_msrs {
 };
 typedef struct xen_domctl_vcpu_msrs xen_domctl_vcpu_msrs_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_vcpu_msrs_t);
+
+/* XEN_DOMCTL_avail_vcpus */
+struct xen_domctl_avail_vcpus {
+    uint32_t num; /* available number of vcpus */
+};
+typedef struct xen_domctl_avail_vcpus xen_domctl_avail_vcpus_t;
+DEFINE_XEN_GUEST_HANDLE(xen_domctl_avail_vcpus_t);
 #endif
 
 /* XEN_DOMCTL_setvnumainfo: specifies a virtual NUMA topology for the guest */
@@ -1221,6 +1228,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_monitor_op                    77
 #define XEN_DOMCTL_psr_cat_op                    78
 #define XEN_DOMCTL_soft_reset                    79
+#define XEN_DOMCTL_set_avail_vcpus               80
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
@@ -1269,6 +1277,7 @@ struct xen_domctl {
         struct xen_domctl_cpuid             cpuid;
         struct xen_domctl_vcpuextstate      vcpuextstate;
         struct xen_domctl_vcpu_msrs         vcpu_msrs;
+        struct xen_domctl_avail_vcpus       avail_vcpus;
 #endif
         struct xen_domctl_set_access_required access_required;
         struct xen_domctl_audit_p2m         audit_p2m;
xen/xsm/flask/hooks.c +3 -0
index 177c11f..377549a 100644
@@ -748,6 +748,9 @@ static int flask_domctl(struct domain *d, int cmd)
     case XEN_DOMCTL_soft_reset:
         return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SOFT_RESET);
 
+    case XEN_DOMCTL_set_avail_vcpus:
+        return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_AVAIL_VCPUS);
+
     default:
         return avc_unknown_permission("domctl", cmd);
     }
xen/xsm/flask/policy/access_vectors +2 -0
index 49c9a9e..f8a5e6c 100644
@@ -244,6 +244,8 @@ class domain2
     mem_sharing
 # XEN_DOMCTL_psr_cat_op
     psr_cat_op
+# XEN_DOMCTL_set_avail_vcpus
+    set_avail_vcpus
 }
 
 # Similar to class domain, but primarily contains domctls related to HVM domains
Signature · 7 lines
2.7.4


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

Re: [PATCH 01/10] x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

Quoted 3 lines · Boris Ostrovsky

This domctl is called when a VCPU is hot-(un)plugged to a guest (via 'xl vcpu-set'). While this currently is only intended to be needed by PVH guests we will call this domctl for all (x86) guests for consistency.

In light of that perhaps the change in domctl.h should also include this comment?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH 01/10] x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Boris Ostrovsky

This domctl is called when a VCPU is hot-(un)plugged to a guest (via 'xl vcpu-set'). While this currently is only intended to be needed by PVH guests we will call this domctl for all (x86) guests for consistency.

In light of that perhaps the change in domctl.h should also include this comment?

This is part of the interface so I am not sure whether use cases belong in public headers. domctl.c may be a better place.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v1 1/10
#4 lore raw

Re: [PATCH 01/10] x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

In reply to Boris Ostrovsky
Quoted 5 lines · Boris Ostrovsky

This domctl is called when a VCPU is hot-(un)plugged to a guest (via 'xl vcpu-set'). While this currently is only intended to be needed by PVH guests we will call this domctl for all (x86) guests for consistency.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH 2/10 acpi: Define ACPI IO registers for PVH guests

In reply to Boris Ostrovsky

ACPI hotplug-related IO accesses (to GPE0 block) are handled by qemu for HVM guests. Since PVH guests don't have qemu these accesses will need to be procesed by the hypervisor.

Because ACPI event model expects pm1a block to be present we need to have the hypervisor emulate it as well.

---
 tools/libacpi/static_tables.c    | 28 +++++++++++-----------------
 xen/include/asm-x86/hvm/domain.h |  6 ++++++
 xen/include/public/hvm/ioreq.h   |  3 +++
 3 files changed, 20 insertions(+), 17 deletions(-)
tools/libacpi/static_tables.c +11 -17
index 617bf68..413abcc 100644
@@ -20,6 +20,8 @@
  * Firmware ACPI Control Structure (FACS).
  */
 
+#define ACPI_REG_BIT_OFFSET    0
+
 struct acpi_20_facs Facs = {
     .signature = ACPI_2_0_FACS_SIGNATURE,
     .length    = sizeof(struct acpi_20_facs),
@@ -30,14 +32,6 @@ struct acpi_20_facs Facs = {
 /*
  * Fixed ACPI Description Table (FADT).
  */
-
-#define ACPI_PM1A_EVT_BLK_BIT_WIDTH         0x20
-#define ACPI_PM1A_EVT_BLK_BIT_OFFSET        0x00
-#define ACPI_PM1A_CNT_BLK_BIT_WIDTH         0x10
-#define ACPI_PM1A_CNT_BLK_BIT_OFFSET        0x00
-#define ACPI_PM_TMR_BLK_BIT_WIDTH           0x20
-#define ACPI_PM_TMR_BLK_BIT_OFFSET          0x00
-
 struct acpi_20_fadt Fadt = {
     .header = {
         .signature    = ACPI_2_0_FADT_SIGNATURE,
@@ -56,9 +50,9 @@ struct acpi_20_fadt Fadt = {
     .pm1a_cnt_blk = ACPI_PM1A_CNT_BLK_ADDRESS_V1,
     .pm_tmr_blk = ACPI_PM_TMR_BLK_ADDRESS_V1,
     .gpe0_blk = ACPI_GPE0_BLK_ADDRESS_V1,
-    .pm1_evt_len = ACPI_PM1A_EVT_BLK_BIT_WIDTH / 8,
-    .pm1_cnt_len = ACPI_PM1A_CNT_BLK_BIT_WIDTH / 8,
-    .pm_tmr_len = ACPI_PM_TMR_BLK_BIT_WIDTH / 8,
+    .pm1_evt_len = ACPI_PM1A_EVT_BLK_LEN,
+    .pm1_cnt_len = ACPI_PM1A_CNT_BLK_LEN,
+    .pm_tmr_len = ACPI_PM_TMR_BLK_LEN,
     .gpe0_blk_len = ACPI_GPE0_BLK_LEN_V1,
 
     .p_lvl2_lat = 0x0fff, /* >100,  means we do not support C2 state */
@@ -79,22 +73,22 @@ struct acpi_20_fadt Fadt = {
 
     .x_pm1a_evt_blk = {
         .address_space_id    = ACPI_SYSTEM_IO,
-        .register_bit_width  = ACPI_PM1A_EVT_BLK_BIT_WIDTH,
-        .register_bit_offset = ACPI_PM1A_EVT_BLK_BIT_OFFSET,
+        .register_bit_width  = ACPI_PM1A_EVT_BLK_LEN * 8,
+        .register_bit_offset = ACPI_REG_BIT_OFFSET,
         .address             = ACPI_PM1A_EVT_BLK_ADDRESS_V1,
     },
 
     .x_pm1a_cnt_blk = {
         .address_space_id    = ACPI_SYSTEM_IO,
-        .register_bit_width  = ACPI_PM1A_CNT_BLK_BIT_WIDTH,
-        .register_bit_offset = ACPI_PM1A_CNT_BLK_BIT_OFFSET,
+        .register_bit_width  = ACPI_PM1A_CNT_BLK_LEN * 8,
+        .register_bit_offset = ACPI_REG_BIT_OFFSET,
         .address             = ACPI_PM1A_CNT_BLK_ADDRESS_V1,
     },
 
     .x_pm_tmr_blk = {
         .address_space_id    = ACPI_SYSTEM_IO,
-        .register_bit_width  = ACPI_PM_TMR_BLK_BIT_WIDTH,
-        .register_bit_offset = ACPI_PM_TMR_BLK_BIT_OFFSET,
+        .register_bit_width  = ACPI_PM_TMR_BLK_LEN * 8,
+        .register_bit_offset = ACPI_REG_BIT_OFFSET,
         .address             = ACPI_PM_TMR_BLK_ADDRESS_V1,
     }
 };
xen/include/asm-x86/hvm/domain.h +6 -0
index f34d784..f492a2b 100644
@@ -87,6 +87,12 @@ struct hvm_domain {
     } ioreq_server;
     struct hvm_ioreq_server *default_ioreq_server;
 
+    /* PVH guests */
+    struct {
+        uint8_t pm1a[ACPI_PM1A_EVT_BLK_LEN];
+        uint8_t gpe[ACPI_GPE0_BLK_LEN_V1];
+    } acpi_io;
+
     /* Cached CF8 for guest PCI config cycles */
     uint32_t                pci_cf8;
 
xen/include/public/hvm/ioreq.h +3 -0
index 2e5809b..c36dd0f 100644
@@ -124,6 +124,9 @@ typedef struct buffered_iopage buffered_iopage_t;
 #define ACPI_GPE0_BLK_ADDRESS        ACPI_GPE0_BLK_ADDRESS_V0
 #define ACPI_GPE0_BLK_LEN            ACPI_GPE0_BLK_LEN_V0
 
+#define ACPI_PM1A_EVT_BLK_LEN        0x04
+#define ACPI_PM1A_CNT_BLK_LEN        0x02
+#define ACPI_PM_TMR_BLK_LEN          0x04
 
 #endif /* _IOREQ_H_ */
 
Signature · 7 lines
2.7.4


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

PATCH 3/10 pvh: Set online VCPU map to avail_vcpus

In reply to Boris Ostrovsky

ACPI builder marks VCPUS set in vcpu_online map as enabled in MADT. With ACPI-based CPU hotplug we only want VCPUs that are started by the guest to be marked as such. Remaining VCPUs will be set to "enable" by ACPI code during hotplug.

---
 tools/libxl/libxl_x86_acpi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libxl/libxl_x86_acpi.c +3 -3
index ff0e2df..949f555 100644
@@ -98,7 +98,7 @@ static int init_acpi_config(libxl__gc *gc,
     uint32_t domid = dom->guest_domid;
     xc_dominfo_t info;
     struct hvm_info_table *hvminfo;
-    int i, rc = 0;
+    int rc = 0;
 
     config->dsdt_anycpu = config->dsdt_15cpu = dsdt_pvh;
     config->dsdt_anycpu_len = config->dsdt_15cpu_len = dsdt_pvh_len;
@@ -144,8 +144,8 @@ static int init_acpi_config(libxl__gc *gc,
         hvminfo->nr_vcpus = info.max_vcpu_id + 1;
     }
 
-    for (i = 0; i < hvminfo->nr_vcpus; i++)
-        hvminfo->vcpu_online[i / 8] |= 1 << (i & 7);
+    memcpy(hvminfo->vcpu_online, b_info->avail_vcpus.map,
+           b_info->avail_vcpus.size);
 
     config->hvminfo = hvminfo;
 
Signature · 7 lines
2.7.4


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

Re: [PATCH 03/10] pvh: Set online VCPU map to avail_vcpus

Quoted 3 lines · Boris Ostrovsky

ACPI builder marks VCPUS set in vcpu_online map as enabled in MADT. With ACPI-based CPU hotplug we only want VCPUs that are started by the guest to be marked as such. Remaining VCPUs will be set to

Oh, so this is a bug then? We always marked them as enabled? Is this mentioned somewhere in the ACPI docs?

But what about guests that don't want to start their CPUs using ACPI but are using SMP MPtables?

Quoted 1 line

"enable" by ACPI code during hotplug.

. which ACPI code? The libacpi one? You may want to be specific. Or the QEMU code?

Quoted 38 lines
---
 tools/libxl/libxl_x86_acpi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libxl/libxl_x86_acpi.c +3 -3
index ff0e2df..949f555 100644
@@ -98,7 +98,7 @@ static int init_acpi_config(libxl__gc *gc,
     uint32_t domid = dom->guest_domid;
     xc_dominfo_t info;
     struct hvm_info_table *hvminfo;
-    int i, rc = 0;
+    int rc = 0;
 
     config->dsdt_anycpu = config->dsdt_15cpu = dsdt_pvh;
     config->dsdt_anycpu_len = config->dsdt_15cpu_len = dsdt_pvh_len;
@@ -144,8 +144,8 @@ static int init_acpi_config(libxl__gc *gc,
         hvminfo->nr_vcpus = info.max_vcpu_id + 1;
     }
 
-    for (i = 0; i < hvminfo->nr_vcpus; i++)
-        hvminfo->vcpu_online[i / 8] |= 1 << (i & 7);
+    memcpy(hvminfo->vcpu_online, b_info->avail_vcpus.map,
+           b_info->avail_vcpus.size);
 
     config->hvminfo = hvminfo;
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH 03/10] pvh: Set online VCPU map to avail_vcpus

Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Boris Ostrovsky

ACPI builder marks VCPUS set in vcpu_online map as enabled in MADT. With ACPI-based CPU hotplug we only want VCPUs that are started by the guest to be marked as such. Remaining VCPUs will be set to

Oh, so this is a bug then? We always marked them as enabled? Is this mentioned somewhere in the ACPI docs?

But what about guests that don't want to start their CPUs using ACPI but are using SMP MPtables?

This code is only applicable to PVH guests and it wasn't a bug because until now I assumed PV-like CPU hotplug (where the guest would watch xenstore). That required having all VCPUs marked as enabled in MADT and the guest (well, Linux guest) would immediately offline them.

Now that we are going full-ACPI this is no longer the case.

Quoted 4 lines
Quoted 2 lines

"enable" by ACPI code during hotplug.

. which ACPI code? The libacpi one? You may want to be specific. Or the QEMU code?

AML code in DSDT. I'll update the comment.

(No qemu --- this is PVH)

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw

PATCH 4/10 acpi: Power and Sleep ACPI buttons are not emulated

In reply to Boris Ostrovsky

.. for PVH guests. However, since emulating them for HVM guests also doesn't seem useful we can have FADT disable those buttons for both types of guests.

---
 tools/libacpi/static_tables.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libacpi/static_tables.c +2 -1
index 413abcc..ebe8ffe 100644
@@ -61,7 +61,8 @@ struct acpi_20_fadt Fadt = {
     .flags = (ACPI_PROC_C1 |
               ACPI_WBINVD |
               ACPI_FIX_RTC | ACPI_TMR_VAL_EXT |
-              ACPI_USE_PLATFORM_CLOCK),
+              ACPI_USE_PLATFORM_CLOCK |
+              ACPI_PWR_BUTTON | ACPI_SLP_BUTTON),
 
     .reset_reg = {
         .address_space_id    = ACPI_SYSTEM_IO,
Signature · 7 lines
2.7.4


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

Re: [PATCH 04/10] acpi: Power and Sleep ACPI buttons are not emulated

Quoted 3 lines · Boris Ostrovsky

.. for PVH guests. However, since emulating them for HVM guests also doesn't seem useful we can have FADT disable those buttons for both types of guests.

Wait, we need S3 suspend for HVM guests (think Windows without PV drivers)! And I this is how we "inject" the event to the guest.

CC-ing Annie and Adnan who I believe had to do something like this in old version of OVS, maybe they can recall more details.

Quoted 28 lines
---
 tools/libacpi/static_tables.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libacpi/static_tables.c +2 -1
index 413abcc..ebe8ffe 100644
@@ -61,7 +61,8 @@ struct acpi_20_fadt Fadt = {
     .flags = (ACPI_PROC_C1 |
               ACPI_WBINVD |
               ACPI_FIX_RTC | ACPI_TMR_VAL_EXT |
-              ACPI_USE_PLATFORM_CLOCK),
+              ACPI_USE_PLATFORM_CLOCK |
+              ACPI_PWR_BUTTON | ACPI_SLP_BUTTON),
 
     .reset_reg = {
         .address_space_id    = ACPI_SYSTEM_IO,
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw

Re: [PATCH 04/10] acpi: Power and Sleep ACPI buttons are not emulated

Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Boris Ostrovsky

.. for PVH guests. However, since emulating them for HVM guests also doesn't seem useful we can have FADT disable those buttons for both types of guests.

Wait, we need S3 suspend for HVM guests (think Windows without PV drivers)! And I this is how we "inject" the event to the guest.

CC-ing Annie and Adnan who I believe had to do something like this in old version of OVS, maybe they can recall more details.

Andrew has already requested that HVM guests keep their buttons so this change will only be implemented for PVH guests.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#12 lore raw

Re: [PATCH 04/10] acpi: Power and Sleep ACPI buttons are not emulated

In reply to Konrad Rzeszutek Wilk
Quoted 9 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Boris Ostrovsky

.. for PVH guests. However, since emulating them for HVM guests also doesn't seem useful we can have FADT disable those buttons for both types of guests.

Wait, we need S3 suspend for HVM guests (think Windows without PV drivers)! And I this is how we "inject" the event to the guest.

CC-ing Annie and Adnan who I believe had to do something like this in old version of OVS, maybe they can recall more details.

Our winpv supports S4(hibernation) which will be tested by WHQL, and S3(Sleep) is optional(no real process for it yet).

Thanks
Annie

Quoted 23 lines
Quoted 23 lines
---
  tools/libacpi/static_tables.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tools/libacpi/static_tables.c +2 -1
index 413abcc..ebe8ffe 100644
@@ -61,7 +61,8 @@ struct acpi_20_fadt Fadt = {
      .flags = (ACPI_PROC_C1 |
                ACPI_WBINVD |
                ACPI_FIX_RTC | ACPI_TMR_VAL_EXT |
-              ACPI_USE_PLATFORM_CLOCK),
+              ACPI_USE_PLATFORM_CLOCK |
+              ACPI_PWR_BUTTON | ACPI_SLP_BUTTON),
 
      .reset_reg = {
          .address_space_id    = ACPI_SYSTEM_IO,
Signature · 1 line
2.7.4
Quoted 8 lines
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#13 lore raw

PATCH 5/10 acpi: Make pmtimer optional in FADT

In reply to Boris Ostrovsky

PM timer is not supported by PVH guests.

---
 tools/firmware/hvmloader/util.c | 3 ++-
 tools/libacpi/build.c           | 5 +++++
 tools/libacpi/libacpi.h         | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/util.c +2 -1
index 6e0cfe7..1d78973 100644
@@ -948,7 +948,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     if ( !strncmp(xenstore_read("platform/acpi_s4", "1"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_S4;
 
-    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC | ACPI_HAS_WAET);
+    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
+                            ACPI_HAS_WAET | ACPI_HAS_PMTIMER);
 
     config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
 
tools/libacpi/build.c +5 -0
index 47dae01..58822d3 100644
@@ -574,6 +574,11 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
 
     fadt = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_fadt), 16);
     if (!fadt) goto oom;
+    if ( !(config->table_flags & ACPI_HAS_PMTIMER) )
+    {
+        Fadt.pm_tmr_blk = 0;
+        memset(&Fadt.x_pm_tmr_blk, 0, sizeof(Fadt.x_pm_tmr_blk));
+    }
     memcpy(fadt, &Fadt, sizeof(struct acpi_20_fadt));
     fadt->dsdt   = ctxt->mem_ops.v2p(ctxt, dsdt);
     fadt->x_dsdt = ctxt->mem_ops.v2p(ctxt, dsdt);
tools/libacpi/libacpi.h +1 -0
index 1d388f9..bda692e 100644
@@ -30,6 +30,7 @@
 #define ACPI_HAS_TCPA        (1<<7)
 #define ACPI_HAS_IOAPIC      (1<<8)
 #define ACPI_HAS_WAET        (1<<9)
+#define ACPI_HAS_PMTIMER     (1<<10)
 
 struct xen_vmemrange;
 struct acpi_numa {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 5/10
#14 lore raw

Re: [PATCH 05/10] acpi: Make pmtimer optional in FADT

Quoted 3 lines · Boris Ostrovsky

PM timer is not supported by PVH guests.

Quoted 56 lines
---
 tools/firmware/hvmloader/util.c | 3 ++-
 tools/libacpi/build.c           | 5 +++++
 tools/libacpi/libacpi.h         | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/util.c +2 -1
index 6e0cfe7..1d78973 100644
@@ -948,7 +948,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     if ( !strncmp(xenstore_read("platform/acpi_s4", "1"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_S4;
 
-    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC | ACPI_HAS_WAET);
+    config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
+                            ACPI_HAS_WAET | ACPI_HAS_PMTIMER);
 
     config->tis_hdr = (uint16_t *)ACPI_TIS_HDR_ADDRESS;
 
tools/libacpi/build.c +5 -0
index 47dae01..58822d3 100644
@@ -574,6 +574,11 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
 
     fadt = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_fadt), 16);
     if (!fadt) goto oom;
+    if ( !(config->table_flags & ACPI_HAS_PMTIMER) )
+    {
+        Fadt.pm_tmr_blk = 0;
+        memset(&Fadt.x_pm_tmr_blk, 0, sizeof(Fadt.x_pm_tmr_blk));
+    }
     memcpy(fadt, &Fadt, sizeof(struct acpi_20_fadt));
     fadt->dsdt   = ctxt->mem_ops.v2p(ctxt, dsdt);
     fadt->x_dsdt = ctxt->mem_ops.v2p(ctxt, dsdt);
tools/libacpi/libacpi.h +1 -0
index 1d388f9..bda692e 100644
@@ -30,6 +30,7 @@
 #define ACPI_HAS_TCPA        (1<<7)
 #define ACPI_HAS_IOAPIC      (1<<8)
 #define ACPI_HAS_WAET        (1<<9)
+#define ACPI_HAS_PMTIMER     (1<<10)
 
 struct xen_vmemrange;
 struct acpi_numa {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw

PATCH 6/10 acpi: PVH guests need _E02 method

In reply to Boris Ostrovsky

This is the method that will get invoked on an SCI.

---
 tools/libacpi/mk_dsdt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/libacpi/mk_dsdt.c +5 -5
index 4ae68bc..407386a 100644
@@ -280,11 +280,6 @@ int main(int argc, char **argv)
 
     pop_block();
 
-    if (dm_version == QEMU_NONE) {
-        pop_block();
-        return 0;
-    }
-
     /* Define GPE control method. */
     push_block("Scope", "\\_GPE");
     push_block("Method",
@@ -292,6 +287,11 @@ int main(int argc, char **argv)
     stmt("\\_SB.PRSC ()", NULL);
     pop_block();
     pop_block();
+
+    if (dm_version == QEMU_NONE) {
+        pop_block();
+        return 0;
+    }
     /**** Processor end ****/
 
 
Signature · 7 lines
2.7.4


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

Re: [PATCH 06/10] acpi: PVH guests need _E02 method

Quoted 3 lines · Boris Ostrovsky

This is the method that will get invoked on an SCI.

.. thought I wonder - do you want to also make the writes to _GPE.DPT1 and _GPE.DPT2 be optional? Looking at the mk_dsdt.c those are defined at 0xb044 and are done in:
/**** PCI0 start ****/

aka:

stmt("OperationRegion", "DG1, SystemIO, 0xb044, 0x04");
415

416     push_block("Field", "DG1, ByteAcc, NoLock, Preserve");                      
417     indent(); printf("DPT1, 8, DPT2, 8\n");                                     
418     pop_block();                                     

Which means if you run 'acpixtract' and 'acpixecute' to play with the DSDTs you will get nasty warnings about the DPT1 and DPT2 not being defined.

I am actually not sure what the kernel will do with undefind DPT1 and DPT2? I would have thought the iasl compiler would throw an nasty fit?

Quoted 40 lines
---
 tools/libacpi/mk_dsdt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/libacpi/mk_dsdt.c +5 -5
index 4ae68bc..407386a 100644
@@ -280,11 +280,6 @@ int main(int argc, char **argv)
 
     pop_block();
 
-    if (dm_version == QEMU_NONE) {
-        pop_block();
-        return 0;
-    }
-
     /* Define GPE control method. */
     push_block("Scope", "\\_GPE");
     push_block("Method",
@@ -292,6 +287,11 @@ int main(int argc, char **argv)
     stmt("\\_SB.PRSC ()", NULL);
     pop_block();
     pop_block();
+
+    if (dm_version == QEMU_NONE) {
+        pop_block();
+        return 0;
+    }
     /**** Processor end ****/
 
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH 06/10] acpi: PVH guests need _E02 method

Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Boris Ostrovsky

This is the method that will get invoked on an SCI.

.. thought I wonder - do you want to also make the writes to _GPE.DPT1 and _GPE.DPT2 be optional? Looking at the mk_dsdt.c those are defined at 0xb044 and are done in:
/**** PCI0 start ****/

aka:

stmt("OperationRegion", "DG1, SystemIO, 0xb044, 0x04");
415

416     push_block("Field", "DG1, ByteAcc, NoLock, Preserve");                      
417     indent(); printf("DPT1, 8, DPT2, 8\n");                                     
418     pop_block();                                     
Quoted 6 lines

Which means if you run 'acpixtract' and 'acpixecute' to play with the DSDTs you will get nasty warnings about the DPT1 and DPT2 not being defined.

I am actually not sure what the kernel will do with undefind DPT1 and DPT2? I would have thought the iasl compiler would throw an nasty fit?

Are these ACPI debug ports?

I don't see any warnings from acpixtract, unless it's a particular AML that would cause it.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw

Re: [PATCH 06/10] acpi: PVH guests need _E02 method

Quoted 19 lines · Boris Ostrovsky
Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Boris Ostrovsky

This is the method that will get invoked on an SCI.

.. thought I wonder - do you want to also make the writes to _GPE.DPT1 and _GPE.DPT2 be optional? Looking at the mk_dsdt.c those are defined at 0xb044 and are done in:
/**** PCI0 start ****/

aka:

stmt("OperationRegion", "DG1, SystemIO, 0xb044, 0x04");
415

416     push_block("Field", "DG1, ByteAcc, NoLock, Preserve");                      
417     indent(); printf("DPT1, 8, DPT2, 8\n");                                     
418     pop_block();                                     
Quoted 8 lines
Quoted 6 lines

Which means if you run 'acpixtract' and 'acpixecute' to play with the DSDTs you will get nasty warnings about the DPT1 and DPT2 not being defined.

I am actually not sure what the kernel will do with undefind DPT1 and DPT2? I would have thought the iasl compiler would throw an nasty fit?

Are these ACPI debug ports?

Yes.

Quoted 3 lines

I don't see any warnings from acpixtract, unless it's a particular AML that would cause it.

Could you send the .dsl files over ?

Quoted 3 lines

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#19 lore raw

PATCH 7/10 pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

In reply to Boris Ostrovsky

No IOREQ server installed for an HVM guest (as indicated by HVM_PARAM_NR_IOREQ_SERVER_PAGES being set to zero) implies a PVH guest. These guests need to handle ACPI-related IO accesses.

Logic for the handler will be provided by a later patch.

---
CC: Paul Durrant <[email protected]>

---
 tools/libxc/xc_dom_x86.c        |  3 +++
 xen/arch/x86/hvm/hvm.c          | 13 +++++++++----
 xen/arch/x86/hvm/ioreq.c        | 17 +++++++++++++++++
 xen/include/asm-x86/hvm/ioreq.h |  1 +
 4 files changed, 30 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_x86.c +3 -0
index 7fcdee1..0017694 100644
@@ -649,6 +649,9 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
         /* Limited to one module. */
         if ( dom->ramdisk_blob )
             start_info_size += sizeof(struct hvm_modlist_entry);
+
+        /* No IOREQ server for PVH guests. */
+        xc_hvm_param_set(xch, domid, HVM_PARAM_NR_IOREQ_SERVER_PAGES, 0);
     }
     else
     {
xen/arch/x86/hvm/hvm.c +9 -4
index 704fd64..6f8439d 100644
@@ -5206,14 +5206,19 @@ static int hvmop_set_param(
     {
         unsigned int i;
 
-        if ( a.value == 0 ||
-             a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )
+        if ( a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )
         {
             rc = -EINVAL;
             break;
         }
-        for ( i = 0; i < a.value; i++ )
-            set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+
+        if ( a.value == 0 ) /* PVH guest */
+            acpi_ioreq_init(d);
+        else
+        {
+            for ( i = 0; i < a.value; i++ )
+                set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+        }
 
         break;
     }
xen/arch/x86/hvm/ioreq.c +17 -0
index d2245e2..171ea82 100644
@@ -1389,6 +1389,23 @@ void hvm_ioreq_init(struct domain *d)
         register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
 }
 
+static int acpi_ioaccess(
+    int dir, unsigned int port, unsigned int bytes, uint32_t *val)
+{
+    return X86EMUL_OKAY;
+}
+
+void acpi_ioreq_init(struct domain *d)
+{
+    /* Online CPU map, see DSDT's PRST region. */
+    register_portio_handler(d, 0xaf00, HVM_MAX_VCPUS/8, acpi_ioaccess);
+
+    register_portio_handler(d, ACPI_GPE0_BLK_ADDRESS_V1,
+                            ACPI_GPE0_BLK_LEN_V1, acpi_ioaccess);
+    register_portio_handler(d, ACPI_PM1A_EVT_BLK_ADDRESS_V1,
+                            ACPI_PM1A_EVT_BLK_LEN, acpi_ioaccess);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-x86/hvm/ioreq.h +1 -0
index fbf2c74..e7b7f52 100644
@@ -53,6 +53,7 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s, ioreq_t *proto_p,
 unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool_t buffered);
 
 void hvm_ioreq_init(struct domain *d);
+void acpi_ioreq_init(struct domain *d);
 
 #endif /* __ASM_X86_HVM_IOREQ_H__ */
 
Signature · 7 lines
2.7.4


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

Re: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Quoted 33 lines

-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 06 November 2016 21:43
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Roger Pau Monne <[email protected]>; Boris Ostrovsky <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

No IOREQ server installed for an HVM guest (as indicated by HVM_PARAM_NR_IOREQ_SERVER_PAGES being set to zero) implies a PVH guest. These guests need to handle ACPI-related IO accesses.

Logic for the handler will be provided by a later patch.

---
CC: Paul Durrant <[email protected]>

---
 tools/libxc/xc_dom_x86.c        |  3 +++
 xen/arch/x86/hvm/hvm.c          | 13 +++++++++----
 xen/arch/x86/hvm/ioreq.c        | 17 +++++++++++++++++
 xen/include/asm-x86/hvm/ioreq.h |  1 +
 4 files changed, 30 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_x86.c +0 -0
index 7fcdee1..0017694 100644

tools/libxc/xc_dom_x86.c static int alloc_magic_pages_hvm(struct · line 656

Quoted 8 lines
tools/libxc/xc_dom_x86.c +3 -0
@@ -649,6 +649,9 @@ static int alloc_magic_pages_hvm(struct
 xc_dom_image *dom)
         /* Limited to one module. */
         if ( dom->ramdisk_blob )
             start_info_size += sizeof(struct hvm_modlist_entry);
+
+        /* No IOREQ server for PVH guests. */
+        xc_hvm_param_set(xch, domid,
 HVM_PARAM_NR_IOREQ_SERVER_PAGES, 0);

I thought params defaulted to zero...

xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 5210

Quoted 13 lines
tools/libxc/xc_dom_x86.c +0 -0
     }
     else
     {
xen/arch/x86/hvm/hvm.c +0 -2
index 704fd64..6f8439d 100644
@@ -5206,14 +5206,19 @@ static int hvmop_set_param(
     {
         unsigned int i;
 
-        if ( a.value == 0 ||
-             a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )

...and if they do then you should not need this change.

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1 -0
+        if ( a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )
         {
             rc = -EINVAL;
             break;
         }

xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 5221

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +8 -2
-        for ( i = 0; i < a.value; i++ )
-            set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+
+        if ( a.value == 0 ) /* PVH guest */
+            acpi_ioreq_init(d);
+        else
+        {
+            for ( i = 0; i < a.value; i++ )
+                set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+        }

This looks quite wrong. Initializing the acpi io hander should be done directly in hvm_domain_initialise() IMO and not as an obscure side effect of setting a parameter to its default value.

Paul

Quoted 46 lines
xen/arch/x86/hvm/hvm.c +0 -0
         break;
     }
xen/arch/x86/hvm/ioreq.c +17 -0
index d2245e2..171ea82 100644
@@ -1389,6 +1389,23 @@ void hvm_ioreq_init(struct domain *d)
         register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
 }
 
+static int acpi_ioaccess(
+    int dir, unsigned int port, unsigned int bytes, uint32_t *val)
+{
+    return X86EMUL_OKAY;
+}
+
+void acpi_ioreq_init(struct domain *d)
+{
+    /* Online CPU map, see DSDT's PRST region. */
+    register_portio_handler(d, 0xaf00, HVM_MAX_VCPUS/8, acpi_ioaccess);
+
+    register_portio_handler(d, ACPI_GPE0_BLK_ADDRESS_V1,
+                            ACPI_GPE0_BLK_LEN_V1, acpi_ioaccess);
+    register_portio_handler(d, ACPI_PM1A_EVT_BLK_ADDRESS_V1,
+                            ACPI_PM1A_EVT_BLK_LEN, acpi_ioaccess);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm- renamed from xen/include/asm-x86/hvm/ioreq.h +0 -0

x86/hvm/ioreq.h
index fbf2c74..e7b7f52 100644

xen/include/asm-x86/hvm/ioreq.h +1 -1
@@ -53,6 +53,7 @@ int hvm_send_ioreq(struct hvm_ioreq_server *s,
 ioreq_t *proto_p,
 unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool_t buffered);
 
 void hvm_ioreq_init(struct domain *d);
+void acpi_ioreq_init(struct domain *d);
 
 #endif /* __ASM_X86_HVM_IOREQ_H__ */
 
--
Quoted 1 line

2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Quoted 73 lines · Paul Durrant
Quoted 33 lines

-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 06 November 2016 21:43
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Roger Pau Monne <[email protected]>; Boris Ostrovsky <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

No IOREQ server installed for an HVM guest (as indicated by HVM_PARAM_NR_IOREQ_SERVER_PAGES being set to zero) implies a PVH guest. These guests need to handle ACPI-related IO accesses.

Logic for the handler will be provided by a later patch.

---
CC: Paul Durrant <[email protected]>

---
 tools/libxc/xc_dom_x86.c        |  3 +++
 xen/arch/x86/hvm/hvm.c          | 13 +++++++++----
 xen/arch/x86/hvm/ioreq.c        | 17 +++++++++++++++++
 xen/include/asm-x86/hvm/ioreq.h |  1 +
 4 files changed, 30 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_x86.c +0 -0
index 7fcdee1..0017694 100644

tools/libxc/xc_dom_x86.c static int alloc_magic_pages_hvm(struct · line 656

Quoted 8 lines
tools/libxc/xc_dom_x86.c +3 -0
@@ -649,6 +649,9 @@ static int alloc_magic_pages_hvm(struct
 xc_dom_image *dom)
         /* Limited to one module. */
         if ( dom->ramdisk_blob )
             start_info_size += sizeof(struct hvm_modlist_entry);
+
+        /* No IOREQ server for PVH guests. */
+        xc_hvm_param_set(xch, domid,
 HVM_PARAM_NR_IOREQ_SERVER_PAGES, 0);

I thought params defaulted to zero...

xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 5210

Quoted 13 lines
tools/libxc/xc_dom_x86.c +0 -0
     }
     else
     {
xen/arch/x86/hvm/hvm.c +0 -2
index 704fd64..6f8439d 100644
@@ -5206,14 +5206,19 @@ static int hvmop_set_param(
     {
         unsigned int i;
 
-        if ( a.value == 0 ||
-             a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )

...and if they do then you should not need this change.

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1 -0
+        if ( a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )
         {
             rc = -EINVAL;
             break;
         }

xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 5221

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +8 -2
-        for ( i = 0; i < a.value; i++ )
-            set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+
+        if ( a.value == 0 ) /* PVH guest */
+            acpi_ioreq_init(d);
+        else
+        {
+            for ( i = 0; i < a.value; i++ )
+                set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+        }
Quoted 1 line

This looks quite wrong. Initializing the acpi io hander should be done directly in hvm_domain_initialise() IMO and not as an obscure side effect of setting a parameter to its default value.

Right, this call indeed is used to tell the hypervisor that it should handle IO accesses itself. It was either this or adding another emulation flag (which is what Andrew prefers).

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#22 lore raw

Re: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Quoted 86 lines

-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 07 November 2016 14:01
To: Paul Durrant <[email protected]>; [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Quoted 6 lines · Paul Durrant
Quoted 6 lines

-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 06 November 2016 21:43
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>;

Roger

Quoted 3 lines
Quoted 3 lines

Pau Monne <[email protected]>; Boris Ostrovsky <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH 07/10] pvh/ioreq: Install handlers for ACPI-related PVH

IO

Quoted 64 lines
Quoted 24 lines

accesses

No IOREQ server installed for an HVM guest (as indicated by HVM_PARAM_NR_IOREQ_SERVER_PAGES being set to zero) implies a PVH guest. These guests need to handle ACPI-related IO accesses.

Logic for the handler will be provided by a later patch.

---
CC: Paul Durrant <[email protected]>

---
 tools/libxc/xc_dom_x86.c        |  3 +++
 xen/arch/x86/hvm/hvm.c          | 13 +++++++++----
 xen/arch/x86/hvm/ioreq.c        | 17 +++++++++++++++++
 xen/include/asm-x86/hvm/ioreq.h |  1 +
 4 files changed, 30 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_x86.c +0 -0
index 7fcdee1..0017694 100644

tools/libxc/xc_dom_x86.c static int alloc_magic_pages_hvm(struct · line 656

Quoted 8 lines
tools/libxc/xc_dom_x86.c +3 -0
@@ -649,6 +649,9 @@ static int alloc_magic_pages_hvm(struct
 xc_dom_image *dom)
         /* Limited to one module. */
         if ( dom->ramdisk_blob )
             start_info_size += sizeof(struct hvm_modlist_entry);
+
+        /* No IOREQ server for PVH guests. */
+        xc_hvm_param_set(xch, domid,
 HVM_PARAM_NR_IOREQ_SERVER_PAGES, 0);

I thought params defaulted to zero...

xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 5210

Quoted 13 lines
tools/libxc/xc_dom_x86.c +0 -0
     }
     else
     {
xen/arch/x86/hvm/hvm.c +0 -2
index 704fd64..6f8439d 100644
@@ -5206,14 +5206,19 @@ static int hvmop_set_param(
     {
         unsigned int i;
 
-        if ( a.value == 0 ||
-             a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )

...and if they do then you should not need this change.

Quoted 15 lines
xen/arch/x86/hvm/hvm.c +9 -2
+        if ( a.value > sizeof(d->arch.hvm_domain.ioreq_gmfn.mask) * 8 )
         {
             rc = -EINVAL;
             break;
         }
-        for ( i = 0; i < a.value; i++ )
-            set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+
+        if ( a.value == 0 ) /* PVH guest */
+            acpi_ioreq_init(d);
+        else
+        {
+            for ( i = 0; i < a.value; i++ )
+                set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+        }
Quoted 7 lines
Quoted 1 line

This looks quite wrong. Initializing the acpi io hander should be done

directly in hvm_domain_initialise() IMO and not as an obscure side effect of setting a parameter to its default value.

Right, this call indeed is used to tell the hypervisor that it should handle IO accesses itself. It was either this or adding another emulation flag (which is what Andrew prefers).

Yes, another emulation flag seems like the right thing.

Paul

Quoted 2 lines

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#23 lore raw

PATCH 8/10 pvh/acpi: Handle ACPI accesses for PVH guests

In reply to Boris Ostrovsky

---
CC: Paul Durrant <[email protected]>

---
 xen/arch/x86/hvm/ioreq.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
xen/arch/x86/hvm/ioreq.c +66 -0
index 171ea82..ced7c92 100644
@@ -1392,6 +1392,72 @@ void hvm_ioreq_init(struct domain *d)
 static int acpi_ioaccess(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
+    unsigned int i;
+    unsigned int bits = bytes * 8;
+    uint8_t *reg = NULL;
+    unsigned idx = port & 3;
+    bool is_cpu_map = 0;
+    struct domain *currd = current->domain;
+
+    BUILD_BUG_ON((ACPI_PM1A_EVT_BLK_LEN != 4) ||
+                 (ACPI_GPE0_BLK_LEN_V1 != 4));
+
+    switch (port)
+    {
+    case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ...
+        (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + ACPI_PM1A_EVT_BLK_LEN - 1):
+        reg = currd->arch.hvm_domain.acpi_io.pm1a;
+        break;
+    case ACPI_GPE0_BLK_ADDRESS_V1 ...
+        (ACPI_GPE0_BLK_ADDRESS_V1 + ACPI_GPE0_BLK_LEN_V1 - 1):
+        reg = currd->arch.hvm_domain.acpi_io.gpe;
+        break;
+    case 0xaf00 ... (0xaf00 + HVM_MAX_VCPUS/8 - 1):
+        is_cpu_map = 1;
+        break;
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+
+    if ( bytes == 0 )
+        return X86EMUL_OKAY;
+
+    if ( dir == IOREQ_READ )
+    {
+        *val &= ~((1U << bits) - 1);
+
+        if ( is_cpu_map )
+        {
+            unsigned first_bit, last_bit;
+
+            first_bit = (port - 0xaf00) * 8;
+            last_bit = min(currd->arch.avail_vcpus, first_bit + bits);
+            for (i = first_bit; i < last_bit; i++)
+                *val |= (1U << (i - first_bit));
+        }
+        else
+            memcpy(val, &reg[idx], bytes);
+    }
+    else
+    {
+        if ( is_cpu_map )
+            /* CPU map should not be written. */
+            return X86EMUL_UNHANDLEABLE;
+
+        /* Write either status or enable reegister. */
+        if ( (bytes > 2) || ((bytes == 2) && (port & 1)) )
+            return X86EMUL_UNHANDLEABLE;
+
+        if ( idx < 2 ) /* status, write 1 to clear. */
+        {
+            reg[idx] &= ~(*val & 0xff);
+            if ( bytes == 2 )
+                reg[idx + 1] &= ~((*val >> 8) & 0xff);
+        }
+        else           /* enable */
+            memcpy(&reg[idx], val, bytes);
+    }
+
     return X86EMUL_OKAY;
 }
 
Signature · 7 lines
2.7.4


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

Re: [PATCH 08/10] pvh/acpi: Handle ACPI accesses for PVH guests

Quoted 23 lines

-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 06 November 2016 21:43
To: [email protected]
Cc: [email protected]; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Roger Pau Monne <[email protected]>; Boris Ostrovsky <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH 08/10] pvh/acpi: Handle ACPI accesses for PVH guests

---
CC: Paul Durrant <[email protected]>

---
 xen/arch/x86/hvm/ioreq.c | 66
++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
xen/arch/x86/hvm/ioreq.c +0 -0
index 171ea82..ced7c92 100644

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1399

Quoted 8 lines
xen/arch/x86/hvm/ioreq.c +5 -0
@@ -1392,6 +1392,72 @@ void hvm_ioreq_init(struct domain *d)
 static int acpi_ioaccess(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
+    unsigned int i;
+    unsigned int bits = bytes * 8;
+    uint8_t *reg = NULL;
+    unsigned idx = port & 3;
+    bool is_cpu_map = 0;

Shouldn't we be using false instead of 0 now that we are using proper bool types?

Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +7 -0
+    struct domain *currd = current->domain;
+
+    BUILD_BUG_ON((ACPI_PM1A_EVT_BLK_LEN != 4) ||
+                 (ACPI_GPE0_BLK_LEN_V1 != 4));
+
+    switch (port)
+    {

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1416

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+    case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ...
+        (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + ACPI_PM1A_EVT_BLK_LEN - 1):
+        reg = currd->arch.hvm_domain.acpi_io.pm1a;
+        break;
+    case ACPI_GPE0_BLK_ADDRESS_V1 ...
+        (ACPI_GPE0_BLK_ADDRESS_V1 + ACPI_GPE0_BLK_LEN_V1 - 1):
+        reg = currd->arch.hvm_domain.acpi_io.gpe;
+        break;
+    case 0xaf00 ... (0xaf00 + HVM_MAX_VCPUS/8 - 1):
+        is_cpu_map = 1;

s/1/true ?

Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +5 -0
+        break;
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1431

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+    if ( bytes == 0 )
+        return X86EMUL_OKAY;
+
+    if ( dir == IOREQ_READ )
+    {
+        *val &= ~((1U << bits) - 1);
+
+        if ( is_cpu_map )
+        {
+            unsigned first_bit, last_bit;

unsigned int

Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +17 -0
+
+            first_bit = (port - 0xaf00) * 8;
+            last_bit = min(currd->arch.avail_vcpus, first_bit + bits);
+            for (i = first_bit; i < last_bit; i++)
+                *val |= (1U << (i - first_bit));
+        }
+        else
+            memcpy(val, &reg[idx], bytes);
+    }
+    else
+    {
+        if ( is_cpu_map )
+            /* CPU map should not be written. */
+            return X86EMUL_UNHANDLEABLE;
+
+        /* Write either status or enable reegister. */
+        if ( (bytes > 2) || ((bytes == 2) && (port & 1)) )

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1458

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+            return X86EMUL_UNHANDLEABLE;
+
+        if ( idx < 2 ) /* status, write 1 to clear. */
+        {
+            reg[idx] &= ~(*val & 0xff);
+            if ( bytes == 2 )
+                reg[idx + 1] &= ~((*val >> 8) & 0xff);
+        }
+        else           /* enable */
+            memcpy(&reg[idx], val, bytes);

idx should be strictly == 2 in the else case shouldn't it (since it = port & 3) so would it not be more efficient to use direct assignment rather than resorting to a call to memcpy?

Paul

Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +2 -1
+    }
+
     return X86EMUL_OKAY;
 }
 
--

2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#25 lore raw

Re: [PATCH 08/10] pvh/acpi: Handle ACPI accesses for PVH guests

Quoted 75 lines

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1399

Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +5 -0
index 171ea82..ced7c92 100644
@@ -1392,6 +1392,72 @@ void hvm_ioreq_init(struct domain *d)
 static int acpi_ioaccess(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
+    unsigned int i;
+    unsigned int bits = bytes * 8;
+    uint8_t *reg = NULL;
+    unsigned idx = port & 3;
+    bool is_cpu_map = 0;

Shouldn't we be using false instead of 0 now that we are using proper bool types?

Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +7 -0
+    struct domain *currd = current->domain;
+
+    BUILD_BUG_ON((ACPI_PM1A_EVT_BLK_LEN != 4) ||
+                 (ACPI_GPE0_BLK_LEN_V1 != 4));
+
+    switch (port)
+    {

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1416

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+    case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ...
+        (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + ACPI_PM1A_EVT_BLK_LEN - 1):
+        reg = currd->arch.hvm_domain.acpi_io.pm1a;
+        break;
+    case ACPI_GPE0_BLK_ADDRESS_V1 ...
+        (ACPI_GPE0_BLK_ADDRESS_V1 + ACPI_GPE0_BLK_LEN_V1 - 1):
+        reg = currd->arch.hvm_domain.acpi_io.gpe;
+        break;
+    case 0xaf00 ... (0xaf00 + HVM_MAX_VCPUS/8 - 1):
+        is_cpu_map = 1;

s/1/true ?

Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +5 -0
+        break;
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1431

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+    if ( bytes == 0 )
+        return X86EMUL_OKAY;
+
+    if ( dir == IOREQ_READ )
+    {
+        *val &= ~((1U << bits) - 1);
+
+        if ( is_cpu_map )
+        {
+            unsigned first_bit, last_bit;

unsigned int

Quoted 21 lines
xen/arch/x86/hvm/ioreq.c +21 -0
+
+            first_bit = (port - 0xaf00) * 8;
+            last_bit = min(currd->arch.avail_vcpus, first_bit + bits);
+            for (i = first_bit; i < last_bit; i++)
+                *val |= (1U << (i - first_bit));
+        }
+        else
+            memcpy(val, &reg[idx], bytes);
+    }
+    else
+    {
+        if ( is_cpu_map )
+            /* CPU map should not be written. */
+            return X86EMUL_UNHANDLEABLE;
+
+        /* Write either status or enable reegister. */
+        if ( (bytes > 2) || ((bytes == 2) && (port & 1)) )
+            return X86EMUL_UNHANDLEABLE;
+
+        if ( idx < 2 ) /* status, write 1 to clear. */
+        {
Quoted 8 lines

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1458

Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6 -0
+            reg[idx] &= ~(*val & 0xff);
+            if ( bytes == 2 )
+                reg[idx + 1] &= ~((*val >> 8) & 0xff);
+        }
+        else           /* enable */
+            memcpy(&reg[idx], val, bytes);

idx should be strictly == 2 in the else case shouldn't it (since it = port & 3) so would it not be more efficient to use direct assignment rather than resorting to a call to memcpy?

Why do you think idx can't be 3? Reading 1 byte from index 3 should be possible.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#26 lore raw

Re: [PATCH 08/10] pvh/acpi: Handle ACPI accesses for PVH guests

In reply to Boris Ostrovsky
Quoted 26 lines · Boris Ostrovsky

---
CC: Paul Durrant <[email protected]>

---
 xen/arch/x86/hvm/ioreq.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
xen/arch/x86/hvm/ioreq.c +11 -0
index 171ea82..ced7c92 100644
@@ -1392,6 +1392,72 @@ void hvm_ioreq_init(struct domain *d)
 static int acpi_ioaccess(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
+    unsigned int i;
+    unsigned int bits = bytes * 8;
+    uint8_t *reg = NULL;
+    unsigned idx = port & 3;
+    bool is_cpu_map = 0;
+    struct domain *currd = current->domain;
+
+    BUILD_BUG_ON((ACPI_PM1A_EVT_BLK_LEN != 4) ||
+                 (ACPI_GPE0_BLK_LEN_V1 != 4));
+
+    switch (port)

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1415

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+    {
+    case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ...
+        (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + ACPI_PM1A_EVT_BLK_LEN - 1):
+        reg = currd->arch.hvm_domain.acpi_io.pm1a;
+        break;
+    case ACPI_GPE0_BLK_ADDRESS_V1 ...
+        (ACPI_GPE0_BLK_ADDRESS_V1 + ACPI_GPE0_BLK_LEN_V1 - 1):
+        reg = currd->arch.hvm_domain.acpi_io.gpe;
+        break;
+    case 0xaf00 ... (0xaf00 + HVM_MAX_VCPUS/8 - 1):

That may need some documentation or a #define perhaps?

Also just in case somebody decided it was funny and compile Xen with HVM_MAX_VCPUS set to say 4, won't this go in 0xfffffff region?

You may want to add a BUILD_BUG_ON for the HVM_MAX_VCPUS, like:

BUILD_BUGON(HVM_MAX_VCPUS > 8)?

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1423

Quoted 8 lines
xen/arch/x86/hvm/ioreq.c +8 -0
+        is_cpu_map = 1;
+        break;
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+
+    if ( bytes == 0 )
+        return X86EMUL_OKAY;

Should you also check for other odd sizes? Say 3?

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1433

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+
+    if ( dir == IOREQ_READ )
+    {
+        *val &= ~((1U << bits) - 1);
+
+        if ( is_cpu_map )
+        {
+            unsigned first_bit, last_bit;
+
+            first_bit = (port - 0xaf00) * 8;

Oh, that needs a define.

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1435

Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +2 -0
+            last_bit = min(currd->arch.avail_vcpus, first_bit + bits);
+            for (i = first_bit; i < last_bit; i++)

I think you need spaces here.

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1444

Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +9 -0
+                *val |= (1U << (i - first_bit));
+        }
+        else
+            memcpy(val, &reg[idx], bytes);
+    }
+    else
+    {
+        if ( is_cpu_map )
+            /* CPU map should not be written. */

It shouldn't? Then who updates this? Oh we do it via the the hypercall. You may want to mention in this function how this all is suppose to work?

Quoted 27 lines
xen/arch/x86/hvm/ioreq.c +16 -0
+            return X86EMUL_UNHANDLEABLE;
+
+        /* Write either status or enable reegister. */
+        if ( (bytes > 2) || ((bytes == 2) && (port & 1)) )
+            return X86EMUL_UNHANDLEABLE;
+
+        if ( idx < 2 ) /* status, write 1 to clear. */
+        {
+            reg[idx] &= ~(*val & 0xff);
+            if ( bytes == 2 )
+                reg[idx + 1] &= ~((*val >> 8) & 0xff);
+        }
+        else           /* enable */
+            memcpy(&reg[idx], val, bytes);
+    }
+
     return X86EMUL_OKAY;
 }
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#27 lore raw

Re: [PATCH 08/10] pvh/acpi: Handle ACPI accesses for PVH guests

Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Boris Ostrovsky

---
CC: Paul Durrant <[email protected]>

---
 xen/arch/x86/hvm/ioreq.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
xen/arch/x86/hvm/ioreq.c +14 -0
index 171ea82..ced7c92 100644
@@ -1392,6 +1392,72 @@ void hvm_ioreq_init(struct domain *d)
 static int acpi_ioaccess(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
+    unsigned int i;
+    unsigned int bits = bytes * 8;
+    uint8_t *reg = NULL;
+    unsigned idx = port & 3;
+    bool is_cpu_map = 0;
+    struct domain *currd = current->domain;
+
+    BUILD_BUG_ON((ACPI_PM1A_EVT_BLK_LEN != 4) ||
+                 (ACPI_GPE0_BLK_LEN_V1 != 4));
+
+    switch (port)
+    {
+    case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ...
+        (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + ACPI_PM1A_EVT_BLK_LEN - 1):
Quoted 8 lines

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1415

Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +7 -0
+        reg = currd->arch.hvm_domain.acpi_io.pm1a;
+        break;
+    case ACPI_GPE0_BLK_ADDRESS_V1 ...
+        (ACPI_GPE0_BLK_ADDRESS_V1 + ACPI_GPE0_BLK_LEN_V1 - 1):
+        reg = currd->arch.hvm_domain.acpi_io.gpe;
+        break;
+    case 0xaf00 ... (0xaf00 + HVM_MAX_VCPUS/8 - 1):

That may need some documentation or a #define perhaps?

This will need to get into public header (xen/include/public/hvm/ioreq.h) since mk_dsdt.c is the other user.

Quoted 7 lines

Also just in case somebody decided it was funny and compile Xen with HVM_MAX_VCPUS set to say 4, won't this go in 0xfffffff region?

You may want to add a BUILD_BUG_ON for the HVM_MAX_VCPUS, like:

BUILD_BUGON(HVM_MAX_VCPUS > 8)?

OK (although I'd think compiler would flag the case statment like that)

Quoted 10 lines

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1423

Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +8 -0
+        is_cpu_map = 1;
+        break;
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+
+    if ( bytes == 0 )
+        return X86EMUL_OKAY;

Should you also check for other odd sizes? Say 3?

I think 3-byte read are OK, unless they are not allowed by higher-level ioreq code.

(And writes are already not allowed)

Quoted 5 lines

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1425

Quoted 3 lines
xen/arch/x86/hvm/ioreq.c +2 -0
+        if ( is_cpu_map )
+            /* CPU map should not be written. */

It shouldn't? Then who updates this? Oh we do it via the the hypercall. You may want to mention in this function how this all is suppose to work?

This is updated by the hypervisor's ACPI access handler (or qemu for HVM guests) and read by AML. I'll add a comment to this effect.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#28 lore raw

Re: [PATCH 08/10] pvh/acpi: Handle ACPI accesses for PVH guests

In reply to Konrad Rzeszutek Wilk
Quoted 42 lines
Quoted 1 line
Quoted 1 line · On 07.11.16 at 16:55, <[email protected]> wrote:
Quoted 5 lines · Boris Ostrovsky

---
CC: Paul Durrant <[email protected]>

---
 xen/arch/x86/hvm/ioreq.c | 66 

++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 21 lines
 1 file changed, 66 insertions(+)
xen/arch/x86/hvm/ioreq.c +11 -0
index 171ea82..ced7c92 100644
@@ -1392,6 +1392,72 @@ void hvm_ioreq_init(struct domain *d)
 static int acpi_ioaccess(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
+    unsigned int i;
+    unsigned int bits = bytes * 8;
+    uint8_t *reg = NULL;
+    unsigned idx = port & 3;
+    bool is_cpu_map = 0;
+    struct domain *currd = current->domain;
+
+    BUILD_BUG_ON((ACPI_PM1A_EVT_BLK_LEN != 4) ||
+                 (ACPI_GPE0_BLK_LEN_V1 != 4));
+
+    switch (port)

xen/arch/x86/hvm/ioreq.c void hvm_ioreq_init(struct domain *d) · line 1415

Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10 -0
+    {
+    case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ...
+        (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + ACPI_PM1A_EVT_BLK_LEN - 1):
+        reg = currd->arch.hvm_domain.acpi_io.pm1a;
+        break;
+    case ACPI_GPE0_BLK_ADDRESS_V1 ...
+        (ACPI_GPE0_BLK_ADDRESS_V1 + ACPI_GPE0_BLK_LEN_V1 - 1):
+        reg = currd->arch.hvm_domain.acpi_io.gpe;
+        break;
+    case 0xaf00 ... (0xaf00 + HVM_MAX_VCPUS/8 - 1):

That may need some documentation or a #define perhaps?

Quoted 6 lines

Also just in case somebody decided it was funny and compile Xen with HVM_MAX_VCPUS set to say 4, won't this go in 0xfffffff region?

You may want to add a BUILD_BUG_ON for the HVM_MAX_VCPUS, like:

BUILD_BUGON(HVM_MAX_VCPUS > 8)?

No. The expression wants to be 0xaf00 + (HVM_MAX_VCPUS - 1) / 8. And a BUILD_BUG_ON() should check the range doesn't spill into anything later (presumably starting at 0xb000).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#29 lore raw

PATCH 9/10 events/x86: Define SCI virtual interrupt

In reply to Boris Ostrovsky

PVH guests do not have IOAPIC which typically generates an SCI. For those guests SCI will be provided as a virtual interrupt.

We also move VIRQ_MCA definition out of xen-mca.h to keep all x86-specific VIRQ_ARCH_* in one place.

---
 xen/include/asm-x86/event.h           | 3 ++-
 xen/include/public/arch-x86/xen-mca.h | 2 --
 xen/include/public/arch-x86/xen.h     | 3 +++
 3 files changed, 5 insertions(+), 3 deletions(-)
xen/include/asm-x86/event.h +2 -1
index a82062e..9cad8e3 100644
@@ -38,9 +38,10 @@ static inline void local_event_delivery_enable(void)
     vcpu_info(current, evtchn_upcall_mask) = 0;
 }
 
-/* No arch specific virq definition now. Default to global. */
 static inline int arch_virq_is_global(uint32_t virq)
 {
+    if ( virq == VIRQ_SCI )
+	return 0;
     return 1;
 }
 
xen/include/public/arch-x86/xen-mca.h +0 -2
index a97e821..b76c53c 100644
@@ -91,8 +91,6 @@
 
 #ifndef __ASSEMBLY__
 
-#define VIRQ_MCA VIRQ_ARCH_0 /* G. (DOM0) Machine Check Architecture */
-
 /*
  * Machine Check Architecure:
  * structs are read-only and used to report all kinds of
xen/include/public/arch-x86/xen.h +3 -0
index cdd93c1..bffa3e0 100644
@@ -293,6 +293,9 @@ struct xen_arch_domainconfig {
 };
 #endif
 
+#define VIRQ_MCA VIRQ_ARCH_0 /* G. (DOM0) Machine Check Architecture */
+#define VIRQ_SCI VIRQ_ARCH_1 /* V. (PVH) ACPI interrupt */
+
 #endif /* !__ASSEMBLY__ */
 
 /*
Signature · 7 lines
2.7.4


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

Re: [PATCH 09/10] events/x86: Define SCI virtual interrupt

Quoted 5 lines · Boris Ostrovsky

PVH guests do not have IOAPIC which typically generates an SCI. For those guests SCI will be provided as a virtual interrupt.

We also move VIRQ_MCA definition out of xen-mca.h to keep all x86-specific VIRQ_ARCH_* in one place.

I somehow assumed that the ACPI MADT would be in the PVH guest so the SCI would be enumerated in there (the INT_SVC_OVR) along with the magic way one can figure this out.

But this implies that VIRQ17 is the SCI one? But how does that connect to the SCI being at 9 (or 20)?

I know we don't have the LAPIC in there but going forward we may really want it. Could you kindly explain how this VIRQ ends transumuting itself in the MADT value? Or would there be an event(virq)->emulated GSI to be set?

Sorry for not following that.

Also you may want to expand the PVH markdown as well to document how the CPU hotplug mechanism will work (or where you thinking to do that once you get feedback on this, in which case pls ignore me).

Quoted 59 lines
---
 xen/include/asm-x86/event.h           | 3 ++-
 xen/include/public/arch-x86/xen-mca.h | 2 --
 xen/include/public/arch-x86/xen.h     | 3 +++
 3 files changed, 5 insertions(+), 3 deletions(-)
xen/include/asm-x86/event.h +2 -1
index a82062e..9cad8e3 100644
@@ -38,9 +38,10 @@ static inline void local_event_delivery_enable(void)
     vcpu_info(current, evtchn_upcall_mask) = 0;
 }
 
-/* No arch specific virq definition now. Default to global. */
 static inline int arch_virq_is_global(uint32_t virq)
 {
+    if ( virq == VIRQ_SCI )
+	return 0;
     return 1;
 }
 
xen/include/public/arch-x86/xen-mca.h +0 -2
index a97e821..b76c53c 100644
@@ -91,8 +91,6 @@
 
 #ifndef __ASSEMBLY__
 
-#define VIRQ_MCA VIRQ_ARCH_0 /* G. (DOM0) Machine Check Architecture */
-
 /*
  * Machine Check Architecure:
  * structs are read-only and used to report all kinds of
xen/include/public/arch-x86/xen.h +3 -0
index cdd93c1..bffa3e0 100644
@@ -293,6 +293,9 @@ struct xen_arch_domainconfig {
 };
 #endif
 
+#define VIRQ_MCA VIRQ_ARCH_0 /* G. (DOM0) Machine Check Architecture */
+#define VIRQ_SCI VIRQ_ARCH_1 /* V. (PVH) ACPI interrupt */
+
 #endif /* !__ASSEMBLY__ */
 
 /*
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#31 lore raw

Re: [PATCH 09/10] events/x86: Define SCI virtual interrupt

Quoted 13 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Boris Ostrovsky

PVH guests do not have IOAPIC which typically generates an SCI. For those guests SCI will be provided as a virtual interrupt.

We also move VIRQ_MCA definition out of xen-mca.h to keep all x86-specific VIRQ_ARCH_* in one place.

I somehow assumed that the ACPI MADT would be in the PVH guest so the SCI would be enumerated in there (the INT_SVC_OVR) along with the magic way one can figure this out.

But this implies that VIRQ17 is the SCI one? But how does that connect to the SCI being at 9 (or 20)?

Quoted 6 lines

I know we don't have the LAPIC in there but going forward we may really want it. Could you kindly explain how this VIRQ ends transumuting itself in the MADT value? Or would there be an event(virq)->emulated GSI to be set?

Sorry for not following that.

The IRQ is whatever FADT specifies (in libacpi/static_tables.c), the guest shouldn't care. The expectation is that the guest will them bind VIRQ_SCI to that IRQ.

So in Linux this will be something like

    if (xen_pvh_domain())
               bind_virq_to_irq(VIRQ_SCI, 0,

acpi_gbl_FADT.sci_interrupt, 0);

(and then bind_virq_to_irq() is modified to take IRQ number as argument, if available).

Quoted 4 lines

Also you may want to expand the PVH markdown as well to document how the CPU hotplug mechanism will work (or where you thinking to do that once you get feedback on this, in which case pls ignore me).

I'll add a comment there.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#32 lore raw

PATCH 10/10 pvh: Send an SCI on VCPU hotplug event

In reply to Boris Ostrovsky

.. and update GPE0 registers.

---
 xen/arch/x86/domctl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
xen/arch/x86/domctl.c +12 -0
index 78b7d4b..8151fd7 100644
@@ -1439,6 +1439,18 @@ long arch_do_domctl(
             break;
 
         d->arch.avail_vcpus = num;
+
+        /*
+         * For PVH guests we need to send an SCI and set enable/status
+         * bits in GPE block (DSDT specifies _E02, so it's bit 2).
+         */
+        if ( is_hvm_domain(d) && d->arch.hvm_domain.ioreq_gmfn.mask == 0 )
+        {
+            d->arch.hvm_domain.acpi_io.gpe[2] =
+                d->arch.hvm_domain.acpi_io.gpe[0] = 4;
+            send_guest_vcpu_virq(d->vcpu[0], VIRQ_SCI);
+        }
+
         ret = 0;
         break;
     }
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#33 lore raw
In reply to Boris Ostrovsky
Quoted 7 lines · Boris Ostrovsky

This series adds support for ACPI-based VCPU hotplug for unprivileged PVH guests.

New XEN_DOMCTL_set_avail_vcpus is introduced and is called during guest creation and in response to 'xl vcpu-set' command. This domctl updates GPE0's status and enable registers and sends an SCI to the guest using (newly added) VIRQ_SCI.

Thankyou for doing this. Getting APCI hotplug working has been a low item on my TODO list for while now.

Some queries and comments however.

This series is currently very PVH centric, to the point of making it unusable for plain HVM guests. While I won't insist on you implementing this for HVM (there are some particularly awkward migration problems to be considered), I do insist that its implementation isn't tied implicitly to being PVH.

The first part of this will be controlling the hypervisor emulation of the PM1* blocks with an XEN_X86_EMU_* flag just like all other emulation.

Quoted 4 lines

Boris Ostrovsky (10):
x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

Why is this necessary? Given that a paravirtual hotplug mechanism already exists, why isn't its equivalent mechanism suitable?

Quoted 1 line

acpi: Define ACPI IO registers for PVH guests

Can Xen use pm1b, or does there have to be a pm1a available to the guest?

Quoted 2 lines

pvh: Set online VCPU map to avail_vcpus
acpi: Power and Sleep ACPI buttons are not emulated

PVH might not want power/sleep, but you cannot assume that HVM guests have a paravirtual mechnism of shutting down.

Quoted 2 lines

acpi: Make pmtimer optional in FADT
acpi: PVH guests need _E02 method

Patch 6 Reviewed-by: Andrew Cooper <[email protected]>

Quoted 1 line

pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Do not make any assumptions about PVHness based on IOREQ servers. It will not be true for usecases such as vGPU.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#34 lore raw
Quoted 13 lines · Andrew Cooper
Quoted 7 lines · Boris Ostrovsky

This series adds support for ACPI-based VCPU hotplug for unprivileged PVH guests.

New XEN_DOMCTL_set_avail_vcpus is introduced and is called during guest creation and in response to 'xl vcpu-set' command. This domctl updates GPE0's status and enable registers and sends an SCI to the guest using (newly added) VIRQ_SCI.

Thankyou for doing this. Getting APCI hotplug working has been a low item on my TODO list for while now.

Some queries and comments however.

Quoted 8 lines

This series is currently very PVH centric, to the point of making it unusable for plain HVM guests. While I won't insist on you implementing this for HVM (there are some particularly awkward migration problems to be considered), I do insist that its implementation isn't tied implicitly to being PVH.

The first part of this will be controlling the hypervisor emulation of the PM1* blocks with an XEN_X86_EMU_* flag just like all other emulation.

Something like XEN_X86_EMU_ACPI?

That would also eliminate the need for explicitly setting HVM_PARAM_NR_IOREQ_SERVER_PAGES to zero which I used as indication that we should have IO handler in the hypervisor. Paul (copied) didn't like that.

Quoted 6 lines
Quoted 4 lines

Boris Ostrovsky (10):
x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

Why is this necessary? Given that a paravirtual hotplug mechanism already exists, why isn't its equivalent mechanism suitable?

PV guests register a xenstore watch and the toolstack updates cpu's "available" entry. And ACPI codepath (at least for Linux guest) is not involved at all.

I don't think we can use anything like that in hypervisor.

Quoted 3 lines
Quoted 2 lines

acpi: Define ACPI IO registers for PVH guests

Can Xen use pm1b, or does there have to be a pm1a available to the guest?

pm1a is a required block (unlike pm1b). ACPICA, for example, always first checks pm1a when handling an SCI.

(And how having pm1b only would have helped?)

Quoted 5 lines
Quoted 3 lines

pvh: Set online VCPU map to avail_vcpus
acpi: Power and Sleep ACPI buttons are not emulated

PVH might not want power/sleep, but you cannot assume that HVM guests have a paravirtual mechnism of shutting down.

AFAIK they don't rely on a button-initiated codepath. At least Linux.

I don't know Windows path though. I can add ACPI_HAS_BUTTONS.

Quoted 8 lines
Quoted 3 lines

acpi: Make pmtimer optional in FADT
acpi: PVH guests need _E02 method

Patch 6 Reviewed-by: Andrew Cooper <[email protected]>

Quoted 1 line

pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Do not make any assumptions about PVHness based on IOREQ servers. It will not be true for usecases such as vGPU.

Is this comment related to the last patch or is it a general one? If it's the latter and we use XEN_X86_EMU_ACPI then I think this will not be an issue.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#35 lore raw
Quoted 20 lines · Boris Ostrovsky
Quoted 19 lines · Andrew Cooper
Quoted 7 lines · Boris Ostrovsky

This series adds support for ACPI-based VCPU hotplug for unprivileged PVH guests.

New XEN_DOMCTL_set_avail_vcpus is introduced and is called during guest creation and in response to 'xl vcpu-set' command. This domctl updates GPE0's status and enable registers and sends an SCI to the guest using (newly added) VIRQ_SCI.

Thankyou for doing this. Getting APCI hotplug working has been a low item on my TODO list for while now.

Some queries and comments however.

This series is currently very PVH centric, to the point of making it unusable for plain HVM guests. While I won't insist on you implementing this for HVM (there are some particularly awkward migration problems to be considered), I do insist that its implementation isn't tied implicitly to being PVH.

Quoted 3 lines
Quoted 2 lines

The first part of this will be controlling the hypervisor emulation of the PM1* blocks with an XEN_X86_EMU_* flag just like all other emulation.

Something like XEN_X86_EMU_ACPI?

Sounds good.

Quoted 4 lines

That would also eliminate the need for explicitly setting HVM_PARAM_NR_IOREQ_SERVER_PAGES to zero which I used as indication that we should have IO handler in the hypervisor. Paul (copied) didn't like that.

Definitely an improvement.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Boris Ostrovsky (10):
x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

Why is this necessary? Given that a paravirtual hotplug mechanism already exists, why isn't its equivalent mechanism suitable?

PV guests register a xenstore watch and the toolstack updates cpu's "available" entry. And ACPI codepath (at least for Linux guest) is not involved at all.

I don't think we can use anything like that in hypervisor.

There must be something in the hypervisor; what currently prevents the PV path ignoring xenstore and onlining CPUs themselves?

Or do we currently have nothing... ?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

acpi: Define ACPI IO registers for PVH guests

Can Xen use pm1b, or does there have to be a pm1a available to the guest?

pm1a is a required block (unlike pm1b). ACPICA, for example, always first checks pm1a when handling an SCI.

(And how having pm1b only would have helped?)

For the HVM case, I think we are going to need to one pm1 block belonging to qemu, and one belonging to Xen.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

pvh: Set online VCPU map to avail_vcpus
acpi: Power and Sleep ACPI buttons are not emulated

PVH might not want power/sleep, but you cannot assume that HVM guests have a paravirtual mechnism of shutting down.

AFAIK they don't rely on a button-initiated codepath. At least Linux.

I don't know Windows path though. I can add ACPI_HAS_BUTTONS.

Windows very definitely does respond to button presses (although not in a helpful way). Please keep them enabled by default for HVM guests, even if we disallow their use with PVH.

Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

acpi: Make pmtimer optional in FADT
acpi: PVH guests need _E02 method

Patch 6 Reviewed-by: Andrew Cooper <[email protected]>

Quoted 1 line

pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Do not make any assumptions about PVHness based on IOREQ servers. It will not be true for usecases such as vGPU.

Is this comment related to the last patch or is it a general one? If it's the latter and we use XEN_X86_EMU_ACPI then I think this will not be an issue.

It was about that patch specifically, but XEN_X86_EMU_ACPI is definitely the better way to go.

The only question is whether there might be other things APCI things we wish to emulate in the future (PCI hotplug by any chance?), in which case, should we be slightly more specific than just ACPI in the name label?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#36 lore raw
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

Boris Ostrovsky (10):
x86/domctl: Add XEN_DOMCTL_set_avail_vcpus

Why is this necessary? Given that a paravirtual hotplug mechanism already exists, why isn't its equivalent mechanism suitable?

PV guests register a xenstore watch and the toolstack updates cpu's "available" entry. And ACPI codepath (at least for Linux guest) is not involved at all.

Quoted 5 lines
Quoted 1 line

I don't think we can use anything like that in hypervisor.

There must be something in the hypervisor; what currently prevents the PV path ignoring xenstore and onlining CPUs themselves?

Or do we currently have nothing... ?

I don't think we have anything. libxl__set_vcpuonline_xenstore() is the only thing that the toolstack does.

HVM is *possibly* more strict in that onlining involves qemu but I am not sure even about that (especially qemu-trad, which also triggers hotplug via xenstore watch).

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

acpi: Define ACPI IO registers for PVH guests

Can Xen use pm1b, or does there have to be a pm1a available to the guest?

pm1a is a required block (unlike pm1b). ACPICA, for example, always first checks pm1a when handling an SCI.

(And how having pm1b only would have helped?)

For the HVM case, I think we are going to need to one pm1 block belonging to qemu, and one belonging to Xen.

The only place we use pm1 block in the hypervisor is for pmtimer (and I am actually not sure I see how qemu uses it for Xen guests).

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

acpi: Make pmtimer optional in FADT
acpi: PVH guests need _E02 method

Patch 6 Reviewed-by: Andrew Cooper <[email protected]>

Quoted 1 line

pvh/ioreq: Install handlers for ACPI-related PVH IO accesses

Do not make any assumptions about PVHness based on IOREQ servers. It will not be true for usecases such as vGPU.

Is this comment related to the last patch or is it a general one? If it's the latter and we use XEN_X86_EMU_ACPI then I think this will not be an issue.

Quoted 6 lines

It was about that patch specifically, but XEN_X86_EMU_ACPI is definitely the better way to go.

The only question is whether there might be other things APCI things we wish to emulate in the future (PCI hotplug by any chance?), in which case, should we be slightly more specific than just ACPI in the name label?

The flag would be meant to say that no ACPI accesses are emulated by qemu and that would be true for any accesses by PVH guests --- either CPU or PCI-related.

But the name is somewhat misleading, even without considering other APCI-related things: we do emulate ACPI, but in the hypervisor and not in qemu. (As ridiculous as it sounds that actually was one of the reasons why I didn't use a flag). EMU_NO_DM? But that's the whole PVH thing.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel