diff mbox series

[v1,5/5] KVM: s390: vsie: gmap_table_walk() simplifications

Message ID 20200402184819.34215-6-david@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: s390: vsie: fixes and cleanups. | expand

Commit Message

David Hildenbrand April 2, 2020, 6:48 p.m. UTC
Let's use asce_type where applicable. Also, simplify our sanity check for
valid table levels and convert it into a WARN_ON_ONCE(). Check if we even
have a valid gmap shadow as the very first step.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/mm/gmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Janosch Frank April 3, 2020, 1:03 p.m. UTC | #1
On 4/2/20 8:48 PM, David Hildenbrand wrote:
> Let's use asce_type where applicable. Also, simplify our sanity check for
> valid table levels and convert it into a WARN_ON_ONCE(). Check if we even
> have a valid gmap shadow as the very first step.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  arch/s390/mm/gmap.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
> index fd32ab566f57..3c801dae7988 100644
> --- a/arch/s390/mm/gmap.c
> +++ b/arch/s390/mm/gmap.c
> @@ -790,17 +790,18 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap,
>  	const int asce_type = gmap->asce & _ASCE_TYPE_MASK;
>  	unsigned long *table;
>  
> -	if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4))
> -		return NULL;
>  	if (gmap_is_shadow(gmap) && gmap->removed)
>  		return NULL;
>  
> +	if (WARN_ON_ONCE(level > (asce_type >> 2) + 1))
> +		return NULL;
> +
>  	if (WARN_ON_ONCE(asce_type != _ASCE_TYPE_REGION1) &&
>  			 gaddr & (-1UL << (31 + (asce_type >> 2) * 11)))
>  		return NULL;
>  
>  	table = gmap->table;

We could also initialize this variable at the top, no?

> -	switch (gmap->asce & _ASCE_TYPE_MASK) {
> +	switch (asce_type) {
>  	case _ASCE_TYPE_REGION1:
>  		table += (gaddr & _REGION1_INDEX) >> _REGION1_SHIFT;
>  		if (level == 4)
>
David Hildenbrand April 3, 2020, 1:09 p.m. UTC | #2
On 03.04.20 15:03, Janosch Frank wrote:
> On 4/2/20 8:48 PM, David Hildenbrand wrote:
>> Let's use asce_type where applicable. Also, simplify our sanity check for
>> valid table levels and convert it into a WARN_ON_ONCE(). Check if we even
>> have a valid gmap shadow as the very first step.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  arch/s390/mm/gmap.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
>> index fd32ab566f57..3c801dae7988 100644
>> --- a/arch/s390/mm/gmap.c
>> +++ b/arch/s390/mm/gmap.c
>> @@ -790,17 +790,18 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap,
>>  	const int asce_type = gmap->asce & _ASCE_TYPE_MASK;
>>  	unsigned long *table;
>>  
>> -	if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4))
>> -		return NULL;
>>  	if (gmap_is_shadow(gmap) && gmap->removed)
>>  		return NULL;
>>  
>> +	if (WARN_ON_ONCE(level > (asce_type >> 2) + 1))
>> +		return NULL;
>> +
>>  	if (WARN_ON_ONCE(asce_type != _ASCE_TYPE_REGION1) &&
>>  			 gaddr & (-1UL << (31 + (asce_type >> 2) * 11)))
>>  		return NULL;
>>  
>>  	table = gmap->table;
> 
> We could also initialize this variable at the top, no?

very right, add that.
diff mbox series

Patch

diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index fd32ab566f57..3c801dae7988 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -790,17 +790,18 @@  static inline unsigned long *gmap_table_walk(struct gmap *gmap,
 	const int asce_type = gmap->asce & _ASCE_TYPE_MASK;
 	unsigned long *table;
 
-	if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4))
-		return NULL;
 	if (gmap_is_shadow(gmap) && gmap->removed)
 		return NULL;
 
+	if (WARN_ON_ONCE(level > (asce_type >> 2) + 1))
+		return NULL;
+
 	if (WARN_ON_ONCE(asce_type != _ASCE_TYPE_REGION1) &&
 			 gaddr & (-1UL << (31 + (asce_type >> 2) * 11)))
 		return NULL;
 
 	table = gmap->table;
-	switch (gmap->asce & _ASCE_TYPE_MASK) {
+	switch (asce_type) {
 	case _ASCE_TYPE_REGION1:
 		table += (gaddr & _REGION1_INDEX) >> _REGION1_SHIFT;
 		if (level == 4)