Skip to contentSkip to conversation

linux-user: Use *at functions instead of caching interp_prefix contents

PATCH In review Richard Henderson 3 participants 3 messages Dec 29, 2017 – Jan 3, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 linux-user: Use *at functions instead of caching interp_prefix contents

From: Richard Henderson <[email protected]>

If the interp_prefix is a complete chroot, it may have a *lot* of files. Setting up the cache for this is quite expensive. Instead, use the *at versions of various syscalls to attempt the operation in the prefix.

---

Changes since v2 (Dec 4 2017):
* Use IF as the control construct instead of SWITCH.

Changes since v1 (Nov 2016):
* Require interp_dirfd set before trying the *at path.

r~

---
 linux-user/qemu.h    |   1 +
 linux-user/elfload.c |   7 +-
 linux-user/main.c    |   3 +-
 linux-user/syscall.c | 176 ++++++++++++++++++++++++++++++++++++++-------------
 4 files changed, 141 insertions(+), 46 deletions(-)
linux-user/qemu.h +1 -0
index 4edd7d0c08..d04924fd2e 100644
@@ -437,6 +437,7 @@ void mmap_fork_start(void);
 void mmap_fork_end(int child);
 
 /* main.c */
+extern int interp_dirfd;
 extern unsigned long guest_stack_size;
 
 /* user access */
linux-user/elfload.c +6 -1
index 20f3d8c2c3..e70eebc7b8 100644
@@ -2203,7 +2203,12 @@ static void load_elf_interp(const char *filename, struct image_info *info,
 {
     int fd, retval;
 
-    fd = open(path(filename), O_RDONLY);
+    if (interp_dirfd < 0
+        || filename[0] != '/'
+        || (fd = openat(interp_dirfd, filename + 1, O_RDONLY),
+            fd < 0 && errno == ENOENT)) {
+        fd = open(filename, O_RDONLY);
+    }
     if (fd < 0) {
         goto exit_perror;
     }
linux-user/main.c +2 -1
index 71696ed33d..391cc5ef82 100644
@@ -98,6 +98,7 @@ unsigned long reserved_va;
 static void usage(int exitcode);
 
 static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
+int interp_dirfd;
 const char *qemu_uname_release;
 
 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
@@ -4307,7 +4308,7 @@ int main(int argc, char **argv, char **envp)
     memset(&bprm, 0, sizeof (bprm));
 
     /* Scan interp_prefix dir for replacement files. */
-    init_paths(interp_prefix);
+    interp_dirfd = open(interp_prefix, O_CLOEXEC | O_DIRECTORY | O_PATH);
 
     init_qemu_uname_release();
 
linux-user/syscall.c +132 -44

317 lines not on this page · raw message

Signature · 1 line
2.14.3
#1 lore raw
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3] linux-user: Use *at functions instead of caching interp_prefix contents

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
214763a007 linux-user: Use *at functions instead of caching interp_prefix contents

=== OUTPUT BEGIN ===
Checking PATCH 1/1: linux-user: Use *at functions instead of caching interp_prefix contents...
ERROR: do not use assignment in if condition
#25: FILE: linux-user/elfload.c:2206:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#76: FILE: linux-user/syscall.c:7231:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#99: FILE: linux-user/syscall.c:7653:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#122: FILE: linux-user/syscall.c:8277:
+ if (!(fn = lock_user_string(arg2))) {

ERROR: do not use assignment in if condition
#127: FILE: linux-user/syscall.c:8280:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#143: FILE: linux-user/syscall.c:8301:
+ if (!(fn = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#148: FILE: linux-user/syscall.c:8304:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#161: FILE: linux-user/syscall.c:8316:
+ if (!(fn = lock_user_string(arg2))) {

ERROR: do not use assignment in if condition
#166: FILE: linux-user/syscall.c:8319:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#209: FILE: linux-user/syscall.c:9240:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#241: FILE: linux-user/syscall.c:9267:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#278: FILE: linux-user/syscall.c:9704:
+ if (!(fn = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#283: FILE: linux-user/syscall.c:9707:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#296: FILE: linux-user/syscall.c:9719:
+ if (!(fn = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#301: FILE: linux-user/syscall.c:9722:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#317: FILE: linux-user/syscall.c:10809:
+ if (!(fn = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#322: FILE: linux-user/syscall.c:10812:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#337: FILE: linux-user/syscall.c:10826:
+ if (!(fn = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#342: FILE: linux-user/syscall.c:10829:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#358: FILE: linux-user/syscall.c:10855:
+ if (!(fn = lock_user_string(arg2))) {

ERROR: do not use assignment in if condition
#362: FILE: linux-user/syscall.c:10858:
+ if (interp_dirfd < 0

ERROR: do not use assignment in if condition
#380: FILE: linux-user/syscall.c:11862:
+ if (!(fn = lock_user_string(arg2))) {

ERROR: do not use assignment in if condition
#385: FILE: linux-user/syscall.c:11865:
+ if (interp_dirfd < 0

total: 23 errors, 0 warnings, 352 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
Quoted 10 lines · On 12/29/2017 12:45 PM, [email protected] wrote:

Hi,

This series seems to have some coding style problems. See output below for more information:

=== OUTPUT BEGIN ===
Checking PATCH 1/1: linux-user: Use *at functions instead of caching interp_prefix contents...
ERROR: do not use assignment in if condition
#25: FILE: linux-user/elfload.c:2206:
+ if (interp_dirfd < 0

Given that your compact if with embedded assignment makes the syntax checker unhappy, should we look for a v4 that uses the construct we debated in v2:

while (1) {
    if (interp_dirfd > 0 && filename[0] == '/') {
        fd = openat(interp_dirfd, filename + 1, O_RDONLY);
        if (fd >= 0 || errno != ENOENT) {
            break;
        }
    }
    fd = open(filename, O_RDONLY);
    break;
}
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org