Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3081029rdb; Mon, 4 Dec 2023 16:46:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhrhqE0dexnFY7hACmCm7/WPE8HIoJR5U8Y+0Lpn4LHeLyc7gOyY18/NI7aJ3edPYkFoWp X-Received: by 2002:a17:90b:1245:b0:286:6cc1:293 with SMTP id gx5-20020a17090b124500b002866cc10293mr431026pjb.94.1701737206854; Mon, 04 Dec 2023 16:46:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701737206; cv=none; d=google.com; s=arc-20160816; b=dPBSnNgnjAjhWl2MYSp98S2oJIwG3rIWgJ/zFDb/bblMXnog2xYOeftTDc1drWG6CV 79Zt0zd2cxumC7kpGtBXEjzvspc8MLj31UpS+y2FemM248eaITk4EknjQJtDyCUWD0Nf lbDJZSw9KQakRoURGGmgRvm7thG1Q3+8yiFHLghidNzInprY/KZ5TfYSp1EbksVWlDp4 euffHZcBelZV8QWVWY6D9UF71WWJoIie8GXmjSj6u7dRfh+aZ6soXICS3Wg371qvXfWX pXtenG0GRckOIrc71Ym6gwLkgjtp8THW3Zj+Om+BvQzgkVfYFGWkP1/qYiWXI1FYpLJQ jbtQ== 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=zA2fHex2rG7B979fzbyx1/3VW+BB2gBeo0EHiQQzASXFJRHgcC4dGMAvygrvrCA3HI QDPz8CLHc8M3/Kx7g9pee12T3bEnPD9oiQBaUDeLH1T7HEE6OY82mgc+7bJDSOQlYVUp 2F0o3k9UaMFcsjUh/8rIaZlyqtfWEMLAuqEQ5vBv6aFWpgtr0hjIcHOCy7qjKeyYBXZ+ bqIMN1EpSyIvEIqPpl4uycGi/ml/AebWKeHVvK9l0dDolcwxFPWUHbSHQ2QO3vqgM78P 8OFYvapUsaalcQgDnqSchtq4qq+LddYSbhjv6QM8Msz/cZlk7OAufT9JVFYTFrJTyloK jp8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="h/2DWoQW"; 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 k18-20020a17090a911200b00285196ac998si4545770pjo.104.2023.12.04.16.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 16:46:46 -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="h/2DWoQW"; 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 631DC8072147; Mon, 4 Dec 2023 16:46:45 -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 S1376314AbjLEAqV (ORCPT + 99 others); Mon, 4 Dec 2023 19:46:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234800AbjLEApg (ORCPT ); Mon, 4 Dec 2023 19:45:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B6C310F for ; Mon, 4 Dec 2023 16:45:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701737136; x=1733273136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7MgS2tz+eXb3t+LyzYLE/xkq/zAhJTq68EvRtEFLASY=; b=h/2DWoQWkX45VJv1byn7pMDOhmAtcyjOwYlZCxaBpH6PMXzcDZJgsNLR T18KJ6FZI8IXgdVMwJsRxwwwG71o6QeumVAxEKfArLN6MqCjQyw8pSYN+ Cajon8sbvSooktnuSkkugH4j0SAMP3VGQZgMfHaFkiwxstG/32qOSz4U4 Z1Q1khz4fVkCYNw47Sg5AY9U/PxY8xll7iHL0HPtcBPHgXhBtwllSA77o gKeSQKanOgFzi8XwlNNs3q2FWuNbl29rB7sum5Msm+DtdCHihY0ZZIKbz jpy8vzL/kW0D2Ev3PbZ+2AkFIAsBLy/QHuCv7Xmk0E55tjesqSEzTze0b g==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="392688715" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="392688715" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="944067949" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="944067949" Received: from abijaz-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.240]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:30 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 7E6FD10A448; Tue, 5 Dec 2023 03:45:20 +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: [PATCHv4 08/14] x86/mm: Return correct level from lookup_address() if pte is none Date: Tue, 5 Dec 2023 03:45:04 +0300 Message-ID: <20231205004510.27164-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> References: <20231205004510.27164-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,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]); Mon, 04 Dec 2023 16:46:45 -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