From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 8A699191F9B for ; Wed, 3 Jul 2024 21:29:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042169; cv=none; b=hvnewl64KrhumDmLBLKzWAd1vyF3+qhF+gc/NdGaS8CsWSTwoMJYEmoT0ifMaTZXKEki+cT6TwEk2doe3E3v4Fvc5LH1YQr4MMGaajDGv3ZVYzdfZd09xg25ky2QD+5fMBdMAOqqnqiedCz7fO4bR166/bDFQ3QyeVToBKRNxFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042169; c=relaxed/simple; bh=B0IpMvJzke/973HZPlLZKBuCQcswwxmVEGuJbnrmXVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dn2s9bLP7/oA3lN7rUr7xrJuGrYDy5/Ie9OI1Q7wKhu/+hX63ROiXoOIoUdcmlDq8LUdgvo67Bv1CSTaWCeelhcxf4XX7/ZrxrE5Qo2vZS/hI+nJhvE9yfkjPeUzv0o8dM+wQ1QvlxQnUlcnjGq8Zdnx+bf7jK5vBFO3PtaQ5Xw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=D1/HG1qd; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D1/HG1qd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xrFUBbcc9D0ORnx0qoNz81Y3Ewmb+xGo+hBykZs/BiM=; b=D1/HG1qdiZtGn30l8WJ65cSSZwTBAJrTPkbj1sJL5yGtz9sR02Zb0K8CrcQqys4P0mDx8N sPJKOZy2qMGewGkIPKxklLizLsu/0m6bRj2y5zr3fo4+DKQIySE75bG6U2PyAu90nyshUB Sz8svhkAapMItK7ciP1MGixxFaUNgb8= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-27-vE8YFquDPL6UlTiv0VUJ-w-1; Wed, 03 Jul 2024 17:29:25 -0400 X-MC-Unique: vE8YFquDPL6UlTiv0VUJ-w-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-44671e02749so3589341cf.1 for ; Wed, 03 Jul 2024 14:29:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042164; x=1720646964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xrFUBbcc9D0ORnx0qoNz81Y3Ewmb+xGo+hBykZs/BiM=; b=tEcv4k+6x3NbBAATHaNMKWZwepsKNlNqTe21uifS2Y+kzZZbAuTIAR/JD/CVZBW2KD LqiSsp1wcDuuHB1UuzLxulLiEZC9lpgt5jJYgEao2+OueWROcBsoKFRDwtodZeuW5SLs UxnZmzU4CnGMQBikh9OpU0WO2QriyAoX6b2rSOPQchPPAzuaIMyKdxVB+mRiTgfoJ2Wo kL+G4iNk2jQJh4IWlkiEuR6ecBEGTf7Q0J6dXS5CBwlhVfM+DsrjxA02Lc+SfPY8EEWM 4KI1XDrXOanJtHqsQMG/QHTYkZ3BwrZ6jU3TF4d1GL6SRSkOxHQeCAn/edFyXow8/HH/ ILIg== X-Gm-Message-State: AOJu0Yw+0ht1SYr1Z8nKE1dxSIX1LZVCQ4VbAJWjOpQaoPXw8AK5WcfG pxXLDom6jMfmfmiKfVlMpVvomawJj3BgMln0O2laUp0nP9pOEiPnh+F0gXg2Dnr03CHqCSbrOIk sagyl1nmzWft4tHhwRx72QRXq0OTaZIDDy2AIcbtg0+pEMkABpp/u9WMi4pXClPvLC2sp+Y0JlO wxc6hBVVgccwYRd8SX+9+bHI8kDB3ePVNBoxxY7j5VPw0= X-Received: by 2002:a05:622a:20f:b0:446:395a:37c9 with SMTP id d75a77b69052e-44662e3a591mr137075871cf.4.1720042163979; Wed, 03 Jul 2024 14:29:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMTQtKzW3HcLgwCHDxSHbcORdQ9cM6uS4LGBZ0J8HIBqay3DdOq6gf2nTNP/Qtw7gCSEI+OA== X-Received: by 2002:a05:622a:20f:b0:446:395a:37c9 with SMTP id d75a77b69052e-44662e3a591mr137075451cf.4.1720042163442; Wed, 03 Jul 2024 14:29:23 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:22 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe Subject: [PATCH v2 1/8] mm/dax: Dump start address in fault handler Date: Wed, 3 Jul 2024 17:29:11 -0400 Message-ID: <20240703212918.2417843-2-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the dax fault handler dumps the vma range when dynamic debugging enabled. That's mostly not useful. Dump the (aligned) address instead with the order info. Signed-off-by: Peter Xu --- drivers/dax/device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index eb61598247a9..714174844ca5 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -235,9 +235,9 @@ static vm_fault_t dev_dax_huge_fault(struct vm_fault *v= mf, unsigned int order) int id; struct dev_dax *dev_dax =3D filp->private_data; =20 - dev_dbg(&dev_dax->dev, "%s: %s (%#lx - %#lx) order:%d\n", current->comm, - (vmf->flags & FAULT_FLAG_WRITE) ? "write" : "read", - vmf->vma->vm_start, vmf->vma->vm_end, order); + dev_dbg(&dev_dax->dev, "%s: op=3D%s addr=3D%#lx order=3D%d\n", current->c= omm, + (vmf->flags & FAULT_FLAG_WRITE) ? "write" : "read", + vmf->address & ~((1UL << (order + PAGE_SHIFT)) - 1), order); =20 id =3D dax_read_lock(); if (order =3D=3D 0) --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 BC2DC1940AA for ; Wed, 3 Jul 2024 21:29:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042174; cv=none; b=D7h4rNKBu8wy39a1ijrMIRVgkarvIWLLeQoWUdNuwAVG5wZYvR+cdCznV0qR1z0Iuc1y+9F0fAsy2ZLXbi0/6pqMnEMytdqfjFo4FaNzRV1OvxlT6mKXaVPhG+zeI73nRl9sC7ioN4Ur4ystVwWDANUB1HzdragmSfd3fHy46lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042174; c=relaxed/simple; bh=j4dGntuy5ovfbg5GfpZwgNQjpitGGaZVaqagsHPmSn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N1IlPXHgSrvfHgxeBW5j8Jr9WmL5NxbRAbWG8tz4YPzJ1LhHalciobIaFf5xb5hmA73R6Qe7MTl+I6mnkwWJll4txBx3RDafE+/n9h4m8o1UIyQe6LxwzBa9BG8XX+hT9Y8maHy569f1vOjTUMHOgLAx2pY+S4vZBj/m903qb6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d3bnLMXr; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d3bnLMXr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uDSHiwJLCIYvvzv2DOw1kewa0irBZ6HqHLZp2ORNUK8=; b=d3bnLMXrArWOKD3XyZWq3GMJOO6KZHS2VFgSwdkk2A+2VbovLz2hSVeYyyO5sldvdNJXCa 800Ad8XAuIemhkWqWN84Z52Psqvbyx+EyAaJIwTsTa9UC6b7nvBktFNR1QMfVtyw6kk8EU lvdD7YiPG2pN6xF9EqzPjXHsKdHhLzU= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-wJj-lrkePUyArtq4QckGgw-1; Wed, 03 Jul 2024 17:29:27 -0400 X-MC-Unique: wJj-lrkePUyArtq4QckGgw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4464454e329so1957801cf.1 for ; Wed, 03 Jul 2024 14:29:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042166; x=1720646966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uDSHiwJLCIYvvzv2DOw1kewa0irBZ6HqHLZp2ORNUK8=; b=TlI1plDxnDkp7FA63C204MtrSybwAb6GFGllqOuwHs6TXTUbyBn6XMOuBXXuUVOkCC 26Der5OUmlMV/LWQ5GbAU3vZ1UR5K+DmzTaSvfSM3ThFCn1/TMnIpIc1k4oyoP5QwB9h 6IDNLzWXtl+4WaLoV5cE7N0gHFgVhzaJM5oCmOiYSn+gjoZUJX1TJ4SyL5jKuB9sn3FX kzoyUpCl8udlf6+08ssFruF9oQFj4Ix/1mj0M0BvgYDeqqpBr5yBP1oxOU5gwT8SwEmk Vq5mT9p2QrVWdk0W+9vVh78P/jC1yX1wgiSXlV+To3ndTZYeoskTOaavH3zH7NaCHmX9 gShg== X-Gm-Message-State: AOJu0Yw0J8r1HeB2v51EJKW8O+TbO4/acEOIvD8seyArhuV9ieTT0HL8 Xxru/3KNScA2EcrDDCotqQuBiJL+/kG8/eTH11bBoAN8xZCDoBUF0bTUP41uLpd/Hbr4A4Tj8YN 8QZDmnq+J2HS6saYYvwAQM2mTQvQdzN77dC7QkPXP8lXPpa1lxwLU0+pkHBCDXHjURZg4jb+lbw c7GteHOG4cKUEQ7hA+bospeygN9dd2d2ES2NrjyCUDO2g= X-Received: by 2002:a05:622a:1a29:b0:446:5c96:3e39 with SMTP id d75a77b69052e-44662c7b9b6mr149928501cf.2.1720042165954; Wed, 03 Jul 2024 14:29:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMMhz5U/uaY0swHE/aSBQQusLb0Xfs1HUkfM825Vkmolo2nubsLeOfdQnkewhNugg6U8gw9g== X-Received: by 2002:a05:622a:1a29:b0:446:5c96:3e39 with SMTP id d75a77b69052e-44662c7b9b6mr149928031cf.2.1720042165404; Wed, 03 Jul 2024 14:29:25 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe , Alex Thorlton Subject: [PATCH v2 2/8] mm/mprotect: Remove NUMA_HUGE_PTE_UPDATES Date: Wed, 3 Jul 2024 17:29:12 -0400 Message-ID: <20240703212918.2417843-3-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In 2013, commit 72403b4a0fbd ("mm: numa: return the number of base pages altered by protection changes") introduced "numa_huge_pte_updates" vmstat entry, trying to capture how many huge ptes (in reality, PMD thps at that time) are marked by NUMA balancing. This patch proposes to remove it for some reasons. Firstly, the name is misleading. We can have more than one way to have a "huge pte" at least nowadays, and that's also the major goal of this patch, where it paves way for PUD handling in change protection code paths. PUDs are coming not only for dax (which has already came and yet broken..), but also for pfnmaps and hugetlb pages. The name will simply stop making sense when PUD will start to be involved in mprotect() world. It'll also make it not reasonable either if we boost the counter for both pmd/puds. In short, current accounting won't be right when PUD comes, so the scheme was only suitable at that point in time where PUD wasn't even possible. Secondly, the accounting was simply not right from the start as long as it was also affected by other call sites besides NUMA. mprotect() is one, while userfaultfd-wp also leverages change protection path to modify pgtables. If it wants to do right it needs to check the caller but it never did; at least mprotect() should be there even in 2013. It gives me the impression that nobody is seriously using this field, and it's also impossible to be serious. We may want to do it right if any NUMA developers would like it to exist, but we should do that with all above resolved, on both considering PUDs, but also on correct accountings. That should be able to be done on top when there's a real need of such. Cc: Huang Ying Cc: Mel Gorman Cc: Alex Thorlton Cc: Rik van Riel Signed-off-by: Peter Xu --- include/linux/vm_event_item.h | 1 - mm/mprotect.c | 8 +------- mm/vmstat.c | 1 - 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 747943bc8cc2..2a3797fb6742 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -59,7 +59,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, OOM_KILL, #ifdef CONFIG_NUMA_BALANCING NUMA_PTE_UPDATES, - NUMA_HUGE_PTE_UPDATES, NUMA_HINT_FAULTS, NUMA_HINT_FAULTS_LOCAL, NUMA_PAGE_MIGRATE, diff --git a/mm/mprotect.c b/mm/mprotect.c index 222ab434da54..21172272695e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -363,7 +363,6 @@ static inline long change_pmd_range(struct mmu_gather *= tlb, pmd_t *pmd; unsigned long next; long pages =3D 0; - unsigned long nr_huge_updates =3D 0; struct mmu_notifier_range range; =20 range.start =3D 0; @@ -411,11 +410,8 @@ static inline long change_pmd_range(struct mmu_gather = *tlb, ret =3D change_huge_pmd(tlb, vma, pmd, addr, newprot, cp_flags); if (ret) { - if (ret =3D=3D HPAGE_PMD_NR) { + if (ret =3D=3D HPAGE_PMD_NR) pages +=3D HPAGE_PMD_NR; - nr_huge_updates++; - } - /* huge pmd was handled */ goto next; } @@ -435,8 +431,6 @@ static inline long change_pmd_range(struct mmu_gather *= tlb, if (range.start) mmu_notifier_invalidate_range_end(&range); =20 - if (nr_huge_updates) - count_vm_numa_events(NUMA_HUGE_PTE_UPDATES, nr_huge_updates); return pages; } =20 diff --git a/mm/vmstat.c b/mm/vmstat.c index 73d791d1caad..53656227f70d 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1313,7 +1313,6 @@ const char * const vmstat_text[] =3D { =20 #ifdef CONFIG_NUMA_BALANCING "numa_pte_updates", - "numa_huge_pte_updates", "numa_hint_faults", "numa_hint_faults_local", "numa_pages_migrated", --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 7242B1946A1 for ; Wed, 3 Jul 2024 21:29:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042177; cv=none; b=HKJXwwllr2Wv5ESmZKqGGtFMmh13w7W6sJ84DMPawg7hMu7NY6J2IX63BQYhf85Hdp8Xt4qSDMVI3p/ZOwBodoKFIi/OAFf9pcApXJoMB7AHKY6wA9Ue1W+gpe1VAlWwaoYhZ4vNh4hG6D4Dffe2Bs274XlWu0d2TSJoWUnj0Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042177; c=relaxed/simple; bh=ARxQXTuoo2oZGe8F14hSzMvMkV1cj+qV2fEARS445Kw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fuI8BLC4pcgZQFgzDYkiuCeZGEkf6HEqKdiXFGXSvbV0WrKwXLeUKzWJ0qq3wy2cbpw49aK3UZWSv4b2QiBkR/5kHK/sz2HFs001vTCsZUEsDZ1mTKpwHfp1u6Mv50Df0Enm2iGMIPS0bI6e2GsCXizgiQaFaWxsNlIPn5qXG2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YepT6NxJ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YepT6NxJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VpPwnVRxGccST937wjacfAT3ndiJzOREHKlh4Jm8zSE=; b=YepT6NxJTki+q3mD+1kKXI9ObMM25gFaJ4Wj82lzd1NmxjDMQLoFdeOC/Ctv6ayODyeG/m v1UBPkEryQ2LHsrtTrgp7p4cHDB2SeXDsI1KRuBhwvwH+3DG8Eh0QsGvCIUzHjH8AkPhzj 4IhGQOicjNfyTU9FHI6ZJd1bxe56cug= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-c5oAFW3NOuuZfj-mxmpiyg-1; Wed, 03 Jul 2024 17:29:29 -0400 X-MC-Unique: c5oAFW3NOuuZfj-mxmpiyg-1 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-5c479ad9c8cso171245eaf.2 for ; Wed, 03 Jul 2024 14:29:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042168; x=1720646968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VpPwnVRxGccST937wjacfAT3ndiJzOREHKlh4Jm8zSE=; b=JPxXzV2lHB8CzHRMkv8dF0CtJhsqNPw16eFNYsf8ZjRpys5bcYH9x0AOnKOnJLPTAs l+LNk7+JXEX1KQqv4sCUfCAXc3fsiZ6L0+cxr+aRkUORoJR31Fc2gOBNM7khRqRRXbaj R0urHjjqzhCo5HtrByYSb2UBhHywY+/1oKPsbtQyof1Yz1c8IxwS4haSBxX7Hit38V9L /M2HaLymFX4h10Fb7Tz22FLu9cdj/FKqc0sUrxx/liLjoWCBKewqqQ9Bcx81N7XtlNMq N5zJhDxJdgMGBXI2ZlWMjHOFYPVgOATkvS13wz6prG3trWhOo3oCduMDSw5fZu3JtZWZ O15w== X-Gm-Message-State: AOJu0YwL1IUP5mXcYQ+dcZ8w8aHh7O+mpez3tbdHeFthDGSg4nJaksLN ZuEbQWFhFk709eyygdQ326fDP0pxfFTbsKNXRI7DGXKaMan1MR2VRd34as9cBCCcV9Q0rk0/5lQ uKas/v6C7t+G7XEwAyDTMri0C8e0H+GHPpg/w3cJylD7uUOpKB7+2NwZExH+K2XbcXnNgUbujG2 8VmrYmHhe17wNuxqH+ENty/xmY2XJi8j+TgipWzfhl7ik= X-Received: by 2002:a05:6870:f112:b0:25e:15e1:35c6 with SMTP id 586e51a60fabf-25e15e13956mr2491360fac.0.1720042168276; Wed, 03 Jul 2024 14:29:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFy7qnRAv+DeYDujdDipaXvn8J32B6JV16U/qU1i2FGfDDVRUJs42vciaW1uTjUnBxFRGp+Ow== X-Received: by 2002:a05:6870:f112:b0:25e:15e1:35c6 with SMTP id 586e51a60fabf-25e15e13956mr2491322fac.0.1720042167878; Wed, 03 Jul 2024 14:29:27 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:27 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe , kvm@vger.kernel.org, Sean Christopherson , Paolo Bonzini , David Rientjes Subject: [PATCH v2 3/8] mm/mprotect: Push mmu notifier to PUDs Date: Wed, 3 Jul 2024 17:29:13 -0400 Message-ID: <20240703212918.2417843-4-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mprotect() does mmu notifiers in PMD levels. It's there since 2014 of commit a5338093bfb4 ("mm: move mmu notifier call from change_protection to change_pmd_range"). At that time, the issue was that NUMA balancing can be applied on a huge range of VM memory, even if nothing was populated. The notification can be avoided in this case if no valid pmd detected, which includes either THP or a PTE pgtable page. Now to pave way for PUD handling, this isn't enough. We need to generate mmu notifications even on PUD entries properly. mprotect() is currently broken on PUD (e.g., one can easily trigger kernel error with dax 1G mappings already), this is the start to fix it. To fix that, this patch proposes to push such notifications to the PUD layers. There is risk on regressing the problem Rik wanted to resolve before, but I think it shouldn't really happen, and I still chose this solution because of a few reasons: 1) Consider a large VM that should definitely contain more than GBs of memory, it's highly likely that PUDs are also none. In this case there will have no regression. 2) KVM has evolved a lot over the years to get rid of rmap walks, which might be the major cause of the previous soft-lockup. At least TDP MMU already got rid of rmap as long as not nested (which should be the major use case, IIUC), then the TDP MMU pgtable walker will simply see empty VM pgtable (e.g. EPT on x86), the invalidation of a full empty region in most cases could be pretty fast now, comparing to 2014. 3) KVM has explicit code paths now to even give way for mmu notifiers just like this one, e.g. in commit d02c357e5bfa ("KVM: x86/mmu: Retry fault before acquiring mmu_lock if mapping is changing"). It'll also avoid contentions that may also contribute to a soft-lockup. 4) Stick with PMD layer simply don't work when PUD is there... We need one way or another to fix PUD mappings on mprotect(). Pushing it to PUD should be the safest approach as of now, e.g. there's yet no sign of huge P4D coming on any known archs. Cc: kvm@vger.kernel.org Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Rientjes Cc: Rik van Riel Signed-off-by: Peter Xu --- mm/mprotect.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 21172272695e..fb8bf3ff7cd9 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -363,9 +363,6 @@ static inline long change_pmd_range(struct mmu_gather *= tlb, pmd_t *pmd; unsigned long next; long pages =3D 0; - struct mmu_notifier_range range; - - range.start =3D 0; =20 pmd =3D pmd_offset(pud, addr); do { @@ -383,14 +380,6 @@ static inline long change_pmd_range(struct mmu_gather = *tlb, if (pmd_none(*pmd)) goto next; =20 - /* invoke the mmu notifier if the pmd is populated */ - if (!range.start) { - mmu_notifier_range_init(&range, - MMU_NOTIFY_PROTECTION_VMA, 0, - vma->vm_mm, addr, end); - mmu_notifier_invalidate_range_start(&range); - } - _pmd =3D pmdp_get_lockless(pmd); if (is_swap_pmd(_pmd) || pmd_trans_huge(_pmd) || pmd_devmap(_pmd)) { if ((next - addr !=3D HPAGE_PMD_SIZE) || @@ -428,9 +417,6 @@ static inline long change_pmd_range(struct mmu_gather *= tlb, cond_resched(); } while (pmd++, addr =3D next, addr !=3D end); =20 - if (range.start) - mmu_notifier_invalidate_range_end(&range); - return pages; } =20 @@ -438,10 +424,13 @@ static inline long change_pud_range(struct mmu_gather= *tlb, struct vm_area_struct *vma, p4d_t *p4d, unsigned long addr, unsigned long end, pgprot_t newprot, unsigned long cp_flags) { + struct mmu_notifier_range range; pud_t *pud; unsigned long next; long pages =3D 0, ret; =20 + range.start =3D 0; + pud =3D pud_offset(p4d, addr); do { next =3D pud_addr_end(addr, end); @@ -450,10 +439,19 @@ static inline long change_pud_range(struct mmu_gather= *tlb, return ret; if (pud_none_or_clear_bad(pud)) continue; + if (!range.start) { + mmu_notifier_range_init(&range, + MMU_NOTIFY_PROTECTION_VMA, 0, + vma->vm_mm, addr, end); + mmu_notifier_invalidate_range_start(&range); + } pages +=3D change_pmd_range(tlb, vma, pud, addr, next, newprot, cp_flags); } while (pud++, addr =3D next, addr !=3D end); =20 + if (range.start) + mmu_notifier_invalidate_range_end(&range); + return pages; } =20 --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 42F091922E6 for ; Wed, 3 Jul 2024 21:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042178; cv=none; b=Oh8Me55is9MislrXR/M4iglViDoEvnzSJRYBIj028zdWAryIDxHsm3OgkAQhLIp+63LlR5T2lNRSAbJYwBz3kp7Q3APfO3TCQr5WXipKY2i+HKqYR7hFL34e9XKhUKiLHgfRA7gDDWfQbNo1A+WcLtltsNZbPaD2CgzZTZT+Nsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042178; c=relaxed/simple; bh=lGBhFBkbaz7EzTpAgSm8PUxosOm03SfTjgCaLHkY1V8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WX0F7+2r8f6xkQFTfX8gB4Ro4Zk82LldfOup/RQ8DNcrT0OcslxLCr/AMojcUkCh9xRQGvuoUibPot94MI20VwjXZIAyULWRrM7esF1w+s3fXM4AmUpsMy3HIwTTJlT+eRi/D/qHug3O26W5xZu8CzO179HebFCi5GCeSf8gX50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NQSOKAk1; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NQSOKAk1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DPSgdrK+/9txvlBVeWURx0wHDXuvLt3nB8aMlUhEkV8=; b=NQSOKAk1CmR/7N2YrjoLL0po3/9WSA9KzWqCTQBv/s3HEwxQCirc+CNjSB/T4mnOdAbvtg AsGGkN4GQUVkOFyVwB2zy0RF2Rmf0dm0t1MqIvrPtIaO9lzAz5VifRtklhBOMgaK83Y/NI kG2o6lkBP/Je4e9tiE6QNEq1M+kwnIw= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-t1sEetOWNwKdWF85KXkPkw-1; Wed, 03 Jul 2024 17:29:31 -0400 X-MC-Unique: t1sEetOWNwKdWF85KXkPkw-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4464454e329so1957971cf.1 for ; Wed, 03 Jul 2024 14:29:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042170; x=1720646970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DPSgdrK+/9txvlBVeWURx0wHDXuvLt3nB8aMlUhEkV8=; b=l3Qw5SzNNYEMtWcB4qJiSdCFIgx+g7XC9GNBkARIZrIawHQ4serTOmYURbSwzTMv54 unEMNx/pS6U8kzhYNAwNy1+L2ixPZ/Q8JdjrvWi8WJEuMUrySUyzohnLnByUo+3G6Nhi F7W81RdRzSJpvneeH0MW2Vfa4clJm8M/O2cmSHc8jnJyd5wZhzWPTBOHFgko3RgVpbn5 sx364hCD4IUiay4AFomjT6EM2IiTSxWc8I0ciAD8QVNsOcvMqHvaRRWgKPi4z43bTu8q 5Koy+wIB7C2Inr0sBaZm4PxOkt2N4CVZnFASvkjzUuZ9ij8EoRi+U5i51NS0o94g9+Hh ac+g== X-Gm-Message-State: AOJu0Yw2auDxLo6EvfESoxTl+KN69Vwmm/GWt6VTGgTcF8gvkRWSI0us LIxhFQFwMVgJYDFBMZqP2sTma/M/OOm1jx6aiw0GWsz77XdTfnqUUaHRdsfkyJfIwEwJtzu9CQV yESfWLd4KmBqDBo+veLbcUPD/YOB6AuW7PRNQzZxG4lDJZ9WXf+mur+5SB6Bx1djQVNiWDPgV4f xGb5GQT2gVM72XPbv+VtjTH2zZAibdR07PGjkTVAsgRlY= X-Received: by 2002:a05:622a:102:b0:446:5d1b:5a2e with SMTP id d75a77b69052e-44662f544a3mr145792611cf.5.1720042170365; Wed, 03 Jul 2024 14:29:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbwAQwNTOhld77jh3m6+0aceNgmx9fLMFpnLFNTJ0A2GCbsDu4E9EVwwSQY1Fjy1mOFnq/rQ== X-Received: by 2002:a05:622a:102:b0:446:5d1b:5a2e with SMTP id d75a77b69052e-44662f544a3mr145792111cf.5.1720042169860; Wed, 03 Jul 2024 14:29:29 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:29 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe Subject: [PATCH v2 4/8] mm/powerpc: Add missing pud helpers Date: Wed, 3 Jul 2024 17:29:14 -0400 Message-ID: <20240703212918.2417843-5-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These new helpers will be needed for pud entry updates soon. Introduce them by referencing the pmd ones. Namely: - pudp_invalidate() - pud_modify() Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org Cc: Aneesh Kumar K.V Signed-off-by: Peter Xu --- arch/powerpc/include/asm/book3s/64/pgtable.h | 3 +++ arch/powerpc/mm/book3s64/pgtable.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index 519b1743a0f4..5da92ba68a45 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -1124,6 +1124,7 @@ extern pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgpr= ot); extern pud_t pfn_pud(unsigned long pfn, pgprot_t pgprot); extern pmd_t mk_pmd(struct page *page, pgprot_t pgprot); extern pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot); +extern pud_t pud_modify(pud_t pud, pgprot_t newprot); extern void set_pmd_at(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd); extern void set_pud_at(struct mm_struct *mm, unsigned long addr, @@ -1384,6 +1385,8 @@ static inline pgtable_t pgtable_trans_huge_withdraw(s= truct mm_struct *mm, #define __HAVE_ARCH_PMDP_INVALIDATE extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long add= ress, pmd_t *pmdp); +extern pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long add= ress, + pud_t *pudp); =20 #define pmd_move_must_withdraw pmd_move_must_withdraw struct spinlock; diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/= pgtable.c index f4d8d3c40e5c..5a4a75369043 100644 --- a/arch/powerpc/mm/book3s64/pgtable.c +++ b/arch/powerpc/mm/book3s64/pgtable.c @@ -176,6 +176,17 @@ pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsi= gned long address, return __pmd(old_pmd); } =20 +pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address, + pud_t *pudp) +{ + unsigned long old_pud; + + VM_WARN_ON_ONCE(!pud_present(*pudp)); + old_pud =3D pud_hugepage_update(vma->vm_mm, address, pudp, _PAGE_PRESENT,= _PAGE_INVALID); + flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE); + return __pud(old_pud); +} + pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmdp, int full) { @@ -259,6 +270,15 @@ pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) pmdv &=3D _HPAGE_CHG_MASK; return pmd_set_protbits(__pmd(pmdv), newprot); } + +pud_t pud_modify(pud_t pud, pgprot_t newprot) +{ + unsigned long pudv; + + pudv =3D pud_val(pud); + pudv &=3D _HPAGE_CHG_MASK; + return pud_set_protbits(__pud(pudv), newprot); +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 /* For use by kexec, called with MMU off */ --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 88BA91946AD for ; Wed, 3 Jul 2024 21:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042177; cv=none; b=qTUKr7Noxra90pUqPDyuUCXdANELr6UlgXZ06J72D77CfDibES4PKALu72Xq/dI6ARqwLJKAjLQ0oD2cEqf+41YVOy4fRR7xyGkjWsoEgzOuaxOeOFbUXjy7OMAfKAaQaI/dkD8A2qBIz88PIK0cCfEixcnHTZES9bPYdJZ3tQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042177; c=relaxed/simple; bh=HvLeVYUQ3g1BzJ0yN4wtIuLe5eY6YeKrJD1Hba3arrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XB6idAYII3sgbyLvhWQZscycX0ekmzt7D7mj9UNqAdn1WNlSNR3M7KxNMo3BRLsq5KBLdf/M9EuLxu+G36QBsCtbE4nASr+ErGo5wXihhJdMDL+m5PMxb2/sBb3UCEg8qop1vmq5zPHA56Z6NwrnesOeNkWm4UNFlzXSd0RSRrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Jpe3rZ6s; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Jpe3rZ6s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TFEuzrgphkpyKgRaMn/StFmQ1IWZKcW4qj9eIjoToHw=; b=Jpe3rZ6s0I9P3NGIxEklmOwxwXwhB3m8LS1t8oOXyfS8iH1bjH/Zx/qbswNGICkawDpX7L +fIT1AQ3voRmNtGnhE3PDhOM0l3hNIYllYGm2Ni0nx7xtSHFMp4hvw2hGRr9irTdlaCJtT d0Z99hok70P72wOlC/n/DT0FK1C15dI= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-eaXcqT8gPA6MpjGjm-TfEw-1; Wed, 03 Jul 2024 17:29:33 -0400 X-MC-Unique: eaXcqT8gPA6MpjGjm-TfEw-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4466fe59a3dso2086351cf.3 for ; Wed, 03 Jul 2024 14:29:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042172; x=1720646972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TFEuzrgphkpyKgRaMn/StFmQ1IWZKcW4qj9eIjoToHw=; b=MIfHp0DAgJw7zsEj+izesc4pO+Lyj6XgSJ2aMzXTr+3JAWOtJh5QQkjrCYsG1iwgL3 JDnCS5Td523oI9e3CfCrCBj5QPQ8d8cJkKwQI/C1UZJkkmMYVI5iv0G39ZjbCxDEBs4p rHlB2Wj4visO4RGhXtp2NmmTXcbjjobxUsE4oFs6ZhGMiqmj0yWEISmpdA3Q8dve39dN ZPFUk7aD8H+o3k6ZOCcmNUlMSuNyAyfZdScrbUekt2XTLRbaZAxVWg5Ay9edKASmqrxe 4g15rxm8rcqnhTgeWqApS8BQOL+tVgUGMrlZaKXrw5NNhCiynl3e4hpTUcepbdTba15+ 4EtA== X-Gm-Message-State: AOJu0YyTVHds4jAn6vzEU3jcnX9E34yzYC9inK2uoxKnDW2mU1/CDvZa oxOnLm4+SfAZGfmtRMil9uwKUTjCa+Sb00GrxVVanEaNV9DkmI4pn3ieBa96nYDFFRFl6GWmnJn SSmSflRRVCGQh+NPpivfxUBvuiEkz1DhjUuYibpAIrWzkBlsVQIcyo+2Q3KUcVU++qrptc1pxHo yw/9kuneBub9o9Gc42ZmDrLQYslbsRccRnHK7uEdARue8= X-Received: by 2002:ac8:7c4f:0:b0:446:4428:2d8f with SMTP id d75a77b69052e-44662fe8d5dmr138289861cf.6.1720042171952; Wed, 03 Jul 2024 14:29:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMHO5UTPVYkVSEJYbLjxCcukt7PlLC0h81KBHiBOgwFBj/wiCFjtQJqk/7gb0k9Iu8HJBYNg== X-Received: by 2002:ac8:7c4f:0:b0:446:4428:2d8f with SMTP id d75a77b69052e-44662fe8d5dmr138289521cf.6.1720042171603; Wed, 03 Jul 2024 14:29:31 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:31 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe Subject: [PATCH v2 5/8] mm/x86: Make pud_leaf() only cares about PSE bit Date: Wed, 3 Jul 2024 17:29:15 -0400 Message-ID: <20240703212918.2417843-6-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An entry should be reported as PUD leaf even if it's PROT_NONE, in which case PRESENT bit isn't there. I hit bad pud without this when testing dax 1G on zapping a PROT_NONE PUD. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Acked-by: Dave Hansen Signed-off-by: Peter Xu --- arch/x86/include/asm/pgtable.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 65b8e5bb902c..25fc6d809572 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1073,8 +1073,7 @@ static inline pmd_t *pud_pgtable(pud_t pud) #define pud_leaf pud_leaf static inline bool pud_leaf(pud_t pud) { - return (pud_val(pud) & (_PAGE_PSE | _PAGE_PRESENT)) =3D=3D - (_PAGE_PSE | _PAGE_PRESENT); + return pud_val(pud) & _PAGE_PSE; } =20 static inline int pud_bad(pud_t pud) --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 DEEDF194C7B for ; Wed, 3 Jul 2024 21:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042184; cv=none; b=NoUCnAdeeT6Zwqa2cyoaMqW0c+wp6TTHrvRGH1/6QU30mRH3IuJZvFqxRtvw1Qcuel29ng8SiT+yRZJ40erL7EhtFlsy/qvOgCkJB1z7frFffF1fbIJh2N69y/NUGhmAy7obvOThledIi7bOMkeoHZgoaSGD3e5c/P7MihH4heY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042184; c=relaxed/simple; bh=ND9R4pqR5t4wh8zD63X9n4hfk1GcVTWL+KMdg1b86QQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u1NdwB9D6WC/gPM9x5pgRpG8oyfi87xTs6uJmcl9OmnrgbFE5FZTG3jk++JaoyJcfoFnPm4EkIOgGnK23C2NEF/DYSR3yxA5Ikj9BDzit4mt35Njsg172jieaSwBjl30GzFHk7ggQA4G/o5N8MQr2rGaqQ2/TaH3BFFz94bJkIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LjFLKX3w; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LjFLKX3w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8uNV81qP1pkF0zqyhqKWAPXX0CBAvqkfZkOGu2qHMfo=; b=LjFLKX3wvbl1wM2U+JA9BUHT6HUNCkfTfGIL1rFrAtzUy45s8GprvYTwJ9YhpmQbBz5Kix 0sURxyRcwTH0sT6AHgZYMUZT3VlyVSggkwgtf0zMTElWhzLIXSuZbzE5LzzscrwdXk+OjF ClibOaigW5aIpJXc34cQhpNibIoIsHg= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-341--ZfxC851MnCYQtfTH_Aq0w-1; Wed, 03 Jul 2024 17:29:34 -0400 X-MC-Unique: -ZfxC851MnCYQtfTH_Aq0w-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-446405b39baso4234671cf.0 for ; Wed, 03 Jul 2024 14:29:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042174; x=1720646974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8uNV81qP1pkF0zqyhqKWAPXX0CBAvqkfZkOGu2qHMfo=; b=YeXSPK07JukDW6ROacGUk5cD+vOdZiKFcHAnQETp9WYXwepmsY4bPPeJiCn9/mQQ3m +G7d3xzoWqZKXghv6x9ejgDwzPeZc2U+2KobAr5PhJBBUYhtmxNXw5J087zsgxvyF7+O sI7cnjcbPJCzVpUt7gcnTlCqtx8DuzQbdZI2xd4pexlaAnyly+raM93jIVdlDcmOb+6/ DUDfkvJZn466EsTUX/ToLhKnTvfw00I0nHfDAIf1sarv1k9GK4S/1t4UNK08Vo42KkSa /yHxdktB6VOMeH3qx+ZRQlxvWxjVkkVYnDF9vJnwP70o7Vum4SHUIB/D7vkHeAvOu5qN fohg== X-Gm-Message-State: AOJu0Yz43s52mBhacKFFlPB91pF0j74eZZ7O6pG+lDoIaRQtX7Yx92Tz Tn03CJpVYd6ARHI7W0BsHq+KtogUUrwdMG4LlqtYBh54DY5uc2U4qWKdTBi1PkNBzJRnSbcZZPe 8e6J0j3np3KoHxOV4j1ml1YDiHYuYuvyjckk7iZIweLCRmSx+1uVEn3TXogLXVdI0hBslz6lBWO qMABaDjrb7FbhoytaPF3C4NOh/c2EngtlTIV+g2Ux+M3s= X-Received: by 2002:a05:620a:470c:b0:79d:8ea3:9d24 with SMTP id af79cd13be357-79d8ea39f72mr1046537785a.2.1720042173875; Wed, 03 Jul 2024 14:29:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFduTwlKnISGNZIByqQ7Sp6Ih/1fAT1ztK1vNR6ntfPREjYbbEVcJ6gOgRtr7E4arLOH2JOwA== X-Received: by 2002:a05:620a:470c:b0:79d:8ea3:9d24 with SMTP id af79cd13be357-79d8ea39f72mr1046534585a.2.1720042173510; Wed, 03 Jul 2024 14:29:33 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:33 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe Subject: [PATCH v2 6/8] mm/x86: arch_check_zapped_pud() Date: Wed, 3 Jul 2024 17:29:16 -0400 Message-ID: <20240703212918.2417843-7-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce arch_check_zapped_pud() to sanity check shadow stack on PUD zaps. It has the same logic of the PMD helper. One thing to mention is, it might be a good idea to use page_table_check in the future for trapping wrong setups of shadow stack pgtable entries [1]. That is left for the future as a separate effort. [1] https://lore.kernel.org/all/59d518698f664e07c036a5098833d7b56b953305.ca= mel@intel.com Cc: "Edgecombe, Rick P" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Signed-off-by: Peter Xu --- arch/x86/include/asm/pgtable.h | 10 ++++++++++ arch/x86/mm/pgtable.c | 7 +++++++ include/linux/pgtable.h | 7 +++++++ mm/huge_memory.c | 4 +++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 25fc6d809572..cdf044c2ad6e 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -169,6 +169,13 @@ static inline int pud_young(pud_t pud) return pud_flags(pud) & _PAGE_ACCESSED; } =20 +static inline bool pud_shstk(pud_t pud) +{ + return cpu_feature_enabled(X86_FEATURE_SHSTK) && + (pud_flags(pud) & (_PAGE_RW | _PAGE_DIRTY | _PAGE_PSE)) =3D=3D + (_PAGE_DIRTY | _PAGE_PSE); +} + static inline int pte_write(pte_t pte) { /* @@ -1662,6 +1669,9 @@ void arch_check_zapped_pte(struct vm_area_struct *vma= , pte_t pte); #define arch_check_zapped_pmd arch_check_zapped_pmd void arch_check_zapped_pmd(struct vm_area_struct *vma, pmd_t pmd); =20 +#define arch_check_zapped_pud arch_check_zapped_pud +void arch_check_zapped_pud(struct vm_area_struct *vma, pud_t pud); + #ifdef CONFIG_XEN_PV #define arch_has_hw_nonleaf_pmd_young arch_has_hw_nonleaf_pmd_young static inline bool arch_has_hw_nonleaf_pmd_young(void) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 93e54ba91fbf..564b8945951e 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -926,3 +926,10 @@ void arch_check_zapped_pmd(struct vm_area_struct *vma,= pmd_t pmd) VM_WARN_ON_ONCE(!(vma->vm_flags & VM_SHADOW_STACK) && pmd_shstk(pmd)); } + +void arch_check_zapped_pud(struct vm_area_struct *vma, pud_t pud) +{ + /* See note in arch_check_zapped_pte() */ + VM_WARN_ON_ONCE(!(vma->vm_flags & VM_SHADOW_STACK) && + pud_shstk(pud)); +} diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 2a6a3cccfc36..2289e9f7aa1b 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -447,6 +447,13 @@ static inline void arch_check_zapped_pmd(struct vm_are= a_struct *vma, } #endif =20 +#ifndef arch_check_zapped_pud +static inline void arch_check_zapped_pud(struct vm_area_struct *vma, + pud_t pud) +{ +} +#endif + #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long address, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 251d6932130f..017377920d18 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2278,12 +2278,14 @@ int zap_huge_pud(struct mmu_gather *tlb, struct vm_= area_struct *vma, pud_t *pud, unsigned long addr) { spinlock_t *ptl; + pud_t orig_pud; =20 ptl =3D __pud_trans_huge_lock(pud, vma); if (!ptl) return 0; =20 - pudp_huge_get_and_clear_full(vma, addr, pud, tlb->fullmm); + orig_pud =3D pudp_huge_get_and_clear_full(vma, addr, pud, tlb->fullmm); + arch_check_zapped_pud(vma, orig_pud); tlb_remove_pud_tlb_entry(tlb, pud, addr); if (vma_is_special_huge(vma)) { spin_unlock(ptl); --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 669D8194C74 for ; Wed, 3 Jul 2024 21:29:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042183; cv=none; b=HD2X23GXvm7+ukgVHyIOEXEjQ42+CTmQiFgE8KmgAvAfgsZNHq2W0LgilnsDRw3cLan7azhvowqI88uW7pjtK2XXkZTHInBaQ/w4OWR+VjDPIIlGwI7+wrUZtqoYJvH7zYfzdAHwB38ID4KFY3uIobqp4YbdfXG43N2juhsTPJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042183; c=relaxed/simple; bh=IzaeIndLiHVeJjgbcceV6K1Hd52juxEnC/hKc2l9l9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZY1rtX3SLDVvZmn15CBgJTnR761rnxjdbqGTSMQpp48C4pY784/FyHMaDDYWKvtwSRcd4h1h8/H5zd6CdgAdKvLfBZ+Kikrq+6muNV8f90QDLZZk0bekrq4zVWN5LQsTeAaTrUkKAyNyRKNpvhvejx+X9tc8ntVHQkM/SRYPs/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=R7DUEC51; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R7DUEC51" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VBkUbHh5FhI05CAEJEjFs15FFfGPI8FVTV6ICfAryLc=; b=R7DUEC51h4yzdo27aKlb7ZX/tzSEef14gXxTIRvoxc6oFJ4KfEGYRo7MwTGqoViCxUFZA2 G+dYdZQFUZFRUVjulUZDuGNoA3hqY3yVCETDMNdmYL/DCagfjYsTvw9Y0Z7OsNMVeW1aQg eujSvOMM1Sj4+bM7kJ59dOd6nS+EFV0= Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-J1Xj9X5YNaiPF64Nrvv-1w-1; Wed, 03 Jul 2024 17:29:39 -0400 X-MC-Unique: J1Xj9X5YNaiPF64Nrvv-1w-1 Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-5c21b6db74dso1147858eaf.3 for ; Wed, 03 Jul 2024 14:29:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042178; x=1720646978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VBkUbHh5FhI05CAEJEjFs15FFfGPI8FVTV6ICfAryLc=; b=qhcW936zGLHQo34xMFvqh2l66dO2wKHxqqW3U3rYHFiZTdVMZQAeZjzoYZnnN1iluJ N/cHNi7iO7awhlYJMTIb0of3VdHRw6F5lAvCEP8zgKph4qgpkRR3FS5Q+UcBX2qnzObF ZCUbFYzivGRg+22s3DQHc5aavzL/O8UAEOOYqh09J8SxBruG40rUZfePk28Y5+WTPAxH 8ZOe4WRPzRL4lwQanUrnhATMzQ1w04AcwYpNZoYrsXhKcOgIuCb/fhqPFx3VF3yh5twk 5BDFuhcxsYiX4WeE+OJPrC92xnYxlldkxr9+EMwxLaweRpAdp7qzI4+QIUQrcp5a/HGd v7LA== X-Gm-Message-State: AOJu0YwyJCP4XQfSzgGJpp2mCVOQA2PHh7Tx9pMqusnXq2lo11f+fXco CjsN6MJoGvRUQAHdiYuWba/05bhyrW69rxE+RTmV3pdiZNzOEKVGzRdvReFQ+yPz0sctLJ8wipz Unvvi8JIsqZNcfi9EIIzEOnaorx1sEglb87K6qk+zv6Z2ECXSUJVRFYoj3D2yH8x1d1/9JNFq6k YuVytSCFBOQvawiCsCP4Ecf7uR6wrtgmUzcbywH9y7VCw= X-Received: by 2002:a05:6358:7f0d:b0:1a2:3bde:1425 with SMTP id e5c5f4694b2df-1a6acf18b33mr1469441255d.2.1720042177997; Wed, 03 Jul 2024 14:29:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFh/EdB/xSzquRBRoGgcbcKdNPV887AakpSVBbTc4I0BiDNq1hD4sw71GTYj4zNAp5JLHYzHw== X-Received: by 2002:a05:6358:7f0d:b0:1a2:3bde:1425 with SMTP id e5c5f4694b2df-1a6acf18b33mr1469428955d.2.1720042175430; Wed, 03 Jul 2024 14:29:35 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:34 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe Subject: [PATCH v2 7/8] mm/x86: Add missing pud helpers Date: Wed, 3 Jul 2024 17:29:17 -0400 Message-ID: <20240703212918.2417843-8-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These new helpers will be needed for pud entry updates soon. Introduce these helpers by referencing the pmd ones. Namely: - pudp_invalidate() - pud_modify() Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Signed-off-by: Peter Xu --- arch/x86/include/asm/pgtable.h | 55 +++++++++++++++++++++++++++++----- arch/x86/mm/pgtable.c | 11 +++++++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index cdf044c2ad6e..701593c53f3b 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -782,6 +782,12 @@ static inline pmd_t pmd_mkinvalid(pmd_t pmd) __pgprot(pmd_flags(pmd) & ~(_PAGE_PRESENT|_PAGE_PROTNONE))); } =20 +static inline pud_t pud_mkinvalid(pud_t pud) +{ + return pfn_pud(pud_pfn(pud), + __pgprot(pud_flags(pud) & ~(_PAGE_PRESENT|_PAGE_PROTNONE))); +} + static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask); =20 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) @@ -829,14 +835,8 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t new= prot) pmd_result =3D __pmd(val); =20 /* - * To avoid creating Write=3D0,Dirty=3D1 PMDs, pte_modify() needs to avoi= d: - * 1. Marking Write=3D0 PMDs Dirty=3D1 - * 2. Marking Dirty=3D1 PMDs Write=3D0 - * - * The first case cannot happen because the _PAGE_CHG_MASK will filter - * out any Dirty bit passed in newprot. Handle the second case by - * going through the mksaveddirty exercise. Only do this if the old - * value was Write=3D1 to avoid doing this on Shadow Stack PTEs. + * Avoid creating shadow stack PMD by accident. See comment in + * pte_modify(). */ if (oldval & _PAGE_RW) pmd_result =3D pmd_mksaveddirty(pmd_result); @@ -846,6 +846,29 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t new= prot) return pmd_result; } =20 +static inline pud_t pud_modify(pud_t pud, pgprot_t newprot) +{ + pudval_t val =3D pud_val(pud), oldval =3D val; + pud_t pud_result; + + val &=3D _HPAGE_CHG_MASK; + val |=3D check_pgprot(newprot) & ~_HPAGE_CHG_MASK; + val =3D flip_protnone_guard(oldval, val, PHYSICAL_PUD_PAGE_MASK); + + pud_result =3D __pud(val); + + /* + * Avoid creating shadow stack PUD by accident. See comment in + * pte_modify(). + */ + if (oldval & _PAGE_RW) + pud_result =3D pud_mksaveddirty(pud_result); + else + pud_result =3D pud_clear_saveddirty(pud_result); + + return pud_result; +} + /* * mprotect needs to preserve PAT and encryption bits when updating * vm_page_prot @@ -1384,10 +1407,26 @@ static inline pmd_t pmdp_establish(struct vm_area_s= truct *vma, } #endif =20 +static inline pud_t pudp_establish(struct vm_area_struct *vma, + unsigned long address, pud_t *pudp, pud_t pud) +{ + page_table_check_pud_set(vma->vm_mm, pudp, pud); + if (IS_ENABLED(CONFIG_SMP)) { + return xchg(pudp, pud); + } else { + pud_t old =3D *pudp; + WRITE_ONCE(*pudp, pud); + return old; + } +} + #define __HAVE_ARCH_PMDP_INVALIDATE_AD extern pmd_t pmdp_invalidate_ad(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp); =20 +pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address, + pud_t *pudp); + /* * Page table pages are page-aligned. The lower half of the top * level is used for userspace and the top half for the kernel. diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 564b8945951e..9d97a1b99160 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -641,6 +641,17 @@ pmd_t pmdp_invalidate_ad(struct vm_area_struct *vma, u= nsigned long address, } #endif =20 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address, + pud_t *pudp) +{ + VM_WARN_ON_ONCE(!pud_present(*pudp)); + pud_t old =3D pudp_establish(vma, address, pudp, pud_mkinvalid(*pudp)); + flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE); + return old; +} +#endif + /** * reserve_top_address - reserves a hole in the top of kernel address space * @reserve - size of hole to reserve --=20 2.45.0 From nobody Sat Feb 7 19:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 2ADE0191F8E for ; Wed, 3 Jul 2024 21:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042184; cv=none; b=OJvy7H3WKxqgXmYdm0ugOIitL0N22zL4oLpWw9QJf0LZi6Zl65WwMSeJwdhNuH+B0kHKLcoCQ0mDoioCJTFuoU7sOXQCHIQuRFQEel2MLLtmE3G6skxp5dDxyZDYQzc7T0uAzZOlX8+YK/lpS/FJe5+uncWi3UVNhreOUgR3UPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042184; c=relaxed/simple; bh=RvEiakZHQCqkyKEDQbLD0I2EOD9bX4tcpkuD7BRzdYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=snLjU5/D9u8aoc1AW9WXdfc37ibY8jzelnVAMjSLVm2EtZlIb++Dj0bIvwfnOX6Y0pfaWSS81p97VEP+QPvuvUN/3jqkl8UmQRPiDApJstfQFLoRE8r6IeUI471qDBBnieNSfFT1/7I4UxkCexfhMxaRCwbCfj7aKQd9BdMzDow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a01RS/TJ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a01RS/TJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720042182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j2Zxgw15onbd0eMS/03kg+dHZsOcAz6IsQR1l1z1OuE=; b=a01RS/TJJveUPLYohI+PTw4Fz5ABLMwFdAAq3dpTUoz/WuTF3ra6SI4H9Ng8QvhLaP8Z0f IWHUFdCqTMaKz1YyyoNa/jaJ4g9p3opnxtMz29ono+EO7o1zW8fmDL1K/AvEDthPMXa5IO 7rgSEkSIaXG+XtrE1XZhWOSSDtAcGe0= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-I286sxBrM--7qt7460bY_w-1; Wed, 03 Jul 2024 17:29:40 -0400 X-MC-Unique: I286sxBrM--7qt7460bY_w-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4464454e329so1958291cf.1 for ; Wed, 03 Jul 2024 14:29:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042180; x=1720646980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j2Zxgw15onbd0eMS/03kg+dHZsOcAz6IsQR1l1z1OuE=; b=ZOah8deW2KtMwmOfOMsIS7RCtjPxvq4LE935UBYwYyGooHgWzwMon5Jq9bYGlCvyYa V4O4BwDXuFl+Ba9100AyQX/az7aevssQvlfiTJqAUASgoehTFogSAa9/ohFr0m7Gy6Ud Ky7zjxI82Rl2Lh6DL2rVXAWzXOoh+Se8ksxLfZLt7v1DrkhkFrFZU67tRURklLEGBwKU k9GCuNDuS3Hd6yhEEPnZ45c9CvSZAIrSjbTzkokMfILBqEmHlUXTc5Pxvduh29wFjK4i D5VZ95pZOzkvLxmRHrdQK0Nu+nVthm5xGY18YK8NdzzBU2WbMvhiK2IFd/m2r8TLxZXN jhnQ== X-Gm-Message-State: AOJu0YzajAytjK2C+rVnJ41Gw+6ocpn1Pee+uMzWy1YXCsZwxdVuRUnd esxf/u24XStybVWl+REk4Kgqt1cKOmAORbQ/sn+0KfszxtwRjB0wd+agHzzcrd0ddmByyknJNry FDvcYLe3AOQ6y3wrmGF++nkJDR4uTUVYikQ5u515jB44sHsgFfKQhJ3DmEpTyOBH8kV/hnz06W2 Zs9ElyxuUSRAQhOk8l6s/bAnmZKlZobGVH1jcLhNJ7c6A= X-Received: by 2002:a05:622a:8f:b0:446:3c97:d3ab with SMTP id d75a77b69052e-44662eb7436mr151118711cf.4.1720042179770; Wed, 03 Jul 2024 14:29:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9nYtpxfPIDPA/kSFmDjfHMlL7UyJZQtNoCKoRdFeJRABCZlINs1O4dDPbOXn5gaxSQwwtsA== X-Received: by 2002:a05:622a:8f:b0:446:3c97:d3ab with SMTP id d75a77b69052e-44662eb7436mr151118391cf.4.1720042179335; Wed, 03 Jul 2024 14:29:39 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4465143eb1csm54337481cf.57.2024.07.03.14.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:29:39 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Mel Gorman , Dave Jiang , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Rik van Riel , Vlastimil Babka , Nicholas Piggin , Christophe Leroy , Andrew Morton , Huang Ying , Oscar Salvador , "Aneesh Kumar K . V" , Thomas Gleixner , Dave Hansen , x86@kernel.org, Ingo Molnar , "Kirill A . Shutemov" , Dan Williams , Borislav Petkov , peterx@redhat.com, Hugh Dickins , Rick P Edgecombe Subject: [PATCH v2 8/8] mm/mprotect: fix dax pud handlings Date: Wed, 3 Jul 2024 17:29:18 -0400 Message-ID: <20240703212918.2417843-9-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240703212918.2417843-1-peterx@redhat.com> References: <20240703212918.2417843-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is only relevant to the two archs that support PUD dax, aka, x86_64 and ppc64. PUD THPs do not yet exist elsewhere, and hugetlb PUDs do not count in this case. DAX have had PUD mappings for years, but change protection path never worked. When the path is triggered in any form (a simple test program would be: call mprotect() on a 1G dev_dax mapping), the kernel will report "bad pud". This patch should fix that. The new change_huge_pud() tries to keep everything simple. For example, it doesn't optimize write bit as that will need even more PUD helpers. It's not too bad anyway to have one more write fault in the worst case once for 1G range; may be a bigger thing for each PAGE_SIZE, though. Neither does it support userfault-wp bits, as there isn't such PUD mappings that is supported; file mappings always need a split there. The same to TLB shootdown: the pmd path (which was for x86 only) has the trick of using _ad() version of pmdp_invalidate*() which can avoid one redundant TLB, but let's also leave that for later. Again, the larger the mapping, the smaller of such effect. Another thing worth mention is this path needs to be careful on handling "retry" event for change_huge_pud() (where it can return 0): it isn't like change_huge_pmd(), as the pmd version is safe with all conditions handled in change_pte_range() later, thanks to Hugh's new pte_offset_map_lock(). In short, change_pte_range() is simply smarter than change_pmd_range() now after the shmem thp collapse rework. For that reason, change_pud_range() will need proper retry if it races with something else when a huge PUD changed from under us. Cc: Dan Williams Cc: Matthew Wilcox Cc: Dave Jiang Cc: Hugh Dickins Cc: Kirill A. Shutemov Cc: Vlastimil Babka Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: Michael Ellerman Cc: Aneesh Kumar K.V Cc: Oscar Salvador Cc: x86@kernel.org Cc: linuxppc-dev@lists.ozlabs.org Fixes: a00cc7d9dd93 ("mm, x86: add support for PUD-sized transparent hugepa= ges") Fixes: 27af67f35631 ("powerpc/book3s64/mm: enable transparent pud hugepage") Signed-off-by: Peter Xu --- include/linux/huge_mm.h | 24 +++++++++++++++++++ mm/huge_memory.c | 52 +++++++++++++++++++++++++++++++++++++++++ mm/mprotect.c | 40 ++++++++++++++++++++++++------- 3 files changed, 108 insertions(+), 8 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index cee3c5da8f0e..2ebebadfbe47 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -348,6 +348,17 @@ void split_huge_pmd_address(struct vm_area_struct *vma= , unsigned long address, void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, unsigned long address); =20 +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD +int change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, + pud_t *pudp, unsigned long addr, pgprot_t newprot, + unsigned long cp_flags); +#else +static inline int +change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, + pud_t *pudp, unsigned long addr, pgprot_t newprot, + unsigned long cp_flags) { return 0; } +#endif + #define split_huge_pud(__vma, __pud, __address) \ do { \ pud_t *____pud =3D (__pud); \ @@ -591,6 +602,19 @@ static inline int next_order(unsigned long *orders, in= t prev) { return 0; } + +static inline void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, + unsigned long address) +{ +} + +static inline int change_huge_pud(struct mmu_gather *tlb, + struct vm_area_struct *vma, pud_t *pudp, + unsigned long addr, pgprot_t newprot, + unsigned long cp_flags) +{ + return 0; +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 static inline int split_folio_to_list_to_order(struct folio *folio, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 017377920d18..4998452f7c49 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2099,6 +2099,53 @@ int change_huge_pmd(struct mmu_gather *tlb, struct v= m_area_struct *vma, return ret; } =20 +/* + * Returns: + * + * - 0: if pud leaf changed from under us + * - 1: if pud can be skipped + * - HPAGE_PUD_NR: if pud was successfully processed + */ +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD +int change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, + pud_t *pudp, unsigned long addr, pgprot_t newprot, + unsigned long cp_flags) +{ + struct mm_struct *mm =3D vma->vm_mm; + pud_t oldpud, entry; + spinlock_t *ptl; + + tlb_change_page_size(tlb, HPAGE_PUD_SIZE); + + /* NUMA balancing doesn't apply to dax */ + if (cp_flags & MM_CP_PROT_NUMA) + return 1; + + /* + * Huge entries on userfault-wp only works with anonymous, while we + * don't have anonymous PUDs yet. + */ + if (WARN_ON_ONCE(cp_flags & MM_CP_UFFD_WP_ALL)) + return 1; + + ptl =3D __pud_trans_huge_lock(pudp, vma); + if (!ptl) + return 0; + + /* + * Can't clear PUD or it can race with concurrent zapping. See + * change_huge_pmd(). + */ + oldpud =3D pudp_invalidate(vma, addr, pudp); + entry =3D pud_modify(oldpud, newprot); + set_pud_at(mm, addr, pudp, entry); + tlb_flush_pud_range(tlb, addr, HPAGE_PUD_SIZE); + + spin_unlock(ptl); + return HPAGE_PUD_NR; +} +#endif + #ifdef CONFIG_USERFAULTFD /* * The PT lock for src_pmd and dst_vma/src_vma (for reading) are locked by @@ -2329,6 +2376,11 @@ void __split_huge_pud(struct vm_area_struct *vma, pu= d_t *pud, spin_unlock(ptl); mmu_notifier_invalidate_range_end(&range); } +#else +void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, + unsigned long address) +{ +} #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ =20 static void __split_huge_zero_page_pmd(struct vm_area_struct *vma, diff --git a/mm/mprotect.c b/mm/mprotect.c index fb8bf3ff7cd9..694f13b83864 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -425,29 +425,53 @@ static inline long change_pud_range(struct mmu_gather= *tlb, unsigned long end, pgprot_t newprot, unsigned long cp_flags) { struct mmu_notifier_range range; - pud_t *pud; + pud_t *pudp, pud; unsigned long next; long pages =3D 0, ret; =20 range.start =3D 0; =20 - pud =3D pud_offset(p4d, addr); + pudp =3D pud_offset(p4d, addr); do { +again: next =3D pud_addr_end(addr, end); - ret =3D change_prepare(vma, pud, pmd, addr, cp_flags); - if (ret) - return ret; - if (pud_none_or_clear_bad(pud)) + ret =3D change_prepare(vma, pudp, pmd, addr, cp_flags); + if (ret) { + pages =3D ret; + break; + } + + pud =3D READ_ONCE(*pudp); + if (pud_none(pud)) continue; + if (!range.start) { mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_VMA, 0, vma->vm_mm, addr, end); mmu_notifier_invalidate_range_start(&range); } - pages +=3D change_pmd_range(tlb, vma, pud, addr, next, newprot, + + if (pud_leaf(pud)) { + if ((next - addr !=3D PUD_SIZE) || + pgtable_split_needed(vma, cp_flags)) { + __split_huge_pud(vma, pudp, addr); + goto again; + } else { + ret =3D change_huge_pud(tlb, vma, pudp, + addr, newprot, cp_flags); + if (ret =3D=3D 0) + goto again; + /* huge pud was handled */ + if (ret =3D=3D HPAGE_PUD_NR) + pages +=3D HPAGE_PUD_NR; + continue; + } + } + + pages +=3D change_pmd_range(tlb, vma, pudp, addr, next, newprot, cp_flags); - } while (pud++, addr =3D next, addr !=3D end); + } while (pudp++, addr =3D next, addr !=3D end); =20 if (range.start) mmu_notifier_invalidate_range_end(&range); --=20 2.45.0