From patchwork Tue Dec 5 00:45:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 173618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3133966vqy; Mon, 4 Dec 2023 16:46:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/t0qeTI+P8DODEaQEnUOVchXeUirwajsjWINHaZE7+6Kx82BGPRjQa/qIv9f8kGv2jI4A X-Received: by 2002:a05:6358:524d:b0:170:17eb:14b3 with SMTP id c13-20020a056358524d00b0017017eb14b3mr3107680rwa.35.1701737205853; Mon, 04 Dec 2023 16:46:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701737205; cv=none; d=google.com; s=arc-20160816; b=AnOfC1R0Edkn7Fml2N7LbF0duJKhRMFVYWv2fiR9X4i5cCP7lD8oPoDJqRt3U+mANM rwnE6kjndqQCWxaK0QnZMw/MnxPVJerzDktjcwG7kId4P1hTmOkjKGTSWuFlmn8LZPKO LWRQ0nM1V1ZZJiSV2n7Y8NSWSbFy3cmcNsX57r1H6wbGvrN8AfCwI8pt0KofeXFY9W1c rEg4zIT0EDQMOx8T94uqeFs+qYJ8jkziIlHpaFm1U/ZxXooePoX62sKH2Rh+UwJzNISP 6jkFBfnXMh/7CCjRIYFyH3fJ/Ykua8eEcRlMXdtQibL9TA1/xGlXhfo6Nd7vc4wG+KYB 82Qg== 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 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q5-20020a056a00088500b006c1222c5eaasi8775210pfj.175.2023.12.04.16.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 16:46:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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 2620:137:e000::3:7 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 53AF980A8B40; Mon, 4 Dec 2023 16:46:44 -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 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:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784400792446376862 X-GMAIL-MSGID: 1784400792446376862 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;