From patchwork Tue Mar 5 16:44:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Unai Martinez Corral X-Patchwork-Id: 10839681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E633922 for ; Tue, 5 Mar 2019 16:45:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D1EF28675 for ; Tue, 5 Mar 2019 16:45:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60E572A21B; Tue, 5 Mar 2019 16:45:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFB7C28675 for ; Tue, 5 Mar 2019 16:45:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:45665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1DCV-0008Vq-3k for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Mar 2019 11:45:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1DBd-0007uM-E8 for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:45:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1DBb-00030D-H1 for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:45:01 -0500 Received: from smtp.lg.ehu.es ([158.227.0.66]:50786 helo=smtp.ehu.eus) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1DBY-0002wp-Om for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:44:57 -0500 Received: from imsva1.lgp.ehu.es (imsva1.lgp.ehu.es [10.0.3.245]) by postfix.smtp1.imsva1 (Postfix) with ESMTPS id A3EBE2E5C4 for ; Tue, 5 Mar 2019 17:44:53 +0100 (CET) Received: from imsva1.lgp.ehu.es (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 695BB11005C for ; Tue, 5 Mar 2019 17:44:53 +0100 (CET) Received: from imsva1.lgp.ehu.es (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A9AA110052 for ; Tue, 5 Mar 2019 17:44:53 +0100 (CET) Received: from smtp.ehu.eus (unknown [10.0.100.73]) by imsva1.lgp.ehu.es (Postfix) with ESMTPS for ; Tue, 5 Mar 2019 17:44:53 +0100 (CET) Received: from mail-it1-f172.google.com (mail-it1-f172.google.com [209.85.166.172]) by smtp1 (Postfix) with ESMTPSA id BF676300A5 for ; Tue, 5 Mar 2019 17:44:52 +0100 (CET) Received: by mail-it1-f172.google.com with SMTP id z124so5512869itc.2 for ; Tue, 05 Mar 2019 08:44:52 -0800 (PST) X-Gm-Message-State: APjAAAXX/gHTNECckCmpyWXJQYZnly5UQvojr7N5JOG7lDYavBdcIwrg ORypstLL9zRwhXnRnNeZ2oMqX/MmaneA9iab5A== X-Google-Smtp-Source: APXvYqxujRa7bW73qMPf6egoEpg09Ydc8vJeIip5IEqfMsaRxP2DEJe3PA7PHDJaCAfqfXP7rAre5BfvnMBhicpLVsc= X-Received: by 2002:a24:4087:: with SMTP id n129mr3067266ita.140.1551804291225; Tue, 05 Mar 2019 08:44:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Unai Martinez Corral Date: Tue, 5 Mar 2019 17:44:41 +0100 X-Gmail-Original-Message-ID: Message-ID: To: =?utf-8?q?Unai_Mart=C3=ADnez_Corral?= X-Greylist: ACL 177 matched, not delayed by milter-greylist-4.4.3 (smtp1); Tue, 05 Mar 2019 17:44:53 +0100 (CET) X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSVA-9.1.0.1631-8.2.0.1013-24472.000 X-TM-AS-Result: No--13.598-7.0-31-10 X-imss-scan-details: No--13.598-7.0-31-10 X-TMASE-Version: IMSVA-9.1.0.1631-8.2.1013-24472.000 X-TMASE-Result: 10--13.597800-10.000000 X-TMASE-MatchedRID: VekMgpjOAZ2gBUTSh64wSUKGB4JJ2ELX9gEayu8Z5zHegmUet1i/OyZK RIFpXA+BChf6rI0ISVFz6rjc7yAZlRNlGxRVOitKALBxQHkJtWpeCrB32KOS0P2TbFr0CGOD1xJ M7/udel3hKIPAdqH2ORGJ0gRYySRViQ1BD0J45o/MZk86HxFjjlo1rFkFFs1a8cWgFw6wp7OUi4 TWfJtWitR8wk+lLcooFE65JTruMqm5wzuUO5NtvBJLmlADJjGKo5KBmcJozDZUjspoiX02F0lf9 Khr66EtNlpmSQMjZB/QFeKTnsl15Hy3NtgjFBPrsyNb+yeIRApPn74Ug5EKEFXzges/EJ9sApZD sXStw22amE2YeLQqiA2OPHSuOQd8EuYl3YX/IW5IcJTn2Hkqsf+UEb65dgmQV9eB8vnmKe9kIuc d2z1snehURetUfQ4BJBR9boLgnghQs1SN7/4/IN35+5/2Rxqm1KoSW5Ji1Xs1LB46LFAAkpxak1 lKPxhNIcUZgTKGbvgKDYVhCsJwlG7vEKjEI8LyutvHF25zoU8bFOwqTAzggAagDhBTr1YkrcmmD 7/hK19WYD2sGjM0B/xeJSHqpuqt5tHwb6x0QAhIOPd/RZsItXVCc80MT9xuglg6kRzWXO/LvPGj 5EQSBUpSHFXGSx1mPF1LXEYgwuxqYK1cyTcJXw== X-TMASE-SNAP-Result: 1.821001.0001-0-1-12:0,22:0,33:0,34:0-0 X-Greylist: Sender IP whitelisted, Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (postfix.smtp1.imsva1); Tue, 05 Mar 2019 17:44:53 +0100 (CET) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 158.227.0.66 Subject: [Qemu-devel] [PATCH] qemu-binfmt-conf.sh: add CPUS, add --reset, make -p and -c boolean (no arg) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: unai.martinezcorral@ehu.eus Cc: riku.voipio@iki.fi, qemu-devel@nongnu.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP I'm so sorry for the inconvenience of sending this patch multiple times. This is my first contribution through email, and I am having a hard time preventing the client from mangling with it. This time, I attached que body below too. I hope that this allows any other to properly push it, in case it is still not picked by patchew. Related to https://bugs.launchpad.net/qemu/+bug/1817239 - Positional parameters are supported as [CPUS]. This can be a single target arch, a comma separated list or a space separated list. This parameter replaces qemu_target_list for any mode (default, systemd or debian). If it is left empty or ALL is provided, all the targets are registered. If NONE is provided, no target is registered. - Option [--systemd CPU] is modified to [--systemd], since the functionality is supported by [CPUS] now. - [--credential yes|no] and [--persistent yes|no] are modified to [--credential] and [--persistent], respectively. They are 'no' by default, and 'yes' if the corresponding flag is provided. - [--reset ARCHS] is added. This allows to remove registered interpreters. Supported formats are a single target name or a comma separated list of targets. If ALL is provided, all the existing 'qemu-*' interpreters are removed. - 'usage' is updated according to the changes above. Note that I don't know how to proceed when `--reset` is used together with `--systemd` or `--debian`. At the moment, if `--reset` is provided first, both options are used, one after the other. However, if any of the other two is provided first, a error is shown: 'option reset not implemented for this mode yet'. Some example use cases that are to be supported by this patch: qemu-binfmt-conf.sh -p aarch64 qemu-binfmt-conf.sh -p aarch64 riscv64 qemu-binfmt-conf.sh -p aarch64,riscv64 qemu-binfmt-conf.sh -r ALL -p aarch64 qemu-binfmt-conf.sh -r aarch64 -p aarch64 qemu-binfmt-conf.sh -r ALL -p aarch64 riscv64 qemu-binfmt-conf.sh -r ALL -p aarch64,riscv64 qemu-binfmt-conf.sh -r aarch64,riscv64 -p aarch64 riscv64 qemu-binfmt-conf.sh -r aarch64,riscv64 -p aarch64,riscv64 qemu-binfmt-conf.sh -r ALL NONE The main purpose of these changes is to make it easier to use qemu-user-static to build docker images for foreign architectures. See https://github.com/umarcor/qus/tree/qemu-update Signed-off-by: Unai Martinez-Corral --- scripts/qemu-binfmt-conf.sh | 174 +++++++++++++++++++++++------------- 1 file changed, 110 insertions(+), 64 deletions(-) SYSTEMDDIR="/etc/binfmt.d" DEBIANDIR="/usr/share/binfmts" @@ -324,37 +381,26 @@ CREDENTIAL=no PERSISTENT=no QEMU_SUFFIX="" -options=$(getopt -o ds:Q:S:e:hc:p: -l debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent: -- "$@") +options=$(getopt -o r:dsQ:S:e:hcp -l reset:,debian,systemd,qemu-path:,qemu-suffix:,exportdir:,help,credential,persistent -- "$@") eval set -- "$options" while true ; do case "$1" in + -r|--reset) + shift + qemu_remove_interpreter $1 + ;; -d|--debian) CHECK=qemu_check_debian BINFMT_SET=qemu_generate_debian + BINFMT_REMOVE=qemu_remove_notimplemented EXPORTDIR=${EXPORTDIR:-$DEBIANDIR} ;; -s|--systemd) CHECK=qemu_check_systemd BINFMT_SET=qemu_generate_systemd + BINFMT_REMOVE=qemu_remove_notimplemented EXPORTDIR=${EXPORTDIR:-$SYSTEMDDIR} - shift - # check given cpu is in the supported CPU list - if [ "$1" != "ALL" ] ; then - for cpu in ${qemu_target_list} ; do - if [ "$cpu" = "$1" ] ; then - break - fi - done - - if [ "$cpu" = "$1" ] ; then - qemu_target_list="$1" - else - echo "ERROR: unknown CPU \"$1\"" 1>&2 - usage - exit 1 - fi - fi ;; -Q|--qemu-path) shift @@ -373,12 +419,10 @@ while true ; do exit 1 ;; -c|--credential) - shift - CREDENTIAL="$1" + CREDENTIAL=yes ;; -p|--persistent) - shift - PERSISTENT="$1" + PERSISTENT=yes ;; *) break @@ -387,5 +431,7 @@ while true ; do shift done +shift + $CHECK -qemu_set_binfmts +qemu_set_binfmts $@ -- 2.20.1 diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index b5a16742a1..f044446d5c 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -6,6 +6,32 @@ mips mipsel mipsn32 mipsn32el mips64 mips64el \ sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \ microblaze microblazeel or1k x86_64" +# check if given target CPUS is/are in the supported target list +qemu_check_target_list() { + all="$qemu_target_list" + if [ "$1" = "ALL" ]; then + checked_target_list="$all" + return + fi + list="" + for target in $@; do + unknown_target="true" + for cpu in $all ; do + if [ "$cpu" = "$target" ] ; then + list="$list $target" + unknown_target="false" + break + fi + done + if [ "$unknown_target" = "true" ] ; then + echo "ERROR: unknown CPU \"$target\"" 1>&2 + usage + exit 1 + fi + done + checked_target_list="$list" +} + i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00' i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' i386_family=i386 @@ -167,45 +193,48 @@ qemu_get_family() { usage() { cat <&2 + usage + exit 1 +} + +qemu_remove_interpreter() { + if [ "$1" = "ALL" ]; then + find /proc/sys/fs/binfmt_misc/ -type f -name 'qemu-*' -exec sh -c 'echo -1 > {}' \; + else + qemu_check_target_list $(echo "$1" | tr ',' ' ') + for t in $checked_target_list; do + find /proc/sys/fs/binfmt_misc/ -type f -name "qemu-$t" -exec sh -c 'echo -1 > {}' \; + done + fi +} + CHECK=qemu_check_bintfmt_misc BINFMT_SET=qemu_register_interpreter +BINFMT_REMOVE=qemu_remove_interpreter