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=-17.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 8162BC433DF for ; Thu, 13 Aug 2020 17:31:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B7F92078D for ; Thu, 13 Aug 2020 17:31:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="puw3EcPE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgHMRb4 (ORCPT ); Thu, 13 Aug 2020 13:31:56 -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-Google-Smtp-Source: ABdhPJwdR5FTDq9CbRiChGWtu1ufGfl7Dalv+5O3zt5gsgcAhuL6wrIBY2QfOF+CMmFX5XWI9yNir9yFzeBAldvL6Xo= 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.