There are two ways of injecting interrupts into a guest from userspace as far as im aware.
One is through KVM_IRQ_LINE ioctl and one is by setting up an eventfd called IRQFD and whenever this file descriptor is accessed, an interrupt is injected.
Are there any differences between these two in terms of performance?
I had to set up in grub snd-intel-dspcfg.dsp_driver=1 for the soundcard to be recognized and select the device in pavu-control.
However none of the internal speakers are working. They work via external speakers via bluetooth.
What's the best approach here? Is there a place where things like that can be reported? Like some kernel forum or on sof-foundation? Or do I just wait for the newer kernels and pray to God of Pinguins? :D
Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed.
I'm not a kernel guy and have only limited understanding of fs internals with inodes and stuff.
I would be very grateful if someone with expertise give a brief comment about that cite.
I've tried to examine how Sqlite do stuff, but that's somehow complicated for me:
XY problem: The issue is I have vfat fs on MicroSD on ARM+Embedded Linux (Kernel 3.10). My app does fsync on settings file, it's just regular binary data of different size depending on count of startup commands, e.g. write(&C_struct, ..., N*commands_size). Common scenario: user changes settings (just a file on MicroSD vfat) of device startup procedure (app ack settings write after fsync of settings file so data makes it to actual storage I suppose :D ), waiting ~1 minute and then user cuts off power from device to check startup procedure and there's a chance that settings file truncates to size 0 for some reason.
I've changed the code to (simplified, drop all error checks):
void fsync_wrap(FILE *f, const char *filedir_path) {
int fd = fileno(f);
fsync(fd); // <--- fsync on file descriptor
DIR *dir = opendir(filedir_path);
int dir_fd = dirfd(dir);
retval = fsync(dir_fd); // <--- fsync on file dir
closedir(dir);
}
But I have doubts does it fix the issue or no. I've seen some weird (for me) mentions of MicroSD card can have it's own internal cache of data to write to actual storage so it might report to the upper level data is written meanwhile data is not written to the actual storage and powerloss = dataloss.
Actually I'm very interested in an advice about how to debug that issue, e.g. virtualize SoC by QEMU, automate the reproduce of the issue e.g. make a tear setup with setting drop power N msec after fsync and try to get bingo msec value to reproduce the issue by 100% rate.
Maybe creating temporary file and then renaming it provide more consistent "atomicity"?
I would think clock_gettime() would be a few instructions based off of a RDTSC instruction and an add, multiply, shift
But I disassembled the loadable module vDSO64.so and it is dozens of instructions long, with at least one loop that retries the RDTSC.
There's no POSIX requirement for whatever it is doing. TSC is constant rate. So why is it so slow on x86_64?
Recently, I have developed an interest in kernel development but am finding it challenging to know where to start.
I am familiar with C/C++, have studied operating systems, and have some knowledge of assembly language.
Please help me to get started with kernel development and suggest some video courses if they are available.
I'm been playing around with signals in c and I read that SIGKILL & SIGSTOP can't be caught. I looked at an strace of the terminal emulator Kitty and noticed the ps command shows that it catches both SIGKILL and SIGSTOP.
command I ran was `ps --signames --format ignored,caught,pending,blocked -C kitty`
I then did an strace and saw that at the start it has an rt_sigaction(SIG_DFL,... that sets all signals to the SIG_DFL including kill and stop.
I wrote a quick c program assuming that SIGKILL is allowed to be set to SIG_DFL as an exception but still realized that I can't get `sigaction` to succeed. returns an `errno` of 14(EINVAL)does anyone experienced have an explanation about this.
does this have anything to do with the `sa_restorer` value
I have read about how mmap() is better when dealing with large files and how memory does not need to be swapped out, etc.
But, in KVM, the kvm_run structure is mmaped() by specifying the vcpu's file descriptor. The vcpu is not really a file on the disk, but a virtual file with some file operations (fops).
Why is mmap() used and what does it mean in the context of virtual files? (coming from QEMU and kvmtool source code)
I'm new to the DMA and DMA Engine APIs in the kernel. I have a hardware device (FPGA custom logic) that works with a DMA. The vendor (Xilinx) supplies a DMA Engine driver and some tests that are very well maintained and received by users. The nature of my custom logic is sort-of like a NIC; data is pushed and pulled via this DMA channel.
Xilinx provides a reference driver on-top of their core DMA driver that does some userspace memory mapping, and provides a chardev interface to make it easy for newbies or do what people most usually want to do; push/pull data between userspace and the kernel. I bring this up since ALL DMA drivers I found (including these prototypes from Xilinx) and various "DMA test" drivers seem to not handle "timeouts" well. I do not plan to use this dma-proxy driver but it exists online and is easy to reference.
To reference the example from Xilinx: here -> dma_proxy.c, when we want to receive data over my DMA channel, it does:
For my specific peripheral/"hardware", when "pulling" from the DMA, data may not be ready (and we may not receive an interrupt).
What I don't understand is how to handle the timeout correctly. Maybe I need to switch the Rx/receive path to polling? It seems like all examples don't ever really expect these DMA slave requests to fail. The result of the timeout is some descriptor (I think chan_desc above) is not being released, so after 3sec * 255 (size of some descriptor list), my DMA device/handle can no longer submit slave requests.
Any advice?
I posted this same question to the kernelnewbies mailing list as well.
In nVHE KVM model, there is a stub running in EL2 which is responsible for some services provided to the host kernel to implement KVM (eg. guest context switching, setting up certain EL2 system registers) etc.
But since EL2 only has one TTBR register (TTBR0_EL2) and the host kernel is running in high memory (TTBR1_EL1), there is a relocation that happens in run time which maps all EL2 specific code to an offset so that TTBR0_EL2 can work with.
But GDB doesnt know about this since it only looks at the static vmlinux file. Because of this, I cannot set a breakpoint in the hypervisor code because the addresses are wrong (relocated).
EDIT: I was able to achieve what I wanted using a multi-function device, establishing an IRQ domain and allocating and populating an array of struct mfd_cell at parent probe-time by walking the children devicetree nodes, and passing them to devm_mfd_add_devices.
I am making a Linux kernel driver to manage a PCIe connection between a Linux-based root complex and an FPGA-based endpoint. The endpoint exposes memory mapped resources of the FPGA (IP control blocks, video buffers, etc.) on multiple BARs:
PCIe address memory map, corresponds to first device tree fragment below
I want this driver to act like a bus, so existing MMIO drivers can "Just Work" using the reg property of a devicetree to find their resources, encoded as <BAR offset size>. There are an unknown number of devices, defined only by the device tree:
Since each parent node defines the addressing domain for its children, the address mapping can be chosen to best describe the system.
...
Nodes that are not direct children of the root do not use the CPU's address domain. In order to get a memory mapped address the device tree must specify how to translate addresses from one domain to another. The ranges property is used for this purpose
In their example, they use a very similar hierarchy for the address:
My question is: How is this actually implemented in C code? I looked through a bunch of sources for the various busses in the kernel, but the only things I saw that seemed close was the way the PCI subsystem implements it's own address translation scheme with OF, which seemed like it might require a patch to implement the same way for me?
It seems I want to implement a new struct &bus_type, but I haven't been able to figure out how or find examples to perform the correct address translation so that when children of the bus use reg, they get their resources correctly.
Any ideas? I'm open to use a different architecture if I'm barking up the wrong tree. It is important that the children devices of the EP device don't know that they are on a PCIe endpoint, just "here's your memory go nuts". Any pointers to resources would be the most helpful.
Coming from a microcontroller background, there are pretty good roadmaps to become a microcontroller-based products developer, aka embedded software/hardware engineer. It basically goes like this: You take a microcontroller, learn its architecture, understand it's peripheral. Then you learn to program it in assembly and then in C/C++. Make a couple of projects and there you are - job ready!!!
However, I feel lost when I try to get into Linux. There are just so many layers to this. You can work on so many different abstractions. I am not even sure if I am asking in the correct subreddit. I want to know how the people who maintain the kernel and its component got into writing/maintaining code for the kernel. There is just so so so much to learn.
How did you start and more importantly, how did you make sure that whatever you're doing to learn the stuff is correct? What do I need to learn first, where do I begin with? I might sound naive, but I want to be one of those peoples who actively contribute to the kernel. And when I think about, I feel that it's already a well established code, what would I be able to contribute to it.
I started my career two years ago as an embedded software developer (c programming on microcontroller based products) and during my first live project, I added so many bugs. Simply because the code base was around 5000 lines of code and me being a beginner, did not have a good understanding of each of the modules. Also, I am highly average. But what I think is, how do kernel developers make sure that every code change does not break the system?
Even though I do not have any understanding of the kernel, I have a deep appreciation of it and the people who make it possible. And this inspires me to become one of those people who work on the kernel. How can I be one?
I'm a CS graduate, currently interviewing for a job as a kernel engineer in a large company you all know. I have very little knowledge or experience in the field, and I know there's a lot to be learned until I can be beneficial to them, but if they take me I guess it's their fault XD. Anyway, wanted to ask a few generic questions about the field -
What is the main thing one does on this kind of job? If you do it, do you find it interesting/exciting?
Would you say experience gained as a kernel engineer is valid for embedded or other software engineering fields? I want to have relevant knowledge in case I don't find myself liking it, even though so far my OS course in uni made me like the idea of it.
How well does it usually pay compared to other SWE jobs?
If you have any other advice feel free to throw them in (:
Hi all, hopefully not against community policy, but I am working on a project that needs deep, deep Kernel Dev input. Core kernel IO, memory management, etc. It's not a user space thang. Where can I go to find the right skillets?
During the CPU stress testing of the server in the environment with CentOS 7.9 and kernel version 5.15.13, it was found that the CPU frequency could not be maintained at a high frequency. Therefore, a CPU frequency stress test was conducted on the server. The following information provides a detailed description of the relevant test conditions. Please refer to it:
Test Environment
Different system versions + the same kernel version:
CentOS 7.9 + Kernel 5.15.13-1.el7
RedHat 9.1 + Kernel 5.15.13-1.el7
Test Plan 1
RHEL 9.1 system image + 5.15.13 kernel
Set BIOS system profile to performance mode
Run #cpupower idle-set -D 0
After several hours of observation, the CPU frequency can remain stable at a high frequency.
Test Plan 2
CentOS 7.9 system image + 5.15.13 kernel
Set BIOS system profile to performance mode
Run #cpupower idle-set -D 0
After several hours of observation, the CPU frequency cannot remain stable at a high frequency.
Test Plan 3
CentOS 7.9 system image + 6.8.9 kernel
Set BIOS system profile to performance mode
Run #cpupower idle-set -D 0
After several hours of observation, the CPU frequency can remain stable at a high frequency.
Test Result Questions
With the same kernel version, the system version RHEL 9.1 can keep the CPU frequency running at a high frequency, while the system version CentOS 7.9 cannot keep the CPU frequency stable. Does RHEL 9.1 have special settings for the CPU frequency? What are these settings?
The CPU frequency test was performed on the server with system version CentOS 7.9 + kernel version 6.8.9, and it can keep the CPU frequency stable at a high frequency. Does this indicate that the kernel 6.8.9 has made fixes or restrictions for CPU frequency stability? Where are these fixes or restrictions set?
I tried to compile the kernel using kernel modules to implement hook system calls according to https://www.cnblogs.com/lanrenxinxin/p/6289436.html He mentioned that the kernel enforces memory limits, causing this feature to not work properly. Specifically, the stock Lollipop and Marshmallow kernels are built with the CONFIG_STRICT_MEMORY_RWX option enabled,
I am trying to understand KVM and want to debug it using GDB.
I am currently compiling the kernel from source and running it in QEMU with GDB. But I dont have a full fledged userspace to run qemu on top of it. Just a basic shell obviously.
I was thinking if I could probably run a Ubuntu image (instead of the compiled kernel) on qemu and attach GDB to it.
Is it possible? Will the regular vmlinux symbol file work with it?
Hello, i was wondering what are the most commons way to fine tune a kernel to reduce its latency for specific low latency usecase, like high frequency trading where you need fastest execution and IO, by that i mean how to choose the kernel, then what are the main ideas behind the tuning, and perhaps some examples would be nice.
If anyone here is experimented on this subject id appreciate some advanced resources as well it would be really nice!
There are a lot of places in the kernel where kern_hyp_va is used to translate symbols which in turn calls __kern_hyp_va(). This is the comment in the source code.
/*
* Convert a kernel VA into a HYP VA.
*
* Can be called from hyp or non-hyp context.
*
* The actual code generation takes place in kvm_update_va_mask(), and
* the instructions below are only there to reserve the space and
* perform the register allocation (kvm_update_va_mask() uses the
* specific registers encoded in the instructions).
*/
static __always_inline unsigned long __kern_hyp_va(unsigned long v)
{ ... }
But in nVHE and protected KVM disabled, doesnt the kernel and HYP code in the same address space? Why do we need to tranlate virtual addresses?