Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5409110pxj; Wed, 23 Jun 2021 00:08:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYpF1QMvx0gjpysKSMIJSquh63+9SyGiRSnLU2PAb/ADUAEBxDW/yX+VG6ce6CB3b4+ezD X-Received: by 2002:a05:6402:430b:: with SMTP id m11mr1686491edc.192.1624432124596; Wed, 23 Jun 2021 00:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624432124; cv=none; d=google.com; s=arc-20160816; b=CCSPDUd7vqm1hGdWjz/WII1z3r8Bxvj0utM4DnMqtAxtIhXLHTbrcrtK9Du2GuVgmg FFYzjUGKhQAbrNTX95OCSBqLIVHgPuhdO9jp7TGKHC8kvA0ftwB5UbStY+S99bAPR8Eo Swcfi1aXISavhx8BBrrgORM968WCbGC0+HUzD8givcDB7uqYU59hMjqmRGqPaLlV+SfY 4E2G3RBuJVQCBdq+RAlOGuPe6YZEMKuQ/ovtjmO44ODF7MeS80D00UdsMNFKMqqgrI1q O24t12OeXSOGG6mk8+mL9GhHNhMX9gAQ+7KVlumPVvyzRelh20kkYCV+UOycpMNytAgE zRdw== 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:date:message-id:subject:cc:from:to; bh=zuA9AzRpwERSShTkhgFbvgHwqF0ss/bvt96b8RiS7zA=; b=JeuNrxeoG8SFugPA0SPl6iusT0uKuS46DJYM+MJ9zSwDJ3/NNGDO8zd3olrxbo/BfQ P6hNeOIz3HndVXItGd/dH+a9YxgeJqDO+G/GEU8do8ZHXszCuU84YALChUOFB3QVxmfp nQEi97HfHDlaJyuME4Yvt24NTe/YKRU561mJYpK6xt9rogL4k7ozYXPwaD9/OId/Vlmi uO4/fO16mpR7JGzBYnD8O6r6A+e8mx8YSEdOX/VyWGLvfXgo0XE+KTRV3H+4iUvEplqX 6SSrWACT4W0q/5Fpomdlak3pjKg3krU8/E+rExtyXiudwrltkfR0Q9zf4Eo8x6LNuVae sZtQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mm7si5099487ejb.543.2021.06.23.00.08.21; Wed, 23 Jun 2021 00:08:44 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbhFWHHo (ORCPT + 99 others); Wed, 23 Jun 2021 03:07:44 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:11085 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbhFWHHm (ORCPT ); Wed, 23 Jun 2021 03:07:42 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G8vMy6HyszZhxW; Wed, 23 Jun 2021 15:02:22 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 23 Jun 2021 15:05:23 +0800 Received: from [10.174.186.21] (10.174.186.21) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 23 Jun 2021 15:05:22 +0800 To: Catalin Marinas , Will Deacon , , Marc Zyngier , , Peter Zijlstra From: Zhenyu Ye CC: , , , , Xiexiangyou , , huyaqin , , Subject: [PATCH v1] arm64: tlb: fix the TTL value of tlb_get_level Message-ID: Date: Wed, 23 Jun 2021 15:05:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.186.21] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The TTL field indicates the level of page table walk holding the *leaf* entry for the address being invalidated. But currently, the TTL field may be set to an incorrent value in the following stack: pte_free_tlb __pte_free_tlb tlb_remove_table tlb_table_invalidate tlb_flush_mmu_tlbonly tlb_flush In this case, we just want to flush a PTE page, but the tlb->cleared_pmds is set and we get tlb_level = 2 in the tlb_get_level() function. This may cause some unexpected problems. This patch set the TTL field to 0 if tlb->freed_tables is set. The tlb->freed_tables indicates page table pages are freed, not the leaf entry. Fixes: c4ab2cbc1d87 ("arm64: tlb: Set the TTL field in flush_tlb_range") Reported-by: ZhuRui Signed-off-by: Zhenyu Ye --- arch/arm64/include/asm/tlb.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h index 61c97d3b58c7..c995d1f4594f 100644 --- a/arch/arm64/include/asm/tlb.h +++ b/arch/arm64/include/asm/tlb.h @@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb); */ static inline int tlb_get_level(struct mmu_gather *tlb) { + /* The TTL field is only valid for the leaf entry. */ + if (tlb->freed_tables) + return 0; + if (tlb->cleared_ptes && !(tlb->cleared_pmds || tlb->cleared_puds || tlb->cleared_p4ds)) -- 2.26.2