Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2750853rwb; Sun, 15 Jan 2023 21:57:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXverEVs0xQqeO+gMqzLJnV2Ji3cYMXrJnux+xH0BZUmz6uv2EI1VQznn/fYgN0IjDatbcZM X-Received: by 2002:a17:903:24a:b0:194:480d:6afc with SMTP id j10-20020a170903024a00b00194480d6afcmr21302554plh.48.1673848620972; Sun, 15 Jan 2023 21:57:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673848620; cv=pass; d=google.com; s=arc-20160816; b=ai4ioHSh/zqF6jjgtumJyOX0hsPeRPntIq3uWayWU3rPxOUtc+PHhvzQ82GViezACz zdu7Y97jlpoaWMjyRU1G24d3yc56+zDcRGvPHkEpq3HbVpSHlfLCu4LKk+44a/f/TIsN 9zpTthHfX4NDoHgW30YRWUbtxaTCiREZJwyTnI3a8mlpAGnlIDrkMXVinL8ONq620Nyw pggmRZR97wiQUgZbd+Vd35vHJpJ1KrrrNdZqeMI9AgHaR0qbiRAvR+/iK3f/Qui9C0dd NhyTWiqWpVrvqfYmxbLnim/EjmlnOBQMbGFpkTFenKEAL1JSpad3jjrMtkXREgczHio4 6VvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:content-language:references:cc:to:subject :user-agent:date:message-id:dkim-signature; bh=BEbRuM2xdaEnj0RtKThI2IEO3HwJjbltHB0zGIN8bio=; b=yUMf5EWJSRi8xPy0/ggsgNmiXXHNC8tiuI+k/jStSlkXGWWGcAVDhvKUQtwUVx6b6O sx1X4KuHNOhbmpcBmynzImVUKqGi3NOuTw5oFVdxd7lBPsp3eaX2KE8Oo+Qm/eeitszW FUaxw+DWXa8KKCB2rtHjUO3dWvxAY1nioHgUV7DIh6VZZR8BrKHPzeyoAnLGHRlz2Aaz Fe4yUoWFS3o0yqExVs0v0XdYGXsW2a2RPCHvWmLYzUOr6oVYHn1ejI/+pM6RLHGcl0Kt gD4TZHV3aVDgiXWK6tBkk0WlwtVamnfXsQ4TPZYWmFcNpNxi4oTQrubz2gQsajgFO0hf p6rg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=JTxTVrNk; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n16-20020a170902d2d000b0019274931758si30623198plc.577.2023.01.15.21.56.54; Sun, 15 Jan 2023 21:57:00 -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=@amd.com header.s=selector1 header.b=JTxTVrNk; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbjAPFim (ORCPT + 54 others); Mon, 16 Jan 2023 00:38:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbjAPFih (ORCPT ); Mon, 16 Jan 2023 00:38:37 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2082.outbound.protection.outlook.com [40.107.94.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3E538A40; Sun, 15 Jan 2023 21:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gfvEAfrkUcYm02aoBQR0MZvSj1xFtBGf4k5S3/bzCkiRLVt16DZDGjf5h4nO+uPFY7sSyXco6jkHcBxMa8NmzyZHhJfIAtCq2ApzvgIanFy5L6O42Vz2symK0BtkxftYgxbuM8iWzYaYfqnokEAwMgGKbe98LC5eK81w4EQZCw/URewM4yr+h64Cn5m2uwKaYB/CqGSpMkJnU5c6XGj7963vn9bm5MxKHt/U1Ym01Vd2KeJWs0vXy2YpVRkjMIF27ztOK2IXRMBI7Gz3DvBSKcc6WXwdHlYpz/HCMpjjLVT7yYnsXPm2ITbTxguFElCdP1jeqz5SMMqtvA2+D6krWw== 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=BEbRuM2xdaEnj0RtKThI2IEO3HwJjbltHB0zGIN8bio=; b=R+GYX6wXFf2rwMPVsSWvRclQHorEExYDRi9yAdHwnH4s0c4NZd1A+ZWQyzFnx7moC4CzKWsFelrTGhWv0io+Qi6O3NcQO6kFG/WhxIoonTIx8pXpedeqTgvtBmQGXGXbi3agPBGffS3SNh19WKRhH6hEn5nYuYT+ffvXdnu1QNWAyhsdtlj/UKwLWg8Zxy9CkdqbGvd6Cc/UFOHaRGiOBJOkah5+PukelaXFhluc1B6vooB9t8YeBUqGkqWU6/JWOuAmuIEa1Pq1QgXlckDiKjiqWM60/kada5cUv7mjysQ/uKVxqKkhjqOJT0euz33kikrRZzXqQoZw9UCL3ZNhow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BEbRuM2xdaEnj0RtKThI2IEO3HwJjbltHB0zGIN8bio=; b=JTxTVrNkGg2HZ76GyhdOGMJ+65h2qh4Usaf4z9rMYqgL7sHmAS98TPyWHAzYeb+JL8dy5uhdWVZWflGsDWuaS9KG3DMS3ErtNiOsdUe6k5OYmMYG0/Lnpb+RRtX3dqRRxl+fRKtLhCEr0IvBfs0BBwxtKdaQujdnVn5c73v1Fgs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DS7PR12MB6309.namprd12.prod.outlook.com (2603:10b6:8:96::19) by PH0PR12MB5605.namprd12.prod.outlook.com (2603:10b6:510:129::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.22; Mon, 16 Jan 2023 05:38:33 +0000 Received: from DS7PR12MB6309.namprd12.prod.outlook.com ([fe80::8079:86db:f2e5:7700]) by DS7PR12MB6309.namprd12.prod.outlook.com ([fe80::8079:86db:f2e5:7700%6]) with mapi id 15.20.5986.018; Mon, 16 Jan 2023 05:38:33 +0000 Message-ID: Date: Mon, 16 Jan 2023 11:08:16 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v5] x86/sev: Add SEV-SNP guest feature negotiation support To: Zhi Wang Cc: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, dave.hansen@linux.intel.com, seanjc@google.com, pbonzini@redhat.com, thomas.lendacky@amd.com, michael.roth@amd.com, David Rientjes , stable@kernel.org References: <20230112084139.12615-1-nikunj@amd.com> <20230113135326.00006f06@gmail.com> Content-Language: en-US From: "Nikunj A. Dadhania" In-Reply-To: <20230113135326.00006f06@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MA1PR01CA0150.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::20) To DS7PR12MB6309.namprd12.prod.outlook.com (2603:10b6:8:96::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB6309:EE_|PH0PR12MB5605:EE_ X-MS-Office365-Filtering-Correlation-Id: b8adafc0-99c2-4fbe-304f-08daf783e7f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cftrSH1vnbRqCzMt7O0PQDbPO4w5Vj7BDBhaykBiLlacidAhJhvySkoj7uO5roBE281Ap2G2zb0MZdwulKybJtw/MojtwGsB4/vSaMqo7HHNkR4G5zGTeKRzavT4BaBWE9rT7u9vUF6fw/2dWMiGQbVIT8x3oxQ0QZtGjUqgsji0d9bh+6vLMzV9AzlndVCkyt8uWwWg5vIt+PehW812WuEV+RgLHhN7tg5bvlu7mIYXny4W4cRufPujQ9oz/KaGcPrxfygFR0vSiuajbs6hPyNYpcmthmqs4FQwciwLB4WcvUuh5L30X1LZeg4TT2CdONxdW61g6QdborQ7bu8/C2ioL8y1i5DB/Hq8KoMOOC337CPO5EBnFvaWFPccgClMDQF/K6pTb3qmLEy/+pyHWxEptP8Y7AMTPO3hjufhUxhwnVuERUQmq/w4VKN+af8ktA2sM9QKXEhOT4tkmQC/8uwgPSKUlbf2MX9G3WmYx22lqOpvXGY8ONCYSBWOwLcRQ3sI3TJYYtcExBj0m8aoyXBXYOTsNkk9m6ZNAQ0pSeljoDbL3hBtUtHMWVpYLQRYqyLFukIQCdQ4KkJAUFbWi1EiYMM1/8OJuWBSMHJpiXwd3Vwq3Gts4VQhV10Q2XybgaYD68wb9tk6yJwDPSocH+nC3/R7CaTXp1IKSYrfnvvF1KGNzKbDwY6KT0npTWupSaqwwr4sfm1L8cwF0p6ODJCv6T4oA3jbcXBSoKTdrqhdO7B6UGnakI47zguc8cm1f52a2R3kXOD8NbfUVCEDMLIK6MciZ0/SWh4VJgQ4O4Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB6309.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(136003)(396003)(346002)(39860400002)(376002)(451199015)(6666004)(478600001)(966005)(8676002)(6916009)(36756003)(4326008)(66476007)(66556008)(66946007)(41300700001)(316002)(6486002)(38100700002)(53546011)(2616005)(6506007)(55236004)(6512007)(31696002)(26005)(5660300002)(186003)(7416002)(31686004)(83380400001)(2906002)(8936002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?N0l1alMwRzVIa0thK2xDeG9CODdnZTZlVEY5dFVNRjR6S3daYkRIWjJhYmNt?= =?utf-8?B?RTJsZFlCRDhFcG9VQjBJTU5lQ0t5NVFjYlkyN0RYb3F6aDR5VngxNlZ5Tk5q?= =?utf-8?B?MUZWTXVXdnpDZFZ1dmNQcUlRY3JFd3dkMmszdzBPZUgwUWVIa21YclBaL25B?= =?utf-8?B?MXgxOEg5QnZEZ013QVdybXpNOHNDejF5SGJhTkMxOWlBSXY4VmE1OUFzYmFn?= =?utf-8?B?Q2VlQlhyWXRzbGpHUEFPcU8rczVTM2NPb0V5eHlOMktadjloZkNoTXhSVU82?= =?utf-8?B?dUU1ZGNFVXNGQytGSzhoS0NSZFNyL0x0UTNWa3d3RWZjY2pHMlNwc3hQNCtU?= =?utf-8?B?czFaMEl5cGowQlUwV0tiMHJuZjV3OEttVTRCN2twM2k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-99c2-4fbe-304f-08daf783e7f3 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB6309.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2023 05:38:33.4828 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zQFa82WNnROBxR45hRsqGJQEm66T8jpA1vv+94/hRb9Kp7O9sTrGy6g3Awwlrr+OeSvISTTUDZjRU1cr0LRMag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5605 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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 On 13/01/23 17:23, Zhi Wang wrote: > On Thu, 12 Jan 2023 14:11:39 +0530 > Nikunj A Dadhania wrote: > >> The hypervisor can enable various new features (SEV_FEATURES[1:63]) >> and start the SNP guest. Some of these features need guest side >> implementation. If any of these features are enabled without guest >> side implementation, the behavior of the SNP guest will be undefined. >> The SNP guest boot may fail in a non-obvious way making it difficult >> to debug. >> >> Instead of allowing the guest to continue and have it fail randomly >> later, detect this early and fail gracefully. >> >> SEV_STATUS MSR indicates features which the hypervisor has enabled. >> While booting, SNP guests should ascertain that all the enabled >> features have guest side implementation. In case any feature is not >> implemented in the guest, the guest terminates booting with GHCB >> protocol Non-Automatic Exit(NAE) termination request event[1]. Populate >> SW_EXITINFO2 with mask of unsupported features that the hypervisor >> can easily report to the user. >> >> More details in AMD64 APM[2] Vol 2: 15.34.10 SEV_STATUS MSR >> >> [1] https://developer.amd.com/wp-content/resources/56421.pdf >> 4.1.13 Termination Request >> >> [2] https://www.amd.com/system/files/TechDocs/40332_4.05.pdf >> > > The link of [2] is broken. Better update it. That is strange, I will fix that. >> + >> +void snp_check_features(void) >> +{ >> + u64 unsupported_features; >> + >> + if (!(sev_status & MSR_AMD64_SEV_SNP_ENABLED)) >> + return; >> + >> + /* >> + * Terminate the boot if hypervisor has enabled any feature >> + * lacking guest side implementation. >> + */ >> + unsupported_features = sev_status & SNP_FEATURES_IMPL_REQ & >> ~SNP_FEATURES_PRESENT; >> + if (unsupported_features) { >> + if (sev_es_get_ghcb_version() < 2 || >> + (!boot_ghcb && !early_setup_ghcb())) >> + sev_es_terminate(SEV_TERM_SET_GEN, >> GHCB_SNP_UNSUPPORTED); + > > === >> + u64 exit_info_1 = >> SVM_VMGEXIT_TERM_REASON(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); + >> + vc_ghcb_invalidate(boot_ghcb); >> + ghcb_set_sw_exit_code(boot_ghcb, >> SVM_VMGEXIT_TERM_REQUEST); >> + ghcb_set_sw_exit_info_1(boot_ghcb, exit_info_1); >> + ghcb_set_sw_exit_info_2(boot_ghcb, >> unsupported_features); + >> + sev_es_wr_ghcb_msr(__pa(boot_ghcb)); >> + VMGEXIT(); >> + >> + while (true) >> + asm volatile("hlt\n" : : : "memory"); > === > > This seems another approach to terminate the guest which can bring extra > reason info compared to sev_es_terminate(). It would be better to wrap > the above snippet into a function and call it here. Right, I will add it as part of the new function in my next revision: static void __noreturn sev_es_ghcb_terminate(struct ghcb *ghcb, u64 exit_info_1, u64 exit_info_2) Regards Nikunj