Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
* Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
@ 2019-09-24 10:10 Sahibzada Irfanullah
  2019-09-24 11:16 ` Valdis Klētnieks
  2019-09-24 13:29 ` Greg KH
  0 siblings, 2 replies; 15+ messages in thread
From: Sahibzada Irfanullah @ 2019-09-24 10:10 UTC (permalink / raw)
  To: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1150 bytes --]

Dear All,

I have asked this question previously, but some people told me to explain
what I really want to do. First of all, I am completely naïve andnewbie in
the kernel development.

I am trying to develop my own program that generate the log of guest
physical addresses by trying to save the contents of "gpa" variable (which
is present in the handle_ept_violation()functino in vmx.c ) into my file. I
have found one sample code online (which uses filp_open(), filp_close(),
kernel_read(), and kernel_write() functions), this code is working in the
kernel space as a kernel module, but not working for my task in the
handle_ept_voilation().

My actual goal is to generate log of physical addresses for different
applications by writing them into the file, and then perform some analysis
at runtime in this function by reading the logs from the log file.
Furthermore, I want a file which size can dynamically grow as the size of
log increases.

I know that reading/writing in a kernel is not a good idea, but due to
nature of the task, I have to this.

Thank you very much for your help.
-- 
Regards,

*Mr. Irfanullah*

[-- Attachment #1.2: Type: text/html, Size: 2828 bytes --]

<div dir="ltr"><div><span style="font-family:&quot;Times New Roman&quot;,serif;font-size:12pt">Dear All,</span><br></div><div>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">I have asked this question
previously, but some people told me to explain what I really want to do. First
of all, I am completely naïve andnewbie in the kernel development. </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">I am trying to develop my own
program that generate the log of guest physical addresses by trying
to save the contents of &quot;gpa&quot; variable (which is present in the
handle_ept_violation()functino in vmx.c ) into my file. I have found one sample
code online (which uses filp_open(), filp_close(), kernel_read(), and
kernel_write() functions), this code is working in the kernel space as a kernel
module, but not working for my task in the handle_ept_voilation(). </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">My actual goal is to generate log of
physical addresses for different applications by writing them into the file,
and then perform some analysis at runtime in this function by reading the logs
from the log file. Furthermore, I want a file which size can dynamically grow
as the size of log increases. </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">I know that reading/writing in a
kernel is not a good idea, but due to nature of the task, I have to this.</span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:&quot;Times New Roman&quot;,serif">Thank you very much for your help.</span></p></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><span style="font-size:12.8px;color:rgb(80,0,80)"><b>Mr. Irfanullah</b></span></div><div style="font-size:12.8px"><div style="font-size:12.8px"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-24 10:10 Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime Sahibzada Irfanullah
@ 2019-09-24 11:16 ` Valdis Klētnieks
  2019-09-24 11:26   ` Sahibzada Irfanullah
  2019-09-24 13:29 ` Greg KH
  1 sibling, 1 reply; 15+ messages in thread
From: Valdis Klētnieks @ 2019-09-24 11:16 UTC (permalink / raw)
  To: Sahibzada Irfanullah; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 850 bytes --]

On Tue, 24 Sep 2019 19:10:59 +0900, Sahibzada Irfanullah said:

> My actual goal is to generate log of physical addresses for different
> applications by writing them into the file, and then perform some analysis

What makes you think that the log of physical addresses will tell you anything
useful or interesting?

Hint:  Pretty much all physical pages usable for process space are identical as far
as the kernel is concerned, and if a virtual or disk cache page is pulled into memory
from disk more than once, the same virtual page can end up in different physical
pages.each time.

> at runtime in this function by reading the logs from the log file.
> Furthermore, I want a file which size can dynamically grow as the size of
> log increases.

Are you trying to do this *at runtime in real time*, or is post-run analysis OK?


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-24 11:16 ` Valdis Klētnieks
@ 2019-09-24 11:26   ` Sahibzada Irfanullah
  2019-09-24 18:55     ` Valdis Klētnieks
  0 siblings, 1 reply; 15+ messages in thread
From: Sahibzada Irfanullah @ 2019-09-24 11:26 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1261 bytes --]

Thank you for your response.
After having a reasonable amount  of log data, I want to perform some type
of analsys at run time, e.g., no. of unique addresses, total no. of
addresses, frequency of occurences of each addresses etc.

On Tue, 24 Sep 2019 at 20:16, Valdis Klētnieks <valdis.kletnieks@vt.edu>
wrote:

> On Tue, 24 Sep 2019 19:10:59 +0900, Sahibzada Irfanullah said:
>
> > My actual goal is to generate log of physical addresses for different
> > applications by writing them into the file, and then perform some
> analysis
>
> What makes you think that the log of physical addresses will tell you
> anything
> useful or interesting?
>
> Hint:  Pretty much all physical pages usable for process space are
> identical as far
> as the kernel is concerned, and if a virtual or disk cache page is pulled
> into memory
> from disk more than once, the same virtual page can end up in different
> physical
> pages.each time.
>
> > at runtime in this function by reading the logs from the log file.
> > Furthermore, I want a file which size can dynamically grow as the size of
> > log increases.
>
> Are you trying to do this *at runtime in real time*, or is post-run
> analysis OK?
>
>

-- 
Regards,

*Mr. Irfanullah*

