Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1885594pxb; Mon, 13 Sep 2021 07:31:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4Qi+q0muOpHLbN5FMY7RsDNX6twZT/GG0aaAM36xe4inX5KShYw6jDSzGyfP/2+C9oo60 X-Received: by 2002:a17:906:8450:: with SMTP id e16mr13104764ejy.305.1631543515246; Mon, 13 Sep 2021 07:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631543515; cv=none; d=google.com; s=arc-20160816; b=iu9gKnOalILcEuw4U1gFur1fWnS8eBl3qiP8rBRtdL5+Uxl6DKDOQPJJ1+Ab0Vzfvf zpjn4YuULg+9BkWwBFbsFfmd++9LNR2klEsSknZR3J/dTRfraVc6zKddC/4XNUYg0IeZ +GXgLX2v7q1UFZbIAwIO/m4yckGc+thu0hAMwFiu62/5EfX34+JWQu57zI1VZeFRhnrg gFAKE7XRCfk9ZFjPwFgE3hFujEPaH67WtSgIc5daGYFB3oxQz8gx+THieowRhVM9gWhy FAe5mn+1VzH0K+PG4AwvaMmU7onl7g3z8a8DkqmtmXUm9Tzlh0D/G2mfwNnbi9zWI6xT FJ1A== 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=jITXNrfxIImgNRiy3IXRL9TecF80W3/l+cVgzy1Si4M=; b=OqRZSwRW/s30UBK7NzykLCJuNKoJTeN9PPTwYV0Mnsn0iz8jHNaxBx7mSqOififo0O uVRcgX6cWp0rcMEcTNpjN2tHa5n4Dm3+YwW2oFkkxh2P7kGI4o1bjWQFCcHnRUQ6xQNd 4SRFjsE8XaMiVBpu0EfkZ3HsqxaHMTKZlPi5bc3ZSqrAm5A+DvlwHmUFbXXvQ9t91jKB FvGL/Q2FNlvNs37JUQSy9rFLT8tf2PdEsp/TbjsV0IPgq9saBRTRN3ck1R5y5A0cDxRy MvC7l3cAdqwrKcIFmD2Rv1CBFk68gft+0lRUYTcrM41F+b7YD4S5bFCfkJU+4knZdKfr /9WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wGyfgJka; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si10236317edj.221.2021.09.13.07.31.29; Mon, 13 Sep 2021 07:31:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wGyfgJka; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347221AbhIMOab (ORCPT + 99 others); Mon, 13 Sep 2021 10:30:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:46948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344380AbhIMO03 (ORCPT ); Mon, 13 Sep 2021 10:26:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66DC561B53; Mon, 13 Sep 2021 13:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540938; bh=i8Y3A2oa8ZQSghVHkk4/twGApp7a2hFmEFuBUpGnYJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wGyfgJkaXaC/8DMjnYAFXISbKdq9/ll1MiO2r6BIKNThO1pK2F4iu+Hl0vs41wq16 bMT1IGEofED/2elb4/5CBZUSIwmAlzs0Dnu8JOxXDFRlJA7kHIXgFJ5BLK4SSKvA60 T9RZ4fWBCYGFu+YZc2WsTQtvwdZLKsNoGh8kvK9U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phong Hoang , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Daniel Lezcano , Sasha Levin Subject: [PATCH 5.14 064/334] clocksource/drivers/sh_cmt: Fix wrong setting if dont request IRQ for clock source channel Date: Mon, 13 Sep 2021 15:11:58 +0200 Message-Id: <20210913131115.576551367@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131113.390368911@linuxfoundation.org> References: <20210913131113.390368911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phong Hoang [ Upstream commit be83c3b6e7b8ff22f72827a613bf6f3aa5afadbb ] If CMT instance has at least two channels, one channel will be used as a clock source and another one used as a clock event device. In that case, IRQ is not requested for clock source channel so sh_cmt_clock_event_program_verify() might work incorrectly. Besides, when a channel is only used for clock source, don't need to re-set the next match_value since it should be maximum timeout as it still is. On the other hand, due to no IRQ, total_cycles is not counted up when reaches compare match time (timer counter resets to zero), so sh_cmt_clocksource_read() returns unexpected value. Therefore, use 64-bit clocksoure's mask for 32-bit or 16-bit variants will also lead to wrong delta calculation. Hence, this mask should correspond to timer counter width, and above function just returns the raw value of timer counter register. Fixes: bfa76bb12f23 ("clocksource: sh_cmt: Request IRQ for clock event device only") Fixes: 37e7742c55ba ("clocksource/drivers/sh_cmt: Fix clocksource width for 32-bit machines") Signed-off-by: Phong Hoang Signed-off-by: Niklas Söderlund Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20210422123443.73334-1-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Sasha Levin --- drivers/clocksource/sh_cmt.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index d7ed99f0001f..dd0956ad969c 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -579,7 +579,8 @@ static int sh_cmt_start(struct sh_cmt_channel *ch, unsigned long flag) ch->flags |= flag; /* setup timeout if no clockevent */ - if ((flag == FLAG_CLOCKSOURCE) && (!(ch->flags & FLAG_CLOCKEVENT))) + if (ch->cmt->num_channels == 1 && + flag == FLAG_CLOCKSOURCE && (!(ch->flags & FLAG_CLOCKEVENT))) __sh_cmt_set_next(ch, ch->max_match_value); out: raw_spin_unlock_irqrestore(&ch->lock, flags); @@ -621,20 +622,25 @@ static struct sh_cmt_channel *cs_to_sh_cmt(struct clocksource *cs) static u64 sh_cmt_clocksource_read(struct clocksource *cs) { struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); - unsigned long flags; u32 has_wrapped; - u64 value; - u32 raw; - raw_spin_lock_irqsave(&ch->lock, flags); - value = ch->total_cycles; - raw = sh_cmt_get_counter(ch, &has_wrapped); + if (ch->cmt->num_channels == 1) { + unsigned long flags; + u64 value; + u32 raw; - if (unlikely(has_wrapped)) - raw += ch->match_value + 1; - raw_spin_unlock_irqrestore(&ch->lock, flags); + raw_spin_lock_irqsave(&ch->lock, flags); + value = ch->total_cycles; + raw = sh_cmt_get_counter(ch, &has_wrapped); + + if (unlikely(has_wrapped)) + raw += ch->match_value + 1; + raw_spin_unlock_irqrestore(&ch->lock, flags); + + return value + raw; + } - return value + raw; + return sh_cmt_get_counter(ch, &has_wrapped); } static int sh_cmt_clocksource_enable(struct clocksource *cs) @@ -697,7 +703,7 @@ static int sh_cmt_register_clocksource(struct sh_cmt_channel *ch, cs->disable = sh_cmt_clocksource_disable; cs->suspend = sh_cmt_clocksource_suspend; cs->resume = sh_cmt_clocksource_resume; - cs->mask = CLOCKSOURCE_MASK(sizeof(u64) * 8); + cs->mask = CLOCKSOURCE_MASK(ch->cmt->info->width); cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; dev_info(&ch->cmt->pdev->dev, "ch%u: used as clock source\n", -- 2.30.2