Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memfd: make memfd_open() skip fd attributes not needed for vma mapping #2244

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

osctobe
Copy link
Contributor

@osctobe osctobe commented Aug 10, 2023

There is only one user of memfd_open() outside of memfd.c: open_filemap(). It is restoring a file-backed mapping and doesn't need to F_SETOWN nor update the fd's position.

An optimization / cleanup.

criu/memfd.c Show resolved Hide resolved
@osctobe osctobe force-pushed the memfd-lseek branch 6 times, most recently from 5971864 to 4d15648 Compare August 22, 2023 10:05
@avagin
Copy link
Member

avagin commented Aug 23, 2023

The inhfd tests have been broken.

2023-08-22T11:03:39.7424214Z + ./test//zdtm.py --set inhfd run --all --keep-going --report report -f h
2023-08-22T11:03:40.0318668Z userns is supported
2023-08-22T11:03:40.0717599Z userns is supported
2023-08-22T11:03:40.6251187Z userns is supported
2023-08-22T16:40:23.2394454Z ##[error]The operation was canceled.
2023-08-22T16:40:23.2485541Z Post job cleanup.

@osctobe
Copy link
Contributor Author

osctobe commented Aug 23, 2023

The inhfd tests have been broken.
2023-08-22T11:03:39.7424214Z + ./test//zdtm.py --set inhfd run --all --keep-going --report report -f h

Ah, it seems they are not run by the default zdtm.py invocation. I'll take a look tomorrow.

@avagin
Copy link
Member

avagin commented Aug 23, 2023

It looks like a test bug. Before, we didn't restore file positions for inherited descriptors. In case of memfd, it doesn't look like a right behavior. I think this pr fixes this problem but we need to adjust the test too. I think the following patch should work:

diff --git a/test/zdtm.py b/test/zdtm.py
index c6e852dc1..87234a55a 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -772,6 +772,15 @@ class inhfd_test:
 
     def getropts(self):
         self.__files = self.__fdtyp.create_fds()
+        i = 0
+        for my_file, peer_file in self.__files:
+            msg = self.__get_message(i)
+            my_file.write(msg)
+            my_file.flush()
+            data = peer_file.read(len(msg))
+            if data != msg:
+                raise test_fail_exc("FDs screwup: %r %r" % (msg, data))
+            i += 1
         ropts = ["--restore-sibling"]
         for i in range(len(self.__files)):
             my_file, peer_file = self.__files[i]

@osctobe osctobe force-pushed the memfd-lseek branch 4 times, most recently from 765a0ea to 0a14072 Compare August 24, 2023 17:47
@osctobe osctobe requested a review from avagin August 24, 2023 17:52
@avagin
Copy link
Member

avagin commented Aug 24, 2023

lgtm

@avagin
Copy link
Member

avagin commented Aug 24, 2023

pls fix DCO.

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 86.66% and project coverage change: -0.01% ⚠️

Comparison is base (5fedcaa) 70.62% compared to head (d442a79) 70.61%.

❗ Current head d442a79 differs from pull request most recent head 0a14072. Consider uploading reports for the commit 0a14072 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##           criu-dev    #2244      +/-   ##
============================================
- Coverage     70.62%   70.61%   -0.01%     
============================================
  Files           133      133              
  Lines         33322    33315       -7     
============================================
- Hits          23532    23525       -7     
  Misses         9790     9790              
Files Changed Coverage Δ
criu/memfd.c 82.58% <84.61%> (+0.81%) ⬆️
criu/files-reg.c 75.38% <100.00%> (+0.02%) ⬆️

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@osctobe
Copy link
Contributor Author

osctobe commented Aug 24, 2023

pls fix DCO.

I'm lost as to what it expects from me:

Commit sha: [0a14072](https://github.com/checkpoint-restore/criu/pull/2244/commits/0a1407270b1ad8f7af8cea87d72b24cadc1092eb),
Author: Michał Mirosław, Committer: Michał Mirosław;
Expected "Michał Mirosław [[email protected]](mailto:[email protected])",
but got "Michał Mirosław [[email protected]](mailto:[email protected])".

@osctobe
Copy link
Contributor Author

osctobe commented Aug 24, 2023

git commit --amend --reset-author didn't help.

There is only one user of memfd_open() outside of memfd.c: open_filemap().
It is restoring a file-backed mapping and doesn't need nor expect to
update F_SETOWN nor the fd's position.  Check the inherited_fd() handling
in the callers to simplify the code.

Signed-off-by: Michał Mirosław <[email protected]>
@osctobe
Copy link
Contributor Author

osctobe commented Aug 24, 2023

Ok, it was a non-breaking space in my .gitconfig...

@avagin avagin merged commit 359b257 into checkpoint-restore:criu-dev Aug 24, 2023
31 of 37 checks passed
@osctobe osctobe deleted the memfd-lseek branch August 25, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants