From patchwork Fri Nov 15 11:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62FE1D6DDED for ; Fri, 15 Nov 2024 11:53:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837164.1253082 (Exim 4.92) (envelope-from ) id 1tBuso-0005UX-A3; Fri, 15 Nov 2024 11:53:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837164.1253082; Fri, 15 Nov 2024 11:53:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBuso-0005UQ-73; Fri, 15 Nov 2024 11:53:02 +0000 Received: by outflank-mailman (input) for mailman id 837164; Fri, 15 Nov 2024 11:53:01 +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 1tBusn-0005U9-0E for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:01 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 274ee777-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:52:56 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a99f646ff1bso239968266b.2 for ; Fri, 15 Nov 2024 03:52:56 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:52:55 -0800 (PST) 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: 274ee777-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzIiLCJoZWxvIjoibWFpbC1lajEteDYzMi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI3NGVlNzc3LWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTc2LjYyOTE4NSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671576; x=1732276376; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5mrVRgD97fk4oiduu+jg3TvIRmLCwcya2NVl3bfxaNk=; b=XYI4ZYQrV9Gv/IREjD+hqYJBmV7AWvcUACeXBp9yKlQWTu1ikP0RouMuJtKcDfPOL1 /4kOZO7FyUF4iqTTMwtCYVx4KItQOByW5pfQ5X3Pgd5nIngwvQKbfBzwfSGZNaa7PVHd DyZOCsUJp/4vFmN9ua6gIW5GmXdHVjArPQlc0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671576; x=1732276376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5mrVRgD97fk4oiduu+jg3TvIRmLCwcya2NVl3bfxaNk=; b=CEKIhv8oWZzYuQ9dHfEakqiibabPV8TpVrUyDy4In/IuazuYmODGTw93ub1w0N8dwr yYMo+9rJWlKh6BFiJLTJrja16HvMvnF8QPU9q9LEMpUGpUlb5w3voGIdpRa/9FmQh7r0 OtP5P8VhLDiKlbiGM787d3SrW/EFlpNhuIktHwKcyZc8bln3kU0Ie7MDV9FUY1WYsD2e IhMJ3oeT8JtPSXwwvrsM3aDpndI/QlksDZRAL9gvS/GtexUgxr6q6U4ojGSj042xZTYY j5IzOOBtvtEBBkggvu22Mboar2i4s2XfaZLlGhIKMLDwu9KNNFxqx3/gvuIYo25bOLax k2AA== X-Gm-Message-State: AOJu0YxrpA9OWkx1j3muI44uCC3kB8mmoeY511WVmH00A4IYVx1eNSnr OtbSnUCAOEwIvH4P0XYipDubLj7LCrhahmQeiMDreHfKKHu62TwiQrNEacfMElAmXFACMnCrQiw g X-Google-Smtp-Source: AGHT+IHgSlFouleWW4NhastRrTRfcV9mIE59JpQXE0ASPTZ/NyZSqm4wzfRTNQm7vXFvCwhhIVF96g== X-Received: by 2002:a17:907:1b2a:b0:a9a:d4aa:95bd with SMTP id a640c23a62f3a-aa48354e32emr231728266b.54.1731671575641; Fri, 15 Nov 2024 03:52:55 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Juergen Gross , Julien Grall , Anthony PERARD , Andrew Cooper , Jan Beulich , Stefano Stabellini , Christian Lindig , David Scott , =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Subject: [RFC PATCH 01/25] xen/domctl: Refine grant_opts into max_grant_version Date: Fri, 15 Nov 2024 11:51:30 +0000 Message-ID: <20241115115200.2824-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 grant_opts is overoptimizing for space packing in a hypercall that doesn't warrant the effort. Tweak the ABI without breaking it in order to remove the bitfield by extending it to 8 bits. Xen only supports little-endian systems, so the transformation from uint32_t to uint8_t followed by 3 octets worth of padding is not an ABI breakage. No functional change Signed-off-by: Alejandro Vallejo --- tools/helpers/init-xenstore-domain.c | 2 +- tools/libs/light/libxl_create.c | 6 +----- tools/ocaml/libs/xc/xenctrl_stubs.c | 3 +-- tools/python/xen/lowlevel/xc/xc.c | 2 +- tools/tests/paging-mempool/test-paging-mempool.c | 2 +- tools/tests/resource/test-resource.c | 6 +++--- tools/tests/tsx/test-tsx.c | 4 ++-- xen/arch/arm/dom0less-build.c | 4 ++-- xen/arch/arm/domain_build.c | 2 +- xen/arch/x86/setup.c | 2 +- xen/common/domain.c | 6 +++--- xen/common/grant_table.c | 3 +-- xen/include/public/domctl.h | 15 +++++++++++---- xen/include/xen/grant_table.h | 6 +++--- 14 files changed, 32 insertions(+), 31 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index 01ca667d25d1..a9f2f9859df6 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -96,7 +96,7 @@ static int build(xc_interface *xch) */ .max_grant_frames = 4, .max_maptrack_frames = 128, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, }; xs_fd = open("/dev/xen/xenbus_backend", O_RDWR); diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index edeadd57ef5a..87594809abc8 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -476,10 +476,6 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, else /* No grant table support reported */ b_info->max_grant_version = 0; - } else if (b_info->max_grant_version & ~XEN_DOMCTL_GRANT_version_mask) { - LOG(ERROR, "max grant version %d out of range", - b_info->max_grant_version); - return -ERROR_INVAL; } /* Assume that providing a bootloader user implies enabling restrict. */ @@ -646,7 +642,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, .max_evtchn_port = b_info->event_channels, .max_grant_frames = b_info->max_grant_frames, .max_maptrack_frames = b_info->max_maptrack_frames, - .grant_opts = XEN_DOMCTL_GRANT_version(b_info->max_grant_version), + .max_grant_version = b_info->max_grant_version, .vmtrace_size = ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAGE_SHIFT), .cpupool_id = info->poolid, }; diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c index c78191f95abc..67a690308f1a 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -223,8 +223,7 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co .max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT), .max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES), .max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES), - .grant_opts = - XEN_DOMCTL_GRANT_version(Int_val(VAL_MAX_GRANT_VERSION)), + .max_grant_version = Int_val(VAL_MAX_GRANT_VERSION), .altp2m_opts = Int32_val(VAL_ALTP2M_OPTS), .vmtrace_size = vmtrace_size, .cpupool_id = Int32_val(VAL_CPUPOOL_ID), diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 9feb12ae2b16..ba6a61217f9f 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -167,7 +167,7 @@ static PyObject *pyxc_domain_create(XcObject *self, #else #error Architecture not supported #endif - config.grant_opts = XEN_DOMCTL_GRANT_version(max_grant_version); + config.max_grant_version = max_grant_version; if ( (ret = xc_domain_create(self->xc_handle, &dom, &config)) < 0 ) return pyxc_error_to_exception(self->xc_handle); diff --git a/tools/tests/paging-mempool/test-paging-mempool.c b/tools/tests/paging-mempool/test-paging-mempool.c index 1ebc13455ac2..512c42803c0e 100644 --- a/tools/tests/paging-mempool/test-paging-mempool.c +++ b/tools/tests/paging-mempool/test-paging-mempool.c @@ -24,7 +24,7 @@ static struct xen_domctl_createdomain create = { .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, .max_vcpus = 1, .max_grant_frames = 1, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, .arch = { #if defined(__x86_64__) || defined(__i386__) diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/test-resource.c index 1b10be16a6b4..b0a9f5f1e8b6 100644 --- a/tools/tests/resource/test-resource.c +++ b/tools/tests/resource/test-resource.c @@ -137,7 +137,7 @@ static void test_domain_configurations(void) .create = { .max_vcpus = 2, .max_grant_frames = 40, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, }, }, { @@ -146,7 +146,7 @@ static void test_domain_configurations(void) .flags = XEN_DOMCTL_CDF_hvm, .max_vcpus = 2, .max_grant_frames = 40, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, .arch = { .emulation_flags = XEN_X86_EMU_LAPIC, }, @@ -159,7 +159,7 @@ static void test_domain_configurations(void) .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, .max_vcpus = 2, .max_grant_frames = 40, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, }, }, #endif diff --git a/tools/tests/tsx/test-tsx.c b/tools/tests/tsx/test-tsx.c index 5af04953f340..324bcf67153a 100644 --- a/tools/tests/tsx/test-tsx.c +++ b/tools/tests/tsx/test-tsx.c @@ -457,7 +457,7 @@ static void test_guests(void) struct xen_domctl_createdomain c = { .max_vcpus = 1, .max_grant_frames = 1, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, }; printf("Testing PV guest\n"); @@ -470,7 +470,7 @@ static void test_guests(void) .flags = XEN_DOMCTL_CDF_hvm, .max_vcpus = 1, .max_grant_frames = 1, - .grant_opts = XEN_DOMCTL_GRANT_version(1), + .max_grant_version = 1, .arch = { .emulation_flags = XEN_X86_EMU_LAPIC, }, diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index f328a044e9d3..1c6219c7cc82 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -877,7 +877,7 @@ void __init create_domUs(void) .max_evtchn_port = 1023, .max_grant_frames = -1, .max_maptrack_frames = -1, - .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), + .max_grant_version = opt_gnttab_max_version, }; unsigned int flags = 0U; uint32_t val; @@ -959,7 +959,7 @@ void __init create_domUs(void) } if ( dt_property_read_u32(node, "max_grant_version", &val) ) - d_cfg.grant_opts = XEN_DOMCTL_GRANT_version(val); + d_cfg.max_grant_version = val; if ( dt_property_read_u32(node, "max_grant_frames", &val) ) { diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2c30792de88b..773412ba2acb 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2194,7 +2194,7 @@ void __init create_dom0(void) .max_evtchn_port = -1, .max_grant_frames = gnttab_dom0_frames(), .max_maptrack_frames = -1, - .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), + .max_grant_version = opt_gnttab_max_version, }; int rc; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 5da1c6a34519..0443555d9bb8 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -964,7 +964,7 @@ static struct domain *__init create_dom0(const module_t *image, .max_evtchn_port = -1, .max_grant_frames = -1, .max_maptrack_frames = -1, - .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), + .max_grant_version = opt_gnttab_max_version, .max_vcpus = dom0_max_vcpus(), .arch = { .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, diff --git a/xen/common/domain.c b/xen/common/domain.c index 92263a4fbdc5..86f0e99e0d4a 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -579,9 +579,9 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config) return -EINVAL; } - if ( config->grant_opts & ~XEN_DOMCTL_GRANT_version_mask ) + if ( config->rsvd0[0] | config->rsvd0[1] | config->rsvd0[2] ) { - dprintk(XENLOG_INFO, "Unknown grant options %#x\n", config->grant_opts); + dprintk(XENLOG_INFO, "Rubble in rsvd0 padding\n"); return -EINVAL; } @@ -788,7 +788,7 @@ struct domain *domain_create(domid_t domid, if ( (err = grant_table_init(d, config->max_grant_frames, config->max_maptrack_frames, - config->grant_opts)) != 0 ) + config->max_grant_version)) != 0 ) goto fail; init_status |= INIT_gnttab; diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 6c77867f8cdd..51a3f72a9601 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1963,10 +1963,9 @@ active_alloc_failed: } int grant_table_init(struct domain *d, int max_grant_frames, - int max_maptrack_frames, unsigned int options) + int max_maptrack_frames, uint8_t max_grant_version) { struct grant_table *gt; - unsigned int max_grant_version = options & XEN_DOMCTL_GRANT_version_mask; int ret = -ENOMEM; if ( !max_grant_version ) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 353f831e402e..e37d4337dcf9 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -90,11 +90,18 @@ struct xen_domctl_createdomain { int32_t max_grant_frames; int32_t max_maptrack_frames; -/* Grant version, use low 4 bits. */ -#define XEN_DOMCTL_GRANT_version_mask 0xf -#define XEN_DOMCTL_GRANT_version(v) ((v) & XEN_DOMCTL_GRANT_version_mask) + /* + * Maximum grant table version the domain can be configured with. + * + * Domains always start with v1 (if CONFIG_GRANT_TABLE) and can be bumped + * to use up to `max_grant_version` via GNTTABOP_set_version. + * + * Must be zero iff !CONFIG_GRANT_TABLE. + */ + uint8_t max_grant_version; - uint32_t grant_opts; + /* Unused. Reserved to zero. */ + uint8_t rsvd0[3]; /* * Enable altp2m mixed mode. diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index 50edfecfb62f..a483d5a216a4 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -40,7 +40,7 @@ extern unsigned int opt_max_grant_frames; /* Create/destroy per-domain grant table context. */ int grant_table_init(struct domain *d, int max_grant_frames, - int max_maptrack_frames, unsigned int options); + int max_maptrack_frames, uint8_t max_grant_version); void grant_table_destroy( struct domain *d); void grant_table_init_vcpu(struct vcpu *v); @@ -73,9 +73,9 @@ int gnttab_acquire_resource( static inline int grant_table_init(struct domain *d, int max_grant_frames, int max_maptrack_frames, - unsigned int options) + uint8_t max_grant_version) { - if ( options ) + if ( max_grant_version ) return -EINVAL; return 0; From patchwork Fri Nov 15 11:51:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4183D6DDF4 for ; Fri, 15 Nov 2024 11:53:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837167.1253102 (Exim 4.92) (envelope-from ) id 1tBusq-0005qD-26; Fri, 15 Nov 2024 11:53:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837167.1253102; Fri, 15 Nov 2024 11:53:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusp-0005nH-RW; Fri, 15 Nov 2024 11:53:03 +0000 Received: by outflank-mailman (input) for mailman id 837167; Fri, 15 Nov 2024 11:53:02 +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 1tBuso-0005U9-Mb for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:02 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 27f23757-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:52:57 +0100 (CET) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a9ef275b980so110462066b.0 for ; Fri, 15 Nov 2024 03:52:57 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:52:56 -0800 (PST) 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: 27f23757-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MmMiLCJoZWxvIjoibWFpbC1lajEteDYyYy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI3ZjIzNzU3LWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTc3LjY3OTk5Mywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671577; x=1732276377; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GnUruHtiBjMQURAk6r67+S2KIYkG9l4j/nhhDyE0lxU=; b=TQdxwcj0vfl8Z4r76UuGQgAvehXgC7zclcKZhTgx93f4xIIhNC6dKLmrLwN44d5iWO 0Ep75AvsyIbhaTQxo3ba3PWHbJfwW/dazYgTy2na272LvVdfWdi5PoYCmiwTtGqeCwh9 EuxjyprT/1LgyHNm53kDb2Ljl6/+vK070j/RI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671577; x=1732276377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GnUruHtiBjMQURAk6r67+S2KIYkG9l4j/nhhDyE0lxU=; b=pEcukVvN8/BB/6Bz5R84RadI8B8T/GzOpcya8Yf1JUVFnfINezD49GvSsWqS1jFayK vI8Lwecb9y/BvN7VvcfFDopfrnyAKOx0gg5gDVrnFw8anDvCkKeeK+Ij4qFDZ9hxyJXj xmJupQhPhQuRWjI9HcmBuY55QamWoOEi4tP64yao3e0SaQw54nRXOxSeYOwJBa3wGOFZ jMjWTl9ItW8G4Hrpmiygg7f3xK0sIp9e0EVSbJJt06wNrNWnrc5b3+80SBgLzf/0ocbS acRIddaIIkYSX+VZbwNjGTnH1aOgd8gByj+FyP6iBXFFHw0vAc1sCbKEY1Fbv9eu6qr1 Meqg== X-Gm-Message-State: AOJu0YyK+KN47UOjVr94YKoJq7h9FB9kzovylPReTwhH5MmTSPapFEng uyU3xoqTBpD00F/z03fUhJFYeHG4chhYLfcoQncTLAYt1+KrSv8zUbIhiPJmWIbaYs/QTLx3Ze4 n X-Google-Smtp-Source: AGHT+IGILk9OK5J7KLLfKUoMnXFsNUvPeAvKjx9rCUT4nS0cebUMT0Ne3Hliiw7Pvamek+LfNvJilg== X-Received: by 2002:a17:906:dac7:b0:aa4:777d:739a with SMTP id a640c23a62f3a-aa4833e9fcbmr205498566b.8.1731671576796; Fri, 15 Nov 2024 03:52:56 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Juergen Gross , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Christian Lindig , David Scott , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Subject: [RFC PATCH 02/25] xen/domctl: Replace altp2m_opts with altp2m_mode Date: Fri, 15 Nov 2024 11:51:31 +0000 Message-ID: <20241115115200.2824-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change, in the same direction as the previous grant_opts to max_grant_version. Signed-off-by: Alejandro Vallejo --- tools/libs/light/libxl_create.c | 11 ++++------- tools/ocaml/libs/xc/xenctrl.ml | 2 +- tools/ocaml/libs/xc/xenctrl.mli | 2 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 6 +++--- xen/arch/arm/domain.c | 2 +- xen/arch/x86/domain.c | 13 ++----------- xen/arch/x86/hvm/hvm.c | 6 +++++- xen/common/domain.c | 3 ++- xen/include/public/domctl.h | 12 +++++++----- 9 files changed, 26 insertions(+), 31 deletions(-) diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index 87594809abc8..3ae922e8931b 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -676,22 +676,19 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, LOG(DETAIL, "altp2m: %s", libxl_altp2m_mode_to_string(b_info->altp2m)); switch(b_info->altp2m) { case LIBXL_ALTP2M_MODE_MIXED: - create.altp2m_opts |= - XEN_DOMCTL_ALTP2M_mode(XEN_DOMCTL_ALTP2M_mixed); + create.altp2m_mode = XEN_DOMCTL_ALTP2M_mixed; break; case LIBXL_ALTP2M_MODE_EXTERNAL: - create.altp2m_opts |= - XEN_DOMCTL_ALTP2M_mode(XEN_DOMCTL_ALTP2M_external); + create.altp2m_mode = XEN_DOMCTL_ALTP2M_external; break; case LIBXL_ALTP2M_MODE_LIMITED: - create.altp2m_opts |= - XEN_DOMCTL_ALTP2M_mode(XEN_DOMCTL_ALTP2M_limited); + create.altp2m_mode = XEN_DOMCTL_ALTP2M_limited; break; case LIBXL_ALTP2M_MODE_DISABLED: - /* Nothing to do - altp2m disabled is signaled as mode == 0. */ + create.altp2m_mode = XEN_DOMCTL_ALTP2M_disabled; break; } diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 2690f9a92316..3c4c95d48319 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -85,7 +85,7 @@ type domctl_create_config = max_grant_frames: int; max_maptrack_frames: int; max_grant_version: int; - altp2m_opts: int32; + altp2m_mode: int32; vmtrace_buf_kb: int32; cpupool_id: int32; arch: arch_domainconfig; diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli index febbe1f6ae3f..74919a14bec4 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -77,7 +77,7 @@ type domctl_create_config = { max_grant_frames: int; max_maptrack_frames: int; max_grant_version: int; - altp2m_opts: int32; + altp2m_mode: int32; vmtrace_buf_kb: int32; cpupool_id: int32; arch: arch_domainconfig; diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c index 67a690308f1a..b701f45daa8d 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -204,7 +204,7 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co #define VAL_MAX_GRANT_FRAMES Field(config, 6) #define VAL_MAX_MAPTRACK_FRAMES Field(config, 7) #define VAL_MAX_GRANT_VERSION Field(config, 8) -#define VAL_ALTP2M_OPTS Field(config, 9) +#define VAL_ALTP2M_MODE Field(config, 9) #define VAL_VMTRACE_BUF_KB Field(config, 10) #define VAL_CPUPOOL_ID Field(config, 11) #define VAL_ARCH Field(config, 12) @@ -224,7 +224,7 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co .max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES), .max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES), .max_grant_version = Int_val(VAL_MAX_GRANT_VERSION), - .altp2m_opts = Int32_val(VAL_ALTP2M_OPTS), + .altp2m_mode = Int32_val(VAL_ALTP2M_MODE), .vmtrace_size = vmtrace_size, .cpupool_id = Int32_val(VAL_CPUPOOL_ID), }; @@ -283,7 +283,7 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co #undef VAL_ARCH #undef VAL_CPUPOOL_ID #undef VAL_VMTRACE_BUF_KB -#undef VAL_ALTP2M_OPTS +#undef VAL_ALTP2M_MODE #undef VAL_MAX_GRANT_VERSION #undef VAL_MAX_MAPTRACK_FRAMES #undef VAL_MAX_GRANT_FRAMES diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 3ba959f86633..c6c5a0d1af23 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -688,7 +688,7 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) return -EINVAL; } - if ( config->altp2m_opts ) + if ( config->altp2m_mode ) { dprintk(XENLOG_INFO, "Altp2m not supported\n"); return -EINVAL; diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 78a13e6812c9..1ef095f349f7 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -637,8 +637,6 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) bool hap = config->flags & XEN_DOMCTL_CDF_hap; bool nested_virt = config->flags & XEN_DOMCTL_CDF_nested_virt; unsigned int max_vcpus; - unsigned int altp2m_mode = MASK_EXTR(config->altp2m_opts, - XEN_DOMCTL_ALTP2M_mode_mask); if ( hvm ? !hvm_enabled : !IS_ENABLED(CONFIG_PV) ) { @@ -717,21 +715,14 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) return -EINVAL; } - if ( config->altp2m_opts & ~XEN_DOMCTL_ALTP2M_mode_mask ) - { - dprintk(XENLOG_INFO, "Invalid altp2m options selected: %#x\n", - config->flags); - return -EINVAL; - } - - if ( altp2m_mode && nested_virt ) + if ( config->altp2m_mode && nested_virt ) { dprintk(XENLOG_INFO, "Nested virt and altp2m are not supported together\n"); return -EINVAL; } - if ( altp2m_mode && !hap ) + if ( config->altp2m_mode && !hap ) { dprintk(XENLOG_INFO, "altp2m is only supported with HAP\n"); return -EINVAL; diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 74e58c653e6f..e30c3026479e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -659,7 +659,7 @@ int hvm_domain_initialise(struct domain *d, d->arch.hvm.params[HVM_PARAM_TRIPLE_FAULT_REASON] = SHUTDOWN_reboot; /* Set altp2m based on domctl flags. */ - switch ( MASK_EXTR(config->altp2m_opts, XEN_DOMCTL_ALTP2M_mode_mask) ) + switch ( config->altp2m_mode ) { case XEN_DOMCTL_ALTP2M_mixed: d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_mixed; @@ -672,6 +672,10 @@ int hvm_domain_initialise(struct domain *d, case XEN_DOMCTL_ALTP2M_limited: d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_limited; break; + + case XEN_DOMCTL_ALTP2M_disabled: + d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_disabled; + break; } vpic_init(d); diff --git a/xen/common/domain.c b/xen/common/domain.c index 86f0e99e0d4a..ad19ff1cef23 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -579,7 +579,8 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config) return -EINVAL; } - if ( config->rsvd0[0] | config->rsvd0[1] | config->rsvd0[2] ) + if ( config->rsvd0_a[0] | config->rsvd0_a[1] | config->rsvd0_a[2] | + config->rsvd0_b[0] | config->rsvd0_b[1] | config->rsvd0_b[2] ) { dprintk(XENLOG_INFO, "Rubble in rsvd0 padding\n"); return -EINVAL; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index e37d4337dcf9..95a3b6769f7f 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -101,8 +101,10 @@ struct xen_domctl_createdomain { uint8_t max_grant_version; /* Unused. Reserved to zero. */ - uint8_t rsvd0[3]; + uint8_t rsvd0_a[3]; +/* Keep altp2m disabled */ +#define XEN_DOMCTL_ALTP2M_disabled (0U) /* * Enable altp2m mixed mode. * @@ -116,10 +118,10 @@ struct xen_domctl_createdomain { #define XEN_DOMCTL_ALTP2M_external (2U) /* Enable altp2m limited mode. */ #define XEN_DOMCTL_ALTP2M_limited (3U) -/* Altp2m mode signaling uses bits [0, 1]. */ -#define XEN_DOMCTL_ALTP2M_mode_mask (0x3U) -#define XEN_DOMCTL_ALTP2M_mode(m) ((m) & XEN_DOMCTL_ALTP2M_mode_mask) - uint32_t altp2m_opts; + uint8_t altp2m_mode; + + /* Unused. Reserved to zero. */ + uint8_t rsvd0_b[3]; /* Per-vCPU buffer size in bytes. 0 to disable. */ uint32_t vmtrace_size; From patchwork Fri Nov 15 11:51:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EB9ED6DDF2 for ; Fri, 15 Nov 2024 11:53:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837166.1253096 (Exim 4.92) (envelope-from ) id 1tBusp-0005l5-Ny; Fri, 15 Nov 2024 11:53:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837166.1253096; Fri, 15 Nov 2024 11:53:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusp-0005kA-KE; Fri, 15 Nov 2024 11:53:03 +0000 Received: by outflank-mailman (input) for mailman id 837166; Fri, 15 Nov 2024 11:53:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusn-0005UF-TF for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:01 +0000 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [2a00:1450:4864:20::533]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2880b9e0-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:52:58 +0100 (CET) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5cf7b79c6a6so2446938a12.0 for ; Fri, 15 Nov 2024 03:52:58 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:52:57 -0800 (PST) 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: 2880b9e0-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzMiLCJoZWxvIjoibWFpbC1lZDEteDUzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI4ODBiOWUwLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTc4LjcyOTAxNSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671578; x=1732276378; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q0JqyiXg7hj8nUKWP18rHoNIqWo/9zcWjDpiBX++LLI=; b=Rptfj5b5uCoQPL+KHLOgANK13PgUgiHPjW6Cn9oajHN54L/A07w/ddVIjFknLm9Y+N 5FthqHZvPNBVAiIl4XTHehBDo/CIXLh6AmqbgyhrYdlWDaydHYrsOug/7/yStd9X1W0A Zl4ddzqVCOUPGBy/TsJd85PzmSYzPQqKsgzDg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671578; x=1732276378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q0JqyiXg7hj8nUKWP18rHoNIqWo/9zcWjDpiBX++LLI=; b=v0wxFGbhXN2KnBfJOQ/VSazsX5wbW0rC+3xqSEbmPS1NepPFRuDuue0K+MS8nppq6U 1j2ca1UpPtpqogzZQ82qFsm5kFESZ4IgPMQHyhQpbIL5Imalb4XLKFNH6H6YO4SN5z1j ZVshwLcMgDr00yut11qMDf10sEthN0DBg1NDWv/Aeh7uT3UhvR++sulTNvzwcHbXLTM6 HzxMXXDMwwl8AgWYkPDEgYKCb1wprLmhmUmEhNiPSBg4UkRXeuvAbr12VG1+8LbMi6Nt nG7irMVZVdZjFFmJHdQRENYTvku/Q8oK7Ltl+cxJpSHdKb7vKBecq8zrdKjd6uk5UuwC A1kQ== X-Gm-Message-State: AOJu0YzuWOBTSMdVQtCkEg3vYesdyE0P2yyK2mXtnFvezB83WKHtkSF9 9JY/2PaYjYEtY6ZUmGBusNdniZqFsi+LYuJz0r4rY+oSX+rvlFGH2SDUsD5oD+A/FjZlsYoBs4H v X-Google-Smtp-Source: AGHT+IFyRUpTHxWcmfro+JQ+0TiCChn9dHamvXTEZ3tfV39RbfTRXmP5QGTDDDnyywePlDg1snScIQ== X-Received: by 2002:a17:907:e92:b0:a99:ee26:f416 with SMTP id a640c23a62f3a-aa2076eb6b3mr658636666b.14.1731671577701; Fri, 15 Nov 2024 03:52:57 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 03/25] tools/xenbindgen: Introduce a Xen hypercall IDL generator Date: Fri, 15 Nov 2024 11:51:32 +0000 Message-ID: <20241115115200.2824-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 To be used for parsing TOML-based hypercall ABI specifications and generating language-specific items (structs, enums, etc.). Signed-off-by: Alejandro Vallejo --- tools/rust/Makefile | 29 +++++++++++++++++++++++++++++ tools/rust/xenbindgen/.gitignore | 1 + tools/rust/xenbindgen/Cargo.toml | 15 +++++++++++++++ tools/rust/xenbindgen/src/main.rs | 21 +++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 tools/rust/Makefile create mode 100644 tools/rust/xenbindgen/.gitignore create mode 100644 tools/rust/xenbindgen/Cargo.toml create mode 100644 tools/rust/xenbindgen/src/main.rs diff --git a/tools/rust/Makefile b/tools/rust/Makefile new file mode 100644 index 000000000000..f5db0a9c5e81 --- /dev/null +++ b/tools/rust/Makefile @@ -0,0 +1,29 @@ +XEN_ROOT=$(CURDIR)/../.. + +# Path to the Xen hypercall IDL parser +XENBINDGEN=$(CURDIR)/xenbindgen + +# Clippy settings for all Rust projects +CLIPPY_ARGS=-D warnings \ + -D missing_docs \ + -D clippy::missing_docs_in_private_items \ + -D clippy::all \ + -D clippy::pedantic + +# Not integrated in Xen installations to avoid depending on the Rust toolchain +.PHONY: all install uninstall clean +all install uninstall clean: + +# Verify Rust crates pass lint checks. This is enforced in CI +.PHONY: verify +verify: + set -eu; \ + for i in "${XENBINDGEN}"; do \ + echo "Verifying $$i"; \ + cd "$$i"; \ + cargo fmt -- --check; \ + cargo clippy -- $(CLIPPY_ARGS); \ + cargo deny check; \ + cd -; \ + done + diff --git a/tools/rust/xenbindgen/.gitignore b/tools/rust/xenbindgen/.gitignore new file mode 100644 index 000000000000..b83d22266ac8 --- /dev/null +++ b/tools/rust/xenbindgen/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/tools/rust/xenbindgen/Cargo.toml b/tools/rust/xenbindgen/Cargo.toml new file mode 100644 index 000000000000..4cb3af9ce0de --- /dev/null +++ b/tools/rust/xenbindgen/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "xenbindgen" +version = "0.2.0" +edition = "2021" +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.5.7", features = ["std", "derive"] } +convert_case = "0.6.0" +env_logger = "0.11.3" +log = "0.4.22" +serde = { version = "1.0.203", default-features = false, features = ["derive"] } +toml = { version = "0.8.14", default-features = false, features = ["parse"] } diff --git a/tools/rust/xenbindgen/src/main.rs b/tools/rust/xenbindgen/src/main.rs new file mode 100644 index 000000000000..08fcf8fe4da6 --- /dev/null +++ b/tools/rust/xenbindgen/src/main.rs @@ -0,0 +1,21 @@ +//! CLI tool to generate structs in different languages from specially +//! crafted TOML files. The format of these files follows the following +//! rules. + +use clap::Parser; +use env_logger::Env; +use log::info; + +/// A CLI tool to generate struct definitions in several languages. +#[derive(Parser, Debug)] +#[command(version, about)] +struct Cli; + +fn main() { + env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); + + let cli = Cli::parse(); + info!("args: {:?}", cli); + + todo!("read spec files and generate output files"); +} From patchwork Fri Nov 15 11:51:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 597A9D6DDF4 for ; Fri, 15 Nov 2024 11:53:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837169.1253132 (Exim 4.92) (envelope-from ) id 1tBuss-0006f4-8L; Fri, 15 Nov 2024 11:53:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837169.1253132; Fri, 15 Nov 2024 11:53:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBuss-0006dJ-3K; Fri, 15 Nov 2024 11:53:06 +0000 Received: by outflank-mailman (input) for mailman id 837169; Fri, 15 Nov 2024 11:53:03 +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 1tBusp-0005U9-Mi for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:03 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 28fe931d-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:52:59 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5cacb76e924so2609901a12.0 for ; Fri, 15 Nov 2024 03:52:59 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:52:58 -0800 (PST) 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: 28fe931d-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmMiLCJoZWxvIjoibWFpbC1lZDEteDUyYy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI4ZmU5MzFkLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTc5LjQyMjYzMiwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671579; x=1732276379; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V2Il6CAUmeVuteWCfEnG9JUs06lwoYmMwe5e8Dj7YCc=; b=TnJgR+D4Tw+R2a7imFKFVITpZu9kX9F5Nrdkr5X7h5eXkqyJ/h8c3jJVnDj/rwaSlh gAk4FdruQShsihT/Vbkzju67GhxrGLUP63sX2mHdv6LEh6TCRjtR/3aMf9VJBqjkfobb 8A9udAcyy7unf+3AVePylU/WBLWJr3FUlTeHM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671579; x=1732276379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V2Il6CAUmeVuteWCfEnG9JUs06lwoYmMwe5e8Dj7YCc=; b=PYXgOUimvLQdETTEirGB6tEASV8JdWVJp1Mh+FB7Bx2vHk3kDR/MTRTkBJb1VLZ7nW o3zIGQekLXUni7Qamrpozrk1v1NI3S/0f2xzBrPO3pMyVwMSDwJn6VeXd8dNVkF4ujFK JhFpGHcJc1xtISzOMgbqZ3gMWyMbxOpRyFWrKEZb+ahG34oYpJS6F8PGVAdCNqDItcyq JdiXdLHIhFRs4JJidsdQTL3HONllTdqrYqdCpPPO9wIFMcnSVpOdPZWRLWe5eLmQIeou qkU1Kyr+wmJOjzMxV5SEw1DjeHxVq5kNRQWoAkLv85yd+9cQclwoKnkDClvS7cugyXtd vfuQ== X-Gm-Message-State: AOJu0Yx5JKOjtv8pCv6HzWTCObFHhh3vtGJSnUerIsmNragYtXP356qr kjuWhZJEMZP/xh5O+KSPB68HLP3xoN1n4St4t+A8pCPqDHpOuJM1YafrONhnfG0aa6ZCpouF4cf 0 X-Google-Smtp-Source: AGHT+IHgVBtkRtwgqIS6cGkk9ANUCp8sGTXtxenWTS6ogrhboiDW8cjjoZmcPndAnMBr+ggU7TCVSA== X-Received: by 2002:a17:907:7ba7:b0:a99:3318:e7c3 with SMTP id a640c23a62f3a-aa4835286d3mr208013966b.43.1731671578554; Fri, 15 Nov 2024 03:52:58 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 04/25] tools/xenbindgen: Add a TOML spec reader Date: Fri, 15 Nov 2024 11:51:33 +0000 Message-ID: <20241115115200.2824-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 There isn't any deserialisation yet. It's mere plumbing. Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/main.rs | 28 ++++++++- tools/rust/xenbindgen/src/spec.rs | 96 +++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 tools/rust/xenbindgen/src/spec.rs diff --git a/tools/rust/xenbindgen/src/main.rs b/tools/rust/xenbindgen/src/main.rs index 08fcf8fe4da6..497cf39d3bbd 100644 --- a/tools/rust/xenbindgen/src/main.rs +++ b/tools/rust/xenbindgen/src/main.rs @@ -2,14 +2,22 @@ //! crafted TOML files. The format of these files follows the following //! rules. +mod spec; + +use std::path::PathBuf; + use clap::Parser; use env_logger::Env; -use log::info; +use log::{error, info}; /// A CLI tool to generate struct definitions in several languages. #[derive(Parser, Debug)] #[command(version, about)] -struct Cli; +struct Cli { + /// Path to the input directory containing the hypercall specification + #[arg(short, long)] + indir: PathBuf, +} fn main() { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); @@ -17,5 +25,19 @@ fn main() { let cli = Cli::parse(); info!("args: {:?}", cli); - todo!("read spec files and generate output files"); + let _specification = match spec::Spec::new(&cli.indir) { + Ok(x) => x, + Err(spec::Error::Toml(x)) => { + error!("TOML parsing error:"); + error!("{x:#?}"); + std::process::exit(1); + } + Err(spec::Error::Io(x)) => { + error!("IO error:"); + error!("{x:#?}"); + std::process::exit(1); + } + }; + + todo!("generate output files"); } diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs new file mode 100644 index 000000000000..e69f7c78dc7a --- /dev/null +++ b/tools/rust/xenbindgen/src/spec.rs @@ -0,0 +1,96 @@ +//! Specification descriptions +//! +//! The TOML files are not parsed by hand. This module provides a sort of +//! schema for the TOML descriptions, in the sense that `serde` itself ensures +//! every field is deserialised into its equivalent Rust structure or the +//! deserialization procedure fails. +//! +//! If the specification is clearly invalid (i.e: missing fields) it'll scream +//! in a rather obvious way. +//! +//! A special case is the `typ` field in the specifications is meant to have +//! the format present in the specifications under `extra`. This allows `serde` +//! to properly decode the type and match it with a variant of the [`Typ`] type +//! with the payload landing in the payload of the variant itself. + +use std::{fs::read_to_string, path::Path}; + +use log::{debug, info}; + +/// A language-agnostic specification. +#[derive(Debug, serde::Deserialize)] +struct InFileDef; + +/// Description of an abstract output (i.e: `.rs`, `.h`, etc). +/// +/// Contains every element of the ABI that needs representing. +#[derive(Debug)] +pub struct OutFileDef { + /// The name of the output file, without the final extension. + pub name: String, +} + +impl OutFileDef { + /// Creates a new _output_ file description. Each [`OutFileDef`] is + /// associated with a number of [`InFileDef`] and holds the merged + /// contents described in all of them. + /// + /// # Errors + /// Fails if the TOML is invalid or on IO error. + pub fn new(name: String, dir: &Path) -> Result { + info!("Reading {dir:?} to generate an output file"); + + let mut ret = Self { name }; + + for entry in from_ioerr(dir.read_dir())? { + let path = from_ioerr(entry)?.path(); + debug!("Reading {:?} to generate outfile={}", path, ret.name); + let toml_str = from_ioerr(read_to_string(path))?; + let filedef: InFileDef = toml::from_str(&toml_str).map_err(Error::Toml)?; + } + + Ok(ret) + } +} + +/// Internal error type for every error spec parsing could encounter +#[derive(Debug)] +pub enum Error { + /// Wrapper around IO errors + Io(std::io::Error), + /// Wrapper around deserialization errors + Toml(toml::de::Error), +} + +/// Maps an [`std::io::Error`] onto a [`Error`] type for easier propagation +fn from_ioerr(t: std::io::Result) -> Result { + t.map_err(Error::Io) +} + +/// Object containing the abstract definitions of all output files. +/// +/// See [`OutFileDef`] to details on the specification contents of each output. +#[derive(Debug)] +pub struct Spec(pub Vec); + +impl Spec { + /// Creates a new abstract specification from a top-level directory full + /// of specification files. This is used later to aggregate all the content + /// and generate the appropriate language outputs. + /// + /// # Errors + /// Fails on IO errors. + pub fn new(root: &Path) -> Result { + info!("Reading {root:?} as top-level directory"); + + let mut ret = Self(Vec::new()); + for outfile in from_ioerr(root.read_dir())? { + // Each folder in the root defines a single output file + let outfile = from_ioerr(outfile)?; + let name = outfile.file_name().to_string_lossy().to_string(); + ret.0.push(OutFileDef::new(name, &outfile.path())?); + } + + Ok(ret) + } +} From patchwork Fri Nov 15 11:51:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25F1BD6DDF2 for ; Fri, 15 Nov 2024 11:53:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837168.1253108 (Exim 4.92) (envelope-from ) id 1tBusq-0005wX-Cv; Fri, 15 Nov 2024 11:53:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837168.1253108; Fri, 15 Nov 2024 11:53:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusq-0005uP-6X; Fri, 15 Nov 2024 11:53:04 +0000 Received: by outflank-mailman (input) for mailman id 837168; Fri, 15 Nov 2024 11:53:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBuso-0005UF-NK for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:02 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 299e10b3-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:00 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-aa1e51ce601so311459966b.3 for ; Fri, 15 Nov 2024 03:53:00 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:52:59 -0800 (PST) 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: 299e10b3-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MmUiLCJoZWxvIjoibWFpbC1lajEteDYyZS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI5OWUxMGIzLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTgwLjQ0ODc2NCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671579; x=1732276379; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rG3hGpHC8NrVDhtSg0TjY8wD98UlA4f/+d1taDxiYTY=; b=VXSw+Z7XZmGfwzUdA4cQNyNFkkEN7RDyGpBaSU86ii/KqkFrZdQ1JHsgXHJvV6Z/Fn R89tlfM9O0Umdgd8aywic/ZsBlDgd/STNAm4BAhT8Ow0ClBWiC1x74R8M8M8ejXKbb5R jjUZ3/sNwKgd5yObMuNyKFh11drDZ0L8hGCGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671579; x=1732276379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rG3hGpHC8NrVDhtSg0TjY8wD98UlA4f/+d1taDxiYTY=; b=UBvWUXtoJmbfDVUdCrWUKPJucALq2iT2Tyhae+N/o5wuM9lx2whS95i5Dag03x91m2 S7MOqzqNTaI54Ayk+skKHAfZjG2rwfLfsbdkFKYOqJTk7fD2ownbTqWSer192h7N6WUB TeHV8F08RHEs3PtPVlOU/B2G/PnWzjHfAULIVNJJr3ETpf+gA8DdKaCPEWTgM85dd9iN 57zik/5wHzWkc/YG86WXjh+UALq5sU3XecMUZESkTvfNz4wJUj3ELLvwkC0UytEjCW8O 0dnXU/kO7EcEXg4zLxb2VGzoTzN97zeJ5tg30d15eLnd8XTU3lyE3Bl1veUuEqlOJTlr i93g== X-Gm-Message-State: AOJu0YypUk3rW751LqixkkV8hQ5vuWQIOL1H5yb9gvR/MmzVm2nuVSp7 rj80csInCXoHAUqTy5UGvxNrq1vreZZlVZo5sJimbBHGvDtpoB3EXqxxXw6/W3QRILYFrPKA3KG C X-Google-Smtp-Source: AGHT+IHaqAdkkVTKGpieGu4o1OUKEPqULq1gqWaTMHQnvFF1aQcJHkv9gR/qQtWD0pj2ilQM5lxifg== X-Received: by 2002:a17:906:fd89:b0:a9a:c61b:1329 with SMTP id a640c23a62f3a-aa4833f25bamr192432166b.3.1731671579539; Fri, 15 Nov 2024 03:52:59 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 05/25] tools/xenbindgen: Add basic plumbing for the C backend Date: Fri, 15 Nov 2024 11:51:34 +0000 Message-ID: <20241115115200.2824-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Takes an OutFileDef to generate a string with the file content. That will be all the structs, enums, bitmaps and includes we parse. For the time being, add the guards only, as the others are implemented by follow-up patches. Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/c_lang.rs | 73 +++++++++++++++++++++++++++++ tools/rust/xenbindgen/src/main.rs | 54 +++++++++++++++++++-- tools/rust/xenbindgen/src/spec.rs | 2 +- 3 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 tools/rust/xenbindgen/src/c_lang.rs diff --git a/tools/rust/xenbindgen/src/c_lang.rs b/tools/rust/xenbindgen/src/c_lang.rs new file mode 100644 index 000000000000..f05e36bb362f --- /dev/null +++ b/tools/rust/xenbindgen/src/c_lang.rs @@ -0,0 +1,73 @@ +//! C backend +//! +//! A backend for the C programming language. Enums and bitmaps appear as their +//! backing primitive type. This is in order to mandate size and alignment at +//! the ABI boundary. +//! +//! Otherwise, enums and struct are declared with their native C counterparts, +//! whereas bitmaps are declared as `#define` items. +//! +//! There's an expectation that the supporting library will have the +//! `(u)int64_aligned_t` types and `XEN_GUEST_HANDLE_64()`, These are important +//! in order to allow 32bit domains to interact with 64bit hypervisors. +//! +//! As far as definitions go, `enums` are stored in native `enums`, but bitmaps +//! are given in `#define` instead, with an empty struct on top to provide grep +//! fodder and a tag to follow using an LSP, global, cscope, etc. + +use std::fmt::Write; + +use crate::spec::OutFileDef; + +use convert_case::{Case, Casing}; + +/// An abstract indentation level. 0 is no indentation, 1 is [`INDENT_WIDTH`] +/// and so on. +#[derive(Copy, Clone)] +struct Indentation(usize); + +/// Default width of each level of indentation +const INDENT_WIDTH: usize = 4; + +/// Add a comment to a struct or a field. +fn comment(out: &mut String, comment: &str, ind: Indentation) { + let spaces = " ".repeat(INDENT_WIDTH * ind.0); + + if comment.contains('\n') { + writeln!(out, "{spaces}/*").unwrap(); + for line in comment.split('\n') { + write!(out, "{spaces} *").unwrap(); + if !line.is_empty() { + write!(out, " {line}").unwrap(); + } + writeln!(out).unwrap(); + } + writeln!(out, "{spaces} */").unwrap(); + } else { + writeln!(out, "{spaces}/* {comment} */").unwrap(); + } +} + +/// Generates a single `.h` file. +/// +/// `filedef` is a language-agnostic high level description of what the output +/// must contain. The function returns the contents of the new +/// +/// # Aborts +/// Aborts the process with `rc=1` on known illegal specifications. +pub fn parse(filedef: &OutFileDef) -> String { + let mut out = String::new(); + let name = filedef + .name + .from_case(Case::Kebab) + .to_case(Case::UpperSnake); + let hdr = format!("{}\n\nAUTOGENERATED. DO NOT MODIFY", filedef.name); + + comment(&mut out, &hdr, Indentation(0)); + writeln!(out, "#ifndef __XEN_AUTOGEN_{name}_H").unwrap(); + writeln!(out, "#define __XEN_AUTOGEN_{name}_H\n").unwrap(); + + writeln!(out, "#endif /* __XEN_AUTOGEN_{name}_H */\n").unwrap(); + + out +} diff --git a/tools/rust/xenbindgen/src/main.rs b/tools/rust/xenbindgen/src/main.rs index 497cf39d3bbd..00abf5ed7f33 100644 --- a/tools/rust/xenbindgen/src/main.rs +++ b/tools/rust/xenbindgen/src/main.rs @@ -4,11 +4,15 @@ mod spec; -use std::path::PathBuf; +mod c_lang; + +use std::{io::Write, path::PathBuf}; use clap::Parser; +use convert_case::{Case, Casing}; use env_logger::Env; use log::{error, info}; +use spec::OutFileDef; /// A CLI tool to generate struct definitions in several languages. #[derive(Parser, Debug)] @@ -17,6 +21,20 @@ struct Cli { /// Path to the input directory containing the hypercall specification #[arg(short, long)] indir: PathBuf, + /// Path to the output directory for the generated bindings. + #[arg(short, long)] + outdir: PathBuf, + /// Target language for the contents of `outdir`. + #[arg(short, long, value_enum)] + lang: Lang, +} + +/// Supported target languages +#[derive(clap::ValueEnum, Clone, Debug)] +#[clap(rename_all = "kebab_case")] +enum Lang { + #[doc(hidden)] + C, } fn main() { @@ -25,7 +43,7 @@ fn main() { let cli = Cli::parse(); info!("args: {:?}", cli); - let _specification = match spec::Spec::new(&cli.indir) { + let specification = match spec::Spec::new(&cli.indir) { Ok(x) => x, Err(spec::Error::Toml(x)) => { error!("TOML parsing error:"); @@ -39,5 +57,35 @@ fn main() { } }; - todo!("generate output files"); + let (extension, parser): (&str, fn(&OutFileDef) -> String) = match cli.lang { + Lang::C => (".h", c_lang::parse), + }; + + if let Err(x) = std::fs::create_dir_all(&cli.outdir) { + error!("Can't create outdir {:?}: {x}", cli.outdir); + std::process::exit(1); + } + + for outfile in &specification.0 { + let mut path = cli.outdir.clone(); + let name = outfile.name.from_case(Case::Kebab).to_case(Case::Snake); + path.push(format!("{name}{extension}")); + + info!("Generating {path:?}"); + + // Parse the input file before creating the output + let output = parser(outfile); + + let Ok(mut file) = std::fs::OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(path) + else { + error!("Can't open {}", outfile.name); + std::process::exit(1); + }; + + file.write_all(output.as_bytes()).unwrap(); + } } diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs index e69f7c78dc7a..08c4dc3a7eba 100644 --- a/tools/rust/xenbindgen/src/spec.rs +++ b/tools/rust/xenbindgen/src/spec.rs @@ -40,7 +40,7 @@ impl OutFileDef { pub fn new(name: String, dir: &Path) -> Result { info!("Reading {dir:?} to generate an output file"); - let mut ret = Self { name }; + let ret = Self { name }; for entry in from_ioerr(dir.read_dir())? { let path = from_ioerr(entry)?.path(); From patchwork Fri Nov 15 11:51:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86AD2D6DDED for ; Fri, 15 Nov 2024 11:53:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837171.1253143 (Exim 4.92) (envelope-from ) id 1tBust-0006ta-CU; Fri, 15 Nov 2024 11:53:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837171.1253143; Fri, 15 Nov 2024 11:53:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBust-0006sH-2R; Fri, 15 Nov 2024 11:53:07 +0000 Received: by outflank-mailman (input) for mailman id 837171; Fri, 15 Nov 2024 11:53:05 +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 1tBusr-0005U9-DN for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:05 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2a3d14b8-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:01 +0100 (CET) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-53da353eb2eso3085011e87.3 for ; Fri, 15 Nov 2024 03:53:01 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:00 -0800 (PST) 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: 2a3d14b8-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzEiLCJoZWxvIjoibWFpbC1sZjEteDEzMS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJhM2QxNGI4LWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTgxLjQ4MDI0Nywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671581; x=1732276381; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RtuVAWckySgEwBT7Q2jJXTvvBEFN4qBzWjX18KhTOXI=; b=lCNFOZYgR37FTqluRO7rq+/nzQ1V1196yI3DSqgeCKz0hNcRpx4hPrBT5yuj0GyDi1 zZhD6pFWuGrAtPty2mmzmyIPy3sLjn0wree3q+rr75hUJ2dKC+uVQuHnLy/nG5AHhX5D YhPTzhrroW5DX89nwT1K6GOAhsbEzAbhkgvnM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671581; x=1732276381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RtuVAWckySgEwBT7Q2jJXTvvBEFN4qBzWjX18KhTOXI=; b=BjctP7itKH4OXzP/V94kLz0EgpZfQlaSvJP4uI9a3mfQGDedCEkJlF+HQ6VETU/r2j 2elZh617njmd5eDQ4t64BlK2cPgNWs9J5MxePpTAjSj5u9CqQzRui8oqwSj7WmOAtjz/ Gp5PTLYPUeJFOQpvjNHZ3J7/GLbvGTSNCN112Dk6b+dZGcIMPsTWB+dW5KlrXqIn8P7y f6vlNE0l6ySjLRHvlT+H42MpOuCNlo3rCZ2ehE1Skxq2DBJgwlmH0WZCYZoE2ou095FD b+bush8vWRbFurL76Ahg5Nl2u+Dp8+R3c0anbF96ExAgrQjS4q9Y2mZ4d5vQ2fIzV9CM unOA== X-Gm-Message-State: AOJu0YwkGZNfZhQEnS2mI7MNYWBnf4Jp9HfcE/R1FCstSI938ykn15As y7gjXTcKD3yHi1PGNYZXLneqTgniadnc7nzHo/i/N44B2TOHJEtqcU4sXwVdpj4QcFqZeyf45uW T X-Google-Smtp-Source: AGHT+IFXW/E/Eudkb+RU8nreFxGzgMBtYX278zPiqlB0W34hCbY+VbAJKjG3v6x+rUfwxSmp0xwQIg== X-Received: by 2002:a05:6512:2820:b0:53b:154c:f75d with SMTP id 2adb3069b0e04-53dab2a9e83mr1829785e87.31.1731671580458; Fri, 15 Nov 2024 03:53:00 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 06/25] tools/xenbindgen: Add xenbindgen's Cargo.lock file Date: Fri, 15 Nov 2024 11:51:35 +0000 Message-ID: <20241115115200.2824-7-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Libraries mustn't have lock files, but binaries do. Add the lockfile with all dependencies of xenbindgen. Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/Cargo.lock | 430 +++++++++++++++++++++++++++++++ 1 file changed, 430 insertions(+) create mode 100644 tools/rust/xenbindgen/Cargo.lock diff --git a/tools/rust/xenbindgen/Cargo.lock b/tools/rust/xenbindgen/Cargo.lock new file mode 100644 index 000000000000..2c20c4ae8598 --- /dev/null +++ b/tools/rust/xenbindgen/Cargo.lock @@ -0,0 +1,430 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "clap" +version = "4.5.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "serde" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[package]] +name = "xenbindgen" +version = "0.2.0" +dependencies = [ + "clap", + "convert_case", + "env_logger", + "log", + "serde", + "toml", +] From patchwork Fri Nov 15 11:51:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A66A4D6DDF3 for ; Fri, 15 Nov 2024 11:53:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837170.1253137 (Exim 4.92) (envelope-from ) id 1tBuss-0006nG-Ru; Fri, 15 Nov 2024 11:53:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837170.1253137; Fri, 15 Nov 2024 11:53:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBuss-0006kU-LX; Fri, 15 Nov 2024 11:53:06 +0000 Received: by outflank-mailman (input) for mailman id 837170; Fri, 15 Nov 2024 11:53:05 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusr-0005UF-3I for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:05 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2ad09eef-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:02 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-aa1f73966a5so330068766b.2 for ; Fri, 15 Nov 2024 03:53:02 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:01 -0800 (PST) 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: 2ad09eef-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MjkiLCJoZWxvIjoibWFpbC1lajEteDYyOS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJhZDA5ZWVmLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTgyLjU5MTY5NCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671581; x=1732276381; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sytrPMdwvOY0m83CIY9iwMgAnzbQaeZ6sB2Zn3Z0ves=; b=ia6OOIe7bDVLHBHjRD6YKKlPht7JvSDYOhYyVQ6BNAEv+LbsvqtcCIpcrB3MeG252R Lag/ccoo9K3nrynhE2osLsiqqLpXpt1Nrd6qxOylJvJz7HdedWHeaQkybztMkOTs23+y S6hnVDmmeGfRMZIWBMYchi09yVtEdFNDfkOdU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671581; x=1732276381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sytrPMdwvOY0m83CIY9iwMgAnzbQaeZ6sB2Zn3Z0ves=; b=KfFolUdFcLq8xI6iIFHpu8zfdrcqxznCjngnC/Z2p3ChSKUh+dgBfc5SnIZm+/LM7l jnVx6g8HB96/5y+4TgT/Y0bL0bLCT5OwAr4tc/a4S4WVCJnqY7MqQwWQgZmscwWdRMzW Psfli61wjfzOHjv8SgHfQNyopOI8npiFtiCAtIEBTubqhk5xNvojq6PMF+fKBtyvk5Ql bfkZidZBqSvebBw8zdcggeZBbYpnPnAApD256jFUfujsMiDBntfOUINWy6aspBeWbrZw UsPOMwkpqJxZKLAvmcotdJmTs+wU4ntktCsxvoQP9jKKKQZjvq3vUi04Gbd24qjQAjYB mxgA== X-Gm-Message-State: AOJu0YzwFVj4kvY7v1h786NKSRg6n38hmlK+QEFVVQBk5Jx6xemlgIl3 7MLn8dFMp0GxU6tR4i4R/3CO4Ik5dIQaKFGFgKwdmRRI9ZEcF+SXidlh7kF9/MIDu+h61MPujPa E X-Google-Smtp-Source: AGHT+IGUG2gI1zP3YUOHglb/KaURYas4CdKMa21xCEvuFbstqXQ1lqYUtpzWfSRBrQSH8CDuFDrZvw== X-Received: by 2002:a17:906:eec9:b0:a9e:c954:6afb with SMTP id a640c23a62f3a-aa48355294dmr212971966b.51.1731671581436; Fri, 15 Nov 2024 03:53:01 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 07/25] tools/xenbindgen: Add support for structs in TOML specs Date: Fri, 15 Nov 2024 11:51:36 +0000 Message-ID: <20241115115200.2824-8-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/c_lang.rs | 56 ++++++++++++++++++++++++- tools/rust/xenbindgen/src/spec.rs | 64 ++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/tools/rust/xenbindgen/src/c_lang.rs b/tools/rust/xenbindgen/src/c_lang.rs index f05e36bb362f..597e0ed41362 100644 --- a/tools/rust/xenbindgen/src/c_lang.rs +++ b/tools/rust/xenbindgen/src/c_lang.rs @@ -17,9 +17,10 @@ use std::fmt::Write; -use crate::spec::OutFileDef; +use crate::spec::{OutFileDef, StructDef, Typ}; use convert_case::{Case, Casing}; +use log::{debug, trace}; /// An abstract indentation level. 0 is no indentation, 1 is [`INDENT_WIDTH`] /// and so on. @@ -29,6 +30,39 @@ struct Indentation(usize); /// Default width of each level of indentation const INDENT_WIDTH: usize = 4; +/// Create a C-compatible struct field. Without the terminating semicolon. +fn structfield(typ: &Typ, name: &str) -> String { + match typ { + Typ::Ptr(x) => { + let t: &Typ = x; + format!( + "XEN_GUEST_HANDLE_64({}) {name}", + match t { + Typ::U8 => "uint8", + Typ::U16 => "uint16", + Typ::U32 => "uint32", + Typ::U64 => "uint64_aligned_t", + Typ::I8 => "int8", + Typ::I16 => "int16", + Typ::I32 => "int32", + Typ::I64 => "int64_aligned_t", + _ => panic!("foo {t:?}"), + } + ) + } + Typ::Struct(x) => format!("struct {x} {name}"), + Typ::Array(x, len) => format!("{}{name}[{len}]", structfield(x, "")), + Typ::U8 => format!("uint8_t {name}"), + Typ::U16 => format!("uint16_t {name}"), + Typ::U32 => format!("uint32_t {name}"), + Typ::U64 => format!("uint64_aligned_t {name}"), + Typ::I8 => format!("int8_t {name}"), + Typ::I16 => format!("int16_t {name}"), + Typ::I32 => format!("int32_t {name}"), + Typ::I64 => format!("int64_aligned_t {name}"), + } +} + /// Add a comment to a struct or a field. fn comment(out: &mut String, comment: &str, ind: Indentation) { let spaces = " ".repeat(INDENT_WIDTH * ind.0); @@ -48,6 +82,22 @@ fn comment(out: &mut String, comment: &str, ind: Indentation) { } } +/// Write a C-compatible struct onto `out` +fn structgen(out: &mut String, def: &StructDef) { + debug!("struct {}", def.name); + + comment(out, &def.description, Indentation(0)); + writeln!(out, "struct {} {{", def.name.to_case(Case::Snake)).unwrap(); + for f in &def.fields { + trace!(" field {} type={:?}", f.name, f.typ); + + comment(out, &f.description, Indentation(1)); + writeln!(out, " {};", structfield(&f.typ, &f.name),).unwrap(); + } + writeln!(out, "}};").unwrap(); + writeln!(out).unwrap(); +} + /// Generates a single `.h` file. /// /// `filedef` is a language-agnostic high level description of what the output @@ -67,6 +117,10 @@ pub fn parse(filedef: &OutFileDef) -> String { writeln!(out, "#ifndef __XEN_AUTOGEN_{name}_H").unwrap(); writeln!(out, "#define __XEN_AUTOGEN_{name}_H\n").unwrap(); + for def in &filedef.structs { + structgen(&mut out, def); + } + writeln!(out, "#endif /* __XEN_AUTOGEN_{name}_H */\n").unwrap(); out diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs index 08c4dc3a7eba..e183378329ad 100644 --- a/tools/rust/xenbindgen/src/spec.rs +++ b/tools/rust/xenbindgen/src/spec.rs @@ -17,9 +17,61 @@ use std::{fs::read_to_string, path::Path}; use log::{debug, info}; +/// An IDL type. A type may be a primitive integer, a pointer to an IDL type, +/// an array of IDL types or a struct composed of IDL types. Every integer must +/// be aligned to its size. +/// +/// FIXME: This enumerated type is recovered as-is from the `typ` field in the +/// TOML files. Ideally, that representation should be more ergonomic and the +/// parser instructed to deal with it. +#[allow(clippy::missing_docs_in_private_items)] +#[derive(Debug, serde::Deserialize, PartialEq)] +#[serde(rename_all = "lowercase", tag = "tag", content = "args")] +pub enum Typ { + Struct(String), + U8, + U16, + U32, + U64, + I8, + I16, + I32, + I64, + Ptr(Box), + Array(Box, usize), +} + +/// Deserialized form of a hypercall struct +#[derive(Debug, serde::Deserialize)] +pub struct StructDef { + /// Name of the struct + pub name: String, + /// Description of what the struct is for. This string is added as a comment + /// on top of the autogenerated struct. + pub description: String, + /// Fields contained in the struct. May be none, in which case it's a zero + /// length struct. + pub fields: Vec, +} + +/// Deserialized form of a field within a hypercall struct (see [`StructDef`]) +#[derive(Debug, serde::Deserialize)] +pub struct FieldDef { + /// Name of the field + pub name: String, + /// Description of what the field is for. This string is added as a comment + /// on top of the autogenerated field. + pub description: String, + /// Type of the field. + pub typ: Typ, +} + /// A language-agnostic specification. #[derive(Debug, serde::Deserialize)] -struct InFileDef; +struct InFileDef { + /// List of structs described in this input specification. + structs: Option>, +} /// Description of an abstract output (i.e: `.rs`, `.h`, etc). /// @@ -28,6 +80,8 @@ struct InFileDef; pub struct OutFileDef { /// The name of the output file, without the final extension. pub name: String, + /// List of structs described by all input spec files merged on this file. + pub structs: Vec, } impl OutFileDef { @@ -40,13 +94,19 @@ impl OutFileDef { pub fn new(name: String, dir: &Path) -> Result { info!("Reading {dir:?} to generate an output file"); - let ret = Self { name }; + let mut ret = Self { + name, + structs: Vec::new(), + }; for entry in from_ioerr(dir.read_dir())? { let path = from_ioerr(entry)?.path(); debug!("Reading {:?} to generate outfile={}", path, ret.name); let toml_str = from_ioerr(read_to_string(path))?; let filedef: InFileDef = toml::from_str(&toml_str).map_err(Error::Toml)?; + if let Some(structs) = filedef.structs { + ret.structs.extend(structs); + } } Ok(ret) From patchwork Fri Nov 15 11:51:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF218D6DDF6 for ; Fri, 15 Nov 2024 11:53:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837172.1253158 (Exim 4.92) (envelope-from ) id 1tBusv-0007NW-2A; Fri, 15 Nov 2024 11:53:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837172.1253158; Fri, 15 Nov 2024 11:53:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusu-0007Le-R8; Fri, 15 Nov 2024 11:53:08 +0000 Received: by outflank-mailman (input) for mailman id 837172; Fri, 15 Nov 2024 11:53:07 +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 1tBust-0005U9-0Z for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:07 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2b58546f-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:03 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5cf92052dccso678254a12.3 for ; Fri, 15 Nov 2024 03:53:03 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:01 -0800 (PST) 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: 2b58546f-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmIiLCJoZWxvIjoibWFpbC1lZDEteDUyYi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJiNTg1NDZmLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTgzLjM2NDIxNiwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671582; x=1732276382; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MUgtaKrT3gy7aHkmDb2vFmH4giHOPfcM9Tol6GmTY3s=; b=O3N9hDacTbg0HzuIR4/Gy1gOlKT6qyF6HJzUs+7t7vzOp3zuk1f27xd4Hz7fflRQRX bYsu/sA7jpuu9OObtQWmlo0Kmn+5TAd3VA5M5Gun8x/bvEu/bgCzn7tEJWaOotIKC2ZS Kb7kVfrMy4L+2ghqlj6x1Zcd88iuUFsz2MQAc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671582; x=1732276382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MUgtaKrT3gy7aHkmDb2vFmH4giHOPfcM9Tol6GmTY3s=; b=pcImA0Q4avmzQMt/mXfCZEm3GJzmX5DMiV+FKGq3RAynrmFRRWuP5im0qO+OTUsi7X kyfUEQH8j+8IZvR1l4Xn+5m4Df2TDPcWx+aJvE/RX/UvPGjsE9aruYCPPF3puOjUc5Qy sT281Ip57+Dxgw+jRyZk0Bl/FpMJ7ZiAXhafjpZhb49ES9j9v9XepLNPRHFIuvnx6Qur d4dZpfkO2nxnU5/f8CMME5TVsCfxOrSmFDeDHGRVqmF1fuoekNnWeBOxiDa6ZYBnTMu0 Fy5TisvjwgaUb8hMj6vrmOXyti8W/ZCy//CYE8dSHGOlik/oacDPd2bT2R2ARv4e0xK1 xirw== X-Gm-Message-State: AOJu0YwA5niI2buAXFG/q4ywRlmzSgGIea+hgHBczK7Xai+7sMpyN5Mi VjIF5dtBO51NwGarixvcEeBTWZMHUdUlI7dXcMVx0v+XJDSNt761mP7xwv+3HvFQg6K6dHjt507 M X-Google-Smtp-Source: AGHT+IG9VPnK6lcDqiT+pRatAYmBM3rUx+M/OAGFEqSWL7erFc5SiLGVGbOYZXO4M5kqQUBr7Kg/4A== X-Received: by 2002:a17:907:2ce6:b0:a9a:1a6a:b5f5 with SMTP id a640c23a62f3a-aa48354e251mr219367066b.56.1731671582438; Fri, 15 Nov 2024 03:53:02 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 08/25] tools/xenbindgen: Add support for enums in TOML specs Date: Fri, 15 Nov 2024 11:51:37 +0000 Message-ID: <20241115115200.2824-9-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/c_lang.rs | 57 +++++++++++++++++++++++++---- tools/rust/xenbindgen/src/spec.rs | 45 +++++++++++++++++++++++ 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/tools/rust/xenbindgen/src/c_lang.rs b/tools/rust/xenbindgen/src/c_lang.rs index 597e0ed41362..f15feca8df91 100644 --- a/tools/rust/xenbindgen/src/c_lang.rs +++ b/tools/rust/xenbindgen/src/c_lang.rs @@ -17,10 +17,10 @@ use std::fmt::Write; -use crate::spec::{OutFileDef, StructDef, Typ}; +use crate::spec::{EnumDef, OutFileDef, StructDef, Typ}; use convert_case::{Case, Casing}; -use log::{debug, trace}; +use log::{debug, error, trace}; /// An abstract indentation level. 0 is no indentation, 1 is [`INDENT_WIDTH`] /// and so on. @@ -31,7 +31,7 @@ struct Indentation(usize); const INDENT_WIDTH: usize = 4; /// Create a C-compatible struct field. Without the terminating semicolon. -fn structfield(typ: &Typ, name: &str) -> String { +fn structfield(filedef: &OutFileDef, typ: &Typ, name: &str) -> String { match typ { Typ::Ptr(x) => { let t: &Typ = x; @@ -51,7 +51,20 @@ fn structfield(typ: &Typ, name: &str) -> String { ) } Typ::Struct(x) => format!("struct {x} {name}"), - Typ::Array(x, len) => format!("{}{name}[{len}]", structfield(x, "")), + Typ::Enum(x) => { + // C can't use an enum as a field and fix its width. Look for its + // underlying layout and use that type instead. + let Some(e) = filedef.enums.iter().find(|y| *x == y.name) else { + error!("Can't find enum {x}. Typo?"); + std::process::exit(1); + }; + format!( + "{} /* See {} */", + structfield(filedef, &e.typ, name), + e.name + ) + } + Typ::Array(x, len) => format!("{}{name}[{len}]", structfield(filedef, x, "")), Typ::U8 => format!("uint8_t {name}"), Typ::U16 => format!("uint16_t {name}"), Typ::U32 => format!("uint32_t {name}"), @@ -83,7 +96,7 @@ fn comment(out: &mut String, comment: &str, ind: Indentation) { } /// Write a C-compatible struct onto `out` -fn structgen(out: &mut String, def: &StructDef) { +fn structgen(out: &mut String, filedef: &OutFileDef, def: &StructDef) { debug!("struct {}", def.name); comment(out, &def.description, Indentation(0)); @@ -92,7 +105,33 @@ fn structgen(out: &mut String, def: &StructDef) { trace!(" field {} type={:?}", f.name, f.typ); comment(out, &f.description, Indentation(1)); - writeln!(out, " {};", structfield(&f.typ, &f.name),).unwrap(); + writeln!(out, " {};", structfield(filedef, &f.typ, &f.name),).unwrap(); + } + writeln!(out, "}};").unwrap(); + writeln!(out).unwrap(); +} + +/// Write a C-compatible enum onto `out` +/// +/// This is a generator for the enum _type_, not an instantiation of a bitmap +/// in a struct field. Use [`structfield`] for that. +fn enumgen(out: &mut String, def: &EnumDef) { + debug!("enum {}", def.name); + + comment(out, &def.description, Indentation(0)); + writeln!(out, "enum {} {{", def.name).unwrap(); + for f in &def.variants { + trace!(" variant {}={}", f.name, f.value); + + comment(out, &f.description, Indentation(1)); + writeln!( + out, + " {}_{} = {},", + def.name.from_case(Case::Snake).to_case(Case::UpperSnake), + f.name.from_case(Case::Snake).to_case(Case::UpperSnake), + f.value + ) + .unwrap(); } writeln!(out, "}};").unwrap(); writeln!(out).unwrap(); @@ -117,8 +156,12 @@ pub fn parse(filedef: &OutFileDef) -> String { writeln!(out, "#ifndef __XEN_AUTOGEN_{name}_H").unwrap(); writeln!(out, "#define __XEN_AUTOGEN_{name}_H\n").unwrap(); + for def in &filedef.enums { + enumgen(&mut out, def); + } + for def in &filedef.structs { - structgen(&mut out, def); + structgen(&mut out, filedef, def); } writeln!(out, "#endif /* __XEN_AUTOGEN_{name}_H */\n").unwrap(); diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs index e183378329ad..f6cfedad2150 100644 --- a/tools/rust/xenbindgen/src/spec.rs +++ b/tools/rust/xenbindgen/src/spec.rs @@ -28,6 +28,7 @@ use log::{debug, info}; #[derive(Debug, serde::Deserialize, PartialEq)] #[serde(rename_all = "lowercase", tag = "tag", content = "args")] pub enum Typ { + Enum(String), Struct(String), U8, U16, @@ -66,11 +67,47 @@ pub struct FieldDef { pub typ: Typ, } +/// Description of a lang-agnostic enumerated type. +#[derive(Debug, serde::Deserialize)] +pub struct EnumDef { + /// snake-cased name of this enumeration. + /// + /// Must be converted to whatever is idiomatic in the target language. + pub name: String, + /// Description of what the type is for. + /// + /// Must be turned into documentation in the autogenerated file. + pub description: String, + /// Width of the type given as an equivalent primitive unsigned integer + /// of the same width. + pub typ: Typ, + /// List of variants present in this enum. + /// + /// The backend must export all of these under the same namespace if + /// possible. + pub variants: Vec, +} + +/// A lang-agnostic description of a single variant of an enumerated type. +#[derive(Debug, serde::Deserialize)] +pub struct VariantDef { + /// Name of this variant. Depending on the backend, the name might be + /// prefixed by the name of its type (as is commonly done in C). + pub name: String, + /// Meaning of this variant in the context of its type. + pub description: String, + /// Actual value associated with this variant. Must be explicit to enable + /// deprecation of variants. + pub value: u64, +} + /// A language-agnostic specification. #[derive(Debug, serde::Deserialize)] struct InFileDef { /// List of structs described in this input specification. structs: Option>, + /// List of lang-agnostic enumerated descriptions. + enums: Option>, } /// Description of an abstract output (i.e: `.rs`, `.h`, etc). @@ -82,6 +119,10 @@ pub struct OutFileDef { pub name: String, /// List of structs described by all input spec files merged on this file. pub structs: Vec, + /// List of enumerated descriptions. + /// + /// Implementation is lang-specific. + pub enums: Vec, } impl OutFileDef { @@ -97,6 +138,7 @@ impl OutFileDef { let mut ret = Self { name, structs: Vec::new(), + enums: Vec::new(), }; for entry in from_ioerr(dir.read_dir())? { @@ -107,6 +149,9 @@ impl OutFileDef { if let Some(structs) = filedef.structs { ret.structs.extend(structs); } + if let Some(enums) = filedef.enums { + ret.enums.extend(enums); + } } Ok(ret) From patchwork Fri Nov 15 11:51:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E5F8D6DDF2 for ; Fri, 15 Nov 2024 11:53:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837173.1253169 (Exim 4.92) (envelope-from ) id 1tBusw-0007jC-8s; Fri, 15 Nov 2024 11:53:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837173.1253169; Fri, 15 Nov 2024 11:53:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusw-0007ia-3N; Fri, 15 Nov 2024 11:53:10 +0000 Received: by outflank-mailman (input) for mailman id 837173; Fri, 15 Nov 2024 11:53:08 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusu-0005UF-1x for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:08 +0000 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [2a00:1450:4864:20::12e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2ca2dcb8-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:05 +0100 (CET) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-53b13ea6b78so2731475e87.2 for ; Fri, 15 Nov 2024 03:53:05 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:02 -0800 (PST) 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: 2ca2dcb8-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMmUiLCJoZWxvIjoibWFpbC1sZjEteDEyZS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJjYTJkY2I4LWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTg1LjUzODAwNCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671585; x=1732276385; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4UVXJgy4IHwj4NwXexnbXM0jpHKa0ukLk9RTwQ1hG1I=; b=chfRZVlR38IjXdJcCLnlN5v5M8/A3TNgscAUsZQDAZQjcOYf7slZ5bkSvm7ZDB/Q+G +e7RGUS7Xb+f2+NFU7+1dpbszqBk/c2U659T6Kom4zK34GSM/bi17ZavaTStK8HrnCuA scA4WINPJEX+s7Tfpwu7enufidzhxt/HZzlXs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671585; x=1732276385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4UVXJgy4IHwj4NwXexnbXM0jpHKa0ukLk9RTwQ1hG1I=; b=tlsZMo5wA/Nyc1Iu0fvec4GmE2Ip6yxQzIQ8AOUpcu7wi/g3P/YMP8Cz1HrZYFN8w4 omZ14h76zZHUv7CrakKbOwKGjbcwQ3+B+Vxj0zEbA9nFQhtjnerdvcYLBQc2SutufMWX xU2zt2cuUiPhf8DJHiY7b1wN91PfvrBx6YQXDPzjROr13sXFNHzVn4SuauolMJN1udGc SNxHJRXvPjnUaPmNECe7qIpWkIGXDJh6/yIdfc8WywpZNrfakFrf6sk5WgQHmXNEM1Wc wSnv7YhRtS0ApJbLFKwepKH6SUEGOmwLTXMigqK0dwBmOM/kyRmvRatSLz11QDuGQga4 qe0g== X-Gm-Message-State: AOJu0Ywvpk1MRhZ+pzI9qPn3X+mB5pozO1TpVNseukfD8W/N/xyfTTGZ jmuTZO5xRkUYw0+lH3ZEpEzJyXUz5503mCRdChaM/7hLZz8j4OHF+cxd8/u5HfmPL2Ap5fE5xWw 3 X-Google-Smtp-Source: AGHT+IHB6/A5vaCAqemK1HkjKE8fNgzdfB6BTygGqlZqFndf7w6R/839QxxCcp8cFQ89KFP8D28cVA== X-Received: by 2002:a05:6512:224b:b0:53d:a16e:3684 with SMTP id 2adb3069b0e04-53dab3b16ebmr1877359e87.41.1731671583351; Fri, 15 Nov 2024 03:53:03 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 09/25] tools/xenbindgen: Add support for bitmaps in TOML specs Date: Fri, 15 Nov 2024 11:51:38 +0000 Message-ID: <20241115115200.2824-10-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/c_lang.rs | 62 ++++++++++++++++++++++++++++- tools/rust/xenbindgen/src/spec.rs | 51 ++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 5 deletions(-) diff --git a/tools/rust/xenbindgen/src/c_lang.rs b/tools/rust/xenbindgen/src/c_lang.rs index f15feca8df91..bba310233e60 100644 --- a/tools/rust/xenbindgen/src/c_lang.rs +++ b/tools/rust/xenbindgen/src/c_lang.rs @@ -17,7 +17,7 @@ use std::fmt::Write; -use crate::spec::{EnumDef, OutFileDef, StructDef, Typ}; +use crate::spec::{BitmapDef, EnumDef, OutFileDef, StructDef, Typ}; use convert_case::{Case, Casing}; use log::{debug, error, trace}; @@ -51,6 +51,20 @@ fn structfield(filedef: &OutFileDef, typ: &Typ, name: &str) -> String { ) } Typ::Struct(x) => format!("struct {x} {name}"), + Typ::Bitmap(x) => { + // Dealing with bitfields at the ABI boundary is a + // pain, so we just use the underlying type instead. + let Some(e) = filedef.bitmaps.iter().find(|y| *x == y.name) else { + error!("Can't find bitmap {x}. Typo?"); + trace!("{filedef:#?}"); + std::process::exit(1); + }; + format!( + "{} /* See {} */", + structfield(filedef, &e.typ, name), + e.name + ) + } Typ::Enum(x) => { // C can't use an enum as a field and fix its width. Look for its // underlying layout and use that type instead. @@ -137,6 +151,48 @@ fn enumgen(out: &mut String, def: &EnumDef) { writeln!(out).unwrap(); } +/// Write a C-compatible enum onto `out` +fn bitmapgen(out: &mut String, def: &BitmapDef) { + debug!("bitmap {}", def.name); + + comment(out, &def.description, Indentation(0)); + writeln!(out, "struct {} {{}}; /* GREP FODDER */", def.name).unwrap(); + + let mut mask = 0; + for f in &def.bits { + trace!(" shift {}={}", f.name, f.shift); + + if (1 << f.shift) & mask != 0 { + error!("Bad shift({}) on {}. Shadows another bit.", f.shift, f.name); + std::process::exit(1); + } + + mask |= 1 << f.shift; + + comment(out, &f.description, Indentation(0)); + writeln!( + out, + "#define {}_{} (1U{} << {})", + def.name.from_case(Case::Snake).to_case(Case::UpperSnake), + f.name.from_case(Case::Snake).to_case(Case::UpperSnake), + if def.typ == Typ::U64 { "LL" } else { "" }, + f.shift + ) + .unwrap(); + } + + comment(out, "Mask covering all defined bits", Indentation(0)); + writeln!( + out, + "#define {}__ALL ({:#X}U{})", + def.name.from_case(Case::Snake).to_case(Case::UpperSnake), + mask, + if def.typ == Typ::U64 { "LL" } else { "" }, + ) + .unwrap(); + writeln!(out).unwrap(); +} + /// Generates a single `.h` file. /// /// `filedef` is a language-agnostic high level description of what the output @@ -160,6 +216,10 @@ pub fn parse(filedef: &OutFileDef) -> String { enumgen(&mut out, def); } + for def in &filedef.bitmaps { + bitmapgen(&mut out, def); + } + for def in &filedef.structs { structgen(&mut out, filedef, def); } diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs index f6cfedad2150..4a9c5e7d028b 100644 --- a/tools/rust/xenbindgen/src/spec.rs +++ b/tools/rust/xenbindgen/src/spec.rs @@ -28,6 +28,7 @@ use log::{debug, info}; #[derive(Debug, serde::Deserialize, PartialEq)] #[serde(rename_all = "lowercase", tag = "tag", content = "args")] pub enum Typ { + Bitmap(String), Enum(String), Struct(String), U8, @@ -72,7 +73,7 @@ pub struct FieldDef { pub struct EnumDef { /// snake-cased name of this enumeration. /// - /// Must be converted to whatever is idiomatic in the target language. + /// Must be converted to idiomatic casing in the target language. pub name: String, /// Description of what the type is for. /// @@ -88,11 +89,43 @@ pub struct EnumDef { pub variants: Vec, } -/// A lang-agnostic description of a single variant of an enumerated type. +/// Lang-agnostic description of a bitmap type. +#[derive(Debug, serde::Deserialize)] +pub struct BitmapDef { + /// Snake-cased name of this bitmap. + /// + /// Must be converted to idiomatic casing in the target language. + pub name: String, + /// Description of what the type is for. + /// + /// Must be turned into documentation in the autogenerated file. + pub description: String, + /// Width of the type given as an equivalent primitive unsigned integer + /// of the same width. + pub typ: Typ, + /// List of bits in the bitmap with a described meaning. All other bits are + /// reserved to zero. + pub bits: Vec, +} + +/// Lang-agnostic description of a single bit within a particular bitmap type. +#[derive(Debug, serde::Deserialize)] +pub struct BitDef { + /// Snake-cased name of this bit. Depending on the backend, the name + /// might be prefixed by the name of its type (as is commonly done in C). + pub name: String, + /// Meaning of this bit in the context of its type. + pub description: String, + /// Position of the bit in the underlying type, following a little-endian + /// convention. + pub shift: u8, +} + +/// Lang-agnostic description of a single variant of an enumerated type. #[derive(Debug, serde::Deserialize)] pub struct VariantDef { - /// Name of this variant. Depending on the backend, the name might be - /// prefixed by the name of its type (as is commonly done in C). + /// Snake-cased name of this variant. Depending on the backend, the name + /// might be prefixed by the name of its type (as is commonly done in C). pub name: String, /// Meaning of this variant in the context of its type. pub description: String, @@ -108,6 +141,8 @@ struct InFileDef { structs: Option>, /// List of lang-agnostic enumerated descriptions. enums: Option>, + /// List of lang-agnostic bitmap descriptions. + bitmaps: Option>, } /// Description of an abstract output (i.e: `.rs`, `.h`, etc). @@ -123,6 +158,10 @@ pub struct OutFileDef { /// /// Implementation is lang-specific. pub enums: Vec, + /// List of bitmap descriptions. + /// + /// Implementation is lang-specific. + pub bitmaps: Vec, } impl OutFileDef { @@ -139,6 +178,7 @@ impl OutFileDef { name, structs: Vec::new(), enums: Vec::new(), + bitmaps: Vec::new(), }; for entry in from_ioerr(dir.read_dir())? { @@ -152,6 +192,9 @@ impl OutFileDef { if let Some(enums) = filedef.enums { ret.enums.extend(enums); } + if let Some(bitmaps) = filedef.bitmaps { + ret.bitmaps.extend(bitmaps); + } } Ok(ret) From patchwork Fri Nov 15 11:51:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85BD7D6DDF3 for ; Fri, 15 Nov 2024 11:53:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837176.1253174 (Exim 4.92) (envelope-from ) id 1tBusw-0007ng-Rg; Fri, 15 Nov 2024 11:53:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837176.1253174; Fri, 15 Nov 2024 11:53:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusw-0007lq-Ey; Fri, 15 Nov 2024 11:53:10 +0000 Received: by outflank-mailman (input) for mailman id 837176; Fri, 15 Nov 2024 11:53:08 +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 1tBusu-0005U9-Cr for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:08 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2c704f42-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:05 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9ed0ec0e92so219687566b.0 for ; Fri, 15 Nov 2024 03:53:05 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:03 -0800 (PST) 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: 2c704f42-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MmUiLCJoZWxvIjoibWFpbC1lajEteDYyZS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJjNzA0ZjQyLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTg1LjIxODUzNywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671584; x=1732276384; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tbzbnGY5b9VCsBtIJf+XEboWM0m6rBzXP5FkkZe8vV8=; b=aymRs0YGOTds2TOl2MBBQXJgpWqyzn4AZLSvz1r/XTEiCZKS2mxm5NwQ3b2GP/r4eZ g24oHlGD+6pV2Ogaq8t8zBq06+RaxEQoGARk8T252NAI03vg41ghH59ZnSXg+/2DWFiD RTu585d1F7aBc1pewEv1wNFUJCKObTM3GgKGI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671584; x=1732276384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tbzbnGY5b9VCsBtIJf+XEboWM0m6rBzXP5FkkZe8vV8=; b=g5VuXjssj77uQOxWBnFfm/tywt7rW4UR4xSRkExp95TAGeyZGATo26Lrkr28K3SKE/ ep8Ukj7EkHvzNaOrPodBTX4C2YPG6wCorO3/3bEre2xYHQyQ0faT+mG/lPP0Q1M7qht0 GeIZxdQxT9Sq+dYzDyzKP9d60RR50x0MyBx+fispyDff+5KziQEK27UvVauwu5YPgkwP qrdwDQ/zH6T+HzISh6yUJMhqdSeDlWyUESebOkGdxYABV0+5zXPVZFfYrHckuHq69KzR UUICCJ9fR0C7Lq/SdFo3RA0ae7+QnuX4bfQsTLO1yEmqBUoRBLiFN+j0KwotXeVgPY5+ 79Lg== X-Gm-Message-State: AOJu0YyMnjaZK3l9I6WQ/aFHS1MTgyA//pEHl18AmgvmcWavyZcPu4rB mXLqLfYlDMmnant8W62jPwF4VFSMBkJR7X4MCvVOEooh+gotDSNHvkcUEpen67vMFaxnXd4I7wL 4 X-Google-Smtp-Source: AGHT+IEoZKaaro2gVDw6s0jZEmgVgGc0g3JA1rEf4FQjZi9vMd9pDARUKg2VgqJPwwuPjdnSUjNYjg== X-Received: by 2002:a17:907:701:b0:a9e:b471:8308 with SMTP id a640c23a62f3a-aa4835523d4mr198218066b.49.1731671584278; Fri, 15 Nov 2024 03:53:04 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 10/25] tools/xenbindgen: Add support for includes in the TOML specs Date: Fri, 15 Nov 2024 11:51:39 +0000 Message-ID: <20241115115200.2824-11-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Adds include-like semantics to the TOML files. Note that "arch" is special to allow (a) generating all arch-specific files in one go and (b) demultiplex appropriately. Signed-off-by: Teddy Astie Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/c_lang.rs | 39 ++++++++++++++++++++++++++++- tools/rust/xenbindgen/src/spec.rs | 24 ++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/tools/rust/xenbindgen/src/c_lang.rs b/tools/rust/xenbindgen/src/c_lang.rs index bba310233e60..be6be3756dc0 100644 --- a/tools/rust/xenbindgen/src/c_lang.rs +++ b/tools/rust/xenbindgen/src/c_lang.rs @@ -17,7 +17,7 @@ use std::fmt::Write; -use crate::spec::{BitmapDef, EnumDef, OutFileDef, StructDef, Typ}; +use crate::spec::{BitmapDef, EnumDef, IncludeDef, OutFileDef, StructDef, Typ}; use convert_case::{Case, Casing}; use log::{debug, error, trace}; @@ -109,6 +109,39 @@ fn comment(out: &mut String, comment: &str, ind: Indentation) { } } +/// Adds specified `includes`. `arch` must be treated specially in order to +/// demultiplex the target architecture. +/// +/// The reason for the inclusion must be printed as a comment on top of the +/// `include` itself. +fn includegen(out: &mut String, def: &IncludeDef) { + if !def.imports.is_empty() { + comment( + out, + &format!("for {}", def.imports.join(",\n ")), + Indentation(0), + ); + } + + if def.from == "arch" { + writeln!(out, "#if defined(__i386__) || defined(__x86_64__)").unwrap(); + writeln!(out, "#include \"arch_x86.h\"").unwrap(); + writeln!(out, "#elif defined(__arm__) || defined(__aarch64__)").unwrap(); + writeln!(out, "#include \"arch_arm.h\"").unwrap(); + writeln!(out, "#elif defined(__powerpc64__)").unwrap(); + writeln!(out, "#include \"arch_ppc.h\"").unwrap(); + writeln!(out, "#elif defined(__riscv)").unwrap(); + writeln!(out, "#include \"arch_riscv.h\"").unwrap(); + writeln!(out, "#else").unwrap(); + writeln!(out, "#error \"Unsupported architecture\"").unwrap(); + writeln!(out, "#endif").unwrap(); + } else { + writeln!(out, "#include \"{}.h\"", def.from).unwrap(); + } + + writeln!(out).unwrap(); +} + /// Write a C-compatible struct onto `out` fn structgen(out: &mut String, filedef: &OutFileDef, def: &StructDef) { debug!("struct {}", def.name); @@ -212,6 +245,10 @@ pub fn parse(filedef: &OutFileDef) -> String { writeln!(out, "#ifndef __XEN_AUTOGEN_{name}_H").unwrap(); writeln!(out, "#define __XEN_AUTOGEN_{name}_H\n").unwrap(); + for def in &filedef.includes { + includegen(&mut out, def); + } + for def in &filedef.enums { enumgen(&mut out, def); } diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs index 4a9c5e7d028b..04be05187ac8 100644 --- a/tools/rust/xenbindgen/src/spec.rs +++ b/tools/rust/xenbindgen/src/spec.rs @@ -134,9 +134,24 @@ pub struct VariantDef { pub value: u64, } +/// Dependency links between files. +/// +/// Used in specifications to state a number of types (described in `imports`) +/// is needed from another generated file (the `from` field). +#[derive(Debug, serde::Deserialize)] +pub struct IncludeDef { + /// Name of the [`InFileDef`] that contains the imported tokens of + /// `imports`. + pub from: String, + /// List of tokens used in this spec file that exist in `from`. + pub imports: Vec, +} + /// A language-agnostic specification. #[derive(Debug, serde::Deserialize)] struct InFileDef { + /// List of types described in other [`InFileDef`] that are required here. + includes: Option>, /// List of structs described in this input specification. structs: Option>, /// List of lang-agnostic enumerated descriptions. @@ -152,7 +167,12 @@ struct InFileDef { pub struct OutFileDef { /// The name of the output file, without the final extension. pub name: String, + /// Represents the dependencies between various [`OutFileDef`]. A language + /// backend is free to ignore these if they are not required. + pub includes: Vec, /// List of structs described by all input spec files merged on this file. + /// + /// Implementation is lang-specific. pub structs: Vec, /// List of enumerated descriptions. /// @@ -176,6 +196,7 @@ impl OutFileDef { let mut ret = Self { name, + includes: Vec::new(), structs: Vec::new(), enums: Vec::new(), bitmaps: Vec::new(), @@ -195,6 +216,9 @@ impl OutFileDef { if let Some(bitmaps) = filedef.bitmaps { ret.bitmaps.extend(bitmaps); } + if let Some(includes) = filedef.includes { + ret.includes.extend(includes); + } } Ok(ret) From patchwork Fri Nov 15 11:51:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 076ACD6DDF3 for ; Fri, 15 Nov 2024 11:53:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837178.1253181 (Exim 4.92) (envelope-from ) id 1tBusx-0007zK-MB; Fri, 15 Nov 2024 11:53:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837178.1253181; Fri, 15 Nov 2024 11:53:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusx-0007xN-89; Fri, 15 Nov 2024 11:53:11 +0000 Received: by outflank-mailman (input) for mailman id 837178; Fri, 15 Nov 2024 11:53:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusv-0005UF-SM for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:09 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2d7aaf4e-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:06 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a9e8522445dso325337866b.1 for ; Fri, 15 Nov 2024 03:53:06 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:05 -0800 (PST) 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: 2d7aaf4e-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MmQiLCJoZWxvIjoibWFpbC1lajEteDYyZC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJkN2FhZjRlLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTg2Ljk0NjI0NCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671586; x=1732276386; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ptbAWv8IG3SuQFQX+roZZIviyToXBTNl2Q3I+8WN9Ug=; b=baw161JlfF0ltJZE/lT56q2pt4gHFiaU3yurlW10MDevxr8hG+SSzJB+YdZ42hpxw9 6hSZccREZX7PnIKPEe+Fzw6d1tyRA0wrb0tIMtlqDZ4BNA/myEPqZPoF4gi8SzVXGkj7 CDz909TFTj8JJM0fDzHocRVx86B1gVL6AZmC4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671586; x=1732276386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ptbAWv8IG3SuQFQX+roZZIviyToXBTNl2Q3I+8WN9Ug=; b=AUZjqQWRiolp3pCjgbm50vXW0rGXG/M76lgLNoUZz2Ccm61EGWqrMmCROlW72UrGsv whlrCRwJXs/r8PYpk/Uvdo0U2hnRamIorFt0+4uuM75Ku7Ej2/qiFN7ss20a5mOVog/A a/1iBdg7KMY+r3DUHgNoIpS+sEs+lMaLLENYDvK97Bs7DfflqPlfyPWlZtlmGfzf+M7U 9jVSbt/oCxG+JWkMZHOD9wKKMbA/Rptta5cNzAKBpVFxI07ONHaJ912C15vIUQX76Jcf 4A4uIQsQyKw1A+txgbn2WLXPjMhl6AIRGKXfOLu0kKNS7nB/7yJTe7mJ0K93T88jNUFv Gg7Q== X-Gm-Message-State: AOJu0Yxan113BOVmW7xHjVmjZUbQ5DndxGF6KqAcZZxhP0xSfIQYscql Q8nVxtY4vWK0PAMKy3QuBYDZXcGdHV1ujlUlzy8DBkSHnanH7D33mIBXMpM4+S0mBQVKHBJfGLU b X-Google-Smtp-Source: AGHT+IGs3y1VylX4ofg5+Jz93V/2UMvPpjfx2K5HgMK8nCx+jEuXZKRamTimND23HKB2YnFYWIl/kw== X-Received: by 2002:a17:907:1c85:b0:a9e:d7e3:cced with SMTP id a640c23a62f3a-aa48352767dmr198068066b.45.1731671585853; Fri, 15 Nov 2024 03:53:05 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson Subject: [RFC PATCH 11/25] tools/xenbindgen: Validate ABI rules at generation time Date: Fri, 15 Nov 2024 11:51:40 +0000 Message-ID: <20241115115200.2824-12-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/rust/xenbindgen/src/main.rs | 8 + tools/rust/xenbindgen/src/spec.rs | 357 ++++++++++++++++++++++++++++-- 2 files changed, 341 insertions(+), 24 deletions(-) diff --git a/tools/rust/xenbindgen/src/main.rs b/tools/rust/xenbindgen/src/main.rs index 00abf5ed7f33..dbc610e420f2 100644 --- a/tools/rust/xenbindgen/src/main.rs +++ b/tools/rust/xenbindgen/src/main.rs @@ -55,6 +55,14 @@ fn main() { error!("{x:#?}"); std::process::exit(1); } + Err(spec::Error::BadAbi(x)) => { + error!("Broken ABI rule: {x}"); + std::process::exit(1); + } + Err(spec::Error::MissingDefinition(x)) => { + error!("Missing include: {x}"); + std::process::exit(1); + } }; let (extension, parser): (&str, fn(&OutFileDef) -> String) = match cli.lang { diff --git a/tools/rust/xenbindgen/src/spec.rs b/tools/rust/xenbindgen/src/spec.rs index 04be05187ac8..919f3206c1f6 100644 --- a/tools/rust/xenbindgen/src/spec.rs +++ b/tools/rust/xenbindgen/src/spec.rs @@ -13,7 +13,7 @@ //! to properly decode the type and match it with a variant of the [`Typ`] type //! with the payload landing in the payload of the variant itself. -use std::{fs::read_to_string, path::Path}; +use std::{cmp::max, fs::read_to_string, path::Path}; use log::{debug, info}; @@ -25,7 +25,7 @@ use log::{debug, info}; /// TOML files. Ideally, that representation should be more ergonomic and the /// parser instructed to deal with it. #[allow(clippy::missing_docs_in_private_items)] -#[derive(Debug, serde::Deserialize, PartialEq)] +#[derive(Clone, Debug, serde::Deserialize, PartialEq)] #[serde(rename_all = "lowercase", tag = "tag", content = "args")] pub enum Typ { Bitmap(String), @@ -43,8 +43,120 @@ pub enum Typ { Array(Box, usize), } +impl Typ { + /// Returns the size of this type in octets. The specification must be + /// passed on the side so the function can look-up subordinate types. + /// + /// # Errors + /// `Err` on type lookup failure (e.g: enum doesn't exist). + pub fn size(&self, spec: &Spec) -> Result { + match self { + Typ::U8 | Typ::I8 => Ok(1), + Typ::U16 | Typ::I16 => Ok(2), + Typ::U32 | Typ::I32 => Ok(4), + Typ::U64 | Typ::I64 | Typ::Ptr(_) => Ok(8), + Typ::Enum(s) => spec.find_enum(s)?.typ.size(spec), + Typ::Bitmap(s) => spec.find_bitmap(s)?.typ.size(spec), + Typ::Struct(s) => { + // The size of a struct is the sum of the sizes of its subfields + // as long as it's packed, and that is mandated by the ABI. + let mut size = 0; + for f in &spec.find_struct(s)?.fields { + size += f.typ.size(spec)?; + } + Ok(size) + } + Typ::Array(t, n) => Ok(n * t.size(spec)?), + } + } + + /// Returns the alignment of this type in octets. The specification must + /// be passed on the side so the function can look-up subordinate types. + /// + /// # Errors + /// `Err` on type lookup failure (e.g: enum doesn't exist). + pub fn alignment(&self, spec: &Spec) -> Result { + match self { + Typ::U8 | Typ::I8 => Ok(1), + Typ::U16 | Typ::I16 => Ok(2), + Typ::U32 | Typ::I32 => Ok(4), + Typ::U64 | Typ::I64 | Typ::Ptr(_) => Ok(8), + Typ::Enum(s) => spec.find_enum(s)?.typ.alignment(spec), + Typ::Bitmap(s) => spec.find_bitmap(s)?.typ.alignment(spec), + Typ::Struct(s) => { + // The alignment of a struct is as large as its largest field + let mut alignment = 1; + for f in &spec.find_struct(s)?.fields { + alignment = max(alignment, f.typ.alignment(spec)?); + } + Ok(alignment) + } + Typ::Array(t, _) => t.alignment(spec), + } + } + + /// `Ok` iff the type is {i,u}{8,16,32,64}. + pub fn is_primitive(&self) -> Result<(), Error> { + match self { + Typ::U8 | Typ::I8 | Typ::U16 | Typ::I16 | Typ::U32 | Typ::I32 | Typ::U64 | Typ::I64 => { + Ok(()) + } + _ => Err(Error::BadAbi(format!("{self:?} while expecting primitive"))), + } + } + + /// `Ok` iff the type respects all ABI rules. Note that for a spec to + /// satisfy the ABI restrictions _all_ types must satisfy them. + pub fn abi_compatible(&self, spec: &Spec) -> Result<(), Error> { + match self { + // Unconditionally ok. They have fixed size with equal alignment + Typ::U8 + | Typ::I8 + | Typ::U16 + | Typ::I16 + | Typ::U32 + | Typ::I32 + | Typ::U64 + | Typ::I64 + | Typ::Ptr(_) => Ok(()), + + // Ok as long as their backing type is itself primitive + Typ::Enum(s) => spec.find_enum(s)?.typ.is_primitive(), + Typ::Bitmap(s) => spec.find_bitmap(s)?.typ.is_primitive(), + + // Every field must be compatible and there can be no padding + Typ::Struct(s) => { + let def = spec.find_struct(s)?; + let mut offset = 0; + + for f in &def.fields { + f.typ.abi_compatible(spec)?; + + if offset & (f.typ.alignment(spec)? - 1) != 0 { + return Err(Error::BadAbi(format!( + "implicit padding in struct {s}, before {}", + f.name + ))); + } + + offset += f.typ.size(spec)?; + } + + if offset & (self.alignment(spec)? - 1) != 0 { + return Err(Error::BadAbi(format!( + "implicit padding in struct {s} at the tail", + ))); + } + + Ok(()) + } + Typ::Array(t, _) => t.abi_compatible(spec), + } + } +} + /// Deserialized form of a hypercall struct -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct StructDef { /// Name of the struct pub name: String, @@ -57,7 +169,7 @@ pub struct StructDef { } /// Deserialized form of a field within a hypercall struct (see [`StructDef`]) -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct FieldDef { /// Name of the field pub name: String, @@ -69,7 +181,7 @@ pub struct FieldDef { } /// Description of a lang-agnostic enumerated type. -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct EnumDef { /// snake-cased name of this enumeration. /// @@ -90,7 +202,7 @@ pub struct EnumDef { } /// Lang-agnostic description of a bitmap type. -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct BitmapDef { /// Snake-cased name of this bitmap. /// @@ -109,7 +221,7 @@ pub struct BitmapDef { } /// Lang-agnostic description of a single bit within a particular bitmap type. -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct BitDef { /// Snake-cased name of this bit. Depending on the backend, the name /// might be prefixed by the name of its type (as is commonly done in C). @@ -122,7 +234,7 @@ pub struct BitDef { } /// Lang-agnostic description of a single variant of an enumerated type. -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct VariantDef { /// Snake-cased name of this variant. Depending on the backend, the name /// might be prefixed by the name of its type (as is commonly done in C). @@ -138,7 +250,7 @@ pub struct VariantDef { /// /// Used in specifications to state a number of types (described in `imports`) /// is needed from another generated file (the `from` field). -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] pub struct IncludeDef { /// Name of the [`InFileDef`] that contains the imported tokens of /// `imports`. @@ -148,7 +260,7 @@ pub struct IncludeDef { } /// A language-agnostic specification. -#[derive(Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize)] struct InFileDef { /// List of types described in other [`InFileDef`] that are required here. includes: Option>, @@ -163,7 +275,7 @@ struct InFileDef { /// Description of an abstract output (i.e: `.rs`, `.h`, etc). /// /// Contains every element of the ABI that needs representing. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct OutFileDef { /// The name of the output file, without the final extension. pub name: String, @@ -206,18 +318,18 @@ impl OutFileDef { let path = from_ioerr(entry)?.path(); debug!("Reading {:?} to generate outfile={}", path, ret.name); let toml_str = from_ioerr(read_to_string(path))?; - let filedef: InFileDef = toml::from_str(&toml_str).map_err(Error::Toml)?; - if let Some(structs) = filedef.structs { - ret.structs.extend(structs); + let infiledef: InFileDef = toml::from_str(&toml_str).map_err(Error::Toml)?; + if let Some(x) = infiledef.structs { + ret.structs.extend(x); } - if let Some(enums) = filedef.enums { - ret.enums.extend(enums); + if let Some(x) = infiledef.enums { + ret.enums.extend(x); } - if let Some(bitmaps) = filedef.bitmaps { - ret.bitmaps.extend(bitmaps); + if let Some(x) = infiledef.bitmaps { + ret.bitmaps.extend(x); } - if let Some(includes) = filedef.includes { - ret.includes.extend(includes); + if let Some(x) = infiledef.includes { + ret.includes.extend(x); } } @@ -228,10 +340,14 @@ impl OutFileDef { /// Internal error type for every error spec parsing could encounter #[derive(Debug)] pub enum Error { - /// Wrapper around IO errors + /// IO errors (e.g: opening files, etc) Io(std::io::Error), - /// Wrapper around deserialization errors + /// Deserialization errors (i.e: from malformed specifications) Toml(toml::de::Error), + /// Failed ABI consistency checks + BadAbi(String), + /// Failed definition lookups (typically typos) + MissingDefinition(String), } /// Maps an [`std::io::Error`] onto a [`Error`] type for easier propagation @@ -242,7 +358,7 @@ fn from_ioerr(t: std::io::Result) -> Result { /// Object containing the abstract definitions of all output files. /// /// See [`OutFileDef`] to details on the specification contents of each output. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Spec(pub Vec); impl Spec { @@ -255,7 +371,7 @@ impl Spec { pub fn new(root: &Path) -> Result { info!("Reading {root:?} as top-level directory"); - let mut ret = Self(Vec::new()); + let mut ret: Spec = Self::default(); for outfile in from_ioerr(root.read_dir())? { // Each folder in the root defines a single output file let outfile = from_ioerr(outfile)?; @@ -263,6 +379,199 @@ impl Spec { ret.0.push(OutFileDef::new(name, &outfile.path())?); } + for arch in &[ret.x86(), ret.arm(), ret.riscv(), ret.ppc()] { + arch.is_valid()?; + } + Ok(ret) } + + /// Checks names are not duplicated. Some languages might not support type namespaces + /// so and it simplifies type lookup in [`Spec::abi_is_compliant`]. + fn has_unique_names(&self) -> Result<(), Error> { + let mut all_names = Vec::::new(); + + for outfile in &self.0 { + all_names.extend(outfile.structs.iter().map(|e| e.name.clone())); + all_names.extend(outfile.enums.iter().map(|e| e.name.clone())); + all_names.extend(outfile.bitmaps.iter().map(|e| e.name.clone())); + } + + if all_names.is_empty() { + return Err(Error::BadAbi("Empty spec".to_string())); + } + + let mut dedupped = all_names.clone(); + dedupped.sort(); + dedupped.dedup(); + + if dedupped.len() != all_names.len() { + // There's duplicates. Be nice and point out which + let mut dup = all_names.last().unwrap(); + for (i, name) in dedupped.iter().enumerate() { + if all_names[i] != *name { + dup = name; + break; + } + } + + return Err(Error::BadAbi(format!("Duplicate identifier: {dup}"))); + } + + Ok(()) + } + + /// Enforce restrictions to guarantee ABI sanity + /// + /// 1. ABI must be identical in 32 and 64 bits. + /// 2. For every type, alignment must match size. + /// 3. Structs must have no implicit padding, not even at the tail. + /// 4. All type names are distinct. + fn is_valid(&self) -> Result<(), Error> { + info!("Validating specification"); + + self.has_unique_names()?; + for def in &self.0 { + for s in &def.structs { + debug!("Validating struct {}", s.name); + Typ::Struct(s.name.to_string()).abi_compatible(self)?; + } + } + + Ok(()) + } + + /// Duplicates a specification; Leaves out arch-specific definitions. + /// + /// This has the effect of deduplicating the fields used polymorphically + /// across arch-specific code (e.g: See `xen_arch_domainconfig` in the spec) + fn common(&self) -> Self { + let mut ret = Self::default(); + + for def in &self.0 { + if !def.name.starts_with("arch-") { + ret.0.push(def.clone()); + } + } + + ret + } + + /// Duplicates a specification; Leaves out non-x86 architectures. + /// + /// This has the effect of deduplicating the fields used polymorphically + /// across arch-specific code (e.g: See `xen_arch_domainconfig` in the spec) + pub fn x86(&self) -> Self { + let mut ret = self.common(); + + if let Some(x) = self.0.iter().find(|x| x.name == "arch-x86") { + let mut def = x.clone(); + def.name = String::from("arch"); + ret.0.push(def); + } + + ret + } + + /// Duplicates a specification; Leaves out non-ARM architectures. + /// + /// This has the effect of deduplicating the fields used polymorphically + /// across arch-specific code (e.g: See `xen_arch_domainconfig` in the spec) + pub fn arm(&self) -> Spec { + let mut ret = self.common(); + + if let Some(x) = self.0.iter().find(|x| x.name == "arch-arm") { + let mut def = x.clone(); + def.name = String::from("arch"); + ret.0.push(def); + } + + ret + } + + /// Duplicates a specification; Leaves out non-PowerPC architectures. + /// + /// This has the effect of deduplicating the fields used polymorphically + /// across arch-specific code (e.g: See `xen_arch_domainconfig` in the spec) + pub fn ppc(&self) -> Spec { + let mut ret = self.common(); + + if let Some(x) = self.0.iter().find(|x| x.name == "arch-ppc") { + let mut def = x.clone(); + def.name = String::from("arch"); + ret.0.push(def); + } + + ret + } + + /// Duplicates a specification; Leaves out non-RiscV architectures. + /// + /// This has the effect of deduplicating the fields used polymorphically + /// across arch-specific code (e.g: See `xen_arch_domainconfig` in the spec) + pub fn riscv(&self) -> Spec { + let mut ret = self.common(); + + if let Some(x) = self.0.iter().find(|x| x.name == "arch-riscv") { + let mut def = x.clone(); + def.name = String::from("arch"); + ret.0.push(def); + } + + ret + } + + /// Find a struct with a particular name within a [`Spec`] definition. + /// + /// Assumes a flat namespace, so there are no two types with the same + /// name. This is ensured with [`Spec::has_unique_names`]. + pub fn find_struct(&self, name: &str) -> Result<&StructDef, Error> { + debug!("Looking up struct {name}"); + + for filedef in &self.0 { + for s in &filedef.structs { + if s.name == name { + return Ok(s); + } + } + } + + Err(Error::MissingDefinition(format!("missing struct {name}"))) + } + + /// Find an enum with a particular name within a [`Spec`] definition. + /// + /// Assumes a flat namespace, so there are no two types with the same + /// name. This is ensured with [`Spec::has_unique_names`]. + pub fn find_enum(&self, name: &str) -> Result<&EnumDef, Error> { + debug!("Looking up enum {name}"); + + for filedef in &self.0 { + for s in &filedef.enums { + if s.name == name { + return Ok(s); + } + } + } + + Err(Error::MissingDefinition(format!("missing enum {name}"))) + } + + /// Find a bitmap with a particular name within a [`Spec`] definition. + /// + /// Assumes a flat namespace, so there are no two types with the same + /// name. This is ensured with [`Spec::has_unique_names`]. + pub fn find_bitmap(&self, name: &str) -> Result<&BitmapDef, Error> { + debug!("Looking up bitmap {name}"); + + for filedef in &self.0 { + for s in &filedef.bitmaps { + if s.name == name { + return Ok(s); + } + } + } + + Err(Error::MissingDefinition(format!("missing enum {name}"))) + } } From patchwork Fri Nov 15 11:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5FDB0D6DDED for ; Fri, 15 Nov 2024 11:53:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837179.1253192 (Exim 4.92) (envelope-from ) id 1tBusy-0008C8-Ny; Fri, 15 Nov 2024 11:53:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837179.1253192; Fri, 15 Nov 2024 11:53:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusy-00088T-2y; Fri, 15 Nov 2024 11:53:12 +0000 Received: by outflank-mailman (input) for mailman id 837179; Fri, 15 Nov 2024 11:53:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBusw-0005UF-FV for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:10 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2e019b8d-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:07 +0100 (CET) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-aa3a79d4d59so270568166b.3 for ; Fri, 15 Nov 2024 03:53:07 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:06 -0800 (PST) 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: 2e019b8d-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzEiLCJoZWxvIjoibWFpbC1lajEteDYzMS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJlMDE5YjhkLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTg3LjgyNjk2Niwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671587; x=1732276387; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YTgBp3u8P0cZs4GoU1pcL/XsrDo/t/R26kaPSnnnZ/I=; b=QRqOoqN6TNL+Uqykknt2PjpKKFg5G58/0oc5nPD2EgH2xErwrkK9Zyl1u5lCqfAe2D Mlr4NJMbpgYgyjN31lM7VRaG5yJiD3RD1Z2wra45GqTaDpQWV6MUBC2WPIiYKpslR92k JQXsr69ftEppoxpw1KN7kDae+AxhZZ720EtPk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671587; x=1732276387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YTgBp3u8P0cZs4GoU1pcL/XsrDo/t/R26kaPSnnnZ/I=; b=LIaGNOyH5MYmTD4Zjyyv1VVnQT7DOpLJcdwrmoFcT0edHRTQ22H2vwx0Z3p6whNgxI +Sh2pVRb55RequwHFt+VKFYdGk0vmgV9fKsOo2LdDRgePSy78HxXvMV+coMeGEedpBhq bVo6goWe2/A+x3Tz6sqVFyTYMghLhMXyPKxWmQaYhFBsWk7linAgCEduPAx1vqK8lGCa qhRFMmLrnCxSbGGkelK+KnpYwwvYXA+H1VqO93dLkHsJRQr9m/ggJUuO/scCVL0LOVOp WaldrSw2umsgnNY/pm+SXdcBCWJvpThPLzplSdqCIRCrgGKMomS6puiZu96jz0HbxL7D 9FOg== X-Gm-Message-State: AOJu0Yy3ipifTA0l5LfgAAPt3zyg11V4NR1sq7aS32sVU6b4q0+2HPnp lQw37hrf/++g0p1m5ygc3ykvicYw3GZ4kMp37qTaUYZwvze7eHJT54xLwbC7ah1VUSt8piSn7fY 3 X-Google-Smtp-Source: AGHT+IGGf7chMiYoWULTA+4FqsplpwjC0gZstVC0KtP0DCVj+5C9GYogkSgo5Czrly1ZKHbWy2xagw== X-Received: by 2002:a17:907:3d86:b0:a9f:508:5924 with SMTP id a640c23a62f3a-aa483525ef4mr207071166b.43.1731671586933; Fri, 15 Nov 2024 03:53:06 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Samuel Thibault , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , "Daniel P. Smith" Subject: [RFC PATCH 12/25] xen: Replace sysctl/readconsole with autogenerated version Date: Fri, 15 Nov 2024 11:51:41 +0000 Message-ID: <20241115115200.2824-13-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Describe sysctl/readconsole as a TOML specification, remove old hand-coded version and replace it with autogenerated file. While at it, transform the console driver to use uint8_t rather than char in order to mandate the type to be unsigned and ensure the ABI is not defined with regards to C-specific types. Also grant stubdom access to the new autogen folder, or it won't build. Signed-off-by: Alejandro Vallejo --- stubdom/Makefile | 2 +- tools/rust/Makefile | 19 ++++++++ .../xenbindgen/extra/sysctl/readconsole.toml | 43 +++++++++++++++++++ xen/drivers/char/console.c | 12 +++--- xen/include/public/autogen/sysctl.h | 35 +++++++++++++++ xen/include/public/sysctl.h | 23 +--------- xen/include/public/xen.h | 1 + 7 files changed, 108 insertions(+), 27 deletions(-) create mode 100644 tools/rust/xenbindgen/extra/sysctl/readconsole.toml create mode 100644 xen/include/public/autogen/sysctl.h diff --git a/stubdom/Makefile b/stubdom/Makefile index 2a81af28a16e..5e919889836b 100644 --- a/stubdom/Makefile +++ b/stubdom/Makefile @@ -362,7 +362,7 @@ LINK_STAMPS := $(foreach dir,$(LINK_DIRS),$(dir)/stamp) mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) $(LINK_STAMPS) mkdir -p include/xen && \ ln -sf $(wildcard $(XEN_ROOT)/xen/include/public/*.h) include/xen && \ - ln -sf $(addprefix $(XEN_ROOT)/xen/include/public/,arch-x86 hvm io xsm) include/xen && \ + ln -sf $(addprefix $(XEN_ROOT)/xen/include/public/,arch-x86 autogen hvm io xsm) include/xen && \ ( [ -h include/xen/sys ] || ln -sf $(XEN_ROOT)/tools/include/xen-sys/MiniOS include/xen/sys ) && \ ( [ -h include/xen/libelf ] || ln -sf $(XEN_ROOT)/tools/include/xen/libelf include/xen/libelf ) && \ mkdir -p include/xen-foreign && \ diff --git a/tools/rust/Makefile b/tools/rust/Makefile index f5db0a9c5e81..80e2f0e2817e 100644 --- a/tools/rust/Makefile +++ b/tools/rust/Makefile @@ -3,6 +3,11 @@ XEN_ROOT=$(CURDIR)/../.. # Path to the Xen hypercall IDL parser XENBINDGEN=$(CURDIR)/xenbindgen +# Output folder for the autogenerated C headers +# +# Must contain autogenerated files only because they're all wiped on update +AUTOGEN_C=$(XEN_ROOT)/xen/include/public/autogen/ + # Clippy settings for all Rust projects CLIPPY_ARGS=-D warnings \ -D missing_docs \ @@ -14,6 +19,20 @@ CLIPPY_ARGS=-D warnings \ .PHONY: all install uninstall clean all install uninstall clean: +# Remove all autogenerated files +.PHONY: clean-autogen +clean-autogen: + rm -rf "${AUTOGEN_C}" + +# Refresh autogenerated files. Depending on clean-autogen is required in order +# for removals of specification files to cause the removal of their +# autogenerated files. +.PHONY: update +update: clean-autogen + # Update C bindings + cargo run --manifest-path "${XENBINDGEN}/Cargo.toml" -- --lang c \ + --indir "${XENBINDGEN}/extra" --outdir "${AUTOGEN_C}" + # Verify Rust crates pass lint checks. This is enforced in CI .PHONY: verify verify: diff --git a/tools/rust/xenbindgen/extra/sysctl/readconsole.toml b/tools/rust/xenbindgen/extra/sysctl/readconsole.toml new file mode 100644 index 000000000000..868743a453ff --- /dev/null +++ b/tools/rust/xenbindgen/extra/sysctl/readconsole.toml @@ -0,0 +1,43 @@ +[[structs]] +name = "xen_sysctl_readconsole" +description = "Read console content from Xen buffer ring." + +[[structs.fields]] +name = "clear" +description = "IN: Non-zero -> clear after reading." +typ = { tag = "u8" } + +[[structs.fields]] +name = "incremental" +description = "IN: Non-zero -> start index specified by `index` field." +typ = { tag = "u8" } + +[[structs.fields]] +name = "_pad" +description = "Unused." +typ = { tag = "u16" } + +[[structs.fields]] +name = "index" +description = """ +IN: Start index for consuming from ring buffer (if @incremental); +OUT: End index after consuming from ring buffer.""" +typ = { tag = "u32" } + +[[structs.fields]] +name = "buffer" +description = """ +IN: Virtual address to write console data. + +NOTE: The pointer itself is IN, but the contents of the buffer are OUT.""" +typ = { tag = "ptr", args = { tag = "u8" } } + +[[structs.fields]] +name = "count" +description = "IN: Size of buffer; OUT: Bytes written to buffer." +typ = { tag = "u32" } + +[[structs.fields]] +name = "rsvd0_a" +description = "Tail padding reserved to zero." +typ = { tag = "u32" } diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 7da8c5296f3b..82f6ad7b32cb 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -42,6 +42,8 @@ #include #endif +#include + /* console: comma-separated list of console outputs. */ static char __initdata opt_console[30] = OPT_CONSOLE_STR; string_param("console", opt_console); @@ -108,8 +110,8 @@ size_param("conring_size", opt_conring_size); #define _CONRING_SIZE 16384 #define CONRING_IDX_MASK(i) ((i)&(conring_size-1)) -static char __initdata _conring[_CONRING_SIZE]; -static char *__read_mostly conring = _conring; +static uint8_t __initdata _conring[_CONRING_SIZE]; +static uint8_t *__read_mostly conring = _conring; static uint32_t __read_mostly conring_size = _CONRING_SIZE; static uint32_t conringc, conringp; @@ -339,10 +341,10 @@ static void conring_puts(const char *str, size_t len) long read_console_ring(struct xen_sysctl_readconsole *op) { - XEN_GUEST_HANDLE_PARAM(char) str; + XEN_GUEST_HANDLE_PARAM(uint8_t) str; uint32_t idx, len, max, sofar, c, p; - str = guest_handle_cast(op->buffer, char), + str = guest_handle_cast(op->buffer, uint8_t), max = op->count; sofar = 0; @@ -1052,7 +1054,7 @@ void __init console_init_preirq(void) void __init console_init_ring(void) { - char *ring; + uint8_t *ring; unsigned int i, order, memflags; unsigned long flags; diff --git a/xen/include/public/autogen/sysctl.h b/xen/include/public/autogen/sysctl.h new file mode 100644 index 000000000000..f728b13374d3 --- /dev/null +++ b/xen/include/public/autogen/sysctl.h @@ -0,0 +1,35 @@ +/* + * sysctl + * + * AUTOGENERATED. DO NOT MODIFY + */ +#ifndef __XEN_AUTOGEN_SYSCTL_H +#define __XEN_AUTOGEN_SYSCTL_H + +/* Read console content from Xen buffer ring. */ +struct xen_sysctl_readconsole { + /* IN: Non-zero -> clear after reading. */ + uint8_t clear; + /* IN: Non-zero -> start index specified by `index` field. */ + uint8_t incremental; + /* Unused. */ + uint16_t _pad; + /* + * IN: Start index for consuming from ring buffer (if @incremental); + * OUT: End index after consuming from ring buffer. + */ + uint32_t index; + /* + * IN: Virtual address to write console data. + * + * NOTE: The pointer itself is IN, but the contents of the buffer are OUT. + */ + XEN_GUEST_HANDLE_64(uint8) buffer; + /* IN: Size of buffer; OUT: Bytes written to buffer. */ + uint32_t count; + /* Tail padding reserved to zero. */ + uint32_t rsvd0_a; +}; + +#endif /* __XEN_AUTOGEN_SYSCTL_H */ + diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index b0fec271d36f..9e773490a5ac 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -18,6 +18,8 @@ #include "domctl.h" #include "physdev.h" +#include "autogen/sysctl.h" + /* * The interface version needs to be incremented by 1 in case the interface * is modified in an incompatible way AND if the version hasn't been @@ -30,27 +32,6 @@ */ #define XEN_SYSCTL_INTERFACE_VERSION 0x00000015 -/* - * Read console content from Xen buffer ring. - */ -/* XEN_SYSCTL_readconsole */ -struct xen_sysctl_readconsole { - /* IN: Non-zero -> clear after reading. */ - uint8_t clear; - /* IN: Non-zero -> start index specified by @index field. */ - uint8_t incremental; - uint8_t pad0, pad1; - /* - * IN: Start index for consuming from ring buffer (if @incremental); - * OUT: End index after consuming from ring buffer. - */ - uint32_t index; - /* IN: Virtual address to write console data. */ - XEN_GUEST_HANDLE_64(char) buffer; - /* IN: Size of buffer; OUT: Bytes written to buffer. */ - uint32_t count; -}; - /* Get trace buffers machine base address */ /* XEN_SYSCTL_tbuf_op */ struct xen_sysctl_tbuf_op { diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index e051f989a5ca..cc5133fc19b8 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -36,6 +36,7 @@ __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long); #endif DEFINE_XEN_GUEST_HANDLE(void); +DEFINE_XEN_GUEST_HANDLE(uint8_t); DEFINE_XEN_GUEST_HANDLE(uint64_t); DEFINE_XEN_GUEST_HANDLE(xen_pfn_t); DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); From patchwork Fri Nov 15 11:51:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 785E8D6DDF3 for ; Fri, 15 Nov 2024 11:53:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837181.1253210 (Exim 4.92) (envelope-from ) id 1tBut2-0000g1-9F; Fri, 15 Nov 2024 11:53:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837181.1253210; Fri, 15 Nov 2024 11:53:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut1-0000eC-WA; Fri, 15 Nov 2024 11:53:16 +0000 Received: by outflank-mailman (input) for mailman id 837181; Fri, 15 Nov 2024 11:53:13 +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 1tBusy-0005U9-St for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:12 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2efe3c0a-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:09 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a9a68480164so223660666b.3 for ; Fri, 15 Nov 2024 03:53:09 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:08 -0800 (PST) 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: 2efe3c0a-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzQiLCJoZWxvIjoibWFpbC1lajEteDYzNC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJlZmUzYzBhLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTg5LjUwMTUyMiwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671588; x=1732276388; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GrIHjPwvtOnEhff76Ju8/6PKjtLppyVwNCD/uVKVYE8=; b=fKOsiw+rO5IC6+bPaugvZJ5qJVCnT+LEps7fKjVr/aDb1QF4bYb9ymhf07rRgpbrNJ 0n3q6kk8NqxKb3nx/0M/6tJatp8+L5UOGI4JK3XQNKZJjOYEvZF2sl4SsA0WAk8j5gxR kHUK2yUshZYV1h1goSi6CKrBPzU/j0JeIsKXo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671588; x=1732276388; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GrIHjPwvtOnEhff76Ju8/6PKjtLppyVwNCD/uVKVYE8=; b=cyEB+QFj0YvuHLCqP/ATiOcXZ4p9KSUWUugE3Co3UAAbC12lCfezZCSFFR5ritSutj 2DKXVieK5+sIYljHF7YBzqhxEZQTufj8ns9GaBC1CznOcaDnP2UCp/IY9s9EmxdbWf7O skzJwdZNz7Up61J0QPFdBupaD3S8zvatTFiVH4njs91ovrmIYSU/AKojC39bH3fvcpYy xdYMOMbrhxIOB7voUJTWHVVd4dK4xCZdGcwjFidEgnGTRXRx9sKukRXHKr3QoaKDQR6b 9qtnFbfOUhDlAJJqlvWx+QOQyomJz2gFjc2z5dKyaA7U7vFDbo/coVpQGfWZrFT1t1cz WIqg== X-Gm-Message-State: AOJu0YwFpW1hSjf9bHPGpi/fFPS3sgJHQsj25wpbGLnWfc0qILHxhPm8 h5+UhNJ/ZWQIHDWSqj6cimGrW5iGYCz0HcuHQzo+FiI7ngcDLT+4r2qXtkPElSqnoxcMqXlir69 U X-Google-Smtp-Source: AGHT+IEX15jlu4tYQg3JcLosn63SAFy8FOsWQhMW7RzMOpxh14W+k1b5IUPSYiyNyuPeP2WSUad3HA== X-Received: by 2002:a17:907:2dac:b0:a9a:ad8:fc56 with SMTP id a640c23a62f3a-aa483529cb4mr212134566b.44.1731671588564; Fri, 15 Nov 2024 03:53:08 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Juergen Gross , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , "Daniel P. Smith" Subject: [RFC PATCH 13/25] xen: Replace hand-crafted altp2m_mode descriptions with autogenerated ones Date: Fri, 15 Nov 2024 11:51:42 +0000 Message-ID: <20241115115200.2824-14-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/libs/light/libxl_create.c | 8 +++---- .../xenbindgen/extra/domctl/createdomain.toml | 24 +++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 8 +++---- xen/include/public/autogen/domctl.h | 22 +++++++++++++++++ xen/include/public/domctl.h | 18 +++----------- 5 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 tools/rust/xenbindgen/extra/domctl/createdomain.toml create mode 100644 xen/include/public/autogen/domctl.h diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index 3ae922e8931b..791b0fac0601 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -676,19 +676,19 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, LOG(DETAIL, "altp2m: %s", libxl_altp2m_mode_to_string(b_info->altp2m)); switch(b_info->altp2m) { case LIBXL_ALTP2M_MODE_MIXED: - create.altp2m_mode = XEN_DOMCTL_ALTP2M_mixed; + create.altp2m_mode = XEN_DOMCTL_ALTP2M_MODE_MIXED; break; case LIBXL_ALTP2M_MODE_EXTERNAL: - create.altp2m_mode = XEN_DOMCTL_ALTP2M_external; + create.altp2m_mode = XEN_DOMCTL_ALTP2M_MODE_EXTERNAL; break; case LIBXL_ALTP2M_MODE_LIMITED: - create.altp2m_mode = XEN_DOMCTL_ALTP2M_limited; + create.altp2m_mode = XEN_DOMCTL_ALTP2M_MODE_LIMITED; break; case LIBXL_ALTP2M_MODE_DISABLED: - create.altp2m_mode = XEN_DOMCTL_ALTP2M_disabled; + create.altp2m_mode = XEN_DOMCTL_ALTP2M_MODE_DISABLED; break; } diff --git a/tools/rust/xenbindgen/extra/domctl/createdomain.toml b/tools/rust/xenbindgen/extra/domctl/createdomain.toml new file mode 100644 index 000000000000..097dc202f352 --- /dev/null +++ b/tools/rust/xenbindgen/extra/domctl/createdomain.toml @@ -0,0 +1,24 @@ +[[enums]] +name = "xen_domctl_altp2m_mode" +description = "Content of the `altp2m_mode` field of the domain creation hypercall." +typ = { tag = "u8" } + +[[enums.variants]] +name = "disabled" +description = "Keep altp2m disabled" +value = 0 + +[[enums.variants]] +name = "mixed" +description = "Use mixed-mode for the altp2m (not yet evaluated for safety)." +value = 1 + +[[enums.variants]] +name = "external" +description = "Use external mode for the altp2m." +value = 2 + +[[enums.variants]] +name = "limited" +description = "Use limited mode for the altp2m." +value = 3 diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index e30c3026479e..35caf6131190 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -661,19 +661,19 @@ int hvm_domain_initialise(struct domain *d, /* Set altp2m based on domctl flags. */ switch ( config->altp2m_mode ) { - case XEN_DOMCTL_ALTP2M_mixed: + case XEN_DOMCTL_ALTP2M_MODE_MIXED: d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_mixed; break; - case XEN_DOMCTL_ALTP2M_external: + case XEN_DOMCTL_ALTP2M_MODE_EXTERNAL: d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_external; break; - case XEN_DOMCTL_ALTP2M_limited: + case XEN_DOMCTL_ALTP2M_MODE_LIMITED: d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_limited; break; - case XEN_DOMCTL_ALTP2M_disabled: + case XEN_DOMCTL_ALTP2M_MODE_DISABLED: d->arch.hvm.params[HVM_PARAM_ALTP2M] = XEN_ALTP2M_disabled; break; } diff --git a/xen/include/public/autogen/domctl.h b/xen/include/public/autogen/domctl.h new file mode 100644 index 000000000000..00202f5e65b9 --- /dev/null +++ b/xen/include/public/autogen/domctl.h @@ -0,0 +1,22 @@ +/* + * domctl + * + * AUTOGENERATED. DO NOT MODIFY + */ +#ifndef __XEN_AUTOGEN_DOMCTL_H +#define __XEN_AUTOGEN_DOMCTL_H + +/* Content of the `altp2m_mode` field of the domain creation hypercall. */ +enum xen_domctl_altp2m_mode { + /* Keep altp2m disabled */ + XEN_DOMCTL_ALTP2M_MODE_DISABLED = 0, + /* Use mixed-mode for the altp2m (not yet evaluated for safety). */ + XEN_DOMCTL_ALTP2M_MODE_MIXED = 1, + /* Use external mode for the altp2m. */ + XEN_DOMCTL_ALTP2M_MODE_EXTERNAL = 2, + /* Use limited mode for the altp2m. */ + XEN_DOMCTL_ALTP2M_MODE_LIMITED = 3, +}; + +#endif /* __XEN_AUTOGEN_DOMCTL_H */ + diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 95a3b6769f7f..95d62c859302 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -21,6 +21,8 @@ #include "hvm/save.h" #include "memory.h" +#include "autogen/domctl.h" + /* * The interface version needs to be incremented by 1 in case the interface * is modified in an incompatible way AND if the version hasn't been @@ -103,21 +105,7 @@ struct xen_domctl_createdomain { /* Unused. Reserved to zero. */ uint8_t rsvd0_a[3]; -/* Keep altp2m disabled */ -#define XEN_DOMCTL_ALTP2M_disabled (0U) -/* - * Enable altp2m mixed mode. - * - * Note that 'mixed' mode has not been evaluated for safety from a security - * perspective. Before using this mode in a security-critical environment, - * each subop should be evaluated for safety, with unsafe subops blacklisted in - * XSM. - */ -#define XEN_DOMCTL_ALTP2M_mixed (1U) -/* Enable altp2m external mode. */ -#define XEN_DOMCTL_ALTP2M_external (2U) -/* Enable altp2m limited mode. */ -#define XEN_DOMCTL_ALTP2M_limited (3U) + /* See xen_domctl_altp2m_mode */ uint8_t altp2m_mode; /* Unused. Reserved to zero. */ From patchwork Fri Nov 15 11:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75EFBD6DDF2 for ; Fri, 15 Nov 2024 11:53:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837183.1253223 (Exim 4.92) (envelope-from ) id 1tBut4-00011v-Dt; Fri, 15 Nov 2024 11:53:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837183.1253223; Fri, 15 Nov 2024 11:53:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut3-0000xm-Q9; Fri, 15 Nov 2024 11:53:17 +0000 Received: by outflank-mailman (input) for mailman id 837183; Fri, 15 Nov 2024 11:53:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut1-0005UF-8P for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:15 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2fe136ee-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:10 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5c9693dc739so2408723a12.3 for ; Fri, 15 Nov 2024 03:53:10 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:09 -0800 (PST) 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: 2fe136ee-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmQiLCJoZWxvIjoibWFpbC1lZDEteDUyZC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJmZTEzNmVlLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTkxLjAxNjU3Niwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671590; x=1732276390; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+rE1VyD3E57vOSpzTtqjmMt2x6hf09RI8sZ6fi//89E=; b=FqfVi9STgeP0izdPg3fN7cnsozxkHlwJqZm7cTk4GbtEvtyFImwKUv75PBHRZ4ryOW eYB4uYSR8ny5ECeDK8geZZK3Ik9D+P/k8y9azu116mKyyn756LSADRVTsBr1twEOVsa6 5dhIheA8pWtbiu/uFfL76iAQnFDYT/ZMHZ3lY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671590; x=1732276390; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+rE1VyD3E57vOSpzTtqjmMt2x6hf09RI8sZ6fi//89E=; b=PTusEy5zvdAlyT4aRntoA9hdoDorbdzsjiXRAQ51wI7RPIJ6tqcrCAD0Tm4zRSwypp wvI2SHGbQNzg2dmVN4NMf2TJZ8kKSygg/B+GpUK6PK9wEJdGADruyXBWyeRcvT1LObm9 bpPwhrdhSoubjNN/7rkbwwwTrW2JQjkKOu7th1YQhqKDvc78UzLIPt3MzOE2hycT6mfl WruMtSGCQ4TkbuP6RIJ3BB0p9YFLxtHDyK1iPSGerFcN9H0IXPrrCwmXg8tz9gjqW1z6 rFvv/vISqC3t3S/mE5QKJVLkIp87Lz0Xev7XmZpbA67ojgU2/4UXkjp7kk0eAsNtg1a8 6faw== X-Gm-Message-State: AOJu0YwGS/+ugbLfY7Re4c9Okqr/vXDa4YBxqBPpsJzmvTfRkz4BY6Ce r8jok0CACxPvCPL87DZlQMm6EBc/bKF/EhhZ0QAL1MWjed2XqOZMKwtZ+zR7A34TttQw/cw0qoG 7 X-Google-Smtp-Source: AGHT+IEDY0K0AAGiSnjgrcf0bfnRY/vNG5r7/IRULMB5XGUWNKgKilEXyQPOXdFkiFI2g9bSWgs9ZQ== X-Received: by 2002:a17:907:7b86:b0:a99:d6cf:a1df with SMTP id a640c23a62f3a-aa483525e0bmr175996766b.46.1731671589858; Fri, 15 Nov 2024 03:53:09 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Juergen Gross , Julien Grall , Anthony PERARD , Andrew Cooper , Jan Beulich , Stefano Stabellini , Christian Lindig , David Scott , =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Tim Deegan , Lukasz Hawrylko , "Daniel P. Smith" , =?utf-8?q?Mateusz_M=C3=B3?= =?utf-8?q?wka?= Subject: [RFC PATCH 14/25] xen: Replace common bitmaps in domctl.createdomain with autogenerated versions Date: Fri, 15 Nov 2024 11:51:43 +0000 Message-ID: <20241115115200.2824-15-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/helpers/init-xenstore-domain.c | 4 +- tools/libs/light/libxl_create.c | 14 ++--- tools/ocaml/libs/xc/xenctrl.ml | 4 +- tools/ocaml/libs/xc/xenctrl.mli | 4 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 8 +-- tools/python/xen/lowlevel/xc/xc.c | 4 +- .../xenbindgen/extra/domctl/createdomain.toml | 59 +++++++++++++++++++ .../paging-mempool/test-paging-mempool.c | 2 +- tools/tests/resource/test-resource.c | 8 +-- tools/tests/tsx/test-tsx.c | 4 +- xen/arch/arm/dom0less-build.c | 4 +- xen/arch/arm/domain.c | 6 +- xen/arch/arm/domain_build.c | 4 +- xen/arch/x86/domain.c | 12 ++-- xen/arch/x86/include/asm/hvm/nestedhvm.h | 2 +- xen/arch/x86/mm/shadow/common.c | 4 +- xen/arch/x86/setup.c | 8 +-- xen/arch/x86/tboot.c | 2 +- xen/common/domain.c | 18 +++--- xen/drivers/passthrough/iommu.c | 4 +- xen/include/public/autogen/domctl.h | 28 +++++++++ xen/include/public/domctl.h | 34 +---------- xen/include/xen/sched.h | 10 ++-- 23 files changed, 152 insertions(+), 95 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index a9f2f9859df6..315aa8b8aec9 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -84,7 +84,7 @@ static int build(xc_interface *xch) struct e820entry e820[3]; struct xen_domctl_createdomain config = { .ssidref = SECINITSID_DOMU, - .flags = XEN_DOMCTL_CDF_xs_domain, + .flags = XEN_DOMCTL_CDF_XS_DOMAIN, .max_vcpus = 1, .max_evtchn_port = -1, /* No limit. */ @@ -176,7 +176,7 @@ static int build(xc_interface *xch) if ( dom->container_type == XC_DOM_HVM_CONTAINER ) { - config.flags |= XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap; + config.flags |= XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP; config.arch.emulation_flags = XEN_X86_EMU_LAPIC; dom->target_pages = mem_size >> XC_PAGE_SHIFT; dom->mmio_size = GB(4) - LAPIC_BASE_ADDRESS; diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index 791b0fac0601..042d01191528 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -648,30 +648,30 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, }; if (info->type != LIBXL_DOMAIN_TYPE_PV) { - create.flags |= XEN_DOMCTL_CDF_hvm; + create.flags |= XEN_DOMCTL_CDF_HVM; if ( libxl_defbool_val(info->hap) ) - create.flags |= XEN_DOMCTL_CDF_hap; + create.flags |= XEN_DOMCTL_CDF_HAP; if ( !libxl_defbool_val(info->oos) ) - create.flags |= XEN_DOMCTL_CDF_oos_off; + create.flags |= XEN_DOMCTL_CDF_OOS_OFF; if ( libxl_defbool_val(b_info->nested_hvm) ) - create.flags |= XEN_DOMCTL_CDF_nested_virt; + create.flags |= XEN_DOMCTL_CDF_NESTED_VIRT; } if (libxl_defbool_val(b_info->vpmu)) - create.flags |= XEN_DOMCTL_CDF_vpmu; + create.flags |= XEN_DOMCTL_CDF_VPMU; assert(info->passthrough != LIBXL_PASSTHROUGH_DEFAULT); LOG(DETAIL, "passthrough: %s", libxl_passthrough_to_string(info->passthrough)); if (info->passthrough != LIBXL_PASSTHROUGH_DISABLED) - create.flags |= XEN_DOMCTL_CDF_iommu; + create.flags |= XEN_DOMCTL_CDF_IOMMU; if (info->passthrough == LIBXL_PASSTHROUGH_SYNC_PT) - create.iommu_opts |= XEN_DOMCTL_IOMMU_no_sharept; + create.iommu_opts |= XEN_DOMCTL_IOMMU_OPTS_NO_SHAREPT; LOG(DETAIL, "altp2m: %s", libxl_altp2m_mode_to_string(b_info->altp2m)); switch(b_info->altp2m) { diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 3c4c95d48319..17c2228704f2 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -49,7 +49,7 @@ type x86_arch_emulation_flags = | X86_EMU_VPCI type x86_arch_misc_flags = - | X86_MSR_RELAXED + | X86_MISC_MSR_RELAXED type xen_x86_arch_domainconfig = { @@ -72,7 +72,7 @@ type domain_create_flag = | CDF_VPMU type domain_create_iommu_opts = - | IOMMU_NO_SHAREPT + | IOMMU_OPTS_NO_SHAREPT type domctl_create_config = { diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli index 74919a14bec4..0d351ec2e557 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -43,7 +43,7 @@ type x86_arch_emulation_flags = | X86_EMU_VPCI type x86_arch_misc_flags = - | X86_MSR_RELAXED + | X86_MISC_MSR_RELAXED type xen_x86_arch_domainconfig = { emulation_flags: x86_arch_emulation_flags list; @@ -65,7 +65,7 @@ type domain_create_flag = | CDF_VPMU type domain_create_iommu_opts = - | IOMMU_NO_SHAREPT + | IOMMU_OPTS_NO_SHAREPT type domctl_create_config = { ssidref: int32; diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c index b701f45daa8d..1f2cf41a9cc7 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -232,13 +232,13 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE)); cfg.flags = ocaml_list_to_c_bitmap - /* ! domain_create_flag CDF_ lc */ - /* ! XEN_DOMCTL_CDF_ XEN_DOMCTL_CDF_MAX max */ + /* ! domain_create_flag CDF_ none */ + /* ! XEN_DOMCTL_CDF_ XEN_DOMCTL_CDF__ALL all */ (VAL_FLAGS); cfg.iommu_opts = ocaml_list_to_c_bitmap - /* ! domain_create_iommu_opts IOMMU_ lc */ - /* ! XEN_DOMCTL_IOMMU_ XEN_DOMCTL_IOMMU_MAX max */ + /* ! domain_create_iommu_opts IOMMU_ none */ + /* ! XEN_DOMCTL_IOMMU_ XEN_DOMCTL_IOMMU_OPTS__ALL all */ (VAL_IOMMU_OPTS); arch_domconfig = Field(VAL_ARCH, 0); diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index ba6a61217f9f..d98f18ccc87a 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -158,8 +158,8 @@ static PyObject *pyxc_domain_create(XcObject *self, } #if defined (__i386) || defined(__x86_64__) - if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags = XEN_X86_EMU_ALL & + if ( config.flags & XEN_DOMCTL_CDF_HVM ) + config.arch.emulation_flags = XEN_X86_EMU__ALL & ~(XEN_X86_EMU_VPCI | XEN_X86_EMU_USE_PIRQ); #elif defined (__arm__) || defined(__aarch64__) diff --git a/tools/rust/xenbindgen/extra/domctl/createdomain.toml b/tools/rust/xenbindgen/extra/domctl/createdomain.toml index 097dc202f352..02f65d134b55 100644 --- a/tools/rust/xenbindgen/extra/domctl/createdomain.toml +++ b/tools/rust/xenbindgen/extra/domctl/createdomain.toml @@ -22,3 +22,62 @@ value = 2 name = "limited" description = "Use limited mode for the altp2m." value = 3 + +################################################################################ + +[[bitmaps]] +name = "xen_domctl_cdf" +description = "Content of the `flags` field of the domain creation hypercall." +typ = { tag = "u32" } + +[[bitmaps.bits]] +name = "hvm" +description = "Set if this is an HVM guest. Cleared if it's PV." +shift = 0 + +[[bitmaps.bits]] +name = "hap" +description = "Use hardware-assisted paging if available" +shift = 1 + +[[bitmaps.bits]] +name = "s3_integrity" +description = "Set if domain memory integrity is to be verified by tboot during Sx." +shift = 2 + +[[bitmaps.bits]] +name = "oos_off" +description = "Set if Out-of-Sync shadow page tables are to be disabled" +shift = 3 + +[[bitmaps.bits]] +name = "xs_domain" +description = "Set if this is a xenstore domain" +shift = 4 + +[[bitmaps.bits]] +name = "iommu" +description = "Set if this is domain can make use of the IOMMU" +shift = 5 + +[[bitmaps.bits]] +name = "nested_virt" +description = "Set for the domain to have nested virtualization enabled." +shift = 6 + +[[bitmaps.bits]] +name = "vpmu" +description = "Set to expose a vPMU to this domain." +shift = 7 + +################################################################################ + +[[bitmaps]] +name = "xen_domctl_iommu_opts" +description = "Content of the `iommu_opts` field of the domain creation hypercall." +typ = { tag = "u32" } + +[[bitmaps.bits]] +name = "no_sharept" +description = "Set to _NOT_ share page tables between the CPU and the IOMMU when it would be possible to do so." +shift = 0 diff --git a/tools/tests/paging-mempool/test-paging-mempool.c b/tools/tests/paging-mempool/test-paging-mempool.c index 512c42803c0e..511c4a710e1f 100644 --- a/tools/tests/paging-mempool/test-paging-mempool.c +++ b/tools/tests/paging-mempool/test-paging-mempool.c @@ -21,7 +21,7 @@ static xc_interface *xch; static uint32_t domid; static struct xen_domctl_createdomain create = { - .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, + .flags = XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP, .max_vcpus = 1, .max_grant_frames = 1, .max_grant_version = 1, diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/test-resource.c index b0a9f5f1e8b6..f541044036d9 100644 --- a/tools/tests/resource/test-resource.c +++ b/tools/tests/resource/test-resource.c @@ -143,7 +143,7 @@ static void test_domain_configurations(void) { .name = "x86 PVH", .create = { - .flags = XEN_DOMCTL_CDF_hvm, + .flags = XEN_DOMCTL_CDF_HVM, .max_vcpus = 2, .max_grant_frames = 40, .max_grant_version = 1, @@ -156,7 +156,7 @@ static void test_domain_configurations(void) { .name = "ARM", .create = { - .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, + .flags = XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP, .max_vcpus = 2, .max_grant_frames = 40, .max_grant_version = 1, @@ -175,7 +175,7 @@ static void test_domain_configurations(void) printf("Test %s\n", t->name); #if defined(__x86_64__) || defined(__i386__) - if ( t->create.flags & XEN_DOMCTL_CDF_hvm ) + if ( t->create.flags & XEN_DOMCTL_CDF_HVM ) { if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm) ) { @@ -188,7 +188,7 @@ static void test_domain_configurations(void) * SHADOW is available. */ if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap ) - t->create.flags |= XEN_DOMCTL_CDF_hap; + t->create.flags |= XEN_DOMCTL_CDF_HAP; else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) ) { printf(" Skip: Neither HAP or SHADOW available\n"); diff --git a/tools/tests/tsx/test-tsx.c b/tools/tests/tsx/test-tsx.c index 324bcf67153a..a3097515b280 100644 --- a/tools/tests/tsx/test-tsx.c +++ b/tools/tests/tsx/test-tsx.c @@ -467,7 +467,7 @@ static void test_guests(void) if ( xen_has_hvm ) { struct xen_domctl_createdomain c = { - .flags = XEN_DOMCTL_CDF_hvm, + .flags = XEN_DOMCTL_CDF_HVM, .max_vcpus = 1, .max_grant_frames = 1, .max_grant_version = 1, @@ -477,7 +477,7 @@ static void test_guests(void) }; if ( physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap ) - c.flags |= XEN_DOMCTL_CDF_hap; + c.flags |= XEN_DOMCTL_CDF_HAP; else if ( !(physinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow) ) return fail(" HVM available, but neither HAP nor Shadow\n"); diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 1c6219c7cc82..cd8e59aa762a 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -867,7 +867,7 @@ void __init create_domUs(void) struct domain *d; struct xen_domctl_createdomain d_cfg = { .arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE, - .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, + .flags = XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP, /* * The default of 1023 should be sufficient for guests because * on ARM we don't bind physical interrupts to event channels. @@ -912,7 +912,7 @@ void __init create_domUs(void) if ( iommu_enabled && (iommu || dt_find_compatible_node(node, NULL, "multiboot,device-tree")) ) - d_cfg.flags |= XEN_DOMCTL_CDF_iommu; + d_cfg.flags |= XEN_DOMCTL_CDF_IOMMU; if ( !dt_property_read_u32(node, "nr_spis", &d_cfg.arch.nr_spis) ) { diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index c6c5a0d1af23..54e849b02f9e 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -567,7 +567,7 @@ int arch_vcpu_create(struct vcpu *v) v->arch.hcr_el2 = get_default_hcr_flags(); v->arch.mdcr_el2 = HDCR_TDRA | HDCR_TDOSA | HDCR_TDA; - if ( !(v->domain->options & XEN_DOMCTL_CDF_vpmu) ) + if ( !(v->domain->options & XEN_DOMCTL_CDF_VPMU) ) v->arch.mdcr_el2 |= HDCR_TPM | HDCR_TPMCR; if ( (rc = vcpu_vgic_init(v)) != 0 ) @@ -607,8 +607,8 @@ void vcpu_switch_to_aarch64_mode(struct vcpu *v) int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) { unsigned int max_vcpus; - unsigned int flags_required = (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap); - unsigned int flags_optional = (XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpmu); + unsigned int flags_required = (XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP); + unsigned int flags_optional = (XEN_DOMCTL_CDF_IOMMU | XEN_DOMCTL_CDF_VPMU); unsigned int sve_vl_bits = sve_decode_vl(config->arch.sve_vl); if ( (config->flags & ~flags_optional) != flags_required ) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 773412ba2acb..08b251617bae 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2190,7 +2190,7 @@ void __init create_dom0(void) { struct domain *dom0; struct xen_domctl_createdomain dom0_cfg = { - .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, + .flags = XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP, .max_evtchn_port = -1, .max_grant_frames = gnttab_dom0_frames(), .max_maptrack_frames = -1, @@ -2211,7 +2211,7 @@ void __init create_dom0(void) dom0_cfg.max_vcpus = dom0_max_vcpus(); if ( iommu_enabled ) - dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; + dom0_cfg.flags |= XEN_DOMCTL_CDF_IOMMU; if ( opt_dom0_sve ) { diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 1ef095f349f7..63a52a8ae23d 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -633,9 +633,9 @@ void arch_vcpu_destroy(struct vcpu *v) int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) { - bool hvm = config->flags & XEN_DOMCTL_CDF_hvm; - bool hap = config->flags & XEN_DOMCTL_CDF_hap; - bool nested_virt = config->flags & XEN_DOMCTL_CDF_nested_virt; + bool hvm = config->flags & XEN_DOMCTL_CDF_HVM; + bool hap = config->flags & XEN_DOMCTL_CDF_HAP; + bool nested_virt = config->flags & XEN_DOMCTL_CDF_NESTED_VIRT; unsigned int max_vcpus; if ( hvm ? !hvm_enabled : !IS_ENABLED(CONFIG_PV) ) @@ -654,7 +654,7 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) } if ( !IS_ENABLED(CONFIG_TBOOT) && - (config->flags & XEN_DOMCTL_CDF_s3_integrity) ) + (config->flags & XEN_DOMCTL_CDF_S3_INTEGRITY) ) { dprintk(XENLOG_INFO, "S3 integrity check not valid without CONFIG_TBOOT\n"); return -EINVAL; @@ -668,10 +668,10 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) if ( !hvm ) /* - * It is only meaningful for XEN_DOMCTL_CDF_oos_off to be clear + * It is only meaningful for XEN_DOMCTL_CDF_OOS_OFF to be clear * for HVM guests. */ - config->flags |= XEN_DOMCTL_CDF_oos_off; + config->flags |= XEN_DOMCTL_CDF_OOS_OFF; if ( nested_virt && !hvm_nested_virt_supported() ) { diff --git a/xen/arch/x86/include/asm/hvm/nestedhvm.h b/xen/arch/x86/include/asm/hvm/nestedhvm.h index ea2c1bc328c7..64e9e18a8cfd 100644 --- a/xen/arch/x86/include/asm/hvm/nestedhvm.h +++ b/xen/arch/x86/include/asm/hvm/nestedhvm.h @@ -25,7 +25,7 @@ enum nestedhvm_vmexits { /* Nested HVM on/off per domain */ static inline bool nestedhvm_enabled(const struct domain *d) { - return IS_ENABLED(CONFIG_HVM) && (d->options & XEN_DOMCTL_CDF_nested_virt); + return IS_ENABLED(CONFIG_HVM) && (d->options & XEN_DOMCTL_CDF_NESTED_VIRT); } /* Nested VCPU */ diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c index 0176e33bc9c7..f103f19e9220 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -2344,7 +2344,7 @@ static void sh_update_paging_modes(struct vcpu *v) #endif /* (SHADOW_OPTIMIZATIONS & SHOPT_VIRTUAL_TLB) */ #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) - if ( !(d->options & XEN_DOMCTL_CDF_oos_off) && + if ( !(d->options & XEN_DOMCTL_CDF_OOS_OFF) && mfn_eq(v->arch.paging.shadow.oos_snapshot[0], INVALID_MFN) ) { int i; @@ -2491,7 +2491,7 @@ static void sh_update_paging_modes(struct vcpu *v) #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) /* We need to check that all the vcpus have paging enabled to * unsync PTs. */ - if ( !(d->options & XEN_DOMCTL_CDF_oos_off) ) + if ( !(d->options & XEN_DOMCTL_CDF_OOS_OFF) ) { int pe = 1; struct vcpu *vptr; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 0443555d9bb8..65ea3fc86beb 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -960,7 +960,7 @@ static struct domain *__init create_dom0(const module_t *image, static char __initdata cmdline[MAX_GUEST_CMDLINE]; struct xen_domctl_createdomain dom0_cfg = { - .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0, + .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_S3_INTEGRITY : 0, .max_evtchn_port = -1, .max_grant_frames = -1, .max_maptrack_frames = -1, @@ -975,16 +975,16 @@ static struct domain *__init create_dom0(const module_t *image, if ( opt_dom0_pvh ) { - dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm | + dom0_cfg.flags |= (XEN_DOMCTL_CDF_HVM | ((hvm_hap_supported() && !opt_dom0_shadow) ? - XEN_DOMCTL_CDF_hap : 0)); + XEN_DOMCTL_CDF_HAP : 0)); dom0_cfg.arch.emulation_flags |= XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; } if ( iommu_enabled ) - dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; + dom0_cfg.flags |= XEN_DOMCTL_CDF_IOMMU; /* Create initial domain. Not d0 for pvshim. */ domid = get_initial_domain_id(); diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index d5db60d335e3..648a5269bb8a 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -203,7 +203,7 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE], vmac_set_key((uint8_t *)key, &ctx); for_each_domain( d ) { - if ( !(d->options & XEN_DOMCTL_CDF_s3_integrity) ) + if ( !(d->options & XEN_DOMCTL_CDF_S3_INTEGRITY) ) continue; printk("MACing Domain %u\n", d->domain_id); diff --git a/xen/common/domain.c b/xen/common/domain.c index ad19ff1cef23..799f76bf042d 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -564,16 +564,16 @@ static void _domain_destroy(struct domain *d) static int sanitise_domain_config(struct xen_domctl_createdomain *config) { - bool hvm = config->flags & XEN_DOMCTL_CDF_hvm; - bool hap = config->flags & XEN_DOMCTL_CDF_hap; - bool iommu = config->flags & XEN_DOMCTL_CDF_iommu; - bool vpmu = config->flags & XEN_DOMCTL_CDF_vpmu; + bool hvm = config->flags & XEN_DOMCTL_CDF_HVM; + bool hap = config->flags & XEN_DOMCTL_CDF_HAP; + bool iommu = config->flags & XEN_DOMCTL_CDF_IOMMU; + bool vpmu = config->flags & XEN_DOMCTL_CDF_VPMU; if ( config->flags & - ~(XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap | - XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off | - XEN_DOMCTL_CDF_xs_domain | XEN_DOMCTL_CDF_iommu | - XEN_DOMCTL_CDF_nested_virt | XEN_DOMCTL_CDF_vpmu) ) + ~(XEN_DOMCTL_CDF_HVM | XEN_DOMCTL_CDF_HAP | + XEN_DOMCTL_CDF_S3_INTEGRITY | XEN_DOMCTL_CDF_OOS_OFF | + XEN_DOMCTL_CDF_XS_DOMAIN | XEN_DOMCTL_CDF_IOMMU | + XEN_DOMCTL_CDF_NESTED_VIRT | XEN_DOMCTL_CDF_VPMU) ) { dprintk(XENLOG_INFO, "Unknown CDF flags %#x\n", config->flags); return -EINVAL; @@ -600,7 +600,7 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config) if ( iommu ) { - if ( config->iommu_opts & ~XEN_DOMCTL_IOMMU_no_sharept ) + if ( config->iommu_opts & ~XEN_DOMCTL_IOMMU_OPTS_NO_SHAREPT ) { dprintk(XENLOG_INFO, "Unknown IOMMU options %#x\n", config->iommu_opts); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 9e74a1fc72fa..1d133e56c0bb 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -224,7 +224,7 @@ int iommu_domain_init(struct domain *d, unsigned int opts) * be enabled. */ hd->hap_pt_share = hap_enabled(d) && iommu_hap_pt_share && - !(opts & XEN_DOMCTL_IOMMU_no_sharept); + !(opts & XEN_DOMCTL_IOMMU_OPTS_NO_SHAREPT); /* * NB: 'relaxed' h/w domains don't need the IOMMU mappings to be kept @@ -542,7 +542,7 @@ int iommu_quarantine_dev_init(device_t *dev) static int __init iommu_quarantine_init(void) { - dom_io->options |= XEN_DOMCTL_CDF_iommu; + dom_io->options |= XEN_DOMCTL_CDF_IOMMU; return iommu_domain_init(dom_io, 0); } diff --git a/xen/include/public/autogen/domctl.h b/xen/include/public/autogen/domctl.h index 00202f5e65b9..bd1f4bedc727 100644 --- a/xen/include/public/autogen/domctl.h +++ b/xen/include/public/autogen/domctl.h @@ -18,5 +18,33 @@ enum xen_domctl_altp2m_mode { XEN_DOMCTL_ALTP2M_MODE_LIMITED = 3, }; +/* Content of the `flags` field of the domain creation hypercall. */ +struct xen_domctl_cdf {}; /* GREP FODDER */ +/* Set if this is an HVM guest. Cleared if it's PV. */ +#define XEN_DOMCTL_CDF_HVM (1U << 0) +/* Use hardware-assisted paging if available */ +#define XEN_DOMCTL_CDF_HAP (1U << 1) +/* Set if domain memory integrity is to be verified by tboot during Sx. */ +#define XEN_DOMCTL_CDF_S3_INTEGRITY (1U << 2) +/* Set if Out-of-Sync shadow page tables are to be disabled */ +#define XEN_DOMCTL_CDF_OOS_OFF (1U << 3) +/* Set if this is a xenstore domain */ +#define XEN_DOMCTL_CDF_XS_DOMAIN (1U << 4) +/* Set if this is domain can make use of the IOMMU */ +#define XEN_DOMCTL_CDF_IOMMU (1U << 5) +/* Set for the domain to have nested virtualization enabled. */ +#define XEN_DOMCTL_CDF_NESTED_VIRT (1U << 6) +/* Set to expose a vPMU to this domain. */ +#define XEN_DOMCTL_CDF_VPMU (1U << 7) +/* Mask covering all defined bits */ +#define XEN_DOMCTL_CDF__ALL (0xFFU) + +/* Content of the `iommu_opts` field of the domain creation hypercall. */ +struct xen_domctl_iommu_opts {}; /* GREP FODDER */ +/* Set to _NOT_ share page tables between the CPU and the IOMMU when it would be possible to do so. */ +#define XEN_DOMCTL_IOMMU_OPTS_NO_SHAREPT (1U << 0) +/* Mask covering all defined bits */ +#define XEN_DOMCTL_IOMMU_OPTS__ALL (0x1U) + #endif /* __XEN_AUTOGEN_DOMCTL_H */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 95d62c859302..2d1423f6fd91 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -45,40 +45,10 @@ struct xen_domctl_createdomain { /* IN parameters */ uint32_t ssidref; xen_domain_handle_t handle; - /* Is this an HVM guest (as opposed to a PV guest)? */ -#define _XEN_DOMCTL_CDF_hvm 0 -#define XEN_DOMCTL_CDF_hvm (1U<<_XEN_DOMCTL_CDF_hvm) - /* Use hardware-assisted paging if available? */ -#define _XEN_DOMCTL_CDF_hap 1 -#define XEN_DOMCTL_CDF_hap (1U<<_XEN_DOMCTL_CDF_hap) - /* Should domain memory integrity be verifed by tboot during Sx? */ -#define _XEN_DOMCTL_CDF_s3_integrity 2 -#define XEN_DOMCTL_CDF_s3_integrity (1U<<_XEN_DOMCTL_CDF_s3_integrity) - /* Disable out-of-sync shadow page tables? */ -#define _XEN_DOMCTL_CDF_oos_off 3 -#define XEN_DOMCTL_CDF_oos_off (1U<<_XEN_DOMCTL_CDF_oos_off) - /* Is this a xenstore domain? */ -#define _XEN_DOMCTL_CDF_xs_domain 4 -#define XEN_DOMCTL_CDF_xs_domain (1U<<_XEN_DOMCTL_CDF_xs_domain) - /* Should this domain be permitted to use the IOMMU? */ -#define _XEN_DOMCTL_CDF_iommu 5 -#define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu) -#define _XEN_DOMCTL_CDF_nested_virt 6 -#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) -/* Should we expose the vPMU to the guest? */ -#define XEN_DOMCTL_CDF_vpmu (1U << 7) - -/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_vpmu + /* See xen_domctl_cdf */ uint32_t flags; - -#define _XEN_DOMCTL_IOMMU_no_sharept 0 -#define XEN_DOMCTL_IOMMU_no_sharept (1U << _XEN_DOMCTL_IOMMU_no_sharept) - -/* Max XEN_DOMCTL_IOMMU_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_IOMMU_MAX XEN_DOMCTL_IOMMU_no_sharept - + /* See xen_domctl_iommu_opts */ uint32_t iommu_opts; /* diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 90666576c2f8..1b75277e5dea 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1125,7 +1125,7 @@ static always_inline bool is_control_domain(const struct domain *d) static always_inline bool is_pv_domain(const struct domain *d) { return IS_ENABLED(CONFIG_PV) && - evaluate_nospec(!(d->options & XEN_DOMCTL_CDF_hvm)); + evaluate_nospec(!(d->options & XEN_DOMCTL_CDF_HVM)); } static always_inline bool is_pv_vcpu(const struct vcpu *v) @@ -1167,7 +1167,7 @@ static always_inline bool is_pv_64bit_vcpu(const struct vcpu *v) static always_inline bool is_hvm_domain(const struct domain *d) { return IS_ENABLED(CONFIG_HVM) && - evaluate_nospec(d->options & XEN_DOMCTL_CDF_hvm); + evaluate_nospec(d->options & XEN_DOMCTL_CDF_HVM); } static always_inline bool is_hvm_vcpu(const struct vcpu *v) @@ -1179,7 +1179,7 @@ static always_inline bool hap_enabled(const struct domain *d) { /* sanitise_domain_config() rejects HAP && !HVM */ return IS_ENABLED(CONFIG_HVM) && - evaluate_nospec(d->options & XEN_DOMCTL_CDF_hap); + evaluate_nospec(d->options & XEN_DOMCTL_CDF_HAP); } static inline bool is_hwdom_pinned_vcpu(const struct vcpu *v) @@ -1195,12 +1195,12 @@ static inline bool is_vcpu_online(const struct vcpu *v) static inline bool is_xenstore_domain(const struct domain *d) { - return d->options & XEN_DOMCTL_CDF_xs_domain; + return d->options & XEN_DOMCTL_CDF_XS_DOMAIN; } static always_inline bool is_iommu_enabled(const struct domain *d) { - return evaluate_nospec(d->options & XEN_DOMCTL_CDF_iommu); + return evaluate_nospec(d->options & XEN_DOMCTL_CDF_IOMMU); } extern bool sched_smt_power_savings; From patchwork Fri Nov 15 11:51:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16005D6DDED for ; Fri, 15 Nov 2024 11:53:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837182.1253216 (Exim 4.92) (envelope-from ) id 1tBut3-0000lJ-75; Fri, 15 Nov 2024 11:53:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837182.1253216; Fri, 15 Nov 2024 11:53:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut2-0000jo-Jv; Fri, 15 Nov 2024 11:53:16 +0000 Received: by outflank-mailman (input) for mailman id 837182; Fri, 15 Nov 2024 11:53:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut0-0005UF-8K for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:14 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 30624d4c-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:11 +0100 (CET) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a9ed7d8d4e0so232688266b.1 for ; Fri, 15 Nov 2024 03:53:11 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:10 -0800 (PST) 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: 30624d4c-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzEiLCJoZWxvIjoibWFpbC1lajEteDYzMS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMwNjI0ZDRjLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTkxLjgwNDQ0Miwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671591; x=1732276391; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u2zCTEiiXdj6Z3fAz2PaM6R8L2pJvU1ho+YloSy4GWA=; b=YjbT0SMrx1qS6W+aM/WTWoJZ37H91fqbfVc3DD7wlrpOQE1xEx+y3DpXOzlAIHrB/0 /v8F7Vh5B7rIDnWS84cxZ4gHanWR6N5CAMeVfODbu9cvElV3CqVD/lTzfSOOGO4T+GTv UYyhXja6Cx50WkGj5cb2j9FcucaF6OIhT+2t0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671591; x=1732276391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u2zCTEiiXdj6Z3fAz2PaM6R8L2pJvU1ho+YloSy4GWA=; b=jOeEaE1KrhhgcKs4pECz/gDrVAwHXv+RFvsJbIio2c9B7IwMvKpNKehidi0pTNEEiz a1kVp8bD7bzLKZyhyvkFtK0eg+SUYZDf5jXs2ziCWyY7vTMt504cZ6iDaflzSKuO58P3 sWdKFzrjxqVL8vC97KWj9uCxO/hMvJbgWXgrMZWqdIeX2klyYawV51ltEN+4qvtV3+cc Ids7Mcak8uB8APLIte089n2Ar4wG0BqWo0GWjpNlwF3b0lqKAlJRpp3rv+xLcm43lJCv 1daN/Tkls3GlAg2s5msuoYo2LbQJC3zWrzdZPvy0nVEL4xb5opGcyo0trPjfbEUrhlbT srVw== X-Gm-Message-State: AOJu0Yx/PdKuTl4aX+t3i+Y0zGhRMBoKu5bS433nBOerc2oLAQxGsNK7 gU+iECwNzQ5/awtaLc3hwSVBUf3lu1Me+k9sPwzfsQcHwJO1FO85v/hXQAWQvdHzY6EXCPajuAj M X-Google-Smtp-Source: AGHT+IFupWoJxTg3mKC40rRRwGbsyM1HfRvOK5bnNBOwLcjXdsu/PUy6Jjq+KT54hxdALNM3LBR32Q== X-Received: by 2002:a17:906:daca:b0:a99:88ab:c7cb with SMTP id a640c23a62f3a-aa48347e0fbmr151752766b.33.1731671590923; Fri, 15 Nov 2024 03:53:10 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [RFC PATCH 15/25] xen/arm: Replace hand-crafted xen_arch_domainconfig with autogenerated one Date: Fri, 15 Nov 2024 11:51:44 +0000 Message-ID: <20241115115200.2824-16-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- .../extra/arch-arm/domainconfig.toml | 83 +++++++++++++++++++ xen/arch/arm/domain.c | 4 +- xen/arch/arm/tee/tee.c | 1 + xen/include/public/arch-arm.h | 36 -------- xen/include/public/autogen/arch_arm.h | 59 +++++++++++++ 5 files changed, 145 insertions(+), 38 deletions(-) create mode 100644 tools/rust/xenbindgen/extra/arch-arm/domainconfig.toml create mode 100644 xen/include/public/autogen/arch_arm.h diff --git a/tools/rust/xenbindgen/extra/arch-arm/domainconfig.toml b/tools/rust/xenbindgen/extra/arch-arm/domainconfig.toml new file mode 100644 index 000000000000..d32963445765 --- /dev/null +++ b/tools/rust/xenbindgen/extra/arch-arm/domainconfig.toml @@ -0,0 +1,83 @@ +[[enums]] +name = "xen_domctl_config_gic" +description = "Content of the `gic_version` field of the domainconfig struct." +typ = { tag = "u8" } + +[[enums.variants]] +name = "native" +description = "Emulate the underlying GIC present in the current host." +value = 0 + +[[enums.variants]] +name = "v2" +description = "Emulate a GICv2." +value = 1 + +[[enums.variants]] +name = "v3" +description = "Emulate a GICv3." +value = 2 + +################################################################################ + +[[enums]] +name = "xen_domctl_config_tee" +description = "TEE mediator exposed to the guest" +typ = { tag = "u16" } + +[[enums.variants]] +name = "none" +description = "No mediator. Guest can't communicate with the TEE." +value = 0 + +[[enums.variants]] +name = "optee" +description = "Expose an OP-TEE mediator." +value = 1 + +[[enums.variants]] +name = "ffa" +description = "Expose an FF-A mediator." +value = 2 + +################################################################################ + +[[structs]] +name = "xen_arch_domainconfig" +description = "arm-specific domain settings." + +[[structs.fields]] +name = "gic_version" +description = """IN/OUT: GIC version exposed to the guest. + +When `native` on input the output value holds the automatically chosen version.""" +typ = { tag = "enum", args = "xen_domctl_config_gic" } + +[[structs.fields]] +name = "sve_vl" +description = "IN: SVE vector length (divided by 128) exposed to the guest." +typ = { tag = "u8" } + +[[structs.fields]] +name = "tee_type" +description = "IN: TEE mediator exposed to the guest." +typ = { tag = "enum", args = "xen_domctl_config_tee" } + +[[structs.fields]] +name = "nr_spis" +description = "IN: Number of SPIs exposed to the guest." +typ = { tag = "u32" } + +[[structs.fields]] +name = "clock_frequency" +description = """OUT +Based on the property clock-frequency in the DT timer node. +The property may be present when the bootloader/firmware doesn't +set correctly CNTFRQ which hold the timer frequency. + +As it's not possible to trap this register, we have to replicate +the value in the guest DT. + += 0 => property not present +> 0 => Value of the property""" +typ = { tag = "u32" } diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 54e849b02f9e..57ed11598754 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -639,10 +639,10 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) } /* The P2M table must always be shared between the CPU and the IOMMU */ - if ( config->iommu_opts & XEN_DOMCTL_IOMMU_no_sharept ) + if ( config->iommu_opts & XEN_DOMCTL_IOMMU_OPTS_NO_SHAREPT ) { dprintk(XENLOG_INFO, - "Unsupported iommu option: XEN_DOMCTL_IOMMU_no_sharept\n"); + "Unsupported iommu option: XEN_DOMCTL_IOMMU_OPTS_NO_SHAREPT\n"); return -EINVAL; } diff --git a/xen/arch/arm/tee/tee.c b/xen/arch/arm/tee/tee.c index 3f65e45a7892..c5f7629a227a 100644 --- a/xen/arch/arm/tee/tee.c +++ b/xen/arch/arm/tee/tee.c @@ -21,6 +21,7 @@ #include #include +#include extern const struct tee_mediator_desc _steemediator[], _eteemediator[]; static const struct tee_mediator_desc __read_mostly *cur_mediator; diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index e2412a17474e..42ce9e64ed00 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -315,42 +315,6 @@ struct vcpu_guest_context { typedef struct vcpu_guest_context vcpu_guest_context_t; DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); -/* - * struct xen_arch_domainconfig's ABI is covered by - * XEN_DOMCTL_INTERFACE_VERSION. - */ -#define XEN_DOMCTL_CONFIG_GIC_NATIVE 0 -#define XEN_DOMCTL_CONFIG_GIC_V2 1 -#define XEN_DOMCTL_CONFIG_GIC_V3 2 - -#define XEN_DOMCTL_CONFIG_TEE_NONE 0 -#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1 -#define XEN_DOMCTL_CONFIG_TEE_FFA 2 - -struct xen_arch_domainconfig { - /* IN/OUT */ - uint8_t gic_version; - /* IN - Contains SVE vector length divided by 128 */ - uint8_t sve_vl; - /* IN */ - uint16_t tee_type; - /* IN */ - uint32_t nr_spis; - /* - * OUT - * Based on the property clock-frequency in the DT timer node. - * The property may be present when the bootloader/firmware doesn't - * set correctly CNTFRQ which hold the timer frequency. - * - * As it's not possible to trap this register, we have to replicate - * the value in the guest DT. - * - * = 0 => property not present - * > 0 => Value of the property - * - */ - uint32_t clock_frequency; -}; #endif /* __XEN__ || __XEN_TOOLS__ */ struct arch_vcpu_info { diff --git a/xen/include/public/autogen/arch_arm.h b/xen/include/public/autogen/arch_arm.h new file mode 100644 index 000000000000..d19f639671e0 --- /dev/null +++ b/xen/include/public/autogen/arch_arm.h @@ -0,0 +1,59 @@ +/* + * arch-arm + * + * AUTOGENERATED. DO NOT MODIFY + */ +#ifndef __XEN_AUTOGEN_ARCH_ARM_H +#define __XEN_AUTOGEN_ARCH_ARM_H + +/* Content of the `gic_version` field of the domainconfig struct. */ +enum xen_domctl_config_gic { + /* Emulate the underlying GIC present in the current host. */ + XEN_DOMCTL_CONFIG_GIC_NATIVE = 0, + /* Emulate a GICv2. */ + XEN_DOMCTL_CONFIG_GIC_V2 = 1, + /* Emulate a GICv3. */ + XEN_DOMCTL_CONFIG_GIC_V3 = 2, +}; + +/* TEE mediator exposed to the guest */ +enum xen_domctl_config_tee { + /* No mediator. Guest can't communicate with the TEE. */ + XEN_DOMCTL_CONFIG_TEE_NONE = 0, + /* Expose an OP-TEE mediator. */ + XEN_DOMCTL_CONFIG_TEE_OPTEE = 1, + /* Expose an FF-A mediator. */ + XEN_DOMCTL_CONFIG_TEE_FFA = 2, +}; + +/* arm-specific domain settings. */ +struct xen_arch_domainconfig { + /* + * IN/OUT: GIC version exposed to the guest. + * + * When `native` on input the output value holds the automatically chosen version. + */ + uint8_t gic_version /* See xen_domctl_config_gic */; + /* IN: SVE vector length (divided by 128) exposed to the guest. */ + uint8_t sve_vl; + /* IN: TEE mediator exposed to the guest. */ + uint16_t tee_type /* See xen_domctl_config_tee */; + /* IN: Number of SPIs exposed to the guest. */ + uint32_t nr_spis; + /* + * OUT + * Based on the property clock-frequency in the DT timer node. + * The property may be present when the bootloader/firmware doesn't + * set correctly CNTFRQ which hold the timer frequency. + * + * As it's not possible to trap this register, we have to replicate + * the value in the guest DT. + * + * = 0 => property not present + * > 0 => Value of the property + */ + uint32_t clock_frequency; +}; + +#endif /* __XEN_AUTOGEN_ARCH_ARM_H */ + From patchwork Fri Nov 15 11:51:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE857D6DDF2 for ; Fri, 15 Nov 2024 11:53:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837186.1253238 (Exim 4.92) (envelope-from ) id 1tBut7-0001Ux-Ag; Fri, 15 Nov 2024 11:53:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837186.1253238; Fri, 15 Nov 2024 11:53:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut6-0001Su-Df; Fri, 15 Nov 2024 11:53:20 +0000 Received: by outflank-mailman (input) for mailman id 837186; Fri, 15 Nov 2024 11:53:17 +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 1tBut2-0005U9-RE for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:16 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3104a531-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:12 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a9a0ec0a94fso254097366b.1 for ; Fri, 15 Nov 2024 03:53:12 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:11 -0800 (PST) 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: 3104a531-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzIiLCJoZWxvIjoibWFpbC1lajEteDYzMi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMxMDRhNTMxLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTkyLjg4NjA3NSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671592; x=1732276392; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cQe9V1AhYWf4ai4F0ROLJKgWqyUIcsqP1I8KYkQgors=; b=La0jPCBV/Mv1UJUKVVO0NzSMUIXfUZ3Yre25rIj3Ipb6K1tlmZTNOsMRBkaYDneS/9 koBKQnKjqDlHgyiR6RhmtKhfSai6UxVz7JZJwO8q03D0Ztxwr5httpdMyydpsuRkPhQ1 yRX/79bcI6GV6CqjAAYKGFRuz0lguGW49vT30= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671592; x=1732276392; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cQe9V1AhYWf4ai4F0ROLJKgWqyUIcsqP1I8KYkQgors=; b=FmUSueyjK2cYzmqdWsGzEydARoai+GYgUBVW+uINy5XAMzScSDt+aaxn0Tj0BKKLqF ubqYmg6etNI1bQ4Ele61i0DOwYUEIhTgiwVIFiOiWKzWBlAhyv6f3bV08B4XZHJaU9/Y wwXyX1NxntupgzbQuCCr3f8f8xfLM89z61NOr/sZR7twnWFAJMdHns0IV4UYIwQ/sb4D wBVHWETB7ybYO/2Hkx/1eqerLIxhyA3GkF+N9yWO1UDPuXMgIl53UE04n6VGUFb/JDMY IUL99Fc9pe9GoQw/4UffdMaa2ZJIAFMPPPCyhDh/iTGOdgjnd6xxN5yJsxxoisyQydVf TflA== X-Gm-Message-State: AOJu0Yx6lIFtfgTG7fB8nz65SiNm9O5ppGUXd5FT+YQl8hdb4yNM8AgP JWte/ihtNqhGHJhBJOBVXRPy+F8zfjWWm/hqDwjE4rCDPAuppWWHN2NJdgcJgSxhVTQHTmv20U/ U X-Google-Smtp-Source: AGHT+IEQ4pcTgOIxYTLd0C0XYSXTAYZbmAqR/sFKc273vUTbXWV38/T35FJDfzjxrCK0vIaUGLkDjA== X-Received: by 2002:a17:907:868b:b0:a9a:422:ec7 with SMTP id a640c23a62f3a-aa4834827b2mr189416866b.32.1731671591958; Fri, 15 Nov 2024 03:53:11 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Juergen Gross , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Christian Lindig , David Scott , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [RFC PATCH 16/25] xen/x86: Replace hand-crafted xen_arch_domainconfig with autogenerated one Date: Fri, 15 Nov 2024 11:51:45 +0000 Message-ID: <20241115115200.2824-17-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/libs/light/libxl_x86.c | 4 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 4 +- .../extra/arch-x86/domainconfig.toml | 87 +++++++++++++++++++ .../xenbindgen/extra/domctl/createdomain.toml | 6 ++ xen/arch/x86/domain.c | 8 +- xen/arch/x86/include/asm/domain.h | 4 +- xen/arch/x86/setup.c | 2 +- xen/include/public/arch-x86/xen.h | 51 ----------- xen/include/public/autogen/arch_x86.h | 52 +++++++++++ xen/include/public/autogen/domctl.h | 13 +++ 10 files changed, 170 insertions(+), 61 deletions(-) create mode 100644 tools/rust/xenbindgen/extra/arch-x86/domainconfig.toml create mode 100644 xen/include/public/autogen/arch_x86.h diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index a3164a3077fe..a3d856957b54 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -8,7 +8,7 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, { switch(d_config->c_info.type) { case LIBXL_DOMAIN_TYPE_HVM: - config->arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI); + config->arch.emulation_flags = (XEN_X86_EMU__ALL & ~XEN_X86_EMU_VPCI); if (!libxl_defbool_val(d_config->b_info.u.hvm.pirq)) config->arch.emulation_flags &= ~XEN_X86_EMU_USE_PIRQ; break; @@ -24,7 +24,7 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, config->arch.misc_flags = 0; if (libxl_defbool_val(d_config->b_info.arch_x86.msr_relaxed)) - config->arch.misc_flags |= XEN_X86_MSR_RELAXED; + config->arch.misc_flags |= XEN_X86_MISC_MSR_RELAXED; return 0; } diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c index 1f2cf41a9cc7..65ff4f636ea9 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -260,12 +260,12 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co cfg.arch.emulation_flags = ocaml_list_to_c_bitmap /* ! x86_arch_emulation_flags X86_EMU_ none */ - /* ! XEN_X86_EMU_ XEN_X86_EMU_ALL all */ + /* ! XEN_X86_EMU_ XEN_X86_EMU__ALL all */ (VAL_EMUL_FLAGS); cfg.arch.misc_flags = ocaml_list_to_c_bitmap /* ! x86_arch_misc_flags X86_ none */ - /* ! XEN_X86_ XEN_X86_MSR_RELAXED all */ + /* ! XEN_X86_ XEN_X86_MISC__ALL all */ (VAL_MISC_FLAGS); #undef VAL_MISC_FLAGS diff --git a/tools/rust/xenbindgen/extra/arch-x86/domainconfig.toml b/tools/rust/xenbindgen/extra/arch-x86/domainconfig.toml new file mode 100644 index 000000000000..1f85b69de4a8 --- /dev/null +++ b/tools/rust/xenbindgen/extra/arch-x86/domainconfig.toml @@ -0,0 +1,87 @@ +[[bitmaps]] +name = "xen_x86_emu" +description = "Content of the `emulation_flags` field of the domain creation hypercall." +typ = { tag = "u32" } + +[[bitmaps.bits]] +name = "lapic" +description = "Emulate Local APICs." +shift = 0 + +[[bitmaps.bits]] +name = "hpet" +description = "Emulate a HPET timer." +shift = 1 + +[[bitmaps.bits]] +name = "pm" +description = "Emulate the ACPI PM timer." +shift = 2 + +[[bitmaps.bits]] +name = "rtc" +description = "Emulate the RTC clock." +shift = 3 + +[[bitmaps.bits]] +name = "ioapic" +description = "Emulate an IOAPIC device." +shift = 4 + +[[bitmaps.bits]] +name = "pic" +description = "Emulate PIC devices." +shift = 5 + +[[bitmaps.bits]] +name = "vga" +description = "Emulate standard VGA." +shift = 6 + +[[bitmaps.bits]] +name = "iommu" +description = "Emulate an IOMMU." +shift = 7 + +[[bitmaps.bits]] +name = "pit" +description = "Emulate a PIT timer." +shift = 8 + +[[bitmaps.bits]] +name = "use_pirq" +description = "Route physical IRQs over event channels." +shift = 9 + +[[bitmaps.bits]] +name = "vpci" +description = "Handle PCI configuration space traps from within Xen." +shift = 10 + +################################################################################ + +[[bitmaps]] +name = "xen_x86_misc" +description = "Contents of the `misc_flags` field of the domain creation hypercall" +typ = { tag = "u32" } + +[[bitmaps.bits]] +name = "msr_relaxed" +description = "Grants access to the real physical MSR registers of the host." +shift = 0 + +################################################################################ + +[[structs]] +name = "xen_arch_domainconfig" +description = "x86-specific domain settings." + +[[structs.fields]] +name = "emulation_flags" +description = "IN: Bitmap of devices to emulate." +typ = { tag = "bitmap", args = "xen_x86_emu" } + +[[structs.fields]] +name = "misc_flags" +description = "IN: Miscellaneous x86-specific toggles." +typ = { tag = "bitmap", args = "xen_x86_misc" } diff --git a/tools/rust/xenbindgen/extra/domctl/createdomain.toml b/tools/rust/xenbindgen/extra/domctl/createdomain.toml index 02f65d134b55..3a6872aa325f 100644 --- a/tools/rust/xenbindgen/extra/domctl/createdomain.toml +++ b/tools/rust/xenbindgen/extra/domctl/createdomain.toml @@ -1,3 +1,9 @@ +[[includes]] +from = "arch" +imports = ["xen_arch_domainconfig"] + +################################################################################ + [[enums]] name = "xen_domctl_altp2m_mode" description = "Content of the `altp2m_mode` field of the domain creation hypercall." diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 63a52a8ae23d..3c1c8f03aa81 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -708,7 +708,7 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) } } - if ( config->arch.misc_flags & ~XEN_X86_MSR_RELAXED ) + if ( config->arch.misc_flags & ~XEN_X86_MISC_MSR_RELAXED ) { dprintk(XENLOG_INFO, "Invalid arch misc flags %#x\n", config->arch.misc_flags); @@ -735,7 +735,7 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) { #ifdef CONFIG_HVM /* This doesn't catch !CONFIG_HVM case but it is better than nothing */ - BUILD_BUG_ON(X86_EMU_ALL != XEN_X86_EMU_ALL); + BUILD_BUG_ON(X86_EMU_ALL != XEN_X86_EMU__ALL); #endif if ( is_hvm_domain(d) ) @@ -800,7 +800,7 @@ int arch_domain_create(struct domain *d, if ( is_hardware_domain(d) && is_pv_domain(d) ) emflags |= XEN_X86_EMU_PIT; - if ( emflags & ~XEN_X86_EMU_ALL ) + if ( emflags & ~XEN_X86_EMU__ALL ) { printk(XENLOG_G_ERR "d%d: Invalid emulation bitmap: %#x\n", d->domain_id, emflags); @@ -887,7 +887,7 @@ int arch_domain_create(struct domain *d, domain_cpu_policy_changed(d); - d->arch.msr_relaxed = config->arch.misc_flags & XEN_X86_MSR_RELAXED; + d->arch.msr_relaxed = config->arch.misc_flags & XEN_X86_MISC_MSR_RELAXED; return 0; diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index b79d6badd71c..119604fadb5d 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -12,6 +12,8 @@ #include #include +#include + #define has_32bit_shinfo(d) ((d)->arch.has_32bit_shinfo) /* @@ -486,7 +488,7 @@ struct arch_domain #define X86_EMU_PIT XEN_X86_EMU_PIT -/* This must match XEN_X86_EMU_ALL in xen.h */ +/* This must match XEN_X86_EMU__ALL */ #define X86_EMU_ALL (X86_EMU_LAPIC | X86_EMU_HPET | \ X86_EMU_PM | X86_EMU_RTC | \ X86_EMU_IOAPIC | X86_EMU_PIC | \ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 65ea3fc86beb..d408af54d997 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -967,7 +967,7 @@ static struct domain *__init create_dom0(const module_t *image, .max_grant_version = opt_gnttab_max_version, .max_vcpus = dom0_max_vcpus(), .arch = { - .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, + .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MISC_MSR_RELAXED : 0, }, }; struct domain *d; diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h index fc2487986642..e864459cfd93 100644 --- a/xen/include/public/arch-x86/xen.h +++ b/xen/include/public/arch-x86/xen.h @@ -255,57 +255,6 @@ struct arch_shared_info { }; typedef struct arch_shared_info arch_shared_info_t; -#if defined(__XEN__) || defined(__XEN_TOOLS__) -/* - * struct xen_arch_domainconfig's ABI is covered by - * XEN_DOMCTL_INTERFACE_VERSION. - */ -struct xen_arch_domainconfig { -#define _XEN_X86_EMU_LAPIC 0 -#define XEN_X86_EMU_LAPIC (1U<<_XEN_X86_EMU_LAPIC) -#define _XEN_X86_EMU_HPET 1 -#define XEN_X86_EMU_HPET (1U<<_XEN_X86_EMU_HPET) -#define _XEN_X86_EMU_PM 2 -#define XEN_X86_EMU_PM (1U<<_XEN_X86_EMU_PM) -#define _XEN_X86_EMU_RTC 3 -#define XEN_X86_EMU_RTC (1U<<_XEN_X86_EMU_RTC) -#define _XEN_X86_EMU_IOAPIC 4 -#define XEN_X86_EMU_IOAPIC (1U<<_XEN_X86_EMU_IOAPIC) -#define _XEN_X86_EMU_PIC 5 -#define XEN_X86_EMU_PIC (1U<<_XEN_X86_EMU_PIC) -#define _XEN_X86_EMU_VGA 6 -#define XEN_X86_EMU_VGA (1U<<_XEN_X86_EMU_VGA) -#define _XEN_X86_EMU_IOMMU 7 -#define XEN_X86_EMU_IOMMU (1U<<_XEN_X86_EMU_IOMMU) -#define _XEN_X86_EMU_PIT 8 -#define XEN_X86_EMU_PIT (1U<<_XEN_X86_EMU_PIT) -#define _XEN_X86_EMU_USE_PIRQ 9 -#define XEN_X86_EMU_USE_PIRQ (1U<<_XEN_X86_EMU_USE_PIRQ) -#define _XEN_X86_EMU_VPCI 10 -#define XEN_X86_EMU_VPCI (1U<<_XEN_X86_EMU_VPCI) - -#define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ - XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ - XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ - XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ - XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ - XEN_X86_EMU_VPCI) - uint32_t emulation_flags; - -/* - * Select whether to use a relaxed behavior for accesses to MSRs not explicitly - * handled by Xen instead of injecting a #GP to the guest. Note this option - * doesn't allow the guest to read or write to the underlying MSR. - */ -#define XEN_X86_MSR_RELAXED (1u << 0) - uint32_t misc_flags; -}; - -/* Max XEN_X86_* constant. Used for ABI checking. */ -#define XEN_X86_MISC_FLAGS_MAX XEN_X86_MSR_RELAXED - -#endif - /* * Representations of architectural CPUID and MSR information. Used as the * serialised version of Xen's internal representation. diff --git a/xen/include/public/autogen/arch_x86.h b/xen/include/public/autogen/arch_x86.h new file mode 100644 index 000000000000..94f35218342e --- /dev/null +++ b/xen/include/public/autogen/arch_x86.h @@ -0,0 +1,52 @@ +/* + * arch-x86 + * + * AUTOGENERATED. DO NOT MODIFY + */ +#ifndef __XEN_AUTOGEN_ARCH_X86_H +#define __XEN_AUTOGEN_ARCH_X86_H + +/* Content of the `emulation_flags` field of the domain creation hypercall. */ +struct xen_x86_emu {}; /* GREP FODDER */ +/* Emulate Local APICs. */ +#define XEN_X86_EMU_LAPIC (1U << 0) +/* Emulate a HPET timer. */ +#define XEN_X86_EMU_HPET (1U << 1) +/* Emulate the ACPI PM timer. */ +#define XEN_X86_EMU_PM (1U << 2) +/* Emulate the RTC clock. */ +#define XEN_X86_EMU_RTC (1U << 3) +/* Emulate an IOAPIC device. */ +#define XEN_X86_EMU_IOAPIC (1U << 4) +/* Emulate PIC devices. */ +#define XEN_X86_EMU_PIC (1U << 5) +/* Emulate standard VGA. */ +#define XEN_X86_EMU_VGA (1U << 6) +/* Emulate an IOMMU. */ +#define XEN_X86_EMU_IOMMU (1U << 7) +/* Emulate a PIT timer. */ +#define XEN_X86_EMU_PIT (1U << 8) +/* Route physical IRQs over event channels. */ +#define XEN_X86_EMU_USE_PIRQ (1U << 9) +/* Handle PCI configuration space traps from within Xen. */ +#define XEN_X86_EMU_VPCI (1U << 10) +/* Mask covering all defined bits */ +#define XEN_X86_EMU__ALL (0x7FFU) + +/* Contents of the `misc_flags` field of the domain creation hypercall */ +struct xen_x86_misc {}; /* GREP FODDER */ +/* Grants access to the real physical MSR registers of the host. */ +#define XEN_X86_MISC_MSR_RELAXED (1U << 0) +/* Mask covering all defined bits */ +#define XEN_X86_MISC__ALL (0x1U) + +/* x86-specific domain settings. */ +struct xen_arch_domainconfig { + /* IN: Bitmap of devices to emulate. */ + uint32_t emulation_flags /* See xen_x86_emu */; + /* IN: Miscellaneous x86-specific toggles. */ + uint32_t misc_flags /* See xen_x86_misc */; +}; + +#endif /* __XEN_AUTOGEN_ARCH_X86_H */ + diff --git a/xen/include/public/autogen/domctl.h b/xen/include/public/autogen/domctl.h index bd1f4bedc727..276e05168688 100644 --- a/xen/include/public/autogen/domctl.h +++ b/xen/include/public/autogen/domctl.h @@ -6,6 +6,19 @@ #ifndef __XEN_AUTOGEN_DOMCTL_H #define __XEN_AUTOGEN_DOMCTL_H +/* for xen_arch_domainconfig */ +#if defined(__i386__) || defined(__x86_64__) +#include "arch_x86.h" +#elif defined(__arm__) || defined(__aarch64__) +#include "arch_arm.h" +#elif defined(__powerpc64__) +#include "arch_ppc.h" +#elif defined(__riscv) +#include "arch_riscv.h" +#else +#error "Unsupported architecture" +#endif + /* Content of the `altp2m_mode` field of the domain creation hypercall. */ enum xen_domctl_altp2m_mode { /* Keep altp2m disabled */ From patchwork Fri Nov 15 11:51:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E8E3D6DDED for ; Fri, 15 Nov 2024 11:53:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837185.1253230 (Exim 4.92) (envelope-from ) id 1tBut5-0001Jo-S3; Fri, 15 Nov 2024 11:53:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837185.1253230; Fri, 15 Nov 2024 11:53:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut5-0001HZ-Au; Fri, 15 Nov 2024 11:53:19 +0000 Received: by outflank-mailman (input) for mailman id 837185; Fri, 15 Nov 2024 11:53:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut2-0005UF-8e for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:16 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 317a9d80-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:13 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a9ec267b879so113468166b.2 for ; Fri, 15 Nov 2024 03:53:13 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:12 -0800 (PST) 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: 317a9d80-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MjkiLCJoZWxvIjoibWFpbC1lajEteDYyOS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMxN2E5ZDgwLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTkzLjYzOTE0Mywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671593; x=1732276393; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YdcqdHnAzRpCPLvdrirhNP7a31l6SrQju/bT6qqXrVU=; b=YmWdTlDwHBXbwdfMD0UbUgKB3ZdQwRcSUJD4sAFQ2j6ecy59TxJZiDucKUUIZhy9nc DMQAT16N6+PBOi8C89lrqEcn81ZScvLTNR0cNzAwOwTnGVzZwXM8cKRDxpaBP9CBpBpk k2a7FVeQlKc4RPXR6m3wcfF/OFSzQrcAIuBhg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671593; x=1732276393; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YdcqdHnAzRpCPLvdrirhNP7a31l6SrQju/bT6qqXrVU=; b=SbcmlRjvJ/K/l7RlGe+qN24W9dvsDq99TterbOrW2vKWC4nUvFvuXYDwXPV299ShjP 5LzWtCtH3LpGAU1+peAYXBBpDIXZfTS5AkkPA+T76Y7LGSS5mBCb3R4T/kbeIa0S6omt 4iZ94MY8FZXBgs8e1eZnTVtwJ29TeTlFQC8YcYj6QP7mKzxYD/6R2Vpt6tzUsThCxcue 3z+O5jQMrjLbFsKM+278XLQV4Jswi4vboARlUysqJ4yHsy4QLE1CXqduS9ND0U+8y44G DqeT5rAD4e0JdNw6SEe7Pbfaou1jUceOGsZEFjicQAPlOjqZ8DKcPmvIfWunxk3H4BXi LHEQ== X-Gm-Message-State: AOJu0YyivA/CZ9Vd/m2oGU7lhIMtCJAj75+B+2bcmrixJmZYDo/qsky0 r+bZ5ngt7dbJEEuL2WIVXV4jrDLQsLpDlBRTnsn/ikGup4hWxXcctQAVxU0EvMFhFMv7qoe06oS p X-Google-Smtp-Source: AGHT+IEDvV/405n73PWITIupZoKMG8c3LKgslPdtmAcYUaLjTP9TC/yezrFCJS0CrByvX0O/Df5EAw== X-Received: by 2002:a17:907:f19f:b0:aa4:844d:e5cb with SMTP id a640c23a62f3a-aa4844dfdaamr172436166b.48.1731671592851; Fri, 15 Nov 2024 03:53:12 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [RFC PATCH 17/25] xen/ppc: Replace empty xen_arch_domainconfig with autogenerated one Date: Fri, 15 Nov 2024 11:51:46 +0000 Message-ID: <20241115115200.2824-18-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- .../xenbindgen/extra/arch-ppc/domainconfig.toml | 4 ++++ xen/include/public/arch-ppc.h | 3 --- xen/include/public/autogen/arch_ppc.h | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tools/rust/xenbindgen/extra/arch-ppc/domainconfig.toml create mode 100644 xen/include/public/autogen/arch_ppc.h diff --git a/tools/rust/xenbindgen/extra/arch-ppc/domainconfig.toml b/tools/rust/xenbindgen/extra/arch-ppc/domainconfig.toml new file mode 100644 index 000000000000..ecf9f1d9937d --- /dev/null +++ b/tools/rust/xenbindgen/extra/arch-ppc/domainconfig.toml @@ -0,0 +1,4 @@ +[[structs]] +name = "xen_arch_domainconfig" +description = "ppc-specific domain settings." +fields = [] diff --git a/xen/include/public/arch-ppc.h b/xen/include/public/arch-ppc.h index 33a24e379551..1e0018e12c73 100644 --- a/xen/include/public/arch-ppc.h +++ b/xen/include/public/arch-ppc.h @@ -102,9 +102,6 @@ struct arch_shared_info { struct arch_vcpu_info { }; -struct xen_arch_domainconfig { -}; - typedef struct xen_pmu_arch { uint8_t dummy; } xen_pmu_arch_t; #endif diff --git a/xen/include/public/autogen/arch_ppc.h b/xen/include/public/autogen/arch_ppc.h new file mode 100644 index 000000000000..48fcc302f341 --- /dev/null +++ b/xen/include/public/autogen/arch_ppc.h @@ -0,0 +1,14 @@ +/* + * arch-ppc + * + * AUTOGENERATED. DO NOT MODIFY + */ +#ifndef __XEN_AUTOGEN_ARCH_PPC_H +#define __XEN_AUTOGEN_ARCH_PPC_H + +/* ppc-specific domain settings. */ +struct xen_arch_domainconfig { +}; + +#endif /* __XEN_AUTOGEN_ARCH_PPC_H */ + From patchwork Fri Nov 15 11:51:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B4BCD6DDED for ; Fri, 15 Nov 2024 11:53:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837187.1253243 (Exim 4.92) (envelope-from ) id 1tBut8-0001po-Sn; Fri, 15 Nov 2024 11:53:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837187.1253243; Fri, 15 Nov 2024 11:53:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut7-0001jT-MJ; Fri, 15 Nov 2024 11:53:21 +0000 Received: by outflank-mailman (input) for mailman id 837187; Fri, 15 Nov 2024 11:53:18 +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 1tBut3-0005U9-Ro for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:17 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3217a713-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:14 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-aa4833e9c44so87785166b.2 for ; Fri, 15 Nov 2024 03:53:14 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:13 -0800 (PST) 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: 3217a713-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzAiLCJoZWxvIjoibWFpbC1lajEteDYzMC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMyMTdhNzEzLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTk0LjY3MzAwNywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671594; x=1732276394; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iGLhEwTxqC5XGNE3vexdwFzRd1DT5gLHTbpiHQthKgs=; b=aixj6kqoggGMFmWTQOLTYZo28HbmjoTOUv6mtXu7yhF8zZQ24exlgiD032UhNZdvE2 xv+g4h+uv0PUeVSNYWUPd11HUT5IdK8rFRHZdv66+AivLvzyes76gHnCT9+0D3VnH88x fQizSFh59Cci/UbfVGqo+Xbmc3bj7xencqLlc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671594; x=1732276394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iGLhEwTxqC5XGNE3vexdwFzRd1DT5gLHTbpiHQthKgs=; b=FtFVlTExfbODNE5jkyaZ/uKKeQ5zugGYWZ7ABO1rXW1WyxgGRFExpJrOKqn/2RZmNr CV24iZy27GjHf0bHpRbW6TEEaDA4FM0/8YP6UTJiuc3zEQRneBkUpKd00ye7dCe5t8YT FeDYydUEYca9OdmQ1WRkdu7gNuViLv6eUcpM19sPtjKiClrDYjXGwFjJID3fLdVFSbEt 2QLX/xyttO724CtX35jf3NqI+Nlj4IWzHRg+XeS6TMhgNRoFojc5uPxpK1CbmzOqRQMs HDy5yTQppvwhq1KHiUvNWsc5rqAWsthP21C2Mh7AbOwpB6WaEZj0w44WaLwaPbP3rXzD Um2A== X-Gm-Message-State: AOJu0YypNaQtQTYCdm1evDDU/R5WJ1LC/q3wsmmL/RFiFZOg3qhcwQET y3wgcDXikJTqKwZpZvdv+IyvkUV2L7QacBgpgpHAItf2JDp5JghYwKcDEJO9A7jEViSRwG8S8za 0 X-Google-Smtp-Source: AGHT+IFlQzPLfoakEsrMGH/yEjfZGv9k2/KhyBMVLvwJK0oZD/d0ZH9yGyQOjD/yvsTZZkuoQv0fwg== X-Received: by 2002:a17:907:3f03:b0:a9a:a891:b43e with SMTP id a640c23a62f3a-aa483555ef6mr204083366b.50.1731671593836; Fri, 15 Nov 2024 03:53:13 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [RFC PATCH 18/25] xen/riscv: Replace empty xen_arch_domainconfig with autogenerated one Date: Fri, 15 Nov 2024 11:51:47 +0000 Message-ID: <20241115115200.2824-19-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- .../xenbindgen/extra/arch-riscv/domainconfig.toml | 4 ++++ xen/include/public/arch-riscv.h | 3 --- xen/include/public/autogen/arch_riscv.h | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tools/rust/xenbindgen/extra/arch-riscv/domainconfig.toml create mode 100644 xen/include/public/autogen/arch_riscv.h diff --git a/tools/rust/xenbindgen/extra/arch-riscv/domainconfig.toml b/tools/rust/xenbindgen/extra/arch-riscv/domainconfig.toml new file mode 100644 index 000000000000..ecac1ae22b1c --- /dev/null +++ b/tools/rust/xenbindgen/extra/arch-riscv/domainconfig.toml @@ -0,0 +1,4 @@ +[[structs]] +name = "xen_arch_domainconfig" +description = "riscv-specific domain settings." +fields = [] diff --git a/xen/include/public/arch-riscv.h b/xen/include/public/arch-riscv.h index 168263b92074..a199dbc6a15f 100644 --- a/xen/include/public/arch-riscv.h +++ b/xen/include/public/arch-riscv.h @@ -55,9 +55,6 @@ struct vcpu_guest_context { typedef struct vcpu_guest_context vcpu_guest_context_t; DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); -struct xen_arch_domainconfig { -}; - #endif /* TODO: add a placeholder entry if no real ones surface */ diff --git a/xen/include/public/autogen/arch_riscv.h b/xen/include/public/autogen/arch_riscv.h new file mode 100644 index 000000000000..e0d3aa681862 --- /dev/null +++ b/xen/include/public/autogen/arch_riscv.h @@ -0,0 +1,14 @@ +/* + * arch-riscv + * + * AUTOGENERATED. DO NOT MODIFY + */ +#ifndef __XEN_AUTOGEN_ARCH_RISCV_H +#define __XEN_AUTOGEN_ARCH_RISCV_H + +/* riscv-specific domain settings. */ +struct xen_arch_domainconfig { +}; + +#endif /* __XEN_AUTOGEN_ARCH_RISCV_H */ + From patchwork Fri Nov 15 11:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E5D0D6DDF2 for ; Fri, 15 Nov 2024 12:02:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837305.1253302 (Exim 4.92) (envelope-from ) id 1tBv1q-00024w-JC; Fri, 15 Nov 2024 12:02:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837305.1253302; Fri, 15 Nov 2024 12:02:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBv1q-00024p-G2; Fri, 15 Nov 2024 12:02:22 +0000 Received: by outflank-mailman (input) for mailman id 837305; Fri, 15 Nov 2024 12:02:21 +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 1tBut5-0005U9-H2 for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:19 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 32c5a80e-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:15 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a9a0ef5179dso313774066b.1 for ; Fri, 15 Nov 2024 03:53:15 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:14 -0800 (PST) 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: 32c5a80e-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MjkiLCJoZWxvIjoibWFpbC1lajEteDYyOS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMyYzVhODBlLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNTk1Ljg2MjQ0Mywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671595; x=1732276395; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b+N/BoPDPF+FDyxeB8VC1PzNpWxozefZT+Maz4yXPWA=; b=eogdI5RyCeSJRRo3o/h6GKQaGMQgJN0kx6vEXPZ/S4j4954W5g2WxHjnIH+bllQitP jp38C7CLoKP2qGphLBmkkfBPVUdxSoiXPflmnANKuXGaT56cbVTlTNTDb8NiNtGi6gvU H+qs8RmSCfhsQJO46xM5rsi3RUW1wHuJOBSTU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671595; x=1732276395; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b+N/BoPDPF+FDyxeB8VC1PzNpWxozefZT+Maz4yXPWA=; b=O/xG2wznR4JphlJpL4IQuCefGbQfCmUeNWWZMWsz1/j0SU6iCQzbj3xbswH5+hqQib KnYd500Hi3PDyXtLHfKFrxJ6KwyP/o3055F0H9gaaqYJH65qQoXQXbs62wk5XMrKykaR GV9AU1wIZDdLnwB3wXwJb+3sF/j/L2hlmsFJduSlTXQR/+M8r0MRdrrIq/Bxi8IYs6CD xTZhoCMLvkqGgZDLq0TZjH25c/AZsjMW9xrlRAjd1bh3OuhNTWPPoqB8QmR1hol0FMBo Mh0xl1blZztGAwHBEu4WmNqkPdYK3ZO9Qey3Ke0A0v0qyhPv9SKZvItYAwUrsxDnJUfn UxXA== X-Gm-Message-State: AOJu0YwzvBvK+Sc9t/eTHuARhuUtcG4r63jLTJd/r0Fj8JxNX/ntHviB YwrcqheM2zzkR+blykLlfdgvCyWlQIRK6zTZqG92KMjTe4oSnvdkQ7W4D7ikS8NfnRa7aARRZzW I X-Google-Smtp-Source: AGHT+IGKtdNpRNDLBKXGKwssmmliwCnjWY1IyAWAm+Wgg9U0l7uFgihat0PlR051i92rPrUjj6XKvA== X-Received: by 2002:a17:907:6e94:b0:a9a:c57f:9634 with SMTP id a640c23a62f3a-aa483525e7dmr215523866b.42.1731671594834; Fri, 15 Nov 2024 03:53:14 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , "Daniel P. Smith" Subject: [RFC PATCH 19/25] xen: Replace hand-crafted domctl/createdomain with autogenerated version Date: Fri, 15 Nov 2024 11:51:48 +0000 Message-ID: <20241115115200.2824-20-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 With xen_arch_domainconfig and every bitmap/enum already autogenerated, add the final piece to enable autogeneration of the createdomain hypercall. Signed-off-by: Alejandro Vallejo --- .../xenbindgen/extra/domctl/createdomain.toml | 96 +++++++++++++++++++ xen/include/public/autogen/domctl.h | 54 +++++++++++ xen/include/public/domctl.h | 56 +---------- xen/include/public/sysctl.h | 1 + 4 files changed, 152 insertions(+), 55 deletions(-) diff --git a/tools/rust/xenbindgen/extra/domctl/createdomain.toml b/tools/rust/xenbindgen/extra/domctl/createdomain.toml index 3a6872aa325f..f20cb8790039 100644 --- a/tools/rust/xenbindgen/extra/domctl/createdomain.toml +++ b/tools/rust/xenbindgen/extra/domctl/createdomain.toml @@ -87,3 +87,99 @@ typ = { tag = "u32" } name = "no_sharept" description = "Set to _NOT_ share page tables between the CPU and the IOMMU when it would be possible to do so." shift = 0 + +################################################################################ + +[[structs]] +name = "xen_domctl_createdomain" +description = """ +Create a new domain with the passed parameters. + +IMPORTANT: The domid part of the domctl is IN/OUT. When the passed +domid is 0 or over `DOMID_FIRST_RESERVED` a new domid is auto-allocated +and returned.""" + +[[structs.fields]] +name = "ssidref" +description = "IN: `Source Security IDentifier` (See XSM)." +typ = { tag = "u32" } + +[[structs.fields]] +name = "handle" +description = "IN: Unique identifier for this guest given by the toolstack." +typ = { tag = "array", args = [{ tag = "u8" }, 16] } + +[[structs.fields]] +name = "flags" +description = "IN: Bitmap of domain features to enable/disable." +typ = { tag = "bitmap", args = "xen_domctl_cdf" } + +[[structs.fields]] +name = "iommu_opts" +description = "IN: Bitmap of configuration settings for the IOMMU." +typ = { tag = "bitmap", args = "xen_domctl_iommu_opts" } + +[[structs.fields]] +name = "max_vcpus" +description = "IN: Maximum number of CPUs this domain can hold, including hotplug." +typ = { tag = "u32" } + +[[structs.fields]] +name = "max_evtchn_port" +description = "IN: Maximum number of usable event channels" +typ = { tag = "u32" } + +[[structs.fields]] +name = "max_grant_frames" +description = ''' +IN: Maximum number of pages this domain is able + to grant access to for other domains. + +`< 0` means "use default value in the hypervisor."''' +typ = { tag = "i32" } + +[[structs.fields]] +name = "max_maptrack_frames" +description = ''' +IN: Maximum number of pages of foreign domains + can be accessed via the grant mechanism. + +`< 0` means "use default value in the hypervisor."''' +typ = { tag = "i32" } + +[[structs.fields]] +name = "max_grant_version" +description = "Maximum grant table version allowed for this domain" +typ = { tag = "u8" } + +[[structs.fields]] +name = "rsvd0_a" +description = "Unused padding. Reserved to zero." +typ = { tag = "array", args = [{ tag = "u8" }, 3] } + +[[structs.fields]] +name = "altp2m_mode" +description = "Which mode to configure altp2m with" +typ = { tag = "u8" } + +[[structs.fields]] +name = "rsvd0_b" +description = "Unused padding. Reserved to zero." +typ = { tag = "array", args = [{ tag = "u8" }, 3] } + +[[structs.fields]] +name = "vmtrace_size" +description = "IN: Per-vCPU buffer size in octets. 0 to disable." +typ = { tag = "u32" } + +[[structs.fields]] +name = "cpupool_id" +description = "IN: CPU pool to use; 0 or an existing CPU pool." +typ = { tag = "u32" } + +[[structs.fields]] +name = "arch" +description = """Arch-specific settings. + +Each architecture is free to make its fields IN/OUT/INOUT""" +typ = { tag = "struct", args = "xen_arch_domainconfig" } diff --git a/xen/include/public/autogen/domctl.h b/xen/include/public/autogen/domctl.h index 276e05168688..8a0934039169 100644 --- a/xen/include/public/autogen/domctl.h +++ b/xen/include/public/autogen/domctl.h @@ -59,5 +59,59 @@ struct xen_domctl_iommu_opts {}; /* GREP FODDER */ /* Mask covering all defined bits */ #define XEN_DOMCTL_IOMMU_OPTS__ALL (0x1U) +/* + * Create a new domain with the passed parameters. + * + * IMPORTANT: The domid part of the domctl is IN/OUT. When the passed + * domid is 0 or over `DOMID_FIRST_RESERVED` a new domid is auto-allocated + * and returned. + */ +struct xen_domctl_createdomain { + /* IN: `Source Security IDentifier` (See XSM). */ + uint32_t ssidref; + /* IN: Unique identifier for this guest given by the toolstack. */ + uint8_t handle[16]; + /* IN: Bitmap of domain features to enable/disable. */ + uint32_t flags /* See xen_domctl_cdf */; + /* IN: Bitmap of configuration settings for the IOMMU. */ + uint32_t iommu_opts /* See xen_domctl_iommu_opts */; + /* IN: Maximum number of CPUs this domain can hold, including hotplug. */ + uint32_t max_vcpus; + /* IN: Maximum number of usable event channels */ + uint32_t max_evtchn_port; + /* + * IN: Maximum number of pages this domain is able + * to grant access to for other domains. + * + * `< 0` means "use default value in the hypervisor." + */ + int32_t max_grant_frames; + /* + * IN: Maximum number of pages of foreign domains + * can be accessed via the grant mechanism. + * + * `< 0` means "use default value in the hypervisor." + */ + int32_t max_maptrack_frames; + /* Maximum grant table version allowed for this domain */ + uint8_t max_grant_version; + /* Unused padding. Reserved to zero. */ + uint8_t rsvd0_a[3]; + /* Which mode to configure altp2m with */ + uint8_t altp2m_mode; + /* Unused padding. Reserved to zero. */ + uint8_t rsvd0_b[3]; + /* IN: Per-vCPU buffer size in octets. 0 to disable. */ + uint32_t vmtrace_size; + /* IN: CPU pool to use; 0 or an existing CPU pool. */ + uint32_t cpupool_id; + /* + * Arch-specific settings. + * + * Each architecture is free to make its fields IN/OUT/INOUT + */ + struct xen_arch_domainconfig arch; +}; + #endif /* __XEN_AUTOGEN_DOMCTL_H */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 2d1423f6fd91..01404cf301fa 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -33,62 +33,8 @@ * * Last version bump: Xen 4.19 */ -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000017 - -/* - * NB. xen_domctl.domain is an IN/OUT parameter for this operation. - * If it is specified as an invalid value (0 or >= DOMID_FIRST_RESERVED), - * an id is auto-allocated and returned. - */ -/* XEN_DOMCTL_createdomain */ -struct xen_domctl_createdomain { - /* IN parameters */ - uint32_t ssidref; - xen_domain_handle_t handle; - /* See xen_domctl_cdf */ - uint32_t flags; - /* See xen_domctl_iommu_opts */ - uint32_t iommu_opts; - - /* - * Various domain limits, which impact the quantity of resources - * (global mapping space, xenheap, etc) a guest may consume. For - * max_grant_frames and max_maptrack_frames, < 0 means "use the - * default maximum value in the hypervisor". - */ - uint32_t max_vcpus; - uint32_t max_evtchn_port; - int32_t max_grant_frames; - int32_t max_maptrack_frames; - - /* - * Maximum grant table version the domain can be configured with. - * - * Domains always start with v1 (if CONFIG_GRANT_TABLE) and can be bumped - * to use up to `max_grant_version` via GNTTABOP_set_version. - * - * Must be zero iff !CONFIG_GRANT_TABLE. - */ - uint8_t max_grant_version; - - /* Unused. Reserved to zero. */ - uint8_t rsvd0_a[3]; - - /* See xen_domctl_altp2m_mode */ - uint8_t altp2m_mode; - - /* Unused. Reserved to zero. */ - uint8_t rsvd0_b[3]; - - /* Per-vCPU buffer size in bytes. 0 to disable. */ - uint32_t vmtrace_size; - - /* CPU pool to use; specify 0 or a specific existing pool */ - uint32_t cpupool_id; - - struct xen_arch_domainconfig arch; -}; +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000017 /* XEN_DOMCTL_getdomaininfo */ struct xen_domctl_getdomaininfo { diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 9e773490a5ac..e882c1e31059 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -17,6 +17,7 @@ #include "xen.h" #include "domctl.h" #include "physdev.h" +#include "autogen/sysctl.h" #include "autogen/sysctl.h" From patchwork Fri Nov 15 11:51:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74204D6DDF2 for ; Fri, 15 Nov 2024 11:53:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837189.1253252 (Exim 4.92) (envelope-from ) id 1tButB-0002Hh-0v; Fri, 15 Nov 2024 11:53:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837189.1253252; Fri, 15 Nov 2024 11:53:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut9-0002C5-Vl; Fri, 15 Nov 2024 11:53:23 +0000 Received: by outflank-mailman (input) for mailman id 837189; Fri, 15 Nov 2024 11:53:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut5-0005UF-Lg for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:19 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 334a5837-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:16 +0100 (CET) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9ed0ec0e92so219707066b.0 for ; Fri, 15 Nov 2024 03:53:16 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:15 -0800 (PST) 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: 334a5837-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MmEiLCJoZWxvIjoibWFpbC1lajEteDYyYS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMzNGE1ODM3LWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTk2LjY3ODEwNSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671596; x=1732276396; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wd12TLoYnDOqV6lniP/y6y+oLqd9d3Mn0zg1NVePIgk=; b=DXhOzYtn4SA/66Fz3lA6Cyi6bf6ZcGXtbkIb2otsJRm5itLvOMIgGYTVrPbsLWJ5w0 /U0BosFIqRGduyJC6cukG0UBBxVlForgksBwR82nKiCz9Wy+SMFjs2c93x43ZoEhO6AQ zJ3zAPtcvA9pH+0ci6CMv8kgL2m3cHvmzcE6E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671596; x=1732276396; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wd12TLoYnDOqV6lniP/y6y+oLqd9d3Mn0zg1NVePIgk=; b=MarlDjurWRNqPllPRyWyHKgUNvxWnkIeENdRaLUcqwJXAOVSahxEG7THmcYssocwdW 25u/U4X3uDiBcxL5NOIskY1BDVlWgUpvgMxJZVeLClPJQpQPxXKDzJCgtOjU5OJc3MVw x2XktnOo7WnufWGKEFngQADTbnPK12kzasFRiF+5tYZhQCahwx+FDW+7Vi8SUqin54GO K7Dwh5+zPFLOQKqH8zYHZdUNme97FrZHQSPPH1pgnXF/hpmfMsRIYRximkb9pKiaQ0No KqQu0FBEz81d3u6dXICNJygwuoFmQ79jmGaT/A6rVRnV4eoSqUZjVK6TUXCopzBjyzTx rHxg== X-Gm-Message-State: AOJu0YzYOfyjeqjLIe3ZC658oMLrONvPIzU2OsazxDmyy2a08xkm6kB6 bmXb42Pw7wJs4HulMZolkHxKiBapCCrfIvnIdWWeZHKUVa6UlpulIetuA99YjeL40nIIYP1rGU1 u X-Google-Smtp-Source: AGHT+IHs4nZ1914Yii8bj8glRUI8ZTNmXj93Zs7v2Scvi8HxKrRIJdlKohw+2miFfcCUCEzgqMcJWA== X-Received: by 2002:a17:907:3e0f:b0:a7a:9f0f:ab18 with SMTP id a640c23a62f3a-aa48341caa6mr189774766b.20.1731671595801; Fri, 15 Nov 2024 03:53:15 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD Subject: [RFC PATCH 20/25] tools/xen-sys: Create a crate with autogenerated Rust constructs Date: Fri, 15 Nov 2024 11:51:49 +0000 Message-ID: <20241115115200.2824-21-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Signed-off-by: Alejandro Vallejo --- tools/rust/Makefile | 5 ++++- tools/rust/xen-sys/.gitignore | 2 ++ tools/rust/xen-sys/Cargo.toml | 8 +++++++ tools/rust/xen-sys/src/lib.rs | 41 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tools/rust/xen-sys/.gitignore create mode 100644 tools/rust/xen-sys/Cargo.toml create mode 100644 tools/rust/xen-sys/src/lib.rs diff --git a/tools/rust/Makefile b/tools/rust/Makefile index 80e2f0e2817e..814e5b94447f 100644 --- a/tools/rust/Makefile +++ b/tools/rust/Makefile @@ -3,6 +3,9 @@ XEN_ROOT=$(CURDIR)/../.. # Path to the Xen hypercall IDL parser XENBINDGEN=$(CURDIR)/xenbindgen +# Path to the autogenerated Rust bindings crate +CRATE_XENSYS=$(CURDIR)/xen-sys + # Output folder for the autogenerated C headers # # Must contain autogenerated files only because they're all wiped on update @@ -37,7 +40,7 @@ update: clean-autogen .PHONY: verify verify: set -eu; \ - for i in "${XENBINDGEN}"; do \ + for i in "${CRATE_XENSYS}" "${XENBINDGEN}"; do \ echo "Verifying $$i"; \ cd "$$i"; \ cargo fmt -- --check; \ diff --git a/tools/rust/xen-sys/.gitignore b/tools/rust/xen-sys/.gitignore new file mode 100644 index 000000000000..ca98cd96efdc --- /dev/null +++ b/tools/rust/xen-sys/.gitignore @@ -0,0 +1,2 @@ +/target/ +Cargo.lock diff --git a/tools/rust/xen-sys/Cargo.toml b/tools/rust/xen-sys/Cargo.toml new file mode 100644 index 000000000000..fb91beaa1525 --- /dev/null +++ b/tools/rust/xen-sys/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "xen-sys" +version = "0.1.0" +edition = "2021" +license = "MIT" + +[dependencies] +bitflags = { version = "2.6.0", default-features = false } diff --git a/tools/rust/xen-sys/src/lib.rs b/tools/rust/xen-sys/src/lib.rs new file mode 100644 index 000000000000..7b3ea6c8ad4c --- /dev/null +++ b/tools/rust/xen-sys/src/lib.rs @@ -0,0 +1,41 @@ +//! xen-sys +//! +//! This crate contains low-level primitives to interact with the Xen +//! hypervisor. It relies on the autogenerated bindings of xenbindgen and +//! a few closely related primitives, like [`Align64`]. +#![no_std] + +use core::ops::{Deref, DerefMut}; + +/// Wrapper for pointers and 64bit integers so they are _always_ aligned to 8 +/// octets, even in 32bit machines. +#[repr(align(8))] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct Align64(pub T); + +impl Default for Align64 { + fn default() -> Self { + // Experimental feature + // + // This is required because `*mut U` can't implement Default. We take + // the convention that `Default` means "zero". For `t: Align64<*mut T>` + // that means `t` is null. + // + // If the `xen` crate stops needing this, then this impl must go away. + unsafe { Self(core::mem::zeroed()) } + } +} + +impl Deref for Align64 { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for Align64 { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} From patchwork Fri Nov 15 11:51:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876160 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 778E2D6DDED for ; Fri, 15 Nov 2024 12:05:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837379.1253342 (Exim 4.92) (envelope-from ) id 1tBv4e-0005H8-Ri; Fri, 15 Nov 2024 12:05:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837379.1253342; Fri, 15 Nov 2024 12:05:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBv4e-0005H0-Ma; Fri, 15 Nov 2024 12:05:16 +0000 Received: by outflank-mailman (input) for mailman id 837379; Fri, 15 Nov 2024 12:05:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut7-0005UF-MN for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:21 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 33f089b7-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:17 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a9ef275b980so110506066b.0 for ; Fri, 15 Nov 2024 03:53:17 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:16 -0800 (PST) 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: 33f089b7-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzMiLCJoZWxvIjoibWFpbC1lajEteDYzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjMzZjA4OWI3LWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTk3Ljc4MDcwOCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671597; x=1732276397; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G8IJxvsENAAnpsQy10FyIA1V+srxUr4XR8FTrJ0CEGs=; b=PnM9Hetsqwn7XqVpibWXtAveOxCSkSa9txa9YhCpystOIqN/kJ/Ycj0jilAU5BR7iM UEdRpDlpL0zrtArDKvwCEV9Hyk9UON7LNBZLkmZqqrlwiLDn6ZMHrhwMNRhSauzTiobe Sm31e/l6gcmtPdDIDyQyyUbX8+yqagjEyGffk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671597; x=1732276397; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G8IJxvsENAAnpsQy10FyIA1V+srxUr4XR8FTrJ0CEGs=; b=xGM0vTDHjmNEFyJjMNs1VENAWai0mlK3llq/3tsENEk65mbVKqG2VJ0NoKbJeg58A5 tuSx7VA9Cn/FP4fFWc63yGfYDRKpC6FXwXbAQ2rc3NoPbx6Q0GUa65D9PLE98Fit+oya g2dr79VJ/c71gCG3R7yAYPD2T0Fh47WUJMRxwraJdGZ9xgHKBn7gMc06Wwvl2wBmpdd9 u0TuRqsdcIA82GxS9AGKg1iwsodBM2vsHfpOHsBMI/cXueV3pqzHLyfEWrjv7Ws9hYT1 smcLvQm0jPD83fLJDe2btUUVtNTCyaSkltZpQ0vYpySj937nwejsvkuIRmDV7g+f+kzF m0Uw== X-Gm-Message-State: AOJu0YwspulAS0IGKvcaS+bv+7w7fIapUp6/JG2uWqSYIfmLRnAkgIIc SjuXT1dAFDmonbxO3EypMWMJGa1e7wyj4EnS63DMs1AEgspMwtHPukkfq1151pArOGqOEORu1Bb C X-Google-Smtp-Source: AGHT+IECS/ncMc6P9Q42wlKXYbU9TWMpS2F64uBBQH9XaQw86jpNMutwQkL9l17OdZ5ZCicNfye9SA== X-Received: by 2002:a17:907:2d8e:b0:a9a:67aa:31f5 with SMTP id a640c23a62f3a-aa4833eb75cmr216937566b.10.1731671596814; Fri, 15 Nov 2024 03:53:16 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , Teddy Astie , Yann Dirson , Teddy Astie Subject: [RFC PATCH 21/25] tools/xenbindgen: Add Rust backend to xenbindgen Date: Fri, 15 Nov 2024 11:51:50 +0000 Message-ID: <20241115115200.2824-22-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Teddy added support for includes in this backend, as in the C backend. Signed-off-by: Alejandro Vallejo Signed-off-by: Teddy Astie --- tools/rust/Makefile | 10 +- tools/rust/xen-sys/src/lib.rs | 2 + tools/rust/xenbindgen/src/main.rs | 4 + tools/rust/xenbindgen/src/rs_lang.rs | 227 +++++++++++++++++++++++++++ 4 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 tools/rust/xenbindgen/src/rs_lang.rs diff --git a/tools/rust/Makefile b/tools/rust/Makefile index 814e5b94447f..4f064c37f45c 100644 --- a/tools/rust/Makefile +++ b/tools/rust/Makefile @@ -6,6 +6,9 @@ XENBINDGEN=$(CURDIR)/xenbindgen # Path to the autogenerated Rust bindings crate CRATE_XENSYS=$(CURDIR)/xen-sys +# Output folder for the autogenerated Rust files +AUTOGEN_RS=$(CRATE_XENSYS)/src/autogen + # Output folder for the autogenerated C headers # # Must contain autogenerated files only because they're all wiped on update @@ -25,13 +28,18 @@ all install uninstall clean: # Remove all autogenerated files .PHONY: clean-autogen clean-autogen: - rm -rf "${AUTOGEN_C}" + rm -rf "${AUTOGEN_RS}" "${AUTOGEN_C}" # Refresh autogenerated files. Depending on clean-autogen is required in order # for removals of specification files to cause the removal of their # autogenerated files. .PHONY: update update: clean-autogen + # Update Rust bindings + cargo run --manifest-path "${XENBINDGEN}/Cargo.toml" -- --lang rust \ + --indir "${XENBINDGEN}/extra" --outdir "${AUTOGEN_RS}" + cargo fmt --manifest-path "${CRATE_XENSYS}/Cargo.toml" + # Update C bindings cargo run --manifest-path "${XENBINDGEN}/Cargo.toml" -- --lang c \ --indir "${XENBINDGEN}/extra" --outdir "${AUTOGEN_C}" diff --git a/tools/rust/xen-sys/src/lib.rs b/tools/rust/xen-sys/src/lib.rs index 7b3ea6c8ad4c..efab54ee1025 100644 --- a/tools/rust/xen-sys/src/lib.rs +++ b/tools/rust/xen-sys/src/lib.rs @@ -5,6 +5,8 @@ //! a few closely related primitives, like [`Align64`]. #![no_std] +pub mod autogen; + use core::ops::{Deref, DerefMut}; /// Wrapper for pointers and 64bit integers so they are _always_ aligned to 8 diff --git a/tools/rust/xenbindgen/src/main.rs b/tools/rust/xenbindgen/src/main.rs index dbc610e420f2..a1cf47e26bf5 100644 --- a/tools/rust/xenbindgen/src/main.rs +++ b/tools/rust/xenbindgen/src/main.rs @@ -5,6 +5,7 @@ mod spec; mod c_lang; +mod rs_lang; use std::{io::Write, path::PathBuf}; @@ -35,6 +36,8 @@ struct Cli { enum Lang { #[doc(hidden)] C, + #[doc(hidden)] + Rust, } fn main() { @@ -66,6 +69,7 @@ fn main() { }; let (extension, parser): (&str, fn(&OutFileDef) -> String) = match cli.lang { + Lang::Rust => (".rs", rs_lang::parse), Lang::C => (".h", c_lang::parse), }; diff --git a/tools/rust/xenbindgen/src/rs_lang.rs b/tools/rust/xenbindgen/src/rs_lang.rs new file mode 100644 index 000000000000..cd5ce2989d51 --- /dev/null +++ b/tools/rust/xenbindgen/src/rs_lang.rs @@ -0,0 +1,227 @@ +//! Rust backend +//! +//! A backend for the Rust programming language. Enums, structs and bitmaps +//! are native (with the latter being available via the `bitflags` crate. +//! +//! 64bit primitives and pointers are wrapped in a _magic_ type called `Align64`. +//! This type is expected to exist in the target crate and is meant to provide +//! ergonomic mechanisms to, create, access and modify its contents. Its whole +//! purpose is make those types have 64bit size and be 64bit aligned even on +//! 32bit targets. +use std::fmt::Write; + +use crate::spec::{BitmapDef, EnumDef, IncludeDef, OutFileDef, StructDef, Typ}; + +use convert_case::{Case, Casing}; +use log::{debug, trace}; + +/// An abstract indentation level. 0 is no indentation, 1 is [`INDENT_WIDTH`] +/// and so on. +#[derive(Copy, Clone)] +struct Indentation(usize); + +/// Default width of each level of indentation +const INDENT_WIDTH: usize = 4; + +/// Convert an IDL type into its Rust type. +fn typ_rs(typ: &Typ) -> String { + match typ { + Typ::Ptr(x) => format!("crate::Align64<*mut {}>", typ_rs(x)), + Typ::Enum(x) | Typ::Struct(x) | Typ::Bitmap(x) => x.to_case(Case::Pascal), + Typ::Array(x, len) => format!("[{}; {}]", typ_rs(x), len), + Typ::U8 => String::from("u8"), + Typ::U16 => String::from("u16"), + Typ::U32 => String::from("u32"), + Typ::U64 => String::from("crate::Align64"), + Typ::I8 => String::from("i8"), + Typ::I16 => String::from("i16"), + Typ::I32 => String::from("i32"), + Typ::I64 => String::from("crate::Align64"), + } +} + +/// Add a comment to a struct or a field. +fn comment(out: &mut String, comment: &str, ind: Indentation) { + let spaces = " ".repeat(INDENT_WIDTH * ind.0); + for line in comment.split('\n') { + write!(out, "{spaces}///").unwrap(); + if !line.is_empty() { + write!(out, " {line}").unwrap(); + } + writeln!(out).unwrap(); + } +} + +/// Perform external inclusion in the form of a Rust _use_ statement. +fn includegen(out: &mut String, def: &IncludeDef) { + if def.imports.is_empty() { + return; + } + + let refered_pascal: Vec = def + .imports + .iter() + .map(|s| s.to_case(Case::Pascal)) + .collect(); + + writeln!( + out, + "use super::{}::{{{}}};", + &def.from, + refered_pascal.join(",") + ) + .unwrap(); + + writeln!(out).unwrap(); +} + +/// Write a Rust-compatible struct onto `out` +fn structgen(out: &mut String, def: &StructDef) { + debug!("struct {}", def.name); + + comment(out, &def.description, Indentation(0)); + writeln!(out, "#[repr(C)]").unwrap(); + writeln!(out, "#[derive(Clone, Debug, Default)]").unwrap(); + write!(out, "pub struct {}", def.name.to_case(Case::Pascal)).unwrap(); + + if def.fields.is_empty() { + // zero-sized struct + writeln!(out, ";\n").unwrap(); + return; + } + + writeln!(out, " {{").unwrap(); + + for f in &def.fields { + trace!(" field {} type={:?}", f.name, f.typ); + + comment(out, &f.description, Indentation(1)); + writeln!( + out, + " pub {}: {},", + f.name.to_case(Case::Snake), + typ_rs(&f.typ) + ) + .unwrap(); + } + writeln!(out, "}}\n").unwrap(); +} + +/// Write a Rust-compatible enum onto `out` +fn enumgen(out: &mut String, def: &EnumDef) { + debug!("enum {}", def.name); + + comment(out, &def.description, Indentation(0)); + + // If the underlying type is 64bits things get trickier. What we want + // in that case is to use u64 for the underlying type, but set + // align(8) on the overall repr. Otherwise 32bit platforms have the wrong + // alignment. + let repr: &str = if def.typ == Typ::U64 || def.typ == Typ::I64 { + "align(8)" + } else { + &typ_rs(&def.typ) + }; + + writeln!(out, "#[repr({repr})]").unwrap(); + writeln!(out, "#[derive(Clone, Debug, Default, PartialEq, Eq)]").unwrap(); + writeln!(out, "pub enum {} {{", def.name.to_case(Case::Pascal)).unwrap(); + for (i, f) in def.variants.iter().enumerate() { + trace!(" variant {}={}", f.name, f.value); + + comment(out, &f.description, Indentation(1)); + if i == 0 { + writeln!(out, " #[default]").unwrap(); + } + writeln!(out, " {} = {},", f.name.to_case(Case::Pascal), f.value).unwrap(); + } + writeln!(out, "}}\n").unwrap(); +} + +/// Write a Rust-compatible bitmap onto `out`. +/// +/// NOTE: Uses the bitflags crate underneath +fn bitmapgen(out: &mut String, def: &BitmapDef) { + debug!("bitmap {}", def.name); + + writeln!(out, "bitflags! {{").unwrap(); + comment(out, &def.description, Indentation(1)); + + // If the underlying type is 64bits things get trickier. What we want + // in that case is to use u64 for the underlying type, but set + // align(8) on the overall repr. + let is_64bits = def.typ == Typ::U64 || def.typ == Typ::I64; + let repr = if is_64bits { "align(8)" } else { "C" }; + + writeln!(out, " #[repr({repr})]").unwrap(); + writeln!( + out, + " #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]" + ) + .unwrap(); + writeln!( + out, + " pub struct {}: {} {{", + def.name.from_case(Case::Snake).to_case(Case::Pascal), + if is_64bits { + "u64".to_owned() + } else { + typ_rs(&def.typ) + } + ) + .unwrap(); + + for f in &def.bits { + trace!(" shift {}={}", f.name, f.shift); + + comment(out, &f.description, Indentation(2)); + writeln!( + out, + " const {} = 1 << {};", + f.name.from_case(Case::Snake).to_case(Case::Pascal), + f.shift + ) + .unwrap(); + } + writeln!(out, " }}").unwrap(); + + writeln!(out, "}}\n").unwrap(); +} + +/// Generates a single `.rs` file. +/// +/// `filedef` is a language-agnostic high level description of what the output +/// must contain. The function returns the contents of the new +/// +/// # Aborts +/// Aborts the process with `rc=1` on known illegal specifications. +pub fn parse(filedef: &OutFileDef) -> String { + let mut out = String::new(); + + writeln!(out, "//! {}", &filedef.name).unwrap(); + writeln!(out, "//!").unwrap(); + writeln!(out, "//! AUTOGENERATED. DO NOT MODIFY").unwrap(); + writeln!(out).unwrap(); + + if !filedef.bitmaps.is_empty() { + writeln!(out, "use bitflags::bitflags;\n").unwrap(); + } + + for def in &filedef.includes { + includegen(&mut out, def); + } + + for def in &filedef.bitmaps { + bitmapgen(&mut out, def); + } + + for def in &filedef.enums { + enumgen(&mut out, def); + } + + for def in &filedef.structs { + structgen(&mut out, def); + } + + out +} From patchwork Fri Nov 15 11:51:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72C35D6DDF2 for ; Fri, 15 Nov 2024 12:04:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837349.1253332 (Exim 4.92) (envelope-from ) id 1tBv3d-00048Q-Fv; Fri, 15 Nov 2024 12:04:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837349.1253332; Fri, 15 Nov 2024 12:04:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBv3d-00048J-DB; Fri, 15 Nov 2024 12:04:13 +0000 Received: by outflank-mailman (input) for mailman id 837349; Fri, 15 Nov 2024 12:04:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBut9-0005UF-Mf for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:23 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3490053b-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:18 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a9a0c7abaa6so208764266b.2 for ; Fri, 15 Nov 2024 03:53:18 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:17 -0800 (PST) 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: 3490053b-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzMiLCJoZWxvIjoibWFpbC1lajEteDYzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjM0OTAwNTNiLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNTk4LjgxMjcwOCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671598; x=1732276398; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UP4t8//FGJyNBLIO0mqUe6Ltob3Zl7JdI4z52xmh06g=; b=XLX5hNb1XRxR7tYsrRIGpptdr7QKNTWMuBt348NVFwz3ikMauWsEx2YiLs7XkjUYsf qJ9++th2oKDnjm+nJacq+wFAb4uVP8u/+pVwrG+rS5K3rrz4Qy5JLnWn/jaexc+0BK0O aP/2XYsV6Co9Dkdx8jdQ9fAqPQ//nTx7pgDlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671598; x=1732276398; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UP4t8//FGJyNBLIO0mqUe6Ltob3Zl7JdI4z52xmh06g=; b=X+OYVRYrSUXN/3GLk57wGjnJwWyYhWoiYk/3txS3CelA3Cuih4FFO7v3FD63bQq5fT WjC2puP4l76ic2MJGoCCHOWN4a4R0rUPwZyRfT7egDHs6Hh0VKNWZUbBKNmZSoqMomPP iiwW+9a0ieDi+cKL+3GLWUXYVpxJSNjIL0dOZ5Vy6p1E3LdYsPXsCPpDIi3ihg9BwaaX tJM3rKP/FxiBM1hQQmRVdqHGlDkyubM0JJIIed155mcspocKge5Vr4d4e+t+n3EBAgRs Ep7di5aI01xRFEIliR9WeD8jswSVnsq1hPWzlNlMXaHjBsGBjj58k/MQQEwCcgBeCYX9 J7jg== X-Gm-Message-State: AOJu0YwOOvuKykzec8geF3qSjNENShu6Mep2ACoS/ykKXFhcfRoM+Knj YH6EtlXC97GaIVtcSIGpdZh1O2SM+6sY5rHvzQiUN8dgMaMmY/tc0t1hZSLuuTzW29J05DDItSu 7 X-Google-Smtp-Source: AGHT+IHg0ja9QNxUZ4tZIEtdCtUnugpmjWlFsHvFvUqEWr/jij87LRHqfv+lw7XDsHJoaVUXh8EXFg== X-Received: by 2002:a17:907:7f1e:b0:a9f:508:6726 with SMTP id a640c23a62f3a-aa4833f60eemr182698766b.2.1731671597758; Fri, 15 Nov 2024 03:53:17 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD , "Daniel P. Smith" Subject: [RFC PATCH 22/25] tools/xen-sys: Add autogenerated Rust files Date: Fri, 15 Nov 2024 11:51:51 +0000 Message-ID: <20241115115200.2824-23-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 And a single autogen.rs file to demultiplex the arch module into whatever arch-specific target is mandated by target_arch. Signed-off-by: Alejandro Vallejo --- tools/rust/xen-sys/src/autogen.rs | 27 +++++ tools/rust/xen-sys/src/autogen/arch_arm.rs | 56 ++++++++++ tools/rust/xen-sys/src/autogen/arch_ppc.rs | 8 ++ tools/rust/xen-sys/src/autogen/arch_riscv.rs | 8 ++ tools/rust/xen-sys/src/autogen/arch_x86.rs | 55 ++++++++++ tools/rust/xen-sys/src/autogen/domctl.rs | 104 +++++++++++++++++++ tools/rust/xen-sys/src/autogen/sysctl.rs | 26 +++++ tools/rust/xen-sys/src/lib.rs | 2 + 8 files changed, 286 insertions(+) create mode 100644 tools/rust/xen-sys/src/autogen.rs create mode 100644 tools/rust/xen-sys/src/autogen/arch_arm.rs create mode 100644 tools/rust/xen-sys/src/autogen/arch_ppc.rs create mode 100644 tools/rust/xen-sys/src/autogen/arch_riscv.rs create mode 100644 tools/rust/xen-sys/src/autogen/arch_x86.rs create mode 100644 tools/rust/xen-sys/src/autogen/domctl.rs create mode 100644 tools/rust/xen-sys/src/autogen/sysctl.rs diff --git a/tools/rust/xen-sys/src/autogen.rs b/tools/rust/xen-sys/src/autogen.rs new file mode 100644 index 000000000000..8a1cab8561f2 --- /dev/null +++ b/tools/rust/xen-sys/src/autogen.rs @@ -0,0 +1,27 @@ +//! Low-level description of buffers as used in hypercalls with the Xen hypervisor +//! +//! This module is fully autogenerated from TOML files defining the hypercall +//! specification. + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +pub mod arch_x86; +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +pub use arch_x86 as arch; + +#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +pub mod arch_arm; +#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +pub use arch_arm as arch; + +#[cfg(target_arch = "riscv64")] +pub mod arch_riscv; +#[cfg(target_arch = "riscv64")] +pub use arch_riscv as arch; + +#[cfg(target_arch = "powerpc64")] +pub mod arch_ppc; +#[cfg(target_arch = "powerpc64")] +pub use arch_ppc as arch; + +pub mod domctl; +pub mod sysctl; diff --git a/tools/rust/xen-sys/src/autogen/arch_arm.rs b/tools/rust/xen-sys/src/autogen/arch_arm.rs new file mode 100644 index 000000000000..dc460557b2f0 --- /dev/null +++ b/tools/rust/xen-sys/src/autogen/arch_arm.rs @@ -0,0 +1,56 @@ +//! arch-arm +//! +//! AUTOGENERATED. DO NOT MODIFY + +/// Content of the `gic_version` field of the domainconfig struct. +#[repr(u8)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub enum XenDomctlConfigGic { + /// Emulate the underlying GIC present in the current host. + #[default] + Native = 0, + /// Emulate a GICv2. + V2 = 1, + /// Emulate a GICv3. + V3 = 2, +} + +/// TEE mediator exposed to the guest +#[repr(u16)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub enum XenDomctlConfigTee { + /// No mediator. Guest can't communicate with the TEE. + #[default] + None = 0, + /// Expose an OP-TEE mediator. + Optee = 1, + /// Expose an FF-A mediator. + Ffa = 2, +} + +/// arm-specific domain settings. +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct XenArchDomainconfig { + /// IN/OUT: GIC version exposed to the guest. + /// + /// When `native` on input the output value holds the automatically chosen version. + pub gic_version: XenDomctlConfigGic, + /// IN: SVE vector length (divided by 128) exposed to the guest. + pub sve_vl: u8, + /// IN: TEE mediator exposed to the guest. + pub tee_type: XenDomctlConfigTee, + /// IN: Number of SPIs exposed to the guest. + pub nr_spis: u32, + /// OUT + /// Based on the property clock-frequency in the DT timer node. + /// The property may be present when the bootloader/firmware doesn't + /// set correctly CNTFRQ which hold the timer frequency. + /// + /// As it's not possible to trap this register, we have to replicate + /// the value in the guest DT. + /// + /// = 0 => property not present + /// > 0 => Value of the property + pub clock_frequency: u32, +} diff --git a/tools/rust/xen-sys/src/autogen/arch_ppc.rs b/tools/rust/xen-sys/src/autogen/arch_ppc.rs new file mode 100644 index 000000000000..8b68799648b9 --- /dev/null +++ b/tools/rust/xen-sys/src/autogen/arch_ppc.rs @@ -0,0 +1,8 @@ +//! arch-ppc +//! +//! AUTOGENERATED. DO NOT MODIFY + +/// ppc-specific domain settings. +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct XenArchDomainconfig; diff --git a/tools/rust/xen-sys/src/autogen/arch_riscv.rs b/tools/rust/xen-sys/src/autogen/arch_riscv.rs new file mode 100644 index 000000000000..1a68c7a02c7f --- /dev/null +++ b/tools/rust/xen-sys/src/autogen/arch_riscv.rs @@ -0,0 +1,8 @@ +//! arch-riscv +//! +//! AUTOGENERATED. DO NOT MODIFY + +/// riscv-specific domain settings. +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct XenArchDomainconfig; diff --git a/tools/rust/xen-sys/src/autogen/arch_x86.rs b/tools/rust/xen-sys/src/autogen/arch_x86.rs new file mode 100644 index 000000000000..d63a3920c91e --- /dev/null +++ b/tools/rust/xen-sys/src/autogen/arch_x86.rs @@ -0,0 +1,55 @@ +//! arch-x86 +//! +//! AUTOGENERATED. DO NOT MODIFY + +use bitflags::bitflags; + +bitflags! { + /// Content of the `emulation_flags` field of the domain creation hypercall. + #[repr(C)] + #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] + pub struct XenX86Emu: u32 { + /// Emulate Local APICs. + const Lapic = 1 << 0; + /// Emulate a HPET timer. + const Hpet = 1 << 1; + /// Emulate the ACPI PM timer. + const Pm = 1 << 2; + /// Emulate the RTC clock. + const Rtc = 1 << 3; + /// Emulate an IOAPIC device. + const Ioapic = 1 << 4; + /// Emulate PIC devices. + const Pic = 1 << 5; + /// Emulate standard VGA. + const Vga = 1 << 6; + /// Emulate an IOMMU. + const Iommu = 1 << 7; + /// Emulate a PIT timer. + const Pit = 1 << 8; + /// Route physical IRQs over event channels. + const UsePirq = 1 << 9; + /// Handle PCI configuration space traps from within Xen. + const Vpci = 1 << 10; + } +} + +bitflags! { + /// Contents of the `misc_flags` field of the domain creation hypercall + #[repr(C)] + #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] + pub struct XenX86Misc: u32 { + /// Grants access to the real physical MSR registers of the host. + const MsrRelaxed = 1 << 0; + } +} + +/// x86-specific domain settings. +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct XenArchDomainconfig { + /// IN: Bitmap of devices to emulate. + pub emulation_flags: XenX86Emu, + /// IN: Miscellaneous x86-specific toggles. + pub misc_flags: XenX86Misc, +} diff --git a/tools/rust/xen-sys/src/autogen/domctl.rs b/tools/rust/xen-sys/src/autogen/domctl.rs new file mode 100644 index 000000000000..7c3b872409be --- /dev/null +++ b/tools/rust/xen-sys/src/autogen/domctl.rs @@ -0,0 +1,104 @@ +//! domctl +//! +//! AUTOGENERATED. DO NOT MODIFY + +use bitflags::bitflags; + +use super::arch::XenArchDomainconfig; + +bitflags! { + /// Content of the `flags` field of the domain creation hypercall. + #[repr(C)] + #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] + pub struct XenDomctlCdf: u32 { + /// Set if this is an HVM guest. Cleared if it's PV. + const Hvm = 1 << 0; + /// Use hardware-assisted paging if available + const Hap = 1 << 1; + /// Set if domain memory integrity is to be verified by tboot during Sx. + const S3Integrity = 1 << 2; + /// Set if Out-of-Sync shadow page tables are to be disabled + const OosOff = 1 << 3; + /// Set if this is a xenstore domain + const XsDomain = 1 << 4; + /// Set if this is domain can make use of the IOMMU + const Iommu = 1 << 5; + /// Set for the domain to have nested virtualization enabled. + const NestedVirt = 1 << 6; + /// Set to expose a vPMU to this domain. + const Vpmu = 1 << 7; + } +} + +bitflags! { + /// Content of the `iommu_opts` field of the domain creation hypercall. + #[repr(C)] + #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] + pub struct XenDomctlIommuOpts: u32 { + /// Set to _NOT_ share page tables between the CPU and the IOMMU when it would be possible to do so. + const NoSharept = 1 << 0; + } +} + +/// Content of the `altp2m_mode` field of the domain creation hypercall. +#[repr(u8)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub enum XenDomctlAltp2MMode { + /// Keep altp2m disabled + #[default] + Disabled = 0, + /// Use mixed-mode for the altp2m (not yet evaluated for safety). + Mixed = 1, + /// Use external mode for the altp2m. + External = 2, + /// Use limited mode for the altp2m. + Limited = 3, +} + +/// Create a new domain with the passed parameters. +/// +/// IMPORTANT: The domid part of the domctl is IN/OUT. When the passed +/// domid is 0 or over `DOMID_FIRST_RESERVED` a new domid is auto-allocated +/// and returned. +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct XenDomctlCreatedomain { + /// IN: `Source Security IDentifier` (See XSM). + pub ssidref: u32, + /// IN: Unique identifier for this guest given by the toolstack. + pub handle: [u8; 16], + /// IN: Bitmap of domain features to enable/disable. + pub flags: XenDomctlCdf, + /// IN: Bitmap of configuration settings for the IOMMU. + pub iommu_opts: XenDomctlIommuOpts, + /// IN: Maximum number of CPUs this domain can hold, including hotplug. + pub max_vcpus: u32, + /// IN: Maximum number of usable event channels + pub max_evtchn_port: u32, + /// IN: Maximum number of pages this domain is able + /// to grant access to for other domains. + /// + /// `< 0` means "use default value in the hypervisor." + pub max_grant_frames: i32, + /// IN: Maximum number of pages of foreign domains + /// can be accessed via the grant mechanism. + /// + /// `< 0` means "use default value in the hypervisor." + pub max_maptrack_frames: i32, + /// Maximum grant table version allowed for this domain + pub max_grant_version: u8, + /// Unused padding. Reserved to zero. + pub rsvd_0_a: [u8; 3], + /// Which mode to configure altp2m with + pub altp_2_m_mode: u8, + /// Unused padding. Reserved to zero. + pub rsvd_0_b: [u8; 3], + /// IN: Per-vCPU buffer size in octets. 0 to disable. + pub vmtrace_size: u32, + /// IN: CPU pool to use; 0 or an existing CPU pool. + pub cpupool_id: u32, + /// Arch-specific settings. + /// + /// Each architecture is free to make its fields IN/OUT/INOUT + pub arch: XenArchDomainconfig, +} diff --git a/tools/rust/xen-sys/src/autogen/sysctl.rs b/tools/rust/xen-sys/src/autogen/sysctl.rs new file mode 100644 index 000000000000..a2d8beb91d84 --- /dev/null +++ b/tools/rust/xen-sys/src/autogen/sysctl.rs @@ -0,0 +1,26 @@ +//! sysctl +//! +//! AUTOGENERATED. DO NOT MODIFY + +/// Read console content from Xen buffer ring. +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct XenSysctlReadconsole { + /// IN: Non-zero -> clear after reading. + pub clear: u8, + /// IN: Non-zero -> start index specified by `index` field. + pub incremental: u8, + /// Unused. + pub pad: u16, + /// IN: Start index for consuming from ring buffer (if @incremental); + /// OUT: End index after consuming from ring buffer. + pub index: u32, + /// IN: Virtual address to write console data. + /// + /// NOTE: The pointer itself is IN, but the contents of the buffer are OUT. + pub buffer: crate::Align64<*mut u8>, + /// IN: Size of buffer; OUT: Bytes written to buffer. + pub count: u32, + /// Tail padding reserved to zero. + pub rsvd_0_a: u32, +} diff --git a/tools/rust/xen-sys/src/lib.rs b/tools/rust/xen-sys/src/lib.rs index efab54ee1025..526193a920f8 100644 --- a/tools/rust/xen-sys/src/lib.rs +++ b/tools/rust/xen-sys/src/lib.rs @@ -7,6 +7,8 @@ pub mod autogen; +pub use autogen::*; + use core::ops::{Deref, DerefMut}; /// Wrapper for pointers and 64bit integers so they are _always_ aligned to 8 From patchwork Fri Nov 15 11:51:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8519D6DDED for ; Fri, 15 Nov 2024 12:01:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837296.1253292 (Exim 4.92) (envelope-from ) id 1tBv1C-0001Or-97; Fri, 15 Nov 2024 12:01:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837296.1253292; Fri, 15 Nov 2024 12:01:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBv1C-0001Ok-6V; Fri, 15 Nov 2024 12:01:42 +0000 Received: by outflank-mailman (input) for mailman id 837296; Fri, 15 Nov 2024 12:01:41 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tButB-0005UF-NF for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:25 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 350c12ee-a348-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 12:53:20 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a9a850270e2so324784966b.0 for ; Fri, 15 Nov 2024 03:53:20 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:18 -0800 (PST) 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: 350c12ee-a348-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzYiLCJoZWxvIjoibWFpbC1lajEteDYzNi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjM1MGMxMmVlLWEzNDgtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjcxNjAwLjA4ODQ4NSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671599; x=1732276399; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5TtGZQt/o/0voOaBWuW5frWebRPJ5tcYXUj7qWmm5UM=; b=cByWrLaV4JZ+ej7rI5qyHE/Jj5wvQ8+cyeb2H/byDHR97euSJeHkIipRqL+JBhwJeW WGRfD1Zy83Sv2j9oibcdcW4M8SciMYtaM0NNhGGBM/CYVSZags2rUUcyn2CE4Ws8pHtl WT9PaZXP7pGjSjRFrBRRqGEKlzOYMRwdvDmwE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671599; x=1732276399; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5TtGZQt/o/0voOaBWuW5frWebRPJ5tcYXUj7qWmm5UM=; b=aSYzGy+3xjSKx4Nqq7lg9l8EfpcLhJHPbStjGTxY/dQhMtsr8j4/0Z2nSP1sFwTWYy 2aZ1gXYk2u15zp+nhul19D0YI9Jsj9hGHPKTwFrXtkLXUNbwwjr5v4+qOqxkw+nCyvLa 2/j8vOLCHP14YkP+SD1dZdJioyjqi1150+F1qE+xOms40b8MdIhJ06Y/UKyg6f9I0foD 2MPFlOJrC9KsaSXnvkZ6sAuGhQxSZOPt4i2Z6ZkQyvXBbr9PKxMrz7VxCpHAxUyOc7uK CupBQecGM9tMlB40SNWHrzfWEbqZS9RaC/xdhmcXmNWlbRBwFaLQlC+nhgKt+mlpiVC6 mHFA== X-Gm-Message-State: AOJu0YzdRsFHSKCeF4G3kucaPWEi+1mPNDWD5e8tj0MXNtzmkDpObU8I 31xUVee/px5zKgE9ZjgnXNWxaOuaP1HnVGej3urVQ/H7ONnpAx61T2AfSlOpLjB8QhFb3BtHek7 x X-Google-Smtp-Source: AGHT+IHqwuL6u7ZjChl11XwFW1ENcCh75yYnxH+6nO4Gf2UMXhuGEEd24iwFQNwokjSfqH88fD717Q== X-Received: by 2002:a17:907:9802:b0:a9a:1778:7024 with SMTP id a640c23a62f3a-aa483421c64mr210075266b.20.1731671598808; Fri, 15 Nov 2024 03:53:18 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [RFC PATCH 23/25] licence: Add Unicode-DFS-2016 to the list of licences Date: Fri, 15 Nov 2024 11:51:52 +0000 Message-ID: <20241115115200.2824-24-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 It's transitively reached by Rust code. Signed-off-by: Alejandro Vallejo --- LICENSES/Unicode-DFS-2016 | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 LICENSES/Unicode-DFS-2016 diff --git a/LICENSES/Unicode-DFS-2016 b/LICENSES/Unicode-DFS-2016 new file mode 100644 index 000000000000..eca277f05e0e --- /dev/null +++ b/LICENSES/Unicode-DFS-2016 @@ -0,0 +1,56 @@ +UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE + +See Terms of Use for definitions of Unicode Inc.'s Data Files and Software. + +Unicode Data Files include all data files under the directories +http://www.unicode.org/Public/, http://www.unicode.org/reports/, +http://www.unicode.org/cldr/data/, http://source.icu-project.org/repos/icu/, +http://www.unicode.org/ivd/data/, and +http://www.unicode.org/utility/trac/browser/. + +Unicode Data Files do not include PDF online code charts under the directory +http://www.unicode.org/Public/. + +Software includes any source code published in the Unicode Standard or under +the directories http://www.unicode.org/Public/, +http://www.unicode.org/reports/, http://www.unicode.org/cldr/data/, +http://source.icu-project.org/repos/icu/, and +http://www.unicode.org/utility/trac/browser/. + +NOTICE TO USER: Carefully read the following legal agreement. BY DOWNLOADING, +INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S DATA FILES ("DATA +FILES"), AND/OR SOFTWARE ("SOFTWARE"), YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO +BE BOUND BY, ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT +AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR +SOFTWARE. + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 1991-2016 Unicode, Inc. All rights reserved. Distributed under the +Terms of Use in http://www.unicode.org/copyright.html. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of the Unicode data files and any associated documentation (the "Data Files") +or Unicode software and any associated documentation (the "Software") to deal +in the Data Files or Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, and/or +sell copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either + + * (a) this copyright and permission notice appear with all copies of the Data Files or Software, or + * (b) this copyright and permission notice appear in associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD +PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN +THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL +DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE +DATA FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall not +be used in advertising or otherwise to promote the sale, use or other dealings +in these Data Files or Software without prior written authorization of the +copyright holder. From patchwork Fri Nov 15 11:51:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 403B7D6DDF2 for ; Fri, 15 Nov 2024 12:06:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837404.1253352 (Exim 4.92) (envelope-from ) id 1tBv5M-0006RV-72; Fri, 15 Nov 2024 12:06:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837404.1253352; Fri, 15 Nov 2024 12:06:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBv5M-0006RK-3T; Fri, 15 Nov 2024 12:06:00 +0000 Received: by outflank-mailman (input) for mailman id 837404; Fri, 15 Nov 2024 12:05:58 +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 1tButA-0005U9-Rc for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:24 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 359f7a9b-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:20 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aaddeso2095185a12.2 for ; Fri, 15 Nov 2024 03:53:20 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:19 -0800 (PST) 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: 359f7a9b-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzUiLCJoZWxvIjoibWFpbC1lZDEteDUzNS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjM1OWY3YTliLWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNjAwLjYxMTAxNywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671600; x=1732276400; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zTdZvHzMqCg672JmJfQu/BpWmdmI7oAFHqt1BwWMkes=; b=fzGUhy4CsqblxfQY2kS/RzohNmwI37bz2LSkhCN8z66Ll7PCVZw04rUzqrmOlCJH0j brKfPKRhCFOjUgF/ohsTaVMLNpnqQW80WPVrluxdGzxHUhuAZcCXKybi7SG6nTjI9Gjn 1ATLGv8SA7dWoV6NXgQQTBdUx2mhKebvXijMQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671600; x=1732276400; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zTdZvHzMqCg672JmJfQu/BpWmdmI7oAFHqt1BwWMkes=; b=jQgHi7WPno1Vm2uYmISqnFpxflF8rPPc17ZpNmHB5ul0EkIfwPqq+hz1eTK+K0RH4r EbQqFZFXC2cmysWPr2h8tF683Li4bNp+9l6Eeoz1/8EWs+lWsU/s4U3GwIBlaW9ZDpe+ DDrZAeLK/Ncg0aOsyadVNP6q2A1avc3YCUpXSTJ4kCcS7dxyvrtm4UVXUiLfoFUtaak/ tezZWNLw59zxpk3xDhRIhssqXJnUEkE9W3egFtdPphtdDY0JAY8TXHWsEgU4kv+Niz9x KKzPw5ioZ3liGCDaBfe6gNSQk5/KpPMj/j0y9dV/YLy3xFNxeah9lfvzaocfru9K+ye2 gB5Q== X-Gm-Message-State: AOJu0Yw8tmsFRJuX/OTPaWH+84uzR+S56ki1rjajR7+/EeV6mIdeWvAQ CAmcRnU694Z26nTRltA8w1ptyWF0aY83fJ+eG0Gkf0nFiolozde1/nRb4bpH36cIMiVWGjdJWVp X X-Google-Smtp-Source: AGHT+IE8XiJ8tp24GnfdR7Je8BJiINigYyfTk7VwSyv6r7upQwl+mJmJWXsPnxmN/u71KRrKVPKOmQ== X-Received: by 2002:a17:907:1c85:b0:a9e:c442:2c15 with SMTP id a640c23a62f3a-aa483525ba6mr224027166b.38.1731671599630; Fri, 15 Nov 2024 03:53:19 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Anthony PERARD Subject: [RFC PATCH 24/25] tools/rust: Add deny.toml Date: Fri, 15 Nov 2024 11:51:53 +0000 Message-ID: <20241115115200.2824-25-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 deny.toml allows auditing transitive dependencies and allowed licences. In particular it allows the use of cargo-deny for all Rust project. Signed-off-by: Alejandro Vallejo --- tools/rust/deny.toml | 236 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 tools/rust/deny.toml diff --git a/tools/rust/deny.toml b/tools/rust/deny.toml new file mode 100644 index 000000000000..1b74553569a7 --- /dev/null +++ b/tools/rust/deny.toml @@ -0,0 +1,236 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# The graph table configures how the dependency graph is constructed and thus +# which crates the checks are performed against +[graph] +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #"x86_64-unknown-linux-musl", + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] + +# The output table provides options for how/if diagnostics are outputted +[output] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +# The path where the advisory databases are cloned/fetched into +#db-path = "$CARGO_HOME/advisory-dbs" +# The url(s) of the advisory databases to use +#db-urls = ["https://github.com/rustsec/advisory-db"] +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", + #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, + #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish + #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, +] +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "MIT", + "Apache-2.0", + "Unicode-DFS-2016", + #"Apache-2.0 WITH LLVM-exception", +] +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], crate = "adler32" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The package spec the clarification applies to +#crate = "ring" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ +# Each entry is a crate relative path, and the (opaque) hash of its contents +#{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "deny" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, +] +# List of crates to deny +deny = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#crate = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #"ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies + #{ crate = "ansi_term@0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "deny" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "deny" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# 1 or more github.com organizations to allow git sources for +#github = [""] +# 1 or more gitlab.com organizations to allow git sources for +#gitlab = [""] +# 1 or more bitbucket.org organizations to allow git sources for +#bitbucket = [""] From patchwork Fri Nov 15 11:51:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13876157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A748FD6DDF2 for ; Fri, 15 Nov 2024 12:03:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837329.1253321 (Exim 4.92) (envelope-from ) id 1tBv2c-0003Jh-6y; Fri, 15 Nov 2024 12:03:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837329.1253321; Fri, 15 Nov 2024 12:03:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBv2c-0003Ja-4I; Fri, 15 Nov 2024 12:03:10 +0000 Received: by outflank-mailman (input) for mailman id 837329; Fri, 15 Nov 2024 12:03:08 +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 1tButA-0005U9-Jt for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 11:53:24 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 36227785-a348-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 12:53:21 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a9a850270e2so324790366b.0 for ; Fri, 15 Nov 2024 03:53:21 -0800 (PST) Received: from localhost.localdomain (0545937c.skybroadband.com. [5.69.147.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0860afsm173492766b.188.2024.11.15.03.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 03:53:20 -0800 (PST) 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: 36227785-a348-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzQiLCJoZWxvIjoibWFpbC1lajEteDYzNC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjM2MjI3Nzg1LWEzNDgtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjcxNjAxLjQ2MTAwMywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1731671601; x=1732276401; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iI58YlmX6WMPh6dl0fn6iaDnb6hEIyQ+Q00IE22iGr8=; b=Zc7o1mppYx+KTQSxfzWrOXp815wyxLTVbTQFYABYgWDPdBk7AIePsJCdSM1GhBK8NG l9EWhUgfJNT5pTfwAvrzv2XfvBYMMd0otAj9hwwgknLKgTqKi7+zXHEhXMrBDz51w6m7 DKPO5I0U3esLn1at1QIUn2EdfOct1G6giC/YQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731671601; x=1732276401; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iI58YlmX6WMPh6dl0fn6iaDnb6hEIyQ+Q00IE22iGr8=; b=jRn2+kPYgS4aOpcUxYu/yxsvMBMXkw7Xqf+/A9Im4eLZaPFKb4XSW2S8IieDe48UCy nQaUgmTwlpNPuvjfOpyCp3M83xCTBgkd8FCXBGkTsx1jLpH1lj2FB30X4zvI6bLHM9Pf JwQPL+HAOvzJlm2Al3M//CUO6nh5n81To+zAxI9vg459d8oYwbxdKPbAHdzhmoBWiyCm wzXgMarr1RDyfkVwS7YjKEVd/GYNJswEY5iWXLZLijOIfYItnnI3I9aHHaaFZRaZbPDl yymK+v9yCu6sZsqmiuSxwAzpmw2SdORPE//jfowWkN/KAJCX1Q9yiwdtzYCM2k8zhXUF NkFg== X-Gm-Message-State: AOJu0YyKoZ7DJfJnnB736Yawriq4aAsrn2YbR22Fbz9oVPH9HVnE/BZX 2U9PunFWlz9+auqYa0x21N+7dgtzBamyeCcXod8Dpd02WydqUUTl4UpfjDhGs+Lt46FFyZ6XORW a X-Google-Smtp-Source: AGHT+IHEjkBMpMN9NNeDK3YMv4dvAvN0GFdxsCjFCE6bcbGg6VuZ6UwEEudgdftQtP4K/TH6K1uXmg== X-Received: by 2002:a17:907:2d91:b0:a9e:b68e:909 with SMTP id a640c23a62f3a-aa4834212e5mr175722966b.15.1731671600580; Fri, 15 Nov 2024 03:53:20 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Doug Goldstein , Stefano Stabellini , Anthony PERARD Subject: [RFC PATCH 25/25] ci: Add a CI checker for Rust-related helpful properties Date: Fri, 15 Nov 2024 11:51:54 +0000 Message-ID: <20241115115200.2824-26-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115115200.2824-1-alejandro.vallejo@cloud.com> References: <20241115115200.2824-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Checks in both xenbindgen and xen-sys (including autogenerated headers) that: * Autogenerated files are in sync with the specification files. * Specification files abide by certain ABI rules (e.g: no padding). * Clippy and rustfmt are happy with the every .rs file. * All transitive licences are accounted for (cargo-deny). * No transitive dependency has outstanding security advisories (cargo-deny) Signed-off-by: Alejandro Vallejo --- automation/gitlab-ci/analyze.yaml | 14 ++++++++++++++ tools/rust/Makefile | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/automation/gitlab-ci/analyze.yaml b/automation/gitlab-ci/analyze.yaml index 02e0ea692c66..c63c909fe175 100644 --- a/automation/gitlab-ci/analyze.yaml +++ b/automation/gitlab-ci/analyze.yaml @@ -72,3 +72,17 @@ eclair-ARM64:on-schedule: ANALYSIS_KIND: "${RULESET}-scheduled" LOGFILE: "eclair-${VARIANT}-${RULESET}.log" allow_failure: true + +rust-verify: + stage: analyze + image: rust:latest # FIXME: Create and use dedicated container + script: + - rustup component add clippy rustfmt + - cargo install cargo-deny + - make -C tools/rust verify 2>&1 | tee rust-verify.log + artifacts: + when: always + paths: + - '*.log' + needs: [] + diff --git a/tools/rust/Makefile b/tools/rust/Makefile index 4f064c37f45c..602722f9d9cc 100644 --- a/tools/rust/Makefile +++ b/tools/rust/Makefile @@ -45,8 +45,33 @@ update: clean-autogen --indir "${XENBINDGEN}/extra" --outdir "${AUTOGEN_C}" # Verify Rust crates pass lint checks. This is enforced in CI +# +# Also ensures autogenerated files are up to date with TOML files. Generation +# is done at commit time rather than build time to avoid a hard dependency on +# the Rust toolchain. .PHONY: verify verify: + @echo "Checking autogenerated C headers to be consistent with TOML" + OUTDIR=`mktemp -d /tmp/xenbindgen-XXXXXXX`; \ + cargo run --manifest-path "${XENBINDGEN}/Cargo.toml" -- --lang c \ + --indir "${XENBINDGEN}/extra" --outdir "$${OUTDIR}"; \ + if ! diff -r "$${OUTDIR}" "${AUTOGEN_C}"; then \ + rm -rf "$${OUTDIR}"; \ + exit 1; \ + fi; \ + rm -rf "$${OUTDIR}" + + @echo "Checking autogenerated Rust files to be consistent with TOML" + OUTDIR=`mktemp -d /tmp/xenbindgen-XXXXXXX`; \ + cargo run --manifest-path "${XENBINDGEN}/Cargo.toml" -- --lang rust \ + --indir "${XENBINDGEN}/extra" --outdir "$${OUTDIR}"; \ + rustfmt $$( find "$${OUTDIR}" -name "*.rs" ); \ + if ! diff -r "$${OUTDIR}" "${AUTOGEN_RS}"; then \ + rm -rf "$${OUTDIR}"; \ + exit 1; \ + fi; \ + rm -rf "$${OUTDIR}" + set -eu; \ for i in "${CRATE_XENSYS}" "${XENBINDGEN}"; do \ echo "Verifying $$i"; \ @@ -56,4 +81,3 @@ verify: cargo deny check; \ cd -; \ done -