Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp604192pxa; Fri, 14 Aug 2020 12:35:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW7ixl2hfJMh36iOVGw6o14A/6XHcBJz653O5Y2vyUSUDR35wv+/68cYtOSviY9WraYqUo X-Received: by 2002:a17:906:d8f:: with SMTP id m15mr3901229eji.494.1597433756462; Fri, 14 Aug 2020 12:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597433756; cv=none; d=google.com; s=arc-20160816; b=KMNHBjT1xNaZl0kGGD9vsjd9bg3yxh3tsKIO3EYvOxLHBdgsQWCauvjPLpFWR7JwqA f8IlSAjDKgmPlQ8tmLydqVyZMTmOP4EIMTByNgc/HRfo0EoRs2ms8N/Tgim9Tni9UHfo BLbKBNrMCCwzuPzl6/bi5WN0YOk5pmDNxcE9hyVKDPe0aTR1MmdtsYBT1O/dZv60zhGR dtaFRBfVC36S5j/t6c7x/kZyNp3vLK4nv/FHFgvY3/54/qc8Far0YUlchg3/B3a5TdKp ZBCx26H+kwG1yxc6jgLjMndtPgXiZTtftS4Eeor//IAHjfyMdf2mgD8j6pU016ASi4b3 dWMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=BeRR5BzKObBdnK+fwz2UMgE1kYYlUJPk1LUN7o/xOdo=; b=Kf5EK8fv5yma8aVZk3aubW3Xj8MUG5D3QNkVm2ISJa1V6/KiZ0rhtnMni7W5Vhofpq Cbz4FKY2b9S+4OCNjgrmzyzMD9dgxJ/BVfPeWiCS0oP1rTDS1043oyvMfVj1yPysnuGr 4w5Xvzwkm1qTMuI6MqdcVQUcWE+Hz0lWPXrWuvW74Uj/EqO3XD2sVdV3fJgqlzfYDx7e 7nPs6pFgKyarnMkvAjUjFhzf5ETfk7P6zElZbcp67Shq2lZiAGdeErwQWROwLkUCcCXI IMt71KOC/xHekuFmbrxcEmJLsoM2o9imGXp0A+5VVWciDoSzxeUofQ1a+nWa059JWCh9 Sw8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Gth4o4u+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si5829050ejs.273.2020.08.14.12.35.33; Fri, 14 Aug 2020 12:35:56 -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=@google.com header.s=20161025 header.b=Gth4o4u+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728889AbgHNRer (ORCPT + 99 others); Fri, 14 Aug 2020 13:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728657AbgHNReq (ORCPT ); Fri, 14 Aug 2020 13:34:46 -0400 Received: from mail-oo1-xc43.google.com (mail-oo1-xc43.google.com [IPv6:2607:f8b0:4864:20::c43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 354AFC061385 for ; Fri, 14 Aug 2020 10:34:45 -0700 (PDT) Received: by mail-oo1-xc43.google.com with SMTP id p137so2074228oop.4 for ; Fri, 14 Aug 2020 10:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BeRR5BzKObBdnK+fwz2UMgE1kYYlUJPk1LUN7o/xOdo=; b=Gth4o4u+BkS4uuzbxWgDAcemzHF6oW0a+jDbxQPWhywWdFUx49bWOeLvc6PLgn90wj 4E7Bdbqv/daLEB0xpvYOdkpXThby+VgfCQe3UnYzRrFhXDykNwL5mVrk2U+GZKQ54ImZ Yf6KRxLhyDeFkhq58rqwAmSDDkIGJQuoNXgDoT3vORVXbTtS8hrsQH7IA5thm0SUbb3A c0QPfqvoHjsom0u/nNnIWhGY6GsGhsp7yZ39jLqFBxNDgz2oLrSR9KgAAw3VMoAbdnyF ozpOZQOlPvK7YalbqVTpyRJd3qUjMEJGnH/paK0pON6yTCpaGy4m16p0xPch9xhCydrU KbcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BeRR5BzKObBdnK+fwz2UMgE1kYYlUJPk1LUN7o/xOdo=; b=ndzyfVp1xt5fddRi+Vp1DvcyMo3R1+GLzzm2Bqo60qnf2G3lBEWlSKBWiQnd1Nog5Q x1nk10aSslTQMZpwzX1Ahl7IVVgf8ekXJgejxJqO8V2xss5eEDoa0tu8QOfSUzU8hEAS BXloGq0Ek71aElSsummTxnDsxBsGXCgRE7tMRihYcFTuBzp8q5OlRgrHtR0JA39ZhA63 3gzwn9Rki5I3IN7e3rLVqA5xMHAJc9gDsRYTNa7j2TDRkxMwgP1crCe+a+6pD5aYEMJy FB0UHUMEtoJnOOMkEVnxaUYMFWUhjBD/Jh/5nnhY59MaI/eeltyAWssytjBYzdny8auk Gx7Q== X-Gm-Message-State: AOAM5314/NOTQRC5CHB+mHvt7EgqOAs11g1asgFDJfPObVed51SdqgKd MEI6hfF9Z22JU5xorL9oy4nD4Y9Y3UcqB8IxigeXNw== X-Received: by 2002:a4a:87c8:: with SMTP id c8mr2455742ooi.81.1597426484278; Fri, 14 Aug 2020 10:34:44 -0700 (PDT) MIME-Version: 1.0 References: <20200807084841.7112-1-chenyi.qiang@intel.com> <20200807084841.7112-8-chenyi.qiang@intel.com> <1481a482-c20b-5531-736c-de0c5d3d611c@intel.com> In-Reply-To: From: Jim Mattson Date: Fri, 14 Aug 2020 10:34:33 -0700 Message-ID: Subject: Re: [RFC 7/7] KVM: VMX: Enable PKS for nested VM To: Chenyi Qiang Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , Xiaoyao Li , kvm list , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 14, 2020 at 3:09 AM Chenyi Qiang wrote: > > > > On 8/14/2020 1:52 AM, Jim Mattson wrote: > > On Wed, Aug 12, 2020 at 9:54 PM Chenyi Qiang wrote: > >> > >> > >> > >> On 8/11/2020 8:05 AM, Jim Mattson wrote: > >>> On Fri, Aug 7, 2020 at 1:47 AM Chenyi Qiang wrote: > >>>> > >>>> PKS MSR passes through guest directly. Configure the MSR to match the > >>>> L0/L1 settings so that nested VM runs PKS properly. > >>>> > >>>> Signed-off-by: Chenyi Qiang > >>>> --- > > > >>>> + (!vmx->nested.nested_run_pending || > >>>> + !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PKRS))) > >>>> + vmcs_write64(GUEST_IA32_PKRS, vmx->nested.vmcs01_guest_pkrs); > >>> > >>> This doesn't seem right to me. On the target of a live migration, with > >>> L2 active at the time the snapshot was taken (i.e., > >>> vmx->nested.nested_run_pending=0), it looks like we're going to try to > >>> overwrite the current L2 PKRS value with L1's PKRS value (except that > >>> in this situation, vmx->nested.vmcs01_guest_pkrs should actually be > >>> 0). Am I missing something? > >>> > >> > >> We overwrite the L2 PKRS with L1's value when L2 doesn't support PKS. > >> Because the L1's VM_ENTRY_LOAD_IA32_PKRS is off, we need to migrate L1's > >> PKRS to L2. > > > > I'm thinking of the case where vmx->nested.nested_run_pending is > > false, and we are processing a KVM_SET_NESTED_STATE ioctl, yet > > VM_ENTRY_LOAD_IA32_PKRS *is* set in the vmcs12. > > > > Oh, I miss this case. What I'm still confused here is that the > restoration for GUEST_IA32_DEBUGCTL and GUEST_BNDCFGS have the same > issue, right? or I miss something. I take it back. This does work, assuming that userspace calls KVM_SET_MSRS before calling KVM_SET_NESTED_STATE. Assuming L2 is active when the checkpoint is taken, the MSR values saved will be the L2 values. When restoring the MSRs with KVM_SET_MSRS, the L2 MSR values will be written into vmcs01. They don't belong there, but we're never going to launch vmcs01 with those MSR values. Instead, when userspace calls KVM_SET_NESTED_STATE, those values will be transferred first to the vmcs01_ fields of the vmx->nested struct, and then to vmcs02. This is subtle, and I don't think it's documented anywhere that KVM_SET_NESTED_STATE must be called after KVM_SET_MSRS. In fact, there are probably a number of dependencies among the various KVM_SET_* functions that aren't documented anywhere.