diff mbox series

[v3,10/14] arm64: Force device mappings to be non-secure shared

Message ID 20240605093006.145492-11-steven.price@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64: Support for running as a guest in Arm CCA | expand

Commit Message

Steven Price June 5, 2024, 9:30 a.m. UTC
From: Suzuki K Poulose <suzuki.poulose@arm.com>

Device mappings (currently) need to be emulated by the VMM so must be
mapped shared with the host.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
---
 arch/arm64/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Kelley June 17, 2024, 3:33 a.m. UTC | #1
From: Steven Price <steven.price@arm.com> Sent: Wednesday, June 5, 2024 2:30 AM
> 
> From: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> Device mappings (currently) need to be emulated by the VMM so must be
> mapped shared with the host.
> 
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> Signed-off-by: Steven Price <steven.price@arm.com>
> ---
>  arch/arm64/include/asm/pgtable.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 11d614d83317..c986fde262c0 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -644,7 +644,7 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
>  #define pgprot_writecombine(prot) \
>  	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
>  #define pgprot_device(prot) \
> -	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
> +	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN | PROT_NS_SHARED)
>  #define pgprot_tagged(prot) \
>  	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED))
>  #define pgprot_mhp	pgprot_tagged

In v2 of the patches, Catalin raised a question about the need for
pgprot_decrypted(). What was concluded? It still looks to me like
pgprot_decrypted() and prot_encrypted() are needed, by
dma_direct_mmap() and remap_oldmem_pfn_range(), respectively.
Also, assuming Hyper-V supports CCA at some point, the Linux guest
drivers for Hyper-V need pgprot_decrypted() in hv_ringbuffer_init().

Michael
Suzuki K Poulose June 17, 2024, 2:55 p.m. UTC | #2
On 17/06/2024 04:33, Michael Kelley wrote:
> From: Steven Price <steven.price@arm.com> Sent: Wednesday, June 5, 2024 2:30 AM
>>
>> From: Suzuki K Poulose <suzuki.poulose@arm.com>
>>
>> Device mappings (currently) need to be emulated by the VMM so must be
>> mapped shared with the host.
>>
>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
>> Signed-off-by: Steven Price <steven.price@arm.com>
>> ---
>>   arch/arm64/include/asm/pgtable.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>> index 11d614d83317..c986fde262c0 100644
>> --- a/arch/arm64/include/asm/pgtable.h
>> +++ b/arch/arm64/include/asm/pgtable.h
>> @@ -644,7 +644,7 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
>>   #define pgprot_writecombine(prot) \
>>   	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
>>   #define pgprot_device(prot) \
>> -	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
>> +	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN | PROT_NS_SHARED)
>>   #define pgprot_tagged(prot) \
>>   	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED))
>>   #define pgprot_mhp	pgprot_tagged
> 
> In v2 of the patches, Catalin raised a question about the need for
> pgprot_decrypted(). What was concluded? It still looks to me like
> pgprot_decrypted() and prot_encrypted() are needed, by
> dma_direct_mmap() and remap_oldmem_pfn_range(), respectively.
> Also, assuming Hyper-V supports CCA at some point, the Linux guest
> drivers for Hyper-V need pgprot_decrypted() in hv_ringbuffer_init().

Right, I think we could simply do :

diff --git a/arch/arm64/include/asm/pgtable.h 
b/arch/arm64/include/asm/pgtable.h
index c986fde262c0..1ed45893d1e6 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -648,6 +648,10 @@ static inline void set_pud_at(struct mm_struct *mm, 
unsigned long addr,
  #define pgprot_tagged(prot) \
         __pgprot_modify(prot, PTE_ATTRINDX_MASK, 
PTE_ATTRINDX(MT_NORMAL_TAGGED))
  #define pgprot_mhp     pgprot_tagged
+
+#define pgprot_decrypted(prot) __pgprot_modify(prot, PROT_NS_SHARED, 
PROT_NS_SHARED)
+#define pgprot_encrypted(prot)  __pgprot_modify(prot, PROT_NS_SHARED, 0)
+


Suzuki
Catalin Marinas June 17, 2024, 3:43 p.m. UTC | #3
On Mon, Jun 17, 2024 at 03:55:22PM +0100, Suzuki K Poulose wrote:
> On 17/06/2024 04:33, Michael Kelley wrote:
> > From: Steven Price <steven.price@arm.com> Sent: Wednesday, June 5, 2024 2:30 AM
> > > 
> > > From: Suzuki K Poulose <suzuki.poulose@arm.com>
> > > 
> > > Device mappings (currently) need to be emulated by the VMM so must be
> > > mapped shared with the host.
> > > 
> > > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > > Signed-off-by: Steven Price <steven.price@arm.com>
> > > ---
> > >   arch/arm64/include/asm/pgtable.h | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> > > index 11d614d83317..c986fde262c0 100644
> > > --- a/arch/arm64/include/asm/pgtable.h
> > > +++ b/arch/arm64/include/asm/pgtable.h
> > > @@ -644,7 +644,7 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
> > >   #define pgprot_writecombine(prot) \
> > >   	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
> > >   #define pgprot_device(prot) \
> > > -	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
> > > +	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN | PROT_NS_SHARED)
> > >   #define pgprot_tagged(prot) \
> > >   	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED))
> > >   #define pgprot_mhp	pgprot_tagged
> > 
> > In v2 of the patches, Catalin raised a question about the need for
> > pgprot_decrypted(). What was concluded? It still looks to me like
> > pgprot_decrypted() and prot_encrypted() are needed, by
> > dma_direct_mmap() and remap_oldmem_pfn_range(), respectively.
> > Also, assuming Hyper-V supports CCA at some point, the Linux guest
> > drivers for Hyper-V need pgprot_decrypted() in hv_ringbuffer_init().
> 
> Right, I think we could simply do :
> 
> diff --git a/arch/arm64/include/asm/pgtable.h
> b/arch/arm64/include/asm/pgtable.h
> index c986fde262c0..1ed45893d1e6 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -648,6 +648,10 @@ static inline void set_pud_at(struct mm_struct *mm,
> unsigned long addr,
>  #define pgprot_tagged(prot) \
>         __pgprot_modify(prot, PTE_ATTRINDX_MASK,
> PTE_ATTRINDX(MT_NORMAL_TAGGED))
>  #define pgprot_mhp     pgprot_tagged
> +
> +#define pgprot_decrypted(prot) __pgprot_modify(prot, PROT_NS_SHARED, PROT_NS_SHARED)
> +#define pgprot_encrypted(prot)  __pgprot_modify(prot, PROT_NS_SHARED, 0)

And maybe rewrite pgprot_device() as:

#define __pgprot_device(prot) \
	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
#define pgprot_device(prot)	__pgprot_device(pgprot_decrypted(prot))
Michael Kelley June 17, 2024, 3:46 p.m. UTC | #4
From: Suzuki K Poulose <suzuki.poulose@arm.com> Sent: Monday, June 17, 2024 7:55 AM
> 
> On 17/06/2024 04:33, Michael Kelley wrote:
> > From: Steven Price <steven.price@arm.com> Sent: Wednesday, June 5, 2024 2:30 AM
> >>
> >> From: Suzuki K Poulose <suzuki.poulose@arm.com>
> >>
> >> Device mappings (currently) need to be emulated by the VMM so must be
> >> mapped shared with the host.
> >>
> >> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> >> Signed-off-by: Steven Price <steven.price@arm.com>
> >> ---
> >>   arch/arm64/include/asm/pgtable.h | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/arch/arm64/include/asm/pgtable.h
> b/arch/arm64/include/asm/pgtable.h
> >> index 11d614d83317..c986fde262c0 100644
> >> --- a/arch/arm64/include/asm/pgtable.h
> >> +++ b/arch/arm64/include/asm/pgtable.h
> >> @@ -644,7 +644,7 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
> >>   #define pgprot_writecombine(prot) \
> >>   	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
> >>   #define pgprot_device(prot) \
> >> -	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
> >> +	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN | PROT_NS_SHARED)
> >>   #define pgprot_tagged(prot) \
> >>   	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED))
> >>   #define pgprot_mhp	pgprot_tagged
> >
> > In v2 of the patches, Catalin raised a question about the need for
> > pgprot_decrypted(). What was concluded? It still looks to me like
> > pgprot_decrypted() and prot_encrypted() are needed, by
> > dma_direct_mmap() and remap_oldmem_pfn_range(), respectively.
> > Also, assuming Hyper-V supports CCA at some point, the Linux guest
> > drivers for Hyper-V need pgprot_decrypted() in hv_ringbuffer_init().
> 
> Right, I think we could simply do :
> 
> diff --git a/arch/arm64/include/asm/pgtable.h
> b/arch/arm64/include/asm/pgtable.h
> index c986fde262c0..1ed45893d1e6 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -648,6 +648,10 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
>   #define pgprot_tagged(prot) \
>          __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED))
>   #define pgprot_mhp     pgprot_tagged
> +
> +#define pgprot_decrypted(prot) __pgprot_modify(prot, PROT_NS_SHARED, PROT_NS_SHARED)
> +#define pgprot_encrypted(prot)  __pgprot_modify(prot, PROT_NS_SHARED, 0)
> +
> 

Yes, looks right to me.

Michael
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 11d614d83317..c986fde262c0 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -644,7 +644,7 @@  static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
 #define pgprot_writecombine(prot) \
 	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
 #define pgprot_device(prot) \
-	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN)
+	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN | PROT_NS_SHARED)
 #define pgprot_tagged(prot) \
 	__pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED))
 #define pgprot_mhp	pgprot_tagged