here we go I'm Daniel I work for Red Hat I'm a blah blah blah software engineer there and I work in the real-time team but I actually love to work in the university and I actually work from a university in Pisa or I'm leaving now and I'm trying to connect those real-time in Linux kernel and now run time verification in the Linux kernel and read had believed on my ideas and now I'm working on this and let's see what you all think so Linux is critical there are many people saying that in the future we
might use Linux on cars and as a kernel developer I know that the kernel crashes and the cars and crash isn't a good thing right and another point is that Linux is complex for later we will see that model for a part of the things on inner skin can reach a number a huge number of states and it's even hard to explain those things using words because they might be contradictory and it's not easy to translate those things but because of the critical size of Linux any in the complexity of it we need to be
sure that Linux behaves as expected but what do we expect from Linux right okay we have a lot of documentation explaining what we should expect of deadline scheduler for example or the prime 30 we have many different languages I'll learn Linux in Portuguese for example and we have a lot of assertions in the code that say ok if this happen and I generate a warn on you guys nobody should use a bug on anymore we learned that and we have a lot of test cases and fuzzing and all those stuff to try to check if
the system behaves and all these things are good but it needs something more reboost for example how do you check that our reasoning in how to check that what we are writing is correct and how do we check that or know that or asserts are not contradictory for example in the real-time community we say that we do not cow is casual err when we have a preemption disable right that's a common knowledge but actually these scheduler is called always with preemption disabled so this kind of corner cases of understanding it's hard to assert on our
natural language and how do we check that we are covering all the cases on our tests and we are expressing all the behavior of Linux and how can we verify all these ideas so but the main point when we go to save critical systems or when we go to talk with mathematicians on the real-time community for example is that how do we convince people of our properties like it's easy to convince myself Daniel that Linux is a good thing you know and it will be very easy on these audience I would not need to explain
me anything but when you go to use Linux on cars you need to convince certification authorities and they would like something more than just a Linux grand explanation and what people in computer science say about it when we need to to explain complex behaviour right people say formal methods that that's the first thing that comes to our mind and we have some successful example of formal methods applied to the Linux kernel we have the memory management the memory model that has a lot of examples and catch problems on memory model we have some somehow formal
locked app there are many working groups using formal language for example people own arm Gately marinas like he wrote de this pinlock implementation and use temporal logic to find bugs so we have some good examples of formal methods apply to the internal but we need a more generic into it in the intuitive way for modeling other parts of the kernel or a more broad behavior not just a simple behavior of a subsystem like memory or locking but a way to connect many subsystem on a higher level or in design level so how can we turn
this easier the answer is like is using a formal language that looks natural for us like and how do we naturally observe the dynamics of Linux we trace we have a lot of tools for tracing we have F trace and we have birth and now BB F and we can do a lot of magic we have trace and we've tracing subsystems and why you're tracing we are inside our minds create some sort of state machines and that's natural for operating system developers because we read a lot of books saying the states of a task on
an operating system write the disease this this seems to be one way to go or an intuitive way to go like I just copy and paste these from the gigs for gigs yeah that's a very computer science name so so when we think about state machines in formal methods one possible solution is the usage of automata so we can use automata for many things but also to specify even prevent systems and on even driven systems we we see the evolution of the system as events or a sequence of events that forms the language that dead
system talks and we we can also do use it for around time analysis so this is a simple example I'd say that we want to to to write or to specify how a client a network client a bugs Network line works we can say that we can open and close a connection and then we can write icon requests and read the response right this is a very simple case I mean it's easy to read in this format but the good thing about formal methods that we have a mathematical description of what we explicit I and
here I will not enter in details here but in the end one out order is an a set of states or for example set of states affinity set of events and a state transition saying that all in a given state and we've given event what is my next state so we have everything is specified deterministically the specified automata allow some kind of implicit verification like I can check if the reasoner I am expressing his deadlock free lock free and it also allows you the modular development of system by using operations mathematical operations and if you
will try to to do an exercise on this so this was the previous example and we can model this as a separate set of modules so we can say that one module is the open and closed so I can open and then my sock will be open and I can close and any to be closed and then I can be ready to write and then I write a request and way to request and read it so very straightforward then I can synchronize these two small models and create a big model that represents all the chain
of events that are possible or that might exist on a synchronized version of the system there will be a set of it's hard for Italian to speak with top it and I'm I need to move so so here we have a set of events that we expect like open closed and rewrite in a set of that we don't expect like it's not correct to write before opening and it's not expected to close and open while we are in the middle of a connection this is just an example right so then I get events of two
or more generators and put inside a small model to synchronize the operation of these events what we expect so I say that I can close again I say that I can close why I am NOT in the operation and I can say that I can only read and write after opening this soft ok it makes sense simple and then while modeling there are some tools like here I'm using Supra mica which is academic - but it allows us to do anything I need and it says ok the system is blocking this is an implicit e-verification
that might that gives me evenness that system is either with a live lock or a deadlock so here I take the model that is created from the synchronization of our events and I see that there is something strange here because I can ok I can open it but I cannot return to the initial state so there's something wrong with my specifications and then what was wrong say that I can read right after opening but I cannot after I closed it with these are synchronized we have the system I had at the beginning right why my
do not draw it Daniel yeah that's easy well why all these these problems because Linux is complex right Linux is way more complex than just restate for example I model the behavior of the parameter T and just for the single car case using the the level of abstraction that I was using was not a cold it was distinct Rinna's ation including irq zebra q enable preemption control locking and nested lock in any scheduling and so on on the level that we as a real-time developers work and I end up having a a model with 9000
states in more than 23,000 transitions now I could write this but not in the in the time of my PhD and I think I would need some bands like some two or three to draw it so just drawing the model by hand it's not sufficient when you have a complex system like Linux using this modular approach I could break down all the problem on the 12 generators like small subsystem independent and 23 specifications which in the end are properties that I wanted to express and during the development we found actually for now books that would
not know tree bugs that were could not be detected by any other tool available on Linux so let's just have a look on that case right so I can set need risk at when there is a newer higher priority tread I can I have a task on a slip above state then if I wake it up or a itself set each state as runnable I got runnable and return to sleep of of state I can call this scheduler and return to the scheduler I can Cybil preemption to not call the scheduler or disable preemption to
actually call the scheduler I can say boy Eric you to avoid Eric use or to wire run in Eric you of whatever in currency because I our queues are not framed both on Linux we can get a task and switch in and out and these were the generators and now I'm start to expressing and in joining all those producers Auto notice I would have a view of all the of the transaction and now I know be sure that it would not be forgetting anyone now I start to talk the properties that I expect from Linux
for example one property is that the scheduler will never be called Wi-Fi or accuse disabled and that the scheduler will necessarily be called we've scheduled with preemption disable to actually run this scheduler and I can say that the contacts which we've always run inside the scheduler that SCAD need were scared and scared waking we will always take place with ir accuse and preemption disabled and this guide all the necessary conditions to cut the contacts wage and I know it's boring and I did it on weekends because it was in the very beginning it took me
a while to convince redhead I could work with this on full time and it was summer in Tuscany it was very boring but I liked it I have to admit it was nice like doing a break it was nice to show that we have a deterministic set of instructions that that that makes the parameter D deterministic that was the challenge I was looking for and that that is one good example before I was talking about necessary conditions in which having the necessary conditions that event can happen or cannot but there is there are also the
possibility of doing sufficient conditions that says that after one one thing happened I am sure that it will order event will eventually happen so for example after I said need risk at I will want to return to the initial State after having the context switch that is I am forcing this scheduler and I am blocking all these leap above operations until there I'm just trying to find the fastest way to call the scheduler while block in other kind of code here I can abstract either asleep or code on Linux or a code that are called
outside of a brain disabled section and so these are the possible paths and I always return to the initial state after a context with this is a formal way to say that that there is a deterministic set of events and sequence of events that will bring me they need for rescaled to the scheduling of the highest priority tried on Linux and that's a good property for the to show in the real-time realm right so a parameter T is deterministic somehow and talked into other communities this idea of modeling the approach of modeling and the model
it was accepted there is one Journal paper on on the review now so yeah that's that is how tomorrow that was the first part but how do we use the model and how can we check the modernist Linux and the Linux against the botto to try to get something meaningful for us as kernel users or developers so in the first part of the project I used something that is called offline runtime verification in which I the modern I talked him first about the modeling in then I will reach in a briefcase so in one hand
I start modeling with the formal and informal knowledge about Linux how it works I am a developer I somehow know how it works and the kernel and then I start modeling my knowledge II and tracing the system and then I collected trace of Linux and at that time I took birth and tried to run step by step the automata with the feed from the trace from the kernel right then I was trying to validate the the model and at the beginning I found a lot of problems on my model because my reasoning was in complex
or was wrong but at some point in time I start to seeing problems that were not in the model they were problems in the kernel and then it was the point in which we found is useful for a runtime verification because before I was just trying to explain the behavior of the parameter T so it was good but on a mucho in the sense that I found bugs the automata verification as you see it's it's it's done in a good timing we see this later but as I was tracing the system in the as the
granularity of the events is so small I reach cases in each in a single core for 30 seconds i generated 2.5 gigs of data and that's a massive amount of data and i was not even tracing all the functions was just tracing the synchronization so what could we do to turn it better so I translated that from an offline kind of runtime verification into a online in synchronous from time verification and these are the steps and I'll explain one by one so in the first place we have the big model and then I have to
translate that model to something that we can run on a computer right so I wrote a Python script that just translates the formal definition of the model into C code yay and here's one example of the code translation I have the zero simple model in which I said that while imperative I will not call the I will not wake up a task that is the necessary condition to call the schedule a Kinney's disabling preemption and I just run the script and voila I translated the the set of states into an inner in the set of
events on one and all and I used the classical definition of automata and I fulfill the automata with the data from the fulfill d.c definition of the automata with information from the real automata and it turns out to be very simple data structures and we will see why it's good now I hope so that was generating a code now we need to try to code to link that out to self generated code with the kernel and so here is one of the here is the main function on the front I verification which is anytime I
receive one event from the kernel like disabling preemption I will call this function telling which event I am receiving right and here is just the information information about the tracing where I store data so I get the current state given the current state and event I am receiving I'm getting the next I'm expected to go if it's a possible state I go to the next state I might bring some debug information or not but if it's not expected I bring to the bug information in like to a stack trace I can take any action but
here's just an example sector now going into the functions so get the current state is a variable lookup set the current state is writing into a variable get in the next state is a matrix lookup simple things getting the name of the events is also getting the name of Mantinea and states are just vector lookups so yeah all the operations are all of what and this means that doesn't matter how frequently I call TD the event yeah doesn't matter how frequently that will not affect what we effector is the number of states are no better
the number of states doesn't matter what matters the frequency that I call these titties verification code and I just use one variable to keep the state so these are good properties and in the end I load the model and while running the system if I don't find any exceptions if one event that's not recognized it doesn't happens I can do I can bring it into the trace buffer or I can just ignore because things are working fine and if some unexpected event that happens I can bring some information so here's one example let's say that
I was that I catch one case in which I was in the primitive state and after disabling I after returned to the initial state I had the cat waking which was not expected and then I say hey there's a problem here and this problem was a bug in the tracing subsystem and that a bug that no other two could catch and I forgot to open the link but here's the link and here's information so ok nice but we know that there is no free meal right it's nice to say oh it runs it's all of
one and uh okay I was using a not compact structure by using a vector right but I was thinking if I add any structure data I would have to lockups in no in oh of n or o of n by the numbers of events that can be caught on that state and the overhead of putting linkings and other things will be to hide for just one variable that I want to store them and also for the prime charity model which is a let's say a big model it uses only eight kilobytes of data it's not
that much it's affordable for another's computer for doing verification so it Indians it's acceptable and in practice we don't need such a big model like I did we can check just some property of the system that we want to observe it's better to have a good model a big model because it's more efficient but I can just check some properties if I wanted to for example I can do y ou testing the latency on the parameter T I can also try to catch cases in which I would potentially going to sleep while I in an
atomically context or when I cannot go sleep because I'm either within Eric you are pension disabled so I could run could try to catch a logical problems in the prime 30 while running TDD performance II measurements so we can do more things at us if the thing is performs well enough right and that's what do you see now how efficient is this idea okay it's nice to say it's all of one my boy but in practice like we need to see things on the on the way that we like with benchmarks right so I need
two benchmarks I use the fur Onix test suite which I like it and it's good for doing academic papers because the format the outputs on SVG and we can do a lot of transformation on the graphs and it's very nice an ID test for throughput and for latency which is determining I like more so the base comparison in the kernel s is is the kernel without any trace or verification just the kernel running and the trace is why you're tracing the events that I'm verifying but just tracing it not processing just saving it in the
trace buffer and I'm using that model in the prime 13 so when not calling kernel as expected it would not cause many interference right it's sometimes it's even in the error margin so not calling the Carnot it doesn't affect okay that's expected and it's good that things are as expected but when we start to doing higher activation on the kernel we will see some performance degradation that's that's normal right that's what there is more code running there but the good thing is that the verification is now is in between the baseline kernel and the tracing
and also like you're running the latency tests with the cyclic test like this is the line of kernel decide the prime charity kernel running and this is the line with verification and this is the line we've traced so it causes less overhead then tracing because we are not storing data in the traced buffers the number of operations are bounded there are smaller than tracing so it I don't want to say that tracing is bad so because I'm friend of Steven and I like him what I wanted to say is that this approach is efficient enough
to be used in production because we can trace in production writing as we can trace in production we can do verification as well because we don't cause more damage than them and actually I'm using the trace infrastructure to hook the events to the kernel wire Ronnie so trés users and that this idea was also academically accepted like I talked to them and they liked and there are more things to come so it's possible to model complex behavior of Linux using a formal language creating big models from so on and it's also possible to verify properties
of the auto and the as automata is a run an executable formalism we can also run other kinds of formalism on top of the automata rather than on the code like using temporal logic and it's possible to run TTT verify the runtime behavior of Linux so now I'm working with I Steven an hour now to to make a generic subsystem I don't know how to say this or a generic a way to to run the the to verified system using automata now both with perf because there are cases in which it's better to use an
offline runtime verification and we have trace when it's better to use an online for runtime verification also I need to explain this using I have all these described in papers but papers are boring for this community and we would prefer to read things on lwn because it's you know you know I like lwn too so we were talking to try to translate all these ideas into a Linux kernel natural language and there are other things that we need to model on the system like parts of lock tab for example and the first because like one
one reason to try at least is that as I'm using dynamic trace I can run all these things and plug in and unplug while the system is running I don't need to recompile if I already have the events I need so it's handy and I was talking to Doyle Fernandez we are trying to make something with our CU and trying to show that this idea is not only applicable for one case because it would not be useful if it's just for my case alright but okay it's worth mentioning now like I say there are many
good things about the runtime versification Flynn Lara is an automata but I don't want to say that this is the only way and that this is the best way it's not it's not the best way there are a lot of ways to model Linux we can model on a code level and trying to explain it to explain like the behavior of spin locks and using like primeira and then using temporal logic to verify that's one kind of from a model where the form of verification we can run we can also have from runtime or static
code analysis that our people find a lot of bugs and fixing bugs with that so the theory I'm working here is for a runtime behavior for system for more Design level not can't be used also good level puts more Design level thing and there is a space for a lot of research on formal methods on Linux kernel there are many good people working on many good projects there is the the personal project verifies that drivers for Linux its Linux test not or gating and there are the thing with coccynelle they also based on julia also
works on this so there are many good people working and the more and more we will see the application of formal methods on linux and the more we see the better the more abstraction the better the more ways to verify it it's better because we don't want two cars to be crashing because of linux crash that's it it went fine so thank you for not sleeping you