From patchwork Thu Jun 15 06:37:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 108277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp436595vqr; Wed, 14 Jun 2023 23:51:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jeCTUNaRENN+SQ+2sOEa17p80ijE9uocK0fUW3NLQiGbFMwyFkqRvj9pEeNXnjE9lcMNU X-Received: by 2002:aa7:c516:0:b0:51a:2db1:3ddd with SMTP id o22-20020aa7c516000000b0051a2db13dddmr33681edq.31.1686811891639; Wed, 14 Jun 2023 23:51:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686811891; cv=pass; d=google.com; s=arc-20160816; b=QxqaQVKCWGmoL+Oy2JBaV/zxHbeT7mO5t4NY4jTlcRErvVlHil5mPhvVwHaFRYC1Vy xtR6pzYuDtPdsIZru9UnwWG6PBhyQiUQsaOXqTYk+jAcIqPhROWlENQpW1EflTQYZ8hY 9ZHt3JZBjz1NSFemfuM7Yg4CNJMrq5kiTNs3RGuyDH/syC+JkX/cDEZimJx3sERW1HTU s4PknpBMkjta8Vwujpstx0A00Brl1qGxhduEW5aKnqX8EB/ryjPzJ+LB/KCz/rbjO/I8 nn1CvoAN2K7PXHI14KOSc0qjEb6sZkda/hPYbsdxumWQCuETArd2z8flS+9XBi99BJot H0zQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BU8usJu9FWlNapYkideYsZqh/0lbBgQTMVI09v776vM=; b=VYGNxDD34H4E/G5RJG598kSbINeOiHJF9sk9x0IiMbBHrGVEh/Btuf0NdD6Ky93HGw ybxScX5QefnQQ6xaBh7JegKSNzMquO9++cONqPosnlz3xMpg/3Z4Zo39Ld9fv5CSg5my 3nTsd1ML5eTGVnqg6wvSgZroC9ey48dh9r1epAJQj6RSLyS59+43oWdh5ltyAHDweeKd OEtS6uYpw1Q+yUhoEpweuMHdVDreDhpbNXIWI4PZKrtiHZ7nJYwbUD9rQ2vecpsgnETv FeAHRf7jxN6sBWvnb1iO3HbjtoMJv3GucCDCjowcDHJMyU7P0Wgv0X8AaCP4YMv2Q1jI bNNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=CsccAJ84; 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 e12-20020a50ec8c000000b00516b291217fsi9584307edr.0.2023.06.14.23.51.05; Wed, 14 Jun 2023 23:51:31 -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=CsccAJ84; 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 S244352AbjFOGsG (ORCPT + 99 others); Thu, 15 Jun 2023 02:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243833AbjFOGr1 (ORCPT ); Thu, 15 Jun 2023 02:47:27 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2058.outbound.protection.outlook.com [40.107.92.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F07652D73; Wed, 14 Jun 2023 23:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J+eGVH8AKE2F4zQrZsE6YVis1zrKs741KNUWPUEyq8j6bLjFXZIkD3Cc2x/ZrlJYPcX4kk1hxc820MWuLYhs2v6JNi3UrEvlpaX1sf3FW6ADsxVx1TPC9ga/xSXZgN50+nkmgLaGxdodGI9ewAkVHvsItRLDk3/arkbTYqjAdEnzswD4dMuO+CIX1LcIKH9Iw78V6dLa2HUKFR2ofaQzwmQPE/TvRXHmBI19JEw0BlRjZ5/cg7peCRbCrPm/VKf3mVlxB3yjjedPbwCIEEanIwnfvdsFX4Kde+8d00D32uFx6QGh4sfhJwk+uZhoTG0juf7+Fp0gcFbkQfpVlwHqFA== 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=BU8usJu9FWlNapYkideYsZqh/0lbBgQTMVI09v776vM=; b=OZ/9Lf/Bh4aY1MYHOj28Cz8Pb471ARDyrv5eFPu+MxbqCCmqTu3F8EGyptGPffuuDUMaLJ+Q/HG8477tLfuflgpvtJJbaOFritYFj6dvSX0ywyt7rKt5/v/Vqo6atSUs9bwE7vro1RC9jRsKpGX/usa95xEg62K/ISCx7qDLKbRfWKhbq/w7s95tZf0khlag1RnTk+8rJKIWOEuqyOVrS+kuzXdxeTyiX0Qw8CYmgfSAilh+ICYjYoBzHXA9Laone+98Prd99UyIqeLTwZSetq5yOFQSEHqQcT8AfUfSzdjIZjZmvKi0Sf5ul5icwrah7Da3lRAsWSuh9mKYCFwbMA== 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=BU8usJu9FWlNapYkideYsZqh/0lbBgQTMVI09v776vM=; b=CsccAJ84eIYBvbGdcm2md5XOnYNaPPbB5rxKpi3YVz5ydPReJ8/gF+/C3Y2Bj9KymaDIxec5vZ8MWImM6SBMa2fF7R/A7qSjiVrPhh2TtLzyoAoc4hnQkIdsxMaO177ySKkE9wciyE9i5li3MxMIYIPLEuVNWW3H/Qk04aYj+fg= Received: from PH8PR07CA0004.namprd07.prod.outlook.com (2603:10b6:510:2cd::13) by DM4PR12MB6397.namprd12.prod.outlook.com (2603:10b6:8:b4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.25; Thu, 15 Jun 2023 06:45:54 +0000 Received: from SN1PEPF000252A1.namprd05.prod.outlook.com (2603:10b6:510:2cd:cafe::57) by PH8PR07CA0004.outlook.office365.com (2603:10b6:510:2cd::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37 via Frontend Transport; Thu, 15 Jun 2023 06:45:54 +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 SN1PEPF000252A1.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.27 via Frontend Transport; Thu, 15 Jun 2023 06:45:54 +0000 Received: from aiemdeew.1.ozlabs.ru (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.2507.23; Thu, 15 Jun 2023 01:45:50 -0500 From: Alexey Kardashevskiy To: CC: , , Tom Lendacky , Sean Christopherson , "Alexey Kardashevskiy" Subject: [PATCH kernel 9/9] KVM: SVM: Don't try to pointlessly single-step SEV-ES guests for NMI window Date: Thu, 15 Jun 2023 16:37:57 +1000 Message-ID: <20230615063757.3039121-10-aik@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230615063757.3039121-1-aik@amd.com> References: <20230615063757.3039121-1-aik@amd.com> MIME-Version: 1.0 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: SN1PEPF000252A1:EE_|DM4PR12MB6397:EE_ X-MS-Office365-Filtering-Correlation-Id: 37b20135-383b-40aa-e660-08db6d6c2ab4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wdbAKxL95S0WRAWLCF/G6GtFVaAs39K1D4rTp9zNFuslMq0C+xMDqlAtuvX/T4HhNvoxDuXX9c+uIfx7lYSh16mFmkUD66vJX1pv/WjOGVYpfdyFjKUgqWRFasQy4Of1aQdfjZlpr3L7cAXx5wnRroTDc0jvEMD5Ua4X3L6OJdNefgKgbIqONo4wkMKRxCODDrByag9JaN/lASbIV39Y9b2IBsoB+7SWFrmwcJy34Hz+7BxoTdBKgwrI85DPvE60qIJpPtVgfF9RROuPLNtCOeYZCUXarimueEXxqcLNvqVz8K9StqtIZ47B0mfXLNlgW6nmsHtN9n1I7nhubEjHkZzPB94x4odio87yirjc5/wnPR9IDQXtPBezETozEDjuhedl2XRdEh8dg0H8coZr2abv+Q5cAVQ/CqZN1W7PGd1a7NjlZ6giNX/mt7hQp1UXI0Zjlf3mdNKwMjjIOVWstNumh71y3ki3lPngP7HPq1ZkLyZnRQYld+NEZ4GKC7Vpouq/fqJB0GVLXWN8lnsLqTmkZLL8Jrxp5MGtlS0pa+vY25BHsTHo04NGMambr5+FVXoOc9fAxlaAnRRPAJpX33Bu/AJNCocaOdsY6V1FLPQpoyUHGAW1XaF2uW3Ii5PwsnBmIzCh8r4hu2Q+3kkwDQq+HOYviTtDxGjhzaGJXB44Yhxv2WxxdiXeASs59DcbYu1CtdKnVlWGT9BQTo4xVPqdqDL5IZOJThfS34Fgo9NAkmHgHQUINgdiDJVQ+XLM2DS4s86W+crjSkw0h7xHuQ== 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)(39860400002)(376002)(136003)(396003)(346002)(451199021)(46966006)(36840700001)(40470700004)(1076003)(26005)(478600001)(16526019)(36756003)(186003)(40480700001)(40460700003)(2906002)(316002)(41300700001)(356005)(82310400005)(81166007)(5660300002)(8936002)(8676002)(82740400003)(336012)(426003)(54906003)(83380400001)(47076005)(2616005)(6916009)(70586007)(70206006)(4326008)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2023 06:45:54.2826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37b20135-383b-40aa-e660-08db6d6c2ab4 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: SN1PEPF000252A1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6397 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768750466149309336?= X-GMAIL-MSGID: =?utf-8?q?1768750466149309336?= From: Sean Christopherson Bail early from svm_enable_nmi_window() for SEV-ES guests without trying to enable single-step of the guest, as single-stepping an SEV-ES guest is impossible and the guest is responsible for *telling* KVM when it is ready for an new NMI to be injected. Functionally, setting TF and RF in svm->vmcb->save.rflags is benign as the field is ignored by hardware, but it's all kinds of confusing. Signed-off-by: Sean Christopherson [aik: removed the clause about "KVM suppresses EFER.SVME (see efer_trap())"] Signed-off-by: Alexey Kardashevskiy --- Changes: v6: * new to the series --- arch/x86/kvm/svm/svm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 52f1d88e82a0..c9837a8667b7 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3824,6 +3824,19 @@ static void svm_enable_nmi_window(struct kvm_vcpu *vcpu) if (svm_get_nmi_mask(vcpu) && !svm->awaiting_iret_completion) return; /* IRET will cause a vm exit */ + /* + * SEV-ES guests are responsible for signaling when a vCPU is ready to + * receive a new NMI, as SEV-ES guests can't be single-stepped, i.e. + * KVM can't intercept and single-step IRET to detect when NMIs are + * unblocked (architecturally speaking). See SVM_VMGEXIT_NMI_COMPLETE. + * + * Note, GIF is guaranteed to be '1' for SEV-ES guests as hardware + * ignores SEV-ES guest writes to EFER.SVME *and* CLGI/STGI are not + * supported NAEs in the GHCB protocol. + */ + if (sev_es_guest(vcpu->kvm)) + return; + if (!gif_set(svm)) { if (vgif) svm_set_intercept(svm, INTERCEPT_STGI);