From: "Gupta, Pankaj" <pankaj.gupta@amd.com>
To: "Borislav Petkov (AMD)" <bp@alien8.de>,
Tom Lendacky <thomas.lendacky@amd.com>
Cc: x86-ml <x86@kernel.org>, lkml <linux-kernel@vger.kernel.org>,
linux-coco@lists.linux.dev
Subject: Re: [RFC PATCH] x86/sev: Cleanup vc_handle_msr()
Date: Thu, 7 Nov 2024 12:02:46 +0100 [thread overview]
Message-ID: <beaed4f3-58f8-b344-ef95-9f3c988ddd49@amd.com> (raw)
In-Reply-To: <20241106172647.GAZyum1zngPDwyD2IJ@fat_crate.local>
On 11/6/2024 6:26 PM, Borislav Petkov (AMD) wrote:
> Hi,
>
> I think we should clean this one up before in-flight patchsets make it more
> unreadable and in need for an even more cleanup.
>
> ---
> Carve out the MSR_SVSM_CAA into a helper with the suggestion that
> upcoming future users should do the same. Rename that silly exit_info_1
> into what it actually means in this function - whether the MSR access is
> a read or a write.
>
> No functional changes.
>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
LGTM
With minor comments from Tom,
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
> ---
> arch/x86/coco/sev/core.c | 34 +++++++++++++++++++---------------
> 1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
> index 97f445f3366a..1efb4a5c5ab3 100644
> --- a/arch/x86/coco/sev/core.c
> +++ b/arch/x86/coco/sev/core.c
> @@ -1406,35 +1406,39 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd)
> return 0;
> }
>
> +/* Writes to the SVSM CAA MSR are ignored */
> +static enum es_result __vc_handle_msr_caa(struct pt_regs *regs, bool write)
> +{
> + if (write)
> + return ES_OK;
> +
> + regs->ax = lower_32_bits(this_cpu_read(svsm_caa_pa));
> + regs->dx = upper_32_bits(this_cpu_read(svsm_caa_pa));
> +
> + return ES_OK;
> +}
> +
> static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
> {
> struct pt_regs *regs = ctxt->regs;
> enum es_result ret;
> - u64 exit_info_1;
> + bool write;
>
> /* Is it a WRMSR? */
> - exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0;
> -
> - if (regs->cx == MSR_SVSM_CAA) {
> - /* Writes to the SVSM CAA msr are ignored */
> - if (exit_info_1)
> - return ES_OK;
> -
> - regs->ax = lower_32_bits(this_cpu_read(svsm_caa_pa));
> - regs->dx = upper_32_bits(this_cpu_read(svsm_caa_pa));
> + write = ctxt->insn.opcode.bytes[1] == 0x30;
>
> - return ES_OK;
> - }
> + if (regs->cx == MSR_SVSM_CAA)
> + return __vc_handle_msr_caa(regs, write);
>
> ghcb_set_rcx(ghcb, regs->cx);
> - if (exit_info_1) {
> + if (write) {
> ghcb_set_rax(ghcb, regs->ax);
> ghcb_set_rdx(ghcb, regs->dx);
> }
>
> - ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MSR, exit_info_1, 0);
> + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MSR, !!write, 0);
>
> - if ((ret == ES_OK) && (!exit_info_1)) {
> + if ((ret == ES_OK) && (!write)) {
> regs->ax = ghcb->save.rax;
> regs->dx = ghcb->save.rdx;
> }
next prev parent reply other threads:[~2024-11-07 11:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 17:26 Borislav Petkov (AMD)
2024-11-06 19:40 ` Tom Lendacky
2024-11-06 19:47 ` Borislav Petkov
2024-11-07 11:02 ` Gupta, Pankaj [this message]
2024-11-07 11:26 ` [tip: x86/sev] " tip-bot2 for Borislav Petkov (AMD)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=beaed4f3-58f8-b344-ef95-9f3c988ddd49@amd.com \
--to=pankaj.gupta@amd.com \
--cc=bp@alien8.de \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®