Re: kernel projects for students

2021-03-22 Thread Okash Khawaja
+Speakup is a screen review system for Linux. 

Speak up had some plans


On Mon, Mar 22, 2021 at 3:37 PM Muni Sekhar  wrote:

> Hi all,
>
> What are some good Linux projects in kernel space for final year
> computer.science engineering students?
> Could someone help and share your ideas on this please.
>
> --
> Thanks,
> Sekhar
>
> ___
> 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


Re: What will happen if 2 processes map same physical page

2019-03-22 Thread Okash Khawaja
Hi Lev,

On Fri, 22 Mar 2019 12:15:49 +0300
Lev Olshvang  wrote:

> Hello Okash,
> 
> Actually there were 3 question:
> 
> Third question is :
> Is there any way to tell the kernel that PTE of same physical page
> should be equal in all processes?
Not that I am aware of. You mention SELinux feature which might be a
way but I don't know about it.

> 
> For example, shared lib mapped from different processes to same
> physical page must have same PTE, isn it?
This is policy vs. mechanism question. I think kernel - wherever
possible - provides mechanism, leaving policy to be determined by user
space. So in case of shared lib mapping, it's the dynamic linker which
ensures that all mappings are similar across different processes.

> 
> And  the presence of SELinux feature SELINUX_CHECKREQPROT_VALUE
> indicates for me that kernel somehow knows the correct page
> protections. (although I do not see in code how it is done)
> 
> But the question might be rephrased :  IMHO Kernel should mandate
> same PTE flags no matter how many virtual mapping were made to the
> same physical page.
> 
> What do you think?

I'm not sure if that would be the best default option. One reason is
that PTE flags aren't a property of physical page itself. Instead, PTE
flags are a property of a process's view of the physical page. Physical
page itself is a series of bytes. Meaning is given to those bytes by
the process which accesses them.

This is a bit more subjective opinion rather than an objective answer
so I'm ot sure if this answers your query.

Thanks,
Okash

> 
> 
> 
> 
> 
> 
> 21.03.2019, 13:45, "Okash Khawaja" :
> > On Thu, 21 Mar 2019 12:56:17 +0300
> > Lev Olshvang  wrote:
> >  
> >>  Hi Vaaldis,
> >>
> >>  Thanks for answer,
> >>  I still wondering whether the kernel will allow write to a
> >> read-only page of shared library while it has mapped to several
> >> processes? Kernel knows that page's reference count >1, will it
> >> allow mmap/mprotect to change page protection ? Or will it allow
> >> direct right by physical address? I suppose that CPU should raise
> >> page fault when write is made to read only page,
> >>
> >>  What is the sequence CPU raises page faul before write to page of
> >>  after data is written Will CPU wait until kernel will consider
> >> what to do , whether agree and change PTE "writable " bit to 1 ? Or
> >>  kernel may disagree and raise SEGFAULT?  
> >
> > Note that each process has its own PTE. So PTE in one process may
> > say the page is writable and PTE in another process may say it's
> > read-only. 
> >>  I checked in the handle_mm_fault() calls for
> >>  arch_vma_access_permitted() which just returns true on most
> >>  architectures which is very strange and contradicts my prediction
> >> of SEFFAULT. arch_vma_access_permitted() retutus true when is sees
> >> that access is made from foreign process?
> >>  https://elixir.bootlin.com/linux/latest/ident/arch_vma_access_permitted
> >>
> >>  I am totally confused.
> >>
> >>  What do you think ?
> >>
> >>  Regards,
> >>  Lev  
> >
> > It looks like there are two separate questions in the email.
> >
> > 1) Will kernel allow the same physical page to be mapped as
> > read-only in one process and as read-write in another process?
> >
> > 2) How page fault is generated?
> >
> > Answer for first is yes. Same physical page can be mapped with
> > different permissions in two different processes. It means read-only
> > process will ultimately (hopefully very soon) notice changes made by
> > read-write process.
> >
> > Answer for second question is a bit complicated. However there is a
> > trick to it. Once we know that, rest will become clear automaticaly.
> > The trick (at least for x86 systems) is that permissions are
> > maintained at two different levels:
> >
> > - VMA level
> > - PTE level (or PUD level for larger page size but that is not
> > relevant here)
> >
> > When a page in memory is accessed, permission on corresponding VMA
> > is checked first. If the access is allowed by VMA then PTE
> > permissions are checked. Otherwise segfault is generated. If
> > permissions at PTE level don't match the access type then a page
> > fault is generated. That's when page fault hander kicks in and
> > tries to resolve the problem by faulting the page into RAM, copying
> > the page in RAM (for copy-on-write) etc. 
> >>  20.03.2019, 20:08, &q

Re: What will happen if 2 processes map same physical page

2019-03-21 Thread Okash Khawaja
On Thu, 21 Mar 2019 12:56:17 +0300
Lev Olshvang  wrote:

> Hi Vaaldis,
> 
> Thanks for answer,
> I still wondering whether the kernel will allow write to a read-only
> page of shared library while it has mapped to several processes?
> Kernel knows that page's reference count >1,  will it allow
> mmap/mprotect to change page protection ? Or will it allow direct
> right by physical address? I suppose that CPU should raise page fault
> when write is made to read only page, 
> 
> What is the sequence  CPU raises page faul before write to page of
> after data is written Will  CPU wait until kernel will consider what
> to do , whether agree and change PTE  "writable " bit to 1 ? Or
> kernel may disagree and raise SEGFAULT?

Note that each process has its own PTE. So PTE in one process may say
the page is writable and PTE in another process may say it's read-only.

> 
> I checked in the handle_mm_fault()  calls for
> arch_vma_access_permitted() which just returns true on most
> architectures which is very strange and  contradicts my prediction of
> SEFFAULT. arch_vma_access_permitted() retutus true when is sees that
> access is made from foreign process?
> https://elixir.bootlin.com/linux/latest/ident/arch_vma_access_permitted
> 
> I am totally confused.
> 
> What do you think ?
> 
> Regards,
> Lev

It looks like there are two separate questions in the email.

1) Will kernel allow the same physical page to be mapped as read-only
in one process and as read-write in another process?

2) How page fault is generated?

Answer for first is yes. Same physical page can be mapped with
different permissions in two different processes. It means read-only
process will ultimately (hopefully very soon) notice changes made by
read-write process.

Answer for second question is a bit complicated. However there is a
trick to it. Once we know that, rest will become clear automaticaly.
The trick (at least for x86 systems) is that permissions are maintained
at two different levels:

- VMA level
- PTE level (or PUD level for larger page size but that is not relevant
  here)

When a page in memory is accessed, permission on corresponding VMA is
checked first. If the access is allowed by VMA then PTE permissions are
checked. Otherwise segfault is generated. If permissions at PTE level
don't match the access type then a page fault is generated. That's when
page fault hander kicks in and tries to resolve the problem by faulting
the page into RAM, copying the page in RAM (for copy-on-write) etc.

> 
> 
> 
> 20.03.2019, 20:08, "Valdis Klētnieks" :
> > On Wed, 20 Mar 2019 16:42:39 +0300, Lev Olshvang said:  
> >>  The question is it ipossiblle in Linux/MMU/TLB that 2 processes
> >> map to the same physical address?  
> >
> > Totally possible. That's how mmap shared memory works, and why
> > shared libraries are possible.
> >  
> >>  Will CPU or TLB discover that second process tries to reach
> >> occupied physical page?  
> >
> > Well, the hardware won't discover it as a "second" process, it only
> > knows it's processing *this* memory access.
> >  
> >>  What if first process set page permission to read and second
> >> whats to write to this page ?  
> >
> > Perfectly OK - the two processes have separate page table mappings,
> > with separate permission bits. So (for example) physical page
> > 0x17F000 is mapped to virtual address 0x2034D000 with read-only
> > permission n process 1's page tables, and to virtual address
> > 0x98FF3000 with read-write permission in process 2's page tables.
> > No problem.
> >
> > (And before you ask, yes it's possible for process 2 to running on
> > one core doing a write to the page at the exact same time that
> > process 1 is doing a read on another core. Depending on the
> > hardware cache design, this may or may not get process 1 updated
> > data. This is why locking and memory barriers are important. See
> > Documentation/memory-barriers.txt for more details)
> >
> > "And then there's the Alpha" - a processor design that got much of
> > its speed by being weird about this stuff. :)
> >  
> >>  Perhaps during context switch all page access permissions of
> >> first process is flashed out from MMU ?  
> >
> > Actually, the kernel just points the MMU at a new set of page table
> > entries and lets the TLB reload as needed. In particular, on most
> > architectures, the kernel tries really hard to ensure that all
> > processes share at least part of their page table mappings so the
> > kernel is always mapped at the same place, meaning that there's a
> > better chance that on a syscall, the TLB already has hot entries
> > for large parts of the kernel so no TLB reloads are needed.  
> 
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/l

Re: where to find the kmalloc implementation

2019-01-09 Thread Okash Khawaja
On Wed, Jan 9, 2019 at 3:17 PM Carter Cheng  wrote:
>
> Hi,
>
> I am curious where in the kernel sources would I find the kmalloc 
> implementation? I am curious how GFP_ATOMIC option is implemented.
>
> Thanks,
>
> Carter.

Hi Carter,

kmalloc() implementation can be found in include/linux/slab.h.
Interesting part of kmalloc() is the use of kmem_cache. kmem_cache is
basically a pool of memory. kmalloc() maintains a system of
kmem_cache's and allocates memory from those caches to the caller. How
it allocates that memory is determined by type of request (e.g.
GFP_ATOMIC) and "buddy system" algorithm, which is an algorithm
designed to minimise fragmentation and be cache efficient.

>From what I remember, kmalloc system sets aside memory for "emergency"
uses, like kmalloc calls with GFP_ATOMIC. So for normal memory
allocation calls, execution may sleep until memory becomes available,
even though there may be memory available in the emergence cache.

Hope it helps :)

Okash

> ___
> 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


Purpose of PTRACE_SETSIGINFO for x86

2018-12-14 Thread Okash Khawaja
Hi,

What does the PTRACE_SETSIGINFO ptrace command do?

I can see in kernel/ptrace.c:ptrace_request() it calls
ptrace_setsiginfo(), passing it the child's (tracee's) task descriptor
and siginfo_t instance originally passed in from user space.

ptrace_setsiginfo() sets child's last_siginfo to the siginfo_t
instance passed in. Now there are only two places where a
child->last_siginfo's value is read are in kernel/ptrace.c:

1. by the ptrace command PTRACE_GETSIGINFO
2. by the ptrace command PTRACE_LISTEN

There doesn't seem to be a place where value of last_siginfo is read
by signal handling code. There is however this comment in
kernel/signal.c:ptrace_signal():

/*
 * Update the siginfo structure if the signal has
 * changed.  If the debugger wanted something
 * specific in the siginfo structure then it should
 * have updated *info via PTRACE_SETSIGINFO.
 */

Where does PTRACE_SETSIGINFO update *info?

Thanks,
Okash

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


Re: request_module with params

2017-08-21 Thread Okash Khawaja
Hi,

On 21 Aug 2017 8:21 am, "Cihangir Akturk"  wrote:

On Sun, Aug 20, 2017 at 09:24:09AM +0100, Okash Khawaja wrote:
> Hi,
>
> Is there a way to load a kernel module from another module and pass
> parameters to it? Something like
>
> request_module("mymod param1=val1");

I think this is exactly what you are looking for:


This works fine when no parameters are supplied. But if I call it like
this:

request_module("mymod param1=val1");

It doesn't work.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


request_module with params

2017-08-20 Thread Okash Khawaja
Hi,

Is there a way to load a kernel module from another module and pass
parameters to it? Something like

request_module("mymod param1=val1");

Thanks,
Okash
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Is vnode number also limit system-wide number of open file?

2017-05-31 Thread Okash Khawaja


> On 31 May 2017, at 14:37, Yubin Ruan  wrote:
> 
> I notice that there is a 
> 
>unsigned longi_ino;
> 
> in definition of `struct inode' [1], which is the virtual filesystem inode.
> Does that mean "inode number" and is it used for indexing in the system-wide
> inode table? 
> 
> If that is the case, would that limit the number of open file in Linux?
> 
> I know there *is* such a limit, and superusers can adjust that by
> /proc/sys/fs/file-max. Currently I cannot raise that to too high, otherwise
> the system would crash, which I think is because I have limited memory. But,
> the point is, if I have lots of memory in my machine (say hunderds of
> Gigabytes), would the number of open file system-wide limited by the `i_ino'
> above? Since its type is "unsigned long", I guess I can only open
> 2^(sizeof(unsigned long)) file simultaneously? 

2^(8*sizeof(unsigned long))

Which is big. Is there some use case for very large number of files?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Importance of kobject

2017-05-17 Thread Okash Khawaja
Hi,

On Wed, May 17, 2017 at 8:08 AM, Madhu K  wrote:
> Hi All,
>
> I am kernel newbie, I want to know the importance of kobject, can anybody
> explain the importance of kobject with an example.

To state a not-so-popular analogy, kobjects can also be viewed as root
object in object oriented programming. So a bit like java.lang.Object.
Of course it is not a root object and indeed C is not OO, but this
view helps in thinking about it.

This section from ldd3 lists some of the tasks handled by kobject:
http://www.makelinux.net/ldd3/chp-14-sect-1. So whichever struct
ultimately encapsulates (inherits from) kobject will have those tasks
handled for it for free. This view is in addition to others expressed
here.

HTH
Okash

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


Re: Error while sending a mail from mutt

2017-03-30 Thread Okash Khawaja

> How do I see what arguments are being sent by mutt to sendmail.

In ~/.muttrc, where it says

set sendmail=...

Replace the argument with your custom script which logs all arguments passed to 
it. 

> Is there any quicker way by which I can get mutt working fine.

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


Re: Error while sending a mail from mutt

2017-03-29 Thread Okash Khawaja

> On 29 Mar 2017, at 21:19, Jim Davis  wrote:
> 
> On Wed, Mar 29, 2017 at 12:32 PM, AYAN KUMAR HALDER
>  wrote:
>> Hi,
>> 
>> I am trying to send a mail using mutt. I am getting the error as follows :-
>> 
>> SMTP session failed: 501 5.5.4
>> 
>> I understand the error meant that a valid mail transaction protocol
>> was used with invalid arguments. Please let me know how do I debug
>> this issue further.
> 
> Mutt usually invokes some other program to send mail -- on my
> workstation, for instance, that other program is /usr/sbin/sendmail:
> 
> [jim@krebstar ~]$ mutt -v | grep '^SENDMAIL'
> SENDMAIL="/usr/sbin/sendmail"
> 
> so to debug a similar problem on my workstation I'd first look to see
> where sendmail (or whatever program your mutt installation uses) logs
> its messages.
> 
> That used to be in /var/log/maillog or such; nowadays you might have
> to run journalctl instead.
> 
> For example, if I try
> 
> mutt postmas...@example.com  
> on my workstation, then
> 
> journalctl | grep sendmail
> 
> tells me
> 
> Mar 29 12:59:06 krebstar.arl.arizona.edu sendmail[27263]:
> v2TJx61J027263: to=postmas...@example.com, ctladdr=jim (1000/1000),
> delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30294,
> relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection
> refused by [127.0.0.1]
> 
> which reminds me I don't actually have the sendmail service running.

You can check ~/.muttrc file to see what it is using to send emails. If it is 
using sendmail or esmtp, then in .muttrc file where it specifies sending 
program you can append -X /path/to/log/file. That will output the whole SMTP 
dialog to that log file.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


quilt mail not threading

2017-03-10 Thread Okash Khawaja
Hi,

I can send patchset using quilt mail alright but the emails don't appear
threaded. Checking email headers, I couldn't see References header either,
which is what it should be using according to the README.MAIL.

Have I missed something?

Thanks,
Okash

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


Re: unregister_input_polled_device() leads to null pointer deref

2016-03-28 Thread Okash Khawaja


> On 28 Mar 2016, at 14:55, Carlo Caione  wrote:
> 
>> On Mon, Mar 28, 2016 at 3:32 PM, Okash Khawaja  
>> wrote:
>> Hi,
>> 
>> I'm writing a i2c device driver. In probe(), among other things I call:
>> 
>> polled_input = input_allocate_polled_device();
>> input_register_polled_device(polled_input);
>> 
>> Then inside remove(), I extract the instance of input_polled_dev and
>> call
>> 
>> input_unregister_polled_device(polled_input);
>> 
>> This results in kernel error:
>> 
>> "Unable to handle kernel NULL pointer dereference at virtual address
>> 0474".
>> 
>> It turns out that the input_dev pointer inside input_polled_dev is null
>> which leads to this error. But why is input_dev pointer null? It is not
>> null inside probe() function and I don't release it anywhere.
>> 
>> This is code: http://pastebin.com/JJdepyEG and here is link to the output,
>> along with my log statements: http://pastebin.com/badwSvyy.
> 
> input_free_polled_device(polled_input) is always called in your probe 
> function.

Of course! Thanks very much 

> 
> 
> -- 
> Carlo Caione

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


unregister_input_polled_device() leads to null pointer deref

2016-03-28 Thread Okash Khawaja
Hi,

I'm writing a i2c device driver. In probe(), among other things I call:

polled_input = input_allocate_polled_device();
input_register_polled_device(polled_input);

Then inside remove(), I extract the instance of input_polled_dev and
call 

input_unregister_polled_device(polled_input);

This results in kernel error:

"Unable to handle kernel NULL pointer dereference at virtual address
0474". 

It turns out that the input_dev pointer inside input_polled_dev is null
which leads to this error. But why is input_dev pointer null? It is not
null inside probe() function and I don't release it anywhere.

This is code: http://pastebin.com/JJdepyEG and here is link to the output,
along with my log statements: http://pastebin.com/badwSvyy. 

Thanks,
Okash

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Free electrons course wii nunchuk and BBB i2c connection DTS

2016-01-31 Thread Okash Khawaja
Hi,

In this free-electrons course http://free-electrons.com/training/kernel/
it talks about setting up i2c between beagle bone black and nintendo wii
nunchuk with UEXT connector. To do that I created the DTS which I have 
put at the end of this email. It doesn't seem to be working. When I send
some bytes to the device which is on i2c1, I get "omap_i2c 4802a000.i2c:
timeout waiting for bus ready" message.

Feel free to ask details. Any help will be appreciated.

Thanks,
Okash

/dts-v1/;

#include "am33xx.dtsi"
#include "am335x-bone-common.dtsi"

/ {
model = "TI AM335x BeagleBone Black";
compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
};

&i2c1 {
status = "okay";
clock-frequency = <10>;

nunchuk@52 {
compatible = "nintendo,nunchuk";
reg = <0x52>;
};
};

&am33xx_pinmux {
pinctrl-names = "default";
pinctrl-0 = <&i2c1_pins>;
i2c1_pins: pinmux_i2c1_pins {
pinctrl_single,pins = <
0x158 (PIN_INPUT_PULLUP | MUX_MODE2) /* 
spi0_d1.i2c1_sda */
0x15c (PIN_INPUT_PULLUP | MUX_MODE2) /* 
spi0_cs0.i2c1_scl */
>;
};
};


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies