From: panand@redhat.com (Pratyush Anand) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH kexec-tools v2 12/32] kexec: add helper to exlude a region from a set of memory ranges Date: Tue, 7 Jun 2016 10:25:15 +0530 [thread overview] Message-ID: <20160607045515.GA13643@dhcppc6> (raw) In-Reply-To: <E1b9xsO-0003sa-Sr@e0050434b2927.dyn.armlinux.org.uk> On 06/06/2016:05:59:44 PM, Russell King wrote: > Add a helper to exclude a region from a set of memory ranges. > > Signed-off-by: Russell King <rmk@arm.linux.org.uk> Reviewed-by: Pratyush Anand <panand@redhat.com> > --- > kexec/mem_regions.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > kexec/mem_regions.h | 4 +++ > 2 files changed, 75 insertions(+) > > diff --git a/kexec/mem_regions.c b/kexec/mem_regions.c > index 804984a..b01a5c8 100644 > --- a/kexec/mem_regions.c > +++ b/kexec/mem_regions.c > @@ -55,3 +55,74 @@ int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, > return 0; > } > > +static void mem_regions_remove(struct memory_ranges *ranges, int index) > +{ > + int tail_entries; > + > + /* we are assured to have at least one entry */ > + ranges->size -= 1; > + > + /* if we have following entries, shuffle them down one place */ > + tail_entries = ranges->size - index; > + if (tail_entries) > + memmove(ranges->ranges + index, ranges->ranges + index + 1, > + tail_entries * sizeof(*ranges->ranges)); > + > + /* zero the new tail entry */ > + memset(ranges->ranges + ranges->size, 0, sizeof(*ranges->ranges)); > +} > + > +/** > + * mem_regions_exclude() - excludes a memory region from a set of memory ranges > + * @ranges: memory ranges to exclude the region from > + * @range: memory range to exclude > + * > + * Exclude a memory region from a set of memory ranges. We assume that > + * the region to be excluded is either wholely located within one of the > + * memory ranges, or not at all. > + */ > +int mem_regions_exclude(struct memory_ranges *ranges, > + const struct memory_range *range) > +{ > + int i, ret; > + > + for (i = 0; i < ranges->size; i++) { > + struct memory_range *r = ranges->ranges + i; > + > + /* > + * We assume that crash area is fully contained in > + * some larger memory area. > + */ > + if (r->start <= range->start && r->end >= range->end) { > + if (r->start == range->start) { > + if (r->end == range->end) > + /* Remove this entry */ > + mem_regions_remove(ranges, i); > + else > + /* Shrink the start of this memory range */ > + r->start = range->end + 1; > + } else if (r->end == range->end) { > + /* Shrink the end of this memory range */ > + r->end = range->start - 1; > + } else { > + /* > + * Split this area into 2 smaller ones and > + * remove excluded range from between. First > + * create new entry for the remaining area. > + */ > + ret = mem_regions_add(ranges, range->end + 1, > + r->end - range->end, 0); > + if (ret < 0) > + return ret; > + > + /* > + * Update this area to end before excluded > + * range. > + */ > + r->end = range->start - 1; > + break; > + } > + } > + } > + return 0; > +} > diff --git a/kexec/mem_regions.h b/kexec/mem_regions.h > index da7b5e8..ae9e972 100644 > --- a/kexec/mem_regions.h > +++ b/kexec/mem_regions.h > @@ -2,9 +2,13 @@ > #define MEM_REGIONS_H > > struct memory_ranges; > +struct memory_range; > > void mem_regions_sort(struct memory_ranges *ranges); > > +int mem_regions_exclude(struct memory_ranges *ranges, > + const struct memory_range *range); > + > int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, > unsigned long long length, int type); > > -- > 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: Pratyush Anand <panand@redhat.com> To: Russell King <rmk@arm.linux.org.uk> Cc: kexec@lists.infradead.org, Baoquan He <bhe@redhat.com>, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH kexec-tools v2 12/32] kexec: add helper to exlude a region from a set of memory ranges Date: Tue, 7 Jun 2016 10:25:15 +0530 [thread overview] Message-ID: <20160607045515.GA13643@dhcppc6> (raw) In-Reply-To: <E1b9xsO-0003sa-Sr@e0050434b2927.dyn.armlinux.org.uk> On 06/06/2016:05:59:44 PM, Russell King wrote: > Add a helper to exclude a region from a set of memory ranges. > > Signed-off-by: Russell King <rmk@arm.linux.org.uk> Reviewed-by: Pratyush Anand <panand@redhat.com> > --- > kexec/mem_regions.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > kexec/mem_regions.h | 4 +++ > 2 files changed, 75 insertions(+) > > diff --git a/kexec/mem_regions.c b/kexec/mem_regions.c > index 804984a..b01a5c8 100644 > --- a/kexec/mem_regions.c > +++ b/kexec/mem_regions.c > @@ -55,3 +55,74 @@ int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, > return 0; > } > > +static void mem_regions_remove(struct memory_ranges *ranges, int index) > +{ > + int tail_entries; > + > + /* we are assured to have at least one entry */ > + ranges->size -= 1; > + > + /* if we have following entries, shuffle them down one place */ > + tail_entries = ranges->size - index; > + if (tail_entries) > + memmove(ranges->ranges + index, ranges->ranges + index + 1, > + tail_entries * sizeof(*ranges->ranges)); > + > + /* zero the new tail entry */ > + memset(ranges->ranges + ranges->size, 0, sizeof(*ranges->ranges)); > +} > + > +/** > + * mem_regions_exclude() - excludes a memory region from a set of memory ranges > + * @ranges: memory ranges to exclude the region from > + * @range: memory range to exclude > + * > + * Exclude a memory region from a set of memory ranges. We assume that > + * the region to be excluded is either wholely located within one of the > + * memory ranges, or not at all. > + */ > +int mem_regions_exclude(struct memory_ranges *ranges, > + const struct memory_range *range) > +{ > + int i, ret; > + > + for (i = 0; i < ranges->size; i++) { > + struct memory_range *r = ranges->ranges + i; > + > + /* > + * We assume that crash area is fully contained in > + * some larger memory area. > + */ > + if (r->start <= range->start && r->end >= range->end) { > + if (r->start == range->start) { > + if (r->end == range->end) > + /* Remove this entry */ > + mem_regions_remove(ranges, i); > + else > + /* Shrink the start of this memory range */ > + r->start = range->end + 1; > + } else if (r->end == range->end) { > + /* Shrink the end of this memory range */ > + r->end = range->start - 1; > + } else { > + /* > + * Split this area into 2 smaller ones and > + * remove excluded range from between. First > + * create new entry for the remaining area. > + */ > + ret = mem_regions_add(ranges, range->end + 1, > + r->end - range->end, 0); > + if (ret < 0) > + return ret; > + > + /* > + * Update this area to end before excluded > + * range. > + */ > + r->end = range->start - 1; > + break; > + } > + } > + } > + return 0; > +} > diff --git a/kexec/mem_regions.h b/kexec/mem_regions.h > index da7b5e8..ae9e972 100644 > --- a/kexec/mem_regions.h > +++ b/kexec/mem_regions.h > @@ -2,9 +2,13 @@ > #define MEM_REGIONS_H > > struct memory_ranges; > +struct memory_range; > > void mem_regions_sort(struct memory_ranges *ranges); > > +int mem_regions_exclude(struct memory_ranges *ranges, > + const struct memory_range *range); > + > int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, > unsigned long long length, int type); > > -- > 1.9.1 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2016-06-07 4:55 UTC|newest] Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-06-06 16:41 [PATCH kexec-tools v2 00/32] Keystone II updates for kexec tools Russell King - ARM Linux 2016-06-06 16:41 ` Russell King - ARM Linux 2016-06-06 16:58 ` [PATCH kexec-tools v2 01/32] kdump: mmap() and munmap() only work on page-aligned quantites Russell King 2016-06-06 16:58 ` Russell King 2016-06-06 16:58 ` [PATCH kexec-tools v2 02/32] kdump: fix multiple program header entries Russell King 2016-06-06 16:58 ` Russell King 2016-06-06 16:58 ` [PATCH kexec-tools v2 03/32] kdump: actually write out the memory Russell King 2016-06-06 16:58 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 04/32] kdump: fix kdump mapping Russell King 2016-06-06 16:59 ` Russell King 2016-06-07 2:05 ` Pratyush Anand 2016-06-07 2:05 ` Pratyush Anand 2016-06-06 16:59 ` [PATCH kexec-tools v2 05/32] arm: fix kdump to work on LPAE systems Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 06/32] kdump: print mmap() offset in hex Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 07/32] kexec: fix warnings caused by selecting 64-bit file IO on 32-bit platforms Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 08/32] kexec: add max_size to memory_ranges Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 09/32] kexec: phys_to_virt() must take unsigned long long Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 10/32] kexec: add generic helper to add to memory_regions Russell King 2016-06-06 16:59 ` Russell King 2016-06-08 1:13 ` Baoquan He 2016-06-08 1:13 ` Baoquan He 2016-06-08 1:22 ` Simon Horman 2016-06-08 1:22 ` Simon Horman 2016-06-09 16:18 ` [PATCH] Remove "max" parameter comment Russell King 2016-06-09 16:18 ` Russell King 2016-06-09 17:06 ` Pratyush Anand 2016-06-09 17:06 ` Pratyush Anand 2016-06-23 0:40 ` Simon Horman 2016-06-23 0:40 ` Simon Horman 2016-06-06 16:59 ` [PATCH kexec-tools v2 11/32] kexec: add mem_regions sorting implementation Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 12/32] kexec: add helper to exlude a region from a set of memory ranges Russell King 2016-06-06 16:59 ` Russell King 2016-06-07 4:55 ` Pratyush Anand [this message] 2016-06-07 4:55 ` Pratyush Anand 2016-06-06 16:59 ` [PATCH kexec-tools v2 13/32] arm: fix pointer signedness warning in kexec-uImage-arm.c Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 16:59 ` [PATCH kexec-tools v2 14/32] arm: fix off-by-one on memory end Russell King 2016-06-06 16:59 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 15/32] arm: fix get_kernel_stext_sym() to close its file Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 16/32] arm: fix ELF32/ELF64 check Russell King 2016-06-06 17:00 ` Russell King 2016-06-07 5:41 ` Pratyush Anand 2016-06-07 5:41 ` Pratyush Anand 2016-06-06 17:00 ` [PATCH kexec-tools v2 17/32] arm: return proper error for missing crash kernel Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 18/32] arm: report if crash kernel is out of bounds Russell King 2016-06-06 17:00 ` Russell King 2016-06-07 5:41 ` Pratyush Anand 2016-06-07 5:41 ` Pratyush Anand 2016-06-06 17:00 ` [PATCH kexec-tools v2 19/32] arm: add memory ranges debug Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 20/32] arm: add maximum number of memory ranges Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 21/32] arm: parse crash_reserved_mem early Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 22/32] arm: use generic mem_region sorting implementation Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 23/32] arm: move crash system RAM parsing earlier Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 24/32] arm: add support for platforms with boot memory aliases Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 25/32] arm: crashdump needs boot alias of crash kernel region Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:00 ` [PATCH kexec-tools v2 26/32] arm: rename crash_reserved_mem to crash_kernel_mem Russell King 2016-06-06 17:00 ` Russell King 2016-06-06 17:01 ` [PATCH kexec-tools v2 27/32] arm: add support for multiple reserved regions Russell King 2016-06-06 17:01 ` Russell King 2016-06-06 17:01 ` [PATCH kexec-tools v2 28/32] arm: add support for boot-time crash kernel resource Russell King 2016-06-06 17:01 ` Russell King 2016-06-06 17:01 ` [PATCH kexec-tools v2 29/32] arm: add debug of reserved and coredump memory ranges Russell King 2016-06-06 17:01 ` Russell King 2016-06-06 17:01 ` [PATCH kexec-tools v2 30/32] arm: fix type of phys_offset Russell King 2016-06-06 17:01 ` Russell King 2016-06-06 17:01 ` [PATCH kexec-tools v2 31/32] arm: clean up phys/page offset debug Russell King 2016-06-06 17:01 ` Russell King 2016-06-06 17:01 ` [PATCH kexec-tools v2 32/32] arm: report which ELF core format we will use Russell King 2016-06-06 17:01 ` Russell King 2016-06-08 0:27 ` [PATCH kexec-tools v2 00/32] Keystone II updates for kexec tools Simon Horman 2016-06-08 0:27 ` Simon Horman
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20160607045515.GA13643@dhcppc6 \ --to=panand@redhat.com \ --cc=linux-arm-kernel@lists.infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.