Skip to content

Commit c2b353a

Browse files
kirylbp3tk0v
authored andcommitted
x86/tdx: Refactor try_accept_one()
Rework try_accept_one() to return accepted size instead of modifying 'start' inside the helper. It makes 'start' in-only argument and streamlines code on the caller side. Suggested-by: Borislav Petkov <[email protected]> Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ff40b57 commit c2b353a

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -713,18 +713,18 @@ static bool tdx_cache_flush_required(void)
713713
return true;
714714
}
715715

716-
static bool try_accept_one(phys_addr_t *start, unsigned long len,
717-
enum pg_level pg_level)
716+
static unsigned long try_accept_one(phys_addr_t start, unsigned long len,
717+
enum pg_level pg_level)
718718
{
719719
unsigned long accept_size = page_level_size(pg_level);
720720
u64 tdcall_rcx;
721721
u8 page_size;
722722

723-
if (!IS_ALIGNED(*start, accept_size))
724-
return false;
723+
if (!IS_ALIGNED(start, accept_size))
724+
return 0;
725725

726726
if (len < accept_size)
727-
return false;
727+
return 0;
728728

729729
/*
730730
* Pass the page physical address to the TDX module to accept the
@@ -743,15 +743,14 @@ static bool try_accept_one(phys_addr_t *start, unsigned long len,
743743
page_size = 2;
744744
break;
745745
default:
746-
return false;
746+
return 0;
747747
}
748748

749-
tdcall_rcx = *start | page_size;
749+
tdcall_rcx = start | page_size;
750750
if (__tdx_module_call(TDX_ACCEPT_PAGE, tdcall_rcx, 0, 0, 0, NULL))
751-
return false;
751+
return 0;
752752

753-
*start += accept_size;
754-
return true;
753+
return accept_size;
755754
}
756755

757756
/*
@@ -788,21 +787,22 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc)
788787
*/
789788
while (start < end) {
790789
unsigned long len = end - start;
790+
unsigned long accept_size;
791791

792792
/*
793793
* Try larger accepts first. It gives chance to VMM to keep
794-
* 1G/2M SEPT entries where possible and speeds up process by
795-
* cutting number of hypercalls (if successful).
794+
* 1G/2M Secure EPT entries where possible and speeds up
795+
* process by cutting number of hypercalls (if successful).
796796
*/
797797

798-
if (try_accept_one(&start, len, PG_LEVEL_1G))
799-
continue;
800-
801-
if (try_accept_one(&start, len, PG_LEVEL_2M))
802-
continue;
803-
804-
if (!try_accept_one(&start, len, PG_LEVEL_4K))
798+
accept_size = try_accept_one(start, len, PG_LEVEL_1G);
799+
if (!accept_size)
800+
accept_size = try_accept_one(start, len, PG_LEVEL_2M);
801+
if (!accept_size)
802+
accept_size = try_accept_one(start, len, PG_LEVEL_4K);
803+
if (!accept_size)
805804
return false;
805+
start += accept_size;
806806
}
807807

808808
return true;

0 commit comments

Comments
 (0)