From patchwork Tue Feb 7 09:00:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 9559553 X-Patchwork-Delegate: bhelgaas@google.com 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 7CFE06047A for ; Tue, 7 Feb 2017 09:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68BAF26E98 for ; Tue, 7 Feb 2017 09:00:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D49D28307; Tue, 7 Feb 2017 09:00:17 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C3FC26E98 for ; Tue, 7 Feb 2017 09:00:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149AbdBGJAO (ORCPT ); Tue, 7 Feb 2017 04:00:14 -0500 Received: from mail-cys01nam02on0121.outbound.protection.outlook.com ([104.47.37.121]:37856 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752035AbdBGJAN (ORCPT ); Tue, 7 Feb 2017 04:00:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=0pC/kmhBVc0hbCzFwBE8qyPWtPrSPCbbzln++gSGr6s=; b=KOW0KCYPWQJK1BzgkIotH7+eHibIpH5d6h4X2+IfJUrK4YJD3ib1CM9zD2NjsfDaqzhpK9taEHz3glSxtUF6/Gn1lJpY0A0QrrIrz8Mmw+7CBPlD/9dbWV1TpYddvXYtvMsg4hnHDtd6qX6aplHrMZh7eV1OHNNtxIWm7zDud6o= Received: from MWHPR03MB2669.namprd03.prod.outlook.com (10.168.207.15) by MWHPR03MB2495.namprd03.prod.outlook.com (10.169.201.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Tue, 7 Feb 2017 09:00:10 +0000 Received: from MWHPR03MB2669.namprd03.prod.outlook.com ([10.168.207.15]) by MWHPR03MB2669.namprd03.prod.outlook.com ([10.168.207.15]) with mapi id 15.01.0888.025; Tue, 7 Feb 2017 09:00:10 +0000 From: Dexuan Cui To: Bjorn Helgaas , "linux-pci@vger.kernel.org" , "devel@linuxdriverproject.org" , Jake Oshins CC: KY Srinivasan , Stephen Hemminger , Haiyang Zhang , "olaf@aepfle.de" , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "apw@canonical.com" , "jasowang@redhat.com" , Vitaly Kuznetsov Subject: [PATCH] PCI: hv: fix wslot_to_devfn() Thread-Topic: [PATCH] PCI: hv: fix wslot_to_devfn() Thread-Index: AdKBIEKnPkYnxGJkQAaWWcqS+FlgHA== Date: Tue, 7 Feb 2017 09:00:10 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-originating-ip: [2404:f801:9000:19::23f] x-ms-office365-filtering-correlation-id: fb71e7ac-cd03-4ec0-2470-08d44f37b8a7 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:MWHPR03MB2495; x-microsoft-exchange-diagnostics: 1; MWHPR03MB2495; 7:fOaeB6lReJ5w6H6tWE860QFhCXJHyXRWSuQbmmHbqzCrJlSIjpeeRY41Z37Z9qNMRPE6vBmbjjFAGR7CZUxo8Z6djQS2kDAfmzX7df4f65wwmWhqkYHxkddF0jevaByMPLpUUhBHvwBa2xyu9cBVbm0nL12Y/Nk/2/ceuuso3+wbaOXWqWFQmbAHmig5HjVTuGCYtSuvispjzbi/ISykitMv50EBrGrhxTgobQFPxv7pJ9I4wLT78XI72TIkTbEWnn0L2fwc3mENXk8luCDEeI5oc10L11ds8SehNA/oTgMTnO1ykPoMIRI8cEo+g+2ZhoC99xfMkIRhPeFOxlQMnSFrxotv3vzVLSwR9VCHEA1pRtKXfkflqX/MHz3/EHv1InPsKRbqaGC7DNG9CrtNTcXGylNmI0C2YbpKsVAIUL23WTvg+7lMfUk8KSoY4UjOB39Kn4y7kq0wh7qRe1N8mZ4AaQG3UKyzGOqGVfidENQRtWSQ1wZAByCjh3MDpmpl8VKdIzIAu7Hp7af07h93ywQdNaUWBLHk4S7jvaIGe/4= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6040375)(601004)(2401047)(5005006)(2017020603029)(20170203043)(8121501046)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041248)(20161123560025)(20161123558025)(20161123555025)(20161123564025)(20161123562025)(6042181)(6072148); SRVR:MWHPR03MB2495; BCL:0; PCL:0; RULEID:; SRVR:MWHPR03MB2495; x-forefront-prvs: 0211965D06 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(199003)(189002)(2900100001)(7736002)(8936002)(6862003)(2906002)(86612001)(305945005)(10090500001)(53936002)(189998001)(38730400002)(92566002)(33656002)(102836003)(6116002)(4326007)(1511001)(74316002)(10290500002)(5005710100001)(101416001)(25786008)(54906002)(9686003)(99286003)(8990500004)(3660700001)(86362001)(2501003)(97736004)(2201001)(3280700002)(68736007)(106356001)(81156014)(5660300001)(2421001)(122556002)(7696004)(6636002)(81166006)(8676002)(2561002)(55016002)(50986999)(6436002)(6506006)(54356999)(105586002)(77096006); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR03MB2495; H:MWHPR03MB2669.namprd03.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Feb 2017 09:00:10.3637 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2495 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The devfn of 00:02.0 is 0x10. devfn_to_wslot(0x10) == 0x2, and wslot_to_devfn(0x2) should be 0x10, while it's 0x2 in the current code. Due to this, hv_eject_device_work() -> pci_get_domain_bus_and_slot() returns NULL and pci_stop_and_remove_bus_device() is not called. Later when the real device driver's .remove() is invoked by hv_pci_remove() -> pci_stop_root_bus(), some warnings can be noticed because the VM has lost the access to the underlying device at that time. Signed-off-by: Jake Oshins Signed-off-by: Dexuan Cui Cc: stable@vger.kernel.org Cc: K. Y. Srinivasan CC: Haiyang Zhang Cc: Stephen Hemminger Acked-by: Haiyang Zhang --- drivers/pci/host/pci-hyperv.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) The patch is co-made by Jake and me. diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 3efcc7b..cd114c6 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -130,7 +130,8 @@ enum pci_message_type { */ union win_slot_encoding { struct { - u32 func:8; + u32 dev:5; + u32 func:3; u32 reserved:24; } bits; u32 slot; @@ -485,7 +486,8 @@ static u32 devfn_to_wslot(int devfn) union win_slot_encoding wslot; wslot.slot = 0; - wslot.bits.func = PCI_SLOT(devfn) | (PCI_FUNC(devfn) << 5); + wslot.bits.dev = PCI_SLOT(devfn); + wslot.bits.func = PCI_FUNC(devfn); return wslot.slot; } @@ -503,7 +505,7 @@ static int wslot_to_devfn(u32 wslot) union win_slot_encoding slot_no; slot_no.slot = wslot; - return PCI_DEVFN(0, slot_no.bits.func); + return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func); } /*