From patchwork Mon Nov 21 19:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 24002 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1798385wrr; Mon, 21 Nov 2022 11:53:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf6JhYPGuH96Iwp5tTokt7vLTR7OF1SjHwOY0M4sDvGY8jtcuc8iRsJlB4SANQHbosm936Gu X-Received: by 2002:a17:90a:9bcb:b0:206:f02a:cb4b with SMTP id b11-20020a17090a9bcb00b00206f02acb4bmr22031208pjw.159.1669060433361; Mon, 21 Nov 2022 11:53:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669060433; cv=pass; d=google.com; s=arc-20160816; b=JTdv8VyHqqVYd//12zxdQtj0ioOFmFHmlhkrXLS2pw3BIXRnYAAtNKCMtD9IWEdLiD 2VTWjLygfOsUlESE30cFILpHPC3VYxmW+1nBcg89y+xmZwv5Zkje4Kh0ZOYxIwMRTXlo FGgu/QAaAtBhro6fBY8uvN4WcokUYT+zVDkshWOGwBX8kTspTGXlPBBJhes5G6Yp8f6l jFX32BP4l0QCjWYMORnKUbEEPoG8A1N/vKg8bRr0Fnav2PSYouczLt2KXPoMtTVPFxkd GICBv7rhCctSKiAlYGJZ+q5ddKN1Ntn1xmDnM8hlvklmpPFhutyL2tSoa3euohCdrFQQ Xrvw== 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=uQ5cCBCdmXSDGpxujQ4rE647Xt26Pt7EGMqw+j0HTOk=; b=pAuG9157wJfloSUwSaUU1jI8v9uMvpQG4C5fVtcmCK6HDd2HcJk3UaqVHHHYcjiMds 3/iSQXFSkSPCQ+Y53lMH765MyUDG5w4y+Vt9pGuxTg1nxT6DZjAVs2xcdZG17WH2tF6a afvHoQvD7FLOqy81zcmxHZ/OwV0izV/sGn3iYvIC+klX+wE0AijW9t8PElYaK8/mtrA0 q34Ku8xBrXVEwKGQdFZmY9J+32zZXLkYgTPPsURU85/qoR9QoceVy496VJYLFHH8jTih PEexFTTsAZC8PomlgaOCWb7IjIztVUlf1U1zhRbni/r5AS4cFVxEnG09hQ4vJBZz1Lc8 VMOQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=X02ybRpd; 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 s2-20020a17090302c200b00176d22a068csi10609012plk.515.2022.11.21.11.53.40; Mon, 21 Nov 2022 11:53: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=X02ybRpd; 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 S231771AbiKUTxN (ORCPT + 99 others); Mon, 21 Nov 2022 14:53:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbiKUTxA (ORCPT ); Mon, 21 Nov 2022 14:53:00 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022019.outbound.protection.outlook.com [52.101.53.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 273A323EAC; Mon, 21 Nov 2022 11:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CE3Ao5ZNjyaGCiLV0uMIDZZSGVLf42nu4LDOtGJZyOdp9F5h6e2NtZ1aKMSi3/3ll11DVHA3lPFpAiX9zyGMUU/ZFhZzkRcRVv5/mEp35yrzq3udKtP4j+paZEBRkjtkkTtH5FH37KSWxZ2MB9cvMQy1/ENqaSQkucasvIAd9Py2lyaezXCmMeCRfPaHIcb0vY8ShWaVdBte/K7pCZwH+dN6R8NUA/QDRSDPnGs3DOzlBUB7DXtIrcR5vwMvqEcDGkz+5iejSgwdG7jFYwwGV7Tck9PZT2Dj+38Fr2bPkyij6R1XZg14MQuWHXN8r25C4AUqDfTcsJbVL3nSABY5tQ== 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=uQ5cCBCdmXSDGpxujQ4rE647Xt26Pt7EGMqw+j0HTOk=; b=Ma7hj/S6oBktG+5vINq+rMDaES4069aQpkzOHliA7NXVp9dMGNvr4aPJDoo0R8mAYFl3F5psdtB9J8AWKrFFUExtz+ClVZ7Nni84Km4EiBTLxHrvvmL74IrQpdUXTaSneEEjP12rvKY6erHZzVCDDRS56A0fn0MuvVYfNOAApIVyibSVSd9UmFTVg1Ts6DRnRKX7QOWS9LXNqmf57xzMgDlsFc616BLtmxNMFpEfedb6iL01eKgrCdUFDQK15L8L5Mvzc/3yX0No4066pl4O50jenJ6A7mQrefonHYAA3SVRSxFhs11wLmNA7jC0YAk4VlgR7PgJpspYTIl1tk+VqA== 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=uQ5cCBCdmXSDGpxujQ4rE647Xt26Pt7EGMqw+j0HTOk=; b=X02ybRpdPPYInfPGf2fzTYP121P1LsSSDuAjFD1LSLQbcc48f/gStlQcBIKyGRflbrzKfKmtMgCLU53cNPm7xQreRbYRPnhZiagu/uT3BkQoc/BwbqYfsXJc3d5/mBZCIzdJOpFS7U+ctayICjh6l8V4lXY8KSrkGxq3eWZlHro= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by BL1PR21MB3280.namprd21.prod.outlook.com (2603:10b6:208:398::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.2; Mon, 21 Nov 2022 19:52:50 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020%7]) with mapi id 15.20.5880.001; Mon, 21 Nov 2022 19:52:50 +0000 From: Dexuan Cui To: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH 1/6] x86/tdx: Support hypercalls for TDX guests on Hyper-V Date: Mon, 21 Nov 2022 11:51:46 -0800 Message-Id: <20221121195151.21812-2-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221121195151.21812-1-decui@microsoft.com> References: <20221121195151.21812-1-decui@microsoft.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|BL1PR21MB3280:EE_ X-MS-Office365-Filtering-Correlation-Id: f5ec224f-0622-4ad8-4be5-08dacbf9f88b 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: UE4lUQCW+7X/AnYNMvIgeQLHLzJs3fEMg1avC14vyGDfE1ioGF01VaF6y5e/LDdNcsx8xBZbLD0ALyUJAMwL8P0jdFw3VueCgEgGKStK4ss90WAyShZ6MChy3VsNw1X9wVKSy8dIx+jwNVqgeKezWm2QhBiHLBpVbdSxV7Yy7ZdD9N0kG4VUVKxy8zU49AXY1Kubi6d9TMQQN4zIWNXNBps4/Bv4wYIiVP5pvvIXdfok4H7Ie4IDYbJSKGGTIgIChbZkVqhNymp79/otuHa9msYe7CZomPc4uy5vGgTwyxQQyR16K3sSD7mNEfkSLQM71WDqnOQlfsHIzpOjSfIiM1ciqybA0CiwfTozNSTc1AFNoCUjuKpsglq9LbjOHxfGyp2wDhNBHycOEa67CTJb5G9myKNNMzejCR6vZ5S4qaOpuUQHnsVVFEuGbbPrhBf8fjb1QTAwi5l9q/WAraejhP/1naabz2XzsJxSWi71DoJXWYDAphp+EigJKuxy7o6+1goC3pc5ajjrYvxOczUt8XdSYplbShGIAXMabk1z0GKv7jx4T1V1O9nfxIEmmxKE3LSNAe8OLAPDlOiQQKST7TRCpPX2U2yRkUo6iyawuuZQtfBClzJNK0KCJ9gF81ZRIrV1rp46Zh9RSX9G74dliQLBAWThQzqNgZGfkWmL3pL9LitRfr9ZX+V7KfYdgwZRl9x9AKJhtwECpMdtSH3dERcOc8uilsrQcxYPrsNL4dU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(136003)(376002)(39860400002)(451199015)(83380400001)(2906002)(7416002)(5660300002)(8936002)(2616005)(186003)(1076003)(36756003)(86362001)(41300700001)(82950400001)(38100700002)(921005)(82960400001)(6666004)(10290500003)(107886003)(6506007)(52116002)(6512007)(316002)(478600001)(66556008)(8676002)(66946007)(66476007)(6486002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GXS3KDBBxm5RrpxH2mBzI09aEVDEUVEW0AYLlLxkwpUI2SEijYGQDvEVORUPbTxf4fFOsyqZI1IYDSTM7PjkWl7NQgGBhfoSp8DLTnW4RtIiqSZvtA5emrVtXvnrilwDWc6x3LoBr/p4A1PPb7rm4OhhBpOYpxHBWVycwQNIVFNy7amNN/TmzMm2ss8fmmVYyh+2XIKSd7yULJ3w8AfELmqG335CEPCqBE81vsGlieRwpxzhZv/PET5tMZ6fa2M0d3cPld0sdbAwq0weNyoJrMMGeuq0nbe+x5QU5beTBQqvAkdUKcI64Krk42pvL1BqgmfWuXK14yi53bOnx6wLPjEo0zO7MRxOdVt1RQKzzMnd9Vw0Qyum1gqn8bqAPkYmukR1LWsRPiNVI/zE60SOkNdwf5ZDhWL+f/4N6Lr9J9FVd06EoUbrWTEb2dUMlcJm1aBfhSIgYwMOIjQFxYd0f05544IOjAxo327D++ySCtcX9+Za0td1/DYc8FHr+DpQovUiqSHxdxewAKINPcX9bvmxwut63kBrIPCnNESeoJe+GEhyiE8+tOkk4kB8b/s5mAVy1oA1OTBqDsrilvv1DAp6UGO0b4lGzSFZOLtmzCGbsFlYhIH1xzn7TbVE3jR6JpoPXndIxIotVWZpr/qbDG2o8zfOsBzsdAKu45HrXLls10r5m7uUfd8Am87lC2sfUSW9MHCgaLjQ9p4YKDaU0/d4+5oZWqaejocJgS9mh321ylTb7zgiOTC+6MF/U8oPlTjxmdLyPoW7cFEvFM133YFndFN76BuXi5yD8ONC3Jqf5HQ7uwG4URrK9CzGe8v6TpH3YEULt9EGfCRcYiyUaovkm+8gXJIGQdd9BVjorerxhnf0Oh7w+192zWYYhbO8Fyn7bqvHbzaGP6qauacxLV1l3g80g14VNyhaV8EsTXr8usxL83EFHiDA2LxnMfg3z/xzQRzRJMsVcZqV/ohNoAjO/vldagrZoMNIS6JkKpkE3dTEGyHYMiRu4lFcoU2DDr5F/DPnMVI7z0z5Yzp/yLceFvJUjH3avbYRRmZz/60ieAwX8eSgSIN1hgLRuQgEyezp8vucOZHb2xQw5olsZpJVwuUcj2s1aQzBKiTeMMsCYhvErrrfBzC9bb4P1Z3z9fKMbDhjpu4iqok7BuV7kjhrkkXqqhR0fwomHYfYLQbDjeKmagt87N5VzSF183Tdq57/Cxcj0UMhjRcbJVUKU1axpF1tV5Rh0r5mnUjb6rYWNPVDA+tE2vkfrzaCyTKJeLimNADiS/USWn2oqajsDhamFz7hkAxFtEpxzbI6BfTVzhtfe4v324sLhkVFK7oA1nxEGqJStSuV27I1d+LIFYx9NgyZDv/aMFN8gqnZHIEAtlHagcJlJOmwiYbzE61TM4lhMngXSg1io+IGUxVEgEeQh9zyrXutwV2txvdylTl9gZX/zS61Zo0tttKBQb6N/26bo0O6tWG0BvXKntfa2BXvALyUwWSp/NkWf9aXtexjJiI3PVN7jFmGccUXwXngQYzukBuglJDlrW5KvHGJ4kRrYXQ9isRjB3prTxcZDIkvqbDugTwpCYhQOhkuRg8Xylk3KcMj7ORHFHaaUa3wX8Q1B+YmuOwyYtaZDgEhnDVI5yJ7LAy9grcJMz5DRHl9 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5ec224f-0622-4ad8-4be5-08dacbf9f88b X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 19:52:50.4926 (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: QSBjbq8M1+6wqoVG1zFvUIz6hTXhNnH6dKwoPd72A+7S32dqhdGSsIv7sR6+jD+vzvrYi09pTXkJd5tPNsU58g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3280 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,RCVD_IN_MSPIKE_H2,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?1750136712978543143?= X-GMAIL-MSGID: =?utf-8?q?1750136712978543143?= __tdx_hypercall() doesn't work for a TDX guest running on Hyper-V, because Hyper-V uses a different calling convention, so add the new function __tdx_ms_hv_hypercall(). Signed-off-by: Dexuan Cui Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdcall.S | 87 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 2 + 2 files changed, 89 insertions(+) diff --git a/arch/x86/coco/tdx/tdcall.S b/arch/x86/coco/tdx/tdcall.S index f9eb1134f22d..468b71738485 100644 --- a/arch/x86/coco/tdx/tdcall.S +++ b/arch/x86/coco/tdx/tdcall.S @@ -13,6 +13,8 @@ /* * Bitmasks of exposed registers (with VMM). */ +#define TDX_RDX BIT(2) +#define TDX_R8 BIT(8) #define TDX_R10 BIT(10) #define TDX_R11 BIT(11) #define TDX_R12 BIT(12) @@ -203,3 +205,88 @@ SYM_FUNC_START(__tdx_hypercall) REACHABLE jmp .Lpanic SYM_FUNC_END(__tdx_hypercall) + +/* + * __tdx_ms_hv_hypercall() - Make hypercalls to Hype-V using TDVMCALL leaf + * of TDCALL instruction + * + * Transforms values in function call arguments "input control, output_addr, + * and input_addr" into the TDCALL register ABI. After TDCALL operation, + * Hyper-V has changed the memory pointed by output_addr, and R11 is the + * output control code. Note: before the TDCALL operation, the guest must + * share the memory pointed by input_addr and output_addr with Hyper-V. + *------------------------------------------------------------------------- + * TD VMCALL ABI on Hyper-V: + *------------------------------------------------------------------------- + * + * Input Registers: + * + * RAX - TDCALL instruction leaf number (0 - TDG.VP.VMCALL) + * RCX - BITMAP which controls which part of TD Guest GPR + * is passed as-is to the VMM and back. + * R10 - Set to Hyper-V hypercall input control code. + * Note: legal Hyper-V hypercall input control codes + * are always non-zero, i.e. they don't conflict with + * TDX_HYPERCALL_STANDARD. + * R8 - Output physical addr. + * RDX - Input physical addr. + * + * Output Registers: + * + * RAX - TDCALL instruction status (Not related to hypercall + * output). + * R11 - Output control code. + * + *------------------------------------------------------------------------- + * + * __tdx_ms_hv_hypercall() function ABI: + * + * @arg (RDI) - Input control code, moved to R10 + * @arg (RSI) - Output address, moved to R8 + * @arg (RDX) - Input address. RDX is passed to Hyper-V as-is. + * + * On successful completion, return the hypercall output control code. + */ +SYM_FUNC_START(__tdx_ms_hv_hypercall) + FRAME_BEGIN + + /* Set TDCALL leaf ID (TDVMCALL (0)) in RAX */ + xor %eax, %eax + + /* Do not leak the value of the output-only register to Hyper-V */ + xor %r11, %r11 + + /* Load input control code */ + mov %rdi, %r10 + + /* Load output addr. NB: input addr is already in RDX. */ + mov %rsi, %r8 + + /* Expose these registers to Hyper-V as-is */ + mov $(TDX_RDX | TDX_R8 | TDX_R10 |TDX_R11), %ecx + + tdcall + + /* + * RAX==0 indicates a failure of the TDVMCALL mechanism itself and that + * something has gone horribly wrong with the TDX module. + * + * The return status of the hypercall operation is in a separate + * register (in R11). Hypercall errors are a part of normal operation + * and are handled by callers. + */ + testq %rax, %rax + jne .Lpanic_ms_hv + + /* Copy output control code as the function's return value */ + movq %r11, %rax + + FRAME_END + + RET +.Lpanic_ms_hv: + call __tdx_hypercall_failed + /* __tdx_hypercall_failed never returns */ + REACHABLE + jmp .Lpanic_ms_hv +SYM_FUNC_END(__tdx_ms_hv_hypercall) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 61f0c206bff0..fc09b6739922 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -36,6 +36,8 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); +u64 __tdx_ms_hv_hypercall(u64 control, u64 output_addr, u64 input_addr); + static inline u64 hv_do_hypercall(u64 control, void *input, void *output) { u64 input_address = input ? virt_to_phys(input) : 0; From patchwork Mon Nov 21 19:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 24003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1798432wrr; Mon, 21 Nov 2022 11:54:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Xzsad6sUY/LRkqbXJd2+/vknzXi6GXujK5rwamRzPF1dLgF1Om9HGjbt4diMenmBsE8le X-Received: by 2002:a17:90a:b906:b0:213:b349:143e with SMTP id p6-20020a17090ab90600b00213b349143emr22020012pjr.114.1669060439798; Mon, 21 Nov 2022 11:53:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669060439; cv=pass; d=google.com; s=arc-20160816; b=yKPt4LcoK2ykXc47XpORoNOKXXIYbuYtS6fDBiM2FgU/Zvu+ZaA1HljtXEH6VsN1Ow tB7wA4bZAUyGltyZpexFgZO0spvbHq4WUZloNz6d/x9+LG6v/a1PoSSCf/Jg55nfRMQQ aAgbA5seRBevVJTYBfZmEZuCpxq90yT9eKw17Kvq5fUtHHVynO3pxdkZyy2xnmE6o7oG x6Aak7M47iXjPOoeNehM6Gmy6Jcwie8sBdErDaYzZSQzEDQP3zIYCRHgg35G/Lzl+k5l 3XWUSeaVTJOYGnO4QqTW60ziAED89d3ddpIqiKiGY8U+CSOP0F6Aqr6rqsGDSWd9M3mb BpDQ== 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=fA157Zk6ADQ5Q1UdtkapEDIAJPf8V706VHw/r6JPUJc=; b=VuOZH8AO6BLYk9J7TX4TOmgr8iOmowoGCycEMyvhkVyGZ2eRUD2tROa6cNPXRzAN5r EMNT3vbH4A1DK2TXEyVSUvOM/Vw9LTlapKHfy6h7Ob4CnjfOYN7M5ygNFMUqRnOybNqn mhtsMJ0ncNoRwxE8kJ/ENhAVqtonE6rij0vyHo63Q5TUixKKhXwL700hb/l+AsPyddnT txGrK57zHFMob2RkG5rb8Jm65RlG8Gwj7eS2BZAaDk+eTovIVsJkgqIidO1odEEyVvaK pmpIAjK+XvqicIzwexPkYUPgm4UyhvWYpvp6nj5qPfsBU/c6MC03DNlEoPpJHG/7Bksh Lnow== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=RBqg2Ytz; 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 mr20-20020a17090b239400b001fac102fdeesi10554654pjb.95.2022.11.21.11.53.46; Mon, 21 Nov 2022 11:53:59 -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=RBqg2Ytz; 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 S231838AbiKUTx3 (ORCPT + 99 others); Mon, 21 Nov 2022 14:53:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231726AbiKUTxC (ORCPT ); Mon, 21 Nov 2022 14:53:02 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022019.outbound.protection.outlook.com [52.101.53.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE97429AC; Mon, 21 Nov 2022 11:53:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XnmbqObCx0UvuAZAsu32Amp3RFi+0VD8y1RPTPXBgFjPpwNQaK8yLoEfBSvtw8DXXQU4C+eW03UJCduDu8KJbvAeyucRQqEib7EORJQxlCDR8t/gwda7erByJhe/vEkfwPeSiPSgaQ5ewXjX4ChYrKyie4D316XyNKlg9hzLgVvNf5g8s7hHMNMsGegyB25r1Zp9SG4pVpBJ0wb2G61oKXFue9/WCEHplDGAMOlKOn0ljTmtuxzMoAzCKV9q42Rwup7coAPAm0g1E6PBQ2Og7wWQntedHXh3OAO7CqgQeja3ehKodjlSsl/S3hxpfo77MsxGcxU+m8zT8HXiA6s74Q== 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=fA157Zk6ADQ5Q1UdtkapEDIAJPf8V706VHw/r6JPUJc=; b=Lz9yXLNt6Kjw1Nr0DG61wIj0KhjTtabFzrrhrAOt9P6j66k9Cnq6DVi24uoK+TyEeurvUHR+FJQyhZfk2s9WijLbYWUr4+R9kTSBXNCTtsYZk5MTNH+vHvnj7VkD4iqPlnDWXi5krGEu3qgjJq40SVdChcep+Uc/axzuBo4bCFIpaUCwiN8jrob+giObWThdUvpFGEC7mST50ulqMGdAhIzqSG7ip7H+2iDC2jgXov/T+WyM0oromJkTYd2kVLjSvqKF/IxAnY83vEsZIed/MXUpbkI31v12fCFxugkDndmPJLXHzvhavJIIvnWNkdFKwxdDvQukoXqHkzdZKHkiGw== 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=fA157Zk6ADQ5Q1UdtkapEDIAJPf8V706VHw/r6JPUJc=; b=RBqg2YtzBYCYjVMmUJnZMIB8uwnsGtT5r0d+TN/yGR0ru0kKAJC+PwLEsb5FzbI+TXNUI6SY1tdYQgYaJxQuNecP+E9XXxbYM3zWXKbCK2Gt3uVVSXpmCtuRrHbIdiuAuja85FPpO6W/CwylbLBVrXS0A9TBY4vmXmMY7JfZ7xI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by BL1PR21MB3280.namprd21.prod.outlook.com (2603:10b6:208:398::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.2; Mon, 21 Nov 2022 19:52:53 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020%7]) with mapi id 15.20.5880.001; Mon, 21 Nov 2022 19:52:53 +0000 From: Dexuan Cui To: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH 2/6] x86/tdx: Retry TDVMCALL_MAP_GPA() when needed Date: Mon, 21 Nov 2022 11:51:47 -0800 Message-Id: <20221121195151.21812-3-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221121195151.21812-1-decui@microsoft.com> References: <20221121195151.21812-1-decui@microsoft.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|BL1PR21MB3280:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e480212-775f-49a1-d707-08dacbf9fa14 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: VG7V8qlKtz9xvH4It+AljjSB724Ie+SvG8AWm8+WW+i/VWeLBnbw3i5r/heslVj0D6qBQlnS/o4nzQi7dB0TcR6fN0Grc6Jdb+8vP+6RJWoVDviGYHl1FVJ2g1sgETEzvhB5AB2c+gscf1O1lJ7wyXADE9SGh7igSi0h+euzxuQKMQfNhM4z0afxVPFJUw1RrAgID7D6ivmI4vsqV7IzMm0Zb3AhRH5fbWfmGFb/Oq7X5fiqflGfBMGZuqTjgHVG+SdPTUMMCnbP1cX2JSSMTpn1RftWr1YaNTZLDi+AOl05BDQMqu76R4aUas54MBB3tO6PPSgk7buoK8GXwKq5eo9wAeekMA+cNtRveqIk0GRlSMg31ETtfAWYpzvnxrqYifV0Pp0KoTMg2qPXF1m8yDwjYRdyN70m5XrQsZmZb7GQZeloxUEOpxqmDZW8ytv+eX/PzlsPf68HWoVicu0R7zOxPscoxSWy+IsH1vUALThJn9EdoBHuynsyEamKBhZE9hD8GIbOTt4VgCQNoNdFuQxP8FxD8KXCk2/XOR1+BeLLKCQL8DFm15RhR4BTkEnRYNeK45UPLa/uJgfNDXBfQDHsj3BNdYqWEVE9tjQFYnLa9g5jUP90Y7HyYsp57wJbNY3d2eWB8KN5NmNx0yxwB2qcsboiX2i+tAb7Uh5uNx+0Ha3FfJprpENZn9g8EcLpY6wchKp+rstgGeVJpy6/MVixaNodujmsy9PPJwxiuvA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(136003)(376002)(39860400002)(451199015)(83380400001)(2906002)(7416002)(5660300002)(8936002)(2616005)(186003)(1076003)(36756003)(86362001)(41300700001)(82950400001)(38100700002)(921005)(82960400001)(6666004)(10290500003)(107886003)(6506007)(52116002)(6512007)(316002)(478600001)(66556008)(8676002)(66946007)(66476007)(6486002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RRiG/Zm/Z2PbHB3Pv996duy996aUtmvLNEH3D0hKkdPNs4p5l/WuqyXZiM5FLoBdsYTNsrSWzZuTW7xQxVQAwk6SYx11PVH49Ai/ZkcG1ukk+QbghfBqWgScIKm2Nrq2d38pm1FygcF/EP6knIMXwgyyk74P9fsS9xMKeyFx5nIIf+FyIvddemVRDh39YLNDIZEK9htUjD/0zamhP5AfQ30wdZFygrp22hLTNWdTHLhHIdMtEk2EiJXpS/13tuYEZG4uuX377uiUe286p+kd+YRIydhpNWEqPqTZy11pR3s0vNhtLIJq0Ncw1o2eV81+jfZx+E1B5QDTdywssQiGDemrlksAyCDzGLeU6y2KKce6bbi7AMLapsFWQrF++HfEvVb/gSzNyfI5eDIWPhodosDsqKO5OA8Us8ndr0eQ9DrgJ/njaN4w9S4Zh/Xbjxy2KyRRFKDHeIEK5041Vjw2EDJz7cM0XbUbk0G1WAuvWZ0SJRq6wmO5Q43i1h+9h3DPIW5/vTl460GpGZwo0bCQECBdn98OzKUDHRikGrP9hQOs8Z9BB5nwbWaRy2eh7gebTIPqeQzOqBnIrigTTLIe7tCu13biLJDGKwRIpM3j3tgCHL16gSZeuqQwkR5+WrJUedaAK1UuBtCmPFXuwVeRbAperC7vl9o5ZqHrcxRsT80EdchLrF72vPo++KHtXTbE0WmqbTZquZI3Xuoned6twaboikXbGDkEjZAFStTLfiaw4p1YKDPtL85sAOu5YP1rx7fwSEZrV2664RwFbQ8H2+X1GPMivqMMtxalE2Z/pJNNP9syDDquiz/y+bFMJ4YVvM6nbNNeIEUA4WYkMaZpCVTJgL0oHDbLwEW+uDcx/l+PDx2SeD2/bXvDJjZ4VP1FO12RbPlE6hjsct004kU/lF8s6DYp5PepmUvJMFNUykNansecOwh79Renm2CitNVe6hIptg1Sg4hRgNRxK5QyPAN+oH9uK60YhxAkAApP0kGtb0neSzyT8oH6//+UfFoWsQVrJIixHuv3CCaVW4c0ousRZvoxMImB9SpwiaFqITN1mMqs8PAXV0Yt9egHME3F5VhCROjE6hGaDgA/PS3ww3F8+2wt6qc2dKNEU5wNrK40zaw1evaZcJOh1knGW87owrXqQJopAY2GIerc6LCOjSTM9hfnJYN5mXGeOXatKEKW73VgQ1q7K7nTMpaM919LjOvZ6gg4gk8eIRHpGW98FAb2/UPdtnvR7qasePs1NR+9ixcPtmZgrcLNS6L139wR2ONFBWn/VqjwpTGjTt/NgtvL6JuAMElNm3K2LZwviUsjPdC1RjEr5acS9RKY3cqN8yA3+bidRhbfutt5ekea7Wstu8SUfuXf+26rlo41/m3t4umyclX+UL8E4h/J52Rj9msSs9fFbgKBLaYiLfcRdXQA+5VBAugwenXmEe05VnT7BdxmRpqLEh90beC8UvjAi/ddeFCYcL0UVMc6KoCge00RVi+ybBCX01ridzjNyheWMIkNV351rDzQkb2KW9VIvfw30hpp7WAl6dMtrtQ6+HQHF8+DOu3228Xg1z0tDRe7zMA9CNsAAwHqks1YeoQ43ee6JIEKDyp/pbj9GRF6K0d8k5RFbdOWeRtQ53RGVwRZ3JIJXpINRAPUEF6vGNpv X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e480212-775f-49a1-d707-08dacbf9fa14 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 19:52:53.1186 (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: ZqxzgourQicJx5tudqMkpZXdRrrvVXCGjLQrD5beeMyOc1aPeJVScB8x0enYUswDknJc+flDVqW1Hg3e09qKZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3280 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,RCVD_IN_MSPIKE_H2,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?1750136719667601817?= X-GMAIL-MSGID: =?utf-8?q?1750136719667601817?= GHCI spec for TDX 1.0 says that the MapGPA call may fail with the R10 error code = TDG.VP.VMCALL_RETRY (1), and the guest must retry this operation for the pages in the region starting at the GPA specified in R11. When a TDX guest runs on Hyper-V, Hyper-V returns the retry error when hyperv_init() -> swiotlb_update_mem_attributes() -> set_memory_decrypted() decrypts up to 1GB of swiotlb bounce buffers. Signed-off-by: Dexuan Cui --- arch/x86/coco/tdx/tdx.c | 65 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 3fee96931ff5..46971cc7d006 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -20,6 +20,8 @@ /* TDX hypercall Leaf IDs */ #define TDVMCALL_MAP_GPA 0x10001 +#define TDVMCALL_STATUS_RETRY 1 + /* MMIO direction */ #define EPT_READ 0 #define EPT_WRITE 1 @@ -52,6 +54,25 @@ static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15) return __tdx_hypercall(&args, 0); } +static inline u64 _tdx_hypercall_output_r11(u64 fn, u64 r12, u64 r13, u64 r14, + u64 r15, u64 *r11) +{ + struct tdx_hypercall_args args = { + .r10 = TDX_HYPERCALL_STANDARD, + .r11 = fn, + .r12 = r12, + .r13 = r13, + .r14 = r14, + .r15 = r15, + }; + + u64 ret; + + ret = __tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT); + *r11 = args.r11; + return ret; +} + /* Called from __tdx_hypercall() for unrecoverable failure */ void __tdx_hypercall_failed(void) { @@ -691,6 +712,43 @@ static bool try_accept_one(phys_addr_t *start, unsigned long len, return true; } +/* + * Notify the VMM about page mapping conversion. More info about ABI + * can be found in TDX Guest-Host-Communication Interface (GHCI), + * section "TDG.VP.VMCALL" + */ +static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc) +{ + u64 ret, r11; + + while (1) { + ret = _tdx_hypercall_output_r11(TDVMCALL_MAP_GPA, start, + end - start, 0, 0, &r11); + if (!ret) + break; + + if (ret != TDVMCALL_STATUS_RETRY) + break; + + /* + * The guest must retry the operation for the pages in the + * region starting at the GPA specified in R11. Make sure R11 + * contains a sane value. + */ + if ((r11 & ~cc_mkdec(0)) < (start & ~cc_mkdec(0)) || + (r11 & ~cc_mkdec(0)) >= (end & ~cc_mkdec(0))) + return false; + + start = r11; + + /* Set the shared (decrypted) bit. */ + if (!enc) + start |= cc_mkdec(0); + } + + return !ret; +} + /* * Inform the VMM of the guest's intent for this physical page: shared with * the VMM or private to the guest. The VMM is expected to change its mapping @@ -707,12 +765,7 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) end |= cc_mkdec(0); } - /* - * Notify the VMM about page mapping conversion. More info about ABI - * can be found in TDX Guest-Host-Communication Interface (GHCI), - * section "TDG.VP.VMCALL" - */ - if (_tdx_hypercall(TDVMCALL_MAP_GPA, start, end - start, 0, 0)) + if (!tdx_map_gpa(start, end, enc)) return false; /* private->shared conversion requires only MapGPA call */ From patchwork Mon Nov 21 19:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 24004 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1798647wrr; Mon, 21 Nov 2022 11:54:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf5NI7CQRRgwgst5HzzlN96wLGHxcBG7AbKDIRZMfKxxfe7e4pdDTZ6wF1+7/XHxoM6nf/Gt X-Received: by 2002:a63:ce58:0:b0:473:e2bb:7fc0 with SMTP id r24-20020a63ce58000000b00473e2bb7fc0mr648114pgi.604.1669060468226; Mon, 21 Nov 2022 11:54:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669060468; cv=pass; d=google.com; s=arc-20160816; b=bk0S4zqizQ7LNdah6QokLRCD7DgNS60rw4YW/ikqZMY0+c6FnmMM/tGTcjKGniPo4v 5mvVWL90Fr8dP8fUCzp7Ce7ZNIJS0W6EL4GLqsPbB6XY6JlC7cb3QunRJx3nBuOcO+cw 5vte7yt/hHWb6XHpx9f59WNCVwbaPMg7U/QNxLYboUG0hIyEYL6wlATbJSMo0I7E8D/A /3DcKWsdzGJW7ou0enIOuwiWOlSCMYMCN8G65EYqSKY5UzvKQ7/Zdl5HVYPrGPjqE1Ag ZJZ/bnsa3txyVIg2GXLpRbYAsBAzsyCB1STaCpCjCvRh5aXTrxEpFPoPDGglTIVTzCmr OEsg== 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=pla7uQG4lVqvFfu1Gw/DyERK93jZZt64p0einsyczpQ=; b=pATm7lhQNNUYVeXH6MwvRDoL9M2t2Fqh2jiuzGXQm7wFOtH01zrDi8mvY7Mie4c7f3 IptJPULBL47xHSw/Uvd8Ym3hpJcu9ir6DDM04iKxklfw9349Id9GFHarg3ZpI8NTv7j1 siyBgHIFVnZvvG4Z+HGTr6gcUvzWyM0o4UCjHMnTg2KIA4dZ9TJqtTNWd2q0xQbXRjvg hrnoNd+XhUnoPszgNR0cO2qiAZ5+h5taTsBk515OdnEZp9LyjtOx/tM4USx+8P4QQMDL OK4GQGGXFlhdwf7d2k4EmgtPO/67ElpJAF874/mgZtlgt1LO7IBcn5UlTY9fuONs9NRr Ldxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=cZM3eZpG; 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 w20-20020a63fb54000000b00461ffae7b37si12151436pgj.0.2022.11.21.11.54.15; Mon, 21 Nov 2022 11:54:28 -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=cZM3eZpG; 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 S231739AbiKUTxe (ORCPT + 99 others); Mon, 21 Nov 2022 14:53:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbiKUTxE (ORCPT ); Mon, 21 Nov 2022 14:53:04 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022019.outbound.protection.outlook.com [52.101.53.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E1115A34; Mon, 21 Nov 2022 11:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XIs7HH7tVo4Wh8N/s2NcGz4RAwvP9T0wOp7mDvUkFa9ZJ/wpN2tMAIKgWR52repWq/SMBQM4W3ZL4ALzFIG3xe+CpyPPUYEEdf7LHqzFi2xw4JxLCIOOjr1XnVBYqdhwkIgbRkbq7EfYChT/Dlmjbr3KQ7hU13PPL6fr7MW8V67yRV1zofkWRGNJI6daWhZQVFEmPyfL+47hQWUfKk0ybBgNSaX4IOhIoMq5mqgnM+gaAiaUHdmWUJxzDoQPS4sTnsMXV1RZKggtV7G/dgsCQ8xWTdfwbXkDX7cZ++WtuULJAwqj/B8BJ1eJm7ZkuK08r4uwmxrz5/GRURTjduDWKw== 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=pla7uQG4lVqvFfu1Gw/DyERK93jZZt64p0einsyczpQ=; b=W/VNT3U0l4iwHDNyuxQtNeC5AI9EpVYxmi10XwXcolo6uZptuefeXS77VLrtaHh1mmqI8qeqzJ7cyCVYeAw2pj7oFT28o+rYdCjOCIouAGvPoPHfO9yeMdJH66cykcFrMeYcnv1Gee3PXJdJlzGwEJFuhha3k0l1HYLbkeRc2WcJRWesXifMPp1JPOv+U/r6gUy2esc52RYssyhfgQz5jlzsjJgXbwJThw1jfareih3K84A2XkeSA07vW7BCA+1AXfnaHHd2MG60935FrqF9Xa4V7UkvA/XzHqNswv9nJRQWUxW3k1LKCDtys49CJS/4xalQmoNsWicIOsNg2DbbSA== 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=pla7uQG4lVqvFfu1Gw/DyERK93jZZt64p0einsyczpQ=; b=cZM3eZpGOzTe2kRKWPGph5qWoHX14lnSYW1I9i2RAHwYMTe8YMuZHFrvlttYNefDNfDBYH5h7oGMmMTK2LCBTlcdbpkWYTOsI2WGVArKzj6Y839UxJ2iId+XiLubt+fK05iPHzlETDSHpI/rVss89yU0Xdp1A0eodTSdBUSqsOM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by BL1PR21MB3280.namprd21.prod.outlook.com (2603:10b6:208:398::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.2; Mon, 21 Nov 2022 19:52:55 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020%7]) with mapi id 15.20.5880.001; Mon, 21 Nov 2022 19:52:55 +0000 From: Dexuan Cui To: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH 3/6] x86/tdx: Support vmalloc() for tdx_enc_status_changed() Date: Mon, 21 Nov 2022 11:51:48 -0800 Message-Id: <20221121195151.21812-4-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221121195151.21812-1-decui@microsoft.com> References: <20221121195151.21812-1-decui@microsoft.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|BL1PR21MB3280:EE_ X-MS-Office365-Filtering-Correlation-Id: 1fb044d9-54f8-482c-945b-08dacbf9fb9e 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: h1pet3+1/gFMuw/zXD93ksb5HxBwditLhOB2Q+IH9hHacNUWuMslAwfNupInf4jz2gIbUKZZotAC+YyX+zB3b9XkV3y0Nv2jfFaV0yTgeCK1OTry45KK1Z1vUIjZLHcdzistDmn8in3RupdyTw58zSV3ec+A5TYpatJCk0n3ALYMPjsANb92NCE6Vdq59aHrMhF9GaN8SQVDe0m3pimmFNCrMxWpUbBO1akcos4aKlXRYh5nQwoe+ofb8W5izawz8kIjZmf8hiITwGSTMzv61mnDTlxaly1ZmOQADXBf/XsgieOQ8yFk1Bm+FI85t9qG5aNAX0jGrLZlKuTJJoCIjdac+7L0QzWTqBziXLndmW0qTq54P3niwtw0ffiA/9Xs1aoeKAi2XQ/NNaAsYg1DxpDpIL8xNm1UFcTt75YjikQ7RcvByPNMbmw6EBoE0JquLkJUHuCZi2LLTFiO+p9T616LNjkMJ4kCPaUChjzHrVpjiOdCFjlaLeFyYU8agpgw91/P12Yjk2N2KWqwEl+vCGxFs7HoXcm+e4pd+kdeYkNwARf97q7pieFnhK5C9UThKfLNRD2PjDoa+/wjsKMi0gyAxaBf21RZgKM3+eBs/Wi0UPGDZj2uQWDe6WPr6UPBSm3XyzBi9JI5iHkOH9AixECreffj+FPhxG/w+jzP4tx2wRQheKx8S3ubge8yrxRmINxRPvHrG2sXvXkbEPRlihXI4Er+V57MM3F3kQf6dJU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(136003)(376002)(39860400002)(451199015)(83380400001)(2906002)(7416002)(5660300002)(8936002)(2616005)(186003)(1076003)(36756003)(86362001)(41300700001)(82950400001)(38100700002)(921005)(82960400001)(6666004)(10290500003)(107886003)(6506007)(52116002)(6512007)(316002)(478600001)(66556008)(8676002)(66946007)(66476007)(6486002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FAcyz1CYOlAs13EhkkK5N7mwIwerzs0HvcOaKv+gJlQrkIuL2c7IjwBEjPuKsTfBVVm+K8fxh/L109DkEOnBp6a+A88HtK9G4QffeoeGDz1lr6rBR8pbhPF3H9k+krtK5vRPIdAIaODVjKTWglOzibo9UybVDXgePcE7ZYGzCB/eymWiMFQTL6NkLw42jDTX8eGVBmMQTKKw5FI9CQu5f2gPYK3zeYjWokdC7BjgI3eUBRhLOz+pQjgu0Dw1+woIdc33dbvIh8Gxici0QW59GpuY/hy5tnVFKQpaplSuIIB3y3V81fAH/UDpsfWBqC+PdWTSHga7ZtjI1R0x4Cux2nBBAr+x8bi0YpOBfiEyVRKF7S69XU5cJyEdLY5o/dTr4m6Mz7Mz6L01Qa4DkZ18pnKARbaetcafe95Y9ldavXLD7XV+pbGIOW3K2P6VulY/gR6tT2OfSx8lYTIZjoOuYhaSqgkYEIOj96nuoyVWsluSjHS7s+OsDHRooL0JI6m//Dszwzfj98u9c8NLL/QvSy9lU7Y7u+cDouD+A3BqL/Fx4OoKJawrrSCuBPnQFkfKEN8YznixwO7BhLl90yp6/Mw3mtzRKdDFdPdcxm+9wVkbcxeW66YCjvfA9gQNYj6V+oRz/BiRsObE6TdhmpGddF2d/1HfHxaaNeE1jsu101DWiLPntkZb17Pv8PrVcXToUNFoDQJXrEK1Z5KTQQ3V0CjNByr5mA6jNHOUvRr5wTM7yh+GL0oqdJlOY4lf7QQyAe7Cibmzj4XdtRfnSc9KnRGXDQGvaG4+ksS3dvpA8gZcWghsbT0TzCDba7WnycqR5R4hwM5yFeubVEVZMYURf79/T9/P6UzvqF+qCrut9LQ4wC4ZXFPJMK1MTONmV4FnqT2Ub+IgFOVgq3hYPMhKL3OX6Lp7WmP6bq/DAZvyQwh4igkLxa/+hNoQlRhHfwla4PB3p/+zMZ15hoT7B2EBuAY4EutqmTODbkQWi14YCsNgVIuXS6IXB+yF4W9ZYiCKuzTCST8VAwI+ele9mxpsTtCv2KLtNZn6akCG0Foz0KWYw/M/S96kjuPWelq8ywbG6pegQAQfuzuvS+RMWru/fjR+NqQpfqvJ/cz4dqSRhk3XlyNMH3emIIT3UhhzCNcZhZppILwGoI27kERfBXHXHmv5rVU5ExbfxrVkoZrnzaT8Asr9QHm1G8+vvrngHa58HPQCi9bQGlny9AykiMjP4Eddv0y+KuP4lwD7RiBpGiGD/QVzhyHXee53qMWJoRKDnP6yiV+Dtwa/A5XEQdLAKt8Dd0+MJ2CHV6O00qc35tjGjhK6VzfoEXa/mf9UamcP8OTEvBE4akVQqz40FMR+430Z0ozaCL6jN/uvK0yx2c6ZcCNjVptQY01XVdcREcnV5HONnJ/QR0/+iZi05ANa8jawV+nCi6pofUC6GEt5I9G72bUcnvze4Vih9xVXlXb8XUGFPxrsP4BGaZCjGrR9sqoev6kQQd4h7nQm3xPHFum9mDIn6nm9pLayIEZRGLVzmsqlnLTZSJHqlozOTPVSnYxi4M0NokD76Q9nsfCF1YPxkxZ2rVG1EJGpO/EyfL6Bj9rEg8Tm8nORj9oC2HHx97+rUJdAHlhM4QO5k3xsZeU770OY/CS3irp4/OGNhdNB X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fb044d9-54f8-482c-945b-08dacbf9fb9e X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 19:52:55.6834 (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: ApMGIJ3c8vbrVpXTxtGY1kvBBw1XNSthBTR6PLAy4Ln1SpjYJEnv5EVz+9kvqGA1Cr9ZN8H1pCNyMWR9MXYWtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3280 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,RCVD_IN_MSPIKE_H2,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?1750136749486411387?= X-GMAIL-MSGID: =?utf-8?q?1750136749486411387?= When a TDX guest runs on Hyper-V, the hv_netvsc driver's netvsc_init_buf() allocates buffers using vzalloc(), and needs to share the buffers with the host OS by calling set_memory_decrypted(), which is not working for vmalloc() yet. Add the support by handling the pages one by one. Signed-off-by: Dexuan Cui --- arch/x86/coco/tdx/tdx.c | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 46971cc7d006..8bccae962b6d 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -5,6 +5,7 @@ #define pr_fmt(fmt) "tdx: " fmt #include +#include #include #include #include @@ -754,7 +755,8 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc) * the VMM or private to the guest. The VMM is expected to change its mapping * of the page in response. */ -static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) +static bool tdx_enc_status_changed_for_contiguous_pages(unsigned long vaddr, + int numpages, bool enc) { phys_addr_t start = __pa(vaddr); phys_addr_t end = __pa(vaddr + numpages * PAGE_SIZE); @@ -798,6 +800,47 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) return true; } +static bool tdx_enc_status_changed_for_vmalloc(unsigned long vaddr, + int numpages, bool enc) +{ + void *start_va = (void *)vaddr; + void *end_va = start_va + numpages * PAGE_SIZE; + phys_addr_t pa; + + if (offset_in_page(vaddr) != 0) + return false; + + while (start_va < end_va) { + pa = slow_virt_to_phys(start_va); + if (!enc) + pa |= cc_mkdec(0); + + if (!tdx_map_gpa(pa, pa + PAGE_SIZE, enc)) + return false; + + /* + * private->shared conversion requires only MapGPA call. + * + * For shared->private conversion, accept the page using + * TDX_ACCEPT_PAGE TDX module call. + */ + if (enc && !try_accept_one(&pa, PAGE_SIZE, PG_LEVEL_4K)) + return false; + + start_va += PAGE_SIZE; + } + + return true; +} + +static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) +{ + if (is_vmalloc_addr((void *)vaddr)) + return tdx_enc_status_changed_for_vmalloc(vaddr, numpages, enc); + + return tdx_enc_status_changed_for_contiguous_pages(vaddr, numpages, enc); +} + void __init tdx_early_init(void) { u64 cc_mask; From patchwork Mon Nov 21 19:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 24005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1798783wrr; Mon, 21 Nov 2022 11:54:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf65bX8KfRUgbxm/kB5E8lHW4c/CU5NXzRlYXxqhhAPwACCOBRqtgrJkCCocMzUIEBnPUeGe X-Received: by 2002:a17:903:1250:b0:188:6ccd:f2c5 with SMTP id u16-20020a170903125000b001886ccdf2c5mr1048415plh.6.1669060485294; Mon, 21 Nov 2022 11:54:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669060485; cv=pass; d=google.com; s=arc-20160816; b=obnpYGLxcfIh++nQ4e9v/7cUcuTMimK/0sY3/8kXjZ6DZzAZLQXJaGYybUDoiwUGHN MISOyOlkDD5A+g9Hx8uwyC9hausRxClVCXE9A4QvblQdfNgFqJHynnuAJFxJiUdc5Rfp hJ/3A+nhztKq4XeLs0Bdx/4hruc6cIcGQ5tYZk0sAqEfMnBFgCahOxWY5YyJ4FTwpDK6 XGq5L5A/Ztw8q0ng0ZwlpNPTPSRldisTzK0lirq3xc+ca2jYXPngU84UerHYkWPjcZgr wuor6aAfqk09JfTJ8+/XgPDX66CYLar2SKv7xPNORKHVTGCS3f83/2Up5O2KtVG6opde mJlw== 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=L9DNDJsrttehAaDab5LVic1ti+liukgIoMo1UJ7xFYI=; b=hAeg2GzjsEch1zpa87oFlDCeffBFAPfXBwLV2POhTpqLkOEvTQNvAAsOaIFPdB8EMu p/s9SRBifK3VhpDFqA3k94cE9jKnPKDrvZCO0Z6F4+aNgnL/wv+gG2bMv6rSS7doitNn 4bhOv2Eo+BYbBMqe0BHCUDJTuRgYtHS4kelt1oF9nEqF5MHbZQROhXVT22h8a2SUfotw BGNiuTvX8Gv19r7OjxEZNdD4+051WV1z+r7YIdFxiM7t3iAinIpg/risaZbzjoNwVC6t 5hNXVBFIOAkGhIDryEuWRXryYTpiebyKT1qzBDfInbqTAKi9VbWWd4OYCWc+tcqVc8xO usJQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=gcWzYido; 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 y10-20020a170903010a00b0018862b8c9a2si10898389plc.12.2022.11.21.11.54.31; Mon, 21 Nov 2022 11:54:45 -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=gcWzYido; 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 S231855AbiKUTxj (ORCPT + 99 others); Mon, 21 Nov 2022 14:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231717AbiKUTxF (ORCPT ); Mon, 21 Nov 2022 14:53:05 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022019.outbound.protection.outlook.com [52.101.53.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D561929C; Mon, 21 Nov 2022 11:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mRxRn+rOd4UqwNn9MVnJBQqTWPKrHT2YJzhK05F/qTQm2PHeWHw60uwSzgAooAadM7lbrktdjmkVKMhRFGHJ+xkk+ct+Q/0BBYli3YNkJt4j0OXmUhXM4kQ9uX4uo1ZdR/TL9xYUXaT+ZRWIwSB8baMN/UHI6LbirD2v1Ma7S28Ehuqqus/NQZXqVy1wpmNiooG4VwMxJVZJkxKdH2Q7e+OyF1gDnuBtaynu1uI7fy8TfygFUcapm+zZGB580unELBaoQDbE5JWArVNUSAtYBPWW8f5+3SfFwGtyXPXjzevCJvUYcojy/vzZsGnu9qZL395MINKpu5gJjeqfNer0Jg== 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=L9DNDJsrttehAaDab5LVic1ti+liukgIoMo1UJ7xFYI=; b=AeEPpvFtjkfzwtNH3kI6hdIpNtpylvuohPs3wo+6SDLs6vRv7orcH8p4JKZ+kzBjwHd//IUEVGzyk4bC7WMb4dnIE3Ggu39PpWeS+LVRAMgbOBO7EHY88O2Kbb6Ah4xxmEwUkzHqxiqRbIo1314giLdb8aA2u+bXkRjT6xM/TSaofKYfaODReOWdnNE70LHwN9ipjRyBXtsLsddN+Vp05b1//i1IiadnsI6igRunumdYusszG5O+xjLRPAW/E5lVmb0fHNT3ytigRPW55GvFo/D+3sJY04UO+vuIatFD5alvmaQ6/p3wJ62EroIE56ERGBxggYITrWApWL40DvXgbQ== 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=L9DNDJsrttehAaDab5LVic1ti+liukgIoMo1UJ7xFYI=; b=gcWzYidoZfELndoID4GW1Z2j75wnEfRSKCjgZWZCGPF3BcjNWbm/8xf9oBA9VRNOAkmBrCAK17ov4S8zoYM7vrZd0na7U7XgzpSxMkdqvQMJQfnA0xr7AH9u6QnTmWpIgeXIvTpDKes/y1TPlZ8h1gSrXT5qu0yUw2hsA+sTmtA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by BL1PR21MB3280.namprd21.prod.outlook.com (2603:10b6:208:398::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.2; Mon, 21 Nov 2022 19:52:58 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020%7]) with mapi id 15.20.5880.001; Mon, 21 Nov 2022 19:52:58 +0000 From: Dexuan Cui To: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH 4/6] x86/hyperv: Add hv_isolation_type_tdx() to detect TDX guests Date: Mon, 21 Nov 2022 11:51:49 -0800 Message-Id: <20221121195151.21812-5-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221121195151.21812-1-decui@microsoft.com> References: <20221121195151.21812-1-decui@microsoft.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|BL1PR21MB3280:EE_ X-MS-Office365-Filtering-Correlation-Id: e2f5f61a-4123-4103-bba4-08dacbf9fd25 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: lsbOOR2STjbK8HyO4Dn688iwDu5DY6+KsjHrdS6I9u1a/NWnmm2QdgfB0OcgLJj4jOSVWUdOIJHT1LzC2QNt4Wc1C6djPjYTTdlKnMfIBSy2DoE0Nr0O39pHWJnDAQAR5VV9/s+g/SHnrQpbnn9CBU3bhqzUJ6OcsdIYfS57KJxdfjE9CCMzSWDR0WV+QByacWd6sgzsEBnaIeDZL/LDdXCtO1R9dJsPvRzsF4zJJjaslN5LAOwmuPLCpcRn09FAbc64iYgyKAWqOPw6gHOmeRNNz/VlxgDj+288M7tWUXcXhLax5PSUBpFq7dkvvE7rJlMFdVGRTOCj2oBQSktxl96gZ0TNtCwTq0KEZLN7qQqXz+uW53bIee2fwRorOo8oYoC7xaRqr9JGExaLsupGhISz2BzSETLLl6B5EltNesqnSh4ZuO0e0XEDo2Tz5Lst7bVAxq+OEbZsJbD0GvQaHvH1xd5/Wij5Uur91Q5gH4lNxa5cxIrq5pdEVnS7wEzJrOKP4FMuQhxAhUPavXOoyhcD0pqY10pezAlCbj1s8KM/aO0RsV6URAo3zKkHk5cKd4HS4rBx7+YKNDNhYtkKF6OT5peOZF6scfmRyGdo+uSXdrD8UEBD0FZP2UnIwI2uCvejqd735UgIfS+ogzcSEU/ctvicMNXm8MMu3RHJO9epWUW4XpCTZLTUSRFhLTrn7gs0MbLspmJPHtlFyDCgAC7AoaUikKuHnLzffhnM+EM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(136003)(376002)(39860400002)(451199015)(83380400001)(2906002)(7416002)(5660300002)(8936002)(2616005)(186003)(1076003)(36756003)(86362001)(41300700001)(82950400001)(38100700002)(921005)(82960400001)(6666004)(10290500003)(107886003)(6506007)(52116002)(6512007)(316002)(478600001)(66556008)(8676002)(66946007)(66476007)(6486002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b8KhCxYIhc6dznErSNzpapVe9HxSjzOdN94HtTM+2lvwaKX+mlGMXRxA1yPoPyp70nz9nn+ZL5E7AupxPpdQFkMXP1BXJROJ4TA3MAGuaQLp1j2ZfChPh/DhFpPhEHd+PvdAzjN3FzElyfhHAkD7V/H/9ukIDC5JhbTCZ9YchinqeHRa2P3k/PGlaWcM063oA47o05l6fkDOxLGriXy6N04+2rrx6mHfHY1FgCTOn2K5Gj14GgiNybMnGKRyZyIpE44zM5X0e9OavI7UN7ba+9ztT78qTYXRLEdooaApLZx/EfHM368wsOYAgbo/Aef9yg41Cj/YdTLBB3D9PEuTCgx70Wg+hNHGl5slcSN6MwAnQFFa9Fx+oQY1yi+Tuoj2FPSpSoY/Cvi+F7nYobJ/imlhOAa1xrkl7rTkPxMobE+jDkPh58z6tA0P5Hab55HXiyibUXBc67EXDyUF1Xg11z0PraNSnMWlaKjXuU9asVBxh8msXcqXNBy1WwtiybbkSPsZp5m50awzqGyenE/jpXRBs/VWglOZS/4ub5vSJuG285uA1VtH0ZFsP8e/oh577KhP5gJFfpkffwczXIY7qAo+qotDvHdS5olzw2E3yZ/Egtgd4cxvJA3X5S/CeG4RZ/QagmDdsTx9ueHkxXu7ySr5sr/00U9eXXfZyuNLySm5wMKX8dMp8GWFHrJWzVyMh4a/ceQ2e/YRSXfiRlz8ehrq+McDpcnI7yqhsEWO5r2p/UhOA1l6AP3ZldPp++LdxN/sX50/HtspuE/DcF5KCJqj8L4rHjjBp2yzBf7prScPI/ltjiPIoiZ/uLMMLogSYNohSTfPoBbbwFRiUYbwk589AiCPFlLKaCX73DRn450UK8wsR9eKu3JwUYbS+44OAySWN+7u7Q7qJZsmWzIRvN+mgUjVb3VC1uRwMomniJlFXIBHCRkOjGi+GfPlzqi0v7cl9Ze3SGH3hLo4pTKsyZgfa2aMajxpHqucSfXQ3qIP9qHwqXGRjooxwEBhXwO3r6fUpwRnElQDICvFJzRQN3IN9uhdtOi0AwPnDC4kTzyr7OP6YJUvQyFWW3Hx/P4AJ4L1ZB6dvkQ5XAmNZUX119n4tEm0z0trpIoMbCQMnInD6hqg6Pj+fA5wJNbkghRjWx84x0Q29s356u9p8/zLdSOv01r5wm8agqgI9XUVhr+wnFXaCn9josgeN0/JAIsbn9xnfOYN3sHbRm+POMmraiE+DIp3N2kUf3xZ0gKKtH4EA+iNGey+Y1CtbIBlssSiYb70h2SeITsaR+WZmUD36cTxqvuwNq9TfU5vlOVvRMuSnMbVLDn6GBACmLbG6IOXiDACvysf2uApCAxj/6tvydIMnqe+hJJEn4pwcecF6cHbV/X1XpduRJWQQsq6uC+ly2NsfjttcotIINiZfqmufcNabgNC+4+P3ZQQD/GMTIjcc6MQOOvcHY6me1xw/HmUUQoSDDBl9COuDUDQSYVvhgVrPfEFUkqv9b9HkQHUNJkCyxggha89dgFauew7SBncDeDbSC4tHWyjyW0g9sSHIspdrkJfvsHumTbINBPYEuAYAVu4p/S1U6O2A/L9Np9lBa9sjcGC1M/jeYKgD9t0sFFOOM/dj83s/6rhyn0gKxfbFU/YuZYyYAewY+YXxm74 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2f5f61a-4123-4103-bba4-08dacbf9fd25 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 19:52:58.2625 (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: d3KAExd2rppxm3+R5G1Rq3QjBvQnYfuTWDGV1jiv+fZv8P8T1Dy43Y5dQSgny6YajwJlGXdAbxuU/mRKWNVL3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3280 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,RCVD_IN_MSPIKE_H2,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?1750136767520474108?= X-GMAIL-MSGID: =?utf-8?q?1750136767520474108?= No logic change to SNP/VBS guests. Signed-off-by: Dexuan Cui --- arch/x86/hyperv/ivm.c | 7 +++++++ arch/x86/include/asm/hyperv-tlfs.h | 3 ++- arch/x86/include/asm/mshyperv.h | 3 +++ arch/x86/kernel/cpu/mshyperv.c | 18 ++++++++++++++++-- drivers/hv/hv_common.c | 6 ++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 1dbcbd9da74d..0c219f163f71 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -269,6 +269,13 @@ bool hv_isolation_type_snp(void) return static_branch_unlikely(&isolation_type_snp); } +DEFINE_STATIC_KEY_FALSE(isolation_type_tdx); + +bool hv_isolation_type_tdx(void) +{ + return static_branch_unlikely(&isolation_type_tdx); +} + /* * hv_mark_gpa_visibility - Set pages visible to host via hvcall. * diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 6d9368ea3701..6c0a04d078f5 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -161,7 +161,8 @@ enum hv_isolation_type { HV_ISOLATION_TYPE_NONE = 0, HV_ISOLATION_TYPE_VBS = 1, - HV_ISOLATION_TYPE_SNP = 2 + HV_ISOLATION_TYPE_SNP = 2, + HV_ISOLATION_TYPE_TDX = 3 }; /* Hyper-V specific model specific registers (MSRs) */ diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index fc09b6739922..9d593ab2be26 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -14,6 +14,7 @@ union hv_ghcb; DECLARE_STATIC_KEY_FALSE(isolation_type_snp); +DECLARE_STATIC_KEY_FALSE(isolation_type_tdx); typedef int (*hyperv_fill_flush_list_func)( struct hv_guest_mapping_flush_list *flush, @@ -32,6 +33,8 @@ extern u64 hv_current_partition_id; extern union hv_ghcb * __percpu *hv_ghcb_pg; +extern bool hv_isolation_type_tdx(void); + int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 831613959a92..9ad0b0abf0e0 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -338,9 +338,23 @@ static void __init ms_hyperv_init_platform(void) #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) + if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT) || + IS_ENABLED(CONFIG_INTEL_TDX_GUEST)) { + + switch (hv_get_isolation_type()) { + case HV_ISOLATION_TYPE_VBS: + case HV_ISOLATION_TYPE_SNP: cc_set_vendor(CC_VENDOR_HYPERV); + break; + + case HV_ISOLATION_TYPE_TDX: + static_branch_enable(&isolation_type_tdx); + break; + + default: + WARN_ON(1); + break; + } } } diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index ae68298c0dca..a9a03ab04b97 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -268,6 +268,12 @@ bool __weak hv_isolation_type_snp(void) } EXPORT_SYMBOL_GPL(hv_isolation_type_snp); +bool __weak hv_isolation_type_tdx(void) +{ + return false; +} +EXPORT_SYMBOL_GPL(hv_isolation_type_tdx); + void __weak hv_setup_vmbus_handler(void (*handler)(void)) { } From patchwork Mon Nov 21 19:51:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 24007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1799322wrr; Mon, 21 Nov 2022 11:56:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf6fvdVwhaqLstfG/L/QL6aiF1/+5mFkgMNdS/vEUn152koYtz3egUbKlJo/TgIMbPIbaPmC X-Received: by 2002:a63:fc1b:0:b0:46f:fea7:4816 with SMTP id j27-20020a63fc1b000000b0046ffea74816mr378650pgi.532.1669060561714; Mon, 21 Nov 2022 11:56:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669060561; cv=pass; d=google.com; s=arc-20160816; b=c2XC6EQwL88SevaA3rlHVedA7D7iG4FBsWqQ9c+xxHKRDpx66e6M5joFyqxOu14WHH e62elRD8lr1l84ft32AJwbTgbD/dRlAClneHYOGf/3FZqk4BFIbw701EIkiO33Fw6t7T oVZU+c0D2ruSMtp9tL68XW09YF+pB9GaSACvBen2yvQKGw1i8C5LOj8NlLK/QhCverbj WWOAezjei2zAJTl2TX7EB/0aTfU77ebuRYfj+TDjctVwHzRamtFyvUGU54dHw6K8yEmy rslpt6Vt25TdFByy6Cpc23jhM8wljvs8LhRY9wl8ForZI0MVw96tK05UfTNZk1qGZWPH ZHSw== 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=1RvUGjpNnrfcGibK66Xh6KWAqOypfvu/g4MB0/15czM=; b=REsfT6GEwQZQW18X0NH6F4PQMa25q3DFpDCEQuSFS4f6AgbJIbtNLZj83EQhl0OVgE 9sP9LnZn8tlhSQc202YgBfp+osq0oo6LkBHapYC/tJ6Nvksk+VFw3FHRDlsj6yvsXJdz fNNyBnv76UT3g8QfCAxiwpef4DD+1zRrTo5/Fl05N8Jl41g+N44g+vvbwgu6R4Zq/INB N0HEQZ4dtjmyTqfIj3xilqg9l31qM1Q4n1B+x8ujdXIsA++FmrQOn3QTzZ7MwdENNRmi cwGiHgQRqGto12w/b6R5y20Stsf2ky1h+WEAqTDL4L922U4mD1MQvXa+aqJJE4EqWIbT 3Zrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Hc65KUcc; 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 x186-20020a6331c3000000b0044e466f47a2si12493749pgx.141.2022.11.21.11.55.47; Mon, 21 Nov 2022 11:56:01 -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=Hc65KUcc; 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 S231876AbiKUTxs (ORCPT + 99 others); Mon, 21 Nov 2022 14:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbiKUTxL (ORCPT ); Mon, 21 Nov 2022 14:53:11 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022024.outbound.protection.outlook.com [52.101.53.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6234623EAC; Mon, 21 Nov 2022 11:53:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kOvHRzhBvFjVSkWsDPGOJRF/O8zJijfk88N1Zus6q1zB4Y17EiK6t9vDL0vj2yaalw6elKTdj/2b3XzoveLlW2XP4bnWEXRAetBfRQlFWVvygwDB5umw85wjBL0PqPmFBE14UbJPg0o3JwpovPVVzYRpFbLHKqutZNeuqit22HTSIR272zAjBeCDd1ldewfFlByayW317JetVThgKXosj2HWyyxXeR1tI5cZzRu7B99ilstPF/tsVxB0OxotR/1DFUVZfQ4iVGzOUgKKSA1rpCE6WLWGwnQCxxlPu6oilWrtYDvLPTjer9dxZkOpIS5MqUtAOQS1yUxxGyuLgnKziQ== 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=1RvUGjpNnrfcGibK66Xh6KWAqOypfvu/g4MB0/15czM=; b=kQQZCe+2jIwBIe4OAHaPg2PrcxkMCXzDAW1iCPCoJKNCgm8Ud66k5CInZLkJsvjXFolahfrWn1z3joowSetEwzsIzKALW8kOjrpfJojkMpyUWVKspIRtCOYQEwmnfq1umAMmQm801I+9mRwW1CWIFeBss0qcIY83hTdWshBe96a3ZK2iGTyxDtLv//sdkkeolhZGftRFaGhJwWx+aGR1zP7kokCOfBGQjojydz0RKCuNHsLxaC26FYVvjB866xhtpHLrgbJolZJk9KeMHO1x5qNuCYYUdlWCY2FS2eHeXf3ArpsZc42ccdQEOIF/CokU8VnMq/6CtbSNJTwhpxU7FA== 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=1RvUGjpNnrfcGibK66Xh6KWAqOypfvu/g4MB0/15czM=; b=Hc65KUccwUQM2eey2JZpKu/Kw7j+ToBZ4v2/mU21tCIvjiUDaU4szKovgQA6XT/S/dkrTJMcsTG/kdFMtrcnxjnGYTtI+3OPhV572qI88lpf4RIPMZj+FvSMHusFRZOrsD1Tc4NzN+4EFtOsAwcHJS2iKY2qYm51gIVTPoR7idU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by BL1PR21MB3280.namprd21.prod.outlook.com (2603:10b6:208:398::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.2; Mon, 21 Nov 2022 19:53:00 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020%7]) with mapi id 15.20.5880.001; Mon, 21 Nov 2022 19:53:00 +0000 From: Dexuan Cui To: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH 5/6] x86/hyperv: Support hypercalls for TDX guests Date: Mon, 21 Nov 2022 11:51:50 -0800 Message-Id: <20221121195151.21812-6-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221121195151.21812-1-decui@microsoft.com> References: <20221121195151.21812-1-decui@microsoft.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|BL1PR21MB3280:EE_ X-MS-Office365-Filtering-Correlation-Id: 41f8d18c-d33a-4668-a894-08dacbf9feb1 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: JiOdgEZCgxIPEL03+sMgen2Cq+oKnUCssr9WXcxMY+MWX/Gkwo21k/ZF0mnq6XyMrC9eL7F0MirinpHKMywDXgNylIsH8cTp8CMvNmQrf/RfxJNUeEKGQj8ftSTVlcqxNf5cXVd+IMhv8xLUcAsIYCgZPpXT6tyK5Ro2CZuYOE/QSLnYtu7lV6/GqfiFQMo9XMnsQ4jHaeIqexHhpAkg0ZeKpalQR4L/8gT+bT6sMIXN/AEJzUM8dR7MPOsnsKUNh1dSoBai3hFc1YmUeP0OJbMy4f5DU4TseOc84tkj1DHsNxDj1nckE7dOuGlRfjQ17xDLa5PAHB7AalVqLT3IF1DOt3fdMOLyfw3shvhQ2d+dZkg2PMaGr30utmpnbk+lU85wJQFa48fbzY+iokFNZQJwihnL735x27zc1W5VA2Fk/bX2HEmHXJtLaqbBe8Qw48j6FPgofpG0i5I0fw06qTzy0DgQQ12JVTjDybgr2dWOxEeU+dY1bOGHFEoo8XLjVo6qiUsFrMDuOGWARuyqvv9WPpqwX4a6vcIAbqBTJ1XasJlRQuBeyTBNhTZVlmc3Z2b8aaAwAbkyQdkRTZM2Nw0iYG0seMlxUarxYACLCKT90wfLgIn3ANm/YQYWmSUDu6RVipuFVOZwqy4kA9RjRM9IDgJ5J3vqzYgqbxaPntry5FeOzr/VO9uBCS0UFock6IjH6z4iDxjlhafnej32qZTArO4be512eHD1+KfbqbI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(136003)(376002)(39860400002)(451199015)(83380400001)(2906002)(7416002)(5660300002)(8936002)(2616005)(186003)(1076003)(36756003)(86362001)(41300700001)(82950400001)(38100700002)(921005)(82960400001)(6666004)(10290500003)(107886003)(6506007)(52116002)(6512007)(316002)(478600001)(66556008)(8676002)(66946007)(66476007)(6486002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aomPXmDea2/RSP3uppbRKrPBSFFgbV0fH2JHyiYFVFUpehCsWLwPwZAf2FCQiOiRsaSUm/awUa66sjZYxC7g5Mk4/o0v+1DTd6fAv+nqI8TcCmlqRhr9UeNSSODVL9mDyUPNRUYmTJoUysCC5nm0KgLzoNDdrg4xJXsq+ifXw7MIDS+HyJtQslM4cUjBFGkTeX9Tb4HQK+nvoAyd7FfC1AINvtqFX9kibWGUES6HT0kBE9ihSrdQVwqZOvwcBbMADAUqyzewA3JufXlQYb4CMGHm7JK6Ys15+LIQX/1Ih4pmziEEthnGjB4DKxeUntCEuYT8ii6RiMDzmaLwtlIlKkm/mQDtkPtw/+q7f4cgFi9mX9uv0E6xn7ZfmaAYcrVwI/8JRQPVA7xvWlyB3hw05L75wlwi760r5PsIpZ+5mI4UHAYolHeWCCnUjwNhc6o7vrW7iNlOxe+I17Urrv3NO/9Pxgm86sLnWq5pWWKB+n/VHYVyAx9PN5YIibZTYNMMWsefGTdQwsEqQjIGh+z7ViSyZcKE2u8qL7uRfu2MmqsvxLAy/r0daITJOGglreq+DzKz2XU+P6hm6dYmP6E7u5GuKYvOKz6dH29IWBfN8mfZWdcY8XwMZL0wQVzZ4QS27F/n4tjfPwmDOdkdzHavW63qXKBJhdmilCG7xBoVyuu9oYnDT/9Mt5qVoI3C/2Omh398+r1jhQ+ZDQFRPeaoLuSqk4UxOrMo4ZPykILxlQUScHEVQVkiAxoc375Tbaj/Y3RA5+tqdMrea98Pv5DSII0/p15qjKSM6lz2QujGpTShYJ4LUlywa839qoP1QUZHMyfkp3yXL88Z1m0WNAeuOlmk4wAJKd55fSziUfq1YH00/rhXWAtWIsuD/bY+eBlAOATl6ubNnOasL91Cr7ocjGgZv/RqUiMgyYRLYgqWAXDZQzMHzcuGpAAcviUk7piX0QJa3zTD6qw5oCcF2sW3+XU3fKqJ9i7uvxCBuH5g6uwGTKcXytMvxfAunA6kADLq82lWAw3g6HdEDT4gLv98nOe8KfiXrpgV0eQn9+mo8XKi89KDmKDHnh6eDQP3l5QQ8f0rcOP9MrnhfAR+dW79TYja+ustAll8tJAdl9Yj90ZosRxSz7Fz3Q1W3/MaTBFKElHe2DzsO45StVVg1geA2I151zA18U51+/iP0fE0WQkxfQM1B+2nrPZ6SwAVFXdHROA8BueehsrSexGyrEQ5n1XzRI4fKNQrbZDnHFW704BUqvrsx4KATayRpORSGSOHaqGmrB4NsfdnA4XwUGgTQ5N7NzRPx07T/KIw69YTTJyAU6lHANy1fQ54Rh9TfLCkis/TWQRQUGVG9teUR3Bu1ClzGnRhV0i73BrAS7BBhnykMbaZc4hW+1PzNsPqTHoKHT1EalHPpAQQJ3pRuOXKojeBRtoBREHoXdcMlS2AqKwHhUqrr0MnNRNI6TeKjvf5rUN7FJb/j719phvK/ACYgKeOoGwCj/iDH0BYxxGqh9h2r7zLMavsN/iafBtZlUpJsd/xcD/2aFvKVh2ahX1xatVVAP2P5B3u24tWgmmM9qgfZsNGTsiQcrMfhhUE9UNa2ogCsyJrAIAecXAgRJKnimRMnr8gnyNNUqmk7mEvOSJup+nlJbfmB1bGFWI5bNdi X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41f8d18c-d33a-4668-a894-08dacbf9feb1 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 19:53:00.7947 (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: xx8DsGBUsOqy+eTCYxUpbk08s0Gxt+ZwB4aJ65D5Dz8UCkBpapcGgTo06RXynKJgP6rgkLf4YmTESkLTJmKffw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3280 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?1750136847737803179?= X-GMAIL-MSGID: =?utf-8?q?1750136847737803179?= A TDX guest uses the GHCI call rather than hv_hypercall_pg. In hv_do_hypercall(), Hyper-V requires that the input/output addresses must have the vTOM bit set. With current Hyper-V, the bit for TDX is bit 47, which is saved into ms_hyperv.shared_gpa_boundary() in ms_hyperv_init_platform(). arch/x86/include/asm/mshyperv.h: hv_do_hypercall() needs "struct ms_hyperv_info", which is defined in include/asm-generic/mshyperv.h, which can't be included in arch/x86/include/asm/mshyperv.h because include/asm-generic/mshyperv.h has vmbus_signal_eom() -> hv_set_register(), which is defined in arch/x86/include/asm/mshyperv.h. Break this circular dependency by introducing a new header file for "struct ms_hyperv_info". Signed-off-by: Dexuan Cui --- MAINTAINERS | 1 + arch/x86/hyperv/hv_init.c | 8 ++++++++ arch/x86/include/asm/mshyperv.h | 24 ++++++++++++++++++++++- arch/x86/kernel/cpu/mshyperv.c | 2 ++ include/asm-generic/ms_hyperv_info.h | 29 ++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 24 +---------------------- 6 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 include/asm-generic/ms_hyperv_info.h diff --git a/MAINTAINERS b/MAINTAINERS index 256f03904987..455ecaf188fe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9537,6 +9537,7 @@ F: drivers/scsi/storvsc_drv.c F: drivers/uio/uio_hv_generic.c F: drivers/video/fbdev/hyperv_fb.c F: include/asm-generic/hyperv-tlfs.h +F: include/asm-generic/ms_hyperv_info.h F: include/asm-generic/mshyperv.h F: include/clocksource/hyperv_timer.h F: include/linux/hyperv.h diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 89954490af93..05682c4e327f 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -432,6 +432,10 @@ void __init hyperv_init(void) /* Hyper-V requires to write guest os id via ghcb in SNP IVM. */ hv_ghcb_msr_write(HV_X64_MSR_GUEST_OS_ID, guest_id); + /* A TDX guest uses the GHCI call rather than hv_hypercall_pg. */ + if (hv_isolation_type_tdx()) + goto skip_hypercall_pg_init; + hv_hypercall_pg = __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END, GFP_KERNEL, PAGE_KERNEL_ROX, VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, @@ -471,6 +475,7 @@ void __init hyperv_init(void) wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); } +skip_hypercall_pg_init: /* * hyperv_init() is called before LAPIC is initialized: see * apic_intr_mode_init() -> x86_platform.apic_post_init() and @@ -606,6 +611,9 @@ bool hv_is_hyperv_initialized(void) if (x86_hyper_type != X86_HYPER_MS_HYPERV) return false; + /* A TDX guest uses the GHCI call rather than hv_hypercall_pg. */ + if (hv_isolation_type_tdx()) + return true; /* * Verify that earlier initialization succeeded by checking * that the hypercall page is setup diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 9d593ab2be26..650b4fae2fd8 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include union hv_ghcb; @@ -48,6 +48,18 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output) u64 hv_status; #ifdef CONFIG_X86_64 +#if CONFIG_INTEL_TDX_GUEST + if (hv_isolation_type_tdx()) { + if (input_address) + input_address += ms_hyperv.shared_gpa_boundary; + + if (output_address) + output_address += ms_hyperv.shared_gpa_boundary; + + return __tdx_ms_hv_hypercall(control, output_address, + input_address); + } +#endif if (!hv_hypercall_pg) return U64_MAX; @@ -85,6 +97,11 @@ static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; #ifdef CONFIG_X86_64 +#if CONFIG_INTEL_TDX_GUEST + if (hv_isolation_type_tdx()) + return __tdx_ms_hv_hypercall(control, 0, input1); +#endif + { __asm__ __volatile__(CALL_NOSPEC : "=a" (hv_status), ASM_CALL_CONSTRAINT, @@ -116,6 +133,11 @@ static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2) u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; #ifdef CONFIG_X86_64 +#if CONFIG_INTEL_TDX_GUEST + if (hv_isolation_type_tdx()) + return __tdx_ms_hv_hypercall(control, input2, input1); +#endif + { __asm__ __volatile__("mov %4, %%r8\n" CALL_NOSPEC diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 9ad0b0abf0e0..dddccdbc5526 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -349,6 +349,8 @@ static void __init ms_hyperv_init_platform(void) case HV_ISOLATION_TYPE_TDX: static_branch_enable(&isolation_type_tdx); + + ms_hyperv.shared_gpa_boundary = cc_mkdec(0); break; default: diff --git a/include/asm-generic/ms_hyperv_info.h b/include/asm-generic/ms_hyperv_info.h new file mode 100644 index 000000000000..734583dfea99 --- /dev/null +++ b/include/asm-generic/ms_hyperv_info.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_GENERIC_MS_HYPERV_INFO_H +#define _ASM_GENERIC_MS_HYPERV_INFO_H + +struct ms_hyperv_info { + u32 features; + u32 priv_high; + u32 misc_features; + u32 hints; + u32 nested_features; + u32 max_vp_index; + u32 max_lp_index; + u32 isolation_config_a; + union { + u32 isolation_config_b; + struct { + u32 cvm_type : 4; + u32 reserved1 : 1; + u32 shared_gpa_boundary_active : 1; + u32 shared_gpa_boundary_bits : 6; + u32 reserved2 : 20; + }; + }; + u64 shared_gpa_boundary; +}; +extern struct ms_hyperv_info ms_hyperv; + +#endif diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index bfb9eb9d7215..2ae3e4e4256b 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -25,29 +25,7 @@ #include #include #include - -struct ms_hyperv_info { - u32 features; - u32 priv_high; - u32 misc_features; - u32 hints; - u32 nested_features; - u32 max_vp_index; - u32 max_lp_index; - u32 isolation_config_a; - union { - u32 isolation_config_b; - struct { - u32 cvm_type : 4; - u32 reserved1 : 1; - u32 shared_gpa_boundary_active : 1; - u32 shared_gpa_boundary_bits : 6; - u32 reserved2 : 20; - }; - }; - u64 shared_gpa_boundary; -}; -extern struct ms_hyperv_info ms_hyperv; +#include extern void * __percpu *hyperv_pcpu_input_arg; extern void * __percpu *hyperv_pcpu_output_arg; From patchwork Mon Nov 21 19:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 24006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1798899wrr; Mon, 21 Nov 2022 11:55:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf4htkjDAK2rMlEOVNmXsfJRzjtPhDsFKxxI/gczbVe0OD1H57Q5d3gXGvDDmDS5/AeJAoBp X-Received: by 2002:a17:90a:fe4:b0:218:721e:3e17 with SMTP id 91-20020a17090a0fe400b00218721e3e17mr22176619pjz.245.1669060501295; Mon, 21 Nov 2022 11:55:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669060501; cv=pass; d=google.com; s=arc-20160816; b=CDUh0BkT/KLDfziWE3PX3VwUOdaM9SWm35e+bPteFId3EN0lBfuzP+6JV6KLTA3cYg V7AXFpf4IV+hxwNWD52f1D7MEyRaxTWsBlPhXFERm1G80VjRLVfN66kd4tyZ+WjjhV67 /y4jdAZJ7TfRUJjeE1ZCbR38Sco0WUqXoQisTZ6IhJ3zAeARZwHirUcHYWV/ryNIvWo0 +x4hMzixDuLJrZsGdj3T4wJ9uNfRtpV4cxeZEzem9LSACSZUWrROZ7LxwUOqZP7/li29 o55yrMPtCPWdT11WmyI4yJ6knvp5HD8Y74Y7owytj1MkdjS5DG7X7A7wkNaX8eVrF7Pq eEQg== 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=wgYfMXk7zCZD22uzpi5M+jBRlsI28SBPGNnSrAPMfR0=; b=P2LraJHddrKoCYr05HEEuHZ1EeWpFpeUGq46oqeJURAQdQOQTSxHtZiX9KezTKZhRR PwYecuOWEInf+54XBJ/KcnonW1B3VMgnV7pc+T8Vte8W+6D1DSM9NX3wJ6jL59iH5Geu ZTOheVHmXzFZps+/0uAV3i++RU0YxHZvXLcBS2ByjMPyDdGR0R0Jp7peK0AoK+tap9+U mTWA7af9YRjEjXGV4MKZSGncxXvMuPO1a/KGX3+V+oOm2W5LzDn+72OQbRQzbe2WaMzh nGMT/VuTYeXRd7RzW0c7xABAlI7ahRq62cpqjzUbpgwgzoai1UZy37jtlgEJ77NIonY1 GihA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Uv+fOadH; 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 a10-20020a170902b58a00b001865dfb6774si11030905pls.458.2022.11.21.11.54.46; Mon, 21 Nov 2022 11:55:01 -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=Uv+fOadH; 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 S231750AbiKUTxn (ORCPT + 99 others); Mon, 21 Nov 2022 14:53:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231710AbiKUTxK (ORCPT ); Mon, 21 Nov 2022 14:53:10 -0500 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11022024.outbound.protection.outlook.com [52.101.53.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3401BB7EAD; Mon, 21 Nov 2022 11:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=akOshGiJYHNlu8O/cWNR+cs9PPEwLAq7QdJR5J+m6wilqW1+JncGt7PXOgixP0Z6Ru7So4VBEiiRtOxcxJKySX0/7v0LyPANW6TikEXfWbFVtwtThvxeR0Sw3mF2iHfHqfqbSTdd02/EH8Y9VZ4FneLKj8yt43RN4/ZnA6xektUT6Pzm1pXMUSwLUD6mhquZZ8jQx9H36tXE9phO42w3bBeCZ4GKECfbF/McPNEHtOoA1K7qutB6UyqNlMZd7L4GipRZhlqYRRNHn3nMZu0zzcRIswdW5bFWXQQKlr3TdUObqmvx3lc6K+RTgj0Ef5hKywR005Wl/iITZErDZzm0vQ== 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=wgYfMXk7zCZD22uzpi5M+jBRlsI28SBPGNnSrAPMfR0=; b=NNE6TI+0WSVdFZhelhTpnSSSOTf0kqbRmi+Uj7zVW1AjGqmB7/msa4W0PjJqns25kle1vJXNdIFs7Rit7b6LfJU/1EspjZkBMBp+QbzK8FJpIysi+CfAslT5i0vHSUM4bVwQBdQMso4GSBP7xvYJ9VdYypzO7NgjULFPru0hUlasNXwfkURICfdZwEMLsJYzCkw4UPl3V+q2MLJmNFhJ50nMadpOzF5m+K0g5XJqo7+RakrlEePb1Ad507qsu4KLTerSyg+VsUqOze6RFbHojueppP7ogVL/YaOWLEeVElTQH+upYfDAd6oU53PryiofFR7Lh4QAGeXn1ffeDd4O6Q== 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=wgYfMXk7zCZD22uzpi5M+jBRlsI28SBPGNnSrAPMfR0=; b=Uv+fOadHv1TjLM0SrCay6mOhZ+H7E8ZSyrx5tXq83fRtNtxvfePDjfiTG/I8CYcVTSckEPLwCc1X54UiCD3KTVu8r6RDGSsw2QF3K3Y0k6/xEQpU1kVpmukRobd02JHvClsB7yV2yBQInv6NI7dYabf8gFayUMzF4etlNfh5dM8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by BL1PR21MB3280.namprd21.prod.outlook.com (2603:10b6:208:398::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.2; Mon, 21 Nov 2022 19:53:03 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::ae03:5b1e:755c:a020%7]) with mapi id 15.20.5880.001; Mon, 21 Nov 2022 19:53:03 +0000 From: Dexuan Cui To: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, Dexuan Cui Subject: [PATCH 6/6] Drivers: hv: vmbus: Support TDX guests Date: Mon, 21 Nov 2022 11:51:51 -0800 Message-Id: <20221121195151.21812-7-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221121195151.21812-1-decui@microsoft.com> References: <20221121195151.21812-1-decui@microsoft.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|BL1PR21MB3280:EE_ X-MS-Office365-Filtering-Correlation-Id: a8a5fc50-3c0d-43ad-8274-08dacbfa0031 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: XPhqZNnog6EHNh6//PITMQXTLouygSgnMlRUZghJSZKe4CN/ksOCu5MAHo1woJUSMPLRCrM/VcxDPhdtS6xd2PLKZIpeegyyBZFMvHEUtilB9TwBXqTi2hT7hfTAmgDD/JJNmRtYn6Wz0ZZocllI6QhnJsbf5ntDQdGRWo7NL4XLeLrbYAHpoRzgxbAPUygHy272qJUsgNoZhiWQp+d8FbdunjG/4q/4iU73VckxAJoHc5SMwuJYMridsp0gyiZXiLpcuNVqnRFM7IKtUOzQCcx0lJrPJ7exk4hu2nTCnA1D8I2M/EeLVqbeyAJE9x5XMOszvZch56WaclbE3+W0+OwuwyFG59sqMrTt5+uHL1yrcUCWSF+cRqOx+gDHUPFkEWyz9SWxYLsWfD0qAX2TVf/peXSmFfASYAjPAl8nfKp4zG5oogw5R+q+DoaZf1XYmvgc813G+CKdophIbXgMa3C9XXBRriN934oXWB3XGh/xhhuVvQWI5r82+nIYrhUDvMsvFSNSOVSMLVD6/Ixn5CXOcAbSA3eigYmEhmHpjT9HONHWK5dW5C5rOKynDvx+kmMMbBaPz98plL6+qdFJPueXpR/5RRDJYtNOd0NQoONpnl3+zo7whk+YavswKzWrCDlkW+R0v4xzkRSbitCTR5ao/hWEhDUsdk1sXAn9KvSRHlvsnWn+HxvtPNUNPRYPNsaOieUFtfqv4zWZcstiQ6vxE6F7ldLP7cq28zxfhz8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(136003)(376002)(39860400002)(451199015)(83380400001)(2906002)(7416002)(5660300002)(8936002)(2616005)(186003)(1076003)(36756003)(86362001)(41300700001)(82950400001)(38100700002)(921005)(82960400001)(6666004)(10290500003)(107886003)(6506007)(52116002)(6512007)(316002)(478600001)(66556008)(8676002)(66946007)(66476007)(6486002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rTMVx7+DCPnjJ4Ib3HojHSjYQEV8ohuGDlvGAL6WC+mBDIB/Oy5VyFYnvRQfqaiRSRphIEZ1AflikRrgzJrCLQu+Fwcm5H7ZuSP34LvwC9xAvQ5LEM4prrtL4Qtsgmlkqp44JRZjDiWaLXNsgy9JoGR5NaJN1jL1u6pCuPCuhlQva8tlV0jB129aP/m9T+CFqMD2PzNzWW5uGcaF0AM0dxf3KLSYJv5o4BGb1bl/sbUhxort9e95U+Vaj+XUywxgqLYGm7/K93lvszBFPhbelgkf7hYA9qkZNfHkPV9XFeHqml1fvtD56+OoAHQHO9fiMR5d+DTEYx/BKYXYCMcKuevik4frNOOLCC03Foh8wifY5s3a2r33JFshOjUStvnVfEwDMHy2v+8IufeSXx11hWUZeW4HDWI52/Osj9ydwigkRfaCOL946HEV+z/tvkq9VMHMuAWa7es6JXp+M1iiBHdlgBE86ZHujtNhaSCSlwBe3rvs1RY5/YBclUVeDwss86bl9TH2DFe8ZuEmzZ7ApwAxdcOkE6DD8HEv2MhvfC6dOT/eAwRCgdVVqks0whalpOpps00s8DrgYSdIjwUtMug2CJmbbccAl24twVMNpL+GAe7PfRoTgit2OcaGIm6uCDN5o+X/s7Zp+9KwuzAJkcj7yLDxZg8nxvWD0UdGfvsUroY++rXF3uVPanlgKXo3DdwM1/xYmv/jhj+8vh00AhhwPfnHJADVhHjSWXKIOWvXXSuE6noTvSYzfik8H9ZF2yLN6j8kyjHMbnkWLEeHxLVKmt3xeDQoH1SRYXED33RnoY+Q/rk7z1r2lXFsjrgW1mgexl0qV5AZfPxg5iGE9wiVuRaoa2TOCqynOljyt/2tbnQeSiDHQTlVGT/c9PutH2ArKVNGbhnN+QESDJTgJcuTgmSVZx24cQp1oclR1ewI0RF8SvarHJSXBIyhDb2rcMh8JAGVQznNcYe40VlCNR+Vz03Wyi/0D4zM0V8Kwj70lVvY8WfzFjgBGd63XGa+DyxEOu2N/STzPMVguf/zL9xH4ODgQ9EtnEI0YImdpOLC5EnJa01L538jEqPw//6JPQlf9M2s/Jkb2N4adoCARzWjNfORPkrIOwFTlyKE+9MPfbN7lrfjU55mS/RVHc0ZSj0s+KP2AeyvHqcwkObRXhdKEQAZLorUfPNa7rsnqHYkOEeT75v1BRQ7HaJ3V44kShZMqCBDLlPWvvA7D+Gqg4plvaNmZBbiQW63eXWctKJ8kx6YTxs41Pd1vrsTp8lKy8k+Y1i9zg9GdbCtCV5M8UpmpTwXu8yVOVRK9cf0td29XU0tNqPFrYqmL4XxCrAvjpc9faOk3A4vexNVy4gp8FcFjtrZ6EYZPhYXgts8bYkhK7xxJ64VrNKUgio9ccHFSNdXNT2W8Lq1nHaPZ9dXWQJR2l8WkeW4jB9cU8zTEkZq0t2KZ+9ZvUFb6xu30y9FWP3IumOUdxjk9B0AUZruKKslN20/bpOBGEoRHeg5Z2mxfaXyYhVyiAbHV/44IMvfBbGHGDXKqZlUTwEuhMC4/PsvFcRaib/XOiY7v3zUt6lKhGuzQ4AURbpQqe0TQ6pFLvXnOYG4jspfRdHvRVytoHzZu8y5cQc/3zNiu+ervyCy/SJX6wPe4vx7iMqI04cF X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8a5fc50-3c0d-43ad-8274-08dacbfa0031 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 19:53:03.3103 (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: 5rjY8z7ouiBCGXNuZqjA2IV7ZSwTtccqr/LF3oMryUpGf5IZ5x9HAUW1Lq+5JsabUyK/RH6D4OiYxUG/udhv2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3280 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?1750136784415971732?= X-GMAIL-MSGID: =?utf-8?q?1750136784415971732?= Intel folks added the generic code to support a TDX guest in April, 2022. This commit and some earlier commits from me add the Hyper-V specific code so that a TDX guest can run on Hyper-V. Signed-off-by: Dexuan Cui --- arch/x86/hyperv/hv_init.c | 19 +++++++++++++++---- arch/x86/kernel/cpu/mshyperv.c | 10 ++++++++++ arch/x86/mm/pat/set_memory.c | 2 +- drivers/hv/connection.c | 4 +++- drivers/hv/hv.c | 25 +++++++++++++++++++++++++ drivers/hv/ring_buffer.c | 2 +- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 05682c4e327f..694f7fb04e5d 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -77,7 +77,7 @@ static int hyperv_init_ghcb(void) static int hv_cpu_init(unsigned int cpu) { union hv_vp_assist_msr_contents msr = { 0 }; - struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()]; + struct hv_vp_assist_page **hvp; int ret; ret = hv_common_cpu_init(cpu); @@ -87,6 +87,7 @@ static int hv_cpu_init(unsigned int cpu) if (!hv_vp_assist_page) return 0; + hvp = &hv_vp_assist_page[smp_processor_id()]; if (!*hvp) { if (hv_root_partition) { /* @@ -398,11 +399,21 @@ void __init hyperv_init(void) if (hv_common_init()) return; - hv_vp_assist_page = kcalloc(num_possible_cpus(), - sizeof(*hv_vp_assist_page), GFP_KERNEL); + /* + * The VP assist page is useless to a TDX guest: the only use we + * would have for it is lazy EOI, which can not be used with TDX. + */ + if (hv_isolation_type_tdx()) + hv_vp_assist_page = NULL; + else + hv_vp_assist_page = kcalloc(num_possible_cpus(), + sizeof(*hv_vp_assist_page), + GFP_KERNEL); if (!hv_vp_assist_page) { ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED; - goto common_free; + + if (!hv_isolation_type_tdx()) + goto common_free; } if (hv_isolation_type_snp()) { diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index dddccdbc5526..6f597b23ad3e 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -350,7 +350,17 @@ static void __init ms_hyperv_init_platform(void) case HV_ISOLATION_TYPE_TDX: static_branch_enable(&isolation_type_tdx); + cc_set_vendor(CC_VENDOR_INTEL); + ms_hyperv.shared_gpa_boundary = cc_mkdec(0); + + /* Don't use the unsafe Hyper-V TSC page */ + ms_hyperv.features &= + ~HV_MSR_REFERENCE_TSC_AVAILABLE; + + /* HV_REGISTER_CRASH_CTL is unsupported */ + ms_hyperv.misc_features &= + ~HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE; break; default: diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 2e5a045731de..bb44aaddb230 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2120,7 +2120,7 @@ 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()) + if (hv_is_isolation_supported() && !hv_isolation_type_tdx()) return hv_set_mem_host_visibility(addr, numpages, !enc); if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 9dc27e5d367a..1ecc3c29e3f7 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -250,12 +250,14 @@ int vmbus_connect(void) * Isolation VM with AMD SNP needs to access monitor page via * address space above shared gpa boundary. */ - if (hv_isolation_type_snp()) { + if (hv_isolation_type_snp() || hv_isolation_type_tdx()) { vmbus_connection.monitor_pages_pa[0] += ms_hyperv.shared_gpa_boundary; vmbus_connection.monitor_pages_pa[1] += ms_hyperv.shared_gpa_boundary; + } + if (hv_isolation_type_snp()) { vmbus_connection.monitor_pages[0] = memremap(vmbus_connection.monitor_pages_pa[0], HV_HYP_PAGE_SIZE, diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 4d6480d57546..03b3257bc1ab 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include "hyperv_vmbus.h" @@ -119,6 +120,7 @@ int hv_synic_alloc(void) { int cpu; struct hv_per_cpu_context *hv_cpu; + int ret; /* * First, zero all per-cpu memory areas so hv_synic_free() can @@ -168,6 +170,21 @@ int hv_synic_alloc(void) pr_err("Unable to allocate post msg page\n"); goto err; } + + + if (hv_isolation_type_tdx()) { + ret = set_memory_decrypted( + (unsigned long)hv_cpu->synic_message_page, 1); + BUG_ON(ret); + + ret = set_memory_decrypted( + (unsigned long)hv_cpu->synic_event_page, 1); + BUG_ON(ret); + + ret = set_memory_decrypted( + (unsigned long)hv_cpu->post_msg_page, 1); + BUG_ON(ret); + } } return 0; @@ -225,6 +242,10 @@ void hv_synic_enable_regs(unsigned int cpu) } else { simp.base_simp_gpa = virt_to_phys(hv_cpu->synic_message_page) >> HV_HYP_PAGE_SHIFT; + + if (hv_isolation_type_tdx()) + simp.base_simp_gpa += ms_hyperv.shared_gpa_boundary + >> HV_HYP_PAGE_SHIFT; } hv_set_register(HV_REGISTER_SIMP, simp.as_uint64); @@ -243,6 +264,10 @@ void hv_synic_enable_regs(unsigned int cpu) } else { siefp.base_siefp_gpa = virt_to_phys(hv_cpu->synic_event_page) >> HV_HYP_PAGE_SHIFT; + + if (hv_isolation_type_tdx()) + siefp.base_siefp_gpa += ms_hyperv.shared_gpa_boundary + >> HV_HYP_PAGE_SHIFT; } hv_set_register(HV_REGISTER_SIEFP, siefp.as_uint64); diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index c6692fd5ab15..a51da82316ce 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -233,7 +233,7 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, ring_info->ring_buffer = (struct hv_ring_buffer *) vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, - PAGE_KERNEL); + pgprot_decrypted(PAGE_KERNEL_NOENC)); kfree(pages_wraparound); if (!ring_info->ring_buffer)