arm64: fix paging issues
cover arm64: fix paging issues
From: Nadav Amit <[email protected]>
Two more arm64 fixes, besides the vtimer ISTATUS fix that I recently sent.
The first patch fixes an actual issue I encountered on my setup and caused tests to crash.
The second fix is a theoretical one, which I found while reading the code.
Nadav Amit (2):
arm64: set sctlr_el1.SPAN
arm64: ensure tlbi is safe
arm/cstart64.S | 1 + lib/arm64/asm/mmu.h | 4 ++-- lib/arm64/asm/sysreg.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 arm64: set sctlr_el1.SPAN
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
Without setting sctlr_el1.SPAN, tests crash when they access the memory after an exception.
--- arm/cstart64.S | 1 + lib/arm64/asm/sysreg.h | 1 + 2 files changed, 2 insertions(+)
arm/cstart64.S +1 -0
@@ -245,6 +245,7 @@ asm_mmu_enable: orr x1, x1, SCTLR_EL1_C orr x1, x1, SCTLR_EL1_I orr x1, x1, SCTLR_EL1_M + orr x1, x1, SCTLR_EL1_SPAN msr sctlr_el1, x1 isb
lib/arm64/asm/sysreg.h +1 -0
@@ -81,6 +81,7 @@ asm(/* System Control Register (SCTLR_EL1) bits */ #define SCTLR_EL1_EE (1 << 25) +#define SCTLR_EL1_SPAN (1 << 23)#define SCTLR_EL1_WXN (1 << 19)#define SCTLR_EL1_I (1 << 12)#define SCTLR_EL1_SA0 (1 << 4)
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Quoted 10 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
Without setting sctlr_el1.SPAN, tests crash when they access the memory after an exception.
Andrew,
You’ve been kind enough to review the other patch-set and perhaps this one fell through the cracks. Can you please have a look at this one specifically and on:
https://lore.kernel.org/all/[email protected]/
These issues cause problem on other environments.
Thanks,
Nadav
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
In reply to Nadav AmitQuoted 43 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
Without setting sctlr_el1.SPAN, tests crash when they access the memory after an exception.
Signed-off-by Nadav Amit <[email protected]>---
arm/cstart64.S| 1 +lib/arm64/asm/sysreg.h| 1 +2 files changed, 2 insertions(+)arm/cstart64.S +1
-0@@ -245,6 +245,7 @@ asm_mmu_enable: orr x1, x1, SCTLR_EL1_C orr x1, x1, SCTLR_EL1_I orr x1, x1, SCTLR_EL1_M + orr x1, x1, SCTLR_EL1_SPAN msr sctlr_el1, x1 isblib/arm64/asm/sysreg.h +1
-0@@ -81,6 +81,7 @@ asm(/* System Control Register (SCTLR_EL1) bits */ #define SCTLR_EL1_EE (1 << 25) +#define SCTLR_EL1_SPAN (1 << 23)#define SCTLR_EL1_WXN (1 << 19)#define SCTLR_EL1_I (1 << 12)#define SCTLR_EL1_SA0 (1 << 4)Signature · 1 line
2.34.1
Ping? (this one specifically is an issue)
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
In reply to Nadav AmitHi,
Quoted 3 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
In arm/cstart64.S
.globl start
start:
/* get our base address */ [..]
1:
/* zero BSS */
[..]
/* zero and set up stack */
[..]
/* set SCTLR_EL1 to a known value */
ldr x4, =INIT_SCTLR_EL1_MMU_OFF
[..]
/* set up exception handling */
bl exceptions_init
[..]Where in lib/arm64/asm/sysreg.h:
#define SCTLR_EL1_RES1 (_BITUL(7) | _BITUL(8) | _BITUL(11) | _BITUL(20) | \
_BITUL(22) | _BITUL(23) | _BITUL(28) | _BITUL(29))
#define INIT_SCTLR_EL1_MMU_OFF \
SCTLR_EL1_RES1Look like bit 23 (SPAN) should be set.
How are you seeing SCTLR_EL1.SPAN unset?
Thanks,
Alex
Quoted 38 lines
Without setting sctlr_el1.SPAN, tests crash when they access the memory after an exception.
Signed-off-by Nadav Amit <[email protected]>--- arm/cstart64.S | 1 + lib/arm64/asm/sysreg.h | 1 + 2 files changed, 2 insertions(+)arm/cstart64.S +1
-0@@ -245,6 +245,7 @@ asm_mmu_enable: orr x1, x1, SCTLR_EL1_C orr x1, x1, SCTLR_EL1_I orr x1, x1, SCTLR_EL1_M + orr x1, x1, SCTLR_EL1_SPAN msr sctlr_el1, x1 isblib/arm64/asm/sysreg.h +1
-0@@ -81,6 +81,7 @@ asm(/* System Control Register (SCTLR_EL1) bits */ #define SCTLR_EL1_EE (1 << 25) +#define SCTLR_EL1_SPAN (1 << 23)#define SCTLR_EL1_WXN (1 << 19)#define SCTLR_EL1_I (1 << 12)#define SCTLR_EL1_SA0 (1 << 4)Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Hi,
Quoted 31 lines · Alexandru Elisei
Hi,
Quoted 3 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
In
arm/cstart64.S.globl start
start:/* get our base address */ [..]1:
/* zero BSS */ [..] /* zero and set up stack */ [..] /* set SCTLR_EL1 to a known value */ ldr x4, =INIT_SCTLR_EL1_MMU_OFF [..] /* set up exception handling */ bl exceptions_init [..]Where in
lib/arm64/asm/sysreg.h:
Quoted 8 lines
#define SCTLR_EL1_RES1 (_BITUL(7) | _BITUL(8) | _BITUL(11) | _BITUL(20) | \ _BITUL(22) | _BITUL(23) | _BITUL(28) | _BITUL(29)) #define INIT_SCTLR_EL1_MMU_OFF \ SCTLR_EL1_RES1Look like bit 23 (SPAN) should be set.
How are you seeing SCTLR_EL1.SPAN unset?
Yeah. the sctlr_el1.SPAN has always been set by the above flow. So Nadav you can describe what you encounter with more details. Like which tests crash you encounter, and how to reproduce it.
Thanks,
Shaoqin
Quoted 43 lines
Thanks,
AlexQuoted 38 lines
Without setting sctlr_el1.SPAN, tests crash when they access the memory after an exception.
Signed-off-by Nadav Amit <[email protected]>--- arm/cstart64.S | 1 + lib/arm64/asm/sysreg.h | 1 + 2 files changed, 2 insertions(+)arm/cstart64.S +1
-0@@ -245,6 +245,7 @@ asm_mmu_enable: orr x1, x1, SCTLR_EL1_C orr x1, x1, SCTLR_EL1_I orr x1, x1, SCTLR_EL1_M + orr x1, x1, SCTLR_EL1_SPAN msr sctlr_el1, x1 isblib/arm64/asm/sysreg.h +1
-0@@ -81,6 +81,7 @@ asm(/* System Control Register (SCTLR_EL1) bits */ #define SCTLR_EL1_EE (1 << 25) +#define SCTLR_EL1_SPAN (1 << 23)#define SCTLR_EL1_WXN (1 << 19)#define SCTLR_EL1_I (1 << 12)#define SCTLR_EL1_SA0 (1 << 4)Signature · 1 line
2.34.1
Signature · 1 line
Shaoqin
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Quoted 45 lines · Shaoqin Huang
!! External Email
Hi,
Quoted 36 lines · Alexandru Elisei
Hi,
Quoted 3 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
In
arm/cstart64.S.globl start
start:/* get our base address */ [..]1:
/* zero BSS */ [..] /* zero and set up stack */ [..] /* set SCTLR_EL1 to a known value */ ldr x4, =INIT_SCTLR_EL1_MMU_OFF [..] /* set up exception handling */ bl exceptions_init [..]Where in
lib/arm64/asm/sysreg.h:#define SCTLR_EL1_RES1 (_BITUL(7) | _BITUL(8) | _BITUL(11) | _BITUL(20) | \ _BITUL(22) | _BITUL(23) | _BITUL(28) | _BITUL(29)) #define INIT_SCTLR_EL1_MMU_OFF \ SCTLR_EL1_RES1
Quoted 7 lines
Quoted 3 lines
Look like bit 23 (SPAN) should be set.
How are you seeing SCTLR_EL1.SPAN unset?
Yeah. the sctlr_el1.SPAN has always been set by the above flow. So Nadav you can describe what you encounter with more details. Like which tests crash you encounter, and how to reproduce it.
I am using Nikos’s work to run the test using EFI, not from QEMU.
So the code that you mentioned - which is supposed to initialize SCTLR - is not executed (and actually not part of the EFI image).
Note that using EFI, the entry point is _start [1], and not “start”.
That is also the reason lack of BSS zeroing also caused me issues with the EFI setup, which I reported before.
[1] https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/blob/master/arm/efi/crt0-efi-aarch64.S#L113
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Quoted 55 lines · Nadav Amit
Quoted 45 lines · Shaoqin Huang
!! External Email
Hi,
Quoted 36 lines · Alexandru Elisei
Hi,
Quoted 3 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
In
arm/cstart64.S.globl start
start:/* get our base address */ [..]1:
/* zero BSS */ [..] /* zero and set up stack */ [..] /* set SCTLR_EL1 to a known value */ ldr x4, =INIT_SCTLR_EL1_MMU_OFF [..] /* set up exception handling */ bl exceptions_init [..]Where in
lib/arm64/asm/sysreg.h:#define SCTLR_EL1_RES1 (_BITUL(7) | _BITUL(8) | _BITUL(11) | _BITUL(20) | \ _BITUL(22) | _BITUL(23) | _BITUL(28) | _BITUL(29)) #define INIT_SCTLR_EL1_MMU_OFF \ SCTLR_EL1_RES1Quoted 7 lines
Quoted 3 lines
Look like bit 23 (SPAN) should be set.
How are you seeing SCTLR_EL1.SPAN unset?
Yeah. the sctlr_el1.SPAN has always been set by the above flow. So Nadav you can describe what you encounter with more details. Like which tests crash you encounter, and how to reproduce it.
I am using Nikos’s work to run the test using EFI, not from QEMU.
Quoted 7 lines
So the code that you mentioned - which is supposed to initialize SCTLR - is not executed (and actually not part of the EFI image).
Note that using EFI, the entry point is
_start[1], and not “start”.That is also the reason lack of BSS zeroing also caused me issues with the EFI setup, which I reported before.
Nadav,
Would you mind reposting this along with the BSS zeroing patch, the way I proposed we do that, and anything else you've discovered when trying to use the EFI unit tests without QEMU? We'll call that our first non-QEMU EFI support series, since the first EFI series was only targeting QEMU.
Thanks,
drew
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Quoted 64 lines · Andrew Jones
Quoted 55 lines · Nadav Amit
Quoted 45 lines · Shaoqin Huang
!! External Email
Hi,
Quoted 36 lines · Alexandru Elisei
Hi,
Quoted 3 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
In
arm/cstart64.S.globl start
start:/* get our base address */ [..]1:
/* zero BSS */ [..] /* zero and set up stack */ [..] /* set SCTLR_EL1 to a known value */ ldr x4, =INIT_SCTLR_EL1_MMU_OFF [..] /* set up exception handling */ bl exceptions_init [..]Where in
lib/arm64/asm/sysreg.h:#define SCTLR_EL1_RES1 (_BITUL(7) | _BITUL(8) | _BITUL(11) | _BITUL(20) | \ _BITUL(22) | _BITUL(23) | _BITUL(28) | _BITUL(29)) #define INIT_SCTLR_EL1_MMU_OFF \ SCTLR_EL1_RES1Quoted 7 lines
Quoted 3 lines
Look like bit 23 (SPAN) should be set.
How are you seeing SCTLR_EL1.SPAN unset?
Yeah. the sctlr_el1.SPAN has always been set by the above flow. So Nadav you can describe what you encounter with more details. Like which tests crash you encounter, and how to reproduce it.
I am using Nikos’s work to run the test using EFI, not from QEMU.
Quoted 7 lines
So the code that you mentioned - which is supposed to initialize SCTLR - is not executed (and actually not part of the EFI image).
Note that using EFI, the entry point is
_start[1], and not “start”.That is also the reason lack of BSS zeroing also caused me issues with the EFI setup, which I reported before.
Quoted 7 lines
Nadav,
Would you mind reposting this along with the BSS zeroing patch, the way I proposed we do that, and anything else you've discovered when trying to use the EFI unit tests without QEMU? We'll call that our first non-QEMU EFI support series, since the first EFI series was only targeting QEMU.
Oh, and I meant to mention that, when reposting this patch, maybe we can consider managing sctlr in a similar way to the non-efi start path?
Thanks,
drew
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Quoted 67 lines · Andrew Jones
Quoted 66 lines · Andrew Jones
Quoted 55 lines · Nadav Amit
Quoted 45 lines · Shaoqin Huang
!! External Email
Hi,
Quoted 36 lines · Alexandru Elisei
Hi,
Quoted 3 lines · Nadav Amit
From: Nadav Amit <[email protected]>
Do not assume PAN is not supported or that sctlr_el1.SPAN is already set.
In
arm/cstart64.S.globl start
start:/* get our base address */ [..]1:
/* zero BSS */ [..] /* zero and set up stack */ [..] /* set SCTLR_EL1 to a known value */ ldr x4, =INIT_SCTLR_EL1_MMU_OFF [..] /* set up exception handling */ bl exceptions_init [..]Where in
lib/arm64/asm/sysreg.h:#define SCTLR_EL1_RES1 (_BITUL(7) | _BITUL(8) | _BITUL(11) | _BITUL(20) | \ _BITUL(22) | _BITUL(23) | _BITUL(28) | _BITUL(29)) #define INIT_SCTLR_EL1_MMU_OFF \ SCTLR_EL1_RES1Quoted 7 lines
Quoted 3 lines
Look like bit 23 (SPAN) should be set.
How are you seeing SCTLR_EL1.SPAN unset?
Yeah. the sctlr_el1.SPAN has always been set by the above flow. So Nadav you can describe what you encounter with more details. Like which tests crash you encounter, and how to reproduce it.
I am using Nikos’s work to run the test using EFI, not from QEMU.
Quoted 7 lines
So the code that you mentioned - which is supposed to initialize SCTLR - is not executed (and actually not part of the EFI image).
Note that using EFI, the entry point is
_start[1], and not “start”.That is also the reason lack of BSS zeroing also caused me issues with the EFI setup, which I reported before.
Nadav,
Quoted 9 lines
Quoted 5 lines
Would you mind reposting this along with the BSS zeroing patch, the way I proposed we do that, and anything else you've discovered when trying to use the EFI unit tests without QEMU? We'll call that our first non-QEMU EFI support series, since the first EFI series was only targeting QEMU.
Oh, and I meant to mention that, when reposting this patch, maybe we can consider managing sctlr in a similar way to the non-efi start path?
Nadav, if you are running baremetal, it might be worth checking what EL you're running in as well. If HW is implementing EL2, EFI will handover in EL2.
I was planning to rebase an old patch (more like rewrite it) but I haven't found the time yet [1]. If I remember correctly, we have to check what EL we're running in and if it's EL2 we have to add a stub EL2, drop to EL1 and setup EL1. But things have change since that patch and with the new structure, I am not sure if we would drop to EL1 right at the start (crt0-efi-aarch64.S) or somewhere in setup_efi().
In general, I think, it would be easier to deal with this in QEMU (-machine secure=on) and before we even start thinking about real hardware where it is very likely that we will have to address other issues (such as the problem with the BSS, cache maintenance) as well.
[1]: https://github.com/relokin/kvm-unit-tests/commit/1468abeee7be1d85140ed92cb91a42ee27a9bf1f
Thanks,
Nikos
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Combining the answers to Andrew and Nikos.
Quoted 7 lines · Nikos Nikoleris
Quoted 7 lines
Quoted 7 lines
Would you mind reposting this along with the BSS zeroing patch, the way I proposed we do that, and anything else you've discovered when trying to use the EFI unit tests without QEMU? We'll call that our first non-QEMU EFI support series, since the first EFI series was only targeting QEMU.
I need to rehash the solution that you proposed for BSS (if there is anything special there). I had a different workaround for that issue, because IIRC I had some issues with the zeroing. I’ll give it another
Quoted 4 lines
Quoted 4 lines
Oh, and I meant to mention that, when reposting this patch, maybe we can consider managing sctlr in a similar way to the non-efi start path?
I am afraid of turning on random bits on SCTLR. Arguably, the way that the non-efi test sets the default value of SCTLR (with no naming of the different bits) is not very friendly.
I will have a look on the other bits of SCTLR and see if I can do something quick and simple, but I don’t want to refactor things in a way that might break things.
Quoted 4 lines
Nadav, if you are running baremetal, it might be worth checking what EL you're running in as well. If HW is implementing EL2, EFI will handover in EL2.
I don’t. I run the test on a different hypervisor. When I enabled the x86 tests to run on a different hypervisor years ago, there were many many test and real issues that required me to run KVM-unit-tests on bare metal - and therefore I fixed these tests to run on bare-metal as well.
With ARM, excluding the BSS and the SCTLR issue, I didn’t encounter any additional test issues. So I don’t have the need or time to enable it to run on bare-metal… sorry.
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Hi,
Quoted 16 lines · Nadav Amit
Combining the answers to Andrew and Nikos.
Quoted 7 lines · Nikos Nikoleris
Quoted 7 lines
Quoted 7 lines
Would you mind reposting this along with the BSS zeroing patch, the way I proposed we do that, and anything else you've discovered when trying to use the EFI unit tests without QEMU? We'll call that our first non-QEMU EFI support series, since the first EFI series was only targeting QEMU.
I need to rehash the solution that you proposed for BSS (if there is anything special there). I had a different workaround for that issue, because IIRC I had some issues with the zeroing. I’ll give it another
Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Oh, and I meant to mention that, when reposting this patch, maybe we can consider managing sctlr in a similar way to the non-efi start path?
I am afraid of turning on random bits on SCTLR. Arguably, the way that
What do you mean by turning on random bits on SCTLR? All the functional bits are documented in the architecture. Same goes for RES1 (it's in the Glossary).
Quoted 2 lines
the non-efi test sets the default value of SCTLR (with no naming of the different bits) is not very friendly.
That's because as the architecture gets updated, what used to be a RES1 bit becomes a functional bit. The only sane way to handle this is to disable all the features you don't support, **and** set all the RES1 bits (and clear RES0 bits), to disable any newly introduced features you don't know about yet which were left enabled by software running at a higher privilege level.
You can send a patch if you want to give a name to the bits which have become functional since SCTLR_EL1_RES1 was introduced.
Thanks,
Alex
Quoted 19 lines
I will have a look on the other bits of SCTLR and see if I can do something quick and simple, but I don’t want to refactor things in a way that might break things.
Quoted 4 lines
Nadav, if you are running baremetal, it might be worth checking what EL you're running in as well. If HW is implementing EL2, EFI will handover in EL2.
I don’t. I run the test on a different hypervisor. When I enabled the x86 tests to run on a different hypervisor years ago, there were many many test and real issues that required me to run KVM-unit-tests on bare metal - and therefore I fixed these tests to run on bare-metal as well.
With ARM, excluding the BSS and the SCTLR issue, I didn’t encounter any additional test issues. So I don’t have the need or time to enable it to run on bare-metal… sorry.
Re: [kvm-unit-tests PATCH 1/2] arm64: set sctlr_el1.SPAN
Quoted 43 lines · Alexandru Elisei
Hi,
Quoted 16 lines · Nadav Amit
Combining the answers to Andrew and Nikos.
Quoted 7 lines · Nikos Nikoleris
Quoted 7 lines
Quoted 7 lines
Would you mind reposting this along with the BSS zeroing patch, the way I proposed we do that, and anything else you've discovered when trying to use the EFI unit tests without QEMU? We'll call that our first non-QEMU EFI support series, since the first EFI series was only targeting QEMU.
I need to rehash the solution that you proposed for BSS (if there is anything special there). I had a different workaround for that issue, because IIRC I had some issues with the zeroing. I’ll give it another
Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Oh, and I meant to mention that, when reposting this patch, maybe we can consider managing sctlr in a similar way to the non-efi start path?
I am afraid of turning on random bits on SCTLR. Arguably, the way that
What do you mean by turning on random bits on SCTLR? All the functional bits are documented in the architecture. Same goes for RES1 (it's in the Glossary).
Quoted 2 lines
the non-efi test sets the default value of SCTLR (with no naming of the different bits) is not very friendly.
That's because as the architecture gets updated, what used to be a RES1 bit becomes a functional bit. The only sane way to handle this is to disable all the features you don't support, **and** set all the RES1 bits (and clear RES0 bits), to disable any newly introduced features you don't know about yet which were left enabled by software running at a higher privilege level.
Quoted 2 lines
You can send a patch if you want to give a name to the bits which have become functional since
SCTLR_EL1_RES1was introduced.
I can give it a quick shot, but I do need to clarify something. Although I have rather deep knowledge of x86 architecture with over 20 years of experience, my experience with ARM is limited to 2 weeks. And I don’t even have an environment in which I can run KVM+ARM.
So I am not inclined to revamp code that was actually just added to kvm-unit-tests. I will attempt to refactor the code to solve both the BSS and SCTLR issues in EFI under these limitations.
PATCH 2/2 arm64: ensure tlbi is safe
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
While no real problem was encountered, having an inline assembly without volatile keyword and output can allow the compiler to ignore it. And without a memory clobber, potentially reorder it.
Add volatile and memory clobber.
--- lib/arm64/asm/mmu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/arm64/asm/mmu.h +2 -2
@@ -14,7 +14,7 @@static inline void flush_tlb_all (void ) {dsb (ishst); - asm("tlbi vmalle1is" ); + asmvolatile ("tlbi vmalle1is" :::"memory" );dsb (ish);isb (); }
@@ -23,7 +23,7 @@ static inline void flush_tlb_page(unsigned long vaddr) {unsigned long page = vaddr >>12 ;dsb (ishst); - asm("tlbi vaae1is, %0" ::"r" (page)); + asmvolatile ("tlbi vaae1is, %0" ::"r" (page) :"memory" );dsb (ish);isb (); }
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH 2/2] arm64: ensure tlbi is safe
Hi,
Quoted 18 lines · Nadav Amit
From: Nadav Amit <[email protected]>
While no real problem was encountered, having an inline assembly without volatile keyword and output can allow the compiler to ignore it. And without a memory clobber, potentially reorder it.
Add volatile and memory clobber.
Signed-off-by Nadav Amit <[email protected]>--- lib/arm64/asm/mmu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/arm64/asm/mmu.h +0
-0
lib/arm64/asm/mmu.h line 17
Quoted 4 lines
lib/arm64/asm/mmu.h +0
-1@@ -14,7 +14,7 @@static inline void flush_tlb_all (void ) {dsb (ishst); - asm("tlbi vmalle1is" );
From the gas manual [1]:
"asm statements that have no output operands and asm goto statements, are implicitly volatile."
Looks to me like both TLBIs fall into this category.
And I think the "memory" clobber is not needed because the dsb macro before and after the TLBI already have it.
[1] https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
Thanks,
Alex
Quoted 17 lines
lib/arm64/asm/mmu.h +2
-1+ asmvolatile ("tlbi vmalle1is" :::"memory" );dsb (ish);isb (); }@@ -23,7 +23,7 @@ static inline void flush_tlb_page(unsigned long vaddr) {unsigned long page = vaddr >>12 ;dsb (ishst); - asm("tlbi vaae1is, %0" ::"r" (page)); + asmvolatile ("tlbi vaae1is, %0" ::"r" (page) :"memory" );dsb (ish);isb (); }Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH 2/2] arm64: ensure tlbi is safe
Quoted 34 lines · Alexandru Elisei
!! External Email
Hi,
Quoted 18 lines · Nadav Amit
From: Nadav Amit <[email protected]>
While no real problem was encountered, having an inline assembly without volatile keyword and output can allow the compiler to ignore it. And without a memory clobber, potentially reorder it.
Add volatile and memory clobber.
Signed-off-by Nadav Amit <[email protected]>---
lib/arm64/asm/mmu.h| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)lib/arm64/asm/mmu.h +0
-0lib/arm64/asm/mmu.h line 17
Quoted 4 lines
lib/arm64/asm/mmu.h +0
-1@@ -14,7 +14,7 @@static inline void flush_tlb_all (void ) {dsb (ishst); - asm("tlbi vmalle1is" );From the gas manual [1]:
Quoted 7 lines
"asm statements that have no output operands and asm goto statements, are implicitly volatile."
Looks to me like both TLBIs fall into this category.
And I think the "memory" clobber is not needed because the dsb macro before and after the TLBI already have it.
You are completely correct. I forgot about the implicit “volatile”.
This one can be dropped.