diff mbox

[RFC,1/2] kvm: x86: mmu: return zero if s > e in rsvd_bits()

Message ID 1415957488-27490-1-git-send-email-tiejun.chen@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tiejun Chen Nov. 14, 2014, 9:31 a.m. UTC
In some real scenarios 'start' may not be less than 'end' like
maxphyaddr = 52.

Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
---
 arch/x86/kvm/mmu.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Paolo Bonzini Nov. 14, 2014, 10:06 a.m. UTC | #1
On 14/11/2014 10:31, Tiejun Chen wrote:
> In some real scenarios 'start' may not be less than 'end' like
> maxphyaddr = 52.
> 
> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
> ---
>  arch/x86/kvm/mmu.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index bde8ee7..0e98b5e 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -58,6 +58,8 @@
>  
>  static inline u64 rsvd_bits(int s, int e)
>  {
> +	if (unlikely(s > e))
> +		return 0;
>  	return ((1ULL << (e - s + 1)) - 1) << s;
>  }
>  
> 

s == e + 1 is supported:

   (1ULL << (e - (e + 1) + 1)) - 1) << s ==
   (1ULL << 0) << s ==
   0

Is there any case where s is even bigger?

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tiejun Chen Nov. 17, 2014, 1:34 a.m. UTC | #2
On 2014/11/14 18:06, Paolo Bonzini wrote:
>
>
> On 14/11/2014 10:31, Tiejun Chen wrote:
>> In some real scenarios 'start' may not be less than 'end' like
>> maxphyaddr = 52.
>>
>> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
>> ---
>>   arch/x86/kvm/mmu.h | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
>> index bde8ee7..0e98b5e 100644
>> --- a/arch/x86/kvm/mmu.h
>> +++ b/arch/x86/kvm/mmu.h
>> @@ -58,6 +58,8 @@
>>
>>   static inline u64 rsvd_bits(int s, int e)
>>   {
>> +	if (unlikely(s > e))
>> +		return 0;
>>   	return ((1ULL << (e - s + 1)) - 1) << s;
>>   }
>>
>>
>
> s == e + 1 is supported:
>
>     (1ULL << (e - (e + 1) + 1)) - 1) << s ==

(1ULL << (e - (e + 1) + 1)) - 1) << s
	= (1ULL << (e - e - 1) + 1)) - 1) << s
	= (1ULL << (-1) + 1)) - 1) << s
	= (1ULL << (0) - 1) << s
	= (1ULL << (- 1) << s

Am I missing something?

Thanks
Tiejun

>     (1ULL << 0) << s ==
>     0
>
> Is there any case where s is even bigger?
>
> Paolo
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini Nov. 17, 2014, 9:22 a.m. UTC | #3
On 17/11/2014 02:34, Chen, Tiejun wrote:
> On 2014/11/14 18:06, Paolo Bonzini wrote:
>>
>>
>> On 14/11/2014 10:31, Tiejun Chen wrote:
>>> In some real scenarios 'start' may not be less than 'end' like
>>> maxphyaddr = 52.
>>>
>>> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
>>> ---
>>>   arch/x86/kvm/mmu.h | 2 ++
>>>   1 file changed, 2 insertions(+)
>>>
>>> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
>>> index bde8ee7..0e98b5e 100644
>>> --- a/arch/x86/kvm/mmu.h
>>> +++ b/arch/x86/kvm/mmu.h
>>> @@ -58,6 +58,8 @@
>>>
>>>   static inline u64 rsvd_bits(int s, int e)
>>>   {
>>> +    if (unlikely(s > e))
>>> +        return 0;
>>>       return ((1ULL << (e - s + 1)) - 1) << s;
>>>   }
>>>
>>>
>>
>> s == e + 1 is supported:
>>
>>     (1ULL << (e - (e + 1) + 1)) - 1) << s ==
> 
> (1ULL << (e - (e + 1) + 1)) - 1) << s
>     = (1ULL << (e - e - 1) + 1)) - 1) << s
>     = (1ULL << (-1) + 1)) - 1) << s

no,

        ((1ULL << (-1 + 1)) - 1) << s

>     = (1ULL << (0) - 1) << s

        ((1ULL << (0)) - 1) << s

>     = (1ULL << (- 1) << s

        (1 - 1) << s
        0 << s

Paolo

> 
> Am I missing something?
> 
> Thanks
> Tiejun
> 
>>     (1ULL << 0) << s ==
>>     0
>>
>> Is there any case where s is even bigger?
>>
>> Paolo
>> -- 
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> -- 
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tiejun Chen Nov. 17, 2014, 9:27 a.m. UTC | #4
On 2014/11/17 17:22, Paolo Bonzini wrote:
>
>
> On 17/11/2014 02:34, Chen, Tiejun wrote:
>> On 2014/11/14 18:06, Paolo Bonzini wrote:
>>>
>>>
>>> On 14/11/2014 10:31, Tiejun Chen wrote:
>>>> In some real scenarios 'start' may not be less than 'end' like
>>>> maxphyaddr = 52.
>>>>
>>>> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
>>>> ---
>>>>    arch/x86/kvm/mmu.h | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
>>>> index bde8ee7..0e98b5e 100644
>>>> --- a/arch/x86/kvm/mmu.h
>>>> +++ b/arch/x86/kvm/mmu.h
>>>> @@ -58,6 +58,8 @@
>>>>
>>>>    static inline u64 rsvd_bits(int s, int e)
>>>>    {
>>>> +    if (unlikely(s > e))
>>>> +        return 0;
>>>>        return ((1ULL << (e - s + 1)) - 1) << s;
>>>>    }
>>>>
>>>>
>>>
>>> s == e + 1 is supported:
>>>
>>>      (1ULL << (e - (e + 1) + 1)) - 1) << s ==
>>
>> (1ULL << (e - (e + 1) + 1)) - 1) << s
>>      = (1ULL << (e - e - 1) + 1)) - 1) << s
>>      = (1ULL << (-1) + 1)) - 1) << s
>
> no,

You're right since I'm seeing "()" wrongly.

Sorry to bother you.

Thanks
Tiejun
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index bde8ee7..0e98b5e 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -58,6 +58,8 @@ 
 
 static inline u64 rsvd_bits(int s, int e)
 {
+	if (unlikely(s > e))
+		return 0;
 	return ((1ULL << (e - s + 1)) - 1) << s;
 }