From patchwork Tue Aug 20 14:04:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Persvold X-Patchwork-Id: 13770182 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FA53C531DC for ; Tue, 20 Aug 2024 14:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=EpVsKFQ5NF4ow0WMsc/fFRx9SO54pTzDAAtSk8M82To=; b=pHNrl8izDN1Xmx5YbEZC2XpFSC BGw/Z8HA1xRY+JlScT5kulqgqqvSDuaMqrEXNFiejA5+zsh+sxPTu5o7Wn3fL/olgiGl4kRcXSb6q TDt7wgfPOJ4kpGBpMEq5BRf1lo7RbpYjtw3zYmc+01Z8WsLq8+zwlXYAPe9hmHWrFdQNU6pNNpNsN dJOrMz0Yhn6YHKgq8qY0bJF92qgnYaClBZtxhMB0sUtjtHl7CNw24I5SF8xKeRLuamOThs1tc51CI 7lZNQwMMIPADFXGmy8tGcVmglweMIkV2J9eLF/QmN7zBc7eqWbPbjO2qn7UkZqVf+q1fsaBg+a5P/ 9P6du9mA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPWP-00000005TYK-0Mgx; Tue, 20 Aug 2024 14:07:41 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPTv-00000005Sz1-34DU for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 14:05:09 +0000 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2f040733086so54893191fa.1 for ; Tue, 20 Aug 2024 07:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724162705; x=1724767505; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EpVsKFQ5NF4ow0WMsc/fFRx9SO54pTzDAAtSk8M82To=; b=jzLJ8GKh6hJY8SwVcyh5IVROeYMyVx9wNH2L4/H8l73iKOZiX6UMMDgtAXn5z/fTAz G47pZf55VZvwk4hO3Z28QAOAvEt/DDJyuZXnzTvHVE7E7d7mRfpyOLu696yQ3KMz0yyz u8Nx3csHrRFew7IHdNnn8f3B6IsJzVPsSRMMhuaACFb6K9HRoE5fIWZSfx7RSCsVvH9S bJH6+qoLaL5PoFTmmnM3CB9gbHqQUmw+cCm68ned5PTh3NsJodgS+t0THTwgT3OpC84k eJnc6VRnB0pzC9z/iG4xq6oG7LvKoAGiRGHPlaWCCyF5Eqs6tFLTzZCChaCxGXO/6eSG bWzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724162705; x=1724767505; 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=EpVsKFQ5NF4ow0WMsc/fFRx9SO54pTzDAAtSk8M82To=; b=t7QGc8SSiL+9/eD4xPjDWxQOjv1RpAUgUluPwzGvPbNDxEgMzoy8dXf1bTiUODTrss WGRrTDRxWKwkXGaVBWjhkNkWv4RyR5noJJXWIPiDjEglxbLfoizHZ+h6sAl9hOwQa4v1 RgxO7UxeSQ2xTMqGIA6JbQm6/kYdQNgszC5Y8Q+HVnQSwHeYq/G/mTMg5XfNdQxs+DjY grBBBX2BjcwjArQ+ETSbrlyBw6TwbbtjTHj8Zlvl7OUWH6DST6BoHkUQUwZzC002/6D3 kzrqGVTW3+U6DNgKqeikH8YCflDM5SFk6q7apuoxorDbVYM+KeregwZ8quoJ7chhixRZ cQog== X-Forwarded-Encrypted: i=1; AJvYcCURSquMHwOQI1WjZ+CGjU44aOm8jjoX42yzafbMeTGyTfQavXawsXL4XFfqPDeMgH2U0ezFLX6L6UX2aJ/r405WjpJpIDYLz3c2SPjDLT1FYM/ySWo= X-Gm-Message-State: AOJu0YyEWV38hFZgLdGDW2G1nlR5FrA8CPTl2DTOf1eWd2ZO2XXTSq03 cyXDpqz6ASuMaUAu7hs3hmstewCTd2CY9PE6GFAc3lVw8rwJXTiH X-Google-Smtp-Source: AGHT+IFY1TsBmitACLqYyEqO/YS03tngiajm+rIfQ7sMYhGmY0hDJjdKGRTr8cL35/r6R0VF/c0Rgg== X-Received: by 2002:a05:651c:544:b0:2f1:a7f8:810f with SMTP id 38308e7fff4ca-2f3be5de18cmr100618031fa.36.1724162704707; Tue, 20 Aug 2024 07:05:04 -0700 (PDT) Received: from SP-RaptorLake.dyn.int.numascale.com (fwa5c9b-54.bb.online.no. [88.92.155.54]) by smtp.googlemail.com with ESMTPSA id 38308e7fff4ca-2f3b77039ffsm17908081fa.77.2024.08.20.07.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:05:04 -0700 (PDT) From: Steffen Persvold To: Will Deacon , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas Cc: spersvold@gmail.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] PCI: host-generic: Fix NULL pointer dereference on 32-bit CAM systems Date: Tue, 20 Aug 2024 16:04:23 +0200 Message-Id: <20240820140423.29410-1-spersvold@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240820_070507_798321_F980457C X-CRM114-Status: GOOD ( 17.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org CAM (legacy) host drivers also need to refer to pci_ecam_add_bus and pci_ecam_remove_bus functions to get mapped resources on 32-bit systems. This is because 32-bit systems have separate iomap resources per bus segment and pci_ecam_add_bus is the one that sets that up. Move the pci_ecam_ops for CAM mode to ecam.c so we can refer the static functions. This fixes : [ 1.356001] pci-host-generic 30000000.pci: host bridge /soc/pci@30000000 ranges: [ 1.365324] pci-host-generic 30000000.pci: MEM 0x0040000000..0x004fffffff -> 0x0040000000 [ 1.375556] pci-host-generic 30000000.pci: MEM 0x0050000000..0x006fffffff -> 0x0050000000 [ 1.386132] pci-host-generic 30000000.pci: ECAM at [mem 0x30000000-0x30ffffff] for [bus 00-ff] [ 1.399490] pci-host-generic 30000000.pci: PCI host bridge to bus 0000:00 [ 1.407073] pci_bus 0000:00: root bus resource [bus 00-ff] [ 1.413648] pci_bus 0000:00: root bus resource [mem 0x40000000-0x4fffffff] [ 1.421718] pci_bus 0000:00: root bus resource [mem 0x50000000-0x6fffffff pref] [ 1.430647] Unable to handle kernel NULL pointer dereference at virtual address 00000800 [ 1.439441] Oops [#1] [ 1.442152] CPU: 0 PID: 1 Comm: swapper Not tainted 6.9.7+ #43 [ 1.448753] Hardware name: Digilent Nexys-Video-A7 RV32 (DT) [ 1.454968] epc : pci_generic_config_read+0x40/0xb0 [ 1.460652] ra : pci_generic_config_read+0x2c/0xb0 [ 1.466322] epc : c038db9c ra : c038db88 sp : c1c3bc20 [ 1.472095] gp : c18726d0 tp : c1c5c000 t0 : 0000006e [ 1.477859] t1 : 00000063 t2 : 00000000 s0 : c1c3bc30 [ 1.483604] s1 : 00000004 a0 : 00000800 a1 : 00000800 [ 1.489348] a2 : 00000000 a3 : 00000008 a4 : c1d15800 [ 1.495090] a5 : 00000002 a6 : 0000008a a7 : c1809ec0 [ 1.500844] s2 : c1c3bc38 s3 : 0000ea60 s4 : 00000008 [ 1.506600] s5 : c1ce4a00 s6 : 00000006 s7 : c11c7460 [ 1.512353] s8 : 00000008 s9 : c0800108 s10: 00000000 [ 1.518095] s11: 00000000 t3 : 3ffff7ff t4 : 00000000 [ 1.523833] t5 : 00000001 t6 : 00000000 [ 1.528252] status: 00000100 badaddr: 00000800 cause: 0000000d [ 1.534729] [] pci_generic_config_read+0x40/0xb0 [ 1.541096] [] pci_bus_read_config_dword+0x50/0xb0 [ 1.547623] [] pci_bus_generic_read_dev_vendor_id+0x3c/0x1ec [ 1.555010] [] pci_scan_single_device+0xa4/0x11c [ 1.561273] [] pci_scan_slot+0x9c/0x23c [ 1.566716] [] pci_scan_child_bus_extend+0x58/0x2f4 [ 1.573275] [] pci_scan_root_bus_bridge+0x64/0xe8 [ 1.579650] [] pci_host_probe+0x20/0xc8 [ 1.585104] [] pci_host_common_probe+0x144/0x1e4 [ 1.591396] [] platform_probe+0x54/0x9c [ 1.596957] [] really_probe+0xbc/0x418 [ 1.602367] [] __driver_probe_device+0x70/0xfc [ 1.608507] [] driver_probe_device+0x48/0xf0 [ 1.614487] [] __driver_attach+0xbc/0x264 [ 1.620190] [] bus_for_each_dev+0x84/0xf8 [ 1.625868] [] driver_attach+0x28/0x38 [ 1.631269] [] bus_add_driver+0x140/0x278 [ 1.636956] [] driver_register+0x70/0x15c [ 1.642666] [] __platform_driver_register+0x28/0x38 [ 1.649332] [] gen_pci_driver_init+0x24/0x34 [ 1.655241] [] do_one_initcall+0x88/0x164 [ 1.660943] [] kernel_init_freeable+0x1dc/0x264 [ 1.667199] [] kernel_init+0x28/0x138 [ 1.672578] [] ret_from_fork+0x14/0x24 [ 1.678399] Code: 0463 0605 0793 0010 8663 04f4 0793 0020 8663 02f4 (2503) 0005 [ 1.686462] ---[ end trace 0000000000000000 ]--- [ 1.691591] Kernel panic - not syncing: Fatal exception Signed-off-by: Steffen Persvold --- drivers/pci/controller/pci-host-generic.c | 11 +---------- drivers/pci/ecam.c | 13 +++++++++++++ include/linux/pci-ecam.h | 3 +++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/pci-host-generic.c b/drivers/pci/controller/pci-host-generic.c index 41cb6a05..3b7da1c3 100644 --- a/drivers/pci/controller/pci-host-generic.c +++ b/drivers/pci/controller/pci-host-generic.c @@ -14,15 +14,6 @@ #include #include -static const struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = { - .bus_shift = 16, - .pci_ops = { - .map_bus = pci_ecam_map_bus, - .read = pci_generic_config_read, - .write = pci_generic_config_write, - } -}; - static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn) { struct pci_config_window *cfg = bus->sysdata; @@ -58,7 +49,7 @@ static const struct pci_ecam_ops pci_dw_ecam_bus_ops = { static const struct of_device_id gen_pci_of_match[] = { { .compatible = "pci-host-cam-generic", - .data = &gen_pci_cfg_cam_bus_ops }, + .data = &pci_generic_cam_ops }, { .compatible = "pci-host-ecam-generic", .data = &pci_generic_ecam_ops }, diff --git a/drivers/pci/ecam.c b/drivers/pci/ecam.c index 1c40d250..97430664 100644 --- a/drivers/pci/ecam.c +++ b/drivers/pci/ecam.c @@ -208,6 +208,19 @@ const struct pci_ecam_ops pci_generic_ecam_ops = { }; EXPORT_SYMBOL_GPL(pci_generic_ecam_ops); +/* CAM ops */ +const struct pci_ecam_ops pci_generic_cam_ops = { + .bus_shift = 16, + .pci_ops = { + .add_bus = pci_ecam_add_bus, + .remove_bus = pci_ecam_remove_bus, + .map_bus = pci_ecam_map_bus, + .read = pci_generic_config_read, + .write = pci_generic_config_write, + } +}; +EXPORT_SYMBOL_GPL(pci_generic_cam_ops); + #if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) /* ECAM ops for 32-bit access only (non-compliant) */ const struct pci_ecam_ops pci_32b_ops = { diff --git a/include/linux/pci-ecam.h b/include/linux/pci-ecam.h index 3a4860bd..7ebec8ce 100644 --- a/include/linux/pci-ecam.h +++ b/include/linux/pci-ecam.h @@ -77,6 +77,9 @@ void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn, /* default ECAM ops */ extern const struct pci_ecam_ops pci_generic_ecam_ops; +/* default CAM ops */ +extern const struct pci_ecam_ops pci_generic_cam_ops; + #if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) extern const struct pci_ecam_ops pci_32b_ops; /* 32-bit accesses only */ extern const struct pci_ecam_ops pci_32b_read_ops; /* 32-bit read only */