Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp514859imm; Wed, 29 Aug 2018 05:47:34 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda4BksNem8JV9a2Y5Wr2yrxXJ5x8zeZAlOJfqxPvc1rQODFf0fz62ZESjQWlIFK9+IAklaQ X-Received: by 2002:a62:1544:: with SMTP id 65-v6mr5816126pfv.178.1535546854362; Wed, 29 Aug 2018 05:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535546854; cv=none; d=google.com; s=arc-20160816; b=TS6Ia9MkK5cqQGvpavXcUXrV8zSNEPphFswxMo+2VcdAGdBW7o0SzxCfvoCU8sDmFx 1lJ0vSlkxNqc7S6xATHLsTXsIdl+TKZlQOriiKkUN+hAoT3sHU15sky6HPpzLwVmDSk4 Yqu9oa6dC3DzJ8j/gEsShA7SBGy//qXJiWE4jvgE3g8dzG210RPkweenzFBncPSqcIHD lNPTuEUZTdnCjamqzevh6IhkQXXrBD2ZrH414qDYJCgzNeyLImhQUPFa5EQwvfE5eu1J sTwu1XeyZ1I66Px/Ea009i4537gx6BU+hQKa7TAP5FyhGPmOddJvpiREQr0midB4mq2t DNoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=6uni45XjeYvyvMFlMzVVRIf63ZGi9s64H+79TGDJ+yA=; b=gUibxDN5ikAaHxAYqMCNdhRcIE3CFFyrmHYCG8BBVsj8c+Xss+nDiEPSmkiZFvn7Vn M5yvNkZhQZ6uovHFRgsuCM2VtD9ejNeR3qoJJAHa1h73lXCZiKdjRQlqb1GabRBxynwU lVypPsvGyXRqOPAccQeNMBwCsMNKOe+gEDWfFm9/N1PuGRRzt86avryBKH6jPm7Zx0wt rVp6w17WkZ+7lv2UWMqxvkMzOBhuXJKk0Q7HDlRlYohnpw2EcSonCEPeXAQsaidgfE6q 1P+TJvzozQjutw6/RJi7XsosIyvfHHc1ok/xnIuXYgGOHH31bZW+EsrN32wfWt3/mvGR uIYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y9-v6si3683438pgi.691.2018.08.29.05.47.18; Wed, 29 Aug 2018 05:47:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728708AbeH2QmY (ORCPT + 99 others); Wed, 29 Aug 2018 12:42:24 -0400 Received: from smtp17.cstnet.cn ([159.226.251.17]:50214 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728144AbeH2QmY (ORCPT ); Wed, 29 Aug 2018 12:42:24 -0400 Received: from pw-vbox.higon.com (unknown [182.150.46.145]) by APP-09 (Coremail) with SMTP id swCowACHjJBblYZbTqD_BA--.100S2; Wed, 29 Aug 2018 20:45:19 +0800 (CST) From: Pu Wen To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, thomas.lendacky@amd.com, bp@alien8.de, pbonzini@redhat.com, boris.ostrovsky@oracle.com, jgross@suse.com, JBeulich@suse.com Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, xen-devel@lists.xenproject.org, Pu Wen Subject: [PATCH v5 12/16] x86/xen: enable Hygon support to Xen Date: Wed, 29 Aug 2018 20:45:14 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-C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nUUI43 ZEXa7VUbKLvtUUUUU== X-Originating-IP: [182.150.46.145] X-CM-SenderInfo: psxzv046klw03qof0z/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To make Xen works functionly on Hygon platforms, reuse AMD's Xen support code path for Hygon. There are six core performance events counters per thread, so there are six MSRs for these counters(0-5). Also there are four legacy PMC MSRs, they are alias of the counters(0-3). In this version of kernel Hygon use the lagacy and safe versions of MSR access. It works fine when VPMU enabled in Xen on Hygon platforms by testing with perf. Reviewed-by: Boris Ostrovsky Signed-off-by: Pu Wen --- arch/x86/xen/pmu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c index 7d00d4a..9403854 100644 --- a/arch/x86/xen/pmu.c +++ b/arch/x86/xen/pmu.c @@ -90,6 +90,12 @@ static void xen_pmu_arch_init(void) k7_counters_mirrored = 0; break; } + } else if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) { + amd_num_counters = F10H_NUM_COUNTERS; + amd_counters_base = MSR_K7_PERFCTR0; + amd_ctrls_base = MSR_K7_EVNTSEL0; + amd_msr_step = 1; + k7_counters_mirrored = 0; } else { uint32_t eax, ebx, ecx, edx; @@ -285,7 +291,7 @@ static bool xen_amd_pmu_emulate(unsigned int msr, u64 *val, bool is_read) bool pmu_msr_read(unsigned int msr, uint64_t *val, int *err) { - if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) { if (is_amd_pmu_msr(msr)) { if (!xen_amd_pmu_emulate(msr, val, 1)) *val = native_read_msr_safe(msr, err); @@ -308,7 +314,7 @@ bool pmu_msr_write(unsigned int msr, uint32_t low, uint32_t high, int *err) { uint64_t val = ((uint64_t)high << 32) | low; - if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) { if (is_amd_pmu_msr(msr)) { if (!xen_amd_pmu_emulate(msr, &val, 0)) *err = native_write_msr_safe(msr, low, high); @@ -379,7 +385,7 @@ static unsigned long long xen_intel_read_pmc(int counter) unsigned long long xen_read_pmc(int counter) { - if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) return xen_amd_read_pmc(counter); else return xen_intel_read_pmc(counter); -- 2.7.4