Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp711692pxv; Thu, 15 Jul 2021 14:09:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylYGc11FQ/Ifwu+69ssdUULwNkAAMFtcHg2Vs1QJyOYJKWEdc2sjJOPe2Ns6qvv8ZLKl39 X-Received: by 2002:a05:6402:502:: with SMTP id m2mr9910532edv.57.1626383380056; Thu, 15 Jul 2021 14:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383380; cv=none; d=google.com; s=arc-20160816; b=y7uxMVoOgqAuGvqkRJXXmJNXokuOlLOXfedDBLo2uRy9/UbrkVHcbm5FEQ6388mWsN gXzdGFN2ri5YkTJtMKDaiTMBCqqWgXMdsnVX0B43+nBU4n33aTuMzTaXPVW7NSg4Ha41 XIUNvOP3kBxUXuXygDjDRLi19twqiwKapg1o8e635nuTXMhzifO7YIKh8sIdU9pSJ0xP tkVcvmCPJ/FcaxXGH5ILq7vdUyQdnL1c5pJ/UjvJIXe0cedcbCO1lb+tCRi2XO7k/vjG nkTf3/2TKFSeCUMCXhegzA0UpWAVtBFNLGMeZogGcowtunlrztIdPEPzNtkJ3DJe/p2b PxHA== 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=Nz/J/CsIFzUZ3LmcpANciDLkR/+KvhZHeQed61ox0iHPIPQQeFk5mp4nKOfGqeh8sO 3pEDsaPyEfhC4052LsBC7X/CgBfzl8xm7H4HVuVW0Gyitj99wWsiFg1yf0gl5oJwFtR4 aUKitKpqH47Be38Wk55GCRNuY4YpO+ogrfaw16S4k1nPFnx6gjf+hYu7+vUlMeem/zko feqz2YlvOaYyKbPPHvtgGqqq9cxJGg6eeu6ARf+hwU4a7yKvf60yMZBbQAqFbRxufRii +8FtK2lzehNQsuvr3imnUb9QzUX8YO4PAHlmvvyEDNP8Zw+AXrGmqjL1StastHh4WBVJ j35Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H0sewmnY; 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 b13si8935715edv.57.2021.07.15.14.09.17; Thu, 15 Jul 2021 14:09:40 -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=H0sewmnY; 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 S243677AbhGOTUF (ORCPT + 99 others); Thu, 15 Jul 2021 15:20:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:38430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242628AbhGOTFN (ORCPT ); Thu, 15 Jul 2021 15:05:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CB1656141F; Thu, 15 Jul 2021 19:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375680; bh=VaSw8eXxJwYqDAsNRRTpRkjq+fkc9jcRrS0A8LIPC8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H0sewmnYiH3qIu6GaTb5DBDURekAxubQZO+4nPPuqECCUksxqhAeXwmX40eVCVSTp ClmYqUZrJqgASYGcdcK96+qLqbBozJ2pxlnemQgBEFVfWDYvmGdlP7V9x7SHSnSXZA /xnHONGZS4IfL6Oy2Qy9OFrQ5wAChUIvadmvTvds= 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.12 189/242] arm64: tlb: fix the TTL value of tlb_get_level Date: Thu, 15 Jul 2021 20:39:11 +0200 Message-Id: <20210715182626.512411535@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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))