Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1626892rdb; Mon, 8 Jan 2024 05:35:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IG59aiOa0NLybWdq1AJIUr2h5MUJra6ir0xSurf52QjY6bIhIH1neWLl+4y/PkG580XMDN6 X-Received: by 2002:a05:6a20:7354:b0:199:9828:8b3b with SMTP id v20-20020a056a20735400b0019998288b3bmr2740486pzc.58.1704720953761; Mon, 08 Jan 2024 05:35:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704720953; cv=none; d=google.com; s=arc-20160816; b=hFqZpp3tmECPiNmusbF32A0pKxVLaV0tuH4mAsx+vLeLX+m0vv7D29nHKDtw+WFYau Jj4UICGo1HWEW2zUHVp1p1Ad+SeYRD1JR4WxglKwtVyDBjKTUHEWRrykjMJqzfUrAVBw +841rQDg96d6tfPP8ki33iqhpEXz5DRPUlIiojNkER9Ux5F9kvnM78EepIExpljHm8zR 2yJ0daSmnGpvejojLDQM88Vre5izW6FgyoFA65940ePRl2nFwkluPwlqooULp5+8OKZV CCCXi+DgU3TSDrGaWBVRUfWzTV+BD93nWisCupGMc4B6ZvXQr86mm6sdz3JEUPV8MKxF BuYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Gvk0gbFJDnzIbxq+TiL7WBux01UrurBcrcO4sf/5tQI=; fh=vhoPMhkAzfhc3N97pptx9qu50selY+XmIcJ7sMXv8Ys=; b=OhiinqTuSg6vB4HyhvQ/Zmir6XDklWheWFlCg/DtPHUPGuVq1oWxEL1FML+RQeSWMd N5SesZ98aNkNa4rwlYhjUAF+MNdIDpbgcANbat2LzFc2gSoyG7UMjQGND8iKeme8WzW8 X8/I1PdOBHylrGhXfXkkJYc8aZi7S6BeGPGaModes1pjc+HkoB9c2ozvvPdKEPC2Apc6 wELtKbsLaPd7B8Tau3mauxS7Ejq4om20fWnjALU1XPBlhiAe+sZmvkpBXAARP0hNemur DqzwnuVeoME1SQZMhRGaL3WjDx/jkepDZ5h+OD18wjcjQof/lTnmBfVvc9d6vZPETS6a bkvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wo70vdpY; spf=pass (google.com: domain of linux-kernel+bounces-19627-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19627-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jv3-20020a170903058300b001cf817b01d2si6005825plb.277.2024.01.08.05.35.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:35:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19627-linux.lists.archive=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=Wo70vdpY; spf=pass (google.com: domain of linux-kernel+bounces-19627-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19627-linux.lists.archive=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 BE998284064 for ; Mon, 8 Jan 2024 13:35:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 881E644C97; Mon, 8 Jan 2024 13:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Wo70vdpY" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (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 491EB45940 for ; Mon, 8 Jan 2024 13:35:45 +0000 (UTC) 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.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704720945; x=1736256945; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Tvyxi9rLpB6tMw43Ff+F4ni44W91YgQK1/npXpO1cwc=; b=Wo70vdpYUc7Cr1IosTWjGQfKA/Ynnl13U96bHDNkPoSY8m8Is44h7ePv gZal7uWhwSov8Ekp2htXKRrKa6dgBs3zWvQAgQgXOsHz+nfJGq8z9329Z l9DHJ2EKRje4b7jc4s0OrTHtjQ3FggVnKHwfjpDgIj38TbJx7oq09QZON TZtpOxup4i+zEUigKZ+6zLHzT2g5iQqdo+hkvCE53a20xMFbCqFJtyWN0 L1C6qf5MrjYgSc0f6vI+t4R5b1Ndv557BFhRJlTC6aw2gnBGt250eHz1L nJp+H4MLuFAZh6a9c91+Sd2dKdEAjRdaCBXjavF2wMa5ojZX5X+EIdy1p w==; X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="429064494" X-IronPort-AV: E=Sophos;i="6.04,341,1695711600"; d="scan'208";a="429064494" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2024 05:35:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="1028403682" X-IronPort-AV: E=Sophos;i="6.04,341,1695711600"; d="scan'208";a="1028403682" Received: from ddraghic-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.212.53]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2024 05:35:39 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id D536E10498C; Mon, 8 Jan 2024 16:35:36 +0300 (+03) Date: Mon, 8 Jan 2024 16:35:36 +0300 From: "kirill.shutemov@linux.intel.com" To: "Huang, Kai" Cc: "kexec@lists.infradead.org" , "linux-coco@lists.linux.dev" , "ashish.kalra@amd.com" , "dave.hansen@linux.intel.com" , "thomas.lendacky@amd.com" , "Hunter, Adrian" , "Reshetova, Elena" , "linux-kernel@vger.kernel.org" , "mingo@redhat.com" , "seanjc@google.com" , "tglx@linutronix.de" , "bhe@redhat.com" , "Nakajima, Jun" , "peterz@infradead.org" , "Edgecombe, Rick P" , "bp@alien8.de" , "rafael@kernel.org" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "x86@kernel.org" Subject: Re: [PATCHv5 15/16] x86/mm: Introduce kernel_ident_mapping_free() Message-ID: <20240108133536.7mi6oc2sfkumjqpv@box.shutemov.name> References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> <20231222235209.32143-16-kirill.shutemov@linux.intel.com> <3bddc0a0d69b6b18ce3fd568e6a7e6d7be8a1a11.camel@intel.com> <20240108101715.7hxn3wj6njemsf2x@box.shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jan 08, 2024 at 01:13:18PM +0000, Huang, Kai wrote: > On Mon, 2024-01-08 at 13:17 +0300, kirill.shutemov@linux.intel.com wrote: > > On Mon, Jan 08, 2024 at 03:30:21AM +0000, Huang, Kai wrote: > > > On Mon, 2024-01-08 at 03:13 +0000, Huang, Kai wrote: > > > > On Sat, 2023-12-23 at 02:52 +0300, Kirill A. Shutemov wrote: > > > > > 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() > > > > > callback hooked up and the pgd_t to free. > > > > > > > > > > Signed-off-by: Kirill A. Shutemov > > > > > --- > > > > > 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 cc9ccf61b6bd..14d72727d7ee 100644 > > > > > --- a/arch/x86/include/asm/init.h > > > > > +++ b/arch/x86/include/asm/init.h > > > > > @@ -6,6 +6,7 @@ > > > > > > > > > > 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_page, > > > > > unsigned long pstart, unsigned long pend); > > > > > > > > > > +void kernel_ident_mapping_free(struct x86_mapping_info *info, pgd_t *pgd); > > > > > > > > Maybe range-based free function can provide more flexibility (e.g., you can > > > > directly call the free function to cleanup in kernel_ident_mapping_init() > > > > internally when something goes wrong), but I guess this is sufficient for > > > > current use case (and perhaps the majority use cases). > > > > > > > > Reviewed-by: Kai Huang > > > > > > > > > > Another argument of range-based free function is, theoretically you can build > > > the identical mapping table using different x86_mapping_info on different > > > ranges, thus it makes less sense to use one 'struct x86_mapping_info *info' to > > > free the entire page table, albeit in this implementation only the > > > 'free_pgt_page()' callback is used. > > > > The interface can be changed if there will be need for such behaviour. > > This kind of future-proofing rarely helpful. > > > > Do you want to just pass the 'free_pgt_page' function pointer to > kernel_ident_mapping_free(), instead of 'struct x86_mapping_info *info'? As > mentioned above conceptually the page table can be built from multiple > x86_mapping_info for multiple ranges. I don't think we have such cases in kernel. Let's not overcomplicate things. I see value in keeping interface symmetric. We can always change things according to needs. -- Kiryl Shutsemau / Kirill A. Shutemov