x86/sgx: use vm_flags_t for vm_prot_bits
Subsystems (3)
PATCH v2 1/1 x86/sgx: use vm_flags_t for vm_prot_bits
The vm_flags_t type is the dedicated type for virtual memory flags. Architecture and driver code should use this type instead of assuming vm_flags is an unsigned long, as the underlying type may change in the future.
This follows the cleanup in commit d75fa3c94750 ("mm: update architecture and driver code to use vm_flags_t") by converting the remaining vm_prot_bits usage in SGX code. Also, update the vm_max_prot_bits type in struct sgx_encl_page to vm_flags_t for consistency.
No functional change intended.
---
v2:
- Also convert the type of vm_max_prot_bits in struct sgx_encl_page to vm_flags_t, as suggested.
arch/x86/kernel/cpu/sgx/encl.c | 2 +- arch/x86/kernel/cpu/sgx/encl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/encl.c +1 -1
@@ -281,7 +281,7 @@ static struct sgx_encl_page *sgx_encl_load_page_in_vma(struct sgx_encl *encl, unsigned long addr, vm_flags_t vm_flags) { -unsigned long vm_prot_bits = vm_flags &VM_ACCESS_FLAGS ; +vm_flags_t vm_prot_bits = vm_flags &VM_ACCESS_FLAGS ;struct sgx_encl_page *entry; entry =xa_load (&encl->page_array,PFN_DOWN (addr));
arch/x86/kernel/cpu/sgx/encl.h +1 -1
@@ -27,7 +27,7 @@struct sgx_encl_page {unsigned long desc; -unsigned long vm_max_prot_bits:8 ; +vm_flags_t vm_max_prot_bits:8 ;enum sgx_page_type type:16 ;struct sgx_epc_page *epc_page;struct sgx_encl *encl;
Signature · 1 line
2.34.1
Quoted 10 lines · Wentong Tian
The
vm_flags_ttype is the dedicated type for virtual memory flags. Architecture and driver code should use this type instead of assumingvm_flagsis an unsigned long, as the underlying type may change in the future.This follows the cleanup in commit
d75fa3c94750("mm: update architecture and driver code to usevm_flags_t") by converting the remainingvm_prot_bitsusage in SGX code. Also, update thevm_max_prot_bitstype in structsgx_encl_pagetovm_flags_tfor consistency.
Quoted 7 lines
No functional change intended.
Signed-off-by Wentong Tian <[email protected]>---
v2:
- Also convert the type ofvm_max_prot_bitsin structsgx_encl_pagetovm_flags_t, as suggested.
Hmm I was actually just pointing out, but not suggesting, since I am not sure (honestly).
Back to technical:
Gcc doc says:
A structure field declaration with an integer type can specify the number of bits the field should occupy. We call that a bit field.
With vm_flags_t I think "theoretically" it could stop being integer type someday. But I guess the advantage is when someone does that that can trigger build error here (so that we can be aware) which perhaps isn't a bad thing?
Sorry about that, I'll make sure to reply to the list.
Quoted 2 lines · Kai
Hmm I was actually just pointing out, but not suggesting, since I am not sure (honestly).
Sorry for the misunderstanding.
Quoted 4 lines
With
vm_flags_tI think "theoretically" it could stop being integer type someday. But I guess the advantage is when someone does that that can trigger build error here (so that we can be aware) which perhaps isn't a bad thing?
You're right, the build error would be a useful early warning if vm_flags_t ever becomes incompatible. I'm fine either way, let me know if you'd prefer keeping
unsigned long and I'll send a v3.
Huang, Kai
Acked-byQuoted 8 lines
Quoted 5 lines
With
vm_flags_tI think "theoretically" it could stop being integer type someday. But I guess the advantage is when someone does that that can trigger build error here (so that we can be aware) which perhaps isn't a bad thing?You're right, the build error would be a useful early warning if
vm_flags_tever becomes incompatible.
Agreed. It's what type safety means IMHO.
Quoted 3 lines
I'm fine either way, let me know
if you'd prefer keeping
unsigned long and I'll send a v3.
It's up to maintainer(s), but v2 makes sense to me, so:
Quoted 40 lines · Wentong Tian
The
vm_flags_ttype is the dedicated type for virtual memory flags. Architecture and driver code should use this type instead of assumingvm_flagsis an unsigned long, as the underlying type may change in the future.This follows the cleanup in commit
d75fa3c94750("mm: update architecture and driver code to usevm_flags_t") by converting the remainingvm_prot_bitsusage in SGX code. Also, update thevm_max_prot_bitstype in structsgx_encl_pagetovm_flags_tfor consistency.No functional change intended.
Signed-off-by Wentong Tian <[email protected]>---
v2:
- Also convert the type ofvm_max_prot_bitsin structsgx_encl_pagetovm_flags_t, as suggested.arch/x86/kernel/cpu/sgx/encl.c | 2 +- arch/x86/kernel/cpu/sgx/encl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/sgx/encl.c +1
-1@@ -281,7 +281,7 @@ static struct sgx_encl_page *sgx_encl_load_page_in_vma(struct sgx_encl *encl, unsigned long addr, vm_flags_t vm_flags) { -unsigned long vm_prot_bits = vm_flags &VM_ACCESS_FLAGS ; +vm_flags_t vm_prot_bits = vm_flags &VM_ACCESS_FLAGS ;struct sgx_encl_page *entry; entry =xa_load (&encl->page_array,PFN_DOWN (addr));arch/x86/kernel/cpu/sgx/encl.h +0
-0
arch/x86/kernel/cpu/sgx/encl.h line 33
Quoted 8 lines
arch/x86/kernel/cpu/sgx/encl.h +1
-1@@ -27,7 +27,7 @@struct sgx_encl_page {unsigned long desc; -unsigned long vm_max_prot_bits:8 ; +vm_flags_t vm_max_prot_bits:8 ;enum sgx_page_type type:16 ;struct sgx_epc_page *epc_page;struct sgx_encl *encl;
OK, I missed the remark from Kai, but it is acceptable.
Quoted 3 lines
Signature · 1 line
2.34.1
So again:
BR, Jarkko