The following functions have been referenced in places which is either guarded with CONFIG_MGMT_HYPERCALLS or CONFIG_MEM_SHARING: - arch_hvm_save - arch_hvm_check - arch_hvm_load - hvm_save_size - hvm_save - hvm_load While CONFIG_MEM_SHARING is also dependent on CONFIG_MGMT_HYPERCALLS. So they shall be wrapped under MGMT_HYPERCALLS, otherwise they will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1. We move arch_hvm_save(), arch_hvm_check(), arch_hvm_load() and hvm_save_size() nearer to the left functions, to avoid scattered #ifdef-wrapping.
Signed-off-by: Penny Zheng <[email protected]> --- v3 -> v4 - new commit --- xen/arch/x86/hvm/save.c | 154 ++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/xen/arch/x86/hvm/save.c b/xen/arch/x86/hvm/save.c index 8ab6405706..5e99dd5998 100644 --- a/xen/arch/x86/hvm/save.c +++ b/xen/arch/x86/hvm/save.c @@ -15,62 +15,6 @@ #include <public/hvm/save.h> -static void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr) -{ - uint32_t eax, ebx, ecx, edx; - - /* Save some CPUID bits */ - cpuid(1, &eax, &ebx, &ecx, &edx); - hdr->cpuid = eax; - - /* Save guest's preferred TSC. */ - hdr->gtsc_khz = d->arch.tsc_khz; - - /* Time when saving started */ - d->arch.hvm.sync_tsc = rdtsc(); -} - -static int arch_hvm_check(const struct domain *d, - const struct hvm_save_header *hdr) -{ - uint32_t eax, ebx, ecx, edx; - - if ( hdr->magic != HVM_FILE_MAGIC ) - { - printk(XENLOG_G_ERR "HVM%d restore: bad magic number %#"PRIx32"\n", - d->domain_id, hdr->magic); - return -EINVAL; - } - - if ( hdr->version != HVM_FILE_VERSION ) - { - printk(XENLOG_G_ERR "HVM%d restore: unsupported version %u\n", - d->domain_id, hdr->version); - return -EINVAL; - } - - cpuid(1, &eax, &ebx, &ecx, &edx); - /* CPUs ought to match but with feature-masking they might not */ - if ( (hdr->cpuid & ~0x0fUL) != (eax & ~0x0fUL) ) - printk(XENLOG_G_INFO "HVM%d restore: VM saved on one CPU " - "(%#"PRIx32") and restored on another (%#"PRIx32").\n", - d->domain_id, hdr->cpuid, eax); - - return 0; -} - -static void arch_hvm_load(struct domain *d, const struct hvm_save_header *hdr) -{ - /* Restore guest's preferred TSC frequency. */ - if ( hdr->gtsc_khz ) - d->arch.tsc_khz = hdr->gtsc_khz; - if ( d->arch.vtsc ) - hvm_set_rdtsc_exiting(d, 1); - - /* Time when restore started */ - d->arch.hvm.sync_tsc = rdtsc(); -} - /* List of handlers for various HVM save and restore types */ static struct { hvm_save_handler save; @@ -101,26 +45,6 @@ void __init hvm_register_savevm(uint16_t typecode, hvm_sr_handlers[typecode].kind = kind; } -size_t hvm_save_size(struct domain *d) -{ - struct vcpu *v; - size_t sz; - int i; - - /* Basic overhead for header and footer */ - sz = (2 * sizeof (struct hvm_save_descriptor)) + HVM_SAVE_LENGTH(HEADER); - - /* Plus space for each thing we will be saving */ - for ( i = 0; i <= HVM_SAVE_CODE_MAX; i++ ) - if ( hvm_sr_handlers[i].kind == HVMSR_PER_VCPU ) - for_each_vcpu(d, v) - sz += hvm_sr_handlers[i].size; - else - sz += hvm_sr_handlers[i].size; - - return sz; -} - /* * Extract a single instance of a save record, by marshalling all records of * that type and copying out the one we need. @@ -196,6 +120,83 @@ int hvm_save_one(struct domain *d, unsigned int typecode, unsigned int instance, return rv; } +#ifdef CONFIG_MGMT_HYPERCALLS +static void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr) +{ + uint32_t eax, ebx, ecx, edx; + + /* Save some CPUID bits */ + cpuid(1, &eax, &ebx, &ecx, &edx); + hdr->cpuid = eax; + + /* Save guest's preferred TSC. */ + hdr->gtsc_khz = d->arch.tsc_khz; + + /* Time when saving started */ + d->arch.hvm.sync_tsc = rdtsc(); +} + +static int arch_hvm_check(const struct domain *d, + const struct hvm_save_header *hdr) +{ + uint32_t eax, ebx, ecx, edx; + + if ( hdr->magic != HVM_FILE_MAGIC ) + { + printk(XENLOG_G_ERR "HVM%d restore: bad magic number %#"PRIx32"\n", + d->domain_id, hdr->magic); + return -EINVAL; + } + + if ( hdr->version != HVM_FILE_VERSION ) + { + printk(XENLOG_G_ERR "HVM%d restore: unsupported version %u\n", + d->domain_id, hdr->version); + return -EINVAL; + } + + cpuid(1, &eax, &ebx, &ecx, &edx); + /* CPUs ought to match but with feature-masking they might not */ + if ( (hdr->cpuid & ~0x0fUL) != (eax & ~0x0fUL) ) + printk(XENLOG_G_INFO "HVM%d restore: VM saved on one CPU " + "(%#"PRIx32") and restored on another (%#"PRIx32").\n", + d->domain_id, hdr->cpuid, eax); + + return 0; +} + +static void arch_hvm_load(struct domain *d, const struct hvm_save_header *hdr) +{ + /* Restore guest's preferred TSC frequency. */ + if ( hdr->gtsc_khz ) + d->arch.tsc_khz = hdr->gtsc_khz; + if ( d->arch.vtsc ) + hvm_set_rdtsc_exiting(d, 1); + + /* Time when restore started */ + d->arch.hvm.sync_tsc = rdtsc(); +} + +size_t hvm_save_size(struct domain *d) +{ + struct vcpu *v; + size_t sz; + unsigned int i; + + /* Basic overhead for header and footer */ + sz = (2 * sizeof (struct hvm_save_descriptor)) + HVM_SAVE_LENGTH(HEADER); + + /* Plus space for each thing we will be saving */ + for ( i = 0; i <= HVM_SAVE_CODE_MAX; i++ ) + if ( hvm_sr_handlers[i].kind == HVMSR_PER_VCPU ) + for_each_vcpu(d, v) + sz += hvm_sr_handlers[i].size; + else + sz += hvm_sr_handlers[i].size; + + return sz; +} + int hvm_save(struct domain *d, hvm_domain_context_t *h) { char *c; @@ -390,6 +391,7 @@ int hvm_load(struct domain *d, bool real, hvm_domain_context_t *h) /* Not reached */ } +#endif /* CONFIG_MGMT_HYPERCALLS */ int _hvm_init_entry(struct hvm_domain_context *h, uint16_t tc, uint16_t inst, uint32_t len) -- 2.34.1
