Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
* Fwd: Need Help regarding Reading and Writting to a file from kernel function file
       [not found] <CAGaWEbomboZ=MCT4GaKj+5tUNDGc5ZknvhLTikCPSWpjY5E7hA@mail.gmail.com>
@ 2019-09-24  7:10 ` Sahibzada Irfanullah
  2019-09-24  7:35   ` Greg KH
  2019-09-24  8:48   ` Valdis Klētnieks
  0 siblings, 2 replies; 6+ messages in thread
From: Sahibzada Irfanullah @ 2019-09-24  7:10 UTC (permalink / raw)
  To: kernelnewbies

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

Dear Sir,
Hope you are doing well. Actually, I have one problem metioned in the
subject line. The problem is:  I am trying to write/read page faulted
physical addresses to a file in a kernel (v5.3-1) function, i.e.,
handle_ept_violation() which is present in vmx.c. I have followed this
<https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module>,
it's working as a standalone kernel module when I load/unload this kernel
module, but when I try to use this code in the handle_ept_violation()
function, I can't able to open the file and get the error codes, i.e., -2,
-3, or -13. It's compiled successfully but generate the error at runtime. I
searched for error codes online but I didn't find any help.
Can anyone please provide me with any good guidlines, or links where I can
start and solve this problem in a fast way.
Thank you very much

-- 
Regards,

*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu@gmail.com
 sahibzada_irfanullah



-- 
Regards,

*Mr. Irfanullah*

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

<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Dear Sir, <br></div><div dir="ltr"><div>Hope you are doing well. Actually, I have one problem metioned in the subject line. The problem is:  <span style="color:rgb(36,39,41);font-family:Arial,&quot;Helvetica Neue&quot;,Helvetica,sans-serif;font-size:15px">I am trying to write/read page faulted physical addresses to a file in a kernel (v5.3-1) function, i.e., handle_ept_violation() which is present in vmx.c. I have followed </span><a href="https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module" style="color:rgba(220,70,29,0.7);margin:0px;padding:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-stretch:inherit;line-height:inherit;font-family:Arial,&quot;Helvetica Neue&quot;,Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit" target="_blank">this</a><span style="color:rgb(36,39,41);font-family:Arial,&quot;Helvetica Neue&quot;,Helvetica,sans-serif;font-size:15px">, it&#39;s working as a standalone kernel module when I load/unload this kernel module, but when I try to use this code in the handle_ept_violation() function, I can&#39;t able to open the file and get the error codes, i.e., -2, -3, or -13. It&#39;s compiled successfully but generate the error at runtime. I searched for error codes online but I didn&#39;t find any help.</span></div><div><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px">Can anyone please provide me with any good guidlines, or links where I can start and solve this problem in a fast way.</span></font></div><div><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px">Thank you very much</span></font></div><div><br></div>-- <br><div dir="ltr" data-smartmail="gmail_signature"><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"><div dir="ltr"><span style="font-size:12.8px">Regards,</span><div style="font-size:12.8px"><br><div dir="ltr" style="color:rgb(136,136,136);font-size:small"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr" style="color:rgb(136,136,136);font-size:small"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family:arial,sans-serif;font-size:12.8px"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size:12.8px"><span style="font-size:12.8px"><font color="#000000">  </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&amp;id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&amp;revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size:12.8px"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></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><br clear="all"><div><br></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] 6+ messages in thread

* Re: Fwd: Need Help regarding Reading and Writting to a file from kernel function file
  2019-09-24  7:10 ` Fwd: Need Help regarding Reading and Writting to a file from kernel function file Sahibzada Irfanullah
@ 2019-09-24  7:35   ` Greg KH
  2019-09-24  8:48   ` Valdis Klētnieks
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-09-24  7:35 UTC (permalink / raw)
  To: Sahibzada Irfanullah; +Cc: kernelnewbies

On Tue, Sep 24, 2019 at 04:10:07PM +0900, Sahibzada Irfanullah wrote:
> Dear Sir,
> Hope you are doing well. Actually, I have one problem metioned in the
> subject line. The problem is:  I am trying to write/read page faulted
> physical addresses to a file in a kernel (v5.3-1) function, i.e.,
> handle_ept_violation() which is present in vmx.c. I have followed this
> <https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module>,
> it's working as a standalone kernel module when I load/unload this kernel
> module, but when I try to use this code in the handle_ept_violation()
> function, I can't able to open the file and get the error codes, i.e., -2,
> -3, or -13. It's compiled successfully but generate the error at runtime. I
> searched for error codes online but I didn't find any help.
> Can anyone please provide me with any good guidlines, or links where I can
> start and solve this problem in a fast way.

Please do not try to read or write a file from within the kernel, that
way almost always lies madness and major problems.

Step back and try to describe the problem you are attempting to solve
here first.  Odds are it can be done in a much better way.

Also, do you have a pointer to your code anywhere?

thanks,

greg k-h

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

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

* Re: Fwd: Need Help regarding Reading and Writting to a file from kernel function file
  2019-09-24  7:10 ` Fwd: Need Help regarding Reading and Writting to a file from kernel function file Sahibzada Irfanullah
  2019-09-24  7:35   ` Greg KH
@ 2019-09-24  8:48   ` Valdis Klētnieks
  2019-09-24  9:51     ` Saket Sinha
  2019-09-24 10:02     ` Martin Christian
  1 sibling, 2 replies; 6+ messages in thread
From: Valdis Klētnieks @ 2019-09-24  8:48 UTC (permalink / raw)
  To: Sahibzada Irfanullah; +Cc: kernelnewbies

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

On Tue, 24 Sep 2019 16:10:07 +0900, Sahibzada Irfanullah said:

> subject line. The problem is:  I am trying to write/read page faulted
> physical addresses to a file in a kernel (v5.3-1) function, i.e.,
> handle_ept_violation() which is present in vmx.c. I have followed this
> <https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module>,

Just because somebody on stackoverflow gave a guide doesn't mean it's
a good idea.

What problem are you trying to solve here?  Are you trying to write the faulted
pages themselves to a file?  In that case, just creating the file, using something like
'dd if=/dev/zero of=/your/file/here bs=1M count=4096' and then using mkswap
and swapon will probably work much better.

If you're trying to produce a trace of what pages are being faulted, you can
probably do a better job by using 'perf' to produce trace events with a lot of
added data for you, or use debugfs or netlink and a userspace program to read
the data and write it to disk from userspace.


[-- 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] 6+ messages in thread

* Re: Fwd: Need Help regarding Reading and Writting to a file from kernel function file
  2019-09-24  8:48   ` Valdis Klētnieks
@ 2019-09-24  9:51     ` Saket Sinha
  2019-09-24 13:32       ` Greg KH
  2019-09-24 10:02     ` Martin Christian
  1 sibling, 1 reply; 6+ messages in thread
From: Saket Sinha @ 2019-09-24  9:51 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: Sahibzada Irfanullah, kernelnewbies

Hi,

I am sorry but I am really tempted to share -
https://www.linuxjournal.com/article/8110

But as suggested, you should never try this.

Regards,
Saket Sinha

On Tue, Sep 24, 2019 at 10:50 AM Valdis Klētnieks
<valdis.kletnieks@vt.edu> wrote:
>
> On Tue, 24 Sep 2019 16:10:07 +0900, Sahibzada Irfanullah said:
>
> > subject line. The problem is:  I am trying to write/read page faulted
> > physical addresses to a file in a kernel (v5.3-1) function, i.e.,
> > handle_ept_violation() which is present in vmx.c. I have followed this
> > <https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module>,
>
> Just because somebody on stackoverflow gave a guide doesn't mean it's
> a good idea.
>
> What problem are you trying to solve here?  Are you trying to write the faulted
> pages themselves to a file?  In that case, just creating the file, using something like
> 'dd if=/dev/zero of=/your/file/here bs=1M count=4096' and then using mkswap
> and swapon will probably work much better.
>
> If you're trying to produce a trace of what pages are being faulted, you can
> probably do a better job by using 'perf' to produce trace events with a lot of
> added data for you, or use debugfs or netlink and a userspace program to read
> the data and write it to disk from userspace.
>
> _______________________________________________
> 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] 6+ messages in thread

* Re: Fwd: Need Help regarding Reading and Writting to a file from kernel function file
  2019-09-24  8:48   ` Valdis Klētnieks
  2019-09-24  9:51     ` Saket Sinha
@ 2019-09-24 10:02     ` Martin Christian
  1 sibling, 0 replies; 6+ messages in thread
From: Martin Christian @ 2019-09-24 10:02 UTC (permalink / raw)
  To: kernelnewbies

[-- Attachment #1.1.1: Type: text/plain, Size: 822 bytes --]

> Just because somebody on stackoverflow gave a guide doesn't mean it's
> a good idea.

I'll put that on my quotation list. ;-)

Regards,

Martin

-- 
Dipl.-Inf. Martin Christian
Senior Berater Entwicklung Hardware
Division Verteidigung
secunet Security Networks AG

Tel.: +49 201 5454-3612, Fax +49 201 5454-1323
E-Mail: martin.christian@secunet.com
Ammonstraße 74, 01067 Dresden
www.secunet.com
__________________________________________________________________________

secunet Security Networks AG
Sitz: Kurfürstenstraße 58, 45138 Essen, Deutschland
Amtsgericht Essen
HRB 13615
Vorstand: Axel Deininger (Vors.), Torsten Henn, Dr. Kai Martius,
          Thomas Pleines
Aufsichtsratsvorsitzender: Ralf Wintergerst
__________________________________________________________________________


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 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] 6+ messages in thread

* Re: Fwd: Need Help regarding Reading and Writting to a file from kernel function file
  2019-09-24  9:51     ` Saket Sinha
@ 2019-09-24 13:32       ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-09-24 13:32 UTC (permalink / raw)
  To: Saket Sinha; +Cc: Sahibzada Irfanullah, Valdis Klētnieks, kernelnewbies

On Tue, Sep 24, 2019 at 11:51:57AM +0200, Saket Sinha wrote:
> Hi,
> 
> I am sorry but I am really tempted to share -
> https://www.linuxjournal.com/article/8110

That's out of date, and the stack overflow link points to it.

Maybe someday I'll update that article somewhere else, as it's actually
much simpler to do this now than it was when I wrote that article.  But
it still doesn't make it something that anyone should do :)

thanks,

greg k-h

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

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAGaWEbomboZ=MCT4GaKj+5tUNDGc5ZknvhLTikCPSWpjY5E7hA@mail.gmail.com>
2019-09-24  7:10 ` Fwd: Need Help regarding Reading and Writting to a file from kernel function file Sahibzada Irfanullah
2019-09-24  7:35   ` Greg KH
2019-09-24  8:48   ` Valdis Klētnieks
2019-09-24  9:51     ` Saket Sinha
2019-09-24 13:32       ` Greg KH
2019-09-24 10:02     ` Martin Christian

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