From patchwork Fri Nov 11 06:21:30 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: 13039719 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 F09BDC47088 for ; Fri, 11 Nov 2022 06:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232846AbiKKGWa (ORCPT ); Fri, 11 Nov 2022 01:22:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232796AbiKKGWY (ORCPT ); Fri, 11 Nov 2022 01:22:24 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022018.outbound.protection.outlook.com [52.101.53.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A353663F7; Thu, 10 Nov 2022 22:22:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dyd+tNPoq+DsxYcFVp5ChX4QzWVDolygZioLO6CXDK2dYbMz+8yQUA4yGx9gCWfw+0xGLaAoMswyANPP/IEZ27VuIAYKL03WUxvVUoCklDrqSpyDLKCCbO/hO2NdiYONdtH8LqotzfFHxHr4pSwP9mQoR2YKjC2yL3j7U3InVJ/GaOiYhj7VVVOiD3OjfnEvFwZqZWOh/4izx5gEjeSRHlFcSgczBzJEe8A8ttR/movJlSrh787oZFqQrGS4DHKLn1wyivEteYQaDMuRB2qJKvmDQZorPHqZgE3kR62SC5SuUV3ElEh2o50SBxu+tdaJZhtWHrNMDs9MLiIHG6VepQ== 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=EUCyzmkL9E0xfHGyVi0or0/DEkE8oYk71P05Ucrudhc0Q+9TEV74UCYg3Z+0uBuoHTQH5AE1wktj/UDh1BYuGaCr4N6YwYMWyn519wgWifvBcJLtePC4EEFQAMGZd37NcaxFvFVsEX2CmjjjvV4/9+0cpKyBaE04zRig1bx9jx7e4AsmgWCQ9MA448+JxBpxQ0yos9MfL/cK8pkxjshAXrd8ftb0DpYxEuDbqbjCcbTBkuWOABOEhNbIpNaBTeBUlLAwSaC81YX/LT7suP4ajlPH14CK9FiPtYyu7ug6oQtaWyloYNwRX0s5Gpjsaeuey3Lo+r6sqo1oWNE0pBmyHw== 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=WJOFgTUjULQoGtmlR+eX3trNyQrZcAhvxAHkfWqwJLrnOoPE91eFL+qWJ2biQQjC8VuPVqqsaFrFOMcOAszvwH04RkzfB8NAFzrAbA8w2QiPsZrczIWpm4G22oKDHUAeVkBg9uhnLHIfVsQQl7MgySuP7alzff46jN8ALRyTYDo= 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.5834.2; Fri, 11 Nov 2022 06:22:11 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:11 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 01/12] x86/ioremap: Fix page aligned size calculation in __ioremap_caller() Date: Thu, 10 Nov 2022 22:21:30 -0800 Message-Id: <1668147701-4583-2-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: a8a19a48-a701-49c6-8330-08dac3ad114e 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: O942vygdyu6sGmiqdX4F83fJs4RaAhEShbt53qNcCJsXTz3OFg2fPnbVX5TiDnY3m0u9BafDH0T6hQocu45Q2B/HZOoqIGDrGsErYrP30abMnxoyh/zkuOm36fkglhLz0iR6B4M+PJsZ7Ah2Kl24sG1KE+beeW4LQg1IRktiIAPeypNPAhYrlnP22HGr9Hi4PM0JeEsIADtv+OvqEIuLVbAx64m4BY8VcC4PKBIsIgOZyy50+d/CD3ZMADsuKSYgLsjpLpl5hY5P255xx+wsPBzCIyMyQ7QweSSKFvCnITRnI/9viRYrYfDdUNXK95BQmeGzV3Q3c7dwSjbdn6gZMsbThGb1FE+ZDHyOu1zPPqweTCEZ0qUMY23850m+wWpIVfWMOpK+yIYnE/l2C9pJjhz/4cjM90PmFPmS1Lm1An7m9zH3n1eBfPV1FHueMopo2bgE4XiRrpTAXDfIACGlIscBE9rMbf42Lb71kw+l7xJoalmqLuuXXCVUQl9IOQkwm2f/H1zQceys6pSrL91PVhY7OILygrwcfQxKnPFLf0no2pUA8K5tJQUhgCdvWLIWNLxzsKEhR6mDKoIgzxuj6tON4GRNX3iWnbrEdc4dCGsoowpLwFduEknDc6+l7MpyL08muAv0g8Z806J8ekieRwbml2CoKr5My6/WBkdKF71YWzuMJnCCh/IW3Kh5UxWrnOWcsOe4/RcjrHxQltUO43QLaU4b1FqrlBCei6leAj5WwNv/lbQSKbI3lU6zpE616EyzJa7tErLyzF6mSstSnS/HdeGvqxe5E6qARICmb/QljounYUY0Ev8Ln3hPLliLltj3vHTp87G3VV1QEHB/gg== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(4744005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z4apJ6YhEdSmsnSzYynciuGRev2zgVUIRyNkWEQ9ftfc+t2mqNmuJn7bejzpAQc+wOB1zOHgzOBl6ebOh2DvSkVW77Tz8fD92SfH4pxEDK0X/vMN/ntqGKOVlgMUtGVQUCNg7TEnIFV+ptg9xppcRYIj6BOzWm48qzyjxmiyZRHbDymYmEP1+Qh5sIoV2upL+Fa4TMog82lJEsKHv1cGQ3aE8w8rqzz+1VXUwzvBJwEEWSLpZFrNGqnpQuQuKDpvzvkwsXWeIUI+4GmJwo4tONGsS0KEd4QbfOhuYG0tblEtOI1CbByTtgmmCF9pHpms3lFzqsq6RnvY6WGVU8CytJR+aJy3qlDFU/JBPxIxIkcziefodgHsmz+gQh+CF2O2ynz1AB2EUd5lgMuo+oP4zlNSpH1+USP3CAjE0CjHHpMty2lRS9LAQSke9feAGBlLHakRVK5KVeUOOJwMb5ZVR8pXSfsDngnxBS9F3IGi7nk2Jt3EHb7N/nmlGxahcaxbZztPQvDk0eCU8LJCWwtrlRBjmKO4nOe18BEu2qTL1Nk1+/hSLnKxitX6otzbSq/icVstTtZebgqL5VHWzoEle2RMZavp+iPyUDkNDu7LAFL9QoWY8k65Idu2dr0sCMtH+1tbvc7VgIUD0+zcrlTdAssiQhQc+ZtXwdws3PKEb6VCLPqmVWg1CkmhW3zwLx/Nvs5agqfFTwCvBqHx3bN1B9dd0QlbK/pyWs7UUXd8t7eqeD9u/mW9+P6v//Y+kZ69iLb5moxh+RO4WRdGFTJgKFmLGCdwFbzlz2dzP1kSLbxYGiZL9cXrXYZC7J4zGiCQj7Tnqk9HiBHAwqvdV/7WPO8sdjKz1MwJJ12RNMpo3IvordwCs0/8lPYXpoXiKqWd4pBPIolpi3GxE5f18hD4mwLfJPrMDkTKbLxVDCLM8u1qH+mIx3UqwvZbSdM7aCYPW4SX/ODU67brTa6FNMgM8fnBT779P2jtLXWu80vh5+AsccxEyjKpJ+AkpzIBpMSPJwDhn0AUfjsgvbUp20sbXOxR6Qfh4eadV1LxjcJEwMn7wWnAWCLab2tllAobQBe+aGy77GgnM2eusNDpVaBqR+3oXs3mYQ0t6SfEEYfNnBvTTim26l5BZT5g998luPRBSAaAW7mdhayNedhtucuvoQjsTx/HLISmFB7AQP8R4/X8fszRozRM9F1Fhlbi7y4udR71gq35MvzRavEkOTozQl3UB23bApwUq76rAnvh/Os0L+P3MbeQ2F1w5Be5+9uCmw9XlavBzQ23CgCvfZLPOEVusVvrSy9PXTsa5SnC50zgAtbVMSoGtW1gt2J/GtWZyjwCxZSlM2Qul6cAvU2QnaayEpgicLbRyLBnRe3FB3UD2DCo4peb/G8V7RCo7Em2CpS33TMu2IIUd/CdQADYLiMR9uE3o4U10QSIZgJMyRHQ+wQJXo0aGhYU+neFvC9X1yQbTUmZ1n2xWsmk1I3/xs5/9UoObzFsFE+WFkOe2TGyUGAKr4+jjHtsdTD3yWAhVzdfiTlfo8Lk41+6me+SaTNXhvSR+tHHhqVA2v5HhsnVY8DxeZd0AqytV6y87yuX5Wy38ctbGxaHzAyah9MFSg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8a19a48-a701-49c6-8330-08dac3ad114e X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:11.5962 (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: c2ylF2QBcPbdSugSRfyLTUi0wX4/iJuZAMpOy54HALKhmqvdVAnb00b+OJpkVTV0UYrbK8t+LwK3kqq+5ep4HA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 Fri Nov 11 06:21:31 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: 13039717 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 62CB5C43217 for ; Fri, 11 Nov 2022 06:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232815AbiKKGW3 (ORCPT ); Fri, 11 Nov 2022 01:22:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232784AbiKKGW0 (ORCPT ); Fri, 11 Nov 2022 01:22:26 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022018.outbound.protection.outlook.com [52.101.53.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F8E663FB; Thu, 10 Nov 2022 22:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RMcBWMbKBOl0gTR43MuD/6CkRQDi9YQYWASKE8jQWJJ9TR1l6rQ0rLuoaD9BgnnLqWlK0im22P8OHa7Ua8xjD85Np0WoZexi/s16YVjL+jOi2M8K2LvFH1IsZqKUmkrkpXWXSEwS3GYBuKIFVpiYZA+CbRScibHGihfE4wMYJe6OyBro5qIPAN5r5E7JpQYI1FLt8jWMOwTkHbbRVUNxBbhj3o+gEcAjS0KvinzoOIyP91cn1IxNf1saXhLo6cdo+u5OugL7riRxr8bCOrdyqkPxRB7KJZ6rhu5XwalKAyib0kpg0Ub3frAIjTEC5YU1X4e2gKZwcnHQJ7K90IVDHg== 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=8OcaeMt/u9wYn2yxcRzom+6u54BPUvchqecBRIxcVm4=; b=PjJVYA5y+dEffQ9Zz8cXxCQmIRWZJbFmp+N2llI1a1KKic22eKZYI6+R5wbYQQe+ixPP0QzUN8258KAgWgBms+DggZUzOaK9a2+D81aJk5myM+t3e53VTtex3QcvxSAwBC1G9rm1YXspDwQUc2WeVzxJi7DQZyO9bxeKBL7xgIg/aYlChlnKnQcH2r1fkutZIxYa8vtDUpnOm6y2iZNIl+cybwGsiaR6lUvOixEPl0vYS72J6FRA3zfH7we590Q2iscm7WQbqYV0UMRrvm8repd/CZuZALrOK9rcMFlrmCYBMD4nZKxT0p0EWWI7wuEfT2VAw8RPmJkf/iEQDknxXw== 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=8OcaeMt/u9wYn2yxcRzom+6u54BPUvchqecBRIxcVm4=; b=H7WU6C6Oh2TMZF+Qzk8SWcmzU2SvWb04XoKdjWxGRLdWESdao1Wvn8KlcRREFr7klyPHACatj0UiCb7m7N1RP6IH3OIM9q6Uk+ZJcKyeMwSPPRXUZ8ewop0z9BkOoLWIlcIABXm01BmxnDzxLw5lYjUv2V3iTrmt38GZd5E9K1c= 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.5834.2; Fri, 11 Nov 2022 06:22:14 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:14 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 02/12] x86/ioapic: Gate decrypted mapping on cc_platform_has() attribute Date: Thu, 10 Nov 2022 22:21:31 -0800 Message-Id: <1668147701-4583-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: e5f819b8-a68f-4569-c9ed-08dac3ad12c2 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: UJtq86ry/vEbYzqSqkbP2e7HDBlzZa7in6TGb6fzURJDIUdq6Fm5nA88Sw6GYiPgq8gyGzSixyHjk+pOCOLcoYH0nkvlHa+++SK2wplIVdoQ01BKl7ghphXoMEjh6RToVBTZ6a74X0lRsc4pcwvFZR2qFuMl2qQOjQ+iZ7cCp66KQ4tKAoeeCWfDWbTk89Glwk98jHSJxnx2t1X1hvNH2DHCdSYk0XpP5hiO5YEbNlfbIliDDiApEOWXtf1EK1862C3JMytMZTUuJmhQ6zDlQHwdl9YNDY+xoC+6OHKefSR2nJZYdrfc2OccFk+dCrrShYVAgNEX2f3iKKzG+bXIQDHROaDxQrMqEHMh+7Hnw77FSUFJ2SN4W+7vf9OrcKQ3MB+ijqpahrTSWMNKJwqOzNZNMpfRct1niEiZ4V0s99FmVM0EmDGlTRmLznPSdk2wtwsjgveXucKrAbiSAFxCijt7hMwvMoJi8tC0OqQte0vGzjB12IEZAzLfUNY6oRVhqQsMiFYNh3LdYiGmc5RXmbCUaist69XG/nrWC2kAMQ8gXuSMRxv+FbMz5ys0CXq4IFRs8y2HFvC9eS7g9pCwoAcGXHjukZanchKuGtjupIMLU5hTDM6bnE/wWPyDXwltWUlRkXpno8KIq4k9+sdFpiljOk5vTo5iO1LjNpzyOS9lwlqko1HkmwZR7Um8SGIpvBcgUF7vZ/jueAsHRRhCEPE2jiT8y2yw0KnY264JeGhoFWAqkcK95wFD5Sa3QVkfg343BYNIFeGZROCStcbhPN4ECTfD9BVjbzRZ9yq0BuLmIVDpPDzKnQty9Py33suw5Na7QqD24YwbaTOuFvcBxg== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Nh+v0WkPJj4vMR/VScDAW9JXeXPIMtWP1pYrcNyZFp7CV7u36TDTIG5tnPIyiVKUXE4pdqi/9ILRA9+VKhFZGEoH4BKCamiQALiquY0p2l/tVUqrOau+m8jyDa8eQ+nvI5tmgkWyEuHNsEUsGmVF7MLNqy6Sv7yO4MNA0TGKYmw8li4MnJ/fjobF9pJOvFviVYvHDy8/p7iBf0yGmzZJ3usTESFROfljubW0WoZtpYB0tYqA3bMeb4kUvmwSQU/gRv+kpI0hJx3yQ86FCzjReeem+ATcfjk0ydfAVRWacPGSMiktzGmKfWY9roSy6LDN560xKzvgZvC78uG0itvIsKYhQoSkquflpozWy5jgWleUb+je9uwUaN6pB4+Z42HtOO/U3d5XzI6/Qq/e3MGGiHz2IhNTw44cqSUlUHDXjU0SRTfJ0Cm4YEx3CsL0sF9gjfUfi4lc7ZhgTR6DlI7cF23WyIq220HFwvc9mQWaJU3OOz+Y6W8HUfDeGcW/dZaj01fjQstxo/xdDzlv1VbqYjgwKTla6HVbOTAH/zsBnV0D9qDkNoQ3oCRUgIKu5sMkKN0eruVBgAso6lNNEXbQd000UFz1K2U1yRySJDt3ybaZUvqDlugGY/tORrf2X3U8wALrGS5zY0PF5nRQwToJ5awv+dj7uAz2bE4KBmJB+la96ANtByaisu8DW+Esj0fIgbl6EERWp6MK4tf6MI/dafsdWji5X+BT6ZHrIT3DC7ZNyUpGVHw3528utEzElSp1kxW9ExDyfr1EjBamFMWVZyDkCzjN5ny0qNUha19qbum3d9jYOf8lyoQzVn1vyWRsAaXDdhvVBEbVPkDGAFYDoD45Fin29sF/mXMtbukVKng49YQjN80sfGgwGn4uXYGox+F7q6cDL3PLcez2jQ2KarSXBZxV5Nf9al6ayA9QN/YyFt/r9sQTX1ENaFpyPPL7k6Nvesi5eUM0ljqV4678trWygIuO7H2jdetKpr/cbUGqQeHZseZQPLcRUl3Eg9eMNNoDNoNcJ8xjaTPeYVfocEjDvno3rEIrIaBJjRJWjxzP+7jytHAZh2WKwKQDGvubsk01qLY3I6+8zikLrMCa771A9YkljjFXEFJ08b8el9RL60cIiCAUeTJZ4mRRvnbo1L8hCt1SaiIyhb3Xj+YR0Sa6B9vW0/Ngqad6mjjS1Rz4zlOr+efI5YshrbPhXrE0UGHP+l83KZhAZhJQsgA1XMZ4Jv+EYkbgpZBp1BKO9I242LQXF6mNzIZdO6meN9CkYvv4JLrF1+alMqDI3PUEn9C9WEqIz9atELNbWIfrTap2kuZ0FOkZ/SawmFXymPDyzvT7MCRuKfnYN8KA2vwc4Ogj+XBSa4op4xzDHFObhr8umwqlVsYlES+b7xk8IQO4Qzxf1lI4Vs1CZ51S2uk3feGVXss7XXpgQ5olYfsmiGs78ccsuxgS83tX1XCOjwA7yAgbwMWjpVc6wwaOqABk//JWV7sjPn863w/lhjGTg1194OpF/xDHHstuMTt9yaZLxKYixwXS5gwoLQoxfhmNdHk9+6XWwTk/rL/S/WI1dKQ4V4CILoDel4RF7Fehi/EgHMiY8OjrzeU/dFbHg/4M9g== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5f819b8-a68f-4569-c9ed-08dac3ad12c2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:13.9891 (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: F5ZGfvO9AJ0eB4++BJ9L+a7Sy6FwfIh8OXjs2EuR5V19H9l/us+D+xzPH7+fIHTlnWw7ZvneK41cW+8SJriudg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 Fri Nov 11 06:21:32 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: 13039720 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 DF96FC43217 for ; Fri, 11 Nov 2022 06:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232080AbiKKGWc (ORCPT ); Fri, 11 Nov 2022 01:22:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232809AbiKKGW2 (ORCPT ); Fri, 11 Nov 2022 01:22:28 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022026.outbound.protection.outlook.com [52.101.53.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5A565E56; Thu, 10 Nov 2022 22:22:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jXMXHN8pcs730U166+emPYKoaS9NOnvOxYMX6EmwTBoN3ksTgRq2nJCNZTM6dITp9rtSAbIOETj2rRBrfuNJ8omUPxWWiTZ0LYAYFkYwS9jCMBSs/YCqVNYmLmBnGRgQcx2u6JpQ357xNaeFfsjbPeJL9jGJSITLnxvC2oYDdaZjKqyeNq5aaq/j4vubi3HUzZbiN2bacKtf9eL5UwfpbwIirEc+kMqij1ZtBtDmuR6NYI75kKcCJcVc+BAPzFZ59bsT8cGj+Sc3DM9dkryHe0cMsaL6cPiP3QBpfoC9XXHBxq1QFXdugWu89b1PSsti1PKoSnsrafhNqz62Fa1tmA== 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=My+3F4xeoCZ4C3uLqj81e5Dg1XL4CiWYfO/yE8xDujE=; b=fqQUiQMsOvLPWh8q4yN2s9lsiWnQcTVQxUHYobAy2wWqKli8wKhpDmgxu24ZCqZU+NyjCNj4p1GEAaNCuxzptgp3VW7kuADZ/Wl8FzbAsSFiacJlpF2mkAVa13R49vnzAhA3ve/t6NtEtCOupCzjkj92M98m20QsAssUw1jjmUC8bSBPFDsQWBWrrfjxJPOpZTyg/cDOl7WL5XX32Vod8hqHdl1muNsm6vO9CaT/JtN5NcKxw+XYQTR6zizBdau/4RF4CCs+fAcGkUWF3N8dyvlds20cBxtUvJopIPW4/qoKFM/4QAhT+WXv2BmQTayJoddcCtGda9z5mTPYMURW3g== 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=My+3F4xeoCZ4C3uLqj81e5Dg1XL4CiWYfO/yE8xDujE=; b=XRhaIDFimPBI1yWp/4pfDVDXc/wSzQZX2g7QpMrnu3dX+Te4Qc8NDUroCy2fUgBA5sqSvnx5+aoYdD2Tz0l5DhRQs/XABBflQ1IThl0NLygw8dXOlftpqFxhtqjuYIUjFe87kOJ7hPc7SWe+i/kseBPn2OgGmUdJgtCmvsS7+uY= 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.5834.2; Fri, 11 Nov 2022 06:22:16 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:16 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 03/12] x86/hyperv: Reorder code in prep for subsequent patch Date: Thu, 10 Nov 2022 22:21:32 -0800 Message-Id: <1668147701-4583-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: e26b72df-ecc6-48e9-8ee8-08dac3ad142f 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: kjb9tGC1C3wU40pP8KOe8p1wJnlsJNnKGCmgfDvvWguVTqlxkSAZ2LF/B78VYBLuibXfnN6AwckynYWXKhbxbZuZ1futgn0/SaelO6a+ByiCuB6n04Xm7ZU7OFgsQWoLA0499ZsKXtCL3rbCVDxuhNm0AVmFgEL5I+LdoANfzBVYHdbQbN8T1uRA6BGOQ6bGPiUzH8GSZa9u5PA0OeeSjTzRZJSezeAejxu2iPpbxWGFpXH46fcw+Z//WQb2YGWeNejN89I7Fe9jJXry3ub2modwIZ9RR2RfTS56XxGTSOJtv1DpQzur7/aXbvyXJhPk78J2yfcmpxhtheHTp6/2rvMLXEXuRxf9GZ5RSO5IO4vWpwOXWhcSawRM7pV9VTv0RgKpv+He1TvpUR27O6pWJxLtyoUvLFUO5QNtnQVdAXcAEdkDazPoKGQ9PpY2OKjAYaZmN+7Kq87k5auocQuN8ZDblC7aOERYl8mRq8QRiVjyVTO5PVcX54f0Ss++ntKh6z80l0W57u/xbNCTA622/OoSRzV+2NVhu6Rxa3+uq97IUQotEIzO2d6TDQL9OR0B1zgZsC6GlauNU4cWeUZHxA8BlO+4tUBmNHU3zrggPn8qe5LD5YiZbNnTXZQH5PmxFl9sH5Y+djUsfEVVXAa41TAKo+HVNy5ATWxOqDcehN9iehsoNYGcUQl2UXl8ZVC1FBuf5FUu68EZx1ZAxdiTsmdXNdol0Yc2pkeaJOO8rxRwC8/8oApw01FTL4IA5eLbyVRawnkCveCpBQH0Mf561UFw5upnsf3s9BDicAob9GN0/6wfgxVsHB1tzg3bGrM4dKHVKBUo109firlwv2ehgA== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HJtr3GSn9Gwv3XBW9/xl4DI4UlQXrdY0cl7xmDlS9G44f6zOvE534peyJW5LnW5q41cliqtZHHMb8plOG49MC8+8PVCl1Wnsj89/ANDNJfi6cVXPw7NMW0GUIhn7DzgOJBEjkBkchEHNoXrOj+iN1WyWhLHKDLDM+69L0CrXG/e45Y2BvIiIfVuVmAxnWNcEXY3iqRogLJziLQAC95sjqy+2x0+eKTrUhm7/K8J3EhW+AGpXAncQ6McZjoht3EBE3gHWJ8MzmMay1bwqu/8U4I7pUnE6CkLkkkVgdCrPu59ulNqRiS9ZucWFNU7cKew5GggkBkOfvw6TY3+BWiGTyz+CQcmlePFh1gVDVafb2HchKzp0rK17PxOk5j2SBVKdwShWHll9XxWj/aQLn/tPlCKhaq4a75+RZvXXLQ764o+NgOfddXExMSakgRwi1ZVuEleiGJFlGVJFcl9iQqozGIsLmAPcBHg2gzfC3/Xt5ixndt51zMTNYtEbSwTk9HerBxUtiARSL8GRFeInqReAZl69HCddPlfSYMz97qQcpITQFRXqWHZS2tEXEBLYhpXR2S6Jub8X5FxDKL9RtbABC8vio3+T9o9B1FR/jIWXYD4Wdv7dd27lQUjx65GmrPkZRsImfp5v0XsQtHbuOQCmhuCFhy47v5RpEoHDpNvDMkyBLw4W8CL1Jl98M3NDC9Hg3KgHjm+6m6jSfeVyUmRW2WdH0w+GRk/mkwHE7pIhtcD1ETPvItTzY2vO8vmrJ5lS+ZqgnrsWVUlWAr+tOZqafejHri35Hm5I1qNQ41A6qPcqluwwovZqw2U8XlqINHoSzdcpZVwsuuJnMVSHTleA3xjcKuACAQYhKeV4JuRlzfpiTd2xVMv2BkLnRPKZZpc8D317RSKC+PG3UA/H+3LCxsnxJ/BWRz7/ZsTtZyGjDsJF6Fh1tHTScDeJWVKPD8VfU6qgnqtmdD740uJvC9jmTcHEStOe5961m+IzOmQxEI6wkqlMqQOVCeF+2Ej6RytI3czkQDMqmjEtzUBVtA7ScM1l63IUZFUy+JhAu+BcEE6B4PA50OTWAU34KPrfS7bjE7UPaZlsPubO+THVCEcpIEJjLsiQip7jYLzzMCHywpoy5ZyB4fQ9MrWd+8GgP2Hx3e6ghF9KCa3KcIe1CUn9HodOwZzaAAjFyY5BlvsqrifsIeeHwSwsHlsS7yEiRx7/yjHbJyx6aUsLkAg1D9WtfCqYADgZs+cE54OzlkeDi55iD04hSoIWsEdZHHUc2hm2/fAus6OfaHfBeHf7/NRR2qOpOeH/CdvhE4DK1yWZ2hHKWGtY6Vyh8VU/MBSFwHta6a8xLS8f7xXVMs/ErtZnnv4No5GCcDkdP8kQlmk+OZYbQvNnn7WgO22tlXppioGJHLax63wm7x0IO5k/Gh0di5YSZqQBKAwQ2we37xDH3CF0OcxhSucqe67KdOH5MaAq2M6vrndLJdTeDl4m0ZwCGFAk4a3/XqiizoFYq8aNYyxY9zCSOn/AhwFMiWLbN04Y/A/LyrixCrAx/oDztlQ6hBJpRm13fTErudMVCUjXVXZY5q7i379iTdA0Aqf97aEHVSvcCqJzohWVNTJ4p1g1sw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e26b72df-ecc6-48e9-8ee8-08dac3ad142f X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:16.3953 (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: y159C0QRE0uTL2z1KZubA2FqGg6gOBjQBNDazA7pR1D3+TnZw/+A0Lz8z4cTKe8ibLkMpJr20gPtdz5aDJsFRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 Fri Nov 11 06:21:33 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: 13039721 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 472AAC433FE for ; Fri, 11 Nov 2022 06:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232877AbiKKGWd (ORCPT ); Fri, 11 Nov 2022 01:22:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232729AbiKKGWa (ORCPT ); Fri, 11 Nov 2022 01:22:30 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022022.outbound.protection.outlook.com [52.101.53.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCF9A65E56; Thu, 10 Nov 2022 22:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GVcGn8cyaQGiWKjphjLfA7sl4O/5mulT/YMgxdCm/eUu4ALoXUgNo3mYN6BDYrfQaII5kKKgXs1paqf125mtqlIDb8y49u5fSK6dsF/G4BqmccTZ0Mj2UDo2NXk1LFcw6ossMC7rqSv5yLBZUOtQ6JH0CcGX+XndTV0qKXE+rldC5mB7q9LdUJu8auYssaAlXnA+6vEKHR8vxY/ocl3ns6CuQSEpOL+xSBNK1aaTQV40iJbBsSwIRctNCohXpN2T8A4g124CI0kCceqB0mDD+fdM14tEQCT58k6DNSIxRNDK4eBSUDi1ETF7u7P67x2DD7f6qk5HoXS2kBmnSyjelg== 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=a+yUY1oU7EZvlInJkWwCVnIM5lY35B5anu5GgTI054E=; b=L/naLONsWajIBztUnkDr8tz8+Cenel5dH4uNatIzih32Jy3Gsui1br1YLWkWO7YrEGbLoNeKSjt7oRnafdYEDduH6ZHatmo41qDGCERFaVIJS5WZ4/UIkNqPcIAiL6pKmhr36gvBXEyUnFg4CVDLYwajdF31aAZKkBLUdlkFOebGSwlE1E8y0Bhc4VMOi9qbIh9o1E+clOh8qPtgNYKqjysdguf1Owdqy/vd6LJKm1DcXzx78Mlr0R42+pWgz/I8AovDt5GE5N3hxalmknZhsk5yQ4Zgt7yJf14I2A49eUbhx05mFVFWB3TXBkc+Hthv5nrt22LAKoi6mF6hOh1ghg== 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=a+yUY1oU7EZvlInJkWwCVnIM5lY35B5anu5GgTI054E=; b=E0gtpm1EhC7ibUs3psSkDfoZSmKAQrvqUD6TK7/6JKfclIs4fhwyeHzuf6Maosi6c1GE4mRMUZ2x1cbkzSGsROSG+7z50cjt7X0eTlGFmu5i83Ms1MAhFGYqxDQ2/cMa06IKHqtxOb5NcFu99PNsZvuFbGLMwVsJE1DbzsyX90k= 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.5834.2; Fri, 11 Nov 2022 06:22:18 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:18 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 04/12] Drivers: hv: Explicitly request decrypted in vmap_pfn() calls Date: Thu, 10 Nov 2022 22:21:33 -0800 Message-Id: <1668147701-4583-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: b20950c9-8e52-4d58-e334-08dac3ad159e 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: K3P1qiXVjXqAKBRnzvRQEVcWO0E0fIj+6/OuuUAoc5sof06HL9CMTMoGVz214Zj1JyEdKqTwImvZUpRS0bKOL3SQybvtTXUXPKiOO6GpDlbbz4OSsn7wl3a6UmxM7Pv6m1IAnY70/5+xMjN0pugXaHSRQherdA75jwIt5juDloR+PLdkrchNLrbZuBPQkqD80f5MZ/kFEHgQWn7xaHeHmodRvi6AuDXDu1+nrV/OezGJ0TXl/Gx5kqvlS8QzpP4H5JszlOqs06MFtrkLwf2E9vxAPf4TfpiZkgGqM2bxoAmybDDMokraRK0kJWzbmEe81wSFTvzRya+cE28ZAxDFEwGGnR2cngFekxuhuIr7mnBNUCc6DKrZTku4CIlICWvkPicW2+KkFUDuB9i1HZKKZHomqZjHHQz0nADfMvI5NMEmnT5AM6Tv87SHBtU4eJsQqpsbXW9PeqZelqmVMd0XJvTEhnSfVZIa9Z0W2F52LEZrhIX7AIrafitaLAcdlraOd51vnz0fjNFvdleWwaISX8HETmdju1Thdmy7a/oysBULym6xSSNKsMCA8hJ8KU2wKyXW4f78pnmL13kwu8vAAe7bRfHSpMieyuij9uSEtPcvyEAO5E2UCuhPo49tX9AbQMJ/wrm8Ill+Galb+ItIW2EkolLj1pbvaz3qc4Eg9HrVJ2E4Qg0jmX9t3nNvHcuf6XTxN3KIbi4jEnIuCCLjT28HlVt0D1c3Clthp3RVAJDCaRmjEd8dCVRx+t2V3ugZUAplyXPajs/dX8XWo2tNMRr8iW5VN1FJdrEIcUkarrFnDDJ6SjpPLxxhDDYSs607Dwn7oDOXIqhVOBbx94L/8g== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gSMAxW0hTsiGVmbKBekmBDEz/vKFo/lo4scH4AstgErLImAG0WsIPjSM7NDIAvBezhP1jCrnPH9Ch7mPdPvsyWKHxXUsG2fIPJw7ML5OAcq9tIl1h2F4PC2tWgKh/0wqOqmxzC40kkjIfoqdWfzRWDdG4f5z4i1AC9XFYAGP8rLN0/0u7Lg/YM5HtoqytZzkIiUP4eYb2iIES099w0+d5UQnPHTNb6K4XP5ZJr40gjtpESN8pbdU3CuyrtiC1jlbBmoTVNwPFHaXyOgKrP2nDpm/j3f5ITJe/wUTnmNDWbGyHP47lWUjPv/3xyfS+qY5U9uD877yotI0nf0gFm5kqVTrULZ4Ft+vGR7FToKzqlxa1jH+SruFx1RxL9znGhPfm6d7FajBjr2qVKv44c41StVeLFWt4rExm2zG6tjBwgq5iNOkhNNig9leo/JED4vpUP9VHp6i1Z6aCQTUgYozVW6stHRkUCFiWe0JQPErMtJMvyFjmz2QWf6sztc09FcuXZ56ojIJwVUQxGklK2UhXokiZ6V5lWcpejY+GduSaOyAb8En+y4sNPPeOzsld3kPJ+ELendp6M5cmy33nCOndBSCioTDHgEHlX28hiJIv+2Ebn0MgrYj9MoxbqCXptuAGWdGPwbOvXGcdBLwPeeEFjz/siuz1g9TW/46aWcAaKwaX/D+KNWbAnaAhXrYqz4RbIEDKEDDnC8zozOcAJyf6CKA2azOWxoGxyrqFo02dUgKW50LTBILPdu8lbMq8DK2qxvKwyok6TypQ0ul1IDeltSJcxMeOipnaAacyTc4D9JSeZD8mRnKLnfbz3F+7rPImvbfBU1WPg/hG+7OWGeE8dsZW/PGcr7Q/0RUEbj/g36HbWi+p7M+c6QSx9UonNpt5amfm126glyjsaYC0+L9020b8q2mG3+1NY0cnO2R5/ksv0HapUCP3vknrBbKsZ54HieW4wFwNEUXCiSQG9MtwQltiMh5wFOVqThKHoZe5YngFqlAL+NBtz4qVej+6HbfsB3ZhloB6DWL6iz7RvybTi4Z8e2SkwvMb4j5CDtStdqud60JP61Ncn/OEfkZpK0CQB3lwuDgbkaFeTY99vbBzTbHq9SQDSW79fSCDcJ2UpluGrsAHbMSTjRrZ2xGZbk7i6YUww1AqlKgXIV4lsQ3KYmmscsxa6h04t5oR0268d/JoRbOEax3U15c44cx+V4K3B+0FPD3DnhgV5uvke+/IujCJDim0RXJFZ5TUzIRUiShl0teeVR5P85CXKN6zaHMwB3ibD651YXyZI+gfKv1+nlVs4e6e3cP/YO8XmPFqQ41BTGPNM2Epg2BjogcNh0HjhcY28xPIv01ALaSyD9/WQSGIGh+l+cwDLCx1COAIwf6x1MqlaECKETg+7bpWq5IOWbHeGIZlyRyi84CejTa9aSsoQqWqvt5c3qe7N53w1xwcLW/+Eo1N8qE1JQspRVypPHp/ekbyRTJ3yrF7V5tGJfWoiti6Acwj+OcntSKSVaz7Ag+IoqUyVaAjHajubwe0qcfmcjyYTYm1hSH/o2c8aKY9EVKcm9fd5SLGG2ogeZgFGH7LrW9eNuVS4HkTVNCEg536U+Vwemv0TidpH1OdQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b20950c9-8e52-4d58-e334-08dac3ad159e X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:18.7870 (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: CturQpzSe/Is6w6zyRsmLjJnndvA80h2yeQySKBdgEfgIC71pfAt4KQ0sUOZETQx+tQuw73NBqXF6M81N9QZXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 Fri Nov 11 06:21:34 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: 13039722 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 843A9C3A5A7 for ; Fri, 11 Nov 2022 06:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232594AbiKKGWf (ORCPT ); Fri, 11 Nov 2022 01:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232855AbiKKGWd (ORCPT ); Fri, 11 Nov 2022 01:22:33 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DE34663C0; Thu, 10 Nov 2022 22:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QusDCotf6EQWFgHIQ6t1Cdc46/aVgN0qrS/ZZ3FHoHIkZCW4Wz6PMbP3Qq+QoiRNgGE7lQmpg4Qosha7N9YRIW63A2+uzzfYcZD5TLWoQETJqh0rUl6pAsj/SF1t8hSEvilAXa7XdnB9OpA7RXhXQ2Rrz0/e5rNp/c1cPLW9zFAM3PCJcqiUW/aybKBVKWYeM4hQB4nOLh3PCv2N5t1IquU3lSGEuUJgY7sIog+PqTfHeNig5orFFT1Shvto8Xvs+TQH9uEZEWenSPBwIgDZxsvFDgF+7RxFN2iW7LLZDvG7Tg2ucQtKO4CZQ1yLIvp/d6coKPoFGFL5p4x2b4YHnA== 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=FT6d4qwlnktmpmC/x/vNnKUNdEG3IaM/xrJmCwikmAA=; b=FxBA4KyEtS7oYu5cg9xsVwjY+GrznMicxiHWX0sjUGdRZJdFPRDyrXIVCBwxLeP3lNEv87GkMnXfwdjWDLErVRi+s4q5keBMopG+MRlxy+1TDnU8/GAm+dgDW9b9PfVx3ssTfsjbqa938dV4HZ86e6e616mYxoucudvrHwK5umEKmeaIDdiLHs5fRyhx+pW9zgwTH0CtnNm37fViqL10h46N3P4+ylf4rI1jXyY6rLwMBtLeRc7Fh8rTNzVR6vJoj/nFXFBNx038+8lJSGvah8og25IEQP7CdwQ/7Mh9YfNU6dQ9GEds3vifvouiW0+YDCbeTB+2g9Sb1J9XNn7Zkg== 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=FT6d4qwlnktmpmC/x/vNnKUNdEG3IaM/xrJmCwikmAA=; b=MmT3ryqbA6QwZ0iKbxv+83VCZBXva++3VVNpeJHgB+SXdWyVSD4UhdJPmuhIZbbfnQ1JeySPN3805tTrTfpAdaFkRkb50UC2Ujn5JLGiojQhVRmexUZfdytl6A1GpvhtijbAbCFiHlsr3cUBF0brULTw0f0iKYhI34iE4Upbeew= 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.5834.2; Fri, 11 Nov 2022 06:22:21 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:21 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 05/12] x86/hyperv: Change vTOM handling to use standard coco mechanisms Date: Thu, 10 Nov 2022 22:21:34 -0800 Message-Id: <1668147701-4583-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: dedc8f1b-e683-4741-afe9-08dac3ad16e5 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: qv7o5k2t43t0QCCkmQzY41r23c9BV3TzhFtF9g6fh+B12NQULinkUsev9ob93ez1YL4hufxAINDXIuAhnetc+L/Hhc1U3/CB5CK13RLarZdYddEOAjkQhW9wGbNvmm0IPGS6jxjOIEHzy8LVMQ9iQ10TCYMRc7m9s+iBVJbmeSwTUUlr7UWRjdd1uuprIgqECreH2QmOoVF7GBBKXKCWEkvEe+Xps2wkGlFoLe0FxNnRAN2gI/Hg+7mdaCCbLWgdYPRdaM3/gMT+1a/Ci13N0IjjjP98gtz9M668rE7TB0EhzSZCWeDgjtorkvYj3S0bvuP2JDKSuzIOwivBlqCQCGq/jfIBSwdGqRj4yxIiD5o0aTDreRxeW9+THN4YoyDZQVy5f8z1nivjQ37qy0aNVclfOGN6z622GCFMUqDhWAX9j/m6SZfPKD2efqPrEG8sHMxRbsqBtwT4+y+V5k2NC8x/L1sZHdrIov8vhLtu9wMITVBuwj7AS6ByGNi6R9jTLcKgVcMj07iuaWOVDNGkfLNPNxyEbtJ+MKBAIzrHWtJOTrCt2sfQztsjMAYn+9qmpNu138djZWzGb8/bXYv+H1qiP2c6ieyCiiAR+r76N7J51ObF3p22YPagvtQZj57eLG763G0OwN+KxDBHAghMOPR7Il7Zf5wQEsd3dGHadEC51XYhsU3Q6lwJtcUURg/XJoQhT50BwO8qlpbEyijt+nTnDzBD47cxPqaX4h3hnXCzezz6lUG3ArVeb67Vy6akQNG+MsdqXkXBqQ34yw8/u/yKX5MY8euExbAKlQVWzhj/7IeZQOedbkTNvcpyF1aoEv+yIAGVe1mvK/3IM2W2LepRmJCVtk3nuebUaAg92wf9LbXsXMEbt/6lkAiw7lVBDJxsY6mwGspm9K/R+lesCw== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(30864003)(10290500003)(6486002)(66946007)(66476007)(5660300002)(966005)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KdVa7u+jmJOHz7zMcOwviqiQ2kdYPBQBLgmAee4tipldfu+QMPGyVgLqyXvQTmGy+0fXBUqL4OZiktAUFTLXtgbO25vm/vwkXiah02u9knButPuucOu7WNjCmM8Aa8Pn1zRi/t3OaxB42OichmX5R8r333rqtNtF2scKXoXhUG7taDeyVTT22Xp7Kdcbd58zPpr9WpMVUmwDrDBJgaH79ySXMpka4P6UtjD23Bj7UJxx0ckwH3zVCc1po9eyY6Vp3saf135guJmZ+Tn0rkiQY6+ZYMyEHv8ajF9c9iOaVPgi+YJmROrRy4HChkeXHjhAn80ItEl29OSAKZYQRnFOSOp9qfi7nfnJWoWsxirwPUw2zSdtkR2xo70KLMJlpEyooEKTWgC9WrFD/PicpQ5AJ6SV/ppIN3tpnInB6ik4eLjkbZtz+eeKFZGtN8UOYJA9wBygOXCBpUza/giYQLFJovzw5FZPIEx3NqDBxpqGPYjnhVjE6SqTKXi2864GME+qAr8QZ7YOSdAuOklG1FSeRYRAUMctg0FAPNuP7LOPcXyR93n99awB9EqH/FFKtLv1hVC7z6M6ly1vIFZZQTYzW/+G4ml4oLdI4a3/rQhwRLqXuLOW55g2DxjI6IPVqZpzkSRcgzcRCCf1v3dqVmQvou9POvraXjj1DrcpiOGot8QiMRF6zusqdMXvcUqpk4PFSXMiDjopVCQyphsgR60tQnbm05Lh5c+bNCerbc9tHtRrLLk5KEfNJr6DL8yFJ3Q86BAfUVEFMijTWOHRymPOpJx1JjcUr0WCxZRi4S7GnaUPh5Qvpf21gOWAHLjurrD38CdhWmiD5fjLDMJ16vFE6DWnXrX9lVV6EbHk7eSSNYaSqh7qSmKf9HSB/YfJCmS+S8FGgA6IxhA/62e85KLwRcvMAnDABd+XEoRLvtWuinFVcp31TzuafREkpOrAHW5icmK+DcZUQo/CckVMxI6Rhw8SX0K+ldyUsSaZEboKhGZXYJ4wpQwsApdoWBr3gm20DCioqeTtmxhirbZFLt7c5xOG7uK9O6OH0HaBE2nLlUInUD2mCRKI17u3fKFsqwPcRoVJI0d/AbsRRXqT7OquM/7XNe0wyT8V+iFM5f+rZR95IRTF3Oi+EV0Gq8h1PDbBE/Zfsv0yLKGyFAnacSJQ7tzutQ14F/bBrzL/tVEGzNMj7fGCHfiDqJ2t7wf6nelO3yCXvzOteVwXCCrKlhMx31mJ/oPwYcpSGNJRK3puxH987S0t+MeeHBJD+QcrwKwySXRKEvi69TTYJ8FPqTrgL+O1nL0C9ZqSuHYx4r1199sLEs+hV81t2pi4+zmFheMgKAWcfXHzyjSEcEA0+bbv4RXnpXWXPbBzso6XZfJRSd3v9zMmSEGoBpbXPeI8FGo4bKvjug6vxmbpVMB2jGrK3xb7EUuC7RKjMBi6HLd31aBRL+ObivWkQkE1igy06wUBnZQOBo/7cxJZzWy0UjBBTlhMNu47rCdoBD0Iscbh1R358kz529pKstNbNbWZmY2uW6uGWEGK8YXKtHKpHcatfQGVZhw6/aq9LYb93lYZE7QLhfCD4jt8d2uH8+vMvUNCuE8wMT3QiSakbMMKGEsKkQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: dedc8f1b-e683-4741-afe9-08dac3ad16e5 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:20.9273 (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: +RK1DAnDnd8OSpf1dzZh9dIdA3P9jCg+1BSAa24eW44cSlYR0AFrxYCCgwIo4bWrVYXbMm2qJUDqUb1BUvdE6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Hyper-V guests on AMD SEV-SNP hardware have the option of using the "virtual Top Of Memory" (vTOM) feature specified by the SEV-SNP architecture. With vTOM, shared vs. private memory accesses are controlled by splitting the guest physical address space into two halves. vTOM is the dividing line where the uppermost bit of the physical address space is set; e.g., with 47 bits of guest physical address space, vTOM is 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 06eb8910..024fbf4 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2126,10 +2126,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 Fri Nov 11 06:21:35 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: 13039723 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 C6388C4167B for ; Fri, 11 Nov 2022 06:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbiKKGWk (ORCPT ); Fri, 11 Nov 2022 01:22:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbiKKGWe (ORCPT ); Fri, 11 Nov 2022 01:22:34 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 917E9725C4; Thu, 10 Nov 2022 22:22:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LUnsIXiYZLhwz9aFOQ8tRJim8iVuyIb6xTkFIXp5WxA9YwjFO12M9NPuRkvD5/SSkEGf3/3S8ChGzbSxfHUFUtJ2vBzm0NIACVBmLqFo2FCyiKusQsBaj5suJ3DNlWLqIOoOtXpera/XEWAr4ZvljT6ARPXteqH8ztiCLDVfnzzMeTTHPhBymcYa6YeEIfxQ+hdcGEBqfQdAdZTa8DWi8gwD8ReknLjsU1DmhFLKzwkBEm1JDMErHdpM1fEPDIgGwPkKrqPindYPjrba0fUpYoga/rYFAlf+dA9iPlLHdk5OIMcTe/rZOyU6vcSI4yseJgUZDRPbVVWJVMpCJHINLg== 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=rS+XEDLCYXK3kG0pGvcV2b4OXTcv8/63SxxK34hw9ig=; b=aqsCHCl/sNXv7XM6LZQm6xn7ffGXXVs8e8vIXPQqHGcAK0Gs4v2srCwnReCd1pB9IXDT6ha6AVU2Rgq87UvnV5Ll2qcgCnp6pQfWyvXtN9Q1jcz9jFDMHbGPb3VsqA5NAXzDtA8IDqseJ+vTl11Rzjphjv0ItuhnIuiKi0ta2oItFhWZ0AhN2JDryzo/RnnQgAlTyUwnSlpgIqT+3UsrF0Wnfn2JuWLSoN4TLGb47GVkWCtrGPDmqLiVO5LSYFNyCoiU5sWI4cB7OKcnHYMGSgdynKsbh54ATpOjYGbyG+dGm62zZ2x0qCjm9FNf1K5w3RbmgYUUE2ZZTtgjLgbn7A== 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=rS+XEDLCYXK3kG0pGvcV2b4OXTcv8/63SxxK34hw9ig=; b=dkfcZQMZ/ZE/ZQYihrlVDOpnaJvMOpmEWpKIWTlXNx22l5UwiajeCdsSkFYLgYVZ9vkK2xOFKY+5T8UEEhtczI2uplebaU1sIOv8oxj6DGXD1m5I6VUZUpHMULxJNMx0Yh7KYjZQFjXVmGBNCXKLGnvUYAakXz4DZW4DODLmvnw= 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.5834.2; Fri, 11 Nov 2022 06:22:23 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:23 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 06/12] swiotlb: Remove bounce buffer remapping for Hyper-V Date: Thu, 10 Nov 2022 22:21:35 -0800 Message-Id: <1668147701-4583-7-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: 7e331c76-0886-4c76-7d95-08dac3ad1827 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: W4TmHbEIKU4oZVirCCHWFzDxYYsKPURdYKHmNiBvnLcQdDF2jlFaIHsNIe48ZKgof8KzPK9WEoUJN4tLepWy4QEt21qjyWkIFPHQlQxMRDi7wxOa0tfQnubdHaz3JT6scVxmHZ27awBllP+A2eu3h8IJZ6vhHjVNYHVsmdu58bltSUAu+5u04q8bQgnhqZy6+e5GV+NKFH+OekfrDcTEDTcaRa3eqsWtUVBmK7Ljoh19+K/0pwjAy0fpVhSXtwg/QkZRfx4L2CJ2TZhzZT7uZwtheYd6ke7SnWmfUhip6BfiG6F2QCBbgTyZJm7GkzpZ20uRuFuy6pzEKUuykXEulUg64KJvA1F9r829wgWtfi5WDCNIfysfSz2vyuDm4z+5FoOdW/OJRmLrk5DB89k0oSJTkaKf8+Z2zqxmGCo1ivmoX/Wvtrd/8Y4qww94l4chBy9H86laDPbE9hZIbnoMNLd9douePTxFg25wtNZrUbdHq0JlX8kNRgEBmLSU7sWO1t2dRi6Zkebro36riTXnTfrza2PDn1GzRSrlAvsxJoyYRTzNUj/q/Zi1yuNXYbRZqr9jrzZzKmXs+wqirFwUd9b3E61E6mzVvPRqdbNNVM1LXKoGkS1IZNR9CwvXXdVQF4nOQnyL8VEoEjsEo7W9Ve2sg3YlR+p9fFIbTz2b5DFESSiZVa4lvrfjnMM2LtTdOj4lOXJZhLk0uoaBfArn85A8CCOXXSEw91VnX50fK6n2GiFiGfx1SdS0syzsTiiZDZhtvPjqo8uakipUMJz2ACiHCXO3QUwCNdSSOb2osu58+NpqtSgx69rHhuLsTbU/DZSjs4m5NQaGKtiznXjyxg== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PqeMroTCtrxVCX0NySwSDl7NdrpiMg0/7annXQ30e0qJiob7dMjVGkX7Q/rddm39VObLKCRpzx0AxPJCUOzvRK++EsEW6/G+EdeZXZkQeBwzrHDAf7bSw3x+rFzhGPxshkQty5yNPGFa8JV2oRbJCjGm8YKTcew9QqjxTS1PBUBfyw2E841Tvq2SWKBVvUB2FGCYnfhBkfmCoryGjMY1D/ffUbzdL+XCOL6y7zk3V7/JUr1SBCCNgi1sQaeNmxVEXXAihuQ5ob7LdmhJOtTzMyM7uMoku/yBEnUHGQgjcAsETqCa6wl7ENVrx/DlPAcpTvy5HFJtaOiPFD8TLGKfioXBqkGHHH7pRQN9qLhj5gt/pisOCxFI0CpCNHhNQ/YRKzJZJbEgJHVBOn8qAWWbrK2u+smaPqh/YgDxl1YNXFSlK+tJIayNA98tBHM7fUQ4p8hX53GOqpZkwpfer1hEYSwtCGlcqTvwY4Y+jsXHLVpXpbEgpQVlrw31SvNtCi+I4tlCOc9EvfZfpBGqGmGgcb9V7eN7kSf4fqpDr/VHAiz9nnUM2WKo72wnV7UGa5GDD0gz7zui13X9qkk+OOmdJ9pXLqSp15/zaPcfSEeaUO9XvTBtKXGsMErrEf0UIBmbQhLxbWecE3uXbet587cg0ZYvN1kAHeKCq/d5GQ0+30bEHIsc48S20o+S+1sY+5MpI+rKJ2AsB8eAted7nwHKpbFUv8PlUQdxo8eem5/wFWcLAZmc2yQZdq7S6FBqlTok3DoGfsGMr0LdaEH5td4p1FBqYq8fpkAX2ZA7mdI/FDWfzI2+MU5I3GThxV5eX2lrHUh6age6Bg9/O+OSfPz6dIFA458n49xkWA239X265BXxaerRqWxLVZxoBnjxuScHpspV34EFl8q70F4nu4u9RPe+AAKdIVaugGPocV96y/yJRg0oHTiXHL6sn//RrGsqrnNtnw19ELxoBGnQF9JBh+8XiLb9/5Wytk3a2JRqZ9//gcZdm8VKgr1iV6fK/Bn4xgUkKwZHH+FBShly0L9RjZebfV/H/d4AcE150bfFKEaBUgRuVmdtnRm4nx0Moui1M0QkM8a7xwDjEn1AgYwxAT/544VVpGXzk4BZA4W+JuxmMOEErUxmKlmiO2C0G0dg9cHJM46UcB7nO+EmbFeXgHtVQ314P5BrundG4eOGR4JqGYKiUDFxH+s18eNVo1vBmPtgNCTUCV/+Nvi6M71DYodO08hiWDhqe4F7SN+iuedjkjvHvL34WMbBM+CiG9jgnts9/YHdMMCJdg9RRIOUu7uI7lTqbvLFyYXYBpjezqtJJ61QNA+GJSLDclbupgt+uFwpmMbCHPjsZ31XtXb0QXzdh5B1PZ4AxtCxB0w5iM+dzn7Cmy4kpI5BPg0R+HrGyIP63PQmfzIK08hnMJIUAzBPfDUowmhssp8tn0+krbgz5sR9yYYL6JwqPbXQN2zEkAi04NMvBNAeh8PmopnYdkz8xlpSAPE+mGy+vT/yrT4eFwxpxA+GwhU9ZZYvlVntNyIbCPmibGGnMcCP/oQru9H/BjMFYcSpzWHIjcQn5X2Z7nBI5kMoUb2FLim32crFwUeiCKw/9ukj9qrDrXQLLw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e331c76-0886-4c76-7d95-08dac3ad1827 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:23.0389 (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: 1x0Haz/BZbKe+uUPNRDlkzGZYIOPhxG92e1ur4og4bvBdLUmtoe+YBVuFgUVJYuBHdNAo+0cgQurOgM9rxHzeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove swiotlb_unencrypted_base and the associated code. Signed-off-by: Michael Kelley Acked-by: Christoph Hellwig --- 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 a34c38b..d3d6be0 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 Fri Nov 11 06:21:36 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: 13039724 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 EA657C43217 for ; Fri, 11 Nov 2022 06:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232955AbiKKGWn (ORCPT ); Fri, 11 Nov 2022 01:22:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232341AbiKKGWh (ORCPT ); Fri, 11 Nov 2022 01:22:37 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97673725F8; Thu, 10 Nov 2022 22:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SL+Op8c668UmcNoEXmNzBaCOv9BacVAZDfaFZe0SKpfngVVUvL6Yt4JW+SU1t6z9oGgax/aVzldtKVs9QtRWcHa0KRn8QsZQifUZn2wLrocQkFfKtCS98J4ouO8hQxSwA4sgzIJ+L4OduDx6xdhvkSqnYZmdRGoZ8PMbEXrIwKuYNlhllxbuJvO+On1eaxoIEDIgYaekKEFSv6nkB5M2rfT3atIR5c3LDBpViuzLt0Id5FLzDcUqaTp+nzEf0CraOMYojauSWgWtUuBhmJHeY12+pDI6ZSwV6WiavJeXOdGbIHM8Cm0vYQl9j8WhHJ+V25EjHTaxBV7xTMM+YvygXw== 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=xgm+jUaF9HijpG4qFbxbmrNC62Z56ETkSKfonyRpknY=; b=jKA3k3rP2iVfNIEyy3oCpHUC8HazGSu0aqnwN8jM3W7n/BsXw+uTt1YAMuwI7E8+H2/8kKOXzUlJBaNK3lCAiplgWSrPTTqeBJsPJTB9uKrS4Z6HTmc6kRqM5JKJbMAapdqboPZOwaNJSteZOleiYsvVczKlGRmSw4jXzwRTQ8uDLizBMgX+RGXepeNX5/7xazrGYqQ2YlQnvdnDULxGj4tiy83d1z0uxvm+f5Bcj1aeirdqFED+Q8lYasGYGVAJX9yB6QwAdETa6gG6z4BTrsSc9dWbPlQuBiT5VJvVycqM4sHwlbuLWGdqM/irTr651Eoz6nCwZLqoa8NUYJgXGw== 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=xgm+jUaF9HijpG4qFbxbmrNC62Z56ETkSKfonyRpknY=; b=ToILCqheV+R4T8gHNVRCPL9Zy2M3rQ9fC9X/ZivK5oxqPsUUkP9w+p6vvJljaZt6cS2Bj9Koid7ZwBIuPZW8uOf4EsahE+KXY9rfJmEIMTqJ6LePFAW7D1yAeXEE1LL8b2br6iM0VmokI/QG7IqHyAI8mgQqTozRRUsWFLH3A34= 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.5834.2; Fri, 11 Nov 2022 06:22:25 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:25 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 07/12] Drivers: hv: vmbus: Remove second mapping of VMBus monitor pages Date: Thu, 10 Nov 2022 22:21:36 -0800 Message-Id: <1668147701-4583-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: 1eb04da1-f7bb-4932-14d0-08dac3ad196c 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: M+2Joy1XceC4wilOgAilQQJ/ir4WSMAOAaRqo7SX31Zh6Nwa1ozLQWVgwHmuFQ65wrrD/ybUKzK+9Xz3k57gLFoUWJlwMSzynRCYpvJhRX5nrX9zjhvlptqaZ4Oivpc3/oFjYqWR8FjItJuOirGjvGqn0pE6++AkwXE9MTxhtvDLdbm4MJy50lEAiZt10lHgCKAtK2BSpOTjhZXJ5Xxq0V3OCVIiUhrBDQhqz4+2gTY1uPVYX0ECrI1tUO4CwP9PLSZNZZ2JRdQG8KpSdu4OPdG78j76KZ0BblBEyjCLUahzQHVcKV/+vJlcWLERi8k2EuZ8oNhMrxP7MtTCHHPMGv8sMqvF5ams6ZsK2LT2DhvhjpyOrSFoHtUY53gMU3+beF+lq8lKyxu8nQLTX/aMaZRljHozTRKGrojsC1BzjioXDew+I5n6cdpNXx/O5ld7y7nS4bJMs2jRGckhQ6hAOp+fyrsrSd9La+54p0Klgiw3D6kOHCixk+tqBQd3JHXq4itzlW8IzKbaWoRh93oBjgfV2sdq/GCY46H/Bq31Ss6sA6T64Svic+9WvBCny2xbhGeDk3ZPvxkkUn7kpkjelpVH5KQ7XOK0K0N3Q+9hvGwb4iiki+E8ARTByc6JWVbBgcBT0SPzXhkpzkswhOTgugXGrNBfc/R/0wJqjSMO7PFKYyZvlQG6ibk3TR9eGwYNicwNZOuHHeWe8FLYXypDdFcDgCoeLGR6FrX620rm1OVo8qIMWZ8dbn0auMpmm8AVbJfEfWufErkK6vApdH6OZVhrUl1vG0B6DhDVt+kE9hMftPpqYh5CyYYaFb+4weO8 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VZHo8GhM/3ERLUqVaD8hPUbkmwdCPWbQS/6ZWJWiN6KiVJb8YWznHEwiiPBaF9pbkOibP9FJZLRK2/IXgWza7cBtnRJ+R5DW3X6o+AqpnDBAi5AomzLdwPKvdK7bc8Rap3PrY29Jue2ZIeanpO2TXPAsEb3NZCP0sC+lg/no9vbMevjcG+seoYFCK1KIiI0uTaEUnisYSFPsdtAepPSRVJv7RjEvoOzgIPebeJz9Xi3tujEHOQvjmiiMUtHmsvoViN5n0HeGtccu+bq8loAH96NEQCTZegYQPNQnQV5OoEXE3GzTamshnl7BcI30igP88mFkduap/rQwJau6pz4dWrb5seylUU78J95M8B1WRLlD5vEilfmAbl64aIYPxNAf7KHevNcbbJGMchl9GIR7dbYvbtMLE6faFgjK5cnxMBeJhtitjp9BOHqMY4NnTFOpa9jrlJlAzr/4X9/szDixZVUvpplUhzHmDGG8YWu/g+BW6FfuWrFZw04CYIRWqI+WELoY7RaN0ElrigOgHZsmQcu3pEV/1rqGgNhZZwsYGmk8YJ3fmc32qoUK3ewmGeozfE2vk5/91YQ4U2ZuuOjkmjjWtuVMjVjXzHR/Twb+oTOmFVRFcC1B07W9nioGd7TU07kZtC0Pj8piDuyxY2pkczZu6FQRbMLq4WfFqI6IDOKCoHdCsgpTiCs1HoPP2jG5onpP1TX9AGLKuVmvNDxrJab0J6wRMF7fcgav0sLuJmqDbhtjEPCu6xTUNzxVjoVHDw2qGCUmAC3ybw7MFYoHx7Y/FcXOsS86WKH40WkPOY7Et2acakG52u+EEibyhfEPtuiSpJ/mG2qI1fuKAdRSI7KUoRm03rmaCHw9dqwPUP78/29FBEzXqyF/NHeLc+sxwpuEyEt6GdKTrQAc+t3V/XBGNHnP/zuUGtv18DOSo9WRNZwlgatRhpUWLfxEGpmyUrPrd2lzu8oc3m41TtodKyd4Xxr1FexeET+6RinCd7xoUUc3urluAvR+6flLw4qdv9t4ub3QQjqs6Oxm6XsR81lv2oil00mHrStFwHSlfQ+BN+v1do6GuFiiKjke+2ecAi9s57H7CEa/jSPjVpx/tmf9IykF3KjE0cLICzENS0brhGdKtam9lvJgVqwGY1F+eGpv+taEkDTR5TFec3v9b9tAoEy/6i9UpN0eG7pmoJh7Zje9QouD78V01EPjiG1gMqPPay3QEqEgEDUuv5dKdvrJGytzFjb1VELWO9P/MRCB6fX/Gt40ynSrS7i17ysvdIMYgujOZthXv0IRxJAYaK0DCxtyR7Wpn54O7ZkcTdLxQyS6/YnHKk9FFxEMVjBd02Yoo1IDsBuBwh7lq0Oho23Xg6zP9toW/nFZq+AgqTuQf441WWk3tk7NVDfzBa20l1V/pE4/9nu63Gs2hYw4JswkP//G2oljnHmS8f8UfeI3iWObVHvU032eycxn8QWBPlQi4RlMPKahneADq5YdrquurndoTGb9XvQ/gdqU7C+WCJ5GIYybZM3vZ3uoY+6cNCetgsZuJcIsjKtHm2f+PR/WC1XwA2m371usuB5iqDSrEXFKacRdwl6uPfOw212tTbM788RCyoR0Lj0BK4NLmA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1eb04da1-f7bb-4932-14d0-08dac3ad196c X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:25.1649 (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: E5syjhMfnGMGWJ5udiITNHWz4QRE381JbygKyQ+97i+RVRxbYzkVKQa1L3ZHZcm4MvOjFo4BNaQG5KMniMuQIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for VMBus monitor pages. Because set_memory_decrypted() and set_memory_encrypted() are no-ops in normal VMs, it's not even necessary to test for being in a Confidential VM (a.k.a., "Isolation VM"). Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/connection.c | 113 ++++++++++++---------------------------------- drivers/hv/hyperv_vmbus.h | 2 - 2 files changed, 28 insertions(+), 87 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 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 Fri Nov 11 06:21:37 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: 13039725 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 A9EEBC43219 for ; Fri, 11 Nov 2022 06:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233023AbiKKGXF (ORCPT ); Fri, 11 Nov 2022 01:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232929AbiKKGWj (ORCPT ); Fri, 11 Nov 2022 01:22:39 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9616C71F3F; Thu, 10 Nov 2022 22:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ORhch3e2Jr/zndq+e4nA9wD9ofWvBrWhGFAxy2JVi1XosCdV+Z9rLjjYZNSt/XKRjAk467nuOWcFHq1yUQPsPV7WGeFzb1SpKMZP010xE3iGGv/MulT6363D/z+uyAGjr9+MfcJCXRenZE2Fc2IEYNjO8jIOYIySQ1xemRZwaoBaPZXbYcMLB/WVMndjre+YEw2G1RSKaUy42+ixXn9hjNYOWvdWxtXhPNMG3Xgff3r9nahk+TsV5jK1X/h9apcj9617Lp03uc8fwhUjgqn7cPAIf45FwbRMnEC3idX2ow6EV1gQDG2/pJl+ptNfIUnMAGBM/SM08ueLkxcJ4AixDw== 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=Ukiq3mpmblNcB6SjkymwPbJw8wM1j3J+T3/kZJCLbMk=; b=NMuDSdDHt50Po7q1nQ2CmluEwQ+i9uE6AEWLSnlhSLXwhxsNtfUbTXq37xMQpzOzjYTP5okWfm01+A0qLYkM/z5nnsU7z/19xtWbg2HWaGJkk2Z8b5MUbJJxytZc7vPFhneDCqi1DWqv0ruIh3Hu1w+Df4rits7WFtFkQ0DnWvcFZLn+yCvG0ChN8qzhZXD23Cp5jRysY1cwV1SfBv6LrufopBxEqBNWgbYeUWuh2+0k6hutynV4R8r234Lras+puJVMy6Pcse3GMNV78+2KbqBLql+cygVoVAyDC6WEYRty8/nhDxEwCpZaQSUKqMHhr44OuEL8ygTkXPc2kXIUYw== 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=Ukiq3mpmblNcB6SjkymwPbJw8wM1j3J+T3/kZJCLbMk=; b=aXFyNhJiQ+VJnQ92m26HuIfreIlyEYbw3MdKQW3tb+BGQFKjZMPgesUOPwfJ2/aKg241j8G8f0yn6tNFS9XozIzlidRowrfUDWAMLUGEaX487IXFSkdU5FNEAXk1XujSWAo3P8RUaEA/0uFor6yMFA3LPnE6KY72/eUAuBappAM= 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.5834.2; Fri, 11 Nov 2022 06:22:27 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:27 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 08/12] Drivers: hv: vmbus: Remove second way of mapping ring buffers Date: Thu, 10 Nov 2022 22:21:37 -0800 Message-Id: <1668147701-4583-9-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: 787fc119-4485-4fee-4e75-08dac3ad1ab0 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: 9FnQEjAqbNYCEaY2IjSG6k+uVehxqgYL4BQPCKKVn4r1l1qFhU/1xoVk/tZkkvfcezK5UIg3NC8JyUWX62rvZcufjIUteXo4rrMiAs/OodD4g+y4wAgtqoFMAovvT7X8Uf7pTgP8rgFQywNSFzRthUj6BStEwWrVkXJz8plzqY9IGDfxjFFEz9cUYEgCv4WORsLBCHciEMaMeMPW2yCDmiizVbddn9kP61docaIwWKL1krKqcnsrcqrDR0ICba2njmM89kHqc/Ow0c0O2ECgvUi4GHVr0I/kEWevGaGXR/Y8fBQNrgIMOR9ftRTXqSHZ+eb2W/isLx5AW252EhPYc32JM0SDSZxGiPghbVoYkZlLVjJVnfitKgrhWFYagBieNFp9Qiy5vKbdB5hF2/8ej4A/9CLz6nLlXC1fiw2mYVjd82/PO7j8PeExXeW1KadYvnH2AmM8cnlHQZSVowK5qshMhXkZ/8tMs1G4FmXvIJR88+ih/8VAOxEKnCz3LyI7zPfnwvlx/TvrHtJ64tTnpXHLnWIM8OS2vTD0Zifcj5fSEmH652eS/egAbliufxZwdcAy+YguAcahSsXyu4oPo6aPvDQwvKGxo0+DxrDb8B4y7DindSRYBjrcpIXBuJQZtxAm+eTrzeFnvs9Z2VzSywWJgNK9p0XdH6ql9pSXJF2To44YmIionY8HxhAV/30UdvAfkplT1IJRPBTQrE9gaucW9uyRmKet0ibi+A5M3RoFIvxlx8nojr1bxR40cCCCYFkNJU7NMuFCv5+IRNkvHbXHP5gItDtIzTR6qeFIzSxtFaIlj9yWFkzjw5IaY2F/QryQ7tTUwLHPIOtFO4tshw== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ft7kr+wauI3y8EAXQxCbznZYiOPWJnrTLS/BrpzjDs6OQdPWArlgv3OO7jYvf8q/21nPGHAqvLDJ9ycJ/51e6YJaI2jMTubq9j3VqNa/idqwnvPqOSW6dotrxBSZ7B4EFnikZA8s8tK0yZd62aF0bAM5sDd2NzzCNnsdMyVJ9MeYCxLA51bFW+tTidCmOb16TBHW3+iK3mhxPpulxD8SAzQsvcfLZ4pGP5Vq084LJZyjekgvfuWuDPBfNJZswgKAYg4tcZZZEHUDvHAztqh7aZVu/nI2TakkRKM0hh7j33GLqv5VdlQnxa/H9jRDKxbyVw44BJa/gOBai/6EdZURePUeBi8KRjxQ01UppVjUIWvIkdo4OUo6yhkco4A8JwO6ELwD68l9/WybqXwPSzlGkbMJm9NASaagjcanUPAQ1e0POnq1kLvnSA6OWK0UlgKl/gyUHxpb+ragpVHaZvdyqlg1UNctimNlfiBX6WoB2kpX7q2mPsFhy8neBTUCfTDIcw4sfeZBWBzefsIzg0D/P+rAFcQy6AMRj73+9bpQq/B06tQ2y28GD48u0gqEqQPEKtU1Oo/ORAbt3uD7sMHqQ98a4VD9MveqNFe5Z8QumV65rpfTfnIRmVdnblqQhbNeWztSQKjf5TOa7ltOcAVC2pc6s2BR8cxfJi8gJ7zvF/qaMEqRILCDF1DVO/MkqfiptvZY0QTMVu4tDizd+PL2DPJ/7jb1UYJw29fPNpAmMEi5b6NKyguYInsvG51ZNehWqytMtXaFmxAzIGcvzBOFNkWyJ/HYl/ajgFc6iOVyevkAI+WiJXUqFi+5ruUN2aNVsDi3Mjm0GZdJQxZyi7gxjUxjWWQ1Lr4UPXG9Y/jvjAi75G2nPoPBf0Os4Y4U4SwGMvJ9b3Rf+1/QmP131fnsDCyvmdeUQcrdtMvJwua8ai3bYz0k5wUELwpPxF/YjDzFLKeJmvuYVFJEk3OdpPxykSUhIxhTjISJ8r0xmVX8Z5pGlBXlLE1o7eZHNSa6+o4lpQuuQCHLJ2+2AmxHlxYRQbn06b9KRrKlEryIIQR0ts2e9GZKGYkJ2G4X/g6IPEScR3rxiGzHwIxfNyIYEl5Wm4/D/VZ5fz4Vaf70OBTMbyZf1s3iToDJimhSVVVsF2Z1Snrl/OlwvJfBIL66T/eOXHvTSzTWC3v5ZxjfTf39Ui6vwIXvlYF49LH37JArfXDxKgo4Zyj+A5mHdyEOwFJCpvC/07J8eaJnevnp1+/Yeb3M/sFrpDnDIfm+l+/qkJgLbyFhY22RrEBUqVcVAdMs78hYTUA1Sk6QE8Xwe4ZeiS6EN4CJe+LXGrKJUNclqnqF/+9dPBsDMGFopgGo/j+2Xg1h8yCzAd0aUAH2tEDcb1TjgvZDY2aEpmf51phKBS7naPgaKzwpKpkftYOhJjOhw32FaXSDK1+pc5MXTi8KGpevc7mvF4A5KaR56Nkd8oju7AxyvXr0WlSMe2F+gkSCJkDtOG5b08QNnFDKXWQMIOXEblUPdhZvVXy8UFtVvxRYMFe6SlD2+FR7JKnKjPACEEPgFO8vcbAzGzjfAyEYzeNSi5yjfzd7ij7NshDCPao0hqFuZMxBBQDiw6SnVSSW0A== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 787fc119-4485-4fee-4e75-08dac3ad1ab0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:27.3210 (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: qrs+q0L/5tzk/3PmFuBtjFLPZUMHSve4ku+I6BtwZdBNfa2jwDzujyqCn5E6doKsVkDBYKHBQtT3M4x9SiRrKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), it's no longer necessary to have separate code paths for mapping VMBus ring buffers for for normal VMs and for Confidential VMs. As such, remove the code path that uses vmap_pfn(), and set the protection flags argument to vmap() to account for the difference between normal and Confidential VMs. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/ring_buffer.c | 62 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 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 Fri Nov 11 06:21:38 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: 13039726 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 3D101C4332F for ; Fri, 11 Nov 2022 06:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233061AbiKKGYk (ORCPT ); Fri, 11 Nov 2022 01:24:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232894AbiKKGXC (ORCPT ); Fri, 11 Nov 2022 01:23:02 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E0F72994; Thu, 10 Nov 2022 22:22:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AUnmqIFpsX5KAi2rMoVlR5Xx/AguMoBLwU6gL6y24pUcuOhDkkmH4l/vn9ZAOjpzu2+RNbQfiGEAdi/1XTSjVZ6euXcE8o0JtyaTYc3NLsN1OXiOP80ruW34CM7hdmv2Q3/5Uu9PaU6fPKzNfNDne3kaP17l+YbgRMj43r4azqoXazV0om8psvSMoapA1RXewxqYxvb++u6LOfbetW725WSOGlHTBcUE6+aJ/Bwq3iAiPJwi47olGrmY7mWyEzCxGXwxAFff/+mxFpBI+L7+z7Yd+3X+PBIuQcWJQQcmofyBjR4zCq9c0/DUWBwyG9dRBerqy6UWKxMB9SelCXj5sQ== 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=uMQFfu0nvpSqyQBcQ+B8fVzRzFcxDk9HPFep8luloWg=; b=A/0rVR64E1B94/e048pKR5UQBQi490tvUPjyxKUUukpF7fHNMcFraTzAXU9FE/pa/MC7NwVzNl7Amc0GYGHgX6xP0eUaSPlzvBKW9XMTKaPznnn081LIZAweufzvvKsmIFvnA1TANF51Sr4kFkUXUby3b8rK/l+FJ5figJ27zd5oWpoDQ7RViBh9qWfMDlDz87TsYyAfE2EzYOrfuYMciuemNB8r8nWEh/fIsL18muosyzCfH14SfYhJVS4Z13ecW9V0KAzH+xMltsoMTXYY96Ix2+NNegKfGAQ8A+kq5wybtw34fY8lO+1tfL3wTGZGIafbey0db65PUuA4kCXgGQ== 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=uMQFfu0nvpSqyQBcQ+B8fVzRzFcxDk9HPFep8luloWg=; b=Y9bLG2rO+iTW/NzWpab7xp30zCvAexdry+HXcHXcKAYHoEAeuuxgFcpzme8mlzwJMtsAifTX7Sq/9Hmj01WkvPZArZxZfs/+l4YeKkwBi0PLtl3tJl4ewsJnn/WRyCybWBootrG3SyaTU76sh158RPfnI6XGxjCAtycwmhJjpbI= 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.5834.2; Fri, 11 Nov 2022 06:22:29 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:29 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 09/12] hv_netvsc: Remove second mapping of send and recv buffers Date: Thu, 10 Nov 2022 22:21:38 -0800 Message-Id: <1668147701-4583-10-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: 88677587-5b72-4c7c-dc46-08dac3ad1bfb 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: 52CwX+g8Ha/tRtICwUybCcszZWh07zfMU0FIuf7eu8mg6M2IIHy0U4A4NDkv9nvZ3zn/42lyIsTmplmeqARieiK0I2YcFceJXVVtoh9qRQE84Z/QuMsrMTrTNDS7vL3A+Whxa59WgIX0BjRhHa+lbaqsgzfQ277C/ob6cBQRgkHN6rBYAb7xpw4N+pA67AjGEtWOE782vfTt8WzQ2KlaPaG43KWfToqmz3em+TzHcdTzuizM2hqU/AOKEdDesGrXryLJ0WJdY9S5shWxyHEVpqIg8cTKrgSuSPYIHKSs82ACGQV7m5Ssu8dHXYWP6LX7yrhf0EM0CUuPCQcZeqh8z61Z2yAzISqkeUlHs5S5qq1SNCPf/eWYzAD6Wu49OKoQyktvuJ8uSTWiYGgncrCcMFya3rVwIqx5roFNg0t0/0zB6D+FVTroDs/vWBBfiU6E33zXW60efnStibbWCr2Ox60EO8wudMmVb+g0aFwfp5qTXVSDGmf9lqMil65agXY0NRM38s8bDQs+hj9mMLRaGRGw0OaNhUiIb5089cRyowDQ5NerSGIpKRIirxY6gxQo3k7LIslyUJq/FGvAdTaisUkzb14GkxIbOM+glqRMZDjYfRtaTJCL4lFZOW28ckRcaQG2iloYYh+aA0xps7g6FBuDpFozZQsqYE5uyoGgqb+i+TKNcZ9JkhA3r0ACDGgATxgT8MM3FxrhcOa4S8W17ofI8aA82miYqvJSkuzGzJoOHhXiBRXhamGa0vJ+h6WBLhSAfb5MLw/QW4A2waNxwLzr47ixvlIKV75LpjW7cKSVbT3Wi4XXLohbQdBuF0uPUd2/im8vJ9ThzzzsdMyMww== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HFG58Wq3IHaHq47uK+C2Dbnz447vUsZVPpjBWqyRkT6Jzqh862PV5/HJaI6kFJq2l9HGxhmZdAnvfCzaqRI5e0Rgl0dbCNzUQ4Ja8cUddSnsXaksxYvidwKc6imqzylQ25vr/ElNIEHvH7htldCaRNmjCC1Cr1KdkzORgOQiwt6nnK4ExOwZFZXwkLAOL65R9Eq3a3qxfJLGXnHV4R6CbRvI3xtLZCt4kilmcOSTCy05Cw1DPLat/WRNm1/RubIcWXcBxwnMu7p0jR+v3HMEQzw0z7hTy8kvsXdYkKG9xLgAPRQOAYzkrmLFFNsLoF3/Qs9cFH7fDgL86so/jtknWC2hRQUtsTS3igX/sMRI2+9uTblNWzny6BiB05qlRRTr716XiV1pxQRON9WYx44vJ8uibn4EbXzequCPT2mkHEetTOCo1dkiqt1dbXXYSRohIW53IN2qDLM6QL4YLJsAwvoQw50zUKZdg87DVQMZDI5ZlbnA15AvT9DaniA6M1fessopg0AyF8CBe+CIYQ7kxnF2QwvNJZpzF1j/0W94S3WxjiHkDhfjnnpyoVu+ViljwITGpDOzyACa/wi0iDUPc+2dFBjxKHZ06u4Hs3dOGqdH+mihJ4xxWXD+LYczMPzhIHiBoqpWYXLuPZNTKD9wLCw3JrYv3CxZcAcAmA/WCkZ+WvcyR+PdbHFClL4sJqgMNx2aau9P1we9uGe4Y11h8tf7K+49NIOHLFYBxW2P7zflAvaUjP4idldVLv9VeeBX1zlzZ4SEegpZjUh7wWQQln/OzFXCQYfme5aFiTVDUqMydzPH0YLj7hhRfXvAkq8wQevvF0HmF6RrtWnYBgmnHcJ8ETVN4gEXv9aWcfj4tTaVnQGba8Gu50zFAIHp/1Pc0A1DZihjJThjWyW0gi0TJxdASNdavSee2VNnScOEnFnUosvLLe2hO1QITHORDWBmfU1Bz86z1BtHmliz5ZnhRsaz3ryGqdK2qSKwqhQM+BDsi2U9C2I5ygb7X3o5g5m3PMnPUO4rQixi5yCC5LGsFF8Mb45ZLYYGKp6Flk4IBSmjfLVuUZPxBCisv/RE4cOW1KF2OlyL7Zj717Khc/XL6pmmyGC0rh2ERVD0TBpRV5vJDSjjNNG5yNPr4injySwUI6/wZzKfS8y153oBxNOIz4sWitGVGn92KUtpMDh3Mnc5ic8kHpicXNh7eGKnwvnsb7/nE/sXCq25F82Z+MxjHqwSm0bWxbXONBpyBCyBIoYLdUWZ55hkn4/ipAyoXKuOaPhBK4XXCKwgFvP6PyOHfE37xkYeD0A79jz+gxUZ4dbPUDlxS7Brdxaab4xLrNmiGx1oTm3SapvvDdB8AWKPAKsegaBjZLoZBPdqzifDA/gChJfYQpM3etH96k5uHOUOBPhsG5d+a3AS1E5ISDi4PsuBisNj4aLqOV1P8rTKukcs5bjyVFJRyeVn/TkY8q3/C/CODnT+rmcAxEuBdPBlozVN6eOYkSiSNYy7/M6ItvT1hKV4jQQz9iohLf8oQ2R2vlbpa6cwClaM6xJKDHWHsO8tsPncqWhA8bUbkeZGQkT+gV2s9kdduP+NNYM56NrpW/XLMLBF4q2HiG3HN1F4cA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88677587-5b72-4c7c-dc46-08dac3ad1bfb X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:29.4626 (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: WINj/yIlO3K1Ev/sdCDJoTt2QDP5U4rmFywgoWemoOgGMrgrARMIZy+hFsIaeMcsJmfvVdI5ahhCMfi6mYGG6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for the pre-allocated send and recv buffers. This mapping is the last user of hv_map_memory()/hv_unmap_memory(), so delete these functions as well. Finally, hv_map_memory() is the last user of vmap_pfn() in Hyper-V guest code, so remove the Kconfig selection of VMAP_PFN. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 28 ------------------------ drivers/hv/Kconfig | 1 - drivers/hv/hv_common.c | 11 ---------- drivers/net/hyperv/hyperv_net.h | 2 -- drivers/net/hyperv/netvsc.c | 48 ++--------------------------------------- include/asm-generic/mshyperv.h | 2 -- 6 files changed, 2 insertions(+), 90 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 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 Fri Nov 11 06:21:39 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: 13039727 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 8BD78C4332F for ; Fri, 11 Nov 2022 06:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233082AbiKKGZj (ORCPT ); Fri, 11 Nov 2022 01:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233084AbiKKGZA (ORCPT ); Fri, 11 Nov 2022 01:25:00 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E1C742ED; Thu, 10 Nov 2022 22:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JO2W/czR37M5ICw6NwvMsTK2N0V0pxL2XWScbdGP6ucPDPI9TWQb5WDKYkt/Mu4lT1AD06s/zJNek0L4d0L1qaddac/ddeOJ3RnG2AoZ+64mnEYVLo+SFxC2qwEmyAOfGq+LcJLxG0wx4ogdAZXcC7xLI3qDmaKfXeB61fsVQ8/VromjEebZZ5vAk8Z1Znyx6ArLgky/qEG7Ma/YvW1n3p3X7nX3Vv/8lOGOoYseXNuDzCyKsXI/6upKnzufpQCWvxjJlry5BuU9Fh8aRubYryix0ktN97aX4WgpfqnCeEfgbjK+9zykYf2uhfi9Siy59op9VoPScbBZycVUYDsV0Q== 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=85+v0DH+3mlkLMx0kKGVKEBUtraxUVOFMF0rnKO4Ujs=; b=Nmf6qtGeNu8gPS6NOFxsFR2/KGjGTcKHjpWn9mUbqh9B8o0IFmkpIT1bmMGWCm7A4onmsMcTxCBqO9pVFakbLQUTzoy3hWHxiGM7KX6O3Uc/AT4JBGSi7KtpOFolBbZyYBHp9dqcYCSlpw6Of+0UsHxQGYi9TUL+5naEHynkw8dDgOVcWQomcf0hmA1OOZJimcDTAph01fuSYpt7ZOrtWUQGHOf+igTilfIsegnMricHktwm9d/vMt5rtedqzmNGqij4Myh2JWrxLEFKN7ZwbvqP7etYKQYiGXSyIT61X+3X8QE4Tu4FIKqXbC09c5dziGx0nu/uHmD/oYFN0064vA== 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=85+v0DH+3mlkLMx0kKGVKEBUtraxUVOFMF0rnKO4Ujs=; b=dD+2/RWGREcqP4efxr72IltZ5Kuj1g5Y9HK7adQhrzfkUaY8OB0D9MJPTFIIWFO5PomXvm+BkSBSDbHWkaoJcUAtRGOSkC8lNorgko3DiRIztwIvI40mPLKMLj9+GW8bjW26dOy3TTK3CncQ3yVJKh4dWbo95qrcDiQrgixyMzo= 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.5834.2; Fri, 11 Nov 2022 06:22:31 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:31 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 10/12] Drivers: hv: Don't remap addresses that are above shared_gpa_boundary Date: Thu, 10 Nov 2022 22:21:39 -0800 Message-Id: <1668147701-4583-11-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: aca4de34-11a5-4b9e-47b7-08dac3ad1d47 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: QuuGLwZOqIiFsDou76mZxxZgiO4uWWlMu7Jw+xHuC9GzyIYWBtpWWNy79DbW9Na0hxyt5NFnrava5033PSJllS9wba2tVd4EhUFqydjVN2CjkaavUH6Y9McZjox7wM2xzvM+OpI9hm3zVyQ4VaM3MMr5UdkKHu2Rt7dpOYJOcPnybbTl69JlGiLGj/1U4/cud+REe+x08bKCoNIR+Mg+IBPZauU9QbgohAg0DX0k1gGu1tKR/ezWmMDin7DP0ORWlqIuqsEdsQod1Mu/kmOQuDB189Al0MeC9pgl77zZKioGds2N39z4xvJJK65zkS+DERSzVSMn0WwH4OBeUk2kfh4Hp3cRq7e5sE1qHCQLoMfrKz/GKCrPIOe9sK8opQ+hYikuku89KAagUa1/2tr8gUFU0uZY1t2Jwz1ofYVlkczRVpxAqmrc+bhJF9vrUEuB45ZhoxpogfeI1A1fTa0dkXAzz0rh1xyorVjuc+yd1zjOOfuv/W2BTUT+4D9895ik1LXqd1RLVnEoc1M+vH6WJB1MCRSvQPhYFh249EIxhfEzBxqn5LLfgnIKBLMBSWd0IqRpQ7dBcfUPzN7AaS9Vpq8PM0miwVsbcMZZkXTsbpkhoj84uAJU7WntnroGlud0nxtUgCRVIfuTbpAulELGFAaQAh0lIP2xWb1J6UGlqYOxZAms7HLQTW2OjqAZlaBguMX5NGlrVvzy6XcqRQOz/fsgI3Z0Tz7m/dTWGiYCDqgaWq/Y6mCEMjzgq03dY4knY9Uu49Rxgct6hD6NT3Icbc2sYNqJlQ2qEOtdsqwvp08qfva4/n8aZn93fvZZS32GryQxu7gx0kEa1xf0GQUW5w== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F1rcBub05SGl0Im1L9ZRf3KaqUlASnpz2uzQI1mZe3m+J3Pgrcdf0zOhY3yXHB/CCdmXbblz6NAqnP9N2DSyTWBzK0sxs8hanaLCJH5/0rOxI7v3+1c8focfdbKYknklY6tIOdD0Fittv72aCxW6lKEn8knGI2hMgHF8MCC9fQ+MJQxj/ZJmALycMq6a1d3Q4XvNBeQkPUub4OhQdiIPXw8VsXnltw7M4rNmHT4G3wHHCfpFGR6Vebm572wzpuXxL54XW4pvgUb2GyweWZTWXGk8UZAy9cwLXAOLs8fwXBTmdG8NW6jDA9zrZRh30kfekjKlVZvF7R6M9fcgxi2fBolkSllr+bvh0URUSnNBvhzrKq8IUNCObgRPESVSlZKnVMNB7XRZD2R65YgxqOnB1LhGR/j9LiZrKWWyDbB0MrsvSwh2KFylWZ8L9UC6GvsbCqYfdyOrsiN+3hr9jfdMzXSIpnQZmd7Y3qa/vi8iBtyW+Xi7c0hlVggO+EosefQSGLPn7a/bQxyTi2bwl8Hf9r4ueFLp86qh1hUiqrVwMk/dfWY6VQP9vbWeCT3LOi1fpXH+cEqhfkwZ7gEVjQ/fmOAyrPoDb4PG/Va2zYJYEFEaqG3VjO384qR4YlBMuJqsK+jsmjZ/4FqVFAPcZfz8ROfK/m8rk1ZzMYaWuHS6f9XjlGIRM7vk1OBRLSGMQBg0CF4+rUFDVm00DXNIPeCvLgjKPemotUUJvWkdL6pr1yMr+0jtIZZK6z3DJUfBROvsottj59DzRrNer48+6WXjqyD1GNIOPeErP/Bk8LJ19ShdGUKG6x5SIvzYfjcOCAvapk+GmoPmdAbiEwa4UW8DuRH4qQNmaIlM9hsqskaNrWoSxIEkXDpUxgmUnT8T6Nqo3tnxsYCdok0+6944YOzxA/9jYX2V7Op5HP3d9787K/FKVzVjGyS7XiPyZW5FYvlHE3bbXvhpU94LEeMp2Yhl/YqrBaDAXmSsvu7ALSjYxdEtz46M+AhPiWEbxAQnDa5r2aGkYGCrj5lDmyeGYxw4p9M4ee0mMaQpEaIZbUnmszwiK2X2zL10dzKJffsKgNT9/VJkHmAHQAE1TBlAJZZUtLnIlUxrmV7JH1pcM/z0vbvz3unOHk0X32HmBSHzVILJz16xTKjhSXYYiJrMtKxliahJ0sjgEKlavyWF0cmy8cQwKVB6MeWXoQH68yJDv64B9j4jYhfTP9LNtyv/i+eAF/F6Fq/Ii1vLhqPjfC3e8G8QRH9rPn6cVE1cRbOTqBa0awalLUSwL8ZlgEJnSaeXy3lDRE0kJAC3uhaUJ3JQsRWVeD7mJxTc4l9pWOtnmbggVA2bZKsDqkdm4dgWKrUy77I169s3B6wIK0C+RmGz23WZXj4K4i9WALO0LYGnEAnpN5HMKEXqEO2QRrUpqQ7Ih6Ow/p1ot07qhuQk5o1/OkfDN/F/3iuxyTGUrnVd10gWbBlcOhu+CdwfmuOgyOeZB2abq4MBKZNkxquEoNGp1QRgYlYKn5nVg+BLoJq25GzSUU/+B/37Oj/YcDNgAPAsY4cVTwC1Il+IVbKVJbimlqstupkfDvI4MDnAH5jVB5S/GkblBH3aITiwv3h1ECScDA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: aca4de34-11a5-4b9e-47b7-08dac3ad1d47 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:31.6659 (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: 29kyrMtGKDfK7i3UczBF5zEruTN7oyukrM/di/N8JlNEipiTnpc7XYb2FBxLXOAxpgQjoGG/eh5L8EFh/y/Ltw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org With the vTOM bit now treated as a protection flag and not part of the physical address, avoid remapping physical addresses with vTOM set since technically such addresses aren't valid. Use ioremap_cache() instead of memremap() to ensure that the mapping provides decrypted access, which will correctly set the vTOM bit as a protection flag. While this change is not required for correctness with the current implementation of memremap(), for general code hygiene it's better to not depend on the mapping functions doing something reasonable with a physical address that is out-of-range. While here, fix typos in two error messages. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/hv_init.c | 7 +++++-- drivers/hv/hv.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index f49bc3e..7f46e12 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 Fri Nov 11 06:21:40 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: 13039728 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 B4195C43219 for ; Fri, 11 Nov 2022 06:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233131AbiKKG0Z (ORCPT ); Fri, 11 Nov 2022 01:26:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233037AbiKKGZs (ORCPT ); Fri, 11 Nov 2022 01:25:48 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C6BA72980; Thu, 10 Nov 2022 22:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sjh3I7olrqLnIg1yZuKP3kMp2lmHS2S+PxCPx8DUv3/uBDuizxkJqBtDE2kjjBVdg5hI/YDBa33CCWNPO3wtuocThY/1SJAOy+BWNHH38QGXtxfhPuRFfu26zjjECwgZL65klEgUsK/WHhEXkyBwTs/ODMF1RBMWJjoRLQU41kq4AzpOZ4sUTay1/+i4xEdwZkBagjIqEutdjxl6ipq67CBrb3/mzntjJXf8V66tWCzakyPHnMYjuOkYQ2kIKMoeHMUpvopMy043U1x8Reudjx+0VfpsqsZXsQ0L915m+ZwpdYklrMMfZTngGJxU32IxdKZyCfbyxyyRZuunm25KSg== 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=uDBf1JoaWPUpyxNyOQTOg3bA8mI88YgxN+97JsIj6Qw=; b=oOtdhNZxYROBUf1jaoeuYOKW4IQOEnQEIGJDFfPlsLXlvyI+Yz6f2D5IflwZXWlLAgKMXZLt1KonceM6TBssp5FR9V8n8SqsKo6f56ZpdEOZHd5mdheqQo9Vwe6aP8wp7rR5Wr/t2eLDNyn5CA1CYygaSH7tkv70DuT/ls7PAJ/qMLZ6ZP0vKczzapxfMlL2PfnqiC+Dvy5sP+cL5o+zgz553p2KH3hUKH0vRyWblox3um3DtmxCqbEd88iiQr7GJJxf94HDQPtVkoWK3BqnD0gt8/ftLntcvPrrBoilVpiQjTdt/BG8iDUW3+0N0phDtq1Ol+3nfltgKxHF9SiT2Q== 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=uDBf1JoaWPUpyxNyOQTOg3bA8mI88YgxN+97JsIj6Qw=; b=V3Z9m4+/0q+0NU3BFkvQYq6svuO8j/ukKtStAxEGI5fj4G2mVEg/9ShIjYOUi8/z8p5eggt4OvW+B0viHpmTyC9KAOa7nL7t59aSfPvVRCPCglcL3rD0AONc2m2PmJUCqtWqKNrxg90l6cGVa8YFfbQlFSBEKxDy7oHRtjNxVKw= 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.5834.2; Fri, 11 Nov 2022 06:22:34 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:34 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 11/12] PCI: hv: Add hypercalls to read/write MMIO space Date: Thu, 10 Nov 2022 22:21:40 -0800 Message-Id: <1668147701-4583-12-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: 62979783-ee3a-4db5-1fdf-08dac3ad1ee4 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: 8AT/J8DjlHLroXeo6QKUQVt2G/trJqJsXOWunt78DrWF1ZgBnOviWksSVoTvpKDv6bcYKViy22opFqkdviz37+dQ84mysJLitb8R7HtZ54yzG48Ir2Q86pqwVLr3eis423uqqNisKpGDtoEudFFr4BAN6SQ5Sve8508Z6m3kqqd+s4jCiRMzihh89hNJwWYh8WlfsPDzSri6FBSgljgiU7sKelbywlY6nV+894seBEDX0Y8eIXMC8qqLl4RXPy4E7d4Q/CHTPl761Br29/oOx8f/CXhQ3nqN0Bw+mKjABNpZb67wCKRS/8H6s9P1ecsx1HHTxE8r88SBwRuNwCiax0YcGr25urAQPV9Vryh92CaNdFN6jAa0liSD/z68xBwx/vQKGwNSGyahdHJz9WFra9KZX7NkONi9fhhzI0g6I/UZUh4urJqgc0rIcNgo0U8J9OQkHWiD2gNMV27C3ntbbp39nNh5lX1MXc5L46et6Hr/hw/edABKbCKUQWsvA1YSvCCVNB+hZp/RQA4+ZxJn+wv73f8KW32YOzeT2TeZpRWlDfT+WMRYwbpXA/5efzlCTVCvBBHEnVHXFMxrgLwbj4IRYULLFwRygWVeE9gX8ePnkBYsAQJfndZSamWADGYpEAAVMLd4CzLQae0IGr1/DSUzh+0JzsscssbwJ54p3gQGoAEzVEW57bmisBtrsvmnFONwdi+wQB8vcYPUIJHTGUXNlizx7Tj1/hqblvQ8C2qGIwiDCfmO2wFMBYsSkjB2xLOLRIUO+3Zc3bj27vxsDCU5gVYBrKlO2jDM1XmrU1lfJ19JkW/TS2NQAnnE/pUDMplGGgT97ogsEijy7vrjFA== 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hPSEiGptKFFD62XptuTfVW87yX7flEzAI2X5WPIyVN1w2hHgE5ma9U+Lq+vmM427LxnQYQMw802HD+dbo57YJMcn5iqjAh0Gwts/8djFPJw+UrDxpPq7AtDYJJljMXBa8/c65StZfd/GYterG54QQ/lmmWjvzi8joAXUDSQaEDW0o3jatbccLvhLCzTvH9/qXbivUlbhjwUvaimRoVXHlGOdBGaxHPecctl1xP7EYJlKYt2z6gz0AvsV7gszIb0dYFnIchiK+X4YATJQcTxrlqVE5tXR3mdJaXd8XqwwWOF7zy4tvst1Oa+9DNsLFuctWJkinABBjP4MM1DywUCYsfClUuP36mEbdinfVp7ekcBgp/QVLGi6wdpSmqeiL9fNJTwmGYS0hLxzhZdARdnDrI8AgfzjVB+tVDwFtJnjA7cQAPlKg4PVgUw/IRfuZOUEvkq1RndfZBClbfVLxu3zH3g/3jY14K5/9HsWe9wTYDKrdFWJLfHAwa1A4HgWUyi2rRZQYbuXfTWMhigs29gZaspcgkwi3rZLVn6veK2oLeAZSou5C4lHNKcSOmni90fonfZGpaJiPtKqqHN93kXyUsJkj6glKmiu0TIdmT7mzK8o1/EzlkQE3oC6x8HdfTlYFDK91Sk6wXqGhdvljrxyA6jyuZFIMMfKb7vF5fsngYhqmcX+YhxvOCghD0bqCD/Zedmjl09RQ/S5gJ9yBhnLWqTKkdfJYG89t076+yDoqM7IoWGvOca+KBM4rZRSTVq6PeB7Eh+dG556QYrIPoOK4DkeOkGPiTxG9bEKjK2oh0Fv/JvcTT5njsWJ2Ay5UfvQjZ1vbFcKk/fQmNr53sao7usRDRxZMf9tzKyjXDoVgzws58c8c9Jw0bIBiUlE53sxe2ssblrvJoam/i/Jk58J3qI46jFKfIbFoxo4uNbpVGpaSAENwugbGiEP26l7FRVYQyaubfZi4KG83w5A//zolSFTOlqmiXGSqUcmnkxhgi3W33kl7vFVc26ngXsHdF8ZW5GsbaIB/SDrBlIgNEeC7+8WFijr28g/sCtFkvbw9xVIj/YHB09ZrOdq7R6W0EywxPj7jH3utcD2aPLE4lR2ndIS3vTOUX6z0BgU1SmTlmgsfuQeQ6kvnOWiEjkJTySKzF8/keURKKVR6whfEpYZ32BZl26WVoYyc6rog0fc9NNNvIkWaZP6WHZkR5Tc6JosgLdVmCBgwOiYJnqyndZ+rWikxShi/gQqFDfmCP+D0/EFqBonP9tIWoa4D/1UD1rzp+NIgx1GiX/+l/HCq7zjNOoSL4TYREF0pbt6Q1o4vSmm8OAcDRYTlJNNo+bzhbttnsEtIzO7sPbVt749lE50sFpHsYbUBXK/i3SK78xzrJ4Hjuk7CuY366Sjxjmtc9rhW7LmX+H6p1AsHJot03k/HeosQvWcig76JMCSn2vhTR+g61bmT8nhBf8PCEwRCRd8Pmkf7tthfia+WldEn1dBGpcwFzap4Mu8T+19ucjOrxKBUlB3ljAgMqh4Mcpw+DPJChQ5Pj75J57PoZZipjiSBkOo/z4XeIMbLlnyK5ohHwXhyVv7Mzs+RbqKbD2E76lbx1xgD2UxbDWT+DbVsq5GLw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62979783-ee3a-4db5-1fdf-08dac3ad1ee4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:34.3403 (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: h6n9FMVUVy6erjv8+a3PHIP/JPwwuMjuOH3Bqteaay+QoG1OIqxhWKn5TRqwiiotQ5J9tAchMBwCxdrQ+8xovQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org To support PCI pass-thru devices in Confidential VMs, Hyper-V has added hypercalls to read and write MMIO space. Add the appropriate definitions to hyperv-tlfs.h and implement functions to make the hypercalls. 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 | 64 +++++++++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 22 +++++++++++++ 3 files changed, 89 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 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 ba64284..09b40a1 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1054,6 +1054,70 @@ static int wslot_to_devfn(u32 wslot) return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func); } +static void hv_pci_read_mmio(struct device *dev, phys_addr_t gpa, int size, u32 *val) +{ + struct hv_mmio_read_input *in; + struct hv_mmio_read_output *out; + u64 ret; + + /* + * Must be called with interrupts disabled so it is safe + * to use the per-cpu input argument page. Use it for + * both input and output. + */ + in = *this_cpu_ptr(hyperv_pcpu_input_arg); + out = *this_cpu_ptr(hyperv_pcpu_input_arg) + sizeof(*in); + in->gpa = gpa; + in->size = size; + + ret = hv_do_hypercall(HVCALL_MMIO_READ, in, out); + if (hv_result_success(ret)) { + switch (size) { + case 1: + *val = *(u8 *)(out->data); + break; + case 2: + *val = *(u16 *)(out->data); + break; + default: + *val = *(u32 *)(out->data); + break; + } + } else + dev_err(dev, "MMIO read hypercall error %llx addr %llx size %d\n", + ret, gpa, size); +} + +static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 val) +{ + struct hv_mmio_write_input *in; + u64 ret; + + /* + * Must be called with interrupts disabled so it is safe + * to use the per-cpu input argument memory. + */ + in = *this_cpu_ptr(hyperv_pcpu_input_arg); + in->gpa = gpa; + in->size = size; + switch (size) { + case 1: + *(u8 *)(in->data) = val; + break; + case 2: + *(u16 *)(in->data) = val; + break; + default: + *(u32 *)(in->data) = val; + break; + } + + ret = hv_do_hypercall(HVCALL_MMIO_WRITE, in, NULL); + if (!hv_result_success(ret)) + dev_err(dev, "MMIO write hypercall error %llx addr %llx size %d\n", + ret, gpa, size); +} + /* * PCI Configuration Space for these root PCI buses is implemented as a pair * of pages in memory-mapped I/O space. Writing to the first page chooses diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index b17c6ee..fcab07b 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -168,6 +168,8 @@ struct ms_hyperv_tsc_page { #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db +#define HVCALL_MMIO_READ 0x0106 +#define HVCALL_MMIO_WRITE 0x0107 /* Extended hypercalls */ #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001 @@ -790,4 +792,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 Fri Nov 11 06:21:41 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: 13039732 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 75EB5C433FE for ; Fri, 11 Nov 2022 06:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233113AbiKKG1N (ORCPT ); Fri, 11 Nov 2022 01:27:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232446AbiKKG0q (ORCPT ); Fri, 11 Nov 2022 01:26:46 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022025.outbound.protection.outlook.com [52.101.53.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA488BF47; Thu, 10 Nov 2022 22:23:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dDL6YZLl0JrWEIS1KY8tinsMfJBC7LL6iy9Hh0J12kAMz3KOx3PYdBinorLPzbC23Nv8EG30+6hKhQsHPVGfDUnWfEX5yfT2V4zgqRhSy38TojV7ySqUDmilyxApqbPQ+AUHxebxSxlGMpLjImJQLStmjqp4a1kAbBM7ukPK2OwL8b4AwxwW6jhwLKYq/7s7St07UmjfyfxAXPR7qhbttDD9XUrigwGkjnhCawu+fWw/ny+2svjdj7qKUDoil0slqRkTTy6N03riL94dia3MBTc2Kwkt87kiFldZMm4TQ48cHdQ1XCOsxf3SzpIGzcJ/PGdH9nozP+kCimYZYzcyCw== 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=0vfRKktGtusAn2CuHkYy3SoKI+4YG9f3c1x8BjXPr9U=; b=Y3Up6zVbbaKNYW9CWyEJ7KyGIDNK8BGsvsFB/WjTh2ugqKj0m7VmsM3n4WIK2biK7Z8fUXL4F03aM9NPc7NkqtJ6VI1I8ss1SO4MtsjE0QnsHYY5BoJQtBmPil0Dl9YKAseeKHVoiUwIJhs4yWnw5r6AL4UbK2w8bcdus42Oi3EsKM+lbi0TBHqPJmIgv+vF1X5S8ENxhgmW3p378oereWbLeKUBqg1a52+TcRh9Sgcgke99xgErJAMLCw6QwaXKpofTICpSGLHReIRyJnIBt8r/T2QVQXyltn9svMxKn9pgYVwwWxhE/GWPdBRnMrYLcU51ErO7YXtBmDL12tYhHw== 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=0vfRKktGtusAn2CuHkYy3SoKI+4YG9f3c1x8BjXPr9U=; b=GAV3oE7v8Aap1vFNmCyDs19WaWsTlY7eEhckD0FfhImEhG2kXKwRoJ+iOdnzROAYWZcRKEFkMfDsJz3TGy5B9qSkfKK3SiKAQ+oAROaRtscPz0vt7pnP69vMpCwMAedpMcDxcFuSWN3CKgvfQGVQq0OTQglLOBVoW702zqXPVXA= 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.5834.2; Fri, 11 Nov 2022 06:22:36 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%7]) with mapi id 15.20.5834.002; Fri, 11 Nov 2022 06:22:36 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v2 12/12] PCI: hv: Enable PCI pass-thru devices in Confidential VMs Date: Thu, 10 Nov 2022 22:21:41 -0800 Message-Id: <1668147701-4583-13-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> References: <1668147701-4583-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) 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: a1e3d493-6603-4beb-c515-08dac3ad202a 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: L6dLEXvJhw3Hv+YTYtjwlO4FqoiUlslw/7fjhKItZ25HyixIzuqbyzp8HO7Qcv5NP0LWi3xRh+Ntytt4/AS1gT2wTZm6vKdR6vc8QNKAsE1MW+FreYOrUZ0PnSYWrvZlbvbZpSwdAZhXM/v6IOU3tdI93ttocIfVb7iyS0z6ioFgSc/IIoi0fsDwa7k8gQZ3aPEPAwQTN8o6Y7C/Q8O9RMsDi5TRXXx3eAkiqq6H8rs/bBIBwlWwMputLrZR/K6f+iMGB2I9tC8Q0JWv0s950e8zcC1MEfYKR1c81+w0aIQmmq3OigSOaeLJta6iYU81QDs1IfzvwQT7pWRUcK4Kqv2ePPegsGPnmywFmZhJRT+Bity1nR3wQVNBdNhr/g95xD54oPdrMe8gMcjxsrP1ZUsZkgbaL8eKBvWNpoL2e7JtddQiIe4lP8uGbyIZfsL94JTGYsV20PH+64HsAogSf3I2usftT/Q8uEKUtxkmq2CmCn4YWMGppxKZnVTdruTKO59J75X+4HqqqlmDOmLiU8ppWX7/9tvdxOfde0PcSYyUAYruLc4tfmMlJaWCQPPSXuRZC1HXL+5/6YLtGie1KIlvOCdK0rldp6oIqoGeRqjwvnuC3fnSB9IK+p5ZAAIlHcgi+tVF/5pHmdE2cxSQUPFrqs1I3SCUHDW+pcYNK+/QHX4aa7Uqj5DmR3ZDZxEc2ZOC4aZEy849StSgDs+bwLmRbqf3pau6S6e0DeFBFezztQw+89TGW0EbdNe5jniadf0hCGv8MfFmRCuk2UgY0KznI6xu3qNzNc843L5tvZLgITdanmKRnist5qX58N+XCoQJ1F0z9Ndgt9O97faHhnXdISypThIu0o/HuiNhMRA= 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)(39860400002)(346002)(376002)(366004)(136003)(396003)(451199015)(83380400001)(52116002)(26005)(6666004)(6512007)(186003)(38100700002)(107886003)(2616005)(7406005)(2906002)(316002)(7416002)(6506007)(10290500003)(6486002)(66946007)(66476007)(5660300002)(966005)(8936002)(41300700001)(8676002)(4326008)(66556008)(478600001)(38350700002)(36756003)(86362001)(921005)(82960400001)(82950400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t40nKXbEll/pv94uG4XiAhccctpehCFbCqcIMnI08ih7fWzKoIKLTtYjUURWuX+uTZncQVd5JGEtEAiJF9aRsB8YOvqVht9ARCeFMsVeTM93/M4jtuu9gjtWMLvJd8Hawkm8SOh8/rJQl3+ZrKheUH2Dcxk4yZnck8R3t3KB7w7UisukvgzPtB38IT4oEPObntCcvfN/nO9Isu9EgWnKjNgLpDU5pC/euDMA5IrpGHu5KxChoyjuDkosIZJnFGgT/1OMroJK+yFRol23yYHWz6AybpvOhmDg/7arXYnxTyC/HHTgN2CB3lDcQRo9MZ8gLQHZRTCJCfh0uq/IaKbW6ihdVW6o5TY2Ur6A2/ohotUlXXZw9GTxT07/Pcpzr2FnrqMSZcnWYLVfzWPCP2By4N6r/B7/ai5Cv8HJSW8dmpILVaTOTkbUjKw4hp/dFr8zMESffkdIqz+iCF5SNGMrL3xorUXvQZvqNDRKlnTN0Pu8VqO1139SMplvveKYxPQkDtjLadnZ8XtPsAd/KEHdDXccWhqaA+iroEvWWAq7MLfJKfFcRk5ZDKHPOi7gw6ijsU92m9vGAA4nNGQXiSWN+NuUMdqgZ5vRITTQnQAGYDDYgLl59wWSsPo8I8OYI4T0hUSMxuO9F+v65g1+9gCgFxQS1M5AUsyIi2ucK9j0s7D7guSmRY7YuHto4wCCp2EKavba1vXE9Z1llbJK6tZ6ZKIUJXGxHSRbFHXX2kRGiA2ZlPN14zHcs7SIxhSiXOfOpoTBGpmND4lS+G8b++tz6kQMWNfSmVgeppX2VM8a82nJdanPtvRBiplGUM+tB14p0XAzV6AqNMBCX5t66YY9ZmQmLExYRq0NJiYGTIUxfCb7gGVo10HpwMZpw5l4PXaksN1iSvHnms+V18njpkpEBAyxMpq7tl451xqVNW2LS2b9+U52fBSp5ujNW1NqzJH6kxRpvBTSrkBX12effhPNwsWey2UBCnxmZLlLLpRkjwvYeH/9yaENSGsSSPmZg/Yj30Sesnt71pqNhDh0Nvbd8cwqMFJuKWDZ53+3Ij5YOOC7r+VZX8Mdt4fi62lkontgtJCRM9WlM6+J9k9n+veCOL9vXeLfvAFx/zTXuxRs4Tq5Lso3Q+lwjSu2AcLfUVReYUTkcAObVRqjUcP5MD5U2VYqnuUdVflYU8hhlmJbpQj+huMTPTnT6xJO5RimagWf2ESiKpiklHalcLK7f/vPBbatJVSYTLBNvNAxx7C+9gjViFYXdtU/ep200CR3/OabH+62lrtQ255SYiseEkR0Y+wVlN5TWEo7HBtZqPHvZdXRyZhjrJI5BVzkCioc+YcEKIggMyrOjSNOdMM9fT4Enr6B7Ri5jKZj9Zq4Am3hBnOCX/SKTAq1R+znLc+8leSZs96RWKpRoOaURwZK71rpa3kcvc8RLCV0kddNDO/fdDNjl93taO0xV7n92dxtaQaOxCTC7k/ro2L/13ymHziG7dtJrMHG7IIYCMlRJWL/C2qMsaSfivU/9BL7lRnQ2gWQuVdLNwZKVnK70mXG8lN9Tev0S1U5BVXqxT8hZILu72tTOdyUJ1tfnYfiiPH+MIWikoFr1Gx7fqk43t50wRBgHg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1e3d493-6603-4beb-c515-08dac3ad202a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 06:22:36.4810 (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: PzwHSP8bHTjp0BSFZNcfnU14VY7geNXCsdnZdm4DoEWumVeLW6TaS9bxmb95rlIoiTsniDAMgo1P67arE/SfxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org For PCI pass-thru devices in a Confidential VM, Hyper-V requires that PCI config space be accessed via hypercalls. In normal VMs, config space accesses are trapped to the Hyper-V host and emulated. But in a confidential VM, the host can't access guest memory to decode the instruction for emulation, so an explicit hypercall must be used. Update the PCI config space access functions to use the hypercalls when such use is indicated by Hyper-V flags. Also, set the flag to allow the Hyper-V PCI driver to be loaded and used in a Confidential VM (a.k.a., "Isolation VM"). The driver has previously been hardened against a malicious Hyper-V host[1]. [1] https://lore.kernel.org/all/20220511223207.3386-2-parri.andrea@gmail.com/ Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley Reviewed-by: Boqun Feng --- drivers/hv/channel_mgmt.c | 2 +- drivers/pci/controller/pci-hyperv.c | 168 ++++++++++++++++++++++-------------- 2 files changed, 105 insertions(+), 65 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 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 09b40a1..6ce83e4 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; @@ -1136,8 +1137,10 @@ static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, int size, u32 *val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + int offset = where + CFG_PAGE_OFFSET; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; /* * If the attempt is to read the IDs or the ROM BAR, simulate that. @@ -1165,56 +1168,79 @@ static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, */ *val = 0; } else if (where + size <= CFG_PAGE_SIZE) { - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); - /* Choose the function to be read. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start reading. */ - mb(); - /* Read from that function's config space. */ - switch (size) { - case 1: - *val = readb(addr); - break; - case 2: - *val = readw(addr); - break; - default: - *val = readl(addr); - break; + + spin_lock_irqsave(&hbus->config_lock, flags); + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + offset; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(dev, addr, size, val); + } else { + void __iomem *addr = hbus->cfg_addr + offset; + + /* Choose the function to be read. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before reading. */ + mb(); + /* Read from that function's config space. */ + switch (size) { + case 1: + *val = readb(addr); + break; + case 2: + *val = readw(addr); + break; + default: + *val = readl(addr); + break; + } + /* + * Make sure the read was done before we release the + * spinlock allowing consecutive reads/writes. + */ + mb(); } - /* - * Make sure the read was done before we release the spinlock - * allowing consecutive reads/writes. - */ - mb(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, - "Attempt to read beyond a function's config space.\n"); + dev_err(dev, "Attempt to read beyond a function's config space.\n"); } } static u16 hv_pcifront_get_vendor_id(struct hv_pci_dev *hpdev) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + u32 val; u16 ret; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + - PCI_VENDOR_ID; - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); + spin_lock_irqsave(&hbus->config_lock, flags); - /* Choose the function to be read. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start reading. */ - mb(); - /* Read from that function's config space. */ - ret = readw(addr); - /* - * mb() is not required here, because the spin_unlock_irqrestore() - * is a barrier. - */ + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + + CFG_PAGE_OFFSET + PCI_VENDOR_ID; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(dev, addr, 2, &val); + ret = val; /* Truncates to 16 bits */ + } else { + void __iomem *addr = hbus->cfg_addr + CFG_PAGE_OFFSET + + PCI_VENDOR_ID; + /* Choose the function to be read. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before we start reading. */ + mb(); + /* Read from that function's config space. */ + ret = readw(addr); + /* + * mb() is not required here, because the + * spin_unlock_irqrestore() is a barrier. + */ + } - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); return ret; } @@ -1229,39 +1255,51 @@ static u16 hv_pcifront_get_vendor_id(struct hv_pci_dev *hpdev) static void _hv_pcifront_write_config(struct hv_pci_dev *hpdev, int where, int size, u32 val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + int offset = where + CFG_PAGE_OFFSET; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; if (where >= PCI_SUBSYSTEM_VENDOR_ID && where + size <= PCI_CAPABILITY_LIST) { /* SSIDs and ROM BARs are read-only */ } else if (where >= PCI_COMMAND && where + size <= CFG_PAGE_SIZE) { - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); - /* Choose the function to be written. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start writing. */ - wmb(); - /* Write to that function's config space. */ - switch (size) { - case 1: - writeb(val, addr); - break; - case 2: - writew(val, addr); - break; - default: - writel(val, addr); - break; + spin_lock_irqsave(&hbus->config_lock, flags); + + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + offset; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_write_mmio(dev, addr, size, val); + } else { + void __iomem *addr = hbus->cfg_addr + offset; + + /* Choose the function to write. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before writing. */ + wmb(); + /* Write to that function's config space. */ + switch (size) { + case 1: + writeb(val, addr); + break; + case 2: + writew(val, addr); + break; + default: + writel(val, addr); + break; + } + /* + * Make sure the write was done before we release the + * spinlock allowing consecutive reads/writes. + */ + mb(); } - /* - * Make sure the write was done before we release the spinlock - * allowing consecutive reads/writes. - */ - mb(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, - "Attempt to write beyond a function's config space.\n"); + dev_err(dev, "Attempt to write beyond a function's config space.\n"); } } @@ -3580,6 +3618,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 @@ -3589,6 +3628,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;