linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: mm: Fix dead assignment of old_pte
@ 2019-07-02 23:13 Nathan Huckleberry
  2019-07-02 23:24 ` Nathan Chancellor
  0 siblings, 1 reply; 8+ messages in thread
From: Nathan Huckleberry @ 2019-07-02 23:13 UTC (permalink / raw)
  To: catalin.marinas, will
  Cc: clang-built-linux, linux-kernel, linux-arm-kernel, Nathan Huckleberry

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>
---
 arch/arm64/include/asm/pgtable.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index fca26759081a..42ca4fc67f27 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,8 +246,11 @@ 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).
 	 */
+	#if IS_ENABLED(CONFIG_DEBUG_VM)
+	pte_t old_pte;
+
 	old_pte = READ_ONCE(*ptep);
-	if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(old_pte) && pte_valid(pte) &&
+	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",
@@ -258,6 +259,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
 			     "%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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] arm64: mm: Fix dead assignment of old_pte
  2019-07-02 23:13 [PATCH] arm64: mm: Fix dead assignment of old_pte Nathan Huckleberry
@ 2019-07-02 23:24 ` Nathan Chancellor
  2019-07-02 23:26   ` Nathan Huckleberry
  0 siblings, 1 reply; 8+ messages in thread
From: Nathan Chancellor @ 2019-07-02 23:24 UTC (permalink / raw)
  To: Nathan Huckleberry
  Cc: catalin.marinas, will, linux-kernel, linux-arm-kernel, clang-built-linux

On Tue, Jul 02, 2019 at 04:13:02PM -0700, 'Nathan Huckleberry' via Clang Built Linux wrote:
> 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>
> ---
>  arch/arm64/include/asm/pgtable.h | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index fca26759081a..42ca4fc67f27 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,8 +246,11 @@ 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).
>  	 */
> +	#if IS_ENABLED(CONFIG_DEBUG_VM)
> +	pte_t old_pte;
> +
>  	old_pte = READ_ONCE(*ptep);
> -	if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(old_pte) && pte_valid(pte) &&
> +	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",
> @@ -258,6 +259,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
>  			     "%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
> 

Hi Nathan,

This does not apply on -next because of https://git.kernel.org/arm64/c/9b604722059039a1a3ff69fb8dfd024264046024.
I would get into the habit of testing -next to see if the warning is
present there first because someone may have independently fixed it
already (I'd be surprised if it wasn't fixed by that commit from a quick
glance).

Additionally, when I do apply this patch to mainline and build, I see
the following warning:

In file included from /home/nathan/cbl/linux/arch/arm64/kernel/asm-offsets.c:10:
In file included from /home/nathan/cbl/linux/include/linux/arm_sdei.h:14:
In file included from /home/nathan/cbl/linux/include/acpi/ghes.h:5:
In file included from /home/nathan/cbl/linux/include/acpi/apei.h:9:
In file included from /home/nathan/cbl/linux/include/linux/acpi.h:34:
In file included from /home/nathan/cbl/linux/include/acpi/acpi_io.h:5:
In file included from /home/nathan/cbl/linux/include/linux/io.h:13:
In file included from /home/nathan/cbl/linux/arch/arm64/include/asm/io.h:18:
/home/nathan/cbl/linux/arch/arm64/include/asm/pgtable.h:250:8: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
        pte_t old_pte;
              ^
1 warning generated.

Cheers,
Nathan

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] arm64: mm: Fix dead assignment of old_pte
  2019-07-02 23:24 ` Nathan Chancellor
@ 2019-07-02 23:26   ` Nathan Huckleberry
  2019-07-02 23:41     ` [PATCH v2] " Nathan Huckleberry
  0 siblings, 1 reply; 8+ messages in thread
From: Nathan Huckleberry @ 2019-07-02 23:26 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: catalin.marinas, will, linux-kernel, linux-arm-kernel, clang-built-linux

Oops I forgot moving the variable declaration would cause a warning.
Will send a V2.

Thanks,
Nathan Huckleberry

On Tue, Jul 2, 2019 at 4:25 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Tue, Jul 02, 2019 at 04:13:02PM -0700, 'Nathan Huckleberry' via Clang Built Linux wrote:
> > 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>
> > ---
> >  arch/arm64/include/asm/pgtable.h | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> > index fca26759081a..42ca4fc67f27 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,8 +246,11 @@ 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).
> >        */
> > +     #if IS_ENABLED(CONFIG_DEBUG_VM)
> > +     pte_t old_pte;
> > +
> >       old_pte = READ_ONCE(*ptep);
> > -     if (IS_ENABLED(CONFIG_DEBUG_VM) && pte_valid(old_pte) && pte_valid(pte) &&
> > +     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",
> > @@ -258,6 +259,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
> >                            "%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
> >
>
> Hi Nathan,
>
> This does not apply on -next because of https://git.kernel.org/arm64/c/9b604722059039a1a3ff69fb8dfd024264046024.
> I would get into the habit of testing -next to see if the warning is
> present there first because someone may have independently fixed it
> already (I'd be surprised if it wasn't fixed by that commit from a quick
> glance).
>
> Additionally, when I do apply this patch to mainline and build, I see
> the following warning:
>
> In file included from /home/nathan/cbl/linux/arch/arm64/kernel/asm-offsets.c:10:
> In file included from /home/nathan/cbl/linux/include/linux/arm_sdei.h:14:
> In file included from /home/nathan/cbl/linux/include/acpi/ghes.h:5:
> In file included from /home/nathan/cbl/linux/include/acpi/apei.h:9:
> In file included from /home/nathan/cbl/linux/include/linux/acpi.h:34:
> In file included from /home/nathan/cbl/linux/include/acpi/acpi_io.h:5:
> In file included from /home/nathan/cbl/linux/include/linux/io.h:13:
> In file included from /home/nathan/cbl/linux/arch/arm64/include/asm/io.h:18:
> /home/nathan/cbl/linux/arch/arm64/include/asm/pgtable.h:250:8: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
>         pte_t old_pte;
>               ^
> 1 warning generated.
>
> Cheers,
> Nathan
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20190702232459.GA14941%40archlinux-epyc.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] arm64: mm: Fix dead assignment of old_pte
  2019-07-02 23:26   ` Nathan Huckleberry
@ 2019-07-02 23:41     ` Nathan Huckleberry
  2019-07-03  8:31       ` Vladimir Murzin
                         ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Nathan Huckleberry @ 2019-07-02 23:41 UTC (permalink / raw)
  To: catalin.marinas, will
  Cc: clang-built-linux, linux-kernel, linux-arm-kernel, Nathan Huckleberry

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arm64: mm: Fix dead assignment of old_pte
  2019-07-02 23:41     ` [PATCH v2] " Nathan Huckleberry
