From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 A11343806C1 for ; Wed, 29 Apr 2026 15:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777476629; cv=none; b=ZnvhmbX/IrcsWF0ZL3OtjvMgRMXg8SlK1OKrno8S3xiUMWqZM+uRVJzGzwVl9z0oOAHMDb1Y2EJRPE8Ig7Y+DZKym6cHMMO3dQmDhU3H5XANC5mb/TldVMMm2wocWLkQYgFTbnLCYSUEmPa9PV9OwVbPNG8E7n9wP5cgrGTLlqQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777476629; c=relaxed/simple; bh=wr2Cjzi48zX0nGmklAOr0JeVqZqqLYl0lRJmnThQBwc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Bra2lu+ljWa0kh9rrbW0TumUH4xEVcLJNbvC8URJOEa0V2zufDk1rCp1rSdXhnFI2V/TWSl4M5dHdNRHaY3CeFtn+VS3AwKkNmHeKvWyhOTshMvgx5DSdDfLqOhEKN+j7N7uZEmUHLSCqfMbXfu2sKNNz13EPw6PhzPtfs4+aRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N2xbpZiW; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="N2xbpZiW" Message-ID: <2aa36364-6c60-4927-9344-6c4e0a072aac@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777476625; h=from:from: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=pRKjPGTHB7gLsglvS58rZ1PmYiUs4SxFlaTZpxLq+pI=; b=N2xbpZiWavmWTwLOQZ9SLU3kOEvqkgRkMHKC2SfGAAdy2KqvPcXuf7tfqARmWRGt7BgSDf h03I8++9UxXR5pvDvj1K1I7HyZd7fLtpLApqxFr7VluomyCioKyr7kzB71uz/uydKe/v51 +0jD4ZvgPMiL0Gq0oVrNCjzSzsGQetE= Date: Wed, 29 Apr 2026 23:29:51 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2] x86/mm: fix freeing of PMD-sized vmemmap pages Content-Language: en-US To: "David Hildenbrand (Arm)" Cc: "Mike Rapoport (Microsoft)" , Dave Hansen , Borislav Petkov , Jason Gunthorpe , Andy Lutomirski , linux-kernel@vger.kernel.org, "H. Peter Anvin" , Andrew Morton , Peter Zijlstra , Lu Baolu , linux-mm@kvack.org, stable@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Ingo Molnar References: <20260429-vmemmap-v2-1-8dfcacffd877@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260429-vmemmap-v2-1-8dfcacffd877@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/4/29 18:49, David Hildenbrand (Arm) wrote: > In commit bf9e4e30f353 ("x86/mm: use pagetable_free()"), we switched > from freeing non-boot page tables through __free_pages() to > pagetable_free(). > > However, the function is also called to free vmemmap pages. > > Given that vmemmap pages are not page tables, already the page_ptdesc(page) > is wrong. But worse, pagetable_free() calls > > __free_pages(page, compound_order(page)); > > As vmemmap pages are not compound pages (see vmemmap_alloc_block()) -- > except for HVO, which doesn't apply here -- we will only free the first > page when freeing a PMD-sized vmemmap page, leaking the other ones. > > Fix it by properly decoupling pagetable and vmemmap freeing. > free_pagetable() no longer has to mess with SECTION_INFO, as only the > vmemmap is marked like that in register_page_bootmem_memmap(). > > The indentation in remove_pmd_table() is messed up, let's fix that > while touching it. > > Note that we'll try to get rid of that bootmem info handling soon. For > now, we'll handle it similar to free_pagetable(), just avoiding the > ifdef. > > Tested-by: Lance Yang > Acked-by: Mike Rapoport (Microsoft) > Fixes: bf9e4e30f353 ("x86/mm: use pagetable_free()") > Cc: stable@vger.kernel.org > Signed-off-by: David Hildenbrand (Arm) > --- > Reproduced and tested with a simple VM with a virtio-mem device, > repeatedly adding and removing memory. > > Found by code inspection while working on bootmem_info removal. > --- Retested. Works as expected :) Cheers, Lance