Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1343642pxb; Tue, 26 Oct 2021 07:22:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCoilYf98Q44IuSWJTVmuHhmSs25YE/ToAPD1HglUgVui02ZqH0tdZ+VDSinxo3DxoLF7e X-Received: by 2002:a17:90b:4b83:: with SMTP id lr3mr10110245pjb.162.1635258145781; Tue, 26 Oct 2021 07:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635258145; cv=none; d=google.com; s=arc-20160816; b=oDyVwOnCDWk4RqbjsC/ul/JoBJJ6Dhxysx0K++nyMBOVbJSVMQ7dWI0+8751KclEKX 8JQr9JlkGii2CFQPPAqW8L7qA3IZIf4Ss845peD1lbGmSsqxg27ebFE6STrUdVWFaMYk 5SrN9yPg5cUAO9Dm+n6IJ7ktqdcQaG/hYoDeBr92aup60Z4994GqSojqNfHBEW37oEbN M3FQHagTHMmcAPthmQ7By1YGeojRrGh9fM773QH91ROMM+K0/uHHxj1uQGEA6lzRXro5 2/M7tX//rtGOjlNCFsbsUbxqtbCB3bbAuUl/pPM7XxUTjCQT1AwcKy11Ya26UoNoJdK+ SEzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=hW7xCt9vLH+8oGE8/i400C7AGzNwYQKEsJAnK9bLLTA=; b=LxfFFsua8xWxQUXlozXek06p0EILj1CIrIsOW2o2ERYeVzEmxlYbS/HpTkJRZvpSYa WjfAWDssXwhMExVcjY3BtQXwI/sHMZhQY82MEpGIe49TRdHmxqpLkilz7hyUKv5HEACb xGV6RuW0RyeIN+RxlJlAmLDxBQFUAms9BTH2NbD/rTsBcxQCioeyRGdu/nf+RjzwtV8p 6q2kXrLEtF0dW1031O2zqO/TX1scY+QGfKhgmLEH4fy6CkctyogVg4zZaB4UoHE6lebk 4tPx0a6r9kD248hiSpN531qXEMmv7eg8egD1ZSrfQVsQVhhqb2ogp+GtIz4b6drPVMAb cKGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=1h0UuoHs; 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=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cm2si991682pjb.81.2021.10.26.07.22.11; Tue, 26 Oct 2021 07:22:25 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=1h0UuoHs; 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=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235450AbhJZLSh (ORCPT + 99 others); Tue, 26 Oct 2021 07:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235408AbhJZLSb (ORCPT ); Tue, 26 Oct 2021 07:18:31 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 625E9C061745 for ; Tue, 26 Oct 2021 04:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hW7xCt9vLH+8oGE8/i400C7AGzNwYQKEsJAnK9bLLTA=; b=1h0UuoHsLYWoa7/9uWDWBK2Ruu V3F0LqILns94O4FzgMygAibQDVxOUgKbpMzPn0UaCtF46IqAbpClgNIj6lRolQRH8Uw3pqagCSmt2 mWdH6CfqOpMhX5EFolJ1NY735MyFFh3i1/HWl0CEgqaBPUdX3kv+5qtKKnTjI6bW0BMcwJCJuvcoC Gzc4XPxSocIRwQ9owPtQSMjpYDM0CZ3zzRRDtj1rk+8v5LMk69qRN1maKCgWNqu4J53ar5Fnf30S6 y+wNNtzqyUQA0/ikndG0lXNPQ75eSAUgKCFxc7PjrjtpRw7bJNku1WFS8vtyWmWQ96vP+XQoEfq5m Iu1TJ3dQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:55312) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mfKQz-0005JA-8J; Tue, 26 Oct 2021 12:16:01 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1mfKQw-0006i2-MV; Tue, 26 Oct 2021 12:15:58 +0100 Date: Tue, 26 Oct 2021 12:15:58 +0100 From: "Russell King (Oracle)" To: Ard Biesheuvel Cc: Quanyang Wang , Linus Walleij , Thomas Gleixner , Linux ARM , linux-kernel Subject: Re: [PATCH] ARM: add BUILD_BUG_ON to check if fixmap range spans multiple pmds Message-ID: References: <20211020054942.1608637-1-quanyang.wang@windriver.com> <8905597e-49a9-c898-c78d-3d2f51180133@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: > > > > > > > > > > Hi, > > > > > Sorry for the inconvenience. > > > > > > > > > > On 10/26/21 4:59 PM, Russell King (Oracle) wrote: > > > > > > On Sun, Oct 24, 2021 at 11:44:31PM +0200, Linus Walleij wrote: > > > > > > > On Wed, Oct 20, 2021 at 7:50 AM wrote: > > > > > > > > > > > > > > > From: Quanyang Wang > > > > > > > > > > > > > > > > Not only the early fixmap range, but also the fixmap range should be > > > > > > > > checked if it spans multiple pmds. When enabling CONFIG_DEBUG_HIGHMEM, > > > > > > > > some systems which contain up to 16 CPUs will crash. > > > > > > > > > > > > > > > > Signed-off-by: Quanyang Wang > > > > > > > > > > > > > > Looks reasonable to me. > > > > > > > Reviewed-by: Linus Walleij > > > > > > > > > > > > > > Please submit this patch into Russell's patch tracker. > > > > > > > > > > > > ... and has totally broken what looks like _all_ ARM kernel builds. > > > > > This patch is intended to trigger build error when it check the value of > > > > > __end_of_fixmap_region is equal or larger than 256. > > > > > > > > Why? The fixmap region is larger than one PMD, so why do we need to cap it? > > > In __kmap_local_pfn_prot, arch_kmap_local_set_pte(&init_mm, vaddr, kmap_pte > > > - idx, pteval) is used to set pteval. > > > 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. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!