diff mbox series

[v5,11/19] arm64: rsi: Map unprotected MMIO as decrypted

Message ID 20240819131924.372366-12-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 Aug. 19, 2024, 1:19 p.m. UTC
From: Suzuki K Poulose <suzuki.poulose@arm.com>

Instead of marking every MMIO as shared, check if the given region is
"Protected" and apply the permissions accordingly.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
---
New patch for v5
---
 arch/arm64/kernel/rsi.c | 15 +++++++++++++++
 arch/arm64/mm/mmu.c     |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Suzuki K Poulose Aug. 19, 2024, 2:11 p.m. UTC | #1
Hi Steven

On 19/08/2024 14:19, Steven Price wrote:
> From: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> Instead of marking every MMIO as shared, check if the given region is
> "Protected" and apply the permissions accordingly.
> 
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> Signed-off-by: Steven Price <steven.price@arm.com>
> ---
> New patch for v5
> ---
>   arch/arm64/kernel/rsi.c | 15 +++++++++++++++
>   arch/arm64/mm/mmu.c     |  2 +-
>   2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c
> index 381a5b9a5333..672dd6862298 100644
> --- a/arch/arm64/kernel/rsi.c
> +++ b/arch/arm64/kernel/rsi.c
> @@ -6,6 +6,8 @@
>   #include <linux/jump_label.h>
>   #include <linux/memblock.h>
>   #include <linux/psci.h>
> +
> +#include <asm/io.h>
>   #include <asm/rsi.h>
>   
>   struct realm_config config;
> @@ -93,6 +95,16 @@ bool arm64_rsi_is_protected_mmio(phys_addr_t base, size_t size)
>   }
>   EXPORT_SYMBOL(arm64_rsi_is_protected_mmio);
>   
> +static int realm_ioremap_hook(phys_addr_t phys, size_t size, pgprot_t *prot)
> +{
> +	if (arm64_rsi_is_protected_mmio(phys, size))
> +		*prot = pgprot_encrypted(*prot);
> +	else
> +		*prot = pgprot_decrypted(*prot);
> +
> +	return 0;
> +}
> +
>   void __init arm64_rsi_init(void)
>   {
>   	/*
> @@ -107,6 +119,9 @@ void __init arm64_rsi_init(void)
>   		return;
>   	prot_ns_shared = BIT(config.ipa_bits - 1);
>   
> +	if (arm64_ioremap_prot_hook_register(realm_ioremap_hook))
> +		return;
> +
>   	static_branch_enable(&rsi_present);
>   }
>   
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 06b66c23c124..0c2fa35beca0 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -1207,7 +1207,7 @@ void set_fixmap_io(enum fixed_addresses idx, phys_addr_t phys)
>   	else
>   		prot = pgprot_encrypted(prot);
>   
> -	__set_fixmap(idx, phys, prot);
> +	__set_fixmap(idx, phys & PAGE_MASK, prot);

This looks like it should be part of the previous patch ? Otherwise 
looks good to me.

Suzuki
Steven Price Aug. 30, 2024, 3:54 p.m. UTC | #2
On 19/08/2024 15:11, Suzuki K Poulose wrote:
> Hi Steven
> 
> On 19/08/2024 14:19, Steven Price wrote:
>> From: Suzuki K Poulose <suzuki.poulose@arm.com>
>>
>> Instead of marking every MMIO as shared, check if the given region is
>> "Protected" and apply the permissions accordingly.
>>
>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
>> Signed-off-by: Steven Price <steven.price@arm.com>
>> ---
>> New patch for v5
>> ---
>>   arch/arm64/kernel/rsi.c | 15 +++++++++++++++
>>   arch/arm64/mm/mmu.c     |  2 +-
>>   2 files changed, 16 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c
>> index 381a5b9a5333..672dd6862298 100644
>> --- a/arch/arm64/kernel/rsi.c
>> +++ b/arch/arm64/kernel/rsi.c
>> @@ -6,6 +6,8 @@
>>   #include <linux/jump_label.h>
>>   #include <linux/memblock.h>
>>   #include <linux/psci.h>
>> +
>> +#include <asm/io.h>
>>   #include <asm/rsi.h>
>>     struct realm_config config;
>> @@ -93,6 +95,16 @@ bool arm64_rsi_is_protected_mmio(phys_addr_t base,
>> size_t size)
>>   }
>>   EXPORT_SYMBOL(arm64_rsi_is_protected_mmio);
>>   +static int realm_ioremap_hook(phys_addr_t phys, size_t size,
>> pgprot_t *prot)
>> +{
>> +    if (arm64_rsi_is_protected_mmio(phys, size))
>> +        *prot = pgprot_encrypted(*prot);
>> +    else
>> +        *prot = pgprot_decrypted(*prot);
>> +
>> +    return 0;
>> +}
>> +
>>   void __init arm64_rsi_init(void)
>>   {
>>       /*
>> @@ -107,6 +119,9 @@ void __init arm64_rsi_init(void)
>>           return;
>>       prot_ns_shared = BIT(config.ipa_bits - 1);
>>   +    if (arm64_ioremap_prot_hook_register(realm_ioremap_hook))
>> +        return;
>> +
>>       static_branch_enable(&rsi_present);
>>   }
>>   diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>> index 06b66c23c124..0c2fa35beca0 100644
>> --- a/arch/arm64/mm/mmu.c
>> +++ b/arch/arm64/mm/mmu.c
>> @@ -1207,7 +1207,7 @@ void set_fixmap_io(enum fixed_addresses idx,
>> phys_addr_t phys)
>>       else
>>           prot = pgprot_encrypted(prot);
>>   -    __set_fixmap(idx, phys, prot);
>> +    __set_fixmap(idx, phys & PAGE_MASK, prot);
> 
> This looks like it should be part of the previous patch ? Otherwise
> looks good to me.

Good spot - yes it should!

Thanks,
Steve
diff mbox series

Patch

diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c
index 381a5b9a5333..672dd6862298 100644
--- a/arch/arm64/kernel/rsi.c
+++ b/arch/arm64/kernel/rsi.c
@@ -6,6 +6,8 @@ 
 #include <linux/jump_label.h>
 #include <linux/memblock.h>
 #include <linux/psci.h>
+
+#include <asm/io.h>
 #include <asm/rsi.h>
 
 struct realm_config config;
@@ -93,6 +95,16 @@  bool arm64_rsi_is_protected_mmio(phys_addr_t base, size_t size)
 }
 EXPORT_SYMBOL(arm64_rsi_is_protected_mmio);
 
+static int realm_ioremap_hook(phys_addr_t phys, size_t size, pgprot_t *prot)
+{
+	if (arm64_rsi_is_protected_mmio(phys, size))
+		*prot = pgprot_encrypted(*prot);
+	else
+		*prot = pgprot_decrypted(*prot);
+
+	return 0;
+}
+
 void __init arm64_rsi_init(void)
 {
 	/*
@@ -107,6 +119,9 @@  void __init arm64_rsi_init(void)
 		return;
 	prot_ns_shared = BIT(config.ipa_bits - 1);
 
+	if (arm64_ioremap_prot_hook_register(realm_ioremap_hook))
+		return;
+
 	static_branch_enable(&rsi_present);
 }
 
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 06b66c23c124..0c2fa35beca0 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1207,7 +1207,7 @@  void set_fixmap_io(enum fixed_addresses idx, phys_addr_t phys)
 	else
 		prot = pgprot_encrypted(prot);
 
-	__set_fixmap(idx, phys, prot);
+	__set_fixmap(idx, phys & PAGE_MASK, prot);
 }
 
 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)