From patchwork Wed Oct 28 08:40:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 37062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 205C5B7BF3 for ; Wed, 28 Oct 2009 19:47:31 +1100 (EST) Received: from localhost ([127.0.0.1]:33403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N34Bk-0005FQ-FN for incoming@patchwork.ozlabs.org; Wed, 28 Oct 2009 04:47:28 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N347W-0003It-NY for qemu-devel@nongnu.org; Wed, 28 Oct 2009 04:43:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N347R-0003GP-VV for qemu-devel@nongnu.org; Wed, 28 Oct 2009 04:43:06 -0400 Received: from [199.232.76.173] (port=43913 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N347R-0003GJ-Pj for qemu-devel@nongnu.org; Wed, 28 Oct 2009 04:43:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42656) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N347R-0001xF-7m for qemu-devel@nongnu.org; Wed, 28 Oct 2009 04:43:01 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9S8gvUA029844; Wed, 28 Oct 2009 04:42:57 -0400 Received: from redhat.com (vpn-6-118.tlv.redhat.com [10.35.6.118]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9S8gr7X022412; Wed, 28 Oct 2009 04:42:55 -0400 Date: Wed, 28 Oct 2009 10:40:35 +0200 From: "Michael S. Tsirkin" To: Juan Quintela , anthony@codemonkey.ws Message-ID: <20091028084035.GA23109@redhat.com> References: <20091026142244.GA25423@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20091026142244.GA25423@redhat.com> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH] qemu/msix: fix table access issues X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org BTW, Anthony, I think this is also stable-0.11 material. Patch seems to apply without changes there. ---> Fixes a couple of issues with msix table access: - With misbehaving guests, misaligned 4 byte access could overflow msix table and cause qemu to segfault. Since PCI spec requires host to only issue dword-aligned accesses, as a fix, it's enough to mask the address low bits. - Tables use pci format, not native format, and so we must use pci_[sg]et_long on read/write. Reported-by: Juan Quintela Signed-off-by: Michael S. Tsirkin --- Tested with x86 guest. hw/msix.c | 11 ++++------- 1 files changed, 4 insertions(+), 7 deletions(-) diff --git a/hw/msix.c b/hw/msix.c index b0dea91..3d67c4e 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -128,13 +128,10 @@ void msix_write_config(PCIDevice *dev, uint32_t addr, static uint32_t msix_mmio_readl(void *opaque, target_phys_addr_t addr) { PCIDevice *dev = opaque; - unsigned int offset = addr & (MSIX_PAGE_SIZE - 1); + unsigned int offset = addr & (MSIX_PAGE_SIZE - 1) & ~0x3; void *page = dev->msix_table_page; - uint32_t val = 0; - memcpy(&val, (void *)((char *)page + offset), 4); - - return val; + return pci_get_long(page + offset); } static uint32_t msix_mmio_read_unallowed(void *opaque, target_phys_addr_t addr) @@ -178,9 +175,9 @@ static void msix_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) { PCIDevice *dev = opaque; - unsigned int offset = addr & (MSIX_PAGE_SIZE - 1); + unsigned int offset = addr & (MSIX_PAGE_SIZE - 1) & ~0x3; int vector = offset / MSIX_ENTRY_SIZE; - memcpy(dev->msix_table_page + offset, &val, 4); + pci_set_long(dev->msix_table_page + offset, val); if (!msix_is_masked(dev, vector) && msix_is_pending(dev, vector)) { msix_clr_pending(dev, vector); msix_notify(dev, vector);