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 5D8CDC433E1 for ; Thu, 13 Aug 2020 19:06:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 25FF72078B for ; Thu, 13 Aug 2020 19:06:06 +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="S5XKfNNu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25FF72078B 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 B19628D0001; Thu, 13 Aug 2020 15:06:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA3836B0028; Thu, 13 Aug 2020 15:06:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96C128D0001; Thu, 13 Aug 2020 15:06:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 7CAA56B0027 for ; Thu, 13 Aug 2020 15:06:05 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 37DED824805A for ; Thu, 13 Aug 2020 19:06:05 +0000 (UTC) X-FDA: 77146475490.08.scene65_6301c9726ff6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 1555E1819E785 for ; Thu, 13 Aug 2020 19:06:05 +0000 (UTC) X-HE-Tag: scene65_6301c9726ff6 X-Filterd-Recvd-Size: 4342 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 13 Aug 2020 19:06:04 +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 1C3FE206B2; Thu, 13 Aug 2020 19:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597345563; bh=HhvSTvm9hpBFGnGUKEXn3F8cV/GqpooRW6lZ+5FbOWw=; h=From:To:Cc:Subject:Date:From; b=S5XKfNNuUeHzoblAyhaY9OgjcKcxYdhRP+LwvUMxk2LPYTMFoNsr+60I+vZNv10/l hrVUOS51VuCl0qJhh27FI839A6wQdOkDNbDpRBGXeM9SNn+AftCcB4xKT/CeICZkjp DkWOJvCdSdqCzFxOeo856/V04vi7Z4vopKn/3Ec0= 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 v3] arch/ia64: Restore arch-specific pgd_offset_k implementation Date: Thu, 13 Aug 2020 22:05:46 +0300 Message-Id: <20200813190546.4788-1-rppt@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 1555E1819E785 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 from pgd_offset() = by using different formulas to calculate index into kernel and user PGD tables. The index into user PGDs takes into account the region number and the index into the kernel (init_mm) PGD always presumes predefined kernel region number. Commit 974b9b2c68 ("mm: consolidate pte_index() and pte_offset_*() definitions") made IA-64 to use generic pgd_offset_k() which wrongly used pgd_index() for user page tables. As the result, the index into kernel PGD was going out of bounds and the kernel hang during early boot. Allow overrides of pgd_offset_k() and use an override on IA-64 with the old implementation that will correctly index 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 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..6ef501cd0166 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 never + * should 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