Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3770629pxv; Mon, 19 Jul 2021 08:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7BBRdTGxxWkU8CReDTvrHP7JudnIlbaCcllPR+xEP/5Wblme/sw/4nTfnu9YTvVTl2u1G X-Received: by 2002:a05:6638:192:: with SMTP id a18mr22270575jaq.47.1626708083936; Mon, 19 Jul 2021 08:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708083; cv=none; d=google.com; s=arc-20160816; b=x99+PeRM2yCyZy85JoUos2JgxhQI6xqTk+5TR+ZO7UGiokuhWlw/qQtfzClI2HejS6 nymae01NMyQK7PwppuyNpQik5iCjuH+71ideLBtC3VKmJLRB7pHDjkHDe7/Y/SLH+eRW qwaK6b9Oz1NaediDlw87FVndITFghyKPZUz3gJvJCIVubPq/Ug5hmQZ3ol9dTcrpkC0A 3kSEhCAHwZ+SNCbyJcjUOXf6k0xZmWqoqMWPisWwK4P7HamD8csPiDy1AKMLFlMeTDV6 R+Qms/bPJDECs0q+wRGzlLIpYGMRhOFCjSX0IZWXjLhoE/apHpoqKCa3NHbELPVHRkO3 8Vjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fkm6LZnfTqp/BthOG3rjm7Ue6RagtTuSJN/PWuQRzpc=; b=KLBGXiH5KcsYIwE3dCp31HLpa9MCdHxoKc65gaLbSy1zybNHxUSuKeiuXOwr3KIMOW RYNIDkt5X3NTg/HFxxBzATLoA5RLNS7leEC11LF6F/bMWr2l+3mfUQpCOjMQxsj3ClLO 4uXBIqMlWV5QkXwHV3O5hmUFswlhqYFbE5wWFMskmPStocaiayL3mPFw09HyJH+TRNtj a/FBrpdquW0PP8rdOwFGPWm+mHMFLamD47F/74T3RV2TJggPycualXEOh+vrVSdd2+Si X4Nfl2qCNT4sU2B18QMDvRQEMoL7nIeODh2jarhZaKxfCyrljTUvv1z8l/EI2mNb/BQt 1AeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gtE+tBbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si11075758jav.78.2021.07.19.08.21.12; Mon, 19 Jul 2021 08:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gtE+tBbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244245AbhGSOjN (ORCPT + 99 others); Mon, 19 Jul 2021 10:39:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:37912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244297AbhGSO3d (ORCPT ); Mon, 19 Jul 2021 10:29:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 11A9761351; Mon, 19 Jul 2021 15:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707349; bh=Nj0Udr4R71nGxE+aMr8O49t+TEjcRM2tKiepHUjqTXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gtE+tBbbE3oJOuSJLHBF1RRw5Q47cHTwsuqHy1hE0arupjKI4K/Ri0v1DkmW90TC/ rc4jtVtPi6qBU6ZkjpqXOpdJFDx1d5b5erlcN1prODWBywS28xqW7gJAcMbHawjZ/l wTMl9DdM524Jp78GBMz0HzV8X5P0QsdWKJI2nGlQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bibo Mao , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 4.9 125/245] hugetlb: clear huge pte during flush function on mips platform Date: Mon, 19 Jul 2021 16:51:07 +0200 Message-Id: <20210719144944.453328007@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bibo Mao [ Upstream commit 33ae8f801ad8bec48e886d368739feb2816478f2 ] If multiple threads are accessing the same huge page at the same time, hugetlb_cow will be called if one thread write the COW huge page. And function huge_ptep_clear_flush is called to notify other threads to clear the huge pte tlb entry. The other threads clear the huge pte tlb entry and reload it from page table, the reload huge pte entry may be old. This patch fixes this issue on mips platform, and it clears huge pte entry before notifying other threads to flush current huge page entry, it is similar with other architectures. Signed-off-by: Bibo Mao Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/include/asm/hugetlb.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetlb.h index 982bc0685330..4747a4694669 100644 --- a/arch/mips/include/asm/hugetlb.h +++ b/arch/mips/include/asm/hugetlb.h @@ -67,7 +67,13 @@ static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, static inline void huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { - flush_tlb_page(vma, addr & huge_page_mask(hstate_vma(vma))); + /* + * clear the huge pte entry firstly, so that the other smp threads will + * not get old pte entry after finishing flush_tlb_page and before + * setting new huge pte entry + */ + huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); + flush_tlb_page(vma, addr); } static inline int huge_pte_none(pte_t pte) -- 2.30.2