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 X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1ECCC433E1 for ; Thu, 13 Aug 2020 20:55:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8FBCA20715 for ; Thu, 13 Aug 2020 20:55:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oa3whIX7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FBCA20715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 264E78D0002; Thu, 13 Aug 2020 16:55:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 213E36B0026; Thu, 13 Aug 2020 16:55:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12A308D0002; Thu, 13 Aug 2020 16:55:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id ED5D06B0024 for ; Thu, 13 Aug 2020 16:55:29 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 994E982499A8 for ; Thu, 13 Aug 2020 20:55:29 +0000 (UTC) X-FDA: 77146751178.02.skin19_4605fe426ff7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 65AD210064ADB for ; Thu, 13 Aug 2020 20:55:29 +0000 (UTC) X-HE-Tag: skin19_4605fe426ff7 X-Filterd-Recvd-Size: 4485 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Thu, 13 Aug 2020 20:55:28 +0000 (UTC) Received: from aquarius.haifa.ibm.com (nesher1.haifa.il.ibm.com [195.110.40.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A80A206B2; Thu, 13 Aug 2020 20:55:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597352127; bh=fwqNF7Ek4YQWXYA/eB6lJuI0t+SdQtcs0nxaBRdmccY=; h=From:To:Cc:Subject:Date:From; b=Oa3whIX734bl++81bmONQOYVwNO8rDrBDDv3AnscYHnXEUwcHEqZoJTQxe/8nfU7D 7MdcAO7g9VROG4Zju4dpSwFlkDqotXyzYuyIvAe1EuZdiQc7HB0J3EG8QTZZ/iAACU W51oZd0yIrUz5JliVpYs1NYqgFuxg0fWMbv7kMq4= From: Mike Rapoport To: Jessica Clarke Cc: John Paul Adrian Glaubitz , Tony Luck , linux-ia64@vger.kernel.org, Anatoly Pugachev , Sergei Trofimovich , linux-mm@kvack.org, Frank Scheiner , Mike Rapoport , Mike Rapoport Subject: [PATCH v5] arch/ia64: Restore arch-specific pgd_offset_k implementation Date: Thu, 13 Aug 2020 23:55:21 +0300 Message-Id: <20200813205521.5405-1-rppt@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 65AD210064ADB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Jessica Clarke IA-64 is special and treats pgd_offset_k() differently to pgd_offset(), using different formulae to calculate the indices into the kernel and use= r PGDs. The index into the user PGDs takes into account the region number, but the index into the kernel (init_mm) PGD always assumes a predefined kernel region number. Commit 974b9b2c68 ("mm: consolidate pte_index() and pte_offset_*() definitions") made IA-64 use a generic pgd_offset_k() whic= h incorrectly used pgd_index() for kernel page tables. As a result, the index into the kernel PGD was going out of bounds and the kernel hung during early boot. Allow overrides of pgd_offset_k() and override it on IA-64 with the old implementation that will correctly index the kernel PGD. Fixes: 974b9b2c68 ("mm: consolidate pte_index() and pte_offset_*() defini= tions") Reported-by: John Paul Adrian Glaubitz Signed-off-by: Jessica Clarke Tested-by: John Paul Adrian Glaubitz Signed-off-by: Mike Rapoport --- Changes in v4: * Correct the comment that I missed in v4 :( Changes since v3: * Correct commit message as Jessica suggested Changes since v2: * Rephrase commit message and comment about pgd_offset_k() Changes since v1: * Fixed typo in commit message * Slightly reworded commit message to sound less weird * Included Adrian's Tested-by arch/ia64/include/asm/pgtable.h | 9 +++++++++ include/linux/pgtable.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgta= ble.h index 10850897a91c..779b6972aa84 100644 --- a/arch/ia64/include/asm/pgtable.h +++ b/arch/ia64/include/asm/pgtable.h @@ -366,6 +366,15 @@ pgd_index (unsigned long address) } #define pgd_index pgd_index =20 +/* + * In the kernel's mapped region we know everything is in region number = 5, so + * as an optimisation its PGD already points to the area for that region= . + * However, this also means that we cannot use pgd_index() and we must + * never add the region here. + */ +#define pgd_offset_k(addr) \ + (init_mm.pgd + (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))) + /* Look up a pgd entry in the gate area. On IA-64, the gate-area resides in the kernel-mapped segment, hence we use pgd_offset_k() here. */ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index a124c21e3204..e8cbc2e795d5 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -117,7 +117,9 @@ static inline pgd_t *pgd_offset_pgd(pgd_t *pgd, unsig= ned long address) * a shortcut which implies the use of the kernel's pgd, instead * of a process's */ +#ifndef pgd_offset_k #define pgd_offset_k(address) pgd_offset(&init_mm, (address)) +#endif =20 /* * In many cases it is known that a virtual address is mapped at PMD or = PTE --=20 2.26.2