Re: [PATCH 1/3] KVM: arm64: Check if 52-bits PA is enabled

2020-10-26 Thread Gavin Shan

On 10/26/20 7:53 PM, Marc Zyngier wrote:

On 2020-10-25 22:23, Gavin Shan wrote:

Hi Marc,

On 10/25/20 8:52 PM, Marc Zyngier wrote:

On Sun, 25 Oct 2020 01:27:37 +0100,
Gavin Shan  wrote:


The 52-bits physical address is disabled until CONFIG_ARM64_PA_BITS_52
is chosen. This uses option for that check, to avoid the unconditional
check on PAGE_SHIFT in the hot path and thus save some CPU cycles.


PAGE_SHIFT is known at compile time, and this code is dropped by the
compiler if the selected page size is not 64K. This patch really only
makes the code slightly less readable and the "CPU cycles" argument
doesn't hold at all.

So what are you trying to solve exactly?



There are two points covered by the patch: (1) The 52-bits physical address
is visible only when CONFIG_ARM64_PA_BITS_52 is enabled in arch/arm64 code.
The code looks consistent with this option used here. (2) I had the assumption
that gcc doesn't optimize the code and PAGE_SHIFT is always checked in order
to get higher 4 physical address bits, but you said gcc should optimize the
code accordingly. However, it would be still nice to make the code explicit.


Conditional compilation only results in more breakages, specially for configs
that hardly anyone uses (big-endian and 64K pages are the two that bitrot very
quickly).

So if anything can build without #ifdef, I'll take that anytime. If the compiler
doesn't optimize it away, let's fix the compiler.



Ok. PATCH[1] and PATCH[2] have been dropped in v2.

Cheers,
Gavin



Re: [PATCH 1/3] KVM: arm64: Check if 52-bits PA is enabled

2020-10-26 Thread Marc Zyngier

On 2020-10-25 22:23, Gavin Shan wrote:

Hi Marc,

On 10/25/20 8:52 PM, Marc Zyngier wrote:

On Sun, 25 Oct 2020 01:27:37 +0100,
Gavin Shan  wrote:


The 52-bits physical address is disabled until 
CONFIG_ARM64_PA_BITS_52
is chosen. This uses option for that check, to avoid the 
unconditional

check on PAGE_SHIFT in the hot path and thus save some CPU cycles.


PAGE_SHIFT is known at compile time, and this code is dropped by the
compiler if the selected page size is not 64K. This patch really only
makes the code slightly less readable and the "CPU cycles" argument
doesn't hold at all.

So what are you trying to solve exactly?



There are two points covered by the patch: (1) The 52-bits physical 
address
is visible only when CONFIG_ARM64_PA_BITS_52 is enabled in arch/arm64 
code.
The code looks consistent with this option used here. (2) I had the 
assumption
that gcc doesn't optimize the code and PAGE_SHIFT is always checked in 
order
to get higher 4 physical address bits, but you said gcc should optimize 
the
code accordingly. However, it would be still nice to make the code 
explicit.


Conditional compilation only results in more breakages, specially for 
configs
that hardly anyone uses (big-endian and 64K pages are the two that 
bitrot very

quickly).

So if anything can build without #ifdef, I'll take that anytime. If the 
compiler

doesn't optimize it away, let's fix the compiler.

Thanks,

M.
--
Jazz is not dead. It just smells funny...


Re: [PATCH 1/3] KVM: arm64: Check if 52-bits PA is enabled

2020-10-26 Thread Will Deacon
On Mon, Oct 26, 2020 at 09:23:31AM +1100, Gavin Shan wrote:
> On 10/25/20 8:52 PM, Marc Zyngier wrote:
> > On Sun, 25 Oct 2020 01:27:37 +0100,
> > Gavin Shan  wrote:
> > > 
> > > The 52-bits physical address is disabled until CONFIG_ARM64_PA_BITS_52
> > > is chosen. This uses option for that check, to avoid the unconditional
> > > check on PAGE_SHIFT in the hot path and thus save some CPU cycles.
> > 
> > PAGE_SHIFT is known at compile time, and this code is dropped by the
> > compiler if the selected page size is not 64K. This patch really only
> > makes the code slightly less readable and the "CPU cycles" argument
> > doesn't hold at all.
> > 
> > So what are you trying to solve exactly?
> > 
> 
> There are two points covered by the patch: (1) The 52-bits physical address
> is visible only when CONFIG_ARM64_PA_BITS_52 is enabled in arch/arm64 code.
> The code looks consistent with this option used here. (2) I had the assumption
> that gcc doesn't optimize the code and PAGE_SHIFT is always checked in order
> to get higher 4 physical address bits, but you said gcc should optimize the
> code accordingly. However, it would be still nice to make the code explicit.

