Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4444884ioa; Wed, 27 Apr 2022 04:08:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyuPu18tgnDxk/2ATArxGoLRmfKyWdsbTC2RFzsdAi210gz5nn7+n9s2Ye6b+UxVYkTQ4S X-Received: by 2002:a63:5747:0:b0:381:54b9:b083 with SMTP id h7-20020a635747000000b0038154b9b083mr23277003pgm.178.1651057735565; Wed, 27 Apr 2022 04:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651057735; cv=none; d=google.com; s=arc-20160816; b=zmzef2oKEzFk/4+8t11pY6CzJpyL0EmmLCcfAcr/66uAC3slSAF6QHDQsc/23iYLtK Mq9fxwdSNPWBnHI2Ls5+O1nCsREqousWo1IBgX/Y0FBsI4oDTofvtnvYkYqPsiGpDhYJ XDUCoyRnMrmoXbl9TSKzGmjIuCC4jwJXp7mpdTIuK4La3Brq3s2T3wsDGOdFB0wZo23G GN2VaglJaFI9geR5K1SLtSSulDlr+9ixkDMuERl19YawCZEJ2lIq+izS9FZuQnKmZtsL OcwsKXMYLO5SlGHiTFNCdF95oAwxSe8tV6fVt12zVLTFS+Y/6PDlQDf9ZpZt/OBTO1hz wlTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iOV1SR6KURiDppKXWZIsZnmCZNwq/d5UxBp9gvV/MeM=; b=ODSo+D/hsmUV7zV1k9jeGJ4TkbJjBph/ZDRbp6g6T7LHUCiIAYLUgQAmKuJOq2zm5k amkDNAY0dLppUKxJGwx2SzduBpwdNaQrDt5m500ajL9suJa+TbxLKJqMgzWRlSIcEqOY K/48DhxdTlJ/RcXNJSoQn4ROQtCoMQSqS/Mwv7/Av4c/0E4K1b32D5XgHEl7sbumpotn XsyR23UJiTvv317BGDRTB8E9jy6HYfZJZTrGu8bbtu8FAcA+wbKvy3eeiP/1vv5Bw9CS ABoeVMZjghEpp0YGcqD8JPuUq/k1827B5jhfNQ19W9ulbhOR77kkpm6yse8f4YXPmMB7 0+pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1S55xpgU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a7-20020a63d207000000b003aa2a2bf527si1249066pgg.610.2022.04.27.04.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1S55xpgU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C20DAAE33; Wed, 27 Apr 2022 03:03:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242978AbiDZJRi (ORCPT + 99 others); Tue, 26 Apr 2022 05:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346347AbiDZIuB (ORCPT ); Tue, 26 Apr 2022 04:50:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B49CC90C3; Tue, 26 Apr 2022 01:38:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 718036090C; Tue, 26 Apr 2022 08:38:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77142C385A0; Tue, 26 Apr 2022 08:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962287; bh=1OWTHQQH1jcO8sBBchXhD6ZyJQdD/B6PmUizs65gAqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1S55xpgUGNP+j5OvUz2ON9E5LZZsm09oJH9uUZ0ITM/7N9PM8NRrq737iceWeQwSp +tjBIH0J9xou8UpbaQ/KpaYWzebMypI5klYNtzXnTKS4yLF3YgVlqoWytn/orUnqLa /r2GVNroBiwAD7+KNR4wtTgO9GpO661FBYJJSkV0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kevin Hao , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 047/124] net: stmmac: Use readl_poll_timeout_atomic() in atomic state Date: Tue, 26 Apr 2022 10:20:48 +0200 Message-Id: <20220426081748.638899495@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Hao [ Upstream commit 234901de2bc6847eaa0aeb4aba62c31ffb8d3ad6 ] The init_systime() may be invoked in atomic state. We have observed the following call trace when running "phc_ctl /dev/ptp0 set" on a Intel Agilex board. BUG: sleeping function called from invalid context at drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c:74 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 381, name: phc_ctl preempt_count: 1, expected: 0 RCU nest depth: 0, expected: 0 Preemption disabled at: [] stmmac_set_time+0x34/0x8c CPU: 2 PID: 381 Comm: phc_ctl Not tainted 5.18.0-rc2-next-20220414-yocto-standard+ #567 Hardware name: SoCFPGA Agilex SoCDK (DT) Call trace: dump_backtrace.part.0+0xc4/0xd0 show_stack+0x24/0x40 dump_stack_lvl+0x7c/0xa0 dump_stack+0x18/0x34 __might_resched+0x154/0x1c0 __might_sleep+0x58/0x90 init_systime+0x78/0x120 stmmac_set_time+0x64/0x8c ptp_clock_settime+0x60/0x9c pc_clock_settime+0x6c/0xc0 __arm64_sys_clock_settime+0x88/0xf0 invoke_syscall+0x5c/0x130 el0_svc_common.constprop.0+0x4c/0x100 do_el0_svc+0x7c/0xa0 el0_svc+0x58/0xcc el0t_64_sync_handler+0xa4/0x130 el0t_64_sync+0x18c/0x190 So we should use readl_poll_timeout_atomic() here instead of readl_poll_timeout(). Also adjust the delay time to 10us to fix a "__bad_udelay" build error reported by "kernel test robot ". I have tested this on Intel Agilex and NXP S32G boards, there is no delay needed at all. So the 10us delay should be long enough for most cases. Fixes: ff8ed737860e ("net: stmmac: use readl_poll_timeout() function in init_systime()") Signed-off-by: Kevin Hao Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c index a7ec9f4d46ce..d68ef72dcdde 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c @@ -71,9 +71,9 @@ static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec) writel(value, ioaddr + PTP_TCR); /* wait for present system time initialize to complete */ - return readl_poll_timeout(ioaddr + PTP_TCR, value, + return readl_poll_timeout_atomic(ioaddr + PTP_TCR, value, !(value & PTP_TCR_TSINIT), - 10000, 100000); + 10, 100000); } static int config_addend(void __iomem *ioaddr, u32 addend) -- 2.35.1