xen/arm: Restrict "p2m_ipa_bits" according to the IOMMU requirements
RFC PATCH v2 1/1 xen/arm: Restrict "p2m_ipa_bits" according to the IOMMU requirements
From: Oleksandr Tyshchenko <[email protected]>
There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "p2m_ipa_bits" value as is. But, there are cases when not.
In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic.
First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "pa_range" according to the restricted "p2m_ipa_bits".
---
Still RFC:
1. Patch assumes that IPMMU support is already in.
2. Not checked for the SMMU.
Changes since RFC V1 [1]:
- Don't update p2m_ipa_bits by the IOMMU drivers directly, introduce p2m_restrict_ipa_bits()
- Clarify patch subject/description
- Add more comments to code
- Check for equivalent "pabits" in setup_virt_paging()
- Remove ASSERTs from the SMMU and IPMMU drivers
[1] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg02078.html
--- xen/arch/arm/p2m.c | 33 ++++++++++++++++++++++++++++++-- xen/arch/arm/setup.c | 11 +++++++++-- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 19 ++++-------------- xen/drivers/passthrough/arm/smmu.c | 16 ++++++++-------- xen/include/asm-arm/p2m.h | 8 ++++++++ 5 files changed, 60 insertions(+), 27 deletions(-)
xen/arch/arm/p2m.c +31 -2
@@ -34,7 +34,8 @@ static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT;#define P2M_ROOT_PAGES (1<<P2M_ROOT_ORDER) -unsigned int __read_mostly p2m_ipa_bits; +/* Larger than any possible value */ +unsigned int __read_mostly p2m_ipa_bits =64 ;/* Helpers to lookup the properties of each level */ static const paddr_t level_masks[] =
@@ -1912,6 +1913,16 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,return page; } +void __init p2m_restrict_ipa_bits (unsigned int iommu_ipa_bits) +{ +/* +* Calculate the minimum of the maximum IPA bits that any IOMMU +* can support. +*/ +if ( iommu_ipa_bits < p2m_ipa_bits ) + p2m_ipa_bits = iommu_ipa_bits; +} +/* VTCR value to be configured by all CPUs. Set only once by the boot CPU */ static uint32_t __read_mostly vtcr;
@@ -1966,10 +1977,28 @@ void __init setup_virt_paging(void) [7] = { 0 } /* Invalid */ }; -unsigned int cpu; +unsigned int i, cpu;unsigned int pa_range =0x10 ;/* Larger than any possible value */ bool vmid_8_bit = false; +if ( iommu_enabled ) + { +/* +* Choose suitable "pa_range" according to the IOMMU requirements +* (restricted "p2m_ipa_bits" value). +* As P2M table is always configured with IPA bits == PA bits, +* check for equivalent "pabits" and store it's index. +*/ +for ( i =0 ; i <ARRAY_SIZE (pa_range_info); i++ ) + { +if ( p2m_ipa_bits == pa_range_info[i].pabits ) + { + pa_range = i; +break ; + } + } + } +for_each_online_cpu ( cpu ) {const struct cpuinfo_arm *info = &cpu_data[cpu];
xen/arch/arm/setup.c +9 -2
@@ -936,12 +936,19 @@ void __init start_xen(unsigned long boot_phys_offset,printk ("Brought up %ld CPUs\n" , (long )num_online_cpus ());/* TODO: smp_cpus_done(); */ -setup_virt_paging (); - +/* +* The IOMMU subsystem must be initialized before P2M as we need to gather +* requirements regarding the maximum IPA bits supported by each IOMMU +* device to figure out the minimum value among them. The P2M code will +* choose suitable "pa_range" according to the restricted "p2m_ipa_bits" +* value. +*/ rc =iommu_setup ();if ( !iommu_enabled && rc != -ENODEV )panic ("Couldn't configure correctly all the IOMMUs." ); +setup_virt_paging (); +do_initcalls ();/*
xen/drivers/passthrough/arm/ipmmu-vmsa.c +4 -15
@@ -1314,23 +1314,12 @@ static __init int ipmmu_init(struct dt_device_node *node, const void *data)return -ENODEV ; }else - {/* -* As 4-level translation table is not supported in IPMMU, we need -* to check IPA size used for P2M table beforehand to be sure it is -* 3-level and the IPMMU will be able to use it. -* -* TODO: First initialize the IOMMU and gather the requirements and -* then initialize the P2M. In the P2M code, take into the account -* the IOMMU requirements and restrict "pa_range" if necessary. +* Set maximum Stage-2 input size supported by the IPMMU. We expect +* the P2M code will take into the account the IOMMU requirements and +* choose suitable "pa_range". */ -if (IPMMU_MAX_P2M_IPA_BITS < p2m_ipa_bits ) - { -printk_once (XENLOG_ERR "ipmmu: P2M IPA size is not supported (P2M=%u IPMMU=%u)!\n" , - p2m_ipa_bits,IPMMU_MAX_P2M_IPA_BITS ); -return -ENODEV ; - } - } +p2m_restrict_ipa_bits (IPMMU_MAX_P2M_IPA_BITS ); ret =ipmmu_probe (node);if ( ret )
xen/drivers/passthrough/arm/smmu.c +8 -8
@@ -2198,14 +2198,14 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) size =arm_smmu_id_size_to_bits ((id >>ID2_IAS_SHIFT ) &ID2_IAS_MASK ); smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT, size); -/* Xen: Stage-2 input size has to match p2m_ipa_bits. */ -if (size < p2m_ipa_bits) { -dev_err (smmu->dev, -"P2M IPA size not supported (P2M=%u SMMU=%lu)!\n" , - p2m_ipa_bits, size); -return -ENODEV ; - } - smmu->s2_input_size = p2m_ipa_bits; +/* +* Xen: +* Set maximum Stage-2 input size supported by the SMMU. We expect +* the P2M code will take into the account the IOMMU requirements and +* choose suitable "pa_range". +*/ +p2m_restrict_ipa_bits (size); + smmu->s2_input_size = size;#if 0 /* Stage-2 input size limited due to pgd allocation (PTRS_PER_PGD) */ #ifdef CONFIG_64BIT
xen/include/asm-arm/p2m.h +8 -0
@@ -165,6 +165,14 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx)/* Not supported on ARM. */ } +/* +* Helper to restrict "p2m_ipa_bits" according the IOMMU requirements. +* +* Each IOMMU driver should report the maximum IPA bits (Stage-2 input size) +* it can support. +*/ +void p2m_restrict_ipa_bits (unsigned int iommu_ipa_bits); +/* Second stage paging setup, to be called on all CPUs */ void setup_virt_paging (void );
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Oleksandr,
Quoted 12 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "
p2m_ipa_bits" value as is. But, there are cases when not.In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic.
Quoted 5 lines
First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "
pa_range" according to the restricted "p2m_ipa_bits".
As I pointed in the previous version, all the code you modify is arm64 specific. For arm32, the number of IPA bits is hardcoded. So if you modify p2m_ipa_bits, you would end up to misconfigure VTCR.
In other words, for Arm32, you need to check p2m_ipa_bits is at least 40-bits before overriding it.
Quoted 32 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>CC Julien Grall <[email protected]>---
Still RFC:1. Patch assumes that IPMMU support is already in.
2. Not checked for the SMMU.Changes since RFC V1 [1]:
- Don't updatep2m_ipa_bitsby the IOMMU drivers directly, introducep2m_restrict_ipa_bits()
- Clarify patch subject/description
- Add more comments to code
- Check for equivalent "pabits" insetup_virt_paging()
- Remove ASSERTs from the SMMU and IPMMU drivers[1] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg02078.html
--- xen/arch/arm/p2m.c | 33 ++++++++++++++++++++++++++++++-- xen/arch/arm/setup.c | 11 +++++++++-- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 19 ++++-------------- xen/drivers/passthrough/arm/smmu.c | 16 ++++++++-------- xen/include/asm-arm/p2m.h | 8 ++++++++ 5 files changed, 60 insertions(+), 27 deletions(-)xen/arch/arm/p2m.c +0
-0
xen/arch/arm/p2m.c static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT; · line 37
Quoted 5 lines
xen/arch/arm/p2m.c +1
-1@@ -34,7 +34,8 @@ static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT;#define P2M_ROOT_PAGES (1<<P2M_ROOT_ORDER) -unsigned int __read_mostly p2m_ipa_bits; +/* Larger than any possible value */
I think it would be worth explaining that this is required so the number of P2M bits can be restricted by external entity (e.g IOMMU).
xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1916
Quoted 9 lines
xen/arch/arm/p2m.c +2
-0+unsigned int __read_mostly p2m_ipa_bits =64 ;/* Helpers to lookup the properties of each level */ static const paddr_t level_masks[] =@@ -1912,6 +1913,16 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,return page; } +void __init p2m_restrict_ipa_bits (unsigned int iommu_ipa_bits)
The name of the function is quite generic as most of the code in it. So can we avoid use the term IOMMU in it?
Quoted 13 lines
xen/arch/arm/p2m.c +9
-0+{ +/* +* Calculate the minimum of the maximum IPA bits that any IOMMU +* can support. +*/ +if ( iommu_ipa_bits < p2m_ipa_bits ) + p2m_ipa_bits = iommu_ipa_bits; +} +/* VTCR value to be configured by all CPUs. Set only once by the boot CPU */ static uint32_t __read_mostly vtcr;
xen/arch/arm/p2m.c void __init setup_virt_paging(void) · line 1984
Quoted 9 lines
xen/arch/arm/p2m.c +2
-1@@ -1966,10 +1977,28 @@ void __init setup_virt_paging(void) [7] = { 0 } /* Invalid */ }; -unsigned int cpu; +unsigned int i, cpu;unsigned int pa_range =0x10 ;/* Larger than any possible value */ bool vmid_8_bit = false; +if ( iommu_enabled )
Could we make this IOMMU-agnostic? The main reason to convert from p2m_ipa_bits to pa_range is to cater the rest of the code.
But we could rework the code to do the computation with p2m_ipa_bits and then look-up for the pa_range. In all honesty, I think we can completely avoid pa_range but this is probably going to require more a bit more work.
Quoted 27 lines
xen/arch/arm/p2m.c +17
-0+ { +/* +* Choose suitable "pa_range" according to the IOMMU requirements +* (restricted "p2m_ipa_bits" value). +* As P2M table is always configured with IPA bits == PA bits, +* check for equivalent "pabits" and store it's index. +*/ +for ( i =0 ; i <ARRAY_SIZE (pa_range_info); i++ ) + { +if ( p2m_ipa_bits == pa_range_info[i].pabits ) + { + pa_range = i; +break ; + } + } + } +for_each_online_cpu ( cpu ) {const struct cpuinfo_arm *info = &cpu_data[cpu];xen/arch/arm/setup.c +0
-0@@ -936,12 +936,19 @@ void __init start_xen(unsigned long boot_phys_offset,printk ("Brought up %ld CPUs\n" , (long )num_online_cpus ());/* TODO: smp_cpus_done(); */
xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 945
Quoted 10 lines
xen/arch/arm/setup.c +7
-2-setup_virt_paging (); - +/* +* The IOMMU subsystem must be initialized before P2M as we need to gather +* requirements regarding the maximum IPA bits supported by each IOMMU +* device to figure out the minimum value among them. The P2M code will +* choose suitable "pa_range" according to the restricted "p2m_ipa_bits" +* value. +*/
This is a bit too verbose, implementation details are not necessary here and increasing the risk to have bit rot comment. So how about:
"The IOMMU subsystem must be initialized before the P2M as we need to gather requirements regarding the maximum IPA bit supported by each IOMMU."?
Quoted 19 lines
xen/arch/arm/setup.c +2
-0rc =iommu_setup ();if ( !iommu_enabled && rc != -ENODEV )panic ("Couldn't configure correctly all the IOMMUs." ); +setup_virt_paging (); +do_initcalls ();/* xen/drivers/passthrough/arm/ipmmu-vmsa.c +0
-1@@ -1314,23 +1314,12 @@ static __init int ipmmu_init(struct dt_device_node *node, const void *data)return -ENODEV ; }else - {/*
xen/drivers/passthrough/arm/ipmmu-vmsa.c static __init int ipmmu_init(struct dt_device_node *node, const void *data) · line 1320
Quoted 10 lines
xen/drivers/passthrough/arm/ipmmu-vmsa.c +3
-7-* As 4-level translation table is not supported in IPMMU, we need -* to check IPA size used for P2M table beforehand to be sure it is -* 3-level and the IPMMU will be able to use it. -* -* TODO: First initialize the IOMMU and gather the requirements and -* then initialize the P2M. In the P2M code, take into the account -* the IOMMU requirements and restrict "pa_range" if necessary. +* Set maximum Stage-2 input size supported by the IPMMU. We expect +* the P2M code will take into the account the IOMMU requirements and +* choose suitable "pa_range".
I would drop the last sentence.
Quoted 23 lines
xen/drivers/passthrough/arm/ipmmu-vmsa.c +1
-7*/ -if (IPMMU_MAX_P2M_IPA_BITS < p2m_ipa_bits ) - { -printk_once (XENLOG_ERR "ipmmu: P2M IPA size is not supported (P2M=%u IPMMU=%u)!\n" , - p2m_ipa_bits,IPMMU_MAX_P2M_IPA_BITS ); -return -ENODEV ; - } - } +p2m_restrict_ipa_bits (IPMMU_MAX_P2M_IPA_BITS ); ret =ipmmu_probe (node);if ( ret )xen/drivers/passthrough/arm/smmu.c +0
-3@@ -2198,14 +2198,14 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) size =arm_smmu_id_size_to_bits ((id >>ID2_IAS_SHIFT ) &ID2_IAS_MASK ); smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT, size); -/* Xen: Stage-2 input size has to match p2m_ipa_bits. */ -if (size < p2m_ipa_bits) { - dev_err(smmu->dev,
xen/drivers/passthrough/arm/smmu.c static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) · line 2205
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +5
-5-"P2M IPA size not supported (P2M=%u SMMU=%lu)!\n" , - p2m_ipa_bits, size); -return -ENODEV ; - } - smmu->s2_input_size = p2m_ipa_bits; +/* +* Xen: +* Set maximum Stage-2 input size supported by the SMMU. We expect +* the P2M code will take into the account the IOMMU requirements and +* choose suitable "pa_range".
Same here.
Quoted 16 lines
xen/drivers/passthrough/arm/smmu.c +3
-0+*/ +p2m_restrict_ipa_bits (size); + smmu->s2_input_size = size;#if 0 /* Stage-2 input size limited due to pgd allocation (PTRS_PER_PGD) */ #ifdef CONFIG_64BIT xen/include/asm-arm/p2m.h +1
-0@@ -165,6 +165,14 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx)/* Not supported on ARM. */ } +/*
xen/include/asm-arm/p2m.h void p2m_altp2m_check(struct vcpu *v, uint16_t idx) · line 178
Quoted 10 lines
xen/include/asm-arm/p2m.h +7
-0+* Helper to restrict "p2m_ipa_bits" according the IOMMU requirements. +* +* Each IOMMU driver should report the maximum IPA bits (Stage-2 input size) +* it can support. +*/ +void p2m_restrict_ipa_bits (unsigned int iommu_ipa_bits); +/* Second stage paging setup, to be called on all CPUs */ void setup_virt_paging (void );
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 1 line · Julien Grall
Hi Oleksandr,
Hi, Julien
Quoted 20 lines · Oleksandr Tyshchenko
Quoted 12 lines
From: Oleksandr Tyshchenko <[email protected]>
There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "
p2m_ipa_bits" value as is. But, there are cases when not.In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic.
Quoted 5 lines
First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "
pa_range" according to the restricted "p2m_ipa_bits".
Quoted 3 lines
As I pointed in the previous version, all the code you modify is arm64 specific. For arm32, the number of IPA bits is hardcoded. So if you modify
p2m_ipa_bits, you would end up to misconfigure VTCR.
In other words, for Arm32, you need to checkp2m_ipa_bitsis at least 40-bits before overriding it.
But, all modifications with p2m_ipa_bits are done before setup_virt_paging(), where, actually, the p2m_ipa_bits is hard-coded to 40 bits. How can we end up misconfiguring VTCR for ARM32? Or I really missed something?
Quoted 30 lines
Quoted 30 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>CC Julien Grall <[email protected]>---
Still RFC:1. Patch assumes that IPMMU support is already in.
2. Not checked for the SMMU.Changes since RFC V1 [1]:
- Don't updatep2m_ipa_bitsby the IOMMU drivers directly, introducep2m_restrict_ipa_bits()
- Clarify patch subject/description
- Add more comments to code
- Check for equivalent "pabits" insetup_virt_paging()
- Remove ASSERTs from the SMMU and IPMMU drivers[1] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg02078.html
---
xen/arch/arm/p2m.c | 33
++++++++++++++++++++++++++++++--
xen/arch/arm/setup.c | 11 +++++++++--xen/drivers/passthrough/arm/ipmmu-vmsa.c| 19 ++++-------------- xen/drivers/passthrough/arm/smmu.c | 16 ++++++++-------- xen/include/asm-arm/p2m.h | 8 ++++++++5 files changed, 60 insertions(+), 27 deletions(-)
Quoted 11 lines
xen/arch/arm/p2m.c static unsigned int __read_mostly max_vmid = · line 37
Quoted 9 lines
xen/arch/arm/p2m.c +1
-0@@ -34,7 +34,8 @@ static unsigned int __read_mostly max_vmid =MAX_VMID_8_BIT ; #define P2M_ROOT_PAGES (1<<P2M_ROOT_ORDER) -unsigned int __read_mostly p2m_ipa_bits; +/* Larger than any possible value */ I think it would be worth explaining that this is required so the number of P2M bits can be restricted by external entity (e.g IOMMU).
ok, will add explanation
Quoted 12 lines
xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct · line 1916
Quoted 10 lines
xen/arch/arm/p2m.c +1
-0+unsigned int __read_mostly p2m_ipa_bits =64 ; /* Helpers to lookup the properties of each level */static const
paddr_tlevel_masks[] =xen/arch/arm/p2m.c +0
-0@@ -1912,6 +1913,16 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, return page; } +void __init p2m_restrict_ipa_bits(unsigned int iommu_ipa_bits)The name of the function is quite generic as most of the code in it. So can we avoid use the term IOMMU in it?
yes, will do
Quoted 24 lines
Quoted 13 lines
xen/arch/arm/p2m.c +9
-0+{ + /* + * Calculate the minimum of the maximum IPA bits that any IOMMU + * can support. + */ + if ( iommu_ipa_bits < p2m_ipa_bits ) + p2m_ipa_bits = iommu_ipa_bits; +} + /* VTCR value to be configured by all CPUs. Set only once by the boot CPU */ static uint32_t __read_mostly vtcr;Quoted 8 lines
@@ -1966,10 +1977,28 @@ void
__initsetup_virt_paging(void)
[7] = { 0 } /* Invalid */
};
- unsigned int cpu;
+ unsigned int i, cpu;
unsigned intpa_range=0x10; /* Larger than any possible value */ boolvmid_8_bit= false;
+ if (iommu_enabled)Could we make this IOMMU-agnostic? The main reason to convert from
p2m_ipa_bitstopa_rangeis to cater the rest of the code.
Quoted 1 line
But we could rework the code to do the computation with
p2m_ipa_bitsand then look-up for thepa_range.
I am afraid, I don't completely understand your idea of making this IOMMU-agnostic and what I should do...
Quoted 45 lines
Quoted 34 lines
+ {
+ /*
+ * Choose suitable "pa_range" according to the IOMMU requirements
+ * (restricted "p2m_ipa_bits" value).
+ * As P2M table is always configured with IPA bits == PA bits, + * check for equivalent "pabits" and store it's index. + */
+ for ( i = 0; i <ARRAY_SIZE(pa_range_info); i++ )
+ {
+ if (p2m_ipa_bits== pa_range_info[i].pabits ) + {
+pa_range= i;
+ break;
+ }
+ }
+ }
+
for_each_online_cpu( cpu )
{
const structcpuinfo_arm*info = &cpu_data[cpu];xen/arch/arm/setup.c +2
-1@@ -936,12 +936,19 @@ void __init start_xen(unsigned long boot_phys_offset, printk("Brought up %ld CPUs\n", (long)num_online_cpus()); /* TODO: smp_cpus_done(); */ - setup_virt_paging(); - + /* +* The IOMMU subsystem must be initialized before P2M as we need to gather
Quoted 8 lines
+ * requirements regarding the maximum IPA bits supported by each IOMMU
+ * device to figure out the minimum value among them. The P2M code will
+ * choose suitable "pa_range" according to the restricted "p2m_ipa_bits"
+ * value.
+ */This is a bit too verbose, implementation details are not necessary here and increasing the risk to have bit rot comment. So how about:
Quoted 1 line
"The IOMMU subsystem must be initialized before the P2M as we need to gather requirements regarding the maximum IPA bit supported by each IOMMU."?
you are right, will update a comment
Quoted 30 lines
Quoted 30 lines
rc =
iommu_setup();
if ( !iommu_enabled && rc !=-ENODEV)panic("Couldn't configure correctly all the IOMMUs."); +setup_virt_paging();
+
do_initcalls();
/*xen/drivers/passthrough/arm/ipmmu-vmsa.c +0
-0@@ -1314,23 +1314,12 @@ static __init int ipmmu_init(struct dt_device_node *node, const void *data) return -ENODEV; }else
- {
/*
- * As 4-level translation table is not supported in IPMMU, we need
- * to check IPA size used for P2M table beforehand to be sure it is
- * 3-level and the IPMMU will be able to use it. - *
- * TODO: First initialize the IOMMU and gather the requirements and
- * then initialize the P2M. In the P2M code, take into the account
Quoted 8 lines
Quoted 6 lines
- * the IOMMU requirements and restrict "
pa_range" if necessary. + * Set maximum Stage-2 input size supported by the IPMMU. We expect
+ * the P2M code will take into the account the IOMMU requirements and
+ * choose suitable "pa_range".I would drop the last sentence.
ok. will do
Quoted 30 lines
Quoted 30 lines
*/
- if (IPMMU_MAX_P2M_IPA_BITS<p2m_ipa_bits) - {
- printk_once(XENLOG_ERR "ipmmu: P2M IPA size is not supported (P2M=%u IPMMU=%u)!\n",
-p2m_ipa_bits,IPMMU_MAX_P2M_IPA_BITS); - return-ENODEV;
- }
- }
+p2m_restrict_ipa_bits(IPMMU_MAX_P2M_IPA_BITS); ret =ipmmu_probe(node);
if ( ret )xen/drivers/passthrough/arm/smmu.c +0
-0@@ -2198,14 +2198,14 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) size = arm_smmu_id_size_to_bits((id >> ID2_IAS_SHIFT) & ID2_IAS_MASK); smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT, size);- /* Xen: Stage-2 input size has to match p2m_ipa_bits. */ - if (size <
p2m_ipa_bits) {
- dev_err(smmu->dev,
- "P2M IPA size not supported (P2M=%u SMMU=%lu)!\n", -p2m_ipa_bits, size);
- return-ENODEV;
- }
-smmu->s2_input_size=p2m_ipa_bits;
Quoted 8 lines
Quoted 6 lines
+ /*
+ * Xen:
+ * Set maximum Stage-2 input size supported by the SMMU. We expect + * the P2M code will take into the account the IOMMU requirements and
+ * choose suitable "pa_range".Same here.
ok
Signature · 9 lines
Regards, Oleksandr Tyshchenko _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 27 lines · Oleksandr
Quoted 1 line · Julien Grall
Hi Oleksandr,
Hi, Julien
Quoted 20 lines · Oleksandr Tyshchenko
Quoted 17 lines
From: Oleksandr Tyshchenko <[email protected]>
There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "
p2m_ipa_bits" value as is. But, there are cases when not.In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic.
First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "
pa_range" according to the restricted "p2m_ipa_bits".
Quoted 5 lines
Quoted 3 lines
As I pointed in the previous version, all the code you modify is arm64 specific. For arm32, the number of IPA bits is hardcoded. So if you modify
p2m_ipa_bits, you would end up to misconfigure VTCR.
In other words, for Arm32, you need to checkp2m_ipa_bitsis at least 40-bits before overriding it.But, all modifications with
p2m_ipa_bitsare done beforesetup_virt_paging(), where, actually, thep2m_ipa_bitsis hard-coded to 40 bits. How can we end up misconfiguring VTCR for ARM32? Or I really missed something?
Sorry if I wasn't cleared, I meant the VTCR for the IOMMU. You would end up to configure with a value that is bigger than what it can support.
I am ok if you don't restrict the p2m_ipa_bits and just fail. The point is to notify the user ASAP rather than allowing to continue.
This would make the behavior similar to the current implementation (although the error would be different).
[...]
Quoted 22 lines
Quoted 22 lines
Quoted 11 lines
xen/arch/arm/p2m.c +9
-0+{ + /* + * Calculate the minimum of the maximum IPA bits that any IOMMU + * can support. + */ + if ( iommu_ipa_bits < p2m_ipa_bits ) + p2m_ipa_bits = iommu_ipa_bits; +} +/* VTCR value to be configured by all CPUs. Set only once by the boot CPU */ static
uint32_t__read_mostlyvtcr;Quoted 8 lines
@@ -1966,10 +1977,28 @@ void
__initsetup_virt_paging(void)
[7] = { 0 } /* Invalid */
};
- unsigned int cpu;
+ unsigned int i, cpu;
unsigned intpa_range=0x10; /* Larger than any possible value */ boolvmid_8_bit= false;
+ if (iommu_enabled)Could we make this IOMMU-agnostic? The main reason to convert from
p2m_ipa_bitstopa_rangeis to cater the rest of the code.
Quoted 3 lines
Quoted 1 line
But we could rework the code to do the computation with
p2m_ipa_bitsand then look-up for thepa_range.I am afraid, I don't completely understand your idea of making this IOMMU-agnostic and what I should do...
Roughly what you are doing today is:
if ( iommu_enabled )
pa_range = find_pa_range_from_p2m_bits().
for_each_cpu()
if ( cpu.pa_range < pa_range )
pa_range = cpu.pa_range
....
What you could do is:
for_ech_cpu()
if ( p2m_ipa_bits < pa_range_info[cpu.pa_range].pabits )
p2m_ipa_bits = pa_range_info[cpu.pa_range].pabits;
pa_range = find_pa_range_from_p2m_bits();
/* Check validity */
...
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 1 line · Julien Grall
Hi,
Hi Julien
Quoted 33 lines · Oleksandr
Quoted 31 lines · Julien Grall
Quoted 1 line
Hi Oleksandr,
Hi, Julien
Quoted 23 lines · Oleksandr Tyshchenko
Quoted 12 lines
From: Oleksandr Tyshchenko <[email protected]>
There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "
p2m_ipa_bits" value as is. But, there are cases when not.In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic.
Quoted 5 lines
First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "
pa_range" according to the restricted "p2m_ipa_bits".As I pointed in the previous version, all the code you modify is arm64 specific. For arm32, the number of IPA bits is hardcoded. So if you modify
p2m_ipa_bits, you would end up to misconfigure VTCR.
In other words, for Arm32, you need to checkp2m_ipa_bitsis at least 40-bits before overriding it.
Quoted 6 lines
Quoted 1 line
But, all modifications with
p2m_ipa_bitsare done beforesetup_virt_paging(), where, actually, thep2m_ipa_bitsis hard-coded to 40 bits. How can we end up misconfiguring VTCR for ARM32? Or I really missed something?Sorry if I wasn't cleared, I meant the VTCR for the IOMMU. You would end up to configure with a value that is bigger than what it can support. I am ok if you don't restrict the
p2m_ipa_bitsand just fail. The point is to notify the user ASAP rather than allowing to continue.This would make the behavior similar to the current implementation (although the error would be different).
So, in IOMMU driver we should check if IOMMU is able to support at least 40-bit IPA before trying to restrict. If yes, then go ahead, but if no, then just fail. Correct?
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
Quoted 11 lines
xen/arch/arm/p2m.c +9
-0+{ + /* + * Calculate the minimum of the maximum IPA bits that any IOMMU + * can support. + */ + if ( iommu_ipa_bits < p2m_ipa_bits ) + p2m_ipa_bits = iommu_ipa_bits; +} +/* VTCR value to be configured by all CPUs. Set only once by the boot CPU */ static
uint32_t__read_mostlyvtcr;Quoted 8 lines
@@ -1966,10 +1977,28 @@ void
__initsetup_virt_paging(void)
[7] = { 0 } /* Invalid */
};
- unsigned int cpu;
+ unsigned int i, cpu;
unsigned intpa_range=0x10; /* Larger than any possible value */ boolvmid_8_bit= false;
+ if (iommu_enabled)Could we make this IOMMU-agnostic? The main reason to convert from
p2m_ipa_bitstopa_rangeis to cater the rest of the code.Quoted 3 lines
Quoted 1 line
But we could rework the code to do the computation with
p2m_ipa_bitsand then look-up for thepa_range.I am afraid, I don't completely understand your idea of making this IOMMU-agnostic and what I should do...
Roughly what you are doing today is:
if (
iommu_enabled)
pa_range=find_pa_range_from_p2m_bits().
Quoted 7 lines
for_each_cpu()
if ( cpu.pa_range <pa_range)
pa_range= cpu.pa_range....
What you could do is:
Thank you for the clarification. I think I understand your idea.
But ...
Quoted 3 lines
for_ech_cpu()
if (p2m_ipa_bits< pa_range_info[cpu.pa_range].pabits )
Probably you meant ">" here?
Quoted 4 lines
p2m_ipa_bits= pa_range_info[cpu.pa_range].pabits;
pa_range=find_pa_range_from_p2m_bits();
/* Check validity */
Signature · 9 lines
Regards, Oleksandr Tyshchenko _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 40 lines · Oleksandr
Quoted 1 line · Julien Grall
Hi,
Hi Julien
Quoted 33 lines · Oleksandr
Quoted 31 lines · Julien Grall
Quoted 1 line
Hi Oleksandr,
Hi, Julien
Quoted 23 lines · Oleksandr Tyshchenko
Quoted 12 lines
From: Oleksandr Tyshchenko <[email protected]>
There is a strict requirement for the IOMMU which wants to share the P2M table with the CPU. The IOMMU's Stage-2 input size must be equal to the P2M IPA size. It is not a problem when the IOMMU can support all values the CPU supports. In that case, the IOMMU driver would just use any "
p2m_ipa_bits" value as is. But, there are cases when not.In order to make P2M sharing possible on the platforms which IPMMUs have a limitation in maximum Stage-2 input size introduce the following logic.
Quoted 5 lines
First initialize the IOMMU subsystem and gather requirements regarding the maximum IPA bits supported by each IOMMU device to figure out the minimum value among them. In the P2M code, take into the account the IOMMU requirements and choose suitable "
pa_range" according to the restricted "p2m_ipa_bits".As I pointed in the previous version, all the code you modify is arm64 specific. For arm32, the number of IPA bits is hardcoded. So if you modify
p2m_ipa_bits, you would end up to misconfigure VTCR.
In other words, for Arm32, you need to checkp2m_ipa_bitsis at least 40-bits before overriding it.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
But, all modifications with
p2m_ipa_bitsare done beforesetup_virt_paging(), where, actually, thep2m_ipa_bitsis hard-coded to 40 bits. How can we end up misconfiguring VTCR for ARM32? Or I really missed something?Sorry if I wasn't cleared, I meant the VTCR for the IOMMU. You would end up to configure with a value that is bigger than what it can support. I am ok if you don't restrict the
p2m_ipa_bitsand just fail. The point is to notify the user ASAP rather than allowing to continue.This would make the behavior similar to the current implementation (although the error would be different).
So, in IOMMU driver we should check if IOMMU is able to support at least 40-bit IPA before trying to restrict. If yes, then go ahead, but if no, then just fail. Correct?
There are no need to do this in the IOMU drivers. And I actually don't such check in the drivers.
This is the similar problem to half initialized IOMMU. If the user requests IOMMU and doesn't work, then we don't want to continue an panic. Such check can be done directly in the function setup_virt_paging().
Quoted 43 lines
Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
Quoted 13 lines
xen/arch/arm/p2m.c +9
-0+{ + /* + * Calculate the minimum of the maximum IPA bits that any IOMMU + * can support. + */ + if ( iommu_ipa_bits < p2m_ipa_bits ) + p2m_ipa_bits = iommu_ipa_bits; +} +/* VTCR value to be configured by all CPUs. Set only once by the boot CPU */ static
uint32_t__read_mostlyvtcr;Quoted 8 lines
@@ -1966,10 +1977,28 @@ void
__initsetup_virt_paging(void)
[7] = { 0 } /* Invalid */
};
- unsigned int cpu;
+ unsigned int i, cpu;
unsigned intpa_range=0x10; /* Larger than any possible value */ boolvmid_8_bit= false;
+ if (iommu_enabled)Could we make this IOMMU-agnostic? The main reason to convert from
p2m_ipa_bitstopa_rangeis to cater the rest of the code.Quoted 3 lines
Quoted 1 line
But we could rework the code to do the computation with
p2m_ipa_bitsand then look-up for thepa_range.I am afraid, I don't completely understand your idea of making this IOMMU-agnostic and what I should do...
Roughly what you are doing today is:
if (
iommu_enabled)
pa_range=find_pa_range_from_p2m_bits().Quoted 7 lines
for_each_cpu()
if ( cpu.pa_range <pa_range)
pa_range= cpu.pa_range....
What you could do is:
Thank you for the clarification. I think I understand your idea.
Quoted 7 lines
But ...
Quoted 3 lines
for_ech_cpu()
if (p2m_ipa_bits< pa_range_info[cpu.pa_range].pabits )Probably you meant ">" here?
Yes.
Quoted 8 lines
Quoted 6 lines
p2m_ipa_bits= pa_range_info[cpu.pa_range].pabits;
pa_range=find_pa_range_from_p2m_bits();
/* Check validity */
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel