Message ID | 20250403183315.286710-2-terry.bowman@amd.com |
---|---|
State | New |
Headers | show |
Series | Add managed SOFT RESERVE resource handling | expand |
Hi Andy, Thanks for reviewing this. I'll make updates for all you pointed out below. Regards, Terry On 4/3/2025 1:40 PM, Andy Shevchenko wrote: > On Thu, Apr 03, 2025 at 01:33:12PM -0500, Terry Bowman wrote: >> From: Nathan Fontenot <nathan.fontenot@amd.com> >> >> Add a release_Sam_region_adjustable() interface to allow for >> removing SOFT RESERVE memory resources. This extracts out the code >> to remove a mem region into a common __release_mem_region_adjustable() >> routine, this routine takes additional parameters of an IORES >> descriptor type to add checks for IORES_DESC_* and a flag to check >> for IORESOURCE_BUSY to control it's behavior. >> >> The existing release_mem_region_adjustable() is a front end to the >> common code and a new release_srmem_region_adjustable() is added to >> release SOFT RESERVE resources. > ... > >> +void release_mem_region_adjustable(resource_size_t start, resource_size_t size) >> +{ >> + return __release_mem_region_adjustable(start, size, > You have still room on the previous line for the parameters. > >> + true, IORES_DESC_NONE); > Return on void?! Interesting... What do you want to do here? > >> +} >> +EXPORT_SYMBOL(release_mem_region_adjustable); >> +#endif >> + >> +#ifdef CONFIG_CXL_REGION >> +void release_srmem_region_adjustable(resource_size_t start, >> + resource_size_t size) > This can be put on a single line. > >> +{ >> + return __release_mem_region_adjustable(start, size, >> + false, IORES_DESC_SOFT_RESERVED); > Same comments as per above function. > >> +} >> +EXPORT_SYMBOL(release_srmem_region_adjustable); >> +#endif
On Thu, 3 Apr 2025 13:33:12 -0500 Terry Bowman <terry.bowman@amd.com> wrote: > From: Nathan Fontenot <nathan.fontenot@amd.com> > > Add a release_Sam_region_adjustable() interface to allow for Who is Sam? (typo) > removing SOFT RESERVE memory resources. This extracts out the code > to remove a mem region into a common __release_mem_region_adjustable() > routine, this routine takes additional parameters of an IORES > descriptor type to add checks for IORES_DESC_* and a flag to check > for IORESOURCE_BUSY to control it's behavior. > > The existing release_mem_region_adjustable() is a front end to the > common code and a new release_srmem_region_adjustable() is added to > release SOFT RESERVE resources. > > Signed-off-by: Nathan Fontenot <nathan.fontenot@amd.com> > Signed-off-by: Terry Bowman <terry.bowman@amd.com> > --- > include/linux/ioport.h | 3 +++ > kernel/resource.c | 55 +++++++++++++++++++++++++++++++++++++++--- > 2 files changed, 54 insertions(+), 4 deletions(-) > > diff --git a/include/linux/ioport.h b/include/linux/ioport.h > index 5385349f0b8a..718360c9c724 100644 > --- a/include/linux/ioport.h > +++ b/include/linux/ioport.h > @@ -357,6 +357,9 @@ extern void __release_region(struct resource *, resource_size_t, > #ifdef CONFIG_MEMORY_HOTREMOVE > extern void release_mem_region_adjustable(resource_size_t, resource_size_t); > #endif > +#ifdef CONFIG_CXL_REGION > +extern void release_srmem_region_adjustable(resource_size_t, resource_size_t); I'm not sure the srmem is obvious enough. Maybe it's worth the long name to spell it out some more.. e.g. something like extern void release_softresv_mem_region_adjustable() ? > +#endif > #ifdef CONFIG_MEMORY_HOTPLUG > extern void merge_system_ram_resource(struct resource *res); > #endif > diff --git a/kernel/resource.c b/kernel/resource.c > index 12004452d999..0195b31064b0 100644 > --- a/kernel/resource.c > +++ b/kernel/resource.c > @@ -1387,7 +1387,7 @@ void __release_region(struct resource *parent, resource_size_t start, > } > EXPORT_SYMBOL(__release_region); > > -#ifdef CONFIG_MEMORY_HOTREMOVE > +#if defined(CONFIG_MEMORY_HOTREMOVE) || defined(CONFIG_CXL_REGION) > /** > * release_mem_region_adjustable - release a previously reserved memory region Looks like you left the old docs which I'm guessing is not the intent. > * @start: resource start address > @@ -1407,7 +1407,10 @@ EXPORT_SYMBOL(__release_region); > * assumes that all children remain in the lower address entry for > * simplicity. Enhance this logic when necessary. > */ > -void release_mem_region_adjustable(resource_size_t start, resource_size_t size) > +static void __release_mem_region_adjustable(resource_size_t start, > + resource_size_t size, > + bool busy_check, > + int res_desc) > { > struct resource *parent = &iomem_resource; > struct resource *new_res = NULL; > @@ -1446,7 +1449,12 @@ void release_mem_region_adjustable(resource_size_t start, resource_size_t size) > if (!(res->flags & IORESOURCE_MEM)) > break; > > - if (!(res->flags & IORESOURCE_BUSY)) { > + if (busy_check && !(res->flags & IORESOURCE_BUSY)) { > + p = &res->child; > + continue; > + } > + > + if (res_desc != IORES_DESC_NONE && res->desc != res_desc) { > p = &res->child; > continue; > } > @@ -1496,7 +1504,46 @@ void release_mem_region_adjustable(resource_size_t start, resource_size_t size) > write_unlock(&resource_lock); > free_resource(new_res); > } > -#endif /* CONFIG_MEMORY_HOTREMOVE */ > +#endif > + > +#ifdef CONFIG_MEMORY_HOTREMOVE > +/** > + * release_mem_region_adjustable - release a previously reserved memory region As above. I was surprised to see new docs in here for an existing function. I think you forgot to delete the now wrongly placed ones above. Jonathan
On Fri, Apr 04, 2025 at 02:16:39PM +0100, Jonathan Cameron wrote: > On Thu, 3 Apr 2025 13:33:12 -0500 Terry Bowman <terry.bowman@amd.com> wrote: > > Add a release_Sam_region_adjustable() interface to allow for > > Who is Sam? (typo) Somebody's uncle? ... > > #ifdef CONFIG_MEMORY_HOTREMOVE > > extern void release_mem_region_adjustable(resource_size_t, resource_size_t); > > #endif > > +#ifdef CONFIG_CXL_REGION > > +extern void release_srmem_region_adjustable(resource_size_t, resource_size_t); > I'm not sure the srmem is obvious enough. Maybe it's worth the long > name to spell it out some more.. e.g. something like And perhaps drop 'extern' as it's not needed. > extern void release_softresv_mem_region_adjustable() ? > > #ifdef CONFIG_MEMORY_HOTPLUG > > extern void merge_system_ram_resource(struct resource *res); > > #endif
diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 5385349f0b8a..718360c9c724 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -357,6 +357,9 @@ extern void __release_region(struct resource *, resource_size_t, #ifdef CONFIG_MEMORY_HOTREMOVE extern void release_mem_region_adjustable(resource_size_t, resource_size_t); #endif +#ifdef CONFIG_CXL_REGION +extern void release_srmem_region_adjustable(resource_size_t, resource_size_t); +#endif #ifdef CONFIG_MEMORY_HOTPLUG extern void merge_system_ram_resource(struct resource *res); #endif diff --git a/kernel/resource.c b/kernel/resource.c index 12004452d999..0195b31064b0 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1387,7 +1387,7 @@ void __release_region(struct resource *parent, resource_size_t start, } EXPORT_SYMBOL(__release_region); -#ifdef CONFIG_MEMORY_HOTREMOVE +#if defined(CONFIG_MEMORY_HOTREMOVE) || defined(CONFIG_CXL_REGION) /** * release_mem_region_adjustable - release a previously reserved memory region * @start: resource start address @@ -1407,7 +1407,10 @@ EXPORT_SYMBOL(__release_region); * assumes that all children remain in the lower address entry for * simplicity. Enhance this logic when necessary. */ -void release_mem_region_adjustable(resource_size_t start, resource_size_t size) +static void __release_mem_region_adjustable(resource_size_t start, + resource_size_t size, + bool busy_check, + int res_desc) { struct resource *parent = &iomem_resource; struct resource *new_res = NULL; @@ -1446,7 +1449,12 @@ void release_mem_region_adjustable(resource_size_t start, resource_size_t size) if (!(res->flags & IORESOURCE_MEM)) break; - if (!(res->flags & IORESOURCE_BUSY)) { + if (busy_check && !(res->flags & IORESOURCE_BUSY)) { + p = &res->child; + continue; + } + + if (res_desc != IORES_DESC_NONE && res->desc != res_desc) { p = &res->child; continue; } @@ -1496,7 +1504,46 @@ void release_mem_region_adjustable(resource_size_t start, resource_size_t size) write_unlock(&resource_lock); free_resource(new_res); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ +#endif + +#ifdef CONFIG_MEMORY_HOTREMOVE +/** + * release_mem_region_adjustable - release a previously reserved memory region + * @start: resource start address + * @size: resource region size + * + * This interface is intended for memory hot-delete. The requested region + * is released from a currently busy memory resource. The requested region + * must either match exactly or fit into a single busy resource entry. In + * the latter case, the remaining resource is adjusted accordingly. + * Existing children of the busy memory resource must be immutable in the + * request. + * + * Note: + * - Additional release conditions, such as overlapping region, can be + * supported after they are confirmed as valid cases. + * - When a busy memory resource gets split into two entries, the code + * assumes that all children remain in the lower address entry for + * simplicity. Enhance this logic when necessary. + */ +void release_mem_region_adjustable(resource_size_t start, resource_size_t size) +{ + return __release_mem_region_adjustable(start, size, + true, IORES_DESC_NONE); +} +EXPORT_SYMBOL(release_mem_region_adjustable); +#endif + +#ifdef CONFIG_CXL_REGION +void release_srmem_region_adjustable(resource_size_t start, + resource_size_t size) +{ + return __release_mem_region_adjustable(start, size, + false, IORES_DESC_SOFT_RESERVED); +} +EXPORT_SYMBOL(release_srmem_region_adjustable); +#endif + #ifdef CONFIG_MEMORY_HOTPLUG static bool system_ram_resources_mergeable(struct resource *r1,