Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp330793rwl; Wed, 5 Apr 2023 00:57:30 -0700 (PDT) X-Google-Smtp-Source: AKy350a3bcTw5xTJgIxR8Vzi2/rKFILSa0/PtsAK/g5Dil+ZSqK4En85rn/QEWeqrxCBKwewvTBC X-Received: by 2002:a17:906:13:b0:8f0:ba09:4abe with SMTP id 19-20020a170906001300b008f0ba094abemr2088082eja.2.1680681450726; Wed, 05 Apr 2023 00:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680681450; cv=none; d=google.com; s=arc-20160816; b=wX0N8jWkA3jmCplA8tt9ZZ/6iD0IrHtQceQ8USR4jQAeaWMz+gAA2r5W1niz9Yha07 lN21qUdlur9YDXfZHP7u36wbnfGUn6nopXoADOzeSOcRMGBX/yI73AGYbTC/30Gfhr4a 7sgmrJVGvfCbERnma2+ocIcIO9eYAepKG2s08aEAoScl86qHsk+r9S0omus6z8ICgqkd oRA4ZIqh7NVpJu0P9j5cyjtun8Hf5F3yz2LQaCC7Bm0z1sRkD6V7OltxYam+xfNvfvnl RZ6WaniduS5c0EB/+Quj90PJs5tWCHAwuugdq5IZT/zRf/Zn7IH4Pshky3N7n1NQT1Pr Kl+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=egqdAV4kdd4zNtqfpyFgRnX5D2obdbt5vjBGu/pAukg=; b=KNQtB90pqP3xk8zOj7bL17ekR8fR3ToGPDm9EbFoS247MbeYNV5v3ZDDKw1PfrOOZD ZgaXVAwjkil8jYkx4HGW8haDEyMIY0TdvkgpPcOq/3sGHHMpAlJGDkEuM4YOF1t8lFsW zcf3D8r4N2XWbULbodqUHDn0rkp10zwXxxevvoaeOanRdqhwcY8o8uqIF7LwDJzsGi3B BqHurKoWBuRD+JSK9m1vodFyr56lymmKFp0WrO0WMVIKZYI10FuIO0v2KnmnIj49iPLy pneFI+L5wqV2Wz7gKf2+RCiauc288OXoJa1tDnFL/w+6ZPoH2uFHTZIWmfD3L7mzKuOE NSgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=D+25i0yD; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a170906495400b0094762d75453si1485304ejt.816.2023.04.05.00.57.01; Wed, 05 Apr 2023 00:57:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=D+25i0yD; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S237009AbjDEH4i (ORCPT + 99 others); Wed, 5 Apr 2023 03:56:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237041AbjDEH4h (ORCPT ); Wed, 5 Apr 2023 03:56:37 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC50F30ED; Wed, 5 Apr 2023 00:56:35 -0700 (PDT) Received: from [192.168.2.41] (77-166-152-30.fixed.kpn.net [77.166.152.30]) by linux.microsoft.com (Postfix) with ESMTPSA id 27A40210DEC6; Wed, 5 Apr 2023 00:56:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 27A40210DEC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680681395; bh=egqdAV4kdd4zNtqfpyFgRnX5D2obdbt5vjBGu/pAukg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=D+25i0yDYLpCIJ/YBM9SNd9uQlmVXmidaOufFyZqtV31fx3il+atpwL7iIac0YPKB dnaowxVR8WqIefn4i8lHUEGLmic9T7PQvIHou4sRaUmXj/T18tzeWyZW9DVRnLPfBi Cf+PG1MyCAbSGCJ7UmRTN2898Bv6P5yvTUpeLS/4= Message-ID: <8d39a9a1-4b7b-08fe-7b09-2ff0a419468f@linux.microsoft.com> Date: Wed, 5 Apr 2023 09:56:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v3 0/8] Support ACPI PSP on Hyper-V Content-Language: en-US To: Thomas Gleixner , Borislav Petkov Cc: linux-kernel@vger.kernel.org, Brijesh Singh , Tom Lendacky , "Kalra, Ashish" , linux-crypto@vger.kernel.org, "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Ingo Molnar , Dave Hansen , x86@kernel.org References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> <20230322154655.GDZBsi75f6LnQStxSp@fat_crate.local> <1d25221c-eaab-0f97-83aa-8b4fbe3a53ed@linux.microsoft.com> <20230322181541.GEZBtFzRAMcH9BAzUe@fat_crate.local> <20230323152342.GFZBxu/m3u6aFUDY/7@fat_crate.local> <105d019c-2249-5dfd-e032-95944ea6dc8c@linux.microsoft.com> <20230323163450.GGZBx/qpnclFnMaf7e@fat_crate.local> <20230402154425.GCZCmi2eiKYO2yYhNs@fat_crate.local> <877cutsczn.ffs@tglx> From: Jeremi Piotrowski In-Reply-To: <877cutsczn.ffs@tglx> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-19.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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: X-Mailing-List: linux-crypto@vger.kernel.org On 4/3/2023 8:20 AM, Thomas Gleixner wrote: > On Sun, Apr 02 2023 at 17:44, Borislav Petkov wrote: >> On Fri, Mar 24, 2023 at 06:10:09PM +0100, Jeremi Piotrowski wrote: >>> Since the AMD PSP is a privileged device, there is a desire to not have to trust the >>> ACPI stack, >> >> And yet you do: >> >> + err = acpi_parse_aspt(&res[0], &pdata); >> + if (err) >> + return err; >> >> You don't trust the ACPI stack, and yet you're parsing an ACPI table?!?! >> You have to make up your mind here. >> >> Btw, you still haven't answered my question about doing: >> >> devm_request_irq(dev, 9, ..) >> >> where 9 is the default ACPI interrupt. >> >> You can have some silly table tell you what to map or you can simply map >> IRQ 9 and be done with it. In this second case you can *really* not >> trust ACPI because you know which IRQ it is Will respond to this mail directly. > > The real problem here is that the information provided about the overall > design and requirements is close to zero. All we heard so far is hand > waving about not trusting PCI and ACPI. That's not a fair characterization Thomas, but I will turn the other cheek. > > Jeremi, can you please describe exactly what the design and constraints > are in understandable and coherent sentences? > Here goes, I will keep it as simple as I can. The goal of these patches is to operate all the hardware interfaces required to run AMD SEV-SNP VMs, but in the context of a Linux VM running on top of Hyper-V. This Linux VM is called the SNP-host VM. All the patches I submit target the SNP-host VM kernel, which uses KVM to bring up SEV-SNP VMs. To get SEV-SNP working you need to combine this work with AMD's KVM SEV-SNP patches. I posted two patch sets: one that extends AMD's patches, and one that is independent of them (this one here) that could be merged sooner. Here are the design constraints: 1. the interfaces exposed to the SNP-host VM to operate SEV-SNP match real hardware interface specifications defined by AMD. This is because we are emulating/virtualizing a hardware feature, and not some made up virtual thing. 2. the SNP-host VM may run either Windows(Hyper-V) or Linux, so the SEV-SNP interfaces need to be supported by both. 3. Hyper-V Generation 2 VMs do not have a PCI bus. The SNP-host VM must be a Hyper-V Gen 2 VM. One of the components needed to operate SEV-SNP is the Platform Security Processor (PSP), aka AMD Secure Processor (ASP). The PSP is the root-of-trust on AMD systems. The PSP is specified as being discoverable either on the PCI bus, or through the presence of an ACPI table with the "ASPT" (AMD Secure Processor Table) signature. Here goes the design: Constraint 1 means that only the two specified ways of discovering and configuring a PSP inside the SNP-host VM were in the running: PCI or ASPT. Constraint 3 means that the PCI version of the PSP is not a viable option. Additionally, the ASPT is used on AMD hardware in Microsoft datacenters, which means it is supported in Hyper-V (constraint 2). The outcome is that the SNP-host VM sees an ASPT. The ASPT provides the following information: memory range of PSP registers and offsets of individual PSP registers inside that memory range. There are 7 registers: - 6 are related to the "command submission" portion of the PSP; the ccp module knows how to operate those. - the last one, "ACPI CmdResp" register, is used to configure the PSP interrupt to the OS. The PSP interrupt configuration through the "ACPI CmdResp" register takes the following information: - APIC ID - interrupt vector - destination mode (physical/logical) - message type (fixed/lowest priority) So to hook this up with the Linux device model I wrote patches that do the following: Detect the ASPT table, extract information and register a "psp" platform_device for the "ccp" module to bind to. Create an irq_domain and encapsulate dealing with the PSP interrupt register there, so that the "ccp" module has an irq number that it passes to request_irq(). There is an "if (hypervisor == Hyper-V)" check before the ASPT table detection. Here is the reasoning behind that: According to AMD specifications the *same* PSP may be discoverable both through ASPT and on the PCI bus. In that case, if the ASPT is to be used the OS is supposed to disable the "PCI interface" through the "ACPI CmdResp" register, which will result in no PCI-MSI interrupts, BAR writes ignored, BAR reads return all 0xF's. I can't verify whether that would work correctly, so in the interest of not breaking other users, the ASPT handling is hidden behind the hypervisor check. There is nothing Hyper-V specific about any of this code, it supports a hardware interface present in server grade hardware and would work on physical hardware if when (not if) someone removes the condition. That's all there is to it. All the other information I gave is background information that I hoped would help better understand the setting. The most relevant piece of information is the one that I came across last. You asked "what makes this PSP device special". The PSP is the root-of-trust on the system, it controls memory encryption keys, it can encrypt/decrypt individual memory pages. SEV-SNP ties together a lot of system components and requires enabling support for it in the AMD IOMMU too, which is presumably why the PSP gets the same special treatment (as the AMD IOMMU). The ASPT and AMD PSP interrupt configuration through the "ACPI CmdResp" register is based on a similar design of the AMD IOMMU. The AMD IOMMU is: - discovered through the presence of the IVRS ACPI table - the MMIO address of the IOMMU is parsed out of the IVRS table - if x2APIC support is enabled, the IOMMU interrupts are delivered based on programming APIC-ID+vector+destination mode into an interrupt control register in IOMMU MMIO space. This causes any PCI-MSI configuration present for the IOMMU to be ignored. - Linux supports and uses that interrupt delivery mechanism. It is implemented as an irq_domain. Do you think it makes sense to include parts of the above description in cover letter commit message? Thanks, Jeremi