Ubuntu Core enablement changes#12
Ubuntu Core enablement changes#12artiepoole wants to merge 5 commits intoXilinx:xlnx_rel_v2025.2from
Conversation
|
@artiepoole We’ll check this and get back in a week. |
83fd6da to
9095844
Compare
|
@tjaysukh, Thank you for the haste! I created this as a draft. There have been some tweaks since creation, so please take these into account during assessment. I have now tested it more thoroughly and have marked this as "ready for review" |
9095844 to
740ac2f
Compare
|
@artiepoole, Please let me know your thoughts. |
|
Thanks for the feedback. On point 1), yes, I am happy to implement the direct I/O. I'll do in a follow-up commit. I will also adopt that for libdfx as well, if the responsible team agrees. I also agree with point 3) about waiting for libdfx before merging. I'll mark this PR as draft until the direct IO is implemented and update you here when I think it is ready for review. Best, |
|
Hey @tjaysukh Please see the latest commit for changes regarding removing system calls. Please note that I did not touch any parts of the repository which I am not familiar with (e.g. contents of Edit: If I am to remove the state.txt from libdfx, several of these functions could be moved to libdfx to reduce duplication. This got me thinking - why are they separate projects - are there other projects also using libdfx?
|
|
@artiepoole , I think libdfx should only expose dfx related symbols not the generic utility functions, any further change to ABI of those functions would(should) trigger a library transition for the tools depending libdfx. Ideally I would like to see those common utility functions sourced somewhere common for both libdfx and dfx-mgr but not tied to the library itself. |
src/daemon_helper.c
Outdated
| * Strips trailing needle from haystack - e.g. `\n` from file read | ||
| * results or `/` from paths before concatenating. | ||
| */ | ||
| void strip_trailing(char *haystack, const char needle) |
There was a problem hiding this comment.
can we make this static as well?
src/daemon_helper.c
Outdated
| * Return: 0 if the overlay status "applied" and path matches requested_path, | ||
| * -1 on error or if either assertion is false | ||
| */ | ||
| static int check_overlay_was_applied(char *overlay_dir, char *requested_path) |
There was a problem hiding this comment.
this function modifies overlay_dir so it is not just a check. can we make it so it doesnt do that and use const in arguments to indicate this.
or at worst document this in function header so people are aware that this will change the arguments sent.
For requested_path, I think we are safe to add const easily.
src/daemon_helper.c
Outdated
| char read_buf[128]; | ||
| const char *state_applied = "applied"; | ||
|
|
||
| strip_trailing(overlay_dir, '/'); |
There was a problem hiding this comment.
we might not need this at all, it is best to verify behaviour for //path though
There was a problem hiding this comment.
I will test. usually works for bash cmds otherwise I will copy the buf before modifying
There was a problem hiding this comment.
I decided to make a copy into full_path. strip trailing and assemble the full path in 3 steps instead. This functionality is now moving into libdfx, however, so have made those changes there
src/daemon_helper.c
Outdated
| * Return: 0 on success, | ||
| * -1 on error (e.g., failed to open, write, or close the file) | ||
| */ | ||
| static int write_path_to_overlay(char *overlay_dir, const char *requested_path) |
src/daemon_helper.c
Outdated
| // ignore bits >= 1, only care about partial or full. | ||
| if (write_to_fpga_flags(flag & 1)) { | ||
| DFX_ERR("Failed to set flags"); | ||
| goto ret; | ||
| } |
There was a problem hiding this comment.
I dont see it errors and jumps to the ret on the original file, it could be missed in the original implementation but just wanted to point out the behaviour change here
|
I see DFX_ERR already handles strerror so please ignore my comments about strerror: https://github.com/Xilinx/dfx-mgr/blob/master/src/print.h#L43-L47 |
c3a460a to
0a3a47c
Compare
|
Hey @tjaysukh, I have removed the need for Just fyi, the whitespace is a mess in daemon_helper.c - a mix of spaces, 4-width tabs and8-width tabs, all within the same functions and sometimes the same lines. It was very difficult to make changes and maintain these whitespaces. For this reason, I suggest looking through the changes with "ignore whitespace" on at first, and then enabling whitespace differences after understanding the functional changes. It may be worth enforcing a clantidy and clangformat style for consistency. p.s. I tacked on Talha's suggest const changes, but only for the functions I touched. I also added on newline to a load error print which has been annoying me for ages. Let me know if you'd prefer those/anything else here separately. |
|
Thanks again for the changes and your efforts. I’ll review and test everything, then get back to you
I need to discuss this with the stakeholders. As of now, in the lightweight use-case flow, dfx-mgr is not dependent on libdfx, but with this change, as you mentioned it will become heavily dependent on libdfx. I want to ensure everyone is aligned before we proceed. |
|
Hi @tjaysukh,
If necessary, it would not be difficult to recreate the functionality in dfx-mgr standalone. I was not aware of the need for this mode :) Just let me know what the ultimate decision is. |
|
Hey @tjaysukh, I'm just bumping to ask if has there been any update? Best, |
|
@artiepoole, |
|
Thanks for the update, I am currently testing the changes will keep you posted. |
src/daemon_helper.h
Outdated
| int user_unload_overlay(char *region); | ||
| int user_load(int flag, const char *binfile, const char *overlay, const char *region); | ||
| int user_unload_overlay(const char *region); | ||
| int user_unload(int handle); |
There was a problem hiding this comment.
Please updated the user_unload() declaration with const as function updated.
int user_unload(const int handle)
There was a problem hiding this comment.
I am willing to do this, but it's not typical for values passed by value - this value of handle is a local copy inside the function, and so the const here does nothing (as in, it is ignored in the header file) - at least that is what I understand
There was a problem hiding this comment.
What I mean is that the function definition in src/daemon_helper.c was updated to int user_unload(const int handle). but the corresponding function declaration does not match this definition.
There was a problem hiding this comment.
Ah, I understood that. I pushed back for the reasons explained below, but have just learned that it is preference, and so did as you asked 🫡 - sorry for any frustration.
my point of view
it is explained in the C/C++ standards that it does not matter, and clangtidy regards it as a linter warning/redundant code. In fact, my IDE suggests to remove the const from the header declaration. That's why it wasn't there and I didn't want to put it there.
The reference for the redundancy is point 3 of the Parameter-type-list section of CPP Function specs
…ting location Use `/sys/kernel/config/device-tree/overlays/` instead of remounting Signed-off-by: Artie Poole <stuart.poole@canonical.com>
Note: The implementation for controlling firmware is implemented in libdfx.h/.c to avoid code duplication. The kernel provides a mechanism to set where firmware loads will look to match filenames during probe events. This file is located at `/sys/module/firmware_class/parameters/path`. These changes remove the need for copying firmware files into /lib/firmware. The /lib/firmware location is still probed if the file is not found in the custom location. See https://docs.kernel.org/driver-api/firmware/fw_search_path.html for more information. Signed-off-by: Artie Poole <stuart.poole@canonical.com>
This also removes the need for a `state.txt` file, so we stop creating the `/run/dfx-mgrd` directory because it is no longer necessary Signed-off-by: Artie Poole <stuart.poole@canonical.com>
0a3a47c to
454f56b
Compare
Signed-off-by: Artie Poole <stuart.poole@canonical.com>
Signed-off-by: Artie Poole <stuart.poole@canonical.com>
454f56b to
1be2d55
Compare
|
I have completed testing the dfx-mgr application on my side, and everything looks good. Before we merge it to GitHub, it will go through the internal regression testing. Once that is completed, we will proceed with the merge. |
In an ongoing attempt to enable fpga device functionality in Ubuntu Core, three issues have arisen in relation to the requirement for snaps to be strictly confined. In our case, we are attempting to redistribute dfx-mgr (and libdfx) as part of FPGAd. Once the concept of "softeners" is in place, this snap will enable downstream customers to use dfx-mgr as they expect to be able to, but with the caveat that FPGAd will be the gatekeeper for accessing the FPGA subsystems.
In these efforts, we found three challenges in the way dfx-mgr and libdfx operate:
state.txt. In real operation, this file is created at/state.txtwhich is not allowed in a strictly confined snap, and no layout can be applied to files in the root directory, except as files inside known pre-defined directories./configfs. This mount call requires strong permissions, which the store team can't/wont to grant to the fpgad snap.In order to tackle these three problems, I have edited dfx-mgr and libdfx with the following solutions:
/etc/dfx-mgrd/state.txt/run/dfx-mgrd/state.txt. I would actually prefer to remove the "system(command)" calls to mitigate the need for this file at all, but that is out of scope here./sys/module/firmware_class/parameters/pathinstead. The implementation is in libdfx.c/.h to avoid code duplication./configfsare removed, and all paths pointing to "/configfs/" are replaced by/sys/kernel/config/Please see Xilinx/libdfx#6 for the libdfx changes
Please do not hesitate to suggest changes or ask for clarification.