Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5395994ybe; Tue, 17 Sep 2019 07:26:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwASJAsTANQ+7CHeqVatFx8Sa3ob10XyYPdlHrwxT9RtcYXi3kEvAgKAQfeTJUK3KxPS/77 X-Received: by 2002:a17:906:959:: with SMTP id j25mr4895040ejd.51.1568730419516; Tue, 17 Sep 2019 07:26:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568730419; cv=none; d=google.com; s=arc-20160816; b=qjiXp7gYAHBvOGaQWc8H7IYghY7VQoj8MdopBlK3jPtGLCxN6RePcYOKFUvd/wgUBc euCO8mLELiRvE4/wOCyAdYOhAiAxuNjkQszmRGwdeLocGZuEixXE44bM0ZdggVOGXFdO o+TEqlIcyQFaq33USNqwN8FzzYQSBi5K1renOI/481HS1Ap87lTBdWh03RTMHgtSDF8B 7Xc5oUigadrNfm9q7K1u8lSbWHtus4aBtfN517tM/6HE8EBPwvw1BVpQL5JifPJEURjo ciUhlGcrAVxqYwHQ9Dh8gCr2JaTUX0rF+hmvVw8e2ogRmLekiJwP9/ncdsAhZm6RZFTe TJXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=yilb8wwH8cNotDa0n1x+hR5krQKPZBg1Sm9U0VH6ruk=; b=jsKAlBd/R/qbUEQ4DopiN7v0BuOJD6HVvMfHeDlBzdt0rGUGeIicyGa6d3qjcwXIKc Uw5fJjpTaXApVeuJPh0EVsIyKJfoGy9BXsGbsN5BqC/k5PtwzGVOIxM9oJwFzXfoZqDn QMFBJ/kbGK1FZxydig7VP8M/O78twj116T1f81C9yVLFw6ar8Q7vU2+duWcaNqzE9w26 gr6xJuOI/9wbbqq3GTVtnQHyfJztntvzcEAm58AdWumNkHMLvd5mcaW7vcmEKgDCTnz0 HBnSEigQ8i+AXSZZdRhVqZdbG/SRzn8jiljRNT/NOLeRUzZ6W9AqyzL5zk4OyAv+zkYY OSuw== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si1208066ejf.152.2019.09.17.07.26.35; Tue, 17 Sep 2019 07:26:59 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391647AbfIQBFK (ORCPT + 99 others); Mon, 16 Sep 2019 21:05:10 -0400 Received: from mga04.intel.com ([192.55.52.120]:34819 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727996AbfIQBFD (ORCPT ); Mon, 16 Sep 2019 21:05:03 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Sep 2019 18:05:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,514,1559545200"; d="scan'208";a="180611983" Received: from dpdk-virtio-tbie-2.sh.intel.com ([10.67.104.71]) by orsmga008.jf.intel.com with ESMTP; 16 Sep 2019 18:05:01 -0700 From: Tiwei Bie To: mst@redhat.com, jasowang@redhat.com, alex.williamson@redhat.com, maxime.coquelin@redhat.com Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, dan.daly@intel.com, cunming.liang@intel.com, zhihong.wang@intel.com, lingshan.zhu@intel.com, tiwei.bie@intel.com Subject: [RFC v4 2/3] vfio: support checking vfio driver by device ops Date: Tue, 17 Sep 2019 09:02:03 +0800 Message-Id: <20190917010204.30376-3-tiwei.bie@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190917010204.30376-1-tiwei.bie@intel.com> References: <20190917010204.30376-1-tiwei.bie@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces the support for checking the VFIO driver by device ops. And vfio-mdev's device ops is also exported to make it possible to check whether a VFIO device is based on a mdev device. Signed-off-by: Tiwei Bie --- drivers/vfio/mdev/vfio_mdev.c | 3 ++- drivers/vfio/vfio.c | 7 +++++++ include/linux/vfio.h | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 30964a4e0a28..e0f31c5a5db2 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -98,7 +98,7 @@ static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma) return parent->ops->mmap(mdev, vma); } -static const struct vfio_device_ops vfio_mdev_dev_ops = { +const struct vfio_device_ops vfio_mdev_dev_ops = { .name = "vfio-mdev", .open = vfio_mdev_open, .release = vfio_mdev_release, @@ -107,6 +107,7 @@ static const struct vfio_device_ops vfio_mdev_dev_ops = { .write = vfio_mdev_write, .mmap = vfio_mdev_mmap, }; +EXPORT_SYMBOL_GPL(vfio_mdev_dev_ops); static int vfio_mdev_probe(struct device *dev) { diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 697fd079bb3f..1145110909e4 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1806,6 +1806,13 @@ long vfio_external_check_extension(struct vfio_group *group, unsigned long arg) } EXPORT_SYMBOL_GPL(vfio_external_check_extension); +bool vfio_device_ops_match(struct vfio_device *device, + const struct vfio_device_ops *ops) +{ + return device->ops == ops; +} +EXPORT_SYMBOL_GPL(vfio_device_ops_match); + /** * Sub-module support */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index e75b24fd7c5c..741c5bb567a8 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -56,6 +56,8 @@ extern struct vfio_device *vfio_device_get_from_fd(struct vfio_group *group, int device_fd); extern void vfio_device_put(struct vfio_device *device); extern void *vfio_device_data(struct vfio_device *device); +extern bool vfio_device_ops_match(struct vfio_device *device, + const struct vfio_device_ops *ops); /** * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks @@ -199,4 +201,9 @@ extern int vfio_virqfd_enable(void *opaque, void *data, struct virqfd **pvirqfd, int fd); extern void vfio_virqfd_disable(struct virqfd **pvirqfd); +/* + * VFIO device ops + */ +extern const struct vfio_device_ops vfio_mdev_dev_ops; + #endif /* VFIO_H */ -- 2.17.1