Skip to contentSkip to conversation

x86/pat: pass correct address to sanitize_phys

PATCH Superseded Jeff Moyer 3 participants 5 messages Jul 21, 2021 – Aug 10, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 x86/pat: pass correct address to sanitize_phys

memtype_reserve takes an address range of the form [start, end). It then passes the start and end addresses to sanitize_phys, which is meant to operate on the inclusive addresses. If end falls at the end of the physical address space, sanitize_phys will return 0. This can result in drivers failing to load:

[   10.000087] mpt3sas_cm0: unable to map adapter memory! or resource not found
[   10.000334] mpt3sas_cm0: failure at drivers/scsi/mpt3sas/mpt3sas_scsih.c:10597/_scsih_probe()!

Fix this by passing the inclusive end address to sanitize_phys.

Fixes 510ee090abc3 ("x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses")

--
It might be worth adding a comment, here. If there are any suggestions on what a sane wording would be, I'm all ears.

arch/x86/mm/pat/memtype.c +1 -1
index 3112ca7786ed..482557905294 100644
@@ -583,7 +583,7 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type,
 	int err = 0;
 
 	start = sanitize_phys(start);
-	end = sanitize_phys(end);
+	end = sanitize_phys(end - 1) + 1;
 	if (start >= end) {
 		WARN(1, "%s failed: [mem %#010Lx-%#010Lx], req %s\n", __func__,
 				start, end - 1, cattr_name(req_type));
author
#1 lore raw

Ping? This patch fixes a real problem seen in the field. Can I get some review?

Thanks!
Jeff

Quoted 30 lines · Jeff Moyer

memtype_reserve takes an address range of the form [start, end). It then passes the start and end addresses to sanitize_phys, which is meant to operate on the inclusive addresses. If end falls at the end of the physical address space, sanitize_phys will return 0. This can result in drivers failing to load:

[   10.000087] mpt3sas_cm0: unable to map adapter memory! or resource not found
[   10.000334] mpt3sas_cm0: failure at drivers/scsi/mpt3sas/mpt3sas_scsih.c:10597/_scsih_probe()!

Fix this by passing the inclusive end address to sanitize_phys.

Fixes 510ee090abc3 ("x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses")

--
It might be worth adding a comment, here. If there are any suggestions on what a sane wording would be, I'm all ears.

arch/x86/mm/pat/memtype.c +1 -1
index 3112ca7786ed..482557905294 100644
@@ -583,7 +583,7 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type,
 	int err = 0;
 
 	start = sanitize_phys(start);
-	end = sanitize_phys(end);
+	end = sanitize_phys(end - 1) + 1;
 	if (start >= end) {
 		WARN(1, "%s failed: [mem %#010Lx-%#010Lx], req %s\n", __func__,
 				start, end - 1, cattr_name(req_type));
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jeff Moyer
Quoted 24 lines · Jeff Moyer

memtype_reserve takes an address range of the form [start, end). It then passes the start and end addresses to sanitize_phys, which is meant to operate on the inclusive addresses. If end falls at the end of the physical address space, sanitize_phys will return 0. This can result in drivers failing to load:

[   10.000087] mpt3sas_cm0: unable to map adapter memory! or resource not found
[   10.000334] mpt3sas_cm0: failure at drivers/scsi/mpt3sas/mpt3sas_scsih.c:10597/_scsih_probe()!

Fix this by passing the inclusive end address to sanitize_phys.

Fixes 510ee090abc3 ("x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses")

--
It might be worth adding a comment, here. If there are any suggestions on what a sane wording would be, I'm all ears.

arch/x86/mm/pat/memtype.c +0 -0
index 3112ca7786ed..482557905294 100644

arch/x86/mm/pat/memtype.c int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type, · line 589

Quoted 8 lines
arch/x86/mm/pat/memtype.c +1 -1
@@ -583,7 +583,7 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type,
  	int err = 0;
 
  	start = sanitize_phys(start);
-	end = sanitize_phys(end);
+	end = sanitize_phys(end - 1) + 1;
  	if (start >= end) {
  		WARN(1, "%s failed: [mem %#010Lx-%#010Lx], req %s\n", __func__,
  				start, end - 1, cattr_name(req_type));

LGTM

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
In reply to Jeff Moyer

Jeff,

On Wed, Jul 21 2021 at 15:48, Jeff Moyer wrote:

Please write function names with brackets, i.e. sanitize_phys().

Quoted 1 line

memtype_reserve takes an address range of the form [start, end). It

[start, end]

Quoted 7 lines

then passes the start and end addresses to sanitize_phys, which is meant to operate on the inclusive addresses. If end falls at the end of the physical address space, sanitize_phys will return 0. This can result in drivers failing to load:

[   10.000087] mpt3sas_cm0: unable to map adapter memory! or resource not found
[   10.000334] mpt3sas_cm0: failure at drivers/scsi/mpt3sas/mpt3sas_scsih.c:10597/_scsih_probe()!

Doesn't this trigger the WARN() right below that offending line?

Quoted 7 lines

Fix this by passing the inclusive end address to sanitize_phys.

Fixes 510ee090abc3 ("x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses")

--
It might be worth adding a comment, here. If there are any suggestions on what a sane wording would be, I'm all ears.

See below.

arch/x86/mm/pat/memtype.c int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type, · line 586

Quoted 9 lines
arch/x86/mm/pat/memtype.c +0 -1
index 3112ca7786ed..482557905294 100644
@@ -583,7 +583,7 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type,
 	int err = 0;
 
 	start = sanitize_phys(start);
-	end = sanitize_phys(end);

/*
* [start, end] is an exclusive address range, but
* sanitize_phys() expects an inclusive end address */

arch/x86/mm/pat/memtype.c int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type, · line 589

Quoted 4 lines
arch/x86/mm/pat/memtype.c +1 -0
+	end = sanitize_phys(end - 1) + 1;
 	if (start >= end) {
 		WARN(1, "%s failed: [mem %#010Lx-%#010Lx], req %s\n", __func__,
 				start, end - 1, cattr_name(req_type));

Thanks,

tglx

author
#4 lore raw
Quoted 5 lines · Thomas Gleixner

Jeff,

On Wed, Jul 21 2021 at 15:48, Jeff Moyer wrote:

Please write function names with brackets, i.e. sanitize_phys().

OK, will do.

Quoted 3 lines
Quoted 1 line

memtype_reserve takes an address range of the form [start, end). It

[start, end]

Start is inclusive, end is exclusive, so start <= x < end. I used the notation found here:

https://en.wikipedia.org/wiki/Interval_(mathematics)

If that's too confusing, I can stick to inclusive vs exclusive verbiage.

Quoted 9 lines
Quoted 7 lines

then passes the start and end addresses to sanitize_phys, which is meant to operate on the inclusive addresses. If end falls at the end of the physical address space, sanitize_phys will return 0. This can result in drivers failing to load:

[   10.000087] mpt3sas_cm0: unable to map adapter memory! or resource not found
[   10.000334] mpt3sas_cm0: failure at drivers/scsi/mpt3sas/mpt3sas_scsih.c:10597/_scsih_probe()!

Doesn't this trigger the WARN() right below that offending line?

It does. I'll include the warning message in the v2 posting.

Quoted 17 lines
Quoted 7 lines

Fix this by passing the inclusive end address to sanitize_phys.

Fixes 510ee090abc3 ("x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses")

--
It might be worth adding a comment, here. If there are any suggestions on what a sane wording would be, I'm all ears.

See below.

Quoted 7 lines
arch/x86/mm/pat/memtype.c +0 -0
index 3112ca7786ed..482557905294 100644
@@ -583,7 +583,7 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type,
 	int err = 0;
 
Quoted 7 lines

arch/x86/mm/pat/memtype.c int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type, · line 586

Quoted 2 lines
arch/x86/mm/pat/memtype.c +0 -1
 	start = sanitize_phys(start);
-	end = sanitize_phys(end);

/*
* [start, end] is an exclusive address range, but
* sanitize_phys() expects an inclusive end address */

That works for me (modulo the interval notation), thanks for the suggestion.

Thanks!
Jeff