Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3809046pxy; Tue, 4 May 2021 10:21:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyXWYpmb3lhGVjbEUUsTQWG+5oVPV2n0xGb3s5VzaE+FL84bczeJ0YF5fc8+lrxDgXroLH X-Received: by 2002:a17:90b:893:: with SMTP id bj19mr29019860pjb.6.1620148886020; Tue, 04 May 2021 10:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620148886; cv=none; d=google.com; s=arc-20160816; b=cZb87iie6vtfJw5f3NQzvS3RBRrNyqKIRubbxnH+ym4L5B1RvqEXgbp28riv/YXdHT btKZQs64pR88ume8waW8EzeQoeCvoVWtje2J02WNCDSpj1ciSfm8KQTSdRTN3oU5UjXm 5mIPS+ru3XfohCf4RYJEhUDmtgiCxPy4oNjr2r3YiwZ7EdHr1uElir6QwFQz2lCgNbvn UVCf9IPAZumJtHFFjIULQiSmTMM22X9sTUGk5tSHBOn73JtoxEASTrIuIvi5MSRz/qQA alls8+zqZ8bujVNVr82UNUAAh7qBnYIg7d/WQuR9JuxztYxMVgguOau+tXDivMkRuoTw Ao2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=EJVLUy9Wu1XMVquYiQb1OEBFSqdA144hYS1qNH/p6ok=; b=cOZnNSVLUCvNTI4HLesyAdmAOUpkDz/IFh4X4XH04cJo4f6q36lTQB1+ehVU5hiZnK FFoYGp8+Bxz9/879LLxRdMp4CHXTDI+yvv7gRHzwuKSEFPEoOfHCeL4AC8BBJgJsTYv6 ZfrLKTe2G40Tg5023LlsHA5z7yYKlSEstumQLRuzBVDaMS9Q6g3GBUWvBFYPVmcdrJSE hoTG40Obss8r9dc6BoRQXSaehGRYPXK+aJNyOovleWBawrdhbEcz4BMjlnYX8rvKaVNS zBYMAZl3f5kSW/BUf8rDgpOimZL3r9nt3gMICkm7mYaJylMTavMTLA+I4lx+gpDOTXQ1 KNJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GaRByPbJ; 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 c13si20319816pfl.283.2021.05.04.10.21.13; Tue, 04 May 2021 10:21:26 -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=GaRByPbJ; 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 S232463AbhEDRTd (ORCPT + 99 others); Tue, 4 May 2021 13:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232304AbhEDRTK (ORCPT ); Tue, 4 May 2021 13:19:10 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D238C06134C for ; Tue, 4 May 2021 10:18:11 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id i62-20020a3786410000b02902e4f9ff4af8so8026478qkd.8 for ; Tue, 04 May 2021 10:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=EJVLUy9Wu1XMVquYiQb1OEBFSqdA144hYS1qNH/p6ok=; b=GaRByPbJVmtgHWnYspoS8Dyjsh95eo63qw5bARG4QFcCgvqBFPaPZgkMwhIudspGV3 XxsQJfbuP47evZwpOW+90yLQ54UiDMP0KpyTMEay5IS3EmorT3z2HvoZ8/5HY+58ZT7D kJ1Q9SUEAN74G/9VOxqFRd6SHA+CU6zjz/rfMNmqlbPWQ3VkFDZQnYgRzUciw+sZiZRW QFVzh75tN13ns60wE+2IufukKRoZ2SteQiTMAvH8QOhuRZ86Q7W4fN6vNVaPCs6TWYY+ gDXEUjdS1PRaApRNuzzRf8V8/kPKZjXAdFlxHvSdFGggSKInJtBXv+eGNm05UHzp+n+t TkJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=EJVLUy9Wu1XMVquYiQb1OEBFSqdA144hYS1qNH/p6ok=; b=KasEDrzJre9YPKfBM7FKoAgZGszl1EFvDKYG+iHWA1lGbUrnHPUKIvuBxza5PLlvy6 73XvgjS5gOQcGRSfU+j7TKRVWRTCDAgn+fbUx8kPeqMvIJMAxafVj8HVM3c6/of/Ia+m w417tTn+e/boctW96THnIVnxlIm+P41993utfeAFLemk/EFFszOo0WisBJwajYMtYKuu GOMP9jnEYtCvbxi06+gRqjV6K8DvP5hkXaaahvvyu41cVC1KzZCYoJ+AeoLa99N3nMri XR1/66IGYsnKO4T3NOB3Jv7v9X4SATkDuErYIxSZa+tn7amnFjIZe34UYl5DtLuFsE5y TVYg== X-Gm-Message-State: AOAM5323myWrBhsZvdHioO3Xj5EOMYcPRc8KlXsa0GJ9qMWme2JlYIVN wbHXVsMx59t6+OmDEK3lT5YgzcByRwI= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:df57:48cb:ea33:a156]) (user=seanjc job=sendgmr) by 2002:a0c:e486:: with SMTP id n6mr24367135qvl.21.1620148690729; Tue, 04 May 2021 10:18:10 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 May 2021 10:17:31 -0700 In-Reply-To: <20210504171734.1434054-1-seanjc@google.com> Message-Id: <20210504171734.1434054-13-seanjc@google.com> Mime-Version: 1.0 References: <20210504171734.1434054-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog Subject: [PATCH 12/15] KVM: x86: Export the number of uret MSRs to vendor modules From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split out and export the number of configured user return MSRs so that VMX can iterate over the set of MSRs without having to do its own tracking. Keep the list itself internal to x86 so that vendor code still has to go through the "official" APIs to add/modify entries. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c9452472ed55..10663610f105 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1419,6 +1419,7 @@ struct kvm_arch_async_pf { bool direct_map; }; +extern u32 __read_mostly kvm_nr_uret_msrs; extern u64 __read_mostly host_efer; extern bool __read_mostly allow_smaller_maxphyaddr; extern struct kvm_x86_ops kvm_x86_ops; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 90ef340565a4..2fd46e917666 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -184,11 +184,6 @@ module_param(pi_inject_timer, bint, S_IRUGO | S_IWUSR); */ #define KVM_MAX_NR_USER_RETURN_MSRS 16 -struct kvm_user_return_msrs_global { - int nr; - u32 msrs[KVM_MAX_NR_USER_RETURN_MSRS]; -}; - struct kvm_user_return_msrs { struct user_return_notifier urn; bool registered; @@ -198,7 +193,9 @@ struct kvm_user_return_msrs { } values[KVM_MAX_NR_USER_RETURN_MSRS]; }; -static struct kvm_user_return_msrs_global __read_mostly user_return_msrs_global; +u32 __read_mostly kvm_nr_uret_msrs; +EXPORT_SYMBOL_GPL(kvm_nr_uret_msrs); +static u32 __read_mostly kvm_uret_msrs_list[KVM_MAX_NR_USER_RETURN_MSRS]; static struct kvm_user_return_msrs __percpu *user_return_msrs; #define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \ @@ -330,10 +327,10 @@ static void kvm_on_user_return(struct user_return_notifier *urn) user_return_notifier_unregister(urn); } local_irq_restore(flags); - for (slot = 0; slot < user_return_msrs_global.nr; ++slot) { + for (slot = 0; slot < kvm_nr_uret_msrs; ++slot) { values = &msrs->values[slot]; if (values->host != values->curr) { - wrmsrl(user_return_msrs_global.msrs[slot], values->host); + wrmsrl(kvm_uret_msrs_list[slot], values->host); values->curr = values->host; } } @@ -358,9 +355,9 @@ EXPORT_SYMBOL_GPL(kvm_probe_user_return_msr); void kvm_define_user_return_msr(unsigned slot, u32 msr) { BUG_ON(slot >= KVM_MAX_NR_USER_RETURN_MSRS); - user_return_msrs_global.msrs[slot] = msr; - if (slot >= user_return_msrs_global.nr) - user_return_msrs_global.nr = slot + 1; + kvm_uret_msrs_list[slot] = msr; + if (slot >= kvm_nr_uret_msrs) + kvm_nr_uret_msrs = slot + 1; } EXPORT_SYMBOL_GPL(kvm_define_user_return_msr); @@ -368,8 +365,8 @@ int kvm_find_user_return_msr(u32 msr) { int i; - for (i = 0; i < user_return_msrs_global.nr; ++i) { - if (user_return_msrs_global.msrs[i] == msr) + for (i = 0; i < kvm_nr_uret_msrs; ++i) { + if (kvm_uret_msrs_list[i] == msr) return i; } return -1; @@ -383,8 +380,8 @@ static void kvm_user_return_msr_cpu_online(void) u64 value; int i; - for (i = 0; i < user_return_msrs_global.nr; ++i) { - rdmsrl_safe(user_return_msrs_global.msrs[i], &value); + for (i = 0; i < kvm_nr_uret_msrs; ++i) { + rdmsrl_safe(kvm_uret_msrs_list[i], &value); msrs->values[i].host = value; msrs->values[i].curr = value; } @@ -399,7 +396,7 @@ int kvm_set_user_return_msr(unsigned slot, u64 value, u64 mask) value = (value & mask) | (msrs->values[slot].host & ~mask); if (value == msrs->values[slot].curr) return 0; - err = wrmsrl_safe(user_return_msrs_global.msrs[slot], value); + err = wrmsrl_safe(kvm_uret_msrs_list[slot], value); if (err) return 1; -- 2.31.1.527.g47e6f16901-goog