Linux-Modules Archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [v2] module: fix building stats for 32-bit targets
Date: Tue, 18 Apr 2023 00:48:04 +0200	[thread overview]
Message-ID: <20230417224810.2922059-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

The new module statistics code mixes 64-bit types and wordsized 'long'
variables, which leads to build failures on 32-bit architectures:

kernel/module/stats.c: In function 'read_file_mod_stats':
kernel/module/stats.c:291:29: error: passing argument 1 of 'atomic64_read' from incompatible pointer type [-Werror=incompatible-pointer-types]
  291 |  total_size = atomic64_read(&total_mod_size);
x86_64-linux-ld: kernel/module/stats.o: in function `read_file_mod_stats':
stats.c:(.text+0x2b2): undefined reference to `__udivdi3'

To fix this, the code has to use one of the two types consistently.

Change them all to word-size types here.

Fixes: 0d4ab68ce983 ("module: add debug stats to help identify memory pressure")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: use long instead of u64 everywheren
---
 kernel/module/stats.c | 46 +++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/kernel/module/stats.c b/kernel/module/stats.c
index bbf90190a3fe..cdcd60695399 100644
--- a/kernel/module/stats.c
+++ b/kernel/module/stats.c
@@ -280,8 +280,8 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
 	unsigned int len, size, count_failed = 0;
 	char *buf;
 	u32 live_mod_count, fkreads, fdecompress, fbecoming, floads;
-	u64 total_size, text_size, ikread_bytes, ibecoming_bytes, idecompress_bytes, imod_bytes,
-	    total_virtual_lost;
+	unsigned long total_size, text_size, ikread_bytes, ibecoming_bytes,
+		idecompress_bytes, imod_bytes, total_virtual_lost;
 
 	live_mod_count = atomic_read(&modcount);
 	fkreads = atomic_read(&failed_kreads);
@@ -289,12 +289,12 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
 	fbecoming = atomic_read(&failed_becoming);
 	floads = atomic_read(&failed_load_modules);
 
-	total_size = atomic64_read(&total_mod_size);
-	text_size = atomic64_read(&total_text_size);
-	ikread_bytes = atomic64_read(&invalid_kread_bytes);
-	idecompress_bytes = atomic64_read(&invalid_decompress_bytes);
-	ibecoming_bytes = atomic64_read(&invalid_becoming_bytes);
-	imod_bytes = atomic64_read(&invalid_mod_bytes);
+	total_size = atomic_long_read(&total_mod_size);
+	text_size = atomic_long_read(&total_text_size);
+	ikread_bytes = atomic_long_read(&invalid_kread_bytes);
+	idecompress_bytes = atomic_long_read(&invalid_decompress_bytes);
+	ibecoming_bytes = atomic_long_read(&invalid_becoming_bytes);
+	imod_bytes = atomic_long_read(&invalid_mod_bytes);
 
 	total_virtual_lost = ikread_bytes + idecompress_bytes + ibecoming_bytes + imod_bytes;
 
@@ -315,27 +315,27 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
 
 	len += scnprintf(buf + len, size - len, "%25s\t%u\n", "Mods failed on load", floads);
 
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Total module size", total_size);
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Total mod text size", text_size);
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Total module size", total_size);
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Total mod text size", text_size);
 
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Failed kread bytes", ikread_bytes);
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Failed kread bytes", ikread_bytes);
 
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Failed decompress bytes",
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Failed decompress bytes",
 			 idecompress_bytes);
 
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Failed becoming bytes", ibecoming_bytes);
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Failed becoming bytes", ibecoming_bytes);
 
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Failed kmod bytes", imod_bytes);
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Failed kmod bytes", imod_bytes);
 
-	len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Virtual mem wasted bytes", total_virtual_lost);
+	len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Virtual mem wasted bytes", total_virtual_lost);
 
 	if (live_mod_count && total_size) {
-		len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Average mod size",
+		len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Average mod size",
 				 DIV_ROUND_UP(total_size, live_mod_count));
 	}
 
 	if (live_mod_count && text_size) {
-		len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Average mod text size",
+		len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Average mod text size",
 				 DIV_ROUND_UP(text_size, live_mod_count));
 	}
 
@@ -348,25 +348,25 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
 
 	WARN_ON_ONCE(ikread_bytes && !fkreads);
 	if (fkreads && ikread_bytes) {
-		len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Avg fail kread bytes",
+		len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Avg fail kread bytes",
 				 DIV_ROUND_UP(ikread_bytes, fkreads));
 	}
 
 	WARN_ON_ONCE(ibecoming_bytes && !fbecoming);
 	if (fbecoming && ibecoming_bytes) {
-		len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Avg fail becoming bytes",
+		len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Avg fail becoming bytes",
 				 DIV_ROUND_UP(ibecoming_bytes, fbecoming));
 	}
 
 	WARN_ON_ONCE(idecompress_bytes && !fdecompress);
 	if (fdecompress && idecompress_bytes) {
-		len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Avg fail decomp bytes",
+		len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Avg fail decomp bytes",
 				 DIV_ROUND_UP(idecompress_bytes, fdecompress));
 	}
 
 	WARN_ON_ONCE(imod_bytes && !floads);
 	if (floads && imod_bytes) {
-		len += scnprintf(buf + len, size - len, "%25s\t%llu\n", "Average fail load bytes",
+		len += scnprintf(buf + len, size - len, "%25s\t%lu\n", "Average fail load bytes",
 				 DIV_ROUND_UP(imod_bytes, floads));
 	}
 
@@ -387,8 +387,8 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
 	list_for_each_entry_rcu(mod_fail, &dup_failed_modules, list) {
 		if (WARN_ON_ONCE(++count_failed >= MAX_FAILED_MOD_PRINT))
 			goto out_unlock;
-		len += scnprintf(buf + len, size - len, "%25s\t%15llu\t%25s\n", mod_fail->name,
-				 atomic64_read(&mod_fail->count), mod_fail_to_str(mod_fail));
+		len += scnprintf(buf + len, size - len, "%25s\t%15lu\t%25s\n", mod_fail->name,
+				 atomic_long_read(&mod_fail->count), mod_fail_to_str(mod_fail));
 	}
 out_unlock:
 	mutex_unlock(&module_mutex);
-- 
2.39.2


             reply	other threads:[~2023-04-17 22:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17 22:48 Arnd Bergmann [this message]
2023-04-17 23:31 ` [PATCH] [v2] module: fix building stats for 32-bit targets Luis Chamberlain

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=20230417224810.2922059-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@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 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 read-only IMAP folder(s) and NNTP newsgroup(s).