From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3AE363B8 for ; Mon, 20 Feb 2023 13:42:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C95DC433D2; Mon, 20 Feb 2023 13:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1676900526; bh=Lnw04X8KfxGb+Llj1Db3J9ENDXRKfJmVbkPW+rSoTY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tYrnIdRGiPa9dnPEhLT1sDtp1yXRJYr33I+44ypFj8uwEfiRXhfTSQbpYOffUFh8g I1MGGVRnOSUA6BhJCr2UYzrgmmjPEcUSJ3ToRS00s/nt221yyPaVxrYaXeOr9JkVA6 iqy9zkWB2y16TkJW2ekuTV7FLtgRBrG9eQTg2qUA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guo Ren , Guo Ren , Andrew Jones , Conor Dooley , Palmer Dabbelt Subject: [PATCH 4.19 59/89] riscv: Fixup race condition on PG_dcache_clean in flush_icache_pte Date: Mon, 20 Feb 2023 14:35:58 +0100 Message-Id: <20230220133555.220264041@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230220133553.066768704@linuxfoundation.org> References: <20230220133553.066768704@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Guo Ren commit 950b879b7f0251317d26bae0687e72592d607532 upstream. In commit 588a513d3425 ("arm64: Fix race condition on PG_dcache_clean in __sync_icache_dcache()"), we found RISC-V has the same issue as the previous arm64. The previous implementation didn't guarantee the correct sequence of operations, which means flush_icache_all() hasn't been called when the PG_dcache_clean was set. That would cause a risk of page synchronization. Fixes: 08f051eda33b ("RISC-V: Flush I$ when making a dirty page executable") Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Andrew Jones Reviewed-by: Conor Dooley Link: https://lore.kernel.org/r/20230127035306.1819561-1-guoren@kernel.org Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/mm/cacheflush.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -18,6 +18,8 @@ void flush_icache_pte(pte_t pte) { struct page *page = pte_page(pte); - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) + if (!test_bit(PG_dcache_clean, &page->flags)) { flush_icache_all(); + set_bit(PG_dcache_clean, &page->flags); + } }