Message ID | 20230524155619.415961-1-john.allen@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp30378vqr; Wed, 24 May 2023 09:25:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7OxQQK0pSOxVk5t4v8TUf/f+AiXORbHCDhkGFBNyb5M9rmK3t/zyN00arYcmBpndNPjPkc X-Received: by 2002:a17:90b:3787:b0:253:8a50:1bcb with SMTP id mz7-20020a17090b378700b002538a501bcbmr16317841pjb.25.1684945505576; Wed, 24 May 2023 09:25:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684945505; cv=pass; d=google.com; s=arc-20160816; b=IrbhRdvG6aL6k9nrnamJ9nlducwA2xH+IN+XGJkPlCgF1001qsDRc/IoNbP8B6jGkP aJJZ6WbqKTqAR9hCVWhUWjcUureipRGtUz4vlB+GrwQQVWYQ16MqimVljqysz20YFvx5 Fu+Rhytfq3EnvMJ51+jmcE9NS1VUncHjfqlvQ0QrPb6hcLeaotc+GR/P6ARaOeFFSRBA IqUnwjbG6a7g4QKb7u+t8pL1uv5TMBTm5yxdR9VEjIF7GU/qVVMaW5G/fyeeWJaM3Ptq OkfjH/kwa9W+kFWhu2muTU+3HQh1h21bezpYqu2xh9mIyC31x8c3s/uFxRaoQo0IFwVT nWCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ks+UuaSv5KNQnArNIVH0E99Z78VHH3K53r/X3CDMvc0=; b=DJTAXas5hgYyWnaCkaPhSZ79uhtIv1SNcoMATlC8HgjbLuEd4n6GbxSmBiYrCtomv1 V1lq21S+y5D0fgadxNrwNxYIMTqZczcGBI0/08w/Pr5QCVZ5G7oHXuXplrHq4qg4sWVC keNjfl2qXmzM6hCtHtaKBhASUC55tAS7t1WMlbOEyXo7DysUL41+RLpK1XKM1YV0n8+0 PkqBeZuOkdGv9tulj2IQjxrI2LVH2j6SVNOifxmO6y3GHhDgKnUCb6FC6tiOW6S8amWP BMhRn+b+I3pOyKA8xgmZh/XvYkEOKlR/zKVAZ9/XBMbMXOdUCJwtTqWT3wgDCzmKGqDL eNiA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tNT6oXRQ; arc=pass (i=1 spf=pass spfdomain=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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020a17090ad50400b002477dac5834si1665217pju.95.2023.05.24.09.24.52; Wed, 24 May 2023 09:25:05 -0700 (PDT) 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=tNT6oXRQ; arc=pass (i=1 spf=pass spfdomain=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 S238102AbjEXP66 (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Wed, 24 May 2023 11:58:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236316AbjEXP6Z (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 24 May 2023 11:58:25 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2063.outbound.protection.outlook.com [40.107.212.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC13E6E; Wed, 24 May 2023 08:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oaJG0/+tXqStc4XF5mKfuzLluMkgKkLaaaucUHG/0G1BOlaVr+kfeom21TH9rjd/Y04eTJdxKTM3vHxrjK6DhAU16HIctAtq1BnUA9ZTiZT4wEM6q3USUnpzPWZ+V0wYe/gkaYuz0GHvwmfDHlCcvvqXHHwUl+u7vStL5/G+gto76YDY9GJAW4YCB+E5EvCEMnCQX782pX69455eBVvTIDUgvdOqaE3k57Fp3o5jkiEIPnwrkLUdSZtcBTZNmdg+OfgpXou7tNfY0UKzSjNwRG/yeqbd5q8TSERIEhI7KM/0wkkYErDL865sqWLPBWer024z1sySAjWdP/2otW7DEQ== 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=Ks+UuaSv5KNQnArNIVH0E99Z78VHH3K53r/X3CDMvc0=; b=DzmsBy771kUriH2DZxjzpfd6K70jHuSsL0/G1CAEu/7/PZdQIBGD4iU43/rUHFtel49OQICedzJTPCU8c5+zyJBrq053xHgi3vhAQYyW2ykz3ChNnuu+bIdmUiv8r8VOWEBSnEifoS1XoTOXi8PNP9zrIkh7VP6IZQeLzZ7Vuv6tjqSQSECRZXF/RDvGTRrThnkX5/PijOiaqoD2t0i4iPpgxkVDCabmH79OR36R7h3PiY/z9kHN1knveIhDe7ggQp7UoMWQyPxl9LuFMlvjQDVpBadSUFcIabik/tlP5gIMK/svpm6w1zg7xRWuCK7eVEWJLHro5PjvKI5Q6Y5SiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=Ks+UuaSv5KNQnArNIVH0E99Z78VHH3K53r/X3CDMvc0=; b=tNT6oXRQRyQwCyF4aUktcH/4vfi+U1WHnubisP1rDWbB5oDEvYHt8CC7xPa6NKzduDXdVnVBiwaG9rq9uu+atSuIniIGY0iFsmarMySp81NRBpLgwdOQcvUcBiEkv7cXo93MZA3FbEl6HAVtiGzhzNnhnlstbnsyLdKicKgKQPE= Received: from DM6PR02CA0054.namprd02.prod.outlook.com (2603:10b6:5:177::31) by DM4PR12MB6279.namprd12.prod.outlook.com (2603:10b6:8:a3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.28; Wed, 24 May 2023 15:56:49 +0000 Received: from DM6NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:5:177:cafe::de) by DM6PR02CA0054.outlook.office365.com (2603:10b6:5:177::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.29 via Frontend Transport; Wed, 24 May 2023 15:56:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT064.mail.protection.outlook.com (10.13.172.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.30 via Frontend Transport; Wed, 24 May 2023 15:56:49 +0000 Received: from jallen-jump-host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 24 May 2023 10:56:44 -0500 From: John Allen <john.allen@amd.com> To: <kvm@vger.kernel.org> CC: <linux-kernel@vger.kernel.org>, <pbonzini@redhat.com>, <weijiang.yang@intel.com>, <rick.p.edgecombe@intel.com>, <seanjc@google.com>, <x86@kernel.org>, <thomas.lendacky@amd.com>, <bp@alien8.de>, John Allen <john.allen@amd.com> Subject: [RFC PATCH v2] x86/sev-es: Include XSS value in GHCB CPUID request Date: Wed, 24 May 2023 15:56:19 +0000 Message-ID: <20230524155619.415961-1-john.allen@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT064:EE_|DM4PR12MB6279:EE_ X-MS-Office365-Filtering-Correlation-Id: 41250b9d-e6ec-4a34-d076-08db5c6f7c13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 51d4D6CjgREMNgnFPzhqTpdBzsxCUAI4bf1RFq1D5H/oOj5PdGSiFFIxkZ1h4N6XJEcmdys2IKLMSDLi7n+2n0M16f+WoHztQthZDzuytiDaawa8VcSCdVsjLP5oNK9jDStd9NiWcNzaB+fEzE0ukGhhjeOsCwBxGx3/SUVlpPgIuWeY2hqHQRJskIszT+C59iEvUksDwLP/DkZK0gubaMYpdcD7CLiAQj7Vbt4L2Iyow4V+3PyyY1EHLIbLbNd0mJfjFkQFIN6hZJE8fj8VJDW5xBLKL44Irq1ZqSm8EzCbLKsAIokCIrK71KhoTdzWMxdBTveSLYWG0jgs9oKg37rYxhKhalAPkN+ifBQcFJaKQQRbg7/X7unguKU0WFKP3PnGxFdgP7ZmxWLJeFGGMRo0+bu5UYZGjxJOL379M4HXUSaPFffXz248p4EO7GXp1bM+BlzyyNC0rr6DXnUu5eb02xmj4anjJxWAUyrUQ6GXr9ldosAJ37WeKzTSqgHM+HizRNvPLD9dN9/WLwQsMUub7bGXS9rDSSnlPBSpP6IYpq6mrowizsz67pq9eQFkiFh9NIM+V1ipw+hiqTQ6/d0RZVzcOFVcfa0y8KuenfQUkNj0IuzbMkIxagnzZPKq4DYFoMF4UF7UEWDCwns9kyhPGaNQDLe/iX5pFMBqAKnFGZGT9tF/NSN+q6d2ZuIkpLoYiTwqoSg/FKmp+CS8QZ433ZR70sugFfekNac5RpO9PYtoGOUjze8nXK6yuBZ5I1q1upmFcHnT7wo7791fmQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(376002)(39860400002)(396003)(451199021)(36840700001)(46966006)(40470700004)(54906003)(7696005)(41300700001)(82310400005)(316002)(6666004)(70206006)(4326008)(6916009)(70586007)(8936002)(5660300002)(8676002)(478600001)(86362001)(44832011)(82740400003)(40460700003)(356005)(81166007)(26005)(1076003)(186003)(16526019)(40480700001)(2906002)(2616005)(36756003)(83380400001)(426003)(36860700001)(336012)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2023 15:56:49.4918 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41250b9d-e6ec-4a34-d076-08db5c6f7c13 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6279 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,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, T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766793418263331177?= X-GMAIL-MSGID: =?utf-8?q?1766793418263331177?= |
Series |
[RFC,v2] x86/sev-es: Include XSS value in GHCB CPUID request
|
|
Commit Message
John Allen
May 24, 2023, 3:56 p.m. UTC
When a guest issues a cpuid instruction for Fn0000000D_x0B (CetUserOffset), the
hypervisor may intercept and access the guest XSS value. For SEV-ES, this is
encrypted and needs to be included in the GHCB to be visible to the hypervisor.
The rdmsr instruction needs to be called directly as the code may be used in
early boot in which case the rdmsr wrappers should be avoided as they are
incompatible with the decompression boot phase.
Signed-off-by: John Allen <john.allen@amd.com>
---
v2:
- Do not expose XSS state for ECX > 1
- Direct MSR read was left as is for now. Using __rdmsr produces a warning
during kernel build as the __ex_table section used by __rdmsr isn't used
during decompression boot. Additionally, we can see other code
performing a similar direct msr read in this file in commit
ee0bfa08a3453.
---
arch/x86/kernel/sev-shared.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
Comments
On Wed, May 24, 2023 at 03:56:19PM +0000, John Allen wrote: > + if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx <= 1) { > + unsigned long lo, hi; > + u64 xss; > + > + /* > + * Since vc_handle_cpuid may be used during early boot, the > + * rdmsr wrappers are incompatible and should not be used. > + * Invoke the instruction directly. > + */ > + asm volatile("rdmsr" : "=a" (lo), "=d" (hi) > + : "c" (MSR_IA32_XSS)); > + xss = (hi << 32) | lo; > + ghcb_set_xss(ghcb, xss); $ git grep ghcb_set_xss $ So this patch needs some tree which I'm not aware of. Also, this passing through of host XSS to the guest looks like it is bypassing the vcpu->arch.ia32_xss copy which KVM seems to maintain. It looks to me like the handling needs to be synchronized with it or so. Thx.
On Thu, Jun 15, 2023 at 01:52:55PM +0200, Borislav Petkov wrote: > On Wed, May 24, 2023 at 03:56:19PM +0000, John Allen wrote: > > + if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx <= 1) { > > + unsigned long lo, hi; > > + u64 xss; > > + > > + /* > > + * Since vc_handle_cpuid may be used during early boot, the > > + * rdmsr wrappers are incompatible and should not be used. > > + * Invoke the instruction directly. > > + */ > > + asm volatile("rdmsr" : "=a" (lo), "=d" (hi) > > + : "c" (MSR_IA32_XSS)); > > + xss = (hi << 32) | lo; > > + ghcb_set_xss(ghcb, xss); > > $ git grep ghcb_set_xss > $ > > So this patch needs some tree which I'm not aware of. > > Also, this passing through of host XSS to the guest looks like it is > bypassing the vcpu->arch.ia32_xss copy which KVM seems to maintain. It > looks to me like the handling needs to be synchronized with it or so. Hi Boris, Yeah, sorry, this is confusing. This patch is logically part of the SVM shadow stack support series: https://lore.kernel.org/all/20230524155339.415820-1-john.allen@amd.com/ Since this patch is for the guest kernel, it is meant for the tip tree rather than the kvm tree so I sent it as a separate patch. However, as you noted, this patch depends on patch 5/6 of that series to introduce the ghcb_set_xss function. How would you advise that I handle this entanglement in the next series? Thanks, John
On Thu, Jun 15, 2023 at 10:23:01AM -0500, John Allen wrote: > How would you advise that I handle this entanglement in the next > series? Send the *whole* and complete set to both maintainers - KVM and tip - and they'll decide how to do the patch tetris. Thx.
On Thu, Jun 15, 2023 at 05:30:51PM +0200, Borislav Petkov wrote: > On Thu, Jun 15, 2023 at 10:23:01AM -0500, John Allen wrote: > > How would you advise that I handle this entanglement in the next > > series? > > Send the *whole* and complete set to both maintainers - KVM and tip > - and they'll decide how to do the patch tetris. Thanks Boris. Sounds good to me. Thanks, John
diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 3a5b0c9c4fcc..fc4109cc2e67 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -887,6 +887,21 @@ static enum es_result vc_handle_cpuid(struct ghcb *ghcb, /* xgetbv will cause #GP - use reset value for xcr0 */ ghcb_set_xcr0(ghcb, 1); + if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx <= 1) { + unsigned long lo, hi; + u64 xss; + + /* + * Since vc_handle_cpuid may be used during early boot, the + * rdmsr wrappers are incompatible and should not be used. + * Invoke the instruction directly. + */ + asm volatile("rdmsr" : "=a" (lo), "=d" (hi) + : "c" (MSR_IA32_XSS)); + xss = (hi << 32) | lo; + ghcb_set_xss(ghcb, xss); + } + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0); if (ret != ES_OK) return ret;