Sort
Profile photo for Zhenghong Li

Quora User Thanks for your cool idea. Yes, chattr can be used to set the immutable bit on many Linux file systems, but you know super administrators like root can change that bit too. I wanna hook such system calls as OPEN, CREAT and WRITE to protect key directories and files from being modified. If my hook program is running, even super administrators cannot modify these key directories and files. I tried to modify the SYSCALL table, and it worked on some versions of Linux kernels, and didn’t on other versions. I am not going to implement a new filesystem, I just wanna add new features to the

Quora User Thanks for your cool idea. Yes, chattr can be used to set the immutable bit on many Linux file systems, but you know super administrators like root can change that bit too. I wanna hook such system calls as OPEN, CREAT and WRITE to protect key directories and files from being modified. If my hook program is running, even super administrators cannot modify these key directories and files. I tried to modify the SYSCALL table, and it worked on some versions of Linux kernels, and didn’t on other versions. I am not going to implement a new filesystem, I just wanna add new features to the existing ones. I prefer to add new feature to the virtual file system, is that possible? Tracing chattr is a good idea, I’ll have a try.

Profile photo for Anand Bhat

It is quite simple. Each PCI/PCIe device needs to implement few basic registers which include vendor and device ids. When the Linux PCI driver (drivers/pci) scans the PCI bus and builds the PCI config tree, it basically reads these registers among others. All the device drivers have to do is to register the driver with proper vendor and device ids for which the driver is written. These drivers also register appropriate operations (depends on what class of device it is) structure with the kernel. Kernel checks the PCI ID table specified by the driver with the one stored in the PCI config spac

It is quite simple. Each PCI/PCIe device needs to implement few basic registers which include vendor and device ids. When the Linux PCI driver (drivers/pci) scans the PCI bus and builds the PCI config tree, it basically reads these registers among others. All the device drivers have to do is to register the driver with proper vendor and device ids for which the driver is written. These drivers also register appropriate operations (depends on what class of device it is) structure with the kernel. Kernel checks the PCI ID table specified by the driver with the one stored in the PCI config space and associates the device with the driver and calls the probe entry point in the driver. Probe entry point allocates all the resources needed by the device and "claims" the device. Once the device is claimed by the driver, all operations on the device land up in the driver.

Profile photo for Metis Chan

With today’s modern day tools there can be an overwhelming amount of tools to choose from to build your own website. It’s important to keep in mind these considerations when deciding on which is the right fit for you including ease of use, SEO controls, high performance hosting, flexible content management tools and scalability. Webflow allows you to build with the power of code — without writing any.

You can take control of HTML5, CSS3, and JavaScript in a completely visual canvas — and let Webflow translate your design into clean, semantic code that’s ready to publish to the web, or hand off

With today’s modern day tools there can be an overwhelming amount of tools to choose from to build your own website. It’s important to keep in mind these considerations when deciding on which is the right fit for you including ease of use, SEO controls, high performance hosting, flexible content management tools and scalability. Webflow allows you to build with the power of code — without writing any.

You can take control of HTML5, CSS3, and JavaScript in a completely visual canvas — and let Webflow translate your design into clean, semantic code that’s ready to publish to the web, or hand off to developers.

If you prefer more customization you can also expand the power of Webflow by adding custom code on the page, in the <head>, or before the </head> of any page.

Get started for free today!

Trusted by over 60,000+ freelancers and agencies, explore Webflow features including:

  • Designer: The power of CSS, HTML, and Javascript in a visual canvas.
  • CMS: Define your own content structure, and design with real data.
  • Interactions: Build websites interactions and animations visually.
  • SEO: Optimize your website with controls, hosting and flexible tools.
  • Hosting: Set up lightning-fast managed hosting in just a few clicks.
  • Grid: Build smart, responsive, CSS grid-powered layouts in Webflow visually.

Discover why our global customers love and use Webflow | Create a custom website.

Profile photo for Sebas Sujeen

The LKM is an object file not an executable which means that the functions/symbols are not relocated yet. So, why is this happening? Because we dont have the idea of a shared library in the linux kernel. So if a LKM wants to make use of a function say "X" which is part of the linux kernel, then the symbol needs to be exported using EXPORT_SYMBOL macro which adds the function to the kernel symbol table. The previous step is done in the linux kernel code not in the custom LKM. The module loader fixes the relocation and if it encounters a symbol that is not part of the kernel but part of another

The LKM is an object file not an executable which means that the functions/symbols are not relocated yet. So, why is this happening? Because we dont have the idea of a shared library in the linux kernel. So if a LKM wants to make use of a function say "X" which is part of the linux kernel, then the symbol needs to be exported using EXPORT_SYMBOL macro which adds the function to the kernel symbol table. The previous step is done in the linux kernel code not in the custom LKM. The module loader fixes the relocation and if it encounters a symbol that is not part of the kernel but part of another known LKM, it loads that LKM first, this is what the modprobe does . Also, if you want to verify what all functions/symbols are exported by the linux kernel from user space, you can view the /proc/kallsyms! To answer your question short, symbols exported by the linux kernel "acts" as shared library for the LKM so that you can reuse the code! These relocations are fixed by the LKM loader which is part of the kernel!

Profile photo for Quora User

You can use the chattr (aka “change attribute”) command to set the immutable bit on many (most?) linux filesystems. Ultimately that attribute is enforced by the kernel. Just for fun, trace how the open system call is implemented inside the kernel. See if you can find where the immutable bit is checked.

Now that you understand how the existing system works, do you want to create a new filesystem? Do you have a different set of permissions that you’d like to implement on an existing filesystem?

Profile photo for Abhinav Jangda

Kernel Stack is dependent on architecture. On x86 it is 2 pages, which implies 8KB on 32-bit and 16KB on 64-Bit. It is defined as an array of unsigned long. And struct thread_info is 52 bytes. struct thread_info is stored at the bottom of stack if stack grows down and up if stack grows up. Let, Kernel Stack is 8KB of size. Also, it should have struct thread_info in it. This gives the remaining size of 8192-52 = 8140 Bytes. Whole of this could be represented as a struct or as a union. If both of them is binded as a struct, then we would have something like this:
Each long is a size of 4 Bytes,

Kernel Stack is dependent on architecture. On x86 it is 2 pages, which implies 8KB on 32-bit and 16KB on 64-Bit. It is defined as an array of unsigned long. And struct thread_info is 52 bytes. struct thread_info is stored at the bottom of stack if stack grows down and up if stack grows up. Let, Kernel Stack is 8KB of size. Also, it should have struct thread_info in it. This gives the remaining size of 8192-52 = 8140 Bytes. Whole of this could be represented as a struct or as a union. If both of them is binded as a struct, then we would have something like this:
Each long is a size of 4 Bytes, hence for 8140 Bytes size of long array should contains 8140/4 = 2035 elements.

  1. struct thread_struct 
  2. { 
  3. struct thread_info thread_info; //52 Bytes long 
  4. unsigned long stack [2035]; 
  5. }; 

Hence, total size is 8192 bytes.

Now consider a union. In union, the size of union is the maximum size of all the fields. So, to have a union of size 8KB, we can have the array of unsigned long as 8KB or an array of unsigned long with 8192/4 = 2048 elements. Hence, we have

  1. struct thread_union 
  2. { 
  3. struct thread_info thread_info; 
  4. unsigned long stack [2048]; 
  5. }; 

It is easy to represent in the form of union. Moreover, thread_info and stack share the memory space. It is not like that both of their space is added up to give 8KB, they both share that space.

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of th

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of the biggest mistakes and easiest ones to fix.

Overpaying on car insurance

You’ve heard it a million times before, but the average American family still overspends by $417/year on car insurance.

If you’ve been with the same insurer for years, chances are you are one of them.

Pull up Coverage.com, a free site that will compare prices for you, answer the questions on the page, and it will show you how much you could be saving.

That’s it. You’ll likely be saving a bunch of money. Here’s a link to give it a try.

Consistently being in debt

If you’ve got $10K+ in debt (credit cards…medical bills…anything really) you could use a debt relief program and potentially reduce by over 20%.

Here’s how to see if you qualify:

Head over to this Debt Relief comparison website here, then simply answer the questions to see if you qualify.

It’s as simple as that. You’ll likely end up paying less than you owed before and you could be debt free in as little as 2 years.

Missing out on free money to invest

It’s no secret that millionaires love investing, but for the rest of us, it can seem out of reach.

Times have changed. There are a number of investing platforms that will give you a bonus to open an account and get started. All you have to do is open the account and invest at least $25, and you could get up to $1000 in bonus.

Pretty sweet deal right? Here is a link to some of the best options.

Having bad credit

A low credit score can come back to bite you in so many ways in the future.

From that next rental application to getting approved for any type of loan or credit card, if you have a bad history with credit, the good news is you can fix it.

Head over to BankRate.com and answer a few questions to see if you qualify. It only takes a few minutes and could save you from a major upset down the line.

How to get started

Hope this helps! Here are the links to get started:

Have a separate savings account
Stop overpaying for car insurance
Finally get out of debt
Start investing with a free bonus
Fix your credit

Profile photo for Abhishek Bhardwaj

I couldn't understand your question. You simply load the LKM to "interface with kernel". Some more info would help us answer.

Profile photo for Vaisakh Sudheesh

Hi Santhosh,

In case of embedded Linux kernels, we do have board files defined under arch/arm/mach-<xxx>, in which the devices present on the board and the corresponding arguments for devices drivers are listed.

While kernel boots up, during the init calls, the drivers are registered against their names. After which while processing the platform device list, it is matched up against the registered list of drivers. On hitting a match, the corresponding driver probe function is invoked (passing pointer to platform data) to initialize the required functionality - such as interrupts, pin configurati

Hi Santhosh,

In case of embedded Linux kernels, we do have board files defined under arch/arm/mach-<xxx>, in which the devices present on the board and the corresponding arguments for devices drivers are listed.

While kernel boots up, during the init calls, the drivers are registered against their names. After which while processing the platform device list, it is matched up against the registered list of drivers. On hitting a match, the corresponding driver probe function is invoked (passing pointer to platform data) to initialize the required functionality - such as interrupts, pin configurations, handlers etc.

Now in the case PCI, the hardware shows up like a memory mapped interface (it was similar in case of Marvell's PXA platform, which I worked on, on x86 it might be through BIOS or some other mechanism but it will be similar), through which we can interact with the hardware. The first few block of memory for any PCI based device will have a descriptor kind of region which will contain information such as vendor-id, device-id, subclass, revision etc.

In Linux, the drivers while registering itself will export a pci_device_id table along with probe and other relevant information. Here is an example I took from LDD3

<snip>

static struct pci_device_id i810_ids[ ] = {
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1) },
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3) },
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG) },
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC) },
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_IG) },
{ 0, },
};

static struct pci_driver pci_driver = {
.name = "pci_skel",
.id_table = i810_ids,
.probe = probe,
.remove = remove,
};

</snip>


You can think of more like a driver informing kernel that these are the devices it is compatible with.

Now, when a PCI device is identified, Linux matches up against the registered device drivers (from the table registered earlier). On finding a match, it invokes the probe function of the same and starts off with rest of the processing and registration activities

you can get more insight in to PCI driver probe and registration sequence in the following links:


Hope this clears your doubt :)

Profile photo for Quora User

Here’s the thing: I wish I had known these money secrets sooner. They’ve helped so many people save hundreds, secure their family’s future, and grow their bank accounts—myself included.

And honestly? Putting them to use was way easier than I expected. I bet you can knock out at least three or four of these right now—yes, even from your phone.

Don’t wait like I did. Go ahead and start using these money secrets today!

1. Cancel Your Car Insurance

You might not even realize it, but your car insurance company is probably overcharging you. In fact, they’re kind of counting on you not noticing. Luckily,

Here’s the thing: I wish I had known these money secrets sooner. They’ve helped so many people save hundreds, secure their family’s future, and grow their bank accounts—myself included.

And honestly? Putting them to use was way easier than I expected. I bet you can knock out at least three or four of these right now—yes, even from your phone.

Don’t wait like I did. Go ahead and start using these money secrets today!

1. Cancel Your Car Insurance

You might not even realize it, but your car insurance company is probably overcharging you. In fact, they’re kind of counting on you not noticing. Luckily, this problem is easy to fix.

Don’t waste your time browsing insurance sites for a better deal. A company called Insurify shows you all your options at once — people who do this save up to $996 per year.

If you tell them a bit about yourself and your vehicle, they’ll send you personalized quotes so you can compare them and find the best one for you.

Tired of overpaying for car insurance? It takes just five minutes to compare your options with Insurify and see how much you could save on car insurance.

2. Ask This Company to Get a Big Chunk of Your Debt Forgiven

A company called National Debt Relief could convince your lenders to simply get rid of a big chunk of what you owe. No bankruptcy, no loans — you don’t even need to have good credit.

If you owe at least $10,000 in unsecured debt (credit card debt, personal loans, medical bills, etc.), National Debt Relief’s experts will build you a monthly payment plan. As your payments add up, they negotiate with your creditors to reduce the amount you owe. You then pay off the rest in a lump sum.

On average, you could become debt-free within 24 to 48 months. It takes less than a minute to sign up and see how much debt you could get rid of.

3. You Can Become a Real Estate Investor for as Little as $10

Take a look at some of the world’s wealthiest people. What do they have in common? Many invest in large private real estate deals. And here’s the thing: There’s no reason you can’t, too — for as little as $10.

An investment called the Fundrise Flagship Fund lets you get started in the world of real estate by giving you access to a low-cost, diversified portfolio of private real estate. The best part? You don’t have to be the landlord. The Flagship Fund does all the heavy lifting.

With an initial investment as low as $10, your money will be invested in the Fund, which already owns more than $1 billion worth of real estate around the country, from apartment complexes to the thriving housing rental market to larger last-mile e-commerce logistics centers.

Want to invest more? Many investors choose to invest $1,000 or more. This is a Fund that can fit any type of investor’s needs. Once invested, you can track your performance from your phone and watch as properties are acquired, improved, and operated. As properties generate cash flow, you could earn money through quarterly dividend payments. And over time, you could earn money off the potential appreciation of the properties.

So if you want to get started in the world of real-estate investing, it takes just a few minutes to sign up and create an account with the Fundrise Flagship Fund.

This is a paid advertisement. Carefully consider the investment objectives, risks, charges and expenses of the Fundrise Real Estate Fund before investing. This and other information can be found in the Fund’s prospectus. Read them carefully before investing.

4. Earn Up to $50 this Month By Answering Survey Questions About the News — It’s Anonymous

The news is a heated subject these days. It’s hard not to have an opinion on it.

Good news: A website called YouGov will pay you up to $50 or more this month just to answer survey questions about politics, the economy, and other hot news topics.

Plus, it’s totally anonymous, so no one will judge you for that hot take.

When you take a quick survey (some are less than three minutes), you’ll earn points you can exchange for up to $50 in cash or gift cards to places like Walmart and Amazon. Plus, Penny Hoarder readers will get an extra 500 points for registering and another 1,000 points after completing their first survey.

It takes just a few minutes to sign up and take your first survey, and you’ll receive your points immediately.

5. Get Up to $300 Just for Setting Up Direct Deposit With This Account

If you bank at a traditional brick-and-mortar bank, your money probably isn’t growing much (c’mon, 0.40% is basically nothing).

But there’s good news: With SoFi Checking and Savings (member FDIC), you stand to gain up to a hefty 3.80% APY on savings when you set up a direct deposit or have $5,000 or more in Qualifying Deposits and 0.50% APY on checking balances — savings APY is 10 times more than the national average.

Right now, a direct deposit of at least $1K not only sets you up for higher returns but also brings you closer to earning up to a $300 welcome bonus (terms apply).

You can easily deposit checks via your phone’s camera, transfer funds, and get customer service via chat or phone call. There are no account fees, no monthly fees and no overdraft fees. And your money is FDIC insured (up to $3M of additional FDIC insurance through the SoFi Insured Deposit Program).

It’s quick and easy to open an account with SoFi Checking and Savings (member FDIC) and watch your money grow faster than ever.

Read Disclaimer

5. Stop Paying Your Credit Card Company

If you have credit card debt, you know. The anxiety, the interest rates, the fear you’re never going to escape… but a website called AmONE wants to help.

If you owe your credit card companies $100,000 or less, AmONE will match you with a low-interest loan you can use to pay off every single one of your balances.

The benefit? You’ll be left with one bill to pay each month. And because personal loans have lower interest rates (AmONE rates start at 6.40% APR), you’ll get out of debt that much faster.

It takes less than a minute and just 10 questions to see what loans you qualify for.

6. Lock In Affordable Term Life Insurance in Minutes.

Let’s be honest—life insurance probably isn’t on your list of fun things to research. But locking in a policy now could mean huge peace of mind for your family down the road. And getting covered is actually a lot easier than you might think.

With Best Money’s term life insurance marketplace, you can compare top-rated policies in minutes and find coverage that works for you. No long phone calls. No confusing paperwork. Just straightforward quotes, starting at just $7 a month, from trusted providers so you can make an informed decision.

The best part? You’re in control. Answer a few quick questions, see your options, get coverage up to $3 million, and choose the coverage that fits your life and budget—on your terms.

You already protect your car, your home, even your phone. Why not make sure your family’s financial future is covered, too? Compare term life insurance rates with Best Money today and find a policy that fits.

Profile photo for Agus Budy Wuysang
  1. Improve your English, to understand the documentation & guideline of writing kernel code, and others can understand your in-line code comments later on.
  2. Download the kernel source & read/follow the Documentations/*
  3. Start coding.
Profile photo for INDIAACCESS AND HOSTASP

Signing VirtualBox Kernel Modules

Create an RSA key pair to sign kernel modules. ...

Import the MOK ("Machine Owner Key") so it can be trusted by the system. ...

Reboot your machine to enter the MOK manager EFI utility. ...

Create a script for signing all the VirtualBox kernel modules. ...

Execute the aforementioned script as root . ...

Load the vboxdrv module.

Profile photo for Mark Madsen

Kernel modules really refer to several different kinds of kernel code, just compiled into a “plugin” or module. Many aspects of kernel code can be compiled “as a module” or “compiled into the kernel”.

What makes something modular is that it exports an initialization routine, and an exit or cleanup routine. In code, you’ll see this in source code files like this:

  1. MODULE_INIT(function_name) 
  2. MODULE_EXIT(other_function_name) 

When you insert the module into a running kernel, by calling “insmod”, the init function runs. This is where you might allocate memory or do other actions to “set up” the function

Kernel modules really refer to several different kinds of kernel code, just compiled into a “plugin” or module. Many aspects of kernel code can be compiled “as a module” or “compiled into the kernel”.

What makes something modular is that it exports an initialization routine, and an exit or cleanup routine. In code, you’ll see this in source code files like this:

  1. MODULE_INIT(function_name) 
  2. MODULE_EXIT(other_function_name) 

When you insert the module into a running kernel, by calling “insmod”, the init function runs. This is where you might allocate memory or do other actions to “set up” the functionality in your module. At “rmmod”, the exit routine runs, and this is a place to clean up and make sure you’ve freed any memory used by your module.

Other than that, modules can really refer to a bunch of different things, and “how they integrate” will depend on what kind of kernel code it is. If it’s a block device driver, it will then follow the API for block devices, if it’s a filesystem loaded as a module, it will follow filesystem APIs, etc.

Profile photo for Fahim ul Haq

This is a well-worded question because, unlike coding interview questions, System Design questions are actually more concerned with your approach to the question than the actual answers you give. Let me explain.

I've interviewed hundreds of software engineer candidates during my time at Facebook, Microsoft, and Educative (the interactive developer learning platform I co-founded). The System Design loop has always been one of my favorites to conduct, because it reveals a candidate's creative process and their understanding of building a scalable system.

Here’s one tip I’d start with: Try to appro

This is a well-worded question because, unlike coding interview questions, System Design questions are actually more concerned with your approach to the question than the actual answers you give. Let me explain.

I've interviewed hundreds of software engineer candidates during my time at Facebook, Microsoft, and Educative (the interactive developer learning platform I co-founded). The System Design loop has always been one of my favorites to conduct, because it reveals a candidate's creative process and their understanding of building a scalable system.

Here’s one tip I’d start with: Try to approach System Design interview questions as though you are leading a discussion. SDI questions are intentionally open-ended so that you can take the wheel and show the hiring managers your design thinking approach. The vague prompt can be nervewracking, but remember that there is no right or wrong answer. Hiring managers are testing your ability to split a large problem into smaller components and apply your theoretical knowledge to real life situations. Your goal is to show that you make balanced, thoughtful design choices.

Here is how I recommend approaching system design interview questions:

  1. State what you know first: State the system requirements, including the traffic and problems you may expect to occur.
  2. Identify and state trade-offs: For each design choice you make, demonstrate your knowledge of how system components are interrelated by identifying a negative and positive effect of each choice.
  3. Ask questions: The hiring team wants you to ask questions! Be sure to clarify your system's requirements and priorities.
  4. Discuss recent developments in technology: Demonstrate your awareness of emerging technologies. (e.g. consider pointing out how machine learning could help your system).

I've seen many competent developers struggle with System Design interview questions because they are so different from the technical coding interview. But if you prepare the right way and know what to expect, these questions won't be difficult. To study, I recommend brushing up on system design fundamentals such as load balancing and CAP theorem. Then you can practice common system design interview questions, such as designing a web crawler, pastebin, or Facebook newsfeed.

I recommend the course Grokking the Modern System Design Interview to develop your system design fundamentals and practice real system design interview questions asked by top tech companies. You'll learn proven approaches to common questions as well as common mistakes to avoid. At Educative, we have already helped over 100K learners prepare for success in their system design interviews. I hope it might be of use to you too.

Good luck with your interview!

Profile photo for Pankaj Saraf

You have to to install ncurses package in your Linux Development environment. Then you have to run "make menuconfig", you will be able to see the gui of configuration file. Now, here you can change the configuration options for compilation of Linux Kernel.
Best of Luck!

Profile photo for Or Idgar

It is the interface that the kernel expose to the user space (where normal applications live).

It is also called system calls or syscalls.

For example, when you want to open a file, an application calls syscall for open a file. When it tries to read bytes from the file it uses the read syscall.

Other examples are writing to the screen, send and receive data from the network, stream music files to the sound card and many more.

Profile photo for Dave Ladd

I'm no expert, but I believe Android (the phone/tablet OS) can be said to match that description. So, clearly, it's possible.

Profile photo for Quora User

You have to design a frame work for your interface and expose to the rest of the kernel some primitives for using your frame work. Initialize your frame work from start_kernel function and there you go.

Profile photo for Andrew Droffner

This question makes no sense. The Linux Python interpreter is itself written in Linux/Unix C, and uses the operating system C kernel calls. This is a snake chasing its tail.

You could write a Python bytecode OS from scratch. This proposed OS must directly read the bytecode and translate it directly to the CPU instruction set. This may not provide complex features such as I/O for the open() statement, the bytecode might just jump to the Unix/C open() command to do this.

Profile photo for Sai Natarajan

A kernel module is a pre-compiled code that can be loaded into memory at runtime upon demand. In modern systems the kernel modules are automatically loaded by specific mechanisms when there is a need arising.

The linux kernel is modular and therefore, this design makes it faster to load the kernel into the memory. Modules extend the functionality of the kernel without the need to reboot the system. The kernel need not load and initialize all the unnecessary modules. Also at the time of developing device drivers when you have a problem/bug, one can unload the module, rectify it, compile it and t

A kernel module is a pre-compiled code that can be loaded into memory at runtime upon demand. In modern systems the kernel modules are automatically loaded by specific mechanisms when there is a need arising.

The linux kernel is modular and therefore, this design makes it faster to load the kernel into the memory. Modules extend the functionality of the kernel without the need to reboot the system. The kernel need not load and initialize all the unnecessary modules. Also at the time of developing device drivers when you have a problem/bug, one can unload the module, rectify it, compile it and then load it. There are many uses of this type of design.

  1. It saves RAM space.
  2. Modules can be independently compiled and loaded.
  3. Skipping the need to rebuild the kernel or reboot the device when you add a new module or load a module respectively.
Profile photo for Alan Dillman

You don’t see any of the kernel, you don’t interface directly with it.

When people talk about GNU/Linux, the gnu is what you do. The kernel is what your hardware does. You use tools (such as what GNU provides, and others), and these talk to the kernel, which talks to the hardware.

To do interfaces, you’ll want to learn things like ncurses and the graphical libraries like gtk and qt.

Profile photo for Nitin Chaudhary

Can you be please more specific about the interface you need, what it does and what are its functionalities.

Profile photo for Akhil Krishnan S

Threads are programming abstractions used in concurrent processing. (A subpart of a process which is in execution) A kernel thread is different from a user thread in the way to implement background tasks inside the kernel. It will run only in kernel mode. They are supported directly by the operating system.

Modules are pieces of code that can be loaded and unloaded into the kernel upon demand. Kernel modules need to be compiled a bit differently from regular userspace apps. For a monolithic kernal, they extend the functionality of the kernel without the need to reboot the system.

Profile photo for Raxesh

To insert kernel module, you can use insmod <module_name> command. insmod stands for insertmodule and in contrast rmmod <module_name> is used to remove the kernel module. rmmod stands for removemodule. Please note both commands need root permission to be executed.

Profile photo for Dave Jiang

Of course. As long as the custom module is built against the running kernel binaries.

Profile photo for Ishan Mittal

You'll have to add the config to the respective Kconfig (Kconfig of the subsystem you're trying to add it to).
Following is the way :

config <NAME>
bool "<description>"
depends on <if your new config depends on any other configs which must be turned on>
help
<Whatever you want to write as explanation>

Now if you include this in your defconfig, you'll start seeing it in your .config when you say setup the kernel configuration.

Profile photo for Larye Parkins

Loadable kernel modules (LKMs) can be loaded without recompiling the kernel. That is the literal meaning of LKM. But, if a new kernel is installed, it may be necessary to recompile the module. LKMs can be written to override existing system calls in the kernel, or add new ones, without the need to recompile the kernel or change the kernel code.

Profile photo for Levente Kurusa

Loadable Kernel Modules (or LKMs for short) are a way to extend a running kernel to deal with something new or unusual. A way to understand why these are useful is discussed in this question: Why are kernel modules useful? but for the sake of convenience, I’ll note a few things here as well.

  1. Not all drivers are used.
    If you are like most people, you don’t compile your own kernel specifically to your own machine but use a distribution (Fedora, ubuntu, etc.) provided kernel. Usually kernel maintainers of such distributions package up one kernel and send it off to everyone. Interestingly enough, s

Loadable Kernel Modules (or LKMs for short) are a way to extend a running kernel to deal with something new or unusual. A way to understand why these are useful is discussed in this question: Why are kernel modules useful? but for the sake of convenience, I’ll note a few things here as well.

  1. Not all drivers are used.
    If you are like most people, you don’t compile your own kernel specifically to your own machine but use a distribution (Fedora, ubuntu, etc.) provided kernel. Usually kernel maintainers of such distributions package up one kernel and send it off to everyone. Interestingly enough, somebody far away from you maybe running a network card that you don’t have. However, without LKMs, your kernel would have to contain the code required to handle that network card you do not have, wasting RAM. If you have LKMs, then you can just compile the driver as a module and load it *if and only if* you have that specific network card.
  2. For developers, if you are making a new feature often times, wrapping it in a module is enough and allows for faster iterations as you can unload a module and load the newer version straight away.

Nota bene, recent versions of the Linux kernel use the .ko extension to denote these modules and are often found in /usr/lib/modules or similar folder.

Profile photo for Quora User

Kernel threads is a running kernel modules loaded to be run on one CPU:

“ps -ef” gives (noticed how many copies jfsCommit exists - since each of them is scheduled to run on one CPU (it is possible to have more than one of the same kernel modules running on the same CPU as different threads too, looked at “kworker”):

  1. tteikhua 29186 23443 0 07:33 pts/16 00:00:00 ps -ef 
  2. root 31175 2 0 Sep19 ? 00:00:00 [xfsalloc] 
  3. root 31176 2 0 Sep19 ? 00:00:00 [xfs_mru_cache] 
  4. root 31181 2 0 Sep19 ? 00:00:00 [jfsIO] 
  5. root 31182 2 0 Sep19 ? 00:00:00 [jfsCo 

Kernel threads is a running kernel modules loaded to be run on one CPU:

“ps -ef” gives (noticed how many copies jfsCommit exists - since each of them is scheduled to run on one CPU (it is possible to have more than one of the same kernel modules running on the same CPU as different threads too, looked at “kworker”):

  1. tteikhua 29186 23443 0 07:33 pts/16 00:00:00 ps -ef 
  2. root 31175 2 0 Sep19 ? 00:00:00 [xfsalloc] 
  3. root 31176 2 0 Sep19 ? 00:00:00 [xfs_mru_cache] 
  4. root 31181 2 0 Sep19 ? 00:00:00 [jfsIO] 
  5. root 31182 2 0 Sep19 ? 00:00:00 [jfsCommit] 
  6. root 31183 2 0 Sep19 ? 00:00:00 [jfsCommit] 
  7. root 31184 2 0 Sep19 ? 00:00:00 [jfsCommit] 
  8. root 31185 2 0 Sep19 ? 00:00:00 [jfsCommit] 
  9. root 31186 2 0 Sep19 ? 00:00:00 [jfsCommit] 
  10. root 31187 2 0 Sep19 ? 00:00:00 [jfsCommit] 
  11. root 31188 2 0 Sep19 ? 00:00:00 [jfsSync] 

And the kernel module is just a dynamic ELF file which can be loaded into the kernel.

Your response is private
Was this worth your time?
This helps us sort answers on the page.
Absolutely not
Definitely yes
Profile photo for Genx Star

there exists specifics well defined instructions set and calls like IPC , I/o , dma ,interfaces like i2c , usb bus, pci . You need to adher to some standards, like you have stacks for various elements i.e. I/O ,network etc . A hw /sw driver is just piece of code and there exist standards to communicate with rest of code running system to send cpu calls , allocate memory registers etc.

Profile photo for Alexander Oganezov

The driver will identify the type of bus that it is trying to control. If it is an i2c device it will register itself as i2c driver and provide information that identifies the particular device on the i2c bus. Most buses tend to have a corresponding linux kernel framework that your driver would register with. Those that don’t or generic drivers can register themselves as an abstract platform driver controlling a ‘platform device’.

Profile photo for Justin Ray

Overview of Operating Systems and Kernels

Because of the ever-growing feature set and ill design of some modern commercial operating systems, the notion of what precisely defines an operating system is vague. Many users consider whatever they see on the screen to be the operating system. Technically speaking, and in this book, the operating system is considered the parts of the system responsible for basic use and administration. This includes the kernel and device drivers, boot loader, command shell or other user interface, and basic file and system utilities. It is the stuff you neednot a web

Overview of Operating Systems and Kernels

Because of the ever-growing feature set and ill design of some modern commercial operating systems, the notion of what precisely defines an operating system is vague. Many users consider whatever they see on the screen to be the operating system. Technically speaking, and in this book, the operating system is considered the parts of the system responsible for basic use and administration. This includes the kernel and device drivers, boot loader, command shell or other user interface, and basic file and system utilities. It is the stuff you neednot a web browser or music players. The term system, in turn, refers to the operating system and all the applications running on top of it.

Of course, the topic of this book is the kernel. Whereas the user interface is the outermost portion of the operating system, the kernel is the innermost. It is the core internals; the software that provides basic services for all other parts of the system, manages hardware, and distributes system resources. The kernel is sometimes referred to as the supervisor, core, or internals of the operating system. Typical components of a kernel are interrupt handlers to service interrupt requests, a scheduler to share processor time among multiple processes, a memory management system to manage process address spaces, and system services such as networking and interprocess communication. On modern systems with protected memory management units, the kernel typically resides in an elevated system state compared to normal user applications. This includes a protected memory space and full access to the hardware. This system state and memory space is collectively referred to as kernel-space. Conversely, user applications execute in user-space. They see a subset of the machine's available resources and are unable to perform certain system functions, directly access hardware, or otherwise misbehave (without consequences, such as their death, anyhow). When executing the kernel, the system is in kernel-space executing in kernel mode, as opposed to normal user execution in user-space executing in user mode. Applications running on the system communicate with the kernel via system calls (see Figure 1.1). An application typically calls functions in a libraryfor example, the C librarythat in turn rely on the system call interface to instruct the kernel to carry out tasks on their behalf. Some library calls provide many features not found in the system call, and thus, calling into the kernel is just one step in an otherwise large function. For example, consider the familiar

should (you hope) make no use of the kernel at all. When an application executes a system call, it is said that the kernel is executing on behalf of the application. Furthermore, the application is said to be executing a system call in kernel-space, and the kernel is running in process context. This relationshipthat applications call into the kernel via the system call interfaceis the fundamental manner in which applications get work done.

Figure 1.1. Relationship between applications, the kernel, and hardware.

The kernel also manages the system's hardware. Nearly all architectures, including all systems that Linux supports, provide the concept of interrupts. When hardware wants to communicate with the system, it issues an interrupt that asynchronously interrupts the kernel. Interrupts are identified by a number. The kernel uses the number to execute a specific interrupt handler to process and respond to the interrupt. For example, as you type, the keyboard controller issues an interrupt to let the system know that there is new data in the keyboard buffer. The kernel notes the interrupt number being issued and executes the correct interrupt handler. The interrupt handler processes the keyboard data and lets the keyboard controller know it is ready for more data. To provide synchronization, the kernel can usually disable interruptseither all interrupts or just one specific interrupt number. In many operating systems, including Linux, the interrupt handlers do not run in a process context. Instead, they run in a special interrupt context that is not associated with any process. This special context exists solely to let an interrupt handler quickly respond to an interrupt, and then exit.

These contexts represent the breadth of the kernel's activities. In fact, in Linux, we can generalize that each processor is doing one of three things at any given moment:

  • In kernel-space, in process context, executing on behalf of a specific process
  • In kernel-space, in interrupt context, not associated with a process, handling an interrupt
  • In user-space, executing user code in a process

This list is inclusive. Even corner cases fit into one of these three activities: For example, when idle, it turns out that the kernel is executing an idle process in process context in the kernel.

Profile photo for Dheeraj Kumar

There are several good books on Linux kernel programming. Linux Device Drivers is available online as well as on paper. Chapter 5 deals with concurrency; you can jump in directly to chapter 5 though it would be best to skim through at least chapters 1 and 3 first. Subsequent chapters have relevant sections as well (in particular wait queues are discussed in chapter 6).

The Linux kernel concurrency model is built on shared variables. There is a large range of synchronization methods: atomic integer variables, mutual exclusion locks (spinlocks for nonblocking critical sections, semaphores for blo

There are several good books on Linux kernel programming. Linux Device Drivers is available online as well as on paper. Chapter 5 deals with concurrency; you can jump in directly to chapter 5 though it would be best to skim through at least chapters 1 and 3 first. Subsequent chapters have relevant sections as well (in particular wait queues are discussed in chapter 6).

The Linux kernel concurrency model is built on shared variables. There is a large range of synchronization methods: atomic integer variables, mutual exclusion locks (spinlocks for nonblocking critical sections, semaphores for blocking critical sections), reader-writer locks, condition variables, wait queues, …

Credits : Gilles on stackoverflow.

Profile photo for Quora User

The first code that is part of the source code of a Linux kernel module that executes (at module load time) is the function marked as module_init(). take a look at a simple module: http://www.thegeekstuff.com/2013/07/write-linux-kernel-module/

Profile photo for Shaun Marolf

No but you will need the source code of the kernel version you’re compiling the module on. If you properly setup to use DKMS it will load the module for the kernel to use. Unfortunately it’s been a very long time since I had to compile a kernel module, so I don’t know all the requirements, or the process itself anymore. I just remember there are a few (a lot of) modifiers needed to compile a module correctly. The internet has a lot of information on this, what files you will need and the steps to do it.

Profile photo for Jesse Pollard

No need to write anything. Just mark the file attribute setting the immutable flag.

Unfortunately, doing so will block your updates.

Profile photo for Jesse Pollard

How do I run "invd" instruction from a kernel module?

Depends on the operating system and what you are trying to do.

The invd instruction itself wipes out cache. So using it in most kernel modules is not something you want to do as it will destroy the performance of the system.

It MIGHT be what you want when performing a context switch, but almost never at any other time. Context switching is not something done in a module.

Now MOST C compilers have an assembly language option (asm(“the line of assembly”)), and that allows you to embed some assembly in C.

It is nonportable to use it though, so such

How do I run "invd" instruction from a kernel module?

Depends on the operating system and what you are trying to do.

The invd instruction itself wipes out cache. So using it in most kernel modules is not something you want to do as it will destroy the performance of the system.

It MIGHT be what you want when performing a context switch, but almost never at any other time. Context switching is not something done in a module.

Now MOST C compilers have an assembly language option (asm(“the line of assembly”)), and that allows you to embed some assembly in C.

It is nonportable to use it though, so such operations are usually in an architecture specific library instead.

About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025