From patchwork Mon Feb 26 12:03:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13572036 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 E3C6DC54E4A for ; Mon, 26 Feb 2024 12:03:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2253894002C; Mon, 26 Feb 2024 07:03:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D466440147; Mon, 26 Feb 2024 07:03:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09BC694002F; Mon, 26 Feb 2024 07:03:36 -0500 (EST) 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 EE33394002C for ; Mon, 26 Feb 2024 07:03:35 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 47F5BC08A4 for ; Mon, 26 Feb 2024 12:03:35 +0000 (UTC) X-FDA: 81833820390.22.C4B905D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id AE83F12001A for ; Mon, 26 Feb 2024 12:03:33 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.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=1708949013; 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=ybjrp8rX3TGU6X+DN+R2cZPMTNdzgOnRSM6yDztGhH0=; b=k8A8R4kZdePeqrnFD+HENuFSlXwoJSN53zg8f+6TSKOPJBOU4GPwUhbyWyegtmZ4pt+kYb 279yw5CVIwxuSIKcgldmjIzp4ZRFmPt05DyqhC+4aiSsWxTp740oaZ03GUH7Co0lPeOWdH 5pSM0OHlO3fcw0k5g8XIeQkmfhgiUkI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf29.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=1708949013; a=rsa-sha256; cv=none; b=g3N5FPgj8Zv4syAAc9rurCEJy7UfTRZgXsOoXvrkEnOvy0At41iAXVQ+evf+kD1cjq/+Iu t94BvJffWRSCPfRrOqJOIVHzRdb6Z3HIoslzoVl7QtegOHmPSVpxUUt/UdYKBGMLEAq55S 33+MiBrHItW8bk7rcAbsCz0w5j+nx0c= 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 72F411424; Mon, 26 Feb 2024 04:04:11 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C79383F73F; Mon, 26 Feb 2024 04:03:31 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Catalin Marinas , Mark Rutland , John Hubbard Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH 1/2] arm64/mm: Export contpte symbols only to GPL users Date: Mon, 26 Feb 2024 12:03:20 +0000 Message-Id: <20240226120321.1055731-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240226120321.1055731-1-ryan.roberts@arm.com> References: <20240226120321.1055731-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AE83F12001A X-Stat-Signature: hy3yn6xqhzazs7ytad1ghsxzbr5f5a5n X-HE-Tag: 1708949013-777171 X-HE-Meta: U2FsdGVkX1/1p0EYIveIMZXRax6lx/mO29tmRBbZ8w9BcOjgns1FPLiip3gP39Uzm+PA05U6zomdNouuAoV6SLxbOfGBqbIN+c+BPMK/E+AiUSmlyEfFmPy8gsGKi17Sc6E2OUg24eLZkmJLehpgJouurmsKdU4oGkCp4PGC/p2hNAn/qNMutf7rxea7lLHNcijLqz+aBCpkploidRj2FuLSjj3Z0BRQjjINJp3NVmrD8Jy9+woOn00HufGsiUSYbmL5D+NOV9Ner+AiE22HUVdu1YVGW8ZxkWdYY1K9AW4hg70n4tJYv0GEVDCZbZ0KIb2/P06e46lH+/1FCvDAjB33cnfcJOfanRQZjHZcPHpwJNOVUlJKGsXGJLfx668FagKymKzHc/ZSEJ8+FzZfXQUQpz0PkP7LFAeGTN2jN9G9oE9UqJHmnBlImfxtGObLeAQ9YncXx5H+bGFovmci7ep5RgrB+8Hx6Ddr0OR2g0gGIywtnejpnBbEbKqjuvkraAgesKDZguiFTrU6oK+L68Idd7xtpO0SpXL/jtwVthccMsR2OdPxon1dmkeFRZjxRbob0YkaFGAo7+YAX6ujApkf5fyn/MNydBPSk4SPeLZ6RA3qIsgXIFdvk1A6JXmm6woSQmVY7gzHzUkO5hfmex8TuwwPS/sCgqIadMo8oo0fAebf+8/p0dPy0AyMKQ33terBz39EKiSuwO1aw3U1ovdJcgjQsA9QCSDvzvoTKr33XDKiLgk2FsGVhbNQfHkTLvqCfnzFrsfUxyqQ4TYR3DxjtBu9s3f5u1n+3uKcd3rAgOd+HvwSKUxY1U/SRSy/99k0ruy7lsHqj+qAXzBtrVGZzp5MhhLa 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: List-Subscribe: List-Unsubscribe: The contpte symbols must be exported since some of the public inline ptep_* APIs are called from modules and these inlines now call the contpte functions. Originally they were exported as EXPORT_SYMBOL() for fear of breaking out-of-tree modules. But we subsequently concluded that EXPORT_SYMBOL_GPL() should be safe since these functions are deeply core mm routines, and any module operating at this level is not going to be able to survive on EXPORT_SYMBOL alone. Link: https://lore.kernel.org/linux-mm/f9fc2b31-11cb-4969-8961-9c89fea41b74@nvidia.com/ Signed-off-by: Ryan Roberts Acked-by: David Hildenbrand Reviewed-by: John Hubbard Acked-by: Catalin Marinas --- arch/arm64/mm/contpte.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c index 16788f07716d..be0a226c4ff9 100644 --- a/arch/arm64/mm/contpte.c +++ b/arch/arm64/mm/contpte.c @@ -135,7 +135,7 @@ void __contpte_try_fold(struct mm_struct *mm, unsigned long addr, pte = pte_mkcont(pte); contpte_convert(mm, addr, orig_ptep, pte); } -EXPORT_SYMBOL(__contpte_try_fold); +EXPORT_SYMBOL_GPL(__contpte_try_fold); void __contpte_try_unfold(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) @@ -150,7 +150,7 @@ void __contpte_try_unfold(struct mm_struct *mm, unsigned long addr, pte = pte_mknoncont(pte); contpte_convert(mm, addr, ptep, pte); } -EXPORT_SYMBOL(__contpte_try_unfold); +EXPORT_SYMBOL_GPL(__contpte_try_unfold); pte_t contpte_ptep_get(pte_t *ptep, pte_t orig_pte) { @@ -178,7 +178,7 @@ pte_t contpte_ptep_get(pte_t *ptep, pte_t orig_pte) return orig_pte; } -EXPORT_SYMBOL(contpte_ptep_get); +EXPORT_SYMBOL_GPL(contpte_ptep_get); pte_t contpte_ptep_get_lockless(pte_t *orig_ptep) { @@ -231,7 +231,7 @@ pte_t contpte_ptep_get_lockless(pte_t *orig_ptep) return orig_pte; } -EXPORT_SYMBOL(contpte_ptep_get_lockless); +EXPORT_SYMBOL_GPL(contpte_ptep_get_lockless); void contpte_set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte, unsigned int nr) @@ -274,7 +274,7 @@ void contpte_set_ptes(struct mm_struct *mm, unsigned long addr, } while (addr != end); } -EXPORT_SYMBOL(contpte_set_ptes); +EXPORT_SYMBOL_GPL(contpte_set_ptes); void contpte_clear_full_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned int nr, int full) @@ -282,7 +282,7 @@ void contpte_clear_full_ptes(struct mm_struct *mm, unsigned long addr, contpte_try_unfold_partial(mm, addr, ptep, nr); __clear_full_ptes(mm, addr, ptep, nr, full); } -EXPORT_SYMBOL(contpte_clear_full_ptes); +EXPORT_SYMBOL_GPL(contpte_clear_full_ptes); pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, @@ -291,7 +291,7 @@ pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm, contpte_try_unfold_partial(mm, addr, ptep, nr); return __get_and_clear_full_ptes(mm, addr, ptep, nr, full); } -EXPORT_SYMBOL(contpte_get_and_clear_full_ptes); +EXPORT_SYMBOL_GPL(contpte_get_and_clear_full_ptes); int contpte_ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) @@ -316,7 +316,7 @@ int contpte_ptep_test_and_clear_young(struct vm_area_struct *vma, return young; } -EXPORT_SYMBOL(contpte_ptep_test_and_clear_young); +EXPORT_SYMBOL_GPL(contpte_ptep_test_and_clear_young); int contpte_ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) @@ -337,7 +337,7 @@ int contpte_ptep_clear_flush_young(struct vm_area_struct *vma, return young; } -EXPORT_SYMBOL(contpte_ptep_clear_flush_young); +EXPORT_SYMBOL_GPL(contpte_ptep_clear_flush_young); void contpte_wrprotect_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned int nr) @@ -355,7 +355,7 @@ void contpte_wrprotect_ptes(struct mm_struct *mm, unsigned long addr, contpte_try_unfold_partial(mm, addr, ptep, nr); __wrprotect_ptes(mm, addr, ptep, nr); } -EXPORT_SYMBOL(contpte_wrprotect_ptes); +EXPORT_SYMBOL_GPL(contpte_wrprotect_ptes); int contpte_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, @@ -401,4 +401,4 @@ int contpte_ptep_set_access_flags(struct vm_area_struct *vma, return 1; } -EXPORT_SYMBOL(contpte_ptep_set_access_flags); +EXPORT_SYMBOL_GPL(contpte_ptep_set_access_flags); From patchwork Mon Feb 26 12:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13572037 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 5075FC48BF6 for ; Mon, 26 Feb 2024 12:03:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A55E440149; Mon, 26 Feb 2024 07:03:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55802440147; Mon, 26 Feb 2024 07:03:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A928440149; Mon, 26 Feb 2024 07:03:37 -0500 (EST) 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 213C7440147 for ; Mon, 26 Feb 2024 07:03:37 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EE51A80845 for ; Mon, 26 Feb 2024 12:03:36 +0000 (UTC) X-FDA: 81833820432.30.FA4E7EE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf27.hostedemail.com (Postfix) with ESMTP id 20A3E4002C for ; Mon, 26 Feb 2024 12:03:34 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.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=1708949015; 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=OdjdwRQXLMVJTKYMYLLNlR+fATmBCiXp0EKc+ys3wm0=; b=rq6JV0hm1Fdq51H0ByGGs59dpENtfT/MNh+clihLTDt3v3lnegj1cbCGAFSZfUHKP1c/8Y vSB7UBTjdF/9LJO2V3hQo76j++WJCep8fZw/3eaLXWFc/8VzXgFtq4PBebff7EXlU2UYn+ G89WX6g25NQGJfuVN/RvHOYwWdD4DtU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.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=1708949015; a=rsa-sha256; cv=none; b=tz044Zc5kGlz55u+lCQZBPByYijOQf142NzC7ZbGi9WIGYSY9VbnTSumQ5tMZHqqIfnmNu U+MnLIlNuuyeijSDUyFvC4bYA66dhAWs90Q4DUM/cPA/6RUxhI7yKcYqjhK1bLhZRYAo0x Ya8551deFtPvP+GdE+7OfGGvQ+Ot0Tw= 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 A7EFF1042; Mon, 26 Feb 2024 04:04:12 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 081DC3F7C5; Mon, 26 Feb 2024 04:03:32 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Catalin Marinas , Mark Rutland , John Hubbard Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH 2/2] arm64/mm: Improve comment in contpte_ptep_get_lockless() Date: Mon, 26 Feb 2024 12:03:21 +0000 Message-Id: <20240226120321.1055731-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240226120321.1055731-1-ryan.roberts@arm.com> References: <20240226120321.1055731-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: sp9isbqk57hhzx1yt3fsx3ox9gyqbsmx X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 20A3E4002C X-HE-Tag: 1708949014-968537 X-HE-Meta: U2FsdGVkX18gDMxQM/iuQGrxVvlAGdre9U1GqDUWquJZyUN+TOW3kWWc4q1e3vdcB02CIdW9XSyYC7AF1USHn3TGYyeHjAA15735h9jTylmqUmQfvQfbTJtitVZ4fosQnDF4rafzl40FycQ+nj8mENzQDApt7fYdR2Kdc1bPmEojZ60Ooe2Oa1uJ1XuBzsBG0KIsrb2fy3ioqCKV9CPbJ7jWm9hNYqP0vEDpw+t3ukxTcNzZR5poPhFdumZkgeWxQaPw74zhwnjKDuZxZU3SYWp8omRUI6OLytVYW0BUxe03w6QRosXHX2piUJ0KXLFBJYGixWLx/xs8084S/aWmnOH9B/oTEP7n5qdZ3KcEqVyGwG/R4f7OM/vhotOyjO4lj5EWD7fBH18smeFWx1rTLLKGYCpxqoxnqRgrNayKUwjgGN+WBAVl6H8j9EK5NXd+1Hf0/37jSQQAAgdPuwKH8P2IQhZAq/+tcD5q87l983r+09umGjvKcbjFg72q/GjHoeMRTxcE05Eg9yhDQVtu+dMProy1yZ7wKzwImiQcStPJj2FAuoK6qYbjwRC7g2c6CfGFxY/2tn0+OaeWYfHjg9R35hUi0rHWUEWdoTEhQCBZ6DJnfPD72E/2U8NpcHJyFFb5jbDxGSer+SzgsNE661ZDt59MuomG3oOaMSJbTvetpltYXBI+zRGXkGV2QWeMupB7S/ZvZ55AdQjwZt/m2D08zAHVNMemMlaogpluxtdxyWwQSr1bPsqULY1/pXlunZByuVXCdpSsf363x81mL8kOYUICsH9FMraraALv3HWja3FM6TQ9oW3hL0PTymWjgHL98w7k56m9Hvh2IhjG0M9oThxuJcyKdXugsiCI/5QSiPCIyCv0Sz9de2Gm6UqB/jLM/QhwGfw= 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: List-Subscribe: List-Unsubscribe: Make clear the atmicity/consistency requirements of the API and how we achieve them. Link: https://lore.kernel.org/linux-mm/Zc-Tqqfksho3BHmU@arm.com/ Signed-off-by: Ryan Roberts Reviewed-by: David Hildenbrand Reviewed-by: Catalin Marinas --- arch/arm64/mm/contpte.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c index be0a226c4ff9..1b64b4c3f8bf 100644 --- a/arch/arm64/mm/contpte.c +++ b/arch/arm64/mm/contpte.c @@ -183,16 +183,20 @@ EXPORT_SYMBOL_GPL(contpte_ptep_get); pte_t contpte_ptep_get_lockless(pte_t *orig_ptep) { /* - * Gather access/dirty bits, which may be populated in any of the ptes - * of the contig range. We may not be holding the PTL, so any contiguous - * range may be unfolded/modified/refolded under our feet. Therefore we - * ensure we read a _consistent_ contpte range by checking that all ptes - * in the range are valid and have CONT_PTE set, that all pfns are - * contiguous and that all pgprots are the same (ignoring access/dirty). - * If we find a pte that is not consistent, then we must be racing with - * an update so start again. If the target pte does not have CONT_PTE - * set then that is considered consistent on its own because it is not - * part of a contpte range. + * The ptep_get_lockless() API requires us to read and return *orig_ptep + * so that it is self-consistent, without the PTL held, so we may be + * racing with other threads modifying the pte. Usually a READ_ONCE() + * would suffice, but for the contpte case, we also need to gather the + * access and dirty bits from across all ptes in the contiguous block, + * and we can't read all of those neighbouring ptes atomically, so any + * contiguous range may be unfolded/modified/refolded under our feet. + * Therefore we ensure we read a _consistent_ contpte range by checking + * that all ptes in the range are valid and have CONT_PTE set, that all + * pfns are contiguous and that all pgprots are the same (ignoring + * access/dirty). If we find a pte that is not consistent, then we must + * be racing with an update so start again. If the target pte does not + * have CONT_PTE set then that is considered consistent on its own + * because it is not part of a contpte range. */ pgprot_t orig_prot;