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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C467BC77B73 for ; Tue, 30 May 2023 23:50:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2CA62860CF; Wed, 31 May 2023 01:50:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SCSH9Hvg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E81184773; Wed, 31 May 2023 00:08:52 +0200 (CEST) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 10D4584773 for ; Wed, 31 May 2023 00:08:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ghidoliemanuele@gmail.com Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f606912ebaso52777455e9.3 for ; Tue, 30 May 2023 15:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685484529; x=1688076529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fC0P/8Ww70418wAqESERzGI7wyu0R0Ma1ZUh/WQwJRM=; b=SCSH9HvguEyaS3fvXVCvGtGQ5DVQm0H9b99BIEz0UnXhD8U5eygm3FPUd3y9ZLMsAt M0ZACO0l9I4vquDZpRg8rorYmnkN7UhRSCyeflFNjdX3sZdyTYKOAUSEghFWIs8Y7cVE wyrj8rQGiwzMx8PxQM8VEkzozeu/t83oecOq+lkRLY3+BqgwK/cyGx5V/jLVJS2dlH2A NEuDmabTwi6nt6J30xOR2G8YJSAuKij9peJYpwBk9JwW8UyKwuwZxNiMfUXKM9kww5gP sBpeGP0vY3RCwlrmcv//fcvMnZus+wPAQjWTyEZCFctvexR6H/m+myhcH7bBxL3vLzOi 9UAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685484529; x=1688076529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fC0P/8Ww70418wAqESERzGI7wyu0R0Ma1ZUh/WQwJRM=; b=jJOciVc0R//IDHVXlBBhKmJS5lIgJB6NM39rVYDLhcli+5DtMIBcRcxHjoiw+tAS8E n4fH12h+rs+V5h5HrzUz6yUJixmKhO96G9bWzaviTZBhYErwIsaP7P2ewOSwOS1HgZlJ X1mOGGHLqcq1Tf6o8yVNAFY+ZbmJc+YL1FLZqKOWwx3CsO9jRigWBQwjetoowDWLPxma t12GaNkmsQoNnolQQGFQ2Ju3BUeVqJei/QjUKtNP/As8bMq3gH5gUoYOZiYDNBAgwecS cwZ++kA79Z3j8JB6iqV01ZVnHn+w17pjTFuYp6D7p99tL0l8j+DLXnkX/N8oRhLHWriy uKew== X-Gm-Message-State: AC+VfDwRSgijtPcY7aFvvhBhKrhmjPapRAmeDM+ScFyZQJbeFuFJ6oTE ZMUDv5c2/8MbXdA53gsZHdoyyclHWemGXg== X-Google-Smtp-Source: ACHHUZ4vBTsxqUq0u86/GRJlnfOs1CSx5jlf4SnVHpHbAjEwj9biTg8NiH3EY03aJJ3m59pZDcBhwA== X-Received: by 2002:a1c:ed13:0:b0:3f6:459:eba3 with SMTP id l19-20020a1ced13000000b003f60459eba3mr2759346wmh.0.1685484528982; Tue, 30 May 2023 15:08:48 -0700 (PDT) Received: from localhost.localdomain ([151.48.123.38]) by smtp.gmail.com with ESMTPSA id n15-20020a1c720f000000b003f6cf9afc25sm18338995wmc.40.2023.05.30.15.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 15:08:48 -0700 (PDT) From: Emanuele Ghidoli To: u-boot@lists.denx.de, Simon Glass , Heinrich Schuchardt Cc: Francesco Dolcini , Emanuele Ghidoli Subject: [RFC PATCH 1/1] arm: add invalidate_dcache_all() after disable cache Date: Wed, 31 May 2023 00:08:35 +0200 Message-Id: <20230530220835.2358955-2-ghidoliemanuele@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530220835.2358955-1-ghidoliemanuele@gmail.com> References: <20230530220835.2358955-1-ghidoliemanuele@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Wed, 31 May 2023 01:50:08 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Emanuele Ghidoli On Cortex-R5 flushing and disabling cache is not enough to avoid cache and memory incoherence. In particular, when the cache is enabled after a disable, and if there are entry in the cache the value from the cache is used instead of the value from the memory. This, in particular, lead to stack corruption if the stack is in a cached area. The commit 44df5e8d30a2 ("arm: move flush_dcache_all() to just before disable cache") already states that following a cache disable an invalidate is expected to be done but without coping with cache enable. So just add it explicitly. Signed-off-by: Emanuele Ghidoli --- arch/arm/lib/cache-cp15.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c index 0893915b3004..2921277d69e0 100644 --- a/arch/arm/lib/cache-cp15.c +++ b/arch/arm/lib/cache-cp15.c @@ -254,7 +254,15 @@ static void cache_disable(uint32_t cache_bit) if (cache_bit == CR_C) #endif flush_dcache_all(); + set_cr(reg & ~cache_bit); + +#ifdef CONFIG_SYS_ARM_MMU + if (cache_bit == (CR_C | CR_M)) +#elif defined(CONFIG_SYS_ARM_MPU) + if (cache_bit == CR_C) +#endif + invalidate_dcache_all(); } #endif -- 2.34.1