From patchwork Wed Nov 16 18:41:24 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: 21217 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7122wrr; Wed, 16 Nov 2022 10:49:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf5UlXOZ9T1BfLK+zUv5sjs/MGGAv5WRRd6Y9FcJCGTnKeddz3Moe16fkwgdGjzkMfI7/mro X-Received: by 2002:a17:906:458:b0:78d:98a7:2e7 with SMTP id e24-20020a170906045800b0078d98a702e7mr17274430eja.535.1668624588207; Wed, 16 Nov 2022 10:49:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624588; cv=pass; d=google.com; s=arc-20160816; b=ianpF2fi/6mDOrlGXhdc0vG97Uk4XUDBAJWOZa4EEYxoQiseVG51bzddFuKqfg+Axj DHie32hq2sgnNk/VBtnXgdnpi2QxqCmYzA6Hy8EXPapVCJXNvoCqKmX35ngYFAgmQoMd acYR589+zsq5ewng3pxzudX1sVS6IiMiqpyBc9GrmIG5/DHMKuadUnZ87Uvl64PTppRq Pl/eiG/uxu0qXT/vUXNGIB2dQmRhBP9b+P3Cr82/AFZqDuaoLGryUVwM18OPDglBCtw5 EHv/XRBFelKBxOKQknrxlaog8O2gFsxteOwiCv9d980exTua1XunhioTbj39SF0fWVxk bs7Q== 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=455p0PAhRjkQDFU3d5FTc/8biS9vVijN2mB4Ou3h2T0=; b=Jtzg/VKzLKN6bdhatkzrQhE1/F+pTgew03kKMFpzTyvIoaobY1i9+SqZWi+LE/w8KA dNRbvdRjQnLT6ldgaSw4Y+GREGL10/inEiG0BBKlWiPDuwKXWQNFyD5w3GelCod8pjDt 2xOxdwx0tow9D7wTJ2za5Eq0pyxzoZjJmTQO2gVyS5g4G1dxhrTknza/NqQRx7rWKel2 xj8STcpScIKKN9cROmZlSH5XczDrmVZcqbyO4N044/PqGoHHAkqOsB7rqhKFenmCxsOf 3bHLZHKoOe2vrbra0JxnCaIblZYzfps6MfiE+lQoxiIr8f1yJQuww+c/+0eoz+eylERq JPdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=dkMTWkb4; 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 q21-20020a50cc95000000b00462af00c12bsi13381826edi.398.2022.11.16.10.49.24; Wed, 16 Nov 2022 10:49:48 -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=dkMTWkb4; 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 S234406AbiKPSmf (ORCPT + 99 others); Wed, 16 Nov 2022 13:42:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230205AbiKPSm2 (ORCPT ); Wed, 16 Nov 2022 13:42:28 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022017.outbound.protection.outlook.com [40.93.200.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3521D18F; Wed, 16 Nov 2022 10:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EBvuciUlUFkMOLbeT1laddt3/Mn5qh9DCIsKzV9a7hGQ6tdqRJTRQhsYKG/aDYrzSY9lyIO9Jb0DobeF/InVOOqg5HZgq6gmYeTGDvnTwXzPRgzSFtcluRStPrTqY6Sp3LTjlgZHBEwL8ToC6HfvyotdWccNp90iiDlizFy0Yjxf3qr81SW/lb9912B550eln6mZhH1At7eb8FXFo0RDzuBBXgPLvL7s3rlheqSC2qS6sjbvJPJKOXbVo6eCWRSMv+1x5eefpi2VslVCIR7DGC5yvuDogL0oxYOjqJ1pS6ySefbiYwjmcoAFAsPjIBZtnrREPlyW4UaSxenWyqOR1w== 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=455p0PAhRjkQDFU3d5FTc/8biS9vVijN2mB4Ou3h2T0=; b=ZHIzP3SdSnuqPgxJ7bbNThaEVBATrwhozDJ6ER2nNOketOb+/V66Gltxni71YHqP9WIH4nE8XUfOFaMmd4fuvUVHRtyU5bZL3UF7VqgdMA4V8fcY5Ei45vDA+ZtrVau+j8ZXJd51rJBUwLbtw85BPFtCFl878sk5UrMt0pDYnXXuboI2GePIVCKfkAieI+AdTJI6Bu6MPCfpwSTjQHqQ20KZ3wvgMIhP2iKW3GxsCHiSGQ6jSElPRL+OaaXROhdGd9S75v9UMxT1obu4YeNTFYkLtZyELZ/A0U2eV9t/lmioUURDPVJtRQu8ALLCAadGUOsz+kpO6Uid2eSFEXSaQQ== 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=455p0PAhRjkQDFU3d5FTc/8biS9vVijN2mB4Ou3h2T0=; b=dkMTWkb4Tv0GKUYJGFB/XnCgQvkmnXqF2iELY9xxUEGOG/AhvaQvn9MVp+oY34YlOx8Fjjez0sqi5jDsq2aeMVrDpCNu8cOGZq4nyojt41+SFjjddrq73GVFs+yXh20Ub6Vt6qogJjUXwznJkf0SJCSaLzXGyEX+ritcF+Iz40E= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42: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%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42: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 v3 01/14] x86/ioremap: Fix page aligned size calculation in __ioremap_caller() Date: Wed, 16 Nov 2022 10:41:24 -0800 Message-Id: <1668624097-14884-2-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: ec1d932f-cb78-4508-9519-08dac8024d16 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: bg4Q4tCcZ2sC3QD3sPJrQbVhUJVzbLIaS+Y0MZqh59EMDBJIfnnQzSnXpOMtH9YBN85zhGKZCmOAD8dGea/K+kJUuvf5IzThEAIs+3j6LGliEQLSAapJrnNB7qaQLlhQplpTX1SPuqH6QgJoqRUJFSyMQT09GneHO9vLb1WC1WlF+IJ+pAGF8MirRvDT84Vpn3H+pcdHFViro+pwb/YR7ZQ5sM5x+iC9q+GaomQO7bMTAy5yTXmTzi4mgzGo5a/CoODPcDC7TRQhA04JzYTiSKi7U625uTnKIHB0+PnKai75fCK151ww4jgSJpKcTV15jrjfMLgUVBmk6vsdSv1IqIjIdS8cfeoT8duU1t/2BmRhSWPChMKuexpZ4aouvQxEATps1i2NF0HUXz/A+tdJdY9TKaYC1GJXvHdr6e94HPGnDXpaPdYRO1iX/sgRewjZL6Nlg9qDsRz36wUckGgbaM4JoXdyHVG9crE+dgbdAxU9PRC3gxhg9oj++5/4UHiZhmt1tvtTx3C4cLjNOwQWNqcAr4kmbDUcaqMFNYtUiFhZ9zks+eQlfTvN7hJq4jTvrJTtqmb+MgPEADdXwBo1i8BKG6qG13DJchWHzevYG+s5uUPX3YyDbw6pDxa6295K93WRwA+sntfoI3uHiLOlENQ3c9ei1ZKBh1HrXm38poesWzAvtzTgy7QD/SztJYipb5JjgC16tTkLbk7jD0yQwR/qXuZK2A6s0DOvX+b3YiG/r8/E21rT3fhVfOS0tCi7/4TC0e3OFkSWJfBLHeg7Dr3FMDHnLZKxf+MXrlVDfGROJN7blE9HiZeNKe/g1csE 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X7GBVXybtAAG1M/A4Oydcn05zkMcKGT/tl6zb7KgeS4zfl+Uo6ECucz8uJ6UDzFgKqqed3IbShTu4LJUDeFJ70gUxrPPQTlJPlLaa4MoEXAtts/Mcvzaa72jVMewSLSZXNQHHiMU5Y++CxXGtyg4SWRxpS/3krTLuzOUWc86Wb3kR2mZ/YOe+WJuHC/pV1Wpeq3+CfS51caD2eejzaPGjZHCovsZLKbZIJlfzl2deB5fXG1LzuVHtSxrtS6q11jb6dlZjjylgG+eCgdzajewUY0c4Gi49B2/nhS7PxNui+MXoQM/eJc35R3DpwSo0ZmsVY5AlYQEfl9sWk2Rh7X7vQdhVXZpBo3Wtvw8HrSQrzvbGw+8qm/N1wi0zll0GXKJ7QGH6t57OmoLLhmfHStOZkwFSN4cfqWI2TwaeSXNoGexIgQvQUkWWtmjw/P0nPp019vEEH/qYpmoN2luFLGdKWdXt0J+SHxrU6jSD4rfzwFnCaLLWSgjHSv8qXLuMnW+1tlEt944FGolGY8bmKFm/9YY25gJI43EJojwo+P+NsJeNrbuPPJhP3bSNmOAsDMIPj1Li6EyZ+M2kknsfh14i7xX85LvTZcreN4TVv+YQ7l6/JdqNRZOppk6ERm0Tj6xdcwhdbQTpX750KHsvjYA5pnnQjLU60Xk64KG4Rh381ueubkE6GJX7PORVDJHRYMq0sbGO6PRKCA00nc6jCjPl6O0RkW6xt+xrHGuOOnbDDeQJZ+AKzTyz3ZzI5OpYxvcuGwGVJZEUaCyZDKY+zl0bdQcpFaQjWwbO35ymoeHVxwPfLMLWpKtKCxT8zelwdpkDxdyPV5zPOOZ5cj3s/k3phwcUx46snQHE+F+1FvoqPfivDkmV8uUeIFoU2YmveCMfsaFqdqPC3h+CYKgfQl1h2+RSWmCOepii9Kk3ZuxvsIQCPwxkM4zDg4zkJA2mceVx9X3qbdUecBNk08tq63qHypN5uj4pINkO5DmKIKphA3RWIgHJ2T8+3cN33LUdj8nUkGRCGLiCAcEt5zc6g/UvZ/tBfrOUgH2ahr/GYIh7NY2IwDDUqB7P3YrD4GzUg1Nd7FKFlk39pJ4oAlJeZrPjbOBeqtYg3oT4vAl6FBCQi3VOmzMBMUZrfHfILGl9vYFvbo+y0wLwvL6ZzIRhpHVgsi3LSpYyKxAtcYqy/McVDobtMy3C+RAKYuS543EmAj9KaG1bfzY2L0YXhl2PSD4pB0m5VKCi/3Lykhh2Y2VdqEUhlI/o9eiiXmGrF3wWIt2Pdnv7zjlfC1e84/gympKNm2d3bC8AEln2HEEXtYnAYDba8yZyjdDf6MJ8y9OJ3Lw8+TzrqngIyTJ/AL8FQrRfIjiAEVr/EYOIMldsf0h0UNaS7mDzZd23OK6eRboog1jnSqvT4EmO/DyrUXsXSlAuRN3HTC0poGv+qtA6s6za6+PvkPe6zTay//m/zGAWrsBp56U1sVepyw2czW+07UL8wEzxsVTUys+7rS/7KyeXl0C0AXWG8NILgqeOT+w2qdzSaCAeUL6l1vOzIQr1FqWbwP926ePkQb2DqjBUubPuNIzMav2N4+gui+FtOSm6VwD X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec1d932f-cb78-4508-9519-08dac8024d16 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:23.7661 (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: caJJseyWCU87+Dmbfb/3JTtlYiTYMy8sCqAP4oPtkgHnxxQNqp4f/8TB6qon7g7CRBW6Wgb0DFQpMvp5UFA/Mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679696050211710?= X-GMAIL-MSGID: =?utf-8?q?1749679696050211710?= Current code re-calculates the size after aligning the starting and ending physical addresses on a page boundary. But the re-calculation also embeds the masking of high order bits that exceed the size of the physical address space (via PHYSICAL_PAGE_MASK). If the masking removes any high order bits, the size calculation results in a huge value that is likely to immediately fail. Fix this by re-calculating the page-aligned size first. Then mask any high order bits using PHYSICAL_PAGE_MASK. Signed-off-by: Michael Kelley Acked-by: Dave Hansen --- arch/x86/mm/ioremap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 78c5bc6..6453fba 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -217,9 +217,15 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size, * Mappings have to be page-aligned */ offset = phys_addr & ~PAGE_MASK; - phys_addr &= PHYSICAL_PAGE_MASK; + phys_addr &= PAGE_MASK; size = PAGE_ALIGN(last_addr+1) - phys_addr; + /* + * Mask out any bits not part of the actual physical + * address, like memory encryption bits. + */ + phys_addr &= PHYSICAL_PAGE_MASK; + retval = memtype_reserve(phys_addr, (u64)phys_addr + size, pcm, &new_pcm); if (retval) { From patchwork Wed Nov 16 18:41:25 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: 21218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7124wrr; Wed, 16 Nov 2022 10:49:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cIpxSZawdR+XoG9LiRpxBsmDIEorMIH2QOH4we0weBjEpl3A3xZWwisws5B068MgZ3rjB X-Received: by 2002:a17:906:99d2:b0:7af:bc8:da37 with SMTP id s18-20020a17090699d200b007af0bc8da37mr10531426ejn.18.1668624588653; Wed, 16 Nov 2022 10:49:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624588; cv=pass; d=google.com; s=arc-20160816; b=xROa3SDrYg7P+0nm/4as2CT/VLAg0dqpIuHwHN2wGqZo8rwLHHeagz93t6pkezaNRT grwlJH8Lks3lhaqwC3VDPClVEeeZ2HU8QSL79+0avumnMmXzMlQZwvlnN915kkafiKzu 4Oniv3Kj0byv/1ywX8F9f5LUtKkd8qw5k7NeRS/1FhK9BHAueEqvmB3Rt+hHUD5aVt7u pmvH5VgGe7v5tBcSBernPp9VDw/0s8xRv7aLjALtF6IDcHgn76xVC7aiHkFP5gSSUuAY AfCZBXjacKOPhSMgbuHRBfGb0DhF5Wqh6ILBTDni/70H3mAM8gVRs2t5TR9AqpXs3HSu Fdsg== 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=+Py9ZpK0xmdyoKCjyej6AxiGrgOc0U5ZWOxrEejj/RE=; b=nFKuRfOPdLdrY7GLjRQC9sQn2JkzJBsEzalS8HStGTKfATNaBQZa60S9MUNTnY+5+f yA7TvPB3nSPJVKRTJnobKe4OkcQRCtD+tCEMzkP2WxmCwoN1qbJfHu2kUPurBRxqIN5w 4k+gLocDussHepfmYnlZ3YzePv/sJ7LAkaj3c4ZpM2oAFmhxVSqEKlU8NeDzUb5fms7t DN2uh5PfnUn5RSWh4FGodyBvmirt6XzK6OKmms+PpbFLSwfZV3H6B4h+pb7MRqiudbOF TPCyKImbBjfKH0ZAw+B9RWKKqNWEikefye2EnAF61bHZF+6b1S/RFruongFHAEYvM3Bi 1VgA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=eF84izht; 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 dz17-20020a0564021d5100b0043d00293d23si18355187edb.391.2022.11.16.10.49.25; Wed, 16 Nov 2022 10:49:48 -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=eF84izht; 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 S234434AbiKPSmj (ORCPT + 99 others); Wed, 16 Nov 2022 13:42:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233887AbiKPSm3 (ORCPT ); Wed, 16 Nov 2022 13:42:29 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022017.outbound.protection.outlook.com [40.93.200.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C047A2981A; Wed, 16 Nov 2022 10:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HSpEwcyIQfbals4jFYBERaZfhMrlmZm/CjAY9bKZFSIYQnRSCQCR12HJ21HX0jw9gHLsY2RbLnpfDXTi2Lqx6hinbtLCDZM8Rz5AthJ54Gy0LZtugy40/jtnGmNjULiDNE2N+TKd7bdH9ifCJGyfLkBArheDgUClVs2p94XwNpIhKuN9MxsR7zMA8i12I5lj5J/VkgJN34p1pbljDxHLXFO7BHUmmPK6rYrlKjNi00/qCur3g8UBqrxWGQbyZq4J4cWjfcRA5WmqCjSHpozLvP8fViVN414G10cIhopH2X1ittNa5LF0ZhpigAFhL874IFipXXcXHykyR/NzeXsM9A== 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=+Py9ZpK0xmdyoKCjyej6AxiGrgOc0U5ZWOxrEejj/RE=; b=dSPhDh8FP+AJTnS9fW0AY+nMkveYbkhISDmMlWLKAUzaUkKsDZUyPN37RdZVUTuyAgol/LSNVYAdJP2a0HP7Bl9FlyIZe4sM73Az4i3l+rVHhGsSRs+isr4dMh1foHSFlOXhZ6p1Y99uwV/8txeScRcrZtoniz5yGcoXtjkQwNe+Ajbh+uso3zBJEleuTCkI5mwWRFHnqh1rnlSg6PM2S8lN1PntqphLLJLQChi1KZsEzwsVIirR3A4WrVz5b+oI97ymvinemZxOhV4O9pxsJTEFqboI4masxdwgxKw0ivvF3Ht2k2/y3TWSZ2r+BGykidkbPyiw0lgGc6CE9YYosQ== 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=+Py9ZpK0xmdyoKCjyej6AxiGrgOc0U5ZWOxrEejj/RE=; b=eF84izhtYNIIvRcvxODc2pAVWwGHJTYMfLjo6iYOWcSA64BfdzIcvo1l/5tXZ3dbmvGV+l+hq+BZT6WngOJOtE8F3N1DECdmU3+ODmTsaQx1wDvR6C5K8tzXWUspVu7ZmS/kD6Yyjk0MTy8DVGZYE9bJRoapGkrydrpizfNjcQY= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:26 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:26 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 02/14] x86/ioapic: Gate decrypted mapping on cc_platform_has() attribute Date: Wed, 16 Nov 2022 10:41:25 -0800 Message-Id: <1668624097-14884-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: d7187970-03ef-42c5-fcc4-08dac8024e79 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: 8mi9lESvgUTICpTA/FqyCp2RVhtk2PJAH5l81mO44ti5fuGxdoSzJQsRwvhTNI2JCibM751g0og71+FFr1tPRgNhjq7+J8JoXXILCqXyPRUv4QDgpY1jCu2IY58sZyChTPD7XIMQqFG5jACGkj8GP2189acNxbDGooNjLBXqtDuMu9ED17w0ORxeG/dJTulkSjttHjiu3Dwpwz6c2A8Ltjf6225OQCKx9FyZbWmG24wYstxIPebUQnLLfF9mz3oGhrtXezBHNUnvWNtQ2lO4pALxpPAgCM6X0MOVPpPVUwV1jpDfqCAHHvfBLmkEtKFLOjUjiF2OV6Nch04j22zn62BCWoNgQT/kahYl7WaMwIZ4rztxg/sCqZREqLp8vlUEbR5dMLGlhpNA+zBh2iDF0RhAT+JB6ORmnvgeMxixC0NCnk4qHNa3o/ueF82oVVvwA2MLvjF1g4A4BU0zmRqi62077+HII39yy2oxkdf5lFKG/hCAZjd+yF/LlXco1yD9P5te8t/j4sFIqBkBxNzr/PlUjpFsB3U/ZriLQhsR+MvpTJTa9lB8DbANtyu4Zc1Z230uZot+U5NvbKIl0MUQsa0UIMf2XV/g7o5Xhkqjk9jNTKt2hWrb7A1NV5jxkS0SRsK9TYlDiQdEjKFaTjXnR6o2SXV9vcfJXTm3vAU0oRWz9EmJCTnFIMI5HCjP6VjtQwiwkLbvZL1xtFXXC1l1Ru0S1sTtPXnVJl98I7sELyos3BCgOaJ8BrEGhKDWz3VENuPrjTqKFuw3ifU1mnHlk53JKSRjh/Om0Pf78Oq2gecyLDDWzSP5hDcc3MZnVXWwqFc8xlrFRjGzfmac6OHwTw== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g/esYkbHIzoD8DFXl5GNKKW+XYGSrZ9KL9p+XH5BIHmx1mpVmv1qtOEeOONWoBlQ9kb35U56mXQzNLTaOaCzRwrU0aBaqeiIbvVIT/UQVTRv0r2JMHaBKQKfRS1Q9YFlQKz/jU91JKR5qwslyNaD3YlXbxshNFNMWmiwQOK0VrHs8fyByQz3g77KE/6xPMA7NgF/bqO88oihLUFZAWx1CRdCU5EIw3T1jnpobBv7bieI2s0TldBzOfo+9i1HuPqWzyWCGAmC5vq+Y7N5tpchPyWW2Sx0Iolp0Rg8Zb0G/2qcKY+D60ba6tBhstOeayQlQSuTVv6A2R7hv8WDyuAGMZ9W7gFyDK5Mkg+rYC2aRuQM7es+poFSDIe1gmKNeoWwgW/Eg1S17zywc3kc5RwYyZhY7aT5VcADtoR3SCQzd25XGtuVGVcFj2stsnUwig4AZDd1YWxtO540aq7BBFWr45cXRjxDp4LqrLZnB77goX08d+dY0kQfySWe0hLIoX7719TurBuGXMbYt1n+cF6HIxtV+Avn4G9SvJhAIaWiG7or5gF4DB8YEANApju6mCDQD9QfiYbX2YXrEPZTH9XTNe8ctMG16L6oUYw+T0lBeOBtPNPvyNxtZFyrm+1vXmmok6s+s1syjpptG7OK1S8dTXE5tIyl6kxxIuiEQ1zT9Dq0kw4KrMzMrq7k3W1SzXTQ11yBbJ4Zq7N9XF9aztaKrMZHkxcB2EqqoDIa9tjv4sNXLxOpDRIa6csJCv6aRyiTmOlHuia+zyc5v4AOK6Tu9pdXm7cfUxtymkZY81/Q3xU14mXFgurSjPDfSxkrOUrqL5xiUW8y3aAdkTTHFrojZIOHCEGbZ2h+PWFlPgzT0GSZzJT/XYlVmprwFrz9jcRz68VVDcomVKswnz1iMMSadLldwLMvJR35ZxVKyT+DvumMRuqRe8us1CsjCEYU9Vg7boGTNU6LRtqlSqCRO/ZcU57Gjsh8bnkPALTqNvlSAydjGmdwHejxLY/6RupaCx8Fvm9RReKLLbUBCzcSembUR4Lc5yD41iBWaT97dy7dv1JLLw1h3Krtag6vYYJIx/MUxSXq0naO+zyS3CdTjlskSwUzKvXx5KgOsF+NSyfcLqyJkKRZcTBlz4ihtFsFCuJXmRiAYJ1HRCnXywRWyoRWzf7HXxiR2KC7SdeX+DvMkzW6yfZzPmicjv8eaM/gzJrLg9Z51J+kP2/VuCg/rptJPbT3ULkIqGLbgPVboUMpND4Jn1AeHhnwlQ3cCoGrwrUHss+CzzQI91jJtcP3HyCj3xpVnxYNdB/e5YcwlAwhbnZu3sR19VU2+REbzC7OMv+sjN9Ztb92gWkQfUU4CalfWu83tD5X4oqG+tPVnewsDXzqhVBJpavCpLa7YU2/RRtHOzsrlSrbQp/aSscs96qRdDn145KGPXhuuHrllfAhcjuC92GvYLpkvQa4MhzId1WWtgDmmk4+4a+fj4z2QIgORV4PjjxJ1c98RN0qy+KtCf7116QbVOp8wQuU+LW0vJw4u4Gt9YLu0b55SOi0v+zbgBDPGqr49WX4I/F2SIg/45PtaXv2xCF38ecbBhjo2Dfq X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7187970-03ef-42c5-fcc4-08dac8024e79 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:26.0184 (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: CL15KPB99fnDCdD1qOXZrrzJPFvClz7ETctnN+VhIZW89Ui/q8fP5+1hwFbwFJij5XNajS9EHEJDPnoAvY6zPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679696317027286?= X-GMAIL-MSGID: =?utf-8?q?1749679696317027286?= 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. Signed-off-by: Michael Kelley Reviewed-by: Wei Liu Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/apic/io_apic.c | 3 ++- include/linux/cc_platform.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index a868b76..c65e0cc 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_EMULATED_IOAPIC)) + 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..7a0da75 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -90,6 +90,18 @@ enum cc_attr { * Examples include TDX Guest. */ CC_ATTR_HOTPLUG_DISABLED, + + /** + * @CC_ATTR_EMULATED_IOAPIC: Guest VM has an emulated I/O APIC + * + * The platform/OS is running as a guest/virtual machine with + * an I/O APIC that is emulated by a paravisor running in the + * guest VM context. As such, the I/O APIC is accessed in the + * encrypted portion of the guest physical address space. + * + * Examples include Hyper-V SEV-SNP guests using vTOM. + */ + CC_ATTR_EMULATED_IOAPIC, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM From patchwork Wed Nov 16 18:41:26 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: 21219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7171wrr; Wed, 16 Nov 2022 10:49:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf46LiGi/EC4bIEXRNOd7k+nWc4zWWrA+SAp3oD1JgKoE+tRbYSC/qZRtLrW3I+szC8lI+yb X-Received: by 2002:a17:906:c284:b0:7a1:6786:444f with SMTP id r4-20020a170906c28400b007a16786444fmr18700995ejz.409.1668624595884; Wed, 16 Nov 2022 10:49:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624595; cv=pass; d=google.com; s=arc-20160816; b=N6R0cMKaQo9k/uWkL8fUUsbvj8scErXcMBa8R+1hFFHTJ6z+KrXJSlryTn/kBji4Jq C5aT8bEotKpK064RZYkG6RSRFZKpZmLKy3WT2vC5fEli2OMaISo907lzrq5d05EyrFYY zO6Zy+5AtkYan0JuEbIMelhMDNS5tG0X6/Ql/zW650BS6H3Gz2hnnowoxWL4PrX2+G7G Btxh86GCKgkmSPtGwRLC/gzSmG81luoX16Y0L7IQapt3aPwjS9DHg5NRQgABjfVpTXpu tNkRLhDEMWCfyTlG+5hID9MQyMl8s3xOY0W3ks0OJQbm/eDnlJPEdx/6gXN+o/nAQLTB bI5w== 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=waI/Dl1CDRJFr6xoaI5Jse1tJDnNvHI2sd1BkOU+BCENcHeboC3U0Qx1qneWT2YsKY Pe9x3hrhxKLrodIk2Hd7yLZL1uw3BR6Uc7fcXz7pgWTM0HOVjtI9io5zUNq8rvjud+zQ F5Hfoxjh6NumEw9CAU0rHM/Y+GuxLfI9EkhpSNN1dIo6zba2ASAcdca7bjP/h81h0gp+ homKe6BgaBazXQfR/odRKxPsu/Fl5NZIRWXR2W+LhNKoY2zJl1Nj8sc9bRPBodgsILxa 2tWXZrvwyCnjMdngJ7oHg6HGYwPGmtqa2AId3mYqiOgn+lb64uWb8n2SGRLBDgDwf5n8 fwYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=hbbFkC9e; 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 eb9-20020a0564020d0900b0046289aad428si16745084edb.496.2022.11.16.10.49.32; Wed, 16 Nov 2022 10:49:55 -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=hbbFkC9e; 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 S234523AbiKPSmr (ORCPT + 99 others); Wed, 16 Nov 2022 13:42:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234215AbiKPSmb (ORCPT ); Wed, 16 Nov 2022 13:42:31 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022026.outbound.protection.outlook.com [40.93.200.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF37C5B5B0; Wed, 16 Nov 2022 10:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kKdAfdgeZQ7JnW9dcnGXR1yHClAPTceGupNYRaBuzspOFKBCcic4SNFSVrXLKi+JaPXSbQXDOvXGONTisYWPLXUpPvM+HL9r3tWlJJVbp0go20b+DEu4xL7i1eV22hrvel0QR4sMAXxapvk8zOT63r1sdxosf6voD4naM/ZjNPNMZY2jB0YldFk/lgEV5/nUulyasZ4FqNtp1X0zunVzWcCde8c4McBiwgHKakt0Q9AF4Dr/A/C8fVdiYqvUjUSfw+YBSfqTM8xLTRSJ10OqFjk+B7E3yz3r4rxuju0uHEGrMKIFSSut3rVIGm0D9ygAFNnLrFbrJHbdKpbrmIApOA== 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=jLup3y50yD/Qu/tBepqLjxzFNU1W1qkMUw64GjsVhJLw/OjuG0j7+hzfHiAAD+PiKqOCSWIkcL2OFDQjHhQQZEEi/WcHcKaY4o/fBkv+gK1LffldX9v3LeAbn9GsZ21IYCANVlvJrFiarIHTvoxYxn6PkmvzqozquWAIlxDs/fDUuWQs2SICmt2WzEiPm6n62RyJ7QyOECnonyRLWciyafjEO7lT+XBB0wcSk/CgVDW+oQKoA/2M2nPdeXj0zB9PPkGzDP+CCeEMb6/A8K/xEub8i7aLTKA3TWX51KeZ68FdSZ28UmUfeI6HK8SEPtcntxNMbECbToVKClahCp0S7w== 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=hbbFkC9eY6RFyeis1iwMSKXOEwv+Q3jXEzjnh9HWi7iaO1tBDcXmleyL0oG+YxOsDgs0aJIR3Sw+SDyXS0UcNUWzOh09MPx3Dd1F7LakD1158PGR/AJojHluwABd5hopfNgXeC6t7frg6WydFzm7fiUxDOZE4bz2c01mr8djuu4= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:28 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:28 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 03/14] x86/hyperv: Reorder code in prep for subsequent patch Date: Wed, 16 Nov 2022 10:41:26 -0800 Message-Id: <1668624097-14884-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: d13389da-5585-4ea7-2445-08dac8024fdb 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: bBhqk/qQeMlfL5oU5uJdXIj2Hxdb9roKN/yFOds86t8V15oFaDJs82YLM5RtLD1g6+S1kxXB3gg45SA4JsUaJSlDwkYoXWr+UR5x6Va7dEa97e4oAHPuG8ffuBPqupRcpo3bfl+PXJ/IGYUEdTWMvCuyoS++6mdSMxFSJQXmkD5mB/YgmE6e0AyKNuKo629Ys9Zjc8uAbQuRNCkppspAWfC6ny2XZd5qeJahNHK79dXfS23Jw2BzA4l4GUxymfMQlro7bv+9DgthqURuVCvE/QqxuZsXThl+ZwsjXGZ16C3rLNANjSrSGyhKMZ3HDMhMzkU8fhiuCtK3B9s4zUxmopGnvrxg/XfnSLnlDqxXIudu+OzB9MShX5OPQjoRtQjknABYERlAJUfjrawxVq0iOynnSptZO9Mz/1IbzUyDZIcQEiEowXfCtlLTNtWa7kgHl0vfkV3K2gsbyLCySql1Yj/f/zgmbkCxw3qIeZs2kPy3rIgrmePXIpz8nEr18wv2biTWvn/P8xNqzOJnACA0l1Pc8vZfLFhyDnoLub8XawYkuKPn3UCFiLRC0hXLa0usOFhy6vm2+0HboUGkXNfVjOibq/f0d2W/a+fvGo/qxddp76Ebm6qQctzc/PwtqcmqzHFOwu1pFb7WK5/S0l3MO6/RFOp96rzfslxpzrgQJBIiryJRdSf6/7lSij9A0bGRi20xumSnGUKqt7tvTGCBG8KDj4TrtbdvKouFZWRWQtobMXoHSrg4+FEvq1OZkbcYnVnjwNWfU7tB0kcOLjAGAsI/fsWqIPahin5qVv00/jeLq4JQQjUQ0dRmzFzwyt4T8l0+mM7bodtjPZ3yhmUcUQ== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: suf0yUwN+d9fjgPrh9k+ph13SD/KISbuF2kaFlQK90CfRwj4A0qPlSgb24qTt5Mqy31R9Y6uMb5z7t4MVhw0uao6oV2dGWHK13zJbV87J+NpMST+9Ka4FvNsn0NoSughw6t/Xjfr4M97KAjnfRYiVZjqf9gC3TjkGB68yhFqqlvA8Mw3zMZg9d1ZuXccPsbL/Ok9Yv3w+XXdfadkJifBV9s0Rly9LxzAdjHfK8F8+PgqQSb1aZaK4XpUQXnrXWXr81MXpk/6XVhexE67CsRuk2ovCtfDFDcUrr4WlrnS19aEEtzbHJged60i9Jj1Q2KzZyMA95HunclLghBxX4Pc6RA5EZm/rYQUP9uoGTwGz9Ppnb4cpLHfpnEhwV6lURe2dP2iAZC0N+w75jtwo4rdMJiST6IguYUJk/3Pu8LfB1GVwn5KIHfaqoSHwzsvkjbietzqAFYST/IyrjeLdNvIBtlT0Mz2uAT1siBCa3yLThKkuFQmhephkWIc0k060UlND3ebwbsJHV4Fk1SavDRmMmsT/FadZIHzn59VXHyfI3Y1IvmjhRAFo3+ayKhPImzFvTtFdrDXED8RLMoIIJrHXEo4rrrn4hn98JaAw3Pp9rye2xCeft5Nhf1mWkNDv/FwctbpInV0YsDN9mwC8KbuCRPtIyWE9ML5vLgj7Z72vJWj+zXN+V/9rvcnlAGtdEIqM1PEbcbheOU3sYrxeSrLpCegsn8RVGt1+SIjWRqkf3Rer3/pzJLGVMiGDjmmQZXNRfKACM0juWpE3fTtpz7+6vNmSV6L07byyt7ACpQoQ4og7Mmx7V7TE5bisfVNj8wMSRrMs0veAj8+dKDRVsTM71PIU5vxtcCt2KjDiNR4bLMxJnrCKK1piM6eFOD+C+pwHKUKRyMiVq/Otk00flN5fCv4eZmLl1qtxitWNrXrN4wKb62abLITtNdBg8P158CoHZ8kkh25SR9vnHcJZBhEefi0897GOYi6KAi/Iz+Fd3qHyW7uI/Yv8Na+85V83Di9fTJkjW+ZdKbB1FS0LOM9zQey1tGOV6xk8KCrCR0vy9H8I7w8yNCd8En7mZccbZXui45Xzt5792/ttS7uwsaBPKTlXfRfbJ2fq8XpHCF0Z5gPlqWT6ulCHCn+21n3tY6BZ6rUFZpxxgv3v4gnn6gLj2ap9UQcXsPpv4HKsHzpXyZVNF5ou4ggz4ZFr9owbxAy1emNjm1jcBudZ0LhRj1N1qcyAKzkGNq7fM8msNlhEbbTmGVTlgVuUzZBEA4wZXVMNhhP/xaNT0F+pQB+84wL3tQ4cFVovdigjpT62QAIT/yaysq2qL+BQ3xNpAgJ9Py4i04wzMmBgC1is1C/rGCwt2D+YbxQAm6ZC5qHo5ymHhC6aINKf9I6dKXYqmX5MwjTP68gsK+Hnvo/Wx6eMocNQ9AIwr0O0cxm1wrcsdqEq59bAGHs3YlYvauhfEXGcPcyDSQBlzcSf7j5MKsbmFLSsUhInG+XPklsc/2+tZC9l2F6HNACJHSqJe5NWeH55wkQGHoSB9zavDi2eKyyJLt9Fva/hSOXVpM7yOh3bRuq1C+tPhE/QZnIlbkLKhJTVpaQ X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d13389da-5585-4ea7-2445-08dac8024fdb X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:28.3941 (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: XF7n+MH2AFwhyzYQ6jhPZcJs4C43Dqp7OyAFG5VcL3yZiYYTt32ooAEf4Tebd9MM9wDRpogx6cgUnLU5cVZy9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679703983484224?= X-GMAIL-MSGID: =?utf-8?q?1749679703983484224?= 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 Wed Nov 16 18:41:27 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: 21221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7530wrr; Wed, 16 Nov 2022 10:50:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vwuzFXV/9qDOyGc9I68FM77vZgn5wbPcskfhi4wTCViNc17g7a68iDd50+LyTiotJmdpf X-Received: by 2002:a17:906:f208:b0:7ae:2277:9fec with SMTP id gt8-20020a170906f20800b007ae22779fecmr18344474ejb.623.1668624653037; Wed, 16 Nov 2022 10:50:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624653; cv=pass; d=google.com; s=arc-20160816; b=zwMAnrzBtgdZ+W1lCqLJvPf2WtOM+iSqMcTB8Ja6OvEjfMSrmvEe5QkOMHGHsi4fK0 ArgBteHeMVRV06fU2mo2p5yMvcggrfuq6QK9uKgcxMqU6pc5FXgokO5jDRmheFda9fmh +lIW8Ux74udmc5q8nEEVDVqYaQUS6/+Ub9XykYYRzbjjjyGCz+L1TR0A8BE1bcG8itzu y0yZQfRq+H02q9crY+Tt6LuGdiMKg9uEMIIB1pmgoQ8Gjs5SJHm/9/bg7SEfZW0CzKYb DMAt0oJtTVZAZ2c/hmod5BsMBQbWslIBAnAzg1IZxbG8hv0SmDL6XCAraATSKbkRlZUC O0mA== 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=pwJrtiRV0c0Qyfs/AzHjMUZnYjkHRqdj2IWut1ACx4lgAJvkJxipy0lBtEy7mEQPSJ 87dA95+t0fj/RLvZC9VFA3v34fTJmW7Ug3pDxOaLrjwm4vlqq8BmwUkDKBiEuP1pD8br O5On4wrUtIsfUAaHBENXZvn+lEGABVJV2CjGVVVVmruWot7mCAdHUFDYXSYJzHAN30Dm /yIHhs3pSYKuAPe9neIML5LXRDi8mnKGMmMktyqtjl1GjAsO4xFjjrtcIm3QiZ/SMlHL lJKsNl464UiIQ7PSRY1ttYfyULopD3BZge8XyCbGQZFe1F+Ywjm3tudubFR0LZ5o5WRr 3BBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=LrqNuFRn; 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 a91-20020a509ee4000000b0045c9904fdafsi15014352edf.74.2022.11.16.10.50.28; Wed, 16 Nov 2022 10:50: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=LrqNuFRn; 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 S233533AbiKPSn3 (ORCPT + 99 others); Wed, 16 Nov 2022 13:43:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234504AbiKPSmo (ORCPT ); Wed, 16 Nov 2022 13:42:44 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D866861755; Wed, 16 Nov 2022 10:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MKgPU8nQ8fsXO2B2bSUjbxDgEluMAJvF0GuI/e+4F5jAOqnmQqc4EtgQBnY7+uO4bA0dd2gs6kSAp2opeg87UOD1vqwTMMfi9Vs9qqQTTy7aAcmow6BvZ/RtXRM93B76y4ImxrUyIGRzt9Ub+QdJ5Nwg46Vymq99W6d63r7BXect5uIp2+9zVqLpFq0Isuqz+9lWvGvRr/cTy29u0YnzTyqj2prlU7TqJCn1Ab+KakuibCmo+OdOSWjRwc942vQ435XzLHySO4HyvlrqGdXxSntgG5ltIpcg+WiVRQX8BsgNRBMkgYG0xp67tuvCTqIR/Q3TD5biUWsLrqLuL07FCg== 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=DxLJgVvoQ4IgGW6LttwEbuDXYyt7UDjsH4Z38rTgRO/ouQgOgk3SylyQEPaCvP8ZgA8f0aHB+aaWSwHp8nqzkfGZCGVKR1Wzc02zJhA/dwIwH7yTABQw3MIN9DxTgfbbXeeYIvnAhCds87P4VvNJ6+Z88Yex33070/3cxJlTf5sdC7/inRQ7Nzwt52eK+bL1zmpAVFfD+lKfOZN6Xo+pqRM5JsyS+cH6CfVhztmNWYwZXwnsLQPiQm5ObJ9yF/yub2sFzyG5yg+YqR3wgQxuDbPQ8blnCeeFVeQZWFZPkw2wh8LICnJdhGnArZKGA+GgRsPMwQOCdiPpQMnfpwlseQ== 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=LrqNuFRnpZP7Txjrjwmv2qR8AAKb16jH7GI4wfpAltD4JaprMimNILaagFWkJAQ8TtfNqkc4Tli284m69eEDVIwmISQRMEoNVgM0bIDh3m68FB2moPX2y9ZsMjYWYfJaRAlyyjbKBUIzZWCzgie5SSACtc4BUZu8pYYyQSqSoI0= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:30 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:30 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 04/14] Drivers: hv: Explicitly request decrypted in vmap_pfn() calls Date: Wed, 16 Nov 2022 10:41:27 -0800 Message-Id: <1668624097-14884-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f4319e7-e54d-48a1-27fe-08dac802513c 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: SmTLd8Ujf4b1B5T1ZdWkU3my2lXcFGd3k8PEvOXO4qvsWsKKAl+O4cg6zV2ilSJCgIqD5DOAE+Jf5cDQWmDCSl8NzaDyzTDnKSXWzjHn5mfbot8g1A5l/8p5nAF2eWQV46dFUeF8Tw6GtbMxZm0CgeshrOsV1mTf41Lx1fIMJhLyZJmvi4VUk4O4kmhQrdvWE1EKaeRDrKUUom5xtnjzOT9F5sjhV1Aovcm+yb8gPIfiW4moUmPc/79HwKy0sibERrT5DKIJyiTCZVQSJW8q5gCnRSHYq+bqlGgJY17WlAY0/XDn4PZvqceeo6ORO6Z6TzCYd++MBEVCRTXPRrbq9I6rtNKRmHDzPMu5QDQbEnu2S2ANAS0Ve3d//tt4Eq+fJi/+SIiGl08Tj7UvNMr2SWMW4eVLbyJy0FXtlIRaVIXWwLZfeGPKXtCCI8lKqFJbwkG4aox7cJc8UflUHwps+AraDrYvCYe2mRM+ZOGzMBRupVyttbCp62WzDPGfpSOrJ+MnXKcNwsHzGLmKQvkgI7Xd2G52/d2CrIt12v6B+j5jGyGkXlHvcAaZeeftFLTJAT86WJmV2yHppslB3ZSKl6PBKyeU66CnWqgoC7npngMuJwLWKMHJdSmm9JWqjc/3QqnflSWOwFLsVRAdcRutZBMo6oMS1YV3dTu4iAQJIZMHzyVDFB+iK2ZImDH/cHdzS9SwqDGW3sOXhsfMG/+JUwoklGq8UZPHye2MJRAwC9XgXu8PwzCRHZ0D6CsjLhmuurwuwTkvHvkW4tXVBoaTYt2lkvOeuyl+GO/Lj2C5UGNFO7R1yDTE3V+9DJoPM8Kj04C89Pvn7f0Dw44SMfqiwA== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PG3MD3G8R3MGFvR9unUq6Va1L1iQIqQETT0NnX/ZOJp4+KSd/rfhHXzbasX2yeIRfJ32Re5K70QtNZgxJlcfylrRCAW35dYgqMwvhY0if3KeRjQj40i9UpwxtHP4uBlUmWd1tdXbXEwGCbrrUohrtD92ELPlk2F3ZGqxAqexzboe/mlb8sxv83WARkrbpDn7BX1OGDneAX77zUn3Q46fexsZDGpvkB2W5sL/wK/4pM8cC/dfSn8mENjrbBomkyJDPNavZNME/yNweU9Ub0qbLbcgih236mjAbJK7SYWCJf0hTNxQUqJbhkB+I+NCE3+IkRd8mnlt5Zu1GE441F3whi6jiMt8pmGF4pGsrX82g6rac2t0lpUn3Q7dROhdMQMMmGvMRgBA5J3pzK5Atw2wxC0FcVL1kFjygw+Ju64Q7mp4UcxpncVfzQpyG2sk8vtn34eCmZSbHeK4ukAe0GfP2bl6LPicHJrpwwkTPCWvEMuG8K/1ukDnWlVeemIQt6foqG32ZXR2bQibh0u8ZfYYGdr1Leum2d4aDLfotaszIB5kR9xeOagnEZcPhn2xYX6IlPKf6n0KCzjZ31BuNvUqAesT4DoTNAsHP10PGLY+g1CgYS6yDVIxzMYWTosWu09TSuj/svS6EjoMneijczt49lCvWmV2prHGSez7JsdK11d+dd/8nP9GKFOyPVfjQZo5Ewcak0H7LYEN1KXasomk8yWI8/p3mDVO1n4O9JKbEnGWZXdQEqqpgsJPOfkGrBGZR1FdvyygXoDzIXtBC1RmovpZHSadjOCzT0JcJ+a3ktnEcIUNZM4+itlIGxUmI6fwhS4ShFsECDy5Zytx3FaWLszj4pWw+Fxw3t0+89tTpBEmSrRokvK8G9hgQoK2at9pGgHGB46gWN3LKsjv+XaMFN8+BPnsOg+yF8zLES09KGrpj5tV87yOQt8+KiHhNcA+kUUw/fkzaoueVCpjPgLKcx24UuB40jUo9dSVLVRU96FLPC6rxgTvTtJD6Wx9SwR1BJ3qzeQ9NpSgFYOh4zpNi6/TF9RumV2+YDjcru2DqAMitkVxYa5bMEBVIK9C3Ze4CCNfuEMka+CPe6KKw/g9z1ZEF3MfxLzLhznlc2BAkeXe0ztAf1aKa2EKhTeJ+uod9p2YMowHRhtFUK5NhH7aLUdhgu9zAJbJl3CjF2rGjo0nP0R5BC6DsCHrXp+UN+pbK1/WAxtENUjfdiETHQhXOTXsF1h/tuiqXg+um8ZEkNJbXHz/AngM2UR6eEwpbJb8OElgu/KXcf7+8N3gtyQjVFfczfPo9KrtcFc3N51KXgBWEK8GliyxtYcGupTeg5xcsBio5aWPOgUvF/tdGAaJhLn5/xqH7fs+G+E/OxZSBeOberPL6yMSh8yhmNkeeDCeBTevLwAU37ME8OYj0kuwkXX9HN2IxGwV7h6Xe9fZTNcmPGtlU/3B/KbKM7HGZ9dvC2+sprV6k72Jb9euP4ShtnnYlA0cDjG/I9tz+LCeMUZDrB+KfNRHOlmtIkZwGcJ6DpW8BbjqRjpI+GMe1cgGqmCSKP172Bk1AYtpnAObIAzI2UiZcBiMtxKpUic6/yiZ X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f4319e7-e54d-48a1-27fe-08dac802513c X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:30.6451 (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: iKLxOtXT+tO7L9c87+7uTujAbThWxkMQ2C7cIsfihItD5aF6+j8DboEr/Q1zQeN+QmUW++gFN0dxkV1PyvVXGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679763954788906?= X-GMAIL-MSGID: =?utf-8?q?1749679763954788906?= 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 Wed Nov 16 18:41:28 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: 21220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7395wrr; Wed, 16 Nov 2022 10:50:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5OXxsGIdhsjyXhQLb1oaTpxn7BLfUT4TajdssSD4Y2otIskj6eC80lnPdvHZWYCWEqMosi X-Received: by 2002:a05:6402:5488:b0:462:317a:e02f with SMTP id fg8-20020a056402548800b00462317ae02fmr20345991edb.125.1668624633229; Wed, 16 Nov 2022 10:50:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624633; cv=pass; d=google.com; s=arc-20160816; b=xtI9mRLlENTgALYbDd/l1xC2hwcfTED2LRz5Xb3vEvzV7jnZphHWhgJFKsbHIsW9vC CN5u6MHGerMdZ2RuYAuCUpaE5jHB81aAlvYkCm2fHDvzWkxVZty3rBzBDXQV0/tXBMWY NTU6k1gQ9Lf3rMLQ/JdLuFw3ZvHQvR+wcrh3BSyHGbcg5gZpCifKHKV+UeOkqvTXBf39 bFIYaICZ2DO9BcgJY1umhNWnSNzMbNkBo82iU2VUjRtKi0yI0iy2v3TtvjABhmTIbDfR bqdsmWCq8XZ6o4P5JqLLwfHwFG2llt49qA6W8/2hw/lcpNFRGv4CjopbYpNY5QiTEiPi UBIA== 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=L+eO9zbEWa8pN7ZegOF0MHZo7JisuGqbugG0NAnzUu4=; b=m1WNFdMTjam9n2UAnLinFjCB+p9c7IAR9z2pRxcK76Br+mUdQXIjlS1us2h7PHTHWI vFx5Ox9zvG3UZHaja6+I3rNeDgNd7C81Ve8ssidWOMJFm/uIzRa/htxZpznzeghEN3Px Uhd3/l0bj89bSOsusGzjD7R+NmW5bRfNhD8zUge0TGAVgo6N1UeCgwWNmDNdXBRQvmWV crpDteaJW9KcVhOFjL8lMHF99qXsIXekbV2IvKWNXOOMvxsNoFQBcDOvjCnhNoGONVu2 KX9jfw+TKidKEj2Iak9HlBnCKLPtBdtx54uOk1fmQykyfgypXxBEwepC3vtFPOiGYkWS GfBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=NKZGxiEB; 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 ds7-20020a170907724700b007adfc1509afsi15121794ejc.34.2022.11.16.10.50.09; Wed, 16 Nov 2022 10:50:33 -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=NKZGxiEB; 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 S234504AbiKPSng (ORCPT + 99 others); Wed, 16 Nov 2022 13:43:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234560AbiKPSmu (ORCPT ); Wed, 16 Nov 2022 13:42:50 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A5461B89; Wed, 16 Nov 2022 10:42:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OW2NXnReaPtASGxM0HEYucKddOoZZ2m7pbFRakDkpgDpfJEMefrcPC9xRsZ7uYgNfSeyvgG2d6Y/b8PJoSzvf1OX8I5Yj4Pc7MBDvc/vSbMD/G43Oez8FIJga4G+xCnhkehUc0tGgYP9mzAFmT7xf79oWtDIOb33T5H4mROzy4BJ3ftf2qIfGgFuDBuOWr4PImwUG3Ajpu5CuCwQfS5L8XA3QSRIPxjB07OMMHihBhpx5ddUJURfmf25IOz9gQyRn9ptAMOuELmTrhNXq2KQrFvt5nhw8ruP/Gj9HyBRllJAgzMCsLff+XzA2zBcy3e/UzbtUF17CU6vni5u7vterw== 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=L+eO9zbEWa8pN7ZegOF0MHZo7JisuGqbugG0NAnzUu4=; b=KTjDYhw05IQCl6l/3EhDMz2/W6nBOIcZHNk8yhs9CKERVUoRuh/UaOUXhMWdwuA37u1HcoSykpZMC7Mvzl/PbK1e6SyU5Tfj9nVIEDibmPy1RG/kKXSIBjKMeTn1fm64pqVwgm0C+8POq5OX0Svp8iRGx08OmnP871JGneRNJnWWxya/7Lx2nGaWQehCWSVMKqvlSSWFjBkn9Ul7SGjYXb1hjFRy2lysMqnXvTzZxtESZCmlBgBE4XCgrYDqqDnc3E3mLWSEvsKdVOORLjLc98n0iVZJXkhBSl+QYTvr3CIbhLE36P87XkZKttoNpYVPFRDfvmgZqlqTeAG1hxnsMg== 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=L+eO9zbEWa8pN7ZegOF0MHZo7JisuGqbugG0NAnzUu4=; b=NKZGxiEBQqUm7i+6xwrYZCj+o4WgoNJ4wQuHDoJnaehFhjLbSodRW/upac8IVgkgCaJznSvu6JMeoyp433IEJFFkjUq8fZafEZCbkGvIki+AW2sQNpKWlyEguaYSau01m6+lKtemE3T7MPuErf7DblUzgx+YDYDAWM52De0aw9E= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:32 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:32 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 05/14] x86/mm: Handle decryption/re-encryption of bss_decrypted consistently Date: Wed, 16 Nov 2022 10:41:28 -0800 Message-Id: <1668624097-14884-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 57a8e9ba-f984-4329-3e68-08dac8025291 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: RU2ToKQWW7Bp59x2qq+bWZOknrDDaJgZpuANGvG81bM/zegXdsIEA4Nh9FCDfQEeGTWol55BfiRVgHLByMGiAf6f73RHVntDMGKdF9a9B1U4l+gDQOuagpyDPd8czweltTPN5w7Tv015c7itBvyw47z6aZwdCazi6qRLmRhurdX82ioVI6qyDtWVdg3TnwN4ulBSpbPFprNJbipZheKwgWnwGnzfh+dT+kVJ8tmbFeyDO2Hf85Zh4EiBHxMtBSpoduuZ33CO1UbMFUJ2EOe5S7J3R6SZZVjPYZHAl31OHBSU8pK7tTpbGAP7a9w1ZUCsQ+gKgyd+U64PJI4bYjQC+93R+l/biLqpl2u0Fsi9WxeffwlLPXP+6gJfuGtSB9QyNSXhO08+Zte77r2/5+Gtjd8qAu6NFV0VDMIIGcfSa1oaX1JtMHcZZafKnaq8L0TGRSFq8wiQ3lUML5x/ha+RcIXsUiQaU2iBnqCyqy0cpNf1IaVyEFs93rEKwP39TFacmm5IbxQj7QkQTq6IQ5uniwuBvxLtsIJdBRmGsqekv0actreXfQDt2R7HcMExKY3GsVxBjiB+/ujvpjGvmWkbFnzslp8nPtvYiKkP6B5N6iZ0N/3NbcvppVcuoFD/S3GRo0c55TJBQSlVBbX06ECswhjZruIiqG1Nx52a1k+H/yiY2SBgpCbVI3WlqdJ3lpbPUyD1X8N3ksHX9wmhc5cXZVIV93xklqCFtdF7fz8FKi9HPaficCNqPWw2w9LKGgj5VD2wpN0R1Vj4Rz+5DG9C4VXGEJcQ8P6BNltc7p7/+P+vQtfoGpvy8KHqXCCPiENNKxbt+fiCRU+AFA3D6a4sgw== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ABIIoF96kXQwloAfoVVOps0wQ4BpkUKlW47+AOUqfikQdeWNuRS3SGvZfEdXTjbp82UBXtuXrQQwYU5VyS+C6sN4w4vwWLeYpkEUJ3xaW8TJxP3azjB+CCLSwWheUocSQC618ixMmiiIktKk2wzZrdqw2e02ShXfpKCs3SZknHBhD2/SBSoLh0odHPRW7wvHOtN5L0Rkdd5Mlm0RugvcYDoDgKSwA13/yo2vHyf3JjlrtetYDvLdAidko+a4BDcVC6ksVp+FmbiFaOfPDCJQMdvRDfCLLd3WAa5fPe+UOYRcJMSaNhUHCR35E7sq2F+PE1TCznHvAX0PbOdoVVz43g4qwM8fZ+q15SNFR9DCc9hb5xXZKKCqjCLlf69JftSpBtYBvUuy3Zs3ccVIL2ANrrrROhOuldtXbGF6YQkWmNMVy5WXb5hH50Dya+RHVW1N9hmLxfQn6V5DOl+2/u9LLx0sWhhEpmPmE6YCfuaVrwop+y/7VcU4DIngMIoP7l9yapMSAwP+PdWiDGO8synJJ3g6DfJjUFKL6EQ5fovTboPrXiE6DZdLxzlB9+iyCQa76jzyyFM9KCn6iHArj/9OCT7aFRQvjgW17vyZBV8+KVqTOVLN2QV9mPzlR6p+8XVRskDewoxPYghhU6ALieqEhsOBM5/oEX8L0gsr0S/RfdijstNL5d63kXagwpvk3x8ZgAaU+J+4QLH+8d9Lhd9SYgfqtzXubocvdJVB3C1eC3+MpncVgb7UUOj2f+9/B+jXjIvaJXBzu0nccmTR9JfftDcBVjCJAMA2+RKyr9WwpKc/FtqLveAk6IWMVkC/1YLZkLo3icK95c8l0aYsg2HRY0BQfjbzQrIL/XBfVnvVG04kG7jGJSsZaXmIPLXQKFIdqSsLhRiJGawvEUaCcCSiEtcNypRUv8BywWdaHltOksZE4MOkFeZQzOS6HBrZJn/ASldhAbaeLxXS2pxTDaZ67gwFBp+WJnl69Uad36vK4iOcPFAkm0GUDdelty1YQ/YwxXKHY5+HcqaYCFsSYv7g7FHbqyNS1s+Vd4E/2kUP+1l43PoxjfX6lLIkGX9wyTtCxcUlxy/z1o6p/1cIyIadbIgP8Bc4asU8Ppwph8xvJSqKfkHPUGROTXHWg4RsLg/RpCX4Hv4BmbuKHIYw6hsfV0z1ndXjZCD0Zg3wFjJLnp+gWzC0XPageFMmiR4oCVZLjgPxVPF1iqbWX66mguBCk2kj57hRXAeu9ZI7ovxA52u/jCphzuodVx/f/KnnnN3mFXOUqFHFFtKgt9G+9Bp0R37s9MO3b85HT5EONdVpmW2Wqw+AcKgeO41r1XbxXWW/yP/bTPxAQUrtpKX+ybKGGu/5MnDgRoSyCd/lHyAXX+MIo+0Szljd1ED9hIsmTX+zSaMDwDk1CGABXq0jlmeTVS1HPVqlMhcS1Yzm6J8zRXXMxim/zLIwYjpbVnYVCjKvux0zTbWKOV242bvEncptgnVeFNsQxXCJL3RSqVyQoL/3UkoiLa4hOOGZwGR+RtBZe8CP4y/87i4xRr+zcSy+s7XfMh6bsqVp4PsmKdDZxEAyGIakPOOfQh3Y3IFH6JC4 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57a8e9ba-f984-4329-3e68-08dac8025291 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:32.8961 (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: gkAfaQFTmKXtBqNZ/KJARBebdcNeUWNHIpbfcKHyBpduKFNwLtXaoF5sVWdwWoKT2AUoVJ7e+zNaMrILvzXBSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679743492511251?= X-GMAIL-MSGID: =?utf-8?q?1749679743492511251?= Current code in sme_postprocess_startup() decrypts the bss_decrypted section when sme_me_mask is non-zero. But code in mem_encrypt_free_decrytped_mem() re-encrypts the unused portion based on CC_ATTR_MEM_ENCRYPT. In a Hyper-V guest VM using vTOM, these conditions are not equivalent as sme_me_mask is always zero when using vTOM. Consequently, mem_encrypt_free_decrypted_mem() attempts to re-encrypt memory that was never decrypted. Fix this in mem_encrypt_free_decrypted_mem() by conditioning the re-encryption on the same test for non-zero sme_me_mask. Hyper-V guests using vTOM don't need the bss_decrypted section to be decrypted, so skipping the decryption/re-encryption doesn't cause a problem. Signed-off-by: Michael Kelley Reviewed-by: Tom Lendacky --- arch/x86/mm/mem_encrypt_amd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 9c4d8db..5a51343 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -513,10 +513,14 @@ void __init mem_encrypt_free_decrypted_mem(void) npages = (vaddr_end - vaddr) >> PAGE_SHIFT; /* - * The unused memory range was mapped decrypted, change the encryption - * attribute from decrypted to encrypted before freeing it. + * If the unused memory range was mapped decrypted, change the encryption + * attribute from decrypted to encrypted before freeing it. Base the + * re-encryption on the same condition used for the decryption in + * sme_postprocess_startup(). Higher level abstractions, such as + * CC_ATTR_MEM_ENCRYPT, aren't necessarily equivalent in a Hyper-V VM + * using vTOM, where sme_me_mask is always zero. */ - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { + if (sme_get_me_mask()) { r = set_memory_encrypted(vaddr, npages); if (r) { pr_warn("failed to free unused decrypted pages\n"); From patchwork Wed Nov 16 18:41:29 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: 21222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7560wrr; Wed, 16 Nov 2022 10:50:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf58usDxoIwB/ZgIc98bcWpRmcDTTC4fGo725Q3Jl4cLgFbt1TJvIfSPRomlkVvwjRPLTpgn X-Received: by 2002:a17:906:9143:b0:7a1:b555:6f1 with SMTP id y3-20020a170906914300b007a1b55506f1mr19643754ejw.29.1668624656900; Wed, 16 Nov 2022 10:50:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624656; cv=pass; d=google.com; s=arc-20160816; b=NCHcCAcnmlr0jxyoC2fHn5FicNoO2qTIrQ/WhRdZe/jNElmutTXRwDXj3udRukyou7 R80fj/P2jO+E+twi9jIffrhAtR9kCp36JB01dEXiQBa97KC2BVfAKuKwejCiUxFD1BKx 1suRze8sybIauBsavitFA35U1AKb66+ErzVOlHPWIIy0vPiss5Ihz8oUVv9PXiXaRfIC oyo7zr/kNpDeGwGs4agREjYwV9ikaLpHNdpm0UdV5zSGxiih3uDMdHAkIlVHihkVzMtA CznykqaBs/zhXitjRNIrx8/3Dsf8H+B+8TpI+WVsBwSAQHgk1NvOzTG0FrUatSnF+4lS cU5A== 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=TAJjZIeLGBziRMUt8JU3NW/gfbVay1UmgHRMzXLEb+A=; b=cvHJ0E5f1A8EUxwqLrmFjt5zVai2SDC3jqZhOA9YQVAx7XalmmaKhPMQGMx6fK6XXP 1mS3sixpAcAJ7QDDbBFVgGXNBL6j/OpZTUQgrUbLzJW2aLzMQ8M6qi4hhAqb8YEZJz5G YkEJp7JN6AMuVQEEyg/BoJ4BeFjv8riIhOnWwePk4scmajqt49ujFQJnE0XSxDoyv/mk YKWTi5qX8UXP2Fl9drUoNAwyHkQEUMDT5/PCdmlycED+YDm/F1wMsyQEjFC2F1VDaGen C+YGDN4AGI2DddkTQihot/iQkA0wMAJZmuzBbbfSOMZvac/e7szsC9eOk90o5KM5fBOs 4CDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=UJuV396G; 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 ne27-20020a1709077b9b00b007ae0e8f59a6si15959322ejc.821.2022.11.16.10.50.32; Wed, 16 Nov 2022 10:50:56 -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=UJuV396G; 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 S234206AbiKPSoH (ORCPT + 99 others); Wed, 16 Nov 2022 13:44:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233895AbiKPSn0 (ORCPT ); Wed, 16 Nov 2022 13:43:26 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A49B627D0; Wed, 16 Nov 2022 10:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XmXdOpued6dD138prVJYigkbWyRvwjvK54QsQAV501GcL7CVM2x1xmah+1MTZc28s7r6c3V2OUyBDZukn5jF1g0SYkeqA1UM41h4eWMsP2dpzSHp187mYBI7DC+CfIvkKhtvCuhQZlGqc0USuWruZKQEw0JPDQ40lkxGSXxH1mmCD/fr1tC7pLwQx2VeRT0IceNa6ozJtQjleLwrUhClzz0lXVRLk6Md/X9UATITTudMrhghn3/aHYnA6Uh2bM/2OVr74Ux+O7iG1wA9Q6MPwm25U6mm2hF3/aXa3YWmGctSh/GjGge1e0+17LoWHANCuPVMHjqXmuuNv+tBNkCp3A== 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=TAJjZIeLGBziRMUt8JU3NW/gfbVay1UmgHRMzXLEb+A=; b=ONi/HGLa9eZzLAT1vF5WTQGf7G1Z3fuhyjtLUKOe1SkIkJoN8ZEC0iX5qL3g1gTOD4JPMbisx6TvzHfU736NKGrE2a6IF4teyaxw4t83utSQBaCWaM5pOPI9wwqksKBzw/O53aBVrbInavKFYjf3V40LtXWBHUb/8YPGOBCZVIqGu3/bZKFbAZqaADC90Z4r154PdNn4/0OkLw3GJK1pwblAN+dcj6wEyyz08+poxR/ni8aklDx8IP3UTFMgAcZDvN4BGsxBxzkK45CBHx9JDUBI8Ddn26rC6nVeKjlGBjXYNoT4iCzaBhP/SBjG4QKD0JqgWuFP91K63hKL4vOuDw== 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=TAJjZIeLGBziRMUt8JU3NW/gfbVay1UmgHRMzXLEb+A=; b=UJuV396GjJG6ZcmQvMSvnfU5cEeG7oquPubph/e/0kmpGuF4zoDTyBLHUnETLv57b2/Iq3mmYTTaVpB73u+1znnDZ0ZNe2IVMGkFSarnoWf4k0HAftPh3YBan6EgpnVVjF9p6jYgdIjw5lrRAd3+l6DXsXLf5IGGB8tWDyqvuwI= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:35 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:35 +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 v3 06/14] init: Call mem_encrypt_init() after Hyper-V hypercall init is done Date: Wed, 16 Nov 2022 10:41:29 -0800 Message-Id: <1668624097-14884-7-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d65217e-3b9c-4acf-ed5e-08dac80253ea 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: yNVIrArlO3bLsiM9KXIdg13lyAFEiSP5Fe0Ss72NBAxSYPeafJg3N7xbKtoBWkynsVDdoEQqIVq/tHK38+QEqPJxzUjISllRQDIQlu7ggH0NmaStloBRBC5qg2PnyJd6Nq9hrbk2MrhWhqw0lGfkXM58bIubi5J5yF/mSHm9KU5mSjl7LVo4/w/kIdDKEi1CtWicrNJV/5qjt+9eU0G2J1bOc/Y+75tFkrN06sZBngIgu7WiapAwH20MYFEV/a3i/eMlkZIq5Jgds5tS2Qj2KEIxHA3ppFIX/rCRR2QSLorWhe5Ufvg4ahyBHuBYl+4ZrAvl13pWEwhs0ZcVS9AZ1g+cw5suQtYz6PyBP6z5b/+cr50XPrWmspfIgZPvQ3D//0Oy24uLOfIrqkWDn2I8B8APq7gX8LBEsT4LgHVApWy2zZGn9gsPiix0sLicHC4e/eenYb+N5z/WFsItlq+3dgN+w5foffbqS4uinWZykVt7axeFdnZrcsZu4dLXqDyX5B1qUKJVKQilzHUTyNsQQeVhaHUTnx2YdNanmd7hjoJLmxYSWEwq/CvaIucv6skzM2Zqtj7qFBaF+GqoxbgSmkFhBauwe5Pf9repqOY6RWzF28w399KCV3Yg3nCxWP4b/+s9HUCtJFTbfc4h4qVjVeFVtlqOINZNpxHmbtncjMhUwEk7lEUwqIVXbwstjNon3HuehFBWa/VoKu5GEiUG+jTG1WGfb1k18FGG0g9wUrD6ERnJxU8gPvxTOC6XzuYlS2crA9UOmKffjCuOYv6mKQYMdXSdnRIDsyyjleYhg6nKVYVh+KpMkRpWlzM7P5KfzmjwPEM1dwEMi8ItNlWnNw== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nk5RYgeWZErILh2AybHj1Rh5e/rN+6JU+8bBV7DBQWrEIwT9GPM7/sVl4kvzNcUyu3Ar9lgj//OcHKnrMOfHpNPIXR7WXp3aH+DEpI+nM0uQ6nLtPzjit/JJmYtgMHYNYgN5m7UrFvskqX72GrI+OU1t8cNcEQkpg9m9ihAUBkNFJQE2fDPaPlcuN4ZiyB1t2uYSMVt/GxPOepA8JjCXNhumMpNIk3xj3eWMpocGUGUSkch902GUTNEIB6s3O3EaPfggXKFfvaPe76IsHAYDhSxnuDMivSeXd7iEhvwxVo4z/U34HV4k4L42GBMP5h7cInq6SJ7OO2zPeSK/LH4frz4p2qdgXjAjzhpsACK4kU4ZnWcmnIO8c+6o6U1QyDsSvHaXaGfjqdA0vp7HsCYgNJBh6gHdcfw4PKcSs999YZB9k+CfyUvktghBSjNuyAQitPKVDxDZFecP7BY8+GUsDB1+ISLrmuPDa9s7/h7OqxUAnTb9uk7anQm6F2LVtGlxXlTFUbdOts5xySNiCGKse/cA2ExVvqAbh/3e+zirBlvHjCpTl6JVejlH824QezcjWdzK8yFkaoWIPPd32QHSdiTDkQ25FS7jlkbZu0fMxAJ7XXH0G2enQc84qk+1VJdQJsxRQXzniQ8jGWAgtFhSl05ljTGnq7mj0gz3eR0l2+rrIh/L1qQ7KxbdueMLgTjOwEXdwwVeesPyuNHBcUjRjDi5wve/8q47EcU55dRXHMM5z/dbyfi4m6m9UyRH6r0RLvBXdDUdOqW7uyzjCSfVHvK7eaXNUwVCwYdOGWth8/B/s/riSbThEShM+Ce+mZfqCDP884rj79GyN6YNdNzLTPvpCBS7J55D9nKiFfOgyY5hu92gYk8f8J/rO9Wx3idpHCocu928ccgzAE8MWaGKlgInSg3pMaib3YtNEtQaaaJGcofzzHfMHk+9xeHgBqeSHNI8MXAw7/LCRmys2OuuzCRTbGZU5655QiChUBuSiA2wtZH5thIgeIu0NxQNkT2JtJXWbJGvS1rMYInqKG8Kgu2h8HeJCg2RNn+p7XFkyJCbDJ/H4tKIIqc4jFgVnm4eFwOhSr1t1lvVWII1NRSaTpNj3ncbGutxOqNksKf7esx0RlHifUhCVjtafuMRNrpPsyy4o0rYBy40Od5MaHyTyBaaXb0fsB8W2BcrHqlZIySLZX3l+e6rz6XX0W/AEh86/DKf/zN3oAxW8uXP4WtnqRmW2GyZ+lTllcqZRV668YJWew0I7y3XX9/3OWl/PkY6GFQuNFz74reOZeWD9xbklSZqAhGmBVSPhcmkN+LP5wIjOlQBNQgSv0fYPhlR2sccf2j0eoG6hb3yK25f5YvY0Zx8BdmhGhXP2n0XzI4ZMZlAdN+y31ClQJ0PFVS6yLtCMIw1s+SIAcl95wJKSHPcmQ7VgbmiFiyq8DZVrHK/KS8KYQ2mUDBkpn+l1ECs2IfE0Wi9sGn/4LBmhQSG122SVovuP8ZEzvVeZwbWRBRtX36hVt8qI63xOikOzU4j1sqdOUdOeZayiQbSvkI6r3Hww4jSX4AdNJrlxDBNCc2+scc7kc+5F837yc6Poyv2EX54 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d65217e-3b9c-4acf-ed5e-08dac80253ea X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:35.1616 (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: 6ErtvxZYDyOQqshIpRpxKPnsDGyE5rgAYy9ybuoWfE6uY5NGDq5PmL3PHyGZtKOAQLLWPQb6lwCfWFS1VKdm7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679768200868912?= X-GMAIL-MSGID: =?utf-8?q?1749679768200868912?= Full Hyper-V initialization, including support for hypercalls, is done as an apic_post_init callback via late_time_init(). mem_encrypt_init() needs to make hypercalls when it marks swiotlb memory as decrypted. But mem_encrypt_init() is currently called a few lines before late_time_init(), so the hypercalls don't work. Fix this by moving mem_encrypt_init() after late_time_init() and related clock initializations. The intervening initializations don't do any I/O that requires the swiotlb, so moving mem_encrypt_init() slightly later has no impact. Signed-off-by: Michael Kelley Reviewed-by: Tom Lendacky --- init/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/init/main.c b/init/main.c index e1c3911..5a7c466 100644 --- a/init/main.c +++ b/init/main.c @@ -1088,14 +1088,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) */ locking_selftest(); - /* - * This needs to be called before any devices perform DMA - * operations that might use the SWIOTLB bounce buffers. It will - * mark the bounce buffers as decrypted so that their usage will - * not cause "plain-text" data to be decrypted when accessed. - */ - mem_encrypt_init(); - #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { @@ -1112,6 +1104,17 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) late_time_init(); sched_clock_init(); calibrate_delay(); + + /* + * This needs to be called before any devices perform DMA + * operations that might use the SWIOTLB bounce buffers. It will + * mark the bounce buffers as decrypted so that their usage will + * not cause "plain-text" data to be decrypted when accessed. It + * must be called after late_time_init() so that Hyper-V x86/x64 + * hypercalls work when the SWIOTLB bounce buffers are decrypted. + */ + mem_encrypt_init(); + pid_idr_init(); anon_vma_init(); #ifdef CONFIG_X86 From patchwork Wed Nov 16 18:41: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: 21228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp8487wrr; Wed, 16 Nov 2022 10:53:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Xd/RMILQvIze7K+qif0laFocMf+eHirO9EhLTFV7lTVzObmaO8Epcly3rjLb/t5BFQBwm X-Received: by 2002:a17:90a:d798:b0:213:9c67:1b09 with SMTP id z24-20020a17090ad79800b002139c671b09mr4923969pju.221.1668624795379; Wed, 16 Nov 2022 10:53:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624795; cv=pass; d=google.com; s=arc-20160816; b=IbtLr/mb+K4x5BDNwhp3ShhYvLwXhM8l1zRNuks2ciO1UXTd2NrdoIT40nz66GOcsh h6Fu6tC0up8c3gkfMkUrJnoiKKhh6gzrwVm448sQjrCK7ftAEs5k3IMtJ6bOZOB/a09r +nACzjROr3j8WYFIFk70/h3WOU+L8X4g7Fu1fP2pJdLLrNY9fWjFDylUDZVitN6dF/3O ed48xt7nt/bkYy2j5+207ksyH2rXBf6YLz4/S4x9LC42HEutaRRtiKK+lhgBOlqdy52j OpAguXPbf1K8iOKLW0KJnMPKkOjPcF+t0yfn/fqBhB3GHXW5/cTD+vxRBP3W+aqCmVvJ 51UA== 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=qPMtrSESHJaBt1mpSbTfPYvpZPUYx2MEcXASXYtjV3g=; b=ij40/qoOQylBdXKCSJVAjs+Ogl55YsAzRAbXrQJz1GBjqRC0MNti9eifMCyl50Q9lS 88JkrldXEKPDZBr71xSwdHGcLQfeFN4Fw/YJ+MEJxXIcO9Il/k+nSpHIeezZmbl4p98K Us7Fdnnrx81qmqr7acScXQtxsbwtm4y4OcxyhxxdBZVt15/GRk+zPIZFakZPEl2wmHX1 yPUa7dn8uQWoJlyGzG+GeMpwwf2rjx6ifiqWKsi5jvruXVHPT7HaalXRJHjY/AHrSJZx 02Jj0StrBOZqoDWGKMN4JpUX7nJGHWNWy2Q/E4UrgmoBtN2inFzUmE/SQd77smiNPT8C 6avg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=IffvQ4qH; 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 g4-20020a655944000000b0046ff7bbe583si16614486pgu.702.2022.11.16.10.53.01; Wed, 16 Nov 2022 10:53:15 -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=IffvQ4qH; 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 S239064AbiKPSs5 (ORCPT + 99 others); Wed, 16 Nov 2022 13:48:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232971AbiKPSnv (ORCPT ); Wed, 16 Nov 2022 13:43:51 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFAA26316A; Wed, 16 Nov 2022 10:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nS7ZDI6CzOQGLl5tiYAmu5Ok2FLCzV0w1btwOwnkP0ApDG8EGLQg5QAsA5WhSYGhv+SL0kD+xuHXrviY02PasIhFthReVZI6HQqZDWvz3oG2Q0qE8zSOOvBLNItu3CESYlb29EAcERrl6rO2Qn807DTcheuSsWVH1y5pOixEkpjN9TmUDaGoGxxTkCf6dYVIaH5IjdXmssk4nnBwMrJ854EfHu4f/CvLUmgZ5t3HtfmimBKV7Zj58nROcbx10yhPzEipbu1GYO0IZ2nlrBXX1gsKcayFyPCIz1++Nlg3OzrE6Z1STCJqjl5BeZdIZNkZ19bdyCMMxhgoWNEosvmd1Q== 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=qPMtrSESHJaBt1mpSbTfPYvpZPUYx2MEcXASXYtjV3g=; b=HBj0871pSOtxULENrnLyzr9VB2pDf8y0TxqUJ3OnATo7LuwvH1GfkL6ACgSXAQ8it9zShv0BvkPwWDfD127e7kvLpMgMCpI6cNZ0a9O3/32YVsO0IXMMe2sbgxVDFZ971Q/QtqlRnuai/h7ELDhFW1evoPi4ccP+wAs7o47abl7vJR0zJrxjjsQmp9d9jBBlnAkVLHeKSg2XxXAJBL1Pum57n3Qp2SknXyBD7+ItnDl9hGDguspCnUPaq3MyeTKXO0+U9nnj4C/4/1QimqOLRc1cmS7nk2ubPGAmCu+CoXCwVNBfM6y+3VuAr98ZKEtbsvOD/nEWgK+aem5GyYsuhg== 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=qPMtrSESHJaBt1mpSbTfPYvpZPUYx2MEcXASXYtjV3g=; b=IffvQ4qH6TlBcF8GCu0fMktrPllVyiZ6viWKscA4augdnUmJ+AYFfvj3R3+Nw0HLaYI31E3h9VpQsn6Sgu0BckR0wDwU9Bpn100OD2Fkd9Y7fKm4/efde/9bF9WwECgtpdWSpVabWxAkXZ8WLRfQB+/NIy8hUCRTNQAAd9Aj3Pg= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:37 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:37 +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 v3 07/14] x86/hyperv: Change vTOM handling to use standard coco mechanisms Date: Wed, 16 Nov 2022 10:41:30 -0800 Message-Id: <1668624097-14884-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: df8f2ef8-2a8c-4560-bc93-08dac8025550 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: 33JEd2u7gfestaJWif6zpGhoQ/oDCkUOqf7AT/0Qk72LrCTu3UEB062mS0DVymX9Wqw66K5Jcz95+GzSsZSnVnndR9Gq8s4SE+HgeL05yKQNLnzJl5v4jTkCoqdZPVtoX65ds1SBqJdLpaaZJxN0m1/hmbbBfpJjB19QydUntbWbycFatbhPldGZPYPqTyC40AHLFrTdknT7HWKIzYSDM3ijS7kp2hX1pAxsplPPActRjsbfUfn1awsUaworIn/TS0rsqtUnedrj0b3GIPURYOcTpYr83iq2QvAdxZIH0pEG37cMtUqZmFGDiEXGG3dNjbikSZgcRGIHTHYF4fuzY5Ms3ja4Rj9lIE1BKIQ4acYlKsnqwkNqsIU8jLfC9mp4ZPi87zRKmBy7Ys0nLmWvxk8n7MseoOYhiotN5bqaitLrkqL2mmELRwqQHZaLKKHNZcsYmYRzMsF4zi/BTEPB8rMgE8rYeRokg50ir38qAQ8z+yFAVvFNTE0KMLdydoKYbvz4ejlgkGq7h0PuU1wwKS7kOUBaTJw4yjVJr2GpxR7x52038TJp/aOrIMFMY6+2IlkcKH/sFOago15kavBRMc1rn/0ZnD9aDMhPRJU0WpJSEg0UMaiDxvhb2qhT4fuwIIXFafkQIgAkCRRxIMAk93idgTVuF/l0vFiVllh8qZ9Mc4T/sHgeP8PjSr1JnDtXm4nyJfK2qdqoNu9z/Yjb0rndj5d9dNum+QxZr57/NmIlqAdMB04+KA4pc66QSgUYupR4h3PjkRFU/mTDLSgdXc3neltm4AGc30uX1tOAD78oWdxeqT1ZAaGiBFGAD2qz5uMnvCH9AfElkuQe7WBMvZ0YqwdPLxslY9nk4bYvJd5GuTI5O69OL8AaBm0KxZ/mx9RfGkfAYvPlvX8+NafY2g== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(30864003)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(966005)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AokvdOpD4ogBK/smO6VWKVIFRcIvVqF/5jVCZI1gftI+gZ294s333SKlbNGbniE5A4jxGGWayC3tObkC/gEVoYm+b5zmYK6JYxugQQtbnGtc229Yc30j+r1NT1EyfPa42ZfLpOidDQwGs/hjzg5Ry4iJUVpouyQmFijPu7FNjv48SHO91/cQ+qSEPykGRUIxMIBzbhPxAx/Zslb/0f5uVaNQYzLJhbjfh+K5TBDprPgxIwUQksjUT2S3z6TsNwXPjxgl5k1zuvfiMRUD15T36Sq7WHwcw0rc/oev/oJYhDwxiOdbcnqyzHR80vgOLdHizw+Na+JC9T+Nz8QpATZdL8wOMIIZYeIbn/DCVrGNj1t5B+/ocnWtSFQSXgrSCTcVgwCi8HZZTWWxj+ItDspkbl/iU7+BXuY2LnKdCzdvA30ymhapM0GAOKzWgxOsyo0U6r8RKRrIXgQuONVnLlZswtwUskFo/Swn0szNmXsUmdmBIFk1V8tBanGjSkosPtHf0wn50/FIcrgInahH+dzAKXJtTmzNutlu0XRkqEzybBnTHz9k16VvFHHVMzCHLt9CryQErxdb1R/ySCwx4ByYyiuBwccm2wiDOGp5KPjqGuk4BpyNsDlqvKdUN5j1YRpSwzjg3qOieIRvd1dPIW6WIYMInfI8/BGeoWLiZl1uTJCxGmWZR+TAC9Ubq5sRO2fBbzKSMrFK8CDCs+OKlwcrdWne+wNwg+zXl5Id2BSiUZ4fL79PlPCr+fXPi20q5sr39Xh2pWnMQNYQMbwDKNF+hEr/8YKqJU/Yk9HQh1lV8UR+I8M+M3yr5uMFIV9u6iTx/fZ+mO3HT+IlZ6vAmf3E+64uBaU30gztcYR0XfqzfIpfDxlnIj140VpID3KvF41AI4QaA2s1HExvv9qO08Bjt4TQVNwDGXY0ZJljqXKh9NK0peOsM5wxpE4sscSYQqGLNYdw+AU8u3pjWmfjEOkRf7inPxsWp7KPC2PN+1GSWLo7Me8anwRkNlcB493cGGaCKVRDeMadFWIegEmQTSYFiLmAA+JvKkKFCPYlV+P3hNfk+Zy5SpxBiSFBoi5Z8Ne5ZLdJyJb93RznoIseDDfz4pLiD/0JPLFc8k9E5283p/SI0PIggGJfH94ey1ENKramhtKzHKH63j/Jh2XLvRw2Y9WHWBFYVhskfj0mMCCmYfn3+vdrQ0i7DiZf13D9W930X4cB5dvnbOlcN2iWmUIJ/MhyTxw0bjD8lQaP/Vt7VqviWTHRDq+qf6fKG+JWBIW9Lv8RKKvR52IjbAonWUnxolw7dPBrjjh6nQUf5nIdQhvszCsX4VjzHCVobLgJahLNu8hbSyA0MX7sGOZ7+Y58G4cdAmXvN1IL3XJaVstKJxDVm3cxd+eYPARcrCvkOKWqw5RO7zic/socnzrfVUpoH194MEXZ8hCi9UYg6fPoTEQcAyMxYYmgMWGrXTtEfS9fvWtI734hJ3XD7CJ2Q5ehFxjJL8qFlaylTceNKgOg9mk/0OuxEDdWx9iZNj//QPLDtiUDaEIn80uEgsA6pKnKzV8++DXZ+Ty36mTPv9ulkRSCoRvd+KtE8WLtgQg7ahlz X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: df8f2ef8-2a8c-4560-bc93-08dac8025550 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:37.5065 (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: D8RBwDfc2U51v/WNsu5H3CzbfoakMY2Vy4kq5ufU7/1/9kMDFy7bpM+FMrE3CLT4TP8AXF+7S5uittoD5k5fUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679913300958009?= X-GMAIL-MSGID: =?utf-8?q?1749679913300958009?= 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() * Remove the Hyper-V specific call to swiotlb_update_mem_attributes() since mem_encrypt_init() will now do it. [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 | 11 +++++++++- arch/x86/hyperv/hv_init.c | 11 ---------- 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 | 3 --- 6 files changed, 53 insertions(+), 40 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 49b44f8..f5e1f2d 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -78,7 +78,14 @@ 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_MEM_ENCRYPT: + case CC_ATTR_EMULATED_IOAPIC: + return true; + default: + return false; + } } bool cc_platform_has(enum cc_attr attr) @@ -108,6 +115,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 +129,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/hv_init.c b/arch/x86/hyperv/hv_init.c index f49bc3e..89a97d7 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -29,7 +29,6 @@ #include #include #include -#include int hyperv_init_cpuhp; u64 hv_current_partition_id = ~0ull; @@ -504,16 +503,6 @@ void __init hyperv_init(void) /* Query the VMs extended capability once, so that it can be cached. */ hv_query_ext_cap(0); -#ifdef CONFIG_SWIOTLB - /* - * Swiotlb bounce buffer needs to be mapped in extra address - * space. Map function doesn't work in the early place and so - * call swiotlb_update_mem_attributes() here. - */ - if (hv_is_isolation_supported()) - swiotlb_update_mem_attributes(); -#endif - return; clean_guest_os_id: diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 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..0757cfe 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2126,9 +2126,6 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) { - if (hv_is_isolation_supported()) - return hv_set_mem_host_visibility(addr, numpages, !enc); - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) return __set_memory_enc_pgtable(addr, numpages, enc); From patchwork Wed Nov 16 18:41: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: 21229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp8513wrr; Wed, 16 Nov 2022 10:53:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf61j5HhUFbH6O16HJKbF4BQTyXyc4zHGsC6qAYUK685ETzap8CSqEfb0QmMr8eDxg0wSpyj X-Received: by 2002:a63:1211:0:b0:454:21a6:7ae5 with SMTP id h17-20020a631211000000b0045421a67ae5mr21928180pgl.615.1668624799216; Wed, 16 Nov 2022 10:53:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624799; cv=pass; d=google.com; s=arc-20160816; b=tcoqfXFg+rxhRWVnEV+TcMdr//ZlEUxLixDAgtk3Csele8jtIDcZU/KpsfITLuNaKP blH1D1/gOaeSZNZSi5tXJhW02mBMRDf7BTkKoO2tMQj2zdJ2U/ptEvkBeC1YKRWmp3GZ 2sVwSw9Hqsxzu9RAVE6+aAHydZwS+ewhPAOWFk+sEY1weB1N3+WnuGSHSgbsBAlvegLT p/97PBWdxDsz0MoqJIXH0cWxn6+8E0/ChXqJ7Sln+g1LQEEpp0faUnTycwSlN5UMwUr8 3PIWD4OwXwMleLR2yzem02iBfFBdNp5lPNTN6b+0nowP+ORHOFV14vtOhr9AwpY1dpK9 +bzw== 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=Izt1myb32bmYkZOp1aV6UIn6dwyRz7jn0QJ3An8PvH1HYEjSAXRPH4rb9NQqrBU+8l fswnLV3lhSyVjSEEYvAyBnLIfXgbI6net6GTTs0++3gJaN3vdaW0lL2XZffbMCSH4sLj 7oQvYzrwo0A3yY2kzxBeZyLcdxZ2oymY0CkjVdOzFmZ5OTFWffyGCcaIJSTOTdlnNgkg x3jGqPT52oPDms5yfVZ55TawL6Debx8MBwWGgK14Gm/8YI+5ri1Bga1DRZxs8XrcbtPa Xaj2suGdXS/Li8FySvG9mlSoM7x7/CGl1GYBLg3uwPoWuxY6rZbAD81aX96THAt72XBZ /Sfw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="Oqfk/Qiu"; 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 b13-20020a170902d50d00b00186b3cb49basi18130860plg.202.2022.11.16.10.53.05; Wed, 16 Nov 2022 10:53: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="Oqfk/Qiu"; 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 S239213AbiKPStD (ORCPT + 99 others); Wed, 16 Nov 2022 13:49:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239281AbiKPSoA (ORCPT ); Wed, 16 Nov 2022 13:44:00 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E34F63B98; Wed, 16 Nov 2022 10:42:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fH8eLjcXxid2VufDrAX4P617bUC2lu/tskNP6X81HL4soS5LO7U8x0ZW5w+4bXTxlbryo8AywPuwXQYBxa7QK3RV9zLKpKcuhxkietGnFEMWfQwTg8hy0/la9mYMjrOBPcPcFXKsH6oRoT4Yu53UK1Brv5fLyE8e4bujklyOl1LdACXKspnpCRpO+NcV8GVelYiKBqEcLv/EGeRjajPR2QJ1Z5iSg9uj6DKbUEbJ5G6utiiBufBgVg2XyYlZ7OBky4WRRRPc91wN9NscsxK8GwyZfd1WhJ7FBvs12cVQ/evYEm+xgWbg1lm2oCSJGHLaLWwMxh0Sij5rP9tim7N2wg== 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=ifV0n2eOIkmvwOv4s9uwRoy4CEGEjZTEuF7Tr63W+Y8MA40yyw54we0k8BP/eYaSDFmjKgAl7g+Pr7DbSTMDrTCY2EkdQJQqz9bjcDvQV9gLoTH2iUZ4FP719DFyndiAyhooqNLIiaJOK+xaHEBpvAjaz1MfbWGo+X69ajegwBTV1XwucesOe2M2k8ODTSbjazu7FTArkfYmJwd8ojLZvhVB4DEYmD5+35HSNsTXoIh/+WQX1m/dVQP/fHz9aqyKz+IYdk/WOLIeVa09hcAFRCvyqsmljq+Q3xwFeU5kc8B8GPeWkpSrDBnvJVPVaC4LRgrY2EyiLhgVcWvcAksHPA== 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=Oqfk/QiutCkL0SPpFATFjdaOSr4KVSo6iDCMn3LyREeAXa5+tVDX3i6QtKbSxaw6IDBV66Hh1YWw6MdeiJRT1qZ5MocFS2BvJXtmV4nrSuo6Tl7/8Tje0Lpu6txW5daJlKoOpKFPMzJuzfnDWFRjZYXb+YnbwOvMBAQZNn8yf2g= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:39 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:39 +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 v3 08/14] swiotlb: Remove bounce buffer remapping for Hyper-V Date: Wed, 16 Nov 2022 10:41:31 -0800 Message-Id: <1668624097-14884-9-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: fe84b084-eee4-4093-1e26-08dac80256a8 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: LlLr8jbVIhGS7QfPEWg+lyP9AL8NWvdwnd1jRDs/gVL4LBkWfV/GJn1sIQeWyIp4Zakt9xDVPURr1AX4RWrnHIIvOPoWydng/jYF9msorun2WHI4gtGi44jX83Mrz9DgU8gcG4QvNqyszVbYz5j1oBSRUxr9OE4LzjCkihOKwh++X+3LQZWS852rQiHfGn0TTmYei7rN/C7k6Pue+RGfnaUpiR+fklWZ4neMIzPn0+VsQ8LHJhO/Dgnz6QjY1OERZ8t5mY+R6qWd+SOFqU4+1+sbZ+2m+kfr1USdO0ZSka/yps2/o7oaS67sqpJxqhw5cPwtQY3tvkkAbCNUPEz6ezT19eZS0iSe7wIxdoWxbAVg4NjE7LTDejACy1ev9HjLqzTCiyXcKYERofk1iMBpRBvN+5+NeGvWO2UENdp0btVByxFLAkpZ4TVYX/UVKsybzzbFezu5LwYuUIUQTY2db6qnMJQm69PaTstbKw6jqrpQq+TbGj0q4kIa617F/VM1Eu4I8xRTUknIr0nyGCUpgrhGuxj0iWDNfOHXnGFBnrnhihhdJgHGC6VWAYZgdYoXdLS3RuJSStJazEsFMwGdwfbOcvRGlzL20wKl51PHUMCChc/Ulp5lw7JA94B6oWQ3qbJ82VLkEyGHdRucb8egJ+mNN39JyEmz74k8jdDiGSlV1mamXkogNsM+u8MNdEhWW1+7e1FV9jDi6ZjpmczHtEWiDAIZbTJiR0EhKUYVS8albtVv9HV6ERD1P4t7hIWV5F8EX7ag5gEjOgfxUuwCZg1ZlozlNzahyDgVPb/QzbxTDGq+RqRAW03dprw+JF0QIOGy2B1ddqINrtcSASj5Hw== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dIB6YJnJPGK/K8LxexS0U8vZCjv5wuEg6fmz+OeA2R+N7R7+jmQtZgXoxk6qNLEd9Kso5VTSbu57mx24THBKE2wD7hQnjAHdnSEgA5YU5uY+Bau9oNjt3rw1zLGeD22vWjUD6mQ1DWRaf2vvnzXhjMP4K6YB66zBtZ94MvC65QlyMdOU3am6zL5ATaNFdJaA09Cr6MiXySegPiGqReTsJbmsq1DoIKKuxqTjYpcipTcjHDbIYUcE2TCbvLrWFaBWgkyrvjIK3wLn1odM1gOdDM77HuGYkB+hRSmz7iN0K6Smmh/nN9zAHFhumiSSZ0go1QQPoK0pNzviXCUa/HOnfI8Plx4+AZaBEtGKUyl77kSCgNVydEZ9HYzvmD/aKNC/np4u/a5aN2WZgkbg7ZlU6FHt/OgNSlnfKYReeLzgF2+as16/BjaybsWqlYjMLC7yEiK5Bp90rQEAcNZTtPzgTWJ8BDpgpwmNMxei/mvLa+i+pilPLcXLg2TpLlyCOm/TwDhio6RrsZEKltS5yhBmK9WhQMR6gX955pq64/jBlmFlzwVRuKcua6bNf7P1+G/Qiog+GqDvAeo3MKaiBcGiGCSj2ashHbQXVo+3sl4v4v4Zz/5s1LlSYlYYontU/smXGGip/fC7Ay4LRAAR2HgrJUXZMEzT5D/0IVS0IwssXIF4l9gA6NpRAxM9s9Vk6iKM+6OusArMkNQWODAMqwAo6wRdvthYTcX6ytyj2OYTBEknYNiLbXTHu4snW5iCmjhDQDLl2huQNOAg9n4JMHL77g5+spLRgXlCXdy+tBEUuP/RbMtGrxo2BJ/KqyhNI04R+TOELp2832BjCdsVwuzvZoRdadyknE8UyeTKYHXc6fe5ldB8cV9mrNdSEL8bUbm4Rhy1lUOpfworzT0qGFa22CivbvZdXeKh71/xyQ4AZn7+K9KS6GHMgesBvbqbAY9ZSs2FRLLmYM6lBpX1dZf7j6zUvFGt0lo0Mz85+MgfDhK2M7CXy20SRFS/H+Bg0WTiPaxdkHhXPzlfyzVSNsFsnO6+7JjpuIRoIlQl6/jd04+MxoYBOjAG2R8BfKQi9HUepNcavMOjeTnAgTEVQr9BAeDsJ8j1IlHXyIMQwqn7FTE4A9NThNbprjLfp5HKIdguAueN56wqu+mJtIytXpmyVvyVbGt1bt4fvQ6YQVn7qZJCFvkLlkFb/PPxyrxxc5bAeBba6g2svS/8Z9rUwdWrf792LfxACvZ9v66stIGq9XX2U4pbmSxohzHjSJtPOc/4+XluMvO37+qi6ih5FKzBZyxon1SVVnSKURm+VrosAqeJr/F1Dqx25dCh8ofjLBg9wFNRX5V9AYDPe8JqiRM55jZJyHE3tDyWwSh6LiXdNZ3xvU98j0YWesrnb4P9G8dsaddJkIA3P3ppwq26limZpC2rPUXCN/Bfy/+f0aY8IHshBMVSJuE8+re/Q6ZZ2/XKfJ/vwfL04aDwFNwcJgxRfkIaK4g5SDFaG9ccw2fwV8VuQQgW2Yiizui7U9Bb/ODIgvLyouiFOksETxNIQRKMrNwxBKwYrlsW6817JmLQigDVNMt7550NJIWSgIhSHTDh X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe84b084-eee4-4093-1e26-08dac80256a8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:39.7725 (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: OGtaTkmm+WyPj1qt4KrMB4dq7kMDXcI1h/r/noBLGRoJGhpmNPp8iRpLQ1FGHozsxOji/woQct4QnQZBnbMsUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679917417513706?= X-GMAIL-MSGID: =?utf-8?q?1749679917417513706?= 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 Wed Nov 16 18:41: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: 21223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7649wrr; Wed, 16 Nov 2022 10:51:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf7cz/xMWrv2k89XJ9Gu5QJ/rp7NyDUJNypxRvR1gjcP+DKZ20Jc8PlO0vJxIDeBlWtjxCVd X-Received: by 2002:a17:907:76ec:b0:78d:5966:b093 with SMTP id kg12-20020a17090776ec00b0078d5966b093mr19931011ejc.343.1668624669253; Wed, 16 Nov 2022 10:51:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624669; cv=pass; d=google.com; s=arc-20160816; b=PWgUEdSrAomjQV829JjNHwbN2PbR5Rnookv+LY9Mpzy2qPnJDhZbx2Y8hvfhJXhNRy XWA38TLWFOtcfOy+TsQqjsb0PxG1+FPlXQqaDREJ4BAMGurjGXQlvo+kOJIgDZLjDBjZ MYeTHPMOTKKp18oi6CSxILB1MG/3Ei01SmXnpC1IeqcEmInazJBO2ky3YkMnozhgGslB /DcQNitHwsOlw26Yw1KUPddbesElH1JgSG41KdHca2cwm9TTb/qZfBLbUV8S7J6Rb6u4 0ry8hc4byf0zytg5H4FS85nds4mdoNCEK6WWZoYjpTtanTPruXASGyvYFf7uQNhs5KyI oXug== 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=wtycpQa42eWXL8gqSBS+tAd+BpKwZW4hQJ4cQkYN8Skm+Hi1ZMMnJGocPNDK1iCk2r eAuxMVT049K5IjIpzTorLuCGfKUoFcHJZAfdqGKaqJdX80dAV1ghRKN6KNvXv/lRDujE MDGkiezp/J59GCBrV32xmuSTSfzHQPzlqABMh/5NOEU7aZlDimIDF9iviZOcIn+pek8Z RdM/mUypj/8epEfvwoMSJX3DuQLICBp/dVKsJm2GkLfKlIk8YD9+okvHFaFqVnWRmG9X H5gcJklPH8Y8OLgJXkrMTGsR5os7S3gxKZD4bK0p/yQTBSXNih/mQQrQEIgdNxdtwGjU b85A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=daNn7U6j; 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 jp4-20020a170906f74400b007306ac0faa0si12711456ejb.615.2022.11.16.10.50.44; Wed, 16 Nov 2022 10:51:09 -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=daNn7U6j; 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 S239300AbiKPSpJ (ORCPT + 99 others); Wed, 16 Nov 2022 13:45:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239305AbiKPSoN (ORCPT ); Wed, 16 Nov 2022 13:44:13 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022016.outbound.protection.outlook.com [40.93.200.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A2764A27; Wed, 16 Nov 2022 10:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ha7CP/+32QVIWTPUNrHpjkWBixASNIg2TzmXsaDFLqDlWvV+agdk9ki7QMC3eIzZ+zGI6x7I2HCNMyBhaBuLQU/k/tK5jN0eaCZxE6DfykXbbHKNzD4TnEftE43t/x8gqcPdNFAEHvhZANKVtV37p8gSO7nN53h+qWbnEyOzYlX9E2EPFO72dKNZWwdjwLrrBq+PH2B+Cu/MdSd4Pm8RxIgCojZB92bV3L+FSu0vcIxHlQpTwFQ/UxkhVlnlrF9OGlwU9RFCy4ss9Bmn5WCQesnnNhW2O0eY7kA05Jh9XGs9alhJoM3fsnF8/UBmR5LqP8TM9Yz3YzuYTmscRCUNdQ== 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=lcx+g2fJHv5xGaRp7mTfbpiuo6V07LgdHPPC5nhu/wrSiti1Q6fooqzqG5Jpo/PGRJLmw52NAWJ1kQltusogxCtiPsNNCotf/WerS0wJiGjVPha2pf8r+rtgSQUt9RSnUg3DGOC5XghCqnsGmxVq6d9pGGW3g2ISPGQwqIcJWEKyt8IY3HyZaqbmz7SVXxkZboZ7yvFmBEIMbjlkPgrpkjikMwA3vowJmpAm6PTFmLd6Eurcs3OqA6uIeoq6EL+R3lWXMh4oDsIG9ZNveuBzrYKT2qqA7i9XV0uQYtvAkNXSmgItyeejRhb6mlIz3izTVIfocln97+0r5M4gpsgX1g== 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=daNn7U6jAO+wZ1FYHHdFW1GXiLagv3j1xnVdCLhdYKqA0mmAtv0/3+/2d9FP145GC4ut370MQS6j8qaq2sDInCfrH2+qhBM7Rn0U7B09evChez4XDopsv38DUwt2F+XVkzAe1UTKlls9EGOV4l8pdVzN5V5wc5QmnRZvgHoFowg= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:42 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:42 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 09/14] Drivers: hv: vmbus: Remove second mapping of VMBus monitor pages Date: Wed, 16 Nov 2022 10:41:32 -0800 Message-Id: <1668624097-14884-10-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 96e9a4f1-2e33-4059-1314-08dac802580e 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: eyMYsDy9qJ8JwyG8aV7zxh5UbbBMwjPzLCxeN5blk3A4Kv1k5sAdeuZAX77YRaJG7TxJZY14dOASnU51fO/C7ge5B3nraXy8hu8vTed9GnuB9r+vvPN5kYNG1OX0y6MWRi2oJjyM0RoE4jULchc2AQOq0vYV+buc3Y8NNf/X+jQzBP8g4QytCQgnYlQNkX3A72FByrtj3udNH3lGBTVGJKvK0MSjbiZjI1B7har1kFSUzSYn7Si3b1oL0x2gNNv5M5lUzZ2aOw/MXeDeAkhx0YOq7PrmPb14yLfpNyH0s6c5jxtcNzZ4+JZ/bNhwUYzgpMR1ytiFf7DAqgo4kZLlHPxODgQbPMyP6X8Da9K/UJ02OyS4Bl8t619036bZMo+MZcrcoxClZguKlfVmPluLOjZwI+piDJsUbLah4ndIQ7d5YN7qp7txNErA5owIMzTMkGMZHEDnxsZDt17dwL/gduN3gqPAlCZK5Z/UZ9dpu+ekM21n1yQmEoq1XrqOoEOxrIO9BeSsO4sV0iRO6lGlvRsmxlX7BYLHaWx9y84vLjThX/KMHTudY1TxNq8LuPc2LyAEPhoCP45+vMFPKYKdMCMrFTgF87BWEkZEFYe0Z4QKfpj6HTKYjIxX+YAbTSeAf2GpVx1otlnQJwP/waXqCS6ziebbZOwmqgxzxpjUNPVL6oT0cNyqSpkDjFbhQTwqsNIagjTLgbw7kW1urpLWlBygjGXnIlnqxIoviRuN+SpVb4V+VWwydGMMvByomQygqtVeLJ+IsbVx+oSmXI5AW5dz/+lHCMW44cSwIpsd/s6fo3OGD76CjnydezinTUQy 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DIIPwsl+zZpbAwiRIXWJh67yG8HB/6sqCgWPXF9Ejit3elotEDhFAICGOG3ML8/ISLs1xJWlGRK9qtfjmqL2gWHJmAw+06tGzCXzd9Bo1MbZHRCfL4uCS8wXHDejEXPxjSBpLDa6eERLyimQ5GIl90g9cPa01etSEo1rGprYAT3+Po17KksO7wfv9wPD5wDktJjzWO4Mt21ILpl2pu0nWS2yR21hYevVddPoExOQ69atKp0sicTSeKSuWgU7zqLZT8IzMurneyu549ZtDBUseM6YtQfzC5cGy0zHiJADsIR20GqggFc1atIAhmb3VmmEM/5LE7qqve3ukaSVV4lRod5gzDYWBO+uop+JTcRcOcuQ8St0SjM3Dmoi3lbtZQ61eb552x3y+uOy67YYiziuJJdEqk6MVjqtbd3RvBP4kXNHil3U+4O+utB1STmLKZ3jio0AtI4dRo3S2ITm46sDVboEt8Y03a6TQjOwXIaCRY5P8r4myiBhx/gqgK0hyL836HyVNOkoFXkmQqrVXS9M2ax9aCwYrDrgKtnA07kuEN5gwNEZ6/DyeGUpGC8b1zl++paw+gNFq86/otD1HAlxCMUNu8IZp4RiwLr7NacZ5axS4nXBke2LZwBGCtQyH330uB4y8+XoDGbkk3ei23Iw7ZS5xwDht9nxNcaUDLoeSaUhhamAZYB1MyMX0c/gbQHwaNvpKs4I/wVhxULPosD9HeND6c9i8xqNoanRvIDkOjGVldTn3OH31SX9LT0+eCrETsv+qWmIHRWzZVWpNRjRBsQraRnFP3t1VsP47Px3ruhzVw+3l+DCUeM1RSNr6dInr3N1c0Y2jOxH7d3+OSW8xQjP7d0PfeDPWygCau7gjyIkGjp+cm+XaLRIFOxIKbJqK+m5j9SdvrthDEzE0oW4RYTBVG8b7Xdo17ken8L/XBfFeP5w9yOu3OLCW7T0xLbWd4G4zuPs3eLX54SllsBephdcuqqXUFxn0M1BsYCIUEIQRbPvNlxndcyN0ncNetDRRe3xE2/P5Xr7DHv6LR0U1WP6+aJBx82W4cIHgoKB37HFoPBRmQSvx9LXvZIi3jTa6sn2qHM4s+ly4kSCARtodeWHcf97wiQGEd1C51Z+CiRX8PDVgF5Ef41+wDs21J/4vfUMuFretaR2XJzsJXol7buuBmGYPqDdEioTmSBwP608rkfOF3Ge8540Znr5fI7ymY5o8I1AUghcFM3eGDX7Wc0wWu+EkQ91f30V4SJB5uXY90YDSUU60QBdoGvf9fp/lV8CauCr5qMiOzzZvb97oA5y1xTQ8bzFHL76QU+s/V4zR4LMKa9ElYjlq4z7DqTEN9UGHRvog3iy+CjemYk5m5/VEnFLTnCuZXXT+IyS4HPIDx9zU6jw4ApWjccEY/179bey0B7edScioz0UlBPNof+lIN8wjt467R3+bVs5IU7rqRZfayDoH15FDI4it3vxAXrQwhtNr56GdnI3gQrWModxGxVbJK1SXNne8djTd8fhJcqf0ndEFvTtPLlBbEX+8ZwPNIo1CxqL7I+EDPP7MF6/Jc+fRlqhzlSNcUf5ONLUn695H+6XvU9kAE74GUGi X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96e9a4f1-2e33-4059-1314-08dac802580e X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:42.1181 (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: zZc917t4Imz5aXdWompF/7OYDCnUbWZQd8VM4I03dX+gdebTnWlBQRL8ie+ngGgZsVELacdkH+98Hy7jD0Sdjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679781528630986?= X-GMAIL-MSGID: =?utf-8?q?1749679781528630986?= 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 Wed Nov 16 18:41: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: 21225 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp7935wrr; Wed, 16 Nov 2022 10:51:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf64DwDfCc1ZAOBY7MyDeoaQnPlS7Ov0ujwddSCBSR21c+Wvfgs8U3c2iNumyKsLFC4aHn40 X-Received: by 2002:a17:907:8dcd:b0:78a:efde:b84a with SMTP id tg13-20020a1709078dcd00b0078aefdeb84amr18779662ejc.744.1668624714405; Wed, 16 Nov 2022 10:51:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624714; cv=pass; d=google.com; s=arc-20160816; b=zq/MBrOSqWpDGkG7PEVO+fttT+Be8jZnMp5Y861n1wc6t+HazBZnZL+pXTrvM5NYaG 8i7B50Z1hUFHYRTEYk78vp4F0laIydaEcmj/ewPBNC8uz6yyh8rHkjGbn9bkIDRRmFV/ kIqLrxbnkh2GsO8Z1thtsMvSD0J0XHoWapgom5WAu/pGklWi2/LrBRY+lKLT/nOvTZWh dGf5YMwtl6azhh2B1ATrAuDLaLSusVquKDzV7MQrJakLfInXnTcg0/NR4Rif6eqz1VGB Ga5FsC1aUQuINJwNTRFwqZuqpItFkJJ+dMXpk1cRkzJ0KuaG2wHYXgR2gb1btYi6Dl2O UJqg== 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=mO43oPS20KfGgopWIu7TS63HoJI7dSgOGLxk9LYsTEwABHu1leTnnd5BczUzLiyhXl 6Z27p2JbkNqsQRmujFNbwQZwB4npmgcCjn7V7V8CNnVaRzOF8dTgglh62BFIeNZtMp92 Qtu5fSLfldkg+fiyJLwUzcLE0p46VTEdB8porckbQSX27VkwNyWX4eywn4rXQuW1E8NH 4z3kQeqP7N4RBhhRoWweOKOHRY7jRJP5AsjJmucNDUY2ghL0scyIr1M7drkzCNgglaLo yVjdmsCY8MQkW+GiuFF5/G+SRMH2E3Zgcl9GS7k+0MjLeYKD/O3QrDXQVAw9FJKH3omC 8W3w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=K4yGymIr; 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 e14-20020a17090658ce00b0073d8659db5csi16994673ejs.966.2022.11.16.10.51.31; Wed, 16 Nov 2022 10:51: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=K4yGymIr; 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 S238095AbiKPSpO (ORCPT + 99 others); Wed, 16 Nov 2022 13:45:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239313AbiKPSoO (ORCPT ); Wed, 16 Nov 2022 13:44:14 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF4AA654D3; Wed, 16 Nov 2022 10:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f3hm96vr14GprrcYHN1j0Nl+676JNXsoS08QK/Y+Ge8AJ1CXkYMSdygwMDwQ88zT0CTvXEzMFTLcU6ZB3iO0e7yW0U9wuQWkSs3suG78tArKMFb8z6q/7j6X65K4M87AABK/+iwz+NXNW+cm+Vcz2/nltL6dGHmRiC9wHOtMPyNVy2m6IcE1xP6M/98mNeAiMbMq3F+MxiJwrkCUYdRWt15ZVrjCWiIECFyyeiuPcZeU3GOeESaP7GkY8Eun7fUOQ7PidwMsdtsMjfwCQ7Ix3ohSe7KwgXHv/X9uu6TsuhvYZvY74F0/I1wIPy/wzThrve2x0XQE4M6sdAxcTjb+cA== 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=bb/wrS+937CqpUjepl2agNHSBtz9kEVgHGXuB8W1inx9fY/rPLQ7Ym7y/pipsl8ueREBfOoMrr22WiPLDGiau7tA52DJnYXPqPSBIIMB0cQldQlFtnz0+R4UteBJUNF7GFqpoOsiBvl2dZTWLMnDPdJsCIeoCxHqLdLlWehNbWLAWMonCXc13ipPCsqvNYEIgIoRJi49mjG/BN5XXTZRvpohtsHeHqEui651AyeIM87EVsS0C/902FJrC/B3wpUZzTXP3dqg0Boz9G/S39GcjmkwM6lTnSoy+QyDPt3EbjtfwNWehsksBbVdzcvrBj+/YoNHQkWtSQEVYtPq5GMNJA== 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=K4yGymIr2nVoFquIUE9WLh/xRQW+9f8l0mBR6zEfNEEMUhwYsB77spB/+ctV1FVVyhRaDt/GoxmUcwTYr304a/RAdn27BQUdrQcUHin4Cgld3qE7fHUdVNvVW6YyQeZViJ8ug56zJpEHYt2pIhT+CPp2d8VnGu+W2J2j6QXztfo= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:44 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:44 +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 v3 10/14] Drivers: hv: vmbus: Remove second way of mapping ring buffers Date: Wed, 16 Nov 2022 10:41:33 -0800 Message-Id: <1668624097-14884-11-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: c463e26e-e919-4e4e-75ec-08dac8025966 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: DV5N0FcElG28pd4hhul8Nb1UWuEqizTl30SEu2Rmzj0SDmVuhfXTjX7YvRoDDignDTq/8x1kAA3ylQx5UjBxUQh0EKNT6pdRXjGmtESV27YZs02IxPeOa6hLx8VgnRnHPYIF+Wg/IbQryHTixQoPxvIt/5P5Ensf1NzMnsNBr6CceNAgbCCoVeN4tlaGoIN2wRpUQoNglnSe2FrEZS2T5JZzenbVxjH9RWnVCIJeJ9wg5Y2BPNPPMiXma36Wt+M4DtRvjgVm1QsDGxBIuFj/VXWx9zU4TEpeb0K796sW4/s9WQArZzZry+/gjss0iXgKOn0Piv7C6Z9uiQbvA/mCbgjbMysE6WZjnlT5R4Zneqnre5H5zz2SpW+Qr+YD2DXRHUkdfEQmP2EXTjvnLqgWY5TCV5j5z9cIYHx0iOyF4ntrptlBuZmujGm79sm2/rIppJCPYDL9Dy2Z3HoLoshwteiNN4nhNElhfOKiz8150VbXzS+h9BeuHaRG6Sgw3NmSUPOnYEcOby5bq8hgdVAgLt2KU+hPL59nrMdLzQJWc2dUI/x+nCJrqSI9E9pWZzDEGHte+A0i2YqdFlub3Q11jd8/kggtqAji4F5CTopy2gg4ZEz6lGRCq+9vba0IQjxwohT45OVmK8CfNWitgG+nWUNQHdmpxAvpJb6fEbDw17o4N6qLbZ+sUPp67bYhBd4pyn3l3uO3RKoONS1E5tN+806yeTWD7bypEnGpRtALElSPvufJsGPI+CvAy+7iMceDLpUHyYMTCGRMrsfQ5nOD7a/iDSY47uBl1m9TrQyh8KqHgI4IHLHA8gkSi5OYkVqtrwt3eFJNnSc3qfY1/21ChA== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DNwxNa8l5HwJjWNmhKtgao9kHWkuHA9NhvTCIGiZQgVsr9BKSNAI66VbyGFBUNUIEJ103jyZkozujnLRTr9uziaeNntdZthGUaUsggfI6Ey+qqaeskGmh9plZBbIPemXBjw8fSpvkCvwfwVyCGQDUt5rrjW/Pj4A9h6VcugKzMDyVYP12tVfo0+7T/pkLVAF8TJm7L5I+Tb3FGzsrJR+9jmbHWExQtVJihNZdhBKuwc3FvYp3qQQzia3LG4hyU45hg9BSXJRYoXDgIMSuSPekriqqyaYlrK8n9SsxU3vkOuLluwFZ/pMjF6yrV9OVkpmwsh1F02uymcmkFIjXCoWwJwDx0rUgeZ1je6n8hQ9yn5m+c230nWyPaJvntHk/2LslwrhsYdZu0C+ibqAt0R/ZdotAM7NR1mE11pIaEHxxktGK3lv4kNkFUhIiTB+i2/RwdM3X92x/UDPezcF/9khHAOsaf1dsFDpF4wkFMxVVFxVIsehD+DVOWyYChcxI4GxNDsYh0rveKWBkf1t8RL4KNBfWjSurpJ5F+pENbL0c9t9nHg4vt6YykynGzxxUtu7ilDGzY9PK/94SDndeJRzlxFf7tncRGmVERN5Ce9BI4LNFoSkZKy59w7I1BmeeJfS+PcFSIjJj/SAuQSkYHu8gBBxaauf8d/5EACHFDgoFSGRuKjeZLtWk9R4l1Tg7okGxnqvEymVrl5Uxme0z84vccyWRki9RYM/ad7kb3kV4sWjL1eQwiG0LltWCYeGnQ7rG4ysIeb8j6I25kRk5JcSTmzK8u/s6IMqJuqSszLcrh0KsLF2O/Qs5QfBi9M8J2SdWH+e+k2m1sLSfZRYTFGw25NNfHSd62r2icsVEVFa+kk7x+2kognXr676lXigYz5JKFW/4l0zHuzDF/f9M8p4ykqCyTapPVZfqD1T9mb7g3Mo12LLTDZ+v7zbbkTy1UdmvKMJVQdIKRD8ZKC4wzhIhHDoog87nzVWYQTLGN5UQxnOsc7YtjqAo4W8A1j5pvbj5JRmwFxxIp80/AWpBnr5YGlRnNrRLEs9fLbxI7aKp/ln5O8uhUwaRQOnZ3wiQZC/WfZrtCFDkkx3wFGhUX/5TFapWaI6/CO2qaR5UozVMiolTavwFOAz73D7tYLjpLVqj1GdyUO4i/3ZlJQtPiilI/nyzQ9YJoKDjeS59zxl74djpzshK89fZRfuQrDWqnZN+h5ASDEyk+aA3YOojkdTrNuZXIbzyR7EpZ20Gv6DLcnlyUpQ8k5yVpfo9tzxZnKoghzNtgsIJ9zYkAFfof1wT0XSP1aAQ8hOeDIzOnmPUzsk643GPgAjZVS/n5mmJqBSPYrV5mOaJh/KQZy46KXxO1C8i3hC71D4t8WJua2PTD81YrTFxYoAY4fZzCtEFbo65wZnp+o0jq0NWP7k0kPs/NUljLGC/xjH3JHmaFSWBiJo4SPMaqusHRGFjg3M1xPY/Oh5LmH1OMCMbigMJBPJCqBUdBrhMy9qZ3Es8PANJhsAVoKhwMIB/BuU1wlV7s0ioI5fPU1pEcpqG+nCIWPsogSeL7++1K1FiTxRSbdbZZfu4u3GgABEk+oUw/dBll2R X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c463e26e-e919-4e4e-75ec-08dac8025966 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:44.4066 (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: Sw+Q+fLus9916g6c/myAfCnY2uzty6PdlsJJGcOT7CXr/3EjWzDRVo0bY9mTEA9JJztaR98GT/QYZx2aaRkpNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679828716427374?= X-GMAIL-MSGID: =?utf-8?q?1749679828716427374?= 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 Wed Nov 16 18:41: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: 21226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp8072wrr; Wed, 16 Nov 2022 10:52:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf40BeHMl8ExzdYKG2MHV+0/h9vLlfR/QhsE0wyvgd4/gCJ4WCfsMx843YbYmecSuhDPXbMl X-Received: by 2002:a17:906:1542:b0:7ae:27ed:e90e with SMTP id c2-20020a170906154200b007ae27ede90emr18461643ejd.224.1668624733512; Wed, 16 Nov 2022 10:52:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624733; cv=pass; d=google.com; s=arc-20160816; b=M4GNDBUbjSIQRZp8Q85PMLJy8sssaAmuACDKP3bhxcIXOKmXslpzxHZ72qrSyyuipJ fyyEHK2liQPbwKsJu08UmFyBTORotuE00o7WMpMBsUzvGiZEamOU4TnOvpJd/lKzArds NPylFYhnhgjJFw6oVtFjtAggJFkvUAMTohosUKaHC7P/7iYZ93ap0df2gD7LxuF1HFFI HjVA/RuK4+wQ1a8mX6tTyfdVdjpL0a9Ctni86CSi/WXz3g+LavxH5OaVse1/q/JQPtEe zfJIchIA7EFtk9zN75egxPrOZoP9cW6jNMYz8yjxWeCbpzIrR5rhgiLoXC4ip1l+BEjw 2RLQ== 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=xakj/K4CK1vwDqg5k23K3AsEUUkq78w7rAdjWvTVAwQIYWmazHjVJGxRm3Cc1SRx16 iI1358jeLh/yBzgUlx2LdQm7ptVH8WGyR/Dfo9zT9r/VaVITCfcXx9+Ooxebg5EtRLLG qtZ+5XWf3bfWnY+B+8UBgZhEgcMP7XBXcptRsqn8dw45bk05Kp/O2iT1G3yr6OUUHjjZ r44PxrtSOnXpcSm/iv63At9VWikpOSrVKZgPxy+UxSnNpvuxwWFaZ6YDUSpWItf+ZNtM aNUZfHSlBpdxX+TqG1k9uIiXR5/+0xfzmv1Qs7F67Nv+jDPRft55hBNBoBFCGZepDoqg I9vA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=L7s5NjQ0; 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 g10-20020a056402090a00b00461b2c3c4acsi14962685edz.515.2022.11.16.10.51.49; Wed, 16 Nov 2022 10:52:13 -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=L7s5NjQ0; 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 S239404AbiKPSpW (ORCPT + 99 others); Wed, 16 Nov 2022 13:45:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239341AbiKPSoU (ORCPT ); Wed, 16 Nov 2022 13:44:20 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022016.outbound.protection.outlook.com [40.93.200.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEAA661761; Wed, 16 Nov 2022 10:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ksp55Zd/lyk5iaj4B2+gcnJE+IVfC2zu740VKGoIRvHvxUkfqFo1wqC4jGt1lV1eVOzE1nqJ/m9Hfqjt7dDoqShzbhye7w0YGUPAbL7T/SoG2aXS07xCG4geeqJUxROOno2lV15jcsTC7XS07jR5iTgoDJivEU/a+SMykEAzzEfqcxOCuzPsmXfiNwCjPu7OXZNncy+rEukt1wCwKgUI2EIP8wcOVoqufEvtCKr6Uf+cJwiE8XMvy6HrEJpxkG7aIOF9C4hImof++u73iTe7XoKiU9zGYp9SZ9ggfkUDtkGndyO7Ggq+ZKoSEUPxwlURxfqGZqZS0DH8uSRzyymZ2g== 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=P9hpARPVciqlFK3pxkWnMNg76acFidG1FjVZZBiZpwWQTOulK2QR9HMQORxqx1I3qLsYM4SiLqL1p7FqMnK7O0+3E7ZZqVjGC3y8Tg/pUgHWfDTph+/0JA4sk+jmLsK2+UUUTm6y9u3BU6MNrF2yQR7DTi3UzR/YwtuOxKqbnN1og4d5P3QNMOcD+4ikNom0JAPJpcpMF2t+FkUgoRduxoeCphXCU6QBNjGTExWq4sw9Nf3XosFCHV3q1DyrpdPfzBAvk24lWraggoqliBMeloRcxHebUNKtsna88Yo6OC2gHUyr5TksIx+gMx2ZxI6JGP3OSbpS9V+A8wEa/pOXqA== 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=L7s5NjQ0IiGkxbXkgEGfNG6tc2Ste1dIznwKWQXXoCqYKYHQzjkbl83dpoRup//cyMxSO4qy04ntUrkRNT+/DwG+aeIvDBRYN55vCeOD3Jlm1PE88qSQkWEnnaJVu5lmopLE/cFeuPZEhYPL9OCrJLMM6FXqfY7+tvgHG4EJeUI= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:46 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:46 +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 v3 11/14] hv_netvsc: Remove second mapping of send and recv buffers Date: Wed, 16 Nov 2022 10:41:34 -0800 Message-Id: <1668624097-14884-12-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: d358eca2-6833-400d-6f50-08dac8025ac7 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: pa6hYN7rNMJnRjCNa3J2lBo3EkfKSjLOCPiYmKvn/visDITeqQjLNcsrYTWq1aiQchx1XR5WdJPBugXzcSkImuT/VLJlobm4x9yRmQYzLjNviNB0pT3/RAR4gBQAfvTxeWy992tFcrnKx4xOO/P0lq5xYTKeOR2UYpo6EsTut3xMqPkb2yE79iZxatqTrVS0B1kP153qm8LUsHTq0ngK7fzGOJBXmuysxKIiA3mIVzq/bweChVcLY7V0bJ3j2jvwP5JwmfFlxNXRAMWyVa3GtVuIkLAcqPCv0gvBjCOlziuexbgg2lY0Y/cj4FKWNr1roIG36SIkZNlgZByTEknCBEmH2qc+E5Akhs5ogWA9jZ99BqMyE+6OQ+hKORZxvXWVXGobZBe3+kbDgeXVabhAP2j25pP8vqUlOrZvm1rq4MfFLzOyrhMhDsWDg7CNHOw6EqcJfHrEC+Yi2HG6gCi+6Fxr4P+uQLso6hfGssIT1f/xDKvC2ozzhOCohd6wHmTko7jVZlfE941C4X+7Ts29/Tiy7YbHC0ltpDffv3BOm849F+TNoaY9hidUgAxfINochcwWbd7GHGrqN/gdrY0rXy4LnWcgAGsDyu+ajvoyirCwxE9icJHUG4uymIy9QGHPqUGsj0N+um/L4i18wXY0X7FXraiUErVoh8ys+1g3qsRgX1fA+whFrBVbFyaBJiFqNpPaed5Xgwau6x2hPDkZHR0qHFjFligPqJir3z0IMiy7nVM9djw8FXnujZk0NzZo6WvhAK6BaEc7RDF8lpwF5aNbmgOeoZicbbuRSl6NRh08Gv1D5vBkeKIlx1cMi4BgCyB6R+XJeCWZ6efR6LbQMQ== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yc4CwSYcgP60Vgk904adBOXJfSTQh7VMPge5almqZI233vy+VAb8Qf7MyQV9285rpSCnWCUzv5tzfksZ7ffv+8HhsJrejujNe52eejxuqExd79xwBHimFnyrHu3lOvupazM1HKC0moE2XRkx0aqr5/VJASBZ2fGmwUVakBzIZJEPSji+d9DLQyKsEfZtWBIO7I5mJmJAOSv/kBiskKELzdv7x7TyHvFhveTwQ+2PCl/orN7JQ9sP54UH4jdY+oOIvkA9nx/mEV2/dVrGCV4b/+HUVuoTnnJT1Qgrc6nq2s6iQOv4yWx93YllHLv2PVriQWVqvhoRX6Cj/yp1dzihAjzS/qhdWAmABTXDwyAOFxRtl/YYbW497kyzRdk9TUA+yRXZNqQrN0K+6KX0wdpgo3DsDUS/qDh8XY8mCoZY52D9YN+HQIWJVQKI8fZgTD1Lsr5tsGjwHMOqV4HdlMVCWAYu8fvvYxH/u0SDOHTsQSzQRhB9yrMcT5DJt/zpAm57A5pScv3iwl43vid6AHUfEk0IuYx43oXaekhqWiUQmq47WlZpiyIQ6Q6+0ohSX2TW1+Yxers7ivLJxSfLWucg7c3N/9fSMB2aBKqUhcWYtO8iYtKQ11WnmKvjjs4WqBUX64iKHJlcwukf85V0Rs6HukjkHf799Em9HK7D9+3LX+Wi+32N4O/ydHFJr0NXxCJFIx9KW7KKXPRgj+dzNawKnhXA1JxB0yBLWug9rLvIGOPCpzHQfQZc3d9uT9CUeFR0Cy+7t+JnMkOolkeT7rcvJ58eF6jYlj9/hmE20rfHvvEzMBiTSiK3MbEKjOOHnrel+1EP86lx26pa/x8vE6oDGp5Oq0bFUgHlej2Mh5gRJhdFejvV3whuRgwzGUYceT9u1Dg7NLB3IVPvmRPlZMkP/yxaxvdf3xqCPg+FXZHA3O2ftx3WoLw2F879VFCOCO3XpNLGbxi6XxvteXXwXJ4MgTYgkGYqEzVg9dIl0u2dsk/7f1rQ9WCBTNDUVmuGTjSoeaNu878d/c30w4NHOEA264HuDfnrKM3P5jKydEjgCSYpGNNUFjLGJNqdFREQy/Q0Mvvl4uAuyZRXgDIvz6x9UWs7q+myDl7XNVH6E3I01GxrlCvOzFxKkyqge6EGH8aLUlySs7+W+WdVuZSHuFSlsLv1CagaDlmqrdIPj4K2/HsDDO5Rm+KoTOhT9QjJhW+z+yU/FaOg2WRB+CRtCi0XcyqBzAp/oUEnx9I6JEC71KIZv8AjpcS+8oMDvVSNc0iePw/yNaFWt/2UeFj5e6K3mBOQdMdQKHaM8IcLzjgFSTIz+VLywB/VwNDuAdAdv5QiQjZGjKNeSRw+eN9l76nGKl0VKgWGI2DBChgxQ/0v0ygyrPI/ATbgJu3tFSIXWSKWxQTebhpexyEQpdRYRrCJOR7MTy1REApKKQ8cUxLcRUaZHLWpy7TuSthKkP56FPkKWlAzfmhhlmSk3IMi5Gq/2fwvWUqH7Fi4J+FzwQQ3m0f3XYuojNyCECRWNYybqA26o38xPAg5FeMqHfJxcINsL/6AszdorAFTXxJmhlG+L6ExjMCiqpQvLLA9Py5GzPXd X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d358eca2-6833-400d-6f50-08dac8025ac7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:46.6742 (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: Du+VJp1q6TC+mZc2luLhBGBwsLXgZ2lvUVaExRId1EWlAeFwjzxfvYMFiw/SmqjRRJCdC0erdBk+h9I5INwYLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679848343103485?= X-GMAIL-MSGID: =?utf-8?q?1749679848343103485?= 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 Wed Nov 16 18:41: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: 21227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp8077wrr; Wed, 16 Nov 2022 10:52:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Rht7vCDQ77ecZjsZBLf/qE+GInd+4ufMXGLvkySAGGI8d6RkItiPSBokpKTgsfR2vzoGf X-Received: by 2002:a05:6402:1f0f:b0:45c:6467:94e2 with SMTP id b15-20020a0564021f0f00b0045c646794e2mr19736247edb.295.1668624735511; Wed, 16 Nov 2022 10:52:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624735; cv=pass; d=google.com; s=arc-20160816; b=Cr1O4Oij40a9qBuD4YQoijQURMrDvz38HzFMLoMr9pmG0v+5mADqPKUhJ/hZ5ttXg/ /7ryKLlv6A0tqCbihgs0vf+R9pj/rf2UmRP4UIlRH3syP84wurgg7arspjAmo9OpaCNy Nad4NadKxCNVL9YBjS78MpQp574DY97ftCQmHIEMGzI+izU7Oo6SHzymxxmdARb6uRpY PjP3rc++di/JcJ5JCdUxlybDTQ1QFNtQW92f/O0bq0QV1bSrzzf5JWAOoMuTTn93BlGZ uyGq0MUFW55HUfjyfufRSlFPjT7jp+ghTkN/9M4nBzx1Y6tx1VwgDlOgO4aBWCMzViYL Zlmg== 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=iAFlpt88t8Ntbfh5LtgzKHnItvReHr+mauMNQKBarg4=; b=rBO7a7Weqoik86BWnux38UWG8qc5aBzEyd/hjRNCmy+0PogzuiCrwTMWn2D/7Lc/5P mCxIFUFYwJhCqYHuFJtVkAS4hFj27+B2QTs1hMpefOBJAdo8hPSTTGcScNIXyB67sE+b Tapz68BzFRzUUORHpyiz2W1tm3Vl8hp27a054eOPYu4M2VKz+qoeUnLCJAMiLvt7Zcu2 qpChCWGzj2u9UyJkP5F+clhih2Gq+XsN/JD1UFJsk7aMd+kAWm2LlHX9h1+XBfQ2CcFP H0hsyDwCr5brAWrES4zOgwqxxOkI4ZJu+dOrpyCX4YO2kt1Ycq166I4J0hpXZIBlyaGv w2qQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Rrm2QLHm; 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 la26-20020a170907781a00b007aa493b067asi11348540ejc.396.2022.11.16.10.51.51; Wed, 16 Nov 2022 10:52:15 -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=Rrm2QLHm; 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 S239419AbiKPSp1 (ORCPT + 99 others); Wed, 16 Nov 2022 13:45:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239343AbiKPSo2 (ORCPT ); Wed, 16 Nov 2022 13:44:28 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EB52654F9; Wed, 16 Nov 2022 10:43:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mUx07j+Ieta5NM5z50yxG0+/HKjZczao3j2WtDhbb0LojOSogz4z1Eu/LD5E/0S26Nfnsm+xBpg0NascrDNgwxWgCL/xbzToLJzP9dB71c4+fJSedHpaGrPDXZxIKlRduJ7cdpNFal/8NBtk1EImuf3Pc042eFXdL2tVRq8CDFCczwcHSpwxbdkFfbBDKqaFC9ZEGP7ABoWuJ5nklepH1P8S9qzzoIdcXcAFFVgb5+bpG7YdaPdKSIong+nmp5piDvyVQMRDr4H46j5JM0vr24MmbSPpL9b25eOuihkm1f3daC54jlcMIr8hh13IUd4iWDWCr5Eiqs/3iTRAf51xSw== 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=iAFlpt88t8Ntbfh5LtgzKHnItvReHr+mauMNQKBarg4=; b=nQV6xEoSeQtcKRB+vgIUUHKZdZA6FmF+AjuC0LIIQrQcHVFpY4NV2Z7+rzPWx9DSWSC0nkEs9VuPRDhxYVheq8hUT97oRF8BA4Z59AW1I68tzxV4QfkVMxAYBd5buMr/8Q99v5glm6ws07wuD9eY7tG4W6Ni4r9NWDQDrFQOxMudsHTdhhnmiw2HPLPT0fJwSGUA29MS71M3b3+dqbVyzEHeRBP+qasdNVCT2s17bTCdanIRnhljBT4hNJE944IHSEEZMHdkJx4eaAu7RJGyhH0RauxBJ/hAIpRE0L4HU1J0o/RG18QfWk/mZ7X9kXlL9BjZHIFxnLY9l3BHj04CZg== 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=iAFlpt88t8Ntbfh5LtgzKHnItvReHr+mauMNQKBarg4=; b=Rrm2QLHmN5MnCz1PJC/4j/mGjXJ8ts5gamRba9gP6zBlWDjDSZq0yevtuOmi46pf6WoYGL0BqgpaG4Ose0LHtrc4a1+PlkBEt4l89jrzrk2M4cC7yaeeP9v4ixer2UZE9OJtW83e8Jr2aam6Aic3z4rMX7FEPME21SgbTL0PrbA= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:49 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:49 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 12/14] Drivers: hv: Don't remap addresses that are above shared_gpa_boundary Date: Wed, 16 Nov 2022 10:41:35 -0800 Message-Id: <1668624097-14884-13-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a89cabf-34c4-42a2-3a1c-08dac8025c21 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: ZATUwa7iviBPa3uDhcChSj3J5gSrUyGSStGLus8VUO+8I06io1Q3q/nGKHqkx+7PidRvZk+tc311jdiaxkOzyWWAtrMh1LVOS9sbdAAsKnVNE473qE1bQS0uVi1M8laAebP2RrCNksRZnTffULMa5iijuzooD681i7aK88eYmaKwaU3oKejwDsXMJ3363IzrlgCFYv/6GlPnjfhRwj4+OcR9RVyVX7wlN6R9L42yybHV2IfPzGVx5aiI+zY61Bmi0W8dTAOpoqli1+fGTtcillhgFTUg+53LSPfOAcbaylY+TgpEl2MEQQaRwoeVtgclk1rwrKUPhLSgXUsrxXMn7++rww0ZGUtmlPyDVtokHbxsdzNsrBfxtyodIUU7H/aoDGbLIY+DbSXK3DjDHOmCVgAz6wtMbqvP2yWqeC8qRbvqZ9pk3BjBEyBD+phrQb9EOI/7bVL4DVud0b7LEXgWDrnNRRPUEULVV5Oa23oEHXQizo1sTxmThefeR1H2gQuRc5gIEK1dgtiBrzCSdSFNzSvQKOx5vc1+Eaz9tPr2iEjQ+M4RIqxSofcA4Aqnye4s71d8UuHX7pBUefeVTrKl1fp6YA0BED6sAhy1uWg6TrqjzY18vvAEqyaAqrwePRlUOaq+OHgIWW3yhDPj6PMmrvp/qEpedq9REofeV6DNK7GDnmZQIDhbVCc0qgbIGqfmRp6gU2tgK2zHPN3EhSIGwzJGy43lsibYhjEZOdwB+Ny5VbiihDqTaQcwWSFLfzpbADxMTm7btDM1rWxAM30OaCeISJTENdQf2eyJYn35fifNaEhZLPGdnSrqo93581mASgDrMk0tPMYNsZJxGFUlsA== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CzesoaN1gj4s3PFVDXo8cncydupbmpKmLPSLcPy4z+J51j5iV6cw1oBNY28i7yj1RytK1hdlQI1qNq860QV+KgtIao+RlmAwmAL7rEWUNXsgXW/x5VxUe1Eku2nK4HMIenxsFo4Zer2kQZvg4ctZd8OwP6UJRtmyzkBnIHEALBwHgPxOAdfUlR3qfAcbAgiaoAEfv78WFAvN0Z1DNM81SasSudUW3F2TnPsKfKjazhVbFZ6cj9s+2QVjPzMzz/5dfIOq4yEt4WiXyngEfAC0sejdkhItiRKFUnfipdtLqXJ9niu4zaAhtLJ6OOhtQf9EeHEHlv7wRFq04jLXjQy9/pdnPNb6IORw5Wbz98fTwvl9bubuGjiA+oGAmgM4Az7laxnH0wI1pNjEa+5bOuJBlzlCAg2xB43iv9ommMYQtD7BgtpO0+fc3Rstlhcw3wcL63fpZW6dMFO17jwtJzv1GQxOgLST6nqPqPtM1obJwrPdO2HfSWFPZx2AtZ1eQLlSJkPvDbsSWrICDAF3Rrn4h32eLs2nxNCRijq06LCn5qd7K2CDMAH9BH8J03ogFC+y6N/vJS23i+UOZk4AbIoAt5u+68fXOhu/rtCy2vjxsYpSe3EYOVTh9v+LSC1CsyuGQPPPm0cSWTIQYczA1+em7g8sEMNq6Eo60bM0q8RncESrrL/EHS79suBH2vpnup+3Q5uepYWzon8VJScix21DbqNGa/yF9NVSj6okFCK+rssPJHL69JUwFHODIflN6axA8fiZ+ofnTiP0wwT1IRPFLn7MUIIUhg2Hz3qEH5jMbC1SQe72K/m7QJb7EDZ6EMP5zagj/OQEv2UI2r26WsSJ0S46cfLKnsPqh7Vs61swJtVxaMvF0qjlfpGy5FmGxesUcvRuJdKZ4rFh91KBfxGywy9YrCv5xK4YIfZrY7OuAEPVa8OxXSWD0uh5lI5hYrfmNiPg75+kiKXom3DjXbMsB0PCpPsv7QTrKeJIA3g4N5p9FOMfNYBuon6M20jcMWYXrNpV+NYXJPqVg5WhOLJvHqJAygAZqksAZdE1JrwkRbnAyuttQYApN8QMLyJ2+SxdoJ5mOTqOD01TcqoqNj5T1RfibOP71uyVlagNqM/FRg7PhsaRCinlh8/SJ1v6E2K59a7Sf8IswAhjvEty5iux+4Lb8nOj4pWhEevSdvb7smqUZkGS7CYpZOKyc8GFFBzdMGYbiBG7psDibIY3wKQxBCTTpw/xi4McY+Lnz2shEUeIGzT9jh18qdnerfP3OouqVfqFBilkgNdOz9AgRLyiEFwVRdC9C74meuzK/dJ+Mm3fOKhU0xup4C4dztw6MGCySojNxdiGrtZBiLJ/vrm7MN+2P06aUeuJUmSPIRnwKkI8aERI0LjEmvHbbfXIX3+L06lFtA/icV+tDP7KyyhrTMp/msUa9X0Ksaz+y9KaHX+VtXHQaZqRD56BHA9ziVSRInZWNf+PQAPADa9jKGP8wH/NxjbNofpBxCyAG7bOL9/noxRuOCGzX4/Eu3pEqUJD9U2ZYkfiaocV5IrKWlKqxN6jhsg6mGDnuH/hn8HAXoUnNKF0lbF+oPvmhKdz0vHm X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a89cabf-34c4-42a2-3a1c-08dac8025c21 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:48.9861 (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: yPZyoKktdGZlN2jm4PhOfNa2pY4WrTfCzAcZeT6lLHiGITvpUJzCofBfaamlnCQiI/qvVQz3ljE8xCMJ71h7cA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749679850515373841?= X-GMAIL-MSGID: =?utf-8?q?1749679850515373841?= 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 89a97d7..1346627 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -63,7 +63,10 @@ static int hyperv_init_ghcb(void) * memory boundary and map it here. */ rdmsrl(MSR_AMD64_SEV_ES_GHCB, ghcb_gpa); - ghcb_va = memremap(ghcb_gpa, HV_HYP_PAGE_SIZE, MEMREMAP_WB); + + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + ghcb_gpa &= ~ms_hyperv.shared_gpa_boundary; + ghcb_va = (void *)ioremap_cache(ghcb_gpa, HV_HYP_PAGE_SIZE); if (!ghcb_va) return -ENOMEM; @@ -219,7 +222,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 Wed Nov 16 18:41: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: 21230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp9131wrr; Wed, 16 Nov 2022 10:55:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Ea9D7uAKV+m61hiwemtgL5B0GxLu/sx3VclxovAUUDRmpe+vWUz3rohnu1amMz04hW8Hz X-Received: by 2002:aa7:dad8:0:b0:467:3ea1:acdd with SMTP id x24-20020aa7dad8000000b004673ea1acddmr20819350eds.96.1668624904538; Wed, 16 Nov 2022 10:55:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624904; cv=pass; d=google.com; s=arc-20160816; b=GwBMfBjKKEmd1bog3mndYU/5dmJSfHPPjb60HLyJ0do9sL/pL4MadgeMU2v3bTnZ6r iy2lrpzjjZjEhneHNbzlyY7XPEATp4wA9acv8us2adO7634jAA3LtVM2hwqIuP0+c8bl cudiKf8V2ICqSSS5962/hLX8qvpcMOqxoEx71BWQsoMPemvZUtRnVh9WAuzjtfGWCWax pB1Fuce/MsC2FCY5dCl4HlQysk+hH1sjPjbpG0mJ5Sh6vsC7C3aqKzUbxKZg+sv0z6v8 kIuQs27aUqXQZZEsfAlPNPtX7OcdTOPaOReGVDZIw8UfbNj00rejfaBztJjyx22SqwjZ kbWQ== 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=gnQ+2wHG/qh1KA/H02Yt+id1FzOifmd3UOJKPWGO7OD03deLTKYo7kWQ3xmOQ332mk zFnMh5INxX/Epg49q/Cind2/Eo5VRWz5VwZuWMv6L7Nwx3AkCT6Njxxsg5zUNGopr1gC vRVjqdgF8PHrbLxG6e1JpN2TuCkDxvyX2OlUEWZ+aM/zbWR62VXc19uWhIBkfhKCv+jK EQIIv/3QHbQRg+cP0MWmvLG7EnGijFn2ataYvBORV/Tu5TLeGvZz8oXU6cmIwsxySLWj 24QENhmXYcRMKgLDo7RYEjQ8T8CW69sbGTxjGSE4wP8QjuOMuma+WQWJ/YRd+heO0jWL DtHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Ua47THS3; 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 a91-20020a509ee4000000b0045c9904fdafsi15014352edf.74.2022.11.16.10.54.40; Wed, 16 Nov 2022 10:55:04 -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=Ua47THS3; 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 S239428AbiKPSpb (ORCPT + 99 others); Wed, 16 Nov 2022 13:45:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239347AbiKPSob (ORCPT ); Wed, 16 Nov 2022 13:44:31 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022016.outbound.protection.outlook.com [40.93.200.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9370B657C5; Wed, 16 Nov 2022 10:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PpuFv7ng6Teu26kXqC6xCE73ohKRXkAZ4JU3sbAfkbk7UTrfMx5wjIkj7Zt50s6lpXjgojQyK6PGp805wX8lfUK0eIIF5nHU/iM88xXRl6qkec/o6AZvG9lWeIzxSS9L3R52IIAdEpuxxLSUC7rucCVxE0Sn2XORXLU+fzbChZ9MGdkjTQT+Jjkr5MPNhnZYMjVDwKHjG2PoQX1Z3JLgNqkhGmnslks+c60Zt2+avRRTkw8W+SNIiO3/p2QKEFIsmFBybENtZ00qAmujD/vmC+WDYdJoHx9ACvdC1e07lY2JQnzKm1WPHIIQsnl6x228RB99vO1kkJvbuUVd9tFuSg== 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=SQ6VXQgZWP2gjdPNjnOh68Euh4Gmk5ny+Bl7/uHrCf0O+rXlFKtznLOIeXKyvn9NurrmuNkeLnXNRJe2F9iYE/OhqRnTEZM/n4NGsfohYXg9tvKtNmUeTdg8efZq8S5FRXCLgpBJ6yKRbByv0ie/wLIGjSxfkFMRrRXkKW0qrheXsSN/9x4BI6yDEjDpqTwNcTeO/2WdA3deGZEMtmLQfF/U60IyCjCo+FpwuXhjkXo2q2LSMOGJmQ5UOyyJer9HGhGtkyeIb8IAqbKjZ1e1X6MIUJ9ofUXn0xjOgI1Ynai3E8Ks3Jtyj1T0wkyUcmZfiUeQr1ideSAncXjqBpp2UQ== 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=Ua47THS3wvYalbW4DOnMeJQyayfOsDVkxHaFnqnvUBh89sQh1a/MGg3eO1TPkar10HwE/wRErK/XcJeyPusGtktz2N44Fb/YQKlGkRlWIhYfLVVWu03E1NXEnXJcbJMTZuT9gmgy/BhLnryTY2uThlSW+zVgRDRz03mcXcPtiaY= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:51 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:51 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 13/14] PCI: hv: Add hypercalls to read/write MMIO space Date: Wed, 16 Nov 2022 10:41:36 -0800 Message-Id: <1668624097-14884-14-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 95ee6c52-5480-4257-77c5-08dac8025d7d 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: h3HhoMxBDIe3wdCu85oBIdcM6JSqWRxnfNj2m7W6Xo6zWQCiU5GJCf9ogJ37tWZdXV+BGVWuRQs1LZ/q6rFxsnxXAvXFCB9cSxKK9vzOnKGFWJroqZriNEkaA6svQBRzPMl1JGAo2E3zCz0gXMLd2yA8Bjf3Due1OemDYkkDcyvad2V8iFofC1Hf5ltg38T5mjCmLEWJ/fybWOYKCZlynEWmT2Pq4gIdZyZbyTd5JqBXzZhwKIkWDRXNIk6TA3kfBF2TowE7epf/JIJNjFY3fQIzVkb4W5gtJVtZUfxWabTUh7y13J1L5dwW1YOW0/Ib6heRhUCosvhWV3eqchUbxwVwN26MBv8Az5IEq9tpfSLyCORbWLn9CYsnOSOSiMx33eRoiPjpIcPfW+KI57SgmogqeBA5rT9xy4fOiVPjqndgHdmmQroupGKsoduHfDiir3o/nr90tvA3PkwEJT1djBWrrdu6FbSlZHlLzvbTkZ26z9Gjki7u/mW/nmlcXc2qEeIjd2+ZB0cRoPzh/lBUeFrERYNTk5sanIJ9Ty0QIByGj4SuN5S6C1l4QW4xbFDTAtQChjkUVdCPxBWGru0AO7nuyAWF+kYxaqlSfmHcl/EPE0IQbLXF5s89tts+2IzS2ZdxUp1obdiz26x5o3MExlfYCKmBuWFU8jBMBo+Ts1cJNgambKtlYPAischaJ+N9U+IKtOSRlEw86ECCCxJNt0VsMJXvYF86WxuioOLAbX9LFAe5y1OSqPOouiKVUrungUDLENw9j4rYVNFkrYb7mBseprFSGi2p0Rm0UI3b4WSQdUDZWtApcW9tYP/XlqNacoWe3459/45D6Q1pciC9rQ== 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /KXQHGKP/qhgRTUu8SAuok9/b5FML7suLovXaUy6V5pT3vGKxNfvJhTr803tfIaqpVPVZDPwBTfy+ZiTBRK+Yyv8BWOcXaaoOqJ0AKi1AFK0vIQJBqi04EWLZA7IqQ9/XeRYreveb0ClhPVstEpZQ8HN15mNk/qQc+OuuysbOggXGU79U5kkg8GSvCywWa7I3rKVb9tPBEJq+NChkzv15wDr/w+Qx96fafGVMM6tO9KgNQTCNkK1zGlUfIwz9/CWcSeVKEHwmMgTU0XlzcClZ9Yc8iScohGhVQqn9WmqfnBRdrGiJoNTiyU2sD1EzBfjE+Tgi2ulzOit3M1HoYJCeNO6ukLH1XKcH3Dopm6mEmg07Isb7urhYJrKSsUiGiJKuZeq3UFI1FSgZ+Gsd/IRSc/Ri3uCOttBd2+xvT6Snbj2iO3R3C6vLfWPIhDJaxn7LA1i/Yf0TLJKVrzjCpdr47IqIHGU0rXw9EIgWpu5NKFusngx1nenHalrVySKSAfJqNLnWyL63vZZ+8lV9pUhtxNXyUeLj6uf4hD52SjA1Ix16L0gwFXcBpteFFdXOurUybypWOfBt1Wfmp0bp6rceHUW7bxgIBWjPB81jQotHFZevaeTMM+pwOi/k31aRJ+vSS2oqb8wmccVcpyqwSSCDl4yLXzEHgdm8wMuRDF5sel2w4sD7IbxcP3Jzzez9mnDy0nC3HlbNi/JWwdIEA4giY1j+gAENV/6FVybPzLeBzTPyBbV58e/GSNrmjVHNRjCFIRkGaflETz2+RT9bYu4gT7pccLFgVHwLzLfSZHK/drj8bqUaoYQfPbaBEI8GyCV8lSzuQnP4P74LSuuodxlLk9LAf1ASwYllD8iL7AfwLztqTc+eTnKvNjnnnG6/fvMPEglHf4Q+/2NC39hrVihiXLCtNtAg6lLJ7ClAuMV9Kf/pIdmLN9rn/NEFEVBOFQ0gGYA4IgejWAvffxTals6fOnlgO6vKQt9rC+uLZH9HCoS0n9AGPK8/McIGwCHOuEuEVFgt4e3MCcbN5xvlSiRpvjSWwrvA95r6AkjJtBda5/djViCUy9YQwxJ4nNV2APZNSc/cPHP8YVcGQ43Z2GGG1Kn96ZIFZBo2hpdQfC8IRUOM3QqPE3Dx7+462Yf9ZlISfLgUQ2w3/ouxGSMokQg3nJGgzDYQ9IC22s7hzyoM6H7mQpMcRhHFuQhOlpgE3eiHucHQdXf2vz42ZfA8SYZWje1qsy7lB2NoFSJtzvXUWqZzoS4wCOs56Fv2PnPF2dy45YFexWXG/K5bp8Nt6J/JEvdKf87VCcCI0HiMiD+fMxjHIdfZbeisOZfH1yFKO6ED3ghl3z0pshHEPwiCFFFcuIsDzNlnrP6AQU++voRK1QKzoremvAuWQvHmjHmow+RQY4A0t8D88cfhA6Z4vgVSFDT4+vC1YN3PPRRV4gQkHXikaQrfUaBjUKsfuCox82EFWTL997quuiMwUaaR9g1GBa6oNOcVn5Cfj/PDwEKadRfITqVQA+p1rreeAB3Pa+uKfz+KeoPOIUMNfR/QaM3b6n3sp/0zNEfARZEuVfTIHJl4HW88xI6rlRYgVUB32Zk X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95ee6c52-5480-4257-77c5-08dac8025d7d X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:51.2371 (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: VyT7Qx0H3uiNuVTMrtM9Z7SbUmYDdkh0DD03Zj9oZ0CKYWnUzpeGlrIiidttDow2DZvDYu6iHFcAz9hCOSBcMQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749680027857578448?= X-GMAIL-MSGID: =?utf-8?q?1749680027857578448?= 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 Reviewed-by: Haiyang Zhang --- arch/x86/include/asm/hyperv-tlfs.h | 3 ++ drivers/pci/controller/pci-hyperv.c | 64 +++++++++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 22 +++++++++++++ 3 files changed, 89 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 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 Wed Nov 16 18:41: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: 21231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp9132wrr; Wed, 16 Nov 2022 10:55:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf5YGoCw81ACd5ZqjxPUzZlnwc2nuVeFTNful56mBUFVT2ye5DGXsLO6rxn7t9GeFH/y07XK X-Received: by 2002:a17:906:6b86:b0:7ae:359a:965 with SMTP id l6-20020a1709066b8600b007ae359a0965mr19138722ejr.621.1668624904537; Wed, 16 Nov 2022 10:55:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668624904; cv=pass; d=google.com; s=arc-20160816; b=zMz0svf46qSf2kOBRQ0ZlZrCHX/5C8R9J9jzLkd+XMjaSCbRXqo8a+PgtmIxRP282o sN4SiqiJKIhnrBaPbQ2Gt8kIXeRgDmtATkbGzsUF1Iq4+I/j6oPuT6kO+LL/lL9Tnorj y89EyOq6E9ljCntPGs+hKsR5/6ho4PwY4DDBarLXXTrfNGOfmjnwE/ZuuT2GNqF2iF5C /b1C5lsBuyqmmw7gVaCRgQMZW1GzchcoM4yKwIpNfhz1bq8JWRv0HXbKW/OHbXcEanXn 1lZJ9EGZCl2LkUfXCmExYbOJN+0p9O3xEEvDK7i3c7KMdy0gSp9a6vJU3YP08PlcQFSF pKQQ== 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=TFXIqRHMBEvI6ZU2SuCQm67MT8dkRI3fYtx7IpU1nTgPoNcDfUxys/jLHjBYcr4be7 QWypN1+SGpFUxKXgOjND0C3qzzFBxA+7roXEsJtyOUCsh25ZfRKwFd82CcH4N5wvlkxG VdeqB00O+cV9lzxE7YhQRHrTdW4GVAFj8+ziSeSbBdyu8uWhJ3fV4odgglP1l8Iz/2VU C4AMGi/XuOKCVfJcp9p1XZYP/DpilfrBCRlgV1gMnNRCb421+NRS/XBEgMu9Cv8TPFxT KzxaIia6D6L07D7dyQTLo2jhmYPrAdWLNEfU3zfeoJ06Ic0Nk/intiSqcEPLHC5yJDiA 5Afw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=iw6eek5Y; 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 w21-20020a170907271500b00781b66e7065si11260330ejk.240.2022.11.16.10.54.40; Wed, 16 Nov 2022 10:55:04 -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=iw6eek5Y; 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 S239447AbiKPSpe (ORCPT + 99 others); Wed, 16 Nov 2022 13:45:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239349AbiKPSob (ORCPT ); Wed, 16 Nov 2022 13:44:31 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-westcentralusazon11022025.outbound.protection.outlook.com [40.93.200.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C05D657C8; Wed, 16 Nov 2022 10:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e/zisvuJahIaQlxYEPn0XW/NK5EBhxuExWgvemQZeO2kD+WuK6YsnDvXOYGfFkN2cnAozEfXtQLcpzIdGddYeaOX0HBLFtwIgj9o52QELFEtH9llDXCTrrIAKdznaw4oHVvRmg5CcS0Q449sYpEsNYotlugqgsDeZFfPmIN2PF8ZbeGnl/cRSosslYNioNefzKSIZmm4pSn5J7DH7zoHTLALOVMfUQJFJ97+nTMvkmTFUVqJuR0eBgdYr5Qb9ht5W0kEPldstmLu7FuCRNRUyn2GFBlG39xk03Bo6JTMtPNQabGj1H+CaX4A+ybR03beQU6qecoQLIudmx0fjr8Shg== 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=OIMN2rQw2/OuXtfkMst5UlCN+vwPmrjSBXzhe4Z4fdXPRvT7kugoun8xCNtyIhTpB9cByhKHffYV4lEpcGOKuoPIPP6MKx4NuZ/RDn/u4mqgNPcstfEXzhonZaCorCSNFj8lEacuqjQij081xB4qNa1dF61tY2AQzRZcMHscXB93XBpv/6CA42I2eOLwSRhOAcq7BzDX+gBBdLGK10unIJkNmzAHjR/kXzyeHQyXX6yerkrDEFUfMjXkFBnrbBCtev84HmkDGvy/1u+9gTrB/5+4NNNBumUs/X+EF99vdVpQ82Vq0cTPwxeZmpp1xBW5qspp81U8oxa7vT/8vTTP0g== 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=iw6eek5YreYKRY3hkm9ZcBEKB7P+VoE5V0N+XbYCpMPe/JfZMUrQvp/ibvLNWQ5gJEcw59KZZ6zM4tuKC75j3YTL8+94jndMAXWJT8REwln5WIQQH1ogvPzeEDyTnyzBCKzYkqkJOFdYgEPefVR/0IWqBz/nm+wzYzCus7NEbT4= 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 DM4PR21MB3130.namprd21.prod.outlook.com (2603:10b6:8:63::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.5; Wed, 16 Nov 2022 18:42:53 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5857.005; Wed, 16 Nov 2022 18:42:53 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@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 v3 14/14] PCI: hv: Enable PCI pass-thru devices in Confidential VMs Date: Wed, 16 Nov 2022 10:41:37 -0800 Message-Id: <1668624097-14884-15-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR03CA0178.namprd03.prod.outlook.com (2603:10b6:303:8d::33) 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_|DM4PR21MB3130:EE_ X-MS-Office365-Filtering-Correlation-Id: 810e8982-f83f-4afc-8243-08dac8025ed9 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: kHHYlP8IT6S3zW8i2wWOWKUICfF+x8Vwdvt9OaEYViH4l/0vyo6kKKhbyxTvNbxoWqyhPtX6TqpYk8SXUq0F2RHJSDaKoSFFTO/rDHDN4ogFr4bPwP3zbTnnbMAxFHcSU3k7aDq80FpTkYELLTwq+FIl8zCbz2NMZxATKDuwglE/f10LLSfDm5e/2InlsOF6DWaCFXoKXf8BoObdYJ6Q95plt1Bp0aURtJ4P4UZG7sbLrrN67iLSffPKCgtq+n55KSJootKk3ujgFaZimeiRA932iyscYcyHfRAskKiDFdgyXhQYH1pJRFy5zGa8WFjhKKkl1/mzwY4ZcGVIiHZeFwuL17TALA9z/Jg1kaOsU2znCCXCJGMKgY63D85Hw79nwLX5cSL+IuYJMQv/jBYlAqZ1JDh7X3dbqzq9mGvyjpkHzs8O74EUxDtVGoxp+7IkMkr987cxiuLuevxWhWH8BRwQTVd9pGECXVGAA2RWpobV3e1AsapthPyolREZJIfDzd0DBUUNJPFzpiyfB2uLQMqMzsVwQK7A/0ojFbuZKODVnDjC+SXxo4jcRnqQgdApye3Haeab28Ymt/KEjedD2q46KGT4FzHlukALbXxIL6GT3Kvht/skbFbyfZktD20nUEjmCD+apvlcJX/kCocq+6oRPOmjXf9/QeRwF+WnfHf9PkNkx0QGtsl1bvx7SbgNqApVXxNXpc0mxvGW1NSOgodKZi3Orpm6bZgWMmpRGWk3WkjyZS4bUdhykiQ3EjeL1D9xhXHxzLVZsP9Okvtvw1x+rWvN4g2TlpbE8zILYXzBo9e35ZjAGa3Lm+B4xjsXY55SM9UFGWskBOs/csxkeWVZm78MQ5geSJDl99pA91A= 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)(376002)(346002)(366004)(396003)(39860400002)(136003)(451199015)(4326008)(5660300002)(8676002)(8936002)(7406005)(7416002)(2906002)(66556008)(66946007)(66476007)(41300700001)(107886003)(82950400001)(52116002)(2616005)(6666004)(82960400001)(966005)(6512007)(26005)(36756003)(10290500003)(186003)(83380400001)(316002)(6486002)(478600001)(38100700002)(38350700002)(6506007)(86362001)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2v19J1g01Mi9XTJpsXdZAf6N+2ng4sCdq1w4xaXop+1njGjFvR3ZtVyMMXhKx4RvUs5bKJPbWc2gjAb31kYxm40Kg0kxedpMWsvMebG7jHB5bnUEgHyFhk9+4wKfDnE4Fm9wW+RZucsDQ8uCH+UO/KfW+V7Z1UhV8bjMzT2qQczh2RJDb9LDInFmdpMjhVmNrv4tKI9YplxQ9B7RWeRYnkdvb+4gV1i3cSBxtcHFHH6fOjum5BMZMTu79Jqzei+EZSEGtxHoiwwiAciBidJJ5oEitaCVysrJrnF6y/DWdwzTIG1FICq2gqZd72bzAoTcKPaLXY6MLXmP1L9PUCT9kOndJOHXsqo/+D6cCj5XYYfYBX8/lCInzws2st1D3OaFAfPn0pb/1cY4iffIrVMwj2Lf3ZhYmmDVSntKZZgG7FWWl2vKMx1kvq38o4zLz5cc4PB+tdinmImM1pyaUyWajfzkIeWJRw+t9N08tAWcLWYoOJp+PIdEM7KvLBwsou8fXsD0umj6jTzBB3I3AcNYJkWp2K5ijoWX6t+IkHVkIbWTS4xBUgyKHGaReArwNR6Vi9LGUuRzloL2XPDxxF+ZJshvMY7NgZkjDsjoPS38PQ6mvsEMnQh9yMPFYhHTGmYBOIk+X0SuvDic3TiNPIUi8nDzQiBaf7Umg8HcNZarLmVwNnDAfaup8z97nUcB4Bgj0FPATI5kwuKdyQiyiUgHraRCYsTaLFbYNNmqZQ6kbMn+dCgUOMBwfKb3U02jAkCjlN0+zTVoCjOOvLyIdWEN5qbwk3ylJYigFtXNJVAUKU5lgsPK+/ry37kF17aPAnlmv3JHNHF2+YsgQYuPnmqagK75OYKcOPi5vS8J0ecM6RImYVn4vwRVnOCA1Lfio21xYXKZhY156kj8HMGE9nCLZnwsamtrihNsy3y0jLK/Upk/nq+dy4DbNxrhBjtncTRfHan1CFkpvVLXbWzZPVMEJdOhN0BEcph+exNjFwHN+cCNnkK9tiJTltF3lMg2TmXNxmfAUtEUXffg3OszePM9LEXr2CY3ZGd/qpMbOcCfo76B0/hikhGhgymGO39drmxG/IhJPAN97PtAeECKvlKFHWjnG9isWZXAs/cXEvudbuunMsr7Pnil+CiTQ0UMlDbay2FISpdAFzVGac4JSYIkoY6sUMROMpgH9349jMSgohqhzB7N0fptzBKS8vq4h9YckaLHxuzwfLD3c1iD8ufv3+br677Ca1ApvsUPyiKWiEjUZGcpSVbDXbr2MNiJNAfTYG9hcj4ZmZZoLJ0JsdAxpWW3Jj6YAiAEjTSvSvI0oC3v3EZ+PBiOhfU60HAMlFIFgjudFmGlksGysBnJb6S2FbGsFPNwmINOrCkFL8Kq/NA1lJvXjQDNSvTSKPm2fgXgNX5HzxbvBOhCePvtp6I5wjKlbOARh42kUgWR6y2exv3Ssx1qKZCYDfhCQMbKMycnO79r4XXCfGoxbNRW/OZPndurc86/vnEKxoScimviS/e8kdIrmjeGuM38lT8dCeVDnaQ7o6HtppVAd7lZApHUSRjGCkFUlQz4mXyMrX3XuKEtD+cD8E1DQukDx6fp3VM7 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 810e8982-f83f-4afc-8243-08dac8025ed9 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2022 18:42:53.5024 (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: RzvLOWBwrOzPnkEXvVogFVP0+mpILUifXuXbio5b0xwn6FKFh+Y7pTHDvDGrOP6J+mzPGPrucWPNguVBp80jwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR21MB3130 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?1749680027915896693?= X-GMAIL-MSGID: =?utf-8?q?1749680027915896693?= 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;