* [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits
@ 2026-01-22 5:54 Wentong Tian
2026-01-22 11:42 ` Huang, Kai
2026-01-25 14:45 ` Jarkko Sakkinen
0 siblings, 2 replies; 4+ messages in thread
From: Wentong Tian @ 2026-01-22 5:54 UTC (permalink / raw)
To: jarkko, dave.hansen
Cc: tglx, mingo, bp, x86, linux-sgx, linux-mm, linux-kernel, Wentong Tian
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.
No functional change intended.
Signed-off-by: Wentong Tian <tianwentong2000@gmail.com>
---
arch/x86/kernel/cpu/sgx/encl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index cf149b9f4916..814edcde225d 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -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));
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits
2026-01-22 5:54 [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits Wentong Tian
@ 2026-01-22 11:42 ` Huang, Kai
2026-01-23 6:15 ` TwT pupupu
2026-01-25 14:45 ` Jarkko Sakkinen
1 sibling, 1 reply; 4+ messages in thread
From: Huang, Kai @ 2026-01-22 11:42 UTC (permalink / raw)
To: tianwentong2000, jarkko, dave.hansen
Cc: linux-sgx, linux-mm, mingo, tglx, linux-kernel, bp, x86
On Thu, 2026-01-22 at 13:54 +0800, Wentong Tian wrote:
> 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.
>
> No functional change intended.
>
> Signed-off-by: Wentong Tian <tianwentong2000@gmail.com>
> ---
> arch/x86/kernel/cpu/sgx/encl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index cf149b9f4916..814edcde225d 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -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));
Since commit d75fa3c94750 ("mm: update
architecture and driver code to use vm_flags_t") already converted one
'vm_prot_bits' to vm_flags_t in sgx_encl_may_map(), this looks good to me
too.
One thing though:
'vm_prot_bits' is later bit-ANDed with entry->vm_max_prot_bits:
if ((entry->vm_max_prot_bits & vm_prot_bits) != vm_prot_bits)
return ERR_PTR(-EFAULT);
But 'vm_max_prot_bits' a 8-bit field of 'unsigned long' in 'struct
sgx_encl_page':
struct sgx_encl_page {
unsigned long desc;
unsigned long vm_max_prot_bits:8;
...
};
Not sure we should change that too:
struct sgx_encl_page {
unsigned long desc;
vm_flags_t vm_max_prot_bits:8;
...
};
?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits
2026-01-22 11:42 ` Huang, Kai
@ 2026-01-23 6:15 ` TwT pupupu
0 siblings, 0 replies; 4+ messages in thread
From: TwT pupupu @ 2026-01-23 6:15 UTC (permalink / raw)
To: Huang, Kai
Cc: jarkko, dave.hansen, linux-sgx, linux-mm, mingo, tglx,
linux-kernel, bp, x86
On Wed, Jan 22, 2026 at 7:42 PM Huang, Kai <kai.huang@intel.com> wrote:
> Not sure we should change that too:
>
> struct sgx_encl_page {
> unsigned long desc;
> vm_flags_t vm_max_prot_bits:8;
> ...
> };
>
> ?
Hi, I'll include this in v2 for consistency. The :8
width is unchanged, so no functional or storage difference.
Huang, Kai <kai.huang@intel.com> 於 2026年1月22日週四 下午7:42寫道:
>
> On Thu, 2026-01-22 at 13:54 +0800, Wentong Tian wrote:
> > 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.
> >
> > No functional change intended.
> >
> > Signed-off-by: Wentong Tian <tianwentong2000@gmail.com>
> > ---
> > arch/x86/kernel/cpu/sgx/encl.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> > index cf149b9f4916..814edcde225d 100644
> > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > @@ -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));
>
> Since commit d75fa3c94750 ("mm: update
> architecture and driver code to use vm_flags_t") already converted one
> 'vm_prot_bits' to vm_flags_t in sgx_encl_may_map(), this looks good to me
> too.
>
> One thing though:
>
> 'vm_prot_bits' is later bit-ANDed with entry->vm_max_prot_bits:
>
> if ((entry->vm_max_prot_bits & vm_prot_bits) != vm_prot_bits)
> return ERR_PTR(-EFAULT);
>
> But 'vm_max_prot_bits' a 8-bit field of 'unsigned long' in 'struct
> sgx_encl_page':
>
> struct sgx_encl_page {
> unsigned long desc;
> unsigned long vm_max_prot_bits:8;
> ...
> };
>
> Not sure we should change that too:
>
> struct sgx_encl_page {
> unsigned long desc;
> vm_flags_t vm_max_prot_bits:8;
> ...
> };
>
> ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits
2026-01-22 5:54 [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits Wentong Tian
2026-01-22 11:42 ` Huang, Kai
@ 2026-01-25 14:45 ` Jarkko Sakkinen
1 sibling, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2026-01-25 14:45 UTC (permalink / raw)
To: Wentong Tian
Cc: dave.hansen, tglx, mingo, bp, x86, linux-sgx, linux-mm, linux-kernel
On Thu, Jan 22, 2026 at 01:54:35PM +0800, Wentong Tian wrote:
> 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.
>
> No functional change intended.
>
> Signed-off-by: Wentong Tian <tianwentong2000@gmail.com>
> ---
> arch/x86/kernel/cpu/sgx/encl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index cf149b9f4916..814edcde225d 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -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));
> --
> 2.34.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-25 14:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-22 5:54 [PATCH] x86/sgx: use vm_flags_t for vm_prot_bits Wentong Tian
2026-01-22 11:42 ` Huang, Kai
2026-01-23 6:15 ` TwT pupupu
2026-01-25 14:45 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox