Message ID | 20200818103032.3050-9-paul@xen.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | domain context infrastructure | expand |
On 18.08.2020 12:30, Paul Durrant wrote: > --- a/xen/include/public/save.h > +++ b/xen/include/public/save.h > @@ -93,7 +93,18 @@ struct domain_shared_info_context { > > DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); > > -#define DOMAIN_SAVE_CODE_MAX 2 > +#if defined(__i386__) || defined(__x86_64__) > +struct domain_tsc_info_context { > + uint32_t mode; > + uint32_t incarnation; > + uint64_t elapsed_nsec; > + uint32_t khz; > +}; sizeof() for this struct varies between 32-bit and 64-bit - is this not a problem? (alignof() varies too, but there I think it's indeed not a problem, albeit it could still be taken care of by using uint64_aligned_t, alongside the addition of an explicit padding field). Jan
> -----Original Message----- > From: Jan Beulich <jbeulich@suse.com> > Sent: 26 August 2020 15:03 > To: Paul Durrant <paul@xen.org> > Cc: xen-devel@lists.xenproject.org; Durrant, Paul <pdurrant@amazon.co.uk>; Ian Jackson > <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; Andrew Cooper <andrew.cooper3@citrix.com>; George > Dunlap <george.dunlap@citrix.com>; Julien Grall <julien@xen.org>; Stefano Stabellini > <sstabellini@kernel.org>; Roger Pau Monné <roger.pau@citrix.com> > Subject: RE: [EXTERNAL] [PATCH v7 8/9] x86/time: add a domain context record for tsc_info... > > CAUTION: This email originated from outside of the organization. Do not click links or open > attachments unless you can confirm the sender and know the content is safe. > > > > On 18.08.2020 12:30, Paul Durrant wrote: > > --- a/xen/include/public/save.h > > +++ b/xen/include/public/save.h > > @@ -93,7 +93,18 @@ struct domain_shared_info_context { > > > > DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); > > > > -#define DOMAIN_SAVE_CODE_MAX 2 > > +#if defined(__i386__) || defined(__x86_64__) > > +struct domain_tsc_info_context { > > + uint32_t mode; > > + uint32_t incarnation; > > + uint64_t elapsed_nsec; > > + uint32_t khz; > > +}; > > sizeof() for this struct varies between 32-bit and 64-bit - is > this not a problem? (alignof() varies too, but there I think > it's indeed not a problem, albeit it could still be taken care > of by using uint64_aligned_t, alongside the addition of an > explicit padding field). I don't think it should matter because domain context records have implicit padding to align up to the next 64-bit boundary, so as long as fields within the struct don't move (which I think is true in this case) then we should be ok. Paul > > Jan
On 28.08.2020 13:08, Paul Durrant wrote: >> -----Original Message----- >> From: Jan Beulich <jbeulich@suse.com> >> Sent: 26 August 2020 15:03 >> To: Paul Durrant <paul@xen.org> >> Cc: xen-devel@lists.xenproject.org; Durrant, Paul <pdurrant@amazon.co.uk>; Ian Jackson >> <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; Andrew Cooper <andrew.cooper3@citrix.com>; George >> Dunlap <george.dunlap@citrix.com>; Julien Grall <julien@xen.org>; Stefano Stabellini >> <sstabellini@kernel.org>; Roger Pau Monné <roger.pau@citrix.com> >> Subject: RE: [EXTERNAL] [PATCH v7 8/9] x86/time: add a domain context record for tsc_info... >> >> CAUTION: This email originated from outside of the organization. Do not click links or open >> attachments unless you can confirm the sender and know the content is safe. >> >> >> >> On 18.08.2020 12:30, Paul Durrant wrote: >>> --- a/xen/include/public/save.h >>> +++ b/xen/include/public/save.h >>> @@ -93,7 +93,18 @@ struct domain_shared_info_context { >>> >>> DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); >>> >>> -#define DOMAIN_SAVE_CODE_MAX 2 >>> +#if defined(__i386__) || defined(__x86_64__) >>> +struct domain_tsc_info_context { >>> + uint32_t mode; >>> + uint32_t incarnation; >>> + uint64_t elapsed_nsec; >>> + uint32_t khz; >>> +}; >> >> sizeof() for this struct varies between 32-bit and 64-bit - is >> this not a problem? (alignof() varies too, but there I think >> it's indeed not a problem, albeit it could still be taken care >> of by using uint64_aligned_t, alongside the addition of an >> explicit padding field). > > I don't think it should matter because domain context records have > implicit padding to align up to the next 64-bit boundary, Could you remind me where this is written down and enforced? > so as long as fields within the struct don't move (which I think > is true in this case) then we should be ok. Right. Jan
> -----Original Message----- > From: Jan Beulich <jbeulich@suse.com> > Sent: 28 August 2020 16:53 > To: paul@xen.org > Cc: xen-devel@lists.xenproject.org; 'Ian Jackson' <ian.jackson@eu.citrix.com>; 'Wei Liu' <wl@xen.org>; > 'Andrew Cooper' <andrew.cooper3@citrix.com>; 'George Dunlap' <george.dunlap@citrix.com>; 'Julien > Grall' <julien@xen.org>; 'Stefano Stabellini' <sstabellini@kernel.org>; 'Roger Pau Monné' > <roger.pau@citrix.com> > Subject: Re: [EXTERNAL] [PATCH v7 8/9] x86/time: add a domain context record for tsc_info... > > On 28.08.2020 13:08, Paul Durrant wrote: > >> -----Original Message----- > >> From: Jan Beulich <jbeulich@suse.com> > >> Sent: 26 August 2020 15:03 > >> To: Paul Durrant <paul@xen.org> > >> Cc: xen-devel@lists.xenproject.org; Durrant, Paul <pdurrant@amazon.co.uk>; Ian Jackson > >> <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; Andrew Cooper <andrew.cooper3@citrix.com>; > George > >> Dunlap <george.dunlap@citrix.com>; Julien Grall <julien@xen.org>; Stefano Stabellini > >> <sstabellini@kernel.org>; Roger Pau Monné <roger.pau@citrix.com> > >> Subject: RE: [EXTERNAL] [PATCH v7 8/9] x86/time: add a domain context record for tsc_info... > >> > >> CAUTION: This email originated from outside of the organization. Do not click links or open > >> attachments unless you can confirm the sender and know the content is safe. > >> > >> > >> > >> On 18.08.2020 12:30, Paul Durrant wrote: > >>> --- a/xen/include/public/save.h > >>> +++ b/xen/include/public/save.h > >>> @@ -93,7 +93,18 @@ struct domain_shared_info_context { > >>> > >>> DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); > >>> > >>> -#define DOMAIN_SAVE_CODE_MAX 2 > >>> +#if defined(__i386__) || defined(__x86_64__) > >>> +struct domain_tsc_info_context { > >>> + uint32_t mode; > >>> + uint32_t incarnation; > >>> + uint64_t elapsed_nsec; > >>> + uint32_t khz; > >>> +}; > >> > >> sizeof() for this struct varies between 32-bit and 64-bit - is > >> this not a problem? (alignof() varies too, but there I think > >> it's indeed not a problem, albeit it could still be taken care > >> of by using uint64_aligned_t, alongside the addition of an > >> explicit padding field). > > > > I don't think it should matter because domain context records have > > implicit padding to align up to the next 64-bit boundary, > > Could you remind me where this is written down and enforced? > With the series fully applied, see xen/include/public/save.h line 62-68 for the comment and then see domain_save_end() in xen/common/save.c for where the padding is applied. Paul > > so as long as fields within the struct don't move (which I think > > is true in this case) then we should be ok. > > Right. > > Jan
On 28.08.2020 18:36, Paul Durrant wrote: >> -----Original Message----- >> From: Jan Beulich <jbeulich@suse.com> >> Sent: 28 August 2020 16:53 >> To: paul@xen.org >> Cc: xen-devel@lists.xenproject.org; 'Ian Jackson' <ian.jackson@eu.citrix.com>; 'Wei Liu' <wl@xen.org>; >> 'Andrew Cooper' <andrew.cooper3@citrix.com>; 'George Dunlap' <george.dunlap@citrix.com>; 'Julien >> Grall' <julien@xen.org>; 'Stefano Stabellini' <sstabellini@kernel.org>; 'Roger Pau Monné' >> <roger.pau@citrix.com> >> Subject: Re: [EXTERNAL] [PATCH v7 8/9] x86/time: add a domain context record for tsc_info... >> >> On 28.08.2020 13:08, Paul Durrant wrote: >>>> -----Original Message----- >>>> From: Jan Beulich <jbeulich@suse.com> >>>> Sent: 26 August 2020 15:03 >>>> To: Paul Durrant <paul@xen.org> >>>> Cc: xen-devel@lists.xenproject.org; Durrant, Paul <pdurrant@amazon.co.uk>; Ian Jackson >>>> <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; Andrew Cooper <andrew.cooper3@citrix.com>; >> George >>>> Dunlap <george.dunlap@citrix.com>; Julien Grall <julien@xen.org>; Stefano Stabellini >>>> <sstabellini@kernel.org>; Roger Pau Monné <roger.pau@citrix.com> >>>> Subject: RE: [EXTERNAL] [PATCH v7 8/9] x86/time: add a domain context record for tsc_info... >>>> >>>> CAUTION: This email originated from outside of the organization. Do not click links or open >>>> attachments unless you can confirm the sender and know the content is safe. >>>> >>>> >>>> >>>> On 18.08.2020 12:30, Paul Durrant wrote: >>>>> --- a/xen/include/public/save.h >>>>> +++ b/xen/include/public/save.h >>>>> @@ -93,7 +93,18 @@ struct domain_shared_info_context { >>>>> >>>>> DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); >>>>> >>>>> -#define DOMAIN_SAVE_CODE_MAX 2 >>>>> +#if defined(__i386__) || defined(__x86_64__) >>>>> +struct domain_tsc_info_context { >>>>> + uint32_t mode; >>>>> + uint32_t incarnation; >>>>> + uint64_t elapsed_nsec; >>>>> + uint32_t khz; >>>>> +}; >>>> >>>> sizeof() for this struct varies between 32-bit and 64-bit - is >>>> this not a problem? (alignof() varies too, but there I think >>>> it's indeed not a problem, albeit it could still be taken care >>>> of by using uint64_aligned_t, alongside the addition of an >>>> explicit padding field). >>> >>> I don't think it should matter because domain context records have >>> implicit padding to align up to the next 64-bit boundary, >> >> Could you remind me where this is written down and enforced? >> > > With the series fully applied, see xen/include/public/save.h > line 62-68 for the comment and then see domain_save_end() in > xen/common/save.c for where the padding is applied. Ah, yes, this helped find the places in the patches. Therefore with the stray blank line addition removed from tools/misc/xen-domctx.c Reviewed-by: Jan Beulich <jbeulich@suse.com> Jan
diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c index 6ead7ea89d..e09d75cf68 100644 --- a/tools/misc/xen-domctx.c +++ b/tools/misc/xen-domctx.c @@ -59,9 +59,20 @@ static void dump_header(void) printf(" HEADER: magic %#x, version %u\n", h->magic, h->version); +} + +static void dump_tsc_info(void) +{ + DOMAIN_SAVE_TYPE(TSC_INFO) *t; + GET_PTR(t); + + printf(" TSC_INFO: mode: %u incarnation: %u\n" + " khz %u elapsed_nsec: %"PRIu64"\n", + t->mode, t->incarnation, t->khz, t->elapsed_nsec); } + static void print_binary(const char *prefix, const void *val, size_t size, const char *suffix) { @@ -251,6 +262,7 @@ int main(int argc, char **argv) { case DOMAIN_SAVE_CODE(HEADER): dump_header(); break; case DOMAIN_SAVE_CODE(SHARED_INFO): dump_shared_info(); break; + case DOMAIN_SAVE_CODE(TSC_INFO): dump_tsc_info(); break; case DOMAIN_SAVE_CODE(END): dump_end(); break; default: printf("Unknown type %u: skipping\n", desc->typecode); diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 505e54ebd7..05f65fbf12 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -26,6 +26,7 @@ #include <xen/symbols.h> #include <xen/keyhandler.h> #include <xen/guest_access.h> +#include <xen/save.h> #include <asm/io.h> #include <asm/iocap.h> #include <asm/msr.h> @@ -2334,7 +2335,7 @@ int host_tsc_is_safe(void) * called to collect tsc-related data only for save file or live * migrate; called after last rdtsc is done on this incarnation */ -void tsc_get_info(struct domain *d, uint32_t *tsc_mode, +void tsc_get_info(const struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_nsec, uint32_t *gtsc_khz, uint32_t *incarnation) { @@ -2453,6 +2454,37 @@ int tsc_set_info(struct domain *d, return 0; } +static int save_tsc_info(const struct domain *d, struct domain_context *c, + bool dry_run) +{ + struct domain_tsc_info_context ctxt; + + if ( !dry_run ) + tsc_get_info(d, &ctxt.mode, &ctxt.elapsed_nsec, &ctxt.khz, + &ctxt.incarnation); + + return DOMAIN_SAVE_ENTRY(TSC_INFO, c, 0, &ctxt, sizeof(ctxt)); +} + +static int load_tsc_info(struct domain *d, struct domain_context *c) +{ + struct domain_tsc_info_context ctxt; + unsigned int i; + int rc; + + rc = DOMAIN_LOAD_ENTRY(TSC_INFO, c, &i, &ctxt, sizeof(ctxt)); + if ( rc ) + return rc; + + if ( i ) /* expect only a single instance */ + return -ENXIO; + + return tsc_set_info(d, ctxt.mode, ctxt.elapsed_nsec, ctxt.khz, + ctxt.incarnation); +} + +DOMAIN_REGISTER_SAVE_LOAD(TSC_INFO, save_tsc_info, load_tsc_info); + /* vtsc may incur measurable performance degradation, diagnose with this */ static void dump_softtsc(unsigned char key) { diff --git a/xen/include/asm-x86/time.h b/xen/include/asm-x86/time.h index f347311cc4..7f2ce6226a 100644 --- a/xen/include/asm-x86/time.h +++ b/xen/include/asm-x86/time.h @@ -59,8 +59,9 @@ u64 gtsc_to_gtime(struct domain *d, u64 tsc); int tsc_set_info(struct domain *d, uint32_t tsc_mode, uint64_t elapsed_nsec, uint32_t gtsc_khz, uint32_t incarnation); -void tsc_get_info(struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_nsec, - uint32_t *gtsc_khz, uint32_t *incarnation); +void tsc_get_info(const struct domain *d, uint32_t *tsc_mode, + uint64_t *elapsed_nsec, uint32_t *gtsc_khz, + uint32_t *incarnation); void force_update_vcpu_system_time(struct vcpu *v); diff --git a/xen/include/public/save.h b/xen/include/public/save.h index 0e855a4b97..aeb17298eb 100644 --- a/xen/include/public/save.h +++ b/xen/include/public/save.h @@ -93,7 +93,18 @@ struct domain_shared_info_context { DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); -#define DOMAIN_SAVE_CODE_MAX 2 +#if defined(__i386__) || defined(__x86_64__) +struct domain_tsc_info_context { + uint32_t mode; + uint32_t incarnation; + uint64_t elapsed_nsec; + uint32_t khz; +}; + +DECLARE_DOMAIN_SAVE_TYPE(TSC_INFO, 3, struct domain_tsc_info_context); +#endif + +#define DOMAIN_SAVE_CODE_MAX 3 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */