From patchwork Tue Jan 12 21:33:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 8021091 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@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 B54F49F859 for ; Tue, 12 Jan 2016 21:33:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D26AC2041B for ; Tue, 12 Jan 2016 21:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BF0F2041C for ; Tue, 12 Jan 2016 21:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751500AbcALVdR (ORCPT ); Tue, 12 Jan 2016 16:33:17 -0500 Received: from mga09.intel.com ([134.134.136.24]:49376 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151AbcALVdR (ORCPT ); Tue, 12 Jan 2016 16:33:17 -0500 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 12 Jan 2016 13:33:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,285,1449561600"; d="scan'208";a="28225547" Received: from jekeller-desk.amr.corp.intel.com (HELO jekeller-desk.jekeller.internal) ([134.134.3.65]) by fmsmga004.fm.intel.com with ESMTP; 12 Jan 2016 13:33:16 -0800 From: Jacob Keller To: linux-pci@vger.kernel.org Cc: Jacob Keller Subject: [PATCH] driver: add manual_bind_only option for virtual stub drivers Date: Tue, 12 Jan 2016 13:33:10 -0800 Message-Id: <1452634390-17729-2-git-send-email-jacob.e.keller@intel.com> X-Mailer: git-send-email 2.6.3.505.g5cc1fd1 In-Reply-To: <1452634390-17729-1-git-send-email-jacob.e.keller@intel.com> References: <1452634390-17729-1-git-send-email-jacob.e.keller@intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 The vfio-pci and vfio-platform drivers are intended to be used as stub drivers which can bind to any pci or platform device and are used to enable direct assignment of a host device to a guest virtual machine using IOMMU. However, today, these drivers will bind on device or driver attach, once given a dynamic id to match against. This can cause problems as the drivers may attach to devices that match an id but haven't specifically been requested using the sysfs bind interface. Add a boolean "manual_bind_only" which can be set by drivers which should only bind to devices if they have been explicitly added using the sysfs bind flow. This prevents these drivers from taking control of devices unintentionally. Signed-off-by: Jacob Keller --- drivers/base/dd.c | 6 ++++++ drivers/vfio/pci/vfio_pci.c | 3 +++ drivers/vfio/platform/vfio_platform.c | 1 + include/linux/device.h | 1 + 4 files changed, 11 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a641cf3ccad6..e21bf1d67168 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -491,6 +491,9 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) struct device *dev = data->dev; bool async_allowed; + if (drv->manual_bind_only) + return 0; + /* * Check if device has already been claimed. This may * happen with driver loading, device discovery/registration, @@ -632,6 +635,9 @@ static int __driver_attach(struct device *dev, void *data) * is an error. */ + if (drv->manual_bind_only) + return 0; + if (!driver_match_device(drv, dev)) return 0; diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 56bf6dbb93db..82f139854b56 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1045,6 +1045,9 @@ static struct pci_driver vfio_pci_driver = { .probe = vfio_pci_probe, .remove = vfio_pci_remove, .err_handler = &vfio_err_handlers, + .driver = { + .manual_bind_only = true; + }, }; struct vfio_devices { diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c index b1cc3a768784..91138ac6d1a8 100644 --- a/drivers/vfio/platform/vfio_platform.c +++ b/drivers/vfio/platform/vfio_platform.c @@ -92,6 +92,7 @@ static struct platform_driver vfio_platform_driver = { .remove = vfio_platform_remove, .driver = { .name = "vfio-platform", + .manual_bind_only = true; }, }; diff --git a/include/linux/device.h b/include/linux/device.h index b8f411b57dcb..de755bb64994 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -264,6 +264,7 @@ struct device_driver { const char *mod_name; /* used for built-in modules */ bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ + bool manual_bind_only; /* prevent bind on driver_attach */ enum probe_type probe_type; const struct of_device_id *of_match_table;