Giter Club home page Giter Club logo

vm-fdt's People

Contributors

aghecenco avatar andreeaflorescu avatar danielverkamp avatar dependabot-preview[bot] avatar dependabot[bot] avatar lauralt avatar mkroening avatar rbradford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vm-fdt's Issues

Improve the vm-fdt abstractions for v0.2.0

We can improve the vm-fdt abstractions after we publish an initial version of the crate so that we do not block the first release.

The current interface was built on purpose to be similar to the libfdt one, but we can optimize it (slightly) for Rust.

Things that can be improved are better abstractions for nodes. For example, we can have the property_* functions on the FdtWriterNode instead of FdtWriter so that we can disallow properties to be added in non valid locations (see #19).

Write the `Usage` section of README

In this section we can specify how the vm-fdt can be used and why. For example, we can write that the vm-fdt provides a way for exporting the VM topology.

Unchecked arithmetic operations in `finish`

Use checked arithmetic for operations that can fail. In debug mode these cause panics, in release mode they just wrap around.

For example, this operation should use checked_sub.

Below it's a regression test that triggers a panic in debug mode:

    #[test]
    fn test_overflow_subtract() {
        let overflow_size = u32::MAX / size_of::<FdtReserveEntry>() as u32 - 3;
        let too_large_mem_reserve = vec![FdtReserveEntry::default(); overflow_size as usize];
        let mut fdt = FdtWriter::new(&too_large_mem_reserve);
        let root_node = fdt.begin_node("").unwrap();
        fdt.end_node(root_node).unwrap();
        fdt.finish(0x48).unwrap();
    }

Remove/Move max_size parameter from finish function

In the current implementation of the FdtWriter, the maximum size of the DTB is checked at the end. If the size of the DTB is larger than the specified max_size an error is returned, otherwise DTB is padded such that the total size is max_size.

Chatted with @danielverkamp and this is a leftover from when they were using the C-based libfdt in crosvm, and it does not make a lot of sense to keep it this way.

The options we currently have are:

  1. removing this check altogether
  2. move the initialization of max_size to the new function, and in finish just check that the size is less then max_size without padding the structure with zeroes (as this is not actually a requirement).

Since the caller of the FDT interface is trusted, there is not a lot of sense to add runtime checks for each function that increases the DTB size (the DTB size is directly proportional to the number of function calls in the public interface) as this would introduce delays.

I am fine with either approach (1 or 2), but I was wondering if anyone else has some strong preferences here.

Pinging a few more people: @jiangliu @alexandruag @lauralt @slp @dianpopa

Provide a way to disable long running tests on dev machines

Running the regression tests for things such as overflows (see:

fn test_overflow_subtract() {
) takes a really long time. This is not a good experience for development when you want to quickly check if the changes you introduced don't add other problems. We should find a way to ignore those tests in development environments, and only run them with the CI.

One option might be to have these kind of tests under a feature since the CI runs the tests with all features enabled. This might be a bit awkward since it would a feature only used in tests. Having them with the ignore macro might not be a good option because it requires adding a specialized CI pipeline to run the ignored tests (or maybe this is a good option?). Are there any options here?

Only allow property to be added after begin node

Right now the following code works:

let mut fdt = FdtWriter::new().unwrap();
fdt.property_string("bla", "blabla").unwrap();

But I think that properties can only be added to nodes, and thus we should return an error here instead. To do that, we can check that node_depth != 0, which means that at least one node is created, and the property thus belongs to that node.

begin_node does not enforce limits defined in the specification

The FDT specification describes a string length of e.g. the begin_node of 1 to 31 chars and enforces a strict character limitation described in https://devicetree-specification.readthedocs.io/en/stable/devicetree-basics.html#node-name-requirements.

Enforcing the character limitation would mean adding a dependency on regex, which is undesirable. We could instead enforce the size limitation, and document the character limitation as something that is not currently validated.

@danielverkamp what do you think?

phandle property uniqueness

The phandle property can be used to reference another node within the FDT uniquely: https://devicetree-specification.readthedocs.io/en/stable/devicetree-basics.html?#phandle

Right now we are not checking the uniqueness of the phandle, and I think there are a few things that we can do:

  • create a public API for retrieving a unique phandle, similar to what is implemented in libfdt: https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/scripts/dtc/libfdt/fdt_ro.c#L114
  • add support for the phandle property; we could for example offer an API for setting the phandle of a node (once we clean up the abstractions to have a clear ownership between nodes & properties), and in the set function we can check for uniqueness. This would imply denying adding properties with the name phandle, or just check the name of the property, and in case it is phandle, check for uniqueness. It looks like this adds branching in the code, and we should discuss if we just want to go ahead with documenting this, or enforcing it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.