From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52D5537B40C for ; Tue, 21 Jul 2026 17:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784653821; cv=none; b=Tuh3chsGmHiQlOrBXa/GxmgpZMIiTeohiYGYHUZ99Q0U/cZ+OemvCvwY3fflfddgknMmm47ml8xy9LH2awXIgP8Z9wen7l2FFFyqlweNTASpQmtx9RPcoTmhVAtT+vvHHs/+P02Neql4pjVPj43ORtUei2lTaTkeA67UOa0YBQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784653821; c=relaxed/simple; bh=2JTgTd9toINIPryUJzZ4cjvrunjhL4Ann5jB8FnbsS0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jsEUkyfgFxm3+ZXpYBBVVcb/poqB18HGJdsq/ziDCu0wJJkHZkoKjlIyCFK9DL3oQDX1UcReO+38byPCp2NUhHkzoRBRMHXoOgEApEzzTYxU19M34oKdP1FL7ERqKFK0oELgPvyeP0tetUM/2MDxyUc6yDAOYMt9zc4P99/Qnf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JfYrTuwc; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JfYrTuwc" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2cc7e86e7aeso89837745ad.2 for ; Tue, 21 Jul 2026 10:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784653820; x=1785258620; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Fkn3JmTHyZHrmeo+sPGbWVcJWg9Sa/ZKVruguzBjPig=; b=JfYrTuwciC0eNKbWbFj6cx/b3lnp4/Yz9+ZCra/h+71kTF6R7OpQgCmzY7RZBckyqM lCCrKJRRiCGcPxsYQQnYmcDUM/fqzjYZOEjFk3kW2TL5W8HUIDrw2wiMtK3Y2fc5qcT7 UuvLgNvMyDwNgSVceDfKRYeGu9YINnoB2V1Nos+hlu75UewBPjw9FrKrrp4Xj+Bf1ZMg e8hFnRxGn7XtD+F5hTfFkPZQX2m/g2nmXQlG7cimvMcRGFy/BmBLTby4GrZa9GxXkfsr tSPuhWoUxkUCNzW/qjPlUyN8xkCyNMyhfxkTrKjrqyYAVl0bAIDRZBImPm6OHluVjfg6 vjag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784653820; x=1785258620; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Fkn3JmTHyZHrmeo+sPGbWVcJWg9Sa/ZKVruguzBjPig=; b=SZFqCkF4WF9WkPZ1xlnY69f3oDv5t6cQOfY8ahC03H2Kuhzs6fOMlAeLK4seWOdBWy CRLFcLjafDt6ehc4HKE8mQVXne13vATBHhcRqeZQPZFSpO3OO98zTcPh5Ys9FkKI490m WUXa4d4KgUiWYCowyaGqeKiGSE41os2C4fF9n+Gr94VLX8W0ZbGHogqDEgZ+jIQVsYEr GdPwcMk40emZmUKtbbaVXbLz8on3X5llIz2urDmAfHUsu9G69uqA4EQFLtsezcsU0zCC S3pTYI1tiLmdqfFE9jV1d1as/GKC8lGFRa+qV6dy9MHEM06LHEB5G4c3UCFDRv+78w9y iFiw== X-Forwarded-Encrypted: i=1; AHgh+RoNNIHHotP3j2H2qjWFQ2bWeykmNRWC54EpMV9Lh04CLgG4IBJnshoI5iXGM1em7/Odw4ZMG5mwP/t8mLg=@vger.kernel.org X-Gm-Message-State: AOJu0YzyI8ciMGxAD88LkWjBx7RQJf9+R75PGDqMUOwpnO327ISw8Yn6 XVAB83+e0+ckt1h3g+Rk8vEuXZ+ah+maYXCD0m8Nt+XqrIAbs6tU3inw X-Gm-Gg: AR+sD11vRIRHHm6/uw4SwQ8vy+sl3tD7XvxOlxysEQUVRMhKP158w9DtAKIi/bSG2ln d7taXbIjB7zageNfACcBdxkG9Q6lNiHqE7OM8rMxKH/khZvsPUrZHGQJa7t/ZjESN1PMWc/AD4+ 2TyjKZxucdgd1rcvryI7nPkxI8pXrvBrofJO3FAjte8dfWo3qYO65bu36Czvx/RRnbDh+YcusEQ BZo0hMdwNYoGCXn+j8a2PHrXrPZ7coOdb966S1xbhMXsz11mryoin7a3r4Xt9sOwgSJoItj/fhZ sK/rYw7hBeDQQHX9OslYWGidw3eGgZVKfuGnVNwRebDAn+AiKzIvWcF6fmS9UtCDbo7PJK2e8gc Ru6e7Y1RbMDexMBeG6QKbpXtNEl8wXjKrGbV0S3pTj0PXUDWerbXZyLpNHsZrAHrDu9F4XEbXrX Nq2sraEKXSFlr4cHX9nJNeuXDyp/zdx0Bfhg== X-Received: by 2002:a17:902:e541:b0:2ca:b4b9:4586 with SMTP id d9443c01a7336-2cf348b0a43mr211904095ad.19.1784653819673; Tue, 21 Jul 2026 10:10:19 -0700 (PDT) Received: from fedora ([2601:644:937c:6c90:6d4e:7b2d:4a39:fb0c]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm585939eec.26.2026.07.21.10.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 10:10:18 -0700 (PDT) Date: Tue, 21 Jul 2026 10:10:16 -0700 From: Vishal Moola To: "Lorenzo Stoakes (ARM)" Cc: stable@vger.kernel.org, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Mike Rapoport (Microsoft)" , Jason Gunthorpe , Lu Baolu , Andrew Morton , David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Kiryl Shutsemau , iommu@lists.linux.dev, Kevin Tian Subject: Re: [PATCH v2] x86/mm/pat: allocate split page tables as kernel page tables Message-ID: References: <20260721-fix-cpa-kernel-pagetables-v2-1-2b255deed710@kernel.org> 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: <20260721-fix-cpa-kernel-pagetables-v2-1-2b255deed710@kernel.org> On Tue, Jul 21, 2026 at 01:14:52PM +0100, Lorenzo Stoakes (ARM) wrote: > When splitting a large page in CPA in __split_large_page() we allocate a > PTE directly without going through the standard page table allocation > routines such as pte_alloc_one_kernel(). > > This means the page table constructor is never called nor is the page table > marked as a kernel page table. > > The former results in the folio associated with the page table not being > marked as a page table (__pagetable_ctor() is never called thus neither is > __folio_set_pgtable()) nor are statistics updated to reflect > it (lruvec_stat_add_folio() is never called). > > The latter issue of failing to mark the page table as a kernel page > table (ptdesc_set_kernel() is never called) is far more problematic. > > Since commit 5ba2f0a15564 ("mm: introduce deferred freeing for kernel page > tables") kernel page table freeing has been batched and since the > subsequent commit e37d5a2d60a3 ("iommu/sva: invalidate stale IOTLB entries > for kernel address space") IOTLB cache entries for kernel page tables have > been invalidated upon being freed. > > Since split page tables are freed without this invalidation, the IOTLB can > contain stale entries for them. > > Resolve the issue by using the ordinary PTE allocation API at split time. > > This results in these kernel page tables invoking a page table constructor, > and thus requires a page table destructor. > > Since we cannot assume one is always present (early allocated direct map > page tables are not marked as such), we conditionally call > pagetable_dtor_free() if the PG_table folio flag for the ptdesc is set, > otherwise we free the page table via pagetable_free(). > > Regardless of which path is taken page tables marked as kernel page tables, > which now includes split page tables, take the correct route through > pagetable_free_kernel(). > > There is a user-visible side effect in that split page tables will appear > in nr_page_table_pages in /proc/vmstat (as do other kernel page tables > allocated after early boot), however this is a positive change. > > This issue started being markedly problematic after commit > 5ba2f0a15564 ("mm: introduce deferred freeing for kernel page tables") so > choose this as the Fixes target. > > Fixes: 5ba2f0a15564 ("mm: introduce deferred freeing for kernel page tables") > Cc: stable@vger.kernel.org > Signed-off-by: Lorenzo Stoakes (ARM) Acked-by: Vishal Moola