Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2375084rdb; Mon, 12 Feb 2024 02:47:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPRImXoD0yJB6bLvV7ezU1erM3Zeiut5WwZ3Ahm34CcTAom4FVtZ193sGHGa4xwss1pPY2 X-Received: by 2002:a05:6902:e12:b0:dc6:b088:e742 with SMTP id df18-20020a0569020e1200b00dc6b088e742mr6343917ybb.8.1707734873802; Mon, 12 Feb 2024 02:47:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707734873; cv=pass; d=google.com; s=arc-20160816; b=A7iJtKJPvkW6jJYh4wRcS3WjDF3lBAlvZ+mCuhB5rEd18hw/xFSkhK/BKEmN+v8uwf U778nAS9K64e3E2rSzOO0B6Eg1HlMj2ms29/t8g4zTWRRjhyIDajWdRcuOwCI8Fui4wH 6lvRoAB3VywPFzf2ni9gJtYl6W7DLQUKiE1FLo5eKS9M7wH6xff46hUN2S33vo0JBCi5 rcOXn0e0o6Er/MMzGRwq8c7EDYtK51s/Vyx+i2SJWz/9T417D2nQl/ulZ3QUImShFXlC QPE7OnHOxvzsb5z/Jw5l6MRDQstRHxoppFQt7XQSftCm6qmJr7jfZ8MuvHrmWMXgSrZF HsHw== 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=eUh9XA9SehOx/YhtpoveynW8BRAWHkbsOAhAZsiEH/U=; b=RjbUK5SHPQK5cojL3iNYiRCmbF2J76IspZ3HXm8Zr6iuYl6obQllDUZ39uQ0kq2vXC A/DhpRDAa/TvgmisoGdXnD6HjEzZ1Hz7ZvyNM+WQXGWyJnHV0zu060EhaAWZgXt52IJP 3REYtRaRzgIB+FLUnNfio70XsCTWi+718jRYX3D9hggotPDc5mozctKFcPFAQjf8Sf0p AndbalxW4ok8PiUP2/E+aeyB1ZqFvCyFN+oMfqVRHEWYUtIIBqsNOe1tIHIqZAH509+1 9zWM5K1y1Ge9HOodtglL1vDh27pDr+EMJ8nraWWdJQ6BuqTFUi8GpCkJSGlfC3eh4B3h SIVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RGgpLoD2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61357-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCV/LDP9MBOY0vHzlQqY0EXGujOKZpI/IOS7r6HyNznAi+MR8sQgcLhtk591S6OrBz2IDTlDv0+KTOobhd340iPemu7hJlxZ27ZQIG/1VQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s28-20020a05620a081c00b007858c17df9dsi5491294qks.226.2024.02.12.02.47.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 02:47:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61357-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RGgpLoD2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61357-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61357-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8DE9D1C2244E for ; Mon, 12 Feb 2024 10:47:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CFF93AC2D; Mon, 12 Feb 2024 10:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RGgpLoD2" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 4406B3A8D5 for ; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; cv=none; b=JENKDga0DLLeACPA8tewhBoOEToWoftolWvVdpozHWUxsAcyog6gWlWShPzJinF5+DCROMTQrc5UmYG4sFKTCb1tpTicFy3GHhfIDHrCET15XN+82sOpQMi/qn1PwRXMWIUMSOhuQ5Izr3Eh2B+8xh2TxqJQ7NPfySyIS6oKOcc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; c=relaxed/simple; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rY8M6HCaN1Y4CAKHnrrxDen3YPmktBcA0irOjBb/2FUTaB6CY8C5+Nro5obi1hG05jZi0PlpDUbcuEi+TgBrphd2K3OXFJ/8an0/kgoYMlxZvZkosyvqh54gWI0fbtWkgVTTn38CcRXUepAbgrFTl+8p3SqDYIoXu2ne+xb95es= 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=RGgpLoD2; arc=none smtp.client-ip=192.198.163.17 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=1707734705; x=1739270705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; b=RGgpLoD23pZM1KAvseQfdqsnUo9zf+Vh25P/SEJo81e5kHVkjDY625Ti 13a5h2HGe3e6gXCoW7ApB1DIirVB2QGbbtJ72xxmEqxT3s39sJU66KhMJ TvHSc3mK2hgVxGpgq6HujSHT10tcSBVlk1efJA7vYV8ytTGf28SJEP5Pj hkWPZJ6ze6kUN3gY4NmP4WtCGvma5Xg82FUWgdjQ3m/qmYdK6MCmp4rp3 ufhqPVyjDks87adoEfDfYCoVP1yZU7tYgfomZx1P/HqVf0PQLsuqixvx5 GxN4bA+LYQMeJuBdg3AAOzDp/REq4IX4vvZl3q+T6eMl6sQyrE+qSIbgA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585047" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585047" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035597" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035597" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 483AE53A; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 07/16] x86/mm: Return correct level from lookup_address() if pte is none Date: Mon, 12 Feb 2024 12:44:39 +0200 Message-ID: <20240212104448.2589568-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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