From patchwork Mon Mar 27 10:18:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9646337 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 5FC00602D6 for ; Mon, 27 Mar 2017 10:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F122228C9 for ; Mon, 27 Mar 2017 10:20:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53C412837F; Mon, 27 Mar 2017 10:20:42 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 4A07F228C9 for ; Mon, 27 Mar 2017 10:20:41 +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 1csRjT-000700-F6; Mon, 27 Mar 2017 10:18:39 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1csRjS-0006za-2w for xen-devel@lists.xenproject.org; Mon, 27 Mar 2017 10:18:38 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 2C/F6-14382-DF6E8D85; Mon, 27 Mar 2017 10:18:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRWlGSWpSXmKPExsWyU9JRQvfPsxs RBn0v9Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozdD/ayFiw0q/i2/iNTA+MunS5GTg4JAT+J zstP2EFsNgEdiYtzd7J1MXJwiAioSNzeawBiMguUS8y4EQ9SISzgIzF9/RpmEJtFQFVi27MtY J28ApYST04dYYaYKC/xaNMjsCmcAlYSZ/dVgISFgEo693VBlQtKnJz5hAXEZhbQlGjd/psdwp aXaN46mxmiXlGif94DNoiR6RITn/WwTGDkn4WkfRaS9llI2hcwMq9i1ChOLSpLLdI1stBLKsp MzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZLzs/dxAgMPwYg2MF4fm3gIUZJDiYlUd4Pp29ECPEl 5adUZiQWZ8QXleakFh9ilOHgUJLgzX4KlBMsSk1PrUjLzAFGAkxagoNHSYT3wBOgNG9xQWJuc WY6ROoUo6KUOG8hSJ8ASCKjNA+uDRZ9lxhlpYR5GYEOEeIpSC3KzSxBlX/FKM7BqCTMuxlkCk 9mXgnc9FdAi5mAFh+eD7a4JBEhJdXAqPu+KO3fY45XC/8/en6Qa56LA7+Sg/a6r3zFu/j27v9 iYx/wZa7THNMHF6fmLQh24JikXrUiwvbFaYPr37Z/nPzWNnLHjiM6D5buzFC8eFWo+3NutBjz 08Io7Qq+WgUj43fOvCXJAnN3Rq7+cO4hP9e8u/4iqoI8/F89tiwr+NVt+sn/Y0HUCyWW4oxEQ y3mouJEABS+G3m5AgAA X-Env-Sender: prvs=25239713d=roger.pau@citrix.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1490609913!83588185!2 X-Originating-IP: [185.25.65.24] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25343 invoked from network); 27 Mar 2017 10:18:36 -0000 Received: from smtp.eu.citrix.com (HELO SMTP.EU.CITRIX.COM) (185.25.65.24) by server-8.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 27 Mar 2017 10:18:36 -0000 X-IronPort-AV: E=Sophos;i="5.36,231,1486425600"; d="scan'208";a="43158871" From: Roger Pau Monne To: Date: Mon, 27 Mar 2017 11:18:17 +0100 Message-ID: <20170327101823.99368-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170327101823.99368-1-roger.pau@citrix.com> References: <20170327101823.99368-1-roger.pau@citrix.com> MIME-Version: 1.0 X-ClientProxiedBy: AMSPEX02CAS02.citrite.net (10.69.22.113) To AMSPEX02CL02.citrite.net (10.69.22.126) Cc: Andrew Cooper , Jan Beulich , Roger Pau Monne Subject: [Xen-devel] [PATCH v2 1/7] x86/vioapic: introduce a internal vIO APIC structure 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is required in order to have a variable number of vIO APIC pins, instead of the current fixed value (48). Note that this patch only expands the fields of the hvm_vioapic struct, without actually introducing any new fields or functionality. The reason to expand the hvm_vioapic structure instead of the hvm_hw_vioapic one is that the variable number of pins functionality is only going to be used by the hardware domain, so no modifications are needed to the save format. Signed-off-by: Roger Pau MonnĂ© --- Cc: Jan Beulich Cc: Andrew Cooper --- Changes since v1: - New in this version. --- xen/arch/x86/hvm/vioapic.c | 43 ++++++++++++++++++++++----------------- xen/include/asm-x86/hvm/vioapic.h | 11 ++++++---- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index fdbb21f097..84139a3b7d 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -42,9 +42,9 @@ /* HACK: Route IRQ0 only to VCPU0 to prevent time jumps. */ #define IRQ0_SPECIAL_ROUTING 1 -static void vioapic_deliver(struct hvm_hw_vioapic *vioapic, int irq); +static void vioapic_deliver(struct hvm_vioapic *vioapic, int irq); -static uint32_t vioapic_read_indirect(const struct hvm_hw_vioapic *vioapic) +static uint32_t vioapic_read_indirect(const struct hvm_vioapic *vioapic) { uint32_t result = 0; @@ -94,7 +94,7 @@ static int vioapic_read( struct vcpu *v, unsigned long addr, unsigned int length, unsigned long *pval) { - const struct hvm_hw_vioapic *vioapic = domain_vioapic(v->domain); + const struct hvm_vioapic *vioapic = domain_vioapic(v->domain); uint32_t result; HVM_DBG_LOG(DBG_LEVEL_IOAPIC, "addr %lx", addr); @@ -119,7 +119,7 @@ static int vioapic_read( } static void vioapic_write_redirent( - struct hvm_hw_vioapic *vioapic, unsigned int idx, + struct hvm_vioapic *vioapic, unsigned int idx, int top_word, uint32_t val) { struct domain *d = vioapic_domain(vioapic); @@ -170,7 +170,7 @@ static void vioapic_write_redirent( } static void vioapic_write_indirect( - struct hvm_hw_vioapic *vioapic, uint32_t val) + struct hvm_vioapic *vioapic, uint32_t val) { switch ( vioapic->ioregsel ) { @@ -215,7 +215,7 @@ static int vioapic_write( struct vcpu *v, unsigned long addr, unsigned int length, unsigned long val) { - struct hvm_hw_vioapic *vioapic = domain_vioapic(v->domain); + struct hvm_vioapic *vioapic = domain_vioapic(v->domain); switch ( addr & 0xff ) { @@ -242,7 +242,7 @@ static int vioapic_write( static int vioapic_range(struct vcpu *v, unsigned long addr) { - struct hvm_hw_vioapic *vioapic = domain_vioapic(v->domain); + struct hvm_vioapic *vioapic = domain_vioapic(v->domain); return ((addr >= vioapic->base_address && (addr < vioapic->base_address + VIOAPIC_MEM_LENGTH))); @@ -255,7 +255,7 @@ static const struct hvm_mmio_ops vioapic_mmio_ops = { }; static void ioapic_inj_irq( - struct hvm_hw_vioapic *vioapic, + struct hvm_vioapic *vioapic, struct vlapic *target, uint8_t vector, uint8_t trig_mode, @@ -275,7 +275,7 @@ static inline int pit_channel0_enabled(void) return pt_active(¤t->domain->arch.vpit.pt0); } -static void vioapic_deliver(struct hvm_hw_vioapic *vioapic, int irq) +static void vioapic_deliver(struct hvm_vioapic *vioapic, int irq) { uint16_t dest = vioapic->redirtbl[irq].fields.dest_id; uint8_t dest_mode = vioapic->redirtbl[irq].fields.dest_mode; @@ -361,7 +361,7 @@ static void vioapic_deliver(struct hvm_hw_vioapic *vioapic, int irq) void vioapic_irq_positive_edge(struct domain *d, unsigned int irq) { - struct hvm_hw_vioapic *vioapic = domain_vioapic(d); + struct hvm_vioapic *vioapic = domain_vioapic(d); union vioapic_redir_entry *ent; ASSERT(has_vioapic(d)); @@ -388,7 +388,7 @@ void vioapic_irq_positive_edge(struct domain *d, unsigned int irq) void vioapic_update_EOI(struct domain *d, u8 vector) { - struct hvm_hw_vioapic *vioapic = domain_vioapic(d); + struct hvm_vioapic *vioapic = domain_vioapic(d); struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq; union vioapic_redir_entry *ent; int gsi; @@ -426,38 +426,43 @@ void vioapic_update_EOI(struct domain *d, u8 vector) static int ioapic_save(struct domain *d, hvm_domain_context_t *h) { - struct hvm_hw_vioapic *s = domain_vioapic(d); + struct hvm_vioapic *s = domain_vioapic(d); if ( !has_vioapic(d) ) return 0; - return hvm_save_entry(IOAPIC, 0, h, s); + BUILD_BUG_ON(sizeof(struct hvm_hw_vioapic) != + sizeof(struct hvm_vioapic) - + offsetof(struct hvm_vioapic, base_address)); + + return hvm_save_entry(IOAPIC, 0, h, &s->base_address); } static int ioapic_load(struct domain *d, hvm_domain_context_t *h) { - struct hvm_hw_vioapic *s = domain_vioapic(d); + struct hvm_vioapic *s = domain_vioapic(d); if ( !has_vioapic(d) ) return -ENODEV; - return hvm_load_entry(IOAPIC, h, s); + return hvm_load_entry(IOAPIC, h, &s->base_address); } HVM_REGISTER_SAVE_RESTORE(IOAPIC, ioapic_save, ioapic_load, 1, HVMSR_PER_DOM); void vioapic_reset(struct domain *d) { - struct hvm_vioapic *vioapic = d->arch.hvm_domain.vioapic; + struct hvm_vioapic *vioapic = domain_vioapic(d); int i; if ( !has_vioapic(d) ) return; - memset(&vioapic->hvm_hw_vioapic, 0, sizeof(vioapic->hvm_hw_vioapic)); + memset(vioapic, 0, sizeof(*vioapic)); + vioapic->domain = d; for ( i = 0; i < VIOAPIC_NUM_PINS; i++ ) - vioapic->hvm_hw_vioapic.redirtbl[i].fields.mask = 1; - vioapic->hvm_hw_vioapic.base_address = VIOAPIC_DEFAULT_BASE_ADDRESS; + vioapic->redirtbl[i].fields.mask = 1; + vioapic->base_address = VIOAPIC_DEFAULT_BASE_ADDRESS; } int vioapic_init(struct domain *d) diff --git a/xen/include/asm-x86/hvm/vioapic.h b/xen/include/asm-x86/hvm/vioapic.h index 745c09ab5c..e8ec0be7b6 100644 --- a/xen/include/asm-x86/hvm/vioapic.h +++ b/xen/include/asm-x86/hvm/vioapic.h @@ -48,13 +48,16 @@ #define VIOAPIC_REG_RTE0 0x10 struct hvm_vioapic { - struct hvm_hw_vioapic hvm_hw_vioapic; struct domain *domain; + /* Layout below must match hvm_hw_vioapic. */ + uint64_t base_address; + uint32_t ioregsel; + uint32_t id; + union vioapic_redir_entry redirtbl[VIOAPIC_NUM_PINS]; }; -#define domain_vioapic(d) (&(d)->arch.hvm_domain.vioapic->hvm_hw_vioapic) -#define vioapic_domain(v) (container_of((v), struct hvm_vioapic, \ - hvm_hw_vioapic)->domain) +#define domain_vioapic(d) ((d)->arch.hvm_domain.vioapic) +#define vioapic_domain(v) ((v)->domain) int vioapic_init(struct domain *d); void vioapic_deinit(struct domain *d);