Message ID | 20230320191956.1354602-4-jpiotrowski@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1404168wrt; Mon, 20 Mar 2023 12:47:07 -0700 (PDT) X-Google-Smtp-Source: AK7set/o6RVGSV5W0P2Brt/VNAXwjp+AiZInVp5Vd0OJjh8h4KEvHZ/DDBC8F4unS3QHPaMCSS+C X-Received: by 2002:a17:903:11c5:b0:19c:ea4d:5995 with SMTP id q5-20020a17090311c500b0019cea4d5995mr22470575plh.68.1679341627152; Mon, 20 Mar 2023 12:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679341627; cv=none; d=google.com; s=arc-20160816; b=kTYnUhtlDTJu0WHtwLNTWuoYqyFXj3FjFk23Vpv+Y9Ux+ezGFuB/Q4+4/CzxHRRH+1 OI+Oowthf1tZtV1GiuJIJisQlPS2KrAChWp9j2y2OQjCwhZ4SkJQwXcmmBW+jDmY64Sf isual/2tJYOBkbzwceAqm7NR5ObssWFHwyrh+PF//TPOaWjW54F7YtH5HV/AS0D3zCEm zHiXBSJJ+KSAAlXgm4QpY23wmnvlyO8YIChvsXfg73YnUFHBiSISpmX8LHjmCdA/9dpV DMF/aEI8ZD+nt866aeylIKlKLcGNalkI1ds3OiZ7gs/CoQL9ysGwtB3FmMzP0V2QDyrn sUbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=T/Kzn8Yd7+WmZZ2G5JhyiJuSkC/HTVlKDk1fI7xOGw8=; b=tOrUsrhkHxuXehz9CKNarKzY+xPpU2PDGwUKPe4+ClLpGECw5tBTYEN2pEws3QAQPT xkl5IeDuHikfXTxfcbeJSik5kUTElSY0SE1xPJCv+1nvXHhBBlMkNHOl3lSR81YnQoN+ D/Xdv63kmWDjsFC3SX9pJA26eArMdbWgnGPr+ssEYgXYmChkC0jKxNzCnDsLimlGPZxI qrYNsaqHzv3tBpYxHWSWUVLVBItoure/nO1hbSOZOYqucFCw2Cxy9gFgDhRq8eHaMiQT 9ItJTPxf7pa4nX38knCemyFk2NjlixWBfjVWLl9JYCWtI+9L3pRBRT9fQNnFavFWKS/g YP4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fHWiqLsr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bg11-20020a1709028e8b00b0019ad44844b3si10640109plb.118.2023.03.20.12.46.51; Mon, 20 Mar 2023 12:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fHWiqLsr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbjCTT3V (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Mon, 20 Mar 2023 15:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjCTT2o (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Mar 2023 15:28:44 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 38FCE4EE6 for <linux-kernel@vger.kernel.org>; Mon, 20 Mar 2023 12:21:11 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id D8F7920FB19F; Mon, 20 Mar 2023 12:20:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D8F7920FB19F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340026; bh=T/Kzn8Yd7+WmZZ2G5JhyiJuSkC/HTVlKDk1fI7xOGw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHWiqLsrsK5liuESoXYcTTsH+AG4ywvK6DdfILXohxXaQ8w8PYxf8XsCWZC+quRxc 0LyPjJ7373jeo+PuF+N7d4tJbKXYpVTromx/Fae/X5OBaAPUd+rKgLEcl0Tui6E5jD +/1yfZ8hRogHXmYTmkRpu/XVtLL1+7fiNV8tRkro= From: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>, "Brijesh Singh" <brijesh.singh@amd.com>, "Tom Lendacky" <thomas.lendacky@amd.com>, "Kalra, Ashish" <ashish.kalra@amd.com>, "Thomas Gleixner" <tglx@linutronix.de>, "Ingo Molnar" <mingo@redhat.com>, "Borislav Petkov" <bp@alien8.de>, "Dave Hansen" <dave.hansen@linux.intel.com>, x86@kernel.org Subject: [PATCH v3 3/8] x86/psp: Register PSP platform device when ASP table is present Date: Mon, 20 Mar 2023 19:19:51 +0000 Message-Id: <20230320191956.1354602-4-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760916763701839647?= X-GMAIL-MSGID: =?utf-8?q?1760917325945093466?= |
Series |
Support ACPI PSP on Hyper-V
|
|
Commit Message
Jeremi Piotrowski
March 20, 2023, 7:19 p.m. UTC
The ASP table contains the memory location of the register window for communication with the Platform Security Processor. The device is not exposed as an acpi node, so it is necessary to probe for the table and register a platform_device to represent it in the kernel. At least conceptually, the same PSP may be exposed on the PCIe bus as well, in which case it would be necessary to choose whether to use a PCI BAR or the register window defined in ASPT for communication. There is no advantage to using the ACPI and there are no known bare-metal systems that expose the ASP table, so device registration is restricted to the only systems known to provide an ASPT: Hyper-V VMs. Hyper-V VMs also do not expose the PSP over PCIe. This is a skeleton device at this point, as the ccp driver is not yet prepared to correctly probe it. Interrupt configuration will come later on as well. Acked-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/psp.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 arch/x86/kernel/psp.c
Comments
On 20/03/2023 20:25, Borislav Petkov wrote: > On Mon, Mar 20, 2023 at 07:19:51PM +0000, Jeremi Piotrowski wrote: >> The ASP table contains the memory location of the register window for >> communication with the Platform Security Processor. The device is not >> exposed as an acpi node, so it is necessary to probe for the table and >> register a platform_device to represent it in the kernel. >> >> At least conceptually, the same PSP may be exposed on the PCIe bus as >> well, in which case it would be necessary to choose whether to use a PCI >> BAR or the register window defined in ASPT for communication. There is >> no advantage to using the ACPI and there are no known bare-metal systems >> that expose the ASP table, so device registration is restricted to the >> only systems known to provide an ASPT: Hyper-V VMs. Hyper-V VMs also do >> not expose the PSP over PCIe. >> >> This is a skeleton device at this point, as the ccp driver is not yet >> prepared to correctly probe it. Interrupt configuration will come later >> on as well. >> >> Acked-by: Tom Lendacky <thomas.lendacky@amd.com> >> Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> >> --- >> arch/x86/kernel/Makefile | 1 + >> arch/x86/kernel/psp.c | 42 ++++++++++++++++++++++++++++++++++++++++ > > If this is a platform device (driver), why isn't it part of > the drivers/platform/x86/ lineup? > Because of patch 4. My thinking was that the irq setup requires poking at intimate architectural details (init_irq_alloc_info etc.) so it seems like it fits in arch/x86. I also drew inspiration from the sev-guest device in the arch/x86/kernel/sev.c, which is used in a similar context (the PSP device I am registering here is for SNP-host support). Would you prefer it in drivers/platform/x86? Jeremi
On Mon, Mar 20, 2023 at 08:37:56PM +0100, Jeremi Piotrowski wrote: > Because of patch 4. My thinking was that the irq setup requires poking > at intimate architectural details (init_irq_alloc_info etc.) so it seems > like it fits in arch/x86. arch/x86/platform/uv/uv_irq.c:193: init_irq_alloc_info(&info, cpumask_of(cpu)); drivers/iommu/amd/init.c:2391: init_irq_alloc_info(&info, NULL); Also, what patch 4's commit message says, sounds hacky to me. A simple driver should not need the x86_vector_domain. Especially if it is some ACPI wrapper around the PSP hw. But I'd leave that to tglx. > I also drew inspiration from the sev-guest device in the arch/x86/kernel/sev.c, Yeah, we've designed another mess there considering we already have drivers/virt/coco/sev-guest/sev-guest.c That sev guest thing has no place in sev.c and it should go away from there. > which is used in a similar context (the PSP device I am registering here is > for SNP-host support). > > Would you prefer it in drivers/platform/x86? drivers/hv/? Seeing how hyperv is the only thing that's going to use it, AFAICT.
On 20/03/2023 21:03, Borislav Petkov wrote: > On Mon, Mar 20, 2023 at 08:37:56PM +0100, Jeremi Piotrowski wrote: >> Because of patch 4. My thinking was that the irq setup requires poking >> at intimate architectural details (init_irq_alloc_info etc.) so it seems >> like it fits in arch/x86. > > arch/x86/platform/uv/uv_irq.c:193: init_irq_alloc_info(&info, cpumask_of(cpu)); > drivers/iommu/amd/init.c:2391: init_irq_alloc_info(&info, NULL); > > Also, what patch 4's commit message says, sounds hacky to me. A simple > driver should not need the x86_vector_domain. Especially if it is some > ACPI wrapper around the PSP hw. I agree with you here. The irq config of this thing requires specifying passing a CPU vector, this follows the hardware spec which I linked in the first 2 commits, pages 13-15 here: https://www.amd.com/system/files/TechDocs/58028_1.00-PUB.pdf The only way I found to get this to work was going through x86_vector_domain or statically defining a system vector (the latter felt worse). > > But I'd leave that to tglx. >>> I also drew inspiration from the sev-guest device in the arch/x86/kernel/sev.c, > > Yeah, we've designed another mess there considering we already have > > drivers/virt/coco/sev-guest/sev-guest.c > > That sev guest thing has no place in sev.c and it should go away from > there. > >> which is used in a similar context (the PSP device I am registering here is >> for SNP-host support). >> >> Would you prefer it in drivers/platform/x86? > > drivers/hv/? > > Seeing how hyperv is the only thing that's going to use it, AFAICT. > That could work, let me try that.
On Mon, Mar 20, 2023 at 09:18:19PM +0100, Jeremi Piotrowski wrote: > I agree with you here. The irq config of this thing requires specifying > passing a CPU vector, this follows the hardware spec which I linked in the > first 2 commits, pages 13-15 here: You mean the interrupt vector in table 19? > https://www.amd.com/system/files/TechDocs/58028_1.00-PUB.pdf > > The only way I found to get this to work was going through x86_vector_domain > or statically defining a system vector (the latter felt worse). Hmm. Why is that thing special and can't use devm_request_irq() like the rest of the drivers out there?
On 20/03/2023 22:03, Borislav Petkov wrote: > On Mon, Mar 20, 2023 at 09:18:19PM +0100, Jeremi Piotrowski wrote: >> I agree with you here. The irq config of this thing requires specifying >> passing a CPU vector, this follows the hardware spec which I linked in the >> first 2 commits, pages 13-15 here: > > You mean the interrupt vector in table 19? > Yes - this thing wants to receive an interrupt vector and APIC id which it will then use to target its interrupt at. >> https://www.amd.com/system/files/TechDocs/58028_1.00-PUB.pdf >> >> The only way I found to get this to work was going through x86_vector_domain >> or statically defining a system vector (the latter felt worse). > > Hmm. Why is that thing special and can't use devm_request_irq() like the > rest of the drivers out there? > Because the device is not exposed through AML (with ACPI managed irq routing) and needs to be discovered manually and the interrupt programmed by hand. I don't know the reasoning behind it being specified this way. But essentially I am doing all this nasty stuff so that I get a simple irq number. This is then passed to the actual driver that binds to the platform_device (drivers/crypto/ccp/sp-platform.c) which uses it with devm_request_irq.
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 96d51bbc2bd4..6fe52328bc28 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -139,6 +139,7 @@ obj-$(CONFIG_UNWINDER_ORC) += unwind_orc.o obj-$(CONFIG_UNWINDER_FRAME_POINTER) += unwind_frame.o obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o +obj-$(CONFIG_KVM_AMD_SEV) += psp.o obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev.o obj-$(CONFIG_CFI_CLANG) += cfi.o diff --git a/arch/x86/kernel/psp.c b/arch/x86/kernel/psp.c new file mode 100644 index 000000000000..64f3bfc5c9ff --- /dev/null +++ b/arch/x86/kernel/psp.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/platform_data/psp.h> +#include <linux/platform_device.h> +#include <asm/hypervisor.h> + +static struct platform_device psp_device = { + .name = "psp", + .id = PLATFORM_DEVID_NONE, +}; + +static int __init psp_init_platform_device(void) +{ + struct psp_platform_data pdata = {}; + struct resource res[1]; + int err; + + /* + * The ACPI PSP interface is mutually exclusive with the PCIe interface, + * but there is no reason to use the ACPI interface over the PCIe one. + * Restrict probing ACPI PSP to platforms known to only expose the ACPI + * interface, which at this time is SNP-host capable Hyper-V VMs. + */ + if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) + return -ENODEV; + + err = acpi_parse_aspt(res, &pdata); + if (err) + return err; + err = platform_device_add_resources(&psp_device, res, 1); + if (err) + return err; + err = platform_device_add_data(&psp_device, &pdata, sizeof(pdata)); + if (err) + return err; + + err = platform_device_register(&psp_device); + if (err) + return err; + return 0; +} +device_initcall(psp_init_platform_device);