From patchwork Thu Oct 20 17:57:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBBD2C43219 for ; Thu, 20 Oct 2022 17:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbiJTR6o (ORCPT ); Thu, 20 Oct 2022 13:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbiJTR6m (ORCPT ); Thu, 20 Oct 2022 13:58:42 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022020.outbound.protection.outlook.com [40.93.200.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A75F199F4A; Thu, 20 Oct 2022 10:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cwPWgVu2ZuNb1XYp4JyjksPx7hAEJiyknfOR0OY0tLXCM7eMkqcoHoGchSBY+BT1VJkXqg6QZuXZHYGghCRNMBLw9+unqNwGMAu7P59L2ERBn4bbhByitNn4iQ7/8bD44ZOTESnHMLfw28vfXiCdOTdgFS8sQRCE0TxxUTFu3PBTA5QDWTC+9hLqbz72U0zU62s5sIqtKq9uC7GAIg1g5gMsYbBKyZwj+PX/fu8IaH4vUQX6DMyrPY/r8llCdYJsHmi7REneAXoMajS/Bu8/fwnuI4c9DEMx+Bh5svbr76l5jQy1P2oDz4Ek7h1EuKhc5n6CRjImYLkiq3kA17P8VQ== 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=gFDQLJOQVpUWkm3kDdRVko3vVZx0WrPkQzObAxlAqGc=; b=hGNoADVEABu5ixhhMwrBnvHS7Tm4s2riggbjCxpToBSmSyanXgq3vU6fv9k+hGvLVwByE25nerqkw5oLxhBT7iMxUJbx4hXmFYlmdhmelnmnUk508MHX24AHjcQSN6mutJSsLbOK2wQWvCAxhilcfbr/GZZv32Zdu9QylMf3pYVY/64453ii0clsSf89dpTqlijgVpCech6lGxr3K8szNZH6NLZGXHQV1/IBIC5wmb8DgaYE5IBhZ/AZhAcGnp5nj/b01U3geJzL279D5Wy5fM3DfSzds1OUPPE/amNS+uqoY9Zyad0s5cjQvCS7pI+kZ2oWJAia5CEerNMrH2OrlQ== 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=gFDQLJOQVpUWkm3kDdRVko3vVZx0WrPkQzObAxlAqGc=; b=bySuGWgiMZqfMhMDFE8K8mNnzt61mZaM0p+D6PfeAiXi2Vsu9TEuirsMrIOrOcvY8mlLvQH16+lQFxGV5Ws1AjpaDD4/Euhs0UU1f7v+KczV9Zr+k2zPiv1bCjzi0uKbt+3gv+YZXnxWeeu4mpQxg+p0ha7zoXq9jy5SlVZTVcE= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:23 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:23 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 01/12] x86/ioremap: Fix page aligned size calculation in __ioremap_caller() Date: Thu, 20 Oct 2022 10:57:04 -0700 Message-Id: <1666288635-72591-2-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 63219d09-63bd-4cfa-5a77-08dab2c4ae27 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QZvBN3LtGzsafs0AJT24XkmVUW2FNrBHNC4M4NGQNVR4ngUUnaIOvkFIPkC1I8LEQvDdZ3La8qFCbrVCv7DVJ/zN6U7jEbPjPiRtEtgv5882YN3rhS8+FVXFEFuxM7pUKtmdzqDxYsQDDFYBUIa4GFNU7gaTuzp6MZpHveAaMYmydwKDySOgkfekM9wHFYJtQs5dc+TKL7/k+k//D001fmTZiRobyHa/pQ0R8Y2DZk8UOXI3A91QlGl5VKM6Xc/7ZqvB4OR7r7SB3kgct4ZQnNt6rFuVZEcdXSEHOu1xAz8vil0Vuf2H4GbHSUgWQ6zhV6HzkLgmAtWnE7O2QubnLk8PjnlGPuBFT1a7K4FWlOzmwAlswwGgVjbJf2iyzVKYI63cdt6+z7Ns2hRhaMTD2xif45CjdRfjvM5sdK6l13IgUlmyc60vqIMIRmdCnJmF1CL/co7wGw8YRqh+t3B61KiZ11x8xBgp1GZYyapo8Cnwb02Y6+FbvGb0WefQQe3zJz7txo4sGsjvXx1KDWbUZ7ZS7EbuZ0bZQsXCiRGK6490xWgEK3bL5y009TFf2k1EO0UTBXuVyDTootqGq1vYIvU+XwXYjx/apYKFAwCp1utvIAlvSyiwTpbk6obknBMPX/YmtITDi10NB0ffCjNk5lWIs7s5kZ+OjFFXULINPXTt063pZPjyB1+z+GBlwnecmq24W4WkrePTr5YEAsdTmuskSLGa2WjNMQ+b8Vk0KXVjFqv0oEpLkJE7BUCTYvfOyDvhAsGd43cbk4fE4SbIjPyKqjJZFFEfbVrGD/RK3Hsha6/hQu98I9bQ25B8gTnW2mA+4rikZKiq6LwXAzkg/g== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(4744005)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IViR8EqqOXo6V209ArdsQRWE4a8kg5eK9qIN1EH51JYeJJy5inzXDCRpPmXimokW/Yumz6UxcNwP0GwB0VFsdVsShd2kXrI7vKzdU+It6B5cGDRDBvBEs87kTfrecQajRRF3P/gVVnirR/lmNtgTlOVEA3mTG2CghZxOE8Zrv7rOuRYnmRWtqfL5y6EWMMViG9s5glVlDG0iP88cYv/uZj1bodk2DPJU+HqE4enXuKLVNPN0NL/2fANs86PGeXCYQ4VJYDvPfIstVLjgvjMg4GhX5ddzHxPw9HUWi2s7k8RM2zKgMR3m5NYFR2LIiD9L4pUqqLGploAX8zlnG4Xkps/pIaHa0x7/cJ80dW2gqf7UlcbA71PvLpCZxpyn8xZxvgngv3JX0aDUnTqry22yq/Yo7/rykOa32vaIOCoca4lbcIqwoYKhlLlQCyDmcpPiG5B1qXyLdKeZg1/7nTPNlsY2o3NcX0a+SUxSpU1ZgApOnxT5uKAhUA3fL3Uvv41u6i7quXzdQoLohTlAC+XUz+UK9kz2yp8m+BgBXSzPU36+WljK+koUraFxgwnrkcdl+Wyoj6RBufw7zjWKPAakvTcXDRAy312t6CJa4L57C7PxVGieipz09vNU/Qr1VtkYW9qfHn0eidAHlPO2EnxJuKknw3EwlakPugWZU2GVmJffeb2cTm3iMY/QVllqFDvnoQ0ZHXu8SnTKThhHBU2K6BNmZ0MbKmifJNEzonqsWApMfewyqVxzNA6jEhELFxhE1JVcvxHjgY7AOYUGqAsmASOskx6HBsxznqcVwCRSHJINtRbtDbYvM68zPUMCys692Wk2qwITOtY0PCkoXP9uKRVR6A8YJTRFAM4o4t5dxcezzfadKaT+Ae405uQVg6SBD3jcJxkCTZTjF6mIafG4ZLR1PX1Wqm3EXmxeDVRfpr3IZ+X/8wUxnzIdoCbVnUz5CdexZYwqTAHnBDYKZ/S4jAUX+6UgaufdtmtOUGd4B+M5+ye76BV7ukb0AQs+A8kzWMFaEaPruIfeyENq1pEheUEVViXatQ9MOOzp0GVGr8YR/p6mL51/jmmvncPjZku3FWC+I374ImibvzVMjK8kgkfao6IJWdChGR4UgOdCFftn5XU/BBV1AWnbbaekO9Jd7ZvQcXpOJHi2XG6ZAJFg41UwWIPahEQj/W7ZSHid3Egx8hFWHm637pi68jxnyrgAlZJtZENU+uCvFY076kgjM/BaeLA0t29aiWphawuSrh3Q2ib0la9HAjjyqfy+dyZB2opDrZVrGyfsag6iumNBXHmtmsUohtBoK92nXciQkUFiLSx9W1+s9L21LEq4upjgiPauLZEo+TjC4LI4RhekBOOMRiQrtC7NP4VWG2oA2i5IN4NvWUZ8mXtx6tZHO3y+cZ7diQj5SVukgwLzSVnqTacrm5p79sznm6SdXeAuSCvPSLmBHZEAJIspEWIBRqxzatfGQqvv/bT5dgBXPI7f5xVyZadHFgQ/BU5vAnCWUVDLHMRDyz71Ws3OFZcGEAJUT4wpfPCn8PdRoBnzQO7g5ast7AZ0a5dNHEMQjXLjLmKC2dva8Yy7df3eGZLlSffU X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63219d09-63bd-4cfa-5a77-08dab2c4ae27 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:23.3838 (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: whsvVNXcFswK5ZdrO+lwCxXzhsAG9Mqp7yGBS++CfqOGpuw1SL7gXl3v2uZ/DgJhgdGzE1kz/Pri1PKPSFs5Pg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If applying the PHYSICAL_PAGE_MASK to the phys_addr argument causes upper bits to be masked out, the re-calculation of size to account for page alignment is incorrect because the same bits are not masked out in last_addr. Fix this by masking the page aligned last_addr as well. Signed-off-by: Michael Kelley --- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 78c5bc6..0343de4 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -218,7 +218,7 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size, */ offset = phys_addr & ~PAGE_MASK; phys_addr &= PHYSICAL_PAGE_MASK; - size = PAGE_ALIGN(last_addr+1) - phys_addr; + size = (PAGE_ALIGN(last_addr+1) & PHYSICAL_PAGE_MASK) - phys_addr; retval = memtype_reserve(phys_addr, (u64)phys_addr + size, pcm, &new_pcm); From patchwork Thu Oct 20 17:57:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFC5AC43217 for ; Thu, 20 Oct 2022 17:58:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiJTR6b (ORCPT ); Thu, 20 Oct 2022 13:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiJTR6a (ORCPT ); Thu, 20 Oct 2022 13:58:30 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022023.outbound.protection.outlook.com [40.93.200.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0405A199F4A; Thu, 20 Oct 2022 10:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lmvhNkBCc/lnveXm898BUcfxzo+nODD77nqIR1IjeQofUMNxf3VaCsakcfoqyxf7DxTXZ+n5yQJAS6O6zHiZAI/8dW3478Q1nuNFiYbo4Bv1S8hNPIBKGN6NRSDl5/9B13TKq2aJ9yHs4Ssp+KH+ZoCCBsZtCuk6ohMQE7S74RLVstqPOPxDXFzcMzbQREAZfzFt5lm5GC1fE6i003ypH4tsD19wSnT3XRtaZBvuvxsDzCw4Pt057tQULP+os0WTU9x9gVufFSrjwKAibri1XinMO9/IsMq1XBATrPMG18+0mwyoks0AMqn4CsCQXC7hTmsGf5tL3ffcS3YW7aI8ag== 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=qPFQFBJ2cy3ptAG94AF8myzZ+oHcLnbdNyGAmv7MIzY=; b=d7FcQtP9aXY5P9ZOOxHyeTUJVV+ZD+Dfu469/M9/HmnMfxRQH2sZ48+5aCfuHkXt8P7IsC7bkWhZKGcOkyYDjZy92fTdV+RF1VcYhk5n+DqJTCrrF5UAxhCF2GW/P40hb7OL12TqJka7gRI9FEk0Y0FBE+zPKZkzuBraGqcEPJ24tqfNQhm2/an1lNIVfZbeTEypquIfw6JgAij75LFcfguuYQL0R6V9bVa8YtlIzQO2kSNFH4FBIsRmMOKQYKyHD3oob/z1/rf4bPPIqrMsKFBIHrI+5XP9ssKqAJuOzbZVXqptp/yd/9Tsn1Cqyy+YkQ5ZXNgXr/rkrcn9T1MVcA== 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=qPFQFBJ2cy3ptAG94AF8myzZ+oHcLnbdNyGAmv7MIzY=; b=IK1LYIczikzzumQ5UAp4NLuHNcIil/+RFAS/mN1XXqZVSHjrCf1MswMZUzjlS8eriEyuCkPQgcIzSds7XrwCttER7rgGIuKJiItP5EMjAGuzvqKOz6WEWpDcXECt9npN5kALyppnaTeA5tEpyAeofe1SH3Hqa7SDLWsFQUPcbV0= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:25 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:25 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 02/12] x86/ioapic: Gate decrypted mapping on cc_platform_has() attribute Date: Thu, 20 Oct 2022 10:57:05 -0700 Message-Id: <1666288635-72591-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 9db358de-a263-4117-ea11-08dab2c4af91 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zrSbdrQ7y7RyiqAaqk7qcG1PKbmWmmf2gZiH9JgPp7x9L/b+dHabbn7UhxIvsSGy+Kf3pqUalakPxrpRSwnFtYps5H2J1BK+gXzKZCJNODkLrN6H5SjLoZcd0fvMJq7o3V+3pcRdo8NKAf31d9bL14Dt4WwiuOX8ttRYAqXeAMkkYDrnxCxfdJnBFdhaVf2Q3/5v54nr4dBf0H65yM8l//QhFOE08AVijosBg8UbT0cxu7axDkxi7bvUUB8GaUUIUPc/jPfxhEZbD9Ny+3rmM94xAJTTCObfk6XuvhD3Uj2UTalI9VCK0tYMF0af7ZFVmFFaRGir0XLNpSnXVHojhnbykxvsgs0vU8ifExrDh59pHnV5qSOhNPwwMxjklY7VZENe9lMzx6wPKM3BTMDA0Ea6P8CELyHjH5quDsncIquy7j4LGKnXz3nXDvaxoVeKUlb5Dqxh+mZKJ0622z4Cj4eVSbAi/E/yRu+veVFnRvpUq47T1vQbuj1XPUiDTEvoVaPdvIMnfwLbQ1il4ZS3b/x2bH3V4KHqZNcVLtdsz7aNlKPBSB7X7dSZUdalKf2VDe9TOAlbtFoofXFHUqFWvojf7msiLNFx3b9Fby9XIsncAgawYrPf90SORi6k8EQGxPMtDeRjve94PY8LryFiYQdzZKt+949YwzF5NtszmsBJVFZ2ODyf9YszZfUBRQdeObHwb0oXYQ3Y1kDJjmXh8e6PYrdu2YHvalgrOheKUq0jvWfSrbXcPi54k62LsgZmHGf+iKdxMcbURDW7qoePEC88/i5n7Xb77nJ1+z/HPGy5z7aj1o0zBDq765pTQU/FIrU3J4zBldhak9vZrSqYJw== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wgQ0kXLr14ZHtrrea7b2Cq2FNSjWvg+I/OxrgKVpkgb16N+qyurJ2oAXXeN+Y/wrjSN1f5sJmzBLYcQX8Qvx2azYJ58Xytqf2Yz7Ci+uw8LSHafFNgtZjifFSVTzPDlaL1bX1yIv0Ibx5W9RlzY74JRo/1pyrwTwZQ67XpnlkiIJ15suPCzA2kxU6Yv0n4ttumiQxstUo8pxzPnJJBXfntYwKYybspl+0IuVZaryVXHhWjV69wkX2eQMwk3anlDXDHNmzsh5f00x6GMXQhVzFs0qtT6sGJHJfuIdcnenZAfF/qBXV6VJrvyeIe2cOvXBUcqWXZCTICoSzMMTKszQkTw32cpS8UIL7395LGRmC3FkQ7YgDqgsH9rLokwYnLQ7+3bZPz0PIJt1IJCaswAeyDlHR7sJNMqL9bmG88mTaEUpcEPRZy/E/0RPAc/CR/VwEdzNMOSPHFaxlCmi6X61gncc84LEbs8wQxRzBlJXDHVGaLY/QILGKK29ORa+EnuQZ4f1RPRPU+pc91ro9Hw7HfQFXwM3Wwd7+yPzLiXLQ7tcARrWrUBrfsI0aS3+4GhNm64GHmLdq1CxuITNAKG8q+oEokVDVshlz2JmEdoy9yA5+Y1PlDUjXf+pjKW/SreGJx8IQg+LaEEFxRkaBqoqgTNrFWqCGM3KIWfGbatlzMyPLaGJRLtWPdXUIsNj1jTyp0D8dJuOiUBZJk/6XExAkOIe+rGMK5Bmh2loguFAya3HyrLFTXxMD6T1/NZ3sK2iqXMuu6eA+5Qk0EVNTwMz2Fr4cnSEgXwRPzCnGixHCdQHR6zcHJOJt1AW1VgOyDN4zCcctaOSzcEH46N5LwMu11F+xvr56HTuYfisHsL3NpRSA6qh6vGqiLaM6W+oYZ+AkQczs2nNvW3TuZviZLIBe+5vVTrl3R2cVuEEyb25Xc0Zc8XUUhLBmcN96KkZPTBuy9Jchdw4iAAaVzEjMKwQxrywBNiqOEN3n9sOqps6PoTGL8ylRDbvRtdSbwZvBGmJSHcHzFLV50Wl/akk10xxLe5lCkL4sNNq9gZq0X3HTOsf26SHKFrYVN0XSPWKXoP2Fu+k3Yg0UnKVyUecwYtoe8XuyeIgrK6Nv2+drhwLpaAVkv3+20UfHJoiXIMkWnw6YvDOx2Yi6FdXxcFazX3NgHBWHDckRcejWpxwb/8XLjpsX0mR1OSY2/ZH8lPsqxQmFGxh5GxvHQp6d54RT6P4Kzgy5wFMNZnz3UBENRa/K37SVGdJzXx3LDtpP1+jYcoBBqSYMthVHpx80EjGjygYAzzyGM2kh7OkHAm+u6ZuhnRw8fm3rHhPSoe8/F7yHmtG0WPD9ZM3Lqg3W+DF0MsnrfaNfifCENlnsBC6q35lwXKODoS8Dt5xOI6yFZHAymG8IgB2nRoGhHImNopHug9V78gI/hQCujUdDljqnqaf+wrE4aYdmB0wX0wGFiujaPkIWsGuocfHr9mTJLzdljwxEeCRcsn60Sw7zGAtWViCc8j2eKCIgjjAZNqUpmq6NKSWX2WTvrpol1NDbe2CwgimOPgu/ZuEvz2VDy2t/gtobOkUdU6Zug8zkR//JUMenBIi X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9db358de-a263-4117-ea11-08dab2c4af91 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:25.7455 (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: 8Y1g9Un+cEQ2h7ORI9rfj8GXvsXH6+d/F+/QNpbKmVZbuEbrqvIrhWjQENud+dfpZjAUosbWwKGLL7e180FzAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Current code always maps the IOAPIC as shared (decrypted) in a confidential VM. But Hyper-V guest VMs on AMD SEV-SNP with vTOM enabled use a paravisor running in VMPL0 to emulate the IOAPIC. In such a case, the IOAPIC must be accessed as private (encrypted). Fix this by gating the IOAPIC decrypted mapping on a new cc_platform_has() attribute that a subsequent patch in the series will set only for Hyper-V guests. The new attribute is named somewhat generically because similar paravisor emulation cases may arise in the future. Signed-off-by: Michael Kelley Reviewed-by: Wei Liu --- arch/x86/kernel/apic/io_apic.c | 3 ++- include/linux/cc_platform.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index a868b76..d2c1bf7 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -2686,7 +2686,8 @@ static void io_apic_set_fixmap(enum fixed_addresses idx, phys_addr_t phys) * Ensure fixmaps for IOAPIC MMIO respect memory encryption pgprot * bits, just like normal ioremap(): */ - flags = pgprot_decrypted(flags); + if (!cc_platform_has(CC_ATTR_HAS_PARAVISOR)) + flags = pgprot_decrypted(flags); __set_fixmap(idx, phys, flags); } diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index cb0d6cd..b6c4a79 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -90,6 +90,19 @@ enum cc_attr { * Examples include TDX Guest. */ CC_ATTR_HOTPLUG_DISABLED, + + /** + * @CC_ATTR_HAS_PARAVISOR: Guest VM is running with a paravisor + * + * The platform/OS is running as a guest/virtual machine with + * a paravisor in VMPL0. Having a paravisor affects things + * like whether the I/O APIC is emulated and operates in the + * encrypted or decrypted portion of the guest physical address + * space. + * + * Examples include Hyper-V SEV-SNP guests using vTOM. + */ + CC_ATTR_HAS_PARAVISOR, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM From patchwork Thu Oct 20 17:57:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B2D1C43219 for ; Thu, 20 Oct 2022 17:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbiJTR6s (ORCPT ); Thu, 20 Oct 2022 13:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbiJTR6n (ORCPT ); Thu, 20 Oct 2022 13:58:43 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A42A199F58; Thu, 20 Oct 2022 10:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ODiWjPYpXxSwNH2jjBGvME8rMJrqocIvhpXYhHQvETXeYSDuOZ2QXHX7Ea7yHZKmSTyrp+C3ltXrFD4ic+0nUPfyPUGzFonQOWnC/bOJM5udhQ6YDdSp7yfuRABOwBC4f5ib3rq+WVQgCxyVTEtvAKoEIm0PUl6ZVOuG7OIkv9VWtghPnQ8IaGaM6X/R6Va0F4iA6igKPpKCipGo1JYNMnjGNWSeflCuRuh/kGwmeobohxB9g0S6hubTpEgV4SYmUIJVaIQpaEp8tfqbwC9hjvjZBPnA7jMkhJKVh86nAXUnyFKlpbWKMxx41pAc0p+SnhBrRBEAfMH56qD15xlH4g== 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=Sel3qdBw1/pze8y63YrYV2DOyju1dhU548BTTT17Xjw=; b=dxOzsxTNaSd66FhZemfPsOvMamcdCXwzxT3RWLL2r9dWf03gJYWkuVeUHPPMF+ikiOGT/JWzqaF9QJCkmWQjLyCeU/ioZFd7rkrAIjjlCryh++7IL0yTQdXeXtXLy0BGQ0/H1cWJP/KRTBM1CUC63Se9pf4qZTufdx+mVOmJlgMZCS/JHqtWVnnBpErK9FdH0N/rKenTJabF/04239QZ+dXSaGjRlO0cZXN6BiAg7ANE79CoB5KJZ00ER6hRvQ9Am9hyW7nR8P5htSVUALvLKclzuQMOPaVi37t1zakO5IUH6oMrvhIUYrWxA/d0ZXK8WVFdhXBaZwZQHeZguwK5rw== 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=Sel3qdBw1/pze8y63YrYV2DOyju1dhU548BTTT17Xjw=; b=J7HqNINvL7+bqaRWB3ksYTwxfxc0FvcdoCnqfp/u0sE1UWS6R3SyI2MQenaOqDjRPvrSyPqoa76quN/F/3jAqyrvKW9fb5QhD8BpUAyyqr4ULwGdUxIZTYfiejihgKErZ8Ojw7mrz7KXHcUvDm8kC+olJmmYOLTWu7Nf4RdIibY= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:28 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:28 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 03/12] x86/hyperv: Reorder code in prep for subsequent patch Date: Thu, 20 Oct 2022 10:57:06 -0700 Message-Id: <1666288635-72591-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f60293a-f598-40c7-9417-08dab2c4b0e9 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Iiv5k2GBEmtRLjzhnVO+EE4VEuWd9LGe84JUBsn6zZP86m0e5T7z6RlzI7PqMO/VAKgHMZGKjRXb5BH0AbalyMOskO8JQG9R3JVL8ZqKNchGrAusi2LTyHSLkw4bwb9x7YN34KVXjEKbGXrT3+An5nCYaPRdw/bCusAyLisnpXDN4F3/2Zh/yLiGTe2mUcyfCEHEuInWur6uI0IpNrCfIo71XIyDV7KfV7nNjR9Z0joIK31kpELTRMF4boeSI8Rn7FKo/KAMBY6jWERS3ApOvzeAhh5VP4d2DfaiXvKMlCUo8SzQ0eDvDoGGK3o4nNtn469UpwAdMF9/Vpv3NeLutrEr+DrYewnH69QdBoWCukQ1h0M6gOW2Dpl8RcWZEyagsmkboqMwsuLI/dDT1yNphlhSIpT67RcnRBDGR9vCT4QRQkL0zbSdWXGMuxsj5a3ClORJWoQYw6FpqXmSXmLOcY1gzcFK5pFEPDLZJLNaR1+IoRclCMCWZelrXSAexFMbbo6+W21sGDdail7Xa3683CSCAttrCFIMNjd5F6wsgky3qvOcLcDW5OzBAIocj2bmWMQtML+WyuXr8+NZLXhB1GUPso7WqSzQMsIUaAqqP6axXGQVUmFA+kpDoF7owUkYXmcZ7US1SYCnmOOlXGJ8U/wwrLzkAmArgjbJGWZuD6ZkIeFq8bwZQiu8G1K6vxn1ll0t2D+60WlrjL6Tah4GnWnFt8j+1iPhJm8xuqbClMK0YAXLE699O2W6lfjKyWzOypGiHjS1+V+YMfIEpAUBHONn7FXODSfH9eeNiMsc45LOHzC0Gy4IwL0/Z4zyppGo3vCTJkBsS12GvgKoL4dyUw== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qSFTG6byjCYRwNja6FMW3kl9qpg164TVX8jVuUX3oBIPx2ADLZjeyBFAjn8rnf7a/Z0rVLUudArRJ3OmXIYgb0e+3AGoiKt00DIk6oS19AFP9PKEhPBHcDYlOpfeEhd/ssbEYFtSBbeHpeRmLtl3lKntnhgZqQB6MMry+i4YPR+z/t9z4XBLLeaVuFzt8ANSwfgkeSUPtLoaHLQF8r+IE4fktPQ0n4lYCUaf7f5BlxrrqaKsoMG0WJ2ngdpparJfpxZd6xllutFfInruRjUA0QP1TQFzBHRN/M1M/oKmP8U9xrBQnpj9HqItaPcO9CTZ284R0kqLc/vp2wd2LknlOpYE1bM58NMVsS0rLjdnkWq8Kj+AAkHLzFVdS48iFrf/wjscpQU4lD4ZKsKZXS5PMQicryzoxp2hDXPGvsOX69QTl1s6aKlsSASbPKcMZX7hkz1/yksLn9A+ctT+8+p7LwV/mGuxRmwDeRw3NypKdvjHFIpGUxKOhLrht6av2MRM70zyq2wsnENKsMNEm+tkBC+iaWogznY+4x4vilqKeNVrZIFLQxV6gUpJybWljJKBbyqWZ+MJM1HinHu0vNjwUbWfh9vEcFoLt92MWgSwiyqw8hEUt7dOEsFrEJh4uSRNQCotzIrqvydH2b0i5Pg+1KH9rNFBa8FL5xacV6VwoDZInNbZOEQBjJUjZSOczitNfOlQgUdCLiKbm+QraZTKgaszb12JV5Z3B8+NKUYAJ/61//PqZSPp8Rdbb4IaYHhthw6vnFo/UbHxBgH2M+8923/CwyKdfGKIL7zUQoA0w+Zx/9emxh0E2KIRPwE7Q5XZMSP56tAPI2AAbCwzkqnqHFZK2E63WmkbHaqE3GL+VWqF7oInuWNn4K40Co83SNxKLftD0qjLdulHKeeWJAIR2Wq79NbtIJrJG46HpXIrpn8IEA0mhAAStrruUYBWBLati2HGX/DNcPJ0EnV7lHDOPl4LjoMct08GDSHyu4oHdXrB03XwkRbqLURdan2U3j82o5Jr2CKlgiijZhgVB0ueJGQixtLjj4M9E6grBRrro0ce+A5idki/4Rw03VerRBLYWXCHSwDsHIFnsPrucJNOXTre7AlcfM5s/x5Z3VDyIzqzoEet/5ROorLnnRgAdgXMpsacZYeSHMgaknb3s6PCA64++jIew8oa7IApFe642yMHI6xrwGGCzoGbv1j47upL0NzaYb3Lsb+URhiLD7MYMTgZ0YiI3W3egKPa1axiD6uf/FpYzonkfMzdQgI+F/v2J1JH7M+MZ6kfst5LzHXKgvo3y/g8rfm/VnhBfooyGwYxF3+cnBSygd+ZXcwakRfBsff+y89zldq4l7Jg2V9CTWd3CKQTVuPOLqj4OLYzUJxxnvgRp1ClVZHBcWmRq39zYZMvx+9zbmlQHCfNqQmEc2sRl/tJomxxWEVh8vGV0I5Rr0W64t4ah1RQhXl2PhHARZOy1wlpb2lvh14IJfdVPmFaD9I1X12mpdG4OYfU5AcsQjwiQiX+oibtcqthKISS6IEgmBJF8b793HodhmwE6p2myLe1CWbnjBrLo8M5VvDUSkovaa1/8o33aFvTewiV X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f60293a-f598-40c7-9417-08dab2c4b0e9 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:28.0122 (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: HqpGP/2OtfcTq0ZYvcinz/6lCZRCIf30aUdzgXSsZLdyv/k5YG0qTSX7Uu3SnCgo5Ch6PLhE051M0e5L4DD+PQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Reorder some code as preparation for a subsequent patch. No functional change. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 68 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 1dbcbd9..f33c67e 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -235,40 +235,6 @@ void hv_ghcb_msr_read(u64 msr, u64 *value) EXPORT_SYMBOL_GPL(hv_ghcb_msr_read); #endif -enum hv_isolation_type hv_get_isolation_type(void) -{ - if (!(ms_hyperv.priv_high & HV_ISOLATION)) - return HV_ISOLATION_TYPE_NONE; - return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b); -} -EXPORT_SYMBOL_GPL(hv_get_isolation_type); - -/* - * hv_is_isolation_supported - Check system runs in the Hyper-V - * isolation VM. - */ -bool hv_is_isolation_supported(void) -{ - if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) - return false; - - if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) - return false; - - return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE; -} - -DEFINE_STATIC_KEY_FALSE(isolation_type_snp); - -/* - * hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based - * isolation VM. - */ -bool hv_isolation_type_snp(void) -{ - return static_branch_unlikely(&isolation_type_snp); -} - /* * hv_mark_gpa_visibility - Set pages visible to host via hvcall. * @@ -387,3 +353,37 @@ void hv_unmap_memory(void *addr) { vunmap(addr); } + +enum hv_isolation_type hv_get_isolation_type(void) +{ + if (!(ms_hyperv.priv_high & HV_ISOLATION)) + return HV_ISOLATION_TYPE_NONE; + return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b); +} +EXPORT_SYMBOL_GPL(hv_get_isolation_type); + +/* + * hv_is_isolation_supported - Check system runs in the Hyper-V + * isolation VM. + */ +bool hv_is_isolation_supported(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + return false; + + if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) + return false; + + return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE; +} + +DEFINE_STATIC_KEY_FALSE(isolation_type_snp); + +/* + * hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based + * isolation VM. + */ +bool hv_isolation_type_snp(void) +{ + return static_branch_unlikely(&isolation_type_snp); +} From patchwork Thu Oct 20 17:57:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B65C433FE for ; Thu, 20 Oct 2022 17:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbiJTR6t (ORCPT ); Thu, 20 Oct 2022 13:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbiJTR6p (ORCPT ); Thu, 20 Oct 2022 13:58:45 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E623199F4B; Thu, 20 Oct 2022 10:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b6EgIWD3Rn05x4f2BkAb2XGeEnh+1B/KzZ4h4w/FsscXioXk95Ojj74vVzLYqXH+Acon3J2WmA0ADALUzjHARB9UW/Vrr0LgGELF6naAQZFhzMDS3ZlyCZVbrNnkBifWZ0NnVbmUSKQb+mZh7voo+rTUGZAbfcH6MdUvuz6TyrercPKgyrLtJgQ6YN3NqkL/x61+tlhxdZw9Ie4bD4sKa7GxOuWSfs8dFbdRyk6Q3fw2exIOtSVUeniIIAbC26ilQXoKEUXRquG406Vzd4NWPh3kXWbi9gSgDlDVX9HRHkNZjkvSd0CaTbSFQ2bPpO7aQtkiGGlvAZtFlRKfLT2Pjg== 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=JVJae8bvqhWV+/W8WgU4LbCX1LQ5f5C6r5eDY1i+Crk=; b=Cf8G8VQZZIfMnIQiKKg/TnzGymAJu0r5mi8w6R+PQUFO7VYM5rhMCjfx2VScFdVyQ0KFuJKvaFMRFTZil8ap/tW2g6iob+qJoao1XhZJnLN2pwZlTwC8GMKEq3yqWvF215zQJA6zEs/Q6xqKP5Ydg2bIb2s83BHTbnXCofVOt2ssrlmXAOmJZ9wI/72zzTfjU54xfkc/IXZsgDY3msIBRNYbwapbjIm7bsCVsyApDjLiom8+Ng7F1WsxfGptqXl3/G2kd/cOEY+NV+hQ6bCuW5WdRGNZCXRbrXhXqII8GKtuanhDFUSTk0nola63cfQZcfGM0PVZA75av4gLPu+eUg== 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=JVJae8bvqhWV+/W8WgU4LbCX1LQ5f5C6r5eDY1i+Crk=; b=TUUCcXdPhiDrCFUojK7wykYYj0DZUBX0D9c3I1zP3mlusYAO+nLxfI2QHx6SZnhccjWrUwzoa37+AtzKPFtZMQH8Y2Pz35T6BUq6uOG8u60wVD99P8yEDd78lS7Tlr2RGWTqXoZQlHqaho8Zm8AnEN7BfVDP9YI4gzFGQEHWoYU= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:30 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:30 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 04/12] Drivers: hv: Explicitly request decrypted in vmap_pfn() calls Date: Thu, 20 Oct 2022 10:57:07 -0700 Message-Id: <1666288635-72591-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 1185809a-8c70-4279-6883-08dab2c4b24a X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: myDy796499J7r+/agowhmvTmz3KzMj93nudCxJHRPy2wgxj2aClHWfaAcz+y3+q2apMPvNNSm3+thNlZzxhh7L5JQPLUmwoxtuOX+EcI2AEfizmMhbpSyJmIuPbsVPcouEQfxIREz7tDHFG2i99OFjWwx2g9u7at6eN4ggeEXhyhqgBabw1h2Y2IdFA3/QqRh/BcvExghaHCRjYDNg1ebZ/FOUkQHvjQhUWHqLvscuJ9ZiKOhSIlDKK5IV1E/vcTsCfsHma1rMNbAkL98lrBjEOWjOiHwCDc9djMhFBiNQcjd7fqTFEltODx6ghdD0nhos4prmCxQMqKr2mr9SzAtSr1Jm/AhPgZ30mBB5rAXAEQLYAvmyiRGWv01zRBYW0xlKwMtLK4Ovims5RL+xUxCwgYn5qqjJkqVBJNxssdpDN4o66w/FZRvPLii7OTAXWt+9CClDPN8R8dmeYz/y6bKKMQqFUVOlnCVyFkXv6w8EmDcymWPeO6QlUeNnCSg7AO9rBYuVG3JGBHh/lXniJNEcjOEAMVYaPG8B+uTBVVvjHvJH09OM9vUZO8+ijeM46dNX9Keu7KDFfYRmdRMw4qVHvChDuE/Jpe/0aMLtGks0JqFV92jW9G81SuoS1BasqiSkO1JYcJqFo0yUEZ7IfHHcgZWrybCDV2M6E/W7uAZjvKhOuiViZL+1bBoolkr5MQqD6TZIVsY4J4sQmL1ZLEz3F3Isz5P4I7AY0WALkuUNdsp7rqRTo0yJ16v/hLsc7o8pYG1woEJILUDgWsaYd4ljnr0DgcstvSwv5omKm9iNtIqsqCWM8C7Z9YzxUlebSkpgUVVO6Odw6du4egWI6uMw== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zeLMo2KlJuEqzTS/HhsajZ/hjaspn1yTeBkxBtr/mGlrN228PnKKFOLpZKRtbfiofpSyvpTFInJkHh98pwCdRkL+r17va0ZISPv40dVmrVKU18+esY2l3plXP1VmXt2yswXetB8tAMBLgQVQ5LvpB2KL5tB+nsS/GdMgdVTwxq3Fpzc9vnDckIc43v6SgPTNxJVh8qORufJ8sT8gnzApDU84GQ7+mpAMDexPZXwk2TvWmAPO6T/wrSGcjZq24mkjhlRp/5lcnxHpPYTKEkbp3lyESCU/NwjaN2YQA+H6yj0LJikXWGdEozNyVzT7bqtx2ki1pspmKlGtxXmsG9F3eVczDQ/s+mV4llDRK0485UkHWdhO6Ln9LGKQ9ujVz/fXloaWr7M/kCvbMYz1l924HdLhs2cZTZiA37qbLa9llI2YVLNhiisa84mNE6WuRK43yofwlbqKS9BXSqfJTNl2LdRdRCDHmeZIMVVeKLiub4cX3g1dtlwI7WF9NfXyxT8n2gRWmIUfXxVPAeaaiOu3IxNB6zTOEjBd5JY7QJOre/29xuT6Q8q3uLBuPAJHcpgTbvdye62srsYRQ3Lmd7mWgN+A8SE9p9aVa9UEdsbdDt9KFToBlB+keuLzPD/4lKjNDagGo+cw63vLijYj0BjujGxfwhar63JdWv4vPCWMpOKBNTAqIEpKv7MQHOB3bl2jtnSsTUNmjavsBHVlf0nQ1kkwukWkNZWWhfEcfEHkK/Ojqx0xBzJU33mdTguy8CGhfFoO37W8QSWaau1xS77ohvpnl65542pqU7nUhQN1U7XERfF+aLxhxrMb0atX1OZ7nfYQ+mUATs/zIUhdTQue6kfUqJzjlUjbqc72JVr5gn0YJE2rQi56E3FrjeEgEX8lR+SlnVPLCQrhIS+pl/WFZtEXzRQSI4OlupQxPY0udS4iXvyTk7uto989R0LJvjyza7WLj2dt9/60QNkc+Xi6mLiHa53BhbXcB3CPrPRVdl9cak2XhnziAbTXAhfun7sYZVI0ff5EaVO5Tpnf1+EHE/UIzcWHPupMiAuMm7L/MDPwIamd2DLRgKUjQjGc5RBJzbUaKQl6wYL6FNpY70euGZHTJ17BCzkQKt4vplh/iqUYatvK4Fda2HN15uR/rIDtE+b8djQhz0XDlpe/hXzwSTJm+0uYCSsGlif13KTUA5hF7CdXm2PyS9TSEMJ+JfRt3HGkBur1ui5vCJokxgneGLLQH8pRFi7zvCPOWlvwKPO31DyZihGfLvWaePyfYOa1iDJxaEFGKcUnuug8tzdPBuDxc24TOZRIDkPujTESR8YtWjvjSEhrfuiOTwBdGHjadaHCZ+p1qjp7rVudfjPzTxYxY1fNM2VL4CTJ0xe38YBN9V52118qiboF62GJ4F2Fw8tm9Axhp7B9YKl57jyERv+HomDGxf4KbTa/PCZbbj59Xi3Su/Ij27wzSEkbCuMyvem0X7l1sClyzknVbWHgV75fO0dynshae7uqmrv3jTTzFy2yhOUnnJVU0D7Lt/M0dbTBDLh6nfnlRLELrRfZ3TmvUgFm5jy+opoaGSX48Gpzk4zgzt0+7nJMSi/hRv/o X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1185809a-8c70-4279-6883-08dab2c4b24a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:30.2932 (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: 17hxQelzEnGcmg9LkhR8QSb7K4YhFZvbktDA+ZG/+1zlFRLvPjtJhBqhYfwN9QnBwQTUyH5J4BxK5d6GaWWi0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation for a subsequent patch, 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 a subsequent patch that will cause vmap_pfn() to mask the PFNs to being below the shared_gpa_boundary. While another subsesquent patch removes the vmap_pfn() calls entirely, this temporary tweak avoids the need for a large patch that makes all the changes at once. 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..e8be4c2 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_NOENC)); kfree(pfns); return vaddr; diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 59a4aa8..b4a91b1 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_NOENC)); kfree(pfns_wraparound); if (!ring_info->ring_buffer) From patchwork Thu Oct 20 17:57:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B68EFC43219 for ; Thu, 20 Oct 2022 17:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbiJTR7W (ORCPT ); Thu, 20 Oct 2022 13:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbiJTR64 (ORCPT ); Thu, 20 Oct 2022 13:58:56 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D08199F70; Thu, 20 Oct 2022 10:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T7NI6mIyKKk77K2merCDg75iZz5gYZGk4utdi957qT39BVrbmBm2vDYY1UaIYtGcPeyXTvlqgl5K8sKEhiaK/lJHSkYIMvpoPmM6IR7gkYRKsD0oFdi92EIr9VA7MLs7mn6EdBhzdXDlqgSxnOZp4fLZtrcxOQd9Qt+/JyjVLq8pblLh+cMIGCngCvFjfwg4yMTjEXGnDQJfDX8VcwOEzYS9cLIW3q68OXtO7xAmR89WJlSZyLz7dt92EvVQ9Z8vPJZypj0pwzF8It0NwuCX4MS9sXq72kwQTm3cjwbeTSq5h5saGqck5TYpG9qisEB0o/WwQqkSyGCCwv6Kk0DIVw== 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=FbT+KszCQ0CcPMoOUSbNemIkXPrl/6KRwuTXDQkmQ6Y=; b=eovXReeiv/3arMQ8edmsNklhFNGK9hdqOR/f+LjPQqjxKT0KYKaktkbzbOJd63NvqdAiERWWoxIskzfL0uaf9Xrm/1+YGH/ZGf163tjAE/ChNCo3vi9+Y+XuEKAC5C66G8ykWWuKieHTj0xOyQ3+yJfEJgI43LHk4SOQlrRkuN9myNQ4oZiw7VKWnOmYHCyiMpDQv3sYYr4t6NnS5L8X94GSadn77b7+iqyFhuILCyeOs5BVKd9k/yQ7Rds2PqmeZLstFfsm+u3U/5PUHZ8bZX1dFKEACuw09lRMuzQdaIZnFpBjfjpcQ+49oZxVInohvdgQVBe+XfA2L1cSKnWV0Q== 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=FbT+KszCQ0CcPMoOUSbNemIkXPrl/6KRwuTXDQkmQ6Y=; b=Cm2bntyraKEec0Y0vps8bODxGesEhblIWBWOw1PP/z96O5nVA52X0wNaLaJiQsY3LuSm8I+F5CBQazZqQ4cDcTww3msW/nAwKKVj2r3IuQzVYZ2KZaY3znMaubLI+H+YpggDR8jASLvHqSoIsplNNoBrI+uRb4e+yTUC1MleqIo= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:32 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:32 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 05/12] x86/hyperv: Change vTOM handling to use standard coco mechanisms Date: Thu, 20 Oct 2022 10:57:08 -0700 Message-Id: <1666288635-72591-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: bd397977-0fd8-49d0-1535-08dab2c4b3a2 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: crqAbYRf+wde73ONmSS97p023GsYnttDdrIHfyXycWT1N5yru1pUtUceUJZ3bR7iZKP15mTIjZ6OFXYEFGHM0bfVs/VXncAdqq8Btk5JLTSOh45Qj4Koca91Hb0LGiPejh7gWE5l1M/dCA/W2Sw43Vc6fYaefOYOc1F1wpMAqMuEuRen4z9RCmCE65HIOUwbHcP2ZTVEI7h2UGug1hnUgTWISwSb4bv968XKdEikOvNe0c1cpZ9shy5ROjhkKO5uJ7ptu0TgMJhhCLyalTDvvdkXJc6LwBpxdRMF+kdYpsx717rwrHY7JRJKsjw1IzFAsWpP/iCdIj53NIkKF9KI2cHvdOEjZJOBKCIeNu8ba4RH9Rd41QgYGfvUoeLBta8LuzLMiQNunI/bXqWAnfOPHckDas2b2WL4FIZfwBfG6bcE5VepdnvIbI/LZ8r4bdKoft3LVlD7taw4a6BlMRuCA2OnXSqbiCj5AHUBPoz4wihwkVjUc5HtxYX+sTABhCC2t6HUQ3x0FXhYqBTFwI5YMbYVHqqkS+Y+lvh3Ohz2C+WQ/BMJNRxyE3NlY0iDAk1N5ZCsm5Nu/059EnD49/ZnfTV+sBaKPRnSdz6upDGncllgFVKkoEcusXT4/eObQbsh0A/FbcDPed+1Ler5p3WpIjxpwNTt23eAY6TPIhG0pA+BxuY4dKW3Dck8UoCrhYf8qG8mi+IS0KPArSGDdu6T8jWyvXkyg1IFr7f4gcvuGoQvmZmJGaaPG/iuw0ukXjs9xUYkpZ2+tDuMbnECaDNPryBkhL2wyNKt3yQYURd9vgFnh1eZG3KSw/TcPKFa/NyGgKc7obwJ/4jLT+OT4I5mxXhDQIJvz0bmutbxHtcsdhO4hMnoHgz+cQleANjL6czNf9+Itc7AjfBYAOK8ir1yDQ== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(30864003)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(966005)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cj2irLjg+SAK3vKJRCd9o/g+/v2t6rC8QcWI569dP/ouD9KWSsdTx3YB54WoVHH4GHAu1uhmJ+ghA9u9WBfuomzTfHzeaHcpi40WUjz3ocgYCngAvewP5fLL45rJeXuuWxn7qp8wOSRH5MWvZczVAAYRLA2JUxBI9/OMKh/fQfdEtk9DanA1h24omWvVdPR9+2cYrBbkwuXHB5oARV7ywGZGZ8LVsst1KThRcnZc1xDJHQbiI84GIe8/0v9kbtOQg/u/I0kn5mm9Hm9e/VZDSvmnbi+d3TuSGZ0fUbXovP0siI5iLR5U5IJSE1V8p0TYxX7Z8+fcego9PCDYGj4I7mYL+/bGC6a5QhH6EixRbuDaajejHEBIj2xhLMYHwm+4ltTFXOmgQKmH+PPR6xvpGAF6Ivk5aRivjbPYmPZhDqzgo8LJ5/0FQnWkXVIlZxkOolBZbb/x1R6KEpbmhJdNwyldhqtJL2NLNghpKcA//nXzLUq4mO+tM7PwpftCmLbzSEdbv3wgVOwnzEYm6yZOIbGrTcFf7vqV3VZGJl6IQLHPkd7LP9pHTK3SqxSRB5vU+4/TXr0AYauL/HmQY39UHrH4gKebYgh2+ezpP6NAdsKlCe+MP2JbH556HQb/fOvW1OR2B75AJIwzjbgh/uV150DRypKDfqooJ9Cn41Q0KHwifrF924t4A0oB03YSY588S/V5vg7Hpp2bqVlAjChxrFS7s0qLv2dtE2BWNRTHdLFj7RWVAPn0YDtyh+lqZjm0rWu8FuuT8GUEMxJw+cdLfYtn/3eu0N+Yfm/3RzTcwGGy0Qa+l/QJ4HcnHk8NW+xXZaXwSMR6BQEHgKn5TqtQ9vYZMaG/HgymvnlkxIz3Hgq8R6UUtEp2fPfKYQHZoXT5udXR/H8amBwvlolO51/WkQvlOBuIIemBQeqi4AbJXCVUkPz+i0Kpt20cVOsmgaFTIb1KX2qvr+W93Zg32bRsl2l4oGGa0ZzNm9AHEZIpRligiSwinwTmGjHGjwcDDhAMhgwmO+QsgNUu9KjnznVIfi3AA31oiE2GMtjcezJi/nPodM4sef9EiVLB9/DqjT+YyjBiAxcp8U2Y2Wtf8J6U/BS0XhbyxlEtps6oMzPJSpQ1Town34uuB8SIvJrjQb5GbUrmYUIJncoo7rn/ClwHuao/NinzXYi4AStSMo82oHei6aZedyC5b64qkoveKu09iRDKGKhbjUQ68F2LCsymKiC6aUjssRNuHO3A6qC2Xm9Wv/tqUf3P6qRsgKK2oEATnQ7VaP4+i03AwhKN72t1Z6F/OfyLPu4kplTWG2Al8RNWh7uiNtiCCOLawMf820vfUJWthmfVr40vuyyjjvzqtnniQonXFiyX+lUg0UrbNR5J7kzzXQtKxk9cdlvGplI6IsByuiriAtOrj/BnDzSDLaFZHyUCl/LOW0olJA8iSm/KUqSnMzZEg1P4Bk+7sUT0x3bbTMbaoSLuzEwxvRY9PTG3mo6bDod918A/nyIBnOIkKZQZZ5DFb7q9BIE1WQWzCmko17ozXPVel0BghBaKqvbb2kzB/c1WNThjyd4z7Y+CXLEElLXYLZey69iq++/+ X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd397977-0fd8-49d0-1535-08dab2c4b3a2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:32.5611 (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: uakCjnpFAOTjvKi5AzpG9Xc9q70wf6us7BQImjlyYb6igYFhG1qZ9R4gl4oFeBe1W55vqhLe1VFCF1vC6FErhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hyper-V guests on AMD SEV-SNP hardware have the option of using the "virtual Top Of Memory" (vTOM) feature specified by the SEV-SNP architecture. With vTOM, shared vs. private memory accesses are controlled by splitting the guest physical address space into two halves. vTOM is the dividing line where the uppermost bit of the physical address space is set; e.g., with 47 bits of guest physical address space, vTOM is 0x40000000000 (bit 46 is set). Guest phyiscal 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 I/O APIC to use private accesses. To accomplish the switch in approach, the following must be done in in this single patch: * 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 * Update cc_mkenc() and cc_mkdec() to be active for Hyper-V guests. This makes the vTOM bit part of the protection flags. * 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(), and make the normal case active for Hyper-V VMs, which have CC_ATTR_GUEST_MEM_ENCRYPT, but not CC_ATTR_MEM_ENCRYPT. [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 Reviewed-by: Tianyu Lan --- arch/x86/coco/core.c | 10 ++++++++- arch/x86/hyperv/ivm.c | 45 +++++++++++++++++++++++++++++++---------- arch/x86/include/asm/mshyperv.h | 8 ++------ arch/x86/kernel/cpu/mshyperv.c | 15 +++++++------- arch/x86/mm/pat/set_memory.c | 6 ++---- 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 49b44f8..de4e83e 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -78,7 +78,13 @@ static bool amd_cc_platform_has(enum cc_attr attr) static bool hyperv_cc_platform_has(enum cc_attr attr) { - return attr == CC_ATTR_GUEST_MEM_ENCRYPT; + switch (attr) { + case CC_ATTR_GUEST_MEM_ENCRYPT: + case CC_ATTR_HAS_PARAVISOR: + return true; + default: + return false; + } } bool cc_platform_has(enum cc_attr attr) @@ -108,6 +114,7 @@ u64 cc_mkenc(u64 val) switch (vendor) { case CC_VENDOR_AMD: return val | cc_mask; + case CC_VENDOR_HYPERV: case CC_VENDOR_INTEL: return val & ~cc_mask; default: @@ -121,6 +128,7 @@ u64 cc_mkdec(u64 val) switch (vendor) { case CC_VENDOR_AMD: return val & ~cc_mask; + case CC_VENDOR_HYPERV: case CC_VENDOR_INTEL: return val | cc_mask; default: diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index e8be4c2..29ccbe8 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -233,7 +234,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 +286,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 +313,42 @@ 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; +} + +void __init hv_vtom_init(void) +{ + cc_set_vendor(CC_VENDOR_HYPERV); + cc_set_mask(ms_hyperv.shared_gpa_boundary); + physical_mask &= ms_hyperv.shared_gpa_boundary - 1; + + 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/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 61f0c20..59b3310 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -174,18 +174,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); @@ -241,11 +242,6 @@ static inline int hyperv_flush_guest_mapping_range(u64 as, } static inline void hv_set_register(unsigned int reg, u64 value) { } static inline u64 hv_get_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 8316139..b080795 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; @@ -325,8 +324,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); @@ -337,11 +338,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) { @@ -410,6 +406,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 97342c4..c8612f5 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2116,10 +2116,8 @@ 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)) + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT) || + cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) return __set_memory_enc_pgtable(addr, numpages, enc); return 0; From patchwork Thu Oct 20 17:57:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04B6FC433FE for ; Thu, 20 Oct 2022 17:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbiJTR7l (ORCPT ); Thu, 20 Oct 2022 13:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbiJTR7U (ORCPT ); Thu, 20 Oct 2022 13:59:20 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D681D1E8B84; Thu, 20 Oct 2022 10:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ntD69YMwVlhlHi4MeDxs2qFMlOjQDtrcsAjRUPCfSjzVvuVc+gnkmRiPfdY8pIgTKGRmnAeAxQzwsWLGZ8VeBTOSYfBXyRa5KIwg4eW8HxTAFomcUDUryC2C5VPO5IT5iYVtZ85A9qKXGfbD1k8z929ahQz2tNLk829ag0+qXDuzjNM9tipogt/1F3iyFH+PrbfA9OXpcliEVLoY3A9Eo+D3oMo85f+b+cIzEaHRv9o/FG2F1Ccb68wKZ5rxeXGq3yMZxAEy5OwBOW89QfCHSgw4CXbWY8rtkN3Pi+eTR6urw1K4TYhBY9JIa16Uv0dHXY/JpotV+Amwz+LZz1WFJQ== 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=ENDox1yNNiJUCaK5Df4regkXvUQPQmoTwmsAWyaE8R4=; b=PihloYYYAirtYppbYxfv4wecv7uYMOPBxmAVTLxRuCHJl3/SQodvv9RnzKFxm+rdAAVAryWZSim6a6Jg9J29BwLc0AcrUIsZRA0d7tseXyKMU/tgOUekknEtRdjqH/nZLad6qGHbuXC1MSxCRl88WCL8xrfOrQHv68DlcFX/bElVN+0T+DCAz105cRbzuleDwZx89JdGVRj8wKSmL7DKwHuCF5f9rEYmK9STF7wvj3CxaYuOvlzsmV8/tCn+42CCsSXaaPJkSIWHu+yvkrOcaVRj5zUlPoXat1+ZODdy8/Nzt6FshG5/J0fiy6CKtV+sfBZ8GK42gq6/xc3fALwBPA== 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=ENDox1yNNiJUCaK5Df4regkXvUQPQmoTwmsAWyaE8R4=; b=NsrschHCTTESvbFDjfHKotLXVAlTyU85Gll5laPetowRtlba/ZcqqzD08irS7YZA6HFQINSLQhH2dNxSXQ5d33zXolRNG0FHhOUGA5je+Isw1QVvwZjNCJj7ib3jrG+93XxKAlkNeILGIHZRqxN9s7AIbWimKljqZKeCno08Y54= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:34 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:34 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 06/12] swiotlb: Remove bounce buffer remapping for Hyper-V Date: Thu, 20 Oct 2022 10:57:09 -0700 Message-Id: <1666288635-72591-7-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: b8b55008-6d9a-4899-56d2-08dab2c4b4fe X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fZIsvSuy0KKw6tBT/h2JBUom5D5q3xjx5OI/iBGOwDPoAf2MqsL6xTfGuOVuUjcrX5KqTIqiwxn0bmMslYMVgIlAybwCnl4Fyhih/lyblq1TMr6YCP9G1aWX7/W2JQnU9RtkXJa3P/BlyTZEA1zIIyQfztFxGIYBVnj2m8tD/1xLct5Gth0ltnDBrdqE2PDukpPMeNxr1nUXaFha1GcBX01PdVG3C4SKCcVzdl0nktn8pOi1rOE8f71yIXp1VVulygc2XqIVmDfeywgDBlHX9RVqBu2BNUGvrBniPOCOmJdxlm3uh0FywSwojq6+EiYzLke5MwfJhMHkwSMyTvxFGbopAFBiUd4A6BN84M0gunrCaex9+7u6xqtajkI9ioMi3i0edQPsQL3u0BdtZuhfmogFFlolR5ZA9lMH3MDS3dwOPl5HdI0+tfM3hm/Tk+LICgRNXpy9pl6cNmYA24LTbZDeS4rdxtI53dBXEeXgCOWrcpM0Nv0oQnktixSc/hvM46ERDnJENsXi9sS153WBHP5Q4JacAqnwlWgxNH4m/npgBB+4LBLfy3vFDe0CvoGnFK6Q8XjdAOrHuoLSrlrhk1MdNDBhIAfZhHDp5WRDUq8mT2QIZEuqUocSm4wP1Bn9OB8knJnLUf5s1C+qBIv4j4rRs6DBESwhJg5nvaresfPGhv51oGl26/L5R23wWD+sudXdTXsj+r7aePhfjyNoAZJV7vg1KtAHqs5hmY2cCERTCZxodaDcNxxzQt9Sivd/5+sv7wvzoO367rwjzd7gLbPkiW22eAQ0LlsyPYQA/1iO2rse1TpIGGB5u/b0FfC6Svbjje+9Ma4ve4CMxBV2xw== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4AjrSsaVTrLb8DAHK7ZKpE+uUcgFc1kVRA/JIbbrT3qZC9tATK2W4BvEhMOVSD/l5pyS4giA5lz6G2Yso+0XuFWf4eIQl+tNT0pOrret8CnMg7tzE7SlItJppOkFWGlTa5yTosD0CCFCfZv4547fGWLjKC2ZYA3y5ulDdJcyBSDEYmLdlmCTqHve/FkUp1IfP/+LDsh5nNZzx+OJ+5cSwKyFA7aHkQsqKfLA9nHMENSfECNyE/+keSz+Skh6kGDKLZtCrEtrYah/+nyQi3EDV/E6UnOmMSlV00snhtS+8q3JHXmHV7wproDb1YVTK9Jp3E6ImeGUekwor+kGG+ZrD4ZBucmB/dMSAHJWZNfdL/kMXdosBWoIiug6kkJZC7E1PQkTmNm8O8HqfF7HJ18xhTDQESFYRdwVFAwdovydAcqZKfnWZUBlD0sAxAbGNm+IG+1MC7BtTjc1rwApkqgfnbYOAZt+nkkgzDTWEnyb1spw2HY/MHpMs0WxQ/Kcor48HEM1x2GyIiHpvWXdG4iJ5fHBGbqPKPc4iBupSPGkcivvkN0M3GB01h0+yfFHiGXnSen2eLMCLxBtIv5hI4UUWsPnIg/ExBeGHcfqYQmkGbUpUJP8vXdvbBaHsz6QRCq2t7UKyJw2r32YFtGCTSC6rxC3b6DofC0SpEBvdZEKAlfx4ZkhttWQWq+rC5OCwrFMHhgQujBJ2M40wkAUlBJHIMaRIwoXuK/neiwvBwUIdXD11HUfKLNCuFtwS8GTnOuD0ghOLmj22ZaCphPljpqESgU2aQVpVvvRuCVH5PP+ylGvTFDqzreRdI+u605afhFab3Odx9e86pdMdTqGHPqLFgWBJ+SkaKtTrd66nIVztf4xRAv5PGVec8MQ5I2eSaut52mfZ10SsgbsI4RK2e9si5dBVD2Y3GNDaboFg6WYS5jx1OodtPChsGvzBRDdJ72MVtO3/FTMZmyfogTAIF7eJIIwCjawRPs0jDOtWKuFEXXMtruWQXzAJAWZljtm1h3/H66RH/pfBxHByrfsk3k6mxuog/S4XsfPmJCYpPnNCZD2VE9Fw6TyjRajWOpIwzmu8jyDr0eFADI4TwdE35WGzs0Dumqp85/euNOxo8o9L2unS+vtAAI5tTXBUWdZ4MwWd8dArYg/8c3U3b6a35AVUtV39sSrzYtl+VUUsGt0eKvDmJPxmOlCdkjy1Ds/OSSPQ2fNQXLXbr64gtEMHywgh4Bgu0JkV45YHgjNOTVjtS7k38ofHjXjhjOpLhHpmt5J79tpk3nVLdu2F3COso2eB/jpTLogwXct5qWtGFgNdb8S9DNODjKu+/k8sGnl2aUtv6Wrehmim39uBWvK03CYfJKAYuRbpmXddNrHWFFe/kc3+e3tns75hOCdsPchDq+qF4ygJ16YuRYiWzS4sbAE1LK5o2ivyeVybk/fHk2ItiInwp2WisI0B1p6KnqD0PwlOe7BAzkii+D+e+MJPG9bmWpiA9vDWeaIH6oFcUwPsQr0MH1ebJl9IkTGjKoR/vfr4dO8fhFNTO4x63s6XYktzjMOzCp6/uMGFd6z7eU1t7Dqnom9VY1+HCRXCy/1l62n X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8b55008-6d9a-4899-56d2-08dab2c4b4fe X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:34.8279 (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: 7+k2xcwBEuHYAzVIpdrBUNLBCcRHL0tlQPTLHJTZJlMx+jIv1h9MYHv+pD/UknQsrQQiAPh9W/A7USYenE3A8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove swiotlb_unencrypted_base and the associated code. Signed-off-by: Michael Kelley Acked-by: Christoph Hellwig --- 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 b080795..c87e411 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 @@ -332,12 +331,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 35bc4e2..13d7075 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -185,6 +185,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 339a990..572abf6 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; @@ -210,34 +208,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 @@ -246,18 +216,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, @@ -288,13 +252,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, mem->slots[i].alloc_size = 0; } - /* - * If swiotlb_unencrypted_base is set, the bounce buffer memory will - * be remapped and cleared in swiotlb_update_mem_attributes. - */ - if (swiotlb_unencrypted_base) - return; - memset(vaddr, 0, bytes); mem->vaddr = vaddr; return; From patchwork Thu Oct 20 17:57:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A048CC43219 for ; Thu, 20 Oct 2022 18:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbiJTSAn (ORCPT ); Thu, 20 Oct 2022 14:00:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbiJTSAA (ORCPT ); Thu, 20 Oct 2022 14:00:00 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022018.outbound.protection.outlook.com [40.93.200.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A131EA573; Thu, 20 Oct 2022 10:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XWweT4EQ8KUkmk1s3e5Trah6hb5DDak1OcwNWx6mP023yYWNa1Q7P5WPSJMgVs8nvc2NsVTtX6s97PE6wE6LBY/1qh86F/wN1FJoZKo8syn6BDVKG5DK/vHea9Se2qt46kF/rmwCa5JUsgJ7PJYGsCtIH2kILNpiqE4QHc+tN77RM7vBJCBi/1PmWLRbloWGvjZR1PQ8W9P00HSbTSGFQRTFwYlZBCXQlyCD4cJp1D9B9dJDy0s3rpUnFov4L8aA7SDkiMoqqq/YQalIlclosfM5MvFy3iflgI6HETVpa0iOiKA3PK806sVnTLesrmG3TENDASFDrVxRVQMBNhHHVg== 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=qeAXZg3STGQ4uhs+C+hLKwvmdp9vlTnfXiY2BSEKWok=; b=EL6Rtlq81mMshQYJvFrxAq93QkYkFY92ggd/cNoARNBO/8M250AWK3T86DMRYhS0YizJsXTOh7EcevUFkiaVyaDJ91xO74yayDLHefd+PeGbnqSbFMpKz3abJl4tfeMSPKsOXIsKCTR64yb/hxNXkh8MXjeMpoN/4zsXDdAz8hL7wmZ1aSKYCnEhPAT/uAk/BMYprmIH50ZvzQoJExdtPznlQ3W30YUO0KUisHh14j3BjqwKwKyH/bBwBbohxrvnHZ3kLVOFck88eao8d6X8t+FxPoCu93p4j4j8SBiEAeSb0pqHn7TO/gZ84XnXr1+RLVQL/EceZuASgQsKc/GoGg== 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=qeAXZg3STGQ4uhs+C+hLKwvmdp9vlTnfXiY2BSEKWok=; b=SHPTmDVV19xK2EPBTagY9CRg+R2uGiE2a0E3yTA5P03CKgAuKmL+asiK6JY2DF4cb0fQ+KalK2+DKZPb7bhzUMkWWhSpO/VEuWnZW7h7yZpgH9D1273U0XuDB0ki+SC5c9Yrrb/2vUDFiwOOLdwGRv6X5kZds6bBFcNF0UQx6Yw= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:37 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:37 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 07/12] Drivers: hv: vmbus: Remove second mapping of VMBus monitor pages Date: Thu, 20 Oct 2022 10:57:10 -0700 Message-Id: <1666288635-72591-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 667e529d-2595-4149-d742-08dab2c4b655 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pbQrPcZ1dg5+ljl9eSXN0BogOtE3RCdIpI1qYRZPASGIlW9w4VbKTkzBzmkvZg1i4b2rFawdzISsxrb1GjLWxRVOnWjZYOXZcqWbqLDFgycxjDDCp0wb6UQxG2GBTWMrlIH0iVkAfne8ra1nRELHK3YFbVv45MWuJNFC5oJMSwteOwKvKl90r43EdKuSaPfFV3V5QGLp7vXQNUh3+jKQRFIl7KgvCNLw3YQkPxf/9Dkm2XkYYr90265PwCrXLe39nXRpqX+gTAiMcVI6zXzHcpoaZMArGKMY0+ihotvf5UsdGLrpJkBQEZTx11aE0MZwgF0fv4B1W6jSCBXjMPrsDFwssZSvOYeJqqmkSFMgNCHbn8LyVZ+PM1B6rRkmS6H2mQHIOxjdCRM8R01DEI3qAh1PlwG8qwtWn3CTU/pUJzxiivgFOLV4o8AMehGULzaDAeRJjyRuH0XiqfBnWeWNGIuLOA+KT6ozUDggmBPSJl/j3eFHQZYcEkqzNBur264fbC65hWcdNh+Z+jS1ApaD/2uzyO8ZlPgtsXE2HRUn8kJayeeiyDXm5FK8NfdGD8GR6YcNo0u8UzNX3Ja5p3+hS+v8cGp1/ye/I0QVDRi1g1/S7l8YDUGpKWRT4MkR1GU2OzQ49yoqnn1b1vzMFT+j9N0B0qTKme+x9efL17ezCnnSJ9jBm7tddAV7byDvvrf9+nhz4BxXAnlsDEjJGwKFNZLU3bn/qcSIl7r9QVE9d+AEzJMgwhW2pNMvMbF4T9XDMx6OfW85D3ObbsopRUQMCdhhygJRrM/7Dj5b6x0HPk+umQxMFrHkMjkLGwWWcpOz 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9AbbhGm3Bdfvwa5WCmefqYD8T/1pV9v19C6EIhDFfABvVcY7HH/PqXmq3UBV7BjSlzxCSerBJ6bEYNDUkDm1GwLHfoo51RMyj8Hsq/N3N5pRmtbQzhVLOfVJcBHioRHEgzmzGm1p0J9zTDV5Fok3ZN9/unvdMR0xJaNkXww2YlsGMyPBQpcnF84CM2P3XyyGo0iv4stomQl/5oOlauDHzRqEiHlfcr+flpxWBHB53KGlDMAPJkV7gOzf1E6LDSyFtKWLLLm3YUGeWhsY1z9w1eL8URcaIcCB1PXtTtmPkH1C+ZqTCDuopyXsag/+jUkFxpyFOeNm2By+g4uiLZ64ogtAmNeH6Hm1JaCJj/R+7cY2ZSPUKClDGuOGu0gpGKOFLLv2O5C7Zl0z4EsWfUN5WwhByovf9I1WGWVA44F+12jeD+iN1/aao8fh3deLEnvCFibffBPSz6MHpjLDpzHkGDrk6xk3TplLjWyk84gvJJ5ne5P5EeOCGphBTHRMtRLifsSuaadMCTDikz0iaQhiKeLab8zx2CGH2ZKa3lfMChohUACYaR1E0Y5FH1ngToVgV80K6YgijcC5v9JGMfXwz/5vL7m4AB2QXvRYqS0cpK8FmvvqmWii9bKyp5ot/AIGx0VbnRCKd8EwmaNWcASOPp+Y0VCumCoD+RY3ksVA5x4gIZ5zmZQI7eXUICYrRrqrPz3HVaWZSYPMRWIuZcQqnq7/Zq4oX/9Oh/lx0PZ8l38atOr3LpxMXfV9T61ZG76/JTlHtaVpDKZTWUQV/edMZG6cARB4KOQNSqbJr4TCB4Nhd2pdfSlTcvQGq4yAG2rGYX5L5NkyzF4SjJjVpMGZiNAthrbi7M7ZQRPZxycwdmA737yLXzkXSWC3WKKAOMjQdqseHrQQid5GTNw+5eCtBHRqoQ0KIrAnRkRCQWym8wo06BHB1KGLcDm/LinAqNl3neHUi5o2LkNL+s2KRvJGhUQiSjCsrJbSjnBDuDKUpN9SoX1WhywCf58vqN1MGun6yun6wvlUhdVenqc6wXdGTiU5RqmFJjaGJQbbNmAm6JAtRmq8BC/JHNgOYkzwV3Q8y3Iz9f54KL102cUGx8D1ZOOxRsz+ESenghPQ2Ttk1a7oyHKmP+sw22JjSDNuMYmEPN3t41W3arxcGxGSKT9yPMm5wdcVLvnmjymQQKIrqh3DxHGmOX1yKmSkJri87ZNQw9TQTVKO2y19c12mFiu/DM5Olyc7HmKJ1dv3o8BeeoVLZq9RZzDYr22G/lUpGrRZ8pAeCBF0zolNn9tT9jaZx+E7EvpmFhoJUK1kUSed11vmpFtqg6rfxlDMZ7NgdvuZeTQh2sqSM5TjBJv9y8hUqFc5wdYPVlw+lVN0wjhnjESJwA8SUMGewzirPRql+7x0na9/xuQlFHmq7BVOVYBy79VY+Ks7dRLqH2D0HYzobiw1Fx+r+Ce0iJu5KeE0rg1bXDjWlgeHEdIlxDsK9KYUIKf/ARia4RP8JL2CRvAaVSua3PhwNUhjdhCRZFLrtgHmj2Boc/msGVDCC6kCwQHRuge2ptrQrpYtf4oWdI3DajOcQafFAY4VTJF4q/ke25RM X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 667e529d-2595-4149-d742-08dab2c4b655 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:37.0790 (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: mc14Ni/G97dftdclL4XaQqbJldWOg1pGtCxzzW0jjsWOsFUxuxxaIQkL3BfcePP4I/0eJBiP3Q9T9BN5Z0H5NA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for VMBus monitor pages. Because set_memory_decrypted() and set_memory_encrypted() are no-ops in normal VMs, it's not even necessary to test for being in a Confidential VM (a.k.a., "Isolation VM"). Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/connection.c | 113 ++++++++++++---------------------------------- drivers/hv/hyperv_vmbus.h | 2 - 2 files changed, 28 insertions(+), 87 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 9dc27e5..e473b69 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 + * do the add + */ + msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]) + + ms_hyperv.shared_gpa_boundary; + msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]) + + ms_hyperv.shared_gpa_boundary; msg->target_vcpu = hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU); @@ -219,72 +225,27 @@ int vmbus_connect(void) * Setup the monitor notification facility. The 1st page for * parent->child and the 2nd page for child->parent */ - vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_zeroed_page(); - vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_zeroed_page(); + vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_page(); + vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_page(); if ((vmbus_connection.monitor_pages[0] == NULL) || (vmbus_connection.monitor_pages[1] == NULL)) { ret = -ENOMEM; goto cleanup; } - vmbus_connection.monitor_pages_original[0] - = vmbus_connection.monitor_pages[0]; - vmbus_connection.monitor_pages_original[1] - = vmbus_connection.monitor_pages[1]; - vmbus_connection.monitor_pages_pa[0] - = virt_to_phys(vmbus_connection.monitor_pages[0]); - vmbus_connection.monitor_pages_pa[1] - = virt_to_phys(vmbus_connection.monitor_pages[1]); - - if (hv_is_isolation_supported()) { - ret = set_memory_decrypted((unsigned long) - vmbus_connection.monitor_pages[0], - 1); - ret |= set_memory_decrypted((unsigned long) - vmbus_connection.monitor_pages[1], - 1); - if (ret) - goto cleanup; - - /* - * Isolation VM with AMD SNP needs to access monitor page via - * address space above shared gpa boundary. - */ - if (hv_isolation_type_snp()) { - vmbus_connection.monitor_pages_pa[0] += - ms_hyperv.shared_gpa_boundary; - vmbus_connection.monitor_pages_pa[1] += - ms_hyperv.shared_gpa_boundary; - - vmbus_connection.monitor_pages[0] - = memremap(vmbus_connection.monitor_pages_pa[0], - HV_HYP_PAGE_SIZE, - MEMREMAP_WB); - if (!vmbus_connection.monitor_pages[0]) { - ret = -ENOMEM; - goto cleanup; - } - - vmbus_connection.monitor_pages[1] - = memremap(vmbus_connection.monitor_pages_pa[1], - HV_HYP_PAGE_SIZE, - MEMREMAP_WB); - if (!vmbus_connection.monitor_pages[1]) { - ret = -ENOMEM; - goto cleanup; - } - } - - /* - * Set memory host visibility hvcall smears memory - * and so zero monitor pages here. - */ - memset(vmbus_connection.monitor_pages[0], 0x00, - HV_HYP_PAGE_SIZE); - memset(vmbus_connection.monitor_pages[1], 0x00, - HV_HYP_PAGE_SIZE); + ret = set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[0], 1); + ret |= set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[1], 1); + if (ret) + goto cleanup; - } + /* + * Set_memory_decrypted() will change the memory contents if + * decryption occurs, so zero monitor pages here. + */ + memset(vmbus_connection.monitor_pages[0], 0x00, HV_HYP_PAGE_SIZE); + memset(vmbus_connection.monitor_pages[1], 0x00, HV_HYP_PAGE_SIZE); msginfo = kzalloc(sizeof(*msginfo) + sizeof(struct vmbus_channel_initiate_contact), @@ -376,31 +337,13 @@ void vmbus_disconnect(void) vmbus_connection.int_page = NULL; } - if (hv_is_isolation_supported()) { - /* - * memunmap() checks input address is ioremap address or not - * inside. It doesn't unmap any thing in the non-SNP CVM and - * so not check CVM type here. - */ - memunmap(vmbus_connection.monitor_pages[0]); - memunmap(vmbus_connection.monitor_pages[1]); - - set_memory_encrypted((unsigned long) - vmbus_connection.monitor_pages_original[0], - 1); - set_memory_encrypted((unsigned long) - vmbus_connection.monitor_pages_original[1], - 1); - } + set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[0], 1); + set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[1], 1); - hv_free_hyperv_page((unsigned long) - vmbus_connection.monitor_pages_original[0]); - hv_free_hyperv_page((unsigned long) - vmbus_connection.monitor_pages_original[1]); - vmbus_connection.monitor_pages_original[0] = - vmbus_connection.monitor_pages[0] = NULL; - vmbus_connection.monitor_pages_original[1] = - vmbus_connection.monitor_pages[1] = NULL; + hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[0]); + hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[1]); + vmbus_connection.monitor_pages[0] = NULL; + vmbus_connection.monitor_pages[1] = NULL; } /* diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index dc673ed..167ac51 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -241,8 +241,6 @@ struct vmbus_connection { * is child->parent notification */ struct hv_monitor_page *monitor_pages[2]; - void *monitor_pages_original[2]; - phys_addr_t monitor_pages_pa[2]; struct list_head chn_msg_list; spinlock_t channelmsg_lock; From patchwork Thu Oct 20 17:57:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF313C4167B for ; Thu, 20 Oct 2022 18:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbiJTSAW (ORCPT ); Thu, 20 Oct 2022 14:00:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbiJTR7z (ORCPT ); Thu, 20 Oct 2022 13:59:55 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 305C21EB542; Thu, 20 Oct 2022 10:58:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bbKWJ2ahj+hMI6+Y5mQjp/Ods7M9pAGw+CPc+3JLvo5qHoXgUpMqSKGis8MJUzIYcKqY/46dbq1+INwznyqHELXlrqQa/n6RxJFXkSgxc2ufSd8nRWop5iAvj8ctTCAOY13fTbR4mFsKtgH33pGnW3mROO8NczJel3iNeNEeb2PBGa7PZzYEd5i4osWEnS3QSsSIsL0hDc3PSL3ZldSrXKYXJmLYzspwrV7jPvG9M0leIq8j/suQhhDLJFZFCJEQNq69wTEPSfafRE5mXvSUmd2yRw65jGlZjFOKtaiVVjQQ9e8a5MewGkR+4usGX+gCm/473JouZpG4kmS4a6EdQQ== 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=HxJ8C3oTdHyjmsriP5KiVxO5k6CUwNZJzZyGZWis3kU=; b=btym7Ecp0Y0CO0TLtJV1D6MhLsd9WzKbCdzWDI+ANFgiKfmSxqHab2HwXjPzkGYr1mkMN0sWQ/R8WL11gl2fkI1SPfggEG9TrfRRXNSkeXWXb7LzOtnWPTRBzCnFzpjSp427mbeRDXHp9UaoEzJizQ4SfWkRdy0s82hu3RGxyMrfP0WiYJYnbQIgsaHouNUeY2SWXx/l+/15XncRLdrZZd+jSgmjiSiOtpUAEe8o5LyT7kwIsQ1hfPlY2OERHKtQZcc+DMfnhVpTCPqrRH1sAla9qdUN2pfkBfr23HqI0Jng+3m+4akQDRRRLXeMsqYzkBiKBXt47/kDUFV3vFD7HQ== 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=HxJ8C3oTdHyjmsriP5KiVxO5k6CUwNZJzZyGZWis3kU=; b=afP3SQy/kHh5Dul1DeUV+YJWDWaiYpSWU0cfyHemXCg2Pfw1EnVWV5l0OS5V6UkE1KroEwgoEwMjjk4GMDlA+FlB9OjuoLYUcw/gt+HMM5UVyEono+M4CIUJVs8zy0k/HCrT8/kjU4tA6f458OpmCAXUhp5uAMhZ6yfjqfT4UZU= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:39 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:39 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 08/12] Drivers: hv: vmbus: Remove second way of mapping ring buffers Date: Thu, 20 Oct 2022 10:57:11 -0700 Message-Id: <1666288635-72591-9-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: e9300016-2963-43f5-8bdb-08dab2c4b7af X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2UedVTZwPVZup/+B3I+GCrQ04u1QlDrkoz74NV02WzZkqYvqFGDkSHtc7gPRhzD78NgUgdM39uXve9mA/SaqHYu9IP05fACqezq1YvwFcKJbDKWtdBCHgAbDOsKUB0/uBoLTEGDKMNn8UcrOBvAznwroQDKSG2EQDehSnbckkJc4byDl5xJUCAgT1M6BIuylAReQ33Te9xVuwWpGtz6WpScZsNS39YKZztjrnp8FGh+AHX/RvNbhNfU6OL/qNg3COoaanrb8rS/2RJL1pe3BF3M6TyQi2RPYRX+sd03QwOmVk4no5nGRlF+TrUPVIZ7gtGVophrobNGw0frlfY4dU1nf+TuReWkWTbniqN7zelHpYz/tbDYy80aovDSbLKHiOHOs7CSwv3bzkPwJmIU/IR4cDbHUUXFamuLPu8cWpVXpb8940pwoEh2ZIi/z/HNbvs9dQeCWsQo9xQKbtnbh8d4I0BYxJNAfLT6FzTbXKZWQek+Xo9KEOtkIyBMnFKXwUdZ5akJN32kU0bJKWnaE+MhcXXuLwqJzKp/f8D43RGEQVkINjmjLv1zX8GkkMwmm/GCCqh6Mv9imw9EpQW123HPAqk4FvqyCzPqN9/4yon8ja63PY0L3zi7jyPRHYjiKSKwiWU2bFMPHGW3o6Gh3vGyO4xuGgIORxuaL7uZmtVK9X4SsWkymTjcMePi4QkW2b3dDAmqaioZr/8m4Rf10HmLrnX2E7OFopb7u8SPJOjAyQQRg4r+Gu8ntdf4p4o1eKbMCpdUZhakTLLiq6FtVH8/zUuUOfX4/yphUZEmHnmM5ttEI1b6Bov2Uo7CvSEfyk9D/wk7mB+kJ5zIDc9zZwQ== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0ax73wboF2ftmeUuCMabcf9O9Aj+tJouZqd/UdNtkIrw/eerTnExyB6j/xLu1rx0rEY9/mKdY6jcFmvtkL4xNWgL23I7vCef3UqA62yN6oPkQMWj6UHsTO9LPzef/N2q8/66ptslWz8LnZxjw0z+tk9id50yhPqYd3tYCz0dKJ/0n4ksYtQbftpw9lor2RWzxah3//XAqlIRPsa9exPonzT7BtBUeI8yBd4am3UMreFu8kM8VLFHTHRo+lOHjeQ+oalCJa/TEcTSQE3CVTM0n8ugUGZEYhWx+yzNvzAfC+NbRM0cuTT+2EsWBr8fgD9yLtpQ+LPJ5KhhawITiezm2X2ELm2l5gVm0JL9L4K9ZWwUZUIMWral+igx4aIiD4dkL1ZP59qADzH8f5AA0qLPRfX9n3aODPcYerDguZkbHiJ3uEL/BiGkOfANfYUf8770giZY+sOcLf0pEQxKNEayvDjguEVDV8yFEWLeKmKWCn5pdnhJ3JFJzCVwR8G8+yWaCghQyrkb+ckXdsSQc4whOvGsurDVF+KbGQmwBKQn/tKPDgywTIeb9jNYv9E8ZawrxGkD3hphh/ypObrLp7iBb5ekYYtCnrWV3strnC8qmRa/yzNiZYt9OOEC/NWUxrmaIUzyvXPC7BYbJ01qyajP52pAwR/gDjS8i8tid5uqoxojevEgqAhFT2mgLkFX5lEcTgGtsuzjoUQTcFnZacsO3ViTKW1F+Lnst92oU4Xx0LQs2QPOizIE0L3PgY2nWSN4PsfF+Q2rmOqnuW2pj9ypZmsNKugZvq2UUYVnvl/cLsE+ReyENz0AVXSL+CV6yn5RXrjyH45NaYzC7wx3TScpsSBYQSAB0k5cFgM/QnNy9YbbO2Qu5Q2ieMRixO3xXYK+sWTfviw7TvYBt2ya9C2Xr9idRGRiH42FlX6N+Lc8RGfiR4WJayMttEP+BjbEfC/h53UvLLuSHLQ/jbgSgnXdNFhW83rpto3wQrJVIT42auaGZVhXt7cMVi+/Xd2aIcOGwFh6dvpaH0fDHKRR47ciRAz4ctvJHOSuKqS1gi5RnJhgvP4FKfUFLg7TecI33HH9IM5y8Malk3+sRdmpK4wqXyMCw4UrdpkTFhSUUVlzK5N/kGWwVaenngz8APPWY00M3UxNEDuZfGZ7b/A67FvGl9uJ27sHV+XVF0X1iWL6sMdax1jyOIQ3lDD8S3skkPfG5TDgL/73bYk+YfxOMmCV7MyF818dQNGxhQcWyHl/2/qRfZtl8AS1xAFNlZ2MY7gkrxIM9ZCP77hhRy8mRSK71HlMB4tIul5LwJNdRHUP0bGlht7ioWV3t/GY9/kCcx2Bc1dqu0aqAGnmEWnTOcEqpxIqKFO9/I3NJ51xRI0M6WO/XJwCJqs+hwBqYtNe0riLvKmhLvm6NY2OfIsWqsL+YzPdhe5wMdBZHaxJBE9aNlBRHObmA3Pny1WTCe72f2VXe6DyIvJ4hQwdEjauwT9ZlT78YM1ETApurLV5Yl9czRBBFWLP+4L8obqIeTbiALukYgnGSX1sJwg47wfyq3tnklm6oDsGjGDUh7Zty5+BGBGopuh5bETw0FLTlT9iqqoD X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9300016-2963-43f5-8bdb-08dab2c4b7af X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:39.3759 (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: t4qlx55nTvzptZ7mZlrTYVx8eP2JC7jY8fd0x5yTZI8LZ/lbfJUNFSuoxdq3WOBegKlzYuS9itE25OxpyD5CFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), it's no longer necessary to have separate code paths for mapping VMBus ring buffers for for normal VMs and for Confidential VMs. As such, remove the code path that uses vmap_pfn(), and set the protection flags argument to vmap() to account for the difference between normal and Confidential VMs. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/ring_buffer.c | 62 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index b4a91b1..20a0631 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_NOENC)); - 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_NOENC)); - kfree(pages_wraparound); - if (!ring_info->ring_buffer) - return -ENOMEM; - } + kfree(pages_wraparound); + if (!ring_info->ring_buffer) + return -ENOMEM; + /* + * Ensure the header page is zero'ed since + * encryption status may have changed. + */ + memset(ring_info->ring_buffer, 0, HV_HYP_PAGE_SIZE); ring_info->ring_buffer->read_index = ring_info->ring_buffer->write_index = 0; From patchwork Thu Oct 20 17:57:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013863 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86B1AC433FE for ; Thu, 20 Oct 2022 18:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbiJTSAr (ORCPT ); Thu, 20 Oct 2022 14:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbiJTSAB (ORCPT ); Thu, 20 Oct 2022 14:00:01 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 254D11E8B9F; Thu, 20 Oct 2022 10:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BoETlBi5fl8IcCFM4IBgGbYoqJT8OvjdpKCoXa+bU0QlMkUzZNPJ5ISSkk7QZtwooZ6Z1ViRyc/dd+k1IulP3BUtjoWuTUmU+6+nxS2lIdIdJh9X3iiFlw8JKPKOmrHZ/zPJspSRJdt8yFK+iD5IjSX/g9OwA8RlZMrlTnzPO2PAA2ztlGVfac6sLNFwGKhfxy2hYSUJzFBMtdI4p9DjVD5gQdBSecdpoQNZmweSfkesbdkPazKehm073WseRMsnkvU9ZpcTRW8WASC4W2GRXUxssJn+qhT3p6AyFzpzZ3WnLOJq/QSsqKDhH9mnVz/wjQ7Wqb+bPVPY1JlaIl01uA== 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=PDmLvoG9/pzHasbTbozbfs5gxQVzVwO1XjrgSlWkuMo=; b=Ht3RkviirN6as9T+ylDfOzFMIOzkJOHaSB3jBFzFspojMZpM5EJ3og1EGdfomJSEjc606vfqi+Yh51TxpiYPGImyAZ2vKAngvMfYqnXNLuooyfP4Tm/3Lj2I2GrIiCMr18BbT2+WDWqd+H7A7N/Fut5VVm3DR81MqeH14d7V1KPUniaefefvfGpDtBeUzvTUEpF1GBJGB53evsVc9ZHgJSRCJF1HGTotMXNMHpKmO4zq8hMMuWjjbAE+z8v/uq76Q3xzcIDRlVDbqRuslfrSSCftebFnhV/WqGqPiwvn3bLd2sHiKzgZ80l4444n1Y5t47TKtlFRwCBSP/jYZIGZDQ== 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=PDmLvoG9/pzHasbTbozbfs5gxQVzVwO1XjrgSlWkuMo=; b=hdYJaYIiC0NLiV1bkYI7yBsM4zO2AKrxyOZe4lHKczGE6g5q2lba+qcYrQo+xmbzcIRcdincmMvgAW8K8JZ2d45BCRrmZYIIimxukpCPJI9Rg8jy+p7t4pkgCXQwCwjKokRA9qmIfE8nQI9WGHxpOtKmTB5gY4s+u5TbwqQ4IxM= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:41 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:41 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 09/12] hv_netvsc: Remove second mapping of send and recv buffers Date: Thu, 20 Oct 2022 10:57:12 -0700 Message-Id: <1666288635-72591-10-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 87f79f14-e92e-4ba9-c11e-08dab2c4b910 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ia+yDtN9GpHQdMKo+1zhe6riBfKQfXKvoZj30tWrVe4go2Skz/umj5HHa0E/ULHbp1FeTLsa+dKNau8WZQdd2WUmPbcMjDllH8auDjGB0logMPSr9BBaz5QVyF/A2L601hBQeuMAem0skmhaS7ljRDNB+pHINPbePQOOjYOoZB0V0OWGZnwSqHUbUPy5uZuma/ZprRVDwwdepKaecXuhxSPtGW+ZHzbxGHSXGZEvRPi2aDIViEnPW1iGblOG1UHtmU8UMt63gWm/7CYL0OekHmF10PAi8tamM27x7BpIwEDFgBxpT8TVuBf60e+UvxIK/RQGTJWokX7O4FWfW5l5rEkGgHBbqdywbQ6OE7lVeBHNok1CTYG6p8nJqdc6Eauzb4vmZlD2h82cXMorO7BA+iX9xIySjdUCNyOLQXt5lGV2oPqX7Vzz5+Jz17ictM772DpGB5nCl6zx7jrKf/2geT6CmRJcMtucKG62H3QkY3oaVL6lJ+Nr9dVtJ3axMuDXeeADybMtOk5SD9yKcv7crtuct+/a2L8o+W6PKzf7EqBsDoG+lTxBW3DEW3r8jKIr0/gTOYLYT06fhc6bT4LIfvHwNWLFZpjZVQqNR1ju82fWULp6k3NvDRQ82LT9+p4FhU8EhsgF8uMRlSNw/ecfwPugJM6rVhZOGlSg2EFGDcHyq1AzVa7y3WPYwnZs0iE+OV6NoJ6ajPqWvYEyk2iXzCxTkLq2Qv/RzfY3xrx2rfF2vW2z5hmt1FJFkdoT5S5Sv1OeWPa6aS0JKQTbHQqGM3EllOyoePAESYliTwCrbQ7ztfm2L4cVyad9BHfi8ygJ9EfAGjexknpnYhbejpCGkg== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6YJT2LfGjvq2BKnJg1sMzUFzJ1UG1DDZfX4pJ+oSwqRSIriZaw9PNJGIxQdDH8dv8NpvW3+qdkPvaAMnELLny8zezzwSCdQWTa+loH8FU/J7vSlVqvPbDHhHc9s7lMQGTqYRfPISg+DWPIG3pssAyP+4Hay7hfc/x/B8QNTfdTCYUORfa23zQF1cgkrDCBT14aalR2UusQ0jeRjpVuIPU46KEUrYgwrhY4yVWYuUqFLvx45efLy1iyq2dqXSuSk0DCQJTppgUFKv5CfaMwtPqZ30heL4GFt6LsY+9eD+6CqayCp7SB/GPZM3uvyuTGnADL6kChiRd+k4TAt4143vfMVIP1FcNdMcgLfMypli5kd0dEk3QafTWCsEkffwy6CO0tssJ9Pf++1/+O3O7v+Wal6zXQzVy/yYXbArVMNwXz5X2vJYWt2PXxnmfiEAQ0v2Smt2ckoPOllznP7EUqITDdqiSl74SlhnwqFCWp8hPqPnOZ04ENwtOQRi4PFFd/65w4TC1NhVeL5//cR1R2Ri0dDi87aMwS35484nFGglykBBN4f0oEqoJ/+G2QU4XWM+wlsHbqtAyhjcpRs/YwCP9NYRtTJ37lHumFwpWPSZ9CAsEGRKHt6QDlKwcqdF4XrzGR4dphiDNEzrsZwaB3FgGVsmYp6sn8rhb1HDGCkXO3jag8vbXjm907h9H2/UbJckelPTcrp03gJGuCA0NUyfdMdXbMNYCTnEtpJm0W1MsW+VRaiPsaZJkwzZDSJRdDp7VGZH4YLMgHSa9L0413XvmDGirSLQQDNH8HtVBOWusagBifYLYKcDodTn+j8xVsj+nNv8xaqeb3TZa6+Ot6Fnsnlrp/6xNz+tNezEEARyRhNjzeLhIjU5NiSK70dKsKzr3V8dW8k2YJpGPgavRSMnUAYR02Mk1SgB7V3BrJNttLnQz+Cx0CNdz7IccSRjpZrOgunZKGTzySDR2B0qlIIL7XC77wnyW0WgGcnbJ9vO9GIz7IsSdxkPmIJ2iEOnqaoSCOtkxlC8GduH4Z/hPddCO0KS6SO/ZgxI2XAp+oWpSFyDAXUrWoGSeTjLpOG9zUBeVFhi+uIPtm+NjJSvDnpK+Aap8ayYSMGXYfVWMPRPl790RPvvVfmx15Tlrxmz9ddIFf6qZBoT8bzVj19ctES0KEitqwg0j6ciI+hbyhsES24ZT9+XKLDcO4JgTuLgM2TPZn20AZIlwSXdT/FLBSU/Hwd58fql4XVhluoKjjWYS3ssOGm7zXBuy3LGZl3XXt9X55TdNoKHcCtqZj8DxNIq5Kul6AuuOdDcEvTEfVDsqouUjeKTJI7YdFgwJFU/IiEWdNXOjtgAP5R7ao7Fe7vLgqst64bVE5DMPviDzs5ThGL81tZjwPwJSfUHLxQHkWBE3sV7aoppN+Scwq5xhnFKNtRmoXT9LBFgABRYVYXOohL81Fnplyc5v6nX65wHzjlRzZIoPoxGxq/OM4hJDd+olMRLtXPhRw2SWCdjKGYznhChx6dtAftKxa+Td0Bqzs+au3TWObzCoOENePKAPLHUF8fc4IJllJfRhBOiAXhJ34zvSejOGjRmCGkN7kYY4bw3 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87f79f14-e92e-4ba9-c11e-08dab2c4b910 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:41.6750 (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: G1aiVKKsJZhQvikX6CQaw6GDZHA9mTp1pwqkdftAiV0aUkcNYy6S6cHinxiSec8M37cJ/V/tyfDkrU2ChNDXtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for the pre-allocated send and recv buffers. This mapping is the last user of hv_map_memory()/hv_unmap_memory(), so delete these functions as well. Finally, hv_map_memory() is the last user of vmap_pfn() in Hyper-V guest code, so remove the Kconfig selection of VMAP_PFN. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan 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 29ccbe8..5e4b8b0 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -349,34 +349,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_NOENC)); - 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 ae68298..566735f 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -308,14 +308,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 9352dad..661bbe6 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); } @@ -1831,12 +1793,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 bfb9eb9..6fabc4a 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -267,8 +267,6 @@ static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset, void hyperv_cleanup(void); bool hv_query_ext_cap(u64 cap_query); void hv_setup_dma_ops(struct device *dev, bool coherent); -void *hv_map_memory(void *addr, unsigned long size); -void hv_unmap_memory(void *addr); #else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized(void) { return false; } static inline bool hv_is_hibernation_supported(void) { return false; } From patchwork Thu Oct 20 17:57:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3AE8C4321E for ; Thu, 20 Oct 2022 18:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbiJTSB2 (ORCPT ); Thu, 20 Oct 2022 14:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbiJTSAU (ORCPT ); Thu, 20 Oct 2022 14:00:20 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022018.outbound.protection.outlook.com [40.93.200.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F4182192A0; Thu, 20 Oct 2022 10:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Am5l7j7dYKVMtiVtR8LS5uteN2+Fg9bhithuuhBVkSkRKuuoEbWoltYfVaNCCD4RuNtp5b+5N1FIgkq2t4E53WRRQVlSjql3XfhwP/PG9bHcteWbfpsVRNZ2D/eVr3hNVjwz8nu5SjB7gRoIz/wJ70iIl9hWqV/5BZndf0s+ULnRTiow5cJxSblJP3+vVREdZTFGPtN5FA43pRyCvZyAyvahpee/OIxlm8JUYf2+mBW3PGc57w5PNpi1a1lcAuzGYJNYx5QyGEERhRhoGfFnG4dhaYpDNgERgGAyXt+zaxmv4PUZED5cTApQApA955Br5KWdD+fmEk0vNAmBo7ESGw== 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=9iLJ4haHZkKLkeS3l8DGMNJQ9gab+4nH2WDd7cRqTE0=; b=LVK1i/zkft2/qXnLUbloxMeyHaSQBhYQSbqcgjpSF28uG0Da9fdfdfKOgT2O8XeHfAoWcH9o7hgxdEq9XtKu3M3W2atcBiBaj2pqf9Gj1nYZGl7xOvlQdnJ8IXuj/hlxIspAZ3tXJPw6QTQjOm8OUrgXKPOzNxjKZv+TKou80QnDdf6/7um18FgtuhgGY8O/60/RXXN4nZrr3+6QmxEppS/NKS1zXGGISqTOZ2UWMhYR/H8XGDGJrf4Mh+nf1d30wx2zNon+bAqzzXpfX/6us1J2sSwV8bQdtXKo8WxwjaammVNSOuwnLRVSm3JSEwtMi5fDJqrNopYJ1BHRxo0t9Q== 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=9iLJ4haHZkKLkeS3l8DGMNJQ9gab+4nH2WDd7cRqTE0=; b=PfjIQIFlHqfKRXBLAX//uBUMfzxuEGLjh4IbiVCGGswyMw1V9TFiH1EZ96Q3lVi/RUEjX+naOuouZaO7TdLhWA01uT1fDKE+K9fk/P73UUBDvpVcFUHCXauiZec1k6QEFPrzovrYuzINvjqUs5syrJjGVJHAl3LUFgx5a9zSMCo= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:44 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:44 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 10/12] Drivers: hv: Don't remap addresses that are above shared_gpa_boundary Date: Thu, 20 Oct 2022 10:57:13 -0700 Message-Id: <1666288635-72591-11-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: e116c558-11ff-40ee-74f2-08dab2c4ba6a X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dUwPyQNBaWc3JHmqGXG1z/gIolj6H1xe020Ufiju3vgYtrF8TLO0VRm9IIFzMVGBnqK2dO8CP+HaNhBjsxfUlFB0ezuhSD7TUGAJMVwYrKVD2pPQAsduN74kyoTUFtF8AC+6Y6kOaVCdiryMckAzCB0dyoSFkFjX+pXJrnwlFqKASYlGNZYLrX3tTKheFA0e972/5o4lQ+jUSxUHb0G5rz0Fow/akoszJUe61k7fyziC6GEz0EQV/uk1fNesmZsyqsI5YL9IqpsBdD6d/Ua6HVYEnMsXVzmjyvgG+YXbmDsps/mo0NJrqyFlUQ2geSqy4yz1UmFp9It+Fq8V/jgWZ6QG0vPQuneA52nWu/3N3j/pWEJhT0jrBrkTt+hJhY9yuUfzhggbjiMFgBPtxbULYkaH+4/uLwCU9uzoVKZJx9dInlTNzUIgLLvN1LiWbpOLXS48dsFzhzck/u1BWZKBDv3I/qSFqU6q4V2srgMCnZFaIU4mgrHlA+hiBbC/j21k7Tset6NigCCgIO0xI0HeVRH6KGnD73s+FK0PFpH0jylg8vOyrzihDcw6DtJy1hUy+1vOl8EHFy6hfdCbgsv9EIihM3wwQz5Eu73xm+wlyCNTi9D8/36AmJCOrWMBTretXkFwLHJBJNz/v26W0sUQq7SqH3EL3XnPF8GIg7bSGmDiVO9KgIuTq4KpDdWCh1RbdgQ+zCZM2nfAnHQm07a01/WUj9f7fDVbnnAIEUrqcK6Mbm3l3nLaz/Xtn7BYa2cgrt+DR2gmd0KC42bkfXwOvSzLgZJVHJycTqj86Xda6MY0fppqTKh0bDhAgprKVvzzsSTF0zVyBz9ofXCZm5ChbA== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2OL7jpywzKRe/ZAbFinLiZJWAFde+cW4qRipQLgTqZ2UJ3EOg+0UrjsZY0BhisnN+xdpKYiXJoe7VN0fqnOSU7hR3gFaxgSH7sbMFZrt98Sda/YOhvphkZim7hK1xx3zBrwzhr6H/AjT6rReFjXDtDipQ4zEVKSqg5Jp/egO19I2OmPTpxcgCODe/swbD+2lqZnw4grFEd+SWgxlRt2CIEnAbLZIK4I7Af7HRCrXzNfNNkjMsiu8BIM/J/r7y2Aktvtip9e3J8Svvlat/i/bEu+dTcNvW3GrZcj8tTf5KP7aQurhPexU4X8oSL96jbTy2AEzQqVBRocY+Y2xo4ZBLVmtCP1K/aNdZmxeytwHY0I12ncQSy2WSmAL4CNjQH65ruPM6xn86yETZzFBGnQ2K18cxe2hBBc56KccmQe/4j9s8NxdhyguG0Ab/RQmSJ7Xa4HZWxW5Two7sjUF1aH5cqB2l4aWs0JAig853Ksx3yqH3+AqbLVIw8afotWXH22zuQl83qPf0NuC76QZlSyloW8IMJri2Oy5olzMVh8Pm/e+smNRJD9JvFsUY1569s6FdVIwEoWHudoC36jx5M/h5a+xP/mdLufRfSHSKBjhF18c7NoxeqPRi8uobWWzXMbWcizmRuwAXN6sl1rMzuYd3I6in4nyqeyGRkpW/1r1WITg8VIqT+7p6aYkbtzELhA/3hPUz1uZUTRkS6EdK8xy6lE5LyvPRg6sSc+PnniMl7DSEujT1yzGTZ+lDT56gZc2VqemKAgQpHZm5MK3W01SqRlCqRpkdS4Nx1gP20KMfaAwqnWOLxcSdjDRt+/6Th8W8uA7KcbM0hyf021PmBGBzGOW2XhFNmgwkw4s0UU7hUcT9fni/f5qrD8FwpG+HYLYeO6Pye/0HmqxJCnR1BcpDsWXV027mwRSjBx7frYtZpT4eoOzxR/BmA9kMCcV/UZnlXLSGfjz2hMMrzNyM/olUmL6fgD5rx3VFXl8JAZ3ve7No3knPk1dprROHsFtxHZV/iagWQcgTKyRy6Z9MvC/nZKn165VSPyrlaTuxUwTTOZVm4pGV+BBRqAQXuzkK+HT5DkKwGdJUdNvmxwb1oGcTdQ+pd56wdqzXQwyznT5Ra2VIm+Yej9R0JtCTV/ay6uaV+gRmUqjsVcsmF5UMkQkWZre+yBG2zIlH0xU6ms0Ad6644XWsIn3pcQp4KRVHjfm4KaEpmVU6fF5TmEJNSDh6dyeUwjdjEhvpMI3VSrQxlUnFWBElMmjjo41teQJPOWghVGpyKs4AMvkHyh3tqt1CfBIhvHGcybQjoz6b4kWZZwJnmBlPd7ZOHeUYgsu7iyJezNo0r6i0KRy9X9SfhM9OiRnyArT0JtJMBUBANKnJq9G5rz8+uubpkrdFAzzgCJQ3fWoOW+s2kbZbWg/axZmRwCukBb8jJXXmORB07X5MnCjIY9RxuHRGLc68k057PXf11iuwffGAr8FCA3aV9vfU3nDMjHD2bIhHOimYznTAl2dd7OwC7Yy0oopmjtioJ9q9LKT+EIE3VGjvYO1rSZs5jSTaQb9ODPMJsvNOg4V6HJ31DUW8FbsebYRkFzPL8RC X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e116c558-11ff-40ee-74f2-08dab2c4ba6a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:43.9731 (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: TchAVr5jS45cg6UMnQ+S7l9SevACQOMEmx7AQdqBJarFCZZs4Aa06HeH03OevWiKvDXXkLIbzrtEHz3AO7NRZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With the vTOM bit now treated as a protection flag and not part of the physical address, avoid remapping physical addresses with vTOM set since technically such addresses aren't valid. Use ioremap_cache() instead of memremap() to ensure that the mapping provides decrypted access, which will correctly set the vTOM bit as a protection flag. While this change is not required for correctness with the current implementation of memremap(), for general code hygiene it's better to not depend on the mapping functions doing something reasonable with a physical address that is out-of-range. While here, fix typos in two error messages. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/hv_init.c | 7 +++++-- drivers/hv/hv.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 2977412..c881b5a 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -64,7 +64,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; @@ -220,7 +223,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 4d6480d..410e6c4 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()) { + /* 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_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()) - memunmap(hv_cpu->synic_message_page); + iounmap(hv_cpu->synic_message_page); else simp.base_simp_gpa = 0; @@ -326,7 +329,7 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.siefp_enabled = 0; if (hv_isolation_type_snp()) - memunmap(hv_cpu->synic_event_page); + iounmap(hv_cpu->synic_event_page); else siefp.base_siefp_gpa = 0; From patchwork Thu Oct 20 17:57:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DE5DC4321E for ; Thu, 20 Oct 2022 18:02:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230189AbiJTSCH (ORCPT ); Thu, 20 Oct 2022 14:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbiJTSAm (ORCPT ); Thu, 20 Oct 2022 14:00:42 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022018.outbound.protection.outlook.com [40.93.200.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73991520B4; Thu, 20 Oct 2022 10:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PFoD2/cY1NV/97pRgORmdN87QfS9z5QFTgWR+UuyBaDOdbn0y8ZzQFkJ5G+4YAuv5ar+0lPrcOzqcC74Y2evHqHXNCdCj+049VWs2a65avWuqzV29vDX0ymK/QeJsa4/waJmDxMXCPpQOwttPLfoYgJ6Iu7p4SWb7BOS+lpKbKidavg4nM+1m2u+DOK8jVpmcRU+JfONiYcyT0l6Srr1Cm8kA8+fc6Owk4PQv0uu+SnYADlCYePaiAhRY/fS4n9nv3G8CJ9nRBoxiSTuv+68jYI5mh4Y2uRha0mhq2LxPfw5Wus+Hup63q6R/iBuOnDU85n958JoYvpJ7nqp0xON8g== 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=Plt1PolMVyANi/M5zQYiscshOyKlEv6HGjqlto38Us0=; b=eRgrdXVVF5xFamuyFFANjUt6JQo2P3vy2f7ubcaHbCpfSF6TrOpccMEsul+yn8p7/ALbQYSnOuLjicl4ZIl2JJ6AbTnt/xb/+H0Rjy+zxbOaBzg1ivXD0Dn7xDBne1zuknk3J4SHcZJ7lQ85aBmqsuTJRrrCzioGYVDx69v7luO36nSjYA1zFEdxitMoOUY8cWyw2orv/L1Gev7Ai9F06J1mOhNziUIzMbLCcxG6+51DDZTRTxzjVuIOoWpXvY8WH6yKRIM5m6ZQsko371pZSW8RwxGbbiZCIMHmrXjPQ5ieaPxLosrPfSdJ1ZlZ4kx0XoDaYjOx2VMi+sditTHlMQ== 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=Plt1PolMVyANi/M5zQYiscshOyKlEv6HGjqlto38Us0=; b=NJmEmyimqM2Zg/ZoEI/z3sW6kId4A+c1sZCLF+hsyZ/uRxLRkK7OJvxs/ItoO2DYkHfnN8YvXtACCQKz9soyGj9znLlkOIKtIbtq9jytPPFIbHuZwIDxlwSw/eHz3Ll+9w5V/irjImur3s5tbvJ1ehDz8E5ye/2vDpvts7l/5YI= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:46 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:46 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 11/12] PCI: hv: Add hypercalls to read/write MMIO space Date: Thu, 20 Oct 2022 10:57:14 -0700 Message-Id: <1666288635-72591-12-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 72ab9e0a-98ea-4f07-a6e0-08dab2c4bbea X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fn12x6xTZG2r53+InloGaWYOtEHWigCkYxugkUsFRw4RLkG3C2IRTArOrxk/GGHCdSI+bTVByrmUivl/q87n/LBweKg9qMMv2/D3xEfWzsIktoHA8ZLd0PBDTrMwLv6zVCEOcKPr4LFNnBDkdASsd6grOG4aOePThw685O3J9DeCV12KFGI/hsA270bk5OnSNsexaiODctnUgIlj7F/xvhu8aX1LQCW7qSPXCimZRvAVWSxDZCG9Tk08j2o+/jk10CqAMlfESYvwCNXzdMFXDVTeYs71+znFwXkqXJ9vr/81mnKnNRCSx+Xc2nVmtBnFIWOaneReAbjagv8TSjvXDCvhZV3IYpgg3sYpOIRD0dfEpkBrCsieA/4RxXIut8Sj43cIkrg+xt/Q9KskjD2TnUmF1WkCOXRq9bxreAIRz+OxtgM7RvNtR8yyKo1kaxalcQ6VldnDXdR12WUFmpDvRHHEZuzk82H3pbchRkHbj7RomafQMVTeTfpjS8iLw6gxR93WyQvgEvLBFyjpMuOqTv6tBkO3d8dW09dNWFu6hRWQXTab9ZeTT+PiUSM4iu8CI9FqXZyZFCnxexnn3ma4z/X37azD7LdiIyLSqxYsajp1rfQeyZrVYZzO3sBeLx0AI8z8PgBFXAoQbhV4FCtohPAFqsDS4Esw019r48Fzgn5pRPdCT8oqwgrwCRWJliFF8U6Vz3hjqWge+hDcqFDAjowRECXOyX5yCDajURZ2vWphA/MxoduogL58G9WC4A5cqkgvbmTe8hgGMDbM0phf0M7neFn/bwqC2I6bzYVi2zyi972JE/PimbT9j3FtEP1KEPoY33iLAmevCuNXKcFCoA== 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dMAztay7/FuwhzRbB/FPmUXaOFrzA0IIC2mp9D8Nljk2kQD7rVmbkvAmRS8Y7AGZXKdRc75xJgrfwnxWjwr8wgkj4Uplma4OS/B+oAYdnOL3tdhXC8RtD1pfuaKwgnoDqto942TWc5tFupF2lL0tJdVTUOmzZEsDMc1wUXrAy61mdM+HYGkK0V5gMT/Xr82mPiyRzwf2tgFamL9rhrTawwjh+spQjzNWiEbvoGdfntwR5etu5aNGH/xkzoBRC31S8Kvw2LFJqB4CcN+7tN8QqJl2+zsBwfsgq26eaB7JQR4uMR5HHCEPrf3n20Et+bFNpVK6Hw5QvUG+xtD/cFHUTdH4gUIbLuODewy7d0t+tYcHeHIUZaO0r08polK19cHaLFeitnCOMDbM/B+vytzzKno+X5v0am/eDbkY0YvXYFj9hXTsDLCsiQw94gJSam4YRQ9YUyWhfyCkQrJaO3D6ZqhzNx4Gb3As0b6/WxKKoijs2AclkLWPaypHt+U6YnZgwwWZkXRlQQnIMn2WG/ay5i+FCKQxU+4qA+IHtqrhJpXxjlJSNwuO7m/3AxDfQakXQQpMqzsngacZBXwUr/jtkv6GqKfySJtPBcv4TTrkn/Mgla4KaIANjajQCz9xwVJablid0++wnQQO/5waMYU/EBMmODlhR1Qxt9l03Z32tN3f9tMBLH5g6qUoxBljQzkYpdji36C+t2UAyA2dOUYH5RKC5WICvDdd5Mt7KKPvZPrASkQvtxDENkjbvCheXQraYBppU46Z8e7fWk6IrvtjLewe96s+r4lXKw8F7/0uT2iNmcgQcEXK8eVX1aWOtnp71AS3S1n9/OnJTq48rJE98M25h7kOaLwfHzUDHqKI3BZ/3f4S3Gla9O6BHEpqiuEr3mCNcAwrwFozJ7kAKVKpA8ZbmZBImsb/vHb7NN+v/iaNQYwbq29Ht5Bq++fMb2YCwgijCCnlbpZyd8LmsJIdD+Mz9pN1MrbaDg3HmS7ZUBmW8q5zE7YwBAC6fZAd1hfK1BxQrqv9euYU5RJ7hIxbUVkHCITMk7D4AHtFS40uL+dNuRgGF0CC0k/EQaO2AmFDk05bmDA0wdMBfNxlQbEXM5SfRnMFcYfTcvpCqeSWG7ZXW6G7BCm9A/as+0sreXmhT3oFiMrbRpOXPlUI5jMzQX6YP3tMmdxbAtzR3d4b0S4qw6tcw/+Cc4saySFS798lo/nQrsDy7JH0ohCzbynTtfB5PSKj2WJqY1qCYXwp0jW7JkpdFDFJ9O/3LgajyipsAW+nTOYY9dqlfOsLHIs1j//H8kMXEet5DZ4SatfaxVjzGrmPevFcqmydo2i8qF4hfm+FvSL9NfL+ovcxRJouknfnwSSk5K0PimVK4VZC2wdn9a0M+gm5FrYw1eZhSZkXIm3GFIN0vNYxQufgXHB3e+S9hOU6hmNMzlzQoUMQC2AsMCYQLpSP4jnj59rnWzqzojB8z+koa3Sp+42nhE6iOX5MPEN0BCiEtrAaeC16EAi4ceztQv4RSp/gwLWuM1Hx9MjAvc6Tlb4MkkAuCfK7mrADgGorm8IALsyzFXtAyRHiUd8GSdzuS0X7uIriS9ts X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72ab9e0a-98ea-4f07-a6e0-08dab2c4bbea X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:46.4429 (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: shoh/aELAxONZryg3US9rL+/VybLtOJdUvaks0O7gZ41KHCl4k6vVZXxrOdKoKX9yae/6KIOJFuCKGFk1pJxVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To support PCI pass-thru devices in Confidential VMs, Hyper-V has added hypercalls to read and write MMIO space. Add the appropriate definitions to hyperv-tlfs.h and implement functions to make the hypercalls. These functions are used in a subsequent patch. Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley --- arch/x86/include/asm/hyperv-tlfs.h | 3 ++ drivers/pci/controller/pci-hyperv.c | 62 +++++++++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 22 +++++++++++++ 3 files changed, 87 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 3089ec3..f769b9d 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -117,6 +117,9 @@ /* Recommend using enlightened VMCS */ #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14) +/* Use hypercalls for MMIO config space access */ +#define HV_X64_USE_MMIO_HYPERCALLS BIT(21) + /* * CPU management features identification. * These are HYPERV_CPUID_CPU_MANAGEMENT_FEATURES.EAX bits. diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index e7c6f66..02ebf3e 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1054,6 +1054,68 @@ static int wslot_to_devfn(u32 wslot) return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func); } +static void hv_pci_read_mmio(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 + pr_err("MMIO read hypercall failed with status %llx\n", ret); +} + +static void hv_pci_write_mmio(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)) + pr_err("MMIO write hypercall failed with status %llx\n", ret); +} + /* * PCI Configuration Space for these root PCI buses is implemented as a pair * of pages in memory-mapped I/O space. Writing to the first page chooses diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index fdce7a4..383b620 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -159,6 +159,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 @@ -781,4 +783,24 @@ struct hv_memory_hint { union hv_gpa_page_range ranges[]; } __packed; +/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */ +#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH 64 + +struct hv_mmio_read_input { + u64 gpa; + u32 size; + u32 reserved; +} __packed; + +struct hv_mmio_read_output { + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; +} __packed; + +struct hv_mmio_write_input { + u64 gpa; + u32 size; + u32 reserved; + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; +} __packed; + #endif From patchwork Thu Oct 20 17:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13013880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4FC6C43219 for ; Thu, 20 Oct 2022 18:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbiJTSBr (ORCPT ); Thu, 20 Oct 2022 14:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbiJTSAW (ORCPT ); Thu, 20 Oct 2022 14:00:22 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022019.outbound.protection.outlook.com [40.93.200.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD0931E3CE; Thu, 20 Oct 2022 10:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YT2cEu+YSmC32yD1NlGgbOpDoG4C0suEccXyiuUiac0fEBry8d3xzR8avzuztm0BGIiKWFXU6z2b1e3IH3CEMQQ0cTK/MH2oFEl0sjvp5C2kXTbsg1hjZudkZO74IQN5nmYnfOQOmbsMjl513nTbhL635nw8WyofLwyzIwPPeRnolVgiKZM5wzzquJCLQzSxyfXgYDSDuj0vI5W1GKKhZxirBByGRwxlyAycVVKN90NhTcJ5oH8aCFMTSUxkQpZqdz5PmdLtZij/ux1NBOaiyEqE6uPbRQzeQgO3PXAdBw72zE2iKHBKnnnRseWC/88jEB0hEBBE9epyE/i4AuGi4g== 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=eljc1J1pgzqPiDTnuiJvXOgC32zjnxb/j3MncVDhV0Q=; b=UVnZC3vgnSxz1mL9gRQ6UahpHhcl7Eg9hbpvsCAWX9Kou4zCDEsqfCOqbChIeKwAEzQq2108SO++KM5P3OBwVdgvHyyEduIctkfuk4kkijOxO04DA/YARjLV9ilOiRdB8pVNJaAiR+WFAePf6+g2WAHm1HwkyabXz7JCRtQ+gokZDrA3dzgatfiehsCu7rEbQoa0Gt9Day6E1HRL4Ro3cWPNWWo6HyYD66cShH4vtQLEI2ggDy8LJdFPBOnCmgPr7qnT+J5KXB5kgQtSVHEucYqxHMD++CclGEAGbalkx3F6J/7kHIL4DFfeY4uXEx53k/40oMkoO/BVUeTDB7BeQg== 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=eljc1J1pgzqPiDTnuiJvXOgC32zjnxb/j3MncVDhV0Q=; b=ZqmBRy5CMnmqlOhCmZjLEqYKTiZ0/mGJSO/pFgVIceXyWjs4oWXq29vJ47Fg01yZ1+z9TD6+YHci5wZ/dxnwog/155W6qJtWzMl7YTcMSJbZx5Dms37GXJN5pK1UML+slgTW/WNn9Se2x7NYEE8Nrk2fjpZCqzLOJGbbR1bi4hg= 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 MW4PR21MB1857.namprd21.prod.outlook.com (2603:10b6:303:74::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.17; Thu, 20 Oct 2022 17:58:48 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::be79:e2dc:1dba:44fa%3]) with mapi id 15.20.5723.019; Thu, 20 Oct 2022 17:58:48 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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@infradead.org, 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 12/12] PCI: hv: Enable PCI pass-thru devices in Confidential VMs Date: Thu, 20 Oct 2022 10:57:15 -0700 Message-Id: <1666288635-72591-13-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> References: <1666288635-72591-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) 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_|MW4PR21MB1857:EE_ X-MS-Office365-Filtering-Correlation-Id: 62a96bf9-646e-4679-577f-08dab2c4bd44 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sJu1tWV4gZGPneFsojIUsIQUmGX5sta7AKjtuVF97ZAZBhD8pTGTWUOpJD52b7eSq9Og5geg/Sx1TVOmr9ERWPVqHCejb2IjbCjSRAdTb0baToWmZEWJD1YiBuImuwKXDi8AKdk8IvLzUP1+rjEdcTOmxtm6xYIG2paPhkt2jk7lFsIdz+iDioaoc41msGNQd5CrHm0ZKnVx3rXejx2rpgXUHfB3ViIZwibqSK1aXfl/EGw3ocmEf5hXF7bQJnBCt7lwSsGlWkRZMeoIm9A/UV+wZ55FWD4iOYf6qxRBn0wCl8q0r5i0BDVwSUq56x9THmTzF1CagLIr0ShDvKhBL76Ih/AdKOeW23FMEWlJqG+3y5SKqSvAXvBIMTrSj/eHa4FlMldsJIhcb218jPnfcu1HTphqb02bt8JUl0f+MML/ed0O/51BK0r3pMz8OIAlzKc7vC9bDukRlrDWtyg1xXLy6wl5PUXFmtuQTj7eyM9evNcLXOtJ+A1yVpc4SChb3BOMxCNpxn2pHjPpACbxSnXh8HCDZqnzCjeGIkTA0hJJG9sDzJq2SeZs7AR+17b6C5PNH+Wfx1a7p7lZjjdomvwWRtfLnPyz7kOZe0dyLV+48lx5xtIDILu0nK3ayjZMw/D8SaShl0OW4S8Ugv+fdLm7Xpdn46CWwyjbTzxEzuIfpzk+SHrjR+EKWxirYP/FOx4O9fXKjzrEWO3gF3Ht3YdfyhbTxhGX/LgDSAoYIQIkgQTzMqM3lF4YEQS/rRJbZoKRCIVUrgUaQqObV+3oOBD0M9zPGbRuFqVcg40BahBgydUK1T5QnTGaxgxmdZCNxBRMyIXWz1AU2uANlGYOCsrhlagMn1R0Mde58cfbpIw= 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:(13230022)(4636009)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199015)(186003)(6512007)(6666004)(107886003)(83380400001)(7416002)(52116002)(26005)(2906002)(5660300002)(6506007)(66556008)(41300700001)(8676002)(478600001)(966005)(8936002)(316002)(4326008)(66476007)(66946007)(6486002)(10290500003)(82950400001)(36756003)(86362001)(2616005)(7406005)(82960400001)(38100700002)(38350700002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vwstw3tFllf2Mv0HgkWocbnMIr2f4WoajhctaD6Nvojx9iO63d39hQsB2ehQKovLAQoq52rleousK1yt/T+nkhQMCeGAOboaB4rB3pqaUqYBkxfgi0E57yFvN4djzjm1b2CbAo+D9eMhOH+v1NFb2uxntXTQPB3hl/2Gy9/3V+gTOdqgTpT4L+cM4Xz6F5o3Qtz9VrMp8xe6UunZ1yZ1oZb2DtNuDN5I5YJGdrs4vPOr8qsulfXQ7EjPL3MdsEoQ0YAYdx0zCOsmxnmQMNJd4Ogtg8a2j5MIfm8JLd8dh2ooZRI2R3Ch7EJookrU7gr+6rIaF02k0RByNXV6WmaHrZpXEG48ZlD99LtQtjqmgPQ6N4iD2kPrHz3eqvjMSVFZhmJyw1zyRbDErbKaqqgtRk0urggx1SVC8B1NKX1xOS+z8UxU/9IRnxP8aajEUfIBEDtIHcQ+0GimJ86wkU/jlj+CU4g9uv4hX+s0h2qacwT2/V/f0MDDzgAwvvm+cVTHzWu9hcmJrmZDF5zFwTkJjIVUpNz0QiIIzqmowNfNRh+4qEWWmFREgGXIDG1hHfDIeOvQTZ5n0KcUXRoC8X8nrzCc22mFSDDdqMAPkiUFVVhCC4Dcgcn6wGClarZRq5Nk6m+yx7VQ/zFHthIcxenmxWC2niGlUbChrQtjMTr6Qs+hEZg3+/vJBKg9c5kFfwqifPKP2peTDQu7bPJzMxK6+90O1QZuab4PRMY5NpNsnAkThbuCGuo9opoPi9h7PIEuPW9i08Zq/cWkqoji79wKEDLSRq1l6iBRE3UiMRbHVVVB321L8uyqS+t9BVAN83PUIV2LS2MoV4rs2Hu4EKWWffL7cgykNKmNAHClTcof2NFIGn+DK5dJ5JP8DAnMn7/01ZQ5gqQAp67vVaNhsTBVp2u079Y+238YhreG+0qDBJWptxqCAdYPN1jDllVMRX1HWOyvu9WIr9lqwCjirbahKCB7dOYtng5IXCYtZUSINHCqQ8PH9sJ7Gg0xUGsxQAZ0rRRhcFcE+OpXomzQWCB6z3t1mPzEgYWiv1Mtd05VF7YwdSywz9SKmYiJAnagOcAuBFhAzL/ij3FEo5jhIpuDd6luau7KanWNcAm1rsUjK0UXrhJZMvRPiMF8APQxfBA0i8jiswccBfQ2thPrc2TRl9gCSem99iLHQ4dH95mnKWIU1YJxdZqKH7fo6+0CxCzzQ1gy0PuNGVeOfO3gNP6y7ictcO46ugd2VxyiwwSmCxCuzozD91/o+fYhK6WKhRjUs5rmIUfX2g/miau/dUDQoJatiPZtRcfa+qdcjkD4avuRRfzHQbeG8gp19W3gz+LER2YqNbpQMYLVi3xaOl3ZzhVuOKoNFctS7UVEmqLaeTpmfXqIiHHCgNwf2kVxOIlxgk1bl0zWrw1HHxvAtTGxCAvkIRlvdKLblp/k3J19EH8gnl8WRV5P7E0LjCr/XtJZIOBYMVOlwcpzih9ARldZXZFTtGtROjrkMyMmNSmpdAqrF7CLR/4eC2LdQ7y4VKbP7czrqn9MvGWhcml+e8w1tZbbI8ZK1VpAlzxpRs5YVN902YpaWIhp0RqQZf9BYLny X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62a96bf9-646e-4679-577f-08dab2c4bd44 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 17:58:48.7240 (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: Vm4QhGEEamMt09opXmUgztRVTfY3bvrnqnEKwx/aCbBg4zKfbwDOArVJ9+E3uuXw0Ax8AHL+kAHhJ9IhoIjJkQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For PCI pass-thru devices in a Confidential VM, Hyper-V requires that PCI config space be accessed via hypercalls. In normal VMs, config space accesses are trapped to the Hyper-V host and emulated. But in a confidential VM, the host can't access guest memory to decode the instruction for emulation, so an explicit hypercall must be used. Update the PCI config space access functions to use the hypercalls when such use is indicated by Hyper-V flags. Also, set the flag to allow the Hyper-V PCI driver to be loaded and used in a Confidential VM (a.k.a., "Isolation VM"). The driver has previously been hardened against a malicious Hyper-V host[1]. [1] https://lore.kernel.org/all/20220511223207.3386-2-parri.andrea@gmail.com/ Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley Reviewed-by: Boqun Feng --- drivers/hv/channel_mgmt.c | 2 +- drivers/pci/controller/pci-hyperv.c | 153 +++++++++++++++++++++--------------- 2 files changed, 92 insertions(+), 63 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 5b12040..c0f9ac2 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 02ebf3e..9873296 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; @@ -1134,8 +1135,9 @@ static void hv_pci_write_mmio(phys_addr_t gpa, int size, u32 val) static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, int size, u32 *val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + 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. @@ -1163,56 +1165,74 @@ 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(hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(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(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, + dev_err(&hbus->hdev->device, "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; + 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(hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(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; } @@ -1227,38 +1247,45 @@ 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; + 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(hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_write_mmio(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(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, + dev_err(&hbus->hdev->device, "Attempt to write beyond a function's config space.\n"); } } @@ -3568,6 +3595,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 @@ -3577,6 +3605,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;