diff mbox

[PULL,125/130] target-ppc: Fix page table lookup with kvm enabled

Message ID 878usc7wk8.fsf@linux.vnet.ibm.com
State New
Headers show

Commit Message

Aneesh Kumar K.V March 14, 2014, 1:13 p.m. UTC
Paolo Bonzini <pbonzini@redhat.com> writes:

> Il 07/03/2014 00:34, Alexander Graf ha scritto:
>> @@ -105,30 +106,37 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>>      if (!valid_pte_index(env, pte_index)) {
>>          return H_PARAMETER;
>>      }
>> +
>> +    index = 0;
>> +    hpte = pte_index * HASH_PTE_SIZE_64;
>>      if (likely((flags & H_EXACT) == 0)) {
>>          pte_index &= ~7ULL;
>> -        hpte = pte_index * HASH_PTE_SIZE_64;
>> -        for (i = 0; ; ++i) {
>> -            if (i == 8) {
>> +        token = ppc_hash64_start_access(cpu, pte_index);
>> +        do {
>> +            if (index == 8) {
>> +                ppc_hash64_stop_access(token);
>>                  return H_PTEG_FULL;
>>              }
>> -            if ((ppc_hash64_load_hpte0(env, hpte) & HPTE64_V_VALID) == 0) {
>> +            if ((ppc_hash64_load_hpte0(env, token, index) & HPTE64_V_VALID) == 0) {
>>                  break;
>>              }
>> -            hpte += HASH_PTE_SIZE_64;
>> -        }
>> +        } while (index++);
>> +        ppc_hash64_stop_access(token);
>
> I'm afraid you have a bug here, as spotted by Coverity.  The do...while 
> loop only loops once.  I'm not sure what you meant, could you rewrite it 
> with a "for (index = 0; index < 8; i++)" instead?

good find. how about


         -aneesh

Comments

Paolo Bonzini March 14, 2014, 1:23 p.m. UTC | #1
Il 14/03/2014 14:13, Aneesh Kumar K.V ha scritto:
> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> index e999bbaea062..e079be050fc7 100644
> --- a/hw/ppc/spapr_hcall.c
> +++ b/hw/ppc/spapr_hcall.c
> @@ -118,7 +118,8 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>              if ((ppc_hash64_load_hpte0(env, token, index) & HPTE64_V_VALID) == 0) {
>                  break;
>              }
> -        } while (index++);
> +            index++;
> +        } while (1);

Better use for or while() than do...while, or it could also be

	token = ppc_hash64_start_access(cpu, pte_index);
	for (; index < 8; i++, hpte += HASH_PTE_SIZE_64) {
	   ...
	}
	ppc_hash64_stop_access(token);
	if (index == 8) {
	    return H_PTEG_FULL;
	}

Paolo

>          ppc_hash64_stop_access(token);
>      } else {
>          token = ppc_hash64_start_access(cpu, pte_index);
>
>          -aneesh
>
diff mbox

Patch

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index e999bbaea062..e079be050fc7 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -118,7 +118,8 @@  static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,
             if ((ppc_hash64_load_hpte0(env, token, index) & HPTE64_V_VALID) == 0) {
                 break;
             }
-        } while (index++);
+            index++;
+        } while (1);
         ppc_hash64_stop_access(token);
     } else {
         token = ppc_hash64_start_access(cpu, pte_index);