[-- Attachment #1.2: Type: text/html, Size: 2098 bytes --]

<div dir="ltr">Thank you for your response.<div>After having a reasonable amount  of log data, I want to perform some type of analsys at run time, e.g., no. of unique addresses, total no. of addresses, frequency of occurences of each addresses etc.   </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 24 Sep 2019 at 20:16, Valdis Klētnieks &lt;<a href="mailto:valdis.kletnieks@vt.edu">valdis.kletnieks@vt.edu</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 24 Sep 2019 19:10:59 +0900, Sahibzada Irfanullah said:<br>
<br>
&gt; My actual goal is to generate log of physical addresses for different<br>
&gt; applications by writing them into the file, and then perform some analysis<br>
<br>
What makes you think that the log of physical addresses will tell you anything<br>
useful or interesting?<br>
<br>
Hint:  Pretty much all physical pages usable for process space are identical as far<br>
as the kernel is concerned, and if a virtual or disk cache page is pulled into memory<br>
from disk more than once, the same virtual page can end up in different physical<br>
pages.each time.<br>
<br>
&gt; at runtime in this function by reading the logs from the log file.<br>
&gt; Furthermore, I want a file which size can dynamically grow as the size of<br>
&gt; log increases.<br>
<br>
Are you trying to do this *at runtime in real time*, or is post-run analysis OK?<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><span style="font-size:12.8px;color:rgb(80,0,80)"><b>Mr. Irfanullah</b></span></div><div style="font-size:12.8px"><div style="font-size:12.8px"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-24 10:10 Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime Sahibzada Irfanullah
  2019-09-24 11:16 ` Valdis Klētnieks
@ 2019-09-24 13:29 ` Greg KH
  1 sibling, 0 replies; 15+ messages in thread
From: Greg KH @ 2019-09-24 13:29 UTC (permalink / raw)
  To: Sahibzada Irfanullah; +Cc: kernelnewbies

On Tue, Sep 24, 2019 at 07:10:59PM +0900, Sahibzada Irfanullah wrote:
> Dear All,
> 
> I have asked this question previously, but some people told me to explain
> what I really want to do. First of all, I am completely naïve andnewbie in
> the kernel development.
> 
> I am trying to develop my own program that generate the log of guest
> physical addresses by trying to save the contents of "gpa" variable (which
> is present in the handle_ept_violation()functino in vmx.c ) into my file. I
> have found one sample code online (which uses filp_open(), filp_close(),
> kernel_read(), and kernel_write() functions), this code is working in the
> kernel space as a kernel module, but not working for my task in the
> handle_ept_voilation().
> 
> My actual goal is to generate log of physical addresses for different
> applications by writing them into the file, and then perform some analysis
> at runtime in this function by reading the logs from the log file.
> Furthermore, I want a file which size can dynamically grow as the size of
> log increases.
> 
> I know that reading/writing in a kernel is not a good idea, but due to
> nature of the task, I have to this.

"have to"?

What about a ring buffer that you write to in the kernel and then read
out from in userspace?  You can use debugfs for that.

But really, a simple tracepoint is probably all you need here, and maybe
not even that if you use ftrace.  Have you tried that today?  I doubt
you need any kernel changes at all to get this information directly from
the kernel to userspace.  Look at all of the ebpf and tracing examples
as a way to do this.

good luck!

greg k-h

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-24 11:26   ` Sahibzada Irfanullah
@ 2019-09-24 18:55     ` Valdis Klētnieks
  2019-09-25  2:44       ` Sahibzada Irfanullah
  0 siblings, 1 reply; 15+ messages in thread
From: Valdis Klētnieks @ 2019-09-24 18:55 UTC (permalink / raw)
  To: Sahibzada Irfanullah; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 3329 bytes --]

On Tue, 24 Sep 2019 20:26:36 +0900, Sahibzada Irfanullah said:

> After having a reasonable amount  of log data,

If you're trying to figure out how the kernel memory manager is working, you're
probably better off using 'perf'  or one of the other tracing tools already in
the kernel to track the kernel memory manager. For starters, you can get those
tools to give you things like stack tracebacks so you know who is asking for a
page, and who is *releasing* a page, and so on.

Of course, which of these tools to use depends on what data you need to answer
the question - but simply knowing what physical address was involved in a page
fault is almost certainly not going to be sufficient.

> I want to perform some type of analsys at run time, e.g., no. of unique
> addresses, total no. of addresses, frequency of occurences of each addresses
> etc.

So what "some type of analysis" are you trying to do? What question(s)
are you trying to answer? 

The number of unique physical addresses in your system is dictated by how much
RAM you have installed. Similarly for total number of addresses, although I'm
not sure why you list both - that would mean that there is some number of
non-unique addresses.  What would that even mean?

The number of pages actually available for paging and caching depends on other
things as well - the architecture of the system, how much RAM (if any) is
reserved for use by your video card, the size of the kernel, the size of loaded
modules, space taken up by kmalloc allocations, page tables, whether any
processes have called mlock() on a large chunk of space, whether the pages are
locked by the kernel because there's I/O going on, and then there's things like
mmap(), and so on.

The kernel provides /proc/meminfo and /proc/slabinfo - you're going to want
to understand all that stuff before you can make sense of anything.

Simply looking at the frequency of occurrences of each address is probably not
going to tell you much of anything, because you need to know things like
the total working and resident set sizes for the process and other context.

For example - you do the analysis, and find that there are 8 gigabytes of pages
that are constantly being re-used.  But that doesn't tell you if there are two
processes that are thrashing against each other because each is doing heavy
repeated referencing of 6 gigabytes of data, or if one process is wildly referencing
many pages because some programmer has a multi-dimensional array and is
walking across the array with the indices in the wrong order

i_max = 4095; j_max = 4095;
for (i = 0, i < i_max; i++) for j = 0, j < j_max; j++) {sum += foo[i][j]}

If somebdy is doing foo[j][i] instead, things can get ugly.  And if you're
mixing with Fortran code, where the semantics of array references is reverse
and you *want* to use 'foo[j][i]' for efficient memory access, it's a bullet loaded
in the chamber and waiting for somebody to pull the trigger.

Not that I've ever seen *that* particular error happen with a programmer
processing 2 terabytes of arrays on a machine that only had 1.5 terabytes of
RAM.  But I did tease the person involved about it, because they *really*
should have known better. :)

So again:  What question(s) are you trying to get answers to?


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-24 18:55     ` Valdis Klētnieks
@ 2019-09-25  2:44       ` Sahibzada Irfanullah
  2019-09-25  7:00         ` Sahibzada Irfanullah
  0 siblings, 1 reply; 15+ messages in thread
From: Sahibzada Irfanullah @ 2019-09-25  2:44 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 6341 bytes --]

1 > Have you tried that today?  I doubt you need any kernel changes at all
to get this information directly from the kernel to userspace.
I also feel the same. Because I have to written these information to the
file, as well as read from the file in the same kernel function, i.e,
handle_ept_voilation(). I want the file which stores text (e.g., CSV), not
bytes so that I can also open it using Open Office etc.
Thanks. I will try ftrace, and debugfs. I am not sure ftrace, but may be
debugfs may help some what.

2 > For starters, you can get those tools to give you things like stack
tracebacks so you know who is asking for a page, and who is *releasing* a
page, and so on
At the start my goal is to generating log of physical addresses involved in
page faults. Further, I will extend my program to store other informations
to the file, like as you said, which process is requesting/releasing the
page, and which instruction address refered to which memory reference which
was not present in the memory, how many times an address was involved in a
page fault etc.)

3 > So what "some type of analysis" are you trying to do? What question(s)
are you trying to answer?
   Uptill now I want to perform simple analysis mentioned in the above
question 2. Morevoer, this analysis will provide details about the
instruction address that is responsible for page fault along with memory
reference that is no present, the appliction that generated this page
fault, and for a single address how many times a page fault occured etc.
By unique and non-unique, I  meant the list of addresses in the log without
duplication. For example, we have log of addresses
[1,2,2,3,3,4,3,3,4,4,4,1, 4]. In this list unique addresses are 1,2,3,4,
and frquency of each address is 2,2, 4,5 respectively.   At this stage I
want to keep things very simple by ignoring the details like size of the
RAM, size of kernel, size of loaded modules etc. Briefly I can say I want
to generate the log for guest physical addresses involved in page fault,
the corresponding instruction address, coressponsing logical address, along
with the corresponding application.

