Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1092680rdb; Fri, 20 Oct 2023 08:14:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7bikVtgZGZerBPSBHikjd6I1okzFUkJAUrjC/PnNw1AMzydw+KYEOM5qvo9X2vi/Zou4t X-Received: by 2002:a17:90b:3c0d:b0:27d:29f6:79e0 with SMTP id pb13-20020a17090b3c0d00b0027d29f679e0mr2359937pjb.17.1697814851648; Fri, 20 Oct 2023 08:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697814851; cv=none; d=google.com; s=arc-20160816; b=RgC2K5902h+ouqr4WxrB0s2Weh/6r7KTYnWqOOz6Pe8+TASlF+qgFupzDm5b84v7Bi GtaIdS00Y8VN1hrG9lQVwrGOBy3gUSgtHBQFkO6b5ED4yN8dHKvDiyWRhbE1cv6J7hHb cR+sIvrPPi3WBNmE5rYCRwryPzzmGUOhx91cCBqedDuQgh/E5cpsg1Vq2B/Sa8IG2nc6 TOnH30uB+/LeXdRJ+3tN+jjH/dqWi80juVXRzKcKkrqcNA4GSuzr2T4rsmxGF2dflnSL Cbz+omO3id2vf2FyxFi/TiUCbv/ImvJGh30hQEBFCO5BrkexNDzj13tD2tN2bZwe8ZmF UMbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nRb9odYj0zuUgjn5mN2pRzKe6eite6Cnh5+z/pgqCLI=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=1BkXHcKhRj74S3SjL5vtv9EYc8CgkDEYA/IdjKEySDcRz8WpQywJni5UbvvJrY994Y 4/hhBOFUgB4DW/ugubXkt803fqZn+JiS9kR2R02qmf6YpL/7zHigRXSY00952VCb7mZx CJnGmA3ITcbUbakrpXt78vikkFojI/0B5P7VB3qB4PYyabEqPkvDH6zeARa3OgiDFiKc BZ+fQxqSEbDRUswnp6Q3acX/6GPockLsE3I4kUhcBq+iaTSlRyCbB66ysem2zWY4cLsH 2x+Lj77SNck2xidtLYvFIZi3zS2qnTbq4qMTJ4gUnAC7Vo5mnu+zbwe3Ml7C8NWT57jb W0ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="DHMT5/8/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ch10-20020a056a0208ca00b005accbb92b70si2006268pgb.676.2023.10.20.08.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="DHMT5/8/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DFA6982E17FC; Fri, 20 Oct 2023 08:14:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377741AbjJTPOA (ORCPT + 99 others); Fri, 20 Oct 2023 11:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377689AbjJTPNk (ORCPT ); Fri, 20 Oct 2023 11:13:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1659D5F for ; Fri, 20 Oct 2023 08:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697814806; x=1729350806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7MgS2tz+eXb3t+LyzYLE/xkq/zAhJTq68EvRtEFLASY=; b=DHMT5/8/PBgoZxM20KOoJXYe3xyl5N8oVMLAVTMjxUAMvBfh1T9aW/5R RcFjOLRXl+PSQS6oqFu2lrrBZgsuU/5oSUn+U0g9+ePG1eMSiXManv5Ed e1SRJlFRQbZ7zTfif1GumC267X27dB+H1iN8Jh+miXD/3A7aHN5qn4lcl IbFYe6or020939C9jUfqa6QDkdUtsn0ninBgdHi488jsLJzRSngOqS/AW MGnxkPsnf8EYksLEcXvNPIkv+kkqn3dvHKLwXFmMzOEZerGeYNfpneWnq f5feQkvr+VqJqD84PywbeHhAAqBmUO3ob/uC6ZwSNXZE4Iw1ybiDY2pyG g==; X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="366742898" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="366742898" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:13:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="1004634221" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="1004634221" Received: from dgutows1-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.39.237]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:12:56 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 3109210A299; Fri, 20 Oct 2023 18:12:45 +0300 (+03) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 07/13] x86/mm: Return correct level from lookup_address() if pte is none Date: Fri, 20 Oct 2023 18:12:36 +0300 Message-ID: <20231020151242.1814-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> References: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 20 Oct 2023 08:14:09 -0700 (PDT) lookup_address() only returns correct page table level for the entry if the entry is not none. Make the helper to always return correct 'level'. It allows to implement iterator over kernel page tables using lookup_address(). Add one more entry into enum pg_level to indicate size of VA covered by one PGD entry in 5-level paging mode. Signed-off-by: Kirill A. Shutemov Reviewed-by: Rick Edgecombe --- arch/x86/include/asm/pgtable_types.h | 1 + arch/x86/mm/pat/set_memory.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 0b748ee16b3d..3f648ffdfbe5 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -548,6 +548,7 @@ enum pg_level { PG_LEVEL_2M, PG_LEVEL_1G, PG_LEVEL_512G, + PG_LEVEL_256T, PG_LEVEL_NUM }; diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 6fbf22d5fa56..01f827eb8e80 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -666,32 +666,32 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, pud_t *pud; pmd_t *pmd; - *level = PG_LEVEL_NONE; + *level = PG_LEVEL_256T; if (pgd_none(*pgd)) return NULL; + *level = PG_LEVEL_512G; p4d = p4d_offset(pgd, address); if (p4d_none(*p4d)) return NULL; - *level = PG_LEVEL_512G; if (p4d_large(*p4d) || !p4d_present(*p4d)) return (pte_t *)p4d; + *level = PG_LEVEL_1G; pud = pud_offset(p4d, address); if (pud_none(*pud)) return NULL; - *level = PG_LEVEL_1G; if (pud_large(*pud) || !pud_present(*pud)) return (pte_t *)pud; + *level = PG_LEVEL_2M; pmd = pmd_offset(pud, address); if (pmd_none(*pmd)) return NULL; - *level = PG_LEVEL_2M; if (pmd_large(*pmd) || !pmd_present(*pmd)) return (pte_t *)pmd; -- 2.41.0