From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D471FC2BBD1 for ; Thu, 17 Sep 2020 17:02:52 +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 5E61F206A2 for ; Thu, 17 Sep 2020 17:02:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ez/sMK6M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E61F206A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIxJ5-0004iv-Ey for qemu-devel@archiver.kernel.org; Thu, 17 Sep 2020 13:02:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIxHs-0003hz-0s for qemu-devel@nongnu.org; Thu, 17 Sep 2020 13:01:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIxHp-0005Pp-DV for qemu-devel@nongnu.org; Thu, 17 Sep 2020 13:01:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600362092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AOcg7erdQiG6t1re3jBjRLL6u+BC9P88PDt8o+CU52k=; b=ez/sMK6MBIRNC4TbsSwUqlbi9k4T8zFbfaYnGVqDVLMcH1JEsC1dC6XybtO0VZkjmJam54 qrQTYXCMy2Bq5nlxyMfzFunxe1i5JcWqWcU8cIK+MNULDfFUs/GW6HkcT7B/j09Dnm4+z5 k036HCaHAwE3XigljIQLjAPZjc8uRpk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-etVH8VP5NKa1lqdHXXr32w-1; Thu, 17 Sep 2020 13:01:30 -0400 X-MC-Unique: etVH8VP5NKa1lqdHXXr32w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 618EF800467; Thu, 17 Sep 2020 17:01:28 +0000 (UTC) Received: from work-vm (ovpn-114-108.ams2.redhat.com [10.36.114.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9306078803; Thu, 17 Sep 2020 17:01:22 +0000 (UTC) Date: Thu, 17 Sep 2020 18:01:19 +0100 From: "Dr. David Alan Gilbert" To: Tom Lendacky Subject: Re: [PATCH v3 4/5] sev/i386: Don't allow a system reset under an SEV-ES guest Message-ID: <20200917170119.GR2793@work-vm> References: <058dcb33a9cc223e3180133d29e7a92bfdc40938.1600205384.git.thomas.lendacky@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <058dcb33a9cc223e3180133d29e7a92bfdc40938.1600205384.git.thomas.lendacky@amd.com> User-Agent: Mutt/1.14.6 (2020-07-11) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/17 02:01:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.997, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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 , kvm@vger.kernel.org, "Michael S. Tsirkin" , Connor Kuehl , Marcelo Tosatti , qemu-devel@nongnu.org, Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" * Tom Lendacky (thomas.lendacky@amd.com) wrote: > 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; This seems a bit weird since it's in generic rather than x86 specific code. Dave > +} > + > 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; > -- > 2.28.0 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK