Kernel Newbies archive on lore.kernel.org
 help / Atom feed
* Tracing memory address access in kernel
@ 2018-12-04 10:24 Pritam Bankar
  2018-12-04 13:23 ` Chriz Chow
  2018-12-07 19:49 ` Sudip Mukherjee
  0 siblings, 2 replies; 3+ messages in thread
From: Pritam Bankar @ 2018-12-04 10:24 UTC (permalink / raw)
  To: kernelnewbies

Hello,

I am facing issue of memory corruption where only one field of
allocated structure is getting corrupted. I have bio structure and one
of the page in bio vector is getting set to NULL.

crash> struct bio_vec 0xffff88009dc5eb00

struct bio_vec {
  bv_page = 0xffffea000a434b80,
  bv_len = 4096,
  bv_offset = 0
}

crash> struct bio_vec 0xffff88009dc5eb10
struct bio_vec {
  bv_page = 0x0,
  bv_len = 4096,
  bv_offset = 0

}

crash> struct bio_vec 0xffff88009dc5eb20
struct bio_vec {
  bv_page = 0xffffea000a467500,
  bv_len = 4096,
  bv_offset = 0

}

I have allocated contagious memory for bio vectors. As you can see in
second bio vector bv_page is getting set to NULL. This address is
valid till the time I do some operations in my module. After some
operations bv_page is getting set to NULL. Other fields are having
valid data.

Is there any debugging technique / tool available which will track
access to specific memory access?  I would like to dump stack every
time bv_page is accessed or modified

Thanks and regards,
Pritam Bankar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tracing memory address access in kernel
  2018-12-04 10:24 Tracing memory address access in kernel Pritam Bankar
@ 2018-12-04 13:23 ` Chriz Chow
  2018-12-07 19:49 ` Sudip Mukherjee
  1 sibling, 0 replies; 3+ messages in thread
From: Chriz Chow @ 2018-12-04 13:23 UTC (permalink / raw)
  To: Pritam Bankar; +Cc: kernelnewbies

Hello Pritam,

You may try moving or enlarging the bio_vec first, to see if the NULL is set due to memory corruption, or due to some other bugs.

Next, try to insmod one by one to locate it. Adding some printk() next to the suspicious memcpy() also helps.

I am also a newbie so I would also like to know if there’s any other good ways. :)

Chriz.

> El 4 dic 2018, a las 6:24 p. m., Pritam Bankar <pritambankar1988@gmail.com> escribió:
> 
> Hello,
> 
> I am facing issue of memory corruption where only one field of
> allocated structure is getting corrupted. I have bio structure and one
> of the page in bio vector is getting set to NULL.
> 
> crash> struct bio_vec 0xffff88009dc5eb00
> 
> struct bio_vec {
>  bv_page = 0xffffea000a434b80,
>  bv_len = 4096,
>  bv_offset = 0
> }
> 
> crash> struct bio_vec 0xffff88009dc5eb10
> struct bio_vec {
>  bv_page = 0x0,
>  bv_len = 4096,
>  bv_offset = 0
> 
> }
> 
> crash> struct bio_vec 0xffff88009dc5eb20
> struct bio_vec {
>  bv_page = 0xffffea000a467500,
>  bv_len = 4096,
>  bv_offset = 0
> 
> }
> 
> I have allocated contagious memory for bio vectors. As you can see in
> second bio vector bv_page is getting set to NULL. This address is
> valid till the time I do some operations in my module. After some
> operations bv_page is getting set to NULL. Other fields are having
> valid data.
> 
> Is there any debugging technique / tool available which will track
> access to specific memory access?  I would like to dump stack every
> time bv_page is accessed or modified
> 
> Thanks and regards,
> Pritam Bankar
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tracing memory address access in kernel
  2018-12-04 10:24 Tracing memory address access in kernel Pritam Bankar
  2018-12-04 13:23 ` Chriz Chow
@ 2018-12-07 19:49 ` Sudip Mukherjee
  1 sibling, 0 replies; 3+ messages in thread
From: Sudip Mukherjee @ 2018-12-07 19:49 UTC (permalink / raw)
  To: pritambankar1988; +Cc: kernelnewbies

Hi Pritam,

On Tue, Dec 4, 2018 at 10:26 AM Pritam Bankar
<pritambankar1988@gmail.com> wrote:
>
> Hello,
>
> I am facing issue of memory corruption where only one field of
> allocated structure is getting corrupted. I have bio structure and one
> of the page in bio vector is getting set to NULL.
>
<snip>
>
> Is there any debugging technique / tool available which will track
> access to specific memory access?  I would like to dump stack every
> time bv_page is accessed or modified

In these types of cases I usually use KASAN, or HW Breakpoint.
with HW Breakpoint you can set an alert to monitor any read or write
operation on some memory location. Check
samples/hw_breakpoint/data_breakpoint.c for an example of breakpoints.
KASAN can give you stacktraces when illegal memory access is done.
Hope it helps.

-- 
Regards
Sudip

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-04 10:24 Tracing memory address access in kernel Pritam Bankar
2018-12-04 13:23 ` Chriz Chow
2018-12-07 19:49 ` Sudip Mukherjee

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox