dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id()
@ 2025-08-21 20:09 Nathan Chancellor
  2025-08-22  6:53 ` Dongsheng Yang
  2025-08-25 13:28 ` Mikulas Patocka
  0 siblings, 2 replies; 4+ messages in thread
From: Nathan Chancellor @ 2025-08-21 20:09 UTC (permalink / raw)
  To: Dongsheng Yang, Zheng Gu, Mikulas Patocka
  Cc: dm-devel, patches, Nathan Chancellor

When building for a 32-bit platform (such as ARCH=i386 allmodconfig),
there is a modpost error:

  ERROR: modpost: "__umoddi3" [drivers/md/dm-pcache/dm-pcache.ko] undefined!

Hacking up the driver Makefile to allow building into the kernel shows
that the division comes from get_kset_id(), which is inlined into
cache_key_append() in cache_key.c.

Use the helper div_u64_rem() to avoid emitting a libcall on 32-bit targets.

Fixes: fd5cc4922bef ("dm-pcache: add persistent cache target in device-mapper")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/md/dm-pcache/cache.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-pcache/cache.h b/drivers/md/dm-pcache/cache.h
index b3b361cc406e..b10e721ab1b7 100644
--- a/drivers/md/dm-pcache/cache.h
+++ b/drivers/md/dm-pcache/cache.h
@@ -373,7 +373,9 @@ static inline void *get_key_head_addr(struct pcache_cache *cache)
 
 static inline u32 get_kset_id(struct pcache_cache *cache, u64 off)
 {
-	return (off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT) % cache->n_ksets;
+	u32 rem;
+	div_u64_rem(off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT, cache->n_ksets, &rem);
+	return rem;
 }
 
 static inline struct pcache_cache_kset *get_kset(struct pcache_cache *cache, u32 kset_id)

---
base-commit: fd5cc4922bef4b3c3cd0452f38dcfd066322e9a9
change-id: 20250821-dm-pcache-fix-32-bit-div-err-4f0695e94784

Best regards,
--  
Nathan Chancellor <nathan@kernel.org>


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

