From patchwork Thu Sep 29 11:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 12993932 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 EFF03C433FE for ; Thu, 29 Sep 2022 11:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A60E8D0003; Thu, 29 Sep 2022 07:23:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 856518D0001; Thu, 29 Sep 2022 07:23:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71E3F8D0003; Thu, 29 Sep 2022 07:23:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 63A9D8D0001 for ; Thu, 29 Sep 2022 07:23:35 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4072580E3B for ; Thu, 29 Sep 2022 11:23:35 +0000 (UTC) X-FDA: 79964887590.09.5584DFB Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf23.hostedemail.com (Postfix) with ESMTP id E049F140008 for ; Thu, 29 Sep 2022 11:23:34 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so5633687pjq.3 for ; Thu, 29 Sep 2022 04:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=xxtjUzETZH9DEkady7grPZMHSOc1w1fLwuVdzuJOa7k=; b=F0vnTbakLMMLXNr4+EoGBwJ7euaiMM3zQ1iPMnIFzbzTDT+UedxfCF+nzZ8Pu1dxgo jFnRRQ87mG9ETqHrCRPJ8tYtFphSYYI02spSlat9EK0B813gSaIgau9lC8HO2TnfioyA U5z6aLF8grpUiBTUr+XtFfpPaJYP9p4wA8DQKcjo3sr2dGe0NeM6Fxc/VWkqDOtlnnzg pSkuwm2hb2k8o1a08Un+gZ94hmONuRKnxJltHdPaQsfHBaJZptn+qowTGYNvF6D/Q9Zt 8uDtYYjW2vdcVCbGIPWPG9Hu3SNsD27KC0RvbFFKymk5xhXut/fT0TtX9i9M5v8aewJA XeaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=xxtjUzETZH9DEkady7grPZMHSOc1w1fLwuVdzuJOa7k=; b=fQD/sF6sIa+fy3BpYlbN9SIoinOrs7gi04c6deIbOUKBK9JgNyLr8k0omY1tGGe36E CRP6F08UrrTNdIGS4i0pEzaB6bBZdxKwafTVnMTgR80f28DKIXVbhHyulJdNHIt3l1JH yTyTOLR052H8+di5+gtF74UaymerXRwimjlEkAqet+VyKhPmW85/Pl+sBGDDLcTH8C4r AyTl/l1MHPNf/FvkH0JkDtYqtsC5+dPWyAb3flffSkLUvoFVAKMvez/gmThasWBE/YHg NNFYkOpUYobjyTYo5kcW2M1JpzMMTiv3losHqkRCGhgGRlLmtR5HnSc7wZ+zYHO/ApoG 5Wbw== X-Gm-Message-State: ACrzQf1VXoGcSueo9rui9NHoRp3kQvrAyFyWiMmdPH/I42n86DD/L9GL ChDF4Wbz4xrfoxFPtv9QK3LMmw== X-Google-Smtp-Source: AMsMyM53p08RePYQc/tpM4G6W0IClpl/1lZvEDpnTKE1I+fFxmkZIodX6//T3hVBYwLf82XMjWa5Lw== X-Received: by 2002:a17:90b:180e:b0:202:e725:19e2 with SMTP id lw14-20020a17090b180e00b00202e72519e2mr15923391pjb.163.1664450613800; Thu, 29 Sep 2022 04:23:33 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id i8-20020a655b88000000b00434651f9a96sm5225401pgr.15.2022.09.29.04.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 04:23:33 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, maobibo@loongson.cn, chenhuacai@loongson.cn, songmuchun@bytedance.com, david@redhat.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, loongarch@lists.linux.dev, chris@zankel.net, jcmvbkbc@gmail.com, Qi Zheng Subject: [PATCH v3 1/2] mm: use update_mmu_tlb() on the second thread Date: Thu, 29 Sep 2022 19:23:17 +0800 Message-Id: <20220929112318.32393-2-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220929112318.32393-1-zhengqi.arch@bytedance.com> References: <20220929112318.32393-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664450614; a=rsa-sha256; cv=none; b=vBfWvfj5A8WULOf7mJIsm8yl1RHhr9tkkKhif0jo20kp8BVRpr5RnwZrvn+d9yAAdW3/7m CoVDZ9BCFtTkeWn1ykzv0VQxCriFpm1KOrTQQMkZORWgtZM7nR8j9fu/DQeCqT9WGyGwLK ifuVBG/6beObx7z3hQpIYiz/2TD8p7o= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=F0vnTbak; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664450614; 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=xxtjUzETZH9DEkady7grPZMHSOc1w1fLwuVdzuJOa7k=; b=twLkmBii0ggIGNzKMW6VY0hInFCiDVd1a+aBJH+9P4OzBPJPKj8g++rCSnLJlNXqjxrp84 j4+pFffXgLIbEa6w5a2aaqQ545+ZXcviRV6zrU3AIuCisAz9RPe6O55DM2RrjRORmgiP5j zSwPjBY0r+QGeqNuERwPJ+cUYg2LKcs= X-Stat-Signature: qe8mhooq9ph7uy1hxzkcppou65emphoi X-Rspamd-Queue-Id: E049F140008 X-Rspamd-Server: rspam04 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=F0vnTbak; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com X-Rspam-User: X-HE-Tag: 1664450614-342481 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: As message in commit 7df676974359 ("mm/memory.c: Update local TLB if PTE entry exists") said, we should update local TLB only on the second thread. So in the do_anonymous_page() here, we should use update_mmu_tlb() instead of update_mmu_cache() on the second thread. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: David Hildenbrand Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: David Hildenbrand Signed-off-by: Andrew Morton --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 118e5f023597..9e11c783ba0e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4122,7 +4122,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); if (!pte_none(*vmf->pte)) { - update_mmu_cache(vma, vmf->address, vmf->pte); + update_mmu_tlb(vma, vmf->address, vmf->pte); goto release; } From patchwork Thu Sep 29 11:23:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 12993933 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 559ACC433F5 for ; Thu, 29 Sep 2022 11:23:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4C4F8D0005; Thu, 29 Sep 2022 07:23:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFB918D0001; Thu, 29 Sep 2022 07:23:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C759B8D0005; Thu, 29 Sep 2022 07:23:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B7A918D0001 for ; Thu, 29 Sep 2022 07:23:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4E31B8053E for ; Thu, 29 Sep 2022 11:23:40 +0000 (UTC) X-FDA: 79964887800.28.FEFF41B Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf25.hostedemail.com (Postfix) with ESMTP id B15D3A0016 for ; Thu, 29 Sep 2022 11:23:39 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id f23so989073plr.6 for ; Thu, 29 Sep 2022 04:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=JV29A8S7H9nk8Y3ndCLgLNPfcLB/Fva66Tots67JJ10=; b=WZaIjGyMqadKRxBxDIX3xg5seZAzi2+eG7ff8NVX4HSQpWLaw7qaTpLYv/YzsmJZ78 0NnMOP48NS2eZC/w3a+/Kp++v4n9iZh0e+KrLtb4TdUstzr1aoK25e4/VGuLE8P7JdzK 1suBosGhTDhXAu4NhobZ89FaAuUVv/HxBFU66GPu6JRmMUWn9U5w/bmIC6Pd0IdxLIUz WBDvOvS4A2HpiV0Fh5DMIyi01dV9qwRu46qIq0FpWgrvfDltU6lBc1xSpgDbXd5Ebooa QbTwdU6ICfpqp0gtUx3HBoUF5EFzn3XbeDnFZSckv5p6dpnSL2Qn0DDszzZ1qcEtHrD+ m7GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=JV29A8S7H9nk8Y3ndCLgLNPfcLB/Fva66Tots67JJ10=; b=asZbEaH+16hdO6ktMP+c21kXVFjX/P6AmtKZ7iPgHwhZnHEKLjMfLP1zRMzmCdwrW5 QSokmFTOSZIsmuxoMUvRgfgyrsOMG/Bf0RGkkWJv9f5awuLY9tnetqsrJvEmKRA0hGLo MpR27QpiF43VH011ZCa1MszyMAEkfRxqglA0vl9GQoywgPMp/u1aippmzT0pc3Dg6W/m /JQ9Uy+syhOocDXIqtYBvQI/WjvKDrQ2eZfqIHedcg55gH0POm+ZQC+aKyDpTb3OIKw/ iOR0HQwZyztiLzfTCwKUke/eip9B04Y/mSHM2F638B0xSymBsY7TkIXexgZTkL6CPLhQ 8K0Q== X-Gm-Message-State: ACrzQf3Ax4lVVECgO/J2nDb8fjPhMC4tJErmF+btCUj9CHLE2Ck8as47 dMETGUM4j1AuePH1QOZ60JfGkQ== X-Google-Smtp-Source: AMsMyM4p8HFIjEO65m+ZzDQ2AJS0niFAGYsHTpyebBpnN8u0Uaq8ynnczc/Wl9uJ3y/8nm7ojyMTdQ== X-Received: by 2002:a17:902:efc2:b0:179:fe90:55d3 with SMTP id ja2-20020a170902efc200b00179fe9055d3mr3032982plb.116.1664450618598; Thu, 29 Sep 2022 04:23:38 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id i8-20020a655b88000000b00434651f9a96sm5225401pgr.15.2022.09.29.04.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 04:23:38 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, maobibo@loongson.cn, chenhuacai@loongson.cn, songmuchun@bytedance.com, david@redhat.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, loongarch@lists.linux.dev, chris@zankel.net, jcmvbkbc@gmail.com, Qi Zheng Subject: [PATCH v3 2/2] LoongArch: update local TLB if PTE entry exists Date: Thu, 29 Sep 2022 19:23:18 +0800 Message-Id: <20220929112318.32393-3-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220929112318.32393-1-zhengqi.arch@bytedance.com> References: <20220929112318.32393-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664450619; a=rsa-sha256; cv=none; b=hBfK+fnfjH975TG5nopjJ6CYYSFeAz4uGugkQ8iBPhcRZl84CZZCjEuYuY8gQTa5gWLpte TNlrUktXOQ6phJ5zLNnzIFm9O6GwpWiYVaIuBcAfm/b2scluEonYYqMN7Q8nuPzsAhTgiX sollL96zsZC2pNCZRylHtm4lBVdST+Q= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=WZaIjGyM; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664450619; 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=JV29A8S7H9nk8Y3ndCLgLNPfcLB/Fva66Tots67JJ10=; b=jEqDbP/PBs1uje8K8rfkHTmaIx2KhN4h4pTr9DJAj+QLAkgrXGrQfmQgA0xERucHHODhnj ox5I1DPOQet458APR7p4oK/3FvFqUzHW7svs+YZ+R3DpNkx3Pw3y0Wgl2LDtLqClumYZj3 gJHu0hy2sj0hjdpT37Zkrf8trnFR+Fw= X-Stat-Signature: mod4pu3sudh7ntbmj8mb7x6nfwmibft1 X-Rspamd-Queue-Id: B15D3A0016 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=WZaIjGyM; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1664450619-633788 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: Currently, the implementation of update_mmu_tlb() is empty if __HAVE_ARCH_UPDATE_MMU_TLB is not defined. Then if two threads concurrently fault at the same page, the second thread that did not win the race will give up and do nothing. In the LoongArch architecture, this second thread will trigger another fault, and only updates its local TLB. Instead of triggering another fault, it's better to implement update_mmu_tlb() to directly update the local TLB of the second thread. Just do it. Suggested-by: Bibo Mao Signed-off-by: Qi Zheng Acked-by: Huacai Chen --- arch/loongarch/include/asm/pgtable.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index 8ea57e2f0e04..946704bee599 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -412,6 +412,9 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, __update_tlb(vma, address, ptep); } +#define __HAVE_ARCH_UPDATE_MMU_TLB +#define update_mmu_tlb update_mmu_cache + static inline void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp) {