From patchwork Mon Oct 14 03:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 13834137 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 B7D6ACF2590 for ; Mon, 14 Oct 2024 03:59:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFFAE6B0082; Sun, 13 Oct 2024 23:59:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C63386B008A; Sun, 13 Oct 2024 23:59:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86AD26B0082; Sun, 13 Oct 2024 23:59: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 4C15A6B0085 for ; Sun, 13 Oct 2024 23:59:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 14125C0AFA for ; Mon, 14 Oct 2024 03:58:55 +0000 (UTC) X-FDA: 82670851998.05.AB21A93 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by imf24.hostedemail.com (Postfix) with ESMTP id 8E918180003 for ; Mon, 14 Oct 2024 03:58:58 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1728878199; 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=r39t5OT5vLHizTm15fY38kzPptRVLbY+MwS1wCM3o7w=; b=YlpWekx4XdwCJ6CUba8VBn/lvJPw3rv0j1ifEVbmHkOyHYJxfKDQI4Dj4dMyDv3CgOjlB/ /qYGVAj7TDA44x+FAzKPxZdPPc2v0oNGGlNq/tLTcf0Rt8V9V6+Xgh2bwGdonUjpbhRQM5 1ilj1CAxVTY9zuaeRWiW+z8yN+rkiHk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728878199; a=rsa-sha256; cv=none; b=SyySGSfdXFYh5LJG0hQ56lyUXIF7ErP34ceAo3/PPpMC/t4uLDAz1CGoxINGH+VXy+tiZu eKVOiMfA62Pu8JHFnx43CuXSRHBcvJ/XzbH9peMrYq9bkL3JEfDpg5XK4x7VNtM+yHKzMM nN6Z+jv1kOKbkofkxRZG9bfU+7eiafQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.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 _____8CxbWsBlwxniwIaAA--.38059S3; Mon, 14 Oct 2024 11:58:57 +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> MIME-Version: 1.0 X-CM-TRANSID: qMiowMBxXuT_lgxnc6EoAA--.1717S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Stat-Signature: uscxhnb1t8561utndnfubq41yy46mnnr X-Rspamd-Queue-Id: 8E918180003 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1728878338-717463 X-HE-Meta: U2FsdGVkX1+SSrjytgUISrNgvrYbGrcgv1BUv1cTi1jzMILz2KQKNdHLZy7LcLq/0ltKp10Zt1gkwWd5MnEissSIQbsuack/uKVnzrU92Nw9WhL7bRYXJ42Ji8RxbCkdShO0V6EZHqloSnRTSqfsjVqLcO0u6cMvM0thpjEHySjyJm+wknMZJcXaclxTcYmYqRAbQ115jHFQrfDAn+RPWJlsBE4xrUVcOpddXYiEaeWlue17gYgVTQs7pNbKuMmM0PXzHZGOGPPA4XzFV06+k9g6JaHfyvKapV+Uty7QLz6hZuklxx8VJ3bvTHM5bvSPGkYgVlUNc26yrXNegk5Z7F6lffXq+kEPDQYERRgtYXwGCmtAqHLXfyg9hiLdU2mv/fkEJbor0ceBNfmEJTNJfeRddhDLpbhScU6et1JQZlhcHCWtt2hcVmwYvu5ks5uH9PPWPcJjJdBm6X5e/HGL+9577nUgkqi4pybEu1j/Wg1VWfu9k8jHNYllxAUZkmo1tlNLj7DZ0POARd3geOHhIaV470JndN/ob2ZmI6Hlo7Eq5H+pg84rYefKLpqw3Llj1GpE+n9pKYtKryQWaJSmXI4M64T1fiWNs1PkLetmxE6xQALL2eKe5424ZolvilFmNG2dMrsXgFDyOd0cTPUggpfborGM0DwmBlKVACZK/RWTvvvm3ICRo8yovBQGto6IDT0/wx5P9Gipbac5FbnCeQm8pYr3bHCiRayNKT/uVNlmjdGJEqrbIzOF1SM27ne6MOFUja6Tls9mu4xuTHom81ZrVPf+O4YMU5m4EAp8Q/emmU0eQYTIYzI6H8cItNX2JoEoUB2qYOJQfcW8adPDsYIuC0qDzC3jizMcTVeIqpd2Pgo3MZDMZnZdL372SwtLraU/wWeStNvdSdoOvBU0S/GUlXss+a4iwHY1YhCEJ26BZ+bYSiSoba7qNeWOyPvbASxXYHm0IbtSfqU+49s heG7Ls8c L3dV9+LuNPsTArIC8kci5fSCzcsrybP3mNe06zysjALspdZxMZCh0VxqbT0MMKRofbSgPAJ72EjKhGAlRetkf70hdC54IQkzuNQWU8cNenRof9CoP8PgsznGjiUqHOzImVmlt2GIJffV3CjHDNlahIl63Ng== 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 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 = 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 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 = ptep_get(ptep); + pte_val(pte) &= _PAGE_GLOBAL; + set_pte(ptep, pte); } #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)