Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5359116rwp; Mon, 17 Jul 2023 02:41:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlFplaT2uOFAJoVBKH+DN29wFD6qvLmQDBZMayEYV41opOgWjsjL9/qtb6OUS+pIHHvH/Gdp X-Received: by 2002:a17:907:b11:b0:992:c5ad:18bc with SMTP id h17-20020a1709070b1100b00992c5ad18bcmr9675225ejl.70.1689586897575; Mon, 17 Jul 2023 02:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689586897; cv=none; d=google.com; s=arc-20160816; b=WNkEwUO1jZo71lgec9cjBcMUD1GsZl3ZwmC95q8nFRPZpSvb2I+nSC/DJSjgGknm8r GOy9k4CuT18+5vYBtLe82JJ/YKe7FZD7N8BC1fvtpwcS8/B3RQR1JQHzFrttl+3Y7lTW de86kMAtuF88HXTyZfg2ElrNgXxXPOnHVFicjaYielbsh72iilwbqfSiJRYxUkMPpAaV xGqLtfMcqmlLPh+jjqqx1AkeNHHwDRQNnse5qi1ctlgrVbKX6o/6h+vI3Ur3v607dOAA xB0THOaiugVvHgtuswB6lB1jNuX8tB5NJkTUlPtvsS8/jfk5gSB8NV/GRoeSD68NgfWI Tfqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=Y8JNYfBYjIbnwh4BqD1zU+2zkjayx73cT2gySc48Rp0=; fh=ysDWZrWzDHcMdTBqkUa4vTdxATqRgtwmj0AHG639mko=; b=xzqmid9NfWhQCdLrTOJp3h3uRN52uW4ksntsNg5c2oVfyWEn9MMe8qAp7iZB0tunaW IAWr4JKN2SfBhlvu2zB8MRhHfPj8cKt8GdqsBDLsUlUyuBqqnzIZqRD+fDjqJ8TfYoGg 55EnDUmVtwRKaH0Io2en4/iW/evM7uQL2+LqD/3jGqwFX43EX1nXZB5AuRMVD1jZXpbh Se2XFOW4BRYXoIhO+NfWukLrK4Uyg+p0SDj1Wa4wZDd+v+If7mNQ7TdhFLuMGA5HKNf/ I5FFRf5t19F4+YO69VepJ0mVkqMU9KJpTCiyyJ+KXd7blWFl3iYlZ1fRtBeyWpipc0JX U92A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=C6Lmqx2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020a1709062b5700b00992083e604fsi13450833ejg.154.2023.07.17.02.41.12; Mon, 17 Jul 2023 02:41:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=C6Lmqx2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbjGQJJD (ORCPT + 99 others); Mon, 17 Jul 2023 05:09:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjGQJJC (ORCPT ); Mon, 17 Jul 2023 05:09:02 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E87BE55; Mon, 17 Jul 2023 02:08:59 -0700 (PDT) X-UUID: 8c62ae36248111eeb20a276fd37b9834-20230717 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=Y8JNYfBYjIbnwh4BqD1zU+2zkjayx73cT2gySc48Rp0=; b=C6Lmqx2Ebz3E6OLm0d82Ea0sCKeD77YG90SCaChLf69dmilXMlpleVvNl3WzhwgMb4mh+EKIx5Wiq7khNqWYysTMaovtS1GCWu9mxqT/A+IyPNAL/7AAj0ig8cUZD88BkB2g+uD/Jbw2V/k7Hp1rk5XginR4mMsX+aRyBRS8MRQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.28,REQID:bdf29437-4978-4b75-8c87-58bba670043e,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:100 X-CID-INFO: VERSION:1.1.28,REQID:bdf29437-4978-4b75-8c87-58bba670043e,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:100 X-CID-META: VersionHash:176cd25,CLOUDID:36b1aedc-dc79-4898-9235-1134b97257a8,B ulkID:230717170853FD2V3QFP,BulkQuantity:0,Recheck:0,SF:28|17|19|48|38|29,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_SDM,TF_CID_SPAM_ASC,TF_CID_SPAM_FAS, TF_CID_SPAM_FSD X-UUID: 8c62ae36248111eeb20a276fd37b9834-20230717 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 445378854; Mon, 17 Jul 2023 17:08:51 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 17 Jul 2023 17:08:50 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 17 Jul 2023 17:08:50 +0800 From: To: Mark Rutland , Marc Zyngier , "Daniel Lezcano" , Thomas Gleixner , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , , , Subject: [PATCH] clocksource/drivers/arm_arch_timer: Disable timer before programming CVAL Date: Mon, 17 Jul 2023 17:07:34 +0800 Message-ID: <20230717090735.19370-1-walter.chang@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham 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: Walter Chang Due to the fact that the use of `writeq_relaxed()` to program CVAL is not guaranteed to be atomic, it is necessary to disable the timer before programming CVAL. However, if the MMIO timer is already enabled and has not yet expired, there is a possibility of unexpected behavior occurring: when the CPU enters the idle state during this period, and if the CPU's local event is earlier than the broadcast event, the following process occurs: tick_broadcast_enter() tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER) __tick_broadcast_oneshot_control() ___tick_broadcast_oneshot_control() tick_broadcast_set_event() clockevents_program_event() set_next_event_mem() During this process, the MMIO timer remains enabled while programming CVAL. To prevent such behavior, disable timer explicitly prior to programming CVAL. Fixes: 8b82c4f883a7 ("clocksource/drivers/arm_arch_timer: Move MMIO timer programming over to CVAL") Cc: stable@vger.kernel.org Signed-off-by: Walter Chang --- drivers/clocksource/arm_arch_timer.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index e733a2a1927a..7dd2c615bce2 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -792,6 +792,13 @@ static __always_inline void set_next_event_mem(const int access, unsigned long e u64 cnt; ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk); + + /* Timer must be disabled before programming CVAL */ + if (ctrl & ARCH_TIMER_CTRL_ENABLE) { + ctrl &= ~ARCH_TIMER_CTRL_ENABLE; + arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk); + } + ctrl |= ARCH_TIMER_CTRL_ENABLE; ctrl &= ~ARCH_TIMER_CTRL_IT_MASK; -- 2.18.0