All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Huckleberry <nhuck@google.com>
To: catalin.marinas@arm.com, will@kernel.org
Cc: clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Nathan Huckleberry <nhuck@google.com>
Subject: [PATCH v2] arm64: mm: Fix dead assignment of old_pte
Date: Tue,  2 Jul 2019 16:41:35 -0700	[thread overview]
Message-ID: <20190702234135.78780-1-nhuck@google.com> (raw)
In-Reply-To: <CAJkfWY4yvVVmJoQ0WwyoFBkWYsUJnnQPNU+-g23-m-L3ETe_hQ@mail.gmail.com>

When analyzed with the clang static analyzer the
following warning occurs

line 251, column 2
Value stored to 'old_pte' is never read

This warning is repeated every time pgtable.h is
included by another file and produces ~3500
extra warnings.

Moving old_pte into preprocessor guard.

Cc: clang-built-linux@googlegroups.com
Signed-off-by: Nathan Huckleberry <nhuck@google.com>
---
Changes from v1 -> v2
* Added scope to avoid [-Wdeclaration-after-statement]
 arch/arm64/include/asm/pgtable.h | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index fca26759081a..12b7f08db40d 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -238,8 +238,6 @@ extern void __sync_icache_dcache(pte_t pteval);
 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
 			      pte_t *ptep, pte_t pte)
 {
-	pte_t old_pte;
-
 	if (pte_present(pte) && pte_user_exec(pte) && !pte_special(pte))
 		__sync_icache_dcache(pte);
 
@@ -248,16 +246,23 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
 	 * hardware updates of the pte (ptep_set_access_flags safely changes
 	 * valid ptes without going through an invalid entry).
 	 */
-	old_pte = READ_ONCE(*ptep);
-	if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(old_pte) && pte_valid(pte) &&
-	   (mm == current->active_mm || atomic_read(&mm->mm_users) > 1)) {
-		VM_WARN_ONCE(!pte_young(pte),
-			     "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
-			     __func__, pte_val(old_pte), pte_val(pte));
-		VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
-			     "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
-			     __func__, pte_val(old_pte), pte_val(pte));
+	#if IS_ENABLED(CONFIG_DEBUG_VM)
+	{
+		pte_t old_pte;
+
+		old_pte = READ_ONCE(*ptep);
+		if (pte_valid(old_pte) && pte_valid(pte) &&
+		  (mm == current->active_mm ||
+		   atomic_read(&mm->mm_users) > 1)) {
+			VM_WARN_ONCE(!pte_young(pte),
+				     "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
+				     __func__, pte_val(old_pte), pte_val(pte));
+			VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
+				     "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
+				     __func__, pte_val(old_pte), pte_val(pte));
+		}
 	}
+	#endif
 
 	set_pte(ptep, pte);
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Huckleberry <nhuck@google.com>
To: catalin.marinas@arm.com, will@kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com,
	Nathan Huckleberry <nhuck@google.com>
Subject: [PATCH v2] arm64: mm: Fix dead assignment of old_pte
Date: Tue,  2 Jul 2019 16:41:35 -0700	[thread overview]
Message-ID: <20190702234135.78780-1-nhuck@google.com> (raw)
In-Reply-To: <CAJkfWY4yvVVmJoQ0WwyoFBkWYsUJnnQPNU+-g23-m-L3ETe_hQ@mail.gmail.com>

When analyzed with the clang static analyzer the
following warning occurs

line 251, column 2
Value stored to 'old_pte' is never read

This warning is repeated every time pgtable.h is
included by another file and produces ~3500
extra warnings.

Moving old_pte into preprocessor guard.

Cc: clang-built-linux@googlegroups.com
Signed-off-by: Nathan Huckleberry <nhuck@google.com>
---
Changes from v1 -> v2
* Added scope to avoid [-Wdeclaration-after-statement]
 arch/arm64/include/asm/pgtable.h | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index fca26759081a..12b7f08db40d 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -238,8 +238,6 @@ extern void __sync_icache_dcache(pte_t pteval);
 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
 			      pte_t *ptep, pte_t pte)
 {
-	pte_t old_pte;
-
 	if (pte_present(pte) && pte_user_exec(pte) && !pte_special(pte))
 		__sync_icache_dcache(pte);
 
@@ -248,16 +246,23 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
 	 * hardware updates of the pte (ptep_set_access_flags safely changes
 	 * valid ptes without going through an invalid entry).
 	 */
-	old_pte = READ_ONCE(*ptep);
-	if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(old_pte) && pte_valid(pte) &&
-	   (mm == current->active_mm || atomic_read(&mm->mm_users) > 1)) {
-		VM_WARN_ONCE(!pte_young(pte),
-			     "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
-			     __func__, pte_val(old_pte), pte_val(pte));
-		VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
-			     "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
-			     __func__, pte_val(old_pte), pte_val(pte));
+	#if IS_ENABLED(CONFIG_DEBUG_VM)
+	{
+		pte_t old_pte;
+
+		old_pte = READ_ONCE(*ptep);
+		if (pte_valid(old_pte) && pte_valid(pte) &&
+		  (mm == current->active_mm ||
+		   atomic_read(&mm->mm_users) > 1)) {
+			VM_WARN_ONCE(!pte_young(pte),
+				     "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
+				     __func__, pte_val(old_pte), pte_val(pte));
+			VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
+				     "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
+				     __func__, pte_val(old_pte), pte_val(pte));
+		}
 	}
+	#endif
 
 	set_pte(ptep, pte);
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


  reply	other threads:[~2019-07-02 23:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-02 23:13 [PATCH] arm64: mm: Fix dead assignment of old_pte Nathan Huckleberry
2019-07-02 23:13 ` Nathan Huckleberry
2019-07-02 23:24 ` Nathan Chancellor
2019-07-02 23:24   ` Nathan Chancellor
2019-07-02 23:26   ` Nathan Huckleberry
2019-07-02 23:26     ` Nathan Huckleberry
2019-07-02 23:41     ` Nathan Huckleberry [this message]
2019-07-02 23:41       ` [PATCH v2] " Nathan Huckleberry
2019-07-03  8:31       ` Vladimir Murzin
2019-07-03  8:31         ` Vladimir Murzin
2019-07-03  9:17       ` Will Deacon
2019-07-03  9:17         ` Will Deacon
2019-07-03 11:23       ` Mark Rutland
2019-07-03 11:23         ` Mark Rutland
2019-07-03 17:24         ` Nathan Huckleberry
2019-07-03 17:24           ` Nathan Huckleberry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190702234135.78780-1-nhuck@google.com \
    --to=nhuck@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.