From patchwork Mon Aug 21 21:52:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 9914243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40485603F9 for ; Tue, 22 Aug 2017 05:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24E402867F for ; Tue, 22 Aug 2017 05:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17A70287E9; Tue, 22 Aug 2017 05:51:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7FDE02867F for ; Tue, 22 Aug 2017 05:51:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dk23K-0003Ft-JR; Tue, 22 Aug 2017 05:48:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dk23J-0003Fn-En for xen-devel@lists.xen.org; Tue, 22 Aug 2017 05:48:37 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 40/30-27137-4B5CB995; Tue, 22 Aug 2017 05:48:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVywNykQnfL0dm RBmdDLJZ8XMziwOhxdPdvpgDGKNbMvKT8igTWjJ4fnUwFq6QrXv4Nb2C8JtrFyMUhJDCNUWLD yhdMXYycHBICvBJHls1ghbD9JZqn9YPZQgI1Epc2zWEHsdkElCUufu1lA7FFBKQlrn2+zAgyi FngI7PE5APXwRLCAi4SC7/PBGtgEVCV2Hh2L9AgDg5eASeJ1/fyIOYrSEx5+J55AiP3AkaGVY waxalFZalFuoZGeklFmekZJbmJmTm6hgZmermpxcWJ6ak5iUnFesn5uZsYgb5lAIIdjJc3Bhx ilORgUhLl3ZA6K1KILyk/pTIjsTgjvqg0J7X4EKMMB4eSBG/0kdmRQoJFqempFWmZOcAgg0lL cPAoifB+PAyU5i0uSMwtzkyHSJ1iVJQS5y0C6RMASWSU5sG1wQL7EqOslDAvI9AhQjwFqUW5m SWo8q8YxTkYlYR5y0Cm8GTmlcBNfwW0mAlosWHrNJDFJYkIKakGxkXf9vx8+nezyozgWdPs3o SqFuxZ9aHVq+/jeclwg4Y9K21udE+5cGff9H2mO2S2uLo6lZkscnCsu835fH63N0eowOy3n8z ncDzO2ndkjnteg8pNXRWDfhnJktrJASfdpX/pT2D1LFtRetKDawub9Uzh7/LumeHXfkve6LPg b/DmW/H9qE3mKyWW4oxEQy3mouJEAHGc4oxnAgAA X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1503380913!72294187!1 X-Originating-IP: [192.55.52.120] X-SpamReason: No, hits=0.8 required=7.0 tests=DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11268 invoked from network); 22 Aug 2017 05:48:35 -0000 Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Aug 2017 05:48:35 -0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Aug 2017 22:48:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,410,1498546800"; d="scan'208";a="121372644" Received: from knl-rvp-beta.sh.intel.com ([10.239.48.75]) by orsmga004.jf.intel.com with ESMTP; 21 Aug 2017 22:48:30 -0700 From: Chao Gao To: xen-devel@lists.xen.org Date: Tue, 22 Aug 2017 05:52:04 +0800 Message-Id: <1503352324-13467-1-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.8.3.1 Cc: Kevin Tian , Stefano Stabellini , Wei Liu , George Dunlap , Ian Jackson , Tim Deegan , Jan Beulich , Andrew Cooper , Chao Gao , Crawford Eric R , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v7] VT-d: use correct BDF for VF to search VT-d unit X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When SR-IOV is enabled, 'Virtual Functions' of a 'Physical Function' are under the scope of the same VT-d unit as the 'Physical Function'. A 'Physical Function' can be a 'Traditional Function' or an ARI 'Extended Function'. And furthermore, 'Extended Functions' on an endpoint are under the scope of the same VT-d unit as the 'Traditional Functions' on the endpoint. To search VT-d unit, the BDF of PF or the BDF of a traditional function may be used. And it depends on whether the PF is an extended function or not. Current code uses PCI_SLOT() to recognize an ARI 'Extended Funcion'. But it is problematic for a corner case (a RC endpoint with SRIOV capability and has its own VT-d unit), leading to matching to a wrong VT-d unit. This patch reuses 'is_extfn' field in VF's struct pci_dev_info to indicate whether the PF of this VF is an extended function. The field helps to use correct BDF to search VT-d unit. Reported-by: Crawford, Eric R Signed-off-by: Chao Gao Reviewed-by: Roger Pau Monné Reviewed-by: Jan Beulich --- v7: - Drop Eric's tested-by - Change commit message to be clearer - Re-use VF's is_extfn field - access PF's is_extfn field in locked area --- xen/drivers/passthrough/pci.c | 6 ++++++ xen/drivers/passthrough/vtd/dmar.c | 2 +- xen/include/xen/pci.h | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 27bdb71..2a91320 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -599,6 +599,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, unsigned int slot = PCI_SLOT(devfn), func = PCI_FUNC(devfn); const char *pdev_type; int ret; + bool pf_is_extfn = false; if (!info) pdev_type = "device"; @@ -608,6 +609,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, { pcidevs_lock(); pdev = pci_get_pdev(seg, info->physfn.bus, info->physfn.devfn); + if ( pdev ) + pf_is_extfn = pdev->info.is_extfn; pcidevs_unlock(); if ( !pdev ) pci_add_device(seg, info->physfn.bus, info->physfn.devfn, @@ -707,6 +710,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, seg, bus, slot, func, ctrl); } + /* VF's 'is_extfn' is used to indicate whether PF is an extended function */ + if ( pdev->info.is_virtfn ) + pdev->info.is_extfn = pf_is_extfn; check_pdev(pdev); ret = 0; diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c index 82040dd..83ce5d4 100644 --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -219,7 +219,7 @@ struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *pdev) else if ( pdev->info.is_virtfn ) { bus = pdev->info.physfn.bus; - devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn; + devfn = pdev->info.is_extfn ? 0 : pdev->info.physfn.devfn; } else { diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 59b6e8a..3b0da66 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -39,6 +39,10 @@ #define PCI_SBDF3(s,b,df) ((((s) & 0xffff) << 16) | PCI_BDF2(b, df)) struct pci_dev_info { + /* + * When 'is_virtfn' is set, 'is_extfn' is re-used to indicate whether + * the PF of this VF is an extended function. + */ bool_t is_extfn; bool_t is_virtfn; struct {