Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp633454pxv; Thu, 15 Jul 2021 12:03:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyluFQApJ/G4NQo7xSXMNB9t7cZuQeL+ccUY8zfCdZJUmevKAVJH2Y7EbKYgdZEtxOC+Tw8 X-Received: by 2002:a05:6638:2593:: with SMTP id s19mr5328473jat.11.1626375792958; Thu, 15 Jul 2021 12:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375792; cv=none; d=google.com; s=arc-20160816; b=GnHGXs7S2kfiT2nDHEiD9dbPW+4n5PtjdH+Rm1b74ff+C+8+g89JNbM5ejkQB4x/MN nopsztg00h+xREnn4IDowKLSEgxCXFg/q21G5Oy4PEp2GzOV7N9CR0yl0tgmYAPiOH/c eQb9LSqKb/hc3S1pfzChHaCVGw13qKSWEDCtisb36WrlyoaYURZHmPzNP7BAeIKbHg0s nr7eTDiiWHpC/48CxVExfkSfiWftlx8RlbxMZp5ipbvr1FeLS/ttQeuTXSL2ift7tQkW 7Es3b+R77p4hDNTjMGMJ9EN9a7S96L38luhQzjtJdNPPoR90aFpl4+bd7mHORL07RTc7 C8CQ== 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=idWTxC0X58zyZTGB1eCq6uFy+y2TMPgDmJU3ytKYoSg=; b=Aqx0Tln9tvUWKa5wv+fhuaZpxjkcnES+BjlniYLLUE05e/ZL5eUF9k71RU1zAx8GS7 534TPXV+Un1R8le/ZGNcaWHb+d9MfDQ0QIzWnVEM5G6B7Qauje31Kvi9EQ+ZZp+V8heV 0d3uwGrwpJNTIdXT0w0hYA5qLUrIoxbF5L0KjcfmwOwIMVYUqavSW4x2Pr1/s61jmzvA t9V9oAqDSfeUtpw3g+/5YrwYVSTqwsA8qOL3UDYXZ/N7TEYuUUiS67YL4eCn7c/P6wF7 PhHY9UTLhVSqjYCl8inOsebk3UdYF8lMEEZjGJVr0pAujtOl1LXb6teA9gBTGWKg0Jao Tz2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EZrgEfLB; 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 i13si8632559ilm.156.2021.07.15.12.02.59; Thu, 15 Jul 2021 12:03:12 -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=EZrgEfLB; 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 S241377AbhGOTDW (ORCPT + 99 others); Thu, 15 Jul 2021 15:03:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:59220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242312AbhGOSzC (ORCPT ); Thu, 15 Jul 2021 14:55:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5CEF3613CC; Thu, 15 Jul 2021 18:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375127; bh=VaSw8eXxJwYqDAsNRRTpRkjq+fkc9jcRrS0A8LIPC8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EZrgEfLB3+JBBLdkruBeMMd3IaOu1wmPCS0Nhl6v9gRtMRk9mQORqZSudYwKWkhqh 6JOwafpLrgqBYwmUHbDySid24PaawE3Qd/maFi1j8ts5ano73KY8+mrLw8+5wCPljw MjAnX01yYOi3CzLZDZhWDoOB7tha2t78p9DFybZc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , ZhuRui , Zhenyu Ye , Will Deacon Subject: [PATCH 5.10 171/215] arm64: tlb: fix the TTL value of tlb_get_level Date: Thu, 15 Jul 2021 20:39:03 +0200 Message-Id: <20210715182629.786403180@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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: Zhenyu Ye commit 52218fcd61cb42bde0d301db4acb3ffdf3463cc7 upstream. 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. Cc: # 5.9.x Fixes: c4ab2cbc1d87 ("arm64: tlb: Set the TTL field in flush_tlb_range") Acked-by: Catalin Marinas Reported-by: ZhuRui Signed-off-by: Zhenyu Ye Link: https://lore.kernel.org/r/b80ead47-1f88-3a00-18e1-cacc22f54cc4@huawei.com Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/tlb.h | 4 ++++ 1 file changed, 4 insertions(+) --- 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 */ 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))