Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp348629rdb; Thu, 5 Oct 2023 07:44:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNNaeZOCjboVKQOFHV1OLRL/uXS6FCw/5McmJljd1mgrC8WwSxoVYy75q2FQT8DdPVb/qd X-Received: by 2002:a17:902:ecc8:b0:1c4:4a4d:cda with SMTP id a8-20020a170902ecc800b001c44a4d0cdamr6248456plh.15.1696517056616; Thu, 05 Oct 2023 07:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517056; cv=none; d=google.com; s=arc-20160816; b=lbKNd2nekyrthTq0yB+/jXfcfvYcwe8xP/O4ARQ5Jb+AKsqSFxp2EpqcLmOOrKmUEr 3Ev1kNd66/X3jhmgOFWjGFsry87j66TEE40WWuRMcGpn9Z2rz4oCcdY4VPs3u9bErOBB hWNHm4WhdXOKmm5sdOkkIA+8LDxHifFPlAlGXGmpTDw6gdCI0OJf4+5XwYjvWMzDR8dp s0tgS22FTFJbhUA3mtZuXc+mqAO/tiqzK6JCkoSYdlkXNSxB5xegRNf/j9Lk+qHGZUt9 Mh5HwyIVNt0h+dHhT4Ii7eHKbUF3PXXyoHTqvPsnnJq/6ciNdG8iNvUPRPcYgtHb96Gj Pjcw== 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=F1gpqSS/HYttK+doOKuW4yrAifo5qykyq1MCI9SIQmQ=; b=juAdyjApQfLNc4Ux6oSKDq7q9/B2SNyoG7YFkpcYIbarIYQAaTZOI561rqi72qaL2N g1V9gVLSXykw2sp2LfV37LqNG82fOs6KR6S0wRUemuA50M92RKYiBiKH5XbiZ1uLeH4w 8XYx3+ql7CBNyc9R3c3zaGAsNwkg+2kOmkbHekE1gIirrZ5V/sY5JmZ4M18yYQ78ggeg u3EPrylZ6Dg2F48olMFkrx1WXcDYNfwLoA+fnXXPxT7vMcZEsTxpGfD4/ur9DdUT0oYa /jsxUhpVyH2mFn4YLo1M2PKLkAetkMlDavwupPinsIL7pB3TVAmLTzFIOB6KUIz1b6QK GX4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KBQQ6DFC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id o10-20020a170902d4ca00b001c7347e993esi1657814plg.17.2023.10.05.07.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:44:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KBQQ6DFC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 155C2867F1F5; Thu, 5 Oct 2023 07:44:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237224AbjJEOnw (ORCPT + 99 others); Thu, 5 Oct 2023 10:43:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237218AbjJEOiu (ORCPT ); Thu, 5 Oct 2023 10:38:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0308C93C1 for ; Thu, 5 Oct 2023 07:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696514671; x=1728050671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7MgS2tz+eXb3t+LyzYLE/xkq/zAhJTq68EvRtEFLASY=; b=KBQQ6DFCrx4+ZQd8zRMdkWnWGf4rhDeCaLqhsT/rjjgN7BJWMQek5rA9 f7MjB+0hO+QyYNGdlr54WWenJHJCslo/3dZNlX4vZ4zIaF0MNBiFqXDGJ OBuMJ9Wk3nlaZ7wkDFJcCSOcmc66P2S3ei7hdsMwRaSRvXt2dtFxO/EnB C3/hMQjpaCT+tdx/MAFtzCYelG/5qDgKmj9ES02QmRJq3xZoUQtP9kpCi Vptp0jQ/96SfnKSDRhnLXllcT4WukoyXd77AgITqnSX2aVi45Hyqlz2cf hqspXW9mvrp9TLXwRmrNdN1X+lyykRhHXJwN3AKJoiBMqHoD2DSmlaEof g==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="382357561" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="382357561" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="817564320" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="817564320" Received: from skwasnia-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.222.71]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:23 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 52B2510A150; Thu, 5 Oct 2023 16:14:14 +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 , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 07/13] x86/mm: Return correct level from lookup_address() if pte is none Date: Thu, 5 Oct 2023 16:13:56 +0300 Message-ID: <20231005131402.14611-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 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,URIBL_BLOCKED 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 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:44:15 -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