PVH VCPU hotplug support
v6 cover PVH VCPU hotplug support
This series adds support for ACPI-based VCPU hotplug for unprivileged PVH guests.
Main changes in v6:
* Generate SCI on VCPU map update by domctl
* Simplify public domctl structure
* Make ACPI registers accessible only by guest (and not by domctl)
* Update VCPU map under lock
* Fix pointer update in xc_acpi_access()
Boris Ostrovsky (12):
domctl: Add XEN_DOMCTL_acpi_access
x86/save: public/arch-x86/hvm/save.h is available to hypervisor and
tools only
pvh/acpi: Install handlers for ACPI-related PVH IO accesses pvh/acpi: Handle ACPI accesses for PVH guests x86/domctl: Handle ACPI access from domctl
events/x86: Define SCI virtual interrupt
pvh: Send an SCI on VCPU hotplug event
libxl: Update xenstore on VCPU hotplug for all guest types
tools: Call XEN_DOMCTL_acpi_access on PVH VCPU hotplug
pvh: Set online VCPU map to avail_vcpus
pvh/acpi: Save ACPI registers for PVH guests
docs: Describe PVHv2's VCPU hotplug procedure
docs/misc/hvmlite.markdown | 13 ++ tools/flask/policy/modules/dom0.te | 2 +- tools/flask/policy/modules/xen.if | 4 +- tools/libxc/include/xenctrl.h | 20 +++ tools/libxc/xc_domain.c | 41 ++++++ tools/libxl/libxl.c | 10 +- tools/libxl/libxl_arch.h | 4 + tools/libxl/libxl_arm.c | 6 + tools/libxl/libxl_dom.c | 10 ++ tools/libxl/libxl_x86.c | 11 ++ tools/libxl/libxl_x86_acpi.c | 6 +- xen/arch/x86/domctl.c | 7 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/acpi.c | 226 +++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 2 + xen/arch/x86/hvm/pmtimer.c | 9 ++ xen/common/domain.c | 1 + xen/common/domctl.c | 5 + xen/common/event_channel.c | 7 +- xen/include/asm-x86/domain.h | 2 + xen/include/asm-x86/hvm/domain.h | 5 + xen/include/public/arch-x86/hvm/save.h | 25 +++- xen/include/public/arch-x86/xen.h | 7 +- xen/include/public/domctl.h | 17 +++ xen/include/xen/domain.h | 1 + xen/include/xen/event.h | 8 ++ xen/include/xen/sched.h | 3 + xen/xsm/flask/hooks.c | 3 + xen/xsm/flask/policy/access_vectors | 2 + 29 files changed, 445 insertions(+), 13 deletions(-) create mode 100644 xen/arch/x86/hvm/acpi.c
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 1/12 domctl: Add XEN_DOMCTL_acpi_access
This domctl will allow toolstack to read and write some ACPI registers. It will be available to both x86 and ARM but will be implemented first only for x86
---
CC: Daniel De Graaf <[email protected]>
---
Changes in v6:
* Fold xen_acpi_access into xen_domctl_acpi_access
* Some new error return values
tools/flask/policy/modules/dom0.te | 2 +- tools/flask/policy/modules/xen.if | 4 ++-- xen/arch/x86/domctl.c | 7 +++++++ xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/acpi.c | 24 ++++++++++++++++++++++++ xen/include/asm-x86/hvm/domain.h | 3 +++ xen/include/public/domctl.h | 17 +++++++++++++++++ xen/xsm/flask/hooks.c | 3 +++ xen/xsm/flask/policy/access_vectors | 2 ++ 9 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 xen/arch/x86/hvm/acpi.c
tools/flask/policy/modules/dom0.te +1 -1
@@ -39,7 +39,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 acpi_access }; allow dom0_t dom0_t:resource { add remove };
tools/flask/policy/modules/xen.if +2 -2
@@ -52,7 +52,7 @@ define(`create_domain_common', ` settime setdomainhandle getvcpucontext set_misc_info }; 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 acpi_access }; 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 acpi_access }; ') # migrate_domain_out(priv, target)
xen/arch/x86/domctl.c +7 -0
@@ -1425,6 +1425,13 @@ long arch_do_domctl( }break ; +case XEN_DOMCTL_acpi_access: +if ( !is_hvm_domain (d) ) + ret = -ENODEV ; +else + ret =hvm_acpi_domctl_access (d, &domctl->u.acpi_access); +break ; +default : ret =iommu_do_domctl (domctl, d, u_domctl);break ;
xen/arch/x86/hvm/Makefile +1 -0
@@ -1,6 +1,7 @@ subdir-y += svm subdir-y += vmx +obj-y += acpi.o obj-y += asid.o obj-y += emulate.o obj-y += hpet.o
xen/arch/x86/hvm/acpi.c new file +24 -0
@@ -0,0 +1,24 @@ +/* acpi.c: ACPI access handling +* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +*/ +#include <xen/errno.h> +#include <xen/lib.h> +#include <xen/sched.h> + + +int hvm_acpi_domctl_access (struct domain *d, +const struct xen_domctl_acpi_access *access) +{ +return -ENOSYS ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/hvm/domain.h +3 -0
@@ -166,6 +166,9 @@ struct hvm_domain {#define hap_enabled (d) ((d)->arch.hvm_domain.hap_enabled) +int hvm_acpi_domctl_access (struct domain *d, +const struct xen_domctl_acpi_access *access); +#endif /* __ASM_X86_HVM_DOMAIN_H__ */ /*
xen/include/public/domctl.h +17 -0
@@ -1145,6 +1145,21 @@ struct xen_domctl_psr_cat_op {typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cat_op_t); +struct xen_domctl_acpi_access { +#define XEN_DOMCTL_ACPI_READ 0 +#define XEN_DOMCTL_ACPI_WRITE 1 +uint8_t rw;/* IN: Read or write */ +#define XEN_ACPI_SYSTEM_MEMORY 0 +#define XEN_ACPI_SYSTEM_IO 1 +uint8_t space_id;/* IN: Address space */ +uint8_t width;/* IN: Access size (bytes) */ +uint8_t pad[5 ]; +uint64_aligned_t address;/* IN: 64-bit address of register */ +XEN_GUEST_HANDLE_64 (void ) val;/* IN/OUT: data */ +}; +typedef struct xen_domctl_acpi_access xen_domctl_acpi_access_t ; +DEFINE_XEN_GUEST_HANDLE (xen_domctl_acpi_access_t); +struct xen_domctl {uint32_t cmd;#define XEN_DOMCTL_createdomain 1
@@ -1222,6 +1237,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_acpi_access 80#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -1284,6 +1300,7 @@ struct xen_domctl {struct xen_domctl_psr_cmt_op psr_cmt_op;struct xen_domctl_monitor_op monitor_op;struct xen_domctl_psr_cat_op psr_cat_op; +struct xen_domctl_acpi_access acpi_access;uint8_t pad[128 ]; } u; };
xen/xsm/flask/hooks.c +3 -0
@@ -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_acpi_access: +return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__ACPI_ACCESS ); +default :return avc_unknown_permission ("domctl" , cmd); }
xen/xsm/flask/policy/access_vectors +2 -0
@@ -246,6 +246,8 @@ class domain2 mem_sharing # XEN_DOMCTL_psr_cat_op psr_cat_op +# XEN_DOMCTL_acpi_access + acpi_access } # 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
Re: [PATCH v6 01/12] domctl: Add XEN_DOMCTL_acpi_access
Quoted 5 lines · Boris Ostrovsky
This domctl will allow toolstack to read and write some ACPI registers. It will be available to both x86 and ARM but will be implemented first only for x86
Signed-off-by Boris Ostrovsky <[email protected]>
Signature · 7 lines
Daniel De Graaf National Security Agency _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v6 01/12] domctl: Add XEN_DOMCTL_acpi_access
In reply to Boris Ostrovskyxen/arch/x86/hvm/acpi.c line 3
Quoted 9 lines
xen/arch/x86/hvm/acpi.c new file +3
-0@@ -0,0 +1,24 @@ +/* acpi.c: ACPI access handling +* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
2017.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v6 2/12 x86/save: public/arch-x86/hvm/save.h is available to hypervisor and tools only
In reply to Boris OstrovskyNoone else needs to include it since it is only useful to code that can made domctl calls. And public domctl.h can only be included by the toolstack or the hypervisor.
---
New in v6 (not required by the series).
Q: Should include/public/hvm/save.h have the same guards?
xen/include/public/arch-x86/hvm/save.h | 4 ++++ 1 file changed, 4 insertions(+)
xen/include/public/arch-x86/hvm/save.h +4 -0
@@ -26,6 +26,8 @@#ifndef __XEN_PUBLIC_HVM_SAVE_X86_H__#define __XEN_PUBLIC_HVM_SAVE_X86_H__ +#if defined(__XEN__) || defined(__XEN_TOOLS__) +/* * Save/restore header: general info about the save file. */
@@ -632,6 +634,8 @@ struct hvm_msr {*/ #define HVM_SAVE_CODE_MAX 20 +#endif /* __XEN__ || __XEN_TOOLS__ */ +#endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */ /*
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v6 02/12] x86/save: public/arch-x86/hvm/save.h is available to hypervisor and tools only
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 03.01.17 at 15:04, <[email protected]> wrote:
Noone else needs to include it since it is only useful to code that can made domctl calls. And public
domctl.hcan only be included by the toolstack or the hypervisor.Signed-off-by Boris Ostrovsky <[email protected]>---
New in v6 (not required by the series).Q: Should
include/public/hvm/save.hhave the same guards?
Yes. In fact the architecture specific header should never be included directly, so putting the guard just there (and ...
xen/include/public/arch-x86/hvm/save.h line 29
Quoted 7 lines
xen/include/public/arch-x86/hvm/save.h +1
-0@@ -26,6 +26,8 @@#ifndef __XEN_PUBLIC_HVM_SAVE_X86_H__#define __XEN_PUBLIC_HVM_SAVE_X86_H__ +#if defined(__XEN__) || defined(__XEN_TOOLS__)
... an #error here and in the ARM counterpart) would seem best.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v6 3/12 pvh/acpi: Install handlers for ACPI-related PVH IO accesses
In reply to Boris OstrovskyPVH guests will have ACPI accesses emulated by the hypervisor as opposed to QEMU (as is the case for HVM guests). This patch installs handler for accesses to PM1A, GPE0 (which is added to struct hvm_hw_acpi) and VCPU map. Logic for the handler will be provided by a later patch.
Whether or not the handler needs to be installed is decided based on the value of XEN_X86_EMU_ACPI_FF flag which indicates whether emulation is implemented in QEMU.
---
Changes in v6:
* Drop ifdef guards in include/public/arch-x86/hvm/save.h
xen/arch/x86/hvm/acpi.c | 31 +++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 2 ++ xen/include/asm-x86/domain.h | 2 ++ xen/include/asm-x86/hvm/domain.h | 1 + xen/include/public/arch-x86/hvm/save.h | 21 +++++++++++++++++++-- xen/include/public/arch-x86/xen.h | 4 +++- 6 files changed, 58 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/acpi.c +31 -0
@@ -6,6 +6,7 @@#include <xen/lib.h> #include <xen/sched.h> +#include <public/arch-x86/xen.h> int hvm_acpi_domctl_access (struct domain *d,const struct xen_domctl_acpi_access *access)
@@ -13,6 +14,36 @@ int hvm_acpi_domctl_access(struct domain *d,return -ENOSYS ; } +static int acpi_cpumap_guest_access (int dir,unsigned int port, +unsigned int bytes,uint32_t *val) +{ +return X86EMUL_UNHANDLEABLE ; +} + +static int acpi_guest_access (int dir,unsigned int port, +unsigned int bytes,uint32_t *val) +{ +return X86EMUL_UNHANDLEABLE ; +} + +void hvm_acpi_init (struct domain *d) +{ +if (has_acpi_dm_ff (d) ) +return ; + +register_portio_handler (d,XEN_ACPI_CPU_MAP , +XEN_ACPI_CPU_MAP_LEN , acpi_cpumap_guest_access); + +register_portio_handler (d,ACPI_GPE0_BLK_ADDRESS_V1 , +sizeof (d->arch.hvm_domain.acpi.gpe0_sts) + +sizeof (d->arch.hvm_domain.acpi.gpe0_en), + acpi_guest_access); +register_portio_handler (d,ACPI_PM1A_EVT_BLK_ADDRESS_V1 , +sizeof (d->arch.hvm_domain.acpi.pm1a_sts) + +sizeof (d->arch.hvm_domain.acpi.pm1a_en), + acpi_guest_access); +} +/* * Local variables: * mode: C
xen/arch/x86/hvm/hvm.c +2 -0
@@ -667,6 +667,8 @@ int hvm_domain_initialise(struct domain *d)hvm_ioreq_init (d); +hvm_acpi_init (d); +if (is_pvh_domain (d) ) {register_portio_handler (d,0 ,0x10003 , handle_pvh_io);
xen/include/asm-x86/domain.h +2 -0
@@ -426,6 +426,8 @@ struct arch_domain#define has_vvga (d) (!!((d)->arch.emulation_flags & XEN_X86_EMU_VGA))#define has_viommu (d) (!!((d)->arch.emulation_flags & XEN_X86_EMU_IOMMU))#define has_vpit (d) (!!((d)->arch.emulation_flags & XEN_X86_EMU_PIT)) +#define has_acpi_dm_ff (d) (!!((d)->arch.emulation_flags & \ + XEN_X86_EMU_ACPI_DM_FF))#define has_arch_pdevs (d) (!list_empty(&(d)->arch.pdev_list))
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -166,6 +166,7 @@ struct hvm_domain {#define hap_enabled (d) ((d)->arch.hvm_domain.hap_enabled) +void hvm_acpi_init (struct domain *d);int hvm_acpi_domctl_access (struct domain *d,const struct xen_domctl_acpi_access *access);
xen/include/public/arch-x86/hvm/save.h +19 -2
@@ -529,14 +529,31 @@ DECLARE_HVM_SAVE_TYPE(HPET, 12, struct hvm_hw_hpet);/* * PM timer */ -struct hvm_hw_pmtimer {uint32_t tmr_val;/* PM_TMR_BLK.TMR_VAL: 32bit free-running counter */ uint16_t pm1a_sts;/* PM1a_EVT_BLK.PM1a_STS: status register */ uint16_t pm1a_en;/* PM1a_EVT_BLK.PM1a_EN: enable register */ +uint16_t gpe0_sts; +uint16_t gpe0_en; +}; + +struct hvm_hw_pmtimer_compat { +uint32_t tmr_val; +uint16_t pm1a_sts; +uint16_t pm1a_en; }; -DECLARE_HVM_SAVE_TYPE(PMTIMER, 13, struct hvm_hw_pmtimer); +static inline int _hvm_hw_fix_pmtimer (void *h,uint32_t size) +{ +struct hvm_hw_pmtimer *acpi = (struct hvm_hw_pmtimer *)h; + +if ( size ==sizeof (struct hvm_hw_pmtimer_compat ) ) + acpi->gpe0_sts = acpi->gpe0_en =0 ; +return 0 ; +} + +DECLARE_HVM_SAVE_TYPE_COMPAT(PMTIMER, 13, struct hvm_hw_pmtimer, \ + struct hvm_hw_pmtimer_compat, _hvm_hw_fix_pmtimer);/* * MTRR MSRs
xen/include/public/arch-x86/xen.h +3 -1
@@ -283,12 +283,14 @@ struct xen_arch_domainconfig {#define XEN_X86_EMU_IOMMU (1U<<_XEN_X86_EMU_IOMMU)#define _XEN_X86_EMU_PIT 8#define XEN_X86_EMU_PIT (1U<<_XEN_X86_EMU_PIT) +#define _XEN_X86_EMU_ACPI_DM_FF 9 +#define XEN_X86_EMU_ACPI_DM_FF (1U<<_XEN_X86_EMU_ACPI_DM_FF)#define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ - XEN_X86_EMU_PIT) + XEN_X86_EMU_PIT | XEN_X86_EMU_ACPI_DM_FF)uint32_t emulation_flags; };
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 4/12 pvh/acpi: Handle ACPI accesses for PVH guests
In reply to Boris OstrovskySubsequent domctl access VCPU map will use the same code. We create acpi_cpumap_access_common() routines in anticipation of these changes.
---
Changes in v6:
* ACPI registers are only accessed by guest code (not by domctl), thus acpi_access_common() is no longer needed
* Adjusted access direction (RW) to be a boolean.
* Dropped unnecessary masking of status register
xen/arch/x86/hvm/acpi.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++- xen/common/domain.c | 1 + xen/common/domctl.c | 5 +++ xen/include/xen/sched.h | 3 ++ 4 files changed, 117 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/acpi.c +108 -2
@@ -2,12 +2,43 @@* * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. */ +#include <xen/acpi.h> #include <xen/errno.h> #include <xen/lib.h> #include <xen/sched.h> #include <public/arch-x86/xen.h> +static int acpi_cpumap_access_common (struct domain *d,bool is_write, +unsigned int port, +unsigned int bytes,uint32_t *val) +{ +unsigned int first_byte = port -XEN_ACPI_CPU_MAP ; + +BUILD_BUG_ON (XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN + >ACPI_GPE0_BLK_ADDRESS_V1 ); + +if ( !is_write ) + { +uint32_t mask = (bytes <4 ) ? ~0U << (bytes *8 ) :0 ; + +/* +* Clear bits that we are about to read to in case we +* copy fewer than @bytes. +*/ + *val &= mask; + +if ( ((d->max_vcpus +7 ) /8 ) > first_byte ) +memcpy (val, (uint8_t *)d->avail_vcpus + first_byte, +min (bytes, ((d->max_vcpus +7 ) /8 ) - first_byte)); + } +else +/* Guests do not write CPU map */ +return X86EMUL_UNHANDLEABLE ; + +return X86EMUL_OKAY ; +} +int hvm_acpi_domctl_access (struct domain *d,const struct xen_domctl_acpi_access *access) {
@@ -17,13 +48,88 @@ int hvm_acpi_domctl_access(struct domain *d,static int acpi_cpumap_guest_access (int dir,unsigned int port,unsigned int bytes,uint32_t *val) { -return X86EMUL_UNHANDLEABLE ; +return acpi_cpumap_access_common (current->domain, + (dir ==IOREQ_WRITE ) ? true : false, + port, bytes, val); }static int acpi_guest_access (int dir,unsigned int port,unsigned int bytes,uint32_t *val) { -return X86EMUL_UNHANDLEABLE ; +struct domain *d = current->domain; +uint16_t *sts =NULL , *en =NULL ; +const uint16_t *mask_en =NULL ; +static const uint16_t pm1a_en_mask =ACPI_BITMASK_GLOBAL_LOCK_ENABLE ; +static const uint16_t gpe0_en_mask =1U <<XEN_ACPI_GPE0_CPUHP_BIT ; + +ASSERT (!has_acpi_dm_ff (d)); + +switch ( port ) + { + case ACPI_PM1A_EVT_BLK_ADDRESS_V1 ... +ACPI_PM1A_EVT_BLK_ADDRESS_V1 + +sizeof (d->arch.hvm_domain.acpi.pm1a_sts) + +sizeof (d->arch.hvm_domain.acpi.pm1a_en): + + sts = &d->arch.hvm_domain.acpi.pm1a_sts; + en = &d->arch.hvm_domain.acpi.pm1a_en; + mask_en = &pm1a_en_mask; +break ; + + case ACPI_GPE0_BLK_ADDRESS_V1 ... +ACPI_GPE0_BLK_ADDRESS_V1 + +sizeof (d->arch.hvm_domain.acpi.gpe0_sts) + +sizeof (d->arch.hvm_domain.acpi.gpe0_en): + + sts = &d->arch.hvm_domain.acpi.gpe0_sts; + en = &d->arch.hvm_domain.acpi.gpe0_en; + mask_en = &gpe0_en_mask; +break ; + +default : +return X86EMUL_UNHANDLEABLE ; + } + +if ( dir ==IOREQ_READ ) + { +uint32_t mask = (bytes <4 ) ? ~0U << (bytes *8 ) :0 ; +uint32_t data = (((uint32_t )*en) <<16 ) | *sts; + + data >>=8 * (port &3 ); + *val = (*val & mask) | (data & ~mask); + } +else + { +uint32_t v = *val; + +/* Status register is write-1-to-clear */ +switch ( port &3 ) + { +case 0 : + *sts &= ~(v &0xff ); +if ( !--bytes ) +break ; + v >>=8 ; +/* fallthrough */ +case 1 : + *sts &= ~((v &0xff ) <<8 ); +if ( !--bytes ) +break ; + v >>=8 ; +/* fallthrough */ +case 2 : + *en = ((*en &0xff00 ) | (v &0xff )) & *mask_en; +if ( !--bytes ) +break ; + v >>=8 ; +/* fallthrough */ +case 3 : + *en = (((v &0xff ) <<8 ) | (*en &0xff )) & *mask_en; +break ; + } + } + +return X86EMUL_OKAY ; }void hvm_acpi_init (struct domain *d)
xen/common/domain.c +1 -0
@@ -847,6 +847,7 @@ static void complete_domain_destroy(struct rcu_head *head)xsm_free_security_domain (d);free_cpumask_var (d->domain_dirty_cpumask);xfree (d->vcpu); +xfree (d->avail_vcpus);free_domain_struct (d);send_global_virq (VIRQ_DOM_EXC );
xen/common/domctl.c +5 -0
@@ -651,6 +651,11 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) goto maxvcpu_out; } + d->avail_vcpus = xzalloc_array(unsigned long, +BITS_TO_LONGS (d->max_vcpus)); +if ( !d->avail_vcpus ) + goto maxvcpu_out; + ret =0 ; maxvcpu_out:
xen/include/xen/sched.h +3 -0
@@ -315,6 +315,9 @@ struct domainunsigned int max_vcpus;struct vcpu **vcpu; +/* Bitmap of available VCPUs. */ +unsigned long *avail_vcpus; +shared_info_t *shared_info;/* shared data area */ spinlock_t domain_lock;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 5/12 x86/domctl: Handle ACPI access from domctl
In reply to Boris Ostrovsky---
Changes in v6:
* Adjustments to to patch 4 changes.
* Added a spinlock for VCPU map access
* Return an error on guest trying to write VCPU map
xen/arch/x86/hvm/acpi.c | 57 +++++++++++++++++++++++++++++++++++----- xen/include/asm-x86/hvm/domain.h | 1 + 2 files changed, 52 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/acpi.c +51 -6
@@ -7,17 +7,22 @@#include <xen/lib.h> #include <xen/sched.h> +#include <asm/guest_access.h> +#include <public/arch-x86/xen.h> -static int acpi_cpumap_access_common (struct domain *d,bool is_write, -unsigned int port, +static int acpi_cpumap_access_common (struct domain *d,bool is_guest_access, +bool is_write,unsigned int port,unsigned int bytes,uint32_t *val) {unsigned int first_byte = port -XEN_ACPI_CPU_MAP ; +int rc =X86EMUL_OKAY ;BUILD_BUG_ON (XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN >ACPI_GPE0_BLK_ADDRESS_V1 ); +spin_lock (&d->arch.hvm_domain.acpi_lock); +if ( !is_write ) {uint32_t mask = (bytes <4 ) ? ~0U << (bytes *8 ) :0 ;
@@ -32,23 +37,61 @@ static int acpi_cpumap_access_common(struct domain *d, bool is_write,memcpy (val, (uint8_t *)d->avail_vcpus + first_byte,min (bytes, ((d->max_vcpus +7 ) /8 ) - first_byte)); } +else if ( !is_guest_access ) +memcpy ((uint8_t *)d->avail_vcpus + first_byte, val, +min (bytes, ((d->max_vcpus +7 ) /8 ) - first_byte));else /* Guests do not write CPU map */ -return X86EMUL_UNHANDLEABLE ; + rc =X86EMUL_UNHANDLEABLE ; -return X86EMUL_OKAY ; +spin_unlock (&d->arch.hvm_domain.acpi_lock); + +return rc; }int hvm_acpi_domctl_access (struct domain *d,const struct xen_domctl_acpi_access *access) { -return -ENOSYS ; +unsigned int bytes, i; +uint32_t val =0 ; +uint8_t *ptr = (uint8_t *)&val; +int rc; +bool is_write = (access->rw ==XEN_DOMCTL_ACPI_WRITE ) ? true : false; + +if (has_acpi_dm_ff (d) ) +return -EOPNOTSUPP ; + +if ( access->space_id !=XEN_ACPI_SYSTEM_IO ) +return -EINVAL ; + +if ( !((access->address >=XEN_ACPI_CPU_MAP ) && + (access->address <XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN )) ) +return -ENODEV ; + +for ( i =0 ; i < access->width; i +=sizeof (val) ) + { + bytes = (access->width - i >sizeof (val)) ? +sizeof (val) : access->width - i; + +if ( is_write &©_from_guest_offset (ptr, access->val, i, bytes) ) +return -EFAULT ; + + rc =acpi_cpumap_access_common (d, false, is_write, + access->address, bytes, &val); +if ( rc ) +return rc; + +if ( !is_write &©_to_guest_offset (access->val, i, ptr, bytes) ) +return -EFAULT ; + } + +return 0 ; }static int acpi_cpumap_guest_access (int dir,unsigned int port,unsigned int bytes,uint32_t *val) { -return acpi_cpumap_access_common (current->domain, +return acpi_cpumap_access_common (current->domain, true, (dir ==IOREQ_WRITE ) ? true : false, port, bytes, val); }
@@ -148,6 +191,8 @@ void hvm_acpi_init(struct domain *d)sizeof (d->arch.hvm_domain.acpi.pm1a_sts) +sizeof (d->arch.hvm_domain.acpi.pm1a_en), acpi_guest_access); + +spin_lock_init (&d->arch.hvm_domain.acpi_lock); }/*
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -111,6 +111,7 @@ struct hvm_domain {*/ #define hvm_hw_acpi hvm_hw_pmtimerstruct hvm_hw_acpi acpi; +spinlock_t acpi_lock;/* VCPU which is current target for 8259 interrupts. */ struct vcpu *i8259_target;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v6 05/12] x86/domctl: Handle ACPI access from domctl
Quoted 7 lines · Boris Ostrovsky
Signed-off-by Boris Ostrovsky <[email protected]>---
Changes in v6:
* Adjustments to to patch 4 changes.
* Added a spinlock for VCPU map access
* Return an error on guest trying to write VCPU map
snip
Quoted 55 lines
xen/arch/x86/hvm/acpi.c +28
-5-static int acpi_cpumap_access_common (struct domain *d,bool is_write, -unsigned int port, +static int acpi_cpumap_access_common (struct domain *d,bool is_guest_access, +bool is_write,unsigned int port,unsigned int bytes,uint32_t *val) {unsigned int first_byte = port -XEN_ACPI_CPU_MAP ; +int rc =X86EMUL_OKAY ;BUILD_BUG_ON (XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN >ACPI_GPE0_BLK_ADDRESS_V1 ); +spin_lock (&d->arch.hvm_domain.acpi_lock); +if ( !is_write ) {uint32_t mask = (bytes <4 ) ? ~0U << (bytes *8 ) :0 ;@@ -32,23 +37,61 @@ static int acpi_cpumap_access_common(struct domain *d, bool is_write,memcpy (val, (uint8_t *)d->avail_vcpus + first_byte,min (bytes, ((d->max_vcpus +7 ) /8 ) - first_byte)); } +else if ( !is_guest_access ) +memcpy ((uint8_t *)d->avail_vcpus + first_byte, val, +min (bytes, ((d->max_vcpus +7 ) /8 ) - first_byte));else /* Guests do not write CPU map */ -return X86EMUL_UNHANDLEABLE ; + rc =X86EMUL_UNHANDLEABLE ; -return X86EMUL_OKAY ; +spin_unlock (&d->arch.hvm_domain.acpi_lock); + +return rc; }int hvm_acpi_domctl_access (struct domain *d,const struct xen_domctl_acpi_access *access) { -return -ENOSYS ; +unsigned int bytes, i; +uint32_t val =0 ; +uint8_t *ptr = (uint8_t *)&val; +int rc; +bool is_write = (access->rw ==XEN_DOMCTL_ACPI_WRITE ) ? true : false; + +if (has_acpi_dm_ff (d) ) +return -EOPNOTSUPP ; + +if ( access->space_id !=XEN_ACPI_SYSTEM_IO ) +return -EINVAL ; + +if ( !((access->address >=XEN_ACPI_CPU_MAP ) && + (access->address <XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN )) ) +return -ENODEV ; +
xen/arch/x86/hvm/acpi.c static int acpi_cpumap_access_common(struct domain *d, bool is_write, · line 80
Quoted 10 lines
xen/arch/x86/hvm/acpi.c +10
-0+for ( i =0 ; i < access->width; i +=sizeof (val) ) + { + bytes = (access->width - i >sizeof (val)) ? +sizeof (val) : access->width - i; + +if ( is_write &©_from_guest_offset (ptr, access->val, i, bytes) ) +return -EFAULT ; + + rc =acpi_cpumap_access_common (d, false, is_write, + access->address, bytes, &val);
While I'm looking at this code...
This doesn't work if access->width > sizeof(val) (4 bytes). The same value (access->address) is always passed into acpi_cpumap_access_common for 'port' and this is used as an offset into the avail_cpus array. So the offset is unchanged and only the first 4 bytes of avail_cpus ever gets changed.
Signature · 6 lines
Ross Lagerwall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v6 05/12] x86/domctl: Handle ACPI access from domctl
Quoted 80 lines · Ross Lagerwall
Quoted 7 lines · Boris Ostrovsky
Signed-off-by Boris Ostrovsky <[email protected]>---
Changes in v6:
* Adjustments to to patch 4 changes.
* Added a spinlock for VCPU map access
* Return an error on guest trying to write VCPU mapsnip
Quoted 71 lines
xen/arch/x86/hvm/acpi.c +1
-2-static int acpi_cpumap_access_common(struct domain *d, bool is_write, - unsigned int port, +static int acpi_cpumap_access_common(struct domain *d, bool
is_guest_access,
+ boolis_write, unsigned int port,
unsigned int bytes,uint32_t
*val){ unsigned int first_byte = port - XEN_ACPI_CPU_MAP;xen/arch/x86/hvm/acpi.c +35
-3+int rc =X86EMUL_OKAY ;BUILD_BUG_ON (XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN >ACPI_GPE0_BLK_ADDRESS_V1 ); +spin_lock (&d->arch.hvm_domain.acpi_lock); +if ( !is_write ) {uint32_t mask = (bytes <4 ) ? ~0U << (bytes *8 ) :0 ;@@ -32,23 +37,61 @@ static int acpi_cpumap_access_common(struct domain *d, bool is_write, memcpy(val, (uint8_t *)d->avail_vcpus + first_byte, min(bytes, ((d->max_vcpus + 7) / 8) - first_byte)); } +else if ( !is_guest_access ) +memcpy ((uint8_t *)d->avail_vcpus + first_byte, val, +min (bytes, ((d->max_vcpus +7 ) /8 ) - first_byte));else /* Guests do not write CPU map */ -return X86EMUL_UNHANDLEABLE ; + rc =X86EMUL_UNHANDLEABLE ; -return X86EMUL_OKAY ; +spin_unlock (&d->arch.hvm_domain.acpi_lock); + +return rc; }int hvm_acpi_domctl_access (struct domain *d,const struct xen_domctl_acpi_access *access) { -return -ENOSYS ; +unsigned int bytes, i; +uint32_t val =0 ; +uint8_t *ptr = (uint8_t *)&val; +int rc; +bool is_write = (access->rw ==XEN_DOMCTL_ACPI_WRITE ) ? true : false; + +if (has_acpi_dm_ff (d) ) +return -EOPNOTSUPP ; + +if ( access->space_id !=XEN_ACPI_SYSTEM_IO ) +return -EINVAL ; + +if ( !((access->address >=XEN_ACPI_CPU_MAP ) && + (access->address <XEN_ACPI_CPU_MAP +XEN_ACPI_CPU_MAP_LEN )) ) +return -ENODEV ; + +for ( i =0 ; i < access->width; i +=sizeof (val) ) + { + bytes = (access->width - i >sizeof (val)) ? +sizeof (val) : access->width - i; + +if ( is_write &©_from_guest_offset (ptr, access->val, i, bytes) ) +return -EFAULT ; + + rc = acpi_cpumap_access_common(d, false, is_write,
Quoted 8 lines
xen/arch/x86/hvm/acpi.c static int acpi_cpumap_access_common(struct domain *d, bool is_write, · line 80
Quoted 1 line
xen/arch/x86/hvm/acpi.c +1
-0+ access->address, bytes, &val);While I'm looking at this code...
This doesn't work ifaccess->width> sizeof(val) (4 bytes). The same value (access->address) is always passed intoacpi_cpumap_access_commonfor 'port' and this is used as an offset into theavail_cpusarray. So the offset is unchanged and only the first 4 bytes ofavail_cpusever gets changed.
I'd have to go back to the series (haven't looked at it since it was posted back in January) but I think I enforce somewhere size of the access to fit into 4 bytes. And if not then you are right.
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v6 6/12 events/x86: Define SCI virtual interrupt
In reply to Boris OstrovskyPVH guests do not have IOAPIC which typically generates an SCI. For those guests SCI will be provided as a virtual interrupt.
Copy VIRQ_MCA definition from of xen-mca.h to xen.h to keep all x86-specific VIRQ_ARCH_* in one place. (However, because we don't want to require inclusion of xen.h in xen-mca.h we preserve original definition of VIRQ_MCA as well.)
--- xen/include/public/arch-x86/xen.h | 3 +++ 1 file changed, 3 insertions(+)
xen/include/public/arch-x86/xen.h +3 -0
@@ -302,6 +302,9 @@ struct xen_arch_domainconfig {#define XEN_ACPI_GPE0_CPUHP_BIT 2#endif +#define VIRQ_MCA VIRQ_ARCH_0/* G. (DOM0) Machine Check Architecture */ +#define VIRQ_SCI VIRQ_ARCH_1/* G. (PVH) ACPI interrupt */ +#endif /* !__ASSEMBLY__ */ /*
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 7/12 pvh: Send an SCI on VCPU hotplug event
In reply to Boris OstrovskySend and SCI when VCPU map is updated by domctl or when guest sets GPE0 enable bit and status bit is already set.
Also update send_guest_global_virq() to handle cases when VCPU0 is offlined.
---
Changes in v6:
* Change conditions causing the SCI to be generated:
- domctl write to VCPU map
- Enabling a pending GPE0 event
xen/arch/x86/hvm/acpi.c | 20 ++++++++++++++++++++ xen/common/event_channel.c | 7 +++++-- xen/include/xen/domain.h | 1 + xen/include/xen/event.h | 8 ++++++++ 4 files changed, 34 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/acpi.c +20 -0
@@ -4,6 +4,7 @@*/ #include <xen/acpi.h> #include <xen/errno.h> +#include <xen/event.h> #include <xen/lib.h> #include <xen/sched.h>
@@ -85,6 +86,17 @@ int hvm_acpi_domctl_access(struct domain *d,return -EFAULT ; } +/* +* For simplicity don't verify whether CPU map changed and +* always send an SCI on a write (provided it's enabled). +*/ +if ( is_write ) + { + d->arch.hvm_domain.acpi.gpe0_sts |=1U <<XEN_ACPI_GPE0_CPUHP_BIT ; +if ( d->arch.hvm_domain.acpi.gpe0_en & (1U <<XEN_ACPI_GPE0_CPUHP_BIT ) ) +send_guest_global_virq (d,VIRQ_SCI ); + } +return 0 ; }
@@ -144,6 +156,7 @@ static int acpi_guest_access(int dir, unsigned int port,else {uint32_t v = *val; +uint16_t en_orig = *en;/* Status register is write-1-to-clear */ switch ( port & 3 )
@@ -170,6 +183,13 @@ static int acpi_guest_access(int dir, unsigned int port, *en = (((v &0xff ) <<8 ) | (*en &0xff )) & *mask_en;break ; } + +/* +* If an event became enabled and corresponding status bit is set +* then send an SCI to the guest. +*/ +if ( (*en & ~en_orig) & *sts ) +send_guest_global_virq (d,VIRQ_SCI ); }return X86EMUL_OKAY ;
xen/common/event_channel.c +5 -2
@@ -727,7 +727,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)spin_unlock_irqrestore (&v->virq_lock, flags); } -static void send_guest_global_virq (struct domain *d,uint32_t virq) +void send_guest_global_virq (struct domain *d,uint32_t virq) {unsigned long flags;int port;
@@ -739,7 +739,10 @@ static void send_guest_global_virq(struct domain *d, uint32_t virq)if (unlikely (d ==NULL ) ||unlikely (d->vcpu ==NULL ) )return ; - v = d->vcpu[0 ]; +/* Send to first available VCPU */ +for_each_vcpu (d, v) +if (is_vcpu_online (v) ) +break ;if (unlikely (v ==NULL ) )return ;
xen/include/xen/domain.h +1 -0
@@ -52,6 +52,7 @@ void vcpu_destroy(struct vcpu *v);int map_vcpu_info (struct vcpu *v,unsigned long gfn,unsigned offset);void unmap_vcpu_info (struct vcpu *v); +int arch_update_avail_vcpus (struct domain *d);int arch_domain_create (struct domain *d,unsigned int domcr_flags,struct xen_arch_domainconfig *config);
xen/include/xen/event.h +8 -0
@@ -23,6 +23,14 @@void send_guest_vcpu_virq (struct vcpu *v,uint32_t virq);/* +* send_guest_global_virq: Notify guest via a global VIRQ. +* @d: domain to which virtual IRQ should be sent. First +* online VCPU will be selected. +* @virq: Virtual IRQ number (VIRQ_*) +*/ +void send_guest_global_virq (struct domain *d,uint32_t virq); + +/* * send_global_virq: Notify the domain handling a global VIRQ. * @virq: Virtual IRQ number (VIRQ_*) */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 8/12 libxl: Update xenstore on VCPU hotplug for all guest types
In reply to Boris OstrovskyCurrently HVM guests that use upstream qemu do not update xenstore's availability entry for VCPUs. While it is not strictly necessary for hotplug to work, xenstore ends up not reflecting actual status of VCPUs. We should fix this.
--- tools/libxl/libxl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +4 -2
@@ -5148,7 +5148,6 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)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);
@@ -5158,11 +5157,14 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) }break ;case LIBXL_DOMAIN_TYPE_PV : - rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap, &info);break ;default : rc =ERROR_INVAL ; } + +if (!rc) + rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap, &info); + out:libxl_dominfo_dispose (&info);GC_FREE ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v6 08/12] libxl: Update xenstore on VCPU hotplug for all guest types
Quoted 6 lines · Boris Ostrovsky
Currently HVM guests that use upstream qemu do not update xenstore's availability entry for VCPUs. While it is not strictly necessary for hotplug to work, xenstore ends up not reflecting actual status of VCPUs. We should fix this.
Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 35 lines
--- tools/libxl/libxl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/libxl/libxl.c +4
-2@@ -5148,7 +5148,6 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)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);@@ -5158,11 +5157,14 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap) }break ;case LIBXL_DOMAIN_TYPE_PV : - rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap, &info);break ;default : rc =ERROR_INVAL ; } + +if (!rc) + rc =libxl__set_vcpuonline_xenstore (gc, domid, cpumap, &info); + out:libxl_dominfo_dispose (&info);GC_FREE ;Signature · 1 line
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v6 9/12 tools: Call XEN_DOMCTL_acpi_access on PVH VCPU hotplug
In reply to Boris OstrovskyProvide libxc interface for accessing ACPI via XEN_DOMCTL_acpi_access.
When a VCPU is hot-(un)plugged to/from a PVH guest update VCPU map by writing to ACPI's XEN_ACPI_CPU_MAP register and then set GPE0 status bit in GPE0.status.
---
Changes in v6:
* Fix xc_acpi_access() by updating the val pointer passed to the hypercall and take some domctl initializers out of the loop
* Don't update GPE0 status on VCPU map update as it is no longer necessary
tools/libxc/include/xenctrl.h | 20 ++++++++++++++++++++ tools/libxc/xc_domain.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.c | 4 ++++ tools/libxl/libxl_arch.h | 4 ++++ tools/libxl/libxl_arm.c | 6 ++++++ tools/libxl/libxl_dom.c | 10 ++++++++++ tools/libxl/libxl_x86.c | 11 +++++++++++ 7 files changed, 96 insertions(+)
tools/libxc/include/xenctrl.h +20 -0
@@ -2710,6 +2710,26 @@ int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout);int xc_livepatch_unload (xc_interface *xch,char *name,uint32_t timeout);int xc_livepatch_replace (xc_interface *xch,char *name,uint32_t timeout); +int xc_acpi_access (xc_interface *xch,domid_t domid, +uint8_t rw,uint8_t space_id,unsigned long addr, +unsigned int bytes,void *val); + +static inline int xc_acpi_ioread (xc_interface *xch,domid_t domid, +unsigned long port, +unsigned int bytes,void *val) +{ +return xc_acpi_access (xch, domid,XEN_DOMCTL_ACPI_READ ,XEN_ACPI_SYSTEM_IO , + port, bytes, val); +} + +static inline int xc_acpi_iowrite (xc_interface *xch,domid_t domid, +unsigned long port, +unsigned int bytes,void *val) +{ +return xc_acpi_access (xch, domid,XEN_DOMCTL_ACPI_WRITE ,XEN_ACPI_SYSTEM_IO , + port, bytes, val); +} +/* Compat shims */ #include "xenctrl_compat.h"
tools/libxc/xc_domain.c +41 -0
47 lines not on this page · raw message
tools/libxl/libxl.c +4 -0
@@ -5147,7 +5147,11 @@ 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 : +break ;case LIBXL_DEVICE_MODEL_VERSION_NONE : + rc =libxl__arch_set_vcpuonline (gc, domid, cpumap); +if (rc <0 ) +LOGE (ERROR ,"Can't change vcpu online map (%d)" , rc);break ;case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : rc =libxl__set_vcpuonline_qmp (gc, domid, cpumap, &info);
tools/libxl/libxl_arch.h +4 -0
@@ -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__gc *gc, uint32_t domid, +libxl_bitmap *cpumap); +#if defined(__i386__) || defined(__x86_64__)#define LAPIC_BASE_ADDRESS 0xfee00000
tools/libxl/libxl_arm.c +6 -0
@@ -126,6 +126,12 @@ out:return rc; } +int libxl__arch_set_vcpuonline (libxl__gc *gc,uint32_t domid, +libxl_bitmap *cpumap) +{ +return ERROR_FAIL ; +} + static struct arch_info { const char *guest_type; const char *timer_compat;
tools/libxl/libxl_dom.c +10 -0
@@ -309,6 +309,16 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,return ERROR_FAIL ; } +if ((info->type ==LIBXL_DOMAIN_TYPE_HVM ) && + (libxl__device_model_version_running (gc, domid) == +LIBXL_DEVICE_MODEL_VERSION_NONE )) { + rc =libxl__arch_set_vcpuonline (gc, domid, &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 +11 -0
@@ -3,6 +3,9 @@#include <xc_dom.h> +#include <xen/arch-x86/xen.h> +#include <xen/hvm/ioreq.h> +int libxl__arch_domain_prepare_config (libxl__gc *gc,libxl_domain_config *d_config,xc_domain_configuration_t *xc_config)
@@ -368,6 +371,14 @@ int libxl__arch_extra_memory(libxl__gc *gc,return 0 ; } +int libxl__arch_set_vcpuonline (libxl__gc *gc,uint32_t domid, +libxl_bitmap *cpumap) +{ +/*Update VCPU map. */ +return xc_acpi_iowrite (CTX ->xch, domid,XEN_ACPI_CPU_MAP , + cpumap->size, cpumap->map); +} + int libxl__arch_domain_init_hw_description(libxl__gc *gc, libxl_domain_build_info *info, libxl__domain_build_state *state,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 10/12 pvh: Set online VCPU map to avail_vcpus
In reply to Boris OstrovskyACPI 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 AML 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
@@ -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, r, rc; +int r, rc; config->dsdt_anycpu = config->dsdt_15cpu = dsdt_pvh; config->dsdt_anycpu_len = config->dsdt_15cpu_len = dsdt_pvh_len;
@@ -147,8 +147,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
PATCH v6 11/12 pvh/acpi: Save ACPI registers for PVH guests
In reply to Boris Ostrovsky---
Can't generate SCI over event channel during is an event is enabled and pending:
* v->virq_to_evtchn is not initialized yet (it's done by guest)
* The SCI is sent immediately after event is made pending so it's not possible to miss it (at least for the only event that have)
xen/arch/x86/hvm/pmtimer.c | 9 +++++++++ 1 file changed, 9 insertions(+)
xen/arch/x86/hvm/pmtimer.c +9 -0
@@ -22,6 +22,7 @@#include <asm/hvm/support.h> #include <asm/acpi.h> /* for hvm_acpi_power_button prototype */ #include <public/hvm/params.h> +#include <xen/event.h> /* Slightly more readable port I/O addresses for the registers we intercept */ #define PM1a_STS_ADDR_V0 (ACPI_PM1A_EVT_BLK_ADDRESS_V0)
@@ -257,7 +258,11 @@ static int acpi_save(struct domain *d, hvm_domain_context_t *h)int rc;if ( !has_vpm (d) ) + { +if ( !has_acpi_dm_ff (d) ) +return hvm_save_entry (PMTIMER ,0 , h, acpi);return 0 ; + }spin_lock (&s->lock);
@@ -286,7 +291,11 @@ static int acpi_load(struct domain *d, hvm_domain_context_t *h)PMTState *s = &d->arch.hvm_domain.pl_time->vpmt;if ( !has_vpm (d) ) + { +if ( !has_acpi_dm_ff (d) ) +return hvm_load_entry (PMTIMER , h, acpi);return -ENODEV ; + }spin_lock (&s->lock);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v6 12/12 docs: Describe PVHv2's VCPU hotplug procedure
In reply to Boris Ostrovsky---
CC: George Dunlap <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
---
Changes in v6:
* No GPE0 update is needed anymore.
docs/misc/hvmlite.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+)
docs/misc/hvmlite.markdown +11 -0
@@ -75,3 +75,14 @@ info structure that's passed at boot time (field rsdp_paddr). Description of paravirtualized devices will come from XenStore, just as it's done for HVM guests. + +## VCPU hotplug ## + +VCPU hotplug (e.g. 'xl vcpu-set <domain> <num_vcpus>') for PVHv2 guests +follows ACPI model where change in domain's number of VCPUS (stored in +domain.avail_vcpus) results in an SCI being sent to the guest. The guest +then executes DSDT's PRSC method, updating MADT enable status for the +affected VCPU. + +Updating VCPU number is achieved by having the toolstack issue a write to +ACPI's XEN_ACPI_CPU_MAP.
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v6 12/12] docs: Describe PVHv2's VCPU hotplug procedure
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.01.17 at 15:04, <[email protected]> wrote:
docs/misc/hvmlite.markdown +1
-0@@ -75,3 +75,14 @@ info structure that's passed at boot time (field rsdp_paddr). Description of paravirtualized devices will come from XenStore, just as it's done for HVM guests. +
docs/misc/hvmlite.markdown info structure that's passed at boot time (field rsdp_paddr). · line 88
Quoted 10 lines
docs/misc/hvmlite.markdown +10
-0+## VCPU hotplug ## + +VCPU hotplug (e.g. 'xl vcpu-set <domain> <num_vcpus>') for PVHv2 guests +follows ACPI model where change in domain's number of VCPUS (stored in +domain.avail_vcpus) results in an SCI being sent to the guest. The guest +then executes DSDT's PRSC method, updating MADT enable status for the +affected VCPU. + +Updating VCPU number is achieved by having the toolstack issue a write to +ACPI's XEN_ACPI_CPU_MAP.
Is any of this valid anymore in the context of the recent discussion? Perhaps even wider - how much of this series is applicable if pCPU hotplug is to use the normal ACPI code path? I hope the plan is not to have different vCPU hotplug for DomU and Dom0?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v6 12/12] docs: Describe PVHv2's VCPU hotplug procedure
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 03.01.17 at 15:04, <[email protected]> wrote:
docs/misc/hvmlite.markdown +0
-0@@ -75,3 +75,14 @@ info structure that's passed at boot time (field rsdp_paddr).
Quoted 16 lines
docs/misc/hvmlite.markdown info structure that's passed at boot time (field rsdp_paddr). · line 88
Quoted 13 lines
docs/misc/hvmlite.markdown +11
-0Description of paravirtualized devices will come from XenStore, just as it's done for HVM guests. + +## VCPU hotplug ## + +VCPU hotplug (e.g. 'xl vcpu-set <domain> <num_vcpus>') for PVHv2 guests +follows ACPI model where change in domain's number of VCPUS (stored in +domain.avail_vcpus) results in an SCI being sent to the guest. The guest +then executes DSDT's PRSC method, updating MADT enable status for the +affected VCPU. + +Updating VCPU number is achieved by having the toolstack issue a write to +ACPI's XEN_ACPI_CPU_MAP.Is any of this valid anymore in the context of the recent discussion? Perhaps even wider - how much of this series is applicable if pCPU hotplug is to use the normal ACPI code path?
pCPU hotplug is not going to use this path because it would not be executing PRSC method that we (Xen toolstack) provide.
Quoted 2 lines
I hope the plan is not
to have different vCPU hotplug for DomU and Dom0?
That was not the plan. But I haven't thought of dom0 not being able to execute PRSC.
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v6 12/12] docs: Describe PVHv2's VCPU hotplug procedure
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 03.01.17 at 20:33, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
docs/misc/hvmlite.markdown info structure that's passed at boot time (field
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 03.01.17 at 15:04, <[email protected]> wrote:
docs/misc/hvmlite.markdown +0
-0@@ -75,3 +75,14 @@ info structure that's passed at boot time (field
rsdp_paddr).Quoted 2 lines
docs/misc/hvmlite.markdown info structure that's passed at boot time (field · line 75
Quoted 2 lines
docs/misc/hvmlite.markdown +0
-0Description of paravirtualized devices will come from XenStore, just asit's
Quoted 7 lines
Quoted 7 lines
docs/misc/hvmlite.markdown +6
-0done for HVM guests. + +## VCPU hotplug ## + +VCPU hotplug (e.g. 'xl vcpu-set <domain> <num_vcpus>') for PVHv2 guests +follows ACPI model where change in domain's number of VCPUS (stored in +domain.avail_vcpus) results in an SCI being sent to the guest. The guestQuoted 8 lines
docs/misc/hvmlite.markdown info structure that's passed at boot time (field rsdp_paddr). · line 88
Quoted 5 lines
docs/misc/hvmlite.markdown +5
-0+then executes DSDT's PRSC method, updating MADT enable status for the +affected VCPU. + +Updating VCPU number is achieved by having the toolstack issue a write to +ACPI's XEN_ACPI_CPU_MAP.Is any of this valid anymore in the context of the recent discussion? Perhaps even wider - how much of this series is applicable if pCPU hotplug is to use the normal ACPI code path?
pCPU hotplug is not going to use this path because it would not be executing PRSC method that we (Xen toolstack) provide.
Quoted 5 lines
Quoted 2 lines
I hope the plan is not
to have different vCPU hotplug for DomU and Dom0?That was not the plan. But I haven't thought of dom0 not being able to execute PRSC.
Well - bottom line to me then is: This series needs to be deferred until there is a plan for acceptable Dom0 behavior. In particular it may well be that PVH needs to go the PV vCPU hotplug route instead, in which case we'd need to evaluate which of the already committed patches make no sense anymore.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v6 12/12] docs: Describe PVHv2's VCPU hotplug procedure
In reply to Boris OstrovskyQuoted 23 lines · Boris Ostrovsky
Signed-off-by Boris Ostrovsky <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>---
CC: George Dunlap <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
---
Changes in v6:
* No GPE0 update is needed anymore.docs/misc/hvmlite.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+)docs/misc/hvmlite.markdown +1
-0@@ -75,3 +75,14 @@ info structure that's passed at boot time (field rsdp_paddr). Description of paravirtualized devices will come from XenStore, just as it's done for HVM guests. +
docs/misc/hvmlite.markdown info structure that's passed at boot time (field rsdp_paddr). · line 88
Quoted 10 lines
docs/misc/hvmlite.markdown +10
-0+## VCPU hotplug ## + +VCPU hotplug (e.g. 'xl vcpu-set <domain> <num_vcpus>') for PVHv2 guests +follows ACPI model where change in domain's number of VCPUS (stored in +domain.avail_vcpus) results in an SCI being sent to the guest. The guest +then executes DSDT's PRSC method, updating MADT enable status for the +affected VCPU. + +Updating VCPU number is achieved by having the toolstack issue a write to +ACPI's XEN_ACPI_CPU_MAP.
Looking at [email protected], this is done via domctl. I think it is worth documenting that.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v6 12/12] docs: Describe PVHv2's VCPU hotplug procedure
Quoted 21 lines · Stefano Stabellini
Quoted 20 lines · Boris Ostrovsky
Signed-off-by Boris Ostrovsky <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>---
CC: George Dunlap <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
---
Changes in v6:
* No GPE0 update is needed anymore.docs/misc/hvmlite.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+)docs/misc/hvmlite.markdown +0
-0@@ -75,3 +75,14 @@ info structure that's passed at boot time (field rsdp_paddr).
Quoted 15 lines
docs/misc/hvmlite.markdown info structure that's passed at boot time (field rsdp_paddr). · line 88
Quoted 13 lines
docs/misc/hvmlite.markdown +11
-0Description of paravirtualized devices will come from XenStore, just as it's done for HVM guests. + +## VCPU hotplug ## + +VCPU hotplug (e.g. 'xl vcpu-set <domain> <num_vcpus>') for PVHv2 guests +follows ACPI model where change in domain's number of VCPUS (stored in +domain.avail_vcpus) results in an SCI being sent to the guest. The guest +then executes DSDT's PRSC method, updating MADT enable status for the +affected VCPU. + +Updating VCPU number is achieved by having the toolstack issue a write to +ACPI's XEN_ACPI_CPU_MAP.Looking at [email protected], this is done via domctl. I think it is worth documenting that.
Will do.
-boirs
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel