From patchwork Sun Mar 26 13:51:56 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: 75064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp949680vqo; Sun, 26 Mar 2023 06:55:14 -0700 (PDT) X-Google-Smtp-Source: AK7set8XiT8CbwVWOYjevkNcbFE4xbJfqNZnieuaCPPI4ZW9A8o14l0+ZEWAlZrDX5y1Xw4cX9wY X-Received: by 2002:a05:6a20:1610:b0:da:2b8f:94e1 with SMTP id l16-20020a056a20161000b000da2b8f94e1mr14042293pzj.13.1679838914079; Sun, 26 Mar 2023 06:55:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679838914; cv=pass; d=google.com; s=arc-20160816; b=HLjzN4JsVR2WHfz17RXxed7c9lmnxSGU8KBl8HYwsBFg+27r2moIvqr/alfjrJhFth +j7R3hQUIHxJkB/K+Vx0BN+g+Mr8g7F+SHVBOefnOjNPRAbCbXFP6tEO7Gw1P6WhFxJ0 Ilmz+cGJBvgQd76z6tZPiCjizxfdsWf65xDrmddvNMVBCaydUJpVQCYkET3UDcNFjWkg hyJ+FxTi5+LujBrTzzwdiDs/ZZLSiY7NgZa4LrJQnpx2QVMywQVGZFVF9RoFzuiPIdKU O1neNk1mkigzryG23kIv0pVZ8wtBc/c3vIUuPVsfjyjin0cZEZgzDxbDotg0w489eXE2 mQvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BJSsjkE6n4QET9p3yMwrUTThHUQbkoJIj/zzWReCAO8=; b=kF3tiYWsFMj5bMPrB9BYFBctxZLEA5d5WP/WKyRE8PSfeS84u7aHydLYp0QLy3zKJ5 Ga8HNx+Ugo6j3iXNWBzdSCC8ylRFhQqOadW6ci7kyXmeVaXIfE7UyHGh9AbkScVC0jEC 0bFg00anz/KAS6K4l/znalc1+Eno3umH8t29pNTJ96LDLI8Hb1ngT6WVLSby5fpr6Z1p evWEnkj2QqLzvnw6ka8ssSE5WBigy6bfAUTTdN7Uqz5L1ko+/5+e4/LSG+JFyBI9IXZo vzUs9ZgarrNG4snovtHp8VNt15pTRiOec7gy6pKduXj4rwYb4v3rXz6grs88nJixaCHF XK+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=AVEB38bH; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020a630b4f000000b0050beb83039esi15276718pgl.515.2023.03.26.06.54.55; Sun, 26 Mar 2023 06:55:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=AVEB38bH; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231869AbjCZNxU (ORCPT + 99 others); Sun, 26 Mar 2023 09:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjCZNxO (ORCPT ); Sun, 26 Mar 2023 09:53:14 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021021.outbound.protection.outlook.com [52.101.62.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9F9E7A88; Sun, 26 Mar 2023 06:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YnzCljJoHt1xlZZDJxpu0yXhCN7kG3fNlFS1bJO8QOyYQS6eNWR7I1vF5Rzko7I0GVrI2i8fMrXtjGC6pMeeAFa8qotU+iGrcMC7Mlm3MzKhKcrIBxEiB7guNWZht1ukqJR+AVVRZCP5+uXR1tewvY13KYfaIXdJBaJeqqWLaPL9GM370fzU+wK9vjca6EwvPCORN1Ss9oN2OpbVDzm0SVvHT7FiFOyXaKlnGUPXsBN+xrt8/SzKr0q1pbq35PJdt55YdgasI8R/zrGtaFURne1XbluHbNl/LsFiyF27NYeVPyqkWvBGicwayUgl8o45D0YCoLYRrOvKhmX9LQenUw== 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=VY3NwVtYWLNJO5WgugZSW8u1sKvWeiZ0//UqiMyTg/hmIws9atr9oap79TFWVjUpJyDStQb81w1Zcd6n1esC6Bgp5uAw2+cP77V/Ltk4apmVxN3i9LhkGCrN5zZcdhw82tZO6jGf3VVXqqkp7xNWhYRRf+AGwA2jAXHjdddDMOOuTZmXO2c3lDAvbMOWrLJGypEn2nrbliTqVgsHIwdELk26tt03bNg5xhe9L1sg+Rs4JvQWO3bTy0oTcnDKmCPYeSI4DjzC7NsIOPnQ4vnotxlcKXyV3iRK9JCbOJGPUbm2NHzClIaKUZqJewWbI5r0b3LAi0dLXMwCnrZPZbSKqg== 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=AVEB38bHAZHZXDRDGf2bG17ZBOw/YuCsCVt3UDwrsrG/kWlbY6btWqaz+nhz5eel+IoIAAB3bxrjH+T/vtRJUdFQuKgza444qXANBSyY/wim4iOwRmaWmmcXG2+MdqxidTO8wtwFO6rfiZrZsPpOKzP7YYDMawz9E5by1fwbouY= 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 PH7PR21MB3044.namprd21.prod.outlook.com (2603:10b6:510:1e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.16; Sun, 26 Mar 2023 13:53:09 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:09 +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 v7 01/12] x86/ioremap: Add hypervisor callback for private MMIO mapping in coco VM Date: Sun, 26 Mar 2023 06:51:56 -0700 Message-Id: <1679838727-87310-2-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|PH7PR21MB3044:EE_ X-MS-Office365-Filtering-Correlation-Id: 5579215a-a483-4f49-fdb9-08db2e016ee4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IfhiuqAQvdU5tiJjcO1TUJtO7DtW3tGRYebzBnSgUnxnPkoV7nv24PLkYJxa2FpftOsn5glEnXZF9mdrsQT9Fu5hMN+VSGvS2mTCU7YLKyeVkZzZwB1iSu9m15UeIgycAgjgN8yrd3787nkSNWZQEb8zL/b7iqjmGqRm4jKlNnvCsrHcI0vy2hbFDVGRI0n4QBWUhm97QVEMYPeMGcZCEicb1k0eYjBBvzO39USreUukNrS+V1zEzePDKQeOr4T2KnLov/sGLavib393Dl/9wfoUEJs1yjHCLX5sv/aSHY8XAty+HbHFQTx1ZYtu6Y7AWtgZgUNXfuWU0l25R82Tf2wbiRdJ1dyVWzfJTCFBLb9BXXJ+O79MyvZg+mv9js+MB5ZcfLR3xv3KY5lxKh3r2O44nFPwlLmyuAuI6RkkfI6VqoHX6BxD0iXDOI9rDnjpb5V9Vb4sJv55KIT6Ms+bSZHe6txC0gdow9qY5tvSM1ataYkBtfxzaIzYFy4sVn38OeGF93ktvTy1HOJKsnudRuSa0fRRPBN0D7JOHnUuwSpEsouibH2I93HgT3OxINTTOK0DuQlgrSR6cxqa/D4CClC5qupYioJ87gy03cxp8XIkfnXGgtHawEBl9637jrMDMkiH5fmauGwGr7vE6YHjz0xDazDzmFPtUlobD8IX9aj+/P3l+YUgcbBJJvrkrHP2 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cmlbZdLeHC3jsV7G/H7Zr7MVlQRp9lMFhFuzagJWSkDlktICsjQVuP9RTCXTO9kJv0SHnB6Y9/GHJgBCVqrsgbPjNwZxiTb7bz32MEPL86TH/5/iCjSp/o1O/cHixRdldMx8dvCrfYhwvSxiINyKVU3eC23Mn1u/Mgkow+dlBZ/wJD1Ntv5UZa4stToBn4WNLhpWtkJQhVVSy8WW94b6ogJq/wzsQ6YkZuoOi8AIkZsRuU4OnOvqHmxVJA3jiRflI355qdiECS0bVtR+66GIcRP0ZcOnGE3DnNMWcs4j2IKyQUAD1drdMs4K5hKHipn6gkmUYnUdjO15KUI4sDOJI8DtjuOHWByVMDxut+SMju2WzhMlq84cTECT43iWHyvWpAwtUSYcJw7On8iyW466uOHJnopk5f1an+p2N4w1Xm5o+6liSH5aXTrWOIDkb0ZkLEJ5g7KI9oc1Pr7fKopdksenDGA6oozczaOZAK2qmMpEgljukvfsXEHEP3nd04Kl0Ick3ypZXPz+cHci780LLJikFHPVaZauoj+QYn4uSq4Yfx43zVqPAY7HV1uAvfFZGYnwGVFaiocCHO4OZT+cX/46zreK0wdf44UokutY89dDbVH6FW6GqVqFOupKYH/UuW1q0K36ciGShT+aGRt+nY5QfhYR8SrGwT72xiSKgPP7phxk5mbXdUYKLeI9gL8A5UADtZyOwHFsuwBMqcV+B8her/FwmPtDcB4iil8gSp4+xW0huteP9k+4ipWtl6c39fYVsNcRSPJSW7B9alJoaL7X1D4N0DkV0G5XNWO8aP62c49FPgjB5XUAqlZxknx1qGSYBslWDoEsZ5x5GAOyoz870DMafW1pafkNAegGU66jlB00QJLMuXRyRY2ft05TxA6ss3LANgudFHq7TXpayLlEpt6Ui6oS9H5Dd+W5bLk4SJmILCJT58UZTQsoEBJoL84tK5fXpuuxcXQV3/rpCARaTpJvnqyS8b+sgBDZ9DiCo81Zd+Z8fBdtu0wjJYemPEEYAsSLhahg1aLqhVY1Zsi34GXIXZmxQqPy/fYNmc+CTBvyDWKqf2iejwBLXYfbxTVNUE6726R95ops0dX4IFUrDBSsxV6NG4stl2UpsI5is17g64nSoi2LDz8QbmWJ4F9e2pASni2wwArwzriLL5oBnw05kDkYrynjqAAAs6Em+DLVhZ4zEHcjkq1UGJHdwu1hCSxwLD+Q7vnzgpvCCSXbBOl2KsYbGfKrDaZar/fqbANsKXmXCUkhqlpXNkffnwaVdWYdqR6e488XBxr7ANgmXkcRyv+2rjHIsaya3/TaXX4j6PxPDOL03wVO3rGKTGUfqmPHbdjVorS/gHguF0RurrSS9h1I1aknh50M1M+/YoKh5O98mds/NfI1ho7/Frl/eqwVxWXj7rbiWuPYLuX/emcG+yqRg6XZUiYNzz+34vUxfSa0Ph9Vyo7yAys3ffwMDddRNzdXmRdrsmdGxluloNYbdY4MUiTtxRNzVn3XyEI683ZhEhX6MenI7v18kmxxdtpDxmfs90aP4aePpIhfnFd08LA0EvqrYFkjGocAh7B5ml8sVWerV4bkZL593cTqDVZ7mbEpM7+T4b7miQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5579215a-a483-4f49-fdb9-08db2e016ee4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:09.4828 (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: q0x5wPi0k+aeuQxNmhlkJhcS+Q56V5FCCy/OC++rADWFz4VqE+qK8D3GVhXaMHzeDAeG+eQ3Nbrv5a6Philf2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR21MB3044 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761438769594971028?= X-GMAIL-MSGID: =?utf-8?q?1761438769594971028?= 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 Sun Mar 26 13:51:57 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: 75070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp952541vqo; Sun, 26 Mar 2023 07:01:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YtSWD2eEr1dAejgiIRGavVjY5OuRqsu+I4B57G6x1WMZLspDxy7UQuZsJahpU0hGW13uNP X-Received: by 2002:a17:906:4ac4:b0:921:412b:d8c1 with SMTP id u4-20020a1709064ac400b00921412bd8c1mr9368480ejt.71.1679839268893; Sun, 26 Mar 2023 07:01:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839268; cv=pass; d=google.com; s=arc-20160816; b=hodq+2jlaAMxdqUXSYOIrIVzZ0VuV3EanRBcXrY0EzEmK6Ssk4jDh+qAjWLrX949nt +Ikc8AaqTzbcEjYhoJ5p+odOe+Uq44feJM5s9nbvaYYn67ud91z4W5+xTsld9HMN3NTT fZKbWlmv29VVUdY2ghxmpg3fL0PHOnAFcAPdB8qmKVvU/OU/25pmv9jRUBsQwBE/oUrY I5SK5E48YivvOFo4UyPqEEd2Jpy/Ua+QvIhRbsNnrT6VGFQW0IaCBjNuYHNPC4KWGcE0 txAzMmAfpPPePxaLshlc2Lf8cv3m+oPaVQpeIT7xypa88HSvfbT54/+wKLiJqrLdNSNe deow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kbHFPFmTeMZYHHAR+6LzRBCkRR+Lt6NfcAGOTQF+av8=; b=0Qrom2lXkNMjHqfNJWrESqO8Z+DDnQaQ12Kcq+ySyZljimezNYSeT1/CfjqgM8ALsm TfVDfRS0Avhk2nsy1Yk2rsyl0NCqiuTctqXesuFUlvDBlLnBXC0ywPNtger7eZX3hm6y KQNYPsg2+o/0R3vcQLQ1whAd+QnDb68yOAbF144PE4hqn00avDpj1AfqnTruqbP5Wi2S 9W8ahaku7czRsrRFqjds50RB/MQVY/tcsIndXuVJr3UHwxqNA3NH/1EfF9JadQ9nruQX 5TSxf+gk//GajAJPiTb12nEFPNlClMoNIWCDxPfK9ykZSqTkZ2IqinrWw5aWa/MA/xbD EbHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=AVX3jDlS; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a1709064c4b00b008e0bd541c68si20408160ejw.594.2023.03.26.07.00.45; Sun, 26 Mar 2023 07:01:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=AVX3jDlS; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231786AbjCZNxY (ORCPT + 99 others); Sun, 26 Mar 2023 09:53:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbjCZNxP (ORCPT ); Sun, 26 Mar 2023 09:53:15 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021021.outbound.protection.outlook.com [52.101.62.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7CDE7A89; Sun, 26 Mar 2023 06:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RFkMcEEfN6Eaew1sSrLK1ORQeOP4NkftsFmbxf4LkofkuZQOeaS+9wiFPvrkFpZZfQVfSmuw/8k1hGf/OFokJ9pH3EcPNCieEt5jZ0jiqdgNqGvg04HqHMnVgwQeBwQvB1fweYD7YZDczVQ1HRfHUOb/SDQQSyTgk3wC8SCUZ2dzDWT9W966x/cGmT+wJx9+aGx81bZQrO0wjsBvUaAfbYpqnJfIrBr7oZOquRJuGCgWqNVw9+IyF0fULHbJs4KKBEvZcDbU5mGW0D+0bxyDW0sIg8YUIGWpazxgTyS9erFb4VGhsfV3Yf5lqa0psPTnYYQti7378aXjsA2bNUvL9g== 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=FNO1fcBPVe2OxWbm9XXU9EJ/ca3k6eZJLneyDLYJ7TuneJFc83GJmTAffhLjta8YeBlBcgwqZOvu3n0VFtZ07BfD/xmevaHzrd6hcgShFVbWiqaVC09+d9bEcQZdN85O5OU19RrPiQOcJHl2Ql7/QDyiVFZLbO3VhS7pGhtud7r3AcIakyWQAuYCemwmoHCb2OpujcpaEZu59TtVoD3kX3TIeGj0lj4werWk5XJQ0YQ4CMTQUgN111Yac0ItaX6qnYD78ModEiBSO5xgcz1Cni/ZnSL7/41feSq3Ir99nco9HLrMehxB+aNjpz90dwgiVZhJypp9kbA+hCMLKlUUVw== 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=AVX3jDlStLE9e3KvVi77HwgAJln49xPn5vi/oD6K04i7ELbw19l35sBsE0zPbc4x7VS3E2SPesl4U8OgNXhPqnOZSKr9nizlkZoswQCGkhbL0V80zCLCIp0wh+sCmsWVqFMYIPBPF+ONiSsrFPKOvlq5ZXV8xYDQHjNtJdeSNsQ= 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 PH7PR21MB3044.namprd21.prod.outlook.com (2603:10b6:510:1e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.16; Sun, 26 Mar 2023 13:53:11 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:11 +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 v7 02/12] x86/hyperv: Reorder code to facilitate future work Date: Sun, 26 Mar 2023 06:51:57 -0700 Message-Id: <1679838727-87310-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|PH7PR21MB3044:EE_ X-MS-Office365-Filtering-Correlation-Id: 13065b9f-497c-44b8-dc8f-08db2e01701f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZntesHanzRvcU9VMRAOeAR2ha6yE+L31xCMmWQM+LDWhF1gns+RqYw9Nn3D1RE+xp4wYWFZtfMFt8uB0J+WIl14FtD2qOt5y3SoBt4IUbrhT6p7pYLzMwmZGimLkArcNidMLcWMXAA/tyj5TQbX2I5fS6cusVoFbaGJW97UVEuw1UUMxcbIIpZjwP3sMd0FQcrK/n3xdjT/NddvOyg1CuVeLAKnWwTzUZQycBaPlrRGQqm1mCuzYbAHpN9xQF2riEZ7UCKL+BX2DFsOQxl7LeTIfFq7+KiOy4x5Tr9kEnmZxzKtARcCwdDB5BInkn6EdAEG1egY1Dyu1jxyD7RyDC+BctIztnLs7XgNHNvFa+k3URwmKMQJ3CUvitq8YcTYx0eV/UGBrMLiO+7sVqJL82SHpt8TVib6DuqpMTNaELcqS8J6P8e5TxKMqpAngSINpsXKPG5djfIihzkbGJq6U21Ko9nW2KUDnhyY2lWNB47yYT7G9uxE1m+lhyy2sK80ccnxsmROJ9881VLbCuVxUpY/fD+uuI4yq4Q4YPG26GGDKmUzZenf9iiWycCMr/RUAbJ4987xkuznff/L7nv/7nOhUbk5XZkA923wuuVA4xUwp19kA3zg4RDILt3OAU/vQpyLfpsZfVoi4lQJ8mj5UIxfProc0zIgMF4zkCLwtX90sY7jo+BMxzypA8zjxamsp 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VNgrl0FZZLqk71xZ/0I0xlP523LFKQOCp2Y7ZgxxyDqglDlQKPbMgPa7SV0JBuIuOOW7t0re+gl8n7s2ABQqwaxs3gJ9ZZJDQahalyuD+RimyuSa40RKkbfH4+h5OxAiBZ2ot5GKqPosz+JZRXkjmTYt/w8goC6Ocec9yhuWwMHobqeSlj/dp0x3iUaErw+1spTN0nbRAigRHPt2d/S37ZPt2wZ2piTY7kJnV4YFFzrKPkQVfP3Mf94Y9Zd3i9esCbuQupvhE8+L0GibB/mb3PDPvEDpfc+Hnb8Cqp2lIJSjdWo8giJPswX7D0ubPbqOZnwMbGAom70AXNZHyve97YIRNG2VZcuzUmWcNU9a3jO8rhqp2Gt5KHGca6HS0epjfUH117yNXFQlBurKdp0xxA1nAqHRa1mmEdnyeinPOqLEsWvTjEcJhQOKdnD3JmQRDypgLSxrFHr6j0FOoBMLLXikKbiD/wfhEJaiD9yMnDWkRTGW/1+50/p1EUCPuuC0OSrgR7hC25tRq8TuiqAO2eDmrG2H0AzkyndTOLSBis7L2KYg3K4tdlyEOlDDxlTdin+stTamMKF8HMNk3RugFcWw3DWXSfvnXvuWVxpC95R6jx7eXyYfk7TDqSRi7N1U3FiSgjbZRKwEIKf3mT1E2O+6Cq36yMz7CRiea1AAUUc7sJGC31PfirVDfeDBVCBDy3Lc5lTsDQMjlywNBn12vmRN/1wCqFdNM2L3hnHw7jrhl9gGmv75aVDI6ijUe6RmqaTFGQos+qWgxFf1E+38lNIxdEDYQ45znhh3+o+xIvgEj+sCv0eBY2am1zM3S/ORUSUQAWw3MntvUFoiTOQ7ElZf3rAFVAUKm/Zjr0HXwg8l3jwoSdX9MJ45XNmbz0oR7V0wOXOwgXHKR0/qUz/04hF55lbTnRlNy6uxm16boZmu2vl/xyjXIKMzVEZbZ5RnpgDV2rja/pinO5Bm1FUOuSrpkkYTsF/GbNyNdDCuymUzB+dI/AK/TrIbZ2t+kuUVp5vSj/xDHb25gumZ+T97Mze8lBjiiT8MPO9sVO8G1H8DLzQzN+UylKBT7U1JzdX8MA6lQ0qId6npUfCTq0D1+fcl0Q1v8O/XKPGl9HAm3gS6E7OHEQGERQzKLyd401EIg3jh8Sc6VeG0V0eAIrUpko1N4HKWUc47nx1KqYrJI6mYmHOKHwumzwsbpUNTLtBPz2j7CelPhqF91J2WHIIZlQYl0N2mGco0tLtQCXxwUEo2BR5eLvZdoFBkqtgmfe99eKr34Lz797asr9Zxx/YH6szPywkgn+6oX0rs9AILfgqT/9CqoydjRhd2ss2TEtNyuKxC0sDrWrVGVqFf9izt2WDxtEIkfEgtwGb3UB8VFQHmcL2Z5nZRhnHYc5h3zeBt0wolTEvkhGvI/Kh28WzoVXfFrYIfQ6f3B6Dux9cbIOFfSgKp+SR9Vih10ttZN4nG2+kz66dL3EFIEzN6jbmb67jGYYaf2e+YPrO3BNO/ZeL0dy41YC+2X7vPJFzX6CWzh1yenNZbLdKzd7QaTIvqbEGi7XOkfUHoBgUeK0uKsoN/cKi8UxE/n4y9rpckGkAvceOx6MFY9Nvn5IkKiu+Ycw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13065b9f-497c-44b8-dc8f-08db2e01701f X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:11.5617 (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: r7nO6aSWZ/yklBxjaikoTL3ylm3C1mSx9h5TNdos8OH9epmy6xqi//pGNbnqoGiBOpLyPckI8gw9Z0QUYsGXcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR21MB3044 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439141586089790?= X-GMAIL-MSGID: =?utf-8?q?1761439141586089790?= 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 Sun Mar 26 13:51:58 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: 75065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp951070vqo; Sun, 26 Mar 2023 06:59:11 -0700 (PDT) X-Google-Smtp-Source: AKy350bM/gKKv5b7AXwzHdJd/UrRU85PmWvzMNQOKC53tKivLiDEEE+8cfDcynEyztdBKjZ6O6gC X-Received: by 2002:a62:6346:0:b0:626:cc72:51a7 with SMTP id x67-20020a626346000000b00626cc7251a7mr8758277pfb.9.1679839151177; Sun, 26 Mar 2023 06:59:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839151; cv=pass; d=google.com; s=arc-20160816; b=tJj5hcEZ1KT6zw1K4/3N+jbcq4xW3s7ZvigJlTEULO7kskCFYIXW7a8Cd7xpzpWbX0 6rcqGqJTo2VLfGQ4OffRpAnBnsQD2e2DvJcVdsptE32BBWIH370RHbyHxKvYq31M1TVu sRO8o8KTB82CF2NGYl+QLK8HZF/1OxnizVziRn9YMDaeXpRzMGkIZKnlbFq3qDYDo5DK k7XdrecqF8qHR1coNl7r5sl5mqGHkUcoY4JkEa9eAY9JegsNOOtQdRfk47Hn7dyXgoyo 2Pdd0Q00rEpv51CsgdpYK5Kmj3wz0lfohoCSJP40WR/+sEcM58vDPGT3Er0BEseAETDs vc4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=WMpXjLd+UjKJmPXYudC0MTw+Yv2SaNNAfvRbowIeYws=; b=pKxX7MuicRmNoZockydx7Gnd2xr25U3qkdvlHRJpH03fEhAkgR8fIWRyes1qgj6Xv/ +1HSf0zA/kXwm9cp1wMvqq7LOGqDXbjJ7pSxdvP1ptx6W8Q+Ol2pX5GRget1WZ5Hm/k2 bM6NG1Loda4ap5bFrCk9EXjvaPoUQZne9yO/aRMDwyAF2rNW/RgyDwXKclJ9moBI6+KI Nuk40eqhUkTvIgIaQHXJQ4J0Zylz+7Ci3r7p6aSVk6YdQNsJEpfiKoJpwIriUox9vXHQ +tbp0BHNnQIyudNwKkYjSXdhDhtacuez/kXO5iUeExdhRKFy/A9AlY/1LYno0Vk7UlHh jSww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="Z5Q9I/4r"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f188-20020a6238c5000000b0062ae46c1c06si6032951pfa.78.2023.03.26.06.58.58; Sun, 26 Mar 2023 06:59:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="Z5Q9I/4r"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231873AbjCZNx3 (ORCPT + 99 others); Sun, 26 Mar 2023 09:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232051AbjCZNxQ (ORCPT ); Sun, 26 Mar 2023 09:53:16 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021021.outbound.protection.outlook.com [52.101.62.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 977427A85; Sun, 26 Mar 2023 06:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gX8jD7NYdVetl4g/VQaifLsG390Ob8uhtS4kVBVI7m4G6rOB0189re1kMz8dQqvWUhJB62MqSBoU0Dqo5jRCHGXqGYjVCngUW8HhONW9pcLAC9/Vk3waPAiDz7vyJuGwStk6ATA40KvXvUX+8WvGorcwgv71H+9bh0V5NN+hQ94vMjc/vZMD9SoiXOKVae356S/YG5VsIbLm0v4HmFySH9lJZ2CNexjAXPg0Ybxiep+FDJlzYnxl3y1AEm6E4iG+TtfDo/CuvPQKBkzB/Xxnq40dceEO7m32hg2azKATNmhTMG+hmBjvYo878Yxk/Nc1WpewVOc0DevJ9YXfaOb3pw== 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=BqVoRRFgFTMdPrnS99ZmXSFtuBAZ6szbHqkQS8bqXUWwrGOZpPRuib6c9zZWeohJxsnrKOhFbbMxS6mN8iR4A8d263uQNj/+SxGzfQ+okfxhmxTTkDOQHrCtGDqI/GckeS+WopH5WuCizv1SNuxGnI0Tfu10joYm9KirUyL8VtBHnDAhD78sgZKr0JU+inz7c83GPKkiBIb/SOWwxGRGhTeL9ig6SvdtZqRaIF6myuEleDCVZzp0nussJ5UF6ZkTKcSvKsN6TSCPDNmHCMnU0/Xfu8ORBG6pCQpZRZ6UTUEQwp2y+OY3H+xy390PJA6Awlv7LDe2KCHNVTZWTm6mAQ== 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=Z5Q9I/4rQI4v26Lr3TrSUd2LXgp+UjrUcHDfcjp9Zk8dhFhfcc5H9VaKe2zQ5/QUTWLpt9+mmZ/FA23VAO++ULARzpgT7r/CkGYbZaSSXnFTGI4lyZS/wgDRxRklZieVhLLbslzPbN3d9bEf9koDDIxjRItP8TrVoQ8OKFvAK98= 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 PH7PR21MB3044.namprd21.prod.outlook.com (2603:10b6:510:1e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.16; Sun, 26 Mar 2023 13:53:13 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:13 +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 v7 03/12] Drivers: hv: Explicitly request decrypted in vmap_pfn() calls Date: Sun, 26 Mar 2023 06:51:58 -0700 Message-Id: <1679838727-87310-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|PH7PR21MB3044:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d4344c3-108a-4bff-200d-08db2e01715d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T6OFpnfYXIWqkewQrLAGBzNOtRw5fJw52xNkLK9DsUvcfwJtUOHprHeOl+kYFpMfCx51zyMRxmAfB9Z2Bgikl+capYhfoPm0E81Epm9qp0hWe6T4JYzHYMNDeRzlbQ6HtZv6VfR8gFpgpHF3mLEmomJ4kfqP8/wqUwk7QC31OyuK4z5KdheM70T+Zu7CuLkwIJ3ff/beacaq+7KtKagIop5jeGoA+3+aB7p+TYhJtH+dIysZpOq64eaJzSaf4hDT/NwA2jHVjmKDyER4b6jxqtYi7Vrr5AGMooTNgbqOLnnO/crYcCOszb9NaYrfCv62QwYTojnlWdKe3UiwiNtlQFc/zRdaNLS7HR+s0pc4vk8ppyprWdnof+fTwjSHRIno5tl718M7n1jHaKcLlae44LrNIpBn8m4pxtvs/xkLdMgadTXvqJrgugMfxcWSQuXn+Zb1cllhMRyR9cB/D3SAky6b61XybHlDbUmnm/anwchMSbD6BvypV4+FA3VM0Z/7UcYPE8X8AFC09yfJ7+vFET2iVLoQeKNjfNPSTrl0bXs2iay9afXWHv77hvuWpbwjfr4JBNS7ZD+8QNwVhwP/QglnLCzVXdWVogba03F8BzJEm2oRbApUnybGewtN2suXychY/gnnQK53EG6e1V9cvhspJAl0zn+KdZmYlklDv6dofodsHMKQzx0Po86gHgWS 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ly47m8IUKPLtGbvCQaGI9ab5fuaPa/xAsyOCFtY1zVpGkWHIVX7GXYcxpiegX8MhinRLao+Y+qs4n7V5ur5FvexK8uuFbe/aHCsOxJp39cED45z122Gnzma1XDRxHoahAWfnPEB8eZB/m+7Vh/tGSDJEydwHz5k58z1e8frDVe0wqBgHv2veJ4THIsoxV9H6G9FX7nq9yjPkNSFXJk+VMhEBy3extnrNpPzEZ4vsBRW7aY6G3uIoLoAiUecCdWSfavJ3wgniuVK7gVCki7wkS6YTdarmjhoQWlii7LAQwxploFuV/0faykI39QfBMlJUm+oAkpowm0PYzyBXSGrSTJE2NTvOvm0RRShNZH+FE5GrJCPHI67kvuTlU6YDq+bdY8jBf+U5K1VI9rSDZhGYAJ3ugoKay3yXC+Xq4G2GuA2r53VxsTFuQaLn09a0X4yQblyqqnt2p+aWxNyKfu5Uhh7IgNcNFhYISjIyQ9CzQ5vy25vPIHZPK5xkblwtipuCNDpf8lSyIrDK5QgQttoxrDbrxycLShcp4PrS33uUj3us+xnrRIbAaMRo58B/K9JgtcVC2lKi2kHrNKiuwndp7RXUjdlh4mYeCUDLU9c5W857skMJsJtMTH4fLWiFkSGv3dxZzy7KUoFgM6Qix0R3XbJ2ght1RCSrNoc8cLByHqfeT7PWn6osO3MXH90Ga/aeXC/r3secrUQYLDct9GiW6OwuHdNsf78hm/kQI+sn665XhAbhr3nXYh/RagCucLHR8XfKk/VmbHzici/cYJv/YJpGT9/UWAXlZOmml9b0aVV6OCoCQULc/kwyPFJ0Ov0J3z/b7WvYMF3mmwUHqdgmYHKBeHoptGBEelbvgn1bNCbeJapWwMHbRh5BnVnKl5Dnj+7u3j0vrAcEX5QgmhwxSVmnUuV4IU3F2wsOzrNVsWFw8WYSL3mdCcDE3LM329xODF1oqwazAFcfoO2Jf9M0E4RWN0PGdFVZBhATWkU4P8PmD3gr7mftPQOpzefw+tMR0zBbihVjHOUWzIJyQUt9NnyCTCIToA5bvXFyIAyXlku3CW64pb3yHXmlm/bLi86kL6MyFS7xQkFnKzSqwkRphtqyYzQD6ACl/X4Yd/GjX+Rp8KRvfEkrTLq+yRqwFnWMG5uHnBo0+fnIgL3u0VaeY2+nCw0MVGsPTjKSv/QieMz3vptpwbIagffozuD6j4cWAVIeMsNHg8WWOKPrBrNlY9AYIAG7T2wNfsBlHcUYj+XHSdwkX2yO19/o6olpquXfhpcAkFvea2UQhlXEQqtif6wQ4oyybSuMVLK6CMoRxo3y8V5baCQaK3Tff4/tS7U9SUX3SuZhvjDZSImqEsFLpRnowI32fY7anEzoA7N0atYSyx5/GHma33fbkBFR2C9nZiVn7x69qOfbKoD1YI7lg7ZiAaoiv14MOeeBvkl0rZvThnesfziZWyTYH+aeT7r+um6vm2EP+7/1xGzh2ndpTDxILSa6eIm/fNdW2H6pU2Y544TBUCWMMN82zrtdhYFjP67EwU/p92ourEDeGYWesl9qqzNQfqzS7fahC0ttSJ0si/vlsACn5JDVznS5VIST1rxL1hoPgGKv0h3/9rn5XQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d4344c3-108a-4bff-200d-08db2e01715d X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:13.6254 (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: lCG7REtb9b+b/sQq8voh58d++mvNPxuYDeuQykXWyGZXMT4zfwYQ2hFOHp7XTwV4rCoH9Jd601DZl6AQtYUQqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR21MB3044 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439018243944769?= X-GMAIL-MSGID: =?utf-8?q?1761439018243944769?= 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 Sun Mar 26 13:51:59 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: 75066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp951068vqo; Sun, 26 Mar 2023 06:59:11 -0700 (PDT) X-Google-Smtp-Source: AKy350a0O/NxvQASqDIMKF4P2/fJZ/5bRc6OPoGawcrc5AEjjtGrDnbbhC+OKUeWFopkCk9oHA3x X-Received: by 2002:a17:90a:1d1:b0:23e:7254:e319 with SMTP id 17-20020a17090a01d100b0023e7254e319mr9706272pjd.39.1679839151143; Sun, 26 Mar 2023 06:59:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839151; cv=pass; d=google.com; s=arc-20160816; b=kNQ4Wk1D58Z/JtuzGaPtLAZvluYSP/T6Spe2Nt7yXrER6nBwkEyN4uIYpfTJSWxMwR ASHZA2hzPthgkJHVIAuiJXQMHZrDlK9Dnxkkjf9sjkKcgb3RZVGEXl42Rr4IPDALPBiR HpWTeobK8Jglf5KAgAYUva3hACPx16lF+yc2k4xNRv8kgJyvAA3zcTht4AThThpSu/gc 0+7lFX0ssGxuZD0tsbykoHIsziGTZ+OyTkGnN6jpXCwSCKVOswCHfZxJV36RbfsiUwv9 E4ggsa4gAU8piQ7s1RqEG8JOg4wE24kaRoLlHbJK9W6I2qqwtDtNBztXgleZdU8PIZ04 Mr7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+vVCdaTFGXtkZXyLDOxaOfi/6PmqIHiJZMVI3+wmvEE=; b=a6Z+S0XhlkqWLdW8rPjDcuF4cNa0GGMTgfWkN/j6aVutFb/Cd3mBl7mD60d5o29cun /oJArZvtr5PMjo15+sL5UP25pnOHmDiBwj5hwIbg1DXyXj6vCeUOKFcdp0FhS94VC8uL ca232AYDc0WzVwxLVULcWHOPXLUwmJIKM/ECxEdg7UNtdmX5g9cdcqWS+v6+A+WJ1p42 asJDVvtWMd6tRg0w+XDoSrB42eAKZN5Qb2Vgd/uF7XRbz/JICp+SFohJ53bG9WqDc85b 5iMLwZZgxn4sWqhozJtlM3fzSczxL+t1WTLxtjwj3hDblXwgXffe6A3BSBtIcnlYOGXb OpFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=FLbRtS9y; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a631d42000000b00508e438ff19si24793450pgm.409.2023.03.26.06.58.58; Sun, 26 Mar 2023 06:59:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=FLbRtS9y; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232109AbjCZNxd (ORCPT + 99 others); Sun, 26 Mar 2023 09:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjCZNxT (ORCPT ); Sun, 26 Mar 2023 09:53:19 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021022.outbound.protection.outlook.com [52.101.62.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6322D7A88; Sun, 26 Mar 2023 06:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PoGK1hoWcW5JXX6k63W18u575S+LffM7y77LaMrKRR7WtgjRILd+PEeI6d/CWOwWW87Zbko1QKrP7WBOtLtLh6u3j8/Hwd+T/yjqq9d27fShbnFgv0EU1zYLfCsPSxXTFtYmXsjVEk8HBwkjktORXBar/z5zNxxHs5Q+G+iwBZfA51Wn9MFD82GOiZ8AQaV35mRZcHafQk83oD4RciUBgoUxLrw4rKXS8KSgHwYO9SK5rv+19YIlSLyt4+ErRR6fdI6BTDrlGRc/P3rmy9CVydi5Qm3xIYZIdhxzva0gZQc1JF6JyU2Ysz2gHq9l3CzbFk8bKTDvP98iqoCvU0iL8A== 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=b0IuYMh1KaUkIN3c4Pjp4nck1EnYK/kMXuIvGeISZ72gnJHvT7X41mNdvVdFCxRw74n7CIigIXVGeqqaV1ArdcNhPhsCLg/5TY6t9zVVCHmDZPODq8dWFCqFg5IHxKT6IkIVHEoeoIwDBpaXzaTsPVx9MN0JvWQjF3EfTCyPciUJazRUoQDrR5dvjCvqX07P1PhQqaEOrMSWjSSLTujdkXnSzXl7B2w69d05VQ2wheejOr3xHC+txhI2vUujlUyDzGYbxPafKkb8YIQ/wFhFxyITy+X1yCBRRiLdc0M/TydFmsFgE4i3Za+3859QvHMjQ1yByf0qx3hFsODpLC2rKg== 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=FLbRtS9yGjcyhuMk871R+IvisOrMCPOtYKOasdkSIn92GPkh3DBEaW0fZHTGCUApFYe+L49cZ0xRf5uExONGWS7OZ1ooJN6sYV42c/B2WtZdUVQuDO9qmXD3h8sf6yxeTiCY/Fw6ga4EVc5EPZWXj6WGL4ql9sydtzF94J2tJ54= 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 PH7PR21MB3044.namprd21.prod.outlook.com (2603:10b6:510:1e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.16; Sun, 26 Mar 2023 13:53:15 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:15 +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 v7 04/12] x86/mm: Handle decryption/re-encryption of bss_decrypted consistently Date: Sun, 26 Mar 2023 06:51:59 -0700 Message-Id: <1679838727-87310-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|PH7PR21MB3044:EE_ X-MS-Office365-Filtering-Correlation-Id: 0be3ba50-76ea-4d2e-a7dd-08db2e017297 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JdUm/R0lWK0taqorcLmc75vT6I9ybWPfnGcDNko1z3thiyfKt9VBFZpfNBnHXlmUKUHRsuQRZfpjUm0Wxbd7wqbOl3YzquxW60DyR2wWnU5DdvhZCUNwJBZDbfqHEAZso3Aw27gU2aReXhjFKT/7iX3O46U0Qexzav3tiKbuWfnnw5JUEJ8kjikMY6qjnHGoWjcl6vWfn4/k6GsOOBI2b6TzhVpVTRwiqilPJ6puCH3eNVaI/buK6ECDJ1SsUrEGdTYXxa/OSTTvaNN4mOz5jcstIAopEJKH1w/VOnXATB68gx97iSb35jF4PIDKaRyV7H5Bftxdk3RzV+Ahjus8NV3tpGTfu4t/w553O3bl0C6PK44BuTkaOicgE0ls9sx4LHcp9Uqu0CrK+LHkVh9t8RHBaM9loac1sMU97GzJHNdl2v3nzpAHEA1B/uGylIK2StVru1mxuA2MI9iXhRwIDFEp1Rr/Us/yitV4hG+Ord8zeprnsrK8KKdk73H9AGhX+ocimVWW79q2/ecwclLBvOZY3JJN6wIZYwk03PJ1tAlQ4ampmYeaIaQBQ7vqhBDGt68waw3lHT2Td4CF3e0uS4iZ+5NSZBBWu419H74EUrOiytkmDsPdtw4rxNTI6ybNZI4efqbtyPsDUZOZJgrxRf/hFpmHIzGNW73GnTP6U4NICh1jm2mSWrBEO7FBCD5E 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dmEy6PY7sTpNIjh3tcXKRRA3YTXI1l/E0EtWF0myN4cgfJlqqrlqWGE02Tf/f2D4csuuu7zj9V/oRdKUIv1CbKDL7gCthQHKTe8CZ4xRgjWUjuTj3UpU52yj2v2zmXnSVC3fDJYSa+lAtTDpdV+yTdZRS9qgT5ysGGDu6MFS+jPAmQmyZNZtIfMJ4arfJ0Qcx8kGNxh0ha14NKVFydKY4lVT2Dr52cJ8gK6eDWhEVZVS8Jir3uDLYN8Fty66MRlV1rmqg68RLPruM6ibPW72ArF47C7q8PfyvAouyy9hKuz77Cw+yQeO/eO49K4d+irkt8LOlcw5u0kOyl24CvUGL7Xn74nnGoVuJYqg/CANM26rf54RBLyOh/rukhYHlSir4pR0mHrl3gMzSOW1YMi/uy2MA0JVJMUIKIiABvIDa01+wZzaKWl1npjQ3YqWBWboBVzak87prJG2L2Pi03OdALvUnyxTnoL2eYhbEbPIiV71XPFv/GxB3LFTnFpTs1z10YqTQMF8HhQLqczt1pHg85fEXcdSdFIO+iv7OJato5PPEigPzbT3LWVExCyzG23hfSFq34JK6o+h3dbP89xw/T2wO8Emt3sPuPRWfCvthUirIEHUrxXoTJob7L4EMXcAgWdl109xDiZwo93uPYPXjiM/d/vMl5WT+Lf6hjOJOEKf7M1gxeCCZKCaE/dbo/o+OEVaA3xMAGeqDBIww7+TDBGjkIrpOM38zHLpaiSRtOYpxdNKqjVYLTpGtNdW9i+QTqyw0UeKGZ6hFnvcqa3eebGrCtztpqSDHu8rJpXDZlFtjTkPLpR/9Dfy17cOw/KV24ghDAG29o3lg3FDL3ffmaLsWCYDM/nfox8fIU+SZouJ1K3q+JLAjqNypTUY/jXgGU+x5eul+3ntsv+z8fIa6YuBSgWPGEY2t2MIR/cI4pazdtT9/q47Ks0Ij+wLTKs0hbAF/d5srISuDSkWjZrq7UjKwVdT5PIhbHLU0KyJsxMsuI+PPwFq7vi5SfEvKemny+ICKFKqTedF1NUGH63ZYehAaNz/9nfZlmrZNO2Xv5e8/imTlbIw0mdlDGduLFDOff5B/h/NlI5eJJstYH1ScK6I9koftY6w43obRZmSwEBJIO48GoWFSOZ6Qe0IwKmP+Hbtg3KAQgFGAG1IBWlhEmAQSZb/58v9iGrgPINl7x5qUkpXx08hg+OknQjel92fuIeD/DINtwJynU3dNsL6B86+X8xQzcMpKc163+Kd+P4JO3Sl+zLd59px1qVabc+vaFvrgJCj617Oh8PWZol7CDlm5f94J3O0tyq5M3pqLif4zsSneiFkiIyf9OLo7U1pASB0lNW7ecPq+7zQ0axW2XdXOQzac2m2qSX9HUTAPFQ9rl669p/HSN6P0VkaaPCnhpD+J976YJAAi3e/eKa6hSSFQSKJEls0AR5Dkh21aDnot7wxNibBC5bPsd3yqYN0Ol1A3Tv6sFWCliwXFVm2tAgvqZg0+UcgBm+Qlg8r2xpW55FXFdZ/phml4++drrYwMETGcJgO8hUhLXpuhZSg3FbY3lBBWotshDFiyBESeIMCGdbsfg0Qd+fs9C8oduQbYwqrertC8yEHfyswccYHVA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0be3ba50-76ea-4d2e-a7dd-08db2e017297 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:15.6751 (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: vdF1y13ySNbb7E6pDdsNOt2DIgo0HWAAwBY4YW/fXq7SHFlvkp4D19xMV6dFXAjofCwAWTgF28Exz2SQ+ZpiJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR21MB3044 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439018173020622?= X-GMAIL-MSGID: =?utf-8?q?1761439018173020622?= 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 Sun Mar 26 13:52:00 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: 75073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp954423vqo; Sun, 26 Mar 2023 07:03:20 -0700 (PDT) X-Google-Smtp-Source: AKy350b2GuNhEKanumncPQ7u+sNy9U1uUzHZRljyiRtO5VBXkivQGK1/Q89X6/CKpkcBBcawjyWW X-Received: by 2002:a17:906:580b:b0:931:20fd:3d09 with SMTP id m11-20020a170906580b00b0093120fd3d09mr9100055ejq.17.1679839400758; Sun, 26 Mar 2023 07:03:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839400; cv=pass; d=google.com; s=arc-20160816; b=VccOuahGmJZKP+FFNElbFpTJLcJlYkf3pAPCkgE6t7d+TBQxU9jN+yTm56GztJ5++T EfJ1d7mfiErRIsq08+78wDuE25OIJAuqVAiyKULFgEAo88O8NQ21OU+3/u6MGLxJvHXb UHSrSivTbyjYl8bjRGhR8nX963Y38zqnQLxS1L/RJ3lTx1/C/j2TuzYdIVHnvMt5mxuo 437a8Bl3p81cAQiQzsPF0HNpBTVUd2HXuW5Er51+/jm0L2YXz46N2D2NNZss13vEvlM+ XRxvSnL5ozMkxmUEAOts/13i6r+lRFvAvTXExrNlaeX27uZc7D13joLwa6lgYwx3F2ff 0LXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TI0Z5NqYyhBpz2WATYz1OMj1dRqVGimeG7liXqP/WG8=; b=wvpTW9hGq44j3hBoXfoo739u9bGpeShVRVoAgCHH+l+fyOph1gTz7jDwRwKIvJ/IqN /iQ1u6VQRw2MDM0A0XN2oPvyathJBBJZPMuxTNFXxFyG/qSF0afigUnZOVp74v6dOgnf 2zlzgai2vggdHxiUil1jd7ILZVTIJ6ooIKxYpsAifoQE0LpzrlGqCLrg/scCRraPvzsP w/O62P73h3iC1xuT9f1I5rUFEpcjnF8FFGRJ2RdWodjULTHi6ncNytiZs21hbFkblUPD FgL4eCQsdfrC3WCE2/m/ratNUeYr7DMWmSau4DB0A3yXF7WETsDNZi1iwNthEwD7LnJA j3Pg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=fPZLI+Qj; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xo15-20020a170907bb8f00b008b17569ad76si11907940ejc.241.2023.03.26.07.02.56; Sun, 26 Mar 2023 07:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=fPZLI+Qj; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231976AbjCZNxh (ORCPT + 99 others); Sun, 26 Mar 2023 09:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231297AbjCZNxU (ORCPT ); Sun, 26 Mar 2023 09:53:20 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021022.outbound.protection.outlook.com [52.101.62.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965ED7A93; Sun, 26 Mar 2023 06:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dtG28dw5Eg9vw7JReRKjSNY8oHhY1H4dITSGMVwVFMPQMQGOHwDSBOxrsrGnOyNrvpA0JxLheEXnHHfODMagXPY5buJsSWfHNhJBN81kzmGUEqh76uigqHB+ztkAtutdWuuse4+yAKIbO39Nzt+ubDWyubn04Ya9V38lPVwieuL1Z8FCSTA6AhlS1MXvP/r9IRr9QO0NYlnmcz6YT0LzNrHIIt2oTYqrem7Py3rsF4JOW5tRi/ePVkp4Gn7VMU0jGR6IZJ615wH0SoDpHiZ/3a/e0zZktrDrQi7RFep1XwGfwATd/+7mUKkE5SQ2Hh/d79CazlHpCXePuMO2VD3+Bw== 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=TI0Z5NqYyhBpz2WATYz1OMj1dRqVGimeG7liXqP/WG8=; b=LTwt0cqLy52JFpfBuIzUkI+GxVdJNfsplvHT4IopZ8JCu0E1eYQgGuX364pbLbMgecElDbLr6KoCdBywCiT5m7qg/wQhQmao3zmZLq2KsQEXnqYovcrEFxTRWSv5ItQvKctEp1aO+CDDTvKGe8DHay0mEKaC4SOAPkoObMXotIfWHDVfak7eGp+Rt0COKuAAEJxt6AKyWMeNqxLg4GVHDtMGlbvm52UhG4Kej/CcGfVZyO4/6wVBvv9SgqUGHI1OKxNOiPmXde4Ylrf17BmwVjBCCVDHGEvzOq5Ntc8xrsxty92JyfuNnXWCnXCMgrInCTR2VC5iYCfznPNuB5ydow== 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=TI0Z5NqYyhBpz2WATYz1OMj1dRqVGimeG7liXqP/WG8=; b=fPZLI+Qj6deMC2OGgQ+mU5PWnemtH87+VCkcVksVCoJExd7nG6845ZXKzjbyLQ6KV1OurA7f8p8S+wtHi3pJvcdjv5iNRCdGP77kESvz/nLuhQcblE8RbZ7TN2tlPeXFkRqVK1t4sBDdQNkowUGofuW+cPZEIYy2RcpoDP3x2ss= 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 PH7PR21MB3044.namprd21.prod.outlook.com (2603:10b6:510:1e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.16; Sun, 26 Mar 2023 13:53:17 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:17 +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 v7 05/12] init: Call mem_encrypt_init() after Hyper-V hypercall init is done Date: Sun, 26 Mar 2023 06:52:00 -0700 Message-Id: <1679838727-87310-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|PH7PR21MB3044:EE_ X-MS-Office365-Filtering-Correlation-Id: 81ba3182-375a-4446-26e5-08db2e0173d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6V6A+rQa4ZqdAHZzMP2wT8g76b55FLcujp9ZU32hg2Nx6ZFHm7aoWasNEZJQa0NRici5BpAunmCVDGilS7RPqfN43JmVCy1HH09Hdo+urlz+s1Tbhuc0vIqSBnofwqEBcxmq7NDsDkGe8XXb7hLyeLS1AdjgbCIl6J0QZIb0I7irzzJjvNjeizzSXySWp6gM98VdGDUcsnfcw4dLrTxZqtfN5b3FArZRkJBysQsd9YOceAwv+OW34X4wxP60OKT91gR+nPpSzAsCkRlUsYEdt4I1Q2J2KxE3kbfD1CfEBqNVPutWa/N/2pgwUaqZ+joHvT2d2r9Cg4LLBAYvNx/uZ7FSqDLty8Pre+v5u5Ra3PBO6Pah6BxLmELdUYKrgu+kt1GhKegIjibFn289z3qMnk0j0q3pLquo5w8fwT+jZz1uj95mBrF3ZcQ/xkJupldn3oTZrDyxAKIYiJ+GNISm13vvMR6oy8t8wTOPQz9zdrqj3Rsi+UpAj4OsEdkhTE6FvwMl1HeWYSNHS8/vhiLkQVD8c5UsAXypDrk00vbI9tX3MxaiYZtrQeIbpYlcW39LPyh1Wx2aZhjx80XpZgJMOcioCAB5SO5zoAdjZbMmc9zqCekdzaAoR1tHvP6tob14m2/5ygQ7uPtPoi5yj06fblU9c+71Orts40wOGqJKKm8iSItEDqTaY1Tp1Ok878kk 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pu2n3UtzA2yxKK8wXMDtXmxgu0J7c6QU/XAffJfyvJdP/LAQuyeajQm/T0ziGepkedn9P97vpw5CsDAlMjPyLmU1GH0z+ltsbm13gFU9Z3ur7bBlbNtf8KENe1E/zgFsNal+0R1cqaxOWLELdfK+KQT2NCOZ0aFSwbF+mcFCEIhpg6hVIAdchzZnUFzLrA0s3iILZclDY8kpvZA8hMVVLDf+HCjQG5plDOR0FRJh2Hz1rZFGF87LgVHLzcylRhvz+YuT20bjHQFvs7AmU4hy92FtYLBG3yBKZLCLrdX8ta5LuQptk1wd5nK0IKswfy1kvgJDYz/+0mOY5kVLy3TUZL9LCXnK1BWNT01nURtiqBP9DUlo5rugKmX5EU6LjkGPesw1ieSpDfyeePbcHXhRh1RYFH1p7nbwNB5/WhZuYiQIxz82sQ6Wo84g3hJzi2AGfiqkGst8FoN+O1mS1WGwRKhBWiHa0T8Fvt/pngC1b5dW/MlOgfuWEOwSATJUVxUPYVI6ZlFNycEwF/jmSyWfEWaHpTpGU+xdZg/Ci8duw0kzPVWxMBlS6+imGZq1/rQ5CKhpYjRRujW9P3O1Q9hINIgFf8hg/qeXsc5JEQpp5siiyvFYAo3F6N6b8yr0WqybeEko/Vy1YFxtZorx9+vff6LxN8vgPtGgSv8tmrG+HMDnhnYbxpghJXPvHsFalwDctG+cisIvPGEXIgHfIvJG23wSAcezajE6DXZ5ZvK5dZQIECKxX5Wy9jm/8AsRxqaEenUhvCwBXMYEBeFTj5+2kEI3+JDngtY2KK36TqhKErIS2AfTasmDBirq6/RYOAB44nv5kFfi7e0qaZXI4Cait8MnNl1ChQQvEGBYt3p8pikvelW9DXF+smeE2R95yUxe3INqeKYGngmO8SuPSayqjxAd8L/yR+WeASKHCHVM1wZxFCEW3cJ9g/LYrsN/rJnfnvopY3UHroKRSZg1Ex1Xa3LoA+xd11vkpmm4CT5IUZA4CbFNGTqverareG1ykBEqhfEf2PVf9REXPN0XYwhzEX48ETfz9EB+F7Z792rSbMDm9P1T7Ynm9GsxgF528qvzzoFUNxfb70hC0f+zw+xLY003s2hhortd4/UcK8SX5dlzEdrFgwFCIKlPefWw/soatQWEag3CBUgEuvocaH4XRGX3wJ4wUG3iWgoAe0NrRBE4auDZ8HRADbH9F0CgYaVHWuEjrV50B+kVMo9ejVSd0JMIQZbrGxbp3xjjft2bLnAL5lJsBJ2PMNU/P2+t94puVLytGzGTzt5XYrPsnTUxmukkA967sZhTUMk7iiEk0JVS8cGj2ceIGn9g/TNP0y5mQjUyD3tYTtNf96S/jy/ngr0ntRWLSKxxUbKN4/yLfjIlRrgGAdt3GLwFeo1nXJin1mkFPk+7NZztwPdsxhLPca1ZEcZeUuaneV0PF+qTBG4GRqgMPcwn+e4SXvsc2bNCukkJjB5YwfuULEovDcVjVJriHtWJ4Y8LYf1YAWidyfIQWZCMa8OEm0CCBsg3udUQldZ08Ow3UvbuTLuwtScAnwEzsHpS+Ja+w0UVsK9F3iY8i5d7TtRj3A2wpo9R89/2FCbpSeY/QNAAYoBpkiuivw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81ba3182-375a-4446-26e5-08db2e0173d0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:17.7481 (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: Sm/CV7/wWkMVOexXjBFCJUI1u1EfE1L1WoTXRSZGa/odN7ApzDhELdL3nkoKIldavAdlKKOnPkmmqA/qK9Ozrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR21MB3044 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439279182125989?= X-GMAIL-MSGID: =?utf-8?q?1761439279182125989?= 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 c3a0602..b559540 100644 --- a/init/main.c +++ b/init/main.c @@ -1025,14 +1025,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) { @@ -1049,6 +1041,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 Sun Mar 26 13:52:01 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: 75072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp953125vqo; Sun, 26 Mar 2023 07:01:55 -0700 (PDT) X-Google-Smtp-Source: AKy350a2IitCET8bfKr4SdtGeZFX+fkyiUrrXDrgbnSGms01OXCw6mrBYaFfkkSRSOK7QWW7cSuw X-Received: by 2002:aa7:c799:0:b0:502:3ed2:b9c5 with SMTP id n25-20020aa7c799000000b005023ed2b9c5mr1980003eds.28.1679839315389; Sun, 26 Mar 2023 07:01:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839315; cv=pass; d=google.com; s=arc-20160816; b=qTu+z1zxv8BA1xqc5a6aAsclb9dHzFulrm1iQ5c4+Rh0YCu+jzOAyhI1X3ZelvbUgK zwKCUSbxlFHyoZMF8RcT5lPMKA/dpm9cFgGnBoRhIxNmsDuZxo84vCsaIdCtI2JRQ0Tn X+Jtebq9h/xN/WjWylTRboTO5qeCXaiKnXVFv4R4IkXf49WXAiJjIxmM+/+nODSZfQNd SX/nWovmxxmvYzFIcZjWO/8NCATqahwGBuA8f7z6wRylZfhLmjx2Sxbvttkd8M5Qfwp4 OpMmuQzchlw6Kg+4TZr3VTlqpBcLcRMlrUMrSXU9kEeyC5BmQcc1RaVC+eOa8ifqmVHB zN+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EUPnNioxLganSIyETkUSKKagn93/NWjPJ8gSfERz2lo=; b=HbOtAgSQgF3xH6luV2S5yt19n0I7yrGB6ZyML92DCN0Yq1MWzgCpvJS4CnjT9Zrz5s ROvKfqjFXNgknkASyP55At7mELK+moxvs2wzayJ47GeDPKCcaqAJgVOMtvFrYD+kRKXb QNrOXJwQjvi7YJhRKZCH3/7ZVrE+vt0RUZRnhCnaQiiPWAWWSwn4glI3V8YvC8L5KOlp j6mFuL/LxiNLm1LdJ2ji3GoUtgzGhhHIizgX1vjiZwP03oHix5rWL/K/M4cSEW4P6xa1 YDEAWavLqRhrQzTbQiw7YnY9nh9Qou2OtMzqIASv2Wb9IzJDLmLmb849ihQLELbwNLak TjGQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=WIQSX+lj; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a056402514500b004fafb8d85e2si23974196edd.309.2023.03.26.07.01.32; Sun, 26 Mar 2023 07:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=WIQSX+lj; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232191AbjCZNyY (ORCPT + 99 others); Sun, 26 Mar 2023 09:54:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231893AbjCZNyM (ORCPT ); Sun, 26 Mar 2023 09:54:12 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021025.outbound.protection.outlook.com [52.101.62.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 666E77A85; Sun, 26 Mar 2023 06:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WAsV3CpOZwxg/nCJagy2Y3ZaAjrUfkNtU0EzPuIF8U6oLEzjKSbsxeFZ2A1a8+MIEnzRCcmsFViAQp2vjTR2Kd50NccB+7Wfz5SEJaFr4bv3NrOlOQIcd3Cxpev05Si2hrlfrhM4KIkeH51kOUfVMig8mbVgblHdu0EhTNLFRo1JmAbpDyGubyIOgn5oPQFSHva0uupNRj94NTMk/JMG03BgjcEKRhcJMthXWrJNjLUhx6nYDro/8YR7NZtIupddVd3YdoEzK3wxzPM+96ALGVZYlVSam8r1B6d9UIRPz9/nVsGl4y9qUGvK70IIOAmyWlNjPR+ZGOdZk3v2UFm2bA== 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=EUPnNioxLganSIyETkUSKKagn93/NWjPJ8gSfERz2lo=; b=Ii+3Rsl5FmJ1wwgP8jFgUSTfo4PQVMZdJxUa5QFmHDjHHeR9rehuF80Bv7dBB2ej534mXQDuczNdDDstGo6kVs8pzzIh+nYsRZdmZzOtnPwTXzt+grHnbDQtqRsUy+3LhJttz76nqg2QiLqwUcglnFRRnncCQqHN3RifaAs3ZGKAFmzCL5lgLG9DJKPbaz8M3+qUoZXg878Nli+Stx0IayHyLo7wkzKHXHMDAK5LyT4GB/SdXV13z6hhFKsCGZMrH3dMPNHrek/GDaGdYTKuBi7PUHJhN7QPZoDZzgCRIMJ7R49Cy+V7E3EO4/wmTixqPJS5ysBb4DpRdI15YmovTg== 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=EUPnNioxLganSIyETkUSKKagn93/NWjPJ8gSfERz2lo=; b=WIQSX+lj4gQAbcWk0kEnLlC3O7BZa1q3t7J+Hw7HTfznZjIaORgyobXdSVBPZnwl7x/BcwPg0ORchXvDlZrls7WEvnP6gBmkk9azb6EU8kMB3PGx+Qp+j4iOG93rJ0Tp5OfvUv/wo5NRE7rN8WIxQm0OJmP2hnw+qIR5DmjBMII= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:20 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:19 +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 v7 06/12] x86/hyperv: Change vTOM handling to use standard coco mechanisms Date: Sun, 26 Mar 2023 06:52:01 -0700 Message-Id: <1679838727-87310-7-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: f5474c5f-e5ed-43f1-4c3a-08db2e01750d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8s+5H7XsxmI/tB0bmBizubAim+eVbeUcdOCi6esVpgyKdkGL5POcBApLpfu624xoVK+CFVlzjzQpxUVB/4KJGhz6skbqMPcp6uVJkwrI23kUbdNHakbWeapH9pTvhfrCQ+/ezkE3qzHjUnXPnOG5+txUyPLjec7yl/WFmF72V6bDAJAoXXkpIQPNw1H5p1u1Vvh9OIMHIQjhZC+xYbLhpt88xj+IDWwyPkSu8qUBILFvCS1rSVs7KPpKAp0jIHhlOCl5BGx6RuAPFaQklDNFlDTS9tcyhUm9XoKkcWFXr5T9VHegbfZzeEYHI9MTy6Lf4Vc+EILHg0qyWRzSfKc3irzXcCeMXTf9srDmzozTXn1LkXASffFHq+RUEp/UPq5W0kRP17qcorFn9j/drNHsOTuuvAV3cictT+QdOeVySPBFlfCzc6bWmlchDlmyfNV0x3SHVVsiImCnIXJ57hkAgXuVk/eW62sjrAK9Pp01t5iax8jECtpgT1/D1sO8suuNAlbOntmZ/8xdfUxWydHieMfiWmPiKB6rUo0nfeiC+Zck12WG4tF28if1ebv6SiECL2Dx1CT5WkNyn36orv2/IlpjNEtYn/vLecTVsJ/NrU2ycuuDpEl91IUzpeJD6yhJ8uQZUGpS6kWUTX+BliggY8RnylAQ29gzpBxV3eJhfRc3/MGR7FQXMv1cDq6KcpTSqi3BYE6gMAeolL3O8rcEOg== 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(966005)(6486002)(41300700001)(30864003)(316002)(66899021)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dXHUz2XAUlnnvbVM9BMcwf0bikwfJ4W1LPHGBtuAPDfzI7XUGRQdDgbN08XVCc/8BAbktNSp6v9IJ/u0Rq2Lm6PiRd96nMC7IZ0FpikHp9UMMkKingv7sgiQC1SGpm4xdDViUlWebh/0PGjGBOpG7o7jgfDeA/t57U1cAaKsmzsJ75wMwdBY1a/YhwUBBHPYp7FXsDHUTeUxcvAJs6KaPV7lJYynV+gOfLKOhc987NbpE6Y3kTf+4vOyKyTMhK1Ww7pGK/nLfCYmF4O9Yx5Ke2/+0UciHpSlyTs5lJpjPwztLix3TYL7F0VxO74pVrB8z1OBsoJnl1ZE5JGHRfxVRGBizk2Stu50MF+yj4F9UGszoDWAWtB+c9sj38+F81h8Zyp4IUfMenPVWxdZawnx+raWS+h7ifPwbjhY/yHxeAJgjkddaKW70w+bfi4KT+mB6jwwDcqvvYeCWr1/kv070StBRC9CAXhp4mDiPHrZSpWCacmAH2Q+IMQtSxnFcY+VzEzPfEz6Dt2SQPVC/WvPfLgWS9d+ASiIZfhcCpDIxkyVWZ+mTYNbe1/8VB4V4U3PHXYoOUCO2DOVmsQHF5T4R763EcoRWgwt9HfHJAaQ7fJvQw6N2y8+KHzLFPdUeJFFKNtKr3vkqX9bGOKgxKTuNjJbJltg35zolsybxy0SeCPzuvHcVn4zyjQ3EhrWSE1hQ/qh1l1fMMuWfCOkinTbF9YyoCAtMwc9PDeVRNI5OEJLEMVMnFLUc3I3r1esJktelwDT+n1feI5qjmcGVQkzdOs78cAgjEwSNI8bj0YbEaIIr9M1Lun3ongILWbQEg2a//Y7+4bRe8oh0nGZFgtdDpoldga61dFyXLwzUQKTfJfvaiwUDLiktBzC17XEabxDyqq823CinCi3OKHanPn4KycvavNwAuYX5nLA+Eu9gv8Oi/U6bSwa3DBTLWVfA4e811tLrn9d/jLPuZWWSth2cf6BVf4V4x1UoXVpZI0IXba/iNYXBsDS5NpT6VVZSe15/EUTzHopxrlqM3ASpfGGhVsNj0zlhvOvLHik0BXb+v7O7eUn1/W+dl/KswRLNFL3NK6Fvr1Yi0+iHGaMzsxTpF8Bfr9389JKDVlK+1Wgc4b85mV55ndE+XyqCSuxfpwPXBpOyOsg+l1vdgdX9n9VeM93oVAv+eWfNJJ2g1v9KZ2LaGP53cCYDj53cNMJvnmn3gzg9eKZDJpQJZsSeSDhzfRueYC+IUxdTgwDRsZfv+gejhjM7oIElex9aZXFZ17UxsckMfa3Oj5coFBZKoDGri1rOH5GVdn2042sFMyAiKf+i6pR9fBjPTM77zHsyV1eB5TKvJjtBfmPfYFUztFRJ58B2Na9JL7Mbx3QMplB2twhYBhT/XBuD+/B6RlxbYv2zaF27zRxUgnrH4EODZLIBK34ZgdhUygtzmuSBZW7ggtL01I0DCAgl8vWQrhK4YPt8WuyfnQezt+WM1/LcDCaKVi9BE5xPzvdkrzoQPzlAxtWpdRQ4pQnI5awT2IJCJb5nl7zHdp0QP1ezNUoIqyLYSNNaJeP39PT2D68+YH7nNWKMSYJP0O7Sr4aXBWINsiVMXJFRW70ZEGqcM/UrD2c/w== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5474c5f-e5ed-43f1-4c3a-08db2e01750d X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:19.8102 (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: qUcHEitPJlTIW63UvCbJJE4cFBdRCU1SPrJ/tcH2xOS4VMGeGHfeRXqznoYw0HjnZF9pYm/Ki2dwH+huAHdXAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439189951699011?= X-GMAIL-MSGID: =?utf-8?q?1761439189951699011?= 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/mem_encrypt.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 ++ 10 files changed, 113 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/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 72ca9055..b712670 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -56,6 +56,7 @@ void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0ULL +#define sev_status 0ULL static inline void __init sme_early_encrypt(resource_size_t paddr, unsigned long size) { } 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 f119736..315fc35 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; @@ -401,8 +400,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); @@ -413,11 +414,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) { @@ -486,6 +482,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 1b5c0dc..c434aea 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 229353f..8aab099 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2147,7 +2147,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 Sun Mar 26 13:52: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: 75074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp954424vqo; Sun, 26 Mar 2023 07:03:21 -0700 (PDT) X-Google-Smtp-Source: AKy350b7pLx2k74RYCBKidFwZr5HI54+ld/6dboPApg1QikdGjmbjLplAmRc4GsGmGe5okQPjuGq X-Received: by 2002:a17:907:c088:b0:931:2f49:c040 with SMTP id st8-20020a170907c08800b009312f49c040mr11300164ejc.51.1679839400900; Sun, 26 Mar 2023 07:03:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839400; cv=pass; d=google.com; s=arc-20160816; b=Qb1mS+60QFo/QnLbCExbtr0VfNZ+M1lexAjoyXm03N8mufy2vla6eTU2VYNe+G7qYE mqyY9WGxapaZ6V9kxv5Yq3ylXt9l/6Wt1q6G+bdK6khnVKh07yJTkI7C/swV+QMPiK5I w7VUuuLzcqKx5Fz3uMgDmXZ5tl1GKqZf4/XSYgxDZO5nmJitd/86CBsirNkZmjqOJVlX ndvyA54+A4qI0XWtx/qT+7ntkGm18kcQ4pngTnEFtnC4bUx2IRuLuU79sbpB+Ajd6jjO pR5bcYUv8B2c4MWHaSvM+q9gw9wdE/sBhgTmBqDyR08J6pp/cTOBowGaN/JRjlhFOkwX 0BYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=t5Hd77qDCpkB4ebpkTWX8l1Ig8pl9p45jfWTzt96pKQ=; b=zr3xOK3mStcVii1opDcIk5yo1XN5aIekAvLVDo3iPqP0a73KIyV88EDmAZYEsqM2ck mr0zHHrWPsHhFVoqOTT8DvaVkdG9Yvdp7fWyAzH2Qyh/8MHw+X5xXZieSh4g/Y+YX7Ei 0rBvBhSXe9hb61UCxflUIn/Of2HiQUnI6caT5cBWqRQlYzPTLo2OestTIdZVaOqaFaQn L0fE2TyGFj6PO8y1qsf/Op/KAqpFnZfZmK5WLdklUDsJuPweTaBXc/E58vdMyY679x6Q cXjPDhYvPqmXq+2Ssrj6+KUy4qmmqv98H5HhHwGDTv7Rk5f7iOzP3g4wSq3zTCeFFS+F CWpQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=eIunlEh2; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i20-20020a17090685d400b008b17e994edbsi23196409ejy.543.2023.03.26.07.02.56; Sun, 26 Mar 2023 07:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=eIunlEh2; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232271AbjCZNyn (ORCPT + 99 others); Sun, 26 Mar 2023 09:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232114AbjCZNyX (ORCPT ); Sun, 26 Mar 2023 09:54:23 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021025.outbound.protection.outlook.com [52.101.62.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0627F8A54; Sun, 26 Mar 2023 06:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A6EMMFk25FYYeeS5ZHkgC2sLAW+60xfcvmR4yTgL9GvIOQmCoKXPoAolPUufAIgwshKTPvYogcmZJyR97xphjiV1kuHzMnccfKP07NDIIR0e4X2GQd1F8xDUDDCj8jqIUFZbqY9r1B8mTN+2TUT8N7NRQpQA7B3IiB/I0+9qypGWWIw0LxfdjCvsj9ptT73LMrGeg3EbPGr13F87k1b6XH6Ddf4T6116aoPCsE41wFORATFEl1IUmW1ddhSYvOUCds4hH63G6d8Z7vJH+OTtko1HXBD9z1P5aSqlmCzpCldn0R5bRnvBzwIvIEyMPekNcCi8DVeOTOpVITnaU/hpXQ== 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=t5Hd77qDCpkB4ebpkTWX8l1Ig8pl9p45jfWTzt96pKQ=; b=hG8wvt9/UCDRTfAxkrI3y2Rz4iEoFeZwHKW8UK3cXSDgK6XgCv/RorshxAHT4+AzvtuisTCXlHKbmxQt79puA42WJcO332ttBdFmL0xV4cKGyMLka9Ert591Za7kpSInlfD/GRaFAGUCfrSmtdgn6TSjrz2TUlakQwsPda74RHuqGuhUNgWdv8V6Vd/LhhWaWBuUVnRm23SkEnTSAm1FLMI1BZxB/RBIeJfBRt9FKXhUBO4ipTjWzIJwgWwNZ5KAlTCLeFPzjftNnEWsOSuBeM4DTANgZ1Yt1YXAsaoQ3U8H3uhRR9FFm+W4+i3N9Tzf+TKnbYPVgCPPR2yrFEsnlQ== 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=t5Hd77qDCpkB4ebpkTWX8l1Ig8pl9p45jfWTzt96pKQ=; b=eIunlEh2IYEoCdlmn+QPUHW2RRQzMO5kBKoM2HR5whdZL2lMcUds5qMuSD1RbcLoCKXEoEBCQpebkB0zzT2aUKFzlMU9vpIi7SA4KtQkFiFVWR4QDphf3TWksEWmnCO3cdBDBHquOh3yrOsQmT1XipRvYnYzlJsI5LNfEZtm3jM= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:22 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:21 +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 v7 07/12] swiotlb: Remove bounce buffer remapping for Hyper-V Date: Sun, 26 Mar 2023 06:52:02 -0700 Message-Id: <1679838727-87310-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: 24846201-2b07-4b1d-8d06-08db2e01764a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zv0K8uO8sDvIlqQQRDa8waxFJ578zQZGYPpZKJq46WfzUYxnbIB6NV4S2Vd7DtKxWpKFkRe2p1zv4NZdB2GIUUkzFgEAm/E8xrIatrlMJcBnt6HiGhy/uy8A+IFcRarfJFCZPiSGY2Ayhz0Ht0Qr8xtxS/C3+QV6c4N1ltztlzyl8mb4tKKtx6oGL16R1oTSDq7gnCCa6/x72C5gGG6aFDuzFfAaojbXRknXnTumAJVXwqMojprGxZs8RidHFSXitSBRP6COIMnmoQXg8IUlln9hZuwI3i+ImpUwV1YtSOK3H49Qsxpz7kSBeDzOpaSk/Cl9AzR7EImlPF5hWKTQqzgbAZneoPCXaDmc/vzhvKQiYMLe3BmFTuRuC1s19T52cqbRS4Seqd3g93owc1K6B9wwGldoVTRd36y7bfQkoJTQcmfgnYZQVN4Va3juYxdx2NFDKIJmxm7OAtz9o/xtezwWHixmGCrGxk2eb9YNCkm93PAg5h4L6mNUmvRmM8XkfMTG+pn2Ofr/z903fPSdWwy65kfnTHpSSijIKgaZaIyTkWJDwYQn9ncG+UZdfoTRlgjPm1NsX1QaHpwQyh2VDdNzOpaBZecLMa78eAvh2Is0aXutKoaOTBimKF6XK0rgGaqQpEqdY4W90amJt3lU0v85VI6G4ZXjhyTb2fDt78ZMJgJbEFZf0HPaq6YNGZdQ 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IDcwCpC492yFDlDR7AbUht91hcbefge1xCCgOOgyFZr5Z1ejLmgkIor/otneVATizR9DttJjBKm4u5SZIIv8tYFbcpNeBQmAogbZo01z98f6w0KqQyayDl6OBALoMhSjhp0vr9LGXqTf4oYH00HjUyUTpx5+Mj1LNypqWZg0wHKTGG2A6u9QcALcmsp5DDy1mqCMEXuek2eMHh8/qaU/f5dTDWfLmV/DByOLnT0FxQ+4pnVpxUm4Z+DSjvAJmgh/fXZP0PYO2L6gSCcQ2o2tBQE135uctGDAflmprz85cpRYYZOSusd7+Zz5OjEQ8kOGL6aR3L6wfdq0ldCjawvjvAx3mB7mBBm3gB7MNHJO+uonuL34BfuJWAs4BrDoPayxIFlkt7610jWYUSKWDoPDKD4keH/3bUc/K9+Rfu1BcqGwKX52ErCN3sTUcOYbuIQXXx2CQH9KARZzD+uWe6KZSTYXcdeS4UrlPpFzBUiKGe9+O9jA06vl6j/TyzYoJU4Zubqak7qLX5r+J+vVcO6m2Hlg8a+ppNNv+KQopai6NCUSAqxVprG27sOnXLZV9pfJ0Gm3W977ik49NAS308A005DXlZ5ETo8+8oa/EE18sQrbTLh3Z2YVwYVm9J7rMxW+bJytv78+Bg8/5jq1TCK4QNrnyCAKCtAsjZb2b4WqpcBF1rnlqZNSPfhElB1UdxQIK5ixsUHXB8JEFoKS52nCFD+saztslvrcggpAf4wm6B9tvCMq++M/nyh5CeWZH9af2xUhOtErPezsFePMok2UcV1HDZa5ivFitqYl8xXtRV3sQ+W7u5FoxXWSi0kQxpkzSs7ZvFaFJSzb6sucWpl7nOTV3e0GKS/Vx2laj3NuqvoR5V5GkhgsoO+3vhwDL3UIF0h7eg2MuGj4kRZPWo0u10iysdA/o+iedU6wObOdure/OV4K2VzvJ/m8SGQOOOAEW0efzqJMQXX0GqgXl2U/C2SDC+yAjPkOhcPcLJUTn+o4XyH70+lBrKBuX7ENnZUH2gpFSF3QLKP3JOZAJB+shk7wKlZ91wwsGzBirA1bS/5/0hpLYGRp5ffP+pDt4HuYbmsTl2M5r+CKztnqnym43cWKMpg4CeAw6YEOhVX2RWM4pzNiqPB8qAXsrZzkTYEnvEl2M6ZeRMlOsRkf9UqfHteH68U+2yIZccWkg7g8jB0tool4pEPYvw1VN1/3EJs19NgIVNHPb99npMUwgODUCtnivTRm+Py7Qcu7wtWi+VihpZ8WGxrBAnRMHqzxC7pm6paW0Pp24pLSyhZHOrNx3NzyR0BMGpGn/NyVAB/29265Gd9D2p20Xkj2ucUNTDLFNBRgdiPONAKn9vec9/KpLLMo/AH4R4ntj5Hieyt/Y0xl2XaX0AR5Fz87xTI1fvzNh39myKIkg0YsRG4RgPyayJdwyDD0D6vgvzk/LDSSz02stPG2YA6+67lozjxZc8uCjOFt56rR9ME81cuySj2AAPeSBfTQnMjoqSWtyfh77gvgRYSk2mlkG63mlyAUW9BMjff8mRSnOTkAzYcHazmTVx4+3jA6VrHpZ++xh0OvPdBFdwdsUZxdC2a7WNR6xLJAV8jsr174gNX+9xe7lM//sg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24846201-2b07-4b1d-8d06-08db2e01764a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:21.8801 (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: xxUzz3W4ZBfNop5DZ+lzTX/n9AV2adgv/L4TptS7PIR9hFDVSQScrD0zPk68HGbjKiJMh72fQ0O7ekNNazWXcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439279227882667?= X-GMAIL-MSGID: =?utf-8?q?1761439279227882667?= 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 315fc35..ac630ec 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 @@ -408,12 +407,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 5b919ef..f9f0279 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 Sun Mar 26 13:52: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: 75083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp969506vqo; Sun, 26 Mar 2023 07:33:21 -0700 (PDT) X-Google-Smtp-Source: AKy350avQ1Z/IlL5PNtoC7WXKLixO7g9m56wXhhUphANmhysQJg2BcH2xweJu7fOFceia03vf6le X-Received: by 2002:a62:5251:0:b0:622:85e2:fb93 with SMTP id g78-20020a625251000000b0062285e2fb93mr8589883pfb.15.1679841201217; Sun, 26 Mar 2023 07:33:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679841201; cv=pass; d=google.com; s=arc-20160816; b=tkEC6+CL5LRfhZy9gU3WetbQItZsAt1yd+MKRnbrPKF4VNthP+82Qs8p/4BZ/7BzGF r3hEcNJfcNStfWEtbeS0Ezi6xpZR7qxCOuZWoWDfIwGxyBZP7HIwvcs6iRWfOatsNZWz u4L/MpTc8MgG7hsvLu6F4ynJRqpmKS0eXHq1UYJkCZ4cJx3/7dfa2NaTZ/CfymryfaQv /5t54DoiUf/CHyC1mYzVyPS9DzIreaGaF6qmQ5cToNPFhBp2eO7i02RLChI0bdNmcNW+ pZo9Qq8y69vXIHL7HB9legz3LwTEochLR8AdGq9Ta/ChCJQjCeTQROB57RX1ToJpvi83 Zi4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vEuH5Ee28VRY5Qrxd7yqx/QGPvZZfqnOwBt4Yd6S1g0=; b=X4Ml2jFuqqs2ZQdoLxmp6SbYCl5ttKnfmsEO3lmRM5k0RNLk5xsQuqFSP0nK8/kTnF wGG8x4/uw62UaiuImZKaKr0ZRe2aWNcH91TSK8quNl0wH/3j445KocKQQFVaEdpOsAtf yCCH7oQ7DvzeTYzEwoIBmtMbBOW7Jj6RLHPsKhsR4Xr5jBcBlNX+nsWuOkEqma3dc4jB SX5nmo67I4O3y6C1CppbFGIuRUacCQI3JMo7QOzeXqVGKfSj/Oui4Fhzac4AnOqvL78s Q0imSiZIhkUHzBv2TsXmGsuRXNyn63y58tI4LsTJJ/G8BSdtJxyWXKPWFO7emW4UZdTZ foUA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ZexElqRB; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056a00239300b005cd33628c0fsi27103531pfc.177.2023.03.26.07.33.08; Sun, 26 Mar 2023 07:33:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ZexElqRB; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232106AbjCZN7q (ORCPT + 99 others); Sun, 26 Mar 2023 09:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbjCZN7n (ORCPT ); Sun, 26 Mar 2023 09:59:43 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-cusazlp170110003.outbound.protection.outlook.com [IPv6:2a01:111:f403:c111::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF6B83FC; Sun, 26 Mar 2023 06:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ievpBQnTekX7hWjCJFx8cd9ZHDTIomtdoYy1O+Ia9KEt5PDbYlQ7b8SQHVI8uI4UURwpRiMXb+TS4ao5Y48AhLrSOmx3yfHcPqtt8KiSgAkjgtVeUvMeWQAffrQryVPTzNg99ZtYBxL7qo9IlQhpiu5drE71MqculvsoXfpdYH1AilgDxktDd2QImXXkRRVScGd+sW23dD25oODaMz3Ciz7y5isDPuWSZCTTqyvb2L2lfD8UM920rPLLQxit6BhOl0I8/gszQDxK/js0RGoY3dqi4Gryf1mFzLRuJN6LjuMFs2wT9KFaRBz5VYb2YRgGhDr/M5tZnXu4xuZmXYlVVw== 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=dWdRcujJ21Az7ioDbXrEadTgfmw66mXEmll5LszFJ21xFkBB4tIVO1vbEmFXE3F/FNAnGxvc686A1Oq+ysuqW67+36bpQMh4uuJIM71OrvU9h91Fb62/q0YXbmqDrKz/cwnOEns8vFsmIW+83OADpIX1XssbGeGyDWiAm7jwRIyXdRtmPPPuNg8Sf+s7zPDLjNyYk/5ec8VZYgk4AaZ5IUexSkmwQhN6Rod6h8vFs8QSUJ2jHyZkSl9cNjco6zSWWyGgs3Vr+nBmJ+7kprX3PzoxhNXShUjgeTAeGN5cch9IJRGwqBVis0VggjBhZL53IY9c77rRhU9U241SEwqnCg== 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=ZexElqRB4DpKRM7cul/vFSyfd5nbOsEDe2RDqmJ/FZYmZBwjpeeqm2TxTX4ww2IQiOJEr/V75YV70N29F7Jax9R85GJFzFceE7GF7hGZwGSaMU7++hb1HeBdhKMOK+3SqV6q//8PcpV5Dv724r75JXiEnN+kfZlOiUznPhh/ctg= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:24 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:24 +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 v7 08/12] Drivers: hv: vmbus: Remove second mapping of VMBus monitor pages Date: Sun, 26 Mar 2023 06:52:03 -0700 Message-Id: <1679838727-87310-9-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: fd8408d2-7b47-4a7b-0a6f-08db2e017783 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XCqfV2uMP4FOtfwNua2mmFaBSI4nrS4YyysXmn01wVxeQRaC0NcCqdcDUgkNeLqCXFdFAjlE/RAYPq8hlqFUhaG2Ma9FlEozU40ztJNuY1eTMcsPYm76d4GSayGbhGHrycRhkn0BLt/5PYXnpB9QwuuUYxwNm75vjJBrsB7ytbU67n5gP007/beCTaHTzevCJ63ZOgV3JTDmfZcHFB/Yljio43scp4YQsbrTA4rOis5+ooFcXfG1mI9Lcr/o6V05p4pd/VanZrhOKdO3K1lBV0Y0T6okc14ggWoXdS89dfjrExhHbici6JO3gFBwCiEH+5lbb9coKwLmop75xKVuiscfYv0phutbVQS3BsjFJN0ohAfXByzNBnjqMuCclR5Q3iBbU28gLTpO7pqYfhu68Sxjkc12FxGLCjCallLJa/BqvUoc0Pp0dRBFFgV6fic1QF+PqC2Wi908GudXvJvosiwesgaE4eZqtklTxUZouwxUXcB6SSge88arrvyVb4bdVPB1bDnfhWwRTLRthDhO1fP/pu3vlEM9JwxrLoGxSQlBcLtocW+/lqw/Rj8qe+8HPyDgwfZ2Wm3Ca9u39LFnyuCYLc2jAafSEOR9grTMDL2hp1BTo8PntaMo65Q+zyi3Dfu5ILzdhEm/kgbYW7kSwkD1STDp7tMzhiA20dbofXyaWO3NBAa5LIE61xJ/uFk2 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: alNfdmPcT0NBrNilNPxY+dJ4TQ8tBPZuWks2MaCiAqiscCeaz2xRfgSfV39rW82dH9I73QGyPlCcMSC7SY7w1duu3lE/JaJS4oy79dLuBiOOE4c3XRtXk+74Z6BH9M7d7v6GDZ6XjqYbNnAySFRHi8/bL+YPchDVbPEzJwf3OGEy4ntCcxmO2wcCa88ZeM5X1JLbQtzrRBDnp72SYt+2CalVryjW3LmGhRLcggR+atOSdl0yBh9SVUcVkEUm+aFhYzrrqHQTlchLkO/CYU13q8l0OoqzcIPmYghajUaz83vCwVWUaiiHrrfQT2N5XiOQNKEYMBnHYe60CRGcpK7uCU/qeyrLEiOqtMYZm7AeDxM3Sc2Oe8F97bR53Qsr9rnRMMnCYXtelxrM49fRPjM/LpC/HYV1/uM7wz5gcrQjXPSswKudfDIwYtU0GBWP/+VSKL2QNp86Z3F+9aA5Bkdjx7jsXpiCE23K+osDZCnK84/Jtf4YCiWrMow6JVxgVOwv+PCXBhQt4hSWgi3LjICHXU3X7LDZPcgPTD5p+6p3UjBe5hRJRyQBAmFW3BC1dAusX8aDZUmg/mwnYwLyn3hcMTmnPPQuBkROkZIylPkY7MOPiMgVdPxikh+cPJnhYMauX8RHHVJoQRmx7bzJQhnKAJ3Jtdz28Od5dgRvz+Hmnie73cznlnxj07+fkOGlFaS8L7O6+7jQjMGKcCMhNk2G95wYONWuFx8QrMByZnLhuidTj84kELT0rCsUEhA5BOgxMNn2ZgKsOMx56Z6DvhU/thYcbXR5PWj2/YjpK+5qHEzxVogBUaCOiBrQYI8whCqmEAhEecgGAxC5cx7V69UPwzPc3OPAxnMFe4sEEMvYDHRFkowkTbPJFp8P3cEZgCuxKlEj9aMFnx62TcLsv+Emtt6xWtyrdgV+l0zrAKMaun2bhAFC9/zTq2juyHpDOic2lsKOwFS/IXcOOJwZuAimm4qkSawybSbhn8NItDelo93t3OF9XJDMrKoXRIaMiV+ll22R/jMLA9NwQdlF6ByRGfyhcqUUgMmC3FvtvaZmhBNQhdqfJIZmk7C62GLXHPpr6zB/VxXDNBMYAkJ0ZpFyoIKn0Y2PEbnyvtQWC0sUrLfYV/hVTG+8nrcvfsXc/ReJqs1c5S/0fWnn1hjvdYgGztJwspgbgyWlAyDHUd071Bz6YGxqXmEzIO/iWuEVVrxcBa2kJbn9xTphYQn00DQj3evpphk9xwmnYREU1Gw04nTqb1yh6z/jJzoJSSqu5IfCv2Zd4EuJSqxsnCFnqThbnRtkXoEYML5odwam1a9hGEPT7vEe8z7JHazd/R/cwxYoVdgCVOhI9w+CPls41X3Stlyez9YboLcpMwCBHxeFRjDuw/qfz7/oo7YWDVAFAMCtjiemJxSUJrNza8S9rSSY0bWZISC4cTMStYJ7pe+YZ82I2t0p6+whuvM2W74zpbg69r8WpbGJx7i33bveRv6JhghtuDPkvsxz3iVY7VSRGy4qvUYuayBg0DL2Sf0LQDdbztvDKO0zQyTV/TsN5P1tzF8xCKfDRYAQqt7A7p9Ir2BawqxDkxLb07+UijIPIBIi8BdmJeuGYgcPVO20RbSdig== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd8408d2-7b47-4a7b-0a6f-08db2e017783 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:23.9359 (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: B0kcXYX63JxCgZUC7moEWbRWIXK1Zt6o0x7xs4d+tPWunjjDSIpLPSSqO2BT62NpDwgNLtN9Kd/93GO9HDXRng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761441167732916408?= X-GMAIL-MSGID: =?utf-8?q?1761441167732916408?= 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 Sun Mar 26 13:52: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: 75068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp952264vqo; Sun, 26 Mar 2023 07:00:52 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcE2C6Uhd+l3FH6HEUDIBRSeWRacOaHp0GVjFaN54qhSLXx6JSkvUTKQP/nPPTPd1ox6Zs X-Received: by 2002:a17:906:af87:b0:884:9217:4536 with SMTP id mj7-20020a170906af8700b0088492174536mr9340428ejb.64.1679839252377; Sun, 26 Mar 2023 07:00:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839252; cv=pass; d=google.com; s=arc-20160816; b=uL53E5n+tVDwKMY3tr9t4ltxm4Ijb1emEoLTt1RvLgDxnNOiTEmmcjMyLayhRz4n/t D58GdrwE4TxwyklfXMACYhfj0CY9YBTd3cJM6via4+HJZYw84XjbjAxE4SaBubasQHA6 ILqfi52TdTV/HsHqkBPFZdfMbbpJl2VZwO4wkHQN+RYbr03YbBQ64zcJdfGKOVJw9+eM cx/pYOLoTgtMhsQytPMhY7tsOudS/YAQclH6Zpq03rrls9TQRBZyfMGVE9KvIvxLpA6U f/yYlRM6ze4J+MQVtAdtBuI9xm18MaBrgjjkCBy0ad2n8X3APagDUyTyPXafp1j+jlwt da7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ogveo7t/IcowXK13Ts+Z+XPBvrmc2pZAZdqL5WY6LIQ=; b=GyQQ5uyuKqoq1Uj5sROT/cv/E498a6dnXELlG42hHOc/tTlnxNje4bKN/8mPpLBb7B U8hheV7Dq6kFqanG5n0c2Ha2R6qgzGr14IygwURj2pzGe+CpyW8eBNKYwspZ25girXYb 8mlR4yYc1eSVtaHD+IlSPEzYGJyKJCNPBf3TEqR5wbpAY0dM0AO0VY9Pbvrvtj1MIGJt Rn+6bBxNAHDQ3jSpITeJJBKBgAZ/XHUyXe3YkcfaDd8sf7ZCQNjxSsW/k/b2jzf6oVjd LCXfiYZlL3o02Cou/ziHDcHAZRccuhSY1/5Tfdv3olzL/Eo7h/QpstjpaPy6WqcaMbU+ 6srw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=CtZ9j81b; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f4-20020a1709067f8400b008ddf3c182fdsi18191517ejr.185.2023.03.26.07.00.28; Sun, 26 Mar 2023 07:00:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=CtZ9j81b; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232303AbjCZNzI (ORCPT + 99 others); Sun, 26 Mar 2023 09:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232263AbjCZNym (ORCPT ); Sun, 26 Mar 2023 09:54:42 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021025.outbound.protection.outlook.com [52.101.62.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2030E7ECF; Sun, 26 Mar 2023 06:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NBzdGnozYZ0OB2ytSuF0QWmzUHEvVf1pjWV+4w2WNK7CQw1YdUQh6N86Dm9AHvNLx0avELggxreawQdtGTRtQ4XhRY+5xtP7HNXz/fOeTfiCSv//SqIiTXu6oTBV5LzIyzDeL7VVjYtQptMPWZUXMunrbI9ERFYF8UFCyVh4oqpCRFAFC51jLwmDIJyCCP1Ndot1JpjnMJE7PzC3TJibyxJiG0hUWz1oe0KxsPz+iXA6q57Oqa4cddwawhumq4PBt/nO+PsOh3+/WZQMQnY+4SCc3WppO5VpOaXR2x4KQsfkcFW2g2jfBLKfdvxM3yD9pb3NiT5Vp2CPslJ3di8f8g== 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=HohFbk4hBCnVLjNLBWp3K/Ie7KAdJdY0jFJzPHXZhfhllJ2MprvyhGr8ns5vzRMvm3kJ2UV57aJqKwaQ5BXeCdOI9lOAtp35fW/dDhl+b1CuMNKQpTjD7AZrNvbwcjezB9sTVLx3iewVjLk0cO5hXn34RiPVYPyf6d7f8zLwF2qqnq+lVVxyeSpN3EWbgwSogZudDIF0YkQfy88kFJkqE2Wbi8UZ+Nh9YP8DZiR27igIyKTFT7sbSkkOlt3Cynw5DgCp9cg+E8ErwPhVygzwdnjSwgLnpR6XObezMuOkgVEmoQk98ji2WDKleMMqomBZUYQEs/oQyr9opRlIuvi6ig== 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=CtZ9j81bQR/YvQVfPIOROE5hrP/0faUOJnQa47/mZjoRcqbv5L1L0fTDBeZHTq/lpF7xR3Dfq8mRBK9MJxBjjW28Z11Ov10eB4iS+UQ8CPT7DYJMA5K6H+FbBlZK6qJRRSfdVet6y0l4NnRCBl8GmwRfL2b6AtAthKsy+frKAcM= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:26 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:26 +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 v7 09/12] Drivers: hv: vmbus: Remove second way of mapping ring buffers Date: Sun, 26 Mar 2023 06:52:04 -0700 Message-Id: <1679838727-87310-10-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: 2aecd170-39a8-4e80-927a-08db2e0178bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OVlkv08PVa8+45487HO+svSvSj/xphVezzJrpy6CKsCmXoBifaIAsIAQC/o7oBKTfFYtLWh8bcHkH2B7OhIy+7wEpeRlBe92oyonv3HWMeEURtAt1sNQMmmc7DOyLqgvnBSUnbetMvNMZMGw0Lu2e4Dj/gwxehcOfl6tGBVfXZL4FEEDpWMa7Ll/NtmoGjopRUPs/mO5+br8g55s1NG68kP/VqXveihjt+mrqa+Q5+kx6RUprF971LSNamjdHVF0Nk9x15JHig2kCc+JPsuUJds+vADfmsxyAd/rnwf7BDjeSYAU9dpEVtwZF+atYiuO4+Sjaey/OHphfq0Txy3SNppvcqrLO7UtH09zHSGueg2oTmbKWhWlX/srjsZv7KEljmHEMu0FSBDq4UN0/FbYu10q5t9STY/VTqTzTYnYPMEMx1jn4tFu+lyBod9q0imLrmUJMY2JuBP2X4xxOyNelRXAfxa2ckL80+hNHrHvGFdBRAlkdqILOZ9mJXtXsY/FhRF/MWvnD3IIt0yRnFCzQt0LI7shJFpnrBHco1ucf4He9foebqHwuvHiu7tj4eYhlp1r0pv02cLBSW/+bKJR2IBdqNOYRrThHlVDqG9CmR0VKVr1hZsiTbsHjwvNC+i899AI4pkhXJ/rXFToHY/LSsO3AQEjGx8lluP8q6dZ7y6EAh3/XZ5/nbvbG+ch7QNH 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OP8SFpm9eTNOw9S9MM/V2DxQMfYosELPN1ycrl2JPMg717Bfblhhq5I0XNn6/sofaJ2DiRc72bNxjeHaazTfTCJ19z0Oo895t+kisuxrhA64Zh9QM0pFRanhnG0GEukLbUrFTugFtLEeEQzWSUJ5brhfz5uFXoA1vs9c4CSOhy2LxreVM5iqiLKJFW5wOdaqQSSkHCPAmcD+Tdrws58i2XD2PqjlauK4hnJe1OL1K4/Cmi17skLilwvpSClih7LLvpZkT3ESKTzed731RO/9JnQbfP2tOigJBW+0e4FbbC5CVPXU6TAwbQz9sgVTkPrlp1x2yRC02Hf17MfCF7pHILwl2zhGhxb44WPr1vXV8x0LKkRROHwmodqo0k/S8cdFnmMsdjt+r/tu1r+iouYOnev09t9Mosr+PctrYxR8RBZJbCJswbt7MoKTxkkJrHPdhxGipOa5UuKH4lS1YqdWW21hHhurr4HpZGsIAET2C6DCK+l9BBVv9sMhMrysGQBjLFJ1lNNipnEzGfxxRTphgBZVkLH7mAK4eUPY9qzta2K7pTLuYf/EuyATeVpHSmeg2XcIUQ9StGcXrmwoekYFHa2kCpV5YgE+jBPpO8CF25Z8cqanA7Z/xy99LIUZSp900hH6wFDs0KRXGM4RHqGai506XMlhDip4voaMx24xEz+8EUrDHqibpXDpOOsarAivVJYP6nSlVuxW9hU9DmPSP3LDtlurqotnLfh/quQf8qnsdwWbVtx6I/Zv/aKACsd6I/LFUzLBekc1K4KZjlRcOOVvfQJKpR0oZL9jFBx+vcouYl6y99LZVtIqjrmvfxFaiOCHwVKr7QlHzhbAb/22N7VsacD198yvzerGwKAGFysBQ8qXKxAKkHZ+OACDlj0b/A9+DK5ph0jCb+WjdDnqnK65QskhrTSKVcJYojYRM2YMBaD+RCn8cMAJSIO3tW+dILr1DMKYaMyNhyFb/vUlVae4KMrmgmZMoVP6pKhUsYPWJuTLjtB5Gz56Oo5ONAGzarlNUeOSAFbZ9Vw3hlk10VIakAbLRB8pSnr3gH9EsQas0IA9UM0nGxt+5oJxjonqkCyrfMzj06ps3s96dtRqahQI15jataqDGl6tWLZyHld8aGO1rKFQYetSZb1AoNw3MD4lgpjAdlxdEkZrZCsP39GPo/WJ2qXfksg35h5dXxhTVVHOBfcpuXomBXIQ7SjzMAN1uclJAT9+hQuDQEY5e5wfHf+csyWCPXk4rckdjajG2Lkr/65/9o2hYpqGVENP0LF+hDOc+mIRTe/PZHl+jc1j8scgPXdZPaukgCSjOV7eL6IBhs6nMDPBApMFfrr4kqsJ38i9jQw25yyrqWMU6p0IAaV7JRVH7LoLJhOkowhyWpJxUn08i8cm5fTcjdSHX3dQ/EXjb9tu1uA7guXf9VWZajMcvBpLVcO0xbGoTVNinJMxi5bmij8fMHkk/buqo+/hb5tYDIpvbtlH4ISkI8houJQb2usij796o/40OjPNcndQ0YC4zW4SMadBKlIElJCL+h82Hbw9sqglISTYtCle8XVxxRJ5CFeYWZ1ltTPBOGLoHJFKj4Rqfk7arCHbsPgvxA3ccyFLQdXxqMrUNA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2aecd170-39a8-4e80-927a-08db2e0178bd X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:26.0213 (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: bLw3XS59nEeJQgtVHpdGZoh+/EZBEpSDy8LUWSPZUbIwPXcBczH4W+yfnkXDY10iP/Rd0id67bEPl0ypAI06Ng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439123902504220?= X-GMAIL-MSGID: =?utf-8?q?1761439123902504220?= 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 Sun Mar 26 13:52: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: 75067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp951876vqo; Sun, 26 Mar 2023 07:00:43 -0700 (PDT) X-Google-Smtp-Source: AKy350bNTb928LfcMf8zDUA0uiyq+E1zrpuxS91Gn4dBLynccXDNOivuqfzsatR2I5OKCf+/nTqb X-Received: by 2002:a17:906:3a81:b0:931:cac0:60f3 with SMTP id y1-20020a1709063a8100b00931cac060f3mr8098667ejd.60.1679839243678; Sun, 26 Mar 2023 07:00:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839243; cv=pass; d=google.com; s=arc-20160816; b=QsoJcFTWXKvlgcGUvMoKs+O3BM4Q0P3T63jm9M6/bOpcfSJKwjW2WmvfX4OF3I9gMB 94s+HeOc6xVoupY7+b25zAUcQx4Q9t/myiMoJvIX7V9bw/vxbbTJcm6fPo0hEGpO9qYB CX3VlN9iAsiE/OopR+T+WJqd1gcP8gfj/CygC2YSekhFmLHoqOwYF943CoTgXcmoBxOe eZ3eT7tSeoiHHxKPDSM8/sR1qj1l2gOIeIq/zmVRzBI/zzOn1DF9niOm/yfHg+USha6W Noa6DnHT/Rb/mo/i7g4BZ/R6m+/RoJBB1rwHP0AyVSggshUc8YTw6hQtPciQ4x1fmFGy Zp9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=btHCRwLeI1shgTOdpYSDuK5X6Vba/jr4GkHOzvHVEYc=; b=XuwYljSRXdQk8FuOktpv+UJpi6UM9LaXfzW43pUbY/zMuutOimNWyeOiqG33X+Fq95 Bxg14Rl6dgTDFm9Vc3FKE/IhdME7tKbrFMEfAkvXFkz3Glb3pNiTGRuzj1kH1ZHLrQsX HeZgFhl0f2LAR/RVzxkqc67mXE8F93xmmZrRIPj3qRyaTSAH7AMmxBE0T1xiP+RQuYlW AP8TUm8FFaBhk/krf9WLy1Znp97xYIJzi7MbzLX6tPmYZXCSHNPImLfxSLSkyF23EgKz qh7DxvlDPMEz2cDEOtQccmI12z/4rXFTwymVnTolM5RKcDFUKllchlmYPjIKiv0uVAtT zL4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=j17KpctZ; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c18-20020aa7d612000000b004fd298d4b3esi6013781edr.373.2023.03.26.07.00.19; Sun, 26 Mar 2023 07:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=j17KpctZ; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232115AbjCZN4o (ORCPT + 99 others); Sun, 26 Mar 2023 09:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232140AbjCZN41 (ORCPT ); Sun, 26 Mar 2023 09:56:27 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021024.outbound.protection.outlook.com [52.101.62.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD0857ABA; Sun, 26 Mar 2023 06:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gRDb/w8LR+OYfn293u3vQijGuEf3uhOT+XCCEOdw2NNNORVgeuzJsahEPIl8HGN/Ij7/2uqAfdN7LpAFtI4l24Nd8qJgilQCfP+wVgoKs46hhfehsTFeE8zw/uhF0A9UYxTy0Be8dBU8u+MlZxxj5xfreERIj1zWKAJ2FxNKht+TlOGrclfwBKKgtZHGaCr0vqkvTxY+kXm044BHL8YDCk2ajr3geRdUuheS2tUigobK6Z64fW4cYMlKpA/rWtrvj+zB8IYxmTo+QpLa8GFpemTJ/hTQmDCSzIJ2pSPFLjXURu0188HI1iMJvBd/CqEDzrQ8tlo7aDPTc4SKpUaqXw== 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=f36dVR+s92DEPTBGGZmKLHUcb4F+BXqjxpeAeVk14EHQnTee5UdHIPtBkTE5Qa0qwpr2dKShGFCi7fn2FkGOqdBwM29I/7GWW1pFX3jOaE/DRlWBwgPZboGmmvmu3OcbF/RI8foKkY6p6lMBDQWngTEX+AKwv8QqBxgU2RgtWDjb+5aN4DXVnJ4P9FY1VgaXfKhf5X28R0FBrQMIdTec8eIHUYkQsgRlXASjUlzMxA+kja+5+gALxxf0W8P4JG1jYPKWCyXgzLG4EdIaoWnBy4Vb4RMVUbCVTKm9AWBn5TBTwQtdvOLC3IKwonNvAz1jrtmXxI7gNbE82NrrjnSqHg== 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=j17KpctZQPVPDcMJlFjHiPCV6Do0UsQQpxEYqrU6Rrxry++sLWbiPmzte7tNpVheRe8UrTqKz0NYjQauBrscEpK770aRZvC3zHanPwbqWuKnLOq8lmgF4YbwD+g/2qGrqfzPw+LBP6dJGtvvB5fDN5p6/zfZULgRJn97c2PUShI= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:28 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:28 +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 v7 10/12] hv_netvsc: Remove second mapping of send and recv buffers Date: Sun, 26 Mar 2023 06:52:05 -0700 Message-Id: <1679838727-87310-11-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e7855a9-96a2-44b1-3858-08db2e0179fd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c3rx3+MWVBEye6W7eIkZ25/2KiTegrgV7+DBkCVL9sBLRbgj+UQCyl1WHgU1u0bu4GsxwRCqS6+wFGqV8m+6DGIneDmHuc56bfuh4GXDE5nEYZBpPbv9NYsCr36OnEcuB82M5PqYVK3vXz6eikV8nlbhjaE+JqJspZRMK0m/PZ/F6XFl5iCKBMmTTB1LWUuqwN9v2a63haSOeGfu+DTFdqz3BPJBhaIcDaYZVbXwjQB0t03qqVPXfQAoGS5eNHR9mkDZb7PTmca9CZNxg3yPWzPYaEzyLI8Gb2Nq9hEI50LbT8Yh+GNWbWrG2T9y/Gp5V+Ps1cN8doxu+JgpXH/Eyv9KiLjZ291z26/O3VHdc7i18b/VwPzwwMlfiMS2Y0VSb5h/eWBHSL4JaksMPgXEnZyRfhnGnBOs2MopUcdeuwwSRmPIcCl5ZSL6eLqsdW5fTeD2YhEmLusZ4/6l7vlGoyfW4if7Oi3oLOTzTCF2iXRXxCZJeVQsYFJwOa36FQhNh0yI3aWIR4OXtVoGdA9vc1QUQGsN7BoXizIiTjIzfpvFFOVc43566FDWlYAZ9WQ9EgBd2u/py4Wk+0oyjD2rGFSULmctCGeLQEJZ6Y97UeM3PFU7clVozFf8sT+VfbPJAu/3RswodpeyOR1qIQcr2QM3/Rj8GJign1WvUpxOpxSnkpRCv9lpslDV80JTC4tR 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fvyp/F2OQ2W3mwfQzG5Qeqwe8nH8m2xSDdWUP2pgP6a94yqtbhLMuCbXtYlrR99HOeuKJy3hiFSy1twLKtN764pDy7a6JhAM/MynOppfplJOcmRB5HK+X910PBFDvxsCjiuyz4Ih4Bz2V1fHFsArRzr8ZyY2HCGJNk9BQMKgm2YuxFomjlRLIoO7yjcDximtNCq+dSVbVe7uuLZOqPeRo6jLI/d3XAtn0YgL2tdQ1Dqh4J7RT+wOY9w9qozyW6AlPNp1E3uEuhiknSEY2242anUk8DeG1hY6T8GjkWseJssCYy/LUxyo3HqaS89bm0+WeNZzRuw/vVm5rIWE2u/7J8BTLyiFAg2GateHuXKs/rltT5oSTWWoU98nmCPCPBgJNvxJ/nrwW74LvAUo+fJAP7hxq5dknw7EvrepT8ZyzxvmAK80HIR/f0Im/zv5qI2glo8l/vMUw7VDWxRgwBLnShmWp1iv67EiUWJy7+tZUcEbdXT6bFh6euYY3C1rf0Iw8n0PCF1c2QoVZzg8WrjWhZ+JkzULcoTfrMFcNgCF6rIqhX3xR2aR9hfBxO1FPNUCVFktPA49vlQ1AajdGOGLSOvo18sqML8U6+v9germLrkr/PvGL1cZgF1kCRfEBAobb/nxlO+d6eASM0KQKxJzQXT+Zmt3K+YXXCddOUZIwGVsdALxbwczl4UMi+6FKd3M4j2YAPbyBoFPkhtEl+VACkdyqZ//h5p07FSVIdpfOqUxvbQh9YpnAyliMQahkFLytOLBy6AdW34FVybkd/MBLfzRrrcqB+sqpz7fUm0lYK/1ax6XKDoqbUgZsR+MB6Tlgdr78xDYvIpoJyVOtPGSY69tnW85L6g4kaQ8dN1jGJlL5u73QsPpDW8ERJLO9+DnejoJTv1zBEh0tac/ara/xQ8Y/+4uSmhrtagwM/ePxwm/ovOaQOoVxTgV3AYLg9ADD/iMMI4wmvTUEIrZK0UG7jN4GJfY1/f5LxRGwJprdPw6jAtGpVd30l3RCichlpkyYe4lN8ir33zSxH7ynC1uwx7NifmDod1azcZlWqNg2gMXKW2DT2x65MRsTYVoL7BAFE6EKAaWV771M+ykWsnGAv+1lRi9a+Pk5LE+DU2LeUTJ/snWi8R4bC1LW47bHzTOexDNS+4yKkk82tOBdbBF307nUq9wtJTT3XFmpgsEP9hQCfl2+sRqpII1lmZULn6VYXQ6ATCkLhShf76YMjc0SvAIfQHoXb4jlVWPF5OWLn/joc1hEl/mK772QT/1YExWDypLDgvP2slD3SlxHqisNEp5QIvauLqa9Otqr8niWmi5uLXIAg16HYClcacsrGnPtbKhY/uXxPQt+RCtCJ+85S5I6RC7PRPgEya5ImWqP/UEqanxUofXlIKJcywoYdfVfaGkyHWU4c2MqfIJYxkS3bGWnDq7ucigDGZN9HTi9BSS0oZZazpp+UaD9OrgmLvlazoMHAufvh5y5XrcSX4Ey5ArlpaFzqopYRzU9QASWcyhnc3Uj6CWKOcn+Qk2Xp2JMdRZ7HZNn30jnXXNBSUfnTzkQFdtoOzJjcYxoc4vta1npo+Omgzz5w9ox9A32lEsJu1ZFQ/oTH3I8lomnoCGMA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e7855a9-96a2-44b1-3858-08db2e0179fd X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:28.0967 (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: Xe1ZAw8LYN8Vod71Up4sfdOZTN5CCLvdfIV5OcFcdeF3p1GHkE/LxKA+5j4Mh0vkpLnBGjpn6IkUHi9iQv3otA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439114606401071?= X-GMAIL-MSGID: =?utf-8?q?1761439114606401071?= 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 Sun Mar 26 13:52: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: 75075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp954873vqo; Sun, 26 Mar 2023 07:03:58 -0700 (PDT) X-Google-Smtp-Source: AK7set9+tWtiqqRuWLXXY8NmaJdiGfgMwQKBrO9O4ra7MHoxMW58C48vA8KYRd8P+yWWsYV/dogY X-Received: by 2002:a05:6402:b8c:b0:4b6:821e:1859 with SMTP id cf12-20020a0564020b8c00b004b6821e1859mr15173621edb.7.1679839437947; Sun, 26 Mar 2023 07:03:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839437; cv=pass; d=google.com; s=arc-20160816; b=cW05z1qMYDabY2QCMGVsr9V2URE97a1ZB+5MCLIb20wdMFS8rw/+e4LVA7cwo6l/UE lD0N+Dqn/T1s7EsTPidq0cHS/GhbURLYB4oaET2NT2ghDmarX83vNYU8eCPAAzzLxvRz C31qcOuUtzkIZ5sdPq8msrAEU02ZFKHd5aacGj8W3rt9+l+811VO04OJBT5cxLA7Rrih 9O3kny5Bjgt5R+20Yhp09fgo/DvnkzgQxm+crrNHWTDmN5yt3/JLENfzlog+FOR0/QCo YW1jRjv0LO/TRToHv8nz/sJsUASe5mkexRCfZhRNdz0kOsjkadXdEM1EAAyvZuKoo0R8 fLpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ONuUHkX2s2accV/LU91CFqIQ9xmiy1GHEaZGBeyXQoA=; b=i5Hez5yLvjJPOoki8W2ZANMt6lpfeIcDqPYY77BHhwyuJCI6Aro3+6ugLoeB4f5bOR 58pBPpkH1JMJ/a2NSiEueWJy4ry+lyWd7WIdfGxTsvTJ2YU6kU9qnliSfsLJX8oVV18E wJrAcx0pu/juWHgK/4wQiSrKsMhBDDGcAUJjcNaD3usrtpNIKwPgoafuoBbRR+XWRZI8 b7C1+oSJtx4Lkc0me4Qi9vmgFWeMfqZyJdfs+jnDtWJVw3gpihcta7aZj/u8CzTxJ85u hix4t4kAxrpuaR29/pbq43cKsiT9ioJxHvffuyj11ARCHGRxqiftTTdR6+V6Pmcgmtfx 9HwQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ArYfc2a7; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5-20020aa7d285000000b004bd79b15e43si25617267edq.104.2023.03.26.07.03.34; Sun, 26 Mar 2023 07:03:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ArYfc2a7; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232241AbjCZNzf (ORCPT + 99 others); Sun, 26 Mar 2023 09:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232168AbjCZNzF (ORCPT ); Sun, 26 Mar 2023 09:55:05 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021025.outbound.protection.outlook.com [52.101.62.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9693B93D6; Sun, 26 Mar 2023 06:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LkeczNyTj1/Tm7JU9B6GQITrpGFfKTHnFiGBBb7+OCxKNa0Zx7ab/eytJq5+poSkpIMX2rlb62RglYmFbhMiVArgfC5HdD64yr+Z3AEWzscE0y+WcOzqXADynSnKPWcVrSGhD0AKBXakHFwZ0rK0q91WTIqX0QRTNGnSTo3sfX8c8MagYrhm7gLtDce+XyM7xltPE4AKxcUphWxcTxv31OA+35KZ7NCY4NX/zGcb+IL+cYbCIHeC/fK97SQz38fYb8weUhdI0F5N92gpMEQTs8oRojA5T8sKGGeGqrVK88G0Fp/trO7u1CtOeIJOFhfxFBDIttp6BR5K9LDIzpvt8Q== 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=T8Y/Lw4+Hl+VYT48Xg5u3QR8PFsIese+85TD5WN++j+rNTr1iSlZ7eyubzYqkqP1g4Kn1rjxrytZ2vDl3LhqGxCUKomRgeQr3eeJGLev6SVy+62bivmq9khZKmCNE3pzfg+8FMFCwQYDGKYcmkHOKz7YFE8omstx1jjPjx+0ftnofVnQ9nKKqGwGB9JYhH5BBxZXkvjyc4Pz5Mj6XHPlWwgbbGNnQbVODXMYBmR8FcjdyFW+SfQRujHsPiNVbf3anLGj3nAWTaoZJt1AhNVeXEBeURJTDC327IK/O+Zdbtxq3fXu5iYN5QXyvoo3B2mr2Wun5PZyZVQzPOiyQVm+hg== 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=ArYfc2a7HZ0UGZ/o2gckeO9HXcQCIZ9r3GAg64M45DIGzENCD3n0ZCyBaQ1JoqaEkOIIKsXXnzCwwxVWQP2/v9FlMfjkPHMFAc8wRHFxY3UCgLqapHU+LTSal4P3Tx5+hWyCZdwviguHHbsG2pLWRTnnAKyFmaSXqOmYrx9+VAQ= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:30 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:30 +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 v7 11/12] Drivers: hv: Don't remap addresses that are above shared_gpa_boundary Date: Sun, 26 Mar 2023 06:52:06 -0700 Message-Id: <1679838727-87310-12-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: dcf3a441-03ba-42a3-a887-08db2e017b35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V3e0F1MdQJq0inkX+y5/R894PUIoyU2R8SLr0KrsjeUCEkhVhgjQ9DF9gJXirslCnixHrJfVCK1L/EHYHhxY6GuYf/lGAbkmhoPtcavpzvP+MUyEQnhthG9Gefk20cSIcsUcn/gO8GTPHiyCgOEdmC+buYi7OEOjWf/PdrPNASsY2MiAod7S2www8gPTyZHgd45nLZl4byzRme56eUMly78gfC3MsTrvNoPF9ICosm58a9JtzgLdwuHhQNBfm6jkOOcvp3MhekI3j7nI8rE+ykCGCoqdtWpycpfbPBD6AdgHc1Th7r5OmtvRC+G2Boy6GpS4uOoYB/m22/6EULrC+4Sq54KvXiCaxk5cCFQnjjitshT3h5QAQGVN+Ol9l3YkdMhhEP/kww8gKOVO7GWx+b9StM21g7LC8kXTW2UlfhAdTwNn2Qqf78Kppn5/UA4Rmd7//GZ5QY2msH2WHfKMDfU96SM17AOw/DtP+rxdhE4pPfLTBcyMDV80+nDSydMM8/GTTxh7dXxuxjXKv/yIG89s5C6OhVNS8v5Sbuy5nReXjvR7TJ61PPK2K7v+PQYG7KSjWOBiBGZYHfG1yLoZ6rnirWyToQePvp/sgO5eI04Wl7NidB0wAiWosu8Sm/E5f2fdQWgiujW5svybmOaxobFfOY61Z80tKUwdNhOu6v/3wFYx/vxTuHrn9w2/qqtQ 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(6486002)(41300700001)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qSXq/nYl85E7O1mimCDWYl8PQSKT1OoE90G5RiKbaagAyh0aP5wtMKGc6zcaAjB/PRZtpjMzwjFWxJV0I5cDRVmkMjkcdgh7pgUQ3ptPKmOLWRs5iS3JPBYVvRM1S29L51IP0xmrsnzZu4tytPHZkLiji3ln3/Z1xBnZFqbZlYYkUKxOJ00qtO/uaGPiwa4agzNdOCOq1boqFqMqdqdRuLfsy7fH1fw7hn8JKCzv5E+Hi9HzkyJutZUZh+O7bZmpDPHtd6+81GYi7jPu+wv1d1gn2+3MkBEPgK7BgDooi4Gd5VM8CZyvoIPGOvDICIQrjsewv56TYkMllTvYA7693eVaxh0GZZghXIfkTdBjji1yOdAvxaVzkG5WpxGnXhMWgX4bP9jCtA+ZsWRgC6/LUx5tXnjFQdmOTLD1jELtbaSGZiiu5k/BBfXGgeDBNTX466ArDfAgr0M4v5AVzfLdyZ/E25m2wcqFaf13wruw4GsOHRMZ+1asM7NbPGJ6yQ/9+aT7mZykq3aHE6UJATd4WYzt+hKkr7STkBfBWw8RKCUswuIDRNVCTXKzcwX44CS+rw42Jm8sAWsnzFuR3ndwrSg0Tsevi7ccSNXet6dbDzHLSWA5RcZJ4e2DnVFBVWb5dn4YbNrNNgcHvIrox3guMjEwmU8aQ0K+6qbcIa5CG01TFFSRUhJSl8BjJq/5uAIdwJoYMHLIykdaVeXhs+aBEHHhzF2a3xSDezqtfMzjQfbK2sABKJAqeJrb9o4vK6j8kIIHF2HocEeMc3TvDGbO/dW4NQ70RLYugHI6VyvFdg1gcuRqxluU/pcGiRpNFDzgkMsMqR42bkf65voD+cHWAyyU2xSSrze9MEEX409vJDYfn5fFovY872fd9sIPZCwpgNCooxAJ9YgU+s6qhL6LrbV5UoMCc9AtpxSj9bw/omyy4ou6ZSihahKtM3NXalHCCgxzXmM7WwoHMTHvxnDqIMcTZQ0SkQWQ7FWlDFhBn3dnaSJ7jmGKe/eTze8pf8FVV06pmYTAlBqppV05zch/eQd00P7y9NpVZt0DGQZ9O99qLrpNf/AscA+ui2hBSFa5gpsIqkHX54yC7G7AFpLnaUHawlveX91NQMMtIhemYH8ainvqFH60SPNhx3M0UsHul31XYRIpVs0Ctyyzjzjagcr9hMLdbHoPu+0W+fB98Yfsuk6AnASa1/HSy2WWzqitNdkiCFn+sPThOI+rVGhKI7EwOg+5t8Q07SQ7WBCM8BmY1P9O8HX8nP1zP8oaw0yXcM8YVhQr8eqgs8Pp+Z4RZmvx70z7/3XzYVjcOwThosXB5QbvtFtwVq+f7RVNTFFgK2nz9Cy+vUWI1k1thLyeFKTBwtYTUxXeNsObR61+1wlOVuDr+zyQfgrMy5NM6agPQ35eiJ0svZR6XPPOce+sm4ZQTPZ+1AnY0/U0s9ynJhYAerrvhAgg0F73bjpBOdsRxCGPtDdYauy7cznf/1bDs7mgjnTfNQ5YwgkQ/vYghOyQMqjF0BYEdMTt6kvZGQTLmAz7MoD8b3DfKycAka1Gg98LI5xORuA6CGCsZ3bvKBSsVgSx2XLzVRqoYZ1nchVTbeNhXquUGUNwOXIMWTfmoQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: dcf3a441-03ba-42a3-a887-08db2e017b35 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:30.1689 (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: QiVyTTzfiMJpGhZNivf+WtX1xrGaqeJWSBo8jBWYnKXt9MiQ0WRyBp6HKazzv6OBKJC9F2EwPUxuZXCD5RVKuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439318381781038?= X-GMAIL-MSGID: =?utf-8?q?1761439318381781038?= 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 Sun Mar 26 13:52: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: 75071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp952746vqo; Sun, 26 Mar 2023 07:01:25 -0700 (PDT) X-Google-Smtp-Source: AKy350b4ka2h1rBGhLGtrRTxykBf+fXeLMP6OB6AkA+EWIoei5OGpELBxjBL59uLnXPtqTtJbisv X-Received: by 2002:a17:906:960b:b0:86f:b99c:ac8d with SMTP id s11-20020a170906960b00b0086fb99cac8dmr10165923ejx.44.1679839285020; Sun, 26 Mar 2023 07:01:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679839285; cv=pass; d=google.com; s=arc-20160816; b=DJUhvGPOBw7DFt4FG9FaFbgXHTsau3HlsaxniG1yGRgM2CEdNJx1qpB74LM1L+xj1n BvgxidsGmB7TZybQDExPerbGfUGJeQr4WgBIKW5gjl5D3UWNpTgvd/J7SU4cryot86U5 GlnoB0R2agqgLivpuefOCp8YQb1+/52d12hBYNnnFIXVkiV1a6n9e/CXvuh1MwPQEnXy 5Dy478fV5PrWjjE41q/fC0+O0S03TUwTTL4Wfh3dk0rfslQFx6PYVza7BcHborztKM4C yY/3pERJCsD0AVjrOguKJT2KIQWp5iyP5IB6mQcueqlDDy5eOjtNLaYvh2nkQcpFH2YO cbzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gbY44/+BdsQQ12XPkkNa0EECdNIeOvA1nOIn1gHaafs=; b=lj3U+kym+/FpzqlrVeIyjdKFpEvXChKjWzpcLoTZcbJJgrkRwAakEc3u1PMCpMvR21 gsmIcQ+iEjN/6hC1lSG6GUGgNM9ftCqc67fJx1VJ+W9h+bFk7p+Yuobo2EKME7+auUb1 ba0/fB+LqdV6KpKwXdc9ljdhZFfNbpWUDCQQ5xgYXaqCm16FZ/CfamGpX4BZlsvmX9Qk USeQwQJtk3/d9Az+rA0QOevhSyFwI41fyFQcDR5SIWiW7bFOQUVALWk7mG6mW1C18if7 OhqLMLPGRg4qy0CvWlPfB8hydMAJKGVxbI0NoUMyWEhocL7RT/8dZ6gr+B1Sco6LmV5U ItKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=AGxeYTCQ; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dx26-20020a170906a85a00b009205fe06a7dsi25022986ejb.576.2023.03.26.07.00.58; Sun, 26 Mar 2023 07:01:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=AGxeYTCQ; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232102AbjCZN4V (ORCPT + 99 others); Sun, 26 Mar 2023 09:56:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232140AbjCZN4D (ORCPT ); Sun, 26 Mar 2023 09:56:03 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-cusazlp170110003.outbound.protection.outlook.com [IPv6:2a01:111:f403:c111::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00128A51; Sun, 26 Mar 2023 06:55:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzghvx0apsEnEU0F/Wsp19UI6HMLAzDp31sUM8WjZ0Otf5TVDI/Qk4SPmHIIL5PNhFkVrfvLx0BwwaQbtf3SAgT+jjF/cvh6OwIUNRFFeBIkrIXKIa+VUCvcq8qIYakAsjuAnPQjZlLnguEl7l9MZAuw87F8dixi5KHewk3G7aatwNCzwYmsClIe9ukA3p3dFYmGkEXoEK3AaPrtjAfE+RbzyqVQcOTebumc4ZaFsoCiqINuubjjueMeDUdKWEC5J7Zi6V/oHqKCVebPwKNMtT7hmXTwhiiVy4BZW0gXIbhBbyrrk+bQWK+efUEGtfVeeeMJ/O2T8ARZFdIp8FjNFQ== 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=gbY44/+BdsQQ12XPkkNa0EECdNIeOvA1nOIn1gHaafs=; b=PMHZ7qpEc0/iKT/hvxhvB19soOHkTkIjEsB3uvWJWWQ+Qx7DQlRe1kYpyYOO7yfK/QJGIpuUpLA+bZEBd6qg8VQmxoS/85D3SU+wD9/Fbg+1SlN9JWSoSTDSzLiK4M1+w01vG7X3fC6hjW4fZOu+puubLduIOGhBodBB1RJ03tGZlj003kUpusrQ0MigIDG6YFMg0S0grdbw1+rrLkHmGhJ6Id8NDaaOS0hwKG/tbJaXP9jF2xq12AmjbAzXjHgRp0AIBBEu5QYdgpY4dH7pUolfAJasnJMlSeF9WYb6ILEqepQoYjni8hux1ThsUfvMYybk9Afpz03wG8Pm/fVnQg== 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=gbY44/+BdsQQ12XPkkNa0EECdNIeOvA1nOIn1gHaafs=; b=AGxeYTCQhe6TM4lrLIyIFcgLSSZHCtoAD7b7xn8JGbhoyA6XAn4xcO9f6HPj6a47H34DoKUPLON9bWoaRplzRYgzPjsvMJgLZcVIUbEWd+ZYGVnHRWXiovlhTVy87e8kG0V2QkNLAFl9Bko1Tr6ia/Z/l4oR0w8jcxpXqzzf+zg= 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 MW4PR21MB2001.namprd21.prod.outlook.com (2603:10b6:303:68::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.15; Sun, 26 Mar 2023 13:53:32 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.009; Sun, 26 Mar 2023 13:53:32 +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 v7 12/12] PCI: hv: Enable PCI pass-thru devices in Confidential VMs Date: Sun, 26 Mar 2023 06:52:07 -0700 Message-Id: <1679838727-87310-13-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> References: <1679838727-87310-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0168.namprd03.prod.outlook.com (2603:10b6:303:8d::23) 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_|MW4PR21MB2001:EE_ X-MS-Office365-Filtering-Correlation-Id: 19e2419c-0cc0-4e6d-4b9e-08db2e017c75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8cyK4rqkQ7uhgT/63MQFyIlEpF/sBDl9XhM5DG3uqogonqRkxWJi6ZSOkmhcgtO4NMBvheUXmWxTS4wU1f85x8bCI8IgvrTpKJ/cdpO6y/kzqRtg/mQs1BhGEiyn4dnFM+OnD2RBuzNPC+yjGLhAGywuNpq53WeGVfY8JFzQ4UbiVf+Q/pw7YGU1wK1c8escrCyMBza/WEsA/tVytJXzCK+9Wd2+dMC16qlDEe8SW0i7TRJCDAqXLOotLnJi8l8DX7MHorxyT+dkZFMCCVM8/BfSwC1NStKbfN9YjLKQ8eunpiQcpW3goaQUE9Mejtv/SfvvPQJECH/M1UxoXN0dqTXoj9+Qi0igCXTp9zaL2hJTPzGaJmwYMAQFZg1Yb2QIhuxuZwIgRr9Pk2p8Cooh/unKKYa0raYoavtrDgxIKDyV9LEpsVJvtfAz39yI4CT/dYcNejApJmHS64rck/Hqv0m/DYCz1fm9/XpouVYOy8pCIrGwNn575Q3Sdq/2R6u1n+N25r63i5WSInCWOuVBZ1h6Mn9KhzKqP7AdKIpKok/i0+HeFANkylmPk7sqCjQ1xUgZY9Wa1Eofnq7/Z45HvqTCJoQEXYQYG7JkuL7nxrUQB299aj50/fp+2MLPTm6kvu+agXkNz9oTyJNpbD1pSaGSZjcDcvF2YYLUogEW66E= 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:(13230028)(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(451199021)(38100700002)(38350700002)(82950400001)(82960400001)(36756003)(86362001)(921005)(2906002)(6666004)(107886003)(10290500003)(186003)(26005)(478600001)(6506007)(6512007)(5660300002)(7416002)(7406005)(8936002)(52116002)(966005)(6486002)(41300700001)(30864003)(316002)(66556008)(66476007)(66946007)(4326008)(2616005)(8676002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Rdf/dciESQRn2tdCrxJeAG4Bs1/cjuqNkODQ1RsZssDn7fxDxZqa9rTEFjt4o9HIsZnmKltAGoy3a9NMF0GqX4uOzYBM2lTGOWpmA7e+qhh48HGUct4qe3IEwG8q4tN7RlV1RaCPBhfgAU8SPhY9QBP620wyj5CBadl3me5xgRhHdY8/4BoyKE8u+ltuYH+P0zbIMooGwWBj1TP5TWK2Wa44sU5L06JcRAZX/Mp00u8u1yycKT6+8o/wiF9Zp825u/aQVnsHGoKuUqNENY9p1uQ8SNdy8VKGXQ5W/2AGrFftCL+/K1lfqydtBCmV0uIuq7HGmV+zIsxR/Zo++huSQOO9uHe350LMksm3NhZ3RJGFeDdG+Asm7Q/ApflRIo9IMUmbtyWeNxBoswcN3FMrDUjIQr7yIbw+V2fTOdVsNRJMFuHlybAD0KFDQqOgyAkuwf0nH6bqma6CXg9UsHD9kiAlNCjq6PNLyZTWg9+9Ke9s9nHdYNP8FB28oac73eLkGXriiwmSFyeq+29J1ofH3wt9H60PLlqHf9Wd1CUMAx9dpq4+XGp9+ocWzg/xy6aNmnt8pL8obdP8f7fJhgSdSVSdOuNCWPtEkj/1wh8y8R42eq09dXO9bcXSGdX/qhp1zlnlrEEd0kbOZXJ0cWCc1rYEWhQT2rkp/zFEe5jKASTBGOicfWx503psZleBaDxkH+wVtRV+M3nkXtrqU+a32I8IDnI+3BCxSqbFfSMNR38OVFx/Cp0TLwLWUh+v2VgldXhINyp8bIF7nWzfdxuwMBazWIycUT67KFoEoP/h5WMbvLPuA0UpTmSFda6s0M3ufL8VA1Y1NsX9HBMycu/7O9wUO3cYqCdpjcQJOtgUNFF/SOCmycHcCFx/ELAuA6MUCUjq9ylB9ex7OS+yqbNJDci6u0vswJuDDczixxIUPGSFSxk2+gTagQFBZPXhBx7VJV9/6jueyzG3H0Z7s7x4OAcqBsgcNgDwy7OIORcq835SOJZQiNzb5vdNDwiz6zdbWnRh2tX0EIVyK0bZSYZfV68nPsE7ec4b5skJ2XIrrg+uBwBG1cCsHK+a0UL0HV0ObxX4yc3B97G93MGPcin8D23y7E1foX1QPcc+uq//Fp+fLSKCm47Zob3tMZD8ajtmd2tJA+71hnMrvHTuZhS7enj3D2AtAo4ZDFAwkDqYYg5FDWxxq951oak5Yjq5Iv+g3DwRLkOp/sHT8XLwJOLmhDBl5xfboKc7re7Wd/IDetbdFjg0pIS1H+Y4TjMQq+UZyEYPF2+iFlGsKDu8JW6yf/WPAEvaEG+lr104U5AWJlTBioa4d8UnQIAjpb0J5AZyJvuFPKbAT90nEP9GrplfaMaIsvidjywm7TISUG3IrGsFxbMsnCIB4wr0+Z8yDbKIx20RG+Qikp/pI+/j8X4LLvVX0H3Dm2nB64I/jNnCVN49e1ZY60p58Aei9aiFqLBeAxLlNMBE838ER4dCPx4Km2lnzgI/7AXZ7o9uKoTrOn4u6JYce3s6XRKRJayzqScAwA9ZStTMS9JwGR3usgJeIcFTNLSKA4BEWE98dHkXkQxoE6w7KdPK06UDOw7/JLBcvK8YfEzq8IA97nNw32aiuw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19e2419c-0cc0-4e6d-4b9e-08db2e017c75 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 13:53:32.2313 (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: jjUfcKcLxgOt7KKL9pVc0mCABKvaHo1z1/VkPIiGQzr4PykDE0d03UN9bHjOGpO91tKqbzWFOw4Pt6SBDbdWrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB2001 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761439157910430794?= X-GMAIL-MSGID: =?utf-8?q?1761439157910430794?= 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. Add functions to make the new MMIO read and MMIO write hypercalls. 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 Reviewed-by: Haiyang Zhang --- arch/x86/include/asm/hyperv-tlfs.h | 3 + drivers/hv/channel_mgmt.c | 2 +- drivers/pci/controller/pci-hyperv.c | 232 ++++++++++++++++++++++++++---------- include/asm-generic/hyperv-tlfs.h | 22 ++++ 4 files changed, 194 insertions(+), 65 deletions(-) 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/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 f33370b..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; @@ -1041,6 +1042,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 @@ -1059,8 +1124,10 @@ static int wslot_to_devfn(u32 wslot) 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. @@ -1088,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; } @@ -1152,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"); } } @@ -3563,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 @@ -3572,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; 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