Skip to contentSkip to conversation

lib/logic_pio: Fix overlap check for pio registery

PATCH In review Jiahui Cen 2 participants 8 messages Dec 18, 2020 – Mar 15, 2021 Library code

lore
Share & tools
lore

Jiahui Cen

author
#0 lore raw

PATCH 1/1 lib/logic_pio: Fix overlap check for pio registery

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
 lib/logic_pio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +1 -1
index f32fe481b492..445d611f1dc1 100644
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
 		    new_range->flags == LOGIC_PIO_CPU_MMIO) {
 			/* for MMIO ranges we need to check for overlap */
 			if (start >= range->hw_start + range->size ||
-			    end < range->hw_start) {
+			    end <= range->hw_start) {
 				mmio_end = range->io_start + range->size;
 			} else {
 				ret = -EFAULT;
Signature · 1 line
2.28.0
#1 lore raw
Quoted 13 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
  lib/logic_pio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644

lib/logic_pio.c int logic_pio_register_range(struct logic_pio_hwaddr *new_range) · line 60

Quoted 5 lines
lib/logic_pio.c +1 -1
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
  		    new_range->flags == LOGIC_PIO_CPU_MMIO) {
  			/* for MMIO ranges we need to check for overlap */
  			if (start >= range->hw_start + range->size ||
-			    end < range->hw_start) {
+			    end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Have you seen a problem here?

Thanks,
John

author
#2 lore raw

Hi John,

Quoted 24 lines · John Garry
Quoted 15 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
  lib/logic_pio.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
               new_range->flags == LOGIC_PIO_CPU_MMIO) {
               /* for MMIO ranges we need to check for overlap */
Quoted 3 lines

              if (start >= range->hw_start + range->size || -                end < range->hw_start) {
+                end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Quoted 2 lines

Have you seen a problem here?

No serious problem. I found it just when I was working on adding support of pci expander bridge for Arm in QEMU. I found the IO window of some extended root bus could not be registered when I inserted the extended buses' _CRS info into DSDT table in the x86 way, which does not sort the buses.

Though root buses should be sorted in QEMU, would it be better to accept those non-ascending IO windows?

BTW, for b, it seems to be no space between IO windows of different root buses generated by EDK2. Or maybe I missed something obvious.

Thanks,
Jiahui

Reviewed-by
#3 lore raw
Quoted 28 lines · Jiahui Cen

Hi John,

Quoted 23 lines · John Garry
Quoted 13 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
   lib/logic_pio.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644

lib/logic_pio.c int logic_pio_register_range(struct logic_pio_hwaddr *new_range) · line 60

Quoted 5 lines
lib/logic_pio.c +1 -1
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
               new_range->flags == LOGIC_PIO_CPU_MMIO) {
               /* for MMIO ranges we need to check for overlap */
               if (start >= range->hw_start + range->size ||
-                end < range->hw_start) {
+                end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Quoted 2 lines

Have you seen a problem here?

Quoted 8 lines

No serious problem. I found it just when I was working on adding support of pci expander bridge for Arm in QEMU. I found the IO window of some extended root bus could not be registered when I inserted the extended buses' _CRS info into DSDT table in the x86 way, which does not sort the buses.

Though root buses should be sorted in QEMU, would it be better to accept those non-ascending IO windows?

ok, so it seems that you have seen a real problem, and this issue is not just detected by code analysis.

Quoted 2 lines

BTW, for b, it seems to be no space between IO windows of different root buses generated by EDK2. Or maybe I missed something obvious.

I don't know about that. Anyway, your change looks ok.

BTW, for your virt env, will there be requirement to unregister PCI MMIO ranges? Currently we don't see that in non-virt world.

Thanks,
John

author
#4 lore raw

Hi John,

Quoted 40 lines · John Garry
Quoted 28 lines · Jiahui Cen

Hi John,

Quoted 23 lines · John Garry
Quoted 15 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
   lib/logic_pio.c | 2 +-

   1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
                new_range->flags == LOGIC_PIO_CPU_MMIO) {
                /* for MMIO ranges we need to check for overlap */
Quoted 3 lines

               if (start >= range->hw_start + range->size || -                end < range->hw_start) {
+                end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Quoted 2 lines

Have you seen a problem here?

Quoted 8 lines

No serious problem. I found it just when I was working on adding support of pci expander bridge for Arm in QEMU. I found the IO window of some extended root bus could not be registered when I inserted the extended buses' _CRS info into DSDT table in the x86 way, which does not sort the buses.

Though root buses should be sorted in QEMU, would it be better to accept those non-ascending IO windows?

ok, so it seems that you have seen a real problem, and this issue is not just detected by code analysis.

Quoted 9 lines
Quoted 2 lines

BTW, for b, it seems to be no space between IO windows of different root buses generated by EDK2. Or maybe I missed something obvious.

I don't know about that. Anyway, your change looks ok.

BTW, for your virt env, will there be requirement to unregister PCI MMIO ranges? Currently we don't see that in non-virt world.

Thanks for your review.

And currently there is no such a requirement in my virt env.

Thanks,
Jiahui

#5 lore raw
Quoted 43 lines · Jiahui Cen
Quoted 43 lines · Jiahui Cen
Quoted 28 lines

Hi John,

Quoted 23 lines · John Garry
Quoted 13 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
    lib/logic_pio.c | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644

lib/logic_pio.c int logic_pio_register_range(struct logic_pio_hwaddr *new_range) · line 60

Quoted 5 lines
lib/logic_pio.c +1 -1
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
                new_range->flags == LOGIC_PIO_CPU_MMIO) {
                /* for MMIO ranges we need to check for overlap */
                if (start >= range->hw_start + range->size ||
-                end < range->hw_start) {
+                end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Quoted 2 lines

Have you seen a problem here?

Quoted 8 lines

No serious problem. I found it just when I was working on adding support of pci expander bridge for Arm in QEMU. I found the IO window of some extended root bus could not be registered when I inserted the extended buses' _CRS info into DSDT table in the x86 way, which does not sort the buses.

Though root buses should be sorted in QEMU, would it be better to accept those non-ascending IO windows?

ok, so it seems that you have seen a real problem, and this issue is not just detected by code analysis.

Quoted 2 lines

BTW, for b, it seems to be no space between IO windows of different root buses generated by EDK2. Or maybe I missed something obvious.

I don't know about that. Anyway, your change looks ok.

Quoted 8 lines
Quoted 4 lines

BTW, for your virt env, will there be requirement to unregister PCI MMIO ranges? Currently we don't see that in non-virt world.

Thanks for your review.

And currently there is no such a requirement in my virt env.

I am not sure what happened to this patch, but I plan on sending some patches in this area soon - do you want me to include this one?

Thanks,
John

author
#6 lore raw

Hi John,

Quoted 46 lines · John Garry
Quoted 45 lines · Jiahui Cen
Quoted 45 lines · Jiahui Cen
Quoted 28 lines

Hi John,

Quoted 23 lines · John Garry
Quoted 15 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
    lib/logic_pio.c | 2 +-

    1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
                 new_range->flags == LOGIC_PIO_CPU_MMIO) {
                 /* for MMIO ranges we need to check for overlap */
Quoted 3 lines

                if (start >= range->hw_start + range->size || -                end < range->hw_start) {
+                end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Quoted 2 lines

Have you seen a problem here?

Quoted 8 lines

No serious problem. I found it just when I was working on adding support of pci expander bridge for Arm in QEMU. I found the IO window of some extended root bus could not be registered when I inserted the extended buses' _CRS info into DSDT table in the x86 way, which does not sort the buses.

Though root buses should be sorted in QEMU, would it be better to accept those non-ascending IO windows?

ok, so it seems that you have seen a real problem, and this issue is not just detected by code analysis.

Quoted 2 lines

BTW, for b, it seems to be no space between IO windows of different root buses generated by EDK2. Or maybe I missed something obvious.

I don't know about that. Anyway, your change looks ok.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

BTW, for your virt env, will there be requirement to unregister PCI MMIO ranges? Currently we don't see that in non-virt world.

Thanks for your review.

And currently there is no such a requirement in my virt env.

I am not sure what happened to this patch, but I plan on sending some patches in this area soon - do you want me to include this one?

Sorry for replying late. It's appreciated if you can include this patch.

Thanks!
Jiahui

Quoted 4 lines

Thanks,
John

.

#7 lore raw

On 18/01/2021 01:27, Jiahui Cen wrote:

+

Hi Arnd, xu wei,

Any chance we could pick up this patch via arm-soc tree?

The series which I originally included in, below, is stalled a bit.

Thanks,
John

https://lore.kernel.org/lkml/[email protected]/

Quoted 70 lines

Hi John,

Quoted 46 lines · John Garry
Quoted 45 lines · Jiahui Cen
Quoted 45 lines · Jiahui Cen
Quoted 28 lines

Hi John,

Quoted 23 lines · John Garry
Quoted 13 lines · Jiahui Cen

Since the [start, end) is a half-open interval, a range with the end equal to the start of another range should not be considered as overlapped.

---
     lib/logic_pio.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
lib/logic_pio.c +0 -0
index f32fe481b492..445d611f1dc1 100644

lib/logic_pio.c int logic_pio_register_range(struct logic_pio_hwaddr *new_range) · line 60

Quoted 5 lines
lib/logic_pio.c +1 -1
@@ -57,7 +57,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
                 new_range->flags == LOGIC_PIO_CPU_MMIO) {
                 /* for MMIO ranges we need to check for overlap */
                 if (start >= range->hw_start + range->size ||
-                end < range->hw_start) {
+                end <= range->hw_start) {

It looks like your change is correct, but should not really have an impact in practice since:
a: BIOSes generally list ascending IO port CPU addresses
b. there is space between IO port CPU address regions

Quoted 2 lines

Have you seen a problem here?

Quoted 8 lines

No serious problem. I found it just when I was working on adding support of pci expander bridge for Arm in QEMU. I found the IO window of some extended root bus could not be registered when I inserted the extended buses' _CRS info into DSDT table in the x86 way, which does not sort the buses.

Though root buses should be sorted in QEMU, would it be better to accept those non-ascending IO windows?

ok, so it seems that you have seen a real problem, and this issue is not just detected by code analysis.

Quoted 2 lines

BTW, for b, it seems to be no space between IO windows of different root buses generated by EDK2. Or maybe I missed something obvious.

I don't know about that. Anyway, your change looks ok.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

BTW, for your virt env, will there be requirement to unregister PCI MMIO ranges? Currently we don't see that in non-virt world.

Thanks for your review.

And currently there is no such a requirement in my virt env.

I am not sure what happened to this patch, but I plan on sending some patches in this area soon - do you want me to include this one?

Sorry for replying late. It's appreciated if you can include this patch.

Thanks!
Jiahui

Quoted 4 lines

Thanks,
John

.

.