Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1857579pxb; Mon, 13 Sep 2021 07:03:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKtALHdeFps0OyKDduNn75H0MfmSNiildQTJU0Qwm5aLxn8BpFHN1FZTcIACWyPIsYNiMM X-Received: by 2002:aa7:de92:: with SMTP id j18mr13243309edv.141.1631541813656; Mon, 13 Sep 2021 07:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631541813; cv=none; d=google.com; s=arc-20160816; b=a2MQflII8k0+iMVOVWruRTw6RxUZp7MZmUdUGeNRJquQu8vFLmq/QrC4n14AiVn6WK 4BNsn5JPEQn3SGHUgKPF6aY93n+ZYfZRpowoqIPUtVBNMwLJ/ntA9qatxKt+pb1cIsBP JHvRKiuPEiFUD8EP2YIlryc0HX0Gaht/dRYNTp3NyP8MHT8jv8H0WmLASIrNajHog+zV HXGuY2+L0EDOsz05tWkEZmimOVt8J5P5Ogn5Dam9g/qT7uQeXAHLhixNNfXdUA6TosDG lOi1EKkY0Bg6s6TrjG6rLixmUe4DaC4r4ue3Qjumqow8PjF+xtr4imwrm+eCdoB7zUi6 Nueg== 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=MKrpUDmh6FzulEVrrfJcACsnuVulTsnrb43Mv1xG5LNH6UeouewO4nmYd/0QUKuEZB oiLN53C2zVsrYVIpzrncdCBAT9CW7/HjOWtywBUitaQh0/HeLfER4Id2uYOlHSZHLD9w 5scl8rH1CPkQudZd5qNHIZyDLQ7bigGPPlnQXkxG/s4ktBELg0BHpigSCiN5Ey/HeSYB 2NrH9DDoqKUxlC5lPhC/YkZX9JrsqBObYX3TmLwytOo2Hbez86mHbh/NdO2MKdqvCL9A c+OHvLHMpkgjnRD7j/DLBYl9N7F78x7t2edrONLDBn1YAOCYSk3P8uMb0dujHIiu+ZEE eGfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y2jbFhGh; 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 n25si7597456ejg.73.2021.09.13.07.03.02; Mon, 13 Sep 2021 07:03:33 -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=y2jbFhGh; 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 S244193AbhIMOCE (ORCPT + 99 others); Mon, 13 Sep 2021 10:02:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:46012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243734AbhIMN6h (ORCPT ); Mon, 13 Sep 2021 09:58:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F2BF861A02; Mon, 13 Sep 2021 13:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540204; bh=i8Y3A2oa8ZQSghVHkk4/twGApp7a2hFmEFuBUpGnYJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y2jbFhGhOSJC2ZIMLYLB8dz6hia//H14Lcu5pa5UaO/SyzwErDHqh/zEEaXHFrpyX bs/+l9Q/ujh8vs0GP7YVK8hiuGGNTrjsf0WHsCjFBr1QB9STNLGLguobXUiM4aOXeM i//ZLtPGnUjMVS6bTIB2QV8gfCl3qjMuqUXOemMQ= 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.13 063/300] clocksource/drivers/sh_cmt: Fix wrong setting if dont request IRQ for clock source channel Date: Mon, 13 Sep 2021 15:12:04 +0200 Message-Id: <20210913131111.491800130@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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