I don't know: adding #ifdef CONFIG_ lines just reduces the coverage we
get from CI, so unless the code is actually causing a problem then I'd be
inclined to leave it as-is.

Will


Re: [PATCH 1/3] KVM: arm64: Check if 52-bits PA is enabled

2020-10-25 Thread Gavin Shan

Hi Marc,

On 10/25/20 8:52 PM, Marc Zyngier wrote:

On Sun, 25 Oct 2020 01:27:37 +0100,
Gavin Shan  wrote:


The 52-bits physical address is disabled until CONFIG_ARM64_PA_BITS_52
is chosen. This uses option for that check, to avoid the unconditional
check on PAGE_SHIFT in the hot path and thus save some CPU cycles.


PAGE_SHIFT is known at compile time, and this code is dropped by the
compiler if the selected page size is not 64K. This patch really only
makes the code slightly less readable and the "CPU cycles" argument
doesn't hold at all.

So what are you trying to solve exactly?



There are two points covered by the patch: (1) The 52-bits physical address
is visible only when CONFIG_ARM64_PA_BITS_52 is enabled in arch/arm64 code.
The code looks consistent with this option used here. (2) I had the assumption
that gcc doesn't optimize the code and PAGE_SHIFT is always checked in order
to get higher 4 physical address bits, but you said gcc should optimize the
code accordingly. However, it would be still nice to make the code explicit.

Thanks,
Gavin



Signed-off-by: Gavin Shan 
---
  arch/arm64/kvm/hyp/pgtable.c | 10 ++
  1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index 0cdf6e461cbd..fd850353ee89 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -132,8 +132,9 @@ static u64 kvm_pte_to_phys(kvm_pte_t pte)
  {
u64 pa = pte & KVM_PTE_ADDR_MASK;
  
-	if (PAGE_SHIFT == 16)

-   pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48;
+#ifdef CONFIG_ARM64_PA_BITS_52
+   pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48;
+#endif
  
  	return pa;

  }
@@ -142,8 +143,9 @@ static kvm_pte_t kvm_phys_to_pte(u64 pa)
  {
kvm_pte_t pte = pa & KVM_PTE_ADDR_MASK;
  
-	if (PAGE_SHIFT == 16)

-   pte |= FIELD_PREP(KVM_PTE_ADDR_51_48, pa >> 48);
+#ifdef CONFIG_ARM64_PA_BITS_52
+   pte |= FIELD_PREP(KVM_PTE_ADDR_51_48, pa >> 48);
+#endif
  
  	return pte;

  }
--
2.23.0








Re: [PATCH 1/3] KVM: arm64: Check if 52-bits PA is enabled

2020-10-25 Thread Marc Zyngier
On Sun, 25 Oct 2020 01:27:37 +0100,
Gavin Shan  wrote:
> 
> The 52-bits physical address is disabled until CONFIG_ARM64_PA_BITS_52
> is chosen. This uses option for that check, to avoid the unconditional
> check on PAGE_SHIFT in the hot path and thus save some CPU cycles.

PAGE_SHIFT is known at compile time, and this code is dropped by the
compiler if the selected page size is not 64K. This patch really only
makes the code slightly less readable and the "CPU cycles" argument
doesn't hold at all.

So what are you trying to solve exactly?

M.

> 
> Signed-off-by: Gavin Shan 
> ---
>  arch/arm64/kvm/hyp/pgtable.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index 0cdf6e461cbd..fd850353ee89 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -132,8 +132,9 @@ static u64 kvm_pte_to_phys(kvm_pte_t pte)
>  {
>   u64 pa = pte & KVM_PTE_ADDR_MASK;
>  
> - if (PAGE_SHIFT == 16)
> - pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48;
> +#ifdef CONFIG_ARM64_PA_BITS_52
> + pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48;
> +#endif
>  
>   return pa;
>  }
> @@ -142,8 +143,9 @@ static kvm_pte_t kvm_phys_to_pte(u64 pa)
>  {
>   kvm_pte_t pte = pa & KVM_PTE_ADDR_MASK;
>  
> - if (PAGE_SHIFT == 16)
> - pte |= FIELD_PREP(KVM_PTE_ADDR_51_48, pa >> 48);
> +#ifdef CONFIG_ARM64_PA_BITS_52
> + pte |= FIELD_PREP(KVM_PTE_ADDR_51_48, pa >> 48);
> +#endif
>  
>   return pte;
>  }
> -- 
> 2.23.0
> 
> 

-- 
Without deviation from the norm, progress is not possible.