2020-11-02 21:04:17

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v4 0/6] resource: introduce union(), intersection() API

Some users may want to use resource library to manage their own resources,
besides existing users that open code union() and intersection()
implementations.

Provide a generic API for wider use.

Changelog v4:
- added Rb tag (Rafael)
- Cc'ed to LKML and Greg (Rafael)

Changelog v3:
- rebased on top of v5.10-rc1
- dropped upstreamed dependencies
- added Rb tag to the last patch (Mika)

Cc: Kuppuswamy Sathyanarayanan <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: [email protected]

Andy Shevchenko (6):
resource: Simplify region_intersects() by reducing conditionals
resource: Group resource_overlaps() with other inline helpers
resource: Introduce resource_union() for overlapping resources
resource: Introduce resource_intersection() for overlapping resources
PCI/ACPI: Replace open coded variant of resource_union()
ACPI: watchdog: Replace open coded variant of resource_union()

drivers/acpi/acpi_watchdog.c | 6 +-----
drivers/acpi/pci_root.c | 4 +---
include/linux/ioport.h | 34 +++++++++++++++++++++++++++-------
kernel/resource.c | 10 +++++-----
4 files changed, 34 insertions(+), 20 deletions(-)

--
2.28.0


2020-11-02 21:04:25

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v4 3/6] resource: Introduce resource_union() for overlapping resources

Some already present users may utilize resource_union() helper.
Provide it for them and for wider use in the future.

Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Rafael J. Wysocki <[email protected]>
Cc: Mika Westerberg <[email protected]>
Cc: Kuppuswamy Sathyanarayanan <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: [email protected]
---
include/linux/ioport.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index df4581107536..40320eb5bc0e 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -10,9 +10,10 @@
#define _LINUX_IOPORT_H

#ifndef __ASSEMBLY__
+#include <linux/bits.h>
#include <linux/compiler.h>
+#include <linux/minmax.h>
#include <linux/types.h>
-#include <linux/bits.h>
/*
* Resources are tree-like, allowing
* nesting etc..
@@ -235,6 +236,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
return r1->start <= r2->end && r1->end >= r2->start;
}

+static inline bool
+resource_union(struct resource *r1, struct resource *r2, struct resource *r)
+{
+ if (!resource_overlaps(r1, r2))
+ return false;
+ r->start = min(r1->start, r2->start);
+ r->end = max(r1->end, r2->end);
+ return true;
+}
+
/* Convenience shorthand with allocation */
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0)
#define request_muxed_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
--
2.28.0

2020-11-02 21:04:28

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v4 4/6] resource: Introduce resource_intersection() for overlapping resources

There will be at least one user that can utilize new helper.
Provide the helper for future user and for wider use.

Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Rafael J. Wysocki <[email protected]>
---
include/linux/ioport.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 40320eb5bc0e..ece1a8db309c 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -236,6 +236,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
return r1->start <= r2->end && r1->end >= r2->start;
}

+static inline bool
+resource_intersection(struct resource *r1, struct resource *r2, struct resource *r)
+{
+ if (!resource_overlaps(r1, r2))
+ return false;
+ r->start = max(r1->start, r2->start);
+ r->end = min(r1->end, r2->end);
+ return true;
+}
+
static inline bool
resource_union(struct resource *r1, struct resource *r2, struct resource *r)
{
--
2.28.0

2020-11-03 00:45:44

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] resource: introduce union(), intersection() API

On 2020/11/3 5:00, Andy Shevchenko wrote:
> Some users may want to use resource library to manage their own resources,
> besides existing users that open code union() and intersection()
> implementations.
>
> Provide a generic API for wider use.
>
> Changelog v4:
> - added Rb tag (Rafael)
> - Cc'ed to LKML and Greg (Rafael)
>
> Changelog v3:
> - rebased on top of v5.10-rc1
> - dropped upstreamed dependencies
> - added Rb tag to the last patch (Mika)
>
> Cc: Kuppuswamy Sathyanarayanan <[email protected]>
> Cc: Bjorn Helgaas <[email protected]>
> Cc: [email protected]
>
> Andy Shevchenko (6):
> resource: Simplify region_intersects() by reducing conditionals
> resource: Group resource_overlaps() with other inline helpers
> resource: Introduce resource_union() for overlapping resources
> resource: Introduce resource_intersection() for overlapping resources
> PCI/ACPI: Replace open coded variant of resource_union()
> ACPI: watchdog: Replace open coded variant of resource_union()
>
> drivers/acpi/acpi_watchdog.c | 6 +-----
> drivers/acpi/pci_root.c | 4 +---
> include/linux/ioport.h | 34 +++++++++++++++++++++++++++-------
> kernel/resource.c | 10 +++++-----
> 4 files changed, 34 insertions(+), 20 deletions(-)

Reviewed-by: Hanjun Guo <[email protected]>

2020-11-03 06:50:25

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] resource: introduce union(), intersection() API

On Mon, Nov 02, 2020 at 11:00:19PM +0200, Andy Shevchenko wrote:
> Some users may want to use resource library to manage their own resources,
> besides existing users that open code union() and intersection()
> implementations.
>
> Provide a generic API for wider use.
>
> Changelog v4:
> - added Rb tag (Rafael)
> - Cc'ed to LKML and Greg (Rafael)

