Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1255091rdb; Wed, 24 Jan 2024 09:15:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9Z77Z/4w/EHSxyJWBmLzJ2mv2w0jcJ6a//8LpwgXYOE2hf0dBGeb+Jo2LFOrebGQssEf5 X-Received: by 2002:a05:6a00:4b43:b0:6db:ec12:5ba4 with SMTP id kr3-20020a056a004b4300b006dbec125ba4mr3790173pfb.34.1706116504395; Wed, 24 Jan 2024 09:15:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706116504; cv=pass; d=google.com; s=arc-20160816; b=bF1W37z00Uad1QaJ77aevWB2JR9cXYE/h8Ibm1mjzwB5QT/mUdgKMHss6sB6OzJquR fxv+NTm6IFWe9lreLFAkfKkpFX74kpzDN/OVT/KVJR8ooXi4Ru56NA/BbEAigBQ4+1Hj 4RkVKRGqKfD6RkJgvRwGNNVaaEIvRMjCw4CWqzA285SNNR1xOKa5AkP+bJ9d1WICBh6O n4AMVeuhZQsCjyssS2YQOI8chZJ82pm5TkpHZwGku8TM9zyYghmlurhywGRE1PeCuSIy 5GPBwJ3A88ZJ946EPFZj2bBWEkXUurqr3aBKSVVs1L5ZjHadD0GpjcEnelFhQ3DAmOVh eJ8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kxw9uVRF0uklRfRh6iTwvS8jLXK1PeQrAkZPaXxZPCw=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=lzQyyW+jf5fC7mUmWyVIAD7b4ggR3VmyTlhMYf6fTd0SOPm0458cTPj4haMzRftAEm ghRpUKOnLxfpDUvBzaEv0s5KS2xbx4gNGxTjEanhafEwjw7lbecBmTuzf5Hm7pORK6WQ PAo2QWJDTHLz2EbpRpzB1pC5MU5ME/rCDiCtweqewrRFAu4jpvdwJCBIMZCyQ7tmggYg JCsamdyXTf70xbqDEYtqehk743dosDcFA9qslL2Uidix0FwHl+6GzfQInwRVadQRc62t KCDTK7fPJmGbaxPKNTFVElVB1sO4a+c9w06V25a46/ZkUzP/cbcBGGHa0fgP6siRMmq6 DBzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BpSsIBWA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t14-20020a63224e000000b005ce0160641fsi1553208pgm.551.2024.01.24.09.15.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:15:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BpSsIBWA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37033-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37033-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A9190B2B629 for ; Wed, 24 Jan 2024 12:59:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F3B227CF1B; Wed, 24 Jan 2024 12:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BpSsIBWA" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFD877C0B7 for ; Wed, 24 Jan 2024 12:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.31 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101023; cv=none; b=K28WP57+eNZ67rVM/cYuYPCzwCn0Mu+tsUN23hanAIJdNmtIFKPA6Wa8guwiRhtM8f61oEsmowcTd8DkzAId2dpv1ewqCAc3XWfp3ojGYKjf+c9RvCapD0DYFqnnnlVQB85sazThO5We2M7uwi+Y1yI4LBzV70hYU/iCXNcvoPo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101023; c=relaxed/simple; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UQ9SWfRtwHXGQE1H1U8qJnNkSK5RLclo8x4V1J55gf/O4gz2SPU3cBDjOr4KFEQ0zuiNGPEWlIoXFApZr96jE5en/MNXioLU3ZsvxHxzbnAP+lGJA9lHYv0T868bPWwq5pUUuHzQu1CBRwyF6Xlq1AC0hdsAGjVkHwsnqaBATvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BpSsIBWA; arc=none smtp.client-ip=134.134.136.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706101021; x=1737637021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; b=BpSsIBWAlNmW7Z/DX8dU1I8d3Pt+bzm3x84Ho2XIuPQR/9n7tjCReKys G9WYRWxN2B2fznh0uRwR68yW/nYbSzAPlZLDi723Ux0IUE91Ns2QGvcDD 9VoMpRsroVK3Xpals6lohe3q5DnB7q6IZf31gfnFtaOhOV4ADwtz8bBvX muNzaZ4/qfamxM/Ie+H4k82F8S0wmvIh7kIm7D/kpvJkvRZ/EfNrBACqW t5w3KpWvLeS9e8DBWVAqcL1M3qHe9DKu8zQuRZvb29Qydbxrw4kN9OSPh yUiPBw5mPzjELHZFQqGdN31fn5Edzcdh2z3AJ+iUP7qWEqxFqW1syhS0y A==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="466110225" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="466110225" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 04:56:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="735924096" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="735924096" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 24 Jan 2024 04:56:53 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 6D64D75F; Wed, 24 Jan 2024 14:56:02 +0200 (EET) 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: [PATCHv6 07/16] x86/mm: Return correct level from lookup_address() if pte is none Date: Wed, 24 Jan 2024 14:55:48 +0200 Message-ID: <20240124125557.493675-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124125557.493675-1-kirill.shutemov@linux.intel.com> References: <20240124125557.493675-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 f92da8c9a86d..3612e3167147 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.43.0