From patchwork Tue Feb 27 18:16:07 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: 207399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922503dyb; Tue, 27 Feb 2024 11:36:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVbzJSxRQvDFC4ACafAcC2NTmxaHvsY4K9ek5BD/Wh8eT/SfO9uH14kXbXN6t4o5crvNmXydNkzJ72MPFpAT43Yp/WkaA== X-Google-Smtp-Source: AGHT+IFnrcA8g5Wxhk5DIsPWFREsvBGdExBmNVAmh0U4QQ7x71GONGneDuyVe56RnLkbiItDUArF X-Received: by 2002:a92:d312:0:b0:365:8250:f2fe with SMTP id x18-20020a92d312000000b003658250f2femr12918661ila.0.1709062581595; Tue, 27 Feb 2024 11:36:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062581; cv=pass; d=google.com; s=arc-20160816; b=syvN/2O1bOH5RWn6s6BwQ8lQZgjsLHJKfdePrpJxao1+xvzInxyNTJkZMjQpHl/oIq rL5Arlva2cz1z4GDyjH6W6tSlWI9AuU7vUGXvSzg9nSrr72KxnmDsJCSbc9loMBBb1wU P0tvQ4QIPE19vIRSszIoK8FUZeP8Va3PJ5IN571zNNqLGSnYDxari5MnmugABVXUw14r BNFJ/u+7iTHSpk/JquixKxZTJRwYZwV6o6KPF3ebWZ7i4ouWqk9rYEOhj4CYooUoJtb0 +TEsdwFO0yCWry+PU2iplLvjC0J0UGmj+YeLVGqzocjldWWrZwU9bWSqJsa7yp+xNPqi 0VTQ== 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=Otj4OGZBhugULV/6kY5FIyqj8Pf7RY6Qi1aJNx4HnCDPiGsliupgGJvaLYoOe9rCzQ pwPja5RWlIrQvvjej9XUPdRPDszWjLdkmsovNeKsXhZkXuUvXu/vRlJAGenU6OIRAfHK wiwGSayIQTynoCxSbocFU0vRTo6oK2OqBlRdPsmltweliq05tDWRg0SgTy3zhm+jt1Ew ulVDf+NkLNiI400aEsdSBq5byJouaTCQEX37Mil3We/rCuCJmNQDYW9jla70D9WPXXud pP68+k2z8vxz4TBpGUhalALj7ZFmY79kwCdE0SIKbEX5MhNtIoswsMNQJfUFyQGJKDnf hcFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ecb1cKDv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 16-20020a631150000000b005dc4da21221si6001546pgr.419.2024.02.27.11.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ecb1cKDv; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83816-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83816-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9876E28E8DC for ; Tue, 27 Feb 2024 18:19:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40732151CD7; Tue, 27 Feb 2024 18:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ecb1cKDv" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 47F0D14AD23 for ; Tue, 27 Feb 2024 18:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057824; cv=none; b=cLweYUwMqFRMBIc51x2WVYTEcHLaWONkDr+jStnc1YX8xOdLmOiwhSa5SjCQ3LeoJ4GvGDzMPeq9E1ynMggXyhmq0kb5VSBmieMuBvvKgaIAbxrvMKoew+VCslDnuJlBdWH02jLgjrBkbRcp4tXNezc9xER0ORfZNL1wYlKfUa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057824; c=relaxed/simple; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PiQYFBpIE58zkVfKnDSt6CPj8UtMzCf8erSe4bhn5uTfmnxzs61f0o4F9KaWqSX80qEwsBXHzn6HSxyMonbdtgzzX3y/NQG/keyRph3xthUxz2yeI7WLfH3taBB9yHu0paKr0j1iARuK7G2iJH9mMmNfbsSO2/Acr50YVYGvtlE= 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=Ecb1cKDv; arc=none smtp.client-ip=192.198.163.8 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=1709057822; x=1740593822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SxAJq8PySGkIldIS+Dq+6BevKxjnV/qVUXBP60oIUiw=; b=Ecb1cKDvnj7O98b7Hvr9yu/Vt8vpwVAbyH4g7/3jNVmEocMX8soHTFn5 4c4at/LK02mTCLIcj+3kl1Xn9lK7npmd/N4fc5JtUvd+RxeZwhQqyvEev 0yYBgH14VGniu6GZIBEgVVh7tpI6GhEMuSjQ3mAE0Jqb4CSTTt+Hp3dnb RfvkYXxRzqJclPZXcYtOXZfrY6t89flpb2SGnS7Xxy8o/gzvPTJ0JAdwC /ph72sHtUykNVmMoaY2K4O4SXz4c3kxWW3lA/jJKYxtPjWb2YeY/e8+W6 whwYNXp4BZsSs15llJZagkjOCwMGSPw30hHz/b0bHE8k4SZVUa1nxC+Xr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966140" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966140" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:16:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032732" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032732" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 94635692; Tue, 27 Feb 2024 20:16:19 +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: [PATCHv8 07/16] x86/mm: Return correct level from lookup_address() if pte is none Date: Tue, 27 Feb 2024 20:16:07 +0200 Message-ID: <20240227181616.3032032-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227181616.3032032-1-kirill.shutemov@linux.intel.com> References: <20240227181616.3032032-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: 1792082005576719036 X-GMAIL-MSGID: 1792082005576719036 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;