From nobody Fri May 17 08:24:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688628638; cv=none; d=zohomail.com; s=zohoarc; b=lBkETffkv+/0g0eABs8GcvUF914gLtAu6hiFFkc5yQzIrZfsstus7oUhjg7nUmzTQyJL9zryFgR8lGRoOvV/Lnj3oeuS9+FxvOOMVq6/nYYr9PjHq6ru2vK/zA/RoKtJvh6ocvmlgjjzmOQ+mw3yyI5A0SX0fh+1WWliLB3uTus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688628638; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Ur6U8znIrg+MN1C36AIYyVQaxBlVTa6MnJ12V0yVeWc=; b=icPA3vLyvk7PSR/QcAyo0AlqGe0PVVOr6LMarNA9S3WCngOSuFAA6DwdkvcWOJ7qgqryI+SI+Yur45LtokfeVUaYV3IsgV9C5tYEehAgAh5j3plq+UG33oMrstV5vMoqwWCfHm8rCkONMeie7vvg37iwK7bhKAAGwKFx/3i6LNA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168862863836874.55083826441012; Thu, 6 Jul 2023 00:30:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.559675.874895 (Exim 4.92) (envelope-from ) id 1qHJR7-0004xT-BB; Thu, 06 Jul 2023 07:29:57 +0000 Received: by outflank-mailman (output) from mailman id 559675.874895; Thu, 06 Jul 2023 07:29:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qHJR7-0004xM-8E; Thu, 06 Jul 2023 07:29:57 +0000 Received: by outflank-mailman (input) for mailman id 559675; Thu, 06 Jul 2023 07:29:55 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qHJR5-0004xE-Lq for xen-devel@lists.xen.org; Thu, 06 Jul 2023 07:29:55 +0000 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [2607:f8b0:4864:20::1036]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e4434788-1bce-11ee-8611-37d641c3527e; Thu, 06 Jul 2023 09:29:51 +0200 (CEST) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-262e839647eso367262a91.2 for ; Thu, 06 Jul 2023 00:29:51 -0700 (PDT) Received: from localhost ([122.172.87.195]) by smtp.gmail.com with ESMTPSA id t11-20020a170902e84b00b001b8b6a19bd6sm690159plg.63.2023.07.06.00.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 00:29:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e4434788-1bce-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688628589; x=1691220589; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ur6U8znIrg+MN1C36AIYyVQaxBlVTa6MnJ12V0yVeWc=; b=dk4yfLxO8MqrpL0At35TL5vjmOQOzIZIL8HlehxabEUx4MXzFwfguq+MwfC59UoLNw Nd8gXX7nFsBU/oXffL0gpam4l7aFKM0y+Y+E5LIS85dCEd+crABbs6xichq2oIqLa2NF qHxzySTciQHGjbJ/91CJ4hOGkHDZkIa/32GkFdtNCyPYC4xThBH6s3B4Aba0kMrMLKCj 66Yw+MKE2B9uuwvSVxAsFd6LkFfNhlHoY5tXgsy7VFED7/76Pcs9KJsIw0nPd67S+17B PmvJwiwTUFndTJLoRV+cADqPoiu+HXypyWc2cdymKLm2/9r6Iix50wr4BUxLDWQfUV/7 E1pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688628589; x=1691220589; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ur6U8znIrg+MN1C36AIYyVQaxBlVTa6MnJ12V0yVeWc=; b=JXzjI6ky1W64C3i8suOLFIBSESzrYXLT8TcIxSvg7G5cWAHjUgUFvJftOnvoOn/cJp cQdXNWvk3vXkEHzR1KBJhOhiTWZIXZ+u68zE/ohIebf8d/iokqcW5ALsUCYwk0h1uypz Si4idwlpD17IPk7r4rnaJWayvKNrkNdWadTGTZbxFkaQrr7rGF+SOEjIZntI2s8UmzuJ rfG2cGLDbtHm44IrVcEnGvkn5ezMtB6FOrQhhGOX5p076+k+bWZDFkclDgDxsZltp+ja cmE6dvCpb1omT5BdivUlHjErqwwqDvp0Ct8+2l9C6dKotsd7M+S6GQ4HkxKO9z+h5/vC fI/A== X-Gm-Message-State: ABy/qLaMguZvX2DrKxhDIf3f9J+rBPXLnTEw2WmDrUJ21ZQxjVDF//Tb rHfK40xPN4tSI19qHPc8sPoHq/Kh9DQ0NgH9MD0= X-Google-Smtp-Source: APBJJlFWdg1wCn3ML0F/nyJH5NldND2oLYGYDiT7x2hCCHOfTnYm3RlEj8jcTw/xgxrhbkVzXkBCMA== X-Received: by 2002:a17:90b:4f85:b0:261:875:c2be with SMTP id qe5-20020a17090b4f8500b002610875c2bemr979257pjb.29.1688628589457; Thu, 06 Jul 2023 00:29:49 -0700 (PDT) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD , George Dunlap , Nick Rosbrook , Wei Liu Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mathieu Poirier , Oleksandr Tyshchenko , Erik Schilling Subject: [PATCH V4] libxl: arm: Add grant_usage parameter for virtio devices Date: Thu, 6 Jul 2023 12:59:45 +0530 Message-Id: <144a57807d6f3e6c1e9b45215cb4fa5fa4535f10.1688628006.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688628639912100001 Content-Type: text/plain; charset="utf-8" Currently, the grant mapping related device tree properties are added if the backend domain is not Dom0. While Dom0 is privileged and can do foreign mapping for the entire guest memory, it is still desired for Dom0 to access guest's memory via grant mappings and hence map only what is required. This commit adds the "grant_usage" parameter for virtio devices, which provides better control over the functionality. Signed-off-by: Viresh Kumar Reviewed-by: Anthony PERARD Acked-by: George Dunlap --- V3.1->V4: - Added Reviewed-by tags. - Other patches from the series are already applied. - No code changes. V3->V3.1: - Print "0" or "1" in xenstore instead of "True" or "False" for grant_usage. V2->V3: - Reuse `libxl_defbool` instead of defining a new type, it can take values = 0 and 1. - Improved commit logs and comments. V1->V2: - Instead of just 0 or 1, the argument can take multiple values now and con= trol the functionality in a better way. - Update .gen.go files as well. - Don't add nodes under frontend path. docs/man/xl.cfg.5.pod.in | 8 ++++++++ tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/libs/light/libxl_arm.c | 22 +++++++++++++--------- tools/libs/light/libxl_types.idl | 1 + tools/libs/light/libxl_virtio.c | 23 +++++++++++++++++++++-- tools/xl/xl_parse.c | 2 ++ 7 files changed, 52 insertions(+), 11 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 3979be2a590a..b6fc20ef01c8 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1619,6 +1619,14 @@ hexadecimal format, without the "0x" prefix and all = in lower case, like Specifies the transport mechanism for the Virtio device, only "mmio" is supported for now. =20 +=3Ditem B + +If this option is B, the Xen grants are always enabled. +If this option is B, the Xen grants are always disabled. + +If this option is missing, then the default grant setting will be used, +i.e. enable grants if backend-domid !=3D 0. + =3Dback =20 =3Ditem B diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index cd1a16e32eac..3ecffdf0ef3a 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1794,6 +1794,9 @@ func (x *DeviceVirtio) fromC(xc *C.libxl_device_virti= o) error { x.BackendDomname =3D C.GoString(xc.backend_domname) x.Type =3D C.GoString(xc._type) x.Transport =3D VirtioTransport(xc.transport) +if err :=3D x.GrantUsage.fromC(&xc.grant_usage);err !=3D nil { +return fmt.Errorf("converting field GrantUsage: %v", err) +} x.Devid =3D Devid(xc.devid) x.Irq =3D uint32(xc.irq) x.Base =3D uint64(xc.base) @@ -1811,6 +1814,9 @@ xc.backend_domname =3D C.CString(x.BackendDomname)} if x.Type !=3D "" { xc._type =3D C.CString(x.Type)} xc.transport =3D C.libxl_virtio_transport(x.Transport) +if err :=3D x.GrantUsage.toC(&xc.grant_usage); err !=3D nil { +return fmt.Errorf("converting field GrantUsage: %v", err) +} xc.devid =3D C.libxl_devid(x.Devid) xc.irq =3D C.uint32_t(x.Irq) xc.base =3D C.uint64_t(x.Base) diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index b131a7eedc9d..4f40aac28c2a 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -706,6 +706,7 @@ BackendDomid Domid BackendDomname string Type string Transport VirtioTransport +GrantUsage Defbool Devid Devid Irq uint32 Base uint64 diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index 35f76dfc21e4..f98e1affa294 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -930,7 +930,8 @@ static int make_xen_iommu_node(libxl__gc *gc, void *fdt) =20 /* The caller is responsible to complete / close the fdt node */ static int make_virtio_mmio_node_common(libxl__gc *gc, void *fdt, uint64_t= base, - uint32_t irq, uint32_t backend_dom= id) + uint32_t irq, uint32_t backend_dom= id, + bool grant_usage) { int res; gic_interrupt intr; @@ -953,7 +954,7 @@ static int make_virtio_mmio_node_common(libxl__gc *gc, = void *fdt, uint64_t base, res =3D fdt_property(fdt, "dma-coherent", NULL, 0); if (res) return res; =20 - if (backend_domid !=3D LIBXL_TOOLSTACK_DOMID) { + if (grant_usage) { uint32_t iommus_prop[2]; =20 iommus_prop[0] =3D cpu_to_fdt32(GUEST_PHANDLE_IOMMU); @@ -967,11 +968,12 @@ static int make_virtio_mmio_node_common(libxl__gc *gc= , void *fdt, uint64_t base, } =20 static int make_virtio_mmio_node(libxl__gc *gc, void *fdt, uint64_t base, - uint32_t irq, uint32_t backend_domid) + uint32_t irq, uint32_t backend_domid, + bool grant_usage) { int res; =20 - res =3D make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid= ); + res =3D make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid= , grant_usage); if (res) return res; =20 return fdt_end_node(fdt); @@ -1027,11 +1029,11 @@ static int make_virtio_mmio_node_gpio(libxl__gc *gc= , void *fdt) =20 static int make_virtio_mmio_node_device(libxl__gc *gc, void *fdt, uint64_t= base, uint32_t irq, const char *type, - uint32_t backend_domid) + uint32_t backend_domid, bool grant= _usage) { int res; =20 - res =3D make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid= ); + res =3D make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid= , grant_usage); if (res) return res; =20 /* Add device specific nodes */ @@ -1371,7 +1373,8 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_do= main_config *d_config, iommu_needed =3D true; =20 FDT( make_virtio_mmio_node(gc, fdt, disk->base, disk->irq, - disk->backend_domid) ); + disk->backend_domid, + disk->backend_domid !=3D LIBXL_= TOOLSTACK_DOMID) ); } } =20 @@ -1381,12 +1384,13 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_= domain_config *d_config, if (virtio->transport !=3D LIBXL_VIRTIO_TRANSPORT_MMIO) continue; =20 - if (virtio->backend_domid !=3D LIBXL_TOOLSTACK_DOMID) + if (libxl_defbool_val(virtio->grant_usage)) iommu_needed =3D true; =20 FDT( make_virtio_mmio_node_device(gc, fdt, virtio->base, virtio->irq, virtio->type, - virtio->backend_domid) ); + virtio->backend_domid, + libxl_defbool_val(virtio->gr= ant_usage)) ); } =20 /* diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 9e48bb772646..700b44a164f4 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -762,6 +762,7 @@ libxl_device_virtio =3D Struct("device_virtio", [ ("backend_domname", string), ("type", string), ("transport", libxl_virtio_transport), + ("grant_usage", libxl_defbool), ("devid", libxl_devid), # Note that virtio-mmio parameters (irq and base) are for internal # use by libxl and can't be modified. diff --git a/tools/libs/light/libxl_virtio.c b/tools/libs/light/libxl_virti= o.c index f8a78e22d156..e5e321adc5c4 100644 --- a/tools/libs/light/libxl_virtio.c +++ b/tools/libs/light/libxl_virtio.c @@ -23,8 +23,16 @@ static int libxl__device_virtio_setdefault(libxl__gc *gc= , uint32_t domid, libxl_device_virtio *virtio, bool hotplug) { - return libxl__resolve_domid(gc, virtio->backend_domname, - &virtio->backend_domid); + int rc; + + rc =3D libxl__resolve_domid(gc, virtio->backend_domname, + &virtio->backend_domid); + if (rc < 0) return rc; + + libxl_defbool_setdefault(&virtio->grant_usage, + virtio->backend_domid !=3D LIBXL_TOOLSTACK_DO= MID); + + return 0; } =20 static int libxl__device_from_virtio(libxl__gc *gc, uint32_t domid, @@ -53,6 +61,8 @@ static int libxl__set_xenstore_virtio(libxl__gc *gc, uint= 32_t domid, flexarray_append_pair(back, "base", GCSPRINTF("%#"PRIx64, virtio->base= )); flexarray_append_pair(back, "type", GCSPRINTF("%s", virtio->type)); flexarray_append_pair(back, "transport", GCSPRINTF("%s", transport)); + flexarray_append_pair(back, "grant_usage", + libxl_defbool_val(virtio->grant_usage) ? "1" : "= 0"); =20 return 0; } @@ -104,6 +114,15 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, = const char *libxl_path, } } =20 + tmp =3D NULL; + rc =3D libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/grant_usage", be_path), &tmp= ); + if (rc) goto out; + + if (tmp) { + libxl_defbool_set(&virtio->grant_usage, strtoul(tmp, NULL, 0)); + } + tmp =3D NULL; rc =3D libxl__xs_read_checked(gc, XBT_NULL, GCSPRINTF("%s/type", be_path), &tmp); diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index f036e56fc239..dfd432ca02e2 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1215,6 +1215,8 @@ static int parse_virtio_config(libxl_device_virtio *v= irtio, char *token) } else if (MATCH_OPTION("transport", token, oparg)) { rc =3D libxl_virtio_transport_from_string(oparg, &virtio->transpor= t); if (rc) return rc; + } else if (MATCH_OPTION("grant_usage", token, oparg)) { + libxl_defbool_set(&virtio->grant_usage, strtoul(oparg, NULL, 0)); } else { fprintf(stderr, "Unknown string \"%s\" in virtio spec\n", token); return -1; --=20 2.31.1.272.g89b43f80a514