From patchwork Wed May 16 01:33:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 10402421 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 AB5B3601D4 for ; Wed, 16 May 2018 01:33:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C16D28717 for ; Wed, 16 May 2018 01:33:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90F8B2871D; Wed, 16 May 2018 01:33:43 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 2FC6D28717 for ; Wed, 16 May 2018 01:33:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752106AbeEPBdm (ORCPT ); Tue, 15 May 2018 21:33:42 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:34758 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751847AbeEPBdl (ORCPT ); Tue, 15 May 2018 21:33:41 -0400 Received: by mail-pl0-f66.google.com with SMTP id ay10-v6so1118854plb.1 for ; Tue, 15 May 2018 18:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=vbHHXnEs4QY9jEZW/4cEBccTUK9xTYAwG7YHtK7tRHE=; b=wFtGszEg09NHpm6uBTxAteX46zs6QKqD+RabJ9aq/tvj6WgtJ5p5Fw/EW8OgmZZe9j EU/HWrz2/nmaKu0KxRq/iGyJPc9HfgDy2wT/0JNb+mmPoatjgfoQcgtM5egefB4vVSwt VTsP3GTJPH3/sqwVdAXejHhSuAcok5MPoR7AbvWa2dJBQBG1WvE3negYXr+qUZgvonlx ooQJii2ePjnZBOi90NC0awR+1DM6MbXMyNE7Mfj5GWX3ZeUeuSzhnAUIqZ0RdGZHmkK7 9xkTfMRKD0GOZyrKog4V/+Regr8I0hettnu8+uIPRD6u/qO6fDOJCLvDUYLfmTdus+sF EKyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vbHHXnEs4QY9jEZW/4cEBccTUK9xTYAwG7YHtK7tRHE=; b=YmuNRDRSrEw/UCE1Ufh2sMK1nTr/xPEWBdTurKduAaA7oV57xfacQIynt2pkDIdmgs qnWvhL/X1AABsmtq9cjCuRGkN1YKB5bOaK8xT+hbkB5RaDJMEIr3dV/Jf363HW6ZHc9Y N+ZVNPAedMrqal6o9D/fCdHMd78WRmp7Kd8PPHADppN0/EPw4daUxk3ZH3sQDsk9YGKv GFXZmcTjk8Ah5K8GvpRIM0dD7cdAbOPaGzyzD6wfgIcqr0LZWwKSD/AK0kjt5Q2COySo +dE3hxkvJQMuEXNAIM7Pfkosq5/HCSL3J+dwBjVWQq0XJQ+wDSQ7ERbNo7s+37R13QoL qF0g== X-Gm-Message-State: ALKqPwc8eLs/3rt5qwZJG7z7WvvFdxQ9oU0j1/69flpRhd1aAvAa9MY8 78wfjx/rt72GbF/VuZj2lN3LWA== X-Google-Smtp-Source: AB8JxZrssS50Xv7C3H+0LByFtxzz4SiYA9PipOgFuzsSDZSZFR8fvAogiE94/+oNVMItTtRFjTuk3w== X-Received: by 2002:a17:902:684c:: with SMTP id f12-v6mr17063533pln.139.1526434421085; Tue, 15 May 2018 18:33:41 -0700 (PDT) Received: from rajat.mtv.corp.google.com ([2620:0:1000:1501:dc81:9a9e:fdee:decf]) by smtp.gmail.com with ESMTPSA id q75-v6sm1698658pfj.94.2018.05.15.18.33.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 18:33:40 -0700 (PDT) From: Rajat Jain To: Martin Mares , bhelgaas@google.com, linux-pci@vger.kernel.org Cc: Rajat Jain Subject: [PATCH] lspci: Indicate if the OS / kernel go out-of-sync on BAR Date: Tue, 15 May 2018 18:33:33 -0700 Message-Id: <20180516013333.135259-1-rajatja@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog 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 If the OS and device are reporting different BAR(s), currently the lspci will happily show the OS version with no indication what so ever that there is a problem. This is not correct in my opinion because lspci is often used to debug devices, so should either show the BAR reported by the device, or atleast an indication of out-of-sync. I spent a lot of time debugging a PCI device that would unexpectedly clear out the BAR register due to some bug, and it was quite later I realized that the lspci is showing me the OS version. So fix that. On a system that is in problem state: localhost ~ # setpci -s 1:0.0 0x10.l 00000004 <=== BAR is zeroed out localhost ~ # Before: localhost ~ # lspci -v -s 1:0.0 01:00.0 Network controller: Intel Corporation Wireless 7265 (rev 59) Subsystem: Intel Corporation Dual Band Wireless-AC 7265 Flags: bus master, fast devsel, latency 0, IRQ 275 Memory at d1400000 (64-bit, non-prefetchable) [size=8K] Capabilities: [c8] Power Management version 3 Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ Capabilities: [40] Express Endpoint, MSI 00 Capabilities: [100] Advanced Error Reporting Capabilities: [140] Device Serial Number b4-d5-bd-ff-ff-c8-a1-6d Capabilities: [14c] Latency Tolerance Reporting Capabilities: [154] L1 PM Substates Kernel driver in use: iwlwifi Kernel modules: iwlwifi After: localhost ~ # lspci -v -s 1:0.0 01:00.0 Network controller: Device 8086:095a (rev 59) Subsystem: Device 8086:5010 Flags: bus master, fast devsel, latency 0, IRQ 275 [out-of-sync] Memory at d1400000 (64-bit, non-prefetchable) [size=8K] Capabilities: [c8] Power Management version 3 Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ Capabilities: [40] Express Endpoint, MSI 00 Capabilities: [100] Advanced Error Reporting Capabilities: [140] Device Serial Number b4-d5-bd-ff-ff-c8-a1-6d Capabilities: [14c] Latency Tolerance Reporting Capabilities: [154] L1 PM Substates Kernel driver in use: iwlwifi Kernel modules: iwlwifi Signed-off-by: Rajat Jain --- lspci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lspci.c b/lspci.c index 748452c..81c65f3 100644 --- a/lspci.c +++ b/lspci.c @@ -371,6 +371,20 @@ show_range(char *prefix, u64 base, u64 limit, int is_64bit) putchar('\n'); } +static pciaddr_t +bar_value(struct device *d, int i, u32 flg) +{ + pciaddr_t val = 0; + + /* Read higher order 32 bits if it's a 64 bit bar in memory space */ + if (i < 5 && !(flg & PCI_BASE_ADDRESS_SPACE_IO) && + (flg & PCI_BASE_ADDRESS_MEM_TYPE_MASK == PCI_BASE_ADDRESS_MEM_TYPE_64)) + val = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4 * (i + 1)); + + val = (val << 32) | flg; + return val; +} + static void show_bases(struct device *d, int cnt) { @@ -401,6 +415,10 @@ show_bases(struct device *d, int cnt) flg = pos; virtual = 1; } + else if (pos != bar_value(d, i, flg)) + { + printf("[out-of-sync] "); + } if (flg & PCI_BASE_ADDRESS_SPACE_IO) { pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK;