Message ID | 20231030063652.68675-9-nikunj@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add Secure TSC support for SNP guests | expand |
On 10/29/23 23:36, Nikunj A Dadhania wrote: > diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c > index a37ebd3b4773..a07985a96ca5 100644 > --- a/arch/x86/kernel/x86_init.c > +++ b/arch/x86/kernel/x86_init.c > @@ -136,6 +136,7 @@ static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool > static bool enc_tlb_flush_required_noop(bool enc) { return false; } > static bool enc_cache_flush_required_noop(void) { return false; } > static bool is_private_mmio_noop(u64 addr) {return false; } > +static void enc_init_noop(void) { } > > struct x86_platform_ops x86_platform __ro_after_init = { > .calibrate_cpu = native_calibrate_cpu_early, > @@ -158,6 +159,7 @@ struct x86_platform_ops x86_platform __ro_after_init = { > .enc_status_change_finish = enc_status_change_finish_noop, > .enc_tlb_flush_required = enc_tlb_flush_required_noop, > .enc_cache_flush_required = enc_cache_flush_required_noop, > + .enc_init = enc_init_noop, > }, > }; > > diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c > index 9f27e14e185f..01abecc9a774 100644 > --- a/arch/x86/mm/mem_encrypt.c > +++ b/arch/x86/mm/mem_encrypt.c > @@ -84,5 +84,8 @@ void __init mem_encrypt_init(void) > /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ > swiotlb_update_mem_attributes(); > > + if (x86_platform.guest.enc_init) > + x86_platform.guest.enc_init(); > + > print_mem_encrypt_feature_info(); > } How does '.enc_init' ever get set to NULL? Isn't the point of having and using a 'noop' function so that you don't have to do NULL checks?
On 10/30/23 01:36, Nikunj A Dadhania wrote: > Add generic enc_init guest hook for performing any type of > initialization that is vendor specific. I think this commit message should be expanded on a bit... like when it is intended to be called, etc. Thanks, Tom > > Signed-off-by: Nikunj A Dadhania <nikunj@amd.com> > --- > arch/x86/include/asm/x86_init.h | 2 ++ > arch/x86/kernel/x86_init.c | 2 ++ > arch/x86/mm/mem_encrypt.c | 3 +++ > 3 files changed, 7 insertions(+) > > diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h > index 5240d88db52a..6a08dcd1f3c4 100644 > --- a/arch/x86/include/asm/x86_init.h > +++ b/arch/x86/include/asm/x86_init.h > @@ -148,12 +148,14 @@ struct x86_init_acpi { > * @enc_status_change_finish Notify HV after the encryption status of a range is changed > * @enc_tlb_flush_required Returns true if a TLB flush is needed before changing page encryption status > * @enc_cache_flush_required Returns true if a cache flush is needed before changing page encryption status > + * @enc_init Prepare and initialize encryption features > */ > struct x86_guest { > bool (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc); > bool (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); > bool (*enc_tlb_flush_required)(bool enc); > bool (*enc_cache_flush_required)(void); > + void (*enc_init)(void); > }; > > /** > diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c > index a37ebd3b4773..a07985a96ca5 100644 > --- a/arch/x86/kernel/x86_init.c > +++ b/arch/x86/kernel/x86_init.c > @@ -136,6 +136,7 @@ static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool > static bool enc_tlb_flush_required_noop(bool enc) { return false; } > static bool enc_cache_flush_required_noop(void) { return false; } > static bool is_private_mmio_noop(u64 addr) {return false; } > +static void enc_init_noop(void) { } > > struct x86_platform_ops x86_platform __ro_after_init = { > .calibrate_cpu = native_calibrate_cpu_early, > @@ -158,6 +159,7 @@ struct x86_platform_ops x86_platform __ro_after_init = { > .enc_status_change_finish = enc_status_change_finish_noop, > .enc_tlb_flush_required = enc_tlb_flush_required_noop, > .enc_cache_flush_required = enc_cache_flush_required_noop, > + .enc_init = enc_init_noop, > }, > }; > > diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c > index 9f27e14e185f..01abecc9a774 100644 > --- a/arch/x86/mm/mem_encrypt.c > +++ b/arch/x86/mm/mem_encrypt.c > @@ -84,5 +84,8 @@ void __init mem_encrypt_init(void) > /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ > swiotlb_update_mem_attributes(); > > + if (x86_platform.guest.enc_init) > + x86_platform.guest.enc_init(); > + > print_mem_encrypt_feature_info(); > }
On 10/30/2023 10:53 PM, Dave Hansen wrote: > On 10/29/23 23:36, Nikunj A Dadhania wrote: >> diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c >> index a37ebd3b4773..a07985a96ca5 100644 >> --- a/arch/x86/kernel/x86_init.c >> +++ b/arch/x86/kernel/x86_init.c >> @@ -136,6 +136,7 @@ static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool >> static bool enc_tlb_flush_required_noop(bool enc) { return false; } >> static bool enc_cache_flush_required_noop(void) { return false; } >> static bool is_private_mmio_noop(u64 addr) {return false; } >> +static void enc_init_noop(void) { } >> >> struct x86_platform_ops x86_platform __ro_after_init = { >> .calibrate_cpu = native_calibrate_cpu_early, >> @@ -158,6 +159,7 @@ struct x86_platform_ops x86_platform __ro_after_init = { >> .enc_status_change_finish = enc_status_change_finish_noop, >> .enc_tlb_flush_required = enc_tlb_flush_required_noop, >> .enc_cache_flush_required = enc_cache_flush_required_noop, >> + .enc_init = enc_init_noop, >> }, >> }; >> >> diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c >> index 9f27e14e185f..01abecc9a774 100644 >> --- a/arch/x86/mm/mem_encrypt.c >> +++ b/arch/x86/mm/mem_encrypt.c >> @@ -84,5 +84,8 @@ void __init mem_encrypt_init(void) >> /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ >> swiotlb_update_mem_attributes(); >> >> + if (x86_platform.guest.enc_init) >> + x86_platform.guest.enc_init(); >> + >> print_mem_encrypt_feature_info(); >> } > > How does '.enc_init' ever get set to NULL? Isn't the point of having > and using a 'noop' function so that you don't have to do NULL checks? True, I will remove the check. Regards Nikunj
On 10/31/2023 12:49 AM, Tom Lendacky wrote: > On 10/30/23 01:36, Nikunj A Dadhania wrote: >> Add generic enc_init guest hook for performing any type of >> initialization that is vendor specific. > > I think this commit message should be expanded on a bit... like when it is intended to be called, etc. Sure Regards Nikunj
diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index 5240d88db52a..6a08dcd1f3c4 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -148,12 +148,14 @@ struct x86_init_acpi { * @enc_status_change_finish Notify HV after the encryption status of a range is changed * @enc_tlb_flush_required Returns true if a TLB flush is needed before changing page encryption status * @enc_cache_flush_required Returns true if a cache flush is needed before changing page encryption status + * @enc_init Prepare and initialize encryption features */ struct x86_guest { bool (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc); bool (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc); bool (*enc_tlb_flush_required)(bool enc); bool (*enc_cache_flush_required)(void); + void (*enc_init)(void); }; /** diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index a37ebd3b4773..a07985a96ca5 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -136,6 +136,7 @@ static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool static bool enc_tlb_flush_required_noop(bool enc) { return false; } static bool enc_cache_flush_required_noop(void) { return false; } static bool is_private_mmio_noop(u64 addr) {return false; } +static void enc_init_noop(void) { } struct x86_platform_ops x86_platform __ro_after_init = { .calibrate_cpu = native_calibrate_cpu_early, @@ -158,6 +159,7 @@ struct x86_platform_ops x86_platform __ro_after_init = { .enc_status_change_finish = enc_status_change_finish_noop, .enc_tlb_flush_required = enc_tlb_flush_required_noop, .enc_cache_flush_required = enc_cache_flush_required_noop, + .enc_init = enc_init_noop, }, }; diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 9f27e14e185f..01abecc9a774 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -84,5 +84,8 @@ void __init mem_encrypt_init(void) /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ swiotlb_update_mem_attributes(); + if (x86_platform.guest.enc_init) + x86_platform.guest.enc_init(); + print_mem_encrypt_feature_info(); }
Add generic enc_init guest hook for performing any type of initialization that is vendor specific. Signed-off-by: Nikunj A Dadhania <nikunj@amd.com> --- arch/x86/include/asm/x86_init.h | 2 ++ arch/x86/kernel/x86_init.c | 2 ++ arch/x86/mm/mem_encrypt.c | 3 +++ 3 files changed, 7 insertions(+)