From patchwork Tue Aug 16 23:28:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Goldstein X-Patchwork-Id: 9284985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 607CE607FD for ; Tue, 16 Aug 2016 23:32:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50B1B286F5 for ; Tue, 16 Aug 2016 23:32:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4556B28788; Tue, 16 Aug 2016 23:32:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 692CE286F5 for ; Tue, 16 Aug 2016 23:32:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZnnU-0004bc-EG; Tue, 16 Aug 2016 23:29:28 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZnnT-0004aw-NB for xen-devel@lists.xen.org; Tue, 16 Aug 2016 23:29:27 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 94/E1-05361-7D1A3B75; Tue, 16 Aug 2016 23:29:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRWlGSWpSXmKPExsVyMXThYd2rCze HG6z7YWWx5ONiFgdGj6O7fzMFMEaxZuYl5VcksGasWLWSqWC3bcXam/vZGxjXGnUxcnEICUxk lHi/sYURxGERmMcssf3KF2YQR0Kgn1Xixbq7LF2MnEBOjMSxnQ+YIexqiUt7P7OB2EICChK/J xxighi1gkli24qfYA1sAhoST37NACsSEZCWuPb5MiOIzSxQIrF3/g8wW1jAXGJv/yWwoSwCqh JNPX1gcV4BR4n2nTOB5nAALZOTWPDeByTMKeAkcfRlAzvEXkeJ5jXT2SYwCixgZFjFqFGcWlS WWqRrbKiXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyXnJ+7iREYWgxAsIOxaVHgIUZJDiYl Ud6ZEzeGC/El5adUZiQWZ8QXleakFh9ilOHgUJLgrVuwOVxIsCg1PbUiLTMHGOQwaQkOHiUR3 msgad7igsTc4sx0iNQpRmOOLb+vrWXi2Db13lomIZa8/LxUKXHeoyClAiClGaV5cINg0XeJUV ZKmJcR6DQhnoLUotzMElT5V4ziHIxKwrz6wFgW4snMK4Hb9wroFCagU/SlN4CcUpKIkJJqYPQ yWSZ4N9p120NJh3h9nVMTfJl55sTdP+fg2Brx8my64aItjR+XG35J1tZeZmjMnJ+SLsOY9uep f67ZAnem2PC7kTk8v2xc+LQSX16c0X5UWGDWrwQeaYHNJRG6e2bKaL17KDL1OM+W5h1+zrUaE XOuBL2+/mBK1v1be3dx3NzOEe/OOZNbTomlOCPRUIu5qDgRAIvoHfq5AgAA X-Env-Sender: cardoe@cardoe.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1471390164!22686366!1 X-Originating-IP: [209.85.161.195] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35002 invoked from network); 16 Aug 2016 23:29:25 -0000 Received: from mail-yw0-f195.google.com (HELO mail-yw0-f195.google.com) (209.85.161.195) by server-4.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Aug 2016 23:29:25 -0000 Received: by mail-yw0-f195.google.com with SMTP id j12so4223838ywb.1 for ; Tue, 16 Aug 2016 16:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cardoe.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IJzOOjRt0FIdYDi/y9lZQrcM2pHMsBK+9l7wgauJerU=; b=V/lvPeuukA31StufwGTFK8Me/f62dXbiJnuFC41cFrLQMu8+hWMm+I5mM/aNKacxH6 mOH54uzvQZEf+SMF+dKL17n8f4lAP7ECahzdzPhxRf/SJPL1DbIdv4GYitElt567cEVy H2k2Q0wCM6vBKZFG+2m6Vd8EoAGelE7ouYEtc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IJzOOjRt0FIdYDi/y9lZQrcM2pHMsBK+9l7wgauJerU=; b=ODCqM8+hYj0FH2PMUWSuQJy2xgy8vRktOvcP6wwyijJnzSVezW4D309ERKFNajG9tv HmzbgFSmb1KlNoUPVsQNis+9CuqTkF8BRk2GBsAvywB1zH3JgXwgP4PcqbCnm7tOeMpn /Z0sEzfynW8rdCiH2yMOluGLCU5kxo8nKja+Dcywob5hfelA1hJJK25fstMu0CyGnk8Z ekWbb0D1cUFw9kBByL0Sogq/96m1CCvZ+ziYdXAKU+qzoj63TnALiMKFTLzImtvSDcLi D59RX736KmKZmDrJ/lbTfUUeP/lZ60i7IbfjTEnjaBujhlqkWRhMK0oqrzTPjIiMXKXx 5Uzg== X-Gm-Message-State: AEkoout2RWqJbvfQ3vL1dAQT6hF4c+H8WfXc2z/CkAfn/+MC2Y7eXe9UvnQyvYm3pZlN0Q== X-Received: by 10.129.75.150 with SMTP id y144mr27619451ywa.60.1471390164470; Tue, 16 Aug 2016 16:29:24 -0700 (PDT) Received: from swanson.attlocal.net (104-179-196-18.lightspeed.brhmal.sbcglobal.net. [104.179.196.18]) by smtp.gmail.com with ESMTPSA id p67sm14046603ywe.2.2016.08.16.16.29.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 16:29:23 -0700 (PDT) From: Doug Goldstein To: xen-devel@lists.xen.org Date: Tue, 16 Aug 2016 18:28:22 -0500 Message-Id: <1471390109-10407-3-git-send-email-cardoe@cardoe.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1471390109-10407-1-git-send-email-cardoe@cardoe.com> References: <1471390109-10407-1-git-send-email-cardoe@cardoe.com> Cc: Andrew Cooper , Doug Goldstein , Jan Beulich Subject: [Xen-devel] [PATCH 2/9] x86/mtrr: drop mtrr_if indirection X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP There can only ever be one mtrr_if now and that is the generic implementation so instead of going through an indirect call change everything to call the generic implementation directly. The is_cpu() macro would result in the left side always being equal to X86_VENDOR_INTEL for the generic implementation due to Intel having a value of 0. The use_intel() macro was always true in the generic implementation case as well. Removed some extraneous whitespace at the same time. Signed-off-by: Doug Goldstein --- xen/arch/x86/cpu/mtrr/generic.c | 2 +- xen/arch/x86/cpu/mtrr/main.c | 47 ++++++++++++++------------------------- xen/arch/x86/cpu/mtrr/mtrr.h | 4 ++-- xen/arch/x86/platform_hypercall.c | 2 +- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/xen/arch/x86/cpu/mtrr/generic.c b/xen/arch/x86/cpu/mtrr/generic.c index 224d231..5c4b273 100644 --- a/xen/arch/x86/cpu/mtrr/generic.c +++ b/xen/arch/x86/cpu/mtrr/generic.c @@ -265,7 +265,7 @@ int mtrr_generic_get_free_region(unsigned long base, unsigned long size, int rep if (replace_reg >= 0 && replace_reg < max) return replace_reg; for (i = 0; i < max; ++i) { - mtrr_if->get(i, &lbase, &lsize, <ype); + mtrr_generic_get(i, &lbase, &lsize, <ype); if (lsize == 0) return i; } diff --git a/xen/arch/x86/cpu/mtrr/main.c b/xen/arch/x86/cpu/mtrr/main.c index bf489e3..ff908ad 100644 --- a/xen/arch/x86/cpu/mtrr/main.c +++ b/xen/arch/x86/cpu/mtrr/main.c @@ -58,8 +58,6 @@ static DEFINE_MUTEX(mtrr_mutex); u64 __read_mostly size_or_mask; u64 __read_mostly size_and_mask; -const struct mtrr_ops *__read_mostly mtrr_if = NULL; - static void set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type); @@ -82,7 +80,7 @@ static const char *mtrr_attrib_to_str(int x) /* Returns non-zero if we have the write-combining memory type */ static int have_wrcomb(void) { - return (mtrr_if->have_wrcomb ? mtrr_if->have_wrcomb() : 0); + return mtrr_generic_have_wrcomb(); } /* This function returns the number of variable MTRRs */ @@ -150,9 +148,9 @@ static void ipi_handler(void *info) if (data->smp_reg == ~0U) /* update all mtrr registers */ /* At the cpu hot-add time this will reinitialize mtrr * registres on the existing cpus. It is ok. */ - mtrr_if->set_all(); + mtrr_generic_set_all(); else /* single mtrr register update */ - mtrr_if->set(data->smp_reg, data->smp_base, + mtrr_generic_set(data->smp_reg, data->smp_base, data->smp_size, data->smp_type); atomic_dec(&data->count); @@ -200,7 +198,7 @@ static inline int types_compatible(mtrr_type type1, mtrr_type type2) { * until it hits 0 and proceed. We set the data.gate flag and reset data.count. * Meanwhile, they are waiting for that flag to be set. Once it's set, each * CPU goes through the transition of updating MTRRs. The CPU vendors may each do it - * differently, so we call mtrr_if->set() callback and let them take care of it. + * differently, so we call mtrr_generic_set() callback and let them take care of it. * When they're done, they again decrement data->count and wait for data.gate to * be reset. * When we finish, we wait for data.count to hit 0 and toggle the data.gate flag. @@ -252,9 +250,9 @@ static void set_mtrr(unsigned int reg, unsigned long base, if (reg == ~0U) /* update all mtrr registers */ /* at boot or resume time, this will reinitialize the mtrrs on * the bp. It is ok. */ - mtrr_if->set_all(); + mtrr_generic_set_all(); else /* update the single mtrr register */ - mtrr_if->set(reg,base,size,type); + mtrr_generic_set(reg, base, size, type); /* wait for the others */ while (atomic_read(&data.count)) @@ -317,10 +315,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, mtrr_type ltype; unsigned long lbase, lsize; - if (!mtrr_if) - return -ENXIO; - - if ((error = mtrr_if->validate_add_page(base,size,type))) + if ((error = mtrr_generic_validate_add_page(base,size,type))) return error; if (type >= MTRR_NUM_TYPES) { @@ -351,7 +346,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, /* Search for existing MTRR */ mutex_lock(&mtrr_mutex); for (i = 0; i < num_var_ranges; ++i) { - mtrr_if->get(i, &lbase, &lsize, <ype); + mtrr_generic_get(i, &lbase, &lsize, <ype); if (!lsize || base > lbase + lsize - 1 || base + size - 1 < lbase) continue; /* At this point we know there is some kind of overlap/enclosure */ @@ -386,7 +381,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, goto out; } /* Search for an empty MTRR */ - i = mtrr_if->get_free_region(base, size, replace); + i = mtrr_generic_get_free_region(base, size, replace); if (i >= 0) { set_mtrr(i, base, size, type); if (likely(replace < 0)) @@ -487,15 +482,12 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size) unsigned long lbase, lsize; int error = -EINVAL; - if (!mtrr_if) - return -ENXIO; - max = num_var_ranges; mutex_lock(&mtrr_mutex); if (reg < 0) { /* Search for existing MTRR */ for (i = 0; i < max; ++i) { - mtrr_if->get(i, &lbase, &lsize, <ype); + mtrr_generic_get(i, &lbase, &lsize, <ype); if (lbase == base && lsize == size) { reg = i; break; @@ -511,7 +503,7 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size) printk(KERN_WARNING "mtrr: register: %d too big\n", reg); goto out; } - mtrr_if->get(reg, &lbase, &lsize, <ype); + mtrr_generic_get(reg, &lbase, &lsize, <ype); if (lsize < 1) { printk(KERN_WARNING "mtrr: MTRR %d not used\n", reg); goto out; @@ -569,22 +561,19 @@ struct mtrr_value { void __init mtrr_bp_init(void) { if (cpu_has_mtrr) { - mtrr_if = &generic_mtrr_ops; size_or_mask = ~((1ULL << (paddr_bits - PAGE_SHIFT)) - 1); size_and_mask = ~size_or_mask & 0xfffff00000ULL; } - if (mtrr_if) { - set_num_var_ranges(); - init_table(); - if (use_intel()) - get_mtrr_state(); - } + set_num_var_ranges(); + init_table(); + if (use_intel()) + get_mtrr_state(); } void mtrr_ap_init(void) { - if (!mtrr_if || !use_intel() || hold_mtrr_updates_on_aps) + if (!use_intel() || hold_mtrr_updates_on_aps) return; /* * Ideally we should hold mtrr_mutex here to avoid mtrr entries changed, @@ -630,13 +619,11 @@ void mtrr_bp_restore(void) { if (!use_intel()) return; - mtrr_if->set_all(); + mtrr_generic_set_all(); } static int __init mtrr_init_finialize(void) { - if (!mtrr_if) - return 0; if (use_intel()) mtrr_state_warn(); return 0; diff --git a/xen/arch/x86/cpu/mtrr/mtrr.h b/xen/arch/x86/cpu/mtrr/mtrr.h index 619575f..92b0b11 100644 --- a/xen/arch/x86/cpu/mtrr/mtrr.h +++ b/xen/arch/x86/cpu/mtrr/mtrr.h @@ -63,8 +63,8 @@ extern void set_mtrr_ops(const struct mtrr_ops *); extern u64 size_or_mask, size_and_mask; extern const struct mtrr_ops *mtrr_if; -#define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd) -#define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1) +#define is_cpu(vnd) (X86_VENDOR_INTEL == X86_VENDOR_##vnd) +#define use_intel() (1) extern unsigned int num_var_ranges; diff --git a/xen/arch/x86/platform_hypercall.c b/xen/arch/x86/platform_hypercall.c index 780f22d..4a294b4 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -265,7 +265,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op) ret = -EINVAL; if ( op->u.read_memtype.reg < num_var_ranges ) { - mtrr_if->get(op->u.read_memtype.reg, &mfn, &nr_mfns, &type); + mtrr_generic_get(op->u.read_memtype.reg, &mfn, &nr_mfns, &type); op->u.read_memtype.mfn = mfn; op->u.read_memtype.nr_mfns = nr_mfns; op->u.read_memtype.type = type;