AMD/IOMMU: improve x2APIC handling when XT is unavailable
v2 cover AMD/IOMMU: improve x2APIC handling when XT is unavailable
For AMD the connection between IOMMU and x2APIC is less strong, hence even if unlikely to occur we would better deal correctly with XT being unavailable (for whatever reasons) in particular when x2APIC is already enabled on a system.
1: correct handling when XT's prereq features are unavailable 2: without XT, x2APIC needs to be forced into physical mode
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/2 AMD/IOMMU: correct handling when XT's prereq features are unavailable
We should neither cause IOMMU initialization as a whole to fail in this case (we should still be able to bring up the system in non-x2APIC or x2APIC physical mode), nor should the remainder of the function be skipped (as the main part of it won't get entered a 2nd time) in such an event. It is merely necessary for the function to indicate to the caller (iov_supports_xt()) that setup failed as far as x2APIC is concerned.
---
v2: Also adjust the loop consuming "xt". no_xt -> has_xt.
xen/drivers/passthrough/amd/iommu_init.c +7 -7
@@ -1364,6 +1364,7 @@ static int __init amd_iommu_prepare_one(int __init amd_iommu_prepare (bool xt) {struct amd_iommu *iommu; +bool has_xt = true;int rc = -ENODEV ;BUG_ON ( !iommu_found () );
@@ -1400,17 +1401,16 @@ int __init amd_iommu_prepare(bool xt)if ( rc ) goto error_out; - rc = -ENODEV ; -if ( xt && (!iommu->features.flds.ga_sup || !iommu->features.flds.xt_sup) ) - goto error_out; +if ( !iommu->features.flds.ga_sup || !iommu->features.flds.xt_sup ) + has_xt = false; }for_each_amd_iommu ( iommu ) {/* NB: There's no need to actually write these out right here. */ - iommu->ctrl.ga_en |= xt; - iommu->ctrl.xt_en = xt; - iommu->ctrl.int_cap_xt_en = xt; + iommu->ctrl.ga_en |= xt && has_xt; + iommu->ctrl.xt_en = xt && has_xt; + iommu->ctrl.int_cap_xt_en = xt && has_xt; } rc =amd_iommu_update_ivrs_mapping_acpi ();
@@ -1422,7 +1422,7 @@ int __init amd_iommu_prepare(bool xt) ivhd_type =0 ; } -return rc; +return rc ?: xt && !has_xt ? -ENODEV :0 ; }int __init amd_iommu_init (bool xt)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] AMD/IOMMU: correct handling when XT's prereq features are unavailable
Quoted 8 lines · Jan Beulich
We should neither cause IOMMU initialization as a whole to fail in this case (we should still be able to bring up the system in non-x2APIC or x2APIC physical mode), nor should the remainder of the function be skipped (as the main part of it won't get entered a 2nd time) in such an event. It is merely necessary for the function to indicate to the caller (
iov_supports_xt()) that setup failed as far as x2APIC is concerned.Signed-off-by Jan Beulich <[email protected]>
Looks much better.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] AMD/IOMMU: correct handling when XT's prereq features are unavailable
In reply to Jan BeulichQuoted 4 lines · Jan Beulich
We should neither cause IOMMU initialization as a whole to fail in this case (we should still be able to bring up the system in non-x2APIC or x2APIC physical mode), nor should the remainder of the function be skipped (as the main part of it won't get entered a 2nd time)
I'm not sure I see why it won't get entered a second time. AFAICT init_done won't be set if amd_iommu_init fails, and hence will be called again with xt == false in iov_detect?
Quoted 5 lines
in such an
event. It is merely necessary for the function to indicate to the caller (iov_supports_xt()) that setup failed as far as x2APIC is concerned.Signed-off-by Jan Beulich <[email protected]>
LGTM, but it needs to go in with 2/2 AFAICT, or else you would report interrupt remapping enabled and x2APIC also enabled but won't handle correctly a 32 bit destination field.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] AMD/IOMMU: correct handling when XT's prereq features are unavailable
Quoted 14 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
We should neither cause IOMMU initialization as a whole to fail in this case (we should still be able to bring up the system in non-x2APIC or x2APIC physical mode), nor should the remainder of the function be skipped (as the main part of it won't get entered a 2nd time)
I'm not sure I see why it won't get entered a second time. AFAICT
init_donewon't be set ifamd_iommu_initfails, and hence will be called again with xt == false iniov_detect?Quoted 4 lines
in such an
event. It is merely necessary for the function to indicate to the caller (iov_supports_xt()) that setup failed as far as x2APIC is concerned.
Quoted 5 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>LGTM, but it needs to go in with 2/2 AFAICT, or else you would report interrupt remapping enabled and x2APIC also enabled but won't handle correctly a 32 bit destination field.
Well, this is an improvement on its own imo, even if it doesn't fully fix everything. The primary point here is to make IOMMU initialization not fail altogether, when the system could be run in xAPIC mode.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 1/2] AMD/IOMMU: correct handling when XT's prereq features are unavailable
In reply to Roger Pau MonnéQuoted 9 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
We should neither cause IOMMU initialization as a whole to fail in this case (we should still be able to bring up the system in non-x2APIC or x2APIC physical mode), nor should the remainder of the function be skipped (as the main part of it won't get entered a 2nd time)
I'm not sure I see why it won't get entered a second time. AFAICT
init_donewon't be set ifamd_iommu_initfails, and hence will be called again with xt == false iniov_detect?
Not very far from the top of the function there is
/* Have we been here before? */
if ( ivrs_bdf_entries )
return 0;Hence me saying "main part" rather than "the function as a whole".
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Roger Pau Monné
Reviewed-byRe: [Xen-devel] [PATCH v2 1/2] AMD/IOMMU: correct handling when XT's prereq features are unavailable
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
We should neither cause IOMMU initialization as a whole to fail in this case (we should still be able to bring up the system in non-x2APIC or x2APIC physical mode), nor should the remainder of the function be skipped (as the main part of it won't get entered a 2nd time)
I'm not sure I see why it won't get entered a second time. AFAICT
init_donewon't be set ifamd_iommu_initfails, and hence will be called again with xt == false iniov_detect?
Quoted 7 lines
Not very far from the top of the function there is
/* Have we been here before? */ if ( ivrs_bdf_entries ) return 0;Hence me saying "main part" rather than "the function as a whole".
Oh, yes, sorry.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/2 AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
In reply to Jan BeulichThe wider cluster mode APIC IDs aren't generally representable. Convert the iommu_intremap variable into a tristate, allowing the AMD IOMMU driver to signal this special restriction to the apic_x2apic_probe(). (Note: assignments to the variable get adjusted, while existing consumers - all assuming a boolean property - are left alone.)
---
v2: New.
xen/arch/x86/genapic/x2apic.c +15 -6
@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: +printk ("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n" +"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + :"with restricted" ); + x2apic_phys = true; +break ; + +case iommu_intremap_full: +break ; + }if ( x2apic_phys )return &apic_x2apic_phys;
xen/drivers/passthrough/amd/iommu_init.c +4 -1
@@ -1139,7 +1139,7 @@ static void __init amd_iommu_init_cleanu iommu_enabled =0 ; iommu_hwdom_passthrough = false; - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; iommuv2_enabled =0 ; }
@@ -1413,6 +1413,9 @@ int __init amd_iommu_prepare(bool xt) iommu->ctrl.int_cap_xt_en = xt && has_xt; } +if ( iommu_intremap && !has_xt ) + iommu_intremap = iommu_intremap_restricted; + rc =amd_iommu_update_ivrs_mapping_acpi (); error_out:
xen/drivers/passthrough/amd/pci_amd_iommu.c +1 -1
@@ -157,7 +157,7 @@ int __init acpi_ivrs_init(void)if ( (amd_iommu_detect_acpi () !=0 ) || (iommu_found () ==0 ) ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;return -ENODEV ; }
xen/drivers/passthrough/iommu.c +5 -4
@@ -35,7 +35,7 @@ bool __read_mostly iommu_quarantine = trbool_t __read_mostly iommu_igfx =1 ;bool_t __read_mostly iommu_snoop =1 ;bool_t __read_mostly iommu_qinval =1 ; -bool_t __read_mostly iommu_intremap =1 ; +enum iommu_intremap __read_mostly iommu_intremap = iommu_intremap_full;bool_t __read_mostly iommu_crash_disable; static bool __hwdom_initdata iommu_hwdom_none;
@@ -91,7 +91,7 @@ static int __init parse_iommu_param(conselse if ( (val =parse_boolean ("qinval" , s, ss)) >=0 ) iommu_qinval = val;else if ( (val =parse_boolean ("intremap" , s, ss)) >=0 ) - iommu_intremap = val; + iommu_intremap = val ? iommu_intremap_full : iommu_intremap_off;else if ( (val =parse_boolean ("intpost" , s, ss)) >=0 ) iommu_intpost = val;#ifdef CONFIG_KEXEC
@@ -475,7 +475,7 @@ int __init iommu_setup(void) iommu_enabled = (rc ==0 ); }if ( !iommu_enabled ) - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;if ( (force_iommu && !iommu_enabled) || (force_intremap && !iommu_intremap) )
@@ -557,7 +557,8 @@ void iommu_crash_shutdown(void)if ( iommu_enabled )iommu_get_ops ()->crash_shutdown (); - iommu_enabled = iommu_intremap = iommu_intpost =0 ; + iommu_enabled = iommu_intpost =0 ; + iommu_intremap = iommu_intremap_off; }int iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt)
xen/drivers/passthrough/vtd/iommu.c +5 -5
@@ -2177,7 +2177,7 @@ static int __must_check init_vtd_hw(void {if (ioapic_to_iommu (IO_APIC_ID (apic)) ==NULL ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_ERR VTDPREFIX, "ioapic_to_iommu: ioapic %#x (id: %#x) is NULL! " "Will not try to enable Interrupt Remapping.\n",
@@ -2193,7 +2193,7 @@ static int __must_check init_vtd_hw(void iommu = drhd->iommu;if (enable_intremap (iommu,0 ) !=0 ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_WARNING VTDPREFIX, "Interrupt Remapping not enabled\n");
@@ -2295,7 +2295,7 @@ static int __init vtd_setup(void) iommu_qinval =0 ;if ( iommu_intremap && !ecap_intr_remap (iommu->ecap) ) - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;/* * We cannot use posted interrupt if X86_FEATURE_CX16 is
@@ -2320,7 +2320,7 @@ static int __init vtd_setup(void)if ( !iommu_qinval && iommu_intremap ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_WARNING VTDPREFIX, "Interrupt Remapping disabled " "since Queued Invalidation isn't supported or enabled.\n"); }
@@ -2347,7 +2347,7 @@ static int __init vtd_setup(void) iommu_snoop =0 ; iommu_hwdom_passthrough = false; iommu_qinval =0 ; - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; iommu_intpost =0 ;return ret; }
xen/include/xen/iommu.h +12 -1
@@ -54,7 +54,18 @@ static inline bool_t dfn_eq(dfn_t x, dfnextern bool_t iommu_enable, iommu_enabled;extern bool force_iommu, iommu_quarantine, iommu_verbose, iommu_igfx; -extern bool_t iommu_snoop, iommu_qinval, iommu_intremap, iommu_intpost; +extern bool_t iommu_snoop, iommu_qinval, iommu_intpost; +extern enum __packed iommu_intremap { +/* +* In order to allow traditional boolean uses of the iommu_intremap +* variable, the "off" value has to come first (yielding a value of zero). +*/ + iommu_intremap_off, +#ifdef CONFIG_X86 + iommu_intremap_restricted, +#endif + iommu_intremap_full, +} iommu_intremap;#if defined(CONFIG_IOMMU_FORCE_PT_SHARE )#define iommu_hap_pt_share true
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
Quoted 22 lines · Jan Beulich
The wider cluster mode APIC IDs aren't generally representable. Convert the
iommu_intremapvariable into a tristate, allowing the AMD IOMMU driver to signal this special restriction to theapic_x2apic_probe(). (Note: assignments to the variable get adjusted, while existing consumers - all assuming a boolean property - are left alone.)Signed-off-by Jan Beulich <[email protected]>---
v2: New.xen/arch/x86/genapic/x2apic.c +0
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - }
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 248
Quoted 10 lines
xen/arch/x86/genapic/x2apic.c +10
-0+else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: +printk ("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n" +"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + :"with restricted" ); + x2apic_phys = true;
I think you also need to fixup the usage of iommu_intremap in __cpu_up so that CPUs with APIC IDs > 255 are not brought up when in iommu_intremap_restricted mode.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
Quoted 19 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich
xen/arch/x86/genapic/x2apic.c +6
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n"
Quoted 8 lines
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 248
Quoted 4 lines
xen/arch/x86/genapic/x2apic.c +4
-0+"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true;I think you also need to fixup the usage of
iommu_intremapin__cpu_upso that CPUs with APIC IDs > 255 are not brought up when iniommu_intremap_restrictedmode.
That certainly wants changing, yes, but I view this as an orthogonal adjustment, which I'd like to make only once I understand what the behavior for APIC ID 0xff should be in this setup.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Roger Pau Monné
Reviewed-byRe: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
Quoted 29 lines · Jan Beulich
Quoted 19 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich
xen/arch/x86/genapic/x2apic.c +6
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n"Quoted 8 lines
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 248
Quoted 4 lines
xen/arch/x86/genapic/x2apic.c +4
-0+"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true;I think you also need to fixup the usage of
iommu_intremapin__cpu_upso that CPUs with APIC IDs > 255 are not brought up when iniommu_intremap_restrictedmode.
Quoted 3 lines
That certainly wants changing, yes, but I view this as an orthogonal adjustment, which I'd like to make only once I understand what the behavior for APIC ID
0xffshould be in this setup.
I would say APIC ID 0xff should be the broadcast ID, or else remapped interrupts won't be able to use a broadcast destination? I'm however not able to find any mention to this in the AMD-Vi spec.
So the check in __cpu_up should be adjusted to iommu_intremap != iommu_intremap_full I think, or else you won't be able to address the CPUs brought up from the interrupt remapping tables.
Anyway, the change looks fine, so:
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
In reply to Roger Pau MonnéQuoted 19 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich
xen/arch/x86/genapic/x2apic.c +6
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n"
Quoted 8 lines
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 248
Quoted 4 lines
xen/arch/x86/genapic/x2apic.c +4
-0+"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true;I think you also need to fixup the usage of
iommu_intremapin__cpu_upso that CPUs with APIC IDs > 255 are not brought up when iniommu_intremap_restrictedmode.
I've looked around some (finding indications that, as one would suspect, broadcasting is also supported for IO-APIC based interrupts, and then by implication also for MSI) and then also thought about this some more. I think the corner case here resolves like this: Whether 0xff means "broadcast" exclusively depends on the local APIC. Hence in x2APIC mode, even without XT, 0xff does not mean "broadcast", and hence the code in __cpu_up() is fine as is. In this setup there simply is no way to encode broadcast at the IO-APIC or MSI level; luckily we also don't use this mode.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
Quoted 29 lines · Jan Beulich
Quoted 19 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich
xen/arch/x86/genapic/x2apic.c +6
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n"Quoted 8 lines
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 248
Quoted 4 lines
xen/arch/x86/genapic/x2apic.c +4
-0+"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true;I think you also need to fixup the usage of
iommu_intremapin__cpu_upso that CPUs with APIC IDs > 255 are not brought up when iniommu_intremap_restrictedmode.
Quoted 10 lines
I've looked around some (finding indications that, as one would suspect, broadcasting is also supported for IO-APIC based interrupts, and then by implication also for MSI) and then also thought about this some more. I think the corner case here resolves like this: Whether
0xffmeans "broadcast" exclusively depends on the local APIC. Hence in x2APIC mode, even without XT,0xffdoes not mean "broadcast", and hence the code in__cpu_up()is fine as is. In this setup there simply is no way to encode broadcast at the IO-APIC or MSI level; luckily we also don't use this mode.
I'm talking rubbish - yes, the code needs adjusting as you and I first thought. All that I'm now sure about is that the adjustment doesn't need to be more complicated. I'll make a patch.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
The wider cluster mode APIC IDs aren't generally representable. Convert the
iommu_intremapvariable into a tristate, allowing the AMD IOMMU driver to signal this special restriction to theapic_x2apic_probe(). (Note: assignments to the variable get adjusted, while existing consumers - all assuming a boolean property - are left alone.)
I think it would be helpful to state that while we are not aware of any hardware with this as a restriction, it is a situation which can be created on fully x2apic-capable systems via firmware settings.
Quoted 14 lines
Signed-off-by Jan Beulich <[email protected]>---
v2: New.xen/arch/x86/genapic/x2apic.c +0
-3@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { - printk("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n"
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 245
Quoted 10 lines
xen/arch/x86/genapic/x2apic.c +7
-3- "x2APIC: forcing phys mode\n"); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n" + "x2APIC: forcing phys mode\n",
Any chance to fold this into a single line with "- forcing phys mode\n" as a suffix?
Quoted 17 lines
xen/arch/x86/genapic/x2apic.c +8
-0+ iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true; +break ; + +case iommu_intremap_full: +break ; + }if ( x2apic_phys )return &apic_x2apic_phys;xen/include/xen/iommu.h +0
-0@@ -54,7 +54,18 @@ static inline bool_t dfn_eq(dfn_t x, dfnextern bool_t iommu_enable, iommu_enabled;extern bool force_iommu, iommu_quarantine, iommu_verbose, iommu_igfx;
xen/include/xen/iommu.h static inline bool_t dfn_eq(dfn_t x, dfn · line 65
Quoted 10 lines
xen/include/xen/iommu.h +9
-1-extern bool_t iommu_snoop, iommu_qinval, iommu_intremap, iommu_intpost; +extern bool_t iommu_snoop, iommu_qinval, iommu_intpost; +extern enum __packed iommu_intremap { +/* +* In order to allow traditional boolean uses of the iommu_intremap +* variable, the "off" value has to come first (yielding a value of zero). +*/ + iommu_intremap_off, +#ifdef CONFIG_X86 + iommu_intremap_restricted,
This needs a note about its meaning. How about this?
/* Interrupt remapping enabled, but only able to generate interrupts with an 8-bit APIC ID. */
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Not an issue for now, but "restricted" might become ambiguous with future extensions.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
Quoted 10 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
The wider cluster mode APIC IDs aren't generally representable. Convert the
iommu_intremapvariable into a tristate, allowing the AMD IOMMU driver to signal this special restriction to theapic_x2apic_probe(). (Note: assignments to the variable get adjusted, while existing consumers - all assuming a boolean property - are left alone.)I think it would be helpful to state that while we are not aware of any hardware with this as a restriction, it is a situation which can be created on fully x2apic-capable systems via firmware settings.
Added.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Jan Beulich <[email protected]>---
v2: New.xen/arch/x86/genapic/x2apic.c +2
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) + switch ( iommu_intremap )
Quoted 8 lines
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 245
Quoted 5 lines
xen/arch/x86/genapic/x2apic.c +5
-0+ { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n" + "x2APIC: forcing phys mode\n",Any chance to fold this into a single line with "- forcing phys mode\n" as a suffix?
I did consider doing so myself, but didn't do it then for being an unrelated change. Now that you ask for it - done.
Quoted 30 lines
Quoted 17 lines
xen/arch/x86/genapic/x2apic.c +8
-0+ iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true; +break ; + +case iommu_intremap_full: +break ; + }if ( x2apic_phys )return &apic_x2apic_phys;xen/include/xen/iommu.h +0
-0@@ -54,7 +54,18 @@ static inline bool_t dfn_eq(dfn_t x, dfnextern bool_t iommu_enable, iommu_enabled;extern bool force_iommu, iommu_quarantine, iommu_verbose, iommu_igfx;xen/include/xen/iommu.h static inline bool_t dfn_eq(dfn_t x, dfn · line 65
Quoted 10 lines
xen/include/xen/iommu.h +9
-1-extern bool_t iommu_snoop, iommu_qinval, iommu_intremap, iommu_intpost; +extern bool_t iommu_snoop, iommu_qinval, iommu_intpost; +extern enum __packed iommu_intremap { +/* +* In order to allow traditional boolean uses of the iommu_intremap +* variable, the "off" value has to come first (yielding a value of zero). +*/ + iommu_intremap_off, +#ifdef CONFIG_X86 + iommu_intremap_restricted,This needs a note about its meaning. How about this?
Quoted 2 lines
/* Interrupt remapping enabled, but only able to generate interrupts with an 8-bit APIC ID. */
Added.
Quoted 1 line
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Thanks.
Quoted 2 lines
Not an issue for now, but "restricted" might become ambiguous with future extensions.
Yes, fair point.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
The wider cluster mode APIC IDs aren't generally representable. Convert the
iommu_intremapvariable into a tristate, allowing the AMD IOMMU driver to signal this special restriction to theapic_x2apic_probe(). (Note: assignments to the variable get adjusted, while existing consumers - all assuming a boolean property - are left alone.)Signed-off-by Jan Beulich <[email protected]>
Kevin,
I see you've looked over and acked Xen patches over the weekend. Did you miss this one? It doesn't look controversial, so it'd be nice to have your ack, for it to go in.
Jan
Quoted 172 lines
xen/arch/x86/genapic/x2apic.c +15
-6@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { -printk ("WARNING: x2APIC cluster mode is not supported without interrupt remapping\n" -"x2APIC: forcing phys mode\n" ); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: +printk ("WARNING: x2APIC cluster mode is not supported %s interrupt remapping\n" +"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + :"with restricted" ); + x2apic_phys = true; +break ; + +case iommu_intremap_full: +break ; + }if ( x2apic_phys )return &apic_x2apic_phys;xen/drivers/passthrough/amd/iommu_init.c +4
-1@@ -1139,7 +1139,7 @@ static void __init amd_iommu_init_cleanu iommu_enabled =0 ; iommu_hwdom_passthrough = false; - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; iommuv2_enabled =0 ; }@@ -1413,6 +1413,9 @@ int __init amd_iommu_prepare(bool xt) iommu->ctrl.int_cap_xt_en = xt && has_xt; } +if ( iommu_intremap && !has_xt ) + iommu_intremap = iommu_intremap_restricted; + rc =amd_iommu_update_ivrs_mapping_acpi (); error_out:xen/drivers/passthrough/amd/pci_amd_iommu.c +1
-1@@ -157,7 +157,7 @@ int __init acpi_ivrs_init(void)if ( (amd_iommu_detect_acpi () !=0 ) || (iommu_found () ==0 ) ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;return -ENODEV ; }xen/drivers/passthrough/iommu.c +5
-4@@ -35,7 +35,7 @@ bool __read_mostly iommu_quarantine = trbool_t __read_mostly iommu_igfx =1 ;bool_t __read_mostly iommu_snoop =1 ;bool_t __read_mostly iommu_qinval =1 ; -bool_t __read_mostly iommu_intremap =1 ; +enum iommu_intremap __read_mostly iommu_intremap = iommu_intremap_full;bool_t __read_mostly iommu_crash_disable; static bool __hwdom_initdata iommu_hwdom_none;@@ -91,7 +91,7 @@ static int __init parse_iommu_param(conselse if ( (val =parse_boolean ("qinval" , s, ss)) >=0 ) iommu_qinval = val;else if ( (val =parse_boolean ("intremap" , s, ss)) >=0 ) - iommu_intremap = val; + iommu_intremap = val ? iommu_intremap_full : iommu_intremap_off;else if ( (val =parse_boolean ("intpost" , s, ss)) >=0 ) iommu_intpost = val;#ifdef CONFIG_KEXEC @@ -475,7 +475,7 @@ int __init iommu_setup(void) iommu_enabled = (rc ==0 ); }if ( !iommu_enabled ) - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;if ( (force_iommu && !iommu_enabled) || (force_intremap && !iommu_intremap) )@@ -557,7 +557,8 @@ void iommu_crash_shutdown(void)if ( iommu_enabled )iommu_get_ops ()->crash_shutdown (); - iommu_enabled = iommu_intremap = iommu_intpost =0 ; + iommu_enabled = iommu_intpost =0 ; + iommu_intremap = iommu_intremap_off; }int iommu_get_reserved_device_memory (iommu_grdm_t *func,void *ctxt)xen/drivers/passthrough/vtd/iommu.c +5
-5@@ -2177,7 +2177,7 @@ static int __must_check init_vtd_hw(void {if (ioapic_to_iommu (IO_APIC_ID (apic)) ==NULL ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_ERR VTDPREFIX, "ioapic_to_iommu: ioapic %#x (id: %#x) is NULL! " "Will not try to enable Interrupt Remapping.\n",@@ -2193,7 +2193,7 @@ static int __must_check init_vtd_hw(void iommu = drhd->iommu;if (enable_intremap (iommu,0 ) !=0 ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_WARNING VTDPREFIX, "Interrupt Remapping not enabled\n");@@ -2295,7 +2295,7 @@ static int __init vtd_setup(void) iommu_qinval =0 ;if ( iommu_intremap && !ecap_intr_remap (iommu->ecap) ) - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;/* * We cannot use posted interrupt if X86_FEATURE_CX16 is @@ -2320,7 +2320,7 @@ static int __init vtd_setup(void)if ( !iommu_qinval && iommu_intremap ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_WARNING VTDPREFIX, "Interrupt Remapping disabled " "since Queued Invalidation isn't supported or enabled.\n"); }@@ -2347,7 +2347,7 @@ static int __init vtd_setup(void) iommu_snoop =0 ; iommu_hwdom_passthrough = false; iommu_qinval =0 ; - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; iommu_intpost =0 ;return ret; }xen/include/xen/iommu.h +12
-1@@ -54,7 +54,18 @@ static inline bool_t dfn_eq(dfn_t x, dfnextern bool_t iommu_enable, iommu_enabled;extern bool force_iommu, iommu_quarantine, iommu_verbose, iommu_igfx; -extern bool_t iommu_snoop, iommu_qinval, iommu_intremap, iommu_intpost; +extern bool_t iommu_snoop, iommu_qinval, iommu_intpost; +extern enum __packed iommu_intremap { +/* +* In order to allow traditional boolean uses of the iommu_intremap +* variable, the "off" value has to come first (yielding a value of zero). +*/ + iommu_intremap_off, +#ifdef CONFIG_X86 + iommu_intremap_restricted, +#endif + iommu_intremap_full, +} iommu_intremap;#if defined(CONFIG_IOMMU_FORCE_PT_SHARE )#define iommu_hap_pt_share true
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Tian, Kevin
Reviewed-byRe: [Xen-devel] [PATCH v2 2/2] AMD/IOMMU: without XT, x2APIC needs to be forced into physical mode
Quoted 12 lines
From: Jan Beulich <[email protected]>
Sent: Monday, March 9, 2020 4:59 PMQuoted 7 lines · Jan Beulich
The wider cluster mode APIC IDs aren't generally representable. Convert the
iommu_intremapvariable into a tristate, allowing the AMD IOMMU driver to signal this special restriction to theapic_x2apic_probe(). (Note: assignments to the variable get adjusted, while existing consumers - all assuming a boolean property - are left alone.)Signed-off-by Jan Beulich <[email protected]>
Quoted 7 lines
Kevin,
I see you've looked over and acked Xen patches over the weekend. Did you miss this one? It doesn't look controversial, so it'd be nice to have your ack, for it to go in.
Jan
It is in my list. My review process was interrupted by other tasks yesterday, and now is resumed. 😊
Quoted 181 lines
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic · line 241
Quoted 10 lines
xen/arch/x86/genapic/x2apic.c +0
-3@@ -236,12 +236,21 @@ const struct genapic *__init apic_x2apic x2apic_phys = !iommu_intremap || (acpi_gbl_FADT.flags &ACPI_FADT_APIC_PHYSICAL ); } -else if ( !x2apic_phys && !iommu_intremap ) - { - printk("WARNING: x2APIC cluster mode is not supported withoutinterrupt remapping\n"
xen/arch/x86/genapic/x2apic.c const struct genapic *__init apic_x2apic
Quoted 9 lines
xen/arch/x86/genapic/x2apic.c +6
-3- "x2APIC: forcing phys mode\n"); - x2apic_phys = true; - } +else if ( !x2apic_phys ) +switch ( iommu_intremap ) + { +case iommu_intremap_off: +case iommu_intremap_restricted: + printk("WARNING: x2APIC cluster mode is not supported %sinterrupt remapping\n"
Quoted 47 lines
xen/arch/x86/genapic/x2apic.c +9
-0+"x2APIC: forcing phys mode\n" , + iommu_intremap == iommu_intremap_off ?"without" + : "with restricted"); + x2apic_phys = true; +break ; + +case iommu_intremap_full: +break ; + }if ( x2apic_phys )return &apic_x2apic_phys;xen/drivers/passthrough/amd/iommu_init.c +4
-1@@ -1139,7 +1139,7 @@ static void __init amd_iommu_init_cleanu iommu_enabled =0 ; iommu_hwdom_passthrough = false; - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; iommuv2_enabled =0 ; }@@ -1413,6 +1413,9 @@ int __init amd_iommu_prepare(bool xt) iommu->ctrl.int_cap_xt_en = xt && has_xt; } +if ( iommu_intremap && !has_xt ) + iommu_intremap = iommu_intremap_restricted; + rc =amd_iommu_update_ivrs_mapping_acpi (); error_out:xen/drivers/passthrough/amd/pci_amd_iommu.c +1
-1@@ -157,7 +157,7 @@ int __init acpi_ivrs_init(void)if ( (amd_iommu_detect_acpi () !=0 ) || (iommu_found () ==0 ) ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;return -ENODEV ; }xen/drivers/passthrough/iommu.c bool __read_mostly iommu_quarantine = tr · line 38
Quoted 5 lines
xen/drivers/passthrough/iommu.c +1
-1@@ -35,7 +35,7 @@ bool __read_mostly iommu_quarantine = trbool_t __read_mostly iommu_igfx =1 ;bool_t __read_mostly iommu_snoop =1 ;bool_t __read_mostly iommu_qinval =1 ; -bool_t __read_mostly iommu_intremap =1 ; +enum iommu_intremap __read_mostly iommu_intremap =
iommu_intremap_full;xen/drivers/passthrough/iommu.c static int __init parse_iommu_param(cons · line 94
Quoted 9 lines
xen/drivers/passthrough/iommu.c +1
-1bool_t __read_mostly iommu_crash_disable; static bool __hwdom_initdata iommu_hwdom_none;@@ -91,7 +91,7 @@ static int __init parse_iommu_param(conselse if ( (val =parse_boolean ("qinval" , s, ss)) >=0 ) iommu_qinval = val;else if ( (val =parse_boolean ("intremap" , s, ss)) >=0 ) - iommu_intremap = val; + iommu_intremap = val ? iommu_intremap_full :
iommu_intremap_off;Quoted 13 lines
xen/drivers/passthrough/iommu.c +1
-1else if ( (val =parse_boolean ("intpost" , s, ss)) >=0 ) iommu_intpost = val;#ifdef CONFIG_KEXEC @@ -475,7 +475,7 @@ int __init iommu_setup(void) iommu_enabled = (rc ==0 ); }if ( !iommu_enabled ) - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;if ( (force_iommu && !iommu_enabled) || (force_intremap && !iommu_intremap) )xen/drivers/passthrough/iommu.c void iommu_crash_shutdown(void) · line 564
Quoted 9 lines
xen/drivers/passthrough/iommu.c +2
-1@@ -557,7 +557,8 @@ void iommu_crash_shutdown(void)if ( iommu_enabled )iommu_get_ops ()->crash_shutdown (); - iommu_enabled = iommu_intremap = iommu_intpost =0 ; + iommu_enabled = iommu_intpost =0 ; + iommu_intremap = iommu_intremap_off; } int iommu_get_reserved_device_memory(iommu_grdm_t *func, void*ctxt)
Quoted 30 lines
xen/drivers/passthrough/vtd/iommu.c +3
-3@@ -2177,7 +2177,7 @@ static int __must_check init_vtd_hw(void {if (ioapic_to_iommu (IO_APIC_ID (apic)) ==NULL ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_ERR VTDPREFIX, "ioapic_to_iommu: ioapic %#x (id: %#x) is NULL! " "Will not try to enable Interrupt Remapping.\n",@@ -2193,7 +2193,7 @@ static int __must_check init_vtd_hw(void iommu = drhd->iommu;if (enable_intremap (iommu,0 ) !=0 ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_WARNING VTDPREFIX, "Interrupt Remapping not enabled\n");@@ -2295,7 +2295,7 @@ static int __init vtd_setup(void) iommu_qinval =0 ;if ( iommu_intremap && !ecap_intr_remap (iommu->ecap) ) - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off;/* * We cannot use posted interrupt if X86_FEATURE_CX16 is xen/drivers/passthrough/vtd/iommu.c static int __init vtd_setup(void) · line 2324
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -2320,7 +2320,7 @@ static int __init vtd_setup(void)if ( !iommu_qinval && iommu_intremap ) { - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; dprintk(XENLOG_WARNING VTDPREFIX, "Interrupt Remappingdisabled "
Quoted 14 lines
xen/drivers/passthrough/vtd/iommu.c +1
-1"since Queued Invalidation isn't supported or enabled.\n"); }@@ -2347,7 +2347,7 @@ static int __init vtd_setup(void) iommu_snoop =0 ; iommu_hwdom_passthrough = false; iommu_qinval =0 ; - iommu_intremap =0 ; + iommu_intremap = iommu_intremap_off; iommu_intpost =0 ;return ret; }xen/include/xen/iommu.h static inline bool_t dfn_eq(dfn_t x, dfn · line 56
Quoted 3 lines
xen/include/xen/iommu.h +0
-0@@ -54,7 +54,18 @@ static inline bool_t dfn_eq(dfn_t x, dfnextern bool_t iommu_enable, iommu_enabled; extern bool force_iommu, iommu_quarantine, iommu_verbose,
iommu_igfx;xen/include/xen/iommu.h static inline bool_t dfn_eq(dfn_t x, dfn · line 57
Quoted 1 line
xen/include/xen/iommu.h +0
-1-extern bool_t iommu_snoop, iommu_qinval, iommu_intremap,
iommu_intpost;Quoted 17 lines
xen/include/xen/iommu.h +12
-0+extern bool_t iommu_snoop, iommu_qinval, iommu_intpost; +extern enum __packed iommu_intremap { +/* +* In order to allow traditional boolean uses of the iommu_intremap +* variable, the "off" value has to come first (yielding a value of zero). +*/ + iommu_intremap_off, +#ifdef CONFIG_X86 + iommu_intremap_restricted, +#endif + iommu_intremap_full, +} iommu_intremap;#if defined(CONFIG_IOMMU_FORCE_PT_SHARE )#define iommu_hap_pt_share true
Quoted 5 lines
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel