Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1426838pxb; Tue, 26 Oct 2021 08:49:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6ceWmvg7iSF2JdBWwEHTEh/kazROBwRrjkyASTl72s23dQoWRQ3wnloEVIVelycOEhYp0 X-Received: by 2002:a17:902:c94c:b0:140:4dad:404d with SMTP id i12-20020a170902c94c00b001404dad404dmr13882407pla.72.1635263371424; Tue, 26 Oct 2021 08:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635263371; cv=none; d=google.com; s=arc-20160816; b=jDbNUzbaM3JeVlenhZN0WmIKaoCUVOKe/7TdsLA2pbIfSTRQqv8fm8B9xF/pc/myJI vPYfUvyTB8MJ9XiAD8dTsff0OH2TcRgYxtDJZSqasjLV6d9Ybd1tnV5/nfOc9bEJrEgE 5iVTC4gr1XMHTeUGcMwFJ/+85mHV6q+hdzkExjFk3YRXU4DSdpeSFaMZS2nX4S8WIcSO WXxuK6VlQ9Bo5H7da52wNOb5sfGsF8BAEudJynUc3I+IaQWWs2kVpyveyOsfpUDHZWf5 ZSiEJA1rU/ZFcnRiN1knNWpToPjSeCTQLeYbyNk86P5DVCObIkY6pkfQ2TtBK3POWrpj jA9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4ITX+cKqnNwC5ms3KuQcNJTciqDEOaOs2A/Y2kBp3vI=; b=iTgaCwAWtSNFJlwF0LEQxXh8oQhreS7q4i0nSg/l97N4YmnngyT17EEi9icMj8L2wi OU47VxMMvF5bJCO/bN70aIhojSrIlINb7ROaWNCUsohMK6N+1EpMbHa9ziClyfcDctC7 fPjWlEtTGc+DFsCIrWKHjxQckEXLthUZ2lOB+T7/ZxWeThlbOPSmbF8f4TjE9bMcrd9H lWj04gXp4HYonljytJDsJd2fbKEw9510yNE0SRnudWRmviIXp1QacCUZ8i55Wm8KuemF qJBooXBnK0P2OYEQe9b/1TaVw0Fr815PyMirlUlDZP6YiBo60hg7dcLfZIZBY+Fv7U97 BvAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aCed96h3; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si28931780pgu.404.2021.10.26.08.49.00; Tue, 26 Oct 2021 08:49:31 -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=@kernel.org header.s=k20201202 header.b=aCed96h3; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234381AbhJZL2m (ORCPT + 99 others); Tue, 26 Oct 2021 07:28:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:45222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbhJZL2l (ORCPT ); Tue, 26 Oct 2021 07:28:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B8F160F9B for ; Tue, 26 Oct 2021 11:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635247577; bh=tj9TPpbICm0vt1k7otsj987q68Wno50MNK6OwTmsIi8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aCed96h3OB1w5uvXwzkKT7C+d0iANTq1i7wJCZYfN6UzvWek+MKiA7CwNC9CpX30f vIDffSM6eiMK8zSi9UnJGAR2Ze/7hDTOkQe1Aoa5tiKdLs67CLJhC9BlerjQdXlZXS 2d39B+7hM1FyW7FVnmXEci7OY0hkKraXSBWYTiTuBGXEr3ly6vYQr4t6kRRrlaJdaa IZ871Qlh9nEncwBAbHkFbkKh49sdwPCQHktFWWNtYHVMgKCigCckJw1hefOqm2bRZZ ZmkxcOiUpW0hTuTmlLwA7rzxc4X8ByW1X0eIR9PoLoKbMrRch5FHUA1VyMaZa3yAbq Cv/3Fz5AHeB6A== Received: by mail-oi1-f174.google.com with SMTP id n63so20054700oif.7 for ; Tue, 26 Oct 2021 04:26:17 -0700 (PDT) X-Gm-Message-State: AOAM531GrNpjjXtOYdlGd7wHQM408wC048jJ7dkyvWAVfWVytmXHhhtH p7jatWd6DkhDL2hrx6V8eMZ3L+AJ/aWLYkJ2Dfo= X-Received: by 2002:a05:6808:1805:: with SMTP id bh5mr27062624oib.47.1635247576878; Tue, 26 Oct 2021 04:26:16 -0700 (PDT) MIME-Version: 1.0 References: <20211020054942.1608637-1-quanyang.wang@windriver.com> <8905597e-49a9-c898-c78d-3d2f51180133@windriver.com> In-Reply-To: From: Ard Biesheuvel Date: Tue, 26 Oct 2021 13:26:05 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ARM: add BUILD_BUG_ON to check if fixmap range spans multiple pmds To: "Russell King (Oracle)" Cc: Quanyang Wang , Linus Walleij , Thomas Gleixner , Linux ARM , linux-kernel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Oct 2021 at 13:16, Russell King (Oracle) wrote: > > On Tue, Oct 26, 2021 at 12:56:08PM +0200, Ard Biesheuvel wrote: > > On Tue, 26 Oct 2021 at 12:55, Russell King (Oracle) > > wrote: > > > > > > On Tue, Oct 26, 2021 at 06:38:16PM +0800, Quanyang Wang wrote: > > > > Hi Ard, > > > > > > > > On 10/26/21 6:12 PM, Ard Biesheuvel wrote: > > > > > On Tue, 26 Oct 2021 at 11:53, Quanyang Wang wrote: ... > > > > But the ptep is calculated by "kmap_pte - idx", which means all ptes must be > > > > placed next to each other and no gaps. But for ARM, the ptes for the range > > > > "0xffe00000~0xfff00000" is not next to the ptes for the range > > > > "0xffc80000~0xffdfffff". > > > > > > > > When the idx is larger than 256, virtual address is in 0xffdxxxxx, access > > > > this address will crash since its pteval isn't set correctly. > > > > > > Thanks for the explanation. > > > > > > Sadly, this does seem to be correct. Even if the PTE tables are > > > located next to each other in memory, they _still_ won't be a > > > contiguous array of entries due to being interleaved with the Linux > > > PTE table and the hardware PTE table. > > > > > > Since the address range 0xffe00000-0xfff00000 is already half of one > > > PTE table containing 512 contiguous entries, we are limited to 256 > > > fixmap PTEs maximum. If we have more than that we will start trampling > > > over memory below the PTE table _and_ we will start corrupting Linux > > > PTE entries in the 0xfff00000-0xffffffff range. > > > > > > I suspect this hasn't been seen because of a general lack of ARM > > > systems with more than 4 CPUs. > > > > > > > But doesn't that make it a kmap_local regression? Or do you think this > > issue existed before that as well? > > It definitely is a bug in tglx's kmap_local code, which assumes all > PTEs in the fixmap region are contiguously arranged. > > Looking back further, when local kmaps were handled in arch code, this > bug did /not/ exist. We used to get the PTE entry to update via: > > unsigned long vaddr = __fix_to_virt(idx); > pte_t *ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr); > > which later became: > > pte_t *ptep = virt_to_kpte(vaddr); > > Both of which walk the page tables. > > So in summary a regression caused by converting ARM to kmap_local. > > I think we could fix it by providing our own arch_kmap_local_set_pte() > which ignores the ptep argument, and instead walks the page tables > using the vaddr argument. > Removing all occurrences of 'kmap_pte - idx' and replacing them with virt_to_kpte() seems to do the trick. Unfortunately, these occur in other places as well, not only on the map path, so I doubt that overriding arch_kmap_local_set_pte will be sufficient.