At the first stage, I am trying to develope an application that provides
some basic functionalities (i.e., instruction instrumentation) of Pin Tool
<https://software.intel.com/sites/landingpage/pintool/docs/71313/Pin/html/index.html#EXAMPLES>
for
just guest physical address by tracing instruction addresses, memory
referencees, and save it to the file. And the file can not only be
accessible from within the kernel, but also can be opened using any word
processing application ,e.g., csv or .txt file.
Thank you very much for the help.


On Wed, 25 Sep 2019 at 03:55, Valdis Klētnieks <valdis.kletnieks@vt.edu>
wrote:

> On Tue, 24 Sep 2019 20:26:36 +0900, Sahibzada Irfanullah said:
>
> > After having a reasonable amount  of log data,
>
> If you're trying to figure out how the kernel memory manager is working,
> you're
> probably better off using 'perf'  or one of the other tracing tools
> already in
> the kernel to track the kernel memory manager. For starters, you can get
> those
> tools to give you things like stack tracebacks so you know who is asking
> for a
> page, and who is *releasing* a page, and so on.
>
> Of course, which of these tools to use depends on what data you need to
> answer
> the question - but simply knowing what physical address was involved in a
> page
> fault is almost certainly not going to be sufficient.
>
> > I want to perform some type of analsys at run time, e.g., no. of unique
> > addresses, total no. of addresses, frequency of occurences of each
> addresses
> > etc.
>
> So what "some type of analysis" are you trying to do? What question(s)
> are you trying to answer?
>
> The number of unique physical addresses in your system is dictated by how
> much
> RAM you have installed. Similarly for total number of addresses, although
> I'm
> not sure why you list both - that would mean that there is some number of
> non-unique addresses.  What would that even mean?
>
> The number of pages actually available for paging and caching depends on
> other
> things as well - the architecture of the system, how much RAM (if any) is
> reserved for use by your video card, the size of the kernel, the size of
> loaded
> modules, space taken up by kmalloc allocations, page tables, whether any
> processes have called mlock() on a large chunk of space, whether the pages
> are
> locked by the kernel because there's I/O going on, and then there's things
> like
> mmap(), and so on.
>
> The kernel provides /proc/meminfo and /proc/slabinfo - you're going to want
> to understand all that stuff before you can make sense of anything.
>
> Simply looking at the frequency of occurrences of each address is probably
> not
> going to tell you much of anything, because you need to know things like
> the total working and resident set sizes for the process and other context.
>
> For example - you do the analysis, and find that there are 8 gigabytes of
> pages
> that are constantly being re-used.  But that doesn't tell you if there are
> two
> processes that are thrashing against each other because each is doing heavy
> repeated referencing of 6 gigabytes of data, or if one process is wildly
> referencing
> many pages because some programmer has a multi-dimensional array and is
> walking across the array with the indices in the wrong order
>
> i_max = 4095; j_max = 4095;
> for (i = 0, i < i_max; i++) for j = 0, j < j_max; j++) {sum += foo[i][j]}
>
> If somebdy is doing foo[j][i] instead, things can get ugly.  And if you're
> mixing with Fortran code, where the semantics of array references is
> reverse
> and you *want* to use 'foo[j][i]' for efficient memory access, it's a
> bullet loaded
> in the chamber and waiting for somebody to pull the trigger.
>
> Not that I've ever seen *that* particular error happen with a programmer
> processing 2 terabytes of arrays on a machine that only had 1.5 terabytes
> of
> RAM.  But I did tease the person involved about it, because they *really*
> should have known better. :)
>
> So again:  What question(s) are you trying to get answers to?
>
>

-- 
Regards,

*Mr. Irfanullah*

