From nobody Thu Dec 18 23:05:09 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 AEF8816A953; Tue, 18 Jun 2024 14:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718719309; cv=none; b=bDbSQFyLfN/PDd9n7eXeWUMZ9ZCPpJC49PzOmUi0/RCZoajuZFN2I77GSauwG1Hcrg8MmNNWY4wkuQVBwatv6ulHwlRo7BUBQ1UATczgb9tdCR58tRsBc/BqtfTzrbEtL0ZUGp/vefT+pDtzMPEsMYMYaYh2OS7SAFubyfwGqoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718719309; c=relaxed/simple; bh=n3RH3MQHU7G0vP7NA9NG2KXIVrEweb8f0LbcattsHcs=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=OyUn1fMZmkuapgVX+g8fEV9lkZuWhBpRARcmygAQSMMmSLsQeM63Gg1akrLhy7Je69l0AsY5+WAf4cVKnfaYkvI1wZeuxH8qg2DW9XSmAn/v+7xm2ZZl5xZe83Pq3ia46bR6FigIuzD6L/AcKIcneY2ODarzULAZtThu0oBZTxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mFc3iOYi; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WL2UuDs3; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mFc3iOYi"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WL2UuDs3" Date: Tue, 18 Jun 2024 14:01:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718719299; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iIJJnWb/VtD0XI7h2vuxtI2j2mK9glkVqOu+go+pKDs=; b=mFc3iOYi1UkptY5lSzBjZcPSmus2FkrbfOwwXJR/ldY6tHiJtnysS01x4kBLHT7KLoOGsN +t91Sfx0I+OHbk6oSi5S+r4G10ufIVy4TPTbkuzp/4jqscp6ZI3Yk8SmvuhIIOfnZAAhoB GbymaIMjxcuN/xsnT0y/ClmXBh3pxoKtch0XicnfYL7++38fOM+IViOblmZ0noeQ1RrqxR i0Cprg1/opLi1GMY8lzJNiUM1t7ENEa4/6iOp0oo3hKV4OmFGozSpDUhV7fAfpKbWLcX4Z cBpQoQzmNOeG7HZCFBDviqhEeWsU1H7dCITHMs9sfMIZ+tG2GympEnCoxfKizw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718719299; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iIJJnWb/VtD0XI7h2vuxtI2j2mK9glkVqOu+go+pKDs=; b=WL2UuDs3SjunaCHHyjso8exoC6HmQjEtQFwObS/xeDzbWgX3+N93DQJBEY+YdV5TgTLH3s 3s+3Yd1TVkx1uBBQ== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cc] x86/mm: Introduce kernel_ident_mapping_free() Cc: "Kirill A. Shutemov" , "Borislav Petkov (AMD)" , Kai Huang , Tao Liu , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240614095904.1345461-18-kirill.shutemov@linux.intel.com> References: <20240614095904.1345461-18-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 Message-ID: <171871929865.10875.2820034553680551750.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/cc branch of tip: Commit-ID: d88e7b3e35cff2c318042990d70828f64c3ae296 Gitweb: https://git.kernel.org/tip/d88e7b3e35cff2c318042990d70828f64= c3ae296 Author: Kirill A. Shutemov AuthorDate: Fri, 14 Jun 2024 12:59:02 +03:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 17 Jun 2024 17:46:22 +02:00 x86/mm: Introduce kernel_ident_mapping_free() The helper complements kernel_ident_mapping_init(): it frees the identity mapping that was previously allocated. It will be used in the error path to= free a partially allocated mapping or if the mapping is no longer needed. The caller provides a struct x86_mapping_info with the free_pgd_page() call= back hooked up and the pgd_t to free. Signed-off-by: Kirill A. Shutemov Signed-off-by: Borislav Petkov (AMD) Acked-by: Kai Huang Tested-by: Tao Liu Link: https://lore.kernel.org/r/20240614095904.1345461-18-kirill.shutemov@l= inux.intel.com --- arch/x86/include/asm/init.h | 3 +- arch/x86/mm/ident_map.c | 73 ++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+) diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h index cc9ccf6..14d7272 100644 --- a/arch/x86/include/asm/init.h +++ b/arch/x86/include/asm/init.h @@ -6,6 +6,7 @@ =20 struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ + void (*free_pgt_page)(void *, void *); /* free buf for page table */ void *context; /* context for alloc_pgt_page */ unsigned long page_flag; /* page flag for PMD or PUD entry */ unsigned long offset; /* ident mapping offset */ @@ -16,4 +17,6 @@ struct x86_mapping_info { int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_pa= ge, unsigned long pstart, unsigned long pend); =20 +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd); + #endif /* _ASM_X86_INIT_H */ diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c index 968d700..c451272 100644 --- a/arch/x86/mm/ident_map.c +++ b/arch/x86/mm/ident_map.c @@ -4,6 +4,79 @@ * included by both the compressed kernel and the regular kernel. */ =20 +static void free_pte(struct x86_mapping_info *info, pmd_t *pmd) +{ + pte_t *pte =3D pte_offset_kernel(pmd, 0); + + info->free_pgt_page(pte, info->context); +} + +static void free_pmd(struct x86_mapping_info *info, pud_t *pud) +{ + pmd_t *pmd =3D pmd_offset(pud, 0); + int i; + + for (i =3D 0; i < PTRS_PER_PMD; i++) { + if (!pmd_present(pmd[i])) + continue; + + if (pmd_leaf(pmd[i])) + continue; + + free_pte(info, &pmd[i]); + } + + info->free_pgt_page(pmd, info->context); +} + +static void free_pud(struct x86_mapping_info *info, p4d_t *p4d) +{ + pud_t *pud =3D pud_offset(p4d, 0); + int i; + + for (i =3D 0; i < PTRS_PER_PUD; i++) { + if (!pud_present(pud[i])) + continue; + + if (pud_leaf(pud[i])) + continue; + + free_pmd(info, &pud[i]); + } + + info->free_pgt_page(pud, info->context); +} + +static void free_p4d(struct x86_mapping_info *info, pgd_t *pgd) +{ + p4d_t *p4d =3D p4d_offset(pgd, 0); + int i; + + for (i =3D 0; i < PTRS_PER_P4D; i++) { + if (!p4d_present(p4d[i])) + continue; + + free_pud(info, &p4d[i]); + } + + if (pgtable_l5_enabled()) + info->free_pgt_page(p4d, info->context); +} + +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd) +{ + int i; + + for (i =3D 0; i < PTRS_PER_PGD; i++) { + if (!pgd_present(pgd[i])) + continue; + + free_p4d(info, &pgd[i]); + } + + info->free_pgt_page(pgd, info->context); +} + static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page, unsigned long addr, unsigned long end) {