Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2541935rdb; Wed, 15 Nov 2023 04:03:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiUDfinuinYMEQcx/tf4A0BTod+0OpzQgkJcbIubOPUku8AXYVJA/mP2e1EQmFLTQPQiGV X-Received: by 2002:a05:6a20:8e1f:b0:187:2521:4581 with SMTP id y31-20020a056a208e1f00b0018725214581mr4447535pzj.60.1700049815090; Wed, 15 Nov 2023 04:03:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700049815; cv=none; d=google.com; s=arc-20160816; b=G3FBGEmPUESRW72z0K1Sm/TP75TQlo2JsflvVa4EzDLn5lOExrg7wVZmCFuDeFc2FQ iVPBJkEQxkChCRbEZzFGGxx4LfJ22TnF7Mx39AOHA38lsYVWJ7VY2NQIFzVIJqNrjJyl JM+OYwXx9rQ6Ed8+tnEX34xC8fAH7JIm/WbOhc6EgvHYfgvphpRV+1KojEiwauDxAaEB U8p3qMYZyTb0EfUPWhgn8YntVOgFagBFjoQ3WIskFECUBZYerXY0gnb6a5f/BkaI/VuC Mn8sCUoFxrZfDsNKv7lKM7ocPhkwwjzW9vI5uxn5uW6BgZwQr7nXyTBhgcO1y46lGWky iEqg== 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=gbuJXpOtBglzogOXE2lmLOYTc55Yb/23/a3D0kZY6GC/1HhPlj13k3o1QX/xD54tXK NWubTAVYidQc9CgUqmk88XAqQ1rrMNjwHdujZLRtx+aScekPdehcYKqCm1qwMmlnPRoY GwUQgJoJ8N7OuYCJ/f033nfYQ6v2LqYlwQzjd0j5HBs8larbVAVFl33O4bBoSW3oQmZJ jIBZNx9Em95OgM6N04DlpF6Vx/BIoaE+ZYpQ1OlTE94rYcjylU1+c87eXo+rewSeSrEc vLHhZ5noR6SmleT21AOUPMZYCuKW2PEmvcARkxmmSvYK09VNSOQ8cIlgsS6V87KcmoFa zI4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SBRTvS6f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g18-20020a056a000b9200b006a68a46431bsi10333677pfj.50.2023.11.15.04.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 04:03:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SBRTvS6f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 6668F815D7C1; Wed, 15 Nov 2023 04:02:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343759AbjKOMCX (ORCPT + 99 others); Wed, 15 Nov 2023 07:02:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343711AbjKOMB4 (ORCPT ); Wed, 15 Nov 2023 07:01:56 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B943A197 for ; Wed, 15 Nov 2023 04:01:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700049691; x=1731585691; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7MgS2tz+eXb3t+LyzYLE/xkq/zAhJTq68EvRtEFLASY=; b=SBRTvS6fUy5VrPKbxaBejF+K7xljXAkIrJLWJXEb2qFTaZoLdsbQVzj2 ehgG+6UD3J35APjxTZyqKMJzHzk0WnIBqMeEBxSVtZ046No5fAZXwXEkI xK4dDcIbukFlc4KkVijm3JAttQFM5tORdofIPz8a2m3LDSmhAfW3TyRnp ShzFhV/nNKyJV6Q3dfVG9Rfw4UqnpFuK+9e3cFgAOaD7+2vT5ET3Tj87C qMf6wcUxn5d8SgTdwBYrZL6ZkzuNvxwZiVkeZQ3yW0lPkZ6xPhoQ8GQGF /I+lCWkurbREz7SH5cHD/j9Afv5T+6t+X8NCDLjB/pRj0zehezqrh1hy+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="12411963" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="12411963" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 04:01:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="6377702" Received: from mituomis-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.44.135]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 04:01:21 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 85A4210A301; Wed, 15 Nov 2023 15:01:12 +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: [PATCHv3 08/14] x86/mm: Return correct level from lookup_address() if pte is none Date: Wed, 15 Nov 2023 15:00:38 +0300 Message-ID: <20231115120044.8034-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> References: <20231115120044.8034-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 04:02:37 -0800 (PST) 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