* Re: [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id()
  2025-08-21 20:09 [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id() Nathan Chancellor
@ 2025-08-22  6:53 ` Dongsheng Yang
  2025-08-23  5:27   ` Nathan Chancellor
  2025-08-25 13:28 ` Mikulas Patocka
  1 sibling, 1 reply; 4+ messages in thread
From: Dongsheng Yang @ 2025-08-22  6:53 UTC (permalink / raw)
  To: Nathan Chancellor, Zheng Gu, Mikulas Patocka; +Cc: dm-devel, patches


在 8/22/2025 4:09 AM, Nathan Chancellor 写道:
> When building for a 32-bit platform (such as ARCH=i386 allmodconfig),
> there is a modpost error:
>
>    ERROR: modpost: "__umoddi3" [drivers/md/dm-pcache/dm-pcache.ko] undefined!
>
> Hacking up the driver Makefile to allow building into the kernel shows
> that the division comes from get_kset_id(), which is inlined into
> cache_key_append() in cache_key.c.
>
> Use the helper div_u64_rem() to avoid emitting a libcall on 32-bit targets.
>
> Fixes: fd5cc4922bef ("dm-pcache: add persistent cache target in device-mapper")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>   drivers/md/dm-pcache/cache.h | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/dm-pcache/cache.h b/drivers/md/dm-pcache/cache.h
> index b3b361cc406e..b10e721ab1b7 100644
> --- a/drivers/md/dm-pcache/cache.h
> +++ b/drivers/md/dm-pcache/cache.h
> @@ -373,7 +373,9 @@ static inline void *get_key_head_addr(struct pcache_cache *cache)
>   
>   static inline u32 get_kset_id(struct pcache_cache *cache, u64 off)
>   {
> -	return (off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT) % cache->n_ksets;
> +	u32 rem;
> +	div_u64_rem(off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT, cache->n_ksets, &rem);
> +	return rem;
>   }


Hi Nathan,

Thanx for your fix. It looks good to me.

Just one nit about the variable name. I prefer kset_id to rem.

Mikulas, if this looks good to you, could you apply this change to dm-6.18?

Thanx

Dongsheng

diff --git a/drivers/md/dm-pcache/cache.h b/drivers/md/dm-pcache/cache.h
index b3b361cc406e..f005c9d9a7aa 100644
--- a/drivers/md/dm-pcache/cache.h
+++ b/drivers/md/dm-pcache/cache.h
@@ -373,7 +373,11 @@ static inline void *get_key_head_addr(struct 
pcache_cache *cache)

  static inline u32 get_kset_id(struct pcache_cache *cache, u64 off)
  {
-       return (off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT) % cache->n_ksets;
+       u32 kset_id;
+
+       div_u64_rem(off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT, 
cache->n_ksets, &kset_id);
+
+       return kset_id;
  }

  static inline struct pcache_cache_kset *get_kset(struct pcache_cache 
*cache, u32 kset_id)

> re
>   
>   static inline struct pcache_cache_kset *get_kset(struct pcache_cache *cache, u32 kset_id)
>
> ---
> base-commit: fd5cc4922bef4b3c3cd0452f38dcfd066322e9a9
> change-id: 20250821-dm-pcache-fix-32-bit-div-err-4f0695e94784
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>

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

* Re: [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id()
  2025-08-22  6:53 ` Dongsheng Yang
@ 2025-08-23  5:27   ` Nathan Chancellor
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2025-08-23  5:27 UTC (permalink / raw)
  To: Dongsheng Yang; +Cc: Zheng Gu, Mikulas Patocka, dm-devel, patches

Hi Dongsheng,

On Fri, Aug 22, 2025 at 02:53:42PM +0800, Dongsheng Yang wrote:
> 
> 在 8/22/2025 4:09 AM, Nathan Chancellor 写道:
> > When building for a 32-bit platform (such as ARCH=i386 allmodconfig),
> > there is a modpost error:
> > 
> >    ERROR: modpost: "__umoddi3" [drivers/md/dm-pcache/dm-pcache.ko] undefined!
> > 
> > Hacking up the driver Makefile to allow building into the kernel shows
> > that the division comes from get_kset_id(), which is inlined into
> > cache_key_append() in cache_key.c.
> > 
> > Use the helper div_u64_rem() to avoid emitting a libcall on 32-bit targets.
> > 
> > Fixes: fd5cc4922bef ("dm-pcache: add persistent cache target in device-mapper")
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> > ---
> >   drivers/md/dm-pcache/cache.h | 4 +++-
> >   1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/md/dm-pcache/cache.h b/drivers/md/dm-pcache/cache.h
> > index b3b361cc406e..b10e721ab1b7 100644
> > --- a/drivers/md/dm-pcache/cache.h
> > +++ b/drivers/md/dm-pcache/cache.h
> > @@ -373,7 +373,9 @@ static inline void *get_key_head_addr(struct pcache_cache *cache)
> >   static inline u32 get_kset_id(struct pcache_cache *cache, u64 off)
> >   {
> > -	return (off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT) % cache->n_ksets;
> > +	u32 rem;
> > +	div_u64_rem(off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT, cache->n_ksets, &rem);
> > +	return rem;
> >   }
> 
> 
> Hi Nathan,
> 
> Thanx for your fix. It looks good to me.
> 
> Just one nit about the variable name. I prefer kset_id to rem.

Thanks, seems entirely reasonable, thanks for sending the diff!

> Mikulas, if this looks good to you, could you apply this change to dm-6.18?
> 
> diff --git a/drivers/md/dm-pcache/cache.h b/drivers/md/dm-pcache/cache.h
> index b3b361cc406e..f005c9d9a7aa 100644
> --- a/drivers/md/dm-pcache/cache.h
> +++ b/drivers/md/dm-pcache/cache.h
> @@ -373,7 +373,11 @@ static inline void *get_key_head_addr(struct
> pcache_cache *cache)
> 
>  static inline u32 get_kset_id(struct pcache_cache *cache, u64 off)
>  {
> -       return (off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT) % cache->n_ksets;
> +       u32 kset_id;
> +
> +       div_u64_rem(off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT, cache->n_ksets,
> &kset_id);
> +
> +       return kset_id;
>  }
> 
>  static inline struct pcache_cache_kset *get_kset(struct pcache_cache
> *cache, u32 kset_id)
> 
> > re
> >   static inline struct pcache_cache_kset *get_kset(struct pcache_cache *cache, u32 kset_id)
> > 
> > ---
> > base-commit: fd5cc4922bef4b3c3cd0452f38dcfd066322e9a9
> > change-id: 20250821-dm-pcache-fix-32-bit-div-err-4f0695e94784
> > 
> > Best regards,
> > --
> > Nathan Chancellor <nathan@kernel.org>
> > 

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

* Re: [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id()
  2025-08-21 20:09 [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id() Nathan Chancellor
  2025-08-22  6:53 ` Dongsheng Yang
@ 2025-08-25 13:28 ` Mikulas Patocka
  1 sibling, 0 replies; 4+ messages in thread
From: Mikulas Patocka @ 2025-08-25 13:28 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: Dongsheng Yang, Zheng Gu, dm-devel, patches



On Thu, 21 Aug 2025, Nathan Chancellor wrote:

> When building for a 32-bit platform (such as ARCH=i386 allmodconfig),
> there is a modpost error:
> 
>   ERROR: modpost: "__umoddi3" [drivers/md/dm-pcache/dm-pcache.ko] undefined!
> 
> Hacking up the driver Makefile to allow building into the kernel shows
> that the division comes from get_kset_id(), which is inlined into
> cache_key_append() in cache_key.c.
> 
> Use the helper div_u64_rem() to avoid emitting a libcall on 32-bit targets.
> 
> Fixes: fd5cc4922bef ("dm-pcache: add persistent cache target in device-mapper")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks.

I folded it into the existing dm-pcache commit.

Mikulas


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

end of thread, other threads:[~2025-08-25 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 20:09 [PATCH] dm-pcache: Fix 64-bit division for 32-bit platforms in get_kset_id() Nathan Chancellor
2025-08-22  6:53 ` Dongsheng Yang
2025-08-23  5:27   ` Nathan Chancellor
2025-08-25 13:28 ` Mikulas Patocka

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