From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CF75C433EF for ; Tue, 26 Oct 2021 11:31:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A14A604E9 for ; Tue, 26 Oct 2021 11:31:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4A14A604E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MhermPIpjUkwjLzHChK9Ok/mcNsqTlQJ4Gdo8PK+Zpc=; b=j8F/5H5cCHWSXi 3xRzmc6+F+dZY602eGXmPAq0JWcBuiPmfHjiPUYFmougOmfFscpgl08ANUolyj1isWXztuJLrlj/M fG9RRwtitK0uwtJkiyc/b+kFmOFIGTryCJvRa8TqrAe5FoU8u7oRBdj3X3Mf59Zwj+nIgivps+XIr VoFd4cE+eveTybMwZI7rjfLO/qFV2LyKiluidIwWELQvWbIzIAVP6RVToDj6EbMGB2uD3A8A4VvYB Lh1mPvLjSI0i8XG01/AEUzcU7sbvvCkQAqlsjZmHGeML9GZpqNNSKmbeI2/p1+IaFk3HGZhBlvDNf M1CBxxWtRcJLdgoVKeaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfKeO-001f4q-9w; Tue, 26 Oct 2021 11:29:52 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfKeL-001f3S-1c for linux-arm-kernel@lists.infradead.org; Tue, 26 Oct 2021 11:29:50 +0000 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=IujL7FmhpYmej4pabaxWfMrAULZ6FtGY6DLBse31llI=; b=TzpEpWLF3IJe7KMgQFUk/8ZYv0 XeJ7dqKG24JnQNJBznuwrLIufnHZQ5XonxB1rvB7ntabcWx8hW0A5g6DgLRdcYf9ZY6AGatwWZcgB TStz4KlWw2+ksvCiCiqOwLY5BrND8k48H54r+E4s6WeraXCsJBF4MDrT2jmqX5jDUQp1RszKZUaYY PR4Lu6grS1i+R6ZjJXHiUUV1gPWvtrfHfwq+BppkfJI8GxtpoG6S1E2549KNR8cBjpg9S2sK89KPf D1E+OwD8ydbyYvsIQm/Y/Veiq1F31CHj0Z0c4PT90ndkoZbqCQ9tgtSSbbBhSb6U/kJmiJMD1fRum 4JXZAeLA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:55314) 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 1mfKeF-0005KS-F3; Tue, 26 Oct 2021 12:29:43 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1mfKeE-0006iI-1c; Tue, 26 Oct 2021 12:29:42 +0100 Date: Tue, 26 Oct 2021 12:29:42 +0100 From: "Russell King (Oracle)" To: Ard Biesheuvel , Thomas Gleixner Cc: Quanyang Wang , Linus Walleij , 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_042949_112720_E8C6DDA1 X-CRM114-Status: GOOD ( 34.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Oct 26, 2021 at 01:26:05PM +0200, Ard Biesheuvel wrote: > 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. Right. That's probably going to upset some folk if we make everyone walk page tables, so we probably need to add overrideable macros just like arch_kmap_local_set_pte() is... which feels rather yucky. tglx - any opinions on how you'd like this regression to be fixed? -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel