From patchwork Wed Jan 24 12:55:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 191582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1016129dyi; Wed, 24 Jan 2024 06:15:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnYq4x12x/CKD6RZep09H4ycgybtRQGkP6QgfscSRYuZ9XfMbsSfKpmWxlEu+I2Io71N3u X-Received: by 2002:a05:620a:4310:b0:783:98c4:bcc8 with SMTP id u16-20020a05620a431000b0078398c4bcc8mr7870972qko.10.1706105751078; Wed, 24 Jan 2024 06:15:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706105751; cv=pass; d=google.com; s=arc-20160816; b=K42qBqv7NIk6p1Ryzh7SHNvWIZWWoFQsCnMYWyJ4YNahPLB9SJeDtWM3RitAGsGlp2 KUkwkey3wOfzaoJ9xzk2+j2IXFT60EFpXS9lNvKheQ1TXdXPUCsO+h97uU25FlTvFR6v 2UX4sJz7dY2a4uqYFrswRp6R0pXiD7QA4UPMA+nMiBrLNJSJ6LlYZzms1muDaVj1oxmM 9G+VDCEgFVzEHcLOoxt1v1X1jxVznrAMlTD372U0gMDbD+0ZLhvPEkI09FyqKRm79NpM 8flzaIevwQv+FzK0N1i2giNR+8zKJj6KNksA6of8DCSLRw9fhFBwxFv4l061EJj/0xiL dydA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37033-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id de42-20020a05620a372a00b00781c33a3605si11272850qkb.110.2024.01.24.06.15.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:15:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37033-ouuuleilei=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 BF1B11C258B9 for ; Wed, 24 Jan 2024 12:59:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC0FB7E575; Wed, 24 Jan 2024 12:57:05 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788981544017242822 X-GMAIL-MSGID: 1788981544017242822 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;