From patchwork Sun Oct 23 13:32:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 13016268 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2200AC433FE for ; Sun, 23 Oct 2022 13:33:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83D5E900005; Sun, 23 Oct 2022 09:33:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7ECE1900002; Sun, 23 Oct 2022 09:33:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B4B8900005; Sun, 23 Oct 2022 09:33:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5DA87900002 for ; Sun, 23 Oct 2022 09:33:56 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3F70B1A0597 for ; Sun, 23 Oct 2022 13:33:56 +0000 (UTC) X-FDA: 80052307272.26.79DF2A5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id D20361C003E for ; Sun, 23 Oct 2022 13:33:55 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0CC6660E97; Sun, 23 Oct 2022 13:33:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55DEDC433C1; Sun, 23 Oct 2022 13:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666532034; bh=HM2oYzakfdXfJJzbe5qVxXYIO2tAmfA0Z3AF7nO+COs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+LaVmkYWNM8WRyG7XrRI2PdMKBhVkMak40G66C7VtwH/Kr0Zl+kaP9Lc4w9DZarR aPv6uKX+1AHYRXKEgTublGNogmX+cYSNu2CZY40m6LRy36Er0uipUDC4eWo3HcNRfm dXeTPt13+wyzYnotwEdF3XT72+LTd9DKpn7UJmF5w/Xl2mS+rphOSvB8Y6AG4HR/0m mrP5NC1mukgGEXbdcRCv2TbiA05MdenMXkR+HiezGv+RexxXv41Dekska9vb8uqSlX nlOcZ965NqKjt9iFjG8efAclxrCruGeiuxHP9I4ifNH0zHm9xf/OUDGAwCxOhKJPDl TtQqLUtUwGzgg== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, palmer@rivosinc.com, heiko@sntech.de, arnd@arndb.de, songmuchun@bytedance.com, catalin.marinas@arm.com, chenhuacai@loongson.cn, Conor.Dooley@microchip.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org, Guo Ren , Will Deacon , Steven Price Subject: [PATCH 1/2] riscv: Fixup race condition on PG_dcache_clean in flush_icache_pte Date: Sun, 23 Oct 2022 09:32:04 -0400 Message-Id: <20221023133205.3493564-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221023133205.3493564-1-guoren@kernel.org> References: <20221023133205.3493564-1-guoren@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666532035; a=rsa-sha256; cv=none; b=WPnQRxw2jvyVokURlOo+a7u4Tz74giOtcT5+y6hJft7oWmIZUa/Df5fqmc9bTTPw5c08cx 89iWR27PIv0IC7kV2FDY/Hr4UU2JWPfqSzNywCHX100Tvd5ReYQMGSW2PW4l8STNmlrneW zop/71RpcR4GvinyghTrTkZWSOp92Ms= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J+LaVmkY; spf=pass (imf20.hostedemail.com: domain of guoren@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=guoren@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666532035; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wc77EUO46tkZmvjhga1NyWr3AzK6MXwnC5/wsCI+pnM=; b=sesCppgWAVS3J4H3gXoj0sNfY9z1Lr8JjGwRfv1KBG+Q3fdVHK0SC6IWPf0vJ0pn6Fagu9 aQVhZoYx676qJ0pl7nJsLVQF85Zk50LhHcZc+tOTksSgl/L1FPQor8Cq+xrWuXCJ9efcy/ W5XZOT5tAqGSZnr105wyedRMU0FIoD8= X-Stat-Signature: 1q7jos1ke9s1pzabtbgsg7mio8mjdqgt X-Rspamd-Queue-Id: D20361C003E Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J+LaVmkY; spf=pass (imf20.hostedemail.com: domain of guoren@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=guoren@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1666532035-626574 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Guo Ren RISC-V follows the arm64 flush_icache_pte mechanism and also includes its bug. The patch ensures that instructions are observable in a new mapping. For more details, see 588a513d3425 ("arm64: Fix race condition on PG_dcache_clean in __sync_icache_dcache()"). Signed-off-by: Guo Ren Signed-off-by: Guo Ren Cc: Catalin Marinas Cc: Will Deacon Cc: Steven Price --- arch/riscv/mm/cacheflush.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 6cb7d96ad9c7..7c9f97fa3938 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -82,7 +82,9 @@ 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); + } } #endif /* CONFIG_MMU */ From patchwork Sun Oct 23 13:32:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 13016269 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87B3EC433FE for ; Sun, 23 Oct 2022 13:34:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29721940007; Sun, 23 Oct 2022 09:34:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24796900002; Sun, 23 Oct 2022 09:34:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11032940007; Sun, 23 Oct 2022 09:34:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 015BC900002 for ; Sun, 23 Oct 2022 09:34:02 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B4B66140862 for ; Sun, 23 Oct 2022 13:34:02 +0000 (UTC) X-FDA: 80052307524.03.8E8A79E Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf05.hostedemail.com (Postfix) with ESMTP id 42766100010 for ; Sun, 23 Oct 2022 13:34:01 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4A247B80D5E; Sun, 23 Oct 2022 13:34:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D109C43470; Sun, 23 Oct 2022 13:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666532040; bh=HgCI1fwpCRV6cbIVNToGS+BLd1ULTdQix8qchtvlux4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVFtjHfSb8Pix+ZODNxlJQR5O5aUXDkMSRquLor3ywU7ifraASh1B9mCOEjvSpmhi 5pwloxojUVQPEPJ2nXi5g1JVDuDE1h3HpRLY42daghXEUPTF7NpE69kjP4CO1wc0ML OzbFYnrf6HzV8oxKV1yp5MMhWhLI4SLmS2V+DRTzZxBvEFKaEvXBlJ6KnhO+lYL3dI 1IWrS6h4wVbfMAXen6V8wN5llaAW/lK3lOeEvN7oClwG3ggzWrMfgYvsVvCq5yv/EB qeU0OFXs587rqByUX1KKY/7/nHUUujPncosY2MQnzIcadA2hayGkXIyo9eL+kUJ0RU yMZXSDWBeTMUQ== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, palmer@rivosinc.com, heiko@sntech.de, arnd@arndb.de, songmuchun@bytedance.com, catalin.marinas@arm.com, chenhuacai@loongson.cn, Conor.Dooley@microchip.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org, Guo Ren Subject: [PATCH 2/2] riscv: Enable ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP Date: Sun, 23 Oct 2022 09:32:05 -0400 Message-Id: <20221023133205.3493564-3-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221023133205.3493564-1-guoren@kernel.org> References: <20221023133205.3493564-1-guoren@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AVFtjHfS; spf=pass (imf05.hostedemail.com: domain of guoren@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=guoren@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666532042; a=rsa-sha256; cv=none; b=o1J3lLW9Azq6ECDj+sK4ZWPOofm//GsyznbvfrUnWjAsO3964jmKJXd3Y1ri/o9Kx2cRUT OPvAR9pzWI18ePnlpsChvgM/apra4zRdipbOF9mrby8lGfquh2Vz87RXfbQXqrD7BlbwKI dToOmPn7IJY3xfG1bZj/SvmC8EX8Eig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666532042; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v4QrxhegU7dUYq1gGHr11j/aNsrU+3Q41V6qvRIggk4=; b=V9jg4zZeO3Nh5Huc91kzgrSbdNuDLqF0DHgaL8fz/XOu881ebMybgMsksYmo6R7grm31NY BFTRggeoZSlbDUjhKfJ5/V3CktN8tMvbUOYyQXK6WnxfDZFl9GM+NsPNe8gttCdzFQIF0A Eh/Ys0cmIUxkqErP1wUiA5q+qCDpUB8= Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AVFtjHfS; spf=pass (imf05.hostedemail.com: domain of guoren@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=guoren@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: m6rfec1oezfwgnnthog4is8myzcayx6p X-Rspamd-Queue-Id: 42766100010 X-HE-Tag: 1666532041-222088 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Guo Ren This patch enable the feature of "free some vmemmap pages of HugeTLB page" [1]. To make it work correct, we also need fixup PG_dcache_clean setting for huge page [2]. [1] https://lore.kernel.org/linux-doc/20210510030027.56044-1-songmuchun@bytedance.com/ [2] https://lore.kernel.org/linux-mm/20220302084624.33340-1-songmuchun@bytedance.com/ Signed-off-by: Guo Ren Signed-off-by: Guo Ren Cc: Muchun Song Cc: Huacai Chen Cc: Arnd Bergmann Acked-by: Muchun Song --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/cacheflush.h | 3 +++ arch/riscv/mm/cacheflush.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 6b48a3ae9843..81ac25b0e005 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -45,6 +45,7 @@ config RISCV select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_GENERAL_HUGETLB select ARCH_WANT_HUGE_PMD_SHARE if 64BIT + select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU select BUILDTIME_TABLE_SORT if MMU diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index 8a5c246b0a21..96f7381aeeeb 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -17,6 +17,9 @@ static inline void local_flush_icache_all(void) static inline void flush_dcache_page(struct page *page) { + if (PageHuge(page)) + page = compound_head(page); + if (test_bit(PG_dcache_clean, &page->flags)) clear_bit(PG_dcache_clean, &page->flags); } diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 7c9f97fa3938..ca35807cf185 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -82,6 +82,9 @@ void flush_icache_pte(pte_t pte) { struct page *page = pte_page(pte); + if (PageHuge(page)) + page = compound_head(page); + if (!test_bit(PG_dcache_clean, &page->flags)) { flush_icache_all(); set_bit(PG_dcache_clean, &page->flags);