* [PATCH v1 0/8] Support ACPI PSP on Hyper-V @ 2023-01-23 15:22 Jeremi Piotrowski 2023-01-23 15:22 ` [PATCH v1 1/8] include/acpi: add definition of ASPT table Jeremi Piotrowski 2023-01-23 15:22 ` [PATCH v1 2/8] ACPI: ASPT: Add helper to parse table Jeremi Piotrowski 0 siblings, 2 replies; 5+ messages in thread From: Jeremi Piotrowski @ 2023-01-23 15:22 UTC (permalink / raw) To: linux-kernel Cc: Jeremi Piotrowski, Brijesh Singh, Tom Lendacky, Kalra, Ashish, linux-crypto, Rafael J. Wysocki, Len Brown, linux-acpi, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86 This patch series introduces support for discovering AMD's PSP from an ACPI table and extends the CCP driver to allow binding to that device on x86. This method of PSP discovery is used on Hyper-V when SNP isolation support is exposed to the guest. There is no ACPI node associated with this PSP, so after parsing the ASPT it is registered with the system as a platform_device. I was not quite sure about where to place some of this code but opted for placing the ASPT parsing code in drivers/acpi/ and the platform device creation in arch/x86/ because configuring the irq for the PSP through the ACPI interface requires poking at bits from the architectural vector domain. This was also inspired by the sev-guest device. This series is a prerequisite for nested SNP-host support on Hyper-V but is independent of the SNP-host support patch set. Hyper-V only supports nested SEV-SNP (not SEV or SEV-ES) so the PSP only supports a subset of the full PSP command set. Without SNP-host support (which is not upstream yet), the only PSP command that will succeed is SEV_PLATFORM_STATUS. Jeremi Piotrowski (8): include/acpi: add definition of ASPT table ACPI: ASPT: Add helper to parse table x86/psp: Register PSP platform device when ASP table is present x86/psp: Add IRQ support crypto: cpp - Bind to psp platform device on x86 crypto: ccp - Add vdata for platform device crypto: ccp - Skip DMA coherency check for platform psp crypto: ccp - Allow platform device to be psp master device arch/x86/kernel/Makefile | 2 +- arch/x86/kernel/psp.c | 213 ++++++++++++++++++++++++++++++ drivers/acpi/Makefile | 1 + drivers/acpi/aspt.c | 104 +++++++++++++++ drivers/crypto/ccp/sp-dev.c | 67 +++++++++- drivers/crypto/ccp/sp-dev.h | 16 ++- drivers/crypto/ccp/sp-pci.c | 48 ------- drivers/crypto/ccp/sp-platform.c | 73 +++++++++- include/acpi/actbl1.h | 46 +++++++ include/linux/platform_data/psp.h | 32 +++++ 10 files changed, 544 insertions(+), 58 deletions(-) create mode 100644 arch/x86/kernel/psp.c create mode 100644 drivers/acpi/aspt.c create mode 100644 include/linux/platform_data/psp.h -- 2.25.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 1/8] include/acpi: add definition of ASPT table 2023-01-23 15:22 [PATCH v1 0/8] Support ACPI PSP on Hyper-V Jeremi Piotrowski @ 2023-01-23 15:22 ` Jeremi Piotrowski 2023-01-23 19:56 ` Rafael J. Wysocki 2023-01-23 15:22 ` [PATCH v1 2/8] ACPI: ASPT: Add helper to parse table Jeremi Piotrowski 1 sibling, 1 reply; 5+ messages in thread From: Jeremi Piotrowski @ 2023-01-23 15:22 UTC (permalink / raw) To: linux-kernel Cc: Jeremi Piotrowski, Brijesh Singh, Tom Lendacky, Kalra, Ashish, Rafael J. Wysocki, Len Brown, linux-acpi The AMD Secure Processor ACPI Table provides the memory location of the register window and register offsets necessary to communicate with AMD's PSP (Platform Security Processor). This table is exposed on Hyper-V VMs configured with support for AMD's SNP isolation technology. Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> --- include/acpi/actbl1.h | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 15c78678c5d3..00d40373df37 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -26,6 +26,7 @@ */ #define ACPI_SIG_AEST "AEST" /* Arm Error Source Table */ #define ACPI_SIG_ASF "ASF!" /* Alert Standard Format table */ +#define ACPI_SIG_ASPT "ASPT" /* AMD Secure Processor Table */ #define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */ #define ACPI_SIG_BGRT "BGRT" /* Boot Graphics Resource Table */ #define ACPI_SIG_BOOT "BOOT" /* Simple Boot Flag Table */ @@ -106,6 +107,51 @@ struct acpi_whea_header { u64 mask; /* Bitmask required for this register instruction */ }; +/* https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/acpitabl/ns-acpitabl-aspt_table */ +#define ASPT_REVISION_ID 0x01 +struct acpi_table_aspt { + struct acpi_table_header header; + u32 num_entries; +}; + +struct acpi_aspt_header { + u16 type; + u16 length; +}; + +enum acpi_aspt_type { + ACPI_ASPT_TYPE_GLOBAL_REGS = 0, + ACPI_ASPT_TYPE_SEV_MBOX_REGS = 1, + ACPI_ASPT_TYPE_ACPI_MBOX_REGS = 2, +}; + +/* 0: ASPT Global Registers */ +struct acpi_aspt_global_regs { + struct acpi_aspt_header header; + u32 reserved; + u64 feature_reg_addr; + u64 irq_en_reg_addr; + u64 irq_st_reg_addr; +}; + +/* 1: ASPT SEV Mailbox Registers */ +struct acpi_aspt_sev_mbox_regs { + struct acpi_aspt_header header; + u8 mbox_irq_id; + u8 reserved[3]; + u64 cmd_resp_reg_addr; + u64 cmd_buf_lo_reg_addr; + u64 cmd_buf_hi_reg_addr; +}; + +/* 2: ASPT ACPI Mailbox Registers */ +struct acpi_aspt_acpi_mbox_regs { + struct acpi_aspt_header header; + u32 reserved1; + u64 cmd_resp_reg_addr; + u64 reserved2[2]; +}; + /******************************************************************************* * * ASF - Alert Standard Format table (Signature "ASF!") -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/8] include/acpi: add definition of ASPT table 2023-01-23 15:22 ` [PATCH v1 1/8] include/acpi: add definition of ASPT table Jeremi Piotrowski @ 2023-01-23 19:56 ` Rafael J. Wysocki 2023-01-24 16:05 ` Jeremi Piotrowski 0 siblings, 1 reply; 5+ messages in thread From: Rafael J. Wysocki @ 2023-01-23 19:56 UTC (permalink / raw) To: Jeremi Piotrowski Cc: linux-kernel, Brijesh Singh, Tom Lendacky, Kalra, Ashish, Rafael J. Wysocki, Len Brown, linux-acpi On Mon, Jan 23, 2023 at 4:23 PM Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> wrote: > > The AMD Secure Processor ACPI Table provides the memory location of the > register window and register offsets necessary to communicate with AMD's > PSP (Platform Security Processor). This table is exposed on Hyper-V VMs > configured with support for AMD's SNP isolation technology. > > Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> This modifies the ACPICA code, so it should at least be submitted as a pull request to the upstream ACPICA project on GitHub. Thanks! > --- > include/acpi/actbl1.h | 46 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h > index 15c78678c5d3..00d40373df37 100644 > --- a/include/acpi/actbl1.h > +++ b/include/acpi/actbl1.h > @@ -26,6 +26,7 @@ > */ > #define ACPI_SIG_AEST "AEST" /* Arm Error Source Table */ > #define ACPI_SIG_ASF "ASF!" /* Alert Standard Format table */ > +#define ACPI_SIG_ASPT "ASPT" /* AMD Secure Processor Table */ > #define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */ > #define ACPI_SIG_BGRT "BGRT" /* Boot Graphics Resource Table */ > #define ACPI_SIG_BOOT "BOOT" /* Simple Boot Flag Table */ > @@ -106,6 +107,51 @@ struct acpi_whea_header { > u64 mask; /* Bitmask required for this register instruction */ > }; > > +/* https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/acpitabl/ns-acpitabl-aspt_table */ > +#define ASPT_REVISION_ID 0x01 > +struct acpi_table_aspt { > + struct acpi_table_header header; > + u32 num_entries; > +}; > + > +struct acpi_aspt_header { > + u16 type; > + u16 length; > +}; > + > +enum acpi_aspt_type { > + ACPI_ASPT_TYPE_GLOBAL_REGS = 0, > + ACPI_ASPT_TYPE_SEV_MBOX_REGS = 1, > + ACPI_ASPT_TYPE_ACPI_MBOX_REGS = 2, > +}; > + > +/* 0: ASPT Global Registers */ > +struct acpi_aspt_global_regs { > + struct acpi_aspt_header header; > + u32 reserved; > + u64 feature_reg_addr; > + u64 irq_en_reg_addr; > + u64 irq_st_reg_addr; > +}; > + > +/* 1: ASPT SEV Mailbox Registers */ > +struct acpi_aspt_sev_mbox_regs { > + struct acpi_aspt_header header; > + u8 mbox_irq_id; > + u8 reserved[3]; > + u64 cmd_resp_reg_addr; > + u64 cmd_buf_lo_reg_addr; > + u64 cmd_buf_hi_reg_addr; > +}; > + > +/* 2: ASPT ACPI Mailbox Registers */ > +struct acpi_aspt_acpi_mbox_regs { > + struct acpi_aspt_header header; > + u32 reserved1; > + u64 cmd_resp_reg_addr; > + u64 reserved2[2]; > +}; > + > /******************************************************************************* > * > * ASF - Alert Standard Format table (Signature "ASF!") > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/8] include/acpi: add definition of ASPT table 2023-01-23 19:56 ` Rafael J. Wysocki @ 2023-01-24 16:05 ` Jeremi Piotrowski 0 siblings, 0 replies; 5+ messages in thread From: Jeremi Piotrowski @ 2023-01-24 16:05 UTC (permalink / raw) To: Rafael J. Wysocki Cc: linux-kernel, Brijesh Singh, Tom Lendacky, Kalra, Ashish, Len Brown, linux-acpi On Mon, Jan 23, 2023 at 08:56:32PM +0100, Rafael J. Wysocki wrote: > On Mon, Jan 23, 2023 at 4:23 PM Jeremi Piotrowski > <jpiotrowski@linux.microsoft.com> wrote: > > > > The AMD Secure Processor ACPI Table provides the memory location of the > > register window and register offsets necessary to communicate with AMD's > > PSP (Platform Security Processor). This table is exposed on Hyper-V VMs > > configured with support for AMD's SNP isolation technology. > > > > Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> > > This modifies the ACPICA code, so it should at least be submitted as a > pull request to the upstream ACPICA project on GitHub. > > Thanks! Hi Rafael, Sorry, missed that part of the documentation. Here's the PR: https://github.com/acpica/acpica/pull/829 Thanks, Jeremi > > > --- > > include/acpi/actbl1.h | 46 +++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 46 insertions(+) > > > > diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h > > index 15c78678c5d3..00d40373df37 100644 > > --- a/include/acpi/actbl1.h > > +++ b/include/acpi/actbl1.h > > @@ -26,6 +26,7 @@ > > */ > > #define ACPI_SIG_AEST "AEST" /* Arm Error Source Table */ > > #define ACPI_SIG_ASF "ASF!" /* Alert Standard Format table */ > > +#define ACPI_SIG_ASPT "ASPT" /* AMD Secure Processor Table */ > > #define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */ > > #define ACPI_SIG_BGRT "BGRT" /* Boot Graphics Resource Table */ > > #define ACPI_SIG_BOOT "BOOT" /* Simple Boot Flag Table */ > > @@ -106,6 +107,51 @@ struct acpi_whea_header { > > u64 mask; /* Bitmask required for this register instruction */ > > }; > > > > +/* https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/acpitabl/ns-acpitabl-aspt_table */ > > +#define ASPT_REVISION_ID 0x01 > > +struct acpi_table_aspt { > > + struct acpi_table_header header; > > + u32 num_entries; > > +}; > > + > > +struct acpi_aspt_header { > > + u16 type; > > + u16 length; > > +}; > > + > > +enum acpi_aspt_type { > > + ACPI_ASPT_TYPE_GLOBAL_REGS = 0, > > + ACPI_ASPT_TYPE_SEV_MBOX_REGS = 1, > > + ACPI_ASPT_TYPE_ACPI_MBOX_REGS = 2, > > +}; > > + > > +/* 0: ASPT Global Registers */ > > +struct acpi_aspt_global_regs { > > + struct acpi_aspt_header header; > > + u32 reserved; > > + u64 feature_reg_addr; > > + u64 irq_en_reg_addr; > > + u64 irq_st_reg_addr; > > +}; > > + > > +/* 1: ASPT SEV Mailbox Registers */ > > +struct acpi_aspt_sev_mbox_regs { > > + struct acpi_aspt_header header; > > + u8 mbox_irq_id; > > + u8 reserved[3]; > > + u64 cmd_resp_reg_addr; > > + u64 cmd_buf_lo_reg_addr; > > + u64 cmd_buf_hi_reg_addr; > > +}; > > + > > +/* 2: ASPT ACPI Mailbox Registers */ > > +struct acpi_aspt_acpi_mbox_regs { > > + struct acpi_aspt_header header; > > + u32 reserved1; > > + u64 cmd_resp_reg_addr; > > + u64 reserved2[2]; > > +}; > > + > > /******************************************************************************* > > * > > * ASF - Alert Standard Format table (Signature "ASF!") > > -- > > 2.25.1 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 2/8] ACPI: ASPT: Add helper to parse table 2023-01-23 15:22 [PATCH v1 0/8] Support ACPI PSP on Hyper-V Jeremi Piotrowski 2023-01-23 15:22 ` [PATCH v1 1/8] include/acpi: add definition of ASPT table Jeremi Piotrowski @ 2023-01-23 15:22 ` Jeremi Piotrowski 1 sibling, 0 replies; 5+ messages in thread From: Jeremi Piotrowski @ 2023-01-23 15:22 UTC (permalink / raw) To: linux-kernel Cc: Jeremi Piotrowski, Brijesh Singh, Tom Lendacky, Kalra, Ashish, linux-crypto, Rafael J. Wysocki, Len Brown, linux-acpi The ASP table indicates the presence of a Platform Security Processor with a register window and registers to configure interrupt delivery. The helper checks for the presence of the table and returns a resource and struct with register offsets. Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> --- drivers/acpi/Makefile | 1 + drivers/acpi/aspt.c | 104 ++++++++++++++++++++++++++++++ include/linux/platform_data/psp.h | 32 +++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/acpi/aspt.c create mode 100644 include/linux/platform_data/psp.h diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 0002eecbf870..9621c90e0221 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -57,6 +57,7 @@ acpi-y += evged.o acpi-y += sysfs.o acpi-y += property.o acpi-$(CONFIG_X86) += acpi_cmos_rtc.o +acpi-$(CONFIG_X86) += aspt.o acpi-$(CONFIG_X86) += x86/apple.o acpi-$(CONFIG_X86) += x86/utils.o acpi-$(CONFIG_X86) += x86/s2idle.o diff --git a/drivers/acpi/aspt.c b/drivers/acpi/aspt.c new file mode 100644 index 000000000000..cf629db35036 --- /dev/null +++ b/drivers/acpi/aspt.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0-only +#define pr_fmt(fmt) "ACPI: ASPT: " fmt +#include <linux/acpi.h> +#include <linux/kernel.h> +#include <linux/platform_data/psp.h> + +static int __init psp_validate_regs(const struct acpi_aspt_global_regs *gregs, + const struct acpi_aspt_sev_mbox_regs *sevregs, + const struct acpi_aspt_acpi_mbox_regs *acpiregs) +{ + u64 pfn; + int idx; + u64 regs[] = { + gregs->feature_reg_addr, + gregs->irq_en_reg_addr, + gregs->irq_st_reg_addr, + sevregs->cmd_resp_reg_addr, + sevregs->cmd_buf_lo_reg_addr, + sevregs->cmd_buf_hi_reg_addr, + acpiregs->cmd_resp_reg_addr + }; + pfn = regs[0] >> PAGE_SHIFT; + for (idx = 1; idx < ARRAY_SIZE(regs); idx++) { + if (regs[idx] >> PAGE_SHIFT != pfn) + return -EINVAL; + } + return 0; +} + +/** + * acpi_parse_aspt - Parse ASPT table and return contained information + * @res: will be filled with the address and size of the ASP register window + * @pdata: will be filled with the register offsets parsed from the ASPT table + */ +int __init acpi_parse_aspt(struct resource *res, struct psp_platform_data *pdata) +{ + struct acpi_aspt_acpi_mbox_regs acpiregs = {}; + struct acpi_aspt_sev_mbox_regs sevregs = {}; + struct acpi_aspt_global_regs gregs = {}; + struct acpi_aspt_header *entry, *end; + struct acpi_table_aspt *aspt; + unsigned long base; + acpi_status status; + int err = 0; + + status = acpi_get_table(ACPI_SIG_ASPT, 0, (struct acpi_table_header **)&aspt); + if (ACPI_FAILURE(status)) + return -ENODEV; + if (aspt->header.revision != ASPT_REVISION_ID) { + pr_err("unsupported table revision: %d\n", (int)aspt->header.revision); + err = -ENODEV; + goto exit; + } + entry = (struct acpi_aspt_header *)(aspt + 1); + end = (struct acpi_aspt_header *)((void *)aspt + aspt->header.length); + while (entry < end) { + if (((void *)entry + entry->length) > (void *)end) { + pr_err("error during parsing\n"); + err = -EINVAL; + goto exit; + } + switch (entry->type) { + case ACPI_ASPT_TYPE_GLOBAL_REGS: + memcpy(&gregs, entry, entry->length); + break; + case ACPI_ASPT_TYPE_SEV_MBOX_REGS: + memcpy(&sevregs, entry, entry->length); + break; + case ACPI_ASPT_TYPE_ACPI_MBOX_REGS: + memcpy(&acpiregs, entry, entry->length); + break; + } + entry = (struct acpi_aspt_header *)((void *)entry + entry->length); + } + if (!gregs.header.length || !sevregs.header.length || !acpiregs.header.length) { + pr_err("missing ASPT table entry: %u %u %u\n", gregs.header.length, + sevregs.header.length, + acpiregs.header.length); + err = -EINVAL; + goto exit; + } + /* All registers are expected to be within the same page */ + err = psp_validate_regs(&gregs, &sevregs, &acpiregs); + if (err) { + pr_err("ASPT registers span multiple pages\n"); + goto exit; + } + + base = ALIGN_DOWN(gregs.feature_reg_addr, PAGE_SIZE); + *res = (struct resource)DEFINE_RES_MEM(base, PAGE_SIZE); + + pdata->sev_cmd_resp_reg = sevregs.cmd_resp_reg_addr & ~PAGE_MASK; + pdata->sev_cmd_buf_lo_reg = sevregs.cmd_buf_lo_reg_addr & ~PAGE_MASK; + pdata->sev_cmd_buf_hi_reg = sevregs.cmd_buf_hi_reg_addr & ~PAGE_MASK; + pdata->feature_reg = gregs.feature_reg_addr & ~PAGE_MASK; + pdata->irq_en_reg = gregs.irq_en_reg_addr & ~PAGE_MASK; + pdata->irq_st_reg = gregs.irq_st_reg_addr & ~PAGE_MASK; + pdata->mbox_irq_id = sevregs.mbox_irq_id; + pdata->acpi_cmd_resp_reg = acpiregs.cmd_resp_reg_addr & ~PAGE_MASK; + +exit: + acpi_put_table((struct acpi_table_header *)aspt); + return err; +} diff --git a/include/linux/platform_data/psp.h b/include/linux/platform_data/psp.h new file mode 100644 index 000000000000..b761f72168d6 --- /dev/null +++ b/include/linux/platform_data/psp.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * psp.h - PSP register offsets parsed from ASPT ACPI table + */ + +#ifndef __LINUX_PSP_H +#define __LINUX_PSP_H + +#include <linux/types.h> +#include <linux/ioport.h> + +struct psp_platform_data { + int sev_cmd_resp_reg; + int sev_cmd_buf_lo_reg; + int sev_cmd_buf_hi_reg; + int feature_reg; + int irq_en_reg; + int irq_st_reg; + int mbox_irq_id; + int acpi_cmd_resp_reg; +}; + +#if IS_ENABLED(CONFIG_ACPI) +int acpi_parse_aspt(struct resource *res, struct psp_platform_data *pdata); +#else +static inline acpi_parse_aspt(struct resource *res, struct psp_platform_data *pdata) +{ + return -ENODEV; +} +#endif + +#endif /* __LINUX_PSP_H */ -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-24 16:05 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-01-23 15:22 [PATCH v1 0/8] Support ACPI PSP on Hyper-V Jeremi Piotrowski 2023-01-23 15:22 ` [PATCH v1 1/8] include/acpi: add definition of ASPT table Jeremi Piotrowski 2023-01-23 19:56 ` Rafael J. Wysocki 2023-01-24 16:05 ` Jeremi Piotrowski 2023-01-23 15:22 ` [PATCH v1 2/8] ACPI: ASPT: Add helper to parse table Jeremi Piotrowski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox