From patchwork Wed Feb 13 11:06:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 10809635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CA231575 for ; Wed, 13 Feb 2019 11:06:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4988B2837D for ; Wed, 13 Feb 2019 11:06:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C0D82CA79; Wed, 13 Feb 2019 11:06:28 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD8822837D for ; Wed, 13 Feb 2019 11:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730831AbfBMLGX (ORCPT ); Wed, 13 Feb 2019 06:06:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42966 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbfBMLGW (ORCPT ); Wed, 13 Feb 2019 06:06:22 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FB0681106; Wed, 13 Feb 2019 11:06:22 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-102.ams2.redhat.com [10.36.116.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FAEF101E848; Wed, 13 Feb 2019 11:06:15 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com Subject: [PATCH v2] vfio_pci: Enable memory accesses before calling pci_map_rom Date: Wed, 13 Feb 2019 12:06:10 +0100 Message-Id: <20190213110610.4834-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 13 Feb 2019 11:06:22 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_map_rom/pci_get_rom_size() performs memory access in the ROM. In case the Memory Space accesses were disabled, readw() is likely to crash the host with a synchronous external abort (aarch64). In case memory accesses were disabled, re-enable them before the call and disable them back again just after. Signed-off-by: Eric Auger --- v1 -> v2: - also re-enable in case of error --- drivers/vfio/pci/vfio_pci.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index ff60bd1ea587..721aa55424a4 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -706,8 +706,10 @@ static long vfio_pci_ioctl(void *device_data, break; case VFIO_PCI_ROM_REGION_INDEX: { + bool mem_access_disabled; void __iomem *io; size_t size; + u16 cmd; info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); info.flags = 0; @@ -723,15 +725,28 @@ static long vfio_pci_ioctl(void *device_data, break; } + pci_read_config_word(pdev, PCI_COMMAND, &cmd); + mem_access_disabled = !(cmd & PCI_COMMAND_MEMORY); + if (mem_access_disabled) { + cmd |= PCI_COMMAND_MEMORY; + pci_write_config_word(pdev, PCI_COMMAND, cmd); + } + /* Is it really there? */ io = pci_map_rom(pdev, &size); if (!io || !size) { info.size = 0; - break; + goto rom_info_out; } pci_unmap_rom(pdev, io); info.flags = VFIO_REGION_INFO_FLAG_READ; +rom_info_out: + if (mem_access_disabled) { + cmd &= ~PCI_COMMAND_MEMORY; + pci_write_config_word(pdev, PCI_COMMAND, cmd); + } + break; } case VFIO_PCI_VGA_REGION_INDEX: