From nobody Wed Nov 27 06:37:18 2024 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A10061A7259 for ; Mon, 14 Oct 2024 03:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728878342; cv=none; b=ou22oUGKxwcOp2WkGri8xm5prn6phA5tScLNtKKmaXuN4xM2BtiybMBYJvAbm1v0z1jHtZ8wL2sCbBpvISvC+95WK7ZYnglwo5mtrloKfc1JyZc2yblkkpIEqKG5/pAXy+jkdP29p98gcvkcdx/9BralwI5gcAmRTzyhoiOpSbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728878342; c=relaxed/simple; bh=ptzeV/KUkyoX894HxvO+FYV/s0m195mvVeaeLYKJ5W4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EUEGQvY6g9E9U7JP0DtijoucVhVOp66pfY5oQdh0hLE6MkyKTnVS5+lnUp8UG0+c6tPfgOEYydf1F7S69B8KTflNbVXCp7OZK3gz/2weqSsBze/bbVUYh+DJDILrXaxUCczMfhdyL1tHLw6uPy+/Glxm5DEIx0BTPbXe+i8/0mg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8AxhokClwxnkgIaAA--.37545S3; Mon, 14 Oct 2024 11:58:58 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowMBxXuT_lgxnc6EoAA--.1717S5; Mon, 14 Oct 2024 11:58:57 +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 v2 3/3] LoongArch: Remove pte buddy set with set_pte and pte_clear function Date: Mon, 14 Oct 2024 11:58:55 +0800 Message-Id: <20241014035855.1119220-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20241014035855.1119220-1-maobibo@loongson.cn> References: <20241014035855.1119220-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowMBxXuT_lgxnc6EoAA--.1717S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" For kernel address 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 pte buddy entry. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/pgtable.h | 35 ++++------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/= asm/pgtable.h index 22e3a8f96213..bc29c95b1710 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -325,40 +325,15 @@ 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 =3D 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 =3D 0b11000 */ -#else /* !CONFIG_SMP */ - WRITE_ONCE(*buddy, __pte(pte_val(ptep_get(buddy)) | _PAGE_GLOBAL)); -#endif /* CONFIG_SMP */ - } - } } =20 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)); + pte_t pte; + + pte =3D ptep_get(ptep); + pte_val(pte) &=3D _PAGE_GLOBAL; + set_pte(ptep, pte); } =20 #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1) --=20 2.39.3