Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp665131pxv; Thu, 15 Jul 2021 12:53:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEyoIF6cZadZinKctTpLzJsU3J/rwtbndsnGcGUyekCBg6VsvSt5PTRzcABFcvg+v8OEip X-Received: by 2002:a17:906:384c:: with SMTP id w12mr7303642ejc.445.1626378833401; Thu, 15 Jul 2021 12:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626378833; cv=none; d=google.com; s=arc-20160816; b=mNCKAtcSafcpVhotIr6XSOyEpw6JWQX251qv6/3Q3k+BaIs0LiCpQJZiwKHuzFfOlc sCo1aSsvyAG/vY7+f4c04/Afw/LgVvFAsULnSp4JJmMdPDTbFPJCdqG5rh/DcS8KBUXq caIlCZB4irVGp2Lg0nvuG0i6ulRD75QRV0wuFtSYhhnkgOrR6uR4KUaxfNq86ybAG1IC PKOuBcvAp30H1XzQmDmCBWq7Xu/uPRRFdkOCbOL9BCuEJ7m0ZRCAB3mQdT9d4/F36RYX s59FiguCmtC0slAjCmtulFkRXv8UcgE0/ytamlymoxe/BMyrUCFmZD8Uc9xD6ePh1Ml4 tXiA== 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=YUA1Q9MAtZgoyYsc7vIfGBN7+zUFk5D3vkm+0h1I3ed1wPHtD6En7PYo+y01C3ItIM /XOSq49fW/z4AsD24DIxVp5YLRvHrQhcrv/dke5SeTz0RUby+YNfxJ/1IBvQg3wj8CC4 P21xNTXqbQYFXLKytivgcJp4SdOrJ9fRZMwuJUockhWnHZv/GoxrK8rL3uqquWATd8PN 7dX2UxsUwXU+B1GT05wthWi07ArjkLrYRAOWklwpXQXtDBpUO+8OlT/Ys41ejL8Nw8bi AYRafLcMT2BHJca8xxCLwwT2Sy5CqQ1V98Kga5nAHOqwtBthQYNDU9pn5eqe69zNkwWz sP5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wFx5tLWW; 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 y8si150242edw.166.2021.07.15.12.53.30; Thu, 15 Jul 2021 12:53:53 -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=wFx5tLWW; 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 S1344669AbhGOTtp (ORCPT + 99 others); Thu, 15 Jul 2021 15:49:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:57374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243578AbhGOTSJ (ORCPT ); Thu, 15 Jul 2021 15:18:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5FB8661413; Thu, 15 Jul 2021 19:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376397; bh=VaSw8eXxJwYqDAsNRRTpRkjq+fkc9jcRrS0A8LIPC8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wFx5tLWWZMd4iSX0BMqru0KUrNQ9tfEfkE1KPG4ApJqh69UNzgJpbFy2KtgsmsueW 6lqqoUAVlU+737H3cYtY13kORbOPn4AXtacxycHqrQ78v9JAa+wXihig8wLMxC/REs N/7pFp6HrySHGV+pPvOTzLx+UVfAyrrta0O8Yh4w= 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.13 213/266] arm64: tlb: fix the TTL value of tlb_get_level Date: Thu, 15 Jul 2021 20:39:28 +0200 Message-Id: <20210715182647.282771820@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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))