From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2105C27C4F for ; Wed, 26 Jun 2024 17:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TMmpUeG6AgeBLdnpM+s0li9NSssKRCHhHc2Ibal07EQ=; b=4kArm8jyhz3wknWT9hMW7g39cD nsMKTnNNB3qhLhVkPIhaZOyNu/BgEpjQfKA9hqcW10B/b+zfQbxJluXi8O0vb3yNlvVDF0NUpGNez 4HJ7xC/fqxe4VJtxrrRuXYY6XqQh9M5f3t8ht0t6FFYWHTkWFshB4eQgCJj53HKUh793ZZY0f3QAh MElLN9F2mTsPlY4bvZClM5BFdY5BAhyqDG3XpVNJVtfGH5sTmYAyPAJXL83FbVbv+Qg45qDhsWyWK 8eTfl9iW37DR5tdE5/66XD8ZwKzDjXzbVHcUMUm9uDuZCL/Tg5mq71aZhWgLIXmwdMNlKOpOPrAKw GAZteQng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMW7Y-00000007hyc-2Cbl; Wed, 26 Jun 2024 17:07:48 +0000 Received: from mout-p-202.mailbox.org ([2001:67c:2050:0:465::202]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMW7P-00000007hv0-2kAi for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2024 17:07:41 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4W8Smx29Hwz9sTk; Wed, 26 Jun 2024 19:07:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1719421649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TMmpUeG6AgeBLdnpM+s0li9NSssKRCHhHc2Ibal07EQ=; b=VEgcI4vveCe7PzZUbnLJjFgOYUrCLf+1Xz+DL5HQC+/XDt9dQMmvtgL0MMXOzTk8NUgFrx BkpaB1W5uFUHQCty/47PffMM72gdJ3aH9kikvegJEiBe7IlUzkUjusb6R+hMS0NOEPthgx nkasDb1OBBjtH7Ptna1yU+2yPj7jOYFXLcwPE+JxiyNDQcKchLIpvv9/6S3OcHOdmJ0v4Z h+bzjYiiGqUxLv3Xu5ocpyraPN4DN2EyeJk5QAB0jPMEgt9l3M1hvW2bO834nqBH4pcKfZ 7r7qZRlQURbkLVHtTbcbHZYJAm2AZ2jqhjfcQ86bQl8gnVFrfS3b5JM8F19neQ== Date: Wed, 26 Jun 2024 19:07:19 +0200 (GMT+02:00) From: Frank Oltmanns To: "Pafford, Robert J." Cc: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?UTF-8?Q?Guido_G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, stable@vger.kernel.org Message-ID: <1b359d7e-fe85-48ca-87aa-37ab7e34aaf6@oltmanns.dev> In-Reply-To: References: <20240310-pinephone-pll-fixes-v4-1-46fc80c83637@oltmanns.dev> <87wmmjfxcj.fsf@oltmanns.dev> Subject: Re: [PATCH v4 1/5] clk: sunxi-ng: common: Support minimum and maximum rate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Correlation-ID: <1b359d7e-fe85-48ca-87aa-37ab7e34aaf6@oltmanns.dev> X-Rspamd-Queue-Id: 4W8Smx29Hwz9sTk X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240626_100740_054763_4ED5AEDB X-CRM114-Status: GOOD ( 21.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Robert, 26.06.2024 18:03:24 Pafford, Robert J. : > Hi Frank, > > Moving to a new for loop makes sense. Let me know when you have a patch The patch is here, strange you didn't receive it: https://lore.kernel.org/all/20240623-sunxi-ng_fix_common_probe-v1-1-7c97e32= 824a1@oltmanns.dev/ > and I'll be glad to test it on my board. I do also wonder if this may > have contributed to some of the HDMI issues seen in the other thread. My thought's exactly! Best regards, =C2=A0 Frank > > Best, > Robert > >> Hi Robert, >> >> I'm truly sorry for the trouble the patch has caused you and for my late >> reply! >> >> On 2024-06-14 at 23:52:08 +0000, "Pafford, Robert J." wrote: >>>> The Allwinner SoC's typically have an upper and lower limit for their >>>> clocks' rates. Up until now, support for that has been implemented >>>> separately for each clock type. >>>> >>>> Implement that functionality in the sunxi-ng's common part making use = of >>>> the CCF rate liming capabilities, so that it is available for all cloc= k >>>> types. >>>> >>>> Suggested-by: Maxime Ripard >>>> Signed-off-by: Frank Oltmanns >>>> Cc: stable@vger.kernel.org >>>> --- >>>> =C2=A0 drivers/clk/sunxi-ng/ccu_common.c | 19 +++++++++++++++++++ >>>> =C2=A0 drivers/clk/sunxi-ng/ccu_common.h |=C2=A0 3 +++ >>>> =C2=A0 2 files changed, 22 insertions(+) >>> >>> This patch appears to cause a buffer under-read bug due to the call to = 'hw_to_ccu_common', which assumes all entries >>> in the desc->hw_clocks->hws array are contained in ccu_common structs. >>> >>> However, not all clocks in the array are contained in ccu_common struct= s. For example, as part >>> of the "sun20i-d1-ccu" driver, the "pll-video0" clock holds the 'clk_hw= ' struct inside of a 'clk_fixed_factor' struct, >>> as it is a fixed factor clock based on the "pll-video0-4x" clock, creat= ed with the CLK_FIXED_FACTOR_HWS macro. >>> This results in undefined behavior as the hw_to_ccu_common returns an i= nvalid pointer referencing memory before the >>> 'clk_fixed_factor' struct. >>> >> >> Great catch! At first glance, it seems to me that calling >> clk_hw_set_rate_range() in sunxi_ccu_probe() should not have happenend >> in the loop that iterates over the hw_clks. >> >> Instead we should add one more loop that iterates over the ccu_clks. >> Note, that there is already one such loop but, unfortunately, we can't >> use that as it happens before the hw_clks loop and we can only call >> clk_hw_set_rate_range() after the hw_clk has been registered. >> >> Hence, I propose to move the offending code to a new loop: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < desc->num_c= cu_clks; i++) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 struct ccu_common *cclk =3D desc->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=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 WARN(ccl= k->min_rate, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 "No max_rate, ignoring min_rate of clock %d - %s\n", >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 i, cclk->hw.init->name); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> >> I haven't tested (or even compiled) the above, but I'll test and send a >> patch within the next few days for you to test. >> >> Thanks again, >> =C2=A0 Frank >> >>> >>> I have attached kernel warnings from a system based on the "sun8i-t113s= .dtsi" device tree, where the memory contains >>> a non-zero value for the min-rate but a zero value for the max-rate, tr= iggering the "No max_rate, ignoring min_rate" >>> warning in the 'sunxi_ccu_probe' function. >>> >>> [...]