[PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry()

Konstantin Khorenko posted 1 patch 2 months ago
drivers/iommu/generic_pt/fmt/amdv1.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry()
Posted by Konstantin Khorenko 2 months ago
With -fprofile-update=atomic in CFLAGS_GCOV, GCC fails to eliminate
an impossible branch in FIELD_PREP() inside amdv1pt_install_leaf_entry()
when the function is merely "static inline".  GCC may choose not to
inline it, and without seeing the constant arguments at the call site
it cannot prove the FIELD_PREP value fits the field.

Change from "static inline" to "static __always_inline" so GCC is
forced to inline the function and can see the constant values,
allowing dead code elimination of the impossible branch.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 drivers/iommu/generic_pt/fmt/amdv1.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/generic_pt/fmt/amdv1.h b/drivers/iommu/generic_pt/fmt/amdv1.h
index 3b2c41d9654d..8d11b08291d7 100644
--- a/drivers/iommu/generic_pt/fmt/amdv1.h
+++ b/drivers/iommu/generic_pt/fmt/amdv1.h
@@ -191,7 +191,7 @@ static inline enum pt_entry_type amdv1pt_load_entry_raw(struct pt_state *pts)
 }
 #define pt_load_entry_raw amdv1pt_load_entry_raw
 
-static inline void
+static __always_inline void
 amdv1pt_install_leaf_entry(struct pt_state *pts, pt_oaddr_t oa,
 			   unsigned int oasz_lg2,
 			   const struct pt_write_attrs *attrs)
-- 
2.43.5
Re: [PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry()
Posted by Jason Gunthorpe 2 months ago
On Thu, Apr 09, 2026 at 08:01:17PM +0300, Konstantin Khorenko wrote:
> With -fprofile-update=atomic in CFLAGS_GCOV, GCC fails to eliminate
> an impossible branch in FIELD_PREP() inside amdv1pt_install_leaf_entry()
> when the function is merely "static inline".  GCC may choose not to
> inline it, and without seeing the constant arguments at the call site
> it cannot prove the FIELD_PREP value fits the field.
> 
> Change from "static inline" to "static __always_inline" so GCC is
> forced to inline the function and can see the constant values,
> allowing dead code elimination of the impossible branch.
> 
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
> ---
>  drivers/iommu/generic_pt/fmt/amdv1.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

It was already merged:

commit 8b72aa5704c77380742346d4ac755b074b7f9eaa
Author: Sherry Yang <sherry.yang@oracle.com>
Date:   Thu Mar 26 09:17:19 2026 -0700

    iommupt/amdv1: mark amdv1pt_install_leaf_entry as __always_inline
    
    After enabling CONFIG_GCOV_KERNEL and CONFIG_GCOV_PROFILE_ALL, following
    build failure is observed under GCC 14.2.1: