From patchwork Thu Oct 10 03:50:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bibo Mao X-Patchwork-Id: 13829447 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 BABBDCEDDBB for ; Thu, 10 Oct 2024 03:51:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D52E26B008A; Wed, 9 Oct 2024 23:50:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CDCE56B008C; Wed, 9 Oct 2024 23:50:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A90A36B0092; Wed, 9 Oct 2024 23:50:58 -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 822836B008A for ; Wed, 9 Oct 2024 23:50:58 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05922C1A28 for ; Thu, 10 Oct 2024 03:50:55 +0000 (UTC) X-FDA: 82656316596.08.82DB07B Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by imf28.hostedemail.com (Postfix) with ESMTP id 6AD79C0004 for ; Thu, 10 Oct 2024 03:50:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728532119; 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; bh=GhqZgEmhO01NNuYz9LQ6ht12zOqcVK4S3QCK4DG4Y1Y=; b=18V1iHSYNqOBDJThb4CVflgg92gKJglDLJnLI4yPYEuR7HJb184MMBtYinYVWlNE1cjqrS UVBfbLf1BNCGc5VHE7/IM4ts0m2D0cKL7kMumzB5Z1a+bdRNNcEm3FFME8RVQoNdcdQLbn YdQVzf8moekPcHUszWyrKcrf60OR1hk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728532119; a=rsa-sha256; cv=none; b=eKcYoyzjmUgwccJXP8IrZy6C4KIjEk6M0QahvjT7k7swn8LbTR1v970dkQDCZKbTuXhKUF lqK1MTmfDQKW69pdngYjEvXVXhzHBVXYb/6BKgskLPqi+z7DnRQv4P6O5Q7pEAInHEyZJM vSOckEaONO37r6mi87cmuQfAtrJZQWI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of maobibo@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=maobibo@loongson.cn; dmarc=none Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8CxbWsbTwdn4bsRAA--.25946S3; Thu, 10 Oct 2024 11:50:51 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowMDx7tUZTwdnFP8hAA--.52915S6; Thu, 10 Oct 2024 11:50:51 +0800 (CST) From: Bibo Mao To: Huacai Chen , Andrey Ryabinin , Andrew Morton Cc: David Hildenbrand , Barry Song , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: [PATCH 4/4] LoongArch: Use atomic operation with set_pte and pte_clear function Date: Thu, 10 Oct 2024 11:50:48 +0800 Message-Id: <20241010035048.3422527-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20241010035048.3422527-1-maobibo@loongson.cn> References: <20241010035048.3422527-1-maobibo@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowMDx7tUZTwdnFP8hAA--.52915S6 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Stat-Signature: ms8z7ksz357nnzk4aq3kk8nch8osu883 X-Rspamd-Queue-Id: 6AD79C0004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1728532255-516521 X-HE-Meta: U2FsdGVkX1/aOSbm5HvRUz4vv0Vgmc161UXWp9BlVH+5E+pYc4DeQcDI+DB4v4kICJic6YzuXJhadWP4bB9/SzViHsadJEK+Gl9lWllR5M2iNuKZ/EegzFvWexwPYhu5fvLRDkTh4AIMS+tdnMu9Pbg8RN1gGOkwLUbQb1moYHEEVUmqnR9HR9Z5Zz1AoKlAZ5FTkazkbbHHrJAApH4ufAnTXy8hiBRAnAz0J4C2cZKESg/hwtdKTUYEzuTMxJi/Q+DpiEi3GdB/RR55UeW+h96/a3DZFpdu4HPp4xpDqXaTwN7FlnPpxcUvkvUDbStO92pS0kFD1ws4BmCK9JMXnh1JGUmYIBo8vE0//03W9AMlQE0mG0JTo5Ow2UwSjiVU5y3Ji6TNKsNfIfcSwhDWsBw2N+s/9+1n3Y6FbnuigIQIF7hOk4Rj7JwLMf93czgeA5nfPx3NVlfFXrJUTeemp05ut0/eR3sqjWXPVe20zlbSJ1ATYXx74cz5AETQXUrj5JoSRhNCFGyhabwgv70iTuX+4/mzZfxdpz+VeDYbJkt0bki4KdLYgGAbf/kXocVIEB/jjgQKqrH4CB1Fm8qAHx8b5Q8+ki1pALpJ7I7+KhOE8DWTPpFzapD/aZtoPHuikFco7Js/9JM+KSX7bxaRnVDVtp15YvrAcTqoC5UUsWYdlzZKoil1tjPf0mZ4C3ZFnWVIcP/JYwhF+MO9Lfq0i+LfDi3DM3pj7EZvp+ip2RBQcX8CxeX1z+39+uzltKO/Sjn7U7CS/K7wwPvBxLuHbIElQyZnacmKsnKIpuGQBASM61Euy/EuFkILhsohmefGZsA9PonzZfGZRWT6oDaKbKhe7bUsxQhV8gPbxSOt5R2XLIMlRon+HzUO2hHbjLIvu+XQMAtKCNRskf4SaCG0bMTiZd4LoOvz/p9RRVofBq9+YoW4xxWA7Fj8d23ZdzJR/a+1j0+5opFdF0xrsow bW8PMQXz EFRYADFbEzbhOs5O3D3xTdkfvrLSSr9bf01XiKQX/ntdXHi2UJKGKS4XJdwueKaBGaaudxZCzg8VoZSLxbiTzOK00aqPmeAk0FSj/rjj6ytmE1RYtSiuhOpZczVLBE+E1UsmA2GJrhklMAQKcBjz5gGvelQ== 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: List-Subscribe: List-Unsubscribe: For kernel space area on LoongArch system, both two consecutive page table entries should be enabled with PAGE_GLOBAL bit. So with function set_pte() and pte_clear(), pte buddy entry is checked and set besides its own pte entry. However it is not atomic operation to set both two pte entries, there is problem with test_vmalloc test case. With previous patch, all page table entries are set with PAGE_GLOBAL bit at beginning. Only its own pte entry need update with function set_pte() and pte_clear(), nothing to do with buddy pte entry. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/pgtable.h | 44 ++++++++++------------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index 22e3a8f96213..4be3f0dbecda 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -325,40 +325,26 @@ extern void paging_init(void); static inline void set_pte(pte_t *ptep, pte_t pteval) { WRITE_ONCE(*ptep, pteval); +} - if (pte_val(pteval) & _PAGE_GLOBAL) { - pte_t *buddy = ptep_buddy(ptep); - /* - * Make sure the buddy is global too (if it's !none, - * it better already be global) - */ - if (pte_none(ptep_get(buddy))) { -#ifdef CONFIG_SMP - /* - * For SMP, multiple CPUs can race, so we need - * to do this atomically. - */ - __asm__ __volatile__( - __AMOR "$zero, %[global], %[buddy] \n" - : [buddy] "+ZB" (buddy->pte) - : [global] "r" (_PAGE_GLOBAL) - : "memory"); - - DBAR(0b11000); /* o_wrw = 0b11000 */ -#else /* !CONFIG_SMP */ - WRITE_ONCE(*buddy, __pte(pte_val(ptep_get(buddy)) | _PAGE_GLOBAL)); -#endif /* CONFIG_SMP */ - } - } +static inline unsigned long __ptep_get_and_clear(pte_t *ptep) +{ + return atomic64_fetch_and(_PAGE_GLOBAL, (atomic64_t *)&pte_val(*ptep)); } static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { - /* Preserve global status for the pair */ - if (pte_val(ptep_get(ptep_buddy(ptep))) & _PAGE_GLOBAL) - set_pte(ptep, __pte(_PAGE_GLOBAL)); - else - set_pte(ptep, __pte(0)); + __ptep_get_and_clear(ptep); +} + +#define __HAVE_ARCH_PTEP_GET_AND_CLEAR +static inline pte_t ptep_get_and_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) +{ + unsigned long val; + + val = __ptep_get_and_clear(ptep); + return __pte(val); } #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)