From patchwork Tue Dec 30 08:21:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ethan zhao X-Patchwork-Id: 5551631 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 99295BF6C3 for ; Tue, 30 Dec 2014 08:21:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AE21A20172 for ; Tue, 30 Dec 2014 08:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 881DB20121 for ; Tue, 30 Dec 2014 08:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbaL3IVI (ORCPT ); Tue, 30 Dec 2014 03:21:08 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:28118 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751479AbaL3IVH (ORCPT ); Tue, 30 Dec 2014 03:21:07 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id sBU8L0kf018472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 30 Dec 2014 08:21:01 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sBU8KxUJ008501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 30 Dec 2014 08:21:00 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sBU8Kxmw029147; Tue, 30 Dec 2014 08:20:59 GMT Received: from localhost.localdomain.com (/10.182.70.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 30 Dec 2014 00:20:58 -0800 From: Ethan Zhao To: bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ethan.kernel@gmail.com, Ethan Zhao Subject: [PATCH] PCI: export pci device assignment info as read only via sysfs Date: Tue, 30 Dec 2014 17:21:47 +0900 Message-Id: <1419927707-14462-1-git-send-email-ethan.zhao@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] 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, T_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 This patch exports assignment flag of PCI device via sysfs, so user space application could know if PCI device was assigned to guest OS or not via interface as following from viewpoint of host device management: PCI device was assigned to guest OS $cat /sys/devices/pci0000:00/0000:00:1f.3/assigned 1 PCI device isn't assigned to guest OS $cat /sys/devices/pci0000:00/0000:00:1f.3/assigned 0 Compiled and tested with v3.18.1 Signed-off-by: Ethan Zhao --- drivers/pci/pci-sysfs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 2c6643f..0ac3780 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -547,6 +547,15 @@ static ssize_t driver_override_show(struct device *dev, } static DEVICE_ATTR_RW(driver_override); +static ssize_t assigned_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + + return sprintf(buf, "%d\n", pci_is_dev_assigned(pdev) ? 1 : 0); +} +static DEVICE_ATTR_RO(assigned); + static struct attribute *pci_dev_attrs[] = { &dev_attr_resource.attr, &dev_attr_vendor.attr, @@ -573,6 +582,7 @@ static struct attribute *pci_dev_attrs[] = { &dev_attr_devspec.attr, #endif &dev_attr_driver_override.attr, + &dev_attr_assigned.attr, NULL, };