On Mon, Oct 28, 2024 at 11:04:19AM +0530, Nikunj A Dadhania wrote: > Currently, the SEV guest driver is the only user of SNP guest messaging. > All routines for initializing SNP guest messaging are implemented within > the SEV guest driver. To add Secure TSC guest support, these initialization > routines need to be available during early boot. > > Carve out common SNP guest messaging buffer allocations and message > initialization routines to core/sev.c and export them. These newly added > APIs set up the SNP message context (snp_msg_desc), which contains all the > necessary details for sending SNP guest messages. > > At present, the SEV guest platform data structure is used to pass the > secrets page physical address to SEV guest driver. Since the secrets page > address is locally available to the initialization routine, use the cached > address. Remove the unused SEV guest platform data structure. Do not talk about *what* the patch is doing in the commit message - that should be obvious from the diff itself. Rather, concentrate on the *why* it needs to be done. Imagine one fine day you're doing git archeology, you find the place in the code about which you want to find out why it was changed the way it is now. You do git annotate <filename> ... find the line, see the commit id and you do: git show <commit id> You read the commit message and there's just gibberish and nothing's explaining *why* that change was done. And you start scratching your head, trying to figure out why. See what I mean? > Signed-off-by: Nikunj A Dadhania <nikunj@xxxxxxx> > Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx> > --- > arch/x86/include/asm/sev.h | 71 ++++++++- > arch/x86/coco/sev/core.c | 133 +++++++++++++++- > drivers/virt/coco/sev-guest/sev-guest.c | 195 +++--------------------- > 3 files changed, 215 insertions(+), 184 deletions(-) > > diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h > index 2e49c4a9e7fe..63c30f4d44d7 100644 > --- a/arch/x86/include/asm/sev.h > +++ b/arch/x86/include/asm/sev.h > @@ -14,6 +14,7 @@ > #include <asm/insn.h> > #include <asm/sev-common.h> > #include <asm/coco.h> > +#include <asm/set_memory.h> > > #define GHCB_PROTOCOL_MIN 1ULL > #define GHCB_PROTOCOL_MAX 2ULL > @@ -170,10 +171,6 @@ struct snp_guest_msg { > u8 payload[PAGE_SIZE - sizeof(struct snp_guest_msg_hdr)]; > } __packed; > > -struct sev_guest_platform_data { > - u64 secrets_gpa; > -}; > - > struct snp_guest_req { > void *req_buf; > size_t req_sz; > @@ -253,6 +250,7 @@ struct snp_msg_desc { > > u32 *os_area_msg_seqno; > u8 *vmpck; > + int vmpck_id; > }; > > /* > @@ -438,6 +436,63 @@ u64 sev_get_status(void); > void sev_show_status(void); > void snp_update_svsm_ca(void); > > +static inline void free_shared_pages(void *buf, size_t sz) A function with a generic name exported in a header?! First of all, why is it in a header? Then, why isn't it called something "sev_" or so...? Same holds true for all the below. > + unsigned int npages = PAGE_ALIGN(sz) >> PAGE_SHIFT; > + int ret; > + > + if (!buf) > + return; > + > + ret = set_memory_encrypted((unsigned long)buf, npages); > + if (ret) { > + WARN_ONCE(ret, "failed to restore encryption mask (leak it)\n"); > + return; > + } > + > + __free_pages(virt_to_page(buf), get_order(sz)); > +} ... > +static struct aesgcm_ctx *snp_init_crypto(u8 *key, size_t keylen) > +{ > + struct aesgcm_ctx *ctx; > + > + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT); > + if (!ctx) > + return NULL; > + > + if (aesgcm_expandkey(ctx, key, keylen, AUTHTAG_LEN)) { ld: vmlinux.o: in function `snp_init_crypto': /home/boris/kernel/2nd/linux/arch/x86/coco/sev/core.c:2700:(.text+0x1fa3): undefined reference to `aesgcm_expandkey' make[2]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 make[1]: *** [/mnt/kernel/kernel/2nd/linux/Makefile:1166: vmlinux] Error 2 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:224: __sub-make] Error 2 I'll stop here until you fix those. Btw, tip patches are done against tip/master - not against the branch they get queued in. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette