diff mbox series

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

Message ID 20210921010120.1256762-3-oupton@google.com (mailing list archive)
State New, archived
Headers show
Series selftests: KVM: Fix some compiler warnings | expand

Commit Message

Oliver Upton Sept. 21, 2021, 1:01 a.m. UTC
Building steal_time.c for arm64 with clang throws the following:

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

Signed-off-by: Oliver Upton <oupton@google.com>
---
 tools/testing/selftests/kvm/steal_time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andrew Jones Sept. 21, 2021, 7:19 a.m. UTC | #1
On Tue, Sep 21, 2021 at 01:01:20AM +0000, Oliver Upton wrote:
> Building steal_time.c for arm64 with clang throws the following:
> 
> >> 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) :
>                               ^
> >> 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.
> 
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
>  tools/testing/selftests/kvm/steal_time.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> index ecec30865a74..eb75b31122c5 100644
> --- a/tools/testing/selftests/kvm/steal_time.c
> +++ b/tools/testing/selftests/kvm/steal_time.c
> @@ -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

diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index ecec30865a74..7da957259ce4 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -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

>  	  "x0", "x1", "x2", "x3");
>  
>  	return ret;
> -- 
> 2.33.0.464.g1972c5931b-goog
>
Paolo Bonzini Sept. 21, 2021, 5:38 p.m. UTC | #2
On 21/09/21 09:19, Andrew Jones wrote:
> On Tue, Sep 21, 2021 at 01:01:20AM +0000, Oliver Upton wrote:
>> Building steal_time.c for arm64 with clang throws the following:
>>
>>>> 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) :
>>                                ^
>>>> 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.
>>
>> Signed-off-by: Oliver Upton <oupton@google.com>
>> ---
>>   tools/testing/selftests/kvm/steal_time.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
>> index ecec30865a74..eb75b31122c5 100644
>> --- a/tools/testing/selftests/kvm/steal_time.c
>> +++ b/tools/testing/selftests/kvm/steal_time.c
>> @@ -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
> 
> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> index ecec30865a74..7da957259ce4 100644
> --- a/tools/testing/selftests/kvm/steal_time.c
> +++ b/tools/testing/selftests/kvm/steal_time.c
> @@ -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"
> 

Agreed, can you send out a patch?  Thanks,

Paolo
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index ecec30865a74..eb75b31122c5 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -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;