Skip to contentSkip to conversation

selftests: KVM: Fix some compiler warnings

PATCH Applied Oliver Upton 3 participants 8 messages Sep 21, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover selftests: KVM: Fix some compiler warnings

Building KVM selftests for arm64 using clang throws a couple compiler warnings. This series addresses the warnings found insofar that selftests can be built quietly for arm64 with clang.

Series applies cleanly to 5.15-rc2.

Oliver Upton (2):
selftests: KVM: Fix compiler warning in demand_paging_test
selftests: KVM: Fix 'asm-operand-width' warnings in steal_time.c

 tools/testing/selftests/kvm/demand_paging_test.c | 2 +-
 tools/testing/selftests/kvm/steal_time.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 6 lines
2.33.0.464.g1972c5931b-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#1 lore raw

PATCH 1/2 selftests: KVM: Fix compiler warning in demand_paging_test

Building demand_paging_test.c with clang throws the following warning:

Quoted 1 line
Quoted 1 line

demand_paging_test.c:182:7: error: logical not is only applied to the left hand side of this bitwise operator [-Werror,-Wlogical-not-parentheses]

if (!pollfd[0].revents & POLLIN)

Silence the warning by placing the bitwise operation within parentheses.

---
 tools/testing/selftests/kvm/demand_paging_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
index e79c1b64977f..10edae425ab3 100644
@@ -179,7 +179,7 @@ static void *uffd_handler_thread_fn(void *arg)
 			return NULL;
 		}
 
-		if (!pollfd[0].revents & POLLIN)
+		if (!(pollfd[0].revents & POLLIN))
 			continue;
 
 		r = read(uffd, &msg, sizeof(msg));
Signature · 6 lines
2.33.0.464.g1972c5931b-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] selftests: KVM: Fix compiler warning in demand_paging_test

Quoted 17 lines · Oliver Upton

Building demand_paging_test.c with clang throws the following warning:

Quoted 1 line
Quoted 1 line

demand_paging_test.c:182:7: error: logical not is only applied to the left hand side of this bitwise operator [-Werror,-Wlogical-not-parentheses]

if (!pollfd[0].revents & POLLIN)

Silence the warning by placing the bitwise operation within parentheses.

---
 tools/testing/selftests/kvm/demand_paging_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/demand_paging_test.c +0 -0
index e79c1b64977f..10edae425ab3 100644

tools/testing/selftests/kvm/demand_paging_test.c static void *uffd_handler_thread_fn(void *arg) · line 182

Quoted 5 lines
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
@@ -179,7 +179,7 @@ static void *uffd_handler_thread_fn(void *arg)
 			return NULL;
 		}
 
-		if (!pollfd[0].revents & POLLIN)
+		if (!(pollfd[0].revents & POLLIN))

That's a bug fix. If revents was e.g. POLLPRI then this logic wouldn't have done what it's supposed to do. Maybe we should better call out that this is a fix in the summary and add a fixes tag?

Anyway,

Thanks,
drew

Quoted 6 lines
tools/testing/selftests/kvm/demand_paging_test.c +0 -0
 			continue;
 
 		r = read(uffd, &msg, sizeof(msg));
Signature · 1 line
2.33.0.464.g1972c5931b-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Applied
#3 lore raw

Re: [PATCH 1/2] selftests: KVM: Fix compiler warning in demand_paging_test

In reply to Oliver Upton
Quoted 18 lines · Oliver Upton

Building demand_paging_test.c with clang throws the following warning:

Quoted 1 line
Quoted 1 line

demand_paging_test.c:182:7: error: logical not is only applied to the left hand side of this bitwise operator [-Werror,-Wlogical-not-parentheses]

if (!pollfd[0].revents & POLLIN)

Silence the warning by placing the bitwise operation within parentheses.

---
  tools/testing/selftests/kvm/demand_paging_test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/demand_paging_test.c +0 -0
index e79c1b64977f..10edae425ab3 100644

