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=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 E3CF0C433DB for ; Thu, 7 Jan 2021 20:20:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A682A23406 for ; Thu, 7 Jan 2021 20:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727105AbhAGUUT (ORCPT ); Thu, 7 Jan 2021 15:20:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726507AbhAGUUS (ORCPT ); Thu, 7 Jan 2021 15:20:18 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 568A8C0612F5 for ; Thu, 7 Jan 2021 12:19:38 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id p18so5730335pgm.11 for ; Thu, 07 Jan 2021 12:19:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=SZlEimO4YAkWtxdva4bxnoHuQClhYtsS69UscPllb+A=; b=RlsMFs4KjBCB+f5yJHtNjT/wxOFZnRr78VAoWkzR4IJ1Dj2eqR3aR83EL+qvwINVB1 XJiEfd0TL9UnhCwf3m1jzELfhlAkSg61IDLcdV6qJqOVMh4Kbemd3a1XhXqvVHDqTy++ LHoH15TTy/QucjUfuwxrjsxVJCEuCgYq0rCTIR5LDD6Ut8tI1dTdUIt+XSWIAHD6R9rB yCI9vqOkAuonQ9mTuxjGg0vIClJeSol9ppwr2CtaGx6WapBoNyKBFxm35NlX+ljoTeXb NvSwUoTqQVO3vTe8A2bNkoCSoefP19CNsrhAgNdBf7xz0zSAA1W81tqK/vXF0d9MIiKn 4WEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=SZlEimO4YAkWtxdva4bxnoHuQClhYtsS69UscPllb+A=; b=jmhzFuLgquIQ9PX23Q3bx9Kpsb8nfiRO0ZAKHKiHR4Z0ImU/nOTe6Uxffz7QO5ZOb4 vV06P2tKcX8bTpFyNjGeejIP37XGW4p/t5pnRS891MQBPQczZUfbeEUFp9e5YnUiGYae HX69Stgkjbv5kmkR04mqP6BEauTW1BAtdSpCENk/oWB9fd/ZbYOo2Ymw4SbKIH8wbGJ+ 69o8qZzA7d8y4GWI7CLM4UcxZiaMhMTrYZRf9+SXatlkLW7iNTaXQ0XfeccqOf8Y3EmM oo7Qgln5IvfezEtzhTF7U/NsPOCjnTqqZDQEIJgO26sLKQJYOvpNyIOXDi1501WEyH53 pvvg== X-Gm-Message-State: AOAM531NUuk1amRwpYuwOZ22EEfe1I1IUwi2iPxSQh39lE3TluDYTdae dTneTwYK+MRyyBrQ572hUMvpZw== X-Google-Smtp-Source: ABdhPJxLNOJQnNDN+uN3rSRlA/QRDy9/dvVA3bNQP0tNQeLZb5+4qbAqAGCw8IwhLuvotH6+buWh9g== X-Received: by 2002:a63:3ec9:: with SMTP id l192mr3528736pga.104.1610050777651; Thu, 07 Jan 2021 12:19:37 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id w27sm6547964pfq.104.2021.01.07.12.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 12:19:37 -0800 (PST) Date: Thu, 7 Jan 2021 12:19:30 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Maxim Levitsky , kvm@vger.kernel.org, Vitaly Kuznetsov , "H. Peter Anvin" , Borislav Petkov , Thomas Gleixner , linux-kernel@vger.kernel.org, "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Ingo Molnar , Wanpeng Li , Joerg Roedel , Jim Mattson Subject: Re: [PATCH v2 2/4] KVM: nSVM: correctly restore nested_run_pending on migration Message-ID: References: <20210107093854.882483-1-mlevitsk@redhat.com> <20210107093854.882483-3-mlevitsk@redhat.com> <98f35e0a-d82b-cac0-b267-00fcba00c185@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <98f35e0a-d82b-cac0-b267-00fcba00c185@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 07, 2021, Paolo Bonzini wrote: > On 07/01/21 10:38, Maxim Levitsky wrote: > > The code to store it on the migration exists, but no code was restoring it. > > > > One of the side effects of fixing this is that L1->L2 injected events > > are no longer lost when migration happens with nested run pending. > > > > Signed-off-by: Maxim Levitsky > > --- > > arch/x86/kvm/svm/nested.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > > index ee4f2082ad1bd..cc3130ab612e5 100644 > > --- a/arch/x86/kvm/svm/nested.c > > +++ b/arch/x86/kvm/svm/nested.c > > @@ -1200,6 +1200,10 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, > > * in the registers, the save area of the nested state instead > > * contains saved L1 state. > > */ > > + > > + svm->nested.nested_run_pending = > > + !!(kvm_state->flags & KVM_STATE_NESTED_RUN_PENDING); > > + > > copy_vmcb_control_area(&hsave->control, &svm->vmcb->control); > > hsave->save = *save; > > > > Nice fix and we need to do it anyway. > > That said, the v1 change had some appeal to it. Which v1 change are you referring to? > In the VMX case (if properly implemented) it would allow removing the weird > nested_run_pending case from prepare_vmcs02_early. I think it's a valuable > invariant that there are no events in the VMCS after each KVM_RUN iteration, > and this special case is breaking the invariant. Hmm, as weird as that code is, I think it's actually the most architecturally correct behavior. Technically, the clearing of VM_ENTRY_INTR_INFO.VALID shouldn't be visible in vmcs12 until a nested VM-Exit occurs, e.g. copying the vmcs02 value to vmcs12 in vmx_get_nested_state() would work, but it's wrong at the same time. Ditto for L1 (or L2) writing vmcs12.VM_ENTRY_INTR_INFO while L2 is running (ignoring the SDM's very clear warning that doing so is bad); from L1/L2's perspective, there is no VM-Entry so writing vmcs12.VM_ENTRY_INTR_INFO should never generate an event in L2, even on CPUs without VMCS caching.