From patchwork Thu Sep 21 16:20:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64F45E71093 for ; Thu, 21 Sep 2023 16:20:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0FFD6B01B1; Thu, 21 Sep 2023 12:20:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBECE6B0207; Thu, 21 Sep 2023 12:20:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C87906B0208; Thu, 21 Sep 2023 12:20:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BA6F76B01B1 for ; Thu, 21 Sep 2023 12:20:31 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 858511608F3 for ; Thu, 21 Sep 2023 16:20:31 +0000 (UTC) X-FDA: 81261117462.17.CA55117 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf21.hostedemail.com (Postfix) with ESMTP id E22171C001A for ; Thu, 21 Sep 2023 16:20:29 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313230; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rwFdA7NTCOSN56OoLgooEuv9WkGbezxG1625Lwk7ze8=; b=AlwvZ1a15hndQA2BToGtAmB6/ZxDxmhftan2KP5wXbkRfFuMBVE6Lu06n7W781sWXK0oSz QpTBkBoMfJaY6VxTLgeEi/DfooZdouXQh2Kf4HDEJM2AmujexEBNPueKIRGKTMgEnW5orr 7FT4+MJesqNGNSnc+Is4xJ3LHOCMmpQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313230; a=rsa-sha256; cv=none; b=GbOMxzodPolyk1kTYeTFV1RsCW4d/2NwEXtR5fjzzn96gnTRQ7svaFj8xCwnqIcnSQsFMF yRY2yqYSeQiZooeARHEcoVohS9Z19xYZWUJ4KwyaVDwJ50BBRLuFLUhLojxJdiznNFcUxN TL6sbi3cWZxAAC1nRacB1zui338Ozwk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ECB2D1713; Thu, 21 Sep 2023 09:21:05 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 811AA3F59C; Thu, 21 Sep 2023 09:20:24 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 1/8] parisc: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:00 +0100 Message-Id: <20230921162007.1630149-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E22171C001A X-Rspam-User: X-Stat-Signature: bwxenjs973ps8zg1pf9d5u3wwn39n6hu X-Rspamd-Server: rspam03 X-HE-Tag: 1695313229-881144 X-HE-Meta: U2FsdGVkX19uPj1PIZARTWXTqDfACG+2vlwWCTMAFlrdSqkGzFQiTr/ZLIo45EK075lVaRguiE/gm1Z4XHsSd58eq+VMXQuqo/mbBsXGb+jzVF42NjJFFsj6nLtsEb80TlqZSJsTtoFU8lJ0RsyrRuJcBrWGuFhS89zpzLahC6agTTNQWvEMeuZrYwjHCy5d5unze7xIgYJEter9pknNZ2+WUZ+lOAF/ETAova5o5/fB4Zrq1VXLAqChge+4H4c2dUtDqN+V0imPS5ze+x9Ww5ZlAIfaXV+IzKV+m0CgvM9dMG0AtR2x3z/kvj9ept5TagtMO0or53xUvHschZ0K3rsI8YSLx06vLN4U5+TLOeCIunu1kL6N1b0GEAZ5qFcV//5rPoiKce6eJr/8DOgAOoUL9h2XJUw8QR+5WgrMYVC4uFD+9J63Ua+ohCb2XjMZ+YeY38BknYdda2RDI8SsPHWPyFqawFTv2HxOH2lFqyWC5lT90BQRGIwHbyHEkdMOUEckBApNQS1tQ+5TrHDFYWWHFaWz9G6AkfnTYky4Y/NUrnfqXVupzqYK66AwhVFuCiO2cicn/dtSSnAIIgYdpouYG1fxYJmyFDd5JLFLZwiGSDsqCUIKhrQ0HLqSQMRyJpgYsJzFlQUqyw8/BkOkYh/eMHqvPqohyxe97is/dS6aQkAzQKy6TTrXNe54dYDcDFCMIKp0YtbOZML6FjYxtQXY1jsMQcyy3urk//ke5oK7MI0+nEdhnYu81wACZbSRW30VrfSxLIgLcrcCd9gheujxMuGy9hfil12qRXQ7npTQ1l/V27EuXzNs9Ow/ISsXdVTuOf1z9f/GgvTBhH0NNx3iDCUl+YcNOJUAFQP9fqh4zLaFvHv20qP92Mnwq6Cjja8V885tlRZhFytna5T0PIBafFn5EqZmp/1GyEWGCEL9SrtGO8eurctZIqKpFLq2t+qDHlSqTogCEEWReoY 9Iu22dL1 QxRCsnhU/gf5Cey9/0735HrWoU1VShvkImVIoMd3cKWUxDu2FLzP+fzBpkfFnTmvjZeXQJXxbJNDQWa7kyZb8MNRdHlTEMW6wr4Z9uVGHZciX/cB49k6wCXKbBBjBLVnJeWAyO2YHZVCLHbxBvrqkm/h68ukxpASJ8bWAo1En5fmX29Zv/4JyVUKKPhHFcBGBZBhkxCtNTEDqE3U= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required parisc modifications. Separate commits update the other arches and core code, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts --- arch/parisc/include/asm/hugetlb.h | 2 +- arch/parisc/mm/hugetlbpage.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hugetlb.h index f7f078c2872c..29ba631862c5 100644 --- a/arch/parisc/include/asm/hugetlb.h +++ b/arch/parisc/include/asm/hugetlb.h @@ -5,7 +5,7 @@ #include #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte); #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR diff --git a/arch/parisc/mm/hugetlbpage.c b/arch/parisc/mm/hugetlbpage.c index a8a1a7c1e16e..fc5e1ad8e5e8 100644 --- a/arch/parisc/mm/hugetlbpage.c +++ b/arch/parisc/mm/hugetlbpage.c @@ -139,10 +139,10 @@ static void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, purge_tlb_entries_huge(mm, addr_start); } -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t entry) { - __set_huge_pte_at(mm, addr, ptep, entry); + __set_huge_pte_at(vma->vm_mm, addr, ptep, entry); } From patchwork Thu Sep 21 16:20:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75C8DE71090 for ; Thu, 21 Sep 2023 16:20:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 116F36B0207; Thu, 21 Sep 2023 12:20:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C6AD6B0208; Thu, 21 Sep 2023 12:20:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED1116B0209; Thu, 21 Sep 2023 12:20:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E02C66B0207 for ; Thu, 21 Sep 2023 12:20:35 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B90911203E8 for ; Thu, 21 Sep 2023 16:20:35 +0000 (UTC) X-FDA: 81261117630.28.01CC988 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 11F348000E for ; Thu, 21 Sep 2023 16:20:33 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313234; a=rsa-sha256; cv=none; b=U+SZ7czHZBCu1Vaxdtl349jG4cxa52LEh0Ns23u8qDMuZD9AvvevNxA0Xe+3TOOcX8u39o 2JiDfKL6c7M+Yla1Qn4CMLP3mu65xUARKNz0ObOpDwxqnoMaIYdj5hfxfMh5cDvQmEb6g3 Y0EA0VWc0uQXWS12sh9qNBjRAsSrQFg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313234; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5xwQSctMmYFo12y5XzlJUTq3tE56VCa/T5pbiR1D+lI=; b=chjGfQEWDCm3etqoRtFX0+Zc514E1ZMfjOyYUqL/T7FDbNn/mc2+ZK477Qpa5NLfGJxcYP jin3MtYN4THucroBrVkHKgcu40+XvhmW8ZvcEL/Tllv3A+tKSD+cLmm0YAB8/+Y9jaNa1j S4/0RZBnadheLjOXLa7GyQ7oDHzKzH4= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 735E21756; Thu, 21 Sep 2023 09:21:10 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 07CC83F59C; Thu, 21 Sep 2023 09:20:28 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 2/8] powerpc: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:01 +0100 Message-Id: <20230921162007.1630149-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 11F348000E X-Stat-Signature: boz7ymo8y1aiibfmmbrangmrrgnhqkro X-HE-Tag: 1695313233-586540 X-HE-Meta: U2FsdGVkX18jdHfny45qnkoHoJcMVC7VDLMx/7jIaWiXbERhHa43gSBp3Ncon31QjRabHFqlesHCrW0Th583L1lDe4sAu/Y76IyfgeF9RSuWUhQE06SegBV+aVwbZIdpRwmcp1gj8cHSWLU3lw1k6YuN5lLNW9BXZpSXSSmOR9vmIwVao60mBMtOwfXsV5mEkHFI8QJ0rHV5K8hp1USWHtnqO2KhCGVg4/4+oJvqP9J+91bDoivbQxRR2rsWuoXdKqRYltU4+afaM5p95oBi9bSyd8wQcDSefPNamt4h3VYvayQwHeVIK7qvSyYT/BsHQ3LggATkfnYPfzBaSmk2oty0eruSTQYpogMWhBwD0OVeVbqqNYXE04gaiokfIfdqDY6LwPLG6yNhnrW7lPyoPA7Kfb/lyz4oL/KYKKpvhbIlE/GoI5/S+2BcWZsGF1uP6BigKhjEyoeIKMj5rnHvoLCO/14lSTKRX2yqFbwzbIxVTR3HNort8bhcbKN6Ef4dOH+XwRF1LwQjswdAGdPJYr9QdbrKoqRP2qTsfxiq3c4K2n1uO+iRkgi0flGy1Nr1fGTy/4cMNqfRNTO0fGJUPH0WHhaDx4nSjhSuM6nrOSHN9kZNSC52/q6oLCM/7GMYRjjzOWCMEIuTWWk1+qMfjIby1rpCG71/QqLvTfs+YI2wQC7ThygvDmwRUPkYXGUZA1a1dIn4fNnsYeXX/h3UBO0Z7otj3YC4s4tsma2xGxw8AradKyL1FuRbJPyoKnNJEHU6dpbVkpYN07WZZyIkxjxumrncmhNog5/Mp3M6FPjPGpTj+G68bRYv/AoFNd8ppGu31GmyYZtj8GWxaUxUn6JGdfImbNc5cYtYA5llPJZ4kztRubH0AsloHoH/Gqh11pG/FMGX0q3xW0nMIcif4EnpIrYLWTcQXyCZ7CVlH5HHu2EoIg1jsJixjAzOqxKpXqSQkLCDOCyWOPe7oit 5WDqeeK5 5GRBx7NlBjqcNT1OnKJxEcdyL2UvZkebmnlT2xDREWry9G1mgb6JIqOXkfg0qIJOs1EhVtNd27XSSzYPdHT9/WmuSYFBHO8xLSfCu68XB1b0IzIilMuXLLMXD4+byjLI9B838nPGPFU28ywaRY/Eh1i8EYknxeE1GsEYcZjaELXuG4QT5667aLNKXAwvj9fmAliUkYGIyARCkQ6o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required powerpc modifications. Separate commits update the other arches and core code, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts --- arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h | 3 ++- arch/powerpc/mm/book3s64/hugetlbpage.c | 2 +- arch/powerpc/mm/book3s64/radix_hugetlbpage.c | 2 +- arch/powerpc/mm/nohash/8xx.c | 2 +- arch/powerpc/mm/pgtable.c | 7 ++++++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h index de092b04ee1a..fff8cd726bc7 100644 --- a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h @@ -46,7 +46,8 @@ static inline int check_and_get_huge_psize(int shift) } #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte); +void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); #define __HAVE_ARCH_HUGE_PTE_CLEAR static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, diff --git a/arch/powerpc/mm/book3s64/hugetlbpage.c b/arch/powerpc/mm/book3s64/hugetlbpage.c index 3bc0eb21b2a0..ae7fd7c90eb8 100644 --- a/arch/powerpc/mm/book3s64/hugetlbpage.c +++ b/arch/powerpc/mm/book3s64/hugetlbpage.c @@ -147,7 +147,7 @@ void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr if (radix_enabled()) return radix__huge_ptep_modify_prot_commit(vma, addr, ptep, old_pte, pte); - set_huge_pte_at(vma->vm_mm, addr, ptep, pte); + set_huge_pte_at(vma, addr, ptep, pte); } void __init hugetlbpage_init_defaultsize(void) diff --git a/arch/powerpc/mm/book3s64/radix_hugetlbpage.c b/arch/powerpc/mm/book3s64/radix_hugetlbpage.c index 17075c78d4bc..7cd40a334c3a 100644 --- a/arch/powerpc/mm/book3s64/radix_hugetlbpage.c +++ b/arch/powerpc/mm/book3s64/radix_hugetlbpage.c @@ -58,5 +58,5 @@ void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma, atomic_read(&mm->context.copros) > 0) radix__flush_hugetlb_page(vma, addr); - set_huge_pte_at(vma->vm_mm, addr, ptep, pte); + set_huge_pte_at(vma, addr, ptep, pte); } diff --git a/arch/powerpc/mm/nohash/8xx.c b/arch/powerpc/mm/nohash/8xx.c index dbbfe897455d..650a7a8496b6 100644 --- a/arch/powerpc/mm/nohash/8xx.c +++ b/arch/powerpc/mm/nohash/8xx.c @@ -91,7 +91,7 @@ static int __ref __early_map_kernel_hugepage(unsigned long va, phys_addr_t pa, if (new && WARN_ON(pte_present(*ptep) && pgprot_val(prot))) return -EINVAL; - set_huge_pte_at(&init_mm, va, ptep, pte_mkhuge(pfn_pte(pa >> PAGE_SHIFT, prot))); + __set_huge_pte_at(&init_mm, va, ptep, pte_mkhuge(pfn_pte(pa >> PAGE_SHIFT, prot))); return 0; } diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 3f86fd217690..9cbcb561a4d8 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -288,7 +288,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, } #if defined(CONFIG_PPC_8xx) -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) +void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) { pmd_t *pmd = pmd_off(mm, addr); pte_basic_t val; @@ -310,6 +310,11 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_ for (i = 0; i < num; i++, entry++, val += SZ_4K) *entry = val; } + +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) +{ + __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +} #endif #endif /* CONFIG_HUGETLB_PAGE */ From patchwork Thu Sep 21 16:20:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C2CCE71090 for ; Thu, 21 Sep 2023 16:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC1BA6B020A; Thu, 21 Sep 2023 12:20:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA0D56B0209; Thu, 21 Sep 2023 12:20:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3A3C6B020A; Thu, 21 Sep 2023 12:20:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B59D56B0208 for ; Thu, 21 Sep 2023 12:20:40 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8B29D808FF for ; Thu, 21 Sep 2023 16:20:40 +0000 (UTC) X-FDA: 81261117840.01.802FB8B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf08.hostedemail.com (Postfix) with ESMTP id D9FCD160025 for ; Thu, 21 Sep 2023 16:20:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf08.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313238; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qHCXosr3PvEhIv4wRyQYcPxGRzmyaFYWZMq7sEiKto0=; b=CuBxOXMRsJ/1ZC+FUj4++H2zogV6FvdS29OKhrbyFVOJGEidEIzLALjGB5EjOrmizP/4tO hMtDxLuPWo5sDwhmIxN4BqcpO8xSVRqaolBxjKgSXPNRyPCRfx4g+/yAdBAbOTPahsXjmD FAZG9lmcMbJw3Hf5UarMijP1Dzih6RM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf08.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313238; a=rsa-sha256; cv=none; b=NLO6iTovZ1nniwHX17XcBCBD3Jw64ALJj4xWjaX4+G/nVQYUkfGR5CKg/ARG661efMtMgB IOprk4eywTw+6ZjUaDBLTgSOFAoZ94yiqjbUGpoGLp3mTNklcyGbFD+Q/iXq/VuyriPrnu cLS3evZ0IfMr9r2Em5q+sHoTteWRs3Q= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EE7B51758; Thu, 21 Sep 2023 09:21:14 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 82D213F59C; Thu, 21 Sep 2023 09:20:33 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 3/8] riscv: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:02 +0100 Message-Id: <20230921162007.1630149-4-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D9FCD160025 X-Stat-Signature: i7cahwq7t8rjzq5ew39hfxmtmgop3u4a X-HE-Tag: 1695313238-898732 X-HE-Meta: U2FsdGVkX18IwjfU9TYo5D4jd2R6KSpt+ESjobGs3ciNFt7sd7g9WxPE75S/vWuU1l23WTZgZs3qxQ5FDfZopEIC1uqsbGcGiF1jF8hvIIj9XrRhSkHFiVK0jVLjbKD7cwfwvh26pybUFZjBdeuttnZQHbWQ5sr+SoHcP6QGvOB4dJiftifTuc+HyLIZqiuiPek7pDmX6pEckfwAHFgljzuXmP6tgrYbm69AjNHDY9lfN4UA1ykTLOOpBtQpl0CcPQHHOCKqmPgjF6ko8sGoLtEGqvYonoyI81tv6jzgyt3GnlzBKWH1IiencYNpMjc8RuHtTHb96ddPOvMpuCN8iEL8XDNmItOJ16FBLBy5dr2AD8smG34UVm5e3fAOvhiq2Ad/C7lhqfRZiMYbFvwqlyxlVbSFuVIORxVxlU3DbLAZIbPNaywVJ1IIZ72O8s+ho7zQ498eCiQ6uwNSQIgA5mAITdHzsPHzCj16mWxApl72EaS9Q6C4vO7AbEtogK55kW3s/+qAafA1PKNKgX52VWkrbbYuaXbtk5BDEwM3laaJjvl6NC1wwMUFQQqNteRg8+AuWCj8P3AY7X4/gXF+KTEJ44SZkKzNSNelePaYzJiordy3btT1fXZnxl+G/KaMmIC+YMQ23GK30fUGOVQN2+Wj3FEfN5Z45XQ8g6BeR0EQUvxKQEYYYfLGkrur8lFWFuV+hfAXMaoH9447igFZevdQ8wEPoNKvfIPJKlfUBZToekH6Qe/KMpECfciWVqADBmS50lx9wuk6ZmbUJfFjnSOnGEY/N7Ar4417wjxc+mQNwEmiL0MiR6tFuItO1Z0/SPMGbtqxp431nuUCgtfrXUbL21/3B6HiRnsXL9Dzifx0wP9Wus9SbOjsMxcSfON8jA/+aHoPOmE/3ULgaOnYV3de6xtfebGzIdY2G/zQQdMSXmvgBZV7xUQf42I3waNlbPXDE1dE75MlVRKDaJ8 hbFR0WBM aO/udP5+X53rD2YOXJNkMDIzozrdAw8/dJJOfuNWL74TetPYsecHnX6qnPZ34hx/0d8tmBtjFTrZOtuvqy4Dz8vGQY6qUumHtmDhKiTwRIzmhnUrbai17LhH2mYdjC12lue3MSC4TzLgiMpudMD1YSuLP9+b1U7qKOCt8k/122j6WGA2YNfk8eKuDCO9TlwC4eZ5smqBIurGiQJk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required riscv modifications. Separate commits update the other arches and core code, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/hugetlb.h | 2 +- arch/riscv/mm/hugetlbpage.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index 34e24f078cc1..be1ac8582bc2 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -17,7 +17,7 @@ void huge_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned long sz); #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -void set_huge_pte_at(struct mm_struct *mm, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte); #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index 96225a8533ad..7cdbf0960772 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -177,11 +177,12 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -void set_huge_pte_at(struct mm_struct *mm, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) { + struct mm_struct *mm = vma->vm_mm; int i, pte_num; if (!pte_napot(pte)) { From patchwork Thu Sep 21 16:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D029AE71093 for ; Thu, 21 Sep 2023 16:20:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 647336B0208; Thu, 21 Sep 2023 12:20:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F7476B0209; Thu, 21 Sep 2023 12:20:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BF456B020B; Thu, 21 Sep 2023 12:20:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D3346B0208 for ; Thu, 21 Sep 2023 12:20:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 082B640C33 for ; Thu, 21 Sep 2023 16:20:45 +0000 (UTC) X-FDA: 81261118050.18.477AC17 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 244DC40018 for ; Thu, 21 Sep 2023 16:20:42 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313243; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vypF7oeKU3Uje4sDoCk7NF4kdS/Y+VzjMg+SzT44ILc=; b=gz78bKc9y91mdx0sYwWdd2NVl7AoxOtqK1JV5UIvfSgUrACSSzi+R+3GSBNxnBXZmAfCUm b4EKeWnRaFvaLkP9kZco0iKw+/IrCM4yKricpblWBUtyA+rdjSV8+cydFD22kuwJX3xlzD NExd5xsX23I4PP/93PmyhhkmZ07swb4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313243; a=rsa-sha256; cv=none; b=PCqLOoiiEzNrCwjPjBYmdWJfW81XPtEC6prPq3L9SPBL1YR9oaBPyYIvlNGMlt5ehYC+vB TOivBwyg+dwwXqX1Cv79sttfPVcmVRfmKYtdMpV2qhP+C2Wknm3+aKrwpHJwM7aA6voa7i 131HjLju6DbDh5h/QIoTofKHuVokzLw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 75302175A; Thu, 21 Sep 2023 09:21:19 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 09E233F59C; Thu, 21 Sep 2023 09:20:37 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 4/8] s390: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:03 +0100 Message-Id: <20230921162007.1630149-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: dcr11ybujo5uxkeoirsp9n91saeksitw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 244DC40018 X-HE-Tag: 1695313242-948688 X-HE-Meta: U2FsdGVkX1/7ozjvbF1g9Ir0wrDWvcK7yYSkmdSq65B2CCpl3jUb8ZfueDsigzSLujvggd/Q7d4JWOmL60+Eqkbrz6J9+a3oJA9Ok9QQV54cG5HESbHLq/BLRcyXB+5PkOlOf6JuKQLfDFAh4DpZIt/3YHGWjcmdD59p9hlxf2mz3XkZy+hFqJGXq4tRknqP8cimc5NjuZxPzUsbC4c+3jnQwyRUW/s9CG3HNBy4HSL/lxBiAUaPhU0SxLX0flfVdNtAyA4JbHTDOSBPQ1waTLIWe0jCdyND/Ya9Dukznsr9JNYRp20cf3Ku+EGyty8ZOirR7sB52BclENP5SfmII7X21ANtiJj8L4LKMjcg3F4+Yz4NcHWibwh9rR+DU6FMHbrylS8GTVAO9JKykwuTamH8+Ak0lOsrCu6wxoaAbPP+7mTkdEER3dIeJYfivZ/NDbnfkeiaMniWF9r4mn4VMUAiUXhKPPLJ4b6PKOjcI14Eu9pq8jZuNQPEppNWVlcZ185/EYkppXrtJ/OMzDdqStjEz4yt6zP/owVQR/+0djZRrjEmZo460c7tfChuF8IBzBXFxN/2slHCGH+kfN/xq6UEwOH+z2Fp8ZkokuQBJrjlA2y706sX9wHsI1fWbsHt3oYr+xTWTWVVHn+fVycJbnlgIui1jxz+UWXnLA29z9kKr6XJoQeLPVCksoBQkwqPsihDGl0UFjXPkFlLe60YsWB1l9YMEaBs4oLKai0EO7Jzv0SBqOUjbKwwOOrY99NFfYijtIj8yPT2v4DrykHKVBXAZAEFod6FMyzeFp8EGxMYsgj/eFhI4vgFOwQ8mJ4RMPUwAOI+5IQdS9GpgWXViQ47SiHnX5aLy+9b9MbUK5vq0wkflKE7kwdNzPEmOsRexnaxVkozpdVMfRkEEC9O/tsIY3RZWn19G5dhEkEr2SnBxwtQthORCTmKDlZHaWmIsoIx/o5qXEupxm29G0s mmCCoN4H SKGfCdX3xkBCjvLzq682i92Vr8rV08RDUzJCReaqKIA3w91eG2ZBNcFSuUnTcYzPITvHA1JFQPW9OPKzLogVOL/lRvmYKbWce4VCr/4Ywb1DaHBo+19JTGM6C+bWNQsMgbVIDHY6p2uvuhZMlXQtYYRqPBlsBZu/mf6jNKPiqBpcKxHjAGJZExxFu3toJlOYwX8uPW81YR2n6mVw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required s390 modifications. Separate commits update the other arches and core code, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts --- arch/s390/include/asm/hugetlb.h | 8 +++++--- arch/s390/mm/hugetlbpage.c | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h index f07267875a19..da7f43b1871f 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -15,7 +15,9 @@ #define hugetlb_free_pgd_range free_pgd_range #define hugepages_supported() (MACHINE_HAS_EDAT1) -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pte_t pte); +void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); pte_t huge_ptep_get(pte_t *ptep); pte_t huge_ptep_get_and_clear(struct mm_struct *mm, @@ -65,7 +67,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, int changed = !pte_same(huge_ptep_get(ptep), pte); if (changed) { huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); - set_huge_pte_at(vma->vm_mm, addr, ptep, pte); + __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); } return changed; } @@ -74,7 +76,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { pte_t pte = huge_ptep_get_and_clear(mm, addr, ptep); - set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); + __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); } static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot) diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index c718f2a0de94..d69e2dc6e508 100644 --- a/arch/s390/mm/hugetlbpage.c +++ b/arch/s390/mm/hugetlbpage.c @@ -142,7 +142,7 @@ static void clear_huge_pte_skeys(struct mm_struct *mm, unsigned long rste) __storage_key_init_range(paddr, paddr + size - 1); } -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) { unsigned long rste; @@ -163,6 +163,12 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, set_pte(ptep, __pte(rste)); } +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pte_t pte) +{ + __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +} + pte_t huge_ptep_get(pte_t *ptep) { return __rste_to_pte(pte_val(*ptep)); From patchwork Thu Sep 21 16:20:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EFD8E71093 for ; Thu, 21 Sep 2023 16:20:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 116CD6B0209; Thu, 21 Sep 2023 12:20:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C7616B020B; Thu, 21 Sep 2023 12:20:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAA086B020C; Thu, 21 Sep 2023 12:20:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D89F16B0209 for ; Thu, 21 Sep 2023 12:20:49 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AF9041CA021 for ; Thu, 21 Sep 2023 16:20:49 +0000 (UTC) X-FDA: 81261118218.04.AFD003C Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 8AABAC002D for ; Thu, 21 Sep 2023 16:20:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313247; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dzUffe4GGQ8UncNqgjGcAoM9QB0C02k3oGzHg6Pvf7M=; b=rgSidG36wrMscSe3PQX2yYKwWGODhZzrxpA5c1PrAwG1+FUGoEci0jmUrIqZe3ZZIPWvFV HxHTxs2Lt5RPdzHvVE65QShKd0Qkk/UItWrxO/EQKFNhhnnVKWvHJHUSJkmbCxzlL9mLhp 9S8fjM0e6xhHDOGw8YQoRnczRUyfTzc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313247; a=rsa-sha256; cv=none; b=XdaS2nN7RCzcIL4Kb1FilDGoi6lji4AircS4cc8MQ8alk020kAd6wITxiQ8kfd5AKALXcI /OvFBgXTWCf27dUJILtp2cpRRtgHAk82yDQeqMUO0P+jG/8tQOdrU+Mc40YyVPxGxbmmjU peEgqI/z4XA2UdNHHWARibZCTnnDtz4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F07FB175D; Thu, 21 Sep 2023 09:21:23 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 84F093F59C; Thu, 21 Sep 2023 09:20:42 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 5/8] sparc: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:04 +0100 Message-Id: <20230921162007.1630149-6-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8AABAC002D X-Rspam-User: X-Stat-Signature: jk6gatb4hk1mknazcf4ciizwwxkizk9b X-Rspamd-Server: rspam03 X-HE-Tag: 1695313247-373261 X-HE-Meta: U2FsdGVkX1+Ts7Ey80uBoYbYAbFmSY8m71qX0yNde0MsqXONnfW04MCLtKUS6ZFZK+cD5S45R+f+R7d6kcUQfmYVDZCe01FidEyT/ea/yC6avgCMyLlPr8GlqSWz93/d1aW1Shq7UBCixNzU0x2qc0FR6ezdE258xg5fmvtRUGhCi18y9jEvJZxqCb60AmOM/4glMYTG/r4hFVaXjS7q5xNe0fHOB2nQrPsRkk86aLUD+1lyiy1J1HAKHz1TM+zfNzlYr+o0sA/RctMsIz5zOQnDXgFLPnEkXSfAEJQCg14R0jUyHQLq6n2j1ppqh/m5+HI0KNsj5+H2pvt3b27QEwpAn/7fXfEJyAdtU1+nPPY5jsAm4ZdpsYMW/fnGvhVf+GTGKQMMff9Yh9FDK5E9tm6PXDAH7DzSKbbXDlX7YEXhzlK3mrXCYi/q0eZJ/nQP6/lyBcJNXdkEa1+5gxn9fg9NeSk0FT+ZsJxSbUW107+YSCWtQn4fXfEFPQ9LA3RO4RMt7cOmNq5KD0QKFVBTq7EzASSlxLu51cvTrRwmYuwPRXk0Ttg/JSK7M35PlZIN9IHju/1Immz60gDBhmw5/dNI5+AmbitRyAw0kthIi5GOEa45JcOdTRfQ7+yEKxWoWVfa6o2T+z1dszi/9L8dtpVXZkBUp+t8UF/jRQ0hQMcm6pvWU2oJQgwx3B+sxFOfsNqjLR16VkbpxIS9G1llhlv7V4HTehWzCjTDBj0QqdCbGIUJyjXBsGMDH6IlZwSfBT2gsCJfGxiyAkakDQFcMQrqH8wj33XR5xExpaTSP2JDF54VDICzjY4S0B6m9iFlxT6l3iD1uswI4rojCdqzYACab1UT6bNjqfXG5f0/GxMtJx+lgxe+iNFFqh/PmtSqDQ9Tx4ZXMc9oJ3hsw2Y2qSStLYFJ2GQobhNeEVv2UWWeEzUGj8Q3IG2v+q6XIDRtKLbXOstG7MiDeYaeLC3 mVo0C0XL P0jwrhi0hBIQtKRRXZ5aRJy2y6a30k5fvMyIgmaqlM5cj7pm8YCff3awoDRmEjo9iyi0vNzfE0z/0X7zbyBma4XiequQp/YbouZ6/NSr9nE9Npost08gUjcNO8XeGzLkjSu3o33b66jeuP50KsYuot4tH+Sq+GksuNOy5Vqs73j0m9CMRYiqqZNxhVI2gwbXbtOsQKmG6rsNV00g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required sparc modifications. Separate commits update the other arches and core code, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts --- arch/sparc/include/asm/hugetlb.h | 8 +++++--- arch/sparc/mm/hugetlbpage.c | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/sparc/include/asm/hugetlb.h b/arch/sparc/include/asm/hugetlb.h index 0a26cca24232..14a71b735bb8 100644 --- a/arch/sparc/include/asm/hugetlb.h +++ b/arch/sparc/include/asm/hugetlb.h @@ -13,7 +13,9 @@ extern struct pud_huge_patch_entry __pud_huge_patch, __pud_huge_patch_end; #endif #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pte_t pte); +void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR @@ -32,7 +34,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { pte_t old_pte = *ptep; - set_huge_pte_at(mm, addr, ptep, pte_wrprotect(old_pte)); + __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(old_pte)); } #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS @@ -42,7 +44,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, { int changed = !pte_same(*ptep, pte); if (changed) { - set_huge_pte_at(vma->vm_mm, addr, ptep, pte); + __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); flush_tlb_page(vma, addr); } return changed; diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index d7018823206c..05267b72103f 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -328,7 +328,7 @@ pte_t *huge_pte_offset(struct mm_struct *mm, return pte_offset_huge(pmd, addr); } -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t entry) { unsigned int nptes, orig_shift, shift; @@ -364,6 +364,12 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, orig_shift); } +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pte_t entry) +{ + __set_huge_pte_at(vma->vm_mm, addr, ptep, entry); +} + pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { From patchwork Thu Sep 21 16:20:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5EB2E71090 for ; Thu, 21 Sep 2023 16:20:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24F526B020B; Thu, 21 Sep 2023 12:20:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 226AE6B020C; Thu, 21 Sep 2023 12:20:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C79D6B020D; Thu, 21 Sep 2023 12:20:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F29D76B020B for ; Thu, 21 Sep 2023 12:20:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C5D1480D28 for ; Thu, 21 Sep 2023 16:20:53 +0000 (UTC) X-FDA: 81261118386.27.CDD4B2A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 290A8C0029 for ; Thu, 21 Sep 2023 16:20:51 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313252; a=rsa-sha256; cv=none; b=kHbD/GgXcNcSdNVddwnbfTHsAtZ+BcDDVP3Z0KBLRE2HzxrBW7X8mM5SPWLD+gSRs3Cj7W /svgZO/NvwdvzLyuW8PiYqorq26zss+61G0jqm9ABfn/SgN2C4o8wHmF1jB9xhfMUiIW99 21j6sH2NFJ+S8LTQY3TUM6AF/9mcJAE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313252; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KzfRLaLyR125P3gGdZxsyNO8aJT47vmGKTm1sKBR754=; b=ySMluvZ80aB0CxgcR89puuqIk4vgR0BEdgWhvq94UMhfjhqL4LzpVILdzTxcNjMiB4yAw0 LEhZjW80v4ZtiW1FjAN1vJo4aYMCMkHuWFKOdcV3XkDvQku8XzxUpX3J0V2YCE2ETojtM6 BUQr7bAV9I9FpmFNWrYNdu2WZZB5UFI= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 914391762; Thu, 21 Sep 2023 09:21:28 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0C22D3F59C; Thu, 21 Sep 2023 09:20:46 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 6/8] mm: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:05 +0100 Message-Id: <20230921162007.1630149-7-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 290A8C0029 X-Stat-Signature: zwfpgr8jtnh93ezkyja6oejkdqpeekhm X-Rspam-User: X-HE-Tag: 1695313251-342588 X-HE-Meta: U2FsdGVkX1+X9SjX/ukO/55nCJEfGmpZI66WpPx8MVDrAX5Q8l25hjq3oi9KHvhREf4pRhSoN40sGuSTtb7nqLs38cLQb++U/rR8RXqc04JZO3/gZcCzyaRiJhppmL6W5vw67CQVN3QsiQzHECqGtyXwrqWmLIbI7f3DXLGKcFOmBkgz3lqeyLkOYy52zZ1tuCZehT+7UG3zVDR+VLtF9/UH1Km0w0sP6qhex6MZz8qD4U2UCLJfLUbPt7Qycl6UBIk00UkKT8Q4zZWrGW5itypQIaKypx9R19vXDaT4Z4r6pC3wl26TYbYQBnAx44rd7y45NT/e2QHd1/BT4te13Hn0osXosAb+zQZa8QK9La3co9cuJ8ZHijaieUWl3fH6MRLOMprdd0WGTaaJjNHe+ZEfzql/ypL7TwRNRoXNX7zDizInL84ronSa/o1uycHMyKoQaGboz0zcwpr2q7XSaYlmWWIWG9aPkdscuXJ7/JUPz2fJNQCSbQmGkc/OnbRWGjyU+A0vb32IXIXfv30sN43ATPy2vtvtePmLG4hgDRowdIWW3FSFDiOsKUbrx8IgWMM1Uug+y/Uy2uVQJE2/4vG/JhkPgcR5Wt6I05FJjEAFCKqApXVXmYIJhaWzFQHt5LnzFLmvSHWdt3YUmBWDReMHA3FwaxQYR7GL2sH+KSmfax5bY7eXSnEcO7urjA3Fb9Dmsu4Cnb/RoZbeuXV1TekhmZUmYaMtmfodStdsxXaVaKPk1X+VqWkxOt38cu3ZJImWeIWpYlaaJrOVrCyabYr3fqZuWppOtPXeQZgcwMgmkqJP0VZQjo6FQoOny1y7kgKR7qNLdmaIy9qtDyarsl+Ls90QHdI4JR3+3e6ZWn7s5YBUAxVhVIfVxWTkF6w3jMqNx8F9dvVoW71cETKuxPMVQ0wX6jVTSDAoSoh17QhJZzxUBYbuB04WWUmAgcYZe+Al/RMiGDPQocAvlWV dBGX2bXZ rHsbXmU7+kcNvo2hDMlU7DCoZhKC3ZKzr/P8cYWD5/I/3aXeL4FFrdADVhcMpl1cAzNK8EgFiGNHEexsuYyd1MQlJieDsriO+SgJiKbIrmrKoV6pIu/nH/9bJN6W0oTkVRa13pwvbMnKy8M5BQv//V2xqsef++91cYCWSSiJ6lKWBTTsaNBEznspB/T9zjF5XJlRYxAMG7R4Trb4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required modifications to the core mm. Separate commits update the arches, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts Reviewed-by: SeongJae Park --- include/asm-generic/hugetlb.h | 6 +++--- include/linux/hugetlb.h | 6 +++--- mm/damon/vaddr.c | 2 +- mm/hugetlb.c | 30 +++++++++++++++--------------- mm/migrate.c | 2 +- mm/rmap.c | 10 +++++----- mm/vmalloc.c | 5 ++++- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 4da02798a00b..515e4777fb65 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -75,10 +75,10 @@ static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb, #endif #ifndef __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) +static inline void set_huge_pte_at(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, pte_t pte) { - set_pte_at(mm, addr, ptep, pte); + set_pte_at(vma->vm_mm, addr, ptep, pte); } #endif diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 5b2626063f4f..08184f32430c 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -984,7 +984,7 @@ static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t old_pte, pte_t pte) { - set_huge_pte_at(vma->vm_mm, addr, ptep, pte); + set_huge_pte_at(vma, addr, ptep, pte); } #endif @@ -1172,8 +1172,8 @@ static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, #endif } -static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte) +static inline void set_huge_pte_at(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, pte_t pte) { } diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 4c81a9dbd044..55da8cee8fbc 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -347,7 +347,7 @@ static void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm, if (pte_young(entry)) { referenced = true; entry = pte_mkold(entry); - set_huge_pte_at(mm, addr, pte, entry); + set_huge_pte_at(vma, addr, pte, entry); } #ifdef CONFIG_MMU_NOTIFIER diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ba6d39b71cb1..bcc30cd62586 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4988,7 +4988,7 @@ hugetlb_install_folio(struct vm_area_struct *vma, pte_t *ptep, unsigned long add hugepage_add_new_anon_rmap(new_folio, vma, addr); if (userfaultfd_wp(vma) && huge_pte_uffd_wp(old)) newpte = huge_pte_mkuffd_wp(newpte); - set_huge_pte_at(vma->vm_mm, addr, ptep, newpte); + set_huge_pte_at(vma, addr, ptep, newpte); hugetlb_count_add(pages_per_huge_page(hstate_vma(vma)), vma->vm_mm); folio_set_hugetlb_migratable(new_folio); } @@ -5065,7 +5065,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) { if (!userfaultfd_wp(dst_vma)) entry = huge_pte_clear_uffd_wp(entry); - set_huge_pte_at(dst, addr, dst_pte, entry); + set_huge_pte_at(dst_vma, addr, dst_pte, entry); } else if (unlikely(is_hugetlb_entry_migration(entry))) { swp_entry_t swp_entry = pte_to_swp_entry(entry); bool uffd_wp = pte_swp_uffd_wp(entry); @@ -5080,17 +5080,17 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, entry = swp_entry_to_pte(swp_entry); if (userfaultfd_wp(src_vma) && uffd_wp) entry = pte_swp_mkuffd_wp(entry); - set_huge_pte_at(src, addr, src_pte, entry); + set_huge_pte_at(src_vma, addr, src_pte, entry); } if (!userfaultfd_wp(dst_vma)) entry = huge_pte_clear_uffd_wp(entry); - set_huge_pte_at(dst, addr, dst_pte, entry); + set_huge_pte_at(dst_vma, addr, dst_pte, entry); } else if (unlikely(is_pte_marker(entry))) { pte_marker marker = copy_pte_marker( pte_to_swp_entry(entry), dst_vma); if (marker) - set_huge_pte_at(dst, addr, dst_pte, + set_huge_pte_at(dst_vma, addr, dst_pte, make_pte_marker(marker)); } else { entry = huge_ptep_get(src_pte); @@ -5166,7 +5166,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, if (!userfaultfd_wp(dst_vma)) entry = huge_pte_clear_uffd_wp(entry); - set_huge_pte_at(dst, addr, dst_pte, entry); + set_huge_pte_at(dst_vma, addr, dst_pte, entry); hugetlb_count_add(npages, dst); } spin_unlock(src_ptl); @@ -5202,7 +5202,7 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); pte = huge_ptep_get_and_clear(mm, old_addr, src_pte); - set_huge_pte_at(mm, new_addr, dst_pte, pte); + set_huge_pte_at(vma, new_addr, dst_pte, pte); if (src_ptl != dst_ptl) spin_unlock(src_ptl); @@ -5336,7 +5336,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct */ if (pte_swp_uffd_wp_any(pte) && !(zap_flags & ZAP_FLAG_DROP_MARKER)) - set_huge_pte_at(mm, address, ptep, + set_huge_pte_at(vma, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); else huge_pte_clear(mm, address, ptep, sz); @@ -5370,7 +5370,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct /* Leave a uffd-wp pte marker if needed */ if (huge_pte_uffd_wp(pte) && !(zap_flags & ZAP_FLAG_DROP_MARKER)) - set_huge_pte_at(mm, address, ptep, + set_huge_pte_at(vma, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); hugetlb_count_sub(pages_per_huge_page(h), mm); page_remove_rmap(page, vma, true); @@ -5676,7 +5676,7 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, hugepage_add_new_anon_rmap(new_folio, vma, haddr); if (huge_pte_uffd_wp(pte)) newpte = huge_pte_mkuffd_wp(newpte); - set_huge_pte_at(mm, haddr, ptep, newpte); + set_huge_pte_at(vma, haddr, ptep, newpte); folio_set_hugetlb_migratable(new_folio); /* Make the old page be freed below */ new_folio = old_folio; @@ -5972,7 +5972,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, */ if (unlikely(pte_marker_uffd_wp(old_pte))) new_pte = huge_pte_mkuffd_wp(new_pte); - set_huge_pte_at(mm, haddr, ptep, new_pte); + set_huge_pte_at(vma, haddr, ptep, new_pte); hugetlb_count_add(pages_per_huge_page(h), mm); if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) { @@ -6261,7 +6261,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, } _dst_pte = make_pte_marker(PTE_MARKER_POISONED); - set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); + set_huge_pte_at(dst_vma, dst_addr, dst_pte, _dst_pte); /* No need to invalidate - it was non-present before */ update_mmu_cache(dst_vma, dst_addr, dst_pte); @@ -6412,7 +6412,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, if (wp_enabled) _dst_pte = huge_pte_mkuffd_wp(_dst_pte); - set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); + set_huge_pte_at(dst_vma, dst_addr, dst_pte, _dst_pte); hugetlb_count_add(pages_per_huge_page(h), dst_mm); @@ -6598,7 +6598,7 @@ long hugetlb_change_protection(struct vm_area_struct *vma, else if (uffd_wp_resolve) newpte = pte_swp_clear_uffd_wp(newpte); if (!pte_same(pte, newpte)) - set_huge_pte_at(mm, address, ptep, newpte); + set_huge_pte_at(vma, address, ptep, newpte); } else if (unlikely(is_pte_marker(pte))) { /* No other markers apply for now. */ WARN_ON_ONCE(!pte_marker_uffd_wp(pte)); @@ -6622,7 +6622,7 @@ long hugetlb_change_protection(struct vm_area_struct *vma, /* None pte */ if (unlikely(uffd_wp)) /* Safe to modify directly (none->non-present). */ - set_huge_pte_at(mm, address, ptep, + set_huge_pte_at(vma, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); } spin_unlock(ptl); diff --git a/mm/migrate.c b/mm/migrate.c index b7fa020003f3..6aa752984f32 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -251,7 +251,7 @@ static bool remove_migration_pte(struct folio *folio, rmap_flags); else page_dup_file_rmap(new, true); - set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte); + set_huge_pte_at(vma, pvmw.address, pvmw.pte, pte); } else #endif { diff --git a/mm/rmap.c b/mm/rmap.c index ec7f8e6c9e48..a6353a0c67e8 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1628,7 +1628,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { hugetlb_count_sub(folio_nr_pages(folio), mm); - set_huge_pte_at(mm, address, pvmw.pte, pteval); + set_huge_pte_at(vma, address, pvmw.pte, pteval); } else { dec_mm_counter(mm, mm_counter(&folio->page)); set_pte_at(mm, address, pvmw.pte, pteval); @@ -2020,7 +2020,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { hugetlb_count_sub(folio_nr_pages(folio), mm); - set_huge_pte_at(mm, address, pvmw.pte, pteval); + set_huge_pte_at(vma, address, pvmw.pte, pteval); } else { dec_mm_counter(mm, mm_counter(&folio->page)); set_pte_at(mm, address, pvmw.pte, pteval); @@ -2044,7 +2044,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, if (arch_unmap_one(mm, vma, address, pteval) < 0) { if (folio_test_hugetlb(folio)) - set_huge_pte_at(mm, address, pvmw.pte, pteval); + set_huge_pte_at(vma, address, pvmw.pte, pteval); else set_pte_at(mm, address, pvmw.pte, pteval); ret = false; @@ -2058,7 +2058,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, if (anon_exclusive && page_try_share_anon_rmap(subpage)) { if (folio_test_hugetlb(folio)) - set_huge_pte_at(mm, address, pvmw.pte, pteval); + set_huge_pte_at(vma, address, pvmw.pte, pteval); else set_pte_at(mm, address, pvmw.pte, pteval); ret = false; @@ -2090,7 +2090,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, if (pte_uffd_wp(pteval)) swp_pte = pte_swp_mkuffd_wp(swp_pte); if (folio_test_hugetlb(folio)) - set_huge_pte_at(mm, address, pvmw.pte, swp_pte); + set_huge_pte_at(vma, address, pvmw.pte, swp_pte); else set_pte_at(mm, address, pvmw.pte, swp_pte); trace_set_migration_pte(address, pte_val(swp_pte), diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ef8599d394fd..10fa40222f30 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -94,6 +94,9 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot, unsigned int max_page_shift, pgtbl_mod_mask *mask) { +#ifdef CONFIG_HUGETLB_PAGE + struct vm_area_struct vma = TLB_FLUSH_VMA(&init_mm, 0); +#endif pte_t *pte; u64 pfn; unsigned long size = PAGE_SIZE; @@ -111,7 +114,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pte_t entry = pfn_pte(pfn, prot); entry = arch_make_huge_pte(entry, ilog2(size), 0); - set_huge_pte_at(&init_mm, addr, pte, entry); + set_huge_pte_at(&vma, addr, pte, entry); pfn += PFN_DOWN(size); continue; } From patchwork Thu Sep 21 16:20:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A8DCE71090 for ; Thu, 21 Sep 2023 16:20:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAFA76B020C; Thu, 21 Sep 2023 12:20:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5F9A6B020D; Thu, 21 Sep 2023 12:20:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B27CF6B020F; Thu, 21 Sep 2023 12:20:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A0B0D6B020C for ; Thu, 21 Sep 2023 12:20:58 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 79D261A0381 for ; Thu, 21 Sep 2023 16:20:58 +0000 (UTC) X-FDA: 81261118596.18.A30B72B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id B9D1C40015 for ; Thu, 21 Sep 2023 16:20:56 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313256; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uDoY3OFCzCUrgBPULkVVbTB1+G/+iNF7LD/wFw9wqJU=; b=62wX4oblB05AOI+Oecm2B9zAvFtTqzVziaECoJK1FkToEZqvgh6Xg6n5SHbvq2KtDOE3jS D2ebMoN2ZftyORoa8U/i/wERBfvZYc1NjH7Ig6eKW9q2MmBHkuafhZ6Myljq4B9HwudH+x BCv8scBI6m1u5ImenVDFjF9yOTERFB8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313256; a=rsa-sha256; cv=none; b=P3nFiZJ0K9qYkeSUtM65DdqXVAbzaNGwmFPr0tUbiOYwZQYd5UI0cdjTf7oUolAcfhPtIf z+l330Ad1cjXoMWnvDMbApAkADeXthtnuiXofhmCryI2R2MQ2vM1rdsy//mhqLcTtEv0Ir c8n6hk2fh+L4+ay/44RFHWwcJi3tY8k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 177461763; Thu, 21 Sep 2023 09:21:33 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A068D3F59C; Thu, 21 Sep 2023 09:20:51 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 7/8] arm64: hugetlb: Convert set_huge_pte_at() to take vma Date: Thu, 21 Sep 2023 17:20:06 +0100 Message-Id: <20230921162007.1630149-8-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B9D1C40015 X-Rspam-User: X-Stat-Signature: r17azot87tru1nw9cfhs8mhfsan784y3 X-Rspamd-Server: rspam03 X-HE-Tag: 1695313256-432047 X-HE-Meta: U2FsdGVkX1+FT2HgpZWZgCV99T/JFnz2jAiMnkejCqE2Xf+cvmiJ/5+UDgzho/0XJSS5CeQsKpr2Ef6+0Dplv2Vp0ouu4DgykaVZ2+wMeNO+Tv13w101cpam/S5FKO30+jbVZGhwLgEvHV2jzWfGPzxWosSeqC0ey7KqqzsgobQ/T9Fmd8K0kuB5+sM8f4bKE2pYuxuHEhw8xKeY5kWprbaaHaUEgK24yaCJdN3WNbTsdbzZNYgUP0MXzB3TnS+7eB0S8n6cpneuIouKoXWGyPfdcCUynYlclWYFhV9HJPc8uPDkzDhGTOYDW+k83QcoTHh2tcrVM33Ssd+9tJ+GtsTIkLVLPDv5YEKKCkgRg2AI1gP3IlDfOLaTm8tuezJkf7jTc/xsHQcR0taCQh83366rSt0nIYcv2Pf54QGprOt7owHS7Z0bNtglpSRu10eixkcnWxAv20dyKQmvQbjctb0w2+4e7rZ7RcPhJTtkx6S7Gyd833qY30xyp8oP5mYjUkWejX1w/TMBMd44yCC48OUacSycjfdOLgXEFqR6Br2A/HnHSqf3w4lK2thZVYjG304/atUD2YDr5Hlmef2tauMS4ofTiSj1MWp25Ej4FhHqO6u7oAFg3NG/pkHMqKxVcMSRpgZKKg9thdKy5UcGQTvlcii+zqP5Earzma7EivmgszQZ5EFW881aqJRkNJKS3eQdOKn0wuqhUWqzVv3hZJmLvZFDJYr1x9DqbGaPSYX5C1QQmwREuK0xX4s2COC8dk9XwYL2h7lbAmPXuuFhNbvemLgoD4d/T86zTRSCDx3/GQ/g64OqwKJHuXxYPQu4D5WIZAwALtqWJKdyrzzdxXi0FD5K+vDqWzf56/1VS7Xkpbctcz4oBlWEdEu0qzbel4Tlz62IAY3c2Z1AmD8nLILIBJ5kBp5QsH4MDo6+48c+/r7G2tPvJ5mwK0qNjapoh9Z1+kVY1h1HYpgR5ho ybEo4+P6 dymrgFl10v4N/CXgM1cMtBqsXqp5gZv23w39d1jRfPrNnz1vZ7qAl6kdCXiW08sEnnDwKX2JndWC3h9Rr355sCB/e447z3oNu3kijfv9PGhp7CEutvYrfgn6SZyghMfPkTdPH8qUZIfXdUcfLXPYzAgQwdYB+XeRdbOIpAWyLkSx+7iYmsKluWUx4PQ00RdDa4BPLsQDZ8V1Acsc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to fix a bug, arm64 needs access to the vma inside it's implementation of set_huge_pte_at(). Provide for this by converting the mm parameter to be a vma. Any implementations that require the mm can access it via vma->vm_mm. This commit makes the required arm64 modifications. Separate commits update the other arches and core code, before the actual bug is fixed in arm64. No behavioral changes intended. Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/hugetlb.h | 2 +- arch/arm64/mm/hugetlbpage.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index f43a38ac1779..efc9025b9d27 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -27,7 +27,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags); #define arch_make_huge_pte arch_make_huge_pte #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +extern void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte); #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 9c52718ea750..844832511c1e 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -248,9 +248,10 @@ static inline struct folio *hugetlb_swap_entry_to_folio(swp_entry_t entry) return page_folio(pfn_to_page(swp_offset_pfn(entry))); } -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, +void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) { + struct mm_struct *mm = vma->vm_mm; size_t pgsize; int i; int ncontig; @@ -571,5 +572,5 @@ pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t old_pte, pte_t pte) { - set_huge_pte_at(vma->vm_mm, addr, ptep, pte); + set_huge_pte_at(vma, addr, ptep, pte); } From patchwork Thu Sep 21 16:20:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13394013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F244BE71090 for ; Thu, 21 Sep 2023 16:21:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86A206B0246; Thu, 21 Sep 2023 12:21:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 842516B020F; Thu, 21 Sep 2023 12:21:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 708E16B0246; Thu, 21 Sep 2023 12:21:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6022B6B020D for ; Thu, 21 Sep 2023 12:21:03 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2609AA059B for ; Thu, 21 Sep 2023 16:21:03 +0000 (UTC) X-FDA: 81261118806.04.8580344 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 567E920022 for ; Thu, 21 Sep 2023 16:21:01 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695313261; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NfUxN4bvi8i9D4AKXzSQb1pdt1stW1rn/rlDRpXWERQ=; b=GjGsfmnmyPynWh5hGkFnyLSocJzDsvjYATSmd0723pzanCykI5kHIE70riJEPT2VMGDtbl LMbFE+YGhdHORGNbJo0OfnFAxjCl96pJ6z4bEnucsJ/7BqV30xkpMJVtgBX/onEL9DPb1D vaAYc0r6pWB+yzWSJFmUUBAyfS6seF0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695313261; a=rsa-sha256; cv=none; b=KE1kV33kUNlNwEXFSVY8CvbUDa0DXPkLn+TN3i59laOQnREsFgD4VLTjxqeIX0/CmL4kkZ rdHtLqol0ULXP4/m1Qr0wBB4ywEJnsAMqpFi7CKDkbPEL1U3YMTTk13cTXgviBJWCR/y1W 0fETpMiIo6mnfhHh5qALMZmJMCAWrbo= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 911D21764; Thu, 21 Sep 2023 09:21:37 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 26AFE3F59C; Thu, 21 Sep 2023 09:20:56 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , "James E.J. Bottomley" , Helge Deller , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Arnd Bergmann , Mike Kravetz , Muchun Song , SeongJae Park , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Anshuman Khandual , Peter Xu , Axel Rasmussen , Qi Zheng Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v1 8/8] arm64: hugetlb: Fix set_huge_pte_at() to work with all swap entries Date: Thu, 21 Sep 2023 17:20:07 +0100 Message-Id: <20230921162007.1630149-9-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921162007.1630149-1-ryan.roberts@arm.com> References: <20230921162007.1630149-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 567E920022 X-Stat-Signature: 9cnb4yeb3banriqumtz1onw9ar8akke7 X-Rspam-User: X-HE-Tag: 1695313261-429507 X-HE-Meta: U2FsdGVkX1/RfoUtnO7RB+qPq/X+YQwcQMw6eD4TU2mKdC+nX04s+UZGwF9VbXFzenks/mPPuKk95WTYqOB/Cdp5XmeoE4lWQkMPq4Plmji0zDqmCGay+nwJiXm3VRdKtTgqFrCwja5D7FzuX1opUe1S3dEQNw0yFcZTcU3Yhl7IdWk61vrKb+IW8GYtwIehHInwftsSdkU22yU1Hbd8tfY7+CvuCDLn+SsXGFFJIt34UmlbDYexq1OCuyuh4gaR8FMtWakGvv7ZUVpZHxZSuXy0u3E3FOv+YHT1Au+4hHE1ek4F4jmI9Ea7wLKHSzw7sFLNcpJthEpUX9GPyJlLT68IXSj7eoLIfSEUJCbaGbt5mlI1x18DlIIPyNg/ulZ/vIW0M9DKY6taBBFCvxEZ7vS7rXUz1KziaNzVQkASKu+LXCb7QLipj+V4PqMkJssjCZEQvASbi/2uydODA2wqoNWUgfroq1CQbZxgTHm1t9WC4WBZJLP+RP2Sp1FtuPQexD9wmo4XhU8EL3PhZCmTx9LIlZt9hLP1Lda3dbZa9cOPSML8VEnr2xnf9Fd9U132ykT2y1AMusm53dllNP+1+tsIkViJ5whKb1wc8wi1vMuzfu0HiMCLyvB1Hrrzs4tSRdlcFFMNPuFRSx/B87CkvGHnBA466vZpCopr+vICoku6GF4uc7TLGgCmlTAaZ/ORX1G3v2QNKg65BXC4tJY4J2GOpf3oIYhAJ02NcPzYozQEYWK0G+eRepwiwT9yfbZSsodeYa//buxCva5q03huoUUh8CFOQqxvND4hVTomcJ3kAELFePQMObHWb+ujdZ01/8VE9HTdxLWOgNSwuyVTMXToLlaSNOjGCxdaSbcVxwDcbyS6Qm0ZSypApQNoskpdfVZDhbCmSupReylvhYaLbGntI0c7pF2Y7FQo8GUmb6buDHJ2fHO8X7GfrdCHTeyZN1hvItnkF6Smf/NixVE FWmUfYyZ /8ElendTJi2gWja1dc0Wxm835jHXDaySiN2D7dv4S50eojl44x2GwJR/Nq8O2bzYmByIq9cPIy80Zrjd3fzrquI2r/UoaXzBlLtT9D98ScrVaEH91YH9lDyrL6KI//8GkiHb/cg+H6BSWq8YDOHgNUoX5/VVXD7txjPnmi7wsw3g5w+at2LPwKe0i7CxTTxyqIJJG2XIub7if8PE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When called with a swap entry that does not embed a PFN (e.g. PTE_MARKER_POISONED or PTE_MARKER_UFFD_WP), the previous implementation of set_huge_pte_at() would either cause a BUG() to fire (if CONFIG_DEBUG_VM is enabled) or cause a dereference of an invalid address and subsequent panic. arm64's huge pte implementation supports multiple huge page sizes, some of which are implemented in the page table with contiguous mappings. So set_huge_pte_at() needs to work out how big the logical pte is, so that it can also work out how many physical ptes (or pmds) need to be written. It does this by grabbing the folio out of the pte and querying its size. However, there are cases when the pte being set is actually a swap entry. But this also used to work fine, because for huge ptes, we only ever saw migration entries and hwpoison entries. And both of these types of swap entries have a PFN embedded, so the code would grab that and everything still worked out. But over time, more calls to set_huge_pte_at() have been added that set swap entry types that do not embed a PFN. And this causes the code to go bang. The triggering case is for the uffd poison test, commit 99aa77215ad0 ("selftests/mm: add uffd unit test for UFFDIO_POISON"), which sets a PTE_MARKER_POISONED swap entry. But review shows there are other places too (PTE_MARKER_UFFD_WP). So the root cause is due to commit 18f3962953e4 ("mm: hugetlb: kill set_huge_swap_pte_at()"), which aimed to simplify the interface to the core code by removing set_huge_swap_pte_at() (which took a page size parameter) and replacing it with calls to set_huge_swap_pte_at() where the size was inferred from the folio, as descibed above. While that commit didn't break anything at the time, it did break the interface because it couldn't handle swap entries without PFNs. And since then new callers have come along which rely on this working. Now that we have modified the set_huge_pte_at() interface to pass the vma, we can extract the huge page size from it and fix this issue. I'm tagging the commit that added the uffd poison feature, since that is what exposed the problem, as well as the original change that broke the interface. Hopefully this is valuable for people doing bisect. Signed-off-by: Ryan Roberts Fixes: 18f3962953e4 ("mm: hugetlb: kill set_huge_swap_pte_at()") Fixes: 8a13897fb0da ("mm: userfaultfd: support UFFDIO_POISON for hugetlbfs") --- arch/arm64/mm/hugetlbpage.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 844832511c1e..a08601a14689 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -241,13 +241,6 @@ static void clear_flush(struct mm_struct *mm, flush_tlb_range(&vma, saddr, addr); } -static inline struct folio *hugetlb_swap_entry_to_folio(swp_entry_t entry) -{ - VM_BUG_ON(!is_migration_entry(entry) && !is_hwpoison_entry(entry)); - - return page_folio(pfn_to_page(swp_offset_pfn(entry))); -} - void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) { @@ -258,13 +251,10 @@ void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn, dpfn; pgprot_t hugeprot; - if (!pte_present(pte)) { - struct folio *folio; - - folio = hugetlb_swap_entry_to_folio(pte_to_swp_entry(pte)); - ncontig = num_contig_ptes(folio_size(folio), &pgsize); + ncontig = num_contig_ptes(huge_page_size(hstate_vma(vma)), &pgsize); - for (i = 0; i < ncontig; i++, ptep++) + if (!pte_present(pte)) { + for (i = 0; i < ncontig; i++, ptep++, addr += pgsize) set_pte_at(mm, addr, ptep, pte); return; } @@ -274,7 +264,6 @@ void set_huge_pte_at(struct vm_area_struct *vma, unsigned long addr, return; } - ncontig = find_num_contig(mm, addr, ptep, &pgsize); pfn = pte_pfn(pte); dpfn = pgsize >> PAGE_SHIFT; hugeprot = pte_pgprot(pte);