[-- Attachment #1.2: Type: text/html, Size: 7591 bytes --]

<div dir="ltr"><div><font color="#741b47">1 &gt; Have you tried that today?  I doubt you need any kernel changes at all to get this information directly from the kernel to userspace. </font><font color="#c27ba0"> </font><br></div><div>I also feel the same. Because I have to written these information to the file, as well as read from the file in the same kernel function, i.e, handle_ept_voilation(). I want the file which stores text (e.g., CSV), not bytes so that I can also open it using Open Office etc. </div><div>Thanks. I will try ftrace, and debugfs. I am not sure ftrace, but may be debugfs may help some what.</div><div><br></div><div><font color="#741b47">2 &gt; For starters, you can get those tools to give you things like stack tracebacks so you know who is asking for a page, and who is *releasing* a page, and so on</font> </div><div>At the start my goal is to generating log of physical addresses involved in page faults. Further, I will extend my program to store other informations to the file, like as you said, which process is requesting/releasing the page, and which instruction address refered to which memory reference which was not present in the memory, how many times an address was involved in a page fault etc.)</div><div><br></div><div><font color="#741b47">3 &gt; So what &quot;some type of analysis&quot; are you trying to do? What question(s) are you trying to answer?</font></div><div>   Uptill now I want to perform simple analysis mentioned in the above question 2. Morevoer, this analysis will provide details about the instruction address that is responsible for page fault along with memory reference that is no present, the appliction that generated this page fault, and for a single address how many times a page fault occured etc.  </div><div>By unique and non-unique, I  meant the list of addresses in the log without duplication. For example, we have log of addresses [1,2,2,3,3,4,3,3,4,4,4,1, 4]. In this list unique addresses are 1,2,3,4, and frquency of each address is 2,2, 4,5 respectively.   At this stage I want to keep things very simple by ignoring the details like size of the RAM, size of kernel, size of loaded modules etc. Briefly I can say I want to generate the log for guest physical addresses involved in page fault, the corresponding instruction address, coressponsing logical address, along with the corresponding application. <br></div><div><br></div><div>At the first stage, I am trying to develope an application that provides some basic functionalities (i.e., instruction instrumentation) of <a href="https://software.intel.com/sites/landingpage/pintool/docs/71313/Pin/html/index.html#EXAMPLES">Pin Tool</a> for just guest physical address by tracing instruction addresses, memory referencees, and save it to the file. And the file can not only be accessible from within the kernel, but also can be opened using any word processing application ,e.g., csv or .txt file.<br></div><div>Thank you very much for the help.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 25 Sep 2019 at 03:55, Valdis Klētnieks &lt;<a href="mailto:valdis.kletnieks@vt.edu">valdis.kletnieks@vt.edu</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 24 Sep 2019 20:26:36 +0900, Sahibzada Irfanullah said:<br>
<br>
&gt; After having a reasonable amount  of log data,<br>
<br>
If you&#39;re trying to figure out how the kernel memory manager is working, you&#39;re<br>
probably better off using &#39;perf&#39;  or one of the other tracing tools already in<br>
the kernel to track the kernel memory manager. For starters, you can get those<br>
tools to give you things like stack tracebacks so you know who is asking for a<br>
page, and who is *releasing* a page, and so on.<br>
<br>
Of course, which of these tools to use depends on what data you need to answer<br>
the question - but simply knowing what physical address was involved in a page<br>
fault is almost certainly not going to be sufficient.<br>
<br>
&gt; I want to perform some type of analsys at run time, e.g., no. of unique<br>
&gt; addresses, total no. of addresses, frequency of occurences of each addresses<br>
&gt; etc.<br>
<br>
So what &quot;some type of analysis&quot; are you trying to do? What question(s)<br>
are you trying to answer? <br>
<br>
The number of unique physical addresses in your system is dictated by how much<br>
RAM you have installed. Similarly for total number of addresses, although I&#39;m<br>
not sure why you list both - that would mean that there is some number of<br>
non-unique addresses.  What would that even mean?<br>
<br>
The number of pages actually available for paging and caching depends on other<br>
things as well - the architecture of the system, how much RAM (if any) is<br>
reserved for use by your video card, the size of the kernel, the size of loaded<br>
modules, space taken up by kmalloc allocations, page tables, whether any<br>
processes have called mlock() on a large chunk of space, whether the pages are<br>
locked by the kernel because there&#39;s I/O going on, and then there&#39;s things like<br>
mmap(), and so on.<br>
<br>
The kernel provides /proc/meminfo and /proc/slabinfo - you&#39;re going to want<br>
to understand all that stuff before you can make sense of anything.<br>
<br>
Simply looking at the frequency of occurrences of each address is probably not<br>
going to tell you much of anything, because you need to know things like<br>
the total working and resident set sizes for the process and other context.<br>
<br>
For example - you do the analysis, and find that there are 8 gigabytes of pages<br>
that are constantly being re-used.  But that doesn&#39;t tell you if there are two<br>
processes that are thrashing against each other because each is doing heavy<br>
repeated referencing of 6 gigabytes of data, or if one process is wildly referencing<br>
many pages because some programmer has a multi-dimensional array and is<br>
walking across the array with the indices in the wrong order<br>
<br>
i_max = 4095; j_max = 4095;<br>
for (i = 0, i &lt; i_max; i++) for j = 0, j &lt; j_max; j++) {sum += foo[i][j]}<br>
<br>
If somebdy is doing foo[j][i] instead, things can get ugly.  And if you&#39;re<br>
mixing with Fortran code, where the semantics of array references is reverse<br>
and you *want* to use &#39;foo[j][i]&#39; for efficient memory access, it&#39;s a bullet loaded<br>
in the chamber and waiting for somebody to pull the trigger.<br>
<br>
Not that I&#39;ve ever seen *that* particular error happen with a programmer<br>
processing 2 terabytes of arrays on a machine that only had 1.5 terabytes of<br>
RAM.  But I did tease the person involved about it, because they *really*<br>
should have known better. :)<br>
<br>
So again:  What question(s) are you trying to get answers to?<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><span style="font-size:12.8px;color:rgb(80,0,80)"><b>Mr. Irfanullah</b></span></div><div style="font-size:12.8px"><div style="font-size:12.8px"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25  2:44       ` Sahibzada Irfanullah
@ 2019-09-25  7:00         ` Sahibzada Irfanullah
  2019-09-25  9:38           ` Greg KH
  0 siblings, 1 reply; 15+ messages in thread
From: Sahibzada Irfanullah @ 2019-09-25  7:00 UTC (permalink / raw)
  To: Valdis Klētnieks, greg; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 7012 bytes --]

I am sorry if I am bothering you.
I have read this article
<http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html>,
I have to ask that will Netlink socket work for my task; Storing the
contents of "gpa" variable (which is present in the
handle_ept_violation()functino in vmx.c ) into a file.
Thank you.

On Wed, 25 Sep 2019 at 11:44, Sahibzada Irfanullah <irfan.gomalian@gmail.com>
wrote:

> 1 > Have you tried that today?  I doubt you need any kernel changes at all
> to get this information directly from the kernel to userspace.
> I also feel the same. Because I have to written these information to the
> file, as well as read from the file in the same kernel function, i.e,
> handle_ept_voilation(). I want the file which stores text (e.g., CSV), not
> bytes so that I can also open it using Open Office etc.
> Thanks. I will try ftrace, and debugfs. I am not sure ftrace, but may be
> debugfs may help some what.
>
> 2 > For starters, you can get those tools to give you things like stack
> tracebacks so you know who is asking for a page, and who is *releasing* a
> page, and so on
> At the start my goal is to generating log of physical addresses involved
> in page faults. Further, I will extend my program to store other
> informations to the file, like as you said, which process is
> requesting/releasing the page, and which instruction address refered to
> which memory reference which was not present in the memory, how many times
> an address was involved in a page fault etc.)
>
> 3 > So what "some type of analysis" are you trying to do? What question(s)
> are you trying to answer?
>    Uptill now I want to perform simple analysis mentioned in the above
> question 2. Morevoer, this analysis will provide details about the
> instruction address that is responsible for page fault along with memory
> reference that is no present, the appliction that generated this page
> fault, and for a single address how many times a page fault occured etc.
> By unique and non-unique, I  meant the list of addresses in the log
> without duplication. For example, we have log of addresses
> [1,2,2,3,3,4,3,3,4,4,4,1, 4]. In this list unique addresses are 1,2,3,4,
> and frquency of each address is 2,2, 4,5 respectively.   At this stage I
> want to keep things very simple by ignoring the details like size of the
> RAM, size of kernel, size of loaded modules etc. Briefly I can say I want
> to generate the log for guest physical addresses involved in page fault,
> the corresponding instruction address, coressponsing logical address, along
> with the corresponding application.
>
> At the first stage, I am trying to develope an application that provides
> some basic functionalities (i.e., instruction instrumentation) of Pin Tool
> <https://software.intel.com/sites/landingpage/pintool/docs/71313/Pin/html/index.html#EXAMPLES> for
> just guest physical address by tracing instruction addresses, memory
> referencees, and save it to the file. And the file can not only be
> accessible from within the kernel, but also can be opened using any word
> processing application ,e.g., csv or .txt file.
> Thank you very much for the help.
>
>
> On Wed, 25 Sep 2019 at 03:55, Valdis Klētnieks <valdis.kletnieks@vt.edu>
> wrote:
>
>> On Tue, 24 Sep 2019 20:26:36 +0900, Sahibzada Irfanullah said:
>>
>> > After having a reasonable amount  of log data,
>>
>> If you're trying to figure out how the kernel memory manager is working,
>> you're
>> probably better off using 'perf'  or one of the other tracing tools
>> already in
>> the kernel to track the kernel memory manager. For starters, you can get
>> those
>> tools to give you things like stack tracebacks so you know who is asking
>> for a
>> page, and who is *releasing* a page, and so on.
>>
>> Of course, which of these tools to use depends on what data you need to
>> answer
>> the question - but simply knowing what physical address was involved in a
>> page
>> fault is almost certainly not going to be sufficient.
>>
>> > I want to perform some type of analsys at run time, e.g., no. of unique
>> > addresses, total no. of addresses, frequency of occurences of each
>> addresses
>> > etc.
>>
>> So what "some type of analysis" are you trying to do? What question(s)
>> are you trying to answer?
>>
>> The number of unique physical addresses in your system is dictated by how
>> much
>> RAM you have installed. Similarly for total number of addresses, although
>> I'm
>> not sure why you list both - that would mean that there is some number of
>> non-unique addresses.  What would that even mean?
>>
>> The number of pages actually available for paging and caching depends on
>> other
>> things as well - the architecture of the system, how much RAM (if any) is
>> reserved for use by your video card, the size of the kernel, the size of
>> loaded
>> modules, space taken up by kmalloc allocations, page tables, whether any
>> processes have called mlock() on a large chunk of space, whether the
>> pages are
>> locked by the kernel because there's I/O going on, and then there's
>> things like
>> mmap(), and so on.
>>
>> The kernel provides /proc/meminfo and /proc/slabinfo - you're going to
>> want
>> to understand all that stuff before you can make sense of anything.
>>
>> Simply looking at the frequency of occurrences of each address is
>> probably not
>> going to tell you much of anything, because you need to know things like
>> the total working and resident set sizes for the process and other
>> context.
>>
>> For example - you do the analysis, and find that there are 8 gigabytes of
>> pages
>> that are constantly being re-used.  But that doesn't tell you if there
>> are two
>> processes that are thrashing against each other because each is doing
>> heavy
>> repeated referencing of 6 gigabytes of data, or if one process is wildly
>> referencing
>> many pages because some programmer has a multi-dimensional array and is
>> walking across the array with the indices in the wrong order
>>
>> i_max = 4095; j_max = 4095;
>> for (i = 0, i < i_max; i++) for j = 0, j < j_max; j++) {sum += foo[i][j]}
>>
>> If somebdy is doing foo[j][i] instead, things can get ugly.  And if you're
>> mixing with Fortran code, where the semantics of array references is
>> reverse
>> and you *want* to use 'foo[j][i]' for efficient memory access, it's a
>> bullet loaded
>> in the chamber and waiting for somebody to pull the trigger.
>>
>> Not that I've ever seen *that* particular error happen with a programmer
>> processing 2 terabytes of arrays on a machine that only had 1.5 terabytes
>> of
>> RAM.  But I did tease the person involved about it, because they *really*
>> should have known better. :)
>>
>> So again:  What question(s) are you trying to get answers to?
>>
>>
>
> --
> Regards,
>
> *Mr. Irfanullah*
>
>

-- 
Regards,

*Mr. Irfanullah*

[-- Attachment #1.2: Type: text/html, Size: 8952 bytes --]

<div dir="ltr">I am sorry if I am bothering you.<div>I have read <a href="http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html">this article</a>, I have to ask that will Netlink socket work for my task; Storing<font color="#000000"> the contents of &quot;gpa&quot; variable (which is present in the handle_ept_violation()functino in vmx.c ) into a file.</font></div><div><font color="#000000">Thank you.</font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 25 Sep 2019 at 11:44, Sahibzada Irfanullah &lt;<a href="mailto:irfan.gomalian@gmail.com">irfan.gomalian@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><font color="#741b47">1 &gt; Have you tried that today?  I doubt you need any kernel changes at all to get this information directly from the kernel to userspace. </font><font color="#c27ba0"> </font><br></div><div>I also feel the same. Because I have to written these information to the file, as well as read from the file in the same kernel function, i.e, handle_ept_voilation(). I want the file which stores text (e.g., CSV), not bytes so that I can also open it using Open Office etc. </div><div>Thanks. I will try ftrace, and debugfs. I am not sure ftrace, but may be debugfs may help some what.</div><div><br></div><div><font color="#741b47">2 &gt; For starters, you can get those tools to give you things like stack tracebacks so you know who is asking for a page, and who is *releasing* a page, and so on</font> </div><div>At the start my goal is to generating log of physical addresses involved in page faults. Further, I will extend my program to store other informations to the file, like as you said, which process is requesting/releasing the page, and which instruction address refered to which memory reference which was not present in the memory, how many times an address was involved in a page fault etc.)</div><div><br></div><div><font color="#741b47">3 &gt; So what &quot;some type of analysis&quot; are you trying to do? What question(s) are you trying to answer?</font></div><div>   Uptill now I want to perform simple analysis mentioned in the above question 2. Morevoer, this analysis will provide details about the instruction address that is responsible for page fault along with memory reference that is no present, the appliction that generated this page fault, and for a single address how many times a page fault occured etc.  </div><div>By unique and non-unique, I  meant the list of addresses in the log without duplication. For example, we have log of addresses [1,2,2,3,3,4,3,3,4,4,4,1, 4]. In this list unique addresses are 1,2,3,4, and frquency of each address is 2,2, 4,5 respectively.   At this stage I want to keep things very simple by ignoring the details like size of the RAM, size of kernel, size of loaded modules etc. Briefly I can say I want to generate the log for guest physical addresses involved in page fault, the corresponding instruction address, coressponsing logical address, along with the corresponding application. <br></div><div><br></div><div>At the first stage, I am trying to develope an application that provides some basic functionalities (i.e., instruction instrumentation) of <a href="https://software.intel.com/sites/landingpage/pintool/docs/71313/Pin/html/index.html#EXAMPLES" target="_blank">Pin Tool</a> for just guest physical address by tracing instruction addresses, memory referencees, and save it to the file. And the file can not only be accessible from within the kernel, but also can be opened using any word processing application ,e.g., csv or .txt file.<br></div><div>Thank you very much for the help.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 25 Sep 2019 at 03:55, Valdis Klētnieks &lt;<a href="mailto:valdis.kletnieks@vt.edu" target="_blank">valdis.kletnieks@vt.edu</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 24 Sep 2019 20:26:36 +0900, Sahibzada Irfanullah said:<br>
<br>
&gt; After having a reasonable amount  of log data,<br>
<br>
If you&#39;re trying to figure out how the kernel memory manager is working, you&#39;re<br>
probably better off using &#39;perf&#39;  or one of the other tracing tools already in<br>
the kernel to track the kernel memory manager. For starters, you can get those<br>
tools to give you things like stack tracebacks so you know who is asking for a<br>
page, and who is *releasing* a page, and so on.<br>
<br>
Of course, which of these tools to use depends on what data you need to answer<br>
the question - but simply knowing what physical address was involved in a page<br>
fault is almost certainly not going to be sufficient.<br>
<br>
&gt; I want to perform some type of analsys at run time, e.g., no. of unique<br>
&gt; addresses, total no. of addresses, frequency of occurences of each addresses<br>
&gt; etc.<br>
<br>
So what &quot;some type of analysis&quot; are you trying to do? What question(s)<br>
are you trying to answer? <br>
<br>
The number of unique physical addresses in your system is dictated by how much<br>
RAM you have installed. Similarly for total number of addresses, although I&#39;m<br>
not sure why you list both - that would mean that there is some number of<br>
non-unique addresses.  What would that even mean?<br>
<br>
The number of pages actually available for paging and caching depends on other<br>
things as well - the architecture of the system, how much RAM (if any) is<br>
reserved for use by your video card, the size of the kernel, the size of loaded<br>
modules, space taken up by kmalloc allocations, page tables, whether any<br>
processes have called mlock() on a large chunk of space, whether the pages are<br>
locked by the kernel because there&#39;s I/O going on, and then there&#39;s things like<br>
mmap(), and so on.<br>
<br>
The kernel provides /proc/meminfo and /proc/slabinfo - you&#39;re going to want<br>
to understand all that stuff before you can make sense of anything.<br>
<br>
Simply looking at the frequency of occurrences of each address is probably not<br>
going to tell you much of anything, because you need to know things like<br>
the total working and resident set sizes for the process and other context.<br>
<br>
For example - you do the analysis, and find that there are 8 gigabytes of pages<br>
that are constantly being re-used.  But that doesn&#39;t tell you if there are two<br>
processes that are thrashing against each other because each is doing heavy<br>
repeated referencing of 6 gigabytes of data, or if one process is wildly referencing<br>
many pages because some programmer has a multi-dimensional array and is<br>
walking across the array with the indices in the wrong order<br>
<br>
i_max = 4095; j_max = 4095;<br>
for (i = 0, i &lt; i_max; i++) for j = 0, j &lt; j_max; j++) {sum += foo[i][j]}<br>
<br>
If somebdy is doing foo[j][i] instead, things can get ugly.  And if you&#39;re<br>
mixing with Fortran code, where the semantics of array references is reverse<br>
and you *want* to use &#39;foo[j][i]&#39; for efficient memory access, it&#39;s a bullet loaded<br>
in the chamber and waiting for somebody to pull the trigger.<br>
<br>
Not that I&#39;ve ever seen *that* particular error happen with a programmer<br>
processing 2 terabytes of arrays on a machine that only had 1.5 terabytes of<br>
RAM.  But I did tease the person involved about it, because they *really*<br>
should have known better. :)<br>
<br>
So again:  What question(s) are you trying to get answers to?<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><span style="font-size:12.8px;color:rgb(80,0,80)"><b>Mr. Irfanullah</b></span></div><div style="font-size:12.8px"><div style="font-size:12.8px"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><span style="font-size:12.8px;color:rgb(80,0,80)"><b>Mr. Irfanullah</b></span></div><div style="font-size:12.8px"><div style="font-size:12.8px"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25  7:00         ` Sahibzada Irfanullah
@ 2019-09-25  9:38           ` Greg KH
  2019-09-25 14:21             ` Ruben Safir
  2019-09-25 16:42             ` Valdis Klētnieks
  0 siblings, 2 replies; 15+ messages in thread
From: Greg KH @ 2019-09-25  9:38 UTC (permalink / raw)
  To: Sahibzada Irfanullah; +Cc: Valdis Klētnieks, kernelnewbies

On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada Irfanullah wrote:
> I am sorry if I am bothering you.
> I have read this article
> <http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html>,
> I have to ask that will Netlink socket work for my task; Storing the
> contents of "gpa" variable (which is present in the
> handle_ept_violation()functino in vmx.c ) into a file.

Try using ftrace and tracing in general first, before messing around
with netlink.  ftrace does not require any kernel changes at all, why
would you _not_ want to try that?  :)

thanks,

greg k-h

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25  9:38           ` Greg KH
@ 2019-09-25 14:21             ` Ruben Safir
  2019-09-25 17:08               ` Greg KH
  2019-09-25 16:42             ` Valdis Klētnieks
  1 sibling, 1 reply; 15+ messages in thread
From: Ruben Safir @ 2019-09-25 14:21 UTC (permalink / raw)
  To: kernelnewbies

On 9/25/19 5:38 AM, Greg KH wrote:
> On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada Irfanullah wrote:
>> I am sorry if I am bothering you.
>> I have read this article
>> <http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html>,
>> I have to ask that will Netlink socket work for my task; Storing the
>> contents of "gpa" variable (which is present in the
>> handle_ept_violation()functino in vmx.c ) into a file.
> 
> Try using ftrace and tracing in general first, before messing around
> with netlink.  ftrace does not require any kernel changes at all, why
> would you _not_ want to try that?  :)
> 
> thanks,
> 
> greg k-h
> 


The kernel has GPS data in it?


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


-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

http://www.nylxs.com - Leadership Development in Free Software
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25  9:38           ` Greg KH
  2019-09-25 14:21             ` Ruben Safir
@ 2019-09-25 16:42             ` Valdis Klētnieks
  1 sibling, 0 replies; 15+ messages in thread
From: Valdis Klētnieks @ 2019-09-25 16:42 UTC (permalink / raw)
  To: Greg KH; +Cc: Sahibzada Irfanullah, kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 454 bytes --]

On Wed, 25 Sep 2019 11:38:24 +0200, Greg KH said:
> Try using ftrace and tracing in general first, before messing around
> with netlink.  ftrace does not require any kernel changes at all, why
> would you _not_ want to try that?  :)

Beginning programmers write complicated messy code.
Good programmers write clean readable code.
Great programmers avoid writing code in the first place.

Something that many beginners don't seem to have a handle on. :)


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25 14:21             ` Ruben Safir
@ 2019-09-25 17:08               ` Greg KH
  2019-09-25 18:04                 ` Ruben Safir
  0 siblings, 1 reply; 15+ messages in thread
From: Greg KH @ 2019-09-25 17:08 UTC (permalink / raw)
  To: Ruben Safir; +Cc: kernelnewbies

On Wed, Sep 25, 2019 at 10:21:18AM -0400, Ruben Safir wrote:
> On 9/25/19 5:38 AM, Greg KH wrote:
> > On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada Irfanullah wrote:
> >> I am sorry if I am bothering you.
> >> I have read this article
> >> <http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html>,
> >> I have to ask that will Netlink socket work for my task; Storing the
> >> contents of "gpa" variable (which is present in the
> >> handle_ept_violation()functino in vmx.c ) into a file.
> > 
> > Try using ftrace and tracing in general first, before messing around
> > with netlink.  ftrace does not require any kernel changes at all, why
> > would you _not_ want to try that?  :)
> 
> The kernel has GPS data in it?

Of course it does, why wouldn't it? :)

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25 17:08               ` Greg KH
@ 2019-09-25 18:04                 ` Ruben Safir
  2019-09-26  6:45                   ` Sahibzada Irfanullah
  0 siblings, 1 reply; 15+ messages in thread
From: Ruben Safir @ 2019-09-25 18:04 UTC (permalink / raw)
  To: Greg KH; +Cc: Ruben Safir, kernelnewbies

On Wed, Sep 25, 2019 at 07:08:14PM +0200, Greg KH wrote:
> On Wed, Sep 25, 2019 at 10:21:18AM -0400, Ruben Safir wrote:
> > On 9/25/19 5:38 AM, Greg KH wrote:
> > > On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada Irfanullah wrote:
> > >> I am sorry if I am bothering you.
> > >> I have read this article
> > >> <http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html>,
> > >> I have to ask that will Netlink socket work for my task; Storing the
> > >> contents of "gpa" variable (which is present in the
> > >> handle_ept_violation()functino in vmx.c ) into a file.
> > > 
> > > Try using ftrace and tracing in general first, before messing around
> > > with netlink.  ftrace does not require any kernel changes at all, why
> > > would you _not_ want to try that?  :)
> > 
> > The kernel has GPS data in it?
> 
> Of course it does, why wouldn't it? :)
> 


So when the Nazi's and current Nazi's want to put me in the oven that
they can't track me.

Or put it this way, if it doesn't make the hardware GO, why would it be
in the kernel?

My computer doesn't even have a GPS...and it is going to stay that way.



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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-25 18:04                 ` Ruben Safir
@ 2019-09-26  6:45                   ` Sahibzada Irfanullah
  2019-09-26 10:05                     ` Brock
  0 siblings, 1 reply; 15+ messages in thread
From: Sahibzada Irfanullah @ 2019-09-26  6:45 UTC (permalink / raw)
  To: Ruben Safir; +Cc: Greg KH, kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 2237 bytes --]

Thank you very for your help. I have checked the ftrace, and perf. I think
it won't work for me.I am not analyzing/tracing the the kernel. I want to
develop my own dynamic tool like Pin Tool
<https://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool>
(or moudule which can be loaded/unloaded at run time dynamically), so that
I can easily tune/modify for different purposes , and to get any type of
specific information from the kernel/KVM, espcecially in the context of
virtualization (guest and/or host memory management). That's why I take a
start from generating the log of guest physical addresses from the kernel
by saving it to the file; with the passage of time, I will add the
funcationalities to it.
Thank you.

On Thu, 26 Sep 2019 at 03:05, Ruben Safir <ruben@mrbrklyn.com> wrote:

> On Wed, Sep 25, 2019 at 07:08:14PM +0200, Greg KH wrote:
> > On Wed, Sep 25, 2019 at 10:21:18AM -0400, Ruben Safir wrote:
> > > On 9/25/19 5:38 AM, Greg KH wrote:
> > > > On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada Irfanullah wrote:
> > > >> I am sorry if I am bothering you.
> > > >> I have read this article
> > > >> <
> http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html
> >,
> > > >> I have to ask that will Netlink socket work for my task; Storing the
> > > >> contents of "gpa" variable (which is present in the
> > > >> handle_ept_violation()functino in vmx.c ) into a file.
> > > >
> > > > Try using ftrace and tracing in general first, before messing around
> > > > with netlink.  ftrace does not require any kernel changes at all, why
> > > > would you _not_ want to try that?  :)
> > >
> > > The kernel has GPS data in it?
> >
> > Of course it does, why wouldn't it? :)
> >
>
>
> So when the Nazi's and current Nazi's want to put me in the oven that
> they can't track me.
>
> Or put it this way, if it doesn't make the hardware GO, why would it be
> in the kernel?
>
> My computer doesn't even have a GPS...and it is going to stay that way.
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>


-- 
Regards,

*Mr. Irfanullah*

[-- Attachment #1.2: Type: text/html, Size: 3676 bytes --]

<div dir="ltr">Thank you very for your help. I have checked the ftrace, and perf. I think it won&#39;t work for me.I am not analyzing/tracing the the kernel. I want to develop my own dynamic tool  like <a href="https://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool">Pin Tool</a> 

(or moudule which can be loaded/unloaded at run time dynamically), so that I can easily tune/modify for different purposes 



, and to get any type of specific information from the kernel/KVM, espcecially in the context of virtualization (guest and/or host memory management). That&#39;s why I take a start from generating the log of guest physical addresses from the kernel by saving it to the file; with the passage of time, I will add the funcationalities to it.<div>Thank you.  </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 26 Sep 2019 at 03:05, Ruben Safir &lt;<a href="mailto:ruben@mrbrklyn.com" target="_blank">ruben@mrbrklyn.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Sep 25, 2019 at 07:08:14PM +0200, Greg KH wrote:<br>
&gt; On Wed, Sep 25, 2019 at 10:21:18AM -0400, Ruben Safir wrote:<br>
&gt; &gt; On 9/25/19 5:38 AM, Greg KH wrote:<br>
&gt; &gt; &gt; On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada Irfanullah wrote:<br>
&gt; &gt; &gt;&gt; I am sorry if I am bothering you.<br>
&gt; &gt; &gt;&gt; I have read this article<br>
&gt; &gt; &gt;&gt; &lt;<a href="http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html" rel="noreferrer" target="_blank">http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html</a>&gt;,<br>
&gt; &gt; &gt;&gt; I have to ask that will Netlink socket work for my task; Storing the<br>
&gt; &gt; &gt;&gt; contents of &quot;gpa&quot; variable (which is present in the<br>
&gt; &gt; &gt;&gt; handle_ept_violation()functino in vmx.c ) into a file.<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Try using ftrace and tracing in general first, before messing around<br>
&gt; &gt; &gt; with netlink.  ftrace does not require any kernel changes at all, why<br>
&gt; &gt; &gt; would you _not_ want to try that?  :)<br>
&gt; &gt; <br>
&gt; &gt; The kernel has GPS data in it?<br>
&gt; <br>
&gt; Of course it does, why wouldn&#39;t it? :)<br>
&gt; <br>
<br>
<br>
So when the Nazi&#39;s and current Nazi&#39;s want to put me in the oven that<br>
they can&#39;t track me.<br>
<br>
Or put it this way, if it doesn&#39;t make the hardware GO, why would it be<br>
in the kernel?<br>
<br>
My computer doesn&#39;t even have a GPS...and it is going to stay that way.<br>
<br>
<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><span style="font-size:12.8px;color:rgb(80,0,80)"><b>Mr. Irfanullah</b></span></div><div style="font-size:12.8px"><div style="font-size:12.8px"><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-26  6:45                   ` Sahibzada Irfanullah
@ 2019-09-26 10:05                     ` Brock
  2019-09-26 22:56                       ` Valdis Klētnieks
  0 siblings, 1 reply; 15+ messages in thread
From: Brock @ 2019-09-26 10:05 UTC (permalink / raw)
  To: kernelnewbies

On Thu, 2019-09-26 at 15:45 +0900, Sahibzada Irfanullah wrote:
> Thank you very for your help. I have checked the ftrace, and perf. I
> think it won't work for me.I am not analyzing/tracing the the kernel.
> I want to develop my own dynamic tool like Pin Tool  (or moudule
> which can be loaded/unloaded at run time dynamically), so that I can
> easily tune/modify for different purposes , and to get any type of
> specific information from the kernel/KVM, espcecially in the context
> of virtualization (guest and/or host memory management). That's why I
> take a start from generating the log of guest physical addresses from
> the kernel by saving it to the file; with the passage of time, I will
> add the funcationalities to it.
> Thank you.  
I'm not sure if it's hardware addresses but you can get kernel/user/kvm
page fault information with:
perf record -a -e kvm:kvm_page_fault -e exceptions:page_fault_kernel -e
exceptions:page_fault_user -- sleep 30

An example output from my machine running an Ubuntu 18.04 guest:
kvm:kvm_page_fault:
   0.72%  address 40d26a78 error_code 181
   0.54%  address 46a09d00 error_code 181
   0.36%  address 2b10ef08 error_code 181
   0.36%  address 4a361000 error_code 181
   0.36%  address 4b0a2000 error_code 181
   ...<snipped>
