From patchwork Thu Aug 1 13:14:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 816037 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp1179755wrs; Thu, 1 Aug 2024 06:15:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWIBc4HgY+glC/QzQfp9PWGxExTjRhm0otu30NUuJ6uvvJvBa2FbWLI8j00xxZIUVmG399Wk9LHt05glNmdAv54 X-Google-Smtp-Source: AGHT+IF9SsW49Im7/o82ZK1XhKEEP70r4zuSoApt92hixMzsdGF0/mTLvyD8J9+tuy3ELnjHOxJK X-Received: by 2002:a05:6102:6c6:b0:48f:e954:2426 with SMTP id ada2fe7eead31-4945bde6faamr274565137.2.1722518112330; Thu, 01 Aug 2024 06:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722518112; cv=none; d=google.com; s=arc-20160816; b=EQ4TSKy0YRI1YvUr4PVuxAR//whK4NqHuRyzZgr8uZHp64q1tP94UP5+GMYE6cWaG/ M1DGxh18cC2rdnOdrvFAKh2cQyRQ17AxQI2h/fz1fxy+dXESdXRWeiq/sAga4ZGMs0+k Gq8iU5o+mWGQYlXC+ex/b2kzkno2THv6b11JCDVLiCl3guKpPuEI8OPwxgEn7tyfE6DO L7vIIjNl2UNeKuKwl8b2uZvjROnnorQaDxe8P8sx+bKLgEYa21I/skxY0Pa9i1owT93Y GWAbx9p7zwK3MgC0VUafHqDKqjKOq8ARSZLy9xORTsHTWgVmaunI7Emv9YASCoGbSbSQ 8grg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=7jwh8lRQxFh4MuUn3bOEyy7JI6tHJM1nsPaQiEvU4+o=; fh=2wFEx+iRcfy7kqeYaueXXCV6nEjveQFYOwjKfsU0ywM=; b=rIXjGiG5sNSh3gq2RutHC1sYTn0b4spfdb/j8pegqxK7UxtM11Eo9ISgljX1FpXXzB iR6fKUJcWbsubnjTh56YNYFZ1eEfneiEn3vHtbZSBVSJ84Fj2r2+J4GepYR8iUlyXN7U rRunLBcRz2hf8aC+wyyjBiHTkrrDLfTzWRIVhIxvceb6AYEGgMioKs115dYVtkOcWK4V DZFIrqCow9ydJqGnVi9TOkdQxox0DkJLa4OnINpjX2Cuc3+7yf5Hh02wP6bT6s2TYA0M Oxl6p15fLh9USO6NZDTqYUkarRYmg01V5nwDku5PsN5nnZZeoM5vni53QRSdFl1Vj5f+ 0TbQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lpgjrqae; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ada2fe7eead31-493d98ec7a3si3446913137.629.2024.08.01.06.15.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Aug 2024 06:15:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lpgjrqae; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZVe1-0000ZP-VQ; Thu, 01 Aug 2024 09:15:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sZVe0-0000YY-I8 for qemu-devel@nongnu.org; Thu, 01 Aug 2024 09:15:00 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZVdy-0007U9-QP for qemu-devel@nongnu.org; Thu, 01 Aug 2024 09:15:00 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-52f025bc147so9761505e87.3 for ; Thu, 01 Aug 2024 06:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722518096; x=1723122896; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7jwh8lRQxFh4MuUn3bOEyy7JI6tHJM1nsPaQiEvU4+o=; b=lpgjrqae2LJ7EmskjYMD70ejmfc2Qn2TdyUpFZS75hMBSsXQs4vhGUbIcipSlDQ3Ob wSQ2zyFK3mxnTUcyddahUI9JsF/jocbSiek/3G1GcdbZmHk8FXufYqIEc7tn/erB34a0 4S6VYuIbNR6jnGZepr57Z9a6Po8epum8KCcsyQrmnT0cwM2VySs5cKZd08nUYZz6MFi1 TK1gANgi+zfiThgEVc+o46mESxzzAt08tVzcUMKqe1lgsePqVNCZVbN5Luai5nMA7+W7 IhSibZv3ZrRC95aUbxhFDUvXqN8OitUhrxXomF67qFGbN7o03N/cRSNo9eaNaAJkFQhH siQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722518096; x=1723122896; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7jwh8lRQxFh4MuUn3bOEyy7JI6tHJM1nsPaQiEvU4+o=; b=uPjsKG19uCJlj15CKgMf++Dwdg7Q8yMJ+rxSbCeDMOoaDG7U5WjNVGo9wmBLPFMUGj OcbRc+dH6Cd/7u5ZEW81PQDK2QSg6xCURTn1PmYBPat4+RlROhCqmxV7dXmHnzjS7NOj DZ7z2G1UKQKfC7qb6FLIzTj0e+jD2Is8qDUG4VLfrkoVq5u3mE6LjXOGDMyF3Kxceahl lFAjJpLKDd4ILLqD7vJEWx8sBZR56g02SOvD9IoguM6lKev9+LJxx86eespIwUwiAXSO qjEQawbkFHZkdazGam8wXDemkZW7CDgRDnWA2RA9Dm2XgpJ1+PvIkRFVyTj6pXuf0qv9 HzdQ== X-Gm-Message-State: AOJu0Yzrnz2ev46sG/PgFXMpCezwWg5eX0Y8Yh5GaUEo8l3D0fJtTjBz l6oO4VSx1/wjrOjOzxLkJo5bGTuiSBFj4/0MSIBNjcwrhiUdz9je32iI1SNDlkXDrLJ8Xm8/I6o 2L0w= X-Received: by 2002:a05:6512:2208:b0:52e:9b92:4999 with SMTP id 2adb3069b0e04-530b61a986bmr1708141e87.2.1722518096232; Thu, 01 Aug 2024 06:14:56 -0700 (PDT) Received: from m1x-phil.lan ([176.176.130.148]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acab4de47sm899780766b.67.2024.08.01.06.14.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 01 Aug 2024 06:14:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= Subject: [PATCH-for-9.1? v2] hw/pci/pci-hmp-cmds: Avoid displaying bogus size in 'info pci' Date: Thu, 1 Aug 2024 15:14:49 +0200 Message-ID: <20240801131449.51328-1-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=philmd@linaro.org; helo=mail-lf1-x133.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When BAR aren't mapped, we get: (qemu) info pci Bus 0, device 0, function 0: Host bridge: PCI device dead:beef ... BAR4: 32 bit memory at 0xffffffffffffffff [0x00000ffe]. BAR5: I/O at 0xffffffffffffffff [0x0ffe]. Check the BAR is mapped comparing its address to PCI_BAR_UNMAPPED which is what the PCI layer uses for unmapped BARs. See pci_bar_address and pci_update_mappings implementations and in "hw/pci/pci.h": typedef struct PCIIORegion { pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ #define PCI_BAR_UNMAPPED (~(pcibus_t)0) ... This improves the logging, not displaying bogus sizes: (qemu) info pci Bus 0, device 0, function 0: Host bridge: PCI device dead:beef ... BAR4: 32 bit memory (not mapped) BAR5: I/O (not mapped) Remove trailing dot which is not used in other commands format. Signed-off-by: Philippe Mathieu-Daudé --- hw/pci/pci-hmp-cmds.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c index b09fce9377..fdfe44435c 100644 --- a/hw/pci/pci-hmp-cmds.c +++ b/hw/pci/pci-hmp-cmds.c @@ -83,15 +83,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); if (!strcmp(region->value->type, "io")) { - monitor_printf(mon, "I/O at 0x%04" PRIx64 - " [0x%04" PRIx64 "].\n", - addr, addr + size - 1); + if (addr != PCI_BAR_UNMAPPED) { + monitor_printf(mon, "I/O at 0x%04" PRIx64 + " [0x%04" PRIx64 "]\n", + addr, addr + size - 1); + } else { + monitor_printf(mon, "I/O (not mapped)\n"); + } } else { - monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 - " [0x%08" PRIx64 "].\n", - region->value->mem_type_64 ? 64 : 32, - region->value->prefetch ? " prefetchable" : "", - addr, addr + size - 1); + if (addr != PCI_BAR_UNMAPPED) { + monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 + " [0x%08" PRIx64 "]\n", + region->value->mem_type_64 ? 64 : 32, + region->value->prefetch ? " prefetchable" : "", + addr, addr + size - 1); + } else { + monitor_printf(mon, "%d bit%s memory (not mapped)\n", + region->value->mem_type_64 ? 64 : 32, + region->value->prefetch ? " prefetchable" : ""); + } } }