From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.194.15 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796421898; b=kNqqPBq/S7h0oDF1riravDx7FPwy1cLzwckS8A2E95/jCXU0CN4QmdsPEynNdqTgyc8q 9pMRrqw6DzapDkqu13QaK/ihXfETpHsm9rGs8qybBnE4unXB0krfEVg7+QZULh6DN4eiq 4Nm2vT+jO7CGzpwQOLoq1GBm3e8YL5Gqcxi/xxOT3XiC8zGPTuIElnpVGH5mFTknlgfLI 67ijOrI9zt809kVZLxS/TPRG3yjLIFuWd/t0IQHncOijedMYlxhnKHfdNJXk6P69TXUzw qXEZw7ci/6YUxzITybBxqBq/oP7XvKhqr9fXjF5qaXvbWq07WomPcpGaWwQVTum0AVQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796421898; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-ID:References:In-Reply-To:To:CC:X-Mailer:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=aa2xv1xcOEbSxbM/FfL8ysHE1oN9+KCceVx/lr7NbqY=; b=EbXhBsahLxLtxYs18JS2UQamHNM0nUXRUIw+nzeuDPoAehJPX82bBSLAlGbmdVvn6gSO ftc9i/Xg7NBxkDG9T/Htkem1eS+zEVk1RujpEh+ABmyk6aSQUcczbiLDXKTyVSvtznzNA Rbf80QabvuSZ51OWtHZWEYjaRvQ/MxS7zlDRYLVnvfXE+avXOimsUYgLLyAZ1LfLcMo+r 9zZOL9ArHHcAx3pSQPrhFJxw0uVbLe0FiozrB3izx9xURN0MD0SYMeSO1sCcE+fkyz7uG GvWRjnlYn2DOsxc5A29lA9l/HrEdeOw8mi4QTlmk/NEsMz6hmKipnmIA/ck+MLk1ong== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=P1Wdkx75; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.194.15 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011015.outbound.protection.outlook.com [40.93.194.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67A87606A687; Fri, 4 Dec 2026 22:04:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67A87606A687 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=P1Wdkx75 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JMUy+Zg1i5miF8vn+FXiqbDkAYKIQc0TTMiHuzGWNn9kjuQaEiJGZE+d3Ikf8wXy4siNvgGPCq6OwXby7lqZ4k6NWAupMPWVP78SCwodRlMM3aFFc1t5cP8SWFPM6eDgJFFcu7KUl3MxQCcBMMNSLH0KFaBo90Wz9pD9B/pQLIDIdwX0I+FtuS3H+udG5n9xaLKDraJkFx8hwANT3Iu1AWUb8UsWeyhcBIe4jx3QUrrXR/yV2XqJsB+iN+HCniLlYppJg6/y8ipU6rIVPRFREyzQW2NYNl2XtjVf18/w6I6NYiSNlhUw7pZN8GMMPYtGiDQReWjl7iM88Rfxk29NBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aa2xv1xcOEbSxbM/FfL8ysHE1oN9+KCceVx/lr7NbqY=; b=QvJO4yPf5X5E2iPFR39DgviWPvRYe3/othFG1bOs0EzZqgCIZYw9STsVSZig9Gbugz1iE5pS+cBTUixM/Tlm/rAUP8vjEVt2hJ9T9A++nqTc7to+bkPxH/Lu45BgIcfKaCfK00odgS55QSN8GBjU0Un00Y96gpdQYXLD1W74/pJpzs6LxgwGImNMDhffWh9JibnI2OR0kBWipnTJWBgkVl/XVLeg4cfVeZRSM3RD9FMiFsJw8063j1vMPrHsyuezMP/h0TeV1AYocrlxIAoLTgwBi5SGNqxC+OrqRzcr0uFRt3V8MMprlOKuvw23pO0NQjgC4OaQRjwfblVD1ThcVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aa2xv1xcOEbSxbM/FfL8ysHE1oN9+KCceVx/lr7NbqY=; b=P1Wdkx75q2WoE7mTtnRwM6cbIv5EJi4kE1TRYr8BIm+c+7S/sdGrTPUJpSXbzgEsiGTddpfX0etpJ0RIXyCMVJ1R0mTEYXUXkVI5assUHB0CYRRqIgZSzBCU0sEmYCWjBJDz7QNtIZB5Sz+SxD/WnqQmYZohbz+Q9dQv8BU73+U= Received: from BL1PR13CA0237.namprd13.prod.outlook.com (2603:10b6:208:2bf::32) by DS0PR12MB8573.namprd12.prod.outlook.com (2603:10b6:8:162::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Fri, 4 Dec 2026 22:04:52 +0000 Received: from BL4PEPF000003F3.namprd04.prod.outlook.com (2603:10b6:208:2bf:cafe::15) by BL1PR13CA0237.outlook.office365.com (2603:10b6:208:2bf::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.709.7 via Frontend Transport; Fri, 4 Dec 2026 22:04:52 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL4PEPF000003F3.mail.protection.outlook.com (10.167.249.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Fri, 4 Dec 2026 22:04:52 +0000 Received: from [10.11.96.223] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 16:04:50 -0600 From: "Nikhil P. Rao" Date: Fri, 4 Dec 2026 22:04:22 +0000 Subject: [PATCH net v2 3/5] ionic: fix PHC reads racing the BAR unmap on PCI reset X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20261204-b4-pr60-v2-3-9e0b5408a68e@amd.com> References: <20261204-b4-pr60-v2-0-9e0b5408a68e@amd.com> In-Reply-To: <20261204-b4-pr60-v2-0-9e0b5408a68e@amd.com> To: Brett Creeley , Andrew Lunn , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Richard Cochran CC: , , Eric Joyner , Abhijit Gangurde , "Allen Hubbe" , "Nikhil P. Rao" X-Mailer: b4 0.15.2 X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PEPF000003F3:EE_|DS0PR12MB8573:EE_ X-MS-Office365-Filtering-Correlation-Id: cad104f6-0e7d-4aa0-494d-08df52529f84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|36860700016|376014|1800799024|261028144727099003|22082099003|18002099003|261026140227099003|56012099006|261021135927099003|10067099003|261009223027099003|11063799006|261026121527099003|261021123027099003|261021121427099003|261102123227099003|261022075727099003|261022105027099003; X-Microsoft-Antispam-Message-Info: DZnCcx6UAd/cgtxdgUipVHP+80TJnZ9ITz5eYge6eAJE2S9pILPmnyvAQb4svfnJtDpZxH6Ey36ZIFiP9RNXn6D/UDomXSXUqA74QojeEGQPrMjcB9C7YmvdLQNnOFA64tBY4iuSbert8zwCzLhl7BcwOFkFOPmoZ5fW9D1h9ZqHUBOQ3GtTCBRTpJ0a4RosRTyUKHBG2Ps4p5ulbwRPDpXaTt/b3PxOIbeodj0bvFFWwZZywezEgqWbmdHWYU6RhxKVoZE3/y+twfKomnZX17zt4OCDolzPps/Zzp76LpMfksbj12r2hDdktEgkwRiL9v9ZmY0RH98Ui3ewo2C0ECxmL2eIpN2DoeGvAvfEMB3Jks/RwkdGGfNUEya073MqkjOB52cAFT/U4ry+X4yfsLrLaHrnmle3DsbegKScaKkrFWM2ipdIdJ5t+nR/SsKzRzUdo8YF1EoJXxjeO/M57NwrWLjSzQvicRBwG3PT4/a4Q247AsEOHNaqta5vtaqao/32XIFYFrrpbKPj/JhYb39SKLWrjcvta2+uPu1Qf8FNR6ajNfjyrUX7Nfm/Kjx5ZhfnblZF04hgVtpPvXFRi7tQCxpCGtyWt4EsbwX2C7jrIYCapqNyWn8DhOSEO2ihOFOLT/TJ8U/RmdEeDYkdLAkG1SeL2dnx8UVuW6HgIayRzbxa4eo6DBdSV0Yvk6V3xfjNUMUTFDhC6T77aVd42A== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(82310400026)(36860700016)(376014)(1800799024)(261028144727099003)(22082099003)(18002099003)(261026140227099003)(56012099006)(261021135927099003)(10067099003)(261009223027099003)(11063799006)(261026121527099003)(261021123027099003)(261021121427099003)(261102123227099003)(261022075727099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tGQJ8/4ARxRYLwretQqemQwyfStJXZKLWJBUM2sW9XL+r0fS7DWhkvGTLMwqT4JWk5V8W29KMdCW4NsYApLsi5eYB3LoKxOLc80mBEYQXJtOkn7dgRrBqK43qJ0Pu+ebYWkByqoRqxToT/MkDJeACLdTgXP/h7kAIr2Ydzx4tfr8bzkfHaoiylfJR7LqPrPC/ubMsaCv+X61ARUoRwaKdyzPLvg8sUuagZFbanfhlpqpWNyfym3+ql5SrI8HGVqwb9Qjf8HcxdvsaKoShA8dEM9GuJCnNDqmdg5XMzlnPfd5wrNcn/q+g/r8GXpih3P5a+juB2TOOTU1juvhjGakGNQ0EzJ5AIiCon5KGcknpydVPDaJ/9z07UdD8wzrdd1GscS0lxsUWjze4vxRn5OdEuBRWgE8lx9t4k2s3NDJdPz0zG3MzyaShMl9E/OYt9Zt X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 22:04:52.6515 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cad104f6-0e7d-4aa0-494d-08df52529f84 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL4PEPF000003F3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8573 ionic_dev_setup() points idev.hwstamp_regs into the BAR0 mapping, but a PCI reset unmaps BAR0 with the pointer still set. The PHC stays registered across the reset, and its operations test FW_RESET without a lock before reading the counter, so one that passed the test just before the reset reads the unmapped BAR. Make phc->lock protect the pointer. The timecounter reads the counter through a callback that cannot report a failure, so each operation has to check the pointer before it starts the update, and the pointer must not change until the update ends. ionic_dev_setup() no longer sets the pointer, since it also runs during reset done, outside phc->lock. Reproduced on an AMD Pensando NIC, on a kernel with KASAN and lockdep, by holding phc_ctl get after the FW_RESET test in ionic_phc_gettimex64() with a test-only kprobe module while a PCI reset ran, flushing the local TLB so the stale mapping faults: without this patch the counter read faults, with it the read finds hwstamp_regs cleared. Fixes: a79b559e99be ("ionic: add FLR recovery support") Reported-by: sashiko-bot@kernel.org # Running on a local machine Reviewed-by: Brett Creeley Signed-off-by: Nikhil P. Rao --- drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 16 ++++++++++++++++ drivers/net/ethernet/pensando/ionic/ionic_dev.c | 2 -- drivers/net/ethernet/pensando/ionic/ionic_lif.h | 2 +- drivers/net/ethernet/pensando/ionic/ionic_phc.c | 20 +++++++++++++++++--- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c index 07bc61d6f964..1c283280ce83 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c @@ -444,6 +444,19 @@ static void ionic_remove(struct pci_dev *pdev) ionic_devlink_free(ionic); } +static void ionic_phc_set_regs(struct ionic_lif *lif, + struct ionic_hwstamp_regs __iomem *regs) +{ + unsigned long irqflags; + + if (!lif->phc) + return; + + spin_lock_irqsave(&lif->phc->lock, irqflags); + lif->ionic->idev.hwstamp_regs = regs; + spin_unlock_irqrestore(&lif->phc->lock, irqflags); +} + static void ionic_reset_prepare(struct pci_dev *pdev) { struct ionic *ionic = pci_get_drvdata(pdev); @@ -452,6 +465,7 @@ static void ionic_reset_prepare(struct pci_dev *pdev) dev_dbg(ionic->dev, "%s: device stopping\n", __func__); set_bit(IONIC_LIF_F_FW_RESET, lif->state); + ionic_phc_set_regs(lif, NULL); timer_delete_sync(&ionic->watchdog_timer); cancel_work_sync(&lif->deferred.work); @@ -480,6 +494,8 @@ static void ionic_reset_done(struct pci_dev *pdev) if (err) goto err_out; + ionic_phc_set_regs(lif, &ionic->idev.dev_info_regs->hwstamp); + ionic_debugfs_add_sizes(ionic); ionic_debugfs_add_lif(ionic->lif); diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.c b/drivers/net/ethernet/pensando/ionic/ionic_dev.c index 5ec5af41141a..ce6944f24734 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_dev.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.c @@ -418,8 +418,6 @@ int ionic_dev_setup(struct ionic *ionic) idev->intr_status = bar->vaddr + IONIC_BAR0_INTR_STATUS_OFFSET; idev->intr_ctrl = bar->vaddr + IONIC_BAR0_INTR_CTRL_OFFSET; - idev->hwstamp_regs = &idev->dev_info_regs->hwstamp; - sig = ioread32(&idev->dev_info_regs->signature); if (sig != IONIC_DEV_INFO_SIGNATURE) { dev_err(dev, "Incompatible firmware signature %x", sig); diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.h b/drivers/net/ethernet/pensando/ionic/ionic_lif.h index e790f6b9441e..5def4ae13863 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.h +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.h @@ -248,7 +248,7 @@ struct ionic_lif { }; struct ionic_phc { - spinlock_t lock; /* lock for state_page, cc and tc */ + spinlock_t lock; /* lock for state_page, cc, tc and idev.hwstamp_regs */ struct cyclecounter cc; struct timecounter tc; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_phc.c b/drivers/net/ethernet/pensando/ionic/ionic_phc.c index 388150cbf7e4..2631bc3e9580 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_phc.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_phc.c @@ -377,6 +377,10 @@ static int ionic_phc_adjfine(struct ptp_clock_info *info, long scaled_ppm) adj += phc->init_cc_mult; spin_lock_irqsave(&phc->lock, irqflags); + if (!phc->lif->ionic->idev.hwstamp_regs) { + spin_unlock_irqrestore(&phc->lock, irqflags); + return -EBUSY; + } /* update the point-in-time basis to now, before adjusting the rate */ timecounter_read(&phc->tc); @@ -437,6 +441,10 @@ static int ionic_phc_settime64(struct ptp_clock_info *info, ns = timespec64_to_ns(ts); spin_lock_irqsave(&phc->lock, irqflags); + if (!phc->lif->ionic->idev.hwstamp_regs) { + spin_unlock_irqrestore(&phc->lock, irqflags); + return -EBUSY; + } timecounter_init(&phc->tc, &phc->cc, ns); @@ -466,6 +474,10 @@ static int ionic_phc_gettimex64(struct ptp_clock_info *info, return -EBUSY; spin_lock_irqsave(&phc->lock, irqflags); + if (!ionic->idev.hwstamp_regs) { + spin_unlock_irqrestore(&phc->lock, irqflags); + return -EBUSY; + } tick = ionic_hwstamp_read(ionic, sts); @@ -495,6 +507,10 @@ static long ionic_phc_aux_work(struct ptp_clock_info *info) return phc->aux_work_delay; spin_lock_irqsave(&phc->lock, irqflags); + if (!phc->lif->ionic->idev.hwstamp_regs) { + spin_unlock_irqrestore(&phc->lock, irqflags); + return phc->aux_work_delay; + } /* update point-in-time basis to now */ timecounter_read(&phc->tc); @@ -576,9 +592,6 @@ void ionic_lif_alloc_phc(struct ionic_lif *lif) u64 features; u32 shift; - if (!ionic->idev.hwstamp_regs) - return; - features = le64_to_cpu(ionic->ident.lif.eth.config.features); if (!(features & (IONIC_ETH_HW_TIMESTAMP | IONIC_ETH_HW_RDMA_TIMESTAMP))) return; @@ -672,6 +685,7 @@ void ionic_lif_alloc_phc(struct ionic_lif *lif) /* frequency adjustments are relative to the initial multiplier */ phc->init_cc_mult = phc->cc.mult; + ionic->idev.hwstamp_regs = &ionic->idev.dev_info_regs->hwstamp; timecounter_init(&phc->tc, &phc->cc, ktime_get_real_ns()); /* Update cycle_last at 1/4 the wrap period, or IONIC_PHC_UPDATE_NS */ -- 2.43.0