exceptions:page_fault_kernel
   1.20%  address=0x17d0b30fe000s ip=filldir64 error_code=0x2
   1.20%  address=0x17d0b30ff000s ip=filldir64 error_code=0x2
   1.20%  address=0x17d0b3100000s ip=filldir64 error_code=0x2
   0.40%  address=0x55ac27551b46s ip=do_sys_poll error_code=0x2
   0.20%  address=0x55ac27de2000s ip=copy_user_generic_string
error_code=0x0
   0.20%  address=0x55ac27de3000s ip=copy_user_generic_string
error_code=0x0
   ...<snipped>
exceptions:page_fault_user
   0.12%  address=0xf8553529000s ip=0x7f7dc0d3c5dcs error_code=0x6
   0.12%  address=0xf855352a000s ip=0x7f7dc0d3c617s error_code=0x6
   0.12%  address=0xf855352b000s ip=0x7f7dc0d3c617s error_code=0x6
   0.12%  address=0xf855352c000s ip=0x7f7dc0d3c617s error_code=0x6
   0.12%  address=0xf855352d000s ip=0x7f7dc0d3c617s error_code=0x6
   ...<snipped>

The number (0.12%) at the start is how many times the address was seen
in the total number of samples in this case pagefaults that hit that
address I would guess.

You can find events you're interested in with `perf list` or
`cat /sys/kernel/debug/tracing/available_events`

Seems like you really want to develop your own module though but this
may still help see if there is existing kernel infrastructure you can
leverage.

Regards Brock.

> On Thu, 26 Sep 2019 at 03:05, Ruben Safir <ruben@mrbrklyn.com> wrote:
> > On Wed, Sep 25, 2019 at 07:08:14PM +0200, Greg KH wrote:
> > > On Wed, Sep 25, 2019 at 10:21:18AM -0400, Ruben Safir wrote:
> > > > On 9/25/19 5:38 AM, Greg KH wrote:
> > > > > On Wed, Sep 25, 2019 at 04:00:08PM +0900, Sahibzada
> > Irfanullah wrote:
> > > > >> I am sorry if I am bothering you.
> > > > >> I have read this article
> > > > >> <
> > http://amsekharkernel.blogspot.com/2012/01/what-are-ways-of-communication-bw-user.html>
> > ;,
> > > > >> I have to ask that will Netlink socket work for my task;
> > Storing the
> > > > >> contents of "gpa" variable (which is present in the
> > > > >> handle_ept_violation()functino in vmx.c ) into a file.
> > > > > 
> > > > > Try using ftrace and tracing in general first, before messing
> > around
> > > > > with netlink.  ftrace does not require any kernel changes at
> > all, why
> > > > > would you _not_ want to try that?  :)
> > > > 
> > > > The kernel has GPS data in it?
> > > 
> > > Of course it does, why wouldn't it? :)
> > > 
> > 
> > 
> > So when the Nazi's and current Nazi's want to put me in the oven
> > that
> > they can't track me.
> > 
> > Or put it this way, if it doesn't make the hardware GO, why would
> > it be
> > in the kernel?
> > 
> > My computer doesn't even have a GPS...and it is going to stay that
> > way.
> > 
> > 
> > 
> > _______________________________________________
> > 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] 15+ messages in thread

* Re: Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime
  2019-09-26 10:05                     ` Brock
@ 2019-09-26 22:56                       ` Valdis Klētnieks
  0 siblings, 0 replies; 15+ messages in thread
From: Valdis Klētnieks @ 2019-09-26 22:56 UTC (permalink / raw)
  To: Brock; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1277 bytes --]

On Thu, 26 Sep 2019 20:05:57 +1000, Brock said:
> On Thu, 2019-09-26 at 15:45 +0900, Sahibzada Irfanullah wrote:
> > Thank you very for your help. I have checked the ftrace, and perf. I
> > think it won't work for me.I am not analyzing/tracing the the kernel.
> > I want to develop my own dynamic tool like Pin Tool  (or moudule
> > which can be loaded/unloaded at run time dynamically), so that I can
> > easily tune/modify for different purposes , and to get any type of
> > specific information from the kernel/KVM, espcecially in the context
> > of virtualization (guest and/or host memory management). That's why I
> > take a start from generating the log of guest physical addresses from
> > the kernel by saving it to the file; with the passage of time, I will
> > add the funcationalities to it.
> > Thank you.
> I'm not sure if it's hardware addresses but you can get kernel/user/kvm
> page fault information with:

I admit I'm still mystified by the requirement for the hardware address rather than
the virtual address, when doing any sort of analytics is going to require mapping
back to a process and virtual address - and possibly incorrectly (consider a page fault
from an instruction in a shared library that's mmap'ed into 250 running processes, like
glibc...)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

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

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

end of thread, back to index

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24 10:10 Generating Log of Guest Physical Addresses from a Kernel Function and Perform Analysis at Runtime Sahibzada Irfanullah
2019-09-24 11:16 ` Valdis Klētnieks
2019-09-24 11:26   ` Sahibzada Irfanullah
2019-09-24 18:55     ` Valdis Klētnieks
2019-09-25  2:44       ` Sahibzada Irfanullah
2019-09-25  7:00         ` Sahibzada Irfanullah
2019-09-25  9:38           ` Greg KH
2019-09-25 14:21             ` Ruben Safir
2019-09-25 17:08               ` Greg KH
2019-09-25 18:04                 ` Ruben Safir
2019-09-26  6:45                   ` Sahibzada Irfanullah
2019-09-26 10:05                     ` Brock
2019-09-26 22:56                       ` Valdis Klētnieks
2019-09-25 16:42             ` Valdis Klētnieks
2019-09-24 13:29 ` Greg KH

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

Example config snippet for mirrors

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