Received: by 10.213.65.68 with SMTP id h4csp4056imn; Thu, 15 Mar 2018 14:33:10 -0700 (PDT) X-Google-Smtp-Source: AG47ELsnpWCTNNZA4jXI1+IQ/hWp6A24VC6ISXKJnuNt+nbm1+Im1BsvMV2zKCxWo3WqLTpUG27+ X-Received: by 10.99.116.30 with SMTP id p30mr7893596pgc.60.1521149590211; Thu, 15 Mar 2018 14:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521149590; cv=none; d=google.com; s=arc-20160816; b=RUEJogX1EbdGeA6+TGJ3aRTkv2XvKFJFuyAap8/Qd4/w4gmP+oRpadrBQsO9lXUAX9 2QIHFxY/VvNGCQx5O/cOpWq7Q1HDKvM3LMxBNxdc05pu9mb/m2HFvM7XLr2iiMDQdTd0 epB/1aKgmSHsJkDZl+azfShzgwphxHPK+uvnuYmQl8wucpUehrJGjJTGQx5vPpbi9WIH PH4m3pCxVQDBJmlt06XvM0IzcCNnEJLagHsN3AM53SlentCBeWdmyTiy21m7tiB5NxKV A1BY21LXrilznQEvgRBd4EELsiDF+P2hqxpAsfYA1EuiSJ+de+S6SO7ty5StudvJ4RPJ f6GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=w9pDQByIC5PGPp37Me738/SGt2IHf7cuyCWv5hN3BqU=; b=t+NQR0OBcBwwUKfoDlir+K05gQVsO06wRHWIgLkI8XlXa8I7uvkeXoLT9CpcRXfp6I aj02MnyNvyWn9x4gONWrEi1K1v+2ByDng29VviDjMaNVan9K5TOnHcdcBx1MDjEUaE++ katre9I0FFbSJe6UHO0SNTMPAIHi0Zy8WbDRXpABqgdM/uwPTQ/ZDE33NSf+s7MfWbun DxJ6aG9i244tvZ2kAcAIfHyC29mT2bDt7T18/k3YouWuAqHMyGp9zAwjT4MtQ6D/5VlN TMzpcwU8sY4a4rcHwpQ02/3cA25l5yfETl/hA8TS8ghl+nIR43lYUaHg15T3Wt1Hpd2/ dXeA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18si4300297pfi.31.2018.03.15.14.32.48; Thu, 15 Mar 2018 14:33:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932341AbeCOVbs (ORCPT + 99 others); Thu, 15 Mar 2018 17:31:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57096 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752640AbeCOVbq (ORCPT ); Thu, 15 Mar 2018 17:31:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F66876FB9; Thu, 15 Mar 2018 21:31:46 +0000 (UTC) Received: from gimli.home (ovpn-117-203.phx2.redhat.com [10.3.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CA0E2166BAE; Thu, 15 Mar 2018 21:31:41 +0000 (UTC) Subject: [PATCH v2 1/3] vfio/pci: Pull BAR mapping setup from read-write path From: Alex Williamson To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com, eric.auger@redhat.com, aik@ozlabs.ru Date: Thu, 15 Mar 2018 15:31:40 -0600 Message-ID: <20180315213140.15150.52043.stgit@gimli.home> In-Reply-To: <20180315212634.15150.88094.stgit@gimli.home> References: <20180315212634.15150.88094.stgit@gimli.home> User-Agent: StGit/0.18-102-gdf9f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 15 Mar 2018 21:31:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 15 Mar 2018 21:31:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'alex.williamson@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This creates a common helper that we'll use for ioeventfd setup. Reviewed-by: Peter Xu Reviewed-by: Eric Auger Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci_rdwr.c | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index 357243d76f10..5f2b376dcebd 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -113,6 +113,30 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf, return done; } +static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar) +{ + struct pci_dev *pdev = vdev->pdev; + int ret; + void __iomem *io; + + if (vdev->barmap[bar]) + return 0; + + ret = pci_request_selected_regions(pdev, 1 << bar, "vfio"); + if (ret) + return ret; + + io = pci_iomap(pdev, bar, 0); + if (!io) { + pci_release_selected_regions(pdev, 1 << bar); + return -ENOMEM; + } + + vdev->barmap[bar] = io; + + return 0; +} + ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { @@ -147,22 +171,13 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf, if (!io) return -ENOMEM; x_end = end; - } else if (!vdev->barmap[bar]) { - int ret; - - ret = pci_request_selected_regions(pdev, 1 << bar, "vfio"); + } else { + int ret = vfio_pci_setup_barmap(vdev, bar); if (ret) return ret; - io = pci_iomap(pdev, bar, 0); - if (!io) { - pci_release_selected_regions(pdev, 1 << bar); - return -ENOMEM; - } - - vdev->barmap[bar] = io; - } else io = vdev->barmap[bar]; + } if (bar == vdev->msix_bar) { x_start = vdev->msix_offset;