Skip to contentSkip to conversation

s390/mm: fix improper use of __storage_key_init_range

PATCH Applied Claudio Imbrenda 3 participants 5 messages Apr 16, 2024

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

cover s390/mm: fix improper use of __storage_key_init_range

The function __storage_key_init_range() expects the end address to be the first byte outside the range to be initialized. I.e. end - start should be the size of the area to be initialized.

This small series fixes two cases in which the last address in the range was passed as end address. This was still functionally correct, since __storage_key_init_range() will still loop over single pages and correctly clear the given range, but it will be slower than clearing the storage keys for the whole 1M block with a single instruction.

Claudio Imbrenda (2):
s390/mm: fix storage key clearing for guest huge pages s390/mm: fix clearing storage keys for huge pages

 arch/s390/mm/gmap.c        | 2 +-
 arch/s390/mm/hugetlbpage.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/2 s390/mm: fix storage key clearing for guest huge pages

The function __storage_key_init_range() expects the end address to be the first byte outside the range to be initialized. I.e. end - start should be the size of the area to be initialized.

The current code works because __storage_key_init_range() will still loop over every page in the range, but it is slower than using sske_frame().

Fixes 964c2c05c9f3 ("s390/mm: Clear huge page storage keys on enable_skey")
---
 arch/s390/mm/gmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/mm/gmap.c +1 -1
index 094b43b121cd..12d22a7fa32f 100644
@@ -2661,7 +2661,7 @@ static int __s390_enable_skey_hugetlb(pte_t *pte, unsigned long addr,
 		return 0;
 
 	start = pmd_val(*pmd) & HPAGE_MASK;
-	end = start + HPAGE_SIZE - 1;
+	end = start + HPAGE_SIZE;
 	__storage_key_init_range(start, end);
 	set_bit(PG_arch_1, &page->flags);
 	cond_resched();
Signature · 1 line
2.44.0
#2 lore raw

PATCH 2/2 s390/mm: fix clearing storage keys for huge pages

In reply to Claudio Imbrenda

The function __storage_key_init_range() expects the end address to be the first byte outside the range to be initialized. I.e. end - start should be the size of the area to be initialized.

The current code works because __storage_key_init_range() will still loop over every page in the range, but it is slower than using sske_frame().

Fixes 3afdfca69870 ("s390/mm: Clear skeys for newly mapped huge guest pmds")
---
 arch/s390/mm/hugetlbpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/mm/hugetlbpage.c +1 -1
index c2e8242bd15d..dc3db86e13ff 100644
@@ -139,7 +139,7 @@ static void clear_huge_pte_skeys(struct mm_struct *mm, unsigned long rste)
 	}
 
 	if (!test_and_set_bit(PG_arch_1, &page->flags))
-		__storage_key_init_range(paddr, paddr + size - 1);
+		__storage_key_init_range(paddr, paddr + size);
 }
 
 void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
Signature · 1 line
2.44.0
maintainer Reviewed-by on the v1 series
#3 lore raw
In reply to Claudio Imbrenda
Quoted 10 lines · Claudio Imbrenda

The function __storage_key_init_range() expects the end address to be the first byte outside the range to be initialized. I.e. end - start should be the size of the area to be initialized.

This small series fixes two cases in which the last address in the range was passed as end address. This was still functionally correct, since __storage_key_init_range() will still loop over single pages and correctly clear the given range, but it will be slower than clearing the storage keys for the whole 1M block with a single instruction.

Quoted 7 lines

Claudio Imbrenda (2):
s390/mm: fix storage key clearing for guest huge pages s390/mm: fix clearing storage keys for huge pages

 arch/s390/mm/gmap.c        | 2 +-
 arch/s390/mm/hugetlbpage.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)