tools/testing/selftests/kvm/demand_paging_test.c static void *uffd_handler_thread_fn(void *arg) · line 185

Quoted 8 lines
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
@@ -179,7 +179,7 @@ static void *uffd_handler_thread_fn(void *arg)
  			return NULL;
  		}
 
-		if (!pollfd[0].revents & POLLIN)
+		if (!(pollfd[0].revents & POLLIN))
  			continue;
 
  		r = read(uffd, &msg, sizeof(msg));

Queued (with small adjustments to the commit message and Cc: stable), thanks.

Paolo

#4 lore raw

Re: [PATCH 1/2] selftests: KVM: Fix compiler warning in demand_paging_test

Hi Paolo,

Quoted 26 lines · Paolo Bonzini
Quoted 24 lines · Oliver Upton

Building demand_paging_test.c with clang throws the following warning:

Quoted 1 line
Quoted 1 line

demand_paging_test.c:182:7: error: logical not is only applied to the left hand side of this bitwise operator [-Werror,-Wlogical-not-parentheses]

if (!pollfd[0].revents & POLLIN)

Silence the warning by placing the bitwise operation within parentheses.

---
  tools/testing/selftests/kvm/demand_paging_test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
index e79c1b64977f..10edae425ab3 100644
@@ -179,7 +179,7 @@ static void *uffd_handler_thread_fn(void *arg)
                      return NULL;
              }
 
-             if (!pollfd[0].revents & POLLIN)
+             if (!(pollfd[0].revents & POLLIN))
                      continue;
 
Quoted 5 lines

tools/testing/selftests/kvm/demand_paging_test.c static void *uffd_handler_thread_fn(void *arg) · line 185

Quoted 2 lines
tools/testing/selftests/kvm/demand_paging_test.c +0 -0
              r = read(uffd, &msg, sizeof(msg));

Queued (with small adjustments to the commit message and Cc: stable), thanks.

I sent out a v2 of this series that addressed Drew's comments here and picked up his suggested fix for 2/2. Would you like to queue that version instead?

http://lore.kernel.org/kvm/[email protected]

--
Thanks,
Oliver

#5 lore raw

PATCH 2/2 selftests: KVM: Fix 'asm-operand-width' warnings in steal_time.c

In reply to Oliver Upton

Building steal_time.c for arm64 with clang throws the following:

Quoted 1 line
Quoted 1 line

steal_time.c:130:22: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]

          : "=r" (ret) : "r" (func), "r" (arg) :
                              ^
Quoted 1 line
Quoted 1 line

steal_time.c:130:34: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]

          : "=r" (ret) : "r" (func), "r" (arg) :
                                          ^

Silence by casting operands to 64 bits.

---
 tools/testing/selftests/kvm/steal_time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/steal_time.c +1 -1
index ecec30865a74..eb75b31122c5 100644
@@ -127,7 +127,7 @@ static int64_t smccc(uint32_t func, uint32_t arg)
 		"mov	x1, %2\n"
 		"hvc	#0\n"
 		"mov	%0, x0\n"
-	: "=r" (ret) : "r" (func), "r" (arg) :
+	: "=r" (ret) : "r" ((uint64_t)func), "r" ((uint64_t)arg) :
 	  "x0", "x1", "x2", "x3");
 
 	return ret;
Signature · 6 lines
2.33.0.464.g1972c5931b-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#6 lore raw

Re: [PATCH 2/2] selftests: KVM: Fix 'asm-operand-width' warnings in steal_time.c

Quoted 21 lines · Oliver Upton

Building steal_time.c for arm64 with clang throws the following:

Quoted 1 line
Quoted 1 line

steal_time.c:130:22: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]

          : "=r" (ret) : "r" (func), "r" (arg) :
                              ^
Quoted 1 line
Quoted 1 line

steal_time.c:130:34: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]

          : "=r" (ret) : "r" (func), "r" (arg) :
                                          ^

Silence by casting operands to 64 bits.

