diff mbox series

[v1,17/24] kvm: arm64: Add __hyp_pa_symbol helper macro

Message ID 20201109113233.9012-18-dbrazdil@google.com (mailing list archive)
State New, archived
Headers show
Series Opt-in always-on nVHE hypervisor | expand

Commit Message

David Brazdil Nov. 9, 2020, 11:32 a.m. UTC
Add helper macro for computing the PA of a kernel symbol in nVHE hyp
code. This will be useful for computing the PA of a PSCI CPU_ON entry
point.

Signed-off-by: David Brazdil <dbrazdil@google.com>
---
 arch/arm64/kvm/hyp/nvhe/psci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Quentin Perret Nov. 9, 2020, 4:59 p.m. UTC | #1
Hey David,

On Monday 09 Nov 2020 at 11:32:26 (+0000), David Brazdil wrote:
> Add helper macro for computing the PA of a kernel symbol in nVHE hyp
> code. This will be useful for computing the PA of a PSCI CPU_ON entry
> point.
> 
> Signed-off-by: David Brazdil <dbrazdil@google.com>
> ---
>  arch/arm64/kvm/hyp/nvhe/psci.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c
> index b0b5df590ba5..7510b9e174e9 100644
> --- a/arch/arm64/kvm/hyp/nvhe/psci.c
> +++ b/arch/arm64/kvm/hyp/nvhe/psci.c
> @@ -20,6 +20,16 @@ s64 hyp_physvirt_offset;
>  
>  #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset)
>  
> +#define __hyp_pa_symbol(sym)					\
> +	({							\
> +		extern char sym[];				\
> +		unsigned long kern_va;				\
> +								\
> +		asm volatile("ldr %0, =%1" : "=r" (kern_va)	\
> +					   : "S" (sym));	\
> +		kern_va - kimage_voffset;			\
> +	})
> +

Could this be simplified to __hyp_pa(hyp_symbol_addr(sym))? That would
avoid the dependency on kimage_voffset.

Thanks,
Quentin
Marc Zyngier Nov. 9, 2020, 6:10 p.m. UTC | #2
On 2020-11-09 16:59, Quentin Perret wrote:
> Hey David,
> 
> On Monday 09 Nov 2020 at 11:32:26 (+0000), David Brazdil wrote:
>> Add helper macro for computing the PA of a kernel symbol in nVHE hyp
>> code. This will be useful for computing the PA of a PSCI CPU_ON entry
>> point.
>> 
>> Signed-off-by: David Brazdil <dbrazdil@google.com>
>> ---
>>  arch/arm64/kvm/hyp/nvhe/psci.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>> 
>> diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c 
>> b/arch/arm64/kvm/hyp/nvhe/psci.c
>> index b0b5df590ba5..7510b9e174e9 100644
>> --- a/arch/arm64/kvm/hyp/nvhe/psci.c
>> +++ b/arch/arm64/kvm/hyp/nvhe/psci.c
>> @@ -20,6 +20,16 @@ s64 hyp_physvirt_offset;
>> 
>>  #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset)
>> 
>> +#define __hyp_pa_symbol(sym)					\
>> +	({							\
>> +		extern char sym[];				\
>> +		unsigned long kern_va;				\
>> +								\
>> +		asm volatile("ldr %0, =%1" : "=r" (kern_va)	\
>> +					   : "S" (sym));	\
>> +		kern_va - kimage_voffset;			\
>> +	})
>> +
> 
> Could this be simplified to __hyp_pa(hyp_symbol_addr(sym))? That would
> avoid the dependency on kimage_voffset.

I'm going to move away from evaluating kimage_voffset at runtime anyway,
see [1].

Thanks,

         M.

[1] https://lore.kernel.org/r/20201109175923.445945-1-maz@kernel.org
David Brazdil Nov. 10, 2020, 9:24 a.m. UTC | #3
On Mon, Nov 09, 2020 at 06:10:05PM +0000, Marc Zyngier wrote:
> On 2020-11-09 16:59, Quentin Perret wrote:
> > Hey David,
> > 
> > On Monday 09 Nov 2020 at 11:32:26 (+0000), David Brazdil wrote:
> > > Add helper macro for computing the PA of a kernel symbol in nVHE hyp
> > > code. This will be useful for computing the PA of a PSCI CPU_ON entry
> > > point.
> > > 
> > > Signed-off-by: David Brazdil <dbrazdil@google.com>
> > > ---
> > >  arch/arm64/kvm/hyp/nvhe/psci.c | 10 ++++++++++
> > >  1 file changed, 10 insertions(+)
> > > 
> > > diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c
> > > b/arch/arm64/kvm/hyp/nvhe/psci.c
> > > index b0b5df590ba5..7510b9e174e9 100644
> > > --- a/arch/arm64/kvm/hyp/nvhe/psci.c
> > > +++ b/arch/arm64/kvm/hyp/nvhe/psci.c
> > > @@ -20,6 +20,16 @@ s64 hyp_physvirt_offset;
> > > 
> > >  #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset)
> > > 
> > > +#define __hyp_pa_symbol(sym)					\
> > > +	({							\
> > > +		extern char sym[];				\
> > > +		unsigned long kern_va;				\
> > > +								\
> > > +		asm volatile("ldr %0, =%1" : "=r" (kern_va)	\
> > > +					   : "S" (sym));	\
> > > +		kern_va - kimage_voffset;			\
> > > +	})
> > > +
> > 
> > Could this be simplified to __hyp_pa(hyp_symbol_addr(sym))? That would
> > avoid the dependency on kimage_voffset.

Ah, didn't see that one. Ok, removing this patch.

> 
> I'm going to move away from evaluating kimage_voffset at runtime anyway,
> see [1].

Awesome! One more dependency gone.

> 
> Thanks,
> 
>         M.
> 
> [1] https://lore.kernel.org/r/20201109175923.445945-1-maz@kernel.org
> -- 
> Jazz is not dead. It just smells funny...
diff mbox series

Patch

diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c
index b0b5df590ba5..7510b9e174e9 100644
--- a/arch/arm64/kvm/hyp/nvhe/psci.c
+++ b/arch/arm64/kvm/hyp/nvhe/psci.c
@@ -20,6 +20,16 @@  s64 hyp_physvirt_offset;
 
 #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset)
 
+#define __hyp_pa_symbol(sym)					\
+	({							\
+		extern char sym[];				\
+		unsigned long kern_va;				\
+								\
+		asm volatile("ldr %0, =%1" : "=r" (kern_va)	\
+					   : "S" (sym));	\
+		kern_va - kimage_voffset;			\
+	})
+
 static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt)
 {
 	return host_ctxt->regs.regs[0];