@ 2019-07-03  8:31       ` Vladimir Murzin
  2019-07-03  9:17       ` Will Deacon
  2019-07-03 11:23       ` Mark Rutland
  2 siblings, 0 replies; 8+ messages in thread
From: Vladimir Murzin @ 2019-07-03  8:31 UTC (permalink / raw)
  To: Nathan Huckleberry, catalin.marinas, will
  Cc: clang-built-linux, linux-kernel, linux-arm-kernel

On 7/3/19 12:41 AM, Nathan Huckleberry wrote:
> 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.

I'm wondering if it is a case for __maybe_unused?

Something like:

-       pte_t old_pte;
+       pte_t __maybe_unused old_pte;


Cheers
Vladimir


> 
> 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);
>  }
> 


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arm64: mm: Fix dead assignment of old_pte
  2019-07-02 23:41     ` [PATCH v2] " Nathan Huckleberry
  2019-07-03  8:31       ` Vladimir Murzin
@ 2019-07-03  9:17       ` Will Deacon
  2019-07-03 11:23       ` Mark Rutland
  2 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2019-07-03  9:17 UTC (permalink / raw)
  To: Nathan Huckleberry
  Cc: catalin.marinas, linux-kernel, linux-arm-kernel, clang-built-linux

On Tue, Jul 02, 2019 at 04:41:35PM -0700, Nathan Huckleberry wrote:
> 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.

Does this warning actually trigger with linux-next?

Will

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arm64: mm: Fix dead assignment of old_pte
  2019-07-02 23:41     ` [PATCH v2] " Nathan Huckleberry
  2019-07-03  8:31       ` Vladimir Murzin
  2019-07-03  9:17       ` Will Deacon
@ 2019-07-03 11:23       ` Mark Rutland
  2019-07-03 17:24         ` Nathan Huckleberry
  2 siblings, 1 reply; 8+ messages in thread
From: Mark Rutland @ 2019-07-03 11:23 UTC (permalink / raw)
  To: Nathan Huckleberry
  Cc: catalin.marinas, will, linux-kernel, linux-arm-kernel, clang-built-linux

On Tue, Jul 02, 2019 at 04:41:35PM -0700, Nathan Huckleberry wrote:
> 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(-)

As Will asked, does this also trigger in linux-next?

I rewrote this code to avoid to only perform the READ_ONCE() when we'd
use the value, and IIUC that may be sufficient to avoid the warning:

https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/commit/?h=for-next/core&id=9b604722059039a1a3ff69fb8dfd024264046024

Thanks,
Mark.

> 
> 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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] arm64: mm: Fix dead assignment of old_pte
  2019-07-03 11:23       ` Mark Rutland
@ 2019-07-03 17:24         ` Nathan Huckleberry
  0 siblings, 0 replies; 8+ messages in thread
From: Nathan Huckleberry @ 2019-07-03 17:24 UTC (permalink / raw)
  To: Mark Rutland
  Cc: catalin.marinas, will, linux-kernel, linux-arm-kernel, clang-built-linux

Warning is not triggered in next. Looks like this patch is unnecessary.

Thanks,
Nathan Huckleberry

On Wed, Jul 3, 2019 at 4:23 AM Mark Rutland <mark.rutland@arm.com> wrote:
>
> On Tue, Jul 02, 2019 at 04:41:35PM -0700, Nathan Huckleberry wrote:
> > 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(-)
>
> As Will asked, does this also trigger in linux-next?
>
> I rewrote this code to avoid to only perform the READ_ONCE() when we'd
> use the value, and IIUC that may be sufficient to avoid the warning:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/commit/?h=for-next/core&id=9b604722059039a1a3ff69fb8dfd024264046024
>
> Thanks,
> Mark.
>
> >
> > 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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-03 17:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02 23:13 [PATCH] arm64: mm: Fix dead assignment of old_pte Nathan Huckleberry
2019-07-02 23:24 ` Nathan Chancellor
2019-07-02 23:26   ` Nathan Huckleberry
2019-07-02 23:41     ` [PATCH v2] " Nathan Huckleberry
2019-07-03  8:31       ` Vladimir Murzin
2019-07-03  9:17       ` Will Deacon
2019-07-03 11:23       ` Mark Rutland
2019-07-03 17:24         ` Nathan Huckleberry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).