From patchwork Thu Mar 9 02:40:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166723 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94380C74A4B for ; Thu, 9 Mar 2023 02:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbjCIClm (ORCPT ); Wed, 8 Mar 2023 21:41:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbjCIClk (ORCPT ); Wed, 8 Mar 2023 21:41:40 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021017.outbound.protection.outlook.com [52.101.57.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDC1967732; Wed, 8 Mar 2023 18:41:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WZ8PvzNAHoIPBffwZL3115hQ4jJagk5WW7bCs81r5MOUoHYEVxVSEINELufbKNWKf0Sm8sHY9LEs2BkRJ/dc5Qzt+HYZBg02EPam8QGFlxpHGshrh13LzhCBiFlNcmRxehu2t7HIXcuMtfr6Eh5HSxYGoMmTYM52AQdBy08BHGsOmYZhGPd6y1ZrqZ1TELWX3Vgr95S/1rj3fjaMLu0G3OPmqd2qapabcr/0skwT/ROymBx12vw0vMgSd2h2TlF5jrhNaIfRM5f6xwEl8KWKBqKUNWqU0q2bPbAPn/8S2+QOi43ciIa4XyumV5w/eXBdlCVBqvkErxqOQ+Z9hhhaSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BJSsjkE6n4QET9p3yMwrUTThHUQbkoJIj/zzWReCAO8=; b=hLpS2k/NoTw3KDp+d/iUEkeN1Cq/+OtSUhZBXB7JWuJj8ps42Ql8wNC2sYEZwXaNio0Y8KXRQBrUdRGcjPnb3W0/V1Hb7QgclaB/MoXaRiXUzngCFeMCqIpx+qkWnqVA1ia4xusYDUpMd3GFwIQa3mYVQuZt3ROlWoIETgx0ErNeUBtuEfXSPBQ0caeGGLJMwMniud7H+/D13RFpL1K/VAWARNOYtzcp7U8sM6HU6lUncULvrussVYuwR808Hgs23JbQvYyo9EzS5jV2+Wf1+PnRf9RW8DXQ8JZV00jrfWEjLoR/eerFPySsAghUNt+JRX68x8Bea4Kinv3F28adxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BJSsjkE6n4QET9p3yMwrUTThHUQbkoJIj/zzWReCAO8=; b=KIm5xs/LBXgHOOsr/KyeRFOspSFOXR2263J3e+rixp+EJYKCe8Z18aae0WIcfN+zcqnBr58r1s5jPpcNHeHEuQ5DU1O+WE+oxT7f+KbOeAEg4cA4ujrvLqXAWHN8q71GqpJksmBMYzwBRCrn5B06EMPA9SyKjTxGVW2y5d8xYOM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:36 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:36 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 01/13] x86/ioremap: Add hypervisor callback for private MMIO mapping in coco VM Date: Wed, 8 Mar 2023 18:40:02 -0800 Message-Id: <1678329614-3482-2-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: aae9bbbb-5dbe-403f-7125-08db2047cd1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XwGuW/N+vrB+6+OhLiyC9thzovubM4tJmpQMM+VbZ5L/fesvAt1K2JKXNapmqiV1Lq5uxMaol7CjsIowfidxIEPG+aKQ7O43Hx9D1x84ilrlei9M1r78Y/TG0v1EbwayCBTe1HoTsoB7JG3o373FsTR9MzPQiwtzG0nBsHdtb3u2LKk4aeUGQmabBUFUej+ica00m5FtzUS2XEVyb/TkycN4E0Ruq84/INBbRuuKzD/PQ77k+unFAgcMfFYmCJ/JZxjmRLyGampr4r1AZL1NcO9pNhbViotTz6JYJ02nlV7+ADZ5FbcWnpkqHCO6ons99mtyZU5jbpvCEdIPCdEDRh4WIepxp9dlWR4JbRWx3sjGJ4Sx6uAwxKvnRzXd9xYt+OBD1AvKXT9i2b2FcUizozyxrj+H/joj9p5a2xRVFU9zGuCFaQ9qnUkiV0jU0X4hSvOICV+g+OapUn4VV6aVk7o6cL4PE9DcuExyWK0zjqD3LtVKrz/3xCeX3X8jay3fiYdUnq8qSOsnuJUYN3EUtNPO8L53QqqOFniJI3mP+b5/5lCJzUAA/Nx39XigDdjG7JXe65D0pgwSHpMnd50YApvez3q5u2izh5xRe/kjTQrFLHUf6Wtmt92PIGfLZ50BZ039ydA/w2KCYAMELyj0BtLJx4/BvRcHn5EGT7BXfO9+/4CjGRHHsxYS40xRQP5i3z95wZXVmxBiir/neO9pnmF9wyQnBsE2ABQIQjxEL3OoEBDsp9max1aHb4PhGsCOQIyw8HVhT8SqXEk9ArWFgA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: u3fAXCWuzmTm61bXdPNWo96AbJkyFNK7L2A12xy5X+s1Qv5rPQzezKU1y5MM4M75CvLHQDh4LNarbhdG+IUuvPddDMmckhkCyCqhU0JxriXAs4qVSTZri3ybnIxGfV/JosL5dOSYJd5Zb3Wtjqh/GEMhZVVXjfDrdnCRaGdDxYTQiy3sR2G8Al8K2xBthbMwlETlA4UaSsDDE52UNPLIpbQQ2exC5ZG9e88oKlpMTkJTkYYuQLG4oCjEvzXyo9+MhFxbA8OVYf2BRXkYV6glrf4Ncwq00dPwzoa2VKMjYSbF0MfIbj4/9FnJGq9nvsOSYJ7jcXHO7nZPRgUBm7uUgUdVftgp//DelKqY9U06vlyiY/tqwMDZ80uogLkC3RNKDZTT0QyKALuGfc9veFAkRYXnM/Et0vcn9736BJ74aREFvPlYb3ESPHGNqG40OzCO9VJQVjS2+2eauwwBhPKyErGCXqMKsGyluT7CukJtUD/TOdgDXBLZnyC8rDFw0yBMscExERPkPhS/HtQcn99KL5091SPEmxn6eL6ejiAnp+ZDk3oLwULTMhGTehEF93tMHVLxawXieTGNWBT6pusW6it3CWMDGKiSLTzDpS1S0CxR9lvlV75FELh4M+AdnlQ0YNPg9UG7XTvn/RmgAdwJcPaek6E65HGRyJjxiOI7QRpUZZ0xfxmN/De/xb0wQCRSaBtuHFMh7kwHr8Kw5H0ByhAblUMzAO9dyosmuxuWdU64jCvW18EpnUYgxY/WTZoRVop9FObg3LNslw4QJI+qLfyl8lMOjYOyckzfrJWiCXgFW8A3h7JRad3Z75tb7cs8j0+kD2KEFCfbKRtVXj04ExPXikcG1emGL9lZk0zcSkAlcNo72wY0qNrW+vXrO44MsXci1W/OaWemK7VkBYk6tIjSEePA1WgwXmHFK+acRyxsHv/DJCfnOrR+PYm+CjU1/PLTkUCKEL99IIJsWTj7dk6L6V8136Nay9FXVg0L+i1xlYyzLC7skXE5UM4BqT4k3KSyqtl5AhUTFMG/0PoZARUxACoYKBsFkhDWMiRL7tFQM+avlp6oKc+2Eml7AoCZ6qrznTxVcY6XTvNo0kJTz8TJCzFha/nGLNnsexveY0hVLaEu1Cv9h6cO9SogPFU9q7MjSe2A3N29BMWFTTcyJDVRwWpNOWyPhMbD0Sa6QlwzpUwJTOKE4+Nwc2R0Bf+fVVJblJq+N/DA11qpOaV+7MGRdhIwca+KDaxCX4sAJLVqGbSwuGkmFrH3z9/WL+SY3TJtgx6y595rKYQCfU19CjC0yUBl0licHgxKTs4awVnBJfrl656fOGN26MOZsq4pCILo6hH5XzWnYwFIIjPdinOlEbtScJUsCRKtK6A6gOwmWAtE63XnnEmq08bjh06rKs7dE7Ocytloxs8XarlwgPuStYuN1F5+FdjR3aKm2tC+ojzNs2jWRzsaNN/xOZ/uRG+tk62lTQb6HdVG0deSTPKRBRynHPoF8ewknaYDVjgiXbGQo6cu7mfgfadntU745/TrPeKiucuGIZWstdQYJGMBTQagrvBaSdKPQs1GPflNGJHuL8K+DBtQU38hR2YZxhvUV7D7/oLWtjm1tFfcgw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: aae9bbbb-5dbe-403f-7125-08db2047cd1c X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:36.0735 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /C5aeriFRkR0bancV7rMcB6fQ5BNoBay3qo7qW0P4mU8NezWUXAijubYt7+p3WO2OT0YWgDKoQ/JQCzFH/MzYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Current code always maps MMIO devices as shared (decrypted) in a confidential computing VM. But Hyper-V guest VMs on AMD SEV-SNP with vTOM use a paravisor running in VMPL0 to emulate some devices, such as the IO-APIC and TPM. In such a case, the device must be accessed as private (encrypted) because the paravisor emulates the device at an address below vTOM, where all accesses are encrypted. Add a new hypervisor callback to determine if an MMIO address should be mapped private. The callback allows hypervisor-specific code to handle any quirks, the use of a paravisor, etc. in determining whether a mapping must be private. If the callback is not used by a hypervisor, default to returning "false", which is consistent with normal coco VM behavior. Use this callback as another special case to check for when doing ioremap. Just checking the starting address is sufficient as an ioremap range must be all private or all shared. Also make the callback in early boot IO-APIC mapping code that uses the fixmap. Signed-off-by: Michael Kelley --- arch/x86/include/asm/x86_init.h | 4 ++++ arch/x86/kernel/apic/io_apic.c | 16 +++++++++++----- arch/x86/kernel/x86_init.c | 2 ++ arch/x86/mm/ioremap.c | 5 +++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index c1c8c58..6f873c6 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -259,11 +259,15 @@ struct x86_legacy_features { * VMMCALL under SEV-ES. Needs to return 'false' * if the checks fail. Called from the #VC * exception handler. + * @is_private_mmio: For Coco VM, must map MMIO address as private. + * Used when device is emulated by a paravisor + * layer in the VM context. */ struct x86_hyper_runtime { void (*pin_vcpu)(int cpu); void (*sev_es_hcall_prepare)(struct ghcb *ghcb, struct pt_regs *regs); bool (*sev_es_hcall_finish)(struct ghcb *ghcb, struct pt_regs *regs); + bool (*is_private_mmio)(u64 addr); }; /** diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 1f83b05..88cb8a6 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -66,6 +66,7 @@ #include #include #include +#include #define for_each_ioapic(idx) \ for ((idx) = 0; (idx) < nr_ioapics; (idx)++) @@ -2679,11 +2680,16 @@ static void io_apic_set_fixmap(enum fixed_addresses idx, phys_addr_t phys) { pgprot_t flags = FIXMAP_PAGE_NOCACHE; - /* - * Ensure fixmaps for IOAPIC MMIO respect memory encryption pgprot - * bits, just like normal ioremap(): - */ - flags = pgprot_decrypted(flags); + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { + /* + * Ensure fixmaps for IOAPIC MMIO respect memory encryption + * pgprot bits, just like normal ioremap(): + */ + if (x86_platform.hyper.is_private_mmio(phys)) + flags = pgprot_encrypted(flags); + else + flags = pgprot_decrypted(flags); + } __set_fixmap(idx, phys, flags); } diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index ef80d36..95be383 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -134,6 +134,7 @@ static void enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return false; } static bool enc_tlb_flush_required_noop(bool enc) { return false; } static bool enc_cache_flush_required_noop(void) { return false; } +static bool is_private_mmio_noop(u64 addr) {return false; } struct x86_platform_ops x86_platform __ro_after_init = { .calibrate_cpu = native_calibrate_cpu_early, @@ -149,6 +150,7 @@ struct x86_platform_ops x86_platform __ro_after_init = { .realmode_reserve = reserve_real_mode, .realmode_init = init_real_mode, .hyper.pin_vcpu = x86_op_int_noop, + .hyper.is_private_mmio = is_private_mmio_noop, .guest = { .enc_status_change_prepare = enc_status_change_prepare_noop, diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 6453fba..aa7d279 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -116,6 +116,11 @@ static void __ioremap_check_other(resource_size_t addr, struct ioremap_desc *des if (!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) return; + if (x86_platform.hyper.is_private_mmio(addr)) { + desc->flags |= IORES_MAP_ENCRYPTED; + return; + } + if (!IS_ENABLED(CONFIG_EFI)) return; From patchwork Thu Mar 9 02:40:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166725 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3DEEC7618A for ; Thu, 9 Mar 2023 02:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjCIClo (ORCPT ); Wed, 8 Mar 2023 21:41:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbjCICll (ORCPT ); Wed, 8 Mar 2023 21:41:41 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021017.outbound.protection.outlook.com [52.101.57.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CAEE67731; Wed, 8 Mar 2023 18:41:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cf9HYmQIAyeY3OoV/a7KKq0wZKp/Ld3oGLbTiF5aTGcT6+utxRiyFKJrfrjrg0ntQZyLaA1/PBevZic3B7RuWU1D9DoZ5moqheKUvm9Ra/LYg+sg5WY9hgZ6a7Ibu3EHutTVFD3ygNH8xSn9mi5Ki16VlbCh6vjVVxVFP6ZwayjlES5QdcZakxclDnuxOAvvwk20dzDL+ubZRLBQKJg/1w1HJ8vAY4OrgBuelTkrDgD9fqydUrllCfRSBepeMKBgCRb5HG9qZsniiS0vAUmAydtB2VU5J/0n8c3PW709GBtr+QKeK80dSqpkhud+xRhing8Bz+VVKuvIv3IdA0ARiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kbHFPFmTeMZYHHAR+6LzRBCkRR+Lt6NfcAGOTQF+av8=; b=FAORj/CKq6fSzplsV4Me39SkADngK9aYlJXiQEBB6Q3pMhlzT70aQ+lLNUZypDPv9Sqqxb9PhBZyckayQlhi5sbgyAuWDJCz3vVpUtl7zlYsATWokq6AJEd6wwLUs+jOMakP8LAF+RJNvU/7BefB+1rU8wj6Xp4elpobkf9mtGyjwY0rdqQLUqS8T0MgsMTG6vcDPcO6mXYIkF9SYIBhCzkbqzpIzRYCT1//OyOmMPYC0B16PUo0hsfjNyUiwNw7N+uJHuwaKgQVH191UXhQSIx+WbcENdHFvDmaTDu7kGBiAqu7LYev8sJGQR+pNaW11SLJICr0U6fDtHvcfShPQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kbHFPFmTeMZYHHAR+6LzRBCkRR+Lt6NfcAGOTQF+av8=; b=iORG/Sv83Yt04F6grUfMhOgNekx2TH2SwSlPJ3ehSbo3eujQotiphDqKl0K1+NJTWv0+A11nMThX417klzY/0YLvvAVjoita0gsO2iKALhidHEPuppYfrlW7iLaRq3z0C4LDmSuzw88oDEK5JVZ/L5K9CwYUbWrrI40V6BT6e+w= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:38 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:38 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 02/13] x86/hyperv: Reorder code to facilitate future work Date: Wed, 8 Mar 2023 18:40:03 -0800 Message-Id: <1678329614-3482-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: 86e0b62c-f4f3-47fa-00fb-08db2047ce68 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BJBLSZ5YlPQbYGB/IEFsSR2qoK6tjuJv24RGWfjPYnnBhq4pHMT7Oj9B9uGGqjzvLTNaSRUr1Vgpe8RKFWNxJVfVQcuX0IG2h4z5nGYhAXxndRqBiVMkPpns95vK7Y/J6W0jz0qx88QrEU2zozyG37QPdUCLL2WRKl3NCRb1RybtSGFcjk1Ht4skq/eamkBo1aiSkjst3G4yRJjANi1X4vlSVFfSgWYeN4CSqM5Z1jR6JtWh59S3xTU6Gp1erIBYFNZYmVdO+pfiIhmwtTfb+6/fB5h2poBwrDOW6KiLB6gfgYB7X1MQ4buHdZ528FiUjGfAisFpIqzqXg3dNB2/0fNd1WAinvGNaqpUnNEG6r4ux4nAwW6Hk/Jqo6+p31tig5Rx6+3WZXYfB0J2mBsNlJyfmF5akoq2Dhz/7qDV21UNOm7omVslBwUFopWWtaEK8GbX9npqxK95upj50WaBl3vsM+2/uaEWr4bXZNzT13Pt7G8vWVaYjkyhjR/OtusQishmrLCsyxhUtp8hD5byRqwV1TCIeP1zp20IKczXaIcb2IGuK+CvLEMLp2F0gvzJxsL/UdyltClutNmx81wsSv7WzXATJ1GTHZTEdvKTFyaFM9R1+1B+LutxSi5Kvvm4CFTDsjaBIixb1K+tn6LEhQ3x2aovSlGUSQf9R0lWS1pZGAWL/G0cB2uFvAHbp/IfkxWqpi7q7+6uvY6qRUSMtv00O76ZjNy3mSud0vm3aQH5EmPXoS2RHf413VIrxdbRILulWU/AP2C+gmb9tjXayg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0H3u+svFKZ1kWGX82WIdLmpXyy3cpSi5TvnT+/R63fn7i8zdL3XxHdII3XQLWQ8WwJV9qf+M+rQVDQfAsxY3GDP9FtPB4x4Vyj21a9CnBuQA4fSdrRrFgqa0r1hygPwesViMLq80L3jMkh5EP5DU7jc5knm9q784Az68LV2E5LTahIGmQbRrJwsfkidAIyIymdnXGYcBh/dINP2ufancu2w0ZVNepT4pbyDUZX/4Ga7GhoungDzPBU3g0qPRreWL1aqFjuWK6W0DTBR5OqtMwcUR2e+sO1XkQF1hh5v8/wuxrWzapjTsR6TZbngWbiGQVNQ957zzS/sTlyLKbekFc+5DtQ28iio3KZY4xq6s6JEUwdCGP0XJ2cDBMbNkzqMjSFbRn2Qe3YLQoF7EsDZ1yyP/WqMFMeJxFD/nw7xOQxhJw0rLh5ss3ZJXQ+9kCACIizhMcVterPON8XMt1oPIlk6mkd2y911O8hHzx4nLPcu/Brl+EK6MFRN9kr7G39WhVTSHRrjJkZstOUAA5L32p+VD5scO3v5nvFBh/cwW20EsAvjEjiZG3o/6JXKg2TwzB3O6g/1I++s3yak6vwZcykKUdDGt1WriK4rBPQ/OqbwU5u+O5VtTVtw2iUkRRYG9irQ81T4eq64nu5uqCWb6lz/gA67DsTqMCpuo0rvLtZL931pmdZ20xdqzddH1spsJiNoFexFlGlA0jhv0RYQZPQMTxFei4FosIbpBdVVeZDXKEBxbGNVuqR3xq22lXCpqfzIxSKrcMGKE2W9rasv8Zms5/QuFimI9VPLOPc86KQlbxOODc0pm05bNadw97yu3CLufGjBO73w3FW2ns1H6pRlAd3IJEY6qkSYSRQMnADIeHFmzcc64GgHaGBRByYhi98ys0Wzz5V+St4NW9pEkTCwZQ9JTvE4YinEs7C0gqgs4H7AU2LZ2HD6231d8OUc59p3UyockBwvzCoKbwrlilep8e4UpoI5gpn6z2U/mbMjLYJsowRIL0xDeMpBhhG7UVfXv7kJMkhWCbAWNGR9SMeffLJ9GydLkD96EdZSyWu6su26g7B2nbZadtjusWPYai8Ef7uYfq3axrqMcB1h7gk+HbHCRE7EHZHI6bTyd+bZSCTTkGMVi1oxNRyLp/8Ivrn80ruyLKkEp8Lcaac8M7g0Ld38plq6JAgWjLa9iXLLCkSnsjo4NRVmlOEDAp27zRC30SJ9fl1ajAokV0vs753JtPcEbujABFE3WPmMK55Wvmj8PRUOsueYLGnrLBDUfTWFtpOTQpHEp/ufXzJA+sRGxIxWSohAVmudL2DThwFq85R8LYFgDxV+Nyx//uxo6FIZhuEnvTTJnFP7KLJJWSuooEJByc5n+JjuI64mpvw5wrxbsRj5rASZUcXxGn9zwLSVDFb90XNZn8WVIr0PhCHu9G6Ki57Bc58uk78jbDWOlVzksPJzplACCAtUXEUQmfGpRHIkmVnlSBUo6ekyZtWN8jYtyFtNMOfmns2GHwphLhhcgdzAiz8IUUC1XX2W/F0PwKXEk1S47Fir8iM7Epz7oqSDtefBzB0O/lJVOw22Rvm1Zgqk//1+Zy0nskejTiSrTD0mnBZNTK6hMKnUfgw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86e0b62c-f4f3-47fa-00fb-08db2047ce68 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:38.3090 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ni/wo6H/GTBmecSTW8/rFR5IfFg4aHeSFyjOb2qfgZNP7UDTcITSTUfDSbHXcnloId6NuYBCcvee5rjfBTADwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Reorder some code to facilitate future work. No functional change. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 68 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 1dbcbd9..f33c67e 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -235,40 +235,6 @@ void hv_ghcb_msr_read(u64 msr, u64 *value) EXPORT_SYMBOL_GPL(hv_ghcb_msr_read); #endif -enum hv_isolation_type hv_get_isolation_type(void) -{ - if (!(ms_hyperv.priv_high & HV_ISOLATION)) - return HV_ISOLATION_TYPE_NONE; - return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b); -} -EXPORT_SYMBOL_GPL(hv_get_isolation_type); - -/* - * hv_is_isolation_supported - Check system runs in the Hyper-V - * isolation VM. - */ -bool hv_is_isolation_supported(void) -{ - if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) - return false; - - if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) - return false; - - return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE; -} - -DEFINE_STATIC_KEY_FALSE(isolation_type_snp); - -/* - * hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based - * isolation VM. - */ -bool hv_isolation_type_snp(void) -{ - return static_branch_unlikely(&isolation_type_snp); -} - /* * hv_mark_gpa_visibility - Set pages visible to host via hvcall. * @@ -387,3 +353,37 @@ void hv_unmap_memory(void *addr) { vunmap(addr); } + +enum hv_isolation_type hv_get_isolation_type(void) +{ + if (!(ms_hyperv.priv_high & HV_ISOLATION)) + return HV_ISOLATION_TYPE_NONE; + return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b); +} +EXPORT_SYMBOL_GPL(hv_get_isolation_type); + +/* + * hv_is_isolation_supported - Check system runs in the Hyper-V + * isolation VM. + */ +bool hv_is_isolation_supported(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + return false; + + if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) + return false; + + return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE; +} + +DEFINE_STATIC_KEY_FALSE(isolation_type_snp); + +/* + * hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based + * isolation VM. + */ +bool hv_isolation_type_snp(void) +{ + return static_branch_unlikely(&isolation_type_snp); +} From patchwork Thu Mar 9 02:40:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166726 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B79DFC678D5 for ; Thu, 9 Mar 2023 02:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjCIClq (ORCPT ); Wed, 8 Mar 2023 21:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjCICln (ORCPT ); Wed, 8 Mar 2023 21:41:43 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021026.outbound.protection.outlook.com [52.101.57.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C73AA242; Wed, 8 Mar 2023 18:41:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XX3IswRAnDEM5pvPZjoAm+mviXWexH99Zhw3+wZYTWky2d9uFhA7jyGjWHiQD2oEWURnJhtgaCdoOchCR8vmkpbk+jRcBwy/MG5Oqhfnw5yNfZRoCVblppijqJR5NAkQUSN7n0cPnOW/ZyDAJJnTCCUY0wHmw85S0TAn7r1CH4x4LveIv2ubNsqADu3k+Q7mCpEo901Vn8dMj090ddsKzKRf0OdbnsK8e5l/xn+AK2YN596bF2V02sIZPLyQFkiDoo21BhWvifo9s4Sa8tePzmIGY/CuKgtRmL+gLnhfavaB6urLjyp3gviP/yromMunpH9xZdif9tY/udpQWZQfvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WMpXjLd+UjKJmPXYudC0MTw+Yv2SaNNAfvRbowIeYws=; b=BXGG+cScghzVfSI/OdjxMgr0UU8u/+J/LcwnIgQQOv0pPw8XcVPLUHKGuIKI0mlfpwGqMx5dmmcJ9BhQg0J+ccjPhg8ep+O9WM+GkqQCtPmnrUnLTYn6xp6A323y26o5+GXGlKCxqNGtQcy4GX+l8J3C+Bnt2H5L2cjG5h8HHIGk9RyrbWdx9SOZwdVWc5qukprqM65PrYHwjghksgqkeD0RRyR2r+FZZcDUL3iktJDDgF41w6J+g4/rgnlddCyVm4+BMEPWDnNY1rm8LQdkpwd2HP6iRxiYIZvGAUA1O62pDkLtCYxaEKQ4H0PZhfprE7GMNuKjqfarqcMYDwezZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WMpXjLd+UjKJmPXYudC0MTw+Yv2SaNNAfvRbowIeYws=; b=Y4JZCE6u01xeEcsFTQvpASEbpqo4hC/qjNQcngpO7BfAx0a9uVZQW3MVzh4UiFPGKEJ7kILA56bXiPYc7ewVvxBy3rqLY4QcE/fJZtdDfqtIglBf0Y5bmWQrSPp1F0mAiNr3+ZbAMvG5YWc6KtSX9iHw1yXwn0TNmbZ8h4/Sw8Y= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:40 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:40 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 03/13] Drivers: hv: Explicitly request decrypted in vmap_pfn() calls Date: Wed, 8 Mar 2023 18:40:04 -0800 Message-Id: <1678329614-3482-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: a49cc182-4b56-40fd-6e80-08db2047cfba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OZABL/s18pfGYE0i16VfQkZZKj6LqpeFBcYZx6kwZLI3vpthFQ5N8+Pq5eNJE0ZoJKrjPftE3ICFslD8rHb170ziI4ep5eLWf7GbSIQk93Fdkxbqc7Hx/kOY4XssGSCi9NtTBga/0/Z6Eg30rJFIk7ZVK2OAUUYd3lNTcCJjhZMXkRJrRsYoYiC6f4ShFzZz5foRV0n3VOOG3une7zqDxCtxOwW5pf+qVvsgRe8hMNp3AHhyQzU6/LtdLTOP8JUZfqVXt5Xt+q4wWo+lyJN8TwbWnN+PfBlH6SLQnTbyldA4dXOZ0bVZ1MMhGkFzpRrb0HSxUnNmnO4/g1QXmFRJBpGFXQRBy2aMv9jDhAPYsToPuWlRMqQFQV3TSkYto8s6I6qklQguVfL6aHZXa0dRLWlhZwYJbh6Cy4fwPQlGSlH7SkVmFLzIVco1UwyvJ36LJArzlcwyPl+aQUIE/ej+rJI9K9woRgwjao5grKd9u+WXSglYBmPHl7S18ULVCwS7oPGWtM9btEQhyOgP66EhU8gn5TZCBE0XF1XARPvc/RjEay6uByD8d/2y2HOBoFLUtw94+E0bSpoDBkLvLHk9kIoAdw0//0nexKRBZ753kbht5fxgpZrSlqXXitBWkZkfKkBV2AGtw5VHgniK/9z76kQCxO1URSQoFZD/KIVAt4fR+4J2zMpgn7WXu/aKJFi1z7Ut8jCNpS1twZCMalH9UIJbmDBDJT3QNlY0ZXvkPJwPSMOL4VLWAGqj/KpDkK723UtWLNxLSyB6+OP5TEC7YQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HErpfInEtW/PFb9bgO/DszZaIaCmT4ave17VR/z+Ph8ly/3qux/XKKgECKhKswbQ46lDFoGk8epk1FMVezxEeDZPAdLrptQbNFC26dC7gqZIaDQYT5izeRF5g0hLEfMknKG3rnpPVRzbrsVcIkg30vHzZcNINveXXAWosLIXSFsGqffr0iIMWrjjieX+xh9HyddvON8fM34cQzTPgVVPGocwaW6DcND875iZeXWD8zbanCPKpaMU4DruMV/p/OwLUIX8k3R4Ob9ZfNJAFvMGrdzOcr1g70WL28H4dFv1RlAKgmUk5dJMsPYf55jlY6WAZlSCffvz+qox8MjLQ8FCOHeqjNBrqovsVKzvqssgN5vMJZAsymAau6JMwIcb6x+S87oRi70lmLKKNff7w1ifnzpNC4zSYfqvwXG6EAlJ4oyBFF71ckj5kCIGIYE5hX2rVy8Aklf1tV8Y/u7JxBsujKWXL5kQPe/pkfOlo0F5kZDNm3+uZM6EJifu5bD54BOrpIw90V9m+I852vTm5QfRPfIUWTI9XCYBXYKqVojmaFrmcKS0Oxx7BFaJobNCQeWR2w6idw+hCAX16HG2t2p1W0ZMMmkznXITd98Zu6ZPhqaloBQTe8zbNHZ6YFDiuY+o+1rbYZMQuYYZ+4p1J+CXoKHG89n0SPNu+zc/S5adiJvl5VzDlW0eczxikjVqMJoE7Zbjh/bA5RiWBi7Eikp/jS9+BYcD6ePh84RR5YvqhxGZkgbh8DqKe1zHYpxB6uZXtSrZXnVa65Qsjv8Ht5w3//NOOT2HRizpIuT+JqYH4iKdLnw5yadaFOZ0x0xhVFtEhe1e2+rltQXHtEbJBz/zd2SugPKvF4k+iiSiXP53aZxQEGEFovpiD+GkDKXTJO6/QFc4r9XRpYryVVl8DC73+sHZdqlymZbeCpSVMYNtws+r/Qw0yGaWAscFJYz/hgld1i33l1zdW9HjYLmnlF8Uxox8KpbnDfNHUTk309E1CCghhJqUyV0jIZL6A0hUJIWxpSgBPjDLdmfNxMvcDb+mEk5cnGcXq7UwwYYmuHMd8WtImcy78Cz2V2MNYwH2mbD2Gjwlw8De9c5a2jI/w7vFCPLN6aaDkQe6Jw9mCVdRN1UC0t2ALeXFHPDdR9njQ9+vu8J0ZT82m710Ra8jfapX7gsNfITFCIT71KTygTFWVZTWbfKSf2UmNofL9kcgRmnkgc/GyrEuhYvKe7g+dMNObr8pdoR5YfvNm+hfQ0m78NVcRBQoqxM7z0817roaxqddNz44K+W3AfYdxBoqZBopUZq0XA3dN7pd/vilS1bfDwOX+1dTMduiHxzinbZT489P4PDMs0Voxir/+ONTSfXIjvJvGmJwBqsnqWIO0xPvtcLldFvUwFi/tsakdQwh6UY7Rp7w6o6awGLJWeSKNSlvQZq/qjLqPuedYKQTaZQmm7eogFdvaL6kWr1Ui6qZIO1cAPxjJtBSzd1ZALPVZBsPAq59ou16oVXrP3PEpEMwAD+BHeqIYtWQ2jOydyR4xgTDVYcQhwxzohYAiPL1MoBGU1ObQ059xP372Up9DvivhslTP2x1lOHVb+wqwFX5m4P0rRGtkfg10f/CSsU+Uwvfzw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a49cc182-4b56-40fd-6e80-08db2047cfba X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:40.4800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lX10i8QRYpeAyKNmzAxxJbqS05e2rf053Ccw70/wyz0aHd0XWRvDLjHRJMkFFcabK/X/hzrwy2qqop7EvHOSaw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Update vmap_pfn() calls to explicitly request that the mapping be for decrypted access to the memory. There's no change in functionality since the PFNs passed to vmap_pfn() are above the shared_gpa_boundary, implicitly producing a decrypted mapping. But explicitly requesting "decrypted" allows the code to work before and after changes that cause vmap_pfn() to mask the PFNs to being below the shared_gpa_boundary. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 2 +- drivers/hv/ring_buffer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index f33c67e..5648efb 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -343,7 +343,7 @@ void *hv_map_memory(void *addr, unsigned long size) pfns[i] = vmalloc_to_pfn(addr + i * PAGE_SIZE) + (ms_hyperv.shared_gpa_boundary >> PAGE_SHIFT); - vaddr = vmap_pfn(pfns, size / PAGE_SIZE, PAGE_KERNEL_IO); + vaddr = vmap_pfn(pfns, size / PAGE_SIZE, pgprot_decrypted(PAGE_KERNEL)); kfree(pfns); return vaddr; diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index c6692fd..2111e97 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -211,7 +211,7 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, ring_info->ring_buffer = (struct hv_ring_buffer *) vmap_pfn(pfns_wraparound, page_cnt * 2 - 1, - PAGE_KERNEL); + pgprot_decrypted(PAGE_KERNEL)); kfree(pfns_wraparound); if (!ring_info->ring_buffer) From patchwork Thu Mar 9 02:40:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166727 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 718CCC6FD1C for ; Thu, 9 Mar 2023 02:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbjCIClw (ORCPT ); Wed, 8 Mar 2023 21:41:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbjCIClq (ORCPT ); Wed, 8 Mar 2023 21:41:46 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021020.outbound.protection.outlook.com [52.101.57.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43035C9C17; Wed, 8 Mar 2023 18:41:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kVFohgUgCQOW2y4vGA8maAo/0xSjTSmN0/lNTX4KfK0C+bc4+mN3c9UWPhxw07wZWlqsv5q+E7YkxUj2lZx/GFIXXJZBheFHfD/wJb5msHJ23BDJ7G/STvKwu+EAsvNCJe3QkM94MmvSyAJlHsTURWoTBnEOiBQHCWuxdxc9bHMbvswOFqKOTIkPFIM2vibaujxyvAjJcoU3Oq/tDnbH9b4BDYJ92EBuwsfNftbkmByFpjDGchBtXmBz3GisIT22UqZSrXLfSdRUqkneldL5BaREVLXsFsDOQi2XEFHS8zFjmCb4wgUSTLXAzPiGYRLrHOywxYfJD5xp+P1/Msj+yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+vVCdaTFGXtkZXyLDOxaOfi/6PmqIHiJZMVI3+wmvEE=; b=kbYcka06ayGtLQ1t6YiFfUu0h5TRN7AjhAkyky7h4YTIfDtag7pzVINiXSaS7T5wMKo4tJhkcSmhvxV+8BHE4kuh4kbce+TYd/uMfdr/dtMIE41g+WB9DmrVmiGnx08hQbDQnxC4OdGTVpeRgWN1OYt3AFERezg4cMlj4MEDY0WV7hpPloqKtIFQcrLK+bRP1/PDvFhIrAmGXIf/QBA4d6aaelrFzjyDVcVEroNvzRC98nP0fTZjesCYyxSA8zVAdm7LAOwX2r/8JD2nMMquV7db4vIbUCslZttlnqsXijonOLS/ATq873JyDo5godQQZF2GDszM+lxwV0gSLwNIsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+vVCdaTFGXtkZXyLDOxaOfi/6PmqIHiJZMVI3+wmvEE=; b=fIb7tzXlQYvbp2bRl8y1jQmuLIW6lx8prZEnNISSBQEv7IzYtBgXMExFNHJJo15hjreXsnFUJ9+fNRTR6B7NM8eg1P9OMUCOH2mSNXUhWnvB/Vp6FWV60yNqPziFtfWuVOZuZ9S5MU0d1a72/nb0Uk8bQjIcTU7HRkO/Otso0A4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:42 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:42 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 04/13] x86/mm: Handle decryption/re-encryption of bss_decrypted consistently Date: Wed, 8 Mar 2023 18:40:05 -0800 Message-Id: <1678329614-3482-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: 02555359-c78f-4286-8dc1-08db2047d108 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qYc7DGq4fKEe8gyeZXG/6NO8MxJ0d9obDl4zufaZ/GIvjF7cx1PGx5SiYyJAtqMn8yON4cPiqyb5jAMBaib0jiK6FpqXB5PnmAj9jVRWB+YSkptrSvsHAq0LfaRpFBkWPdi1XoGnSZsfxEEgEahHvNWMdvUIXoVHuKbF9sXHXwnFzlJ6az5BYdiaf4m+YTxLldE1aADae8Ryuqpp8w0OhdNDmj9yU+9XZb67BMUtSVTnfzG02jxudDK7CvB2PlbKzO+e2Cv7L6LesQ6JkLWyuX8E4ztpfWKCh3oAnuNCKXSeJ8+3d+MeHvs8S1VFfisKszYx2C3U1v6UUKT2OF110Qy/j5H5OfC3rKeiBu7RBCCkyQN527jPfQen1Pa+GknEfSY4hhxRraRncTDTU1Maexx1PZ2WK/yJ/LGQC/ag0ak84SmRj4lJl/wcvV/k0MDzQXvfBr+rXkjhUbBYnr6cBXWDZrDS0Wz1fGdzaMRYEcC6NPlGsrd5uV7muMCkatA55ywxarcMwSCfM4zCy8FSyePGkpLwnG/CXB5N4AsBMGzSjFOE4t/2oc5k1ospC9puJczwovpMo0ljRmlpJ7Q/KXVLgr6fEb63ggB6WavnG2oaSQqBemCEmrttP1K6hAZ6B71vLhYQot2kIZeHoSn1XC7R7/zt8bJm/bieDdPMrqjZt8Jaziovi5hJ8wWrF4XrB9kLkhYJ7ggmZ+HzP5a8+I/22K7CxoWZAEBjH8FtXrurrqelP/JJ0rLFhIynD3uafxLD3GxlIztJdi2pU45StQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mun6Pw4MLTQr50T/vTFw6QOFATLN2EZykFB4UrLtc+j7dooJGPv+eHYCXEuBoxG/YXoJV0kMn49n6xlqktur1wll9ENoCMDR6KyuLMYbf7OMu94dsCu24hSTPfiDSisWf012Tz33fM7WOEsXE55HtX2QFuq7aYTb+9tGBmuKmrfSNYs4gOIQQNsbVZLi7pLkcwLyGU05dw4CqxYT/1FmfwRYEYULZ04fvUC7B5s0apaL6iexXFXSpgN7fJWsVjmKSVzm5FKwNQWB5CRdxkGEhSWBh6R1XiJnCH9+zJLYoKRLC4UUZeo+waq7OcDZgilef8Ey6GyKAT+ppZHnrqE4rURM83Ur4h5Db1XlyHf3XLTTH5hWI70xH+ukm9Qyo79C5V5i+aZvkwWHSDTOz5YR5IHI9oTKO/0/fT1u9+xDEtxpC9QWs7cbYRqhGzvVnkzApGfXZlY0nsxEHgYF6qRkg2TnUGJunSGqYVk9WvxN4YzApoQ3XXr1AzxUaeIj+M+DX7OTTPTNvcE+5DdzNOBrvmzpCn6IxdFe9waqCDRARgZopMTjrKuHQAAqSWzzyoS6NByxYTef50fZh39UZi0T9fiJQOFiSaetMQMFLkUOsTLDPLiQzO6cIgOzDd7XUCUXPTR0kYdZHcOTRHm+Jw/4Yg7/0KMCvpOMe2y1dahltxaCTVyxxk8uq/ELf+RZnq9VvifOtlGs3sc50OXntQNdYADEnQjCz8p6MDPRn34AUODdlBBFAwRNFKvA9WukI/mEuAXvRaAy6C2yDFa/SkizdbGvId7Ik4Oihgd1M3L0b3cquw78h5UUSa0IreSvUXKpPE+ciDxSG3eKbcYPBdvAzOsi16yUPrtnKC7Y57ZTDh9XJ/zVB4wEsmOUt/X0iMswTd4YNV6sjnRqErMiVBVtJcYygnUhp0TTTx/8tQhE+YcI4q5NDFSw80M6Qb/oaLbCRGcmOHa9RVqav/01eIHTBgO0833jAOlSizyjokLywuEAPXmHZPJ9BR3EJWJMyAJDqzuww0a35dPAUocSdXASvUqXddyQOwn6k7Q/zb/chgeY/xbI+ctGIDFmuBh2QrUE8y2cvIXscpeccnXmi+XN7ZkPRf3ebIveYX6fhr+97UciWzqOn6PN1v4lFxqjnRZqzQb9lcQhHQpe2jK5oRZf0Sd3FDIs1hG1pWmuz5AOivjlRmcvuBrAAZKyKlHYoTBwXRjNHF4Ab+Ou8gbYAVoNKwv2MciONPFcXM5etkk+lkf7QPAy4ZTOyH5b5vK+JlLVx3Gdn3ikaqYDqmovujAAO0qHH/xLLt1ZxyFvtHdkqkj+/jrFNfJSlZutCxjx3m2VPQEFZjBI7Di59nR+QNXpD3xqIcgHMp2uGOlkdq/yzPiG1PWVGMYThmssuRwNx/bsHDzK7vVBGGg4Q3VHN6sqtjbdQnidiZAR/5tcMWh+t8kTcXiLi32iqBAisFjq1FIhT6c+UripReb+eX7dH5ox0cnsmlJDNpvOAV4XLkrXJz97CQmsvsr+DduOog6pMMY2DZyYY+FnP1WXKmF9Ght/rmXrqAx6mF4+zezy9QE8spqUEprtMEpj3xrcDW23ap7YBFsXRz/BzpVUeNjIEiYc/g== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02555359-c78f-4286-8dc1-08db2047d108 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:42.6541 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uDx/vAuCUrX8CCm+rCLcH57jcs+t+FmhfqUY7HWEV2Tz/GCD4QEK2kTXGtk5u5h49o7g10P/fOg2UZIZHswPpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org sme_postprocess_startup() decrypts the bss_decrypted section when sme_me_mask is non-zero. mem_encrypt_free_decrypted_mem() re-encrypts the unused portion based on CC_ATTR_MEM_ENCRYPT. In a Hyper-V guest VM using vTOM, these conditions are not equivalent as sme_me_mask is always zero when using vTOM. Consequently, mem_encrypt_free_decrypted_mem() attempts to re-encrypt memory that was never decrypted. So check sme_me_mask in mem_encrypt_free_decrypted_mem() too. Hyper-V guests using vTOM don't need the bss_decrypted section to be decrypted, so skipping the decryption/re-encryption doesn't cause a problem. Signed-off-by: Michael Kelley Reviewed-by: Tom Lendacky --- arch/x86/mm/mem_encrypt_amd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 9c4d8db..e0b51c0 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -513,10 +513,14 @@ void __init mem_encrypt_free_decrypted_mem(void) npages = (vaddr_end - vaddr) >> PAGE_SHIFT; /* - * The unused memory range was mapped decrypted, change the encryption - * attribute from decrypted to encrypted before freeing it. + * If the unused memory range was mapped decrypted, change the encryption + * attribute from decrypted to encrypted before freeing it. Base the + * re-encryption on the same condition used for the decryption in + * sme_postprocess_startup(). Higher level abstractions, such as + * CC_ATTR_MEM_ENCRYPT, aren't necessarily equivalent in a Hyper-V VM + * using vTOM, where sme_me_mask is always zero. */ - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { + if (sme_me_mask) { r = set_memory_encrypted(vaddr, npages); if (r) { pr_warn("failed to free unused decrypted pages\n"); From patchwork Thu Mar 9 02:40:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166728 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C8B0C6FD1C for ; Thu, 9 Mar 2023 02:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbjCICmG (ORCPT ); Wed, 8 Mar 2023 21:42:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjCIClt (ORCPT ); Wed, 8 Mar 2023 21:41:49 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021020.outbound.protection.outlook.com [52.101.57.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20356C9C08; Wed, 8 Mar 2023 18:41:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fFWjvHGZ15L7iJfEvlpF5vl5Zn17GCcWA3VLmu+W7jf5tYXM1XESIgrEnD/QTRG84tWI8LAXA5luxWOtI/IRdEqn/TFwy9n6KQTBXwDGlgdh3cNAvn0g1k/FSnN583Hvf9mQCCsfE8+M/+a1PuhIejlBA6suHwYm9Ef7E+aOpdHmcN5pl1hzpa6Xbg6bMVi/KP9BRRKJwBA7/O5nPDrNpX8SWUpTjJo1SweGFv61uE+q+ffWGGiu05ha+m/rEGVyBfKK9StSogICuO2KV0qV/6Zwn8p9mNhvkYNdRPuiFt8ZMlBBpfQgcqpS4GtGciC+N/n0p1IRuSseuoW1jeqKdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hgpLwgl5yyhxkm8Wh28XIUSfBNAlS6z8nmd7fLV0eRI=; b=g3QmD/vsUczty2LCy0zv+QZriK2Mj76OUXkFxd1Qrf2H661j6skpwGkBmPqna2QtwsR0JP7kmuHXn0QEs6P13rqngxw/ooy3Z+1b4Go17BWabBR40rJNIrbyuW86HOq+og8L+TRH3EUgZZS4JezLOADolYVI3za8tzBPHUdcsokhLz8fi8+HkBk8GQe6cff2u7Q25dYn6ThhhemhtZnIdAb/RIPHfjzc4qmqlc7KuRpmZtGu9ELU371NR+FlNZ/12tcxAhIYmOP2XJxlCzlnAkP/cN0ZtINWDfCRFjHS9l2pmel194oyTdCugsrLNlIwosnmyj5HVIQCrujGq+B4bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hgpLwgl5yyhxkm8Wh28XIUSfBNAlS6z8nmd7fLV0eRI=; b=OGvKe9LYmIKjbz62uV1gqg8VMECVugAgiQmR1aY6kOu2Y41xbt5okerUCRn+H49jg04MdCCKcUjg2FcMrkZg8Qk7CINx9mW0DqGkalDS5cojJaPVF+G2qHE20tNEBv2eaU/ndQxcBa98SYjXPoLmbNDcP/SORI9D/QvQ4VJZnSY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:45 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:45 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 05/13] init: Call mem_encrypt_init() after Hyper-V hypercall init is done Date: Wed, 8 Mar 2023 18:40:06 -0800 Message-Id: <1678329614-3482-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: 17f78769-4eba-486b-03fa-08db2047d24f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bG7JGgymHzzoTssk5vNlGSTTlKfgcBu0pSyCYXc8085yzIiVElBkXanUKnBMQM1XSAAmkpZ5CrudaqMYerVGmlsZQWeUGm7JTkSVwMtlDLHmKBVBOfIEmiXSyno0CUTl3s6fZ6zIi9ExdjEqTERglxfk1wiPECf6BqAUuS3IpY9wrHpFD9UKVsvEdf5n4l/FmluWuHU7ov/OxQqyd4SzVvqaTiYAhIgZBEwryKckuGgNW8l0KO+R+XjQGvHF6RMAWb7RmQoa7E+I9ItZpWrmZgU3IlNT+dcItLLkksKyVbnipXy7kKA8o3Txf9oFMyvI243Edx5sXl+V9DR2EOplQR+ddJBjR2MxWH4JCkQcAoTWeMEPJ1SSaicw7IJnzcDOarpNyfw9rHWjQ2TqzdyS6pByq56oQ/Ln/rowrDrCzXcBnlX9UGl860/gEjpfsirb3yFI74gfWubvH9JycweU64UNHzckyuGuK459HAmy+t0pxC7kgBSjlVZKRXB6c66uXBkDXtoqNazk7c718EuLxclZX9E6YUYfy41ENoTEagqfTuoqAjn+dDFnY0ch68O9Q500SHac+Vwtad98lkbttFNRaLkFlqiYqrDh3rLTh86EpxEu7kI8Lm3fwXh3AG7D9w1e4d3rcoXJ46ShLuq5vzoHE8OdJzB5cMQGhp/tGPsLPWvvhabmRNBdsxLRpChma31VuiytO05u71gg4HhsQpjpr2OT8rWsoRlJR7gvr2VBNIwDx5bM2v9wP91FEJ3xxZzoEW/J/woYekNwqh0ehQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dubR/IDeoAP+fNAFJtYzlsmzQBqsJORjXplEXP+SLgpLdyOKkF4GfNS6S2ZEDJj83Qv6Zf51L2ZjVRZN8HusTgxbQqp6N9HR7qWIJpj+lY5cyZcP1oaWe1oOkAyhrCSZJC6I6peePqt05E6q+5zH9fTfAZHr3b4FYSCPcuJTtJI5lANRCvciIV852IVVeGrddefNyCuCHyPhR25nXVgdvdncfDae9ksCVQ0z7AHbZkGmQPc871VnXy13iEXLKhpplyVcLXmWZVBb0IIoBxSsL2MnG3PcGUDwejTSXSkh3wkYUxMTGnpYkUvw6hBqZNxwvLRWqZJJThlZp7643iwDRQxV7hxZZ/J616n9ZV7UdO26yH78rR86EWgdrchg3HgtNdmFeK0OKqddkp9Ov09FnJDLTjfol9vvctcmP59HbuX8AduZ9J2ZdG4dNQ771UIV7pfdn3fahrbFXlMY7xzlcq6pYQ/HzgK2Z4pOCDlewsRfK2ubFh5E0h5a0rJwxdmfTRiuVv4ncpBcfmezOFO7UERuXgpuCyEbUOUT1NEBmAYaSC7foyz9+oHhASX8+FOmZwT0/BzgQD3vNNYqm/dudU+HLyF0lkVuYioslsdf+q09dFuXJIA2zC0RnsrNi7R2buy6HJMGZwvP507UWGInnCVWh+aoAX8qZ5X6r2zfWP3HcbUJuPv0Zm9RjGkPGyEayb+od/mEcNZRj6sfQacPK+QpbBj7nzBGVCOtOZFew5FakcRj0mVp1zvLKVnznnTnYBlTjbM36WZiPZDIH+ePC9pi3lXQ88RXg/MyT7dX0HQNGntW+vBvzxXEht5odOETdM7eXZuoQQD+d20j4/82CEfE2uDeOhYtxKgkbTYfkif5h5YWcb+Xjeopd15dRDnJPQXnyK+paBnIXL6WCbrWFwDh4vsaqq2PAKQsWTSt3Dv2PVkBHmTXpwlNu+thuzwCzSli0pZKWXqh68GKZ8nI9zltFB6g1mn6Lc7gIbn6vHSRlO/Ovw0/j+1vUOk4+sMg3izPTgIZaDZEc8/WxhCeHTXvYrPNp3oNWYAn96GPS8Na4aDXRSZKq04z9APS3y6R8fIyQUWfiI1x9znLq/lLGocSlR4JE6MAdP3FeQsJVApn5bVIf7Q3faqn3XEYHZ+lE4e6N8G6q6JSBxQ94lD09v73Qkzrs/YdgZB0ojuB+bnZZ0Uiv684KR6zVSHwjn7o6ciPPEV8qes6wojQ8TEvCqYQOaJAVoIXAtBsYOnqCW3mSEI4v7dxcYUy22QwoXaiCYDExYjQhk1sijTGtWI/iwkNZRn1J9Am061LMHZDYrb3R9aX74gmV7a2lOZ3DuM1fOsb9Kqtn+8ytUM+kfbw7jNGRoySEm7IN82wGaCBCCzupten7YlBx5uZ/Hcf7o9WKvS9sx53RJGQZUlRCTKAp7jOnjpAzje3hC2ii99offba7tjiV2P7Ys2yFEux19egdjpRwWrUSvCXZ2dl7AiYdI4iZtxNoT3ND3U30jIz7NrLWzls/mxbOEwsd1H0et/xYS7L8LITHJXyAi7xngvlNN5jzwOyhChLSrPR2s9bqdKpQ8+/EGYa89hXFqUaEW2Zmn4rJ/tPxwTbM0BtDW2Deg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17f78769-4eba-486b-03fa-08db2047d24f X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:44.8248 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0GFPFUdL3yklgQ0FzMRaMrblG9rylVkpc93gMcIpRQIQDUSAYSPP5T4jfptiwBIuy+AFIF9uUgfsp8tW7/WeJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Full Hyper-V initialization, including support for hypercalls, is done as an apic_post_init callback via late_time_init(). mem_encrypt_init() needs to make hypercalls when it marks swiotlb memory as decrypted. But mem_encrypt_init() is currently called a few lines before late_time_init(), so the hypercalls don't work. Fix this by moving mem_encrypt_init() after late_time_init() and related clock initializations. The intervening initializations don't do any I/O that requires the swiotlb, so moving mem_encrypt_init() slightly later has no impact. Signed-off-by: Michael Kelley Reviewed-by: Tom Lendacky --- init/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/init/main.c b/init/main.c index 4425d17..7e9c0ca 100644 --- a/init/main.c +++ b/init/main.c @@ -1088,14 +1088,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) */ locking_selftest(); - /* - * This needs to be called before any devices perform DMA - * operations that might use the SWIOTLB bounce buffers. It will - * mark the bounce buffers as decrypted so that their usage will - * not cause "plain-text" data to be decrypted when accessed. - */ - mem_encrypt_init(); - #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { @@ -1112,6 +1104,17 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) late_time_init(); sched_clock_init(); calibrate_delay(); + + /* + * This needs to be called before any devices perform DMA + * operations that might use the SWIOTLB bounce buffers. It will + * mark the bounce buffers as decrypted so that their usage will + * not cause "plain-text" data to be decrypted when accessed. It + * must be called after late_time_init() so that Hyper-V x86/x64 + * hypercalls work when the SWIOTLB bounce buffers are decrypted. + */ + mem_encrypt_init(); + pid_idr_init(); anon_vma_init(); #ifdef CONFIG_X86 From patchwork Thu Mar 9 02:40:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166737 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4EC1C6FD1C for ; Thu, 9 Mar 2023 02:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjCICnN (ORCPT ); Wed, 8 Mar 2023 21:43:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbjCICmV (ORCPT ); Wed, 8 Mar 2023 21:42:21 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021020.outbound.protection.outlook.com [52.101.57.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59B6BD13D2; Wed, 8 Mar 2023 18:41:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0zzP5jXuHtnTR2JT1jzA41owX8L7P4B5r70BbDI8OXyKt7sWIMnBlP8AzvnCneZtpQtW2lZJ6B9HtUUQ5DT/0Ft6lTrMFFVGmSliUJjAuUFEov6Zh8a0o8RKQRXH5h82FwHiklCUqNQ4kQOL0sS4WzsXW2HeLp1Rm6a0dHplwEGrzweDyJeNvqlxJSPfad/rQg/K6v2W9s9075rHo6SKKPBKBE1dj+1y7QgxQpNl8XwWNCKWD+ZIW06AdpesvrA1Zubjghfo+i6YjYLcxSyEG5VKBy9QiVKTqHNiSLJFlXec+gc5Or3wzCnviL3mb2GYx8AzXJCIysvntoQtOKWXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=74/fRsdowhfp4ehzrPV2idoyUtqmbCaOo58WsUVvjjw=; b=Xpq+B2hQ56+YBVwXdqiEaSGSuT4u/aAfjJGzrAzkpL8ykHz8RNuFbaDk2yvD/rzsL34rUvz7UTKCKFpQsnUq39Nipj3VCPkQKd1aKb7ADRaDBPdbSGIac/JjrnS8nQGQpunwhDlUUnYq6CgKV5x7OIGIN0021fPLWhDJXPwMk73bGztb9KTr0WaXkDaFmHFY20cU5JMReMh5fYA5jZ2akVaWJeV99oGL+mAQeJhgDC/dxLLVOWkfqV1KK69Mid1a4ZiNBGvk1XOqlGgnBNaLz2Z7sfLyF6tNT96zF3KJkxH8lzjbakKjyOaujaOS6V+EXSoLdIlvdPRKnad5Te70Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=74/fRsdowhfp4ehzrPV2idoyUtqmbCaOo58WsUVvjjw=; b=H/15VmmWCI7lPfSJxlPniclisTrZ9PDiHE/mdZxl6eB7Zp/rtRpJm7THbS21Tq/dAy3uquCv8zJEgng2Hv/B4htJmolfEl0xbCmwKTH+juUIEAa/pDeAqOs0jr9RwDAFDW98A00gOdA0Y08WRj35DcipYMMQg87mI1t4VyKO8GQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:47 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:47 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 06/13] x86/hyperv: Change vTOM handling to use standard coco mechanisms Date: Wed, 8 Mar 2023 18:40:07 -0800 Message-Id: <1678329614-3482-7-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: dfe9bcc0-9b30-4811-014c-08db2047d39d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qhPWzA36iBA1w2sFzGu0L1/xemfOXZkv1RKge4UUi9o8Q2NIPTjsagXqOSwEcKFl/+Chzc+bcp48ehZK4ftI12A5b3AUn12MJjSsWQNr7JPeYxrIUxDhf2JGPbKP+vmTZNbagpsJ41NycJMn7UqdGXyfVyO801vRTUlREaKnDPLsWp/OonRAu7D+pSiw9PWrl4oz42Q8KZlAlKOq3IOzmJenktLnYTZcj+UmCOQ1guBjJGBrqSlZGMS9CdPfX3wEG8PEfjctfI1eXsKD3JIVIV6kkrstWBVvAw1Ax4P8rnYE49fsIAI92z/mKStnaAYBMOUvO8v2XDbjIjiZ5J/j16fLnY/An1WUyLuOOdnUeWbzNS51/i16/vzdQvOf0lupKYhtr8fIIYIHw4wLWMqP+ZbKH3OBaS+2hOFPVqpvDx4zlbOaTisUUMpAhhHKJXZjQbij2P9nxkDcRqRXMkvHxtBt7LhUsGU4I/skuPNTjTIwxqRgGdjFOpOklzgVWzkKG39hdB50bXX4R87IRO6ME2IzxfYw5INF2NptpMN4mxEnz6a2fABpoL7KrINtSCfdQmWwOyIin/pUmYS1ggPegjchHYMDLCLVVwr81rWF/mNv084K3K5f2C7eXPLopSQOx/Mfvsr4CNe7OKoAV0v0XVG81TyXvHtcS8cFnhSnEfR8JVnk4IkVaBV8oYXiTYMJ9dibZp6yNyUT0itnLibAd213bkDzqF2QJdXynjT2kdGZPwz6qoM6DcaGTJ0Qjd3U7uPE4JSena2llYEznBijZZEEXXQFvthDRgDdXyXf6vc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(66899018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(966005)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(30864003)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +DFV7cIlVVtGoabSF0yLnNetHP0/4MvXfkVdszf3G4ZZiYOFzq5oOvWQYmUrKkTyQPCPnAxpWT/mPhmtQWW1moImcjKKckPIy0CePtLKU/eW8dDDNKlbG0kwrUVVJwp9Lanijyoxacp997IfdRV0W2cgqJpb8kOmB/xg7qHsISm+F5ggvhtv5yLtNqnspzZTewvhXRUDbNEEYd6MfewaY8pTR7W8p9+73s6obXQT/jnXXeSAMJK1YDwmxuM3yrR6bhWVxFVnw8h9D8rs7hriHph0Qa7rGqcyjylELS365q3JB/UVle8n48soKIkK8QqV44noNmgDfqbcbxa+LSt32V9uyQAqY67z+vsAorex4OI+qJkPFnLQWf8aJurQBzKzfd9TdeUvmiISRTbKhIVr4imP+MA1Kxgo7pEmFRsVSWGBPVtAoK5hno3DLB9CRcZdVpRl/ZFKha8+8wjgZqSPrQpqifuaqKz1VmjMr4DxFnq7MXqLzqE1y7imNcVdsXfO3DEyMHIlNe5aNB/PDFSxo9P6q8Xbey/iJvghE6B4Kvsi1Qy+65UGLf/nuOxDrADT20Ym0hL9fltOuU/TUuC7mWUBbLvZcqBhkQwfuW7m//YriRqVL82EK6SH66atgV/HctlZiV85lcPbk5HUiJQdcpofv7NUBpgdvwY4HNrhtwk7QIoVtDG7wXN4o7huP/I3SavSjBQrHLT/TQ8ydcD2pNxuurDTSAEP8TgalrlnmBLWJzJxAGtrYL34Q9jsCPqj8rhGq7fO+rQ5ol3np67sOBJJDVcwQw7wfqiOVlPc4PASBSgYLq8W65xsa2cPCuo6T51BVvS+mnny3575SqnO7YInyrUSpplAAAmrFJtyxV6t51trsYjwrD8ryYmJ9ZXfebDze71pVSqPcDk8kOl5M7ZTRk1+iHku3IT8Nq6aqsdRULKDjYZ8Cm16Hz9cYKFfFohfTOMbmTqFxDhG4183SPxpI5tHJnyQY4pw63uYejRdyp8VDakUHT0wY68sFUblL5njeHSpleyiFRrVDG67/yQKdRRWiRr0bcc42AoGfLHE2ii9K9/qe9MSyG9c0cDNeL5RcpkKxI8LV1idInIw/urA/3grSg9XAww/U0GWIOOaTaycESDGL2vI4rs3GxM2uAshEGujQkXBG80y0x6Wm6yzlrjyTGLwe/qUH+s7gImp9lQkL4rNuI2cV9HhCeVoakRejL5heEmtUppB3ncl0i6NnrBdIwuDi6FD2zTd6RjHbKUKl/le9ph7j9umj80n8IUgC8QQ99tMqIs60lbcYwoIJuSd26En5IMFnYc8iN7CJx6twDbIyxpDCAQAb+6ipuqkbGrL4LtMzUUcpb0cG/2dR2H1FE5MhQb40+LL18Yn2GcPvtn8YOm7H8AFkp8rxC2SAeFEpfZHYrlH2cP6tnS1kxM2WbwvBvcNCO8GsZXtibvp82YmAlmLeO41N7inqwPCXtGzieTr/1xRYdCFjx0gDzO1k0rVEr5+hB545Z/fl6WFNQppdTxgcb5FAvGlqxmu7UKqYNnJJXPzrJmms7IfnCNx0EaqdDtYPYn6otdpem1JJJcYiaa+1o82PTLWL9LWzn0nnKRbp9593/80Hw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfe9bcc0-9b30-4811-014c-08db2047d39d X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:46.9980 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bt5BEKSFhPzsqzAef1PPg1juksIzg+qqxStWzvtMHPx+SklAPGdimhYZjwT5XKwMuLlsLvX98uht4lXLdD/R8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Hyper-V guests on AMD SEV-SNP hardware have the option of using the "virtual Top Of Memory" (vTOM) feature specified by the SEV-SNP architecture. With vTOM, shared vs. private memory accesses are controlled by splitting the guest physical address space into two halves. vTOM is the dividing line where the uppermost bit of the physical address space is set; e.g., with 47 bits of guest physical address space, vTOM is 0x400000000000 (bit 46 is set). Guest physical memory is accessible at two parallel physical addresses -- one below vTOM and one above vTOM. Accesses below vTOM are private (encrypted) while accesses above vTOM are shared (decrypted). In this sense, vTOM is like the GPA.SHARED bit in Intel TDX. Support for Hyper-V guests using vTOM was added to the Linux kernel in two patch sets[1][2]. This support treats the vTOM bit as part of the physical address. For accessing shared (decrypted) memory, these patch sets create a second kernel virtual mapping that maps to physical addresses above vTOM. A better approach is to treat the vTOM bit as a protection flag, not as part of the physical address. This new approach is like the approach for the GPA.SHARED bit in Intel TDX. Rather than creating a second kernel virtual mapping, the existing mapping is updated using recently added coco mechanisms. When memory is changed between private and shared using set_memory_decrypted() and set_memory_encrypted(), the PTEs for the existing kernel mapping are changed to add or remove the vTOM bit in the guest physical address, just as with TDX. The hypercalls to change the memory status on the host side are made using the existing callback mechanism. Everything just works, with a minor tweak to map the IO-APIC to use private accesses. To accomplish the switch in approach, the following must be done: * Update Hyper-V initialization to set the cc_mask based on vTOM and do other coco initialization. * Update physical_mask so the vTOM bit is no longer treated as part of the physical address * Remove CC_VENDOR_HYPERV and merge the associated vTOM functionality under CC_VENDOR_AMD. Update cc_mkenc() and cc_mkdec() to set/clear the vTOM bit as a protection flag. * Code already exists to make hypercalls to inform Hyper-V about pages changing between shared and private. Update this code to run as a callback from __set_memory_enc_pgtable(). * Remove the Hyper-V special case from __set_memory_enc_dec() * Remove the Hyper-V specific call to swiotlb_update_mem_attributes() since mem_encrypt_init() will now do it. * Add a Hyper-V specific implementation of the is_private_mmio() callback that returns true for the IO-APIC and vTPM MMIO addresses [1] https://lore.kernel.org/all/20211025122116.264793-1-ltykernel@gmail.com/ [2] https://lore.kernel.org/all/20211213071407.314309-1-ltykernel@gmail.com/ Signed-off-by: Michael Kelley --- arch/x86/coco/core.c | 42 ++++++++++++++++++------ arch/x86/hyperv/hv_init.c | 11 ------- arch/x86/hyperv/ivm.c | 72 ++++++++++++++++++++++++++++++++++------- arch/x86/include/asm/coco.h | 1 - arch/x86/include/asm/mshyperv.h | 16 +++++---- arch/x86/kernel/cpu/mshyperv.c | 15 ++++----- arch/x86/mm/pat/set_memory.c | 3 -- drivers/hv/vmbus_drv.c | 1 - include/asm-generic/mshyperv.h | 2 ++ 9 files changed, 112 insertions(+), 51 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 49b44f8..d1c3306 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -29,6 +29,18 @@ static bool intel_cc_platform_has(enum cc_attr attr) } } +/* Helper function for AMD SEV-SNP vTOM case */ +static __maybe_unused bool amd_cc_platform_vtom(enum cc_attr attr) +{ + switch (attr) { + case CC_ATTR_GUEST_MEM_ENCRYPT: + case CC_ATTR_MEM_ENCRYPT: + return true; + default: + return false; + } +} + /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The @@ -41,9 +53,20 @@ static bool intel_cc_platform_has(enum cc_attr attr) * up under SME the trampoline area cannot be encrypted, whereas under SEV * the trampoline area must be encrypted. */ + static bool amd_cc_platform_has(enum cc_attr attr) { #ifdef CONFIG_AMD_MEM_ENCRYPT + + /* + * Handle the SEV-SNP vTOM case where sme_me_mask is zero, and + * the other levels of SME/SEV functionality, including C-bit + * based SEV-SNP, are not enabled. + */ + if (sev_status & MSR_AMD64_SNP_VTOM) + return amd_cc_platform_vtom(attr); + + /* Handle the C-bit case */ switch (attr) { case CC_ATTR_MEM_ENCRYPT: return sme_me_mask; @@ -76,11 +99,6 @@ static bool amd_cc_platform_has(enum cc_attr attr) #endif } -static bool hyperv_cc_platform_has(enum cc_attr attr) -{ - return attr == CC_ATTR_GUEST_MEM_ENCRYPT; -} - bool cc_platform_has(enum cc_attr attr) { switch (vendor) { @@ -88,8 +106,6 @@ bool cc_platform_has(enum cc_attr attr) return amd_cc_platform_has(attr); case CC_VENDOR_INTEL: return intel_cc_platform_has(attr); - case CC_VENDOR_HYPERV: - return hyperv_cc_platform_has(attr); default: return false; } @@ -103,11 +119,14 @@ u64 cc_mkenc(u64 val) * encryption status of the page. * * - for AMD, bit *set* means the page is encrypted - * - for Intel *clear* means encrypted. + * - for AMD with vTOM and for Intel, *clear* means encrypted */ switch (vendor) { case CC_VENDOR_AMD: - return val | cc_mask; + if (sev_status & MSR_AMD64_SNP_VTOM) + return val & ~cc_mask; + else + return val | cc_mask; case CC_VENDOR_INTEL: return val & ~cc_mask; default: @@ -120,7 +139,10 @@ u64 cc_mkdec(u64 val) /* See comment in cc_mkenc() */ switch (vendor) { case CC_VENDOR_AMD: - return val & ~cc_mask; + if (sev_status & MSR_AMD64_SNP_VTOM) + return val | cc_mask; + else + return val & ~cc_mask; case CC_VENDOR_INTEL: return val | cc_mask; default: diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 41ef036..edbc67e 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -29,7 +29,6 @@ #include #include #include -#include int hyperv_init_cpuhp; u64 hv_current_partition_id = ~0ull; @@ -504,16 +503,6 @@ void __init hyperv_init(void) /* Query the VMs extended capability once, so that it can be cached. */ hv_query_ext_cap(0); -#ifdef CONFIG_SWIOTLB - /* - * Swiotlb bounce buffer needs to be mapped in extra address - * space. Map function doesn't work in the early place and so - * call swiotlb_update_mem_attributes() here. - */ - if (hv_is_isolation_supported()) - swiotlb_update_mem_attributes(); -#endif - return; clean_guest_os_id: diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 5648efb..f6a020c 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -233,7 +235,6 @@ void hv_ghcb_msr_read(u64 msr, u64 *value) local_irq_restore(flags); } EXPORT_SYMBOL_GPL(hv_ghcb_msr_read); -#endif /* * hv_mark_gpa_visibility - Set pages visible to host via hvcall. @@ -286,27 +287,25 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], } /* - * hv_set_mem_host_visibility - Set specified memory visible to host. + * hv_vtom_set_host_visibility - Set specified memory visible to host. * * In Isolation VM, all guest memory is encrypted from host and guest * needs to set memory visible to host via hvcall before sharing memory * with host. This function works as wrap of hv_mark_gpa_visibility() * with memory base and size. */ -int hv_set_mem_host_visibility(unsigned long kbuffer, int pagecount, bool visible) +static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bool enc) { - enum hv_mem_host_visibility visibility = visible ? - VMBUS_PAGE_VISIBLE_READ_WRITE : VMBUS_PAGE_NOT_VISIBLE; + enum hv_mem_host_visibility visibility = enc ? + VMBUS_PAGE_NOT_VISIBLE : VMBUS_PAGE_VISIBLE_READ_WRITE; u64 *pfn_array; int ret = 0; + bool result = true; int i, pfn; - if (!hv_is_isolation_supported() || !hv_hypercall_pg) - return 0; - pfn_array = kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); if (!pfn_array) - return -ENOMEM; + return false; for (i = 0, pfn = 0; i < pagecount; i++) { pfn_array[pfn] = virt_to_hvpfn((void *)kbuffer + i * HV_HYP_PAGE_SIZE); @@ -315,17 +314,68 @@ int hv_set_mem_host_visibility(unsigned long kbuffer, int pagecount, bool visibl if (pfn == HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount - 1) { ret = hv_mark_gpa_visibility(pfn, pfn_array, visibility); - if (ret) + if (ret) { + result = false; goto err_free_pfn_array; + } pfn = 0; } } err_free_pfn_array: kfree(pfn_array); - return ret; + return result; } +static bool hv_vtom_tlb_flush_required(bool private) +{ + return true; +} + +static bool hv_vtom_cache_flush_required(void) +{ + return false; +} + +static bool hv_is_private_mmio(u64 addr) +{ + /* + * Hyper-V always provides a single IO-APIC in a guest VM. + * When a paravisor is used, it is emulated by the paravisor + * in the guest context and must be mapped private. + */ + if (addr >= HV_IOAPIC_BASE_ADDRESS && + addr < (HV_IOAPIC_BASE_ADDRESS + PAGE_SIZE)) + return true; + + /* Same with a vTPM */ + if (addr >= VTPM_BASE_ADDRESS && + addr < (VTPM_BASE_ADDRESS + PAGE_SIZE)) + return true; + + return false; +} + +void __init hv_vtom_init(void) +{ + /* + * By design, a VM using vTOM doesn't see the SEV setting, + * so SEV initialization is bypassed and sev_status isn't set. + * Set it here to indicate a vTOM VM. + */ + sev_status = MSR_AMD64_SNP_VTOM; + cc_set_vendor(CC_VENDOR_AMD); + cc_set_mask(ms_hyperv.shared_gpa_boundary); + physical_mask &= ms_hyperv.shared_gpa_boundary - 1; + + x86_platform.hyper.is_private_mmio = hv_is_private_mmio; + x86_platform.guest.enc_cache_flush_required = hv_vtom_cache_flush_required; + x86_platform.guest.enc_tlb_flush_required = hv_vtom_tlb_flush_required; + x86_platform.guest.enc_status_change_finish = hv_vtom_set_host_visibility; +} + +#endif /* CONFIG_AMD_MEM_ENCRYPT */ + /* * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. */ diff --git a/arch/x86/include/asm/coco.h b/arch/x86/include/asm/coco.h index 3d98c3a..d2c6a2e 100644 --- a/arch/x86/include/asm/coco.h +++ b/arch/x86/include/asm/coco.h @@ -7,7 +7,6 @@ enum cc_vendor { CC_VENDOR_NONE, CC_VENDOR_AMD, - CC_VENDOR_HYPERV, CC_VENDOR_INTEL, }; diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 4c4c0ec..e3cef98 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -11,6 +11,14 @@ #include #include +/* + * Hyper-V always provides a single IO-APIC at this MMIO address. + * Ideally, the value should be looked up in ACPI tables, but it + * is needed for mapping the IO-APIC early in boot on Confidential + * VMs, before ACPI functions can be used. + */ +#define HV_IOAPIC_BASE_ADDRESS 0xfec00000 + union hv_ghcb; DECLARE_STATIC_KEY_FALSE(isolation_type_snp); @@ -206,18 +214,19 @@ static inline void hv_apic_init(void) {} int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector, struct hv_interrupt_entry *entry); int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry); -int hv_set_mem_host_visibility(unsigned long addr, int numpages, bool visible); #ifdef CONFIG_AMD_MEM_ENCRYPT void hv_ghcb_msr_write(u64 msr, u64 value); void hv_ghcb_msr_read(u64 msr, u64 *value); bool hv_ghcb_negotiate_protocol(void); void hv_ghcb_terminate(unsigned int set, unsigned int reason); +void hv_vtom_init(void); #else static inline void hv_ghcb_msr_write(u64 msr, u64 value) {} static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {} static inline bool hv_ghcb_negotiate_protocol(void) { return false; } static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {} +static inline void hv_vtom_init(void) {} #endif extern bool hv_isolation_type_snp(void); @@ -259,11 +268,6 @@ static inline void hv_set_register(unsigned int reg, u64 value) { } static inline u64 hv_get_register(unsigned int reg) { return 0; } static inline void hv_set_non_nested_register(unsigned int reg, u64 value) { } static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } -static inline int hv_set_mem_host_visibility(unsigned long addr, int numpages, - bool visible) -{ - return -1; -} #endif /* CONFIG_HYPERV */ diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index f36dc2f..ded7506 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -33,7 +33,6 @@ #include #include #include -#include /* Is Linux running as the root partition? */ bool hv_root_partition; @@ -397,8 +396,10 @@ static void __init ms_hyperv_init_platform(void) if (ms_hyperv.priv_high & HV_ISOLATION) { ms_hyperv.isolation_config_a = cpuid_eax(HYPERV_CPUID_ISOLATION_CONFIG); ms_hyperv.isolation_config_b = cpuid_ebx(HYPERV_CPUID_ISOLATION_CONFIG); - ms_hyperv.shared_gpa_boundary = - BIT_ULL(ms_hyperv.shared_gpa_boundary_bits); + + if (ms_hyperv.shared_gpa_boundary_active) + ms_hyperv.shared_gpa_boundary = + BIT_ULL(ms_hyperv.shared_gpa_boundary_bits); pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); @@ -409,11 +410,6 @@ static void __init ms_hyperv_init_platform(void) swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; #endif } - /* Isolation VMs are unenlightened SEV-based VMs, thus this check: */ - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { - if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE) - cc_set_vendor(CC_VENDOR_HYPERV); - } } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { @@ -482,6 +478,9 @@ static void __init ms_hyperv_init_platform(void) i8253_clear_counter_on_shutdown = false; #if IS_ENABLED(CONFIG_HYPERV) + if ((hv_get_isolation_type() == HV_ISOLATION_TYPE_VBS) || + (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP)) + hv_vtom_init(); /* * Setup the hook to get control post apic initialization. */ diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 356758b..b037954 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2175,9 +2175,6 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) { - if (hv_is_isolation_supported()) - return hv_set_mem_host_visibility(addr, numpages, !enc); - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) return __set_memory_enc_pgtable(addr, numpages, enc); diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index d24dd65..e9e1c41 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2156,7 +2156,6 @@ void vmbus_device_unregister(struct hv_device *device_obj) * VMBUS is an acpi enumerated device. Get the information we * need from DSDT. */ -#define VTPM_BASE_ADDRESS 0xfed40000 static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx) { resource_size_t start = 0; diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 8845a2e..90d7f68 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -26,6 +26,8 @@ #include #include +#define VTPM_BASE_ADDRESS 0xfed40000 + struct ms_hyperv_info { u32 features; u32 priv_high; From patchwork Thu Mar 9 02:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166738 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE78DC64EC4 for ; Thu, 9 Mar 2023 02:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbjCICny (ORCPT ); Wed, 8 Mar 2023 21:43:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjCICna (ORCPT ); Wed, 8 Mar 2023 21:43:30 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021020.outbound.protection.outlook.com [52.101.57.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E0FCCE9D; Wed, 8 Mar 2023 18:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZKfzsUP+r2SD3OVTWNl/cIgH7gNPK9ZT+2k5/Aun7uU0th6xDBJxPISSlgTVOcM0fvy+ugAPZ3idCS7zKHp9Ugq9iRPcy+x8p1jY+BUcyKLpVsHEj2jycJ2XCKUE4havAb+uIf1tRkC6XJ1SH4NxWLIw78AB2jpid2S9SOEp56Uv/mPd1UG0GD4MBqDDI45eCJhJIVDk23eBmTqIj1v7ip9EoysOeody0+I6dO6Zo8GKMwe75V2OYritC5yYLvkoIH9WUeZy6zIz5CwagfAfavnWpABoKTf/sRA4VAnvbG8MaxLK974j+pCh52ON9fxokVBYnxFvHgXKVjOP846qcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=D9VhUgukXBjNtMO35hB4AlJX7wObHzM6Gk/maPqBuzs=; b=mq318Plu8QFMUHz2X3NO0QX6y4RrVZmoUjb4iv0WWfh/x/WKuMipURgD7MnV1yxF+96Dxuz4hDDTPdD5lkmyOpes7r61ANjwi6/ysKfyRESonmm9sGqB9/oOI+ukdpbncgqdGYj4uUVLQvFjkkhx/quJUW4KsbENtU3jPZ7izeeBQcaniJQNrCXeDsTkGnhlaT7q1X/szG9PgR2stSQ7OrZ5yKMN7uuQfP8Xvyu3Gp6ut+rVZ5Zk7IGEGYmzFiKy31qaG6dLuYFm4ROliySznRR5PKj9a098mYI1omKgDXDZz6H/cS8hmx4MfBBwHEJn4KD779l/fwHoo02vAU+55Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D9VhUgukXBjNtMO35hB4AlJX7wObHzM6Gk/maPqBuzs=; b=At9uY3HkyBI+RBku6EgXuMU+S+1UT8CRJes0mf3mWgtI7J/UXIj9qloZ8hc5OugS2Bojdy2T+zadGjNvCVl7AWj5wS7m8wmf4IeggQeEyngoCVWfJyj0s0eoRiquo52uoALkgNbIRQkLJb2nWWgEppMQRGGb/Ikobf54/WBiaw4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:49 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:49 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 07/13] swiotlb: Remove bounce buffer remapping for Hyper-V Date: Wed, 8 Mar 2023 18:40:08 -0800 Message-Id: <1678329614-3482-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b7175b4-5491-4153-2e11-08db2047d4f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rhD24eAssfBcNKluahnyF30tPe+ilDgTAQe2KZGwT0cATjvg9264b4iFNDbGeYB8Gw8JYhToyfDUtBUSpPWUUwFv18x8vuHnjaxnCpYD3a4tJwIc7F3kKoQ8KJMsV1WtR9tHUdxNZc4N56aAXJ3h2ie3eSNAJKVDgl68IrwQVUb46pdPtIAmrSxch8XKnmGKskrHC/p0sb6Q5XM0ITTdI6BPTX5FbT7XHKHiqVNvAfDLPwyk0WvUM7SHt+ZLd8S49mGxcl8ODz+zOQDKtnFArox4bOYMjM9xhdGjIn2CmZ+p2HQ9NakYf6wZz3zI/MZkEsYwoOyeixO1TMgibLaJDgWg/kilN24vIAH5Xqs4ERe4uWBxyDnRACEpdDQS9QhUsNKQ1sr+VSuqYbmt+m0os2wTSNTXAYREFSxRu0undRbUNTHEtTZJBCAdSNkfHld1vcQhKPaT6NaPrHo67L3eANFhjNvvbCmRxc5ilXqkh7CE1OeaofeXV9vmW3XXIE5qCPnLtUVelmVk5owisuasSWnvzIVoXCOrQBFTW9b3fVkrLSHfKYtwPepq1gxlQVAxPJsEOYLJF/NWz1GsCkVSGA0A07zn6PXoaa3ReSqmChb9XQ6ZUGu3FuUDSxXXiH3Xk97Ke753F4XCeFq9Rj0KDySgWBwdJ50u4CffgN3MVaCAYYOoPPJWZmtHWCtrn0HRu+Y0MLRh9ZEaOKL+paZDDJCmVEBRqRqVUlWNO4Wm31veeA3wO39/WY3QJneZTjC8kUbQclLLmvz/4PTa0g18Jg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VtKHZXJyVpyaKkVK/AzR5fp5wG2U2Vf4IQvYPFmYPDVNo+N3robmrRLVKEHsywVR72tDItnQ2arksoijvsfhpKuL4waHsyot99teorduW8lPEQqaU+UoYPhgfYJ2Sdgt1aUZT/P59nMj5H1oFGvzYcu0Tg104G+ujU0P48onVG1T6U9VXyGAriUJz4w8fyVx0YiEw7iacYkTuApbELTXeRkak4vsJmHXbTXFN4a4BqBG23rShsbs9q9EP3+iz0neN5DyMrnRgEE1unS/VTDK6RSrvn4JzNuJlTmyVn+ENg6zfj8gnYO9pUvtJ61Op5liHHbdBu6SPX/BeR43mb+kZlB2C9C6IS5Vrrl3r09pJbzrTLXOyKtIIal3JqYB5t3+G2puy0A6+q43nYcL/WXIihubnE27SvWgzfIiTWU9+rwEloaREedBjiW/KqS+M/WMFT0SNQInryrsW+MfaqflJYdjoBWOQ/YPcDdP2P79F6lpUdGqTbMcmDv4fhgYzphj/p0pXyUmkFGCuBOHQSwGIcaWr6aK/S6IrGpEES3pZ7IhS0IfA+t6On6RjDgP9GTKIKRtqn6yhfaI419V+WualJhHNCUN4uIlbV2m+jZ5N8KLAaP2YUt8BnoIWei5lhLAQ3tey/bOjGQXwVREJLuaa3H5pqopd1ypcU4aurtJ8q8ah1Hspm0TgqutsbJrGvz6oJECCZ436wdpBNNfTUAeJ7VuYn5vDEgcK4kXh/NjllLmziJKih1EvQjUwanms7W9f/dtWV7IA43q2c29UxvrOMX36iXIOCnv3Zy7DtH/WczV8rTGb2KKwdKk7H8CeJtd1T4QbNWjY9jJwzk0UhNEA4zDcY6R3kSb3/cAbv9L+YLYGjNom3s+zc1vz5PFYnRA5G2kniwfyBfa6nTgl27BUJourAknkgriDPMqYawY4ZDSordVE3zMDQvJEEX3t4fZWhZBMroxm7TTmgbCIwvtGExTYx5cG7G0M/dnhni1PVGVIpw06o8NKEzE+VU4G43VS5wOS3tDqSbfT/X+wIo0eIACbaL4/ZWXuU8SQcUVNGbkM8VX7bFCRfMSu6hBy3O+xRquCSpnYzlcFsFiMt4qFVwxVJOqocsctl/gOmteTseD87PrjwAUBpNYt8G3gkkHP/Y0VU+QbOKVYJsvzzs26C3tvV+XUv5JyKuX/J+mqNiwwzxt2Qr7Ceq+rI7URS7MrOMx5GAUHB/2abU6Ltg5FPHq8jTJzFe0O3/5igLV2HOlPVDbLxlxPbTE7V627l/nn2ocGc4oc/Gdc7tHSl9B1Kg8W5G4J4nJXPkWAcTfZFwSlStoLghF2o0UYtTGlzwuTJdiOf/aQOu1y8jryELU+vi13R9MYlX3f09XAl57SIMsYBqMYHA/2u+ONEo8jDwW4WdPcibt/5etn+DZ5emyl+06AwIoL4gm7owGKzI41TBb64P0YyswcVBGvdn7ESijT+oz9y/qAYePn9KCcPsu7CK+cq1OJVm8vTViCjCcAkvs+bShnqgeGjqPJcjzyimJrQJBuDccM+5ja9XLchu6B1RKIU8GwFtzF+O/iExkayTbfo8SFQ0VK20oWl2EomsxgWaNovIyoE9cEypcUpZLqw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b7175b4-5491-4153-2e11-08db2047d4f4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:49.2315 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UA9hpCiv6G+1j9lK5lxi0qqZ01zp/FCR3ixRtIaVHixsqYf9frsApB/MJQEqt+WVnePM6BMKOutylGE1jfy3Vw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove swiotlb_unencrypted_base and the associated code. Signed-off-by: Michael Kelley Acked-by: Christoph Hellwig Acked-by: Borislav Petkov (AMD) --- arch/x86/kernel/cpu/mshyperv.c | 7 +------ include/linux/swiotlb.h | 2 -- kernel/dma/swiotlb.c | 45 +----------------------------------------- 3 files changed, 2 insertions(+), 52 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index ded7506..ff348eb 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -404,12 +403,8 @@ static void __init ms_hyperv_init_platform(void) pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); - if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) { + if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) static_branch_enable(&isolation_type_snp); -#ifdef CONFIG_SWIOTLB - swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; -#endif - } } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index bcef10e..2ef25e6 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -180,6 +180,4 @@ static inline bool is_swiotlb_for_alloc(struct device *dev) } #endif /* CONFIG_DMA_RESTRICTED_POOL */ -extern phys_addr_t swiotlb_unencrypted_base; - #endif /* __LINUX_SWIOTLB_H */ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 03e3251..9f7ba60 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -73,8 +73,6 @@ struct io_tlb_slot { struct io_tlb_mem io_tlb_default_mem; -phys_addr_t swiotlb_unencrypted_base; - static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT; static unsigned long default_nareas; @@ -202,34 +200,6 @@ static inline unsigned long nr_slots(u64 val) } /* - * Remap swioltb memory in the unencrypted physical address space - * when swiotlb_unencrypted_base is set. (e.g. for Hyper-V AMD SEV-SNP - * Isolation VMs). - */ -#ifdef CONFIG_HAS_IOMEM -static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) -{ - void *vaddr = NULL; - - if (swiotlb_unencrypted_base) { - phys_addr_t paddr = mem->start + swiotlb_unencrypted_base; - - vaddr = memremap(paddr, bytes, MEMREMAP_WB); - if (!vaddr) - pr_err("Failed to map the unencrypted memory %pa size %lx.\n", - &paddr, bytes); - } - - return vaddr; -} -#else -static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) -{ - return NULL; -} -#endif - -/* * Early SWIOTLB allocation may be too early to allow an architecture to * perform the desired operations. This function allows the architecture to * call SWIOTLB when the operations are possible. It needs to be called @@ -238,18 +208,12 @@ static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) void __init swiotlb_update_mem_attributes(void) { struct io_tlb_mem *mem = &io_tlb_default_mem; - void *vaddr; unsigned long bytes; if (!mem->nslabs || mem->late_alloc) return; - vaddr = phys_to_virt(mem->start); bytes = PAGE_ALIGN(mem->nslabs << IO_TLB_SHIFT); - set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); - - mem->vaddr = swiotlb_mem_remap(mem, bytes); - if (!mem->vaddr) - mem->vaddr = vaddr; + set_memory_decrypted((unsigned long)mem->vaddr, bytes >> PAGE_SHIFT); } static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, @@ -280,13 +244,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, mem->slots[i].alloc_size = 0; } - /* - * If swiotlb_unencrypted_base is set, the bounce buffer memory will - * be remapped and cleared in swiotlb_update_mem_attributes. - */ - if (swiotlb_unencrypted_base) - return; - memset(vaddr, 0, bytes); mem->vaddr = vaddr; return; From patchwork Thu Mar 9 02:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166741 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DECB4C6FD1C for ; Thu, 9 Mar 2023 02:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbjCICpR (ORCPT ); Wed, 8 Mar 2023 21:45:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbjCICob (ORCPT ); Wed, 8 Mar 2023 21:44:31 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021016.outbound.protection.outlook.com [52.101.57.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92E321A965; Wed, 8 Mar 2023 18:43:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b5991xDbNQtM+EWX/DUFsfP+/NCkSEGzZ0zPrAI0JpA3CXGxAN2xHJ4tO/Bx9P8HDFXt7woHgd6D/ZkNuk4q9PdL7rqluXYfvcVnp3G49SBeo/SMIk6+IDLF/Mjc0+ijiQR4N1bmrjpSPMCnToCfvJJQVK5q4WJ2neghewMO7z3y5MhTB/ywI5y9N6yQSr3S64r8vG4GFyyNwEFIFLASJq929GdomAnS7NG8gDhF45Y07I1bnjeKDlnl/0Exqo/oMvqr5jqDuCMmHyc6RUoj1/qcWXU2ZfAaJIUO1W25uZolXRZa462765taEErtJPt7EljhjFN2AlPHJiV4e4TK8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vEuH5Ee28VRY5Qrxd7yqx/QGPvZZfqnOwBt4Yd6S1g0=; b=nwKVCOevDj6yEhLvlGdq3GtO9GKR+aHZTBzmu7QZQjLHFF4RTG6G5sPDxCkZQ5jeQBKKC4E0bAQ62pz7z2IJ6Oew1e8DWP2b7FwbiIQtj1gvMHXWyVNfRHuqT01YzCFD3/QqW2bnqntmk9CD8UGvlffzvJt0ZMA/6t21l6qSzDd49d2supNxP9PnyZpnQrRvkiA3fviXkb4ZVfHwuZUSAe485+V8nUxH8/BkCRYivFTbmedH/9Mevwz62pU6GC0AJNCMZWNUjJkISosSacKC5oLJ3F5cDgOvhU4hI9VwLaYxWow9NazmOdBzNTJXeopJ9NguNlZEyh1Q4Fi+5JYMWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vEuH5Ee28VRY5Qrxd7yqx/QGPvZZfqnOwBt4Yd6S1g0=; b=GAMY7Q4Wuve3YtenDG36mLiUNeLUf7kkuw4FL6HaqZaLk1ur3U0qfUISV51zCEUIiaBaKvtKjV3xpA8EB1MzBsF55CLz2c0DpU4adXUFnznZSzQFc9eJkqycUDlvlVtBoSbuZ+6KDj6cuLBr+FI7e3xLQQjkMHYN+3MdX7x+L+c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:51 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:51 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 08/13] Drivers: hv: vmbus: Remove second mapping of VMBus monitor pages Date: Wed, 8 Mar 2023 18:40:09 -0800 Message-Id: <1678329614-3482-9-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: cc2e8e44-8a39-4129-925a-08db2047d63d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X1wtHL5FFRo0lzKZR6M5yeLp/3vjYSyZbCmfCLL+Mwh6zI+UFvLeuDCG3DHT7M48lRqfsDXiwf0US+Na1bAj874GGZlsVPnmpBWrGhN00uHbs/nUe4hqCjOsi5BKfxHFRqlsjW51tOhK/+EWqrpO5o5nBU+n+FxmUhGW865dGQYVpfcXWrhdizxRAu7/DDy40m8hOvWKa9gtPD9vlCHpw++i+GH5CsVYjfUCR35mB0CpcTvqZloSKpJdl3zxr9ybmRhnWhV4bRiKS+BXDbUvvb9nQSIXCnicHKh8RV91j5qIvgiCkodM0B+8i3LQJMMpgWupnzS/KjI22dU4cHX3DPKnmhXYXSMiSPEGVUr+BI2nsjF9vowacqzCm82KrzJ+IT4Az0eyLvMeMvB6GLquls4CWm43ZSuHnGGu2Hyfzi/ntHVI34sjSH3sQETyJkX72DpSj+rCawuJZIN/OOkgQobe4Ce0GS0p9PFedry9Sb3gYDwD05sH7NiRuk0od/1kdNA40iSsQWQNQ82o/Izm1u40qnuF9vdNDuYcLPOc3Hs6AvfKn+lNVTnhJRz+ssf95USaaPrtEsvKJUp2Q8oqHH8Ukl0PXlTC8kVgpS6y/8gaeWexFfl3G1i2e+jMxi7PfW1HWQ7kOgqZvrEa97z1//zRr3q0BYtaZXX4f2Fhkq59j+NWO8r3vHxTbxjDwG9xS/8TZ2tQTAH1TuIKKRSY43CG45Uq1tKkMs5XQQbMKIJUKC+sjVejq8SUXmiL/Iaa6qzUcGbmiXXxiX/kgu7h4Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 559SJ55jmfi5YkHcVc2E236qXtCIyy2YlqF6Taf8TpYKhVXIzlttc78XN+WPxBI+/8dpmGhEEl/Fqld+XzILfkgESHJHVn254YSaGxKLr4ThSI/gU06Y49MZjvqy4DoOvZ53ps777YUWZ0hdGEaxiYjaOV8HUGu5dPdHC77sa+yUbU053q45LMFxw++xy83madSk9eTuQa8DqoH3KE3aZR42UDRYvsGcCpubKbNdRzdU6tmEpTuFY1cy4BSblaMi7hNsmtauPgQY1vPDc9gl+LbLOlVBDabWOVWjyrx3Kl0ADZMVmv4Ci7fNUGINbGX9SQPf+isYsN0hnS05c3uyfGFU5zenJGoJtASkGSgh4EOYqWWT35S1v1pIqP5YZYhD7GjIEWIdMtR6Hu5uipHcB5KrOZJTygjoUG9tDzjMULulPI3N82Hvb99w3z7tmIZoQi8ny7FQiL3rFN+xkRyzhuAGvV21EQ9br3k+ayMeCEPmYtmBlykQzdrMjCojOxDPT9bOhJk9qZyjszNw3huwXnDUq47RRB8gj3n3GKA0XKyxi+Ioz08j/30xwMpgVqapcr4EvnMAXs9G8GPyPJyv3VvePwKg4kc6rQFedKJxHaLvpy+MytMXdA8I8jN+UQWbcVfa6juv1JFInJdIZ+ZXGEynuuVsr9ymAafhvt0yzcnT/g+tio1CY3EVi2JeOwkhZqjv0ZP3Yhi4Yrp0v0/JMEzVZCKet/6cnqvttoCJuynOrEhiIiQ0ypLqh7FJSz3L3lG8nv1AiRQ+eFsD1d/+LH/C8bBPgaYWxoqPKzpeVMw7Xb/soywMwWUaeosoPPiJAkBjnSTKM3pYymTNc9hy5zSJj+Hm4RyxQsoTZKJu37g5qmHjFcKnnicb68kNx08jCCIJoleJx1x/cWrRTuHn9hm/A7zdLkjtOb20Of7Odyc18Iw8H+eHnZKwPP4/LvC8ti5NterzHY8jmyEwaHOVxSXVk0W8rrk9sedVwgANz5icPP6PzovD6PFBO2+Hcd92qKEv2C3kcGm6J7EJvnhHYBhYO1TbALJogo0g5HQGzZHt+RezyHbZF/TDLqjW/Cc77EliybWy6/r1I7Hc2PyAtwoT5Zu5qTs3kl0Yw8MiY0G4VPK6SUdfDfBnTK4oBvmOMtY2VSHhlfcBEGRHRrJQGdrQzP0MOh1i7AMhp5UBb1qbaadYDCiDt2cH42PYQTFTDg6OHiJ8LVKgtvfTID3TzJq63rAd5GiwVSKGGS6QKxEdmlNDCsaG4MkHJj2A3fwtvNk0BRGJrM2Nk1f+NdqYMgPysecM8mgF4jooF+0aOsh6t/YB3ayYZWLiT095LeK4+r9+9yMiVVnqV6gBn2106hLeUdXEZk6f2YKhHUbrn4E6p4cyKFYOkjs8RuVpaeP0jC/zLeSqt+25Xy/x3l0qFy+DLdUtwGd0TDTrSTw3I6fvC6TSOY311tFi4ZG4qaJUBm39YIpzyNSeaG0zsavx9G1QpekP9DWeEMGxBNipz16Qv/+JKlaXNWYDHxgNo5jDCKHPlevvn70/GQm/KOrv1z4nSCmF/aoI0+BCEt4QtraKdCb9FXCbQJTCMBYW9PgXFmf2vUXsF1ZyGPFHmdWAhA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc2e8e44-8a39-4129-925a-08db2047d63d X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:51.4069 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bfpMAdilGI0VoPFDCL8S/rm660NZHcCoeacVyibX23PD6jPIxwGQ7C2XGY3U5Ept4m7GNtVX7rE6GpOHU9tYGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for VMBus monitor pages. Because set_memory_decrypted() and set_memory_encrypted() are no-ops in normal VMs, it's not even necessary to test for being in a Confidential VM (a.k.a., "Isolation VM"). Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/connection.c | 113 ++++++++++++---------------------------------- drivers/hv/hyperv_vmbus.h | 2 - 2 files changed, 28 insertions(+), 87 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index da51b50..5978e9d 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -104,8 +104,14 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID; } - msg->monitor_page1 = vmbus_connection.monitor_pages_pa[0]; - msg->monitor_page2 = vmbus_connection.monitor_pages_pa[1]; + /* + * shared_gpa_boundary is zero in non-SNP VMs, so it's safe to always + * bitwise OR it + */ + msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]) | + ms_hyperv.shared_gpa_boundary; + msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]) | + ms_hyperv.shared_gpa_boundary; msg->target_vcpu = hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU); @@ -219,72 +225,27 @@ int vmbus_connect(void) * Setup the monitor notification facility. The 1st page for * parent->child and the 2nd page for child->parent */ - vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_zeroed_page(); - vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_zeroed_page(); + vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_page(); + vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_page(); if ((vmbus_connection.monitor_pages[0] == NULL) || (vmbus_connection.monitor_pages[1] == NULL)) { ret = -ENOMEM; goto cleanup; } - vmbus_connection.monitor_pages_original[0] - = vmbus_connection.monitor_pages[0]; - vmbus_connection.monitor_pages_original[1] - = vmbus_connection.monitor_pages[1]; - vmbus_connection.monitor_pages_pa[0] - = virt_to_phys(vmbus_connection.monitor_pages[0]); - vmbus_connection.monitor_pages_pa[1] - = virt_to_phys(vmbus_connection.monitor_pages[1]); - - if (hv_is_isolation_supported()) { - ret = set_memory_decrypted((unsigned long) - vmbus_connection.monitor_pages[0], - 1); - ret |= set_memory_decrypted((unsigned long) - vmbus_connection.monitor_pages[1], - 1); - if (ret) - goto cleanup; - - /* - * Isolation VM with AMD SNP needs to access monitor page via - * address space above shared gpa boundary. - */ - if (hv_isolation_type_snp()) { - vmbus_connection.monitor_pages_pa[0] += - ms_hyperv.shared_gpa_boundary; - vmbus_connection.monitor_pages_pa[1] += - ms_hyperv.shared_gpa_boundary; - - vmbus_connection.monitor_pages[0] - = memremap(vmbus_connection.monitor_pages_pa[0], - HV_HYP_PAGE_SIZE, - MEMREMAP_WB); - if (!vmbus_connection.monitor_pages[0]) { - ret = -ENOMEM; - goto cleanup; - } - - vmbus_connection.monitor_pages[1] - = memremap(vmbus_connection.monitor_pages_pa[1], - HV_HYP_PAGE_SIZE, - MEMREMAP_WB); - if (!vmbus_connection.monitor_pages[1]) { - ret = -ENOMEM; - goto cleanup; - } - } - - /* - * Set memory host visibility hvcall smears memory - * and so zero monitor pages here. - */ - memset(vmbus_connection.monitor_pages[0], 0x00, - HV_HYP_PAGE_SIZE); - memset(vmbus_connection.monitor_pages[1], 0x00, - HV_HYP_PAGE_SIZE); + ret = set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[0], 1); + ret |= set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[1], 1); + if (ret) + goto cleanup; - } + /* + * Set_memory_decrypted() will change the memory contents if + * decryption occurs, so zero monitor pages here. + */ + memset(vmbus_connection.monitor_pages[0], 0x00, HV_HYP_PAGE_SIZE); + memset(vmbus_connection.monitor_pages[1], 0x00, HV_HYP_PAGE_SIZE); msginfo = kzalloc(sizeof(*msginfo) + sizeof(struct vmbus_channel_initiate_contact), @@ -376,31 +337,13 @@ void vmbus_disconnect(void) vmbus_connection.int_page = NULL; } - if (hv_is_isolation_supported()) { - /* - * memunmap() checks input address is ioremap address or not - * inside. It doesn't unmap any thing in the non-SNP CVM and - * so not check CVM type here. - */ - memunmap(vmbus_connection.monitor_pages[0]); - memunmap(vmbus_connection.monitor_pages[1]); - - set_memory_encrypted((unsigned long) - vmbus_connection.monitor_pages_original[0], - 1); - set_memory_encrypted((unsigned long) - vmbus_connection.monitor_pages_original[1], - 1); - } + set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[0], 1); + set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[1], 1); - hv_free_hyperv_page((unsigned long) - vmbus_connection.monitor_pages_original[0]); - hv_free_hyperv_page((unsigned long) - vmbus_connection.monitor_pages_original[1]); - vmbus_connection.monitor_pages_original[0] = - vmbus_connection.monitor_pages[0] = NULL; - vmbus_connection.monitor_pages_original[1] = - vmbus_connection.monitor_pages[1] = NULL; + hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[0]); + hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[1]); + vmbus_connection.monitor_pages[0] = NULL; + vmbus_connection.monitor_pages[1] = NULL; } /* diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index dc673ed..167ac51 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -241,8 +241,6 @@ struct vmbus_connection { * is child->parent notification */ struct hv_monitor_page *monitor_pages[2]; - void *monitor_pages_original[2]; - phys_addr_t monitor_pages_pa[2]; struct list_head chn_msg_list; spinlock_t channelmsg_lock; From patchwork Thu Mar 9 02:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166739 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44EE3C64EC4 for ; Thu, 9 Mar 2023 02:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbjCICob (ORCPT ); Wed, 8 Mar 2023 21:44:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjCICoJ (ORCPT ); Wed, 8 Mar 2023 21:44:09 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021020.outbound.protection.outlook.com [52.101.57.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29F0D4609; Wed, 8 Mar 2023 18:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iWzrAzvisnaSWGjEJZui8j6Ozr0+xAlBE3WaSHrsn3QH+Z8/iRcmTVeU2k4KbtLm2OjgiPHEHEXLySMngjXEaxGTxBxhhlCBNKG2G/S/JM5W3AuKJmwFo8GwwEN11HQPlWicfmF8ETcTeHCcK7Gg7xWaEfkA71Mjn5grlEH0ziucDUHZ+X0Q15CsmqDugiEtxmIboBYBKdRiW3fofeSCQIrA6wnQs4zgaYnl0jjMcPqDrYzEhxTBru3OgO2vFrQjvNt+pi5WSEdQ8H0J78xr7XhvuMZFxpm87IfMG0L7iZ7PurdNHriHELN7DhrYo4ACe/18TC1WbJGCSQVQ3Y3i3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ogveo7t/IcowXK13Ts+Z+XPBvrmc2pZAZdqL5WY6LIQ=; b=Ffay8jNFAdWm+zs8frjhsk4TdUJp5XihsW4VGK8zR2c75kkm/ShzmMsIQ+hIbGmSZ/HvQMGfjtwpRc3hHMDngmPfo27TE5hW0VQRC1jc1c5dVdlRVeFmvYaTf6ohThzFxgzhNWGc8r4Tx0/laX3v6JH8AknK2Hr22ALbrEemwuFrgbWSGhMqlGHFiEYKxpzUQvb6nzn9HKcaw5ZE6SM8hkydd8Wkkn3I/3xzknd/dDhzdpmMXmmw5Ol12n95sqjf8nxQG+SL7N8QRIv0kaMVNO49u6HolhTlEIJY0vGDI+TGNOlX30bzz96zO9fjQ6yIz7rOR1ujJM5aebDkuO2hKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ogveo7t/IcowXK13Ts+Z+XPBvrmc2pZAZdqL5WY6LIQ=; b=INqPYVLObfsM9Ld5clXRjEHuYyXGpVNNeCAnd0+tB5hhiElZ12S9eca5J2mmvdpI3SG87GAI5/GsuElG8Vpkgx4+CawCN5WoRvyJdTLNHVjxE7wR7rrq+vTjpnuqC/r7QPjoCUYwj1Yo2fDwFQlov7x2gzXOMBW5sBQRq74rTfE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:53 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:53 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 09/13] Drivers: hv: vmbus: Remove second way of mapping ring buffers Date: Wed, 8 Mar 2023 18:40:10 -0800 Message-Id: <1678329614-3482-10-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: e2eddb81-1bfc-4c56-ea38-08db2047d795 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zdr1wkybDb85VRdpDsCW+4hPoSJYfFJJ9xnKgLTlEFZUJI0afZahZF6kpDXSytDNsWSQOsvzG/3xM7h3RaH4MNP3s2jR7wybVrjEh6MCWUm89uWFb+CIP2WeWSt4mZulzMXNzAL9A3tUd4xGp152t8pJihe5amd8A6Q5GPiarsh1QXt7Be+NfUO5tiAQduBZBvIdTN+drh0pJ2KjG6B87/4cIyPhqYpEbC8+j50R7feH1SynMUqSBB2GXLFQK92pUXVHv16CBQIEhwS1MfoYrGDZibVLi7ZuFMjryGm1Xavjxh3+xj5YNbLBQArCyEQYiEAEMC0sCfBMQb3lzZ7532FZQn6riP3bD/Q6lrfdTPjcTt+72kTLkPIpl60Q3uhhlWmeEi+RtqXQF46qpiZ9pfGl0krdUW0Urexrh0AFB/VjCthDYOtBQWWnOJ3XU1y9ooKd/Gb7JKgltnGFhdL1kzA1xj0aFDil+Dc8miFXFEvP77n4d0CdLhSMOU32odv+wU8QmMUYf0vm3TMK/3him19MqI790W/1S5wkZDKe9PD6rOtstsLoX4LtwD+RoNI6g4Zj5QhnMUFQsCB9OEbGrR5J1XOgx7WpNiC9ZmiTEaBPBYWsQ4L43ZRuKE4enad1lUFfwWrTE0+9k2er7Qfbwet1f04OdGkBg6nRpkGcqqGUQfYbt426NxCGVx3oxI7+Ag6YgO4N0F+SI4nBqAY70uQLu7aqnRXtdxabomiq6X+PqVbDDvYVNPD6y1DT9AptrDZf6kqgiLPmjiXfuWg1aw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qUnBF838IqXF7s/cMsglZzCEyY6LKgfE+PHNJ32qOVo6xlaJcdVgiNTLRM5+v3EdT8NZ8sBF7FNGcQquKFmTKsnc9zL83EA72vbMqTNqW3sg9B330DQkQv5OV592/j04kneI8+XL5JMOUEy8HFli0zPQJSVYF3W+IL7t4Nj1Wsh3CmwoK8DJshzSXD4SEamuryEfFrUj9ov4+1x7vv9FmfA4//kNiy+QtvKofcANQh7bkOQb+Ak9SDYELlQakz3j65Eb1gYqmkAOw7Mmi9q9IUQRrJ5GUd3kWK7YLqL7qLp8m4JJIdE/CEFuBI4kDy0skxRz4qekfwjre4QJ1EpEoj1pT+skp8aZA9fsh4MczZ8s03URndPff5DGvgmvYQnJsPoPmMa4Jr1B2Bi/ppzhrVxKYqGgAsnDAwwYScXVGdajpeUCrPdMmW0RGogD4xP7sbjl26HKM9uIyb7ExX2F+zezy8rynO6RXgmMg0l3sd87p443n5+dAZVqdEAObXMcn60KCXBynmmIBk2I59EaRMS5sdkD4bNW0McrbZDCYqZUhRZbzAUZGtDgiasFrxnpBPZseuK6xlw+1pDun3GpSp+tEsVssWHlpEX9AUtIehopruBHDDCTjetIK26QTmbfowcYP28uLiFerHcfZ5E/dpdg6ly3j6fOk6ribjOoq8E+ox4jLVzF990sRnW8DeKQbWPUNQGfgSSELlNbGjWLtlalBlHUY6KdQGU/I8C6T27+j8FpyG0wjiYEKnePDYB0t7XuNUS2jI3rB1WvPD8/cq351goDoub4qLufF8jXx9uANXWdJIB/d5CvJ27v3MIifxxc9queiPN7APbtEKKiHnP3+HkkL9RwCvi6KRMz0Ol8Qg7ila4Yr2hh+QSHtODzdD5d5X3KcLDeX/JKGFsKforJAskq1Lar2rwnmw2lt/wHNmvKeArYu1EXFa1srEDQ1XrZ3/nCr1SLNUx7MwlOuBXxekKQhhbDADf0nupmo4AdkL8Q1HFiLkI4SJFJgEykLHbHinBvaetl0py1qChPnob2E0LIh9g6OC+H/1P/nPuxWT90epMtmv/cMNQezJ3F1VN1WE2c185Qmqi0sRF+ocW/skAjO60ct111GbLC3tE4k9tw+BFNvpkziR5Vj7Epw29iDv5KeTlqmszRUfJHf+jbkcGCFhc7Fpez/nlFqRsiwJSFefIpTBYJv2FTgydXcKKM/1/6cl+1+0vvkTRYoZp4o0aVYh4uZk9EIfoy7sHOyYsfHy732x+d/Htxw6J5AL/M76SAacngMpSXwgykbbO3ARydTIeluZaKEp5Gok1vNEg3w7LGDLHFNxNyZnxJ0lbjX6nc6GufqhbXO5b15y9zVryFITDzmMV+Z7Xkd2C7qsyAeZS/zK5A4ruvXotK1emm8qVq6Lyt7IvxxSMhTXnTLQSZ+TsItLEB71dBf4uciR6s9s6XBgyG/hAEHFI0sxkzhCQTBWwNIu4Gj5G7w2ACrSDv8Qp+MNKy7+OAIW3eGLhUsLwrYyM4WGkHzuFZDqOUyfgyFR3mTtFECyy6hd7GezZl/nj6EJv3L3rDVgCGtRk6ATkaddqkbt1qpnAf4zAyy7sF+mncosEnHVB/4A== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2eddb81-1bfc-4c56-ea38-08db2047d795 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:53.6916 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mnOlyPA9pCG4qeAQ3cGyNYwz5sCSV0ZQdP4ET5vonX2VmPX15M0kougC2f41WWXJRsw/UFJjOZsCHKBKSCBeZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), it's no longer necessary to have separate code paths for mapping VMBus ring buffers for for normal VMs and for Confidential VMs. As such, remove the code path that uses vmap_pfn(), and set the protection flags argument to vmap() to account for the difference between normal and Confidential VMs. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/ring_buffer.c | 62 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 2111e97..3c9b024 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -186,8 +186,6 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, struct page *pages, u32 page_cnt, u32 max_pkt_size) { struct page **pages_wraparound; - unsigned long *pfns_wraparound; - u64 pfn; int i; BUILD_BUG_ON((sizeof(struct hv_ring_buffer) != PAGE_SIZE)); @@ -196,50 +194,30 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, * First page holds struct hv_ring_buffer, do wraparound mapping for * the rest. */ - if (hv_isolation_type_snp()) { - pfn = page_to_pfn(pages) + - PFN_DOWN(ms_hyperv.shared_gpa_boundary); + pages_wraparound = kcalloc(page_cnt * 2 - 1, + sizeof(struct page *), + GFP_KERNEL); + if (!pages_wraparound) + return -ENOMEM; - pfns_wraparound = kcalloc(page_cnt * 2 - 1, - sizeof(unsigned long), GFP_KERNEL); - if (!pfns_wraparound) - return -ENOMEM; - - pfns_wraparound[0] = pfn; - for (i = 0; i < 2 * (page_cnt - 1); i++) - pfns_wraparound[i + 1] = pfn + i % (page_cnt - 1) + 1; - - ring_info->ring_buffer = (struct hv_ring_buffer *) - vmap_pfn(pfns_wraparound, page_cnt * 2 - 1, - pgprot_decrypted(PAGE_KERNEL)); - kfree(pfns_wraparound); - - if (!ring_info->ring_buffer) - return -ENOMEM; - - /* Zero ring buffer after setting memory host visibility. */ - memset(ring_info->ring_buffer, 0x00, PAGE_SIZE * page_cnt); - } else { - pages_wraparound = kcalloc(page_cnt * 2 - 1, - sizeof(struct page *), - GFP_KERNEL); - if (!pages_wraparound) - return -ENOMEM; - - pages_wraparound[0] = pages; - for (i = 0; i < 2 * (page_cnt - 1); i++) - pages_wraparound[i + 1] = - &pages[i % (page_cnt - 1) + 1]; + pages_wraparound[0] = pages; + for (i = 0; i < 2 * (page_cnt - 1); i++) + pages_wraparound[i + 1] = + &pages[i % (page_cnt - 1) + 1]; - ring_info->ring_buffer = (struct hv_ring_buffer *) - vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, - PAGE_KERNEL); + ring_info->ring_buffer = (struct hv_ring_buffer *) + vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, + pgprot_decrypted(PAGE_KERNEL)); - kfree(pages_wraparound); - if (!ring_info->ring_buffer) - return -ENOMEM; - } + kfree(pages_wraparound); + if (!ring_info->ring_buffer) + return -ENOMEM; + /* + * Ensure the header page is zero'ed since + * encryption status may have changed. + */ + memset(ring_info->ring_buffer, 0, HV_HYP_PAGE_SIZE); ring_info->ring_buffer->read_index = ring_info->ring_buffer->write_index = 0; From patchwork Thu Mar 9 02:40:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166744 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF818C64EC4 for ; Thu, 9 Mar 2023 02:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbjCICql (ORCPT ); Wed, 8 Mar 2023 21:46:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjCICqA (ORCPT ); Wed, 8 Mar 2023 21:46:00 -0500 Received: from DM5PR00CU002-vft-obe.outbound.protection.outlook.com (mail-centralusazon11021018.outbound.protection.outlook.com [52.101.62.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED6F93E02; Wed, 8 Mar 2023 18:44:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EflOW5kG+rL6qOrXunG5R0VIRxcJuZUNE6yu2dx1GwxtTkmyvoaR43OUKwnmdfhG6VOV2+YaoiYeSBaukJTpt+xFF3I0IONO7cKrsMkuLOniqCBstmy49Cdw3i5nUn9ZBxqlux4dagtF9BQfzX69vtebzxy7hAP5voo5L5sgW08VKPaFfOnKJp+AtIBobOo19LOwBkiN+qqtj/piN6Neu7wJlZU85I5wuYLhTsWA3qDGy0LzKA1gcOW+q9us/qAwHoxfeRL4gXh4mkS5kkdQSz1ab58cE2NfVynK3U6CaWUkaMrFiDpLgwtrk3DK148CB3xt1deT2RZP5ApbpZSe2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=btHCRwLeI1shgTOdpYSDuK5X6Vba/jr4GkHOzvHVEYc=; b=DRgS1fRnwXbtdh9FYEYD0hV+2uR6ps1W5O2OBX/JM9J+ULAwY+HOFTejJZcWk1qzj7gipRgShgyj8E/sZTKjSGRXQqcd2Pd6QXMLyexqTRPw+fD///6DnXn/uhXwlHkG2HBHBigq0rFuxe/s6jKjoPJV/g7yqf1gmRfkP3ArsPCstYhcSxlkPCWmkS/2Q0E/vbheexysHR9AAm6Mkh+ghDuF/Z+HmhcXLglgMNsjBnarS05HMu25e5FL2vFMEGJdRtlcX9RDQ2mUlBryPJHe/HmfbMDQYSVYAURMbQboSmbUaBFvccHSqW4xp0d6Y4Op7XQ3noT2DTX8/8LQwhKv8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=btHCRwLeI1shgTOdpYSDuK5X6Vba/jr4GkHOzvHVEYc=; b=Fb7BSBQ20rI2JDnBVE2lYRVDgK3pMmjTG624vsjDDob5sipSCV8t9sK5cgTWEtU+zxtsBucfCo/HpCGbYSxoSx3wFF4A+4nXGCZwCQTo5nEHvQWv/N7LeuJkhld5VoBB6pLHIxmzXv/4Rn/Rwyh3zcmSs5Axpd6CdIlTcEtjm9w= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:56 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:56 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 10/13] hv_netvsc: Remove second mapping of send and recv buffers Date: Wed, 8 Mar 2023 18:40:11 -0800 Message-Id: <1678329614-3482-11-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: f79e6ef2-9ed1-46ec-e369-08db2047d8ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 52Wp7LZwRD8JlN+8P0mt9JHHxPbx/tDJJIg8iF9xTUVzmeQHRedVe/iJ8pPl6L6gk0CrtzL9SzNtNO8Vka0yJgxxkQ4feYC8qMpvjXiE4w0d94XAFkzdwG9OlYYG214PlwxSIUy/a5XimapeRXNOHbA8IM5Wbnensx+HmOOUiraZpS2z4a/Vphl0y4JkMkizdPQXF3o47Vu0ac4yikLs0nRwj/OTH1d1DQxx58lqZfrbJj2fi3Xcj8kA5gIEeaHZLRunvZQnRuy8BBLR1+M8TUsC5UI0siFG9WLjodjDOpyoOBPO80kRmoBIDs0blzBwl0pwiOYH9yKGqnhVXiAIo8IOC14UyjEZS7H0ABMEgnSaBC9fq6lIRpHwRA8gmvGtUhqmWgwingpt8EU4VGWeUW+TD8F/HrCoFjZlJhdax2qetmFrzHTHEz2gKkwl4A88QnDTHDwUeqZPpUaXZ9zPsVGouwaGmwLNC0d8fLecIxxcNpDo9Zlc/HEyBB3GrUx7G/1I/qeUU+4SeE+EmzRO8ks6IJhet0Sm4DSVJCTVRaiTGco1FTEM6RoW+j5UDQIeYbrjvh0cLSMTlGPw2lrz6T9SCOXxUigBPjEGV0kp69dYk5ME/OLAFgl9D0chiGEQ1rR1G9rUhmZ9JEfzf4InaDoIIE2iNausPDnPeWQhZ4+V64CCqF6tyw9qDxm1DuveYZ5iZr6vlAX2SE1LoVlb08Vwy8L5fgWMHBo8SSeritDTRePhvqiHt0wIsW8JDa95ZHZhsb3ObgtIKlB6JeXIOw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5A952LvTtFh2W25IPQZ0dHscPbMZKDDwvpS1ZkoHb70hYlK5KKOjgHJDLrl7LHY+9Kky/gE5acVMWYpsIVRcI2URg8Fe1DuDXjOgH2IKAQZ3UAzMhTLAgE0bmO3T0g/dVzXry3maTnZICX4z08bNGBmmIfsrt+ptsCTSukoT7pf9iws3WhE+R8KTa98J4qPezfrCqvHFoEJB9x7EhFkQHvdetRlOjWvyScFBIaxYp4s3T3HaExxTCz77mpi40kWecypKJBmHEC0t/S4d4Tjbrqpuhne3GK54En5OnlMJVZpb2qp1xkvvkV75ikBpSGVBwhpXODdEKqu4Y0LyQ95AVoBXZhf74H8NrCcFAe+Yjkw0lXhhAnuaCJuBdipkItbHgYnGBzAIQyS1aec20xbwsuX8/SPLJQiG3WePUZzAggUPfadJArQUbpVZf6/gaUnk/pBck6NlxyDk5zmedAvHPTrIDcHxdTYAMgWxWrgSxdIl21Ia9C/AlzWwWzNEvEy22TOjyKM3iJz1pD5vux/bCySLyAIyo9abe3gQ0uKTTusH5hqK9p700f/nRWSI49aAbATXV9qnVb3hIV+7xiJotNe4deXf7U8bvuntOltLzpXWFFU6Sqo0G1U8M6ysj/aqCULxy4XpNVvVujlV69jlzD7+1V9woZ4hmXvkYQMdm9Wvc0ewBbxoWtdzq8Ieou5Qykjh0L8ZzNlTxeUlhudCkB83Xq2+KIANCyY+XkJii6SyxOPYFl6yvWqfLvzn1N2N8gHaUoBnHmoQReuZr3F0HDMQa+B6BWFs5P6gQ9/vtbWxoetp6Ldh4TjC8YvukqkwlqPofrM2AOekilhgA7Td4svduSZKyUBxPctrSZem8kbdsLaIbIopGfNcbAk3pRn5J15Z51YHG4+b/azbMXiorW9BFv9499AMYSgd4RG6M75uOy/nYFU80JodN/i0Q9WMH2/BGB1SsM9yAnAqUJVdij1t8R9LjID6tRYKUw9fhbkA6DZC6zPjTt2x/XHlXdE1f/GSkUy1YNl7TpSikAb0KUojwmyLsjetz0SWfBEEVYO+6FyRTDwZK4WpApDQQKYWHXuA46v7WTShwdmVWl/+OrCa3J7kPIuda1FTv4qadJWoZDyLOIhjYduNSrbPveK7Na/KwmW/IFGfYu5q4on2rnZN4OVvgjFqBbzOEYxY4GXwBJy+Ce8JT1cyIsX3ff4sbmB/G2CUFRduteedKlGaAElRyHQ5vdEvffiC4K6aceusXURXuG39xe3utxrY+RUrWJykB/T2VaTuUDm1CbKBCxBFeIcfEO0kktkMHEdQwaCKVwlINmyrzoaQ2l9MWrH1oU/GRLICidRh4hznbV65e14odPaOS/nHSlNxdhm6Yk9uLZds//9/EbLz6zweNtUUCIyfDSkx3cM1/HWCLmSzGzo0X6NuUAB15H22pOK9YtKTz4K89HxbcmpDxcw3WA3BcjOXyl2FpAPy2bPoVH7lT0b8Lm9RK8lxcyCnjn/NExNLnLDajpxIyKqY2QKeXLb6vRaNrNuzcXHJRrJRKoizauTISySZJQEyKNfiytpiKWWMl7Idet7oS9HDQqKGXBjvOyTMFnp710OYz2lUxyS0ww== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f79e6ef2-9ed1-46ec-e369-08db2047d8ea X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:55.8827 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Be4z1qQqGQtLXO59Yk4O1OTFq7LhELnErZJsXWCDr6Y3Yn21hh2OK5dXGYN9CXQ4tCVI9GMSfePMd4GxmkIfUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for the pre-allocated send and recv buffers. This mapping is the last user of hv_map_memory()/hv_unmap_memory(), so delete these functions as well. Finally, hv_map_memory() is the last user of vmap_pfn() in Hyper-V guest code, so remove the Kconfig selection of VMAP_PFN. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 28 ------------------------ drivers/hv/Kconfig | 1 - drivers/hv/hv_common.c | 11 ---------- drivers/net/hyperv/hyperv_net.h | 2 -- drivers/net/hyperv/netvsc.c | 48 ++--------------------------------------- include/asm-generic/mshyperv.h | 2 -- 6 files changed, 2 insertions(+), 90 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index f6a020c..127d5b7 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -376,34 +376,6 @@ void __init hv_vtom_init(void) #endif /* CONFIG_AMD_MEM_ENCRYPT */ -/* - * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. - */ -void *hv_map_memory(void *addr, unsigned long size) -{ - unsigned long *pfns = kcalloc(size / PAGE_SIZE, - sizeof(unsigned long), GFP_KERNEL); - void *vaddr; - int i; - - if (!pfns) - return NULL; - - for (i = 0; i < size / PAGE_SIZE; i++) - pfns[i] = vmalloc_to_pfn(addr + i * PAGE_SIZE) + - (ms_hyperv.shared_gpa_boundary >> PAGE_SHIFT); - - vaddr = vmap_pfn(pfns, size / PAGE_SIZE, pgprot_decrypted(PAGE_KERNEL)); - kfree(pfns); - - return vaddr; -} - -void hv_unmap_memory(void *addr) -{ - vunmap(addr); -} - enum hv_isolation_type hv_get_isolation_type(void) { if (!(ms_hyperv.priv_high & HV_ISOLATION)) diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig index 0747a8f..9a074cb 100644 --- a/drivers/hv/Kconfig +++ b/drivers/hv/Kconfig @@ -8,7 +8,6 @@ config HYPERV || (ARM64 && !CPU_BIG_ENDIAN)) select PARAVIRT select X86_HV_CALLBACK_VECTOR if X86 - select VMAP_PFN help Select this option to run Linux as a Hyper-V client operating system. diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 52a6f89..6d40b6c 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -311,14 +311,3 @@ u64 __weak hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_s return HV_STATUS_INVALID_PARAMETER; } EXPORT_SYMBOL_GPL(hv_ghcb_hypercall); - -void __weak *hv_map_memory(void *addr, unsigned long size) -{ - return NULL; -} -EXPORT_SYMBOL_GPL(hv_map_memory); - -void __weak hv_unmap_memory(void *addr) -{ -} -EXPORT_SYMBOL_GPL(hv_unmap_memory); diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index dd5919e..33d51e3 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -1139,7 +1139,6 @@ struct netvsc_device { /* Receive buffer allocated by us but manages by NetVSP */ void *recv_buf; - void *recv_original_buf; u32 recv_buf_size; /* allocated bytes */ struct vmbus_gpadl recv_buf_gpadl_handle; u32 recv_section_cnt; @@ -1148,7 +1147,6 @@ struct netvsc_device { /* Send buffer allocated by us */ void *send_buf; - void *send_original_buf; u32 send_buf_size; struct vmbus_gpadl send_buf_gpadl_handle; u32 send_section_cnt; diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index da737d9..82e9796 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -154,17 +154,8 @@ static void free_netvsc_device(struct rcu_head *head) int i; kfree(nvdev->extension); - - if (nvdev->recv_original_buf) - vfree(nvdev->recv_original_buf); - else - vfree(nvdev->recv_buf); - - if (nvdev->send_original_buf) - vfree(nvdev->send_original_buf); - else - vfree(nvdev->send_buf); - + vfree(nvdev->recv_buf); + vfree(nvdev->send_buf); bitmap_free(nvdev->send_section_map); for (i = 0; i < VRSS_CHANNEL_MAX; i++) { @@ -347,7 +338,6 @@ static int netvsc_init_buf(struct hv_device *device, struct nvsp_message *init_packet; unsigned int buf_size; int i, ret = 0; - void *vaddr; /* Get receive buffer area. */ buf_size = device_info->recv_sections * device_info->recv_section_size; @@ -383,17 +373,6 @@ static int netvsc_init_buf(struct hv_device *device, goto cleanup; } - if (hv_isolation_type_snp()) { - vaddr = hv_map_memory(net_device->recv_buf, buf_size); - if (!vaddr) { - ret = -ENOMEM; - goto cleanup; - } - - net_device->recv_original_buf = net_device->recv_buf; - net_device->recv_buf = vaddr; - } - /* Notify the NetVsp of the gpadl handle */ init_packet = &net_device->channel_init_pkt; memset(init_packet, 0, sizeof(struct nvsp_message)); @@ -497,17 +476,6 @@ static int netvsc_init_buf(struct hv_device *device, goto cleanup; } - if (hv_isolation_type_snp()) { - vaddr = hv_map_memory(net_device->send_buf, buf_size); - if (!vaddr) { - ret = -ENOMEM; - goto cleanup; - } - - net_device->send_original_buf = net_device->send_buf; - net_device->send_buf = vaddr; - } - /* Notify the NetVsp of the gpadl handle */ init_packet = &net_device->channel_init_pkt; memset(init_packet, 0, sizeof(struct nvsp_message)); @@ -762,12 +730,6 @@ void netvsc_device_remove(struct hv_device *device) netvsc_teardown_send_gpadl(device, net_device, ndev); } - if (net_device->recv_original_buf) - hv_unmap_memory(net_device->recv_buf); - - if (net_device->send_original_buf) - hv_unmap_memory(net_device->send_buf); - /* Release all resources */ free_netvsc_device_rcu(net_device); } @@ -1844,12 +1806,6 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device, netif_napi_del(&net_device->chan_table[0].napi); cleanup2: - if (net_device->recv_original_buf) - hv_unmap_memory(net_device->recv_buf); - - if (net_device->send_original_buf) - hv_unmap_memory(net_device->send_buf); - free_netvsc_device(&net_device->rcu); return ERR_PTR(ret); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 90d7f68..afcd9ae 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -271,8 +271,6 @@ static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset, void hyperv_cleanup(void); bool hv_query_ext_cap(u64 cap_query); void hv_setup_dma_ops(struct device *dev, bool coherent); -void *hv_map_memory(void *addr, unsigned long size); -void hv_unmap_memory(void *addr); #else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized(void) { return false; } static inline bool hv_is_hibernation_supported(void) { return false; } From patchwork Thu Mar 9 02:40:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166742 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8748DC76186 for ; Thu, 9 Mar 2023 02:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbjCICpS (ORCPT ); Wed, 8 Mar 2023 21:45:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjCICoc (ORCPT ); Wed, 8 Mar 2023 21:44:32 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021020.outbound.protection.outlook.com [52.101.57.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FB8321A3E; Wed, 8 Mar 2023 18:43:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d7IWfdNl9geToEXeLpbT5rRwWpfKGchas9d6KaA0EE/pcN/JQOqItoiw9fXWJPS0B7Un1zSPXo2cuU1CwUM7ditgQyohXN8RbuYdG7cd+tO2vaoxtk56BtvYwk48oYBfQWylfJGi6hJXwnlvrfemJFS/QqD27dTuTHuLIIm3nClFIMy0LIGbXolAj7Tp/vsJP1/eCgSplN7mZ3QAVHqxik98WyP8SYjjBx0g3lKX6Y91WucOmeyYlOqgMAdQJhbJcrotO91RU0XXp6vzev4lSwDjh2BEgU6bt91fDvdK/dOqrOH4Vd8cIh+q4J65/rVqprqVcd2DQ8P/CmNhZ8hSsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ONuUHkX2s2accV/LU91CFqIQ9xmiy1GHEaZGBeyXQoA=; b=GdY9ILZ6x1q80RkgIWVorRUxVioWJ67aXId64v8QPVLgaH0iMr/zYusgacWaP0Hp6nojbPLPO7PgcFM36cRAzWgub4BHZLUNbXJDTwfnKjR74favFkBQLZvMuvSkkwsv/jqKFUv7rOrme7Yhsr2uvDhH/Ekg99mYMtIrMaJCk6Xc9Q79CV6xIYIRM/d3eOY3KFNVypQwbrQ7f9NUXt2nd3EUG3H0/H90VDyYz2Mh77i4dggdVeHbT5CiCYx5BUMRBaamGIKNOncVG5TpnbRhPjFJmYMUsp8xj0MvytiLyep6yn16BjS/vQUVz7Z0YWxtsjALXElorN4J4tSHX1p8Eg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ONuUHkX2s2accV/LU91CFqIQ9xmiy1GHEaZGBeyXQoA=; b=AhYLes6BxDEy3roA4D7HSywijePtBuYBAKwJ16+zv+ifFZ8P2MBkj54FTWBB9aZ5Os1DZNaxXsHgp/5jy1FOQU6tHUw/qTJphha0KXhGuFqmBFmyjJTUeSTNfh4LXDqKK01VI7GAf2U/tEjzSAMJa+W/jUVy8CkPbxj4p3taUIc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:41:58 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:41:58 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 11/13] Drivers: hv: Don't remap addresses that are above shared_gpa_boundary Date: Wed, 8 Mar 2023 18:40:12 -0800 Message-Id: <1678329614-3482-12-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: aa93137c-5e6c-4864-a194-08db2047da36 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KRIjfXnUtM7idpX1/Yw03bKUPX3PCIeHwuvsf61pk40J/hJpntqkGpRCws5aCRtkc8x3K4m8knyNokRux0sJdFrvS3kj7RJ7CHGRL2/vzC0aFUnhDumrCp/w5jm5C3WSNy35lWEFM7rABJkek78CX0Q7/Y2UEx6bZqNYHVdLWpO9SOLYxFTVU2lvvW8Y9KwuV08c/xpYykXs157lD0pYLwlVtraRcc/BlpGcuxUakaVBwPeGW2Xhaonl5z0EV9G2+HnIM5NBRK79blAR0i9XjL0bQaj1/n2KTaL5uMO+J+TEJNjZRlSS03SyYH6kT2nRqpLR1slty/yrxgYPr2mfPDfrsQVeFEmuieaSYu7eWyPMk8e/GP+AgelWj00tfkwgweYJnkvE3SbOxX91il6oTrCSBqI7Oh1HoZwennAewM+ufkvf58u7bQI8F9QoxZu2sOEm+1aiHWOe2xeHieBWKGGPNirortGEf9FMhxJcb5cwhlasRX8WUWFENIJnK8ruEIoOAygav79tnVYD1qjZh8AGvtY3Z85utfR+Sgtg3sN7sJo7HbAeDS4kLa1uUVpFm2G79tfBqIPwuCLAgXeljwxpX0i6pyp3oYNmudLUSSc/5yOyNZ5Tn0WbJSylqUWMimqdFFnpeVUsUL1NbF6DRVWQePlENE9zHgumki9Dl2f4pmixYtZ54i+9ljP6tXhKjyEn5vZJ0DZELqrg/Z0Z6KXSWmIgH6agMpkQeJrAtnXbuVynxuUP+Lb5ebTtR6lhVcKpC+zsnnQnNzn/Lb9dzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZEFCGp3ksZ+STOgtbVN5arwtLkJ3wo0pqh2cRCI/OYyX1rBOQ8Ho3Gfb5BxC5ln9gPMpItW7F5VNgLOt88MI8zVqAcqvbfct3mCjgi2lxxj//j4ULWbbpdo+Z4EkyP24fZb3GvqmB9MBVq1NodchjuMCQCBKa1n9Clnqo4FcMQSoKrhVwBfgPSitFs7BaxCbng98nDBceeMGY9jP22W5tUGUWcka7INOgwyGZFD8vtwLDet/EDp5hj86k8qT3IIpgxS0V6QqxXcaEeGoGRdBADqsu6Y2ugiQWkiiJzm/UEYaVafQn7Iy7vsEbkPUqXTS4nWV2VwEhjXIdJ6qG83zgaUHWUJbMkS4EzcAN5MXEDYjFlfDti9c7GCtEtsYMakRxLlXt6l3TwEw3jJHx/0tKHmp9P2gBXnTTyvrNaZSkBnnUeCkfmV0A9hcIi+Sc+WOr9uiqU5iDkbGGKpzdgUdVnkrOy0EyrcsA3tpt+wD8nvEoLbz4hbu4lQGnM2C475fb7SDzESmzBQVjVA4XmCYBCvaoXg0gLHQqYq8zzEz/SdD12lGbusRIqFhOjIXe3ES/4+z5ig6tT7q2Iawyee7GomcsKV6qFVbmtNQn1XERNfBJPIY4Q57UJkMxnf9HPSFaMVuZWmhxMIcRIlgQPY3o/cVfvNifQyHhfTUh+6zKF2Z5sF6o1aPUcNDNU9pv0IdmPHr0WVYWQjXIRn+ew70QkQXQly9JysoU2B1V+h+cy0r+QZLrvD0hup1QvnTD8NFe69R8oLWWgZgoDb203tgiOg8vd7fbTAu5J3nfVcNrt3PDo9vhgbL7MQtg+ZCuAZQrffvf5oD4M1LUTWuIiiJy/ysSsyLba5ZharVSBcUBkjSYlROTJIjXWqpgDtAPzi7j+866XHQiPr65cXxCa70KdIooRfYHmcY6Sq9QGZYffDWj/bcQvw3qUgFBNnemHgitvPgCiSlCLgnmhTr2PbiJ8+wAKs74I/KqeCYdEuECibR3SNY8+QIsmpf2VpHQkPKlb/O0YUJeu7/ubZaaM7m+JcWIPIXzCBw9FlweE49iAB/nJ80fpWkqYgrH3cjzaNI3Qn0uHSk8IbR5kl9pEAHrPDUwI2uXiF6hNNUs63/Qz42yUkDPH1QNvo2ptZOWBdT2TFlpBZwXKDt38GEW9GSaNPwakjoxsRjIPLGHPBRC42ArTdfYgyB9fhm7z5mTy7duqzkAMf0a54YF+odZQRRGp8dOVYZ581cmSlf/2j1kTi6O4rCSkVe2JSux6K8C+8x7CahzeBT03xsCP7N5+86XvLzwjj/rYP6TbodtoS1VMKnY6xN5wZ6mmSYUPpZ7Zsa5vrE58MwWWFYaz+Ee+A/E3qK4vO+pOqKp76xOps3rqaC1FQ7nMhw+5ivQdxZEmImMVf9FbWAgCH5a3tZVXeDVfjLjLSqG+n7d7Y8Vy312oDUCusgohH/PFxFU62mrlrRlGXX5iucJ1pU+Gc7K8snWHzd0oTHzeGV6FbD2jnbo1xJ5izL+LXvOHl1eTkD1hz2NhN87ikMr7aXnCqwERgBX1KgsdstFXK6Osmsb3pe6yPksyEfgrt9dOx8v4SUbrW+ZQ6qAe+AOSP84WVgRtBB7Q== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa93137c-5e6c-4864-a194-08db2047da36 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:41:58.1024 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rynMVIIoDveqXtLY/RBu7FTY0b0jtgmGFsfX4yLlmLrVEFR51p57i5xsbEQxDXa1l/siX0hVfWY52CdnxdE4cQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With the vTOM bit now treated as a protection flag and not part of the physical address, avoid remapping physical addresses with vTOM set since technically such addresses aren't valid. Use ioremap_cache() instead of memremap() to ensure that the mapping provides decrypted access, which will correctly set the vTOM bit as a protection flag. While this change is not required for correctness with the current implementation of memremap(), for general code hygiene it's better to not depend on the mapping functions doing something reasonable with a physical address that is out-of-range. While here, fix typos in two error messages. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/hv_init.c | 7 +++++-- drivers/hv/hv.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index edbc67e..a5f9474 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -63,7 +63,10 @@ static int hyperv_init_ghcb(void) * memory boundary and map it here. */ rdmsrl(MSR_AMD64_SEV_ES_GHCB, ghcb_gpa); - ghcb_va = memremap(ghcb_gpa, HV_HYP_PAGE_SIZE, MEMREMAP_WB); + + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + ghcb_gpa &= ~ms_hyperv.shared_gpa_boundary; + ghcb_va = (void *)ioremap_cache(ghcb_gpa, HV_HYP_PAGE_SIZE); if (!ghcb_va) return -ENOMEM; @@ -217,7 +220,7 @@ static int hv_cpu_die(unsigned int cpu) if (hv_ghcb_pg) { ghcb_va = (void **)this_cpu_ptr(hv_ghcb_pg); if (*ghcb_va) - memunmap(*ghcb_va); + iounmap(*ghcb_va); *ghcb_va = NULL; } diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 8b0dd8e..00823489 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -217,11 +217,13 @@ void hv_synic_enable_regs(unsigned int cpu) simp.simp_enabled = 1; if (hv_isolation_type_snp() || hv_root_partition) { + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + u64 base = (simp.base_simp_gpa << HV_HYP_PAGE_SHIFT) & + ~ms_hyperv.shared_gpa_boundary; hv_cpu->synic_message_page - = memremap(simp.base_simp_gpa << HV_HYP_PAGE_SHIFT, - HV_HYP_PAGE_SIZE, MEMREMAP_WB); + = (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE); if (!hv_cpu->synic_message_page) - pr_err("Fail to map syinc message page.\n"); + pr_err("Fail to map synic message page.\n"); } else { simp.base_simp_gpa = virt_to_phys(hv_cpu->synic_message_page) >> HV_HYP_PAGE_SHIFT; @@ -234,12 +236,13 @@ void hv_synic_enable_regs(unsigned int cpu) siefp.siefp_enabled = 1; if (hv_isolation_type_snp() || hv_root_partition) { - hv_cpu->synic_event_page = - memremap(siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT, - HV_HYP_PAGE_SIZE, MEMREMAP_WB); - + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + u64 base = (siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT) & + ~ms_hyperv.shared_gpa_boundary; + hv_cpu->synic_event_page + = (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE); if (!hv_cpu->synic_event_page) - pr_err("Fail to map syinc event page.\n"); + pr_err("Fail to map synic event page.\n"); } else { siefp.base_siefp_gpa = virt_to_phys(hv_cpu->synic_event_page) >> HV_HYP_PAGE_SHIFT; @@ -316,7 +319,7 @@ void hv_synic_disable_regs(unsigned int cpu) */ simp.simp_enabled = 0; if (hv_isolation_type_snp() || hv_root_partition) { - memunmap(hv_cpu->synic_message_page); + iounmap(hv_cpu->synic_message_page); hv_cpu->synic_message_page = NULL; } else { simp.base_simp_gpa = 0; @@ -328,7 +331,7 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.siefp_enabled = 0; if (hv_isolation_type_snp() || hv_root_partition) { - memunmap(hv_cpu->synic_event_page); + iounmap(hv_cpu->synic_event_page); hv_cpu->synic_event_page = NULL; } else { siefp.base_siefp_gpa = 0; From patchwork Thu Mar 9 02:40:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166743 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A521C64EC4 for ; Thu, 9 Mar 2023 02:46:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbjCICqJ (ORCPT ); Wed, 8 Mar 2023 21:46:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbjCICpt (ORCPT ); Wed, 8 Mar 2023 21:45:49 -0500 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azlp170110002.outbound.protection.outlook.com [IPv6:2a01:111:f403:c110::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF84A8E8E; Wed, 8 Mar 2023 18:44:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j1+OtZVFb/z4KgttDICduVs012V9HtdY5R/xeYAbuhe7/611yJYL5HqctQGtW9vIy+CDDpX/r3//mpEQlV04yz08zL2Pc1tqgNYRxrmM37gotRT1B2jEAHE6lnyxeuJYTwBOPNP4q7KSH9YewZUosUtYMWX6Xjzfxue2391A/FMfMKJRKMt7dKuNeKyzey85NHGyfsFeseoRE5r5eQHcgiyE2PGcAFR+23RO6Kxz/Mkwc4NRLtxB0QWAgjlFjrCxab45XBVLGG0IZ5RRDE+TmUyThNAnrP3k09rxNwRJdgK2aqbPTU6JuSAfZHXPIR5xztWero1PpEk/eSe8zC+qvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Rm7maILJ76g+7w+GeRIYyRmp8NpbMCEc1zVNqGmRMIU=; b=mlF45jDWaRT+QR35W6haBmJCAuYrQGE3Fn6HmmtyQHgAGjleMNB5PRUf7iF/kVSn3Gaf5C4K/Bx5Rf8LAfAv3q3SNO8C2LuHYT/tqVER9c/PuEXGmIW679hvYwuMQVkbMcnXkRtnQy2UJitz0xpzh9Z+P/7shNF6k4TAUZ143xhG4Kkmb++uFz20MHN0djgpdW/Rs16Z+X2+FrJ9okX56PQh+hmFFAGhtc9pUgTGD1ZFci9jvQl4wye7MuMRe4SWVRTcgRahJHQV2NfWeM+tOy632CE17+XEYNwdkSurR36J3F6+5Ko8OxpHjc6sjyiwXImbIYdhKSuZfc1oiykk2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rm7maILJ76g+7w+GeRIYyRmp8NpbMCEc1zVNqGmRMIU=; b=frdkB1P9HTtDR8+5nWFc9mJUmK6jW1AiFVZrfvxUVtMXWdRXJHx5fZvXGdDuW6D1HsRpjjS05Aj12q20JHGT+khS3BBdNkRvYmGt85RshZ6JS/u/Z0kL9uXtwehbYOLrdFKCKqodAQMtu5dTudsHBnVp/18jDrXibWGbkXci0uE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1313.namprd21.prod.outlook.com (2603:10b6:208:92::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:42:00 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:42:00 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 12/13] PCI: hv: Add hypercalls to read/write MMIO space Date: Wed, 8 Mar 2023 18:40:13 -0800 Message-Id: <1678329614-3482-13-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1313:EE_ X-MS-Office365-Filtering-Correlation-Id: ebd2d6eb-7e3b-4d54-65f7-08db2047db8b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7jJyZqJzHPZ/WDTUEA0j6UFT5+H0A8C9gaU1Lp0xgtm9dTPiblbNa78OnRNLZYSgsmzXvCLaraefYf9evyE9opUenZTqvGPG3ObSdZOBCX9+soGTH3ODlACTbX21ZdOYtdMz4z34jv0ozaHC0nKTTOfO5zHhasUU4IeT819AHZImUP9m/Xyypob0OGMc4FdwoZ4ML8pLUcQP0aWCt6Ta+ixVYMdczh1NXIziouiE4TAMZLUD6KjxGg0vxXHnV2XdX/7bzvnjuovh8Wr1EVEOOb5E76YqeH+dMu/FOdJsRsxhRY+5826L7W0eo57kVyLwDsJ16EuYfPcjLMF1gJ5Di6SMtQzlDVOVZ76SAenfhFV7olhumswKKRSxGu8ThlJTHZk4KlroSZL7cNgjtO9Tt8xG9cre7WeT+pHRBR3iRdyswW50aXm5E+WvUtPeE5sB19kQtrTCeOf+N8uf/7Y5p52yLmn1h8hZYuyOhcTmZMo/GCjscjV+dhFUDggeqIPqrheswuH9xTfeJbvKX8HNRhPJQO3Cv5PYQodezYyGXMPKKPMYXE1ImXSeBqV6qy/nzKYobkzkUr7oQfuaCTQ7TFM44HFBLgFZvhwG9B7A3pC6e7UcuYa+rmpL6xthK5cDGweKKRZ8beTcmaxEpNYGqtuHLHgLCn1jxinWuahLIe9KmvY/yLc2BTY84LJ5uYy2cKr5D66meuF6j5G1iE03QvYnj68xxSdvvdjSQ9Y8kFlrda3wgQimk+72qFJyd0SnURKzBueXXtsUCIfWAbFBeQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(451199018)(82960400001)(82950400001)(83380400001)(36756003)(10290500003)(478600001)(921005)(316002)(38350700002)(38100700002)(2616005)(6486002)(6666004)(6506007)(6512007)(107886003)(26005)(186003)(7406005)(5660300002)(7416002)(41300700001)(52116002)(66476007)(66556008)(66946007)(2906002)(8936002)(8676002)(86362001)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5CgOMxHHfB8Hqvdl1LZMKzHo/D+2EPpiyVbhBLtaCWchjqXkc6ZAY9t0YrY6IjBVW37vs6EOSRrGH+pMJqoHy/0ztfIlB9D/uYSCsAVjUCnKrGmVd3A1raAU2VOthZz16j8bTKFg7+BUn/4QR1D2x539wv4zR+47PagKmRiljgDzEJt7BN15DEeeRfU26w4y++Q+BYcof6pVKPAeB68GcJ8GWCDXZSJyXzlZCZKxDvRZ98LdaroyRqGH3lqYcnVYccGatqNqAU5vqknvL4g0VX/8Jvgr1KZM5JMAgKiqBM+ZUWy3/27Atim5fTsoeRFf06YK7GXIzr/bozJc3xuSqQQJZvzQP6qFGsuv72FWAfHfnN7jF88Z1TRYNgSIu4Pri9JBay7s+05D+dbyhMJGrebPDnxmghcsLqvbPHh/bGIghpQOv7FL1Ob6/A2PYhMd33m4syVbZlqI6RH08MBOuJI0Xnp25196Xk4anQenr1aVHpZtNwjnEg6DZFKGSKHhEDHui0hVhCMB1wjNGiqmuzCzoLkJjubYAz8l8Qpm43JeRdVSwvcJhC2ldh8qarTI2klZtP5ESZx9Il8GsuLO/AmAENjmmq8qR26+mCgha2PBqdfadtXcaI95UYFXIP1c5gNLksF0H5IiSrp7/R0rOJkn3pSSd8pELY5NmGGFa+UOVdiD0r6C/mweb62orP+H4WdF6De/MoGOdt5V4/s30YoA+N38Z70PqF8EaqWxd/KGnMeetGXrzQJZGNfayEGiFqB0vH1XyRCxlZC0Q0ssyX0qs1EABK28GoOJT0ND6x+0GgvuLLnExRzVa1LS2xMMwByQuSEMt6VZmUnpwYhaoXfXwbchkqcPTY/WYvCRKqn2S7FWuZHAw177waMZa9SYiPip00/vSy4TvbqQ631elmrpLj8wixDexM89/DH27X3yAAnJzGmzgvT1MTScXKqN+Cgd3OduSqep3DtoeUDGSxNKnAaNFOxad6/4xxLp08UWF/adm59XPRVIF8zJcqpMjvMr0XWnhUTWvEfPMMqhHGrU/IIIkAIJNkZTF1MBRrtLQaXiODnFXQ6yFGWrrKgYDaoPo9kCg+jg47OQAvzhEGPqvYRqo1zJB5JKl8UePzgajEzBFeerjCC4VLaUNGFHfHfsr7aShwDqYeV59UVLrVcujIJN77B0yVvrAuuh85lu5u0DCl7aX/imppDnYzcV8GsGCvPZFRklkae7vvgvulCuOB7P3fCkmqqkyHLWpbG+6OQ5QvVgmnKDREPxzkWF527SNAZR7O+zT/bOai9/1waurC92DgpxeY/9N2HydpUYZH5MTapGzBPcqgq9tYkaX4YMYL9T2LiWnLume5+q+R3O0+MAU3o0J0uXhw33bpeEzOVdLqamQ7kFfiteuqQdjHfKDP2shz0hPG20j+v2SOGThwO+CHyKk+Zf4TLO3jX+O7EDXSKb44rM8nVDre5iMaXlhgWLkNqSY0CEbB2zQIUfSjSHySWwUl8x05UiuLbDWZTkzI423QQ20yO03Y03qo1RLo5EfgYGxlY0k9uGmXGMFwkuDy1HDdlRcf48QS7QZIr8MIQ5WmpL1j02G9sF3LrfLtiD9uP8RUMMoodfIg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebd2d6eb-7e3b-4d54-65f7-08db2047db8b X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:42:00.3044 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JGSsMjRvTR/yCnpez2HqysysTFuyI3bzz5/NrF2TRvtZivHEvrMsC7KDtAero3USnMtl71RXT96fu61tVBwDVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1313 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org To support PCI pass-thru devices in Confidential VMs, Hyper-V has added hypercalls to read and write MMIO space. Add the appropriate definitions to hyperv-tlfs.h and implement functions to make the hypercalls. Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley Reviewed-by: Haiyang Zhang --- arch/x86/include/asm/hyperv-tlfs.h | 3 ++ drivers/pci/controller/pci-hyperv.c | 64 +++++++++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 22 +++++++++++++ 3 files changed, 89 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 0b73a80..b4fb75b 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -122,6 +122,9 @@ /* Recommend using enlightened VMCS */ #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14) +/* Use hypercalls for MMIO config space access */ +#define HV_X64_USE_MMIO_HYPERCALLS BIT(21) + /* * CPU management features identification. * These are HYPERV_CPUID_CPU_MANAGEMENT_FEATURES.EAX bits. diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index f33370b..d78a419 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1041,6 +1041,70 @@ static int wslot_to_devfn(u32 wslot) return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func); } +static void hv_pci_read_mmio(struct device *dev, phys_addr_t gpa, int size, u32 *val) +{ + struct hv_mmio_read_input *in; + struct hv_mmio_read_output *out; + u64 ret; + + /* + * Must be called with interrupts disabled so it is safe + * to use the per-cpu input argument page. Use it for + * both input and output. + */ + in = *this_cpu_ptr(hyperv_pcpu_input_arg); + out = *this_cpu_ptr(hyperv_pcpu_input_arg) + sizeof(*in); + in->gpa = gpa; + in->size = size; + + ret = hv_do_hypercall(HVCALL_MMIO_READ, in, out); + if (hv_result_success(ret)) { + switch (size) { + case 1: + *val = *(u8 *)(out->data); + break; + case 2: + *val = *(u16 *)(out->data); + break; + default: + *val = *(u32 *)(out->data); + break; + } + } else + dev_err(dev, "MMIO read hypercall error %llx addr %llx size %d\n", + ret, gpa, size); +} + +static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 val) +{ + struct hv_mmio_write_input *in; + u64 ret; + + /* + * Must be called with interrupts disabled so it is safe + * to use the per-cpu input argument memory. + */ + in = *this_cpu_ptr(hyperv_pcpu_input_arg); + in->gpa = gpa; + in->size = size; + switch (size) { + case 1: + *(u8 *)(in->data) = val; + break; + case 2: + *(u16 *)(in->data) = val; + break; + default: + *(u32 *)(in->data) = val; + break; + } + + ret = hv_do_hypercall(HVCALL_MMIO_WRITE, in, NULL); + if (!hv_result_success(ret)) + dev_err(dev, "MMIO write hypercall error %llx addr %llx size %d\n", + ret, gpa, size); +} + /* * PCI Configuration Space for these root PCI buses is implemented as a pair * of pages in memory-mapped I/O space. Writing to the first page chooses diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index b870983..ea406e9 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -168,6 +168,8 @@ struct ms_hyperv_tsc_page { #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db +#define HVCALL_MMIO_READ 0x0106 +#define HVCALL_MMIO_WRITE 0x0107 /* Extended hypercalls */ #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001 @@ -796,4 +798,24 @@ struct hv_memory_hint { union hv_gpa_page_range ranges[]; } __packed; +/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */ +#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH 64 + +struct hv_mmio_read_input { + u64 gpa; + u32 size; + u32 reserved; +} __packed; + +struct hv_mmio_read_output { + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; +} __packed; + +struct hv_mmio_write_input { + u64 gpa; + u32 size; + u32 reserved; + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; +} __packed; + #endif From patchwork Thu Mar 9 02:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13166740 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF32FC74A4B for ; Thu, 9 Mar 2023 02:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjCICod (ORCPT ); Wed, 8 Mar 2023 21:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjCICoK (ORCPT ); Wed, 8 Mar 2023 21:44:10 -0500 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazlp170100000.outbound.protection.outlook.com [IPv6:2a01:111:f403:c111::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B116D4624; Wed, 8 Mar 2023 18:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ctFP6jEv55rOifZXC1RocdCttjc2isoRcSPEhOkyKNMLjbXeuIUPrgV1xySyYKuFBhtlm7VI5MVRUAhKze3aWPQeg3cPZguuu7y9KmqRJDBBcSoLh3Cpb7wucMREvCOejCkdlHQPtLc/Qmb6fOMH2Acf2tiQFZwjlNTiOBoKdJInlDejUyPzf1dk3dKyGsAzY1qmkJErmO08K/kXWeAynt1wZjP+j6Gb85gdqimEYeDktuaAy4e7hGVBgl27WmZKAcq2ge65HtjpyS3W+iWIgzVc0hy66rf9eNtKBz3hsMZaAz7wS7I/LFQ7GUbeCJisz+kfSxsqSpXH+N9EtJEKVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hUK0Dt9X7UjZw6PR2H6wPn9q+516BXWRDrkS9bV3108=; b=HCo1r9LexJvLaxxk1LM+mkgTuSNULx7oaUDMC1Z52UccawDXl5MHr2hptxF2Wm/wQKKspYhVwPUSnv//S4JwxyRcVPN0z2Tc8KSOM5ho3a3PzfE4T/ve/cZpW0zjGmREp4F2pAWNtnc+Dwr+LReBxkvfs9MW4KIwu5SKTUaMNyH2XlFbcxfsv+vaMwk2sdAI8AlT73Gwu3YhKk8yfvkYljx1sajxNnqoTU+c2mk0F7vJTLWKAXhYqsH/w2OpZYaHSPG55vFZsTWJ65YJ7t93MMgapGfdnqLK59weUMvN5FlPscBUi6oYpxSd2KzUOj091IQ0pAF2aXh+sx73d38Bgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hUK0Dt9X7UjZw6PR2H6wPn9q+516BXWRDrkS9bV3108=; b=FT0r9aPlxlBRoaIjAPwGC6/bljHmXWw7Vl2c/o1sDHMb8Qyfhlgsm4THKsnw/lsYpSG1tDOsL8HEO7WeD7d1zfc2+57W9jIpBdTQIGQLBnpC1NxBZcgxyhjsHqTnU+5FOe7ETRXQz5bdR1M6kM9OQFhJ5a6jt/L4jE3+haQYAew= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by MW4PR21MB1985.namprd21.prod.outlook.com (2603:10b6:303:7a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18; Thu, 9 Mar 2023 02:42:05 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::caf1:81fb:4297:bf17%5]) with mapi id 15.20.6178.016; Thu, 9 Mar 2023 02:42:02 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [PATCH v6 13/13] PCI: hv: Enable PCI pass-thru devices in Confidential VMs Date: Wed, 8 Mar 2023 18:40:14 -0800 Message-Id: <1678329614-3482-14-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> References: <1678329614-3482-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|MW4PR21MB1985:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f579e31-8a87-4e96-a994-08db2047dce0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JoRMO4XM1dCgpCZJRnNJGSOohcbfdyKpMQ17fwQBFPg6SV34QP6/r7fW+8npyvGsYrZftLV9fr389UDzmpV3xKlG3LmvZgmHDWfFDVDih5+T406XDHfuCUfrF4MXBbGetllYEhJHoNZwdm2VOYY48JK3Nrdi+Zj5iqKJgbbcwxwquVx/kpN4JCqxXSoynYm228LE5d2UapL8i5xywuqHqtNe+OLfc2C4buN+BOY9jyVwBsiJKTh4LZxRCztSTDnn4mUNwGES6uCKxcjB/e2rvXQZgzI3LWT78S81hbO0B9DRPkfAb/DMianC8xtKLPgHxQJMgvtHNCo8u9a9bP6eaH+ON9GrmX7CVXJD4m5+BO6mmrkBO2KMq5iOOIrw91iRJjLB+kU1+8zFSi8jqEYLDtRAbD0J9jdruvPNegmlXy5VmlRzV4flK9bq+/CB0dGekiGKNl7+n8yiD8K6Z7TSTCSciYiLLcYB4x0XuNE4mocTuJKhO4Tnk2pv6+FR7QyBQ4H3qirJWgxUsVbKrlIoBmkrG0UavKPjzzpfWwXRr3mTxJSSCN6LBgHGFMb13yGCswrwk3T5087dVmXUOOlt9WJ5rGs7h564KCGLYr47B0vR5jtRAidodRJt3fD9H2irO4SdPw0jH5fy6xWMgKTsqmEr8uvrRxuHvGx1QjbWgCAxadF3MZvo9Rn52Kd2N4BdiCnLz3MyNI6CipgrXdgwvfKM6CVcXH0d8ggpUwHLBrVGXtOX5mL+XqNl7tCLW51I X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(346002)(366004)(136003)(396003)(376002)(39860400002)(451199018)(82950400001)(82960400001)(83380400001)(36756003)(38350700002)(10290500003)(478600001)(107886003)(921005)(38100700002)(316002)(6486002)(2616005)(6506007)(6666004)(966005)(6512007)(52116002)(26005)(186003)(7416002)(7406005)(5660300002)(66946007)(41300700001)(66476007)(8936002)(2906002)(4326008)(66556008)(8676002)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Rsap7eDLATwbBt+dv6cCRRQW0JHV1k5EjvviQwpe4CcwlOezGlVI2c86CxfkYNLfWKCilGsrp4VlVv1Q8aLgfqD6dlA1fJEpIAFJRZ1c/DQt+wf+hnqDWNm/ivQGTnGCZ8dCdPIZBb9HnSnu8WnroFesrmn/az2VcJxcXL9PFo7b4SD4uOLjUAtVi1/rgg48OFKOdZQmB4hIFLGJ6UlyyofuyjBgdnWy32dF/GVcR/LtJawyZKciJZH0+zLPwmOZ+u5yI643bMMRFvoOwZIH6OEBMmLnO4apA7BCt/munDEjlrwYilrWZebvQHAELxdlS+/rbF0pVo1CxFWkWBKUkefm4fkJA0yffC5cJ/TiB7vBLglRUr5ZJgw/7zmONocIxx0ZpTGCwlTxtF7proX4MAxepM2DMYF/LNy1opIVfk/WZq5Lm04O4L3EUq9zb1InD3Nl3Avu5y+03K9sWBHL1WV52oBSVijUv3In2luozhpKy1ge2sYtoi6KnOZG9X83MS/GtG+F3ipdpaStcEBfSbnIKOQ3kbCyMbb36cIIMH912s5okS1HABbw0KIqY2c+G4gvLuhxVecGhnuabbRvHW2Q2oQFOfh11QZmG1mAzCUcPVZ3mwxxH4/ypYzvHahfXTIxwQcdF1Foxe0a0Ga2tMoJ2vBaUec5u7d+KMOrCWBW/Ef14jYufiRvlXZypHm0sNmqdcODyS2Uv4p/6Eb7zCCuWItMbPgidLTkAGP9oE1UcPFyhTmdz+KTSs5ID9DwJAGiFsSBIizFs9qgszt1A9s3lg614foG2f+MDdquImQiLfAa/nhcYaZ96CcS4+CKZ9tRxhWb2fKVwnNyqjKLxV2w5MpUxYzwx0VIYkNfNq9JUu9PgF9w9zJw1rKjEnib3DLiQZZ2UarB1BP7LEyAGkP8kEqiACTML//gaPo+e+pfUiL27oJmP5PDlzXTWpDqTcZ0f4XJIegvVqTBG1YCzjgDBoxn1mTuV43ZggqgymHU3gksVmwOcFb03H+dFh+zI65J+kP+D0baHHIordH9+ZyoYSObdrnWKkUeRu56ifBdqEjhT2GFzaGRKKVOmuWWfgzFxYt1L3GEoCo9IWXJ2BcrBr07/ZkHlsqdP8UrVawpj4ObHsRWmTXXUA/V9nk7+TSeMFC6NFLy3LP4mzeaQx4S6WNEMjrM09n02BhRGLyFEBJUgYb2VUrjEIhBeI35h+5Cew67Vvm3hIyvFKw6pfJbKWAlU5SuzxaVXCcnI4UOXtFbgOz7rgQf5dtieGt+M+hHI2da19gXI1ZnGfn+T66xaTTT6MzpwRmkTGxPA9NEDCBn1jND2vgPbBDt4WBqkCKhG080s3bwWtaw2u3OwZZm9UVJzn09XwaUT+lMH6wm4y34CtrisA+heviKq7AR8Q9GeGhY6HTsdUeJ4fl1kJ8umZidtF1WYwxVMTjKPjlnItPaFrEo6L/WJmTjxJDZc0NKIvIsiGfViIh3g+18DWCeZp1NYc1ZFfXVQGhQV6UaHgG8jbhgVXoAbTP0JcJb4U71fsfVs5v8+x/KhmB/amBvMUDKFPZ9BbNeSsk86CdCQBpTDaE+MJ+Fm3HcVNteQ05Mbyjvxj40cSpWgjvwTA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f579e31-8a87-4e96-a994-08db2047dce0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 02:42:02.5409 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zmeg3N7UOHNYvTDVNqpNzDXzG54oLE3cb/YRysif1XavwoBGvaBr8HNXyl6pqEc6mMqtwnB0z+Ztz2rNkpMAxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1985 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org For PCI pass-thru devices in a Confidential VM, Hyper-V requires that PCI config space be accessed via hypercalls. In normal VMs, config space accesses are trapped to the Hyper-V host and emulated. But in a confidential VM, the host can't access guest memory to decode the instruction for emulation, so an explicit hypercall must be used. Update the PCI config space access functions to use the hypercalls when such use is indicated by Hyper-V flags. Also, set the flag to allow the Hyper-V PCI driver to be loaded and used in a Confidential VM (a.k.a., "Isolation VM"). The driver has previously been hardened against a malicious Hyper-V host[1]. [1] https://lore.kernel.org/all/20220511223207.3386-2-parri.andrea@gmail.com/ Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley Reviewed-by: Boqun Feng --- drivers/hv/channel_mgmt.c | 2 +- drivers/pci/controller/pci-hyperv.c | 168 ++++++++++++++++++++++-------------- 2 files changed, 105 insertions(+), 65 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index cc23b90..007f26d 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -67,7 +67,7 @@ { .dev_type = HV_PCIE, HV_PCIE_GUID, .perf_device = false, - .allowed_in_isolated = false, + .allowed_in_isolated = true, }, /* Synthetic Frame Buffer */ diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index d78a419..337f3b4 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -514,6 +514,7 @@ struct hv_pcibus_device { /* Highest slot of child device with resources allocated */ int wslot_res_allocated; + bool use_calls; /* Use hypercalls to access mmio cfg space */ /* hypercall arg, must not cross page boundary */ struct hv_retarget_device_interrupt retarget_msi_interrupt_params; @@ -1123,8 +1124,10 @@ static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, int size, u32 *val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + int offset = where + CFG_PAGE_OFFSET; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; /* * If the attempt is to read the IDs or the ROM BAR, simulate that. @@ -1152,56 +1155,79 @@ static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, */ *val = 0; } else if (where + size <= CFG_PAGE_SIZE) { - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); - /* Choose the function to be read. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start reading. */ - mb(); - /* Read from that function's config space. */ - switch (size) { - case 1: - *val = readb(addr); - break; - case 2: - *val = readw(addr); - break; - default: - *val = readl(addr); - break; + + spin_lock_irqsave(&hbus->config_lock, flags); + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + offset; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(dev, addr, size, val); + } else { + void __iomem *addr = hbus->cfg_addr + offset; + + /* Choose the function to be read. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before reading. */ + mb(); + /* Read from that function's config space. */ + switch (size) { + case 1: + *val = readb(addr); + break; + case 2: + *val = readw(addr); + break; + default: + *val = readl(addr); + break; + } + /* + * Make sure the read was done before we release the + * spinlock allowing consecutive reads/writes. + */ + mb(); } - /* - * Make sure the read was done before we release the spinlock - * allowing consecutive reads/writes. - */ - mb(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, - "Attempt to read beyond a function's config space.\n"); + dev_err(dev, "Attempt to read beyond a function's config space.\n"); } } static u16 hv_pcifront_get_vendor_id(struct hv_pci_dev *hpdev) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + u32 val; u16 ret; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + - PCI_VENDOR_ID; - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); + spin_lock_irqsave(&hbus->config_lock, flags); - /* Choose the function to be read. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start reading. */ - mb(); - /* Read from that function's config space. */ - ret = readw(addr); - /* - * mb() is not required here, because the spin_unlock_irqrestore() - * is a barrier. - */ + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + + CFG_PAGE_OFFSET + PCI_VENDOR_ID; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(dev, addr, 2, &val); + ret = val; /* Truncates to 16 bits */ + } else { + void __iomem *addr = hbus->cfg_addr + CFG_PAGE_OFFSET + + PCI_VENDOR_ID; + /* Choose the function to be read. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before we start reading. */ + mb(); + /* Read from that function's config space. */ + ret = readw(addr); + /* + * mb() is not required here, because the + * spin_unlock_irqrestore() is a barrier. + */ + } - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); return ret; } @@ -1216,39 +1242,51 @@ static u16 hv_pcifront_get_vendor_id(struct hv_pci_dev *hpdev) static void _hv_pcifront_write_config(struct hv_pci_dev *hpdev, int where, int size, u32 val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + int offset = where + CFG_PAGE_OFFSET; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; if (where >= PCI_SUBSYSTEM_VENDOR_ID && where + size <= PCI_CAPABILITY_LIST) { /* SSIDs and ROM BARs are read-only */ } else if (where >= PCI_COMMAND && where + size <= CFG_PAGE_SIZE) { - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); - /* Choose the function to be written. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start writing. */ - wmb(); - /* Write to that function's config space. */ - switch (size) { - case 1: - writeb(val, addr); - break; - case 2: - writew(val, addr); - break; - default: - writel(val, addr); - break; + spin_lock_irqsave(&hbus->config_lock, flags); + + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + offset; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_write_mmio(dev, addr, size, val); + } else { + void __iomem *addr = hbus->cfg_addr + offset; + + /* Choose the function to write. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before writing. */ + wmb(); + /* Write to that function's config space. */ + switch (size) { + case 1: + writeb(val, addr); + break; + case 2: + writew(val, addr); + break; + default: + writel(val, addr); + break; + } + /* + * Make sure the write was done before we release the + * spinlock allowing consecutive reads/writes. + */ + mb(); } - /* - * Make sure the write was done before we release the spinlock - * allowing consecutive reads/writes. - */ - mb(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, - "Attempt to write beyond a function's config space.\n"); + dev_err(dev, "Attempt to write beyond a function's config space.\n"); } } @@ -3627,6 +3665,7 @@ static int hv_pci_probe(struct hv_device *hdev, hbus->bridge->domain_nr = dom; #ifdef CONFIG_X86 hbus->sysdata.domain = dom; + hbus->use_calls = !!(ms_hyperv.hints & HV_X64_USE_MMIO_HYPERCALLS); #elif defined(CONFIG_ARM64) /* * Set the PCI bus parent to be the corresponding VMbus @@ -3636,6 +3675,7 @@ static int hv_pci_probe(struct hv_device *hdev, * information to devices created on the bus. */ hbus->sysdata.parent = hdev->device.parent; + hbus->use_calls = false; #endif hbus->hdev = hdev;