kexec.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: Petr Tesarik <ptesarik@suse.com>
Cc: Atsushi Kumagai <ats-kumagai@wm.jp.nec.com>, kexec@lists.infradead.org
Subject: Re: [makedumpfile PATCH 1/2] Fix off-by-one errors in exclude_segment()
Date: Mon, 22 Jan 2018 16:20:06 +0800	[thread overview]
Message-ID: <20180122082006.GA6814@localhost.localdomain> (raw)
In-Reply-To: <ca842e328fcf6565a4cf0c8747367b3560d09412.1516354241.git.ptesarik@suse.com>

On 01/19/18 at 12:45pm, Petr Tesarik wrote:
> The crashed reserved memory end offset is the last address within
> range, whereas the end offset in the pt_loads[] denotes the first
> address past the range. This has caused a number of off-by-one
> errors in exclude_segment().
> 
> First, let's unify the meaning of "end" to be the first out-of-range
> address, i.e. start + size. Thanks to that, no +1 or -1 adjustments
> are needed in exclude_segment().
> 
> Second, since the value read from /proc/iomem is the last address
> within range, add one when passing it as an argument to
> exclude_segment(). This is now the only adjustment by one.
> 
> Signed-off-by: Petr Tesarik <ptesarik@suse.com>
> ---
>  elf_info.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/elf_info.c b/elf_info.c
> index 69b1719..1eaddd9 100644
> --- a/elf_info.c
> +++ b/elf_info.c
> @@ -820,26 +820,26 @@ static int exclude_segment(struct pt_load_segment **pt_loads,
>  		if (kvstart <  vend && kvend > vstart) {
>  			if (kvstart != vstart && kvend != vend) {
>  				/* Split load segment */
> -				temp_seg.phys_start = end + 1;
> +				temp_seg.phys_start = end;
>  				temp_seg.phys_end = (*pt_loads)[i].phys_end;
> -				temp_seg.virt_start = kvend + 1;
> +				temp_seg.virt_start = kvend;

Does the old code cause error? I remember I thought about this, forget
why I still took the old way.

Looks a good clean up.

>  				temp_seg.virt_end = vend;
>  				temp_seg.file_offset = (*pt_loads)[i].file_offset
>  					+ temp_seg.virt_start - (*pt_loads)[i].virt_start;
>  				temp_seg.file_size = temp_seg.phys_end
>  					- temp_seg.phys_start;
>  
> -				(*pt_loads)[i].virt_end = kvstart - 1;
> -				(*pt_loads)[i].phys_end =  start - 1;
> +				(*pt_loads)[i].virt_end = kvstart;
> +				(*pt_loads)[i].phys_end =  start;
>  				(*pt_loads)[i].file_size -= temp_seg.file_size;
>  
>  				tidx = i+1;
>  			} else if (kvstart != vstart) {
> -				(*pt_loads)[i].phys_end = start - 1;
> -				(*pt_loads)[i].virt_end = kvstart - 1;
> +				(*pt_loads)[i].phys_end = start;
> +				(*pt_loads)[i].virt_end = kvstart;
>  			} else {
> -				(*pt_loads)[i].phys_start = end + 1;
> -				(*pt_loads)[i].virt_start = kvend + 1;
> +				(*pt_loads)[i].phys_start = end;
> +				(*pt_loads)[i].virt_start = kvend;
>  			}
>  			(*pt_loads)[i].file_size -= (end -start);
>  		}
> @@ -917,7 +917,7 @@ int get_kcore_dump_loads(void)
>  
>  	for (i = 0; i < crash_reserved_mem_nr; i++)	{
>  		exclude_segment(&pt_loads, &num_pt_loads,
> -				crash_reserved_mem[i].start, crash_reserved_mem[i].end);
> +				crash_reserved_mem[i].start, crash_reserved_mem[i].end + 1);
>  	}
>  
>  	max_file_offset = 0;
> -- 
> 2.13.6
> 
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2018-01-22  8:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19 11:45 [makedumpfile PATCH 0/2] Fix calculations in exclude_segment() Petr Tesarik
2018-01-19 11:45 ` [makedumpfile PATCH 1/2] Fix off-by-one errors " Petr Tesarik
2018-01-22  8:20   ` Baoquan He [this message]
2018-01-19 11:45 ` [makedumpfile PATCH 2/2] Fix physical-to-virtual conversion " Petr Tesarik
2018-01-22  6:28 ` [makedumpfile PATCH 0/2] Fix calculations " Bhupesh Sharma
2018-01-23  6:28 ` Baoquan He
2018-01-23  8:49   ` Atsushi Kumagai
2018-01-25  9:15     ` Petr Tesarik

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=20180122082006.GA6814@localhost.localdomain \
    --to=bhe@redhat.com \
    --cc=ats-kumagai@wm.jp.nec.com \
    --cc=kexec@lists.infradead.org \
    --cc=ptesarik@suse.com \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).