Re: [PATCH v2 22/37] arm64: mte: Add in-kernel MTE helpers
From: Vincenzo Frascino
Date: Thu Sep 17 2020 - 15:42:50 EST
On 9/17/20 2:46 PM, Catalin Marinas wrote:
>> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
>> index 52a0638ed967..e238ffde2679 100644
>> --- a/arch/arm64/kernel/mte.c
>> +++ b/arch/arm64/kernel/mte.c
>> @@ -72,6 +74,52 @@ int memcmp_pages(struct page *page1, struct page *page2)
>> return ret;
>> }
>>
>> +u8 mte_get_mem_tag(void *addr)
>> +{
>> + if (system_supports_mte())
>> + asm volatile(ALTERNATIVE("ldr %0, [%0]",
>> + __MTE_PREAMBLE "ldg %0, [%0]",
>> + ARM64_MTE)
>> + : "+r" (addr));
> This doesn't do what you think it does. LDG indeed reads the tag from
> memory but LDR loads the actual data at that address. Instead of the
> first LDR, you may want something like "mov %0, #0xf << 56" (and use
> some macros to avoid the hard-coded 56).
>
Seems I can't encode a shift of 56 neither in mov nor in orr. I propose to
replace both with an and of the address with itself.
This should not change anything.
Thoughts?
>> +
>> + return 0xF0 | mte_get_ptr_tag(addr);
>> +}
>> +
>> +u8 mte_get_random_tag(void)
>> +{
>> + u8 tag = 0xF;
>> + u64 addr = 0;
>> +
>> + if (system_supports_mte()) {
>> + asm volatile(ALTERNATIVE("add %0, %0, %0",
>> + __MTE_PREAMBLE "irg %0, %0",
>> + ARM64_MTE)
>> + : "+r" (addr));
> What was the intention here? The first ADD doubles the pointer value and
> gets a tag out of it (possibly doubled as well, depends on the carry
> from bit 55). Better use something like "orr %0, %0, #0xf << 56".
>
--
Regards,
Vincenzo