Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1539352rdb; Mon, 8 Jan 2024 02:26:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7g8Y9VEnfTsZR/lPyutiJATi12Pba/NKw9Obmys9iZG1Od6EAlP1KNs2kcwWfpdI+O/45 X-Received: by 2002:a50:d644:0:b0:555:f8d6:3958 with SMTP id c4-20020a50d644000000b00555f8d63958mr1738993edj.55.1704709577902; Mon, 08 Jan 2024 02:26:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704709577; cv=none; d=google.com; s=arc-20160816; b=wjgnh4+6q02CJGkfxNI9MI55FKvrcnRnwfVs5KzuwGDnp+LRCic+mv6oX5UJWFQ0Ck bbbKfLUTs4ZzUM3y4i2xLSOm8FbGXXlMFACx8eA5kCOWW2SYcOJeih3mROs8YlxSJIVw evIm/m3Js6FP6OSpHNYtULLN4Pq9G35DoYDg9nklJKvCCVXbxmIJmrFLL/23drycSI4+ DCtwOgWLJE2+92oSLiushCSB5lPAK9o1C9av+V1DtobThfssF/JHaxNX7bHVUbtG9/wS oJdgWwQtLE9TQDPCz4xGeaDNLIrUee7YdaIhv6nkam5CopCVwl6pXQCDSxE3+C8ToaqG ZCMQ== 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=QgxjRqrkEbAppz7CR5Y8VjoMPUKUMQBzLjkIZ+7TEFo=; fh=MndvN+F5ZAlGrXiU0vY0XOrIaBE8yDFJ5GM27y7TH7g=; b=d+UffR/eygkOE2yfgH3KM2DALuDT8zp0T4Sy/xnZOoy0GKIz7ZXMphZKG4eRXKOmjK OjGnjVHoVCuSeAffO+37xIDym8MzoyvZFVDmi7xCxND5MECqRsSHdLLIPkrk7j0bXPBR ecNsHMBqDsCV6SX+PGdnOzf1Oxnv6w9RjIaO15z3aRIWizUIx16xzHjX51vQbG4fvwom l7ngBJobuH6QRHSSJK+kInZI9ut7MlFGreCxvlFpEZ3OdH08RFF/z2dJkwTmLnGNLnwM vdASEimPJwObftR8j48dETGPWof+P5IxXpHMjrDzIrksNLUzGBY6+3LAIAJVeD9q4pOH BdoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q2E69y5g; spf=pass (google.com: domain of linux-kernel+bounces-19328-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l15-20020a056402230f00b00555e51fd902si3184325eda.195.2024.01.08.02.26.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 02:26:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19328-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q2E69y5g; spf=pass (google.com: domain of linux-kernel+bounces-19328-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19328-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2A9211F22B4B for ; Mon, 8 Jan 2024 10:17:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CBE013AEE; Mon, 8 Jan 2024 10:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Q2E69y5g" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) (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 EF89713ADC for ; Mon, 8 Jan 2024 10:17:22 +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=1704709042; x=1736245042; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=XMOz/zIu+0whcXBIOPFjSv94Cgq9Vj6+RGisnpMjR4s=; b=Q2E69y5gxk+x8HO0BjJSkdG/tWp0LMIUuoK+dsWt5T1uxlYN3bY19yuO +YwX0kEXlop4S4IsALmJC2XXZhdkqCH/FH/Lz2JmtGrdqbhvVcVzU+ruN JOsJpnnqeuEDnSTqCxSVNht7pd0BGKmF2O1Zr42O4/8ry6Ye4C7b6wFu/ kajM21WVLGbKo23CZ42zvQySE8ZLTBSamR4EvoaYfh70Rni4GYrG0qKHE UYmgJR9zsfWvQTDvuc1H4yvCL+7egeLeU0ezvGVb3sDE8+p92EtxlFWEZ J27JKx/7PjrWtE3AfM8nKMgQp5ziHvQFJl1nwuJz3Mz9rg8BDz4YoH2Cy Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10946"; a="377983815" X-IronPort-AV: E=Sophos;i="6.04,340,1695711600"; d="scan'208";a="377983815" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2024 02:17:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10946"; a="900331920" X-IronPort-AV: E=Sophos;i="6.04,340,1695711600"; d="scan'208";a="900331920" Received: from ddraghic-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.212.53]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2024 02:17:17 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 66EB4109E5C; Mon, 8 Jan 2024 13:17:15 +0300 (+03) Date: Mon, 8 Jan 2024 13:17:15 +0300 From: "kirill.shutemov@linux.intel.com" To: "Huang, Kai" Cc: "tglx@linutronix.de" , "mingo@redhat.com" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "bp@alien8.de" , "kexec@lists.infradead.org" , "Edgecombe, Rick P" , "Reshetova, Elena" , "rafael@kernel.org" , "Nakajima, Jun" , "peterz@infradead.org" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Hunter, Adrian" , "thomas.lendacky@amd.com" , "linux-kernel@vger.kernel.org" , "ashish.kalra@amd.com" , "seanjc@google.com" , "bhe@redhat.com" , "linux-coco@lists.linux.dev" Subject: Re: [PATCHv5 15/16] x86/mm: Introduce kernel_ident_mapping_free() Message-ID: <20240108101715.7hxn3wj6njemsf2x@box.shutemov.name> References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> <20231222235209.32143-16-kirill.shutemov@linux.intel.com> <3bddc0a0d69b6b18ce3fd568e6a7e6d7be8a1a11.camel@intel.com> 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: <3bddc0a0d69b6b18ce3fd568e6a7e6d7be8a1a11.camel@intel.com> 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. -- Kiryl Shutsemau / Kirill A. Shutemov