From patchwork Tue Jan 26 13:12:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8121851 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D9BBA9F6DA for ; Tue, 26 Jan 2016 13:20:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1120620253 for ; Tue, 26 Jan 2016 13:20:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B518201F2 for ; Tue, 26 Jan 2016 13:20:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aO3Ws-0005Y1-Cb; Tue, 26 Jan 2016 13:19:30 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aO3RZ-00009Q-5w for linux-arm-kernel@lists.infradead.org; Tue, 26 Jan 2016 13:14:02 +0000 Received: by mail-wm0-x22d.google.com with SMTP id b14so129664969wmb.1 for ; Tue, 26 Jan 2016 05:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=df2qfvoPiG1QMRD2EnJ4P7XYhF24Rpht/SAlzJm5Nq4=; b=Xb53UEaIvJARiDr41r3v2X9nT0wYoLap3JqYptYWstKSUussp4bfAAW8ECxY9cNOho d1TQofb3KNBxfjpQx9v6YtbKtyMZPFP2EFHSnRbTkiZmw1yfm0D6gcohbSDGNfyjOJ3+ I4+8mYL2iB30VbthlVC2aKu8tDQKShz3gx8VY= 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=df2qfvoPiG1QMRD2EnJ4P7XYhF24Rpht/SAlzJm5Nq4=; b=eh3hzI7JT4G6/yGhQLIeNGLzz7lMOm1WLedAERpvzzKyHhlWublUKbDqGjzTeeitpL kifzGcMHmpfsuPKHQ7ys1wYyYScplNPnDKyuH6+j0XPx0odSp0dRk4hKl/WplBFkED/S TbeFJ8g/k+gngOAptArIidXWSZqSuBvskfHpT/+AC6NsVpjWyeUYQltpuuy6RPDBM2g9 rUMiIG/9pb+QJWv+/AYestgzrmuE9J9HSWENug63hw9SzQOaZj/xVb2kSZydWAlFxMu4 C3ivpaRUJtN689h8QU2kI4SJtYhtOPjDPLsnMkSTPY3TbcT0XeFCmisF5UcIA2dSAUU6 yEsg== X-Gm-Message-State: AG10YOQlxMkccTk3EB09D0ZMk9cRrVUEjpwaWE6rdPhal+kmFaVZ35x7mloMcEBFm8yLnMia X-Received: by 10.194.161.166 with SMTP id xt6mr25162538wjb.98.1453814019768; Tue, 26 Jan 2016 05:13:39 -0800 (PST) Received: from localhost.localdomain (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id ct2sm1388885wjb.46.2016.01.26.05.13.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 05:13:38 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, will.deacon@arm.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH 07/10] vfio: pci: cache the vfio_group in vfio_pci_device Date: Tue, 26 Jan 2016 13:12:45 +0000 Message-Id: <1453813968-2024-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453813968-2024-1-git-send-email-eric.auger@linaro.org> References: <1453813968-2024-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160126_051401_489611_669805F5 X-CRM114-Status: GOOD ( 14.70 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, suravee.suthikulpanit@amd.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new set_group operation which allows to cache the vfio_group handle within the vfio_pci_device struct. This is useful to do iommu operations from the vfio_pci device. Signed-off-by: Eric Auger --- drivers/vfio/pci/vfio_pci.c | 8 ++++++++ drivers/vfio/pci/vfio_pci_private.h | 1 + drivers/vfio/vfio.c | 3 +++ include/linux/vfio.h | 3 +++ 4 files changed, 15 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 2760a7b..2a32856 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -920,6 +920,13 @@ static void vfio_pci_request(void *device_data, unsigned int count) mutex_unlock(&vdev->igate); } +static void vfio_pci_set_group(void *device_data, struct vfio_group *group) +{ + struct vfio_pci_device *vdev = device_data; + + vdev->vfio_group = group; +} + static const struct vfio_device_ops vfio_pci_ops = { .name = "vfio-pci", .open = vfio_pci_open, @@ -929,6 +936,7 @@ static const struct vfio_device_ops vfio_pci_ops = { .write = vfio_pci_write, .mmap = vfio_pci_mmap, .request = vfio_pci_request, + .set_group = vfio_pci_set_group, }; static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 0e7394f..2893b10 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -35,6 +35,7 @@ struct vfio_pci_irq_ctx { struct vfio_pci_device { struct pci_dev *pdev; + struct vfio_group *vfio_group; void __iomem *barmap[PCI_STD_RESOURCE_END + 1]; u8 *pci_config_map; u8 *vconfig; diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 3d9de00..2760d4c 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -548,6 +548,9 @@ struct vfio_device *vfio_group_create_device(struct vfio_group *group, /* No need to get group_lock, caller has group reference */ vfio_group_get(group); + if (device->ops->set_group) + device->ops->set_group(device_data, group); + mutex_lock(&group->device_lock); list_add(&device->group_next, &group->device_list); mutex_unlock(&group->device_lock); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 0020f81..f7eaf30 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -18,6 +18,8 @@ #include #include +struct vfio_group; + /** * struct vfio_device_ops - VFIO bus driver device callbacks * @@ -42,6 +44,7 @@ struct vfio_device_ops { unsigned long arg); int (*mmap)(void *device_data, struct vm_area_struct *vma); void (*request)(void *device_data, unsigned int count); + void (*set_group)(void *device_data, struct vfio_group *group); }; extern struct iommu_group *vfio_iommu_group_get(struct device *dev);