x86: detect CMOS aliasing on ports other then 0x70/0x71
PATCH 1/1 x86: detect CMOS aliasing on ports other then 0x70/0x71
... in order to also intercept accesses through the alias ports.
Also stop intercepting accesses to the CMOS ports if we won't ourselves use the CMOS RTC.
xen/arch/x86/setup.c +0 -36
@@ -1544,42 +1544,6 @@ int __hwdom_init xen_in_range(unsigned lreturn 0 ; } -static int __hwdom_init io_bitmap_cb(unsigned long s, unsigned long e, -void *ctx) -{ -struct domain *d = ctx; -unsigned int i; - -ASSERT (e <=INT_MAX ); -for ( i = s; i <= e; i++ ) -__clear_bit (i, d->arch.hvm_domain.io_bitmap); - -return 0 ; -} - -void __hwdom_init setup_io_bitmap(struct domain *d) -{ -int rc; - -if (has_hvm_container_domain (d) ) - { -bitmap_fill (d->arch.hvm_domain.io_bitmap,0x10000 ); - rc =rangeset_report_ranges (d->arch.ioport_caps,0 ,0x10000 , - io_bitmap_cb, d); -BUG_ON (rc); -/* -* NB: we need to trap accesses to 0xcf8 in order to intercept -* 4 byte accesses, that need to be handled by Xen in order to -* keep consistency. -* Access to 1 byte RTC ports also needs to be trapped in order -* to keep consistency with PV. -*/ -__set_bit (0xcf8 , d->arch.hvm_domain.io_bitmap); -__set_bit (RTC_PORT (0 ), d->arch.hvm_domain.io_bitmap); -__set_bit (RTC_PORT (1 ), d->arch.hvm_domain.io_bitmap); - } -} -/* * Local variables: * mode: C
xen/arch/x86/time.c +3 -0
@@ -736,7 +736,10 @@ static unsigned long get_cmos_time(void)if ( seconds <60 ) {if ( rtc.sec != seconds ) + { cmos_rtc_probe =0 ; + acpi_gbl_FADT.boot_flags &= ~ACPI_FADT_NO_CMOS_RTC ; + }break ; }
xen/arch/x86/traps.c +101 -13
165 lines not on this page · raw message
x86: detect CMOS aliasing on ports other then 0x70/0x71
... in order to also intercept accesses through the alias ports.
Also stop intercepting accesses to the CMOS ports if we won't ourselves use the CMOS RTC.
xen/arch/x86/setup.c +0 -36
@@ -1544,42 +1544,6 @@ int __hwdom_init xen_in_range(unsigned lreturn 0 ; } -static int __hwdom_init io_bitmap_cb(unsigned long s, unsigned long e, -void *ctx) -{ -struct domain *d = ctx; -unsigned int i; - -ASSERT (e <=INT_MAX ); -for ( i = s; i <= e; i++ ) -__clear_bit (i, d->arch.hvm_domain.io_bitmap); - -return 0 ; -} - -void __hwdom_init setup_io_bitmap(struct domain *d) -{ -int rc; - -if (has_hvm_container_domain (d) ) - { -bitmap_fill (d->arch.hvm_domain.io_bitmap,0x10000 ); - rc =rangeset_report_ranges (d->arch.ioport_caps,0 ,0x10000 , - io_bitmap_cb, d); -BUG_ON (rc); -/* -* NB: we need to trap accesses to 0xcf8 in order to intercept -* 4 byte accesses, that need to be handled by Xen in order to -* keep consistency. -* Access to 1 byte RTC ports also needs to be trapped in order -* to keep consistency with PV. -*/ -__set_bit (0xcf8 , d->arch.hvm_domain.io_bitmap); -__set_bit (RTC_PORT (0 ), d->arch.hvm_domain.io_bitmap); -__set_bit (RTC_PORT (1 ), d->arch.hvm_domain.io_bitmap); - } -} -/* * Local variables: * mode: C
xen/arch/x86/time.c +3 -0
@@ -736,7 +736,10 @@ static unsigned long get_cmos_time(void)if ( seconds <60 ) {if ( rtc.sec != seconds ) + { cmos_rtc_probe =0 ; + acpi_gbl_FADT.boot_flags &= ~ACPI_FADT_NO_CMOS_RTC ; + }break ; }
xen/arch/x86/traps.c +101 -13
165 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 14 lines · Jan Beulich
xen/arch/x86/traps.c +14
-0+for ( offs =2 ; offs <8 ; offs <<=1 ) + { +bool_t read =1 ; + +for ( i =RTC_REG_D +1 ; i <0x80 ; ++i ) + { +uint8_t normal, alt; +unsigned long flags; + +if ( i == acpi_gbl_FADT.century ) +continue ; + +spin_lock_irqsave (&rtc_lock, flags); +
xen/arch/x86/traps.c void __init trap_init(void) · line 3770
Quoted 10 lines
xen/arch/x86/traps.c +10
-0+ normal =CMOS_READ (i); +if (inb (RTC_PORT (offs)) != i ) + read =0 ; + + alt =inb (RTC_PORT (offs +1 )); + +spin_unlock_irqrestore (&rtc_lock, flags); + +if ( normal != alt ) +break ;
Even with a manual to hand, this logic is quite hard to understand. Furthermore, I still cant spot how your r/w vs w/o logic is supposed to work. It doesn't check the writability of the alias, but of the aliases index.
However, it is not robust to the system servicing an SMI and altering the CMOS ram in the middle of this loop. Such a modification would cause the loop to believe that this specific 'offs' is not an alias even when it actually is.
One option would be to reread the non-aliased port again, but that would add yet more io reads.
~Andrew
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 23.09.15 at 20:34, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
xen/arch/x86/traps.c +21
-0+for ( offs =2 ; offs <8 ; offs <<=1 ) + { +bool_t read =1 ; + +for ( i =RTC_REG_D +1 ; i <0x80 ; ++i ) + { +uint8_t normal, alt; +unsigned long flags; + +if ( i == acpi_gbl_FADT.century ) +continue ; + +spin_lock_irqsave (&rtc_lock, flags); + + normal =CMOS_READ (i); +if (inb (RTC_PORT (offs)) != i ) + read =0 ; + + alt =inb (RTC_PORT (offs +1 )); + +spin_unlock_irqrestore (&rtc_lock, flags);
Quoted 8 lines
xen/arch/x86/traps.c void __init trap_init(void) · line 3770
Quoted 3 lines
xen/arch/x86/traps.c +3
-0+ +if ( normal != alt ) +break ;Even with a manual to hand, this logic is quite hard to understand. Furthermore, I still cant spot how your r/w vs w/o logic is supposed to work. It doesn't check the writability of the alias, but of the aliases index.
But that's the only interesting thing. A w/o alias would be rather strange. It's the index register that traditionally hasn't been readable, but has got means added in some chipsets to be read back. For the moment we don't make use of this information anyway, i.e. it's more a thing usable for validation that what the logic determines matches with how the chipset is documented to behave (if someone wanted to check that).
Quoted 7 lines
However, it is not robust to the system servicing an SMI and altering the CMOS ram in the middle of this loop. Such a modification would cause the loop to believe that this specific 'offs' is not an alias even when it actually is.
One option would be to reread the non-aliased port again, but that would add yet more io reads.
SMI is always a problem. Even if we re-read the register, we still couldn't be sure we haven't got hit by another SMI. Considering the index/data port access model I would anyway consider it quite bad for firmware to modify the CMOS in an SMI.
Jan
Quoted 43 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 23.09.15 at 20:34, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
xen/arch/x86/traps.c +20
-0+for ( offs =2 ; offs <8 ; offs <<=1 ) + { +bool_t read =1 ; + +for ( i =RTC_REG_D +1 ; i <0x80 ; ++i ) + { +uint8_t normal, alt; +unsigned long flags; + +if ( i == acpi_gbl_FADT.century ) +continue ; + +spin_lock_irqsave (&rtc_lock, flags); + + normal =CMOS_READ (i); +if (inb (RTC_PORT (offs)) != i ) + read =0 ; + + alt =inb (RTC_PORT (offs +1 )); +Quoted 8 lines
xen/arch/x86/traps.c void __init trap_init(void) · line 3770
Quoted 4 lines
xen/arch/x86/traps.c +4
-0+spin_unlock_irqrestore (&rtc_lock, flags); + +if ( normal != alt ) +break ;Even with a manual to hand, this logic is quite hard to understand. Furthermore, I still cant spot how your r/w vs w/o logic is supposed to work. It doesn't check the writability of the alias, but of the aliases index.
But that's the only interesting thing. A w/o alias would be rather strange. It's the index register that traditionally hasn't been readable, but has got means added in some chipsets to be read back. For the moment we don't make use of this information anyway, i.e. it's more a thing usable for validation that what the logic determines matches with how the chipset is documented to behave (if someone wanted to check that).
Quoted 5 lines
However, it is not robust to the system servicing an SMI and altering the CMOS ram in the middle of this loop. Such a modification would cause the loop to believe that this specific 'offs' is not an alias even when it actually is.
Quoted 6 lines
Quoted 2 lines
One option would be to reread the non-aliased port again, but that would add yet more io reads.
SMI is always a problem. Even if we re-read the register, we still couldn't be sure we haven't got hit by another SMI. Considering the index/data port access model I would anyway consider it quite bad for firmware to modify the CMOS in an SMI.
When one core is executing the SMM handler, all other cores are held paused. (There tends to be some rather complicated cross-socket logic to make this happen properly).
It is safe for the SMM handler to use CMOS if it returns the index register back to how it found it. Furthermore, I am willing to bet that there real SMM handlers out there which do do this.
~Andrew
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 11:55, <[email protected]> wrote:
It is safe for the SMM handler to use CMOS if it returns the index register back to how it found it. Furthermore, I am willing to bet that there real SMM handlers out there which do do this.
So what options do you see then here? Don't do anything (drop the patch) seems the only one I can see not getting in conflict with SMI. Yet using the patch as is would not make anything less safe, it would just have the potential of not always making things as safe as they could be.
Jan
Quoted 9 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 11:55, <[email protected]> wrote:
It is safe for the SMM handler to use CMOS if it returns the index register back to how it found it. Furthermore, I am willing to bet that there real SMM handlers out there which do do this.
So what options do you see then here? Don't do anything (drop the patch) seems the only one I can see not getting in conflict with SMI. Yet using the patch as is would not make anything less safe, it would just have the potential of not always making things as safe as they could be.
Given some orthogonal interaction with cmos-rtc-probe recently, I am fairly sure that we can remove all real RTC interaction from Xen.
Dom0 is required to provide fine-grained time via XENPF_settime{32,64} which gives an absolute time to seed the other domain wallclocks with. The RTC was assumed always to be in UTC, which allows full date and time information to be derived.
It would certainly simplify things to leave all of the RTC in dom0's hand.
~Andrew
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 15:25, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 11:55, <[email protected]> wrote:
It is safe for the SMM handler to use CMOS if it returns the index register back to how it found it. Furthermore, I am willing to bet that there real SMM handlers out there which do do this.
So what options do you see then here? Don't do anything (drop the patch) seems the only one I can see not getting in conflict with SMI. Yet using the patch as is would not make anything less safe, it would just have the potential of not always making things as safe as they could be.
Quoted 5 lines
Given some orthogonal interaction with cmos-rtc-probe recently, I am fairly sure that we can remove all real RTC interaction from Xen.
Dom0 is required to provide fine-grained time via XENPF_settime{32,64} which gives an absolute time to seed the other domain wallclocks with.
Is it? If so, I suppose we should enforce this in some way, e.g. by failing domain creation until done. Right now I guess we expect that to happen, but don't really require it.
Quoted 4 lines
The RTC was assumed always to be in UTC, which allows full date and time information to be derived.
It would certainly simplify things to leave all of the RTC in dom0's hand.
Yes, it would.
Jan