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: 18485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp572740wru; Thu, 10 Nov 2022 22:23:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf45RMEBWE7Ctlxp43JxePDOFjA/LOfenpRQjkOAO93ZFncQnQGt752kQb8SCUTdeDnOZpoM X-Received: by 2002:a05:6402:401b:b0:467:539f:b545 with SMTP id d27-20020a056402401b00b00467539fb545mr236520eda.141.1668147834857; Thu, 10 Nov 2022 22:23:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147834; cv=pass; d=google.com; s=arc-20160816; b=zFDE9SjFNNzvj82e1miAKluzNnXrey/2zeIEy8phcg5qv9+0U05llwNmxKeV8wtYQb W00vBM/cG4fM1vXHXuFwAJqtRIJni6tB9hkPDPCjo21WvDjfk58PCUDu3jrssNjCFxd/ 8VMcmsPoytQQj5aPpMRBvIeNFck2R87zt1dCrcZGPFieaPlIv/WYsXp4vxkDUsm8q8Mq TlNrKob3bm4KaaChONZtbYXpndkR9wKQfk412ZheYQqLBf/U5JhcC0MyQWdSnnuamNE+ 34JYfihnn4FX55grZji6ypVjRskkvX+NwvRolspuPMXI62npPo3LrOjIdrVY9x1L8gec xFTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gFDQLJOQVpUWkm3kDdRVko3vVZx0WrPkQzObAxlAqGc=; b=TFfm0dRyVfd0eTSBXBMcrw8ljfThdBQ/cH1+tbSKpFi1Mvo34c3bKjdG5C32cyu8RN uiPp80FjNYe+p36QR63tMkKyc6dhKVyUin0d5z3p5Ugfq2sGzRrP117D28FWAYVCWBqv iQVGHnsaw68HoWu1Fxci67kdD7V0xrZ7JdRVJeeNryOT5LjZgUl5RyatDtELHcCbib+H 1Rttn6+TIUqigWfPaWTOjysIpdLIFa3L05bABk41MM89pDTj5tb4ZMrqFHJE/e4yF2OT qEbRs3a56nlW0GDmnvruvqwkevpTjIdnB44BvzZuxLxmWaNmK2eZsK4m3RBGFy87wOpw LuBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=WJOFgTUj; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a170906975600b007ae8b1704b9si1481878ejy.406.2022.11.10.22.23.30; Thu, 10 Nov 2022 22:23:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=WJOFgTUj; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbiKKGWh (ORCPT + 99 others); Fri, 11 Nov 2022 01:22:37 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179783952464471?= X-GMAIL-MSGID: =?utf-8?q?1749179783952464471?= 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: 18484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp572568wru; Thu, 10 Nov 2022 22:23:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf7bT7PHKm+MviaQQmT/drYXVkFx/zE/GoP7yN5yT0gzYU9/FRBaaqGcpFDaJnige4BV/boj X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr740090ejj.236.1668147798772; Thu, 10 Nov 2022 22:23:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147798; cv=pass; d=google.com; s=arc-20160816; b=y7trI7nNjYGV0j8U2Slw+6doIG7biJJD2NqXbpCZVBh6SPyD7J0TU0QMS7sgWhPV62 Ksii8qldUAws5Tmvkn1mT+gc54mfJooAIagMPGVwudHiR+NjWr6Cj/OLyqg7ztjZpKKq jJ6dOdFcJxdn5adBQWWziMmGjqpI+rCUfQlA6pTW9pNC25+E70oONN+UiKmzUC9qkwG5 6x69i2q5XGHjnpB0JYE0a5VBKekPVuxHBl10fqrWrWBJNCGbB1EewtEHHgcrmNdG1vh1 Sl5+yjqOUf6ExTxt8IzxP3AyO1APJhzzBwNJTCaRoik+ZJ3IQu74j5zvt6vZpJyFrNuD Qr0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8OcaeMt/u9wYn2yxcRzom+6u54BPUvchqecBRIxcVm4=; b=kWCqZENnl9kGYiClfuDOfYNQFo0TEe4TP4Dj4RR5bbYj7vMRtkQ1KhQz+Qmieudcut Aqmk2pKKUz+Ea+LK+4lFO3lsb0XKlKASp/sY+yYnIxAXuGauMrz6gkGDbiLDxxRqp2dO Kan2W+MSSqTZyBMG4Lj5ptmwpzlUECTdOO05PjpToAT4IaqakhxL9k17z4S5bqIU45Nj yY4/Pmn1gQY7NFlkW+pcpgbFcOBEpoT310nu1zYpJobf1iTu2NUd7Mm+lYFpjIERewFo Oo2ZseqS0+n7EQACW2Kk5YKi6Nh25KzVDGJ04xjGuzAmt8Bt6m3x9F5XO1sukyn5H1WC msdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=H7WU6C6O; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a056402270800b0046751bddcf0si474209edd.425.2022.11.10.22.22.54; Thu, 10 Nov 2022 22:23:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=H7WU6C6O; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232837AbiKKGWa (ORCPT + 99 others); Fri, 11 Nov 2022 01:22:30 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179746221649761?= X-GMAIL-MSGID: =?utf-8?q?1749179746221649761?= 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: 18490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573441wru; Thu, 10 Nov 2022 22:26:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+DvIoRmQrM/rUzpjJ75ju0LyNhnYKfW6PEeucYvrK+hBFEbZJZPzPlTq7xQi/6W+L4IJk X-Received: by 2002:a17:906:9f0e:b0:755:6595:cd34 with SMTP id fy14-20020a1709069f0e00b007556595cd34mr810726ejc.70.1668147967705; Thu, 10 Nov 2022 22:26:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147967; cv=pass; d=google.com; s=arc-20160816; b=YjFtMLgx6YNrpB+tEqMjgNL6A0xvzQCQtoED9+8ZcdwcVwIVuW6mKMZ4T1JaLJAiU1 HaAVv0UVT9OAvktBYRqat1xDpoEP6ce5Xf4fuhvBLeNYaosvQTY0RDEFF9S74IZyPBM4 GIQ32gMy8WAbTcPsRDr8x7eZG+nd5EDoUEziC7Jwci3m9aR5T8ZseYMnRoUJyIEqjmg4 SZOEZrIip06c3SMeiWk6uAtyZQNUoKyoJMcAFJ/PPkTOIM0zLhu4WqFtleK7TbcpeIS0 7JZiuvg2QDytP4+ohAgVoWJvSFNreXH0yBBjn+wInrVUtpkB9OSRF3U90SwxmRlt1GER NdyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=My+3F4xeoCZ4C3uLqj81e5Dg1XL4CiWYfO/yE8xDujE=; b=tg9TkxlP0wiquqrtTbV/P+yhgf/IqQT6NYidxRcKvaWNlYZVH4NgP/vkkldwkd94wZ Ty6y2/er1UPkD8/0lzaCCLc0ISsPg8GeM6dKQN6kMEpV8pYoLDjyFESB4N6+5l0D3bDw 9RukUtbgqSZq1hjKJBxy+LyWysXUaghZW47FA+xwonLruUY9rrmPEauvuZPbbFPlfUUV 1YS/kOgUukihIQzzsS54UiyYUw9wOQnhoUUtft2N105iPG4Jehwb2+svwVd7+L2ypKbv 4hewtmXeK7/SxO4KM+wth8psVxj2WffkJYV8ZyZHkmbZIXr9YsXe+nPm24nIgB7Pm2+Z rhRQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=XRhaIDFi; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb17-20020a1709071c9100b0078232bfe3a0si1487373ejc.331.2022.11.10.22.25.44; Thu, 10 Nov 2022 22:26:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=XRhaIDFi; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232933AbiKKGWk (ORCPT + 99 others); Fri, 11 Nov 2022 01:22:40 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179923555627068?= X-GMAIL-MSGID: =?utf-8?q?1749179923555627068?= 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: 18486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp572986wru; Thu, 10 Nov 2022 22:24:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf444qmezMBE9JgVpz1uozQS4bmv2envTt8ABAeMIRs1G30xYyHyfGQ2yJaqxrZM9m5xFKHP X-Received: by 2002:a05:6402:1acb:b0:45c:8fa2:8785 with SMTP id ba11-20020a0564021acb00b0045c8fa28785mr184657edb.332.1668147875632; Thu, 10 Nov 2022 22:24:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147875; cv=pass; d=google.com; s=arc-20160816; b=m80Y3kIto0+xukVlr3wuMn4defu6v6qk0lxBPz9pqIJMjUZKggf/+nVw6y0j09yZq8 r2cfCkQepqJ6/7QxPhmEjWzawwAtUd85WWAWC+0OX6xKUwMgYrgKZJ18TiQK5AcyrdQe STdMAK70wpsxcbVZR+9jXCfLDcdWe6ooTTwk+4LxxWWsmcb+bExa9MkuErqFrjZ3mr7T RCKCbf7DtFalrUz6PoS5ZSngn5mY7j/NECAFiFO4Ok/jax4OArd7dp2Mc73s1FUANrYz kzdG5WEhvDgek4eug2O/wD/HhZ7Frwm1SZdmfWjgBE62/FpTkdefxn2173CLdjUaim2q 4hLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=a+yUY1oU7EZvlInJkWwCVnIM5lY35B5anu5GgTI054E=; b=XVonAwiB2PsGXRfj/WFmZ6Gjch40352GXsTM7NyASbr2Hy7GHkmk9WyEZx0Umuty2f sLqOPM1om5DdoDtN7dfy6vrLym4D2qDjurAUvYTRozTPoUR35xT2lvWUrxD4vFFSFwE4 7bORwYEAAOFwqd5JfnGAC7DA+bZaPgB28lpX5KhSDW8fLk/FDVfQb+s3eDQr+RMG4sgb 0nk3+wKg7szvbE5tpP8IezXgIlMmIklZCs7VePEFTquGFGHjdLjpoQ394BQf6iHDZ4cN id4HSJxGKDFG255D3ZXyLp+ZS7yhpup1TrnL+g+q5ZvHeYHM5zufwjtNQYdlCTRBGrk/ uLnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=E0gtpm1E; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a50d0c5000000b00448d387c327si1495709edf.181.2022.11.10.22.24.12; Thu, 10 Nov 2022 22:24:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=E0gtpm1E; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232963AbiKKGWq (ORCPT + 99 others); Fri, 11 Nov 2022 01:22:46 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179826641784443?= X-GMAIL-MSGID: =?utf-8?q?1749179826641784443?= 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: 18487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573105wru; Thu, 10 Nov 2022 22:24:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zqRfX+LE5jKtQ6WZie6hdmRyX5IOYkb7EwwOYZzjFtDVCnAGxpQuW9rTkeazPKTsMM59Y X-Received: by 2002:a17:907:c243:b0:781:541:6599 with SMTP id tj3-20020a170907c24300b0078105416599mr765003ejc.45.1668147893265; Thu, 10 Nov 2022 22:24:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147893; cv=pass; d=google.com; s=arc-20160816; b=cyj9P0vztwXQYolmNh0TTf/oNAQ5oe5mLFFPNnNxUIvcfd5wk+qpYguvaL4EKgsnf6 5YGNKZOaM4BEl8kAGYUxNwRp5ZJf05slMn3swdksnAnRYyUcsMg3gM9XZrzTvzWISpoI qBtquCe16g4DyJ1/P8bUV8L1sZcWmi1HSgr+An+dj+qlP2nGmA25egpGSdyGBIGlgd7w CExjC17RgIOqNJgGMKYRZcUWCf0+GFBKJYDazyZXNtGD4vvpCIX1A7yVtq10uW8r0eF7 Bhzc8JLNERReIBFX62l9lxL0gb4kvy0RZdlUMvUKo1FZNzG7lAbV0GAKSMAuEm1gq2gN d53w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FT6d4qwlnktmpmC/x/vNnKUNdEG3IaM/xrJmCwikmAA=; b=oyV5d9zDgrDgK27SdNzfNENbMAbWABVM5MosaIYh/iL+ymMSDGziv4rYoZkwJ4k5YI lMBpYBC4sNdjY4bcUzuMm+IuWyZMKic9kyuStB7BHsv+DKPSLzEkyYeebTn91mlQvzGd pJdJ8ji2I9Y2G5zF+y2EA8htP87nAoLUrtGOXgj73KCotZcWvsho6lRtdMYzeEv3ULDV Dt1YjYkjbArXcAZSbuIa3zfGRNt2xc8R5VWHyfq+vX+NRUWjXuMuNe/SKY6sks4EFhpA lp+8HZLq/vkV5ZD/B4HqIN+JI6w3Z/4PcZ2uBD/7WQRxs2oLCslpdjH7S2rsm3U/GODJ K5IA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=MmT3ryqb; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg6-20020a1709072cc600b0078c3197bf86si1617318ejc.533.2022.11.10.22.24.30; Thu, 10 Nov 2022 22:24:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=MmT3ryqb; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232969AbiKKGWw (ORCPT + 99 others); Fri, 11 Nov 2022 01:22:52 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179845392151940?= X-GMAIL-MSGID: =?utf-8?q?1749179845392151940?= 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: 18488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573172wru; Thu, 10 Nov 2022 22:25:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7rKCf64D71pnHJwkoL0dxySV5C8VhGG/21pljXAfZZtsansdNZWbYJM9sKKby5MpYXn3WX X-Received: by 2002:a05:6402:184b:b0:461:7f5a:e04e with SMTP id v11-20020a056402184b00b004617f5ae04emr164541edy.389.1668147905479; Thu, 10 Nov 2022 22:25:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147905; cv=pass; d=google.com; s=arc-20160816; b=CUloncg3gxbA4Olli82q2V8cZWiuJQLcOarKkf91JyLR6nhg3HHnloooWJbMxiSMVY B2SzMBbMjirvOR+lw/0uPel5kDdJNqGwjQOJPwh4iDTwtaltE1LcugVGxnDLjc4QJTr9 JHh554216E9Gj3gshL3wHO/kToi5XGSGmzWPOCf7/4KpxAZbq44rCX2uszYa58K1GcpW oJTcL9bSqCqeKXpRqC2+StHuN4fkuuIFQ4wAC3KROD9PBiAFub8TvXGVCvw5j9mSlnNo D0ejEVEw77CxhKofguGPd+HxC0nMsKkOp7Hcwzls8j7AlaFfJ4vvwl+tG/S3haR2vXkt 5IVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rS+XEDLCYXK3kG0pGvcV2b4OXTcv8/63SxxK34hw9ig=; b=NsrLx3OusKnREvHd0DZP47jGV8jx7Pr/IHd398GiUX9oi+90kxc/V0VzgZNz9COjLo MaFjFPYARXrXeUoqpP/D4u4lXxeYoKY/Dliqx7V1MuPC+aDShpvx7v1J24uQrmhQwWdZ CCQmRY0LiDaQPFQoOiX/gknEoyFRqCnQdCDj9BwkKlYLRpk8cDimUcPRPuJEkLe3E07I VRFTMhY9SOAy+LFPzs1rLeOoNmSkAEc6/IRJRkUsLRepdw6xSiHzGHmdQr81Nb+5SoF1 g3MUjRyT/JRuggDnPl+cVRYJ8I8cnFkJ54z/OFx8aC5N4HRWV8n8A1KCbd3Mvg/plv6y CmSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=dkfcZQMZ; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg40-20020a170907a42800b0078081036bdasi1160295ejc.501.2022.11.10.22.24.42; Thu, 10 Nov 2022 22:25:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=dkfcZQMZ; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232978AbiKKGW5 (ORCPT + 99 others); Fri, 11 Nov 2022 01:22:57 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179858129378543?= X-GMAIL-MSGID: =?utf-8?q?1749179858129378543?= 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: 18493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573792wru; Thu, 10 Nov 2022 22:27:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Gd9bzNU1f32ARIVkdsmarQ98U/8Fk0Vi+iMVsJAMJ6xX38RkWRrD+b8DJULN6xVrKPIqZ X-Received: by 2002:a05:6402:1944:b0:462:d288:16f8 with SMTP id f4-20020a056402194400b00462d28816f8mr227770edz.170.1668148037362; Thu, 10 Nov 2022 22:27:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668148037; cv=pass; d=google.com; s=arc-20160816; b=bxL9zqRHXyavY+iugMObg1OA2dbcrHksNCWWaXLdV/WLiZQQAxjaOh61Qk/G/y4Cau cHtPeCBvLHm+T7FpMHOqB+mmB/LumSrOVcP0OgXfqk1409+79icyQxsYPDaY6FfcjroJ fxPd7nI67rPMHG/yc9hCAD95CQgpFmm95q9/v3JBCiL4FMH8WhX5VHTEieOnmKDPfIQ2 sk8K3Bw3n3gSswOuZTOs5puA6OXJ+vi7xRWpiEmLC6NoFdQ17mrQV15vNtm6JhL/4JSt ThW2wmXtkuQbkUo5dgtEKN0z57X/yab3yLJq9dfGnK5nq/UfnAT2uzzWpVofqymv1/Tw LEVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xgm+jUaF9HijpG4qFbxbmrNC62Z56ETkSKfonyRpknY=; b=o2Q9VnO9YZrlWR9g6BWukpZPZYQ645P+d2sdYcOs9b1vf+FlfXGMKxsSdJ+Z9c+413 msTUHj6xDcuoRHUdv0eB40A9qbHQV/5XxnMkEirD/98cNhiSYXmelnxGhRnd+DRdyeYW ZbUFrEM3SyvMBID50tsEWjWFASj1nSGKkO5GrkZ27w/9184rGTKhItI9lvQwiw0tzcpj 4V1d/re5jHQI8LTnY7noaePIMFcNNHNeJDO5gKxdSIRIu0pOukjqrCfz+PgBmGjy8Plg qANPQsw950jO72M9Gl4JzM/V44dGIc8gLorjhNcSqEVUx2AwoeiLzHKoRzrFPpQgI3dL 0TBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ToILCqhe; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd11-20020a1709069b8b00b0078d4cf8de04si1395371ejc.380.2022.11.10.22.26.53; Thu, 10 Nov 2022 22:27:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ToILCqhe; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232986AbiKKGXB (ORCPT + 99 others); Fri, 11 Nov 2022 01:23:01 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179996503974079?= X-GMAIL-MSGID: =?utf-8?q?1749179996503974079?= 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: 18489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573429wru; Thu, 10 Nov 2022 22:26:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf56K7r88C1YLxAsu97nI32XH1thqo/052slJM0a8P1OKwCTB/OiMBevKiDVSAtA4ci2P+0i X-Received: by 2002:a17:907:9c08:b0:7ad:c0e7:1242 with SMTP id ld8-20020a1709079c0800b007adc0e71242mr727213ejc.334.1668147965104; Thu, 10 Nov 2022 22:26:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147965; cv=pass; d=google.com; s=arc-20160816; b=dTgBV7kFMOeCx8OauD0jgX5qnQHCEuBjih6kbz99AgSJLGUuHErNIA0avP54skU/PD lsUvMn0MUZr+KIP8oZyITzqCMRoAwsKM+0aMc1Az649UBCaSzXOk0Wf2CecyVeuG3usX MzeFev9jAKi0lJ87mU5qbrERH3lbtGRbj11qobBTeHgN74J0/rdfe9zM3+/+I4n+uQ35 eEuaNj+rK8FDy8hRrYfxiDpiUuSBZVSmKcqJSt1yKggvpuao9iH2dj2PWMYnpnoGWPCq vX073MC0tZY+y4trT1yuSSmHBltSJI4z0K+hxSgKbYDNoVIX+BosJpausmOxMCc4wfuC WeOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ukiq3mpmblNcB6SjkymwPbJw8wM1j3J+T3/kZJCLbMk=; b=Zp2+riX/hFMuPPyaMbbPLRkEydzwKK/bbWGVMI+SPxv0QS/VHXy2ewcUAH5drwHi1I /g9SLeDaMWWhY3AQAID6I2S2IXf0b5UdIEDviW9iRfNEF9lQMtE4xVO2K5VgsCrmmdfD Dss//Q/x42HaX55HfIO6DO7qDQkCww0Gx8BT8za1feKMtyKgI6zibz+XMdxFPumcKhM3 v0FPbGpQYhxYFmbUTEJAFibmbSEzYgxndjv2piImSsjApRwBoHLdQXVERgcvGUV1CZ9N Zs342eSAvawRSPw89nf3SQY3dyjJClPqaFsfb8gVGVpDBEA9mTJtis4dtkcUpEZRW9Zw TZRg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=aXFyNhJi; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020a056402511300b0045d46f28533si1854370edd.377.2022.11.10.22.25.41; Thu, 10 Nov 2022 22:26:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=aXFyNhJi; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233033AbiKKGXH (ORCPT + 99 others); Fri, 11 Nov 2022 01:23:07 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179920764001348?= X-GMAIL-MSGID: =?utf-8?q?1749179920764001348?= 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: 18491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573507wru; Thu, 10 Nov 2022 22:26:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf50XvjBYMrrh/RxA/wQL0m4cZwFKKAs2eBZBoc6LOlwyMwka3nhuK5MEkJa4KeZxEUD6r+e X-Received: by 2002:a17:906:3ace:b0:7ad:9028:4b17 with SMTP id z14-20020a1709063ace00b007ad90284b17mr758305ejd.366.1668147979924; Thu, 10 Nov 2022 22:26:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668147979; cv=pass; d=google.com; s=arc-20160816; b=HNuT6NqxuqnDe2YuiG8W8ZhqxeBs9dd4zMNiM3LXAm4NxRmvGDTI8Qo/pjEYV23pt2 MmSHPJoa6PhL+lBv+SfORL603BG4kLpwunx8AagDCvZkoQPzVYqbFAFwz+NEIg0D3Kkd j8ntAncWwR6MTo7WQv3XiCj2VCuHJSOMGOYeQQPIOlR0S4bdbiyQ/fjGaJEAAUjq08lU SFAkAhzlXfmbv3dW9OsiEt51wrveVMQnymMM3c4e4Tukp+wLJxWBn7mGp6Z546VUAcl+ k+W2XIxA+too0nzuZN8tTh3RG3SGfGORXAMeiAzngreFbgQUi76UCPMX3pp43ajVYQBY RmOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uMQFfu0nvpSqyQBcQ+B8fVzRzFcxDk9HPFep8luloWg=; b=DaRIcBl5/wCioiqwfubjKSOOKTDbeaWfMmjylkPNT4Q6e2tYyKZexsPyTgm04lHIUF +Jn4mfkXbY4UN/9tAzBD/8IGomYJD71g18+zogOOehX2R5Ve2LNI2JbCeqwR5b6mPLVt zY7QMnzuUqHo/mCvkHZcb0fqG35WnP5wnk+qo9ygA77sBzFLYchH4LayDGa3v99oC+Fv hpcBaO939LNaP/xryp3e79nk++ZA5oKAyrOKkKtEBHJ/CYBxMzLQjzRY+Hvrcx31iplb 8CWf6cVh5gcY5g4CEGUJ5QHiVA8CXSM+S1p453wVqDefIakEBog26qVqRl1TGggfd77B LRyQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Y9bLG2rO; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e19-20020a056402089300b0045cd10a4c20si1488861edy.321.2022.11.10.22.25.55; Thu, 10 Nov 2022 22:26:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Y9bLG2rO; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232912AbiKKGYm (ORCPT + 99 others); Fri, 11 Nov 2022 01:24:42 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749179936208715318?= X-GMAIL-MSGID: =?utf-8?q?1749179936208715318?= 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: 18494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp573907wru; Thu, 10 Nov 2022 22:27:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7JbIu0TkwehvFvgBA4aYAzLtuFVnA/wh+4DWt4Y30oxjMfvbm9BspMZNAPkz2VRgPl2omj X-Received: by 2002:a17:906:e2c4:b0:7ad:dfb5:a3f2 with SMTP id gr4-20020a170906e2c400b007addfb5a3f2mr739133ejb.351.1668148057331; Thu, 10 Nov 2022 22:27:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668148057; cv=pass; d=google.com; s=arc-20160816; b=1IyqqPHWwr1DGP7lQ9hIUZh6IsMjRDLLV7+NQf64SxAUck8+2abtiRpY9fnsTVZP5I mNi3DL4hsyvJZW6hyo5qxnmGj67xzGyss3OH7H+IpCIVrfuIukJh9CR96OtA/oRHTBSj 9FCv3BnjC7hZlUuG3G76EnjMa2dNbFqXWXldrq0KGCXNSoeoc4Ci7iFGg69ki3//hPYZ KLOW4+JTZK3g5PMN9Y9ssZChIlSoov5fFZBfmuloGafnQCLRSkxOeOj+Y597x5G2+ouv +XxUdXCxGLp4aebhtDCYGKHbg/JN0xrBWbJVLGRYZ08uqMqfHbFoU4OYQ14BGEr2B1bU faow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=85+v0DH+3mlkLMx0kKGVKEBUtraxUVOFMF0rnKO4Ujs=; b=WVC2Lg3XjOsbhnV5Mcc6oz9ftxXLYRQHp+LM0eX760PIw2eQlZ3qBOP3SPWzbKSP35 6Hq9regUlYGqghu7Ngzxh1VxQ0vUqK7g2oy1uybgUV5e2PznjgGbWVaF/+3HqDx0VAJI VGB+/2CvOdgOqwQnHtzvdXa8t+c6uNLcuLXwmFepy1FWxCePmDQ40wEFBYWBpgZa9GRx DU8RghyKthvQ2y1HlcuTQg9whBEIxjPuTPmIHS6EXQQmpAh+ZjcdM7LDUuBz83NQbTeP rWQVqFkT0rLQVroJLb7g8A4Kfl0SCalwbONJ6KJ/uSGdtJizZMcH1gOoFMkK7Lys80VA VwWg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="dD+2/RWG"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a05640240d100b00461bde34a12si292476edb.627.2022.11.10.22.27.14; Thu, 10 Nov 2022 22:27:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="dD+2/RWG"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233130AbiKKGZl (ORCPT + 99 others); Fri, 11 Nov 2022 01:25:41 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749180017448594595?= X-GMAIL-MSGID: =?utf-8?q?1749180017448594595?= 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: 18495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp574059wru; Thu, 10 Nov 2022 22:28:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/Ln97ZBP7CSnCr8M/Jcui85mVl1GqtAQxgSAMO1lpZnPT9tsEelXsFaDkCnPe4ro3ro8G X-Received: by 2002:a17:906:2f85:b0:7ad:88f8:7621 with SMTP id w5-20020a1709062f8500b007ad88f87621mr730924eji.211.1668148090696; Thu, 10 Nov 2022 22:28:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668148090; cv=pass; d=google.com; s=arc-20160816; b=zCRhxFmBUpgPWRbFz0HmTCxnTtJ8gq5i7IFsGborylguHB3lhZWBwzFtamAPTgcrYO 9lpRVesYCeEBQs251JCW3rYNKGYi3At0lCjYMxKNQuQeZiD3c0Rfd3waUfSLk+jVRV3/ Z0KVnjvuDMaKjyBvjoXrelVAWwQvba+CkFtYZjzcRa03UKdavQeL73uq57WL6tLW8OH4 kEFh9/Y8xXd0K7EnWy8NDD/L5mMJN8f5nZGwVifDa0Mu5xOf3sY+MpG9302t8UqMVo7e Qt4VoJHtLYx6+ZTnLytzPv8nWrOE9cznnFAOjxqZYDh0ovzXd99T4Edl7fwLH88FJiIB aQsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uDBf1JoaWPUpyxNyOQTOg3bA8mI88YgxN+97JsIj6Qw=; b=l8Rlot3h7qNZxAc3zcuWm63ao39SOE21+VbaJxtZ4oLwT6RjDLG9xpTS4SlVEszUKm vq51+U1QtCCyE8SgGLcYZv9AGJM9wDLYp/LdToA4QG4UkatW2T1Av20bIgjaY7biUZRP af5OzAX8QqUMSG1IB3hqAeHiMYnn5iOm/DEb6bSU0O6vOnQsja+SMDTiBDeXeEdh2hL1 tzEKI/2lyRCYX205/wumyFwcfLSV+EYCoDCnnoBwY61G2nSnw2TuiF4FeIKDHdJ1Xw8X e4ZJSp4je9N0j0UareMHilma2cuT5pFtswdL5pZXw7AMU0OOjijkk2sApEcr6TOGq7aH J18A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="V3Z9m4+/"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a50d0c5000000b00448d387c327si1495709edf.181.2022.11.10.22.27.47; Thu, 10 Nov 2022 22:28:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="V3Z9m4+/"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233084AbiKKG0Z (ORCPT + 99 others); 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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749180052067366991?= X-GMAIL-MSGID: =?utf-8?q?1749180052067366991?= 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: 18496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp574312wru; Thu, 10 Nov 2022 22:29:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf57FXsreNQ+shGs5qKVOPuFrhLhIt2Y550Ce7zBo46uY9+1HU4JCaOr+KWaMTFpoeWnN9kS X-Received: by 2002:a17:903:41d0:b0:183:ee9e:4988 with SMTP id u16-20020a17090341d000b00183ee9e4988mr1285447ple.56.1668148152714; Thu, 10 Nov 2022 22:29:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668148152; cv=pass; d=google.com; s=arc-20160816; b=Xb6JJhnTAy10nyPefdd0WGL1qZeC4BvOEdgLPy8xn072ugqKrfPOpufQiD6NdGgnUe 9KO+Agt4e0Aey//K8fyFN34W2DTErlpN90xg7n9ZXdLR/oEcqpSu0EmjHHdmNkdz3Btj X9uF+FYjso0ZqZqQF/VEH3CnO7zWgU/g3YPC9Abw5yubvL+cURlZ8k4aEXsJkStPO8aO v2dXE+rnzuGU4uL36o0t6lh/+F8jsvThZQR+0W09YNT8prXEB85LnHCg/PmDu6mF9HtH RojdPrmYStreGMHlTxDdEsZr9WjtKQNfWwJevgMcfjD0iBhRFEXVQB5Xyf0S/zRXcQqs h3XA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0vfRKktGtusAn2CuHkYy3SoKI+4YG9f3c1x8BjXPr9U=; b=tZMqjgjzOPV/Dzc/YhLWjL2vB4fbjpb+RGSFKbdZLUDurwhnvlbCa7FA9xE0TNSYUq yh5VwVpBvUmrenoTcpejnDymwXhRKtsdUT0pNRsD+6lkShk80SkkJtKVeCMdE2BOXj0Z /nP7peUzdFKSZGqzeFsc6NB1NfCqdBl5fcopgFbSkZnK+9Qd1Ir/b70Yd+fBpCHuI+i8 0G0NMP2+uGx0SXE7uSgPf4C1aj9f4GjRrC244ENMtpLoIm2SmNIGzK224Q36PUVc7eki DmGTR4fvC76q9iMphR2ikJCeqrsvkovFclJCPjqHSKIpMA9g9x7NEsHE7tF8a9bqN78m BYVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=GAV3oE7v; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020a17090aab8f00b00205daac38absi1618692pjq.59.2022.11.10.22.28.58; Thu, 10 Nov 2022 22:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=GAV3oE7v; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233136AbiKKG1O (ORCPT + 99 others); Fri, 11 Nov 2022 01:27:14 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749180117110978483?= X-GMAIL-MSGID: =?utf-8?q?1749180117110978483?= 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;