From nobody Tue Oct 18 15:12:59 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MsHRd6qpFz4g1sf for ; Tue, 18 Oct 2022 15:13:01 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MsHRd2CBkz3QxM for ; Tue, 18 Oct 2022 15:13:01 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: by mail-wr1-f47.google.com with SMTP id j7so24046801wrr.3 for ; Tue, 18 Oct 2022 08:13:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QmGoIBC+e/gE2qnSVIUa9BlgxKUffBrfip+szc55dEM=; b=CsnIfITB51Kf/odtEvz6kzjWDiDvWdL++KEmC1wCIPNO2vl96pa4VLBebroFEL8CnD 29L6LONlJ9hJkm9swcxr6GgMuhINq+uKVeBStEYSfgUOnroM0uOjYwp8UoaLYKUwgM8P TZnH64982WXbMwzc/62U4s+R2HtUfip+Qv/ob4bvOc5hIy/rwrkn8oW0cW4Ws/GkvDub kcTqH2xVjQumpAqiQA81tBD+zumheYVTPZuP4DugQrHQkGxaGvDiuzn0hFK6GWJeGiQA fedrP3fHusn7XahbMgHVOJA+FdGpQedqXLliaJblwyfkZYgowaBkOvrGfOKnbZCsULxy ZIYg== X-Gm-Message-State: ACrzQf142HJRHJEJDQOJ+BvCfGyJMiWSL7/HsU9X5zDXfNRehyzp7mRz jB79KFSi99wo7q+2JrPZn221tA== X-Google-Smtp-Source: AMsMyM4IX6W+p0kXjKvRoJERtAKUnX1q/2wJQ3M7q5BeacCCp/leyWT13rBcvC0G9MZZ+/HG7gNa/g== X-Received: by 2002:adf:f50d:0:b0:22e:2d48:61a5 with SMTP id q13-20020adff50d000000b0022e2d4861a5mr2221363wro.533.1666105979915; Tue, 18 Oct 2022 08:12:59 -0700 (PDT) Received: from smtpclient.apple (global-5-142.n-2.net.cam.ac.uk. [131.111.5.142]) by smtp.gmail.com with ESMTPSA id h10-20020a5d504a000000b0022a9246c853sm11372867wrt.41.2022.10.18.08.12.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2022 08:12:59 -0700 (PDT) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: git: 0e1f5ab7db2c - main - virtio_mmio: Support command-line parameters From: Jessica Clarke In-Reply-To: <202210180603.29I635Zd097281@gitrepo.freebsd.org> Date: Tue, 18 Oct 2022 16:12:59 +0100 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <38DAF585-07F8-4DCD-85D5-E8CFC2099AA5@freebsd.org> References: <202210180603.29I635Zd097281@gitrepo.freebsd.org> To: Colin Percival X-Mailer: Apple Mail (2.3696.80.82.1.1) X-Rspamd-Queue-Id: 4MsHRd2CBkz3QxM X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com X-Spamd-Result: default: False [-2.50 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; TO_DN_EQ_ADDR_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DMARC_NA(0.00)[freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[209.85.221.47:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FREEFALL_USER(0.00)[jrtc27]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; R_DKIM_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.221.47:from] X-ThisMailContainsUnwantedMimeParts: N On 18 Oct 2022, at 07:03, Colin Percival wrote: >=20 > The branch main has been updated by cperciva: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D0e1f5ab7db2cd2837f97f169122897b1= 9c185dbd >=20 > commit 0e1f5ab7db2cd2837f97f169122897b19c185dbd > Author: Colin Percival > AuthorDate: 2022-08-13 00:54:26 +0000 > Commit: Colin Percival > CommitDate: 2022-10-18 06:02:21 +0000 >=20 > virtio_mmio: Support command-line parameters >=20 > The Virtio MMIO bus driver was added in 2014 with support for = devices > exposed via FDT; in 2018 support was added to discover Virtio MMIO > devices via ACPI tables, as in QEMU. The Firecracker VMM eschews = both > FDT and ACPI, instead presenting device information via kernel = command > line arguments of the form virtio_mmio.device=3D. >=20 > These command line parameters get converted into kernel environment > variables; this adds support for parsing those variables and = attaching > virtio_mmio children to nexus. >=20 > There is a case to be made that it would be cleaner to have a new > "cmdlinebus" attached to nexus and virtio_mmio children attached to > that. A future commit might do that. >=20 > Discussed with: imp, jrtc27 > Sponsored by: https://patreon.com/cperciva > Differential Revision: https://reviews.freebsd.org/D36189 > --- > sys/conf/files | 1 + > sys/dev/virtio/mmio/virtio_mmio_cmdline.c | 150 = ++++++++++++++++++++++++++++++ > 2 files changed, 151 insertions(+) >=20 > diff --git a/sys/conf/files b/sys/conf/files > index b7da3626111d..39e6d4aaf0a8 100644 > --- a/sys/conf/files > +++ b/sys/conf/files > @@ -3437,6 +3437,7 @@ dev/virtio/pci/virtio_pci_legacy.c optional = virtio_pci > dev/virtio/pci/virtio_pci_modern.c optional virtio_pci > dev/virtio/mmio/virtio_mmio.c optional virtio_mmio > dev/virtio/mmio/virtio_mmio_acpi.c optional virtio_mmio acpi > +dev/virtio/mmio/virtio_mmio_cmdline.c optional = virtio_mmio As I said in the review, this definitely doesn=E2=80=99t work for INTRNG = due to IRQ number virtualisation, among other things, yet this enables it for all architectures, and I believe it should also get its own config option as it=E2=80=99s rather dangerous to use (Linux separates it out = from virtio_mmio and has it off-by-default). Jess > dev/virtio/mmio/virtio_mmio_fdt.c optional virtio_mmio fdt > dev/virtio/mmio/virtio_mmio_if.m optional virtio_mmio > dev/virtio/network/if_vtnet.c optional vtnet > diff --git a/sys/dev/virtio/mmio/virtio_mmio_cmdline.c = b/sys/dev/virtio/mmio/virtio_mmio_cmdline.c > new file mode 100644 > index 000000000000..cb4762adc964 > --- /dev/null > +++ b/sys/dev/virtio/mmio/virtio_mmio_cmdline.c > @@ -0,0 +1,150 @@ > +/*- > + * Copyright (c) 2022 Colin Percival > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above = copyright > + * notice, this list of conditions and the following disclaimer in = the > + * documentation and/or other materials provided with the = distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' = AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, = THE > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR = PURPOSE > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE = LIABLE > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR = CONSEQUENTIAL > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE = GOODS > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS = INTERRUPTION) > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN = CONTRACT, STRICT > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN = ANY WAY > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE = POSSIBILITY OF > + * SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include > + > +/* Parse @:[:] and add a child. */ > +static void > +parsearg(driver_t *driver, device_t parent, char * arg) > +{ > + device_t child; > + char * p; > + unsigned long sz; > + unsigned long baseaddr; > + unsigned long irq; > + unsigned long id; > + > + /* */ > + sz =3D strtoul(arg, &p, 0); > + if ((sz =3D=3D 0) || (sz =3D=3D ULONG_MAX)) > + goto bad; > + switch (*p) { > + case 'E': case 'e': > + sz <<=3D 10; > + /* FALLTHROUGH */ > + case 'P': case 'p': > + sz <<=3D 10; > + /* FALLTHROUGH */ > + case 'T': case 't': > + sz <<=3D 10; > + /* FALLTHROUGH */ > + case 'G': case 'g': > + sz <<=3D 10; > + /* FALLTHROUGH */ > + case 'M': case 'm': > + sz <<=3D 10; > + /* FALLTHROUGH */ > + case 'K': case 'k': > + sz <<=3D 10; > + p++; > + break; > + } > + > + /* @ */ > + if (*p++ !=3D '@') > + goto bad; > + baseaddr =3D strtoul(p, &p, 0); > + if ((baseaddr =3D=3D 0) || (baseaddr =3D=3D ULONG_MAX)) > + goto bad; > + > + /* : */ > + if (*p++ !=3D ':') > + goto bad; > + irq =3D strtoul(p, &p, 0); > + if ((irq =3D=3D 0) || (irq =3D=3D ULONG_MAX)) > + goto bad; > + > + /* Optionally, : */ > + if (*p) { > + if (*p++ !=3D ':') > + goto bad; > + id =3D strtoul(p, &p, 0); > + if ((id =3D=3D 0) || (id =3D=3D ULONG_MAX)) > + goto bad; > + } else { > + id =3D 0; > + } > + > + /* Should have reached the end of the string. */ > + if (*p) > + goto bad; > + > + /* Create the child and assign its resources. */ > + child =3D BUS_ADD_CHILD(parent, 0, driver->name, id ? id : -1); > + bus_set_resource(child, SYS_RES_MEMORY, 0, baseaddr, sz); > + bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1); > + device_set_driver(child, driver); > + > + return; > + > +bad: > + printf("Error parsing virtio_mmio parameter: %s\n", arg); > +} > + > +static void > +vtmmio_cmdline_identify(driver_t *driver, device_t parent) > +{ > + size_t n; > + char name[] =3D "virtio_mmio.device_XXXX"; > + char * val; > + > + /* First variable just has its own name. */ > + if ((val =3D kern_getenv("virtio_mmio.device")) =3D=3D NULL) > + return; > + parsearg(driver, parent, val); > + freeenv(val); > + > + /* The rest have _%zu suffixes. */ > + for (n =3D 1; n <=3D 9999; n++) { > + sprintf(name, "virtio_mmio.device_%zu", n); > + if ((val =3D kern_getenv(name)) =3D=3D NULL) > + return; > + parsearg(driver, parent, val); > + freeenv(val); > + } > +} > + > +static device_method_t vtmmio_cmdline_methods[] =3D { > + /* Device interface. */ > + DEVMETHOD(device_identify, vtmmio_cmdline_identify), > + DEVMETHOD(device_probe, vtmmio_probe), > + > + DEVMETHOD_END > +}; > +DEFINE_CLASS_1(virtio_mmio, vtmmio_cmdline_driver, = vtmmio_cmdline_methods, > + sizeof(struct vtmmio_softc), vtmmio_driver); > +DRIVER_MODULE(vtmmio_cmdline, nexus, vtmmio_cmdline_driver, 0, 0);