From patchwork Tue Nov 5 17:18:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 840816 Delivered-To: patch@linaro.org Received: by 2002:a5d:6307:0:b0:381:e71e:8f7b with SMTP id i7csp108240wru; Tue, 5 Nov 2024 09:19:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV+Fukw9qocP/uJGWSvPW5bMnrqzYegmTNA5P9ABk0nMW6AYS4Ri6p8D1RdaepT4QduzeoJWA==@linaro.org X-Google-Smtp-Source: AGHT+IEZnIsdpvG9KvbE7yjPucyAnn2oXDRIk7ot8z19g+FdNh01KCsqweyQwQPHrNHVJYoxkXqf X-Received: by 2002:a05:622a:14c6:b0:461:5571:5cc6 with SMTP id d75a77b69052e-462b8755fc8mr253439161cf.46.1730827144284; Tue, 05 Nov 2024 09:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730827144; cv=none; d=google.com; s=arc-20240605; b=Go1cOXPn3PJfKAn4i3qupnzMFW6WjDZ84gV71x1fF7y278IVdD2K5jyLW9wynuDCkS /LQH1vSNIMZiLGNQIx0NIb6SOIhaXs4Zb89Te5C83b7q/MO2DVH9Yl62Ch6bxUKp5lu9 nzsolyZtlGbIRJ+KVG4cgjk5GkHyynODe7Sd+aVp+oAm/AG6YoiiJaSeK36j3L/NAjjE zJZXzjfQIq95OWSsWOWew3VQbIOYRZ2bitWzwYXIDf53j6ONDHo7qOP+ihO7rH0M8Cc0 QAHZ0hyc9RXWM0NZ9bjQ4BE6Fa+pmN0dyXnzSU1OkWodFqe5kNN6rFAesK6y8AHeG07w wUSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=si1GAzVFo9p7658TUKQsKQkHM9JnDZDIhZcoRXj69KM=; fh=2C5A39z2KCyjUY0QB5XkqkBxXGjPA9giu90EbtX3r9g=; b=GW8GJq0QzbDfi0Ng4236mbZL0a8URIWEI1i+2Bm47mhfWTiR8IAqISXFPekScv99bn 8+7FbnCJF/MuQdB6EA3r6SqeU/80SzSAes6Wb1whvQz+ko0PHkz0QjZts5GpaKfQAwar U2Ba9yhcUOEu8RQnYBn75jUAsX0WAdrgALK7kLESM5LElxPIZpPneUlJvok1kZml2X0X h5T+AO+R7/uyztj/rgHeo6XgWb0Ez+rM+HfcD11YFPWP49e7yniD3XIwGtiZPU+EIPhk WUEpSLOnC9XmiHr3GhvSJvk/851CcGKX1Fif7JlVTOqWAgUksmTo9B3uxtXfkL25bId3 L4TQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d6+s1AYu; 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 d75a77b69052e-462ad0d26d0si145398071cf.184.2024.11.05.09.19.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Nov 2024 09:19:04 -0800 (PST) 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=d6+s1AYu; 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 1t8NC8-0001hi-Fg; Tue, 05 Nov 2024 12:18:20 -0500 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 1t8NC7-0001hE-4H for qemu-devel@nongnu.org; Tue, 05 Nov 2024 12:18:19 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8NC5-0007qy-Cu for qemu-devel@nongnu.org; Tue, 05 Nov 2024 12:18:18 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-431695fa98bso45153525e9.3 for ; Tue, 05 Nov 2024 09:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730827095; x=1731431895; 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=si1GAzVFo9p7658TUKQsKQkHM9JnDZDIhZcoRXj69KM=; b=d6+s1AYuc/EjF0UFVJ3RhNSaj/DNdNjpcMnHakCLB9PXUDsm2134MmQd27obv017LF Z68J9A6TH2xBNtPF6IEbSHEqXAAIJKs8vYNVwPFCc4h/Iq6fOAsPXSH3ye/FU8ZfHAoo 3DPlIx4qOJHKCryj0ivDEcjIfV/pIiPeYacppR/eGnD7umBo4lodCNLb8PgpylVMiqzf X2gSxfagk5beLowjm8TKNmaLFEyS9w02PRm4GIDZ2aIsqkskXn1fJDeHHumDlx7Blvuj tJcKIGt044/bYPGSXCGlZUb0wptk94kHpUnGH0XF2LNUG+riJnZjl76iO5trevS21PEX uR7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730827095; x=1731431895; 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=si1GAzVFo9p7658TUKQsKQkHM9JnDZDIhZcoRXj69KM=; b=TEntwREauOjPTy1smLiUGzKhKxMdhwCFzZsKkPdB//RyTt7EzpKQkSJ50YOZ1ZuTsE sz9jV9codC2LJUipEOvby1lUeFvNGQd1CAhzaikEqpQyUXcUxTetoUbVIK8y8+RRz/zs yzEqW/oNZVHkE0X8vvGoIm87lJUzrWVEEibnzFX3mPfz6ZUzycagmpp88BlMYeQe5KFx ZOhoZGeUD1yqO94Jj+g8ubtQj5/Atrz1uoQXKXczI7IZsZe76goGnOTfcPIq6jOviOTc OKPAQuReZu3To6fqMfSrdiZLbpd6w+6jWIN/wElBr4ojpWjbfG4P96SAUW5m8ER9Oyap GrWw== X-Gm-Message-State: AOJu0YyKg4CTnvWCdc8qcbtKtMCXbOVyOLc/9wDDCT8YMXnoyvJ6vOBt DIZnF6ICNK63508efKHT1PvEozcP61fgiGU2msxFxzG291l5IBGrDXylRbqV/1DClS+Wn/bl4Oz V X-Received: by 2002:a05:600c:1d1d:b0:42f:4f6:f8f3 with SMTP id 5b1f17b1804b1-4319ac6fbf7mr323454725e9.7.1730827095190; Tue, 05 Nov 2024 09:18:15 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd947c0esm235361215e9.24.2024.11.05.09.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 09:18:14 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum , David Woodhouse Subject: [PATCH] hw/i386/pc: Don't try to init PCI NICs if there is no PCI bus Date: Tue, 5 Nov 2024 17:18:13 +0000 Message-Id: <20241105171813.3031969-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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 The 'isapc' machine type has no PCI bus, but pc_nic_init() still calls pci_init_nic_devices() passing it a NULL bus pointer. This causes the clang sanitizer to complain: $ ./build/clang/qemu-system-i386 -M isapc ../../hw/pci/pci.c:1866:39: runtime error: member access within null pointer of type 'PCIBus' (aka 'struct PCIBus') SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/pci/pci.c:1866:39 in This is because pci_init_nic_devices() does &bus->qbus which is undefined behaviour on a NULL pointer even though we're not actually dereferencing the pointer. (We don't actually crash as a result, so if you aren't running a sanitizer build then there are no user-visible effects.) Make pc_nic_init() avoid trying to initialize PCI NICs on a non-PCI system. Cc: qemu-stable@nongnu.org Fixes: 8d39f9ba14d64 ("hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices()") Signed-off-by: Peter Maydell Reviewed-by: Bernhard Beschow --- This shows up if you run "make check" on a ubsan build. --- hw/i386/pc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2047633e4cf..1af1a1a1823 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1251,7 +1251,9 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus) } /* Anything remaining should be a PCI NIC */ - pci_init_nic_devices(pci_bus, mc->default_nic); + if (pci_bus) { + pci_init_nic_devices(pci_bus, mc->default_nic); + } rom_reset_order_override(); }