---
 tools/testing/selftests/kvm/steal_time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/steal_time.c +0 -0
index ecec30865a74..eb75b31122c5 100644

tools/testing/selftests/kvm/steal_time.c static int64_t smccc(uint32_t func, uint32_t arg) · line 130

Quoted 5 lines
tools/testing/selftests/kvm/steal_time.c +1 -1
@@ -127,7 +127,7 @@ static int64_t smccc(uint32_t func, uint32_t arg)
 		"mov	x1, %2\n"
 		"hvc	#0\n"
 		"mov	%0, x0\n"
-	: "=r" (ret) : "r" (func), "r" (arg) :
+	: "=r" (ret) : "r" ((uint64_t)func), "r" ((uint64_t)arg) :

Actually, I think I'd rather fix this smccc implementation to match the spec, which I think should be done like this

tools/testing/selftests/kvm/steal_time.c +2 -2
index ecec30865a74..7da957259ce4 100644
@@ -118,12 +118,12 @@ struct st_time {
        uint64_t st_time;
 };
 
-static int64_t smccc(uint32_t func, uint32_t arg)
+static int64_t smccc(uint32_t func, uint64_t arg)
 {
        unsigned long ret;
 
        asm volatile(
-               "mov    x0, %1\n"
+               "mov    w0, %w1\n"
                "mov    x1, %2\n"
                "hvc    #0\n"
                "mov    %0, x0\n"

Thanks,
drew

Quoted 6 lines
tools/testing/selftests/kvm/steal_time.c +0 -0
 	  "x0", "x1", "x2", "x3");
 
 	return ret;
Signature · 1 line
2.33.0.464.g1972c5931b-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#7 lore raw

Re: [PATCH 2/2] selftests: KVM: Fix 'asm-operand-width' warnings in steal_time.c

Quoted 41 lines · Andrew Jones
Quoted 21 lines · Oliver Upton

Building steal_time.c for arm64 with clang throws the following:

Quoted 1 line
Quoted 1 line

steal_time.c:130:22: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]

           : "=r" (ret) : "r" (func), "r" (arg) :
                               ^
Quoted 1 line
Quoted 1 line

steal_time.c:130:34: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm-operand-widths]

           : "=r" (ret) : "r" (func), "r" (arg) :
                                           ^

Silence by casting operands to 64 bits.

---
  tools/testing/selftests/kvm/steal_time.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/steal_time.c +0 -0
index ecec30865a74..eb75b31122c5 100644

tools/testing/selftests/kvm/steal_time.c static int64_t smccc(uint32_t func, uint32_t arg) · line 130

Quoted 5 lines
tools/testing/selftests/kvm/steal_time.c +1 -1
@@ -127,7 +127,7 @@ static int64_t smccc(uint32_t func, uint32_t arg)
  		"mov	x1, %2\n"
  		"hvc	#0\n"
  		"mov	%0, x0\n"
-	: "=r" (ret) : "r" (func), "r" (arg) :
+	: "=r" (ret) : "r" ((uint64_t)func), "r" ((uint64_t)arg) :

Actually, I think I'd rather fix this smccc implementation to match the spec, which I think should be done like this

tools/testing/selftests/kvm/steal_time.c +0 -1
index ecec30865a74..7da957259ce4 100644
@@ -118,12 +118,12 @@ struct st_time {
         uint64_t st_time;
  };
 
-static int64_t smccc(uint32_t func, uint32_t arg)

tools/testing/selftests/kvm/steal_time.c struct st_time { · line 129

Quoted 10 lines
tools/testing/selftests/kvm/steal_time.c +2 -1
+static int64_t smccc(uint32_t func, uint64_t arg)
  {
         unsigned long ret;
 
         asm volatile(
-               "mov    x0, %1\n"
+               "mov    w0, %w1\n"
                 "mov    x1, %2\n"
                 "hvc    #0\n"
                 "mov    %0, x0\n"

Agreed, can you send out a patch? Thanks,

Paolo