Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1538372pxa; Thu, 13 Aug 2020 10:35:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxI9Qd+umv+WNh1Cx2WGzVdjhdhqxoERnmWdTN8hpUk6M3z7weJ6AKnOoOFi8zXCsU/w629 X-Received: by 2002:a17:906:7155:: with SMTP id z21mr6247832ejj.282.1597340107754; Thu, 13 Aug 2020 10:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597340107; cv=none; d=google.com; s=arc-20160816; b=f6gTUjub1OcL5IFDO4o0Qje5+UAUIqiSu3RveG/Qwzn1KobDETx6Pyb6gtymFp2mg6 LErBDbC1jL5M/ZMMz1O48Se90Eb+l75ZWzvpymMmY19lf18RPQtllL4MXSlhReiFEvQE j7o027FbawpImoXQYTA8P56H5a7aKiKyJJ9BPPD1RIJ6wc1aDRFKDhLZSRiQSf5hiEPe lOAFLx2MhZJmEe1f90mCC3BKtuSBOg+8d2ONkSnSsLACamisvx4mou6Ubd3S+/Odee0q UBGfsmBFvZL6Z48kzCXx+BymA8sfu4ZjaSsFG8/Rpvn1WMLmPtsedMXYGTisAqNmDcBp 4sDw== 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=S0mJn9glHvgBKds8mjTmLlgE2xICxjsY+0mNXnuT3Ps=; b=C0Oi4KyYQBlKnq9EAR4pPr43aIbZDOtpXUBEJ+oizxNaewN6nD3w9lR8UvtqgzSk15 6aD5dOr3A5LRgmt3UCkh8Y+1JwsnmC1ERTcYK10JFf4h4iXrbEbrZ+RHWm8XU4GvJilz ZrBpzfKr84fcabn8J24kyOPrxHPl3OJiOpGj9F/97DtNsyDlxiYb+6XunRhWe/bZ6xCv BjlnOEPYsJNs+frvdMzePJiL4MI3ZO5cNzxuNiy6AuM6UgG6y2ZzNByQeyt9EMcM35ud 25jTM3GrQykR/ShpDWPbNulb2KNPOsYXPu9hVMN2aRLy4NgUZp8yo848e99vCgC82oTQ oCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=puw3EcPE; 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 a16si3677625ejx.411.2020.08.13.10.34.44; Thu, 13 Aug 2020 10:35:07 -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=puw3EcPE; 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 S1726583AbgHMRbz (ORCPT + 99 others); Thu, 13 Aug 2020 13:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgHMRby (ORCPT ); Thu, 13 Aug 2020 13:31:54 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 885A2C061757 for ; Thu, 13 Aug 2020 10:31:54 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id j7so5740731oij.9 for ; Thu, 13 Aug 2020 10:31:54 -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=S0mJn9glHvgBKds8mjTmLlgE2xICxjsY+0mNXnuT3Ps=; b=puw3EcPEVQASOhNPkfKBnDy0DJDfSfmsG10pcPqII3pGaR2Mq+QDu53CRMvu7GYsZa CWnR1VoAkCEBTwsuz4qnYc0f2Dkxl5UEf303i9cMjsPQsj4fL45kjOM+y191JNCli56+ l4E0N8LVQgGc3YvdpYYBSLRp0DzYMID7u3N5cnV8xfRgqoZY0+V5KnaYqrLxazLsTRRz kmIOERZUpI6fXf3ElJiREa3seR1LoULHwYPmo8AgxTWVUxbtv8aOJ6o+yR5lJWdQZc+O ms7pRxvjpZOUetuUyUf7+1DEakazTxV5qDW4zFJPMUBKoFMDrTaqB/x7hc5OtbnRlrBw 5VbQ== 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=S0mJn9glHvgBKds8mjTmLlgE2xICxjsY+0mNXnuT3Ps=; b=UB7j2sWqAxbsBIFpXVO+3BhTv7HYuoo4qfGzd3oDfWgfhISMOFXa1p47qAqNghKWH/ YWcCEd6gbPp4Rlv2ARtTrJu0kq2p/lsHApClEZ+zgZavd5SiSxfVPku9Z27O/kDehgWG zkSIV/vQaaFOReoDd5Nsr5+5AFfuFuon7t5AvEkLmA5zO/BkI96qwPg6SVCfA1aRJ0Bd JIM50blJPZ0vZVZMLxQDZ5ybIuJmJCtuBrt/rb1MMag3GOk3iJDxn82gWJzK77Oh78jy uwFJTHWfwR/8LukDsdqKU/3LTmCwCUSrIAY/YLzibxTokffCjEnP0g/62ATgKH+ZIJL0 zW+g== X-Gm-Message-State: AOAM5325KgbgZirHrTgS0F3t21M+eP/YnsqNxXUEZLoxGCfzZ/Bkv4cP h9Lrd1N61zAP+NKHgVP9QFudGBFbmDA2ZJgTre5oVg== X-Received: by 2002:aca:670b:: with SMTP id z11mr4137097oix.6.1597339912244; Thu, 13 Aug 2020 10:31:52 -0700 (PDT) MIME-Version: 1.0 References: <20200807084841.7112-1-chenyi.qiang@intel.com> <20200807084841.7112-3-chenyi.qiang@intel.com> <34b083be-b9d5-fd85-b42d-af0549e3b002@intel.com> In-Reply-To: <34b083be-b9d5-fd85-b42d-af0549e3b002@intel.com> From: Jim Mattson Date: Thu, 13 Aug 2020 10:31:40 -0700 Message-ID: Subject: Re: [RFC 2/7] KVM: VMX: Expose IA32_PKRS MSR 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 Wed, Aug 12, 2020 at 10:42 PM Chenyi Qiang wrote: > > > > On 8/13/2020 5:21 AM, Jim Mattson wrote: > > On Fri, Aug 7, 2020 at 1:46 AM Chenyi Qiang wrote: > >> > >> Protection Keys for Supervisor Pages (PKS) uses IA32_PKRS MSR (PKRS) at > >> index 0x6E1 to allow software to manage supervisor protection key > >> rights. For performance consideration, PKRS intercept will be disabled > >> so that the guest can access the PKRS without VM exits. > >> PKS introduces dedicated control fields in VMCS to switch PKRS, which > >> only does the retore part. In addition, every VM exit saves PKRS into > >> the guest-state area in VMCS, while VM enter won't save the host value > >> due to the expectation that the host won't change the MSR often. Update > >> the host's value in VMCS manually if the MSR has been changed by the > >> kernel since the last time the VMCS was run. > >> The function get_current_pkrs() in arch/x86/mm/pkeys.c exports the > >> per-cpu variable pkrs_cache to avoid frequent rdmsr of PKRS. > >> > >> Signed-off-by: Chenyi Qiang > >> --- > > > >> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > >> index 11e4df560018..df2c2e733549 100644 > >> --- a/arch/x86/kvm/vmx/nested.c > >> +++ b/arch/x86/kvm/vmx/nested.c > >> @@ -289,6 +289,7 @@ static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx, > >> dest->ds_sel = src->ds_sel; > >> dest->es_sel = src->es_sel; > >> #endif > >> + dest->pkrs = src->pkrs; > > > > Why isn't this (and other PKRS code) inside the #ifdef CONFIG_X86_64? > > PKRS isn't usable outside of long mode, is it? > > > > Yes, I'm also thinking about whether to put all pks code into > CONFIG_X86_64. The kernel implementation also wrap its pks code inside > CONFIG_ARCH_HAS_SUPERVISOR_PKEYS which has dependency with CONFIG_X86_64. > However, maybe this can help when host kernel disable PKS but the guest > enable it. What do you think about this? I see no problem in exposing PKRS to the guest even if the host doesn't have CONFIG_ARCH_HAS_SUPERVISOR_PKEYS.