From patchwork Tue Sep 15 21:29:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 11777871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 739C859D for ; Tue, 15 Sep 2020 21:34:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 28BB120731 for ; Tue, 15 Sep 2020 21:34:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="lO8L1F44" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28BB120731 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIIbK-0005kS-Bq for patchwork-qemu-devel@patchwork.kernel.org; Tue, 15 Sep 2020 17:34:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIIXM-0001oH-VX for qemu-devel@nongnu.org; Tue, 15 Sep 2020 17:30:53 -0400 Received: from mail-dm6nam10on2054.outbound.protection.outlook.com ([40.107.93.54]:28256 helo=NAM10-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIIXL-0002jx-Dm for qemu-devel@nongnu.org; Tue, 15 Sep 2020 17:30:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ql1yOt/1sjhmOsDzx40ItUm+M0OydLFK446qUaZDraTcRuusQ0ac/Z207poV8ERodka2AHXbLkTrNKUIuPNNYBmepjzTBDcf7FT/Dn1/TUdu6wobue5IzVHyrhRyj0wXLtJuwsjXW0Us8rrIblbk3QloQzWPAz2CiMK4ZgEuMvIcV46/rwX74iRnyNylRmQCDLfgBq8eWm3oPyVTVATr28P2+9taw80i4yzxtIQuSrkMoPI5kJZSXzBDLGI+l/YZEGln/3Ity7bPxGQIS1MYqVKO7d+nVYM5lB7UmfuATb9dm6pSwjxUwi2Ion5+IWgqEMhhtxQS4qWwnz0ek5iUtw== 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-SenderADCheck; bh=bXF8fTPJ/Y9pFcClOLMeQ5tenPBU4qylEmby8f9sbW8=; b=iZF7Z6ya9RARFt6c2+rWsAVvnHhbindfxsWuOA8KGAIb2uMy+dISq4uj7QafZBDa+kRD81oEOC997lM3FY3ZNJSYkYS88EiwjlV1Y2CBwsWhm4pz98dpIvu5WV13OfOUa3UymiN3/TKBAmrApkXj3i2ONfXwzRjOCn7SSdIMugPwbWEGDBDK0mBjjGc8uftpDCedkO9ukXB8Z4zJuJgdjpRgM0ajlgrua1V8xE1/HWu/jB69hWVJi1xYhP7oMnLcrjUNUlcMzIiVvBQFeBeV4SHSch2QVS7OzXDaJ21gIi+aoRw5GVOI/CBs8t0D4+4Teb9HaO3skhdfaxuNBwOxhA== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bXF8fTPJ/Y9pFcClOLMeQ5tenPBU4qylEmby8f9sbW8=; b=lO8L1F44dYbQrV5PRYOwpt2OOEg9EvFfRa1pUHqqwt3blSFWJs3Gwnp9j4ExpUD6QIIYBduQdOurDxCio13ZnLyK1BX54JF8K94bGJTeOi8aCQWDS9NF4HsEarA3w247PIVFAW9yD33NZz2x/yuhHlAd0H8BpFJX0NF623fP1wI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1607.namprd12.prod.outlook.com (2603:10b6:910:b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Tue, 15 Sep 2020 21:30:34 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::989b:b1b2:464c:443]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::989b:b1b2:464c:443%10]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 21:30:33 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v3 4/5] sev/i386: Don't allow a system reset under an SEV-ES guest Date: Tue, 15 Sep 2020 16:29:43 -0500 Message-Id: <058dcb33a9cc223e3180133d29e7a92bfdc40938.1600205384.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR21CA0024.namprd21.prod.outlook.com (2603:10b6:5:174::34) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR21CA0024.namprd21.prod.outlook.com (2603:10b6:5:174::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.1 via Frontend Transport; Tue, 15 Sep 2020 21:30:32 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 400fbeb3-719d-495c-c1e2-08d859be9416 X-MS-TrafficTypeDiagnostic: CY4PR12MB1607: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:418; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wl4pLzrUN4iZXeFltD1AXlkTQIP2YIoKC3AlR2md2CKgbFj5DLDxc1fdWgkEZqsjxPQ0r/bd9yQgB0JK1yDi8Um2q1N7hlWlcOiEaptQoSaxNyoJ12DCMQDvpmcZmcgzuZSij+PfhLfLXX1IGAmjLJ3FEDkO/sXZZlvBKTIT7elJMsXVjTRKC6nueba9ORa2Sk0N1XlRvC7TPuwKgyZALRyimAkx0dkLjP4cM1GPQEH2vtzXqSxoBIMRjGdb4tvp45PScqRlFh/2JSB6pBras7ZwFBNBaizyI+UZc9HD5IF3KKIlczXds0TRKBU8G9CL X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY4PR12MB1352.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(366004)(346002)(136003)(39860400002)(376002)(5660300002)(956004)(478600001)(6666004)(86362001)(52116002)(2616005)(2906002)(7696005)(36756003)(66476007)(8936002)(66556008)(66946007)(316002)(54906003)(7416002)(26005)(6486002)(4326008)(8676002)(16526019)(83380400001)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: FcvrEI1uBWjZuelOaGS5d/PHx83Yo/QJwB+ZchJEm/cEab7qQ0m+mjp6JosobUENkRYbXIJdrwquCE+yPHeBTqxq19V6riVVorC9hOo+cJSh10mgANqCVB6+BEkvDijv9+q6XvJDmBGE1BN7jquFFHeV1r9imNwqof7/9k/kNIaTsEST0Km+WHKIxGqV58ElEVJIDykgf9/DuTXkKjTY9nZhn88UgTjBxxJABpl0IOFTCuow2GdFAdOAxSbpPViDCKsfaY/mQ8w0NKPAms/m+bD0lvYze+2HuT9pDmJtQkSNDDyemujW6wATs49hDQ/mCtxcDfKDa4UmRSSQN8VIEDdUyYWH0dLgkTN7Z6aO0gSgwV0yOGPuiYmBS2dJBs+2ZF2W8LzaglTs8Wyse1GCd1Ir+Ie4lwDS49NARIeYoqWRAtvo+qD6gMkCn0h4iXSQKzv7kcJdGnyUFIqjz+hNYA61MG6hLxMk73J6Vv+puFdhuuWGEI3tO1mD5lVlq9Xgd31AozgK2TZVQF11QKpmpGi6+gs6/fF1VShA/eYqMZD/mZ6x4DclorktScIauojO1paCdVWkG2NHpBQZVE5pJa6DriXbQzXkd9uRlfi5p/Em7XnZV1opqT5XPe0gxIcQF+lcW7NC0YCSyUztiQwDIA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 400fbeb3-719d-495c-c1e2-08d859be9416 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 21:30:33.8331 (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: OhCEAdmp/u4ySPQ7QKhb7acffs4LNH8mYN9mcjUU6GNGf9983RVbuwX3rhXhmY64JEe1UQTelEuc49+kpjmA6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1607 Received-SPF: none client-ip=40.107.93.54; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 17:30:43 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FORGED_SPF_HELO=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Connor Kuehl , Marcelo Tosatti , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky An SEV-ES guest does not allow register state to be altered once it has been measured. When a SEV-ES guest issues a reboot command, Qemu will reset the vCPU state and resume the guest. This will cause failures under SEV-ES, so prevent that from occurring. Signed-off-by: Tom Lendacky --- accel/kvm/kvm-all.c | 9 +++++++++ include/sysemu/cpus.h | 2 ++ include/sysemu/hw_accel.h | 5 +++++ include/sysemu/kvm.h | 2 ++ softmmu/cpus.c | 5 +++++ softmmu/vl.c | 5 ++++- 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 20725b0368..63153b6e53 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2388,6 +2388,15 @@ void kvm_flush_coalesced_mmio_buffer(void) s->coalesced_flush_in_progress = false; } +bool kvm_cpu_check_resettable(void) +{ + /* + * If we have a valid reset vector override, then SEV-ES is active + * and the CPU can't be reset. + */ + return !kvm_state->reset_valid; +} + static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg) { if (!cpu->vcpu_dirty) { diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index 3c1da6a018..6d688c757f 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -24,6 +24,8 @@ void dump_drift_info(void); void qemu_cpu_kick_self(void); void qemu_timer_notify_cb(void *opaque, QEMUClockType type); +bool cpu_is_resettable(void); + void cpu_synchronize_all_states(void); void cpu_synchronize_all_post_reset(void); void cpu_synchronize_all_post_init(void); diff --git a/include/sysemu/hw_accel.h b/include/sysemu/hw_accel.h index e128f8b06b..8b4536e7ae 100644 --- a/include/sysemu/hw_accel.h +++ b/include/sysemu/hw_accel.h @@ -17,6 +17,11 @@ #include "sysemu/hvf.h" #include "sysemu/whpx.h" +static inline bool cpu_check_resettable(void) +{ + return kvm_enabled() ? kvm_cpu_check_resettable() : true; +} + static inline void cpu_synchronize_state(CPUState *cpu) { if (kvm_enabled()) { diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index f74cfa85ab..eb94bbbff9 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -494,6 +494,8 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr, #endif /* NEED_CPU_H */ +bool kvm_cpu_check_resettable(void); + void kvm_cpu_synchronize_state(CPUState *cpu); void kvm_cpu_synchronize_post_reset(CPUState *cpu); void kvm_cpu_synchronize_post_init(CPUState *cpu); diff --git a/softmmu/cpus.c b/softmmu/cpus.c index a802e899ab..32f286643f 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -927,6 +927,11 @@ void hw_error(const char *fmt, ...) abort(); } +bool cpu_is_resettable(void) +{ + return cpu_check_resettable(); +} + void cpu_synchronize_all_states(void) { CPUState *cpu; diff --git a/softmmu/vl.c b/softmmu/vl.c index 4eb9d1f7fd..422fbb1650 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1475,7 +1475,10 @@ void qemu_system_guest_crashloaded(GuestPanicInformation *info) void qemu_system_reset_request(ShutdownCause reason) { - if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { + if (!cpu_is_resettable()) { + error_report("cpus are not resettable, terminating"); + shutdown_requested = reason; + } else if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { shutdown_requested = reason; } else { reset_requested = reason;