Didn't we have some tests for this code somewhere? Have you added tests
for the new functions you have added? If not, can you do that so that
we "know" these work properly?

thanks,

greg k-h

2020-11-03 08:34:23

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] resource: introduce union(), intersection() API

On Tue, Nov 3, 2020 at 8:53 AM Greg Kroah-Hartman
<[email protected]> wrote:
>
> On Mon, Nov 02, 2020 at 11:00:19PM +0200, Andy Shevchenko wrote:
> > Some users may want to use resource library to manage their own resources,
> > besides existing users that open code union() and intersection()
> > implementations.
> >
> > Provide a generic API for wider use.
> >
> > Changelog v4:
> > - added Rb tag (Rafael)
> > - Cc'ed to LKML and Greg (Rafael)
>
> Didn't we have some tests for this code somewhere? Have you added tests
> for the new functions you have added? If not, can you do that so that
> we "know" these work properly?

Sure, I'll add for v5. Thanks for the hint!

--
With Best Regards,
Andy Shevchenko

2020-11-03 08:35:29

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] resource: introduce union(), intersection() API

On Tue, Nov 3, 2020 at 2:46 AM Hanjun Guo <[email protected]> wrote:
>
> On 2020/11/3 5:00, Andy Shevchenko wrote:
> > Some users may want to use resource library to manage their own resources,
> > besides existing users that open code union() and intersection()
> > implementations.
> >
> > Provide a generic API for wider use.
> >
> > Changelog v4:
> > - added Rb tag (Rafael)
> > - Cc'ed to LKML and Greg (Rafael)
> >
> > Changelog v3:
> > - rebased on top of v5.10-rc1
> > - dropped upstreamed dependencies
> > - added Rb tag to the last patch (Mika)
> >
> > Cc: Kuppuswamy Sathyanarayanan <[email protected]>
> > Cc: Bjorn Helgaas <[email protected]>
> > Cc: [email protected]
> >
> > Andy Shevchenko (6):
> > resource: Simplify region_intersects() by reducing conditionals
> > resource: Group resource_overlaps() with other inline helpers
> > resource: Introduce resource_union() for overlapping resources
> > resource: Introduce resource_intersection() for overlapping resources
> > PCI/ACPI: Replace open coded variant of resource_union()
> > ACPI: watchdog: Replace open coded variant of resource_union()
> >
> > drivers/acpi/acpi_watchdog.c | 6 +-----
> > drivers/acpi/pci_root.c | 4 +---
> > include/linux/ioport.h | 34 +++++++++++++++++++++++++++-------
> > kernel/resource.c | 10 +++++-----
> > 4 files changed, 34 insertions(+), 20 deletions(-)
>
> Reviewed-by: Hanjun Guo <[email protected]>

Thanks. Is it for the entire series?


--
With Best Regards,
Andy Shevchenko

2020-11-03 09:47:15

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] resource: introduce union(), intersection() API

On 2020/11/3 16:31, Andy Shevchenko wrote:
> On Tue, Nov 3, 2020 at 2:46 AM Hanjun Guo <[email protected]> wrote:
>>
>> On 2020/11/3 5:00, Andy Shevchenko wrote:
>>> Some users may want to use resource library to manage their own resources,
>>> besides existing users that open code union() and intersection()
>>> implementations.
>>>
>>> Provide a generic API for wider use.
>>>
>>> Changelog v4:
>>> - added Rb tag (Rafael)
>>> - Cc'ed to LKML and Greg (Rafael)
>>>
>>> Changelog v3:
>>> - rebased on top of v5.10-rc1
>>> - dropped upstreamed dependencies
>>> - added Rb tag to the last patch (Mika)
>>>
>>> Cc: Kuppuswamy Sathyanarayanan <[email protected]>
>>> Cc: Bjorn Helgaas <[email protected]>
>>> Cc: [email protected]
>>>
>>> Andy Shevchenko (6):
>>> resource: Simplify region_intersects() by reducing conditionals
>>> resource: Group resource_overlaps() with other inline helpers
>>> resource: Introduce resource_union() for overlapping resources
>>> resource: Introduce resource_intersection() for overlapping resources
>>> PCI/ACPI: Replace open coded variant of resource_union()
>>> ACPI: watchdog: Replace open coded variant of resource_union()
>>>
>>> drivers/acpi/acpi_watchdog.c | 6 +-----
>>> drivers/acpi/pci_root.c | 4 +---
>>> include/linux/ioport.h | 34 +++++++++++++++++++++++++++-------
>>> kernel/resource.c | 10 +++++-----
>>> 4 files changed, 34 insertions(+), 20 deletions(-)
>>
>> Reviewed-by: Hanjun Guo <[email protected]>
>
> Thanks. Is it for the entire series?

Yes.

By the way, I tested this patch set on a ARM64 machine booting
with ACPI against 5.10-rc2, and no regressions with PCI, so feel
free to add my Tested-by tag for patch [1,2,3,5/6].

Thanks
Hanjun