Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1365445pxj; Wed, 19 May 2021 04:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw84mGHAUAWTtI5Un1lXrBMTudh3Z0wP5wVlr1cFaXHITYH4WXJxmQGdbpEpyKR2d6OGxNj X-Received: by 2002:a02:ca0d:: with SMTP id i13mr12250483jak.98.1621424049835; Wed, 19 May 2021 04:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621424049; cv=none; d=google.com; s=arc-20160816; b=YgBMPkFLhg2Nji+cqASdKgFLsH0IB+6p2rP6PTPOVhrjJ3HOVv5Ae3dh3Wn4LF0yWy +oY07HTq3ScIlr9Y7kPMsoxVqCVQqEOFRLEqrCbmsZEiv42/Mv8bp43Zwv4jacL5xeYH YIRrgy2134CQC2OTO6gsfawhdOslzzLEHMECYly/ZI7H1vHmebCysBtuDtrqjNDMYcee 63gSJAsHc8blO7wajnmRaRoknqbkZFfPCGptXzdFyD+FmGcHmqFPfbGUZJ/cFgKk6MDU ogJOcVEeYtx2jOI3r0/5Dtf91NkrXfSB3G7W5OIwb/oTbbITp4wkuhMxkHxBPqqnC9AO sm7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=prFdT1dQ2HQFGfpQl18+ytQ82tqJA0EOYgcl4wsuIgc=; b=VWqC17I2pPGtjnVKEApXJq4ZPkJFXshctGP9qkMbbC0p12fkt7sg668bv9y14NZM7v C9cF+itcpeCZD5eKQ0NO9IY/9ME8N6SavQWKRZiY3c/MhDcv33M6zXqEQWSbKRmGDjAJ RacJGxfDkl0wDQnptLrglEoSC/mGKyn8EQpwYizM/dQTKyr+eBSoWLpkKgsdiVEyDR9h qRO1YB1zmePEbTbnhAX+9liZQvh+j9RNrBEm9Z7kSWQbE/J7ia0dAvi9UWi0NRP7bzy+ s144M/VqZPgCGMrpUX6Pvxg5gx8uLIOZL+eS0fNxs4No9TLEUW+aM1N7ru1Rhbs9caqr Fedg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Zm17ZW5g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si15701680ilf.140.2021.05.19.04.33.57; Wed, 19 May 2021 04:34:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Zm17ZW5g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240491AbhERDDQ (ORCPT + 99 others); Mon, 17 May 2021 23:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232884AbhERDDP (ORCPT ); Mon, 17 May 2021 23:03:15 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39581C061573 for ; Mon, 17 May 2021 20:01:57 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id v12so8437292wrq.6 for ; Mon, 17 May 2021 20:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=prFdT1dQ2HQFGfpQl18+ytQ82tqJA0EOYgcl4wsuIgc=; b=Zm17ZW5gzs+hSxCoCwZvF59a3BNMhJoGP8e+YpLvq0yBzyvWePQRcTtjmTR+ANPjO3 IWuEg+F1Pxu9axwyqMktPobr0O7fjBza55QWAOaCEw0owRQXmFC3rJrpab8Oe//DjtU5 YI1ddSiwR00502niCiCIAeBR//BTKMvQIkp/bgnVRtVpz0wEeGFYF/fmw1v7AV25Mw+R /o0exomWezLaQzVsHRwTSDJjXauyPkwd9IM3Q1NR1k4KJSFni3N0SEJ6J67rlPEUimZO x+N5Y8rKZ2TNFLkWShDhrqDnCHqfnSaShGxzXh0QQVdgGZUhY8r6tZGJkI9QpF+2Xf0q LdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=prFdT1dQ2HQFGfpQl18+ytQ82tqJA0EOYgcl4wsuIgc=; b=cBs7wFUVHQAgkITl7vNyKl7k7Dit3GER9PnDuubfIGOLC+aaBGQ6fYRUh9oTrF5y1W rAVDZeXwzo1VXvN8XOsvQtVT8HwZ+gePLr85paIQcJWHv9NKcUefHIQdb/vhdPRpJQIJ aVSk2GHev/F3kKttVfmQtgxxASaVuwqOJNfhvAUVVWhcJXaJ1N1iwm5iV/oSW2UZFjtf LR4rkHtCqpXcJu8pgIEAuiwah8fvx4KsykbGmyoReVxsoZCdSGe4DCep3cYf4yXEJCqa O/9a4rKaTfo8e9EdhHunvL6s50VwcB/N1/spC4JlRKcuOiwZU/OE+kjNMIDe+ePzcSWn 8Iwg== X-Gm-Message-State: AOAM532ft7//s0WYdzfMbyd7G2ja2ekEOsNsDAod2+NpNvdqIn6rZ1xO rlgcahnufi+XMC3I49lapVg6jgs/QwPfn0AUkvRrxg== X-Received: by 2002:adf:e58d:: with SMTP id l13mr3629520wrm.369.1621306915600; Mon, 17 May 2021 20:01:55 -0700 (PDT) MIME-Version: 1.0 References: <20210507213110.155492-1-brendanhiggins@google.com> <20210507213110.155492-4-brendanhiggins@google.com> In-Reply-To: From: David Gow Date: Tue, 18 May 2021 11:01:44 +0800 Message-ID: Subject: Re: [PATCH v1 3/4] kunit: tool: add support for QEMU To: Brendan Higgins Cc: Shuah Khan , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , Linux Kernel Mailing List , Jonathan Corbet , "open list:DOCUMENTATION" , Stephen Boyd , Kees Cook , Frank Rowand , Daniel Latypov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 15, 2021 at 3:59 PM David Gow wrote: > > On Sat, May 8, 2021 at 5:31 AM Brendan Higgins > wrote: > > > > Add basic support to run QEMU via kunit_tool. Add support for i386, > > x86_64, arm, arm64, and a bunch more. > > > > Signed-off-by: Brendan Higgins > > Tested-by: David Gow > > --- > > > > Changes since last revision: > > > > - A number of minor obvious issues pointed out by David and Daniel. > > - Added facility for merging Kconfigs at Daniel's suggestion. > > - Broke out qemu_configs each into their own config file which is loaded > > dynamically - mostly at David's suggestion. > > > > --- > > This seems pretty good to me. I only have one real complaint -- > qemu_configs needing to be in a subdirectory of ./tools/testing/kunit > -- but am able to tolerate that (even if I'd prefer not to have it) if > it's documented properly. > > Otherwise, save for a couple of minor nitpicks, this seems good to go. > > Reviewed-by: David Gow > > One thing I forgot to mention is that I'm not 100% sure about the Kconfig fragments being embedded in the qemu_configs. I still kind-of prefer the idea of them being in separate config files. While I don't think this is necessarily a blocker, I did just realise that, by default, kunit.py run --arch= will pull its default .kunitconfig from arch/um/configs/kunit_defconfig, which definitely feels awkward when UML is not otherwise involved. Some further thoughts below (which range a bit from "practical suggestion" to "overcomplicated ponderings", so don't feel the pressure to take all of them). (...snip...) > > diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py > > index e22ade9d91ad5..2bd196fd69e5c 100644 > > --- a/tools/testing/kunit/kunit_kernel.py > > +++ b/tools/testing/kunit/kunit_kernel.py > > @@ -6,23 +6,31 @@ > > # Author: Felix Guo > > # Author: Brendan Higgins > > > > +from __future__ import annotations > > +import importlib.util > > import logging > > import subprocess > > import os > > import shutil > > import signal > > from typing import Iterator > > +from typing import Optional > > > > from contextlib import ExitStack > > > > +from collections import namedtuple > > + > > import kunit_config > > import kunit_parser > > +import qemu_config > > > > KCONFIG_PATH = '.config' > > KUNITCONFIG_PATH = '.kunitconfig' > > DEFAULT_KUNITCONFIG_PATH = 'arch/um/configs/kunit_defconfig' This being in arch/um doesn't seem great if its being used for non-UML builds. Is it worth either: (a) moving this somewhere else (e.g., tools/testing/kunit/configs as with the BROKEN_ALLCONFIG_PATH beflow), or (b) giving each architecture its own kunit_defconfig, possibly in place of the qemuconfig member of QemuArchParams I'm leaning towards (b), which solves two different sources of ugliness in one go, though it would appear to have the downside that the default .kunitconfig could end up being architecture specific, which isn't great. > > BROKEN_ALLCONFIG_PATH = 'tools/testing/kunit/configs/broken_on_uml.config' > > OUTFILE_PATH = 'test.log' > > +ABS_TOOL_PATH = os.path.abspath(os.path.dirname(__file__)) > > +QEMU_CONFIGS_DIR = os.path.join(ABS_TOOL_PATH, 'qemu_configs') > > (...snip...) > > diff --git a/tools/testing/kunit/qemu_config.py b/tools/testing/kunit/qemu_config.py > > new file mode 100644 > > index 0000000000000..aff1fe0442dbc > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_config.py > > @@ -0,0 +1,17 @@ > > +# SPDX-License-Identifier: GPL-2.0 > > +# > > +# Collection of configs for building non-UML kernels and running them on QEMU. > > +# > > +# Copyright (C) 2021, Google LLC. > > +# Author: Brendan Higgins > > + > > +from collections import namedtuple > > + > > + > > +QemuArchParams = namedtuple('QemuArchParams', ['linux_arch', > > + 'qemuconfig', As mentioned, I'm not thrilled about keeping the Kconfig inline here, and would kind-of prefer it to be in another file. I could live with it if I have to, though. Regardless, 'qemuconfig' is not a super-descriptive name, particularly as it's not clear if this is configuring QEMU (no, that's extra_qemu_params'), or configuring the kernel for QEMU compatibility. > > + 'qemu_arch', > > + 'kernel_path', > > + 'kernel_command_line', > > + 'extra_qemu_params']) > > + > > Nit: newline at end of file. > > > > > diff --git a/tools/testing/kunit/qemu_configs/alpha.py b/tools/testing/kunit/qemu_configs/alpha.py > > new file mode 100644 > > index 0000000000000..2cc64f848ca2c > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/alpha.py > > @@ -0,0 +1,10 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='alpha', > > + qemuconfig=''' > > +CONFIG_SERIAL_8250=y > > +CONFIG_SERIAL_8250_CONSOLE=y''', If these were in a separate file, they could be shared across alpha, i386, x86_64, etc. Of course, that wouldn't gel well with putting them in arch/.../config. If there were some way of listing multiple files, it could form part of the config for several more architectures, though that's probably overcomplicating things. > > + qemu_arch='alpha', > > + kernel_path='arch/alpha/boot/vmlinux', > > + kernel_command_line='console=ttyS0', > > + extra_qemu_params=['']) > > diff --git a/tools/testing/kunit/qemu_configs/arm.py b/tools/testing/kunit/qemu_configs/arm.py > > new file mode 100644 > > index 0000000000000..29a043b0531a0 > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/arm.py > > @@ -0,0 +1,13 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='arm', > > + qemuconfig=''' > > +CONFIG_ARCH_VIRT=y > > +CONFIG_SERIAL_AMBA_PL010=y > > +CONFIG_SERIAL_AMBA_PL010_CONSOLE=y > > +CONFIG_SERIAL_AMBA_PL011=y > > +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y''', Similarly, if in a separate file and there were some multiple-file mechanism, these could mostly be shared between arm & arm64 (ARCH_VIRT being the only problem). Again, probably overcomplicating it at this point though. > > + qemu_arch='arm', > > + kernel_path='arch/arm/boot/zImage', > > + kernel_command_line='console=ttyAMA0', > > + extra_qemu_params=['-machine virt']) > > diff --git a/tools/testing/kunit/qemu_configs/arm64.py b/tools/testing/kunit/qemu_configs/arm64.py > > new file mode 100644 > > index 0000000000000..1ba200bc99f0f > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/arm64.py > > @@ -0,0 +1,12 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='arm64', > > + qemuconfig=''' > > +CONFIG_SERIAL_AMBA_PL010=y > > +CONFIG_SERIAL_AMBA_PL010_CONSOLE=y > > +CONFIG_SERIAL_AMBA_PL011=y > > +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y''', > > + qemu_arch='aarch64', > > + kernel_path='arch/arm64/boot/Image.gz', > > + kernel_command_line='console=ttyAMA0', > > + extra_qemu_params=['-machine virt', '-cpu cortex-a57']) > > diff --git a/tools/testing/kunit/qemu_configs/i386.py b/tools/testing/kunit/qemu_configs/i386.py > > new file mode 100644 > > index 0000000000000..3998af306468e > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/i386.py > > @@ -0,0 +1,10 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='i386', > > + qemuconfig=''' > > +CONFIG_SERIAL_8250=y > > +CONFIG_SERIAL_8250_CONSOLE=y''', > > + qemu_arch='x86_64', > > + kernel_path='arch/x86/boot/bzImage', > > + kernel_command_line='console=ttyS0', > > + extra_qemu_params=['']) > > diff --git a/tools/testing/kunit/qemu_configs/powerpc.py b/tools/testing/kunit/qemu_configs/powerpc.py > > new file mode 100644 > > index 0000000000000..46292ce9e368e > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/powerpc.py > > @@ -0,0 +1,12 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='powerpc', > > + qemuconfig=''' > > +CONFIG_PPC64=y > > +CONFIG_SERIAL_8250=y > > +CONFIG_SERIAL_8250_CONSOLE=y > > +CONFIG_HVC_CONSOLE=y''', > > + qemu_arch='ppc64', > > + kernel_path='vmlinux', > > + kernel_command_line='console=ttyS0', > > + extra_qemu_params=['-M pseries', '-cpu power8']) > > diff --git a/tools/testing/kunit/qemu_configs/riscv.py b/tools/testing/kunit/qemu_configs/riscv.py > > new file mode 100644 > > index 0000000000000..de8c62d465723 > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/riscv.py > > @@ -0,0 +1,31 @@ > > +from ..qemu_config import QemuArchParams > > +import os > > +import os.path > > +import sys > > + > > +GITHUB_OPENSBI_URL = 'https://github.com/qemu/qemu/raw/master/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin' > > +OPENSBI_FILE = os.path.basename(GITHUB_OPENSBI_URL) > > + > > +if not os.path.isfile(OPENSBI_FILE): > > + print('\n\nOpenSBI file is not in the current working directory.\n' > > + 'Would you like me to download it for you from:\n' + GITHUB_OPENSBI_URL + ' ?\n') > > + response = input('yes/[no]: ') > > + if response.strip() == 'yes': > > + os.system('wget ' + GITHUB_OPENSBI_URL) > > + else: > > + sys.exit() > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='riscv', > > + qemuconfig=''' > > +CONFIG_SOC_VIRT=y > > +CONFIG_SERIAL_8250=y > > +CONFIG_SERIAL_8250_CONSOLE=y > > +CONFIG_SERIAL_OF_PLATFORM=y > > +CONFIG_SERIAL_EARLYCON_RISCV_SBI=y''', > > + qemu_arch='riscv64', > > + kernel_path='arch/riscv/boot/Image', > > + kernel_command_line='console=ttyS0', > > + extra_qemu_params=[ > > + '-machine virt', > > + '-cpu rv64', > > + '-bios opensbi-riscv64-generic-fw_dynamic.bin']) > > diff --git a/tools/testing/kunit/qemu_configs/s390.py b/tools/testing/kunit/qemu_configs/s390.py > > new file mode 100644 > > index 0000000000000..04c90332f1098 > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/s390.py > > @@ -0,0 +1,14 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='s390', > > + qemuconfig=''' > > +CONFIG_EXPERT=y > > +CONFIG_TUNE_ZEC12=y > > +CONFIG_NUMA=y > > +CONFIG_MODULES=y''', > > + qemu_arch='s390x', > > + kernel_path='arch/s390/boot/bzImage', > > + kernel_command_line='console=ttyS0', > > + extra_qemu_params=[ > > + '-machine s390-ccw-virtio', > > + '-cpu qemu',]) > > diff --git a/tools/testing/kunit/qemu_configs/sparc.py b/tools/testing/kunit/qemu_configs/sparc.py > > new file mode 100644 > > index 0000000000000..f26b5f27cc5a1 > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/sparc.py > > @@ -0,0 +1,10 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='sparc', > > + qemuconfig=''' > > +CONFIG_SERIAL_8250=y > > +CONFIG_SERIAL_8250_CONSOLE=y''', > > + qemu_arch='sparc', > > + kernel_path='arch/sparc/boot/zImage', > > + kernel_command_line='console=ttyS0 mem=256M', > > + extra_qemu_params=['-m 256']) > > diff --git a/tools/testing/kunit/qemu_configs/x86_64.py b/tools/testing/kunit/qemu_configs/x86_64.py > > new file mode 100644 > > index 0000000000000..bd5ab733b92ac > > --- /dev/null > > +++ b/tools/testing/kunit/qemu_configs/x86_64.py > > @@ -0,0 +1,10 @@ > > +from ..qemu_config import QemuArchParams > > + > > +QEMU_ARCH = QemuArchParams(linux_arch='x86_64', > > + qemuconfig=''' > > +CONFIG_SERIAL_8250=y > > +CONFIG_SERIAL_8250_CONSOLE=y''', > > + qemu_arch='x86_64', > > + kernel_path='arch/x86/boot/bzImage', > > + kernel_command_line='console=ttyS0', > > + extra_qemu_params=['']) > > -- > > 2.31.1.607.g51e8a6a459-goog > >