Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp11409pxv; Thu, 24 Jun 2021 01:22:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKLdJfWD/65spgqaqk+sGdxHlahQpkjgxqp9wUQsySDK0LhzMI7nFHX1AYujbydSdliltg X-Received: by 2002:aa7:c5d7:: with SMTP id h23mr5565786eds.305.1624522971673; Thu, 24 Jun 2021 01:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624522971; cv=none; d=google.com; s=arc-20160816; b=iJ7zIIZMDKO3Jw4bW7CXeg8d8BpYQ9dKgicRfXY59vpoqGs6RZVCh8DSn/CZkRtIJ7 /yQuri5CRTL77bepcqSk0SqWJ9ft0EHPl/vH1WkWcyyWNU5hdpyGd2QxHkcZ1rIVjIDy 8WgrQLWh6CvB5UFWUtL/GISpitKy6FmxfQZg0NRN5UeZtZ87/kw1joHRm8psnlNBaoap BQkrCQKqdjcuW5yLklLT5PcO2QhtdAtWlfhcF59jgLNU9yoPO1d8mphAZlfy5idneZ9h dZROgEPPHMK6E/qXQ8CB60fL4Qbepv1KibpDJYb/Rf5+MYOIIb6z9inr8YG5B9Hpb9j2 +a+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=yzCIhgWSWB1sGxIlTQQBY+Zll9G7G2k/fD0vgf07hXQ=; b=Pew2CSeCFvN62qStgH4s/f6A4ZK2akDyf1OSgNo8yxSnYBkQCrapeutfJtf2TiFzGi fhH+OMQHRR1G5TNjKmGlOnoKikTE1/uuoFxlzA+sDnt39SyFCC7SE7c+qOmzYqRIaTPG wqCcBzrS3TYBuxoS09hc7lqkjmlaDSSk8iaBaIfFwzEb2iHn1W0OqRJCP0NAe6siVypZ DE3qvghIudI2U3WiBkLVbkJt72kyYAQlxANiK+6iMG6bo/etBPqOseVZICNF043rlcsV CpahklXzIF1WGqkRQoTD9XVx5zkWL7LUOFWxMkx3qZOwgehoQ3rpN3MB4PDVwttckvbl AFBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QhjDroef; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i19si1209014edc.50.2021.06.24.01.22.28; Thu, 24 Jun 2021 01:22:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QhjDroef; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231895AbhFXIW4 (ORCPT + 99 others); Thu, 24 Jun 2021 04:22:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39640 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbhFXIWu (ORCPT ); Thu, 24 Jun 2021 04:22:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624522831; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yzCIhgWSWB1sGxIlTQQBY+Zll9G7G2k/fD0vgf07hXQ=; b=QhjDroefQcTiQLipjoThTmLc/Mnv0cybC5SxrGjb/GkQt5Qv9BgdNGyaVWWbxk7mXyTlh9 yoPam/i8WGDRXMfW+A8MgtcEgsoFkz7VYRTxkrjJjCHUEclCXNRngtPizhsKALNYC8NROM 2eHeckQKSUoGQU9APOxv6lCaJE247ZA= 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-276-f1BdehLZN8ywnuYFBfwzeA-1; Thu, 24 Jun 2021 04:20:30 -0400 X-MC-Unique: f1BdehLZN8ywnuYFBfwzeA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E72B21054F9A; Thu, 24 Jun 2021 08:20:28 +0000 (UTC) Received: from starship (unknown [10.40.192.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 189FC1001281; Thu, 24 Jun 2021 08:20:25 +0000 (UTC) Message-ID: <83affeedb9a3d091bece8f5fdd5373342298dcd3.camel@redhat.com> Subject: Re: [PATCH RFC] KVM: nSVM: Fix L1 state corruption upon return from SMM From: Maxim Levitsky To: Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Cathy Avery , Emanuele Giuseppe Esposito , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Date: Thu, 24 Jun 2021 11:20:24 +0300 In-Reply-To: <82327cd1-92ca-9f6b-3af0-8215e9d21eae@redhat.com> References: <20210623074427.152266-1-vkuznets@redhat.com> <53a9f893cb895f4b52e16c374cbe988607925cdf.camel@redhat.com> <87pmwc4sh4.fsf@vitty.brq.redhat.com> <5fc502b70a89e18034716166abc65caec192c19b.camel@redhat.com> <82327cd1-92ca-9f6b-3af0-8215e9d21eae@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2021-06-23 at 22:37 +0200, Paolo Bonzini wrote: > On 23/06/21 18:21, Sean Christopherson wrote: > > On Wed, Jun 23, 2021, Sean Christopherson wrote: > > > And I believe this hackery is necessary only because nested_svm_vmexit() isn't > > > following the architcture in the first place. I.e. using vmcb01 to restore > > > host state is flat out wrong. > > > > Ah, that's not true, using vmcb01 is allowed by "may store some or all host state > > in hidden on-chip memory". > > And also, "Different implementations may choose to save the hidden parts > of the host’s segment registers as well as the selectors". > > > From a performance perspective, I do like the SMI/RSM shenanigans. I'm not > > totally opposed to the trickery since I think it will break a guest if and only > > if the L1 guest is also violating the APM. And we're not fudging the spec thaat > > much :-) > > Yeah, that was my reasoning as well. Any reference to "hidden on-chip > memory", plus the forbidding modifications of the host save area, sort > of implies that the processor can actually flush that hidden on-chip > memory for whatever reason (such as on some sleep states?!?). > > Paolo > Let me explain my thoughts about this again, now that I hopefully understand this correctly: L1 register state is stored in VMCB01 since the CPU stores it there, every time L1 VMexits. Now L1 is a host for L2, and therefore this is also L1 "host" state. When we switch to L2, it is therefore natural to keep that state in vmcb01, and not copy it to VM_HSAVE_PA area. So when running SMM code in L1, since we must not corrupt this state, It makes sense to back it up somewhere, but as I said I prefer to store/migrate it out of band instead of saving it in the guest memory, although Paolo's reasoning that CPU might *sometimes* write VM_HSAVE_PA and that *sometimes* is allowed to be when we enter SMM, does make sense. Thus I don't have a strong opinion on this anymore, as long as it works. Something else to note, just for our information is that KVM these days does vmsave/vmload to VM_HSAVE_PA to store/restore the additional host state, something that is frowned upon in the spec, but there is some justification of doing this in the commit message, citing an old spec which allowed this. This shoudn't affect anything, but just FYI. https://patchwork.kernel.org/project/kvm/patch/20201210174814.1122585-1-michael.roth@amd.com/ Best regards, Maxim Levitsky