From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741340; cv=none; d=zohomail.com; s=zohoarc; b=lkBbF+bUPseZHYE90509X0JI19Xtu/0mMKUrgLvJisXV8t3ac4+6Pf0POGivn1+3tQIKBgguHSFWqZH+AYsdSlvhfsVng3RSypvGeQQobCgjCLYCzWtFtpzIXcjtiPPHThXJIY6yMlEdXsbSwfhDkt4LffMXirT+X2BZ0Hs64Js= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741340; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G41Gm1r+0jL4g/l3GF6vapafdMpPd/OeL9O59Yu11q4=; b=kc2Fe78Hel5Zg6waMzXvobno+68+LX4q+xDuMp4fUzzRZX+6F9PAzoozd6WFo+bCN3BseDS+gmW7L448BHcI4Fyed4cyU6feEhLdHHzn8yW5AbzNsbmR7T5ixNtuOL6HFqIrG715lwzmHIIq+9dRu1b+Eab9lwyWvY2gzXEwFkc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741340209543.3786116043182; Mon, 4 Nov 2024 09:29:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rd-0004x4-9p; Mon, 04 Nov 2024 12:27:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rZ-0004ua-C1 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rV-0008WV-FJ for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:35 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-u0w2FweHMjGCnM4ZIG4QoQ-1; Mon, 04 Nov 2024 12:27:27 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43157cff1d1so33007565e9.2 for ; Mon, 04 Nov 2024 09:27:27 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10d40casm13763407f8f.27.2024.11.04.09.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G41Gm1r+0jL4g/l3GF6vapafdMpPd/OeL9O59Yu11q4=; b=A/FoQApo8Grux92CLl7o4LTWUyrxTDoYlG9nABC9yuxy+PmMQT2WqRcS/NM5MGgC5FUV1Z No42eM+NJWaFT/q/cHJtrPL8j+94IpveNEJAckUWP+HAargMZKNY5U/+zrTz7VLFd054Lk tesPAefPcOHjGY7uFjewyCU+TyeSM5E= X-MC-Unique: u0w2FweHMjGCnM4ZIG4QoQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741245; x=1731346045; 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=G41Gm1r+0jL4g/l3GF6vapafdMpPd/OeL9O59Yu11q4=; b=DApphZGjU76OmFKek01HHs1wOqnTu8TVx6y/ckX61mtazUA0DcI0QVVR0UD/IM25mZ rArH/HCPPQsduTJEJbW4pCmEUfk2U9Y/B2RwhP0V3BtWzXwMxHAKvG0qe4L5vwuYzZ7p tbki+iWLodpw6FR8XHPt+JBYBXI8nSH4n1ROgqx10+LO7fWIn5iC4lWN+saYGnIwpfTj /QH6cHSUjg/ZuZJbFA1KuLUv+ypkGZqkwGk1LPNHDFK7X5GNmG1GWZiuNMQVBvVMJRqh o/HYeKAdYiOmYal7J5DAyuLTwIl8uL8wOYRZZpUWBMXFd+xQvu5icS4lrWf2OQG31PFb Xxig== X-Gm-Message-State: AOJu0Yy2e8hhfl1l2ThUxjCKvvOtr9IXPSuhEeZzyOazjSMoc2F/1zN5 xcj8xAol2TRALf9XFzmU/HzfHe1DmdcW4GlrfzBIh+EQ4Z771wFVoX2nsrVvHskGNfQ6wMKbBD5 do+tXzXNU7FzFSlkUvUyY81VgioCRHBU2TGxl/xK+31GQ8eec/gZ/KTHwyZXsi7wvKGlsBCj+y6 5BqLhMiYi+VVw9+FOLQ4dtw1JPpAatJq2yg+v3MXk= X-Received: by 2002:a05:600c:1c26:b0:432:9fdb:1490 with SMTP id 5b1f17b1804b1-4329fdb1571mr13327515e9.7.1730741245437; Mon, 04 Nov 2024 09:27:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzz9GgleBcTafAicin2kz0iC+UtA+M7wUEwIO6MNw397w0/jl3xahcJZD/4DU2sTYCH3EtjQ== X-Received: by 2002:a05:600c:1c26:b0:432:9fdb:1490 with SMTP id 5b1f17b1804b1-4329fdb1571mr13327265e9.7.1730741245051; Mon, 04 Nov 2024 09:27:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 01/40] qdev: make properties array "const" Date: Mon, 4 Nov 2024 18:26:40 +0100 Message-ID: <20241104172721.180255-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741341749116600 Content-Type: text/plain; charset="utf-8" Constify all accesses to qdev properties, except for the ObjectPropertyAccessor itself. This makes it possible to place them in read-only memory, and also lets Rust bindings switch from "static mut" arrays to "static"; which is advantageous, because mutable statics are highly discouraged. Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- include/hw/qdev-core.h | 4 ++-- include/hw/qdev-properties.h | 4 ++-- hw/core/qdev-properties.c | 26 +++++++++++++------------- system/qdev-monitor.c | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index aa97c34a4be..f9fa291cc63 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -132,7 +132,7 @@ struct DeviceClass { * ensures a compile-time error if someone attempts to assign * dc->props directly. */ - Property *props_; + const Property *props_; =20 /** * @user_creatable: Can user instantiate with -device / device_add? @@ -935,7 +935,7 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState *b= us, DeviceState *dev); * you attempt to add an existing property defined by a parent class. * To modify an inherited property you need to use???? */ -void device_class_set_props(DeviceClass *dc, Property *props); +void device_class_set_props(DeviceClass *dc, const Property *props); =20 /** * device_class_set_parent_realize() - set up for chaining realize fns diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 09aa04ca1e2..26ebd230685 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -37,7 +37,7 @@ struct PropertyInfo { int (*print)(Object *obj, Property *prop, char *dest, size_t len); void (*set_default_value)(ObjectProperty *op, const Property *prop); ObjectProperty *(*create)(ObjectClass *oc, const char *name, - Property *prop); + const Property *prop); ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyRelease *release; @@ -223,7 +223,7 @@ void error_set_from_qdev_prop_error(Error **errp, int r= et, Object *obj, * On error, store error in @errp. Static properties access data in a str= uct. * The type of the QOM property is derived from prop->info. */ -void qdev_property_add_static(DeviceState *dev, Property *prop); +void qdev_property_add_static(DeviceState *dev, const Property *prop); =20 /** * qdev_alias_all_properties: Create aliases on source for all target prop= erties diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 86a583574dd..315196bd85a 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -749,7 +749,7 @@ const PropertyInfo qdev_prop_array =3D { =20 /* --- public helpers --- */ =20 -static Property *qdev_prop_walk(Property *props, const char *name) +static const Property *qdev_prop_walk(const Property *props, const char *n= ame) { if (!props) { return NULL; @@ -763,10 +763,10 @@ static Property *qdev_prop_walk(Property *props, cons= t char *name) return NULL; } =20 -static Property *qdev_prop_find(DeviceState *dev, const char *name) +static const Property *qdev_prop_find(DeviceState *dev, const char *name) { ObjectClass *class; - Property *prop; + const Property *prop; =20 /* device properties */ class =3D object_get_class(OBJECT(dev)); @@ -840,7 +840,7 @@ void qdev_prop_set_string(DeviceState *dev, const char = *name, const char *value) =20 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) { - Property *prop; + const Property *prop; =20 prop =3D qdev_prop_find(dev, name); object_property_set_str(OBJECT(dev), name, @@ -956,7 +956,7 @@ const PropertyInfo qdev_prop_size =3D { /* --- object link property --- */ =20 static ObjectProperty *create_link_property(ObjectClass *oc, const char *n= ame, - Property *prop) + const Property *prop) { return object_class_property_add_link(oc, name, prop->link_type, prop->offset, @@ -969,7 +969,7 @@ const PropertyInfo qdev_prop_link =3D { .create =3D create_link_property, }; =20 -void qdev_property_add_static(DeviceState *dev, Property *prop) +void qdev_property_add_static(DeviceState *dev, const Property *prop) { Object *obj =3D OBJECT(dev); ObjectProperty *op; @@ -980,7 +980,7 @@ void qdev_property_add_static(DeviceState *dev, Propert= y *prop) field_prop_getter(prop->info), field_prop_setter(prop->info), prop->info->release, - prop); + (Property *)prop); =20 object_property_set_description(obj, prop->name, prop->info->description); @@ -994,7 +994,7 @@ void qdev_property_add_static(DeviceState *dev, Propert= y *prop) } =20 static void qdev_class_add_property(DeviceClass *klass, const char *name, - Property *prop) + const Property *prop) { ObjectClass *oc =3D OBJECT_CLASS(klass); ObjectProperty *op; @@ -1007,7 +1007,7 @@ static void qdev_class_add_property(DeviceClass *klas= s, const char *name, field_prop_getter(prop->info), field_prop_setter(prop->info), prop->info->release, - prop); + (Property *)prop); } if (prop->set_default) { prop->info->set_default_value(op, prop); @@ -1046,7 +1046,7 @@ static void qdev_get_legacy_property(Object *obj, Vis= itor *v, * Do not use this in new code! QOM Properties added through this interfa= ce * will be given names in the "legacy" namespace. */ -static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop) +static void qdev_class_add_legacy_property(DeviceClass *dc, const Property= *prop) { g_autofree char *name =3D NULL; =20 @@ -1058,12 +1058,12 @@ static void qdev_class_add_legacy_property(DeviceCl= ass *dc, Property *prop) name =3D g_strdup_printf("legacy-%s", prop->name); object_class_property_add(OBJECT_CLASS(dc), name, "str", prop->info->print ? qdev_get_legacy_property : prop->info->get, - NULL, NULL, prop); + NULL, NULL, (Property *)prop); } =20 -void device_class_set_props(DeviceClass *dc, Property *props) +void device_class_set_props(DeviceClass *dc, const Property *props) { - Property *prop; + const Property *prop; =20 dc->props_ =3D props; for (prop =3D props; prop && prop->name; prop++) { diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 44994ea0e16..c346ea6ae4b 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -751,7 +751,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **er= rp) =20 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", #= # __VA_ARGS__) =20 -static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *pro= ps, +static void qdev_print_props(Monitor *mon, DeviceState *dev, const Propert= y *props, int indent) { if (!props) --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741297; cv=none; d=zohomail.com; s=zohoarc; b=V7EXP0I+nKqJd0P0csCFE5HZkXzdlLNg4HBfUeFAXRNopP33oe6tWubcTy4JMMypFUDaGKEhEdhC2mrtWwGuPpCq9pXbFf3Td8u1CbJai5Y5CFPHGXt1a9x19oDnOEF6oHfrCFtrpyITEmyh7egYXAWvXLyaQ4rrfLYp/aCElhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741297; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q8T5ohAzgqW97P1xGHDRejf6Ns5stLHojZxuqE9/t5s=; b=BdFO/PsE9ut39ud8gzqLUgLPnTZUeEviuGhTVqPKAstBrdAoW9KWyv+njnvkeEdnVTgVGChc9ZCQAJPEusOVLRdvDeImxtQpDar2VHacfwlRkvyhqb13IQekQEz5PqngpO5WytPbNKlyQsrKiXp1MJpqFv4zdO5gVYXVYDejfGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741297159390.66775592111435; Mon, 4 Nov 2024 09:28:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rf-0004zu-5p; Mon, 04 Nov 2024 12:27:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rc-0004wb-In for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rV-000059-HT for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:40 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-FF1ufoS8P5W7LyJrbyUlWA-1; Mon, 04 Nov 2024 12:27:29 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315544642eso32998025e9.3 for ; Mon, 04 Nov 2024 09:27:29 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5bf4fdsm158644275e9.17.2024.11.04.09.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q8T5ohAzgqW97P1xGHDRejf6Ns5stLHojZxuqE9/t5s=; b=H/PYl9AxS65mxzCGZcQaUpMR8Lc/N4cX4y9Ii6Q7QfVaIqVhHP/JLHdg8VqwDrROq8gFel cIpCxsg2sGV7s/uHEHFyIAk8DEZvbaoH1BSXKTDL1EeRfWlSM0Axe+KjZQkfzptSfaY4TL jvfuaPiFIC1ltA+rYSKNX2I5mSBr7Is= X-MC-Unique: FF1ufoS8P5W7LyJrbyUlWA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741247; x=1731346047; 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=q8T5ohAzgqW97P1xGHDRejf6Ns5stLHojZxuqE9/t5s=; b=l8lXyW+02AdR8mETh2oRmveqshsL5BjU464k9Fq03w2wwzUzNvx5jbTQrMYYJ5hqHD y/DBiKEMvFpW+pvxAZ+RLhYsLYyaEks0fc9CsxlLRKOXLCfk5YDaGRkaPLijVPYwGsht ZDRIG2KizHCXyq62gGNsfocEKAVCpOwB3D38Lu4NIpvqZVx291paSAPClGJi7sbsmMuL jBIzIJFdGBHGwp+r8jU4jM4skRcpkFPvJPSqiEm7NRzpTJrbmagnvcmdB+YZiWFAU3p1 /JFNSAMckpIhiMlSF9s7a6ok/tM7WTQsYcfHQSEoqbqMOwAbmmVYWeyHYqIzluJn/V4e gRbA== X-Gm-Message-State: AOJu0YxNZLmVjYDNl3Wv9Z+jMSYDo/wcsm8aw6YvhobeiVYcbo7RzCXZ 6pZhyf2cIGFm1A/ppJZinq4rhhMQOfv3gAaHm/cMnk2OxbdABEM/nN91ZxxUjpR2hy1Atwx+ubt qM+buNdPGWynYt7kw6WaVspw/q3/hftPjeAajFSnpV9wHYL15imlpWO2MAhXT5Xe24VpoQUduBm GPOCmuQy3z8vzrKXm446XamBSZrMo5u47RTWc6TnQ= X-Received: by 2002:a05:600c:3b14:b0:42c:de34:34c1 with SMTP id 5b1f17b1804b1-4327b6f9590mr141504765e9.2.1730741247601; Mon, 04 Nov 2024 09:27:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxd5enN/Bvknhn7HAAW4RU8c25hQFA1v7fX1FQJeiIBCFxwfDN0Yse7blmslwYiD8w6zWZzg== X-Received: by 2002:a05:600c:3b14:b0:42c:de34:34c1 with SMTP id 5b1f17b1804b1-4327b6f9590mr141504485e9.2.1730741247161; Mon, 04 Nov 2024 09:27:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 02/40] rust/wrapper.h: define memory_order enum Date: Mon, 4 Nov 2024 18:26:41 +0100 Message-ID: <20241104172721.180255-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741297495116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Add stub definition of memory_order enum in wrapper.h. Creating Rust bindings from C code is done by passing the wrapper.h header to `bindgen`. This fails when library dependencies that use compiler headers are enabled, and the libclang that bindgen detects does not match the expected clang version. So far this has only been observed with the memory_order enum symbols from stdatomic.h. If we add the enum definition to wrapper.h ourselves, the error does not happen. Before this commit, if the mismatch happened the following error could come up: /usr/include/liburing/barrier.h:72:10: error: use of undeclared identifie= r 'memory_order_release' /usr/include/liburing/barrier.h:75:9: error: use of undeclared identifier= 'memory_order_acquire' /usr/include/liburing/barrier.h:75:9: error: use of undeclared identifier= 'memory_order_acquire' /usr/include/liburing/barrier.h:68:9: error: use of undeclared identifier= 'memory_order_relaxed' /usr/include/liburing/barrier.h:65:17: error: use of undeclared identifie= r 'memory_order_relaxed' /usr/include/liburing/barrier.h:75:9: error: use of undeclared identifier= 'memory_order_acquire' /usr/include/liburing/barrier.h:75:9: error: use of undeclared identifier= 'memory_order_acquire' /usr/include/liburing/barrier.h:72:10: error: use of undeclared identifie= r 'memory_order_release' panicked at [..]/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bin= dgen-cli-0.70.1/main.rs:45:36: Unable to generate bindings To fix this (on my system) I would have to export CLANG_PATH and LIBCLANG_PATH: export CLANG_PATH=3D/bin/clang-17 export LIBCLANG_PATH=3D/usr/lib/llvm-17/lib With these changes applied, bindgen is successful with both the environment variables set and unset. Since we're not using those symbols in the bindings (they are only used by dependencies) this does not affect the generated bindings in any way. Signed-off-by: Manos Pitsidianakis Link: https://lore.kernel.org/r/20241027-rust-wrapper-stdatomic-v2-1-dab27b= bf93ea@linaro.org Signed-off-by: Paolo Bonzini --- rust/wrapper.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rust/wrapper.h b/rust/wrapper.h index 77e40213efb..285d0eb6ad0 100644 --- a/rust/wrapper.h +++ b/rust/wrapper.h @@ -30,6 +30,23 @@ * in order to generate C FFI compatible Rust bindings. */ =20 +#ifndef __CLANG_STDATOMIC_H +#define __CLANG_STDATOMIC_H +/* + * Fix potential missing stdatomic.h error in case bindgen does not insert= the + * correct libclang header paths on its own. We do not use stdatomic.h sym= bols + * in QEMU code, so it's fine to declare dummy types instead. + */ +typedef enum memory_order { + memory_order_relaxed, + memory_order_consume, + memory_order_acquire, + memory_order_release, + memory_order_acq_rel, + memory_order_seq_cst, +} memory_order; +#endif /* __CLANG_STDATOMIC_H */ + #include "qemu/osdep.h" #include "qemu/module.h" #include "qemu-io.h" --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741517; cv=none; d=zohomail.com; s=zohoarc; b=MxAvejYygsJroCX6k+Rw1EHJ/3fiphTUMtD41qO/HSRu5nwBRUwSoSSMByO9Mjkq2dnkorw/Zr5pcZ496f040ybpY0RrMWhtrtvTXKO244RlWJpWp6BM47vBsj5sYmkpGbbP1uoOBMT3dzcy/qg99tmO/vHL54kYObAdhFfQjoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741517; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pielT1Cidy6IyE3MSpt/7up90Oktd8lUQB1fEEvCFDA=; b=AtZXJuKVyyq1Xa1cUoGKkmm9+YwBSR7voZjhvPLpVYpaX+0bzmlQCjFa0YWvNbmaqEjU9l9wVKv7tz03AGLoCfNp9KOURNNedHGCxSjgpyjOEpOJhuXE0yL4c44GRb6F9UtDR3eqMwqBwcJyU9i7faOL7TK4IdH/AFWzWztb7Qk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741517251959.144743948279; Mon, 4 Nov 2024 09:31:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rh-00052E-Aw; Mon, 04 Nov 2024 12:27:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80re-0004yr-DK for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rZ-00006Y-1i for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:41 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81-5YqFGO3-Pcao0XsY6wdGYw-1; Mon, 04 Nov 2024 12:27:33 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315f48bd70so31844735e9.2 for ; Mon, 04 Nov 2024 09:27:32 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5e7c8bsm163493745e9.26.2024.11.04.09.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pielT1Cidy6IyE3MSpt/7up90Oktd8lUQB1fEEvCFDA=; b=TpzdiocRbFU3R/DIWqjxgO+nA4YNH17k0ord7Z5P2/PW3a2aiZjK9/afu7TfPRyYBUqVcN P10w07EhysrGgJ5IxS4+lH0dzoGLw9EcvHXqExL710EqEPdQ5S8/H/fwZzEhJa34+xB95k GbGKVLVDsrcKxOw4rSSid4ESL0Sil2Y= X-MC-Unique: 5YqFGO3-Pcao0XsY6wdGYw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741251; x=1731346051; 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=pielT1Cidy6IyE3MSpt/7up90Oktd8lUQB1fEEvCFDA=; b=NS902lqET17u016KqlED5pjDYnFj4fsEMia28RQpzji8RHB5XQMA5PpVu7wB/xauKr zbFhGujVBgf0KZ9AlQpGfpo8F7H8T45fNkyxKrQqBnv5Y2Ce7UwOJDeuFL/YIOWnOHIN C6QgB6jdQrQrlcYlubjPRBsyDOkomGAI/9/Dxxgras5wB03GacWwH/j60HMZyECAld3h 3vtEPEiyb9hkkz7sRd/jo3qb/6cqzYOksgigqc+r9NbGwvftRhSvp6gvlq4XP7rhPRN0 LVFBAjCg+JosjOQNFgqCeTiTXFzV4nwAWhfI5Xqvsr7AysenM0ZogZ3b7NUC+1PMN+Xa WHxw== X-Gm-Message-State: AOJu0YwoIrUv90xeIkC9/QIDcysN2ksxlGaKHNHGkIqTeMq6ijaYkQFy DjByfd0hMHI/yOIBZ8pDeECeXv7qGq5cyE0AyfGJqMQAD7u+1jQTFwIJTGggDpxaHSCWyY+wNy7 1XLfah/ADxEeJsuKWiYJgv5uX/bHEvn64NkJ4l80k6kj9iQxs8Sb4iKGn5Vn5SDNvgBOBwcr/is YVnIpo1VUWor4MaEpk1eg6F66jtdsYqrqoYWiEBd0= X-Received: by 2002:a05:600c:3b91:b0:431:57d2:d7b4 with SMTP id 5b1f17b1804b1-4327b7ea7c6mr155012555e9.26.1730741250484; Mon, 04 Nov 2024 09:27:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCP8qOi3tSb8SdLf4+TON6Z4j7msUHYSWwnNXnubO6t56I1er90sezVxg+wBhM8YvW3Oh6aA== X-Received: by 2002:a05:600c:3b91:b0:431:57d2:d7b4 with SMTP id 5b1f17b1804b1-4327b7ea7c6mr155011935e9.26.1730741249342; Mon, 04 Nov 2024 09:27:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 03/40] Revert "rust: add PL011 device model" Date: Mon, 4 Nov 2024 18:26:42 +0100 Message-ID: <20241104172721.180255-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741518582116600 From: Manos Pitsidianakis Patch was applied with invalid authorship by accident, which confuses git tooling that look at git blame for contributors etc. Patch will be re-applied with correct authorship right after this commit. This reverts commit d0f0cd5b1f7e9780753344548e17ad4df9fcf5d8. Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-1-051e7a25b978@lin= aro.org --- MAINTAINERS | 5 - meson.build | 24 - hw/arm/Kconfig | 30 +- rust/Kconfig | 1 - rust/hw/Kconfig | 2 - rust/hw/char/Kconfig | 3 - rust/hw/char/meson.build | 1 - rust/hw/char/pl011/.gitignore | 2 - rust/hw/char/pl011/Cargo.lock | 134 ---- rust/hw/char/pl011/Cargo.toml | 26 - rust/hw/char/pl011/README.md | 31 - rust/hw/char/pl011/meson.build | 26 - rust/hw/char/pl011/src/device.rs | 599 ------------------ rust/hw/char/pl011/src/device_class.rs | 70 -- rust/hw/char/pl011/src/lib.rs | 586 ----------------- rust/hw/char/pl011/src/memory_ops.rs | 59 -- rust/hw/meson.build | 1 - rust/meson.build | 2 - scripts/archive-source.sh | 4 +- scripts/make-release | 4 +- scripts/rust/rust_root_crate.sh | 13 - subprojects/.gitignore | 7 - subprojects/arbitrary-int-1-rs.wrap | 7 - subprojects/bilge-0.2-rs.wrap | 7 - subprojects/bilge-impl-0.2-rs.wrap | 7 - subprojects/either-1-rs.wrap | 7 - subprojects/itertools-0.11-rs.wrap | 7 - .../arbitrary-int-1-rs/meson.build | 19 - .../packagefiles/bilge-0.2-rs/meson.build | 29 - .../bilge-impl-0.2-rs/meson.build | 45 -- .../packagefiles/either-1-rs/meson.build | 24 - .../itertools-0.11-rs/meson.build | 30 - .../proc-macro-error-1-rs/meson.build | 40 -- .../proc-macro-error-attr-1-rs/meson.build | 32 - .../unicode-ident-1-rs/meson.build | 20 - subprojects/proc-macro-error-1-rs.wrap | 7 - subprojects/proc-macro-error-attr-1-rs.wrap | 7 - 37 files changed, 12 insertions(+), 1906 deletions(-) delete mode 100644 rust/hw/Kconfig delete mode 100644 rust/hw/char/Kconfig delete mode 100644 rust/hw/char/meson.build delete mode 100644 rust/hw/char/pl011/.gitignore delete mode 100644 rust/hw/char/pl011/Cargo.lock delete mode 100644 rust/hw/char/pl011/Cargo.toml delete mode 100644 rust/hw/char/pl011/README.md delete mode 100644 rust/hw/char/pl011/meson.build delete mode 100644 rust/hw/char/pl011/src/device.rs delete mode 100644 rust/hw/char/pl011/src/device_class.rs delete mode 100644 rust/hw/char/pl011/src/lib.rs delete mode 100644 rust/hw/char/pl011/src/memory_ops.rs delete mode 100644 rust/hw/meson.build delete mode 100755 scripts/rust/rust_root_crate.sh delete mode 100644 subprojects/arbitrary-int-1-rs.wrap delete mode 100644 subprojects/bilge-0.2-rs.wrap delete mode 100644 subprojects/bilge-impl-0.2-rs.wrap delete mode 100644 subprojects/either-1-rs.wrap delete mode 100644 subprojects/itertools-0.11-rs.wrap delete mode 100644 subprojects/packagefiles/arbitrary-int-1-rs/meson.build delete mode 100644 subprojects/packagefiles/bilge-0.2-rs/meson.build delete mode 100644 subprojects/packagefiles/bilge-impl-0.2-rs/meson.build delete mode 100644 subprojects/packagefiles/either-1-rs/meson.build delete mode 100644 subprojects/packagefiles/itertools-0.11-rs/meson.build delete mode 100644 subprojects/packagefiles/proc-macro-error-1-rs/meson.bu= ild delete mode 100644 subprojects/packagefiles/proc-macro-error-attr-1-rs/mes= on.build delete mode 100644 subprojects/packagefiles/unicode-ident-1-rs/meson.build delete mode 100644 subprojects/proc-macro-error-1-rs.wrap delete mode 100644 subprojects/proc-macro-error-attr-1-rs.wrap diff --git a/MAINTAINERS b/MAINTAINERS index f48d9142b8a..3f17295d41e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1138,11 +1138,6 @@ F: include/hw/*/microbit*.h F: tests/qtest/microbit-test.c F: docs/system/arm/nrf.rst =20 -ARM PL011 Rust device -M: Manos Pitsidianakis -S: Maintained -F: rust/hw/char/pl011/ - AVR Machines ------------- =20 diff --git a/meson.build b/meson.build index f7d45175212..f290bb70b1d 100644 --- a/meson.build +++ b/meson.build @@ -3534,7 +3534,6 @@ qom_ss =3D ss.source_set() system_ss =3D ss.source_set() specific_fuzz_ss =3D ss.source_set() specific_ss =3D ss.source_set() -rust_devices_ss =3D ss.source_set() stub_ss =3D ss.source_set() trace_ss =3D ss.source_set() user_ss =3D ss.source_set() @@ -4082,29 +4081,6 @@ foreach target : target_dirs arch_srcs +=3D target_specific.sources() arch_deps +=3D target_specific.dependencies() =20 - if have_rust and have_system - target_rust =3D rust_devices_ss.apply(config_target, strict: false) - crates =3D [] - foreach dep : target_rust.dependencies() - crates +=3D dep.get_variable('crate') - endforeach - if crates.length() > 0 - rlib_rs =3D custom_target('rust_' + target.underscorify() + '.rs', - output: 'rust_' + target.underscorify() + '.= rs', - command: [find_program('scripts/rust/rust_ro= ot_crate.sh')] + crates, - capture: true, - build_by_default: true, - build_always_stale: true) - rlib =3D static_library('rust_' + target.underscorify(), - rlib_rs, - dependencies: target_rust.dependencies(), - override_options: ['rust_std=3D2021', 'build.r= ust_std=3D2021'], - rust_args: rustc_args, - rust_abi: 'c') - arch_deps +=3D declare_dependency(link_whole: [rlib]) - endif - endif - # allow using headers from the dependencies but do not include the sourc= es, # because this emulator only needs those in "objects". For external # dependencies, the full dependency is included below in the executable. diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index e7fd9338d11..53eb7bb3d01 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -20,8 +20,7 @@ config ARM_VIRT select PCI_EXPRESS select PCI_EXPRESS_GENERIC_BRIDGE select PFLASH_CFI01 - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL031 # RTC select PL061 # GPIO select GPIO_PWR @@ -74,8 +73,7 @@ config HIGHBANK select AHCI select ARM_TIMER # sp804 select ARM_V7M - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL022 # SPI select PL031 # RTC select PL061 # GPIO @@ -88,8 +86,7 @@ config INTEGRATOR depends on TCG && ARM select ARM_TIMER select INTEGRATOR_DEBUG - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL031 # RTC select PL041 # audio select PL050 # keyboard/mouse @@ -107,8 +104,7 @@ config MUSCA default y depends on TCG && ARM select ARMSSE - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 select PL031 select SPLIT_IRQ select UNIMP @@ -172,8 +168,7 @@ config REALVIEW select WM8750 # audio codec select LSI_SCSI_PCI select PCI - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL031 # RTC select PL041 # audio codec select PL050 # keyboard/mouse @@ -198,8 +193,7 @@ config SBSA_REF select PCI_EXPRESS select PCI_EXPRESS_GENERIC_BRIDGE select PFLASH_CFI01 - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL031 # RTC select PL061 # GPIO select USB_XHCI_SYSBUS @@ -223,8 +217,7 @@ config STELLARIS select ARM_V7M select CMSDK_APB_WATCHDOG select I2C - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL022 # SPI select PL061 # GPIO select SSD0303 # OLED display @@ -284,8 +277,7 @@ config VEXPRESS select ARM_TIMER # sp804 select LAN9118 select PFLASH_CFI01 - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select PL041 # audio codec select PL181 # display select REALVIEW @@ -370,8 +362,7 @@ config RASPI default y depends on TCG && ARM select FRAMEBUFFER - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 # UART select SDHCI select USB_DWC2 select BCM2835_SPI @@ -447,8 +438,7 @@ config XLNX_VERSAL select ARM_GIC select CPU_CLUSTER select DEVICE_TREE - select PL011 if !HAVE_RUST # UART - select X_PL011_RUST if HAVE_RUST # UART + select PL011 select CADENCE select VIRTIO_MMIO select UNIMP diff --git a/rust/Kconfig b/rust/Kconfig index f9f5c390988..e69de29bb2d 100644 --- a/rust/Kconfig +++ b/rust/Kconfig @@ -1 +0,0 @@ -source hw/Kconfig diff --git a/rust/hw/Kconfig b/rust/hw/Kconfig deleted file mode 100644 index 4d934f30afe..00000000000 --- a/rust/hw/Kconfig +++ /dev/null @@ -1,2 +0,0 @@ -# devices Kconfig -source char/Kconfig diff --git a/rust/hw/char/Kconfig b/rust/hw/char/Kconfig deleted file mode 100644 index a1732a9e97f..00000000000 --- a/rust/hw/char/Kconfig +++ /dev/null @@ -1,3 +0,0 @@ -config X_PL011_RUST - bool - default y if HAVE_RUST diff --git a/rust/hw/char/meson.build b/rust/hw/char/meson.build deleted file mode 100644 index 5716dc43ef6..00000000000 --- a/rust/hw/char/meson.build +++ /dev/null @@ -1 +0,0 @@ -subdir('pl011') diff --git a/rust/hw/char/pl011/.gitignore b/rust/hw/char/pl011/.gitignore deleted file mode 100644 index 71eaff2035d..00000000000 --- a/rust/hw/char/pl011/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore generated bindings file overrides. -src/bindings.rs.inc diff --git a/rust/hw/char/pl011/Cargo.lock b/rust/hw/char/pl011/Cargo.lock deleted file mode 100644 index b58cebb186e..00000000000 --- a/rust/hw/char/pl011/Cargo.lock +++ /dev/null @@ -1,134 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version =3D 3 - -[[package]] -name =3D "arbitrary-int" -version =3D "1.2.7" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "c84fc003e338a6f69fbd4f7fe9f92b535ff13e9af8997f3b14b6ddff8b1d= f46d" - -[[package]] -name =3D "bilge" -version =3D "0.2.0" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "dc707ed8ebf81de5cd6c7f48f54b4c8621760926cdf35a57000747c512e6= 7b57" -dependencies =3D [ - "arbitrary-int", - "bilge-impl", -] - -[[package]] -name =3D "bilge-impl" -version =3D "0.2.0" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000ad= b2d8" -dependencies =3D [ - "itertools", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name =3D "either" -version =3D "1.12.0" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385= b58b" - -[[package]] -name =3D "itertools" -version =3D "0.11.0" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3= fe57" -dependencies =3D [ - "either", -] - -[[package]] -name =3D "pl011" -version =3D "0.1.0" -dependencies =3D [ - "bilge", - "bilge-impl", - "qemu_api", - "qemu_api_macros", -] - -[[package]] -name =3D "proc-macro-error" -version =3D "1.0.4" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5c= e38c" -dependencies =3D [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name =3D "proc-macro-error-attr" -version =3D "1.0.4" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35= f869" -dependencies =3D [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name =3D "proc-macro2" -version =3D "1.0.84" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a= 49d6" -dependencies =3D [ - "unicode-ident", -] - -[[package]] -name =3D "qemu_api" -version =3D "0.1.0" - -[[package]] -name =3D "qemu_api_macros" -version =3D "0.1.0" -dependencies =3D [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name =3D "quote" -version =3D "1.0.36" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208ac= aca7" -dependencies =3D [ - "proc-macro2", -] - -[[package]] -name =3D "syn" -version =3D "2.0.66" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cd= cff5" -dependencies =3D [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name =3D "unicode-ident" -version =3D "1.0.12" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0f= ee4b" - -[[package]] -name =3D "version_check" -version =3D "0.9.4" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e= 483f" diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml deleted file mode 100644 index b089e3dded6..00000000000 --- a/rust/hw/char/pl011/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name =3D "pl011" -version =3D "0.1.0" -edition =3D "2021" -authors =3D ["Manos Pitsidianakis "] -license =3D "GPL-2.0-or-later" -readme =3D "README.md" -homepage =3D "https://www.qemu.org" -description =3D "pl011 device model for QEMU" -repository =3D "https://gitlab.com/epilys/rust-for-qemu" -resolver =3D "2" -publish =3D false -keywords =3D [] -categories =3D [] - -[lib] -crate-type =3D ["staticlib"] - -[dependencies] -bilge =3D { version =3D "0.2.0" } -bilge-impl =3D { version =3D "0.2.0" } -qemu_api =3D { path =3D "../../../qemu-api" } -qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } - -# Do not include in any global workspace -[workspace] diff --git a/rust/hw/char/pl011/README.md b/rust/hw/char/pl011/README.md deleted file mode 100644 index cd7dea31634..00000000000 --- a/rust/hw/char/pl011/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# PL011 QEMU Device Model - -This library implements a device model for the PrimeCell=C2=AE UART (PL011) -device in QEMU. - -## Build static lib - -Host build target must be explicitly specified: - -```sh -cargo build --target x86_64-unknown-linux-gnu -``` - -Replace host target triplet if necessary. - -## Generate Rust documentation - -To generate docs for this crate, including private items: - -```sh -cargo doc --no-deps --document-private-items --target x86_64-unknown-linux= -gnu -``` - -To include direct dependencies like `bilge` (bitmaps for register types): - -```sh -cargo tree --depth 1 -e normal --prefix none \ - | cut -d' ' -f1 \ - | xargs printf -- '-p %s\n' \ - | xargs cargo doc --no-deps --document-private-items --target x86_64-unkn= own-linux-gnu -``` diff --git a/rust/hw/char/pl011/meson.build b/rust/hw/char/pl011/meson.build deleted file mode 100644 index 547cca5a96f..00000000000 --- a/rust/hw/char/pl011/meson.build +++ /dev/null @@ -1,26 +0,0 @@ -subproject('bilge-0.2-rs', required: true) -subproject('bilge-impl-0.2-rs', required: true) - -bilge_dep =3D dependency('bilge-0.2-rs') -bilge_impl_dep =3D dependency('bilge-impl-0.2-rs') - -_libpl011_rs =3D static_library( - 'pl011', - files('src/lib.rs'), - override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], - rust_abi: 'rust', - dependencies: [ - bilge_dep, - bilge_impl_dep, - qemu_api, - qemu_api_macros, - ], -) - -rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_depende= ncy( - link_whole: [_libpl011_rs], - # Putting proc macro crates in `dependencies` is necessary for Meson to = find - # them when compiling the root per-target static rust lib. - dependencies: [bilge_impl_dep, qemu_api_macros], - variables: {'crate': 'pl011'}, -)]) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs deleted file mode 100644 index c7193b41bee..00000000000 --- a/rust/hw/char/pl011/src/device.rs +++ /dev/null @@ -1,599 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later - -use core::{ - ffi::{c_int, c_uchar, c_uint, c_void, CStr}, - ptr::{addr_of, addr_of_mut, NonNull}, -}; - -use qemu_api::{ - bindings::{self, *}, - definitions::ObjectImpl, -}; - -use crate::{ - memory_ops::PL011_OPS, - registers::{self, Interrupt}, - RegisterOffset, -}; - -static PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0,= 0x05, 0xb1]; - -const DATA_BREAK: u32 =3D 1 << 10; - -/// QEMU sourced constant. -pub const PL011_FIFO_DEPTH: usize =3D 16_usize; - -#[repr(C)] -#[derive(Debug, qemu_api_macros::Object)] -/// PL011 Device Model in QEMU -pub struct PL011State { - pub parent_obj: SysBusDevice, - pub iomem: MemoryRegion, - #[doc(alias =3D "fr")] - pub flags: registers::Flags, - #[doc(alias =3D "lcr")] - pub line_control: registers::LineControl, - #[doc(alias =3D "rsr")] - pub receive_status_error_clear: registers::ReceiveStatusErrorClear, - #[doc(alias =3D "cr")] - pub control: registers::Control, - pub dmacr: u32, - pub int_enabled: u32, - pub int_level: u32, - pub read_fifo: [u32; PL011_FIFO_DEPTH], - pub ilpr: u32, - pub ibrd: u32, - pub fbrd: u32, - pub ifl: u32, - pub read_pos: usize, - pub read_count: usize, - pub read_trigger: usize, - #[doc(alias =3D "chr")] - pub char_backend: CharBackend, - /// QEMU interrupts - /// - /// ```text - /// * sysbus MMIO region 0: device registers - /// * sysbus IRQ 0: `UARTINTR` (combined interrupt line) - /// * sysbus IRQ 1: `UARTRXINTR` (receive FIFO interrupt line) - /// * sysbus IRQ 2: `UARTTXINTR` (transmit FIFO interrupt line) - /// * sysbus IRQ 3: `UARTRTINTR` (receive timeout interrupt line) - /// * sysbus IRQ 4: `UARTMSINTR` (momem status interrupt line) - /// * sysbus IRQ 5: `UARTEINTR` (error interrupt line) - /// ``` - #[doc(alias =3D "irq")] - pub interrupts: [qemu_irq; 6usize], - #[doc(alias =3D "clk")] - pub clock: NonNull, - #[doc(alias =3D "migrate_clk")] - pub migrate_clock: bool, -} - -impl ObjectImpl for PL011State { - type Class =3D PL011Class; - const TYPE_INFO: qemu_api::bindings::TypeInfo =3D qemu_api::type_info!= { Self }; - const TYPE_NAME: &'static CStr =3D crate::TYPE_PL011; - const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(TYPE_SYS_BUS_DE= VICE); - const ABSTRACT: bool =3D false; - const INSTANCE_INIT: Option = =3D Some(pl011_init); - const INSTANCE_POST_INIT: Option =3D None; - const INSTANCE_FINALIZE: Option =3D None; -} - -#[repr(C)] -pub struct PL011Class { - _inner: [u8; 0], -} - -impl qemu_api::definitions::Class for PL011Class { - const CLASS_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), - > =3D Some(crate::device_class::pl011_class_init); - const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), - > =3D None; -} - -#[used] -pub static CLK_NAME: &CStr =3D c"clk"; - -impl PL011State { - /// Initializes a pre-allocated, unitialized instance of `PL011State`. - /// - /// # Safety - /// - /// `self` must point to a correctly sized and aligned location for the - /// `PL011State` type. It must not be called more than once on the same - /// location/instance. All its fields are expected to hold unitialized - /// values with the sole exception of `parent_obj`. - pub unsafe fn init(&mut self) { - let dev =3D addr_of_mut!(*self).cast::(); - // SAFETY: - // - // self and self.iomem are guaranteed to be valid at this point si= nce callers - // must make sure the `self` reference is valid. - unsafe { - memory_region_init_io( - addr_of_mut!(self.iomem), - addr_of_mut!(*self).cast::(), - &PL011_OPS, - addr_of_mut!(*self).cast::(), - Self::TYPE_INFO.name, - 0x1000, - ); - let sbd =3D addr_of_mut!(*self).cast::(); - sysbus_init_mmio(sbd, addr_of_mut!(self.iomem)); - for irq in self.interrupts.iter_mut() { - sysbus_init_irq(sbd, irq); - } - } - // SAFETY: - // - // self.clock is not initialized at this point; but since `NonNull= <_>` is Copy, - // we can overwrite the undefined value without side effects. This= is - // safe since all PL011State instances are created by QOM code whi= ch - // calls this function to initialize the fields; therefore no code= is - // able to access an invalid self.clock value. - unsafe { - self.clock =3D NonNull::new(qdev_init_clock_in( - dev, - CLK_NAME.as_ptr(), - None, /* pl011_clock_update */ - addr_of_mut!(*self).cast::(), - ClockEvent::ClockUpdate.0, - )) - .unwrap(); - } - } - - pub fn read( - &mut self, - offset: hwaddr, - _size: core::ffi::c_uint, - ) -> std::ops::ControlFlow { - use RegisterOffset::*; - - std::ops::ControlFlow::Break(match RegisterOffset::try_from(offset= ) { - Err(v) if (0x3f8..0x400).contains(&v) =3D> { - u64::from(PL011_ID_ARM[((offset - 0xfe0) >> 2) as usize]) - } - Err(_) =3D> { - // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset = 0x%x\n", (int)offset); - 0 - } - Ok(DR) =3D> { - // s->flags &=3D ~PL011_FLAG_RXFF; - self.flags.set_receive_fifo_full(false); - let c =3D self.read_fifo[self.read_pos]; - if self.read_count > 0 { - self.read_count -=3D 1; - self.read_pos =3D (self.read_pos + 1) & (self.fifo_dep= th() - 1); - } - if self.read_count =3D=3D 0 { - // self.flags |=3D PL011_FLAG_RXFE; - self.flags.set_receive_fifo_empty(true); - } - if self.read_count + 1 =3D=3D self.read_trigger { - //self.int_level &=3D ~ INT_RX; - self.int_level &=3D !registers::INT_RX; - } - // Update error bits. - self.receive_status_error_clear =3D c.to_be_bytes()[3].int= o(); - self.update(); - // Must call qemu_chr_fe_accept_input, so return Continue: - return std::ops::ControlFlow::Continue(c.into()); - } - Ok(RSR) =3D> u8::from(self.receive_status_error_clear).into(), - Ok(FR) =3D> u16::from(self.flags).into(), - Ok(FBRD) =3D> self.fbrd.into(), - Ok(ILPR) =3D> self.ilpr.into(), - Ok(IBRD) =3D> self.ibrd.into(), - Ok(LCR_H) =3D> u16::from(self.line_control).into(), - Ok(CR) =3D> { - // We exercise our self-control. - u16::from(self.control).into() - } - Ok(FLS) =3D> self.ifl.into(), - Ok(IMSC) =3D> self.int_enabled.into(), - Ok(RIS) =3D> self.int_level.into(), - Ok(MIS) =3D> u64::from(self.int_level & self.int_enabled), - Ok(ICR) =3D> { - // "The UARTICR Register is the interrupt clear register a= nd is write-only" - // Source: ARM DDI 0183G 3.3.13 Interrupt Clear Register, = UARTICR - 0 - } - Ok(DMACR) =3D> self.dmacr.into(), - }) - } - - pub fn write(&mut self, offset: hwaddr, value: u64) { - // eprintln!("write offset {offset} value {value}"); - use RegisterOffset::*; - let value: u32 =3D value as u32; - match RegisterOffset::try_from(offset) { - Err(_bad_offset) =3D> { - eprintln!("write bad offset {offset} value {value}"); - } - Ok(DR) =3D> { - // ??? Check if transmitter is enabled. - let ch: u8 =3D value as u8; - // XXX this blocks entire thread. Rewrite to use - // qemu_chr_fe_write and background I/O callbacks - - // SAFETY: self.char_backend is a valid CharBackend instan= ce after it's been - // initialized in realize(). - unsafe { - qemu_chr_fe_write_all(addr_of_mut!(self.char_backend),= &ch, 1); - } - self.loopback_tx(value); - self.int_level |=3D registers::INT_TX; - self.update(); - } - Ok(RSR) =3D> { - self.receive_status_error_clear =3D 0.into(); - } - Ok(FR) =3D> { - // flag writes are ignored - } - Ok(ILPR) =3D> { - self.ilpr =3D value; - } - Ok(IBRD) =3D> { - self.ibrd =3D value; - } - Ok(FBRD) =3D> { - self.fbrd =3D value; - } - Ok(LCR_H) =3D> { - let value =3D value as u16; - let new_val: registers::LineControl =3D value.into(); - // Reset the FIFO state on FIFO enable or disable - if bool::from(self.line_control.fifos_enabled()) - ^ bool::from(new_val.fifos_enabled()) - { - self.reset_fifo(); - } - if self.line_control.send_break() ^ new_val.send_break() { - let mut break_enable: c_int =3D new_val.send_break().i= nto(); - // SAFETY: self.char_backend is a valid CharBackend in= stance after it's been - // initialized in realize(). - unsafe { - qemu_chr_fe_ioctl( - addr_of_mut!(self.char_backend), - CHR_IOCTL_SERIAL_SET_BREAK as i32, - addr_of_mut!(break_enable).cast::(), - ); - } - self.loopback_break(break_enable > 0); - } - self.line_control =3D new_val; - self.set_read_trigger(); - } - Ok(CR) =3D> { - // ??? Need to implement the enable bit. - let value =3D value as u16; - self.control =3D value.into(); - self.loopback_mdmctrl(); - } - Ok(FLS) =3D> { - self.ifl =3D value; - self.set_read_trigger(); - } - Ok(IMSC) =3D> { - self.int_enabled =3D value; - self.update(); - } - Ok(RIS) =3D> {} - Ok(MIS) =3D> {} - Ok(ICR) =3D> { - self.int_level &=3D !value; - self.update(); - } - Ok(DMACR) =3D> { - self.dmacr =3D value; - if value & 3 > 0 { - // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemente= d\n"); - eprintln!("pl011: DMA not implemented"); - } - } - } - } - - #[inline] - fn loopback_tx(&mut self, value: u32) { - if !self.loopback_enabled() { - return; - } - - // Caveat: - // - // In real hardware, TX loopback happens at the serial-bit level - // and then reassembled by the RX logics back into bytes and placed - // into the RX fifo. That is, loopback happens after TX fifo. - // - // Because the real hardware TX fifo is time-drained at the frame - // rate governed by the configured serial format, some loopback - // bytes in TX fifo may still be able to get into the RX fifo - // that could be full at times while being drained at software - // pace. - // - // In such scenario, the RX draining pace is the major factor - // deciding which loopback bytes get into the RX fifo, unless - // hardware flow-control is enabled. - // - // For simplicity, the above described is not emulated. - self.put_fifo(value); - } - - fn loopback_mdmctrl(&mut self) { - if !self.loopback_enabled() { - return; - } - - /* - * Loopback software-driven modem control outputs to modem status = inputs: - * FR.RI <=3D CR.Out2 - * FR.DCD <=3D CR.Out1 - * FR.CTS <=3D CR.RTS - * FR.DSR <=3D CR.DTR - * - * The loopback happens immediately even if this call is triggered - * by setting only CR.LBE. - * - * CTS/RTS updates due to enabled hardware flow controls are not - * dealt with here. - */ - - //fr =3D s->flags & ~(PL011_FLAG_RI | PL011_FLAG_DCD | - // PL011_FLAG_DSR | PL011_FLAG_CTS); - //fr |=3D (cr & CR_OUT2) ? PL011_FLAG_RI : 0; - //fr |=3D (cr & CR_OUT1) ? PL011_FLAG_DCD : 0; - //fr |=3D (cr & CR_RTS) ? PL011_FLAG_CTS : 0; - //fr |=3D (cr & CR_DTR) ? PL011_FLAG_DSR : 0; - // - self.flags.set_ring_indicator(self.control.out_2()); - self.flags.set_data_carrier_detect(self.control.out_1()); - self.flags.set_clear_to_send(self.control.request_to_send()); - self.flags - .set_data_set_ready(self.control.data_transmit_ready()); - - // Change interrupts based on updated FR - let mut il =3D self.int_level; - - il &=3D !Interrupt::MS; - //il |=3D (fr & PL011_FLAG_DSR) ? INT_DSR : 0; - //il |=3D (fr & PL011_FLAG_DCD) ? INT_DCD : 0; - //il |=3D (fr & PL011_FLAG_CTS) ? INT_CTS : 0; - //il |=3D (fr & PL011_FLAG_RI) ? INT_RI : 0; - - if self.flags.data_set_ready() { - il |=3D Interrupt::DSR as u32; - } - if self.flags.data_carrier_detect() { - il |=3D Interrupt::DCD as u32; - } - if self.flags.clear_to_send() { - il |=3D Interrupt::CTS as u32; - } - if self.flags.ring_indicator() { - il |=3D Interrupt::RI as u32; - } - self.int_level =3D il; - self.update(); - } - - fn loopback_break(&mut self, enable: bool) { - if enable { - self.loopback_tx(DATA_BREAK); - } - } - - fn set_read_trigger(&mut self) { - self.read_trigger =3D 1; - } - - pub fn realize(&mut self) { - // SAFETY: self.char_backend has the correct size and alignment fo= r a - // CharBackend object, and its callbacks are of the correct types. - unsafe { - qemu_chr_fe_set_handlers( - addr_of_mut!(self.char_backend), - Some(pl011_can_receive), - Some(pl011_receive), - Some(pl011_event), - None, - addr_of_mut!(*self).cast::(), - core::ptr::null_mut(), - true, - ); - } - } - - pub fn reset(&mut self) { - self.line_control.reset(); - self.receive_status_error_clear.reset(); - self.dmacr =3D 0; - self.int_enabled =3D 0; - self.int_level =3D 0; - self.ilpr =3D 0; - self.ibrd =3D 0; - self.fbrd =3D 0; - self.read_trigger =3D 1; - self.ifl =3D 0x12; - self.control.reset(); - self.flags =3D 0.into(); - self.reset_fifo(); - } - - pub fn reset_fifo(&mut self) { - self.read_count =3D 0; - self.read_pos =3D 0; - - /* Reset FIFO flags */ - self.flags.reset(); - } - - pub fn can_receive(&self) -> bool { - // trace_pl011_can_receive(s->lcr, s->read_count, r); - self.read_count < self.fifo_depth() - } - - pub fn event(&mut self, event: QEMUChrEvent) { - if event =3D=3D bindings::QEMUChrEvent::CHR_EVENT_BREAK && !self.f= ifo_enabled() { - self.put_fifo(DATA_BREAK); - self.receive_status_error_clear.set_break_error(true); - } - } - - #[inline] - pub fn fifo_enabled(&self) -> bool { - matches!(self.line_control.fifos_enabled(), registers::Mode::FIFO) - } - - #[inline] - pub fn loopback_enabled(&self) -> bool { - self.control.enable_loopback() - } - - #[inline] - pub fn fifo_depth(&self) -> usize { - // Note: FIFO depth is expected to be power-of-2 - if self.fifo_enabled() { - return PL011_FIFO_DEPTH; - } - 1 - } - - pub fn put_fifo(&mut self, value: c_uint) { - let depth =3D self.fifo_depth(); - assert!(depth > 0); - let slot =3D (self.read_pos + self.read_count) & (depth - 1); - self.read_fifo[slot] =3D value; - self.read_count +=3D 1; - // s->flags &=3D ~PL011_FLAG_RXFE; - self.flags.set_receive_fifo_empty(false); - if self.read_count =3D=3D depth { - //s->flags |=3D PL011_FLAG_RXFF; - self.flags.set_receive_fifo_full(true); - } - - if self.read_count =3D=3D self.read_trigger { - self.int_level |=3D registers::INT_RX; - self.update(); - } - } - - pub fn update(&self) { - let flags =3D self.int_level & self.int_enabled; - for (irq, i) in self.interrupts.iter().zip(IRQMASK) { - // SAFETY: self.interrupts have been initialized in init(). - unsafe { qemu_set_irq(*irq, i32::from(flags & i !=3D 0)) }; - } - } -} - -/// Which bits in the interrupt status matter for each outbound IRQ line ? -pub const IRQMASK: [u32; 6] =3D [ - /* combined IRQ */ - Interrupt::E - | Interrupt::MS - | Interrupt::RT as u32 - | Interrupt::TX as u32 - | Interrupt::RX as u32, - Interrupt::RX as u32, - Interrupt::TX as u32, - Interrupt::RT as u32, - Interrupt::MS, - Interrupt::E, -]; - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that = has -/// the same size as [`PL011State`]. We also expect the device is -/// readable/writeable from one thread at any time. -#[no_mangle] -pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { - unsafe { - debug_assert!(!opaque.is_null()); - let state =3D NonNull::new_unchecked(opaque.cast::()); - state.as_ref().can_receive().into() - } -} - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that = has -/// the same size as [`PL011State`]. We also expect the device is -/// readable/writeable from one thread at any time. -/// -/// The buffer and size arguments must also be valid. -#[no_mangle] -pub unsafe extern "C" fn pl011_receive( - opaque: *mut core::ffi::c_void, - buf: *const u8, - size: core::ffi::c_int, -) { - unsafe { - debug_assert!(!opaque.is_null()); - let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); - if state.as_ref().loopback_enabled() { - return; - } - if size > 0 { - debug_assert!(!buf.is_null()); - state.as_mut().put_fifo(c_uint::from(buf.read_volatile())) - } - } -} - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that = has -/// the same size as [`PL011State`]. We also expect the device is -/// readable/writeable from one thread at any time. -#[no_mangle] -pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event= : QEMUChrEvent) { - unsafe { - debug_assert!(!opaque.is_null()); - let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); - state.as_mut().event(event) - } -} - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer for `c= hr`. -#[no_mangle] -pub unsafe extern "C" fn pl011_create( - addr: u64, - irq: qemu_irq, - chr: *mut Chardev, -) -> *mut DeviceState { - unsafe { - let dev: *mut DeviceState =3D qdev_new(PL011State::TYPE_INFO.name); - let sysbus: *mut SysBusDevice =3D dev.cast::(); - - qdev_prop_set_chr(dev, bindings::TYPE_CHARDEV.as_ptr(), chr); - sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mu= t Error); - sysbus_mmio_map(sysbus, 0, addr); - sysbus_connect_irq(sysbus, 0, irq); - dev - } -} - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that = has -/// the same size as [`PL011State`]. We also expect the device is -/// readable/writeable from one thread at any time. -#[no_mangle] -pub unsafe extern "C" fn pl011_init(obj: *mut Object) { - unsafe { - debug_assert!(!obj.is_null()); - let mut state =3D NonNull::new_unchecked(obj.cast::()); - state.as_mut().init(); - } -} diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs deleted file mode 100644 index b7ab31af02d..00000000000 --- a/rust/hw/char/pl011/src/device_class.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later - -use core::ptr::NonNull; - -use qemu_api::{bindings::*, definitions::ObjectImpl}; - -use crate::device::PL011State; - -#[used] -pub static VMSTATE_PL011: VMStateDescription =3D VMStateDescription { - name: PL011State::TYPE_INFO.name, - unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::::zeroed().as= sume_init() } -}; - -qemu_api::declare_properties! { - PL011_PROPERTIES, - qemu_api::define_property!( - c"chardev", - PL011State, - char_backend, - unsafe { &qdev_prop_chr }, - CharBackend - ), - qemu_api::define_property!( - c"migrate-clk", - PL011State, - migrate_clock, - unsafe { &qdev_prop_bool }, - bool - ), -} - -qemu_api::device_class_init! { - pl011_class_init, - props =3D> PL011_PROPERTIES, - realize_fn =3D> Some(pl011_realize), - legacy_reset_fn =3D> Some(pl011_reset), - vmsd =3D> VMSTATE_PL011, -} - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that = has -/// the same size as [`PL011State`]. We also expect the device is -/// readable/writeable from one thread at any time. -#[no_mangle] -pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut = *mut Error) { - unsafe { - assert!(!dev.is_null()); - let mut state =3D NonNull::new_unchecked(dev.cast::()); - state.as_mut().realize(); - } -} - -/// # Safety -/// -/// We expect the FFI user of this function to pass a valid pointer, that = has -/// the same size as [`PL011State`]. We also expect the device is -/// readable/writeable from one thread at any time. -#[no_mangle] -pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { - unsafe { - assert!(!dev.is_null()); - let mut state =3D NonNull::new_unchecked(dev.cast::()); - state.as_mut().reset(); - } -} diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs deleted file mode 100644 index 2939ee50c99..00000000000 --- a/rust/hw/char/pl011/src/lib.rs +++ /dev/null @@ -1,586 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later -// -// PL011 QEMU Device Model -// -// This library implements a device model for the PrimeCell=C2=AE UART (PL= 011) -// device in QEMU. -// -#![doc =3D include_str!("../README.md")] -//! # Library crate -//! -//! See [`PL011State`](crate::device::PL011State) for the device model typ= e and -//! the [`registers`] module for register types. - -#![deny( - rustdoc::broken_intra_doc_links, - rustdoc::redundant_explicit_links, - clippy::correctness, - clippy::suspicious, - clippy::complexity, - clippy::perf, - clippy::cargo, - clippy::nursery, - clippy::style, - // restriction group - clippy::dbg_macro, - clippy::as_underscore, - clippy::assertions_on_result_states, - // pedantic group - clippy::doc_markdown, - clippy::borrow_as_ptr, - clippy::cast_lossless, - clippy::option_if_let_else, - clippy::missing_const_for_fn, - clippy::cognitive_complexity, - clippy::missing_safety_doc, - )] - -extern crate bilge; -extern crate bilge_impl; -extern crate qemu_api; - -pub mod device; -pub mod device_class; -pub mod memory_ops; - -pub const TYPE_PL011: &::core::ffi::CStr =3D c"pl011"; - -/// Offset of each register from the base memory address of the device. -/// -/// # Source -/// ARM DDI 0183G, Table 3-1 p.3-3 -#[doc(alias =3D "offset")] -#[allow(non_camel_case_types)] -#[repr(u64)] -#[derive(Debug)] -pub enum RegisterOffset { - /// Data Register - /// - /// A write to this register initiates the actual data transmission - #[doc(alias =3D "UARTDR")] - DR =3D 0x000, - /// Receive Status Register or Error Clear Register - #[doc(alias =3D "UARTRSR")] - #[doc(alias =3D "UARTECR")] - RSR =3D 0x004, - /// Flag Register - /// - /// A read of this register shows if transmission is complete - #[doc(alias =3D "UARTFR")] - FR =3D 0x018, - /// Fractional Baud Rate Register - /// - /// responsible for baud rate speed - #[doc(alias =3D "UARTFBRD")] - FBRD =3D 0x028, - /// `IrDA` Low-Power Counter Register - #[doc(alias =3D "UARTILPR")] - ILPR =3D 0x020, - /// Integer Baud Rate Register - /// - /// Responsible for baud rate speed - #[doc(alias =3D "UARTIBRD")] - IBRD =3D 0x024, - /// line control register (data frame format) - #[doc(alias =3D "UARTLCR_H")] - LCR_H =3D 0x02C, - /// Toggle UART, transmission or reception - #[doc(alias =3D "UARTCR")] - CR =3D 0x030, - /// Interrupt FIFO Level Select Register - #[doc(alias =3D "UARTIFLS")] - FLS =3D 0x034, - /// Interrupt Mask Set/Clear Register - #[doc(alias =3D "UARTIMSC")] - IMSC =3D 0x038, - /// Raw Interrupt Status Register - #[doc(alias =3D "UARTRIS")] - RIS =3D 0x03C, - /// Masked Interrupt Status Register - #[doc(alias =3D "UARTMIS")] - MIS =3D 0x040, - /// Interrupt Clear Register - #[doc(alias =3D "UARTICR")] - ICR =3D 0x044, - /// DMA control Register - #[doc(alias =3D "UARTDMACR")] - DMACR =3D 0x048, - ///// Reserved, offsets `0x04C` to `0x07C`. - //Reserved =3D 0x04C, -} - -impl core::convert::TryFrom for RegisterOffset { - type Error =3D u64; - - fn try_from(value: u64) -> Result { - macro_rules! case { - ($($discriminant:ident),*$(,)*) =3D> { - /* check that matching on all macro arguments compiles, wh= ich means we are not - * missing any enum value; if the type definition ever cha= nges this will stop - * compiling. - */ - const fn _assert_exhaustive(val: RegisterOffset) { - match val { - $(RegisterOffset::$discriminant =3D> (),)* - } - } - - match value { - $(x if x =3D=3D Self::$discriminant as u64 =3D> Ok(Sel= f::$discriminant),)* - _ =3D> Err(value), - } - } - } - case! { DR, RSR, FR, FBRD, ILPR, IBRD, LCR_H, CR, FLS, IMSC, RIS, = MIS, ICR, DMACR } - } -} - -pub mod registers { - //! Device registers exposed as typed structs which are backed by arbi= trary - //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. - //! - //! All PL011 registers are essentially 32-bit wide, but are typed her= e as - //! bitmaps with only the necessary width. That is, if a struct bitmap - //! in this module is for example 16 bits long, it should be conceived - //! as a 32-bit register where the unmentioned higher bits are always - //! unused thus treated as zero when read or written. - use bilge::prelude::*; - - // TODO: FIFO Mode has different semantics - /// Data Register, `UARTDR` - /// - /// The `UARTDR` register is the data register. - /// - /// For words to be transmitted: - /// - /// - if the FIFOs are enabled, data written to this location is pushe= d onto - /// the transmit - /// FIFO - /// - if the FIFOs are not enabled, data is stored in the transmitter - /// holding register (the - /// bottom word of the transmit FIFO). - /// - /// The write operation initiates transmission from the UART. The data= is - /// prefixed with a start bit, appended with the appropriate parity bit - /// (if parity is enabled), and a stop bit. The resultant word is then - /// transmitted. - /// - /// For received words: - /// - /// - if the FIFOs are enabled, the data byte and the 4-bit status (br= eak, - /// frame, parity, - /// and overrun) is pushed onto the 12-bit wide receive FIFO - /// - if the FIFOs are not enabled, the data byte and status are store= d in - /// the receiving - /// holding register (the bottom word of the receive FIFO). - /// - /// The received data byte is read by performing reads from the `UARTD= R` - /// register along with the corresponding status information. The stat= us - /// information can also be read by a read of the `UARTRSR/UARTECR` - /// register. - /// - /// # Note - /// - /// You must disable the UART before any of the control registers are - /// reprogrammed. When the UART is disabled in the middle of - /// transmission or reception, it completes the current character befo= re - /// stopping. - /// - /// # Source - /// ARM DDI 0183G 3.3.1 Data Register, UARTDR - #[bitsize(16)] - #[derive(Clone, Copy, DebugBits, FromBits)] - #[doc(alias =3D "UARTDR")] - pub struct Data { - _reserved: u4, - pub data: u8, - pub framing_error: bool, - pub parity_error: bool, - pub break_error: bool, - pub overrun_error: bool, - } - - // TODO: FIFO Mode has different semantics - /// Receive Status Register / Error Clear Register, `UARTRSR/UARTECR` - /// - /// The UARTRSR/UARTECR register is the receive status register/error = clear - /// register. Receive status can also be read from the `UARTRSR` - /// register. If the status is read from this register, then the status - /// information for break, framing and parity corresponds to the - /// data character read from the [Data register](Data), `UARTDR` prior= to - /// reading the UARTRSR register. The status information for overrun is - /// set immediately when an overrun condition occurs. - /// - /// - /// # Note - /// The received data character must be read first from the [Data - /// Register](Data), `UARTDR` before reading the error status associat= ed - /// with that data character from the `UARTRSR` register. This read - /// sequence cannot be reversed, because the `UARTRSR` register is - /// updated only when a read occurs from the `UARTDR` register. Howeve= r, - /// the status information can also be obtained by reading the `UARTDR` - /// register - /// - /// # Source - /// ARM DDI 0183G 3.3.2 Receive Status Register/Error Clear Register, - /// UARTRSR/UARTECR - #[bitsize(8)] - #[derive(Clone, Copy, DebugBits, FromBits)] - pub struct ReceiveStatusErrorClear { - pub framing_error: bool, - pub parity_error: bool, - pub break_error: bool, - pub overrun_error: bool, - _reserved_unpredictable: u4, - } - - impl ReceiveStatusErrorClear { - pub fn reset(&mut self) { - // All the bits are cleared to 0 on reset. - *self =3D 0.into(); - } - } - - impl Default for ReceiveStatusErrorClear { - fn default() -> Self { - 0.into() - } - } - - #[bitsize(16)] - #[derive(Clone, Copy, DebugBits, FromBits)] - /// Flag Register, `UARTFR` - #[doc(alias =3D "UARTFR")] - pub struct Flags { - /// CTS Clear to send. This bit is the complement of the UART clea= r to - /// send, `nUARTCTS`, modem status input. That is, the bit is 1 - /// when `nUARTCTS` is LOW. - pub clear_to_send: bool, - /// DSR Data set ready. This bit is the complement of the UART dat= a set - /// ready, `nUARTDSR`, modem status input. That is, the bit is 1 w= hen - /// `nUARTDSR` is LOW. - pub data_set_ready: bool, - /// DCD Data carrier detect. This bit is the complement of the UAR= T data - /// carrier detect, `nUARTDCD`, modem status input. That is, the b= it is - /// 1 when `nUARTDCD` is LOW. - pub data_carrier_detect: bool, - /// BUSY UART busy. If this bit is set to 1, the UART is busy - /// transmitting data. This bit remains set until the complete - /// byte, including all the stop bits, has been sent from the - /// shift register. This bit is set as soon as the transmit FIFO - /// becomes non-empty, regardless of whether the UART is enabled - /// or not. - pub busy: bool, - /// RXFE Receive FIFO empty. The meaning of this bit depends on the - /// state of the FEN bit in the UARTLCR_H register. If the FIFO - /// is disabled, this bit is set when the receive holding - /// register is empty. If the FIFO is enabled, the RXFE bit is - /// set when the receive FIFO is empty. - pub receive_fifo_empty: bool, - /// TXFF Transmit FIFO full. The meaning of this bit depends on the - /// state of the FEN bit in the UARTLCR_H register. If the FIFO - /// is disabled, this bit is set when the transmit holding - /// register is full. If the FIFO is enabled, the TXFF bit is - /// set when the transmit FIFO is full. - pub transmit_fifo_full: bool, - /// RXFF Receive FIFO full. The meaning of this bit depends on the= state - /// of the FEN bit in the UARTLCR_H register. If the FIFO is - /// disabled, this bit is set when the receive holding register - /// is full. If the FIFO is enabled, the RXFF bit is set when - /// the receive FIFO is full. - pub receive_fifo_full: bool, - /// Transmit FIFO empty. The meaning of this bit depends on the st= ate of - /// the FEN bit in the [Line Control register](LineControl), - /// `UARTLCR_H`. If the FIFO is disabled, this bit is set when the - /// transmit holding register is empty. If the FIFO is enabled, - /// the TXFE bit is set when the transmit FIFO is empty. This - /// bit does not indicate if there is data in the transmit shift - /// register. - pub transmit_fifo_empty: bool, - /// `RI`, is `true` when `nUARTRI` is `LOW`. - pub ring_indicator: bool, - _reserved_zero_no_modify: u7, - } - - impl Flags { - pub fn reset(&mut self) { - // After reset TXFF, RXFF, and BUSY are 0, and TXFE and RXFE a= re 1 - self.set_receive_fifo_full(false); - self.set_transmit_fifo_full(false); - self.set_busy(false); - self.set_receive_fifo_empty(true); - self.set_transmit_fifo_empty(true); - } - } - - impl Default for Flags { - fn default() -> Self { - let mut ret: Self =3D 0.into(); - ret.reset(); - ret - } - } - - #[bitsize(16)] - #[derive(Clone, Copy, DebugBits, FromBits)] - /// Line Control Register, `UARTLCR_H` - #[doc(alias =3D "UARTLCR_H")] - pub struct LineControl { - /// 15:8 - Reserved, do not modify, read as zero. - _reserved_zero_no_modify: u8, - /// 7 SPS Stick parity select. - /// 0 =3D stick parity is disabled - /// 1 =3D either: - /// =E2=80=A2 if the EPS bit is 0 then the parity bit is transmitt= ed and checked - /// as a 1 =E2=80=A2 if the EPS bit is 1 then the parity bit is - /// transmitted and checked as a 0. This bit has no effect when - /// the PEN bit disables parity checking and generation. See Table= 3-11 - /// on page 3-14 for the parity truth table. - pub sticky_parity: bool, - /// WLEN Word length. These bits indicate the number of data bits - /// transmitted or received in a frame as follows: b11 =3D 8 bits - /// b10 =3D 7 bits - /// b01 =3D 6 bits - /// b00 =3D 5 bits. - pub word_length: WordLength, - /// FEN Enable FIFOs: - /// 0 =3D FIFOs are disabled (character mode) that is, the FIFOs b= ecome - /// 1-byte-deep holding registers 1 =3D transmit and receive FIFO - /// buffers are enabled (FIFO mode). - pub fifos_enabled: Mode, - /// 3 STP2 Two stop bits select. If this bit is set to 1, two stop= bits - /// are transmitted at the end of the frame. The receive - /// logic does not check for two stop bits being received. - pub two_stops_bits: bool, - /// EPS Even parity select. Controls the type of parity the UART u= ses - /// during transmission and reception: - /// - 0 =3D odd parity. The UART generates or checks for an odd nu= mber of - /// 1s in the data and parity bits. - /// - 1 =3D even parity. The UART generates or checks for an even = number - /// of 1s in the data and parity bits. - /// This bit has no effect when the `PEN` bit disables parity chec= king - /// and generation. See Table 3-11 on page 3-14 for the parity - /// truth table. - pub parity: Parity, - /// 1 PEN Parity enable: - /// - /// - 0 =3D parity is disabled and no parity bit added to the data= frame - /// - 1 =3D parity checking and generation is enabled. - /// - /// See Table 3-11 on page 3-14 for the parity truth table. - pub parity_enabled: bool, - /// BRK Send break. - /// - /// If this bit is set to `1`, a low-level is continually output o= n the - /// `UARTTXD` output, after completing transmission of the - /// current character. For the proper execution of the break comma= nd, - /// the software must set this bit for at least two complete - /// frames. For normal use, this bit must be cleared to `0`. - pub send_break: bool, - } - - impl LineControl { - pub fn reset(&mut self) { - // All the bits are cleared to 0 when reset. - *self =3D 0.into(); - } - } - - impl Default for LineControl { - fn default() -> Self { - 0.into() - } - } - - #[bitsize(1)] - #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] - /// `EPS` "Even parity select", field of [Line Control - /// register](LineControl). - pub enum Parity { - /// - 0 =3D odd parity. The UART generates or checks for an odd nu= mber of - /// 1s in the data and parity bits. - Odd =3D 0, - /// - 1 =3D even parity. The UART generates or checks for an even = number - /// of 1s in the data and parity bits. - Even =3D 1, - } - - #[bitsize(1)] - #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] - /// `FEN` "Enable FIFOs" or Device mode, field of [Line Control - /// register](LineControl). - pub enum Mode { - /// 0 =3D FIFOs are disabled (character mode) that is, the FIFOs b= ecome - /// 1-byte-deep holding registers - Character =3D 0, - /// 1 =3D transmit and receive FIFO buffers are enabled (FIFO mode= ). - FIFO =3D 1, - } - - impl From for bool { - fn from(val: Mode) -> Self { - matches!(val, Mode::FIFO) - } - } - - #[bitsize(2)] - #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] - /// `WLEN` Word length, field of [Line Control register](LineControl). - /// - /// These bits indicate the number of data bits transmitted or receive= d in a - /// frame as follows: - pub enum WordLength { - /// b11 =3D 8 bits - _8Bits =3D 0b11, - /// b10 =3D 7 bits - _7Bits =3D 0b10, - /// b01 =3D 6 bits - _6Bits =3D 0b01, - /// b00 =3D 5 bits. - _5Bits =3D 0b00, - } - - /// Control Register, `UARTCR` - /// - /// The `UARTCR` register is the control register. All the bits are cl= eared - /// to `0` on reset except for bits `9` and `8` that are set to `1`. - /// - /// # Source - /// ARM DDI 0183G, 3.3.8 Control Register, `UARTCR`, Table 3-12 - #[bitsize(16)] - #[doc(alias =3D "UARTCR")] - #[derive(Clone, Copy, DebugBits, FromBits)] - pub struct Control { - /// `UARTEN` UART enable: 0 =3D UART is disabled. If the UART is d= isabled - /// in the middle of transmission or reception, it completes the c= urrent - /// character before stopping. 1 =3D the UART is enabled. Data - /// transmission and reception occurs for either UART signals or S= IR - /// signals depending on the setting of the SIREN bit. - pub enable_uart: bool, - /// `SIREN` `SIR` enable: 0 =3D IrDA SIR ENDEC is disabled. `nSIRO= UT` - /// remains LOW (no light pulse generated), and signal transitions= on - /// SIRIN have no effect. 1 =3D IrDA SIR ENDEC is enabled. Data is - /// transmitted and received on nSIROUT and SIRIN. UARTTXD remains= HIGH, - /// in the marking state. Signal transitions on UARTRXD or modem s= tatus - /// inputs have no effect. This bit has no effect if the UARTEN bit - /// disables the UART. - pub enable_sir: bool, - /// `SIRLP` SIR low-power IrDA mode. This bit selects the IrDA enc= oding - /// mode. If this bit is cleared to 0, low-level bits are transmit= ted as - /// an active high pulse with a width of 3/ 16th of the bit period= . If - /// this bit is set to 1, low-level bits are transmitted with a pu= lse - /// width that is 3 times the period of the IrLPBaud16 input signa= l, - /// regardless of the selected bit rate. Setting this bit uses less - /// power, but might reduce transmission distances. - pub sir_lowpower_irda_mode: u1, - /// Reserved, do not modify, read as zero. - _reserved_zero_no_modify: u4, - /// `LBE` Loopback enable. If this bit is set to 1 and the SIREN b= it is - /// set to 1 and the SIRTEST bit in the Test Control register, UAR= TTCR - /// on page 4-5 is set to 1, then the nSIROUT path is inverted, an= d fed - /// through to the SIRIN path. The SIRTEST bit in the test registe= r must - /// be set to 1 to override the normal half-duplex SIR operation. = This - /// must be the requirement for accessing the test registers during - /// normal operation, and SIRTEST must be cleared to 0 when loopba= ck - /// testing is finished. This feature reduces the amount of extern= al - /// coupling required during system test. If this bit is set to 1,= and - /// the SIRTEST bit is set to 0, the UARTTXD path is fed through t= o the - /// UARTRXD path. In either SIR mode or UART mode, when this bit i= s set, - /// the modem outputs are also fed through to the modem inputs. Th= is bit - /// is cleared to 0 on reset, to disable loopback. - pub enable_loopback: bool, - /// `TXE` Transmit enable. If this bit is set to 1, the transmit s= ection - /// of the UART is enabled. Data transmission occurs for either UA= RT - /// signals, or SIR signals depending on the setting of the SIREN = bit. - /// When the UART is disabled in the middle of transmission, it - /// completes the current character before stopping. - pub enable_transmit: bool, - /// `RXE` Receive enable. If this bit is set to 1, the receive sec= tion - /// of the UART is enabled. Data reception occurs for either UART - /// signals or SIR signals depending on the setting of the SIREN b= it. - /// When the UART is disabled in the middle of reception, it compl= etes - /// the current character before stopping. - pub enable_receive: bool, - /// `DTR` Data transmit ready. This bit is the complement of the U= ART - /// data transmit ready, `nUARTDTR`, modem status output. That is,= when - /// the bit is programmed to a 1 then `nUARTDTR` is LOW. - pub data_transmit_ready: bool, - /// `RTS` Request to send. This bit is the complement of the UART - /// request to send, `nUARTRTS`, modem status output. That is, whe= n the - /// bit is programmed to a 1 then `nUARTRTS` is LOW. - pub request_to_send: bool, - /// `Out1` This bit is the complement of the UART Out1 (`nUARTOut1= `) - /// modem status output. That is, when the bit is programmed to a = 1 the - /// output is 0. For DTE this can be used as Data Carrier Detect (= DCD). - pub out_1: bool, - /// `Out2` This bit is the complement of the UART Out2 (`nUARTOut2= `) - /// modem status output. That is, when the bit is programmed to a = 1, the - /// output is 0. For DTE this can be used as Ring Indicator (RI). - pub out_2: bool, - /// `RTSEn` RTS hardware flow control enable. If this bit is set t= o 1, - /// RTS hardware flow control is enabled. Data is only requested w= hen - /// there is space in the receive FIFO for it to be received. - pub rts_hardware_flow_control_enable: bool, - /// `CTSEn` CTS hardware flow control enable. If this bit is set t= o 1, - /// CTS hardware flow control is enabled. Data is only transmitted= when - /// the `nUARTCTS` signal is asserted. - pub cts_hardware_flow_control_enable: bool, - } - - impl Control { - pub fn reset(&mut self) { - *self =3D 0.into(); - self.set_enable_receive(true); - self.set_enable_transmit(true); - } - } - - impl Default for Control { - fn default() -> Self { - let mut ret: Self =3D 0.into(); - ret.reset(); - ret - } - } - - /// Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC - pub const INT_OE: u32 =3D 1 << 10; - pub const INT_BE: u32 =3D 1 << 9; - pub const INT_PE: u32 =3D 1 << 8; - pub const INT_FE: u32 =3D 1 << 7; - pub const INT_RT: u32 =3D 1 << 6; - pub const INT_TX: u32 =3D 1 << 5; - pub const INT_RX: u32 =3D 1 << 4; - pub const INT_DSR: u32 =3D 1 << 3; - pub const INT_DCD: u32 =3D 1 << 2; - pub const INT_CTS: u32 =3D 1 << 1; - pub const INT_RI: u32 =3D 1 << 0; - pub const INT_E: u32 =3D INT_OE | INT_BE | INT_PE | INT_FE; - pub const INT_MS: u32 =3D INT_RI | INT_DSR | INT_DCD | INT_CTS; - - #[repr(u32)] - pub enum Interrupt { - OE =3D 1 << 10, - BE =3D 1 << 9, - PE =3D 1 << 8, - FE =3D 1 << 7, - RT =3D 1 << 6, - TX =3D 1 << 5, - RX =3D 1 << 4, - DSR =3D 1 << 3, - DCD =3D 1 << 2, - CTS =3D 1 << 1, - RI =3D 1 << 0, - } - - impl Interrupt { - pub const E: u32 =3D INT_OE | INT_BE | INT_PE | INT_FE; - pub const MS: u32 =3D INT_RI | INT_DSR | INT_DCD | INT_CTS; - } -} - -// TODO: You must disable the UART before any of the control registers are -// reprogrammed. When the UART is disabled in the middle of transmission or -// reception, it completes the current character before stopping diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/= memory_ops.rs deleted file mode 100644 index 8d066ebf6d0..00000000000 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later - -use core::{mem::MaybeUninit, ptr::NonNull}; - -use qemu_api::bindings::*; - -use crate::device::PL011State; - -pub static PL011_OPS: MemoryRegionOps =3D MemoryRegionOps { - read: Some(pl011_read), - write: Some(pl011_write), - read_with_attrs: None, - write_with_attrs: None, - endianness: device_endian::DEVICE_NATIVE_ENDIAN, - valid: unsafe { MaybeUninit::::zeroed()= .assume_init() }, - impl_: MemoryRegionOps__bindgen_ty_2 { - min_access_size: 4, - max_access_size: 4, - ..unsafe { MaybeUninit::::zeroed().= assume_init() } - }, -}; - -#[no_mangle] -unsafe extern "C" fn pl011_read( - opaque: *mut core::ffi::c_void, - addr: hwaddr, - size: core::ffi::c_uint, -) -> u64 { - assert!(!opaque.is_null()); - let mut state =3D unsafe { NonNull::new_unchecked(opaque.cast::()) }; - let val =3D unsafe { state.as_mut().read(addr, size) }; - match val { - std::ops::ControlFlow::Break(val) =3D> val, - std::ops::ControlFlow::Continue(val) =3D> { - // SAFETY: self.char_backend is a valid CharBackend instance a= fter it's been - // initialized in realize(). - let cb_ptr =3D unsafe { core::ptr::addr_of_mut!(state.as_mut()= .char_backend) }; - unsafe { qemu_chr_fe_accept_input(cb_ptr) }; - - val - } - } -} - -#[no_mangle] -unsafe extern "C" fn pl011_write( - opaque: *mut core::ffi::c_void, - addr: hwaddr, - data: u64, - _size: core::ffi::c_uint, -) { - unsafe { - assert!(!opaque.is_null()); - let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); - state.as_mut().write(addr, data) - } -} diff --git a/rust/hw/meson.build b/rust/hw/meson.build deleted file mode 100644 index 860196645e7..00000000000 --- a/rust/hw/meson.build +++ /dev/null @@ -1 +0,0 @@ -subdir('char') diff --git a/rust/meson.build b/rust/meson.build index def77389cdd..7a32b1b1950 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,4 +1,2 @@ subdir('qemu-api-macros') subdir('qemu-api') - -subdir('hw') diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index 30677c3ec90..62a2cf45d28 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -27,9 +27,7 @@ sub_file=3D"${sub_tdir}/submodule.tar" # in their checkout, because the build environment is completely # different to the host OS. subprojects=3D"keycodemapdb libvfio-user berkeley-softfloat-3 - berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs - bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs - proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs + berkeley-testfloat-3 proc-macro2-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" sub_deinit=3D"" =20 diff --git a/scripts/make-release b/scripts/make-release index 8dc939124c4..cf7d694ef73 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -18,9 +18,7 @@ fi =20 # Only include wraps that are invoked with subproject() SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softfloat-3 - berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs - bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs - proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs + berkeley-testfloat-3 proc-macro2-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" =20 src=3D"$1" diff --git a/scripts/rust/rust_root_crate.sh b/scripts/rust/rust_root_crate= .sh deleted file mode 100755 index 975bddf7f1a..00000000000 --- a/scripts/rust/rust_root_crate.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -eu - -cat < (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741509008909.5405087004167; Mon, 4 Nov 2024 09:31:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rq-00057k-0o; Mon, 04 Nov 2024 12:27:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rl-00054x-A5 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80ra-000088-3W for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:48 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-b_5H9fpxO3KbOXUWKQuy1A-1; Mon, 04 Nov 2024 12:27:35 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43157cff1d1so33008605e9.2 for ; Mon, 04 Nov 2024 09:27:35 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6852d9sm160371265e9.37.2024.11.04.09.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kTatY3+OeQjLuJnbGS8UKHlSrrla1BK3QP782WOHhDU=; b=Dg2lVECFPOa25332lbVU0fadC19bQCR9aPTxnrFs2JlHenZZPn8UaFuo6ZgovKJQTQ3N/z 66AM2CZXboOB98bbF4vv7fKINyux9L15lxY5QB432sEnJFTojcSl8ZMDGcG7PcifEGowVR c39x4c0FjeuT9Oaqr1DWAU0SHL1LQzE= X-MC-Unique: b_5H9fpxO3KbOXUWKQuy1A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741254; x=1731346054; 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=kTatY3+OeQjLuJnbGS8UKHlSrrla1BK3QP782WOHhDU=; b=WXm5ur7PwdRpGamgVSujxowfBDz6+Tzsdz0IZNPNBlL2FgHI1R/h31UhP84TL67BFQ 3pjUu9Xt4zhwgV7kE1AH0IpdVB50AtZced/5RMc4LyBahyOfoPzkS+tTq/XrZ8RwSk5L nPxa2DpNUAgyVwltzC0rj6mTI7DGmA1yUp0ZJbIKgR/RUfLjCgMrEV3Qlibg7dO7QcIO CzZo4XmaG465gSwCq7nJzc2lAYRWpMCZAkyqiyiumvRbSBKnNLAAM2XrsVdnZZq8FH9i S+7MkOB83csXGbydCk1oRBTBemde9u3eF38AwBze1iKwQ+KJR6zDEbJyzfpBSMrHvr1Z LtIA== X-Gm-Message-State: AOJu0YyOfdzkNIq7fsW8xT1tq06V4Uc5nMnSXyU92e7Bk8M3A0/UULA4 pbhgE4z7oLflgWn2vdmSof67fgzsc8D0srxrZpPcEPu/wKnenTOUpJ0JFjxrZoKZk3qeygvvkux JyrILx47d5TVovbEN8KPtyjONTA+DItog2NwxOoTPF0ayof7VzXyW8YIjUWR92kFmFsb04mxX7l vOrNjftAHJPUtfXcR7UtfY8fl15/9bIuGj/a4m/Ww= X-Received: by 2002:a05:600c:1f91:b0:426:66a2:b200 with SMTP id 5b1f17b1804b1-4327b6c79f7mr150575775e9.0.1730741252682; Mon, 04 Nov 2024 09:27:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTfdc+MzC6tMm7l4x+Mv7QBOHWtlPeISMxcs35W/7UGX3jCrK53Catl0EN4/I4Zamwqx+x+g== X-Received: by 2002:a05:600c:1f91:b0:426:66a2:b200 with SMTP id 5b1f17b1804b1-4327b6c79f7mr150574795e9.0.1730741251104; Mon, 04 Nov 2024 09:27:31 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu , Junjie Mao Subject: [PULL 04/40] rust: add PL011 device model Date: Mon, 4 Nov 2024 18:26:43 +0100 Message-ID: <20241104172721.180255-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741510406116600 From: Manos Pitsidianakis This commit adds a re-implementation of hw/char/pl011.c in Rust. How to build: 1. Configure a QEMU build with: --enable-system --target-list=3Daarch64-softmmu --enable-rust 2. Launching a VM with qemu-system-aarch64 should use the Rust version of the pl011 device Co-authored-by: Junjie Mao Co-authored-by: Paolo Bonzini Signed-off-by: Junjie Mao Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-2-051e7a25b978@lin= aro.org --- MAINTAINERS | 5 + meson.build | 24 + hw/arm/Kconfig | 30 +- rust/Kconfig | 1 + rust/hw/Kconfig | 2 + rust/hw/char/Kconfig | 3 + rust/hw/char/meson.build | 1 + rust/hw/char/pl011/.gitignore | 2 + rust/hw/char/pl011/Cargo.lock | 134 ++++ rust/hw/char/pl011/Cargo.toml | 26 + rust/hw/char/pl011/README.md | 31 + rust/hw/char/pl011/meson.build | 26 + rust/hw/char/pl011/src/device.rs | 599 ++++++++++++++++++ rust/hw/char/pl011/src/device_class.rs | 70 ++ rust/hw/char/pl011/src/lib.rs | 586 +++++++++++++++++ rust/hw/char/pl011/src/memory_ops.rs | 59 ++ rust/hw/meson.build | 1 + rust/meson.build | 2 + scripts/archive-source.sh | 4 +- scripts/make-release | 4 +- scripts/rust/rust_root_crate.sh | 13 + subprojects/.gitignore | 7 + subprojects/arbitrary-int-1-rs.wrap | 7 + subprojects/bilge-0.2-rs.wrap | 7 + subprojects/bilge-impl-0.2-rs.wrap | 7 + subprojects/either-1-rs.wrap | 7 + subprojects/itertools-0.11-rs.wrap | 7 + .../arbitrary-int-1-rs/meson.build | 19 + .../packagefiles/bilge-0.2-rs/meson.build | 29 + .../bilge-impl-0.2-rs/meson.build | 45 ++ .../packagefiles/either-1-rs/meson.build | 24 + .../itertools-0.11-rs/meson.build | 30 + .../proc-macro-error-1-rs/meson.build | 40 ++ .../proc-macro-error-attr-1-rs/meson.build | 32 + .../unicode-ident-1-rs/meson.build | 20 + subprojects/proc-macro-error-1-rs.wrap | 7 + subprojects/proc-macro-error-attr-1-rs.wrap | 7 + 37 files changed, 1906 insertions(+), 12 deletions(-) create mode 100644 rust/hw/Kconfig create mode 100644 rust/hw/char/Kconfig create mode 100644 rust/hw/char/meson.build create mode 100644 rust/hw/char/pl011/.gitignore create mode 100644 rust/hw/char/pl011/Cargo.lock create mode 100644 rust/hw/char/pl011/Cargo.toml create mode 100644 rust/hw/char/pl011/README.md create mode 100644 rust/hw/char/pl011/meson.build create mode 100644 rust/hw/char/pl011/src/device.rs create mode 100644 rust/hw/char/pl011/src/device_class.rs create mode 100644 rust/hw/char/pl011/src/lib.rs create mode 100644 rust/hw/char/pl011/src/memory_ops.rs create mode 100644 rust/hw/meson.build create mode 100755 scripts/rust/rust_root_crate.sh create mode 100644 subprojects/arbitrary-int-1-rs.wrap create mode 100644 subprojects/bilge-0.2-rs.wrap create mode 100644 subprojects/bilge-impl-0.2-rs.wrap create mode 100644 subprojects/either-1-rs.wrap create mode 100644 subprojects/itertools-0.11-rs.wrap create mode 100644 subprojects/packagefiles/arbitrary-int-1-rs/meson.build create mode 100644 subprojects/packagefiles/bilge-0.2-rs/meson.build create mode 100644 subprojects/packagefiles/bilge-impl-0.2-rs/meson.build create mode 100644 subprojects/packagefiles/either-1-rs/meson.build create mode 100644 subprojects/packagefiles/itertools-0.11-rs/meson.build create mode 100644 subprojects/packagefiles/proc-macro-error-1-rs/meson.bu= ild create mode 100644 subprojects/packagefiles/proc-macro-error-attr-1-rs/mes= on.build create mode 100644 subprojects/packagefiles/unicode-ident-1-rs/meson.build create mode 100644 subprojects/proc-macro-error-1-rs.wrap create mode 100644 subprojects/proc-macro-error-attr-1-rs.wrap diff --git a/MAINTAINERS b/MAINTAINERS index 3f17295d41e..f48d9142b8a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1138,6 +1138,11 @@ F: include/hw/*/microbit*.h F: tests/qtest/microbit-test.c F: docs/system/arm/nrf.rst =20 +ARM PL011 Rust device +M: Manos Pitsidianakis +S: Maintained +F: rust/hw/char/pl011/ + AVR Machines ------------- =20 diff --git a/meson.build b/meson.build index f290bb70b1d..f7d45175212 100644 --- a/meson.build +++ b/meson.build @@ -3534,6 +3534,7 @@ qom_ss =3D ss.source_set() system_ss =3D ss.source_set() specific_fuzz_ss =3D ss.source_set() specific_ss =3D ss.source_set() +rust_devices_ss =3D ss.source_set() stub_ss =3D ss.source_set() trace_ss =3D ss.source_set() user_ss =3D ss.source_set() @@ -4081,6 +4082,29 @@ foreach target : target_dirs arch_srcs +=3D target_specific.sources() arch_deps +=3D target_specific.dependencies() =20 + if have_rust and have_system + target_rust =3D rust_devices_ss.apply(config_target, strict: false) + crates =3D [] + foreach dep : target_rust.dependencies() + crates +=3D dep.get_variable('crate') + endforeach + if crates.length() > 0 + rlib_rs =3D custom_target('rust_' + target.underscorify() + '.rs', + output: 'rust_' + target.underscorify() + '.= rs', + command: [find_program('scripts/rust/rust_ro= ot_crate.sh')] + crates, + capture: true, + build_by_default: true, + build_always_stale: true) + rlib =3D static_library('rust_' + target.underscorify(), + rlib_rs, + dependencies: target_rust.dependencies(), + override_options: ['rust_std=3D2021', 'build.r= ust_std=3D2021'], + rust_args: rustc_args, + rust_abi: 'c') + arch_deps +=3D declare_dependency(link_whole: [rlib]) + endif + endif + # allow using headers from the dependencies but do not include the sourc= es, # because this emulator only needs those in "objects". For external # dependencies, the full dependency is included below in the executable. diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 53eb7bb3d01..e7fd9338d11 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -20,7 +20,8 @@ config ARM_VIRT select PCI_EXPRESS select PCI_EXPRESS_GENERIC_BRIDGE select PFLASH_CFI01 - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL031 # RTC select PL061 # GPIO select GPIO_PWR @@ -73,7 +74,8 @@ config HIGHBANK select AHCI select ARM_TIMER # sp804 select ARM_V7M - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL022 # SPI select PL031 # RTC select PL061 # GPIO @@ -86,7 +88,8 @@ config INTEGRATOR depends on TCG && ARM select ARM_TIMER select INTEGRATOR_DEBUG - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL031 # RTC select PL041 # audio select PL050 # keyboard/mouse @@ -104,7 +107,8 @@ config MUSCA default y depends on TCG && ARM select ARMSSE - select PL011 + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL031 select SPLIT_IRQ select UNIMP @@ -168,7 +172,8 @@ config REALVIEW select WM8750 # audio codec select LSI_SCSI_PCI select PCI - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL031 # RTC select PL041 # audio codec select PL050 # keyboard/mouse @@ -193,7 +198,8 @@ config SBSA_REF select PCI_EXPRESS select PCI_EXPRESS_GENERIC_BRIDGE select PFLASH_CFI01 - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL031 # RTC select PL061 # GPIO select USB_XHCI_SYSBUS @@ -217,7 +223,8 @@ config STELLARIS select ARM_V7M select CMSDK_APB_WATCHDOG select I2C - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL022 # SPI select PL061 # GPIO select SSD0303 # OLED display @@ -277,7 +284,8 @@ config VEXPRESS select ARM_TIMER # sp804 select LAN9118 select PFLASH_CFI01 - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select PL041 # audio codec select PL181 # display select REALVIEW @@ -362,7 +370,8 @@ config RASPI default y depends on TCG && ARM select FRAMEBUFFER - select PL011 # UART + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select SDHCI select USB_DWC2 select BCM2835_SPI @@ -438,7 +447,8 @@ config XLNX_VERSAL select ARM_GIC select CPU_CLUSTER select DEVICE_TREE - select PL011 + select PL011 if !HAVE_RUST # UART + select X_PL011_RUST if HAVE_RUST # UART select CADENCE select VIRTIO_MMIO select UNIMP diff --git a/rust/Kconfig b/rust/Kconfig index e69de29bb2d..f9f5c390988 100644 --- a/rust/Kconfig +++ b/rust/Kconfig @@ -0,0 +1 @@ +source hw/Kconfig diff --git a/rust/hw/Kconfig b/rust/hw/Kconfig new file mode 100644 index 00000000000..4d934f30afe --- /dev/null +++ b/rust/hw/Kconfig @@ -0,0 +1,2 @@ +# devices Kconfig +source char/Kconfig diff --git a/rust/hw/char/Kconfig b/rust/hw/char/Kconfig new file mode 100644 index 00000000000..a1732a9e97f --- /dev/null +++ b/rust/hw/char/Kconfig @@ -0,0 +1,3 @@ +config X_PL011_RUST + bool + default y if HAVE_RUST diff --git a/rust/hw/char/meson.build b/rust/hw/char/meson.build new file mode 100644 index 00000000000..5716dc43ef6 --- /dev/null +++ b/rust/hw/char/meson.build @@ -0,0 +1 @@ +subdir('pl011') diff --git a/rust/hw/char/pl011/.gitignore b/rust/hw/char/pl011/.gitignore new file mode 100644 index 00000000000..71eaff2035d --- /dev/null +++ b/rust/hw/char/pl011/.gitignore @@ -0,0 +1,2 @@ +# Ignore generated bindings file overrides. +src/bindings.rs.inc diff --git a/rust/hw/char/pl011/Cargo.lock b/rust/hw/char/pl011/Cargo.lock new file mode 100644 index 00000000000..b58cebb186e --- /dev/null +++ b/rust/hw/char/pl011/Cargo.lock @@ -0,0 +1,134 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version =3D 3 + +[[package]] +name =3D "arbitrary-int" +version =3D "1.2.7" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "c84fc003e338a6f69fbd4f7fe9f92b535ff13e9af8997f3b14b6ddff8b1d= f46d" + +[[package]] +name =3D "bilge" +version =3D "0.2.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "dc707ed8ebf81de5cd6c7f48f54b4c8621760926cdf35a57000747c512e6= 7b57" +dependencies =3D [ + "arbitrary-int", + "bilge-impl", +] + +[[package]] +name =3D "bilge-impl" +version =3D "0.2.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000ad= b2d8" +dependencies =3D [ + "itertools", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name =3D "either" +version =3D "1.12.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385= b58b" + +[[package]] +name =3D "itertools" +version =3D "0.11.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3= fe57" +dependencies =3D [ + "either", +] + +[[package]] +name =3D "pl011" +version =3D "0.1.0" +dependencies =3D [ + "bilge", + "bilge-impl", + "qemu_api", + "qemu_api_macros", +] + +[[package]] +name =3D "proc-macro-error" +version =3D "1.0.4" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5c= e38c" +dependencies =3D [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name =3D "proc-macro-error-attr" +version =3D "1.0.4" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35= f869" +dependencies =3D [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name =3D "proc-macro2" +version =3D "1.0.84" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a= 49d6" +dependencies =3D [ + "unicode-ident", +] + +[[package]] +name =3D "qemu_api" +version =3D "0.1.0" + +[[package]] +name =3D "qemu_api_macros" +version =3D "0.1.0" +dependencies =3D [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name =3D "quote" +version =3D "1.0.36" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208ac= aca7" +dependencies =3D [ + "proc-macro2", +] + +[[package]] +name =3D "syn" +version =3D "2.0.66" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cd= cff5" +dependencies =3D [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name =3D "unicode-ident" +version =3D "1.0.12" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0f= ee4b" + +[[package]] +name =3D "version_check" +version =3D "0.9.4" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e= 483f" diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml new file mode 100644 index 00000000000..b089e3dded6 --- /dev/null +++ b/rust/hw/char/pl011/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name =3D "pl011" +version =3D "0.1.0" +edition =3D "2021" +authors =3D ["Manos Pitsidianakis "] +license =3D "GPL-2.0-or-later" +readme =3D "README.md" +homepage =3D "https://www.qemu.org" +description =3D "pl011 device model for QEMU" +repository =3D "https://gitlab.com/epilys/rust-for-qemu" +resolver =3D "2" +publish =3D false +keywords =3D [] +categories =3D [] + +[lib] +crate-type =3D ["staticlib"] + +[dependencies] +bilge =3D { version =3D "0.2.0" } +bilge-impl =3D { version =3D "0.2.0" } +qemu_api =3D { path =3D "../../../qemu-api" } +qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } + +# Do not include in any global workspace +[workspace] diff --git a/rust/hw/char/pl011/README.md b/rust/hw/char/pl011/README.md new file mode 100644 index 00000000000..cd7dea31634 --- /dev/null +++ b/rust/hw/char/pl011/README.md @@ -0,0 +1,31 @@ +# PL011 QEMU Device Model + +This library implements a device model for the PrimeCell=C2=AE UART (PL011) +device in QEMU. + +## Build static lib + +Host build target must be explicitly specified: + +```sh +cargo build --target x86_64-unknown-linux-gnu +``` + +Replace host target triplet if necessary. + +## Generate Rust documentation + +To generate docs for this crate, including private items: + +```sh +cargo doc --no-deps --document-private-items --target x86_64-unknown-linux= -gnu +``` + +To include direct dependencies like `bilge` (bitmaps for register types): + +```sh +cargo tree --depth 1 -e normal --prefix none \ + | cut -d' ' -f1 \ + | xargs printf -- '-p %s\n' \ + | xargs cargo doc --no-deps --document-private-items --target x86_64-unkn= own-linux-gnu +``` diff --git a/rust/hw/char/pl011/meson.build b/rust/hw/char/pl011/meson.build new file mode 100644 index 00000000000..547cca5a96f --- /dev/null +++ b/rust/hw/char/pl011/meson.build @@ -0,0 +1,26 @@ +subproject('bilge-0.2-rs', required: true) +subproject('bilge-impl-0.2-rs', required: true) + +bilge_dep =3D dependency('bilge-0.2-rs') +bilge_impl_dep =3D dependency('bilge-impl-0.2-rs') + +_libpl011_rs =3D static_library( + 'pl011', + files('src/lib.rs'), + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi: 'rust', + dependencies: [ + bilge_dep, + bilge_impl_dep, + qemu_api, + qemu_api_macros, + ], +) + +rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_depende= ncy( + link_whole: [_libpl011_rs], + # Putting proc macro crates in `dependencies` is necessary for Meson to = find + # them when compiling the root per-target static rust lib. + dependencies: [bilge_impl_dep, qemu_api_macros], + variables: {'crate': 'pl011'}, +)]) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs new file mode 100644 index 00000000000..c7193b41bee --- /dev/null +++ b/rust/hw/char/pl011/src/device.rs @@ -0,0 +1,599 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use core::{ + ffi::{c_int, c_uchar, c_uint, c_void, CStr}, + ptr::{addr_of, addr_of_mut, NonNull}, +}; + +use qemu_api::{ + bindings::{self, *}, + definitions::ObjectImpl, +}; + +use crate::{ + memory_ops::PL011_OPS, + registers::{self, Interrupt}, + RegisterOffset, +}; + +static PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0,= 0x05, 0xb1]; + +const DATA_BREAK: u32 =3D 1 << 10; + +/// QEMU sourced constant. +pub const PL011_FIFO_DEPTH: usize =3D 16_usize; + +#[repr(C)] +#[derive(Debug, qemu_api_macros::Object)] +/// PL011 Device Model in QEMU +pub struct PL011State { + pub parent_obj: SysBusDevice, + pub iomem: MemoryRegion, + #[doc(alias =3D "fr")] + pub flags: registers::Flags, + #[doc(alias =3D "lcr")] + pub line_control: registers::LineControl, + #[doc(alias =3D "rsr")] + pub receive_status_error_clear: registers::ReceiveStatusErrorClear, + #[doc(alias =3D "cr")] + pub control: registers::Control, + pub dmacr: u32, + pub int_enabled: u32, + pub int_level: u32, + pub read_fifo: [u32; PL011_FIFO_DEPTH], + pub ilpr: u32, + pub ibrd: u32, + pub fbrd: u32, + pub ifl: u32, + pub read_pos: usize, + pub read_count: usize, + pub read_trigger: usize, + #[doc(alias =3D "chr")] + pub char_backend: CharBackend, + /// QEMU interrupts + /// + /// ```text + /// * sysbus MMIO region 0: device registers + /// * sysbus IRQ 0: `UARTINTR` (combined interrupt line) + /// * sysbus IRQ 1: `UARTRXINTR` (receive FIFO interrupt line) + /// * sysbus IRQ 2: `UARTTXINTR` (transmit FIFO interrupt line) + /// * sysbus IRQ 3: `UARTRTINTR` (receive timeout interrupt line) + /// * sysbus IRQ 4: `UARTMSINTR` (momem status interrupt line) + /// * sysbus IRQ 5: `UARTEINTR` (error interrupt line) + /// ``` + #[doc(alias =3D "irq")] + pub interrupts: [qemu_irq; 6usize], + #[doc(alias =3D "clk")] + pub clock: NonNull, + #[doc(alias =3D "migrate_clk")] + pub migrate_clock: bool, +} + +impl ObjectImpl for PL011State { + type Class =3D PL011Class; + const TYPE_INFO: qemu_api::bindings::TypeInfo =3D qemu_api::type_info!= { Self }; + const TYPE_NAME: &'static CStr =3D crate::TYPE_PL011; + const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(TYPE_SYS_BUS_DE= VICE); + const ABSTRACT: bool =3D false; + const INSTANCE_INIT: Option = =3D Some(pl011_init); + const INSTANCE_POST_INIT: Option =3D None; + const INSTANCE_FINALIZE: Option =3D None; +} + +#[repr(C)] +pub struct PL011Class { + _inner: [u8; 0], +} + +impl qemu_api::definitions::Class for PL011Class { + const CLASS_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), + > =3D Some(crate::device_class::pl011_class_init); + const CLASS_BASE_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), + > =3D None; +} + +#[used] +pub static CLK_NAME: &CStr =3D c"clk"; + +impl PL011State { + /// Initializes a pre-allocated, unitialized instance of `PL011State`. + /// + /// # Safety + /// + /// `self` must point to a correctly sized and aligned location for the + /// `PL011State` type. It must not be called more than once on the same + /// location/instance. All its fields are expected to hold unitialized + /// values with the sole exception of `parent_obj`. + pub unsafe fn init(&mut self) { + let dev =3D addr_of_mut!(*self).cast::(); + // SAFETY: + // + // self and self.iomem are guaranteed to be valid at this point si= nce callers + // must make sure the `self` reference is valid. + unsafe { + memory_region_init_io( + addr_of_mut!(self.iomem), + addr_of_mut!(*self).cast::(), + &PL011_OPS, + addr_of_mut!(*self).cast::(), + Self::TYPE_INFO.name, + 0x1000, + ); + let sbd =3D addr_of_mut!(*self).cast::(); + sysbus_init_mmio(sbd, addr_of_mut!(self.iomem)); + for irq in self.interrupts.iter_mut() { + sysbus_init_irq(sbd, irq); + } + } + // SAFETY: + // + // self.clock is not initialized at this point; but since `NonNull= <_>` is Copy, + // we can overwrite the undefined value without side effects. This= is + // safe since all PL011State instances are created by QOM code whi= ch + // calls this function to initialize the fields; therefore no code= is + // able to access an invalid self.clock value. + unsafe { + self.clock =3D NonNull::new(qdev_init_clock_in( + dev, + CLK_NAME.as_ptr(), + None, /* pl011_clock_update */ + addr_of_mut!(*self).cast::(), + ClockEvent::ClockUpdate.0, + )) + .unwrap(); + } + } + + pub fn read( + &mut self, + offset: hwaddr, + _size: core::ffi::c_uint, + ) -> std::ops::ControlFlow { + use RegisterOffset::*; + + std::ops::ControlFlow::Break(match RegisterOffset::try_from(offset= ) { + Err(v) if (0x3f8..0x400).contains(&v) =3D> { + u64::from(PL011_ID_ARM[((offset - 0xfe0) >> 2) as usize]) + } + Err(_) =3D> { + // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset = 0x%x\n", (int)offset); + 0 + } + Ok(DR) =3D> { + // s->flags &=3D ~PL011_FLAG_RXFF; + self.flags.set_receive_fifo_full(false); + let c =3D self.read_fifo[self.read_pos]; + if self.read_count > 0 { + self.read_count -=3D 1; + self.read_pos =3D (self.read_pos + 1) & (self.fifo_dep= th() - 1); + } + if self.read_count =3D=3D 0 { + // self.flags |=3D PL011_FLAG_RXFE; + self.flags.set_receive_fifo_empty(true); + } + if self.read_count + 1 =3D=3D self.read_trigger { + //self.int_level &=3D ~ INT_RX; + self.int_level &=3D !registers::INT_RX; + } + // Update error bits. + self.receive_status_error_clear =3D c.to_be_bytes()[3].int= o(); + self.update(); + // Must call qemu_chr_fe_accept_input, so return Continue: + return std::ops::ControlFlow::Continue(c.into()); + } + Ok(RSR) =3D> u8::from(self.receive_status_error_clear).into(), + Ok(FR) =3D> u16::from(self.flags).into(), + Ok(FBRD) =3D> self.fbrd.into(), + Ok(ILPR) =3D> self.ilpr.into(), + Ok(IBRD) =3D> self.ibrd.into(), + Ok(LCR_H) =3D> u16::from(self.line_control).into(), + Ok(CR) =3D> { + // We exercise our self-control. + u16::from(self.control).into() + } + Ok(FLS) =3D> self.ifl.into(), + Ok(IMSC) =3D> self.int_enabled.into(), + Ok(RIS) =3D> self.int_level.into(), + Ok(MIS) =3D> u64::from(self.int_level & self.int_enabled), + Ok(ICR) =3D> { + // "The UARTICR Register is the interrupt clear register a= nd is write-only" + // Source: ARM DDI 0183G 3.3.13 Interrupt Clear Register, = UARTICR + 0 + } + Ok(DMACR) =3D> self.dmacr.into(), + }) + } + + pub fn write(&mut self, offset: hwaddr, value: u64) { + // eprintln!("write offset {offset} value {value}"); + use RegisterOffset::*; + let value: u32 =3D value as u32; + match RegisterOffset::try_from(offset) { + Err(_bad_offset) =3D> { + eprintln!("write bad offset {offset} value {value}"); + } + Ok(DR) =3D> { + // ??? Check if transmitter is enabled. + let ch: u8 =3D value as u8; + // XXX this blocks entire thread. Rewrite to use + // qemu_chr_fe_write and background I/O callbacks + + // SAFETY: self.char_backend is a valid CharBackend instan= ce after it's been + // initialized in realize(). + unsafe { + qemu_chr_fe_write_all(addr_of_mut!(self.char_backend),= &ch, 1); + } + self.loopback_tx(value); + self.int_level |=3D registers::INT_TX; + self.update(); + } + Ok(RSR) =3D> { + self.receive_status_error_clear =3D 0.into(); + } + Ok(FR) =3D> { + // flag writes are ignored + } + Ok(ILPR) =3D> { + self.ilpr =3D value; + } + Ok(IBRD) =3D> { + self.ibrd =3D value; + } + Ok(FBRD) =3D> { + self.fbrd =3D value; + } + Ok(LCR_H) =3D> { + let value =3D value as u16; + let new_val: registers::LineControl =3D value.into(); + // Reset the FIFO state on FIFO enable or disable + if bool::from(self.line_control.fifos_enabled()) + ^ bool::from(new_val.fifos_enabled()) + { + self.reset_fifo(); + } + if self.line_control.send_break() ^ new_val.send_break() { + let mut break_enable: c_int =3D new_val.send_break().i= nto(); + // SAFETY: self.char_backend is a valid CharBackend in= stance after it's been + // initialized in realize(). + unsafe { + qemu_chr_fe_ioctl( + addr_of_mut!(self.char_backend), + CHR_IOCTL_SERIAL_SET_BREAK as i32, + addr_of_mut!(break_enable).cast::(), + ); + } + self.loopback_break(break_enable > 0); + } + self.line_control =3D new_val; + self.set_read_trigger(); + } + Ok(CR) =3D> { + // ??? Need to implement the enable bit. + let value =3D value as u16; + self.control =3D value.into(); + self.loopback_mdmctrl(); + } + Ok(FLS) =3D> { + self.ifl =3D value; + self.set_read_trigger(); + } + Ok(IMSC) =3D> { + self.int_enabled =3D value; + self.update(); + } + Ok(RIS) =3D> {} + Ok(MIS) =3D> {} + Ok(ICR) =3D> { + self.int_level &=3D !value; + self.update(); + } + Ok(DMACR) =3D> { + self.dmacr =3D value; + if value & 3 > 0 { + // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemente= d\n"); + eprintln!("pl011: DMA not implemented"); + } + } + } + } + + #[inline] + fn loopback_tx(&mut self, value: u32) { + if !self.loopback_enabled() { + return; + } + + // Caveat: + // + // In real hardware, TX loopback happens at the serial-bit level + // and then reassembled by the RX logics back into bytes and placed + // into the RX fifo. That is, loopback happens after TX fifo. + // + // Because the real hardware TX fifo is time-drained at the frame + // rate governed by the configured serial format, some loopback + // bytes in TX fifo may still be able to get into the RX fifo + // that could be full at times while being drained at software + // pace. + // + // In such scenario, the RX draining pace is the major factor + // deciding which loopback bytes get into the RX fifo, unless + // hardware flow-control is enabled. + // + // For simplicity, the above described is not emulated. + self.put_fifo(value); + } + + fn loopback_mdmctrl(&mut self) { + if !self.loopback_enabled() { + return; + } + + /* + * Loopback software-driven modem control outputs to modem status = inputs: + * FR.RI <=3D CR.Out2 + * FR.DCD <=3D CR.Out1 + * FR.CTS <=3D CR.RTS + * FR.DSR <=3D CR.DTR + * + * The loopback happens immediately even if this call is triggered + * by setting only CR.LBE. + * + * CTS/RTS updates due to enabled hardware flow controls are not + * dealt with here. + */ + + //fr =3D s->flags & ~(PL011_FLAG_RI | PL011_FLAG_DCD | + // PL011_FLAG_DSR | PL011_FLAG_CTS); + //fr |=3D (cr & CR_OUT2) ? PL011_FLAG_RI : 0; + //fr |=3D (cr & CR_OUT1) ? PL011_FLAG_DCD : 0; + //fr |=3D (cr & CR_RTS) ? PL011_FLAG_CTS : 0; + //fr |=3D (cr & CR_DTR) ? PL011_FLAG_DSR : 0; + // + self.flags.set_ring_indicator(self.control.out_2()); + self.flags.set_data_carrier_detect(self.control.out_1()); + self.flags.set_clear_to_send(self.control.request_to_send()); + self.flags + .set_data_set_ready(self.control.data_transmit_ready()); + + // Change interrupts based on updated FR + let mut il =3D self.int_level; + + il &=3D !Interrupt::MS; + //il |=3D (fr & PL011_FLAG_DSR) ? INT_DSR : 0; + //il |=3D (fr & PL011_FLAG_DCD) ? INT_DCD : 0; + //il |=3D (fr & PL011_FLAG_CTS) ? INT_CTS : 0; + //il |=3D (fr & PL011_FLAG_RI) ? INT_RI : 0; + + if self.flags.data_set_ready() { + il |=3D Interrupt::DSR as u32; + } + if self.flags.data_carrier_detect() { + il |=3D Interrupt::DCD as u32; + } + if self.flags.clear_to_send() { + il |=3D Interrupt::CTS as u32; + } + if self.flags.ring_indicator() { + il |=3D Interrupt::RI as u32; + } + self.int_level =3D il; + self.update(); + } + + fn loopback_break(&mut self, enable: bool) { + if enable { + self.loopback_tx(DATA_BREAK); + } + } + + fn set_read_trigger(&mut self) { + self.read_trigger =3D 1; + } + + pub fn realize(&mut self) { + // SAFETY: self.char_backend has the correct size and alignment fo= r a + // CharBackend object, and its callbacks are of the correct types. + unsafe { + qemu_chr_fe_set_handlers( + addr_of_mut!(self.char_backend), + Some(pl011_can_receive), + Some(pl011_receive), + Some(pl011_event), + None, + addr_of_mut!(*self).cast::(), + core::ptr::null_mut(), + true, + ); + } + } + + pub fn reset(&mut self) { + self.line_control.reset(); + self.receive_status_error_clear.reset(); + self.dmacr =3D 0; + self.int_enabled =3D 0; + self.int_level =3D 0; + self.ilpr =3D 0; + self.ibrd =3D 0; + self.fbrd =3D 0; + self.read_trigger =3D 1; + self.ifl =3D 0x12; + self.control.reset(); + self.flags =3D 0.into(); + self.reset_fifo(); + } + + pub fn reset_fifo(&mut self) { + self.read_count =3D 0; + self.read_pos =3D 0; + + /* Reset FIFO flags */ + self.flags.reset(); + } + + pub fn can_receive(&self) -> bool { + // trace_pl011_can_receive(s->lcr, s->read_count, r); + self.read_count < self.fifo_depth() + } + + pub fn event(&mut self, event: QEMUChrEvent) { + if event =3D=3D bindings::QEMUChrEvent::CHR_EVENT_BREAK && !self.f= ifo_enabled() { + self.put_fifo(DATA_BREAK); + self.receive_status_error_clear.set_break_error(true); + } + } + + #[inline] + pub fn fifo_enabled(&self) -> bool { + matches!(self.line_control.fifos_enabled(), registers::Mode::FIFO) + } + + #[inline] + pub fn loopback_enabled(&self) -> bool { + self.control.enable_loopback() + } + + #[inline] + pub fn fifo_depth(&self) -> usize { + // Note: FIFO depth is expected to be power-of-2 + if self.fifo_enabled() { + return PL011_FIFO_DEPTH; + } + 1 + } + + pub fn put_fifo(&mut self, value: c_uint) { + let depth =3D self.fifo_depth(); + assert!(depth > 0); + let slot =3D (self.read_pos + self.read_count) & (depth - 1); + self.read_fifo[slot] =3D value; + self.read_count +=3D 1; + // s->flags &=3D ~PL011_FLAG_RXFE; + self.flags.set_receive_fifo_empty(false); + if self.read_count =3D=3D depth { + //s->flags |=3D PL011_FLAG_RXFF; + self.flags.set_receive_fifo_full(true); + } + + if self.read_count =3D=3D self.read_trigger { + self.int_level |=3D registers::INT_RX; + self.update(); + } + } + + pub fn update(&self) { + let flags =3D self.int_level & self.int_enabled; + for (irq, i) in self.interrupts.iter().zip(IRQMASK) { + // SAFETY: self.interrupts have been initialized in init(). + unsafe { qemu_set_irq(*irq, i32::from(flags & i !=3D 0)) }; + } + } +} + +/// Which bits in the interrupt status matter for each outbound IRQ line ? +pub const IRQMASK: [u32; 6] =3D [ + /* combined IRQ */ + Interrupt::E + | Interrupt::MS + | Interrupt::RT as u32 + | Interrupt::TX as u32 + | Interrupt::RX as u32, + Interrupt::RX as u32, + Interrupt::TX as u32, + Interrupt::RT as u32, + Interrupt::MS, + Interrupt::E, +]; + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011State`]. We also expect the device is +/// readable/writeable from one thread at any time. +#[no_mangle] +pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { + unsafe { + debug_assert!(!opaque.is_null()); + let state =3D NonNull::new_unchecked(opaque.cast::()); + state.as_ref().can_receive().into() + } +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011State`]. We also expect the device is +/// readable/writeable from one thread at any time. +/// +/// The buffer and size arguments must also be valid. +#[no_mangle] +pub unsafe extern "C" fn pl011_receive( + opaque: *mut core::ffi::c_void, + buf: *const u8, + size: core::ffi::c_int, +) { + unsafe { + debug_assert!(!opaque.is_null()); + let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); + if state.as_ref().loopback_enabled() { + return; + } + if size > 0 { + debug_assert!(!buf.is_null()); + state.as_mut().put_fifo(c_uint::from(buf.read_volatile())) + } + } +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011State`]. We also expect the device is +/// readable/writeable from one thread at any time. +#[no_mangle] +pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event= : QEMUChrEvent) { + unsafe { + debug_assert!(!opaque.is_null()); + let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); + state.as_mut().event(event) + } +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer for `c= hr`. +#[no_mangle] +pub unsafe extern "C" fn pl011_create( + addr: u64, + irq: qemu_irq, + chr: *mut Chardev, +) -> *mut DeviceState { + unsafe { + let dev: *mut DeviceState =3D qdev_new(PL011State::TYPE_INFO.name); + let sysbus: *mut SysBusDevice =3D dev.cast::(); + + qdev_prop_set_chr(dev, bindings::TYPE_CHARDEV.as_ptr(), chr); + sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mu= t Error); + sysbus_mmio_map(sysbus, 0, addr); + sysbus_connect_irq(sysbus, 0, irq); + dev + } +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011State`]. We also expect the device is +/// readable/writeable from one thread at any time. +#[no_mangle] +pub unsafe extern "C" fn pl011_init(obj: *mut Object) { + unsafe { + debug_assert!(!obj.is_null()); + let mut state =3D NonNull::new_unchecked(obj.cast::()); + state.as_mut().init(); + } +} diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs new file mode 100644 index 00000000000..b7ab31af02d --- /dev/null +++ b/rust/hw/char/pl011/src/device_class.rs @@ -0,0 +1,70 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use core::ptr::NonNull; + +use qemu_api::{bindings::*, definitions::ObjectImpl}; + +use crate::device::PL011State; + +#[used] +pub static VMSTATE_PL011: VMStateDescription =3D VMStateDescription { + name: PL011State::TYPE_INFO.name, + unmigratable: true, + ..unsafe { ::core::mem::MaybeUninit::::zeroed().as= sume_init() } +}; + +qemu_api::declare_properties! { + PL011_PROPERTIES, + qemu_api::define_property!( + c"chardev", + PL011State, + char_backend, + unsafe { &qdev_prop_chr }, + CharBackend + ), + qemu_api::define_property!( + c"migrate-clk", + PL011State, + migrate_clock, + unsafe { &qdev_prop_bool }, + bool + ), +} + +qemu_api::device_class_init! { + pl011_class_init, + props =3D> PL011_PROPERTIES, + realize_fn =3D> Some(pl011_realize), + legacy_reset_fn =3D> Some(pl011_reset), + vmsd =3D> VMSTATE_PL011, +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011State`]. We also expect the device is +/// readable/writeable from one thread at any time. +#[no_mangle] +pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut = *mut Error) { + unsafe { + assert!(!dev.is_null()); + let mut state =3D NonNull::new_unchecked(dev.cast::()); + state.as_mut().realize(); + } +} + +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011State`]. We also expect the device is +/// readable/writeable from one thread at any time. +#[no_mangle] +pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { + unsafe { + assert!(!dev.is_null()); + let mut state =3D NonNull::new_unchecked(dev.cast::()); + state.as_mut().reset(); + } +} diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs new file mode 100644 index 00000000000..2939ee50c99 --- /dev/null +++ b/rust/hw/char/pl011/src/lib.rs @@ -0,0 +1,586 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later +// +// PL011 QEMU Device Model +// +// This library implements a device model for the PrimeCell=C2=AE UART (PL= 011) +// device in QEMU. +// +#![doc =3D include_str!("../README.md")] +//! # Library crate +//! +//! See [`PL011State`](crate::device::PL011State) for the device model typ= e and +//! the [`registers`] module for register types. + +#![deny( + rustdoc::broken_intra_doc_links, + rustdoc::redundant_explicit_links, + clippy::correctness, + clippy::suspicious, + clippy::complexity, + clippy::perf, + clippy::cargo, + clippy::nursery, + clippy::style, + // restriction group + clippy::dbg_macro, + clippy::as_underscore, + clippy::assertions_on_result_states, + // pedantic group + clippy::doc_markdown, + clippy::borrow_as_ptr, + clippy::cast_lossless, + clippy::option_if_let_else, + clippy::missing_const_for_fn, + clippy::cognitive_complexity, + clippy::missing_safety_doc, + )] + +extern crate bilge; +extern crate bilge_impl; +extern crate qemu_api; + +pub mod device; +pub mod device_class; +pub mod memory_ops; + +pub const TYPE_PL011: &::core::ffi::CStr =3D c"pl011"; + +/// Offset of each register from the base memory address of the device. +/// +/// # Source +/// ARM DDI 0183G, Table 3-1 p.3-3 +#[doc(alias =3D "offset")] +#[allow(non_camel_case_types)] +#[repr(u64)] +#[derive(Debug)] +pub enum RegisterOffset { + /// Data Register + /// + /// A write to this register initiates the actual data transmission + #[doc(alias =3D "UARTDR")] + DR =3D 0x000, + /// Receive Status Register or Error Clear Register + #[doc(alias =3D "UARTRSR")] + #[doc(alias =3D "UARTECR")] + RSR =3D 0x004, + /// Flag Register + /// + /// A read of this register shows if transmission is complete + #[doc(alias =3D "UARTFR")] + FR =3D 0x018, + /// Fractional Baud Rate Register + /// + /// responsible for baud rate speed + #[doc(alias =3D "UARTFBRD")] + FBRD =3D 0x028, + /// `IrDA` Low-Power Counter Register + #[doc(alias =3D "UARTILPR")] + ILPR =3D 0x020, + /// Integer Baud Rate Register + /// + /// Responsible for baud rate speed + #[doc(alias =3D "UARTIBRD")] + IBRD =3D 0x024, + /// line control register (data frame format) + #[doc(alias =3D "UARTLCR_H")] + LCR_H =3D 0x02C, + /// Toggle UART, transmission or reception + #[doc(alias =3D "UARTCR")] + CR =3D 0x030, + /// Interrupt FIFO Level Select Register + #[doc(alias =3D "UARTIFLS")] + FLS =3D 0x034, + /// Interrupt Mask Set/Clear Register + #[doc(alias =3D "UARTIMSC")] + IMSC =3D 0x038, + /// Raw Interrupt Status Register + #[doc(alias =3D "UARTRIS")] + RIS =3D 0x03C, + /// Masked Interrupt Status Register + #[doc(alias =3D "UARTMIS")] + MIS =3D 0x040, + /// Interrupt Clear Register + #[doc(alias =3D "UARTICR")] + ICR =3D 0x044, + /// DMA control Register + #[doc(alias =3D "UARTDMACR")] + DMACR =3D 0x048, + ///// Reserved, offsets `0x04C` to `0x07C`. + //Reserved =3D 0x04C, +} + +impl core::convert::TryFrom for RegisterOffset { + type Error =3D u64; + + fn try_from(value: u64) -> Result { + macro_rules! case { + ($($discriminant:ident),*$(,)*) =3D> { + /* check that matching on all macro arguments compiles, wh= ich means we are not + * missing any enum value; if the type definition ever cha= nges this will stop + * compiling. + */ + const fn _assert_exhaustive(val: RegisterOffset) { + match val { + $(RegisterOffset::$discriminant =3D> (),)* + } + } + + match value { + $(x if x =3D=3D Self::$discriminant as u64 =3D> Ok(Sel= f::$discriminant),)* + _ =3D> Err(value), + } + } + } + case! { DR, RSR, FR, FBRD, ILPR, IBRD, LCR_H, CR, FLS, IMSC, RIS, = MIS, ICR, DMACR } + } +} + +pub mod registers { + //! Device registers exposed as typed structs which are backed by arbi= trary + //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. + //! + //! All PL011 registers are essentially 32-bit wide, but are typed her= e as + //! bitmaps with only the necessary width. That is, if a struct bitmap + //! in this module is for example 16 bits long, it should be conceived + //! as a 32-bit register where the unmentioned higher bits are always + //! unused thus treated as zero when read or written. + use bilge::prelude::*; + + // TODO: FIFO Mode has different semantics + /// Data Register, `UARTDR` + /// + /// The `UARTDR` register is the data register. + /// + /// For words to be transmitted: + /// + /// - if the FIFOs are enabled, data written to this location is pushe= d onto + /// the transmit + /// FIFO + /// - if the FIFOs are not enabled, data is stored in the transmitter + /// holding register (the + /// bottom word of the transmit FIFO). + /// + /// The write operation initiates transmission from the UART. The data= is + /// prefixed with a start bit, appended with the appropriate parity bit + /// (if parity is enabled), and a stop bit. The resultant word is then + /// transmitted. + /// + /// For received words: + /// + /// - if the FIFOs are enabled, the data byte and the 4-bit status (br= eak, + /// frame, parity, + /// and overrun) is pushed onto the 12-bit wide receive FIFO + /// - if the FIFOs are not enabled, the data byte and status are store= d in + /// the receiving + /// holding register (the bottom word of the receive FIFO). + /// + /// The received data byte is read by performing reads from the `UARTD= R` + /// register along with the corresponding status information. The stat= us + /// information can also be read by a read of the `UARTRSR/UARTECR` + /// register. + /// + /// # Note + /// + /// You must disable the UART before any of the control registers are + /// reprogrammed. When the UART is disabled in the middle of + /// transmission or reception, it completes the current character befo= re + /// stopping. + /// + /// # Source + /// ARM DDI 0183G 3.3.1 Data Register, UARTDR + #[bitsize(16)] + #[derive(Clone, Copy, DebugBits, FromBits)] + #[doc(alias =3D "UARTDR")] + pub struct Data { + _reserved: u4, + pub data: u8, + pub framing_error: bool, + pub parity_error: bool, + pub break_error: bool, + pub overrun_error: bool, + } + + // TODO: FIFO Mode has different semantics + /// Receive Status Register / Error Clear Register, `UARTRSR/UARTECR` + /// + /// The UARTRSR/UARTECR register is the receive status register/error = clear + /// register. Receive status can also be read from the `UARTRSR` + /// register. If the status is read from this register, then the status + /// information for break, framing and parity corresponds to the + /// data character read from the [Data register](Data), `UARTDR` prior= to + /// reading the UARTRSR register. The status information for overrun is + /// set immediately when an overrun condition occurs. + /// + /// + /// # Note + /// The received data character must be read first from the [Data + /// Register](Data), `UARTDR` before reading the error status associat= ed + /// with that data character from the `UARTRSR` register. This read + /// sequence cannot be reversed, because the `UARTRSR` register is + /// updated only when a read occurs from the `UARTDR` register. Howeve= r, + /// the status information can also be obtained by reading the `UARTDR` + /// register + /// + /// # Source + /// ARM DDI 0183G 3.3.2 Receive Status Register/Error Clear Register, + /// UARTRSR/UARTECR + #[bitsize(8)] + #[derive(Clone, Copy, DebugBits, FromBits)] + pub struct ReceiveStatusErrorClear { + pub framing_error: bool, + pub parity_error: bool, + pub break_error: bool, + pub overrun_error: bool, + _reserved_unpredictable: u4, + } + + impl ReceiveStatusErrorClear { + pub fn reset(&mut self) { + // All the bits are cleared to 0 on reset. + *self =3D 0.into(); + } + } + + impl Default for ReceiveStatusErrorClear { + fn default() -> Self { + 0.into() + } + } + + #[bitsize(16)] + #[derive(Clone, Copy, DebugBits, FromBits)] + /// Flag Register, `UARTFR` + #[doc(alias =3D "UARTFR")] + pub struct Flags { + /// CTS Clear to send. This bit is the complement of the UART clea= r to + /// send, `nUARTCTS`, modem status input. That is, the bit is 1 + /// when `nUARTCTS` is LOW. + pub clear_to_send: bool, + /// DSR Data set ready. This bit is the complement of the UART dat= a set + /// ready, `nUARTDSR`, modem status input. That is, the bit is 1 w= hen + /// `nUARTDSR` is LOW. + pub data_set_ready: bool, + /// DCD Data carrier detect. This bit is the complement of the UAR= T data + /// carrier detect, `nUARTDCD`, modem status input. That is, the b= it is + /// 1 when `nUARTDCD` is LOW. + pub data_carrier_detect: bool, + /// BUSY UART busy. If this bit is set to 1, the UART is busy + /// transmitting data. This bit remains set until the complete + /// byte, including all the stop bits, has been sent from the + /// shift register. This bit is set as soon as the transmit FIFO + /// becomes non-empty, regardless of whether the UART is enabled + /// or not. + pub busy: bool, + /// RXFE Receive FIFO empty. The meaning of this bit depends on the + /// state of the FEN bit in the UARTLCR_H register. If the FIFO + /// is disabled, this bit is set when the receive holding + /// register is empty. If the FIFO is enabled, the RXFE bit is + /// set when the receive FIFO is empty. + pub receive_fifo_empty: bool, + /// TXFF Transmit FIFO full. The meaning of this bit depends on the + /// state of the FEN bit in the UARTLCR_H register. If the FIFO + /// is disabled, this bit is set when the transmit holding + /// register is full. If the FIFO is enabled, the TXFF bit is + /// set when the transmit FIFO is full. + pub transmit_fifo_full: bool, + /// RXFF Receive FIFO full. The meaning of this bit depends on the= state + /// of the FEN bit in the UARTLCR_H register. If the FIFO is + /// disabled, this bit is set when the receive holding register + /// is full. If the FIFO is enabled, the RXFF bit is set when + /// the receive FIFO is full. + pub receive_fifo_full: bool, + /// Transmit FIFO empty. The meaning of this bit depends on the st= ate of + /// the FEN bit in the [Line Control register](LineControl), + /// `UARTLCR_H`. If the FIFO is disabled, this bit is set when the + /// transmit holding register is empty. If the FIFO is enabled, + /// the TXFE bit is set when the transmit FIFO is empty. This + /// bit does not indicate if there is data in the transmit shift + /// register. + pub transmit_fifo_empty: bool, + /// `RI`, is `true` when `nUARTRI` is `LOW`. + pub ring_indicator: bool, + _reserved_zero_no_modify: u7, + } + + impl Flags { + pub fn reset(&mut self) { + // After reset TXFF, RXFF, and BUSY are 0, and TXFE and RXFE a= re 1 + self.set_receive_fifo_full(false); + self.set_transmit_fifo_full(false); + self.set_busy(false); + self.set_receive_fifo_empty(true); + self.set_transmit_fifo_empty(true); + } + } + + impl Default for Flags { + fn default() -> Self { + let mut ret: Self =3D 0.into(); + ret.reset(); + ret + } + } + + #[bitsize(16)] + #[derive(Clone, Copy, DebugBits, FromBits)] + /// Line Control Register, `UARTLCR_H` + #[doc(alias =3D "UARTLCR_H")] + pub struct LineControl { + /// 15:8 - Reserved, do not modify, read as zero. + _reserved_zero_no_modify: u8, + /// 7 SPS Stick parity select. + /// 0 =3D stick parity is disabled + /// 1 =3D either: + /// =E2=80=A2 if the EPS bit is 0 then the parity bit is transmitt= ed and checked + /// as a 1 =E2=80=A2 if the EPS bit is 1 then the parity bit is + /// transmitted and checked as a 0. This bit has no effect when + /// the PEN bit disables parity checking and generation. See Table= 3-11 + /// on page 3-14 for the parity truth table. + pub sticky_parity: bool, + /// WLEN Word length. These bits indicate the number of data bits + /// transmitted or received in a frame as follows: b11 =3D 8 bits + /// b10 =3D 7 bits + /// b01 =3D 6 bits + /// b00 =3D 5 bits. + pub word_length: WordLength, + /// FEN Enable FIFOs: + /// 0 =3D FIFOs are disabled (character mode) that is, the FIFOs b= ecome + /// 1-byte-deep holding registers 1 =3D transmit and receive FIFO + /// buffers are enabled (FIFO mode). + pub fifos_enabled: Mode, + /// 3 STP2 Two stop bits select. If this bit is set to 1, two stop= bits + /// are transmitted at the end of the frame. The receive + /// logic does not check for two stop bits being received. + pub two_stops_bits: bool, + /// EPS Even parity select. Controls the type of parity the UART u= ses + /// during transmission and reception: + /// - 0 =3D odd parity. The UART generates or checks for an odd nu= mber of + /// 1s in the data and parity bits. + /// - 1 =3D even parity. The UART generates or checks for an even = number + /// of 1s in the data and parity bits. + /// This bit has no effect when the `PEN` bit disables parity chec= king + /// and generation. See Table 3-11 on page 3-14 for the parity + /// truth table. + pub parity: Parity, + /// 1 PEN Parity enable: + /// + /// - 0 =3D parity is disabled and no parity bit added to the data= frame + /// - 1 =3D parity checking and generation is enabled. + /// + /// See Table 3-11 on page 3-14 for the parity truth table. + pub parity_enabled: bool, + /// BRK Send break. + /// + /// If this bit is set to `1`, a low-level is continually output o= n the + /// `UARTTXD` output, after completing transmission of the + /// current character. For the proper execution of the break comma= nd, + /// the software must set this bit for at least two complete + /// frames. For normal use, this bit must be cleared to `0`. + pub send_break: bool, + } + + impl LineControl { + pub fn reset(&mut self) { + // All the bits are cleared to 0 when reset. + *self =3D 0.into(); + } + } + + impl Default for LineControl { + fn default() -> Self { + 0.into() + } + } + + #[bitsize(1)] + #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] + /// `EPS` "Even parity select", field of [Line Control + /// register](LineControl). + pub enum Parity { + /// - 0 =3D odd parity. The UART generates or checks for an odd nu= mber of + /// 1s in the data and parity bits. + Odd =3D 0, + /// - 1 =3D even parity. The UART generates or checks for an even = number + /// of 1s in the data and parity bits. + Even =3D 1, + } + + #[bitsize(1)] + #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] + /// `FEN` "Enable FIFOs" or Device mode, field of [Line Control + /// register](LineControl). + pub enum Mode { + /// 0 =3D FIFOs are disabled (character mode) that is, the FIFOs b= ecome + /// 1-byte-deep holding registers + Character =3D 0, + /// 1 =3D transmit and receive FIFO buffers are enabled (FIFO mode= ). + FIFO =3D 1, + } + + impl From for bool { + fn from(val: Mode) -> Self { + matches!(val, Mode::FIFO) + } + } + + #[bitsize(2)] + #[derive(Clone, Copy, Debug, Eq, FromBits, PartialEq)] + /// `WLEN` Word length, field of [Line Control register](LineControl). + /// + /// These bits indicate the number of data bits transmitted or receive= d in a + /// frame as follows: + pub enum WordLength { + /// b11 =3D 8 bits + _8Bits =3D 0b11, + /// b10 =3D 7 bits + _7Bits =3D 0b10, + /// b01 =3D 6 bits + _6Bits =3D 0b01, + /// b00 =3D 5 bits. + _5Bits =3D 0b00, + } + + /// Control Register, `UARTCR` + /// + /// The `UARTCR` register is the control register. All the bits are cl= eared + /// to `0` on reset except for bits `9` and `8` that are set to `1`. + /// + /// # Source + /// ARM DDI 0183G, 3.3.8 Control Register, `UARTCR`, Table 3-12 + #[bitsize(16)] + #[doc(alias =3D "UARTCR")] + #[derive(Clone, Copy, DebugBits, FromBits)] + pub struct Control { + /// `UARTEN` UART enable: 0 =3D UART is disabled. If the UART is d= isabled + /// in the middle of transmission or reception, it completes the c= urrent + /// character before stopping. 1 =3D the UART is enabled. Data + /// transmission and reception occurs for either UART signals or S= IR + /// signals depending on the setting of the SIREN bit. + pub enable_uart: bool, + /// `SIREN` `SIR` enable: 0 =3D IrDA SIR ENDEC is disabled. `nSIRO= UT` + /// remains LOW (no light pulse generated), and signal transitions= on + /// SIRIN have no effect. 1 =3D IrDA SIR ENDEC is enabled. Data is + /// transmitted and received on nSIROUT and SIRIN. UARTTXD remains= HIGH, + /// in the marking state. Signal transitions on UARTRXD or modem s= tatus + /// inputs have no effect. This bit has no effect if the UARTEN bit + /// disables the UART. + pub enable_sir: bool, + /// `SIRLP` SIR low-power IrDA mode. This bit selects the IrDA enc= oding + /// mode. If this bit is cleared to 0, low-level bits are transmit= ted as + /// an active high pulse with a width of 3/ 16th of the bit period= . If + /// this bit is set to 1, low-level bits are transmitted with a pu= lse + /// width that is 3 times the period of the IrLPBaud16 input signa= l, + /// regardless of the selected bit rate. Setting this bit uses less + /// power, but might reduce transmission distances. + pub sir_lowpower_irda_mode: u1, + /// Reserved, do not modify, read as zero. + _reserved_zero_no_modify: u4, + /// `LBE` Loopback enable. If this bit is set to 1 and the SIREN b= it is + /// set to 1 and the SIRTEST bit in the Test Control register, UAR= TTCR + /// on page 4-5 is set to 1, then the nSIROUT path is inverted, an= d fed + /// through to the SIRIN path. The SIRTEST bit in the test registe= r must + /// be set to 1 to override the normal half-duplex SIR operation. = This + /// must be the requirement for accessing the test registers during + /// normal operation, and SIRTEST must be cleared to 0 when loopba= ck + /// testing is finished. This feature reduces the amount of extern= al + /// coupling required during system test. If this bit is set to 1,= and + /// the SIRTEST bit is set to 0, the UARTTXD path is fed through t= o the + /// UARTRXD path. In either SIR mode or UART mode, when this bit i= s set, + /// the modem outputs are also fed through to the modem inputs. Th= is bit + /// is cleared to 0 on reset, to disable loopback. + pub enable_loopback: bool, + /// `TXE` Transmit enable. If this bit is set to 1, the transmit s= ection + /// of the UART is enabled. Data transmission occurs for either UA= RT + /// signals, or SIR signals depending on the setting of the SIREN = bit. + /// When the UART is disabled in the middle of transmission, it + /// completes the current character before stopping. + pub enable_transmit: bool, + /// `RXE` Receive enable. If this bit is set to 1, the receive sec= tion + /// of the UART is enabled. Data reception occurs for either UART + /// signals or SIR signals depending on the setting of the SIREN b= it. + /// When the UART is disabled in the middle of reception, it compl= etes + /// the current character before stopping. + pub enable_receive: bool, + /// `DTR` Data transmit ready. This bit is the complement of the U= ART + /// data transmit ready, `nUARTDTR`, modem status output. That is,= when + /// the bit is programmed to a 1 then `nUARTDTR` is LOW. + pub data_transmit_ready: bool, + /// `RTS` Request to send. This bit is the complement of the UART + /// request to send, `nUARTRTS`, modem status output. That is, whe= n the + /// bit is programmed to a 1 then `nUARTRTS` is LOW. + pub request_to_send: bool, + /// `Out1` This bit is the complement of the UART Out1 (`nUARTOut1= `) + /// modem status output. That is, when the bit is programmed to a = 1 the + /// output is 0. For DTE this can be used as Data Carrier Detect (= DCD). + pub out_1: bool, + /// `Out2` This bit is the complement of the UART Out2 (`nUARTOut2= `) + /// modem status output. That is, when the bit is programmed to a = 1, the + /// output is 0. For DTE this can be used as Ring Indicator (RI). + pub out_2: bool, + /// `RTSEn` RTS hardware flow control enable. If this bit is set t= o 1, + /// RTS hardware flow control is enabled. Data is only requested w= hen + /// there is space in the receive FIFO for it to be received. + pub rts_hardware_flow_control_enable: bool, + /// `CTSEn` CTS hardware flow control enable. If this bit is set t= o 1, + /// CTS hardware flow control is enabled. Data is only transmitted= when + /// the `nUARTCTS` signal is asserted. + pub cts_hardware_flow_control_enable: bool, + } + + impl Control { + pub fn reset(&mut self) { + *self =3D 0.into(); + self.set_enable_receive(true); + self.set_enable_transmit(true); + } + } + + impl Default for Control { + fn default() -> Self { + let mut ret: Self =3D 0.into(); + ret.reset(); + ret + } + } + + /// Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC + pub const INT_OE: u32 =3D 1 << 10; + pub const INT_BE: u32 =3D 1 << 9; + pub const INT_PE: u32 =3D 1 << 8; + pub const INT_FE: u32 =3D 1 << 7; + pub const INT_RT: u32 =3D 1 << 6; + pub const INT_TX: u32 =3D 1 << 5; + pub const INT_RX: u32 =3D 1 << 4; + pub const INT_DSR: u32 =3D 1 << 3; + pub const INT_DCD: u32 =3D 1 << 2; + pub const INT_CTS: u32 =3D 1 << 1; + pub const INT_RI: u32 =3D 1 << 0; + pub const INT_E: u32 =3D INT_OE | INT_BE | INT_PE | INT_FE; + pub const INT_MS: u32 =3D INT_RI | INT_DSR | INT_DCD | INT_CTS; + + #[repr(u32)] + pub enum Interrupt { + OE =3D 1 << 10, + BE =3D 1 << 9, + PE =3D 1 << 8, + FE =3D 1 << 7, + RT =3D 1 << 6, + TX =3D 1 << 5, + RX =3D 1 << 4, + DSR =3D 1 << 3, + DCD =3D 1 << 2, + CTS =3D 1 << 1, + RI =3D 1 << 0, + } + + impl Interrupt { + pub const E: u32 =3D INT_OE | INT_BE | INT_PE | INT_FE; + pub const MS: u32 =3D INT_RI | INT_DSR | INT_DCD | INT_CTS; + } +} + +// TODO: You must disable the UART before any of the control registers are +// reprogrammed. When the UART is disabled in the middle of transmission or +// reception, it completes the current character before stopping diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/= memory_ops.rs new file mode 100644 index 00000000000..8d066ebf6d0 --- /dev/null +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -0,0 +1,59 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use core::{mem::MaybeUninit, ptr::NonNull}; + +use qemu_api::bindings::*; + +use crate::device::PL011State; + +pub static PL011_OPS: MemoryRegionOps =3D MemoryRegionOps { + read: Some(pl011_read), + write: Some(pl011_write), + read_with_attrs: None, + write_with_attrs: None, + endianness: device_endian::DEVICE_NATIVE_ENDIAN, + valid: unsafe { MaybeUninit::::zeroed()= .assume_init() }, + impl_: MemoryRegionOps__bindgen_ty_2 { + min_access_size: 4, + max_access_size: 4, + ..unsafe { MaybeUninit::::zeroed().= assume_init() } + }, +}; + +#[no_mangle] +unsafe extern "C" fn pl011_read( + opaque: *mut core::ffi::c_void, + addr: hwaddr, + size: core::ffi::c_uint, +) -> u64 { + assert!(!opaque.is_null()); + let mut state =3D unsafe { NonNull::new_unchecked(opaque.cast::()) }; + let val =3D unsafe { state.as_mut().read(addr, size) }; + match val { + std::ops::ControlFlow::Break(val) =3D> val, + std::ops::ControlFlow::Continue(val) =3D> { + // SAFETY: self.char_backend is a valid CharBackend instance a= fter it's been + // initialized in realize(). + let cb_ptr =3D unsafe { core::ptr::addr_of_mut!(state.as_mut()= .char_backend) }; + unsafe { qemu_chr_fe_accept_input(cb_ptr) }; + + val + } + } +} + +#[no_mangle] +unsafe extern "C" fn pl011_write( + opaque: *mut core::ffi::c_void, + addr: hwaddr, + data: u64, + _size: core::ffi::c_uint, +) { + unsafe { + assert!(!opaque.is_null()); + let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); + state.as_mut().write(addr, data) + } +} diff --git a/rust/hw/meson.build b/rust/hw/meson.build new file mode 100644 index 00000000000..860196645e7 --- /dev/null +++ b/rust/hw/meson.build @@ -0,0 +1 @@ +subdir('char') diff --git a/rust/meson.build b/rust/meson.build index 7a32b1b1950..def77389cdd 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,2 +1,4 @@ subdir('qemu-api-macros') subdir('qemu-api') + +subdir('hw') diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index 62a2cf45d28..30677c3ec90 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -27,7 +27,9 @@ sub_file=3D"${sub_tdir}/submodule.tar" # in their checkout, because the build environment is completely # different to the host OS. subprojects=3D"keycodemapdb libvfio-user berkeley-softfloat-3 - berkeley-testfloat-3 proc-macro2-1-rs quote-1-rs + berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs + bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs + proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" sub_deinit=3D"" =20 diff --git a/scripts/make-release b/scripts/make-release index cf7d694ef73..8dc939124c4 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -18,7 +18,9 @@ fi =20 # Only include wraps that are invoked with subproject() SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softfloat-3 - berkeley-testfloat-3 proc-macro2-1-rs quote-1-rs + berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs + bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs + proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" =20 src=3D"$1" diff --git a/scripts/rust/rust_root_crate.sh b/scripts/rust/rust_root_crate= .sh new file mode 100755 index 00000000000..975bddf7f1a --- /dev/null +++ b/scripts/rust/rust_root_crate.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -eu + +cat < (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741419611682.8190250587087; Mon, 4 Nov 2024 09:30:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rm-00055v-Le; Mon, 04 Nov 2024 12:27:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rj-00053h-VO for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rZ-00007c-Pu for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:47 -0500 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-GuEF6pGkPS6jPRsPNrG2bg-1; Mon, 04 Nov 2024 12:27:35 -0500 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539f7ed336bso2776396e87.2 for ; Mon, 04 Nov 2024 09:27:35 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10b7c2bsm13787311f8f.23.2024.11.04.09.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KsXnct9jOSuPLQFzAaGlvw55sZX5mXIut7PiLhLE4FI=; b=KbeNe4qJ5Ik4uKjBzJIVymmH6PDux/D9Od6UNcHDCK2wP692H6O1i8ELa+H+8LkFPLXMAP /EgC8hCiqYz80obNODG9FJNQ7mFidKdewltAyU/jCd73lK/wIZ8p9SP7OveEH0xLPcTUqP qaenKkRjPjPm+tfwdGF9O0luf0Y7WjY= X-MC-Unique: GuEF6pGkPS6jPRsPNrG2bg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741253; x=1731346053; 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=KsXnct9jOSuPLQFzAaGlvw55sZX5mXIut7PiLhLE4FI=; b=Hq84qPrhPTGqUTLQnvD8Q2wdN/otDe200iuTYPpE4BiP/EqmxjNdnFMX4B5YzsB6UZ c4tpOVK53hp3PzOLr0K1cOuJnLqKoUJT/bhMoVVR9yPf7BV6tFH5CoYkluCb47TmP6eA PJ/pYLrc/d9OGVO/bjCcaQ4KZcMkuseGC7rX76/scp6A3pejAZhroY0SEvcRipGSts8+ +86JdtT1+sVg6YPmY+WCsuTFmcGdmNUiOHCLhBUxndNeTV7XEAYKlAqjf/fv4w3zJPty TOV8U47uyTLIzlTygEm9kQJknGjAD38+sKWY3FUHMTorVhUR7d/p0qzzVY7aNBZtHFRr GG2w== X-Gm-Message-State: AOJu0YyYbeKEs4tNH/HBHvVPcn/fZjz7jylElLI2bU5ZewEgjl6WaG9/ oca0KvEn7D3vm9m0LzG0y8VVRlAsLqaEqBpOjsDf3VfD5/YgQ74ed9J3kkKrIv9z6R0vKq1X4qF C7aIXrXqypzxo9vj5SEhCavCXKJETn9rlVSZzHHjqVxJDUks1OP1KwnSqdcsbObuDsWI0k4xiP2 qJo+d92PPTtsbe+x6j5E65ETszlRKAsmCIH+RpY90= X-Received: by 2002:a05:6512:1092:b0:53b:20a1:1c4a with SMTP id 2adb3069b0e04-53b34a19077mr16160843e87.42.1730741253382; Mon, 04 Nov 2024 09:27:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfQW3qVGu5BqFQ/U4DyIUy6sR4ljt9kykUVZo2l3HZNp8nBfaEZzLJ8xsHm/ywUb99RmMXHw== X-Received: by 2002:a05:6512:1092:b0:53b:20a1:1c4a with SMTP id 2adb3069b0e04-53b34a19077mr16160818e87.42.1730741252801; Mon, 04 Nov 2024 09:27:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 05/40] meson: import rust module into a global variable Date: Mon, 4 Nov 2024 18:26:44 +0100 Message-ID: <20241104172721.180255-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741422041116600 Content-Type: text/plain; charset="utf-8" Tested-by: Manos Pitsidianakis Reviewed-by: Manos Pitsidianakis Reviewed-by: Zhao Liu Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- meson.build | 3 ++- rust/qemu-api-macros/meson.build | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index f7d45175212..dd6193c4c37 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ meson.add_postconf_script(find_program('scripts/symlink-i= nstall-tree.py')) =20 not_found =3D dependency('', required: false) keyval =3D import('keyval') +rust =3D import('rust') ss =3D import('sourceset') fs =3D import('fs') =20 @@ -3977,7 +3978,7 @@ if have_rust and have_system # this case you must pass the path to `clang` and `libclang` to your bui= ld # command invocation using the environment variables CLANG_PATH and # LIBCLANG_PATH - bindings_rs =3D import('rust').bindgen( + bindings_rs =3D rust.bindgen( input: 'rust/wrapper.h', dependencies: common_ss.all_dependencies(), output: 'bindings.rs', diff --git a/rust/qemu-api-macros/meson.build b/rust/qemu-api-macros/meson.= build index 517b9a4d2d5..24325dea5c2 100644 --- a/rust/qemu-api-macros/meson.build +++ b/rust/qemu-api-macros/meson.build @@ -2,7 +2,7 @@ quote_dep =3D dependency('quote-1-rs', native: true) syn_dep =3D dependency('syn-2-rs', native: true) proc_macro2_dep =3D dependency('proc-macro2-1-rs', native: true) =20 -_qemu_api_macros_rs =3D import('rust').proc_macro( +_qemu_api_macros_rs =3D rust.proc_macro( 'qemu_api_macros', files('src/lib.rs'), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741507; cv=none; d=zohomail.com; s=zohoarc; b=Q1c3MWDLa0CIKjUA2hCfrDJhXVbjIZMoBqqpif8OO0lIsjxE98HbyXSUKpAVlBcU4tnlg0PQ0kTRrLqy9saGtEWy5qL6+lYWqDXbABm9R85wIa9GTz+YL52++clkHTHMP+Ivt/J6dthlWeQqR4N0+GEj1J7UhTYRw/j+FgepiYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741507; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AON/XT4j/Jh3wZo3lxffNCb05X1SO/4GSB7Qx3W9Ekc=; b=RfXJSfutU7OQ7h0Frri3vJZLmEawYRAMbFBHnZwSHxUFLzZsTaRhqlun9ORf1N9GiV73DWa4utvcKvwMb4ixjcFiC4M8BXOszaCR+KKeutfSOEzoTgMvLYxjD0C4vRx24X2s+RuZ4CHzf4qGwGZjScfcBbPWRCX0bQmMNt6RP80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741507726608.3025724019386; Mon, 4 Nov 2024 09:31:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rk-00053t-KH; Mon, 04 Nov 2024 12:27:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rh-00052K-KJ for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rb-00008X-IE for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:45 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-rL9Z6vPHNAyjlM_l-XCyjA-1; Mon, 04 Nov 2024 12:27:37 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso25364595e9.0 for ; Mon, 04 Nov 2024 09:27:37 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c116abc0sm13709942f8f.94.2024.11.04.09.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AON/XT4j/Jh3wZo3lxffNCb05X1SO/4GSB7Qx3W9Ekc=; b=eatLCB24rsPMPPR2Pkoqcz3vf5LybWYCQOFxeTNmIpLkcAiIWRhW4n8oFT2jtc0p0JPLl3 UxIcDR8gX7rLVEdK37SpXl3+eOrBcJJag+UFwh+ANqWTMGueKF/M3IR4lEmMnE65aevuNX qCl4BdQQVDQ78L5iQTzfBZ/mv3NZs6U= X-MC-Unique: rL9Z6vPHNAyjlM_l-XCyjA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741256; x=1731346056; 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=AON/XT4j/Jh3wZo3lxffNCb05X1SO/4GSB7Qx3W9Ekc=; b=e0FXeFjsFl4GYKuLBowNPU6Nh9unoNhS4CIaHhXSa5J+JxklB7f140uQJKkIiZ0vLQ SzUdQZwVItu0kjKVvS8vJzFxLE9jo5tACJP36+LFeTYyTAhc5u2ngAoFOjdLgOBjPWlu C8piyIIgIUfVByewp0T8T5MW2pBVk2Do94cAa1+s8LAUphlslGx9WJbZ0m69eFJ7lTlT USpVEhnTjc2kxJ5EM2pIQOpzzp6aWjlf24nnFjjsJX6pfgGXn+yP6ONuRbXXZftdHF6D vqhnfSmOheKmP2JM10ck6FufkI72ecNz1XXkGIOHb7WwsONxT+LyDQbI2U0bEXl5cXWQ K0kQ== X-Gm-Message-State: AOJu0YzxiMCs3eaPHBrkZAaF71pvbLx8/SEcetZEc+fZpHwbV3UaCpkm 6rj+Z67lBtPi6sqEclcbImw944uNOH21wOTMSOvuJzAREkY+zdD0K8gNGSfOU0Cnc2Q+zM9L4gE Zd2jbNI1304Xsbo0Q1BCM8PmT9WmaAc/tH5njI9UpBD83sDP5O7cABT0hOb1D2n5UVze52c2Fb/ SxHps1FqeRW4QmwqtGCaxKntlySlX/WUSoatwDGOE= X-Received: by 2002:a05:600c:45cd:b0:42c:b98d:b993 with SMTP id 5b1f17b1804b1-4327da72175mr123417985e9.2.1730741255871; Mon, 04 Nov 2024 09:27:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGA/UEY9bUiqH6wRQsM0gEtD2CU1iyDe8/8hZL7x/Hip8/PaqTIMXudNurjoDLBHOfrvF0jsw== X-Received: by 2002:a05:600c:45cd:b0:42c:b98d:b993 with SMTP id 5b1f17b1804b1-4327da72175mr123417745e9.2.1730741255507; Mon, 04 Nov 2024 09:27:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 06/40] meson: remove repeated search for rust_root_crate.sh Date: Mon, 4 Nov 2024 18:26:45 +0100 Message-ID: <20241104172721.180255-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741508090116600 Content-Type: text/plain; charset="utf-8" Avoid repeated lines of the form Program scripts/rust/rust_root_crate.sh found: YES (/home/pbonzini/work/ups= tream/qemu/scripts/rust/rust_root_crate.sh) in the meson logs. Reviewed-by: Junjie Mao Reviewed-by: Zhao Liu Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index dd6193c4c37..29a8df6d5f2 100644 --- a/meson.build +++ b/meson.build @@ -3991,6 +3991,7 @@ endif =20 =20 feature_to_c =3D find_program('scripts/feature_to_c.py') +rust_root_crate =3D find_program('scripts/rust/rust_root_crate.sh') =20 if host_os =3D=3D 'darwin' entitlement =3D find_program('scripts/entitlement.sh') @@ -4092,7 +4093,7 @@ foreach target : target_dirs if crates.length() > 0 rlib_rs =3D custom_target('rust_' + target.underscorify() + '.rs', output: 'rust_' + target.underscorify() + '.= rs', - command: [find_program('scripts/rust/rust_ro= ot_crate.sh')] + crates, + command: [rust_root_crate, crates], capture: true, build_by_default: true, build_always_stale: true) --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741473; cv=none; d=zohomail.com; s=zohoarc; b=Up5K7j/XXdMmawW1nQxtlfD64rJIkyYG0NpXuVrXLyAtgjFDVkG+QVwMc2DcnT/BGJeuj1uK0/9+W8qkggn964iQCNHnCYRviGD5a+sen49OFqVHZmchl+fdKlhZDODchx3WxjeUJFvxzy3JdVBcNhi9jXiSNRKB4BkPKK7aKj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741473; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5qAG6ukCd1KkybKSvqNo8XTeuhbkZsfnPzCuHeVYnsk=; b=jn0601r1vka7+h8EhCfiBdV5I5OCw81D/T8ueU1gomfM1w6fxXchg7H7Hum40Ex+WoxoP8qsh32EFDIE3i17uOST60u+w6l37KlNbxXp3x8W6s/bmVPSYT6ti3gfLVuxHAYqgZwq/BesGbeaXg8p4g85mgkG2aCzKTGqhKIvFrA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741473558717.1056760705249; Mon, 4 Nov 2024 09:31:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rq-000584-PA; Mon, 04 Nov 2024 12:27:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rm-00055h-FD for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rh-0000AN-SD for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:49 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376-9yHG4_xxP9q-HKr8swn2AA-1; Mon, 04 Nov 2024 12:27:40 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d4a211177so2261463f8f.0 for ; Mon, 04 Nov 2024 09:27:40 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e734csm13734062f8f.60.2024.11.04.09.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5qAG6ukCd1KkybKSvqNo8XTeuhbkZsfnPzCuHeVYnsk=; b=A4py+fU9Nuce7VzJrYwSzmULeDG1tvuL+Vtm92nJaSHYTag5JU5bLmdGIyL0nlB+Bbuwcs S3ztZxHGPm+SwQ8TEjVPZhRcBm1szK3N3ae9SQ6bvKx9uIHNA7eNiuYGY2WMq8uFFBNo7i Cjps+cnBcIgwhdKBKVr4T/7HvL9IeV0= X-MC-Unique: 9yHG4_xxP9q-HKr8swn2AA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741259; x=1731346059; 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=5qAG6ukCd1KkybKSvqNo8XTeuhbkZsfnPzCuHeVYnsk=; b=RSP/ZmXvHvz+jB9cMRsiBP0KUynqjZ6m1QYXNd7WXP/TUTv6u/r3HJ+iSyAa3i588v K9XLZ40z1piwL0SxxNYDiRhuIqWX1iFGVBSCKvUFzzFwcuHsY0uFjkOjb1NV/sdGnHV9 2/5oeUAUw+k7wKW8cqyQdadylgFDPThqIVAwjdIE7XRxJeVW2/Hfyie4oKGVopTFGnIJ l+09LEZqgiBwWYYuf6K4l85GcDCz3d5ExPXd3czwNtTcJeK32d3vsmeuSSsfZ68CQADh rXA1M3HYJl/7PFQ6F3fM4Yod0UIdJ+Q4te5h1p7cCjTCbeBAw7Q7Wtnr6FDnzdhZFWN4 HOgQ== X-Gm-Message-State: AOJu0YybIQ1jFwMvhz6Pm69mDpGqNlG11+vdQGoGIFs2fqqlaqJy7Emo v6iToj3x7KZe9N9cIDxjtVnZZWAjR1ep1izGOnBThg4ky/miE+j64zq8/841SzL+K8vhV8ZK4NG bwIXQ09stthrMHayV6WdS1Pu1hGg0W05X/AeN0KrUYJDMSlPzK0asb7l2uWwFPzz5XQCOH6ZwmV 9+G6Z9hXGyu7MO4g9bPqtk2C6bYfRwSOgTaH+ZDyI= X-Received: by 2002:a05:6000:1fac:b0:381:bdeb:1799 with SMTP id ffacd0b85a97d-381bdeb17fbmr15377240f8f.16.1730741258949; Mon, 04 Nov 2024 09:27:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7NZXabIEkdsFFPILyejhCm5PfJJQL1aLm17DaQ0eefZ4AIfNUkM6m6H99PeqSZSfAd7xJCg== X-Received: by 2002:a05:6000:1fac:b0:381:bdeb:1799 with SMTP id ffacd0b85a97d-381bdeb17fbmr15377208f8f.16.1730741257893; Mon, 04 Nov 2024 09:27:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 07/40] meson: pass rustc_args when building all crates Date: Mon, 4 Nov 2024 18:26:46 +0100 Message-ID: <20241104172721.180255-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741475783116600 Content-Type: text/plain; charset="utf-8" rustc_args is needed to smooth the difference in warnings between the vario= us versions of rustc. Always include those arguments. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- meson.build | 20 +++++++++++++------- rust/qemu-api/meson.build | 2 +- rust/qemu-api/src/device_class.rs | 10 ++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index 29a8df6d5f2..7d06d2fe74e 100644 --- a/meson.build +++ b/meson.build @@ -3331,6 +3331,19 @@ endif =20 genh +=3D configure_file(output: 'config-host.h', configuration: config_ho= st_data) =20 +if have_rust and have_system + rustc_args =3D run_command( + find_program('scripts/rust/rustc_args.py'), + '--config-headers', meson.project_build_root() / 'config-host.h', + capture : true, + check: true).stdout().strip().split() + + # Prohibit code that is forbidden in Rust 2024 + rustc_args +=3D ['-D', 'unsafe_op_in_unsafe_fn'] + add_project_arguments(rustc_args, native: false, language: 'rust') + add_project_arguments(rustc_args, native: true, language: 'rust') +endif + hxtool =3D find_program('scripts/hxtool') shaderinclude =3D find_program('scripts/shaderinclude.py') qapi_gen =3D find_program('scripts/qapi-gen.py') @@ -3923,12 +3936,6 @@ common_all =3D static_library('common', dependencies: common_ss.all_dependencies()) =20 if have_rust and have_system - rustc_args =3D run_command( - find_program('scripts/rust/rustc_args.py'), - '--config-headers', meson.project_build_root() / 'config-host.h', - capture : true, - check: true).stdout().strip().split() - rustc_args +=3D ['-D', 'unsafe_op_in_unsafe_fn'] bindgen_args =3D [ '--disable-header-comment', '--raw-line', '// @generated', @@ -4101,7 +4108,6 @@ foreach target : target_dirs rlib_rs, dependencies: target_rust.dependencies(), override_options: ['rust_std=3D2021', 'build.r= ust_std=3D2021'], - rust_args: rustc_args, rust_abi: 'c') arch_deps +=3D declare_dependency(link_whole: [rlib]) endif diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index c72d34b607d..42ea815fa5a 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -10,7 +10,7 @@ _qemu_api_rs =3D static_library( ), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', - rust_args: rustc_args + [ + rust_args: [ '--cfg', 'MESON', # '--cfg', 'feature=3D"allocator"', ], diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index 1ea95beb78d..b6b68cf9ce2 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -16,10 +16,12 @@ macro_rules! device_class_init { ) { let mut dc =3D ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::D= eviceClass>()).unwrap(); - dc.as_mut().realize =3D $realize_fn; - dc.as_mut().vmsd =3D &$vmsd; - $crate::bindings::device_class_set_legacy_reset(dc.as_mut(), $= legacy_reset_fn); - $crate::bindings::device_class_set_props(dc.as_mut(), $props.a= s_mut_ptr()); + unsafe { + dc.as_mut().realize =3D $realize_fn; + dc.as_mut().vmsd =3D &$vmsd; + $crate::bindings::device_class_set_legacy_reset(dc.as_mut(= ), $legacy_reset_fn); + $crate::bindings::device_class_set_props(dc.as_mut(), $pro= ps.as_mut_ptr()); + } } }; } --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741334; cv=none; d=zohomail.com; s=zohoarc; b=JXanKSCFcAhCMkYA8h/PV9KlWa/EzjvHRJ2lKhpJvLoZ06KLvbGoGPnLW7zd8N5D0yNMVp0WJjbH0fa5nKHb8I/Exmn64hn5l6yc/Jw5Ogcl1mxNckDIPDaJEt5go0t2WwD2+icL7N2RDNRTe8agkJjz/zvf22TkumltppMS5Lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741334; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EGXu5CBuE8xwKZlIqcgq1tN+U8GgEV5+6D9N6jIde4E=; b=f6o6QcmrGl39jyXAgdsPjRdY6NjPdRzZ5D9S90rBwM9B+L/LWMUHb3E7xV4EtQhGsBI3dlBezPN6s41V4XEhOB/0VlXCUj9+vlDb3LxTs1Q5m1IZ1Ba0I3IfDr5W1ARFHy0IkOVZgM9jxxbjmG/NiR4n0TT9kZnWy7p506PyqC4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741334959435.28287470532325; Mon, 4 Nov 2024 09:28:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rq-000583-Op; Mon, 04 Nov 2024 12:27:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rn-00056S-EK for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rg-0000BF-I9 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:51 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-tyMd9xvCPYiFOmxoGtUvGg-1; Mon, 04 Nov 2024 12:27:42 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4327bd6bd60so30190135e9.1 for ; Mon, 04 Nov 2024 09:27:42 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c113e69fsm13732368f8f.69.2024.11.04.09.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EGXu5CBuE8xwKZlIqcgq1tN+U8GgEV5+6D9N6jIde4E=; b=NdMdb2RceOy1kvkjwZ7j9ggWBQgGow+shSOm6f2yW2PwrkdT+CjbRzZ8btKB6DXMlfDqqI 4U6pHKhJMpyN6XBalbUyFwsu/idMZ8ELvLSIJUBHJhKbAIVofcK+PZVu8FhincVRT7AvH6 EV33p0AXGFXbaWkBpI2oeP/2StX3IT4= X-MC-Unique: tyMd9xvCPYiFOmxoGtUvGg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741260; x=1731346060; 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=EGXu5CBuE8xwKZlIqcgq1tN+U8GgEV5+6D9N6jIde4E=; b=Wdj5SUbexm83gQ2HECGu4G4UkP+ZJGYmI7eyqtoJuE0ofdXyeosWOI/8mGmUVn2/1o ydccQ9YpwI2HJFwPCeibimnQDIofyxys+W1ih/cR3HM77EWCu/wUv9qOtxj24HxvesAq iRuzhJBvc81a0PGT2UVsC7tuxcOXWGjos342XIaazoxSulDBTTNTQ7RxE5FpQ5d3RqAS l4wz25yCAManX8ZQNmA9P+hvXEk9VMeWVYh4cRFDGStGEoR73HDovbYi2FLFc0qHXq7E QgFjeSfDgP+dboOkpCPKSCcYxUQLsMzhuwJaY8DBnlfwH/oMkf+oE3OsWOdEkyyBq0Yf leiw== X-Gm-Message-State: AOJu0YzEgwpiIjJWZipQzTBbBusC5u/gkCIbmdystdjvnM72vuva7n7e RvncYGq2Ad2+YccHLEQtH0tNmGAvvbaLzc0FIGWgDBMy/boAXhPJKbUBjiHsUi2Jee7+xDucMeN Y185Zi958bdhSzOIHFNL453+KnIzadctRWSsHsdP/4ZVjK47vpZ8BxOrDYhjHBvNUW1HUvXRkV1 qRVKRCdEzxAHJ0JGJW/8/zUAURlwCHmNLC5VBdNRo= X-Received: by 2002:adf:fc8b:0:b0:37d:5026:f787 with SMTP id ffacd0b85a97d-380611e10f1mr21783304f8f.38.1730741259878; Mon, 04 Nov 2024 09:27:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUe57SiQ8Ew2bqMxFyy0RrQc+kg1McqIBFild4DPEgFSiA2VMp18QcAYdiMXLn/pG0TaG1mA== X-Received: by 2002:adf:fc8b:0:b0:37d:5026:f787 with SMTP id ffacd0b85a97d-380611e10f1mr21783284f8f.38.1730741259376; Mon, 04 Nov 2024 09:27:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 08/40] rust: do not always select X_PL011_RUST Date: Mon, 4 Nov 2024 18:26:47 +0100 Message-ID: <20241104172721.180255-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741335526116600 Content-Type: text/plain; charset="utf-8" Right now the Rust pl011 device is included in all QEMU system emulator binaries if --enable-rust is passed. This is not needed since the board logic in hw/arm/Kconfig will pick it. Signed-off-by: Paolo Bonzini --- rust/hw/char/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/hw/char/Kconfig b/rust/hw/char/Kconfig index a1732a9e97f..5fe800c4806 100644 --- a/rust/hw/char/Kconfig +++ b/rust/hw/char/Kconfig @@ -1,3 +1,2 @@ config X_PL011_RUST bool - default y if HAVE_RUST --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741759; cv=none; d=zohomail.com; s=zohoarc; b=XbIq0uZLHX75IDkm47YXwNgfz5j0u4s0MnC1brSVTrJdqt6G9crC3cOXK71iBLJE7nFcII6y+3/gEMbkegQF1YAZi5Z0HyaVf4y/x/NSiHUpFSqZnOTfVIjSdjuEEBmQcATnyJmW81MEZFiPbtsn0lrs0zx++fUeeprAnA1/bHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741759; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VhAX4O/uTEOcD1m0vx1NVf8UCEBi1EOArDSUiAiYLDo=; b=bap1Nn6yVVGoYpE128aHK95JiXRvUDu809CZ3qifgiYiL/RC2nZ2Vp9OcPZ+KUH3M8yZn2/jtxA3afbt9cDStxR84fBQiP3aPC4p94nUyWxIJiCTTS8yQ79xdjZIuTwfrSm6p7Hv7mY2JITnIBP7JytjrTPmixFUZY4XGJalix4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741759146908.5150250272254; Mon, 4 Nov 2024 09:35:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rs-00058o-Bd; Mon, 04 Nov 2024 12:27:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rp-00057j-SZ for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rj-0000Ck-Ou for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:53 -0500 Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-M2UGbusnNUeNdXFYjYkGCA-1; Mon, 04 Nov 2024 12:27:45 -0500 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-539ebb67c28so3118229e87.3 for ; Mon, 04 Nov 2024 09:27:45 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5c65c7sm158964125e9.19.2024.11.04.09.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VhAX4O/uTEOcD1m0vx1NVf8UCEBi1EOArDSUiAiYLDo=; b=TEZiNy79ijN13bp4mQ1md6L5aea1FiHFks7TPlzlKeYmtP3b1siy7/rRc6sry014/2sO2R TjYwBsjQNAx2qpIBvNT1Bt2IzKwNohyv1casPcDje4XDPSHnOVn+ZsT89mnVsu3sSg+Mk+ 2i+DE2l+nPS7VDTupe7NlFiEf2eksDk= X-MC-Unique: M2UGbusnNUeNdXFYjYkGCA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741263; x=1731346063; 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=VhAX4O/uTEOcD1m0vx1NVf8UCEBi1EOArDSUiAiYLDo=; b=mhkiKRwL3ye4+Ki3Cno4DD0C457mTREGaE9SCr7r0/gfyVPO7UACoyRcGNj8uBHDt2 eWrstvpnRdOQaUDfUZswR1bgashlABr5HMN+vGS8mdSFH/LSQNoDF62bYSsIq74zg2IP mExMy9s1JtanFiLsPr6gXZYd8YnNYqIhXvP4VtOvciGTZqO+Tfr1vQ8J+emFOwvuWhEO jSj1Rmt26GxHU22V6OQNdbv3FMf8+1O11lEcHC5GRWPWLMNP8LXplAz0RFzXG7U0Vvq2 l8XVmfmwmRnJIHqBULcGQ88FCM9Acv4svqY/y+qiMqrt+y3RgSvjhuNlQiwaPlPoL28b Km6A== X-Gm-Message-State: AOJu0YxcrRjbTbZikk7uslgUgjWJ/SW1ZSd1Q8dcSApKPWRW+qfSAJuf OaYQHlTMoVyynCxW5ime9L9d3gxSQBRfTfE4qSzUMp9MS2coD6olE+v/Epc12ku0h+bq20fqpxq wL9Ne4SZ/rhCRPUscISpoFdcq6ZQ/NieV26k+ZSeKE9Mr2Bsey0eFVvfmH4mAFhel4qf7GQWi48 DbB4AQMXhX4JX0wLfBXeFROmKfejYzQGG2dXPUABg= X-Received: by 2002:a05:6512:3b1e:b0:539:e1c6:2128 with SMTP id 2adb3069b0e04-53d65e11a8dmr5771235e87.39.1730741262934; Mon, 04 Nov 2024 09:27:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0B582pRp84m7/eh5z6hePKdDfQ0WgL9n4QcrtrNq8U+I4BysDqmkYkqeLS38uQ8KtTzZo9g== X-Received: by 2002:a05:6512:3b1e:b0:539:e1c6:2128 with SMTP id 2adb3069b0e04-53d65e11a8dmr5771213e87.39.1730741262464; Mon, 04 Nov 2024 09:27:42 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 09/40] rust: do not use --no-size_t-is-usize Date: Mon, 4 Nov 2024 18:26:48 +0100 Message-ID: <20241104172721.180255-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741759490116600 Content-Type: text/plain; charset="utf-8" This is not necessary and makes it harder to write code that is portable between 32- and 64-bit systems: it adds extra casts even though size_of, align_of or offset_of already return the right type. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- meson.build | 1 - rust/qemu-api/src/definitions.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 7d06d2fe74e..34328f7394c 100644 --- a/meson.build +++ b/meson.build @@ -3948,7 +3948,6 @@ if have_rust and have_system '--no-doc-comments', '--use-core', '--with-derive-default', - '--no-size_t-is-usize', '--no-layout-tests', '--no-prepend-enum-name', '--allowlist-file', meson.project_source_root() + '/include/.*', diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitio= ns.rs index 60bd3f8aaa6..0b681c593f2 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -81,13 +81,13 @@ macro_rules! type_info { } else { ::core::ptr::null_mut() }, - instance_size: ::core::mem::size_of::<$t>() as $crate::binding= s::size_t, - instance_align: ::core::mem::align_of::<$t>() as $crate::bindi= ngs::size_t, + instance_size: ::core::mem::size_of::<$t>(), + instance_align: ::core::mem::align_of::<$t>(), instance_init: <$t as $crate::definitions::ObjectImpl>::INSTAN= CE_INIT, instance_post_init: <$t as $crate::definitions::ObjectImpl>::I= NSTANCE_POST_INIT, instance_finalize: <$t as $crate::definitions::ObjectImpl>::IN= STANCE_FINALIZE, abstract_: <$t as $crate::definitions::ObjectImpl>::ABSTRACT, - class_size: ::core::mem::size_of::<<$t as $crate::definitions= ::ObjectImpl>::Class>() as $crate::bindings::size_t, + class_size: ::core::mem::size_of::<<$t as $crate::definitions= ::ObjectImpl>::Class>(), class_init: <<$t as $crate::definitions::ObjectImpl>::Class as= $crate::definitions::Class>::CLASS_INIT, class_base_init: <<$t as $crate::definitions::ObjectImpl>::Cla= ss as $crate::definitions::Class>::CLASS_BASE_INIT, class_data: ::core::ptr::null_mut(), --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741495; cv=none; d=zohomail.com; s=zohoarc; b=fUWpztzdBVkrbWLuFI3vso5Tt24VyQczKSc1Qr1AknMFgBtIkSHsrM0IWQhXS+NE3wcKGxqIw1BJXAPmSNDrPcFGr/qchAkx6sjqBOT6mgTv5VXJ1muLRvwqLEa16nzB5zmL6UHqY6ps3mu3mqriQxfK8d3d/xuQBb9P9RDyErg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741495; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rJNsDbAV50RLo0Vi2FXdvCjsDtZaOavVS7U5n7y+ISs=; b=e+LRRY6wR29qmyae18OQKyFg+nD2extaeXrVqPXqx4TLk1jUIwZSr84z9GMz4cg82J8RU6wQtk4urxLfGvtVhiwgPsX+gWI7f1NwY77Zr6BSXX+dPReSwT7kO7qZ/9gsr1h7gk6jCDJyh033UOtdSmNdZUSX312bUx4Z5KYAouM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173074149499571.05633481263294; Mon, 4 Nov 2024 09:31:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rq-000585-OW; Mon, 04 Nov 2024 12:27:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80ro-00057E-PA for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rl-0000DT-OD for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:52 -0500 Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-BtnaXuVOPXyFw6v0_s_5aw-1; Mon, 04 Nov 2024 12:27:47 -0500 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-539f7ed336bso2776531e87.2 for ; Mon, 04 Nov 2024 09:27:47 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d685308sm157860855e9.33.2024.11.04.09.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rJNsDbAV50RLo0Vi2FXdvCjsDtZaOavVS7U5n7y+ISs=; b=CfBKyELN5Nj0wXVw8S/kjrugdDt1MESfnWGwqH09dlPRahiQ6NAVnx1kla2UMJBW7pBFsh 2VTd1PvPna6NJqPqi4lM+TppubdRm400hjymQAtX0rkw63bhor9VpX+mEfbNyCAjXlNQTm sAVYyB4CzczHNUT8ubE1LsecKmqzuO8= X-MC-Unique: BtnaXuVOPXyFw6v0_s_5aw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741265; x=1731346065; 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=rJNsDbAV50RLo0Vi2FXdvCjsDtZaOavVS7U5n7y+ISs=; b=lvWwlcEk0pf4CBxm5Mi4U90WQZ7hDilNCyQQBNbFJLMQXRcQYPV5RMwGcSOWjYhVvO qNsnrnJkMWnEpGBJ4eKCrk4dIEyRrZuhNkayFtG13zJXYofwh8lNU7Br5aex5KWODsvH ismacY7n+czIbFUtxlMOylz/1C18Bi5uJhuHlqfMnudQlMsKj69oi2qSezRS5vUM9zNo r2ICH3ydCfWKzF6uw2esONHVZQ1ses5NkYjekWlYJWO2I9jwxrLmwLnsGo89TdP0PQWm /LEXit+6i0SwmNRFQZCO3mZJ+ab8zcrfQ2PJFo/iDK5KpvnlqbJN+/D3nrN7XKuLwYzj 3pDA== X-Gm-Message-State: AOJu0YyM7FaYpWY1gLQfXJfGPxMtWTYLDTqXG4hB0AqxGNAihz7ucUZO ldMdSA7SzMDi6OXw9c8pMxxuaWJcSUJH4hQkqViC12/RBg03WI3J1LMFn44ifX8agsPIErB1y3o IYrx596B124WQ20X01bPIWGv1nIMSrO2VtIOZ+qNaNzWytY6XvEeA8I3P5SWBee1ZAG9PPcjbia Kfp5IU7ERO9nxBq4Ar7EpW0pcACSDES23qDo1v4ws= X-Received: by 2002:a05:6512:10c7:b0:539:fcb2:2ff4 with SMTP id 2adb3069b0e04-53b34b373dcmr14278426e87.53.1730741265127; Mon, 04 Nov 2024 09:27:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlT+hpJ0aCm//XZ3HY8wC27OYoLAW4lEWKXwL/wMigi+xlVsujdyAoJ9FRT1yye+S+1sYI2A== X-Received: by 2002:a05:6512:10c7:b0:539:fcb2:2ff4 with SMTP id 2adb3069b0e04-53b34b373dcmr14278401e87.53.1730741264614; Mon, 04 Nov 2024 09:27:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 10/40] rust: remove uses of #[no_mangle] Date: Mon, 4 Nov 2024 18:26:49 +0100 Message-ID: <20241104172721.180255-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741496195116600 Content-Type: text/plain; charset="utf-8" Mangled symbols do not cause any issue; disabling mangling is only useful if C headers reference the Rust function, which is not the case here. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 4 ---- rust/hw/char/pl011/src/device_class.rs | 2 -- rust/hw/char/pl011/src/memory_ops.rs | 2 -- rust/qemu-api/src/definitions.rs | 1 - rust/qemu-api/src/device_class.rs | 2 -- 5 files changed, 11 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index c7193b41bee..0347a027c5f 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -514,7 +514,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that = has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { unsafe { debug_assert!(!opaque.is_null()); @@ -530,7 +529,6 @@ pub fn update(&self) { /// readable/writeable from one thread at any time. /// /// The buffer and size arguments must also be valid. -#[no_mangle] pub unsafe extern "C" fn pl011_receive( opaque: *mut core::ffi::c_void, buf: *const u8, @@ -554,7 +552,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that = has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event= : QEMUChrEvent) { unsafe { debug_assert!(!opaque.is_null()); @@ -589,7 +586,6 @@ pub fn update(&self) { /// We expect the FFI user of this function to pass a valid pointer, that = has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_init(obj: *mut Object) { unsafe { debug_assert!(!obj.is_null()); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index b7ab31af02d..2ad80451e87 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -46,7 +46,6 @@ /// We expect the FFI user of this function to pass a valid pointer, that = has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut = *mut Error) { unsafe { assert!(!dev.is_null()); @@ -60,7 +59,6 @@ /// We expect the FFI user of this function to pass a valid pointer, that = has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -#[no_mangle] pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) { unsafe { assert!(!dev.is_null()); diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/= memory_ops.rs index 8d066ebf6d0..5a5320e66c3 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -22,7 +22,6 @@ }, }; =20 -#[no_mangle] unsafe extern "C" fn pl011_read( opaque: *mut core::ffi::c_void, addr: hwaddr, @@ -44,7 +43,6 @@ } } =20 -#[no_mangle] unsafe extern "C" fn pl011_write( opaque: *mut core::ffi::c_void, addr: hwaddr, diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitio= ns.rs index 0b681c593f2..49ac59af123 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -53,7 +53,6 @@ extern "C" fn __load() { #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() =3D { extern "C" fn __load() { - #[no_mangle] unsafe extern "C" fn $func() { $body } diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index b6b68cf9ce2..2219b9f73d0 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -9,7 +9,6 @@ #[macro_export] macro_rules! device_class_init { ($func:ident, props =3D> $props:ident, realize_fn =3D> $realize_fn:exp= r, legacy_reset_fn =3D> $legacy_reset_fn:expr, vmsd =3D> $vmsd:ident$(,)*) = =3D> { - #[no_mangle] pub unsafe extern "C" fn $func( klass: *mut $crate::bindings::ObjectClass, _: *mut ::core::ffi::c_void, @@ -103,7 +102,6 @@ const fn _calc_prop_len() -> usize { ] } =20 - #[no_mangle] pub static mut $ident: $crate::device_class::Properties = =3D $crate::device_class::Properties(::std::sync::OnceLock::new(), _make_pr= operties); }; } --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741396; cv=none; d=zohomail.com; s=zohoarc; b=NZ3ug3LjpZHZvbhUANBA/qFQShnNGQsoGJfzPZQA1AY7QL7ynlHJjCY98f7Y8b2sPZJ8Vnyi5nLdWU0lWPhAbO8H7fqZDsmSd0h+dwVlwvzqOy1GJdNB9sps6aTKRD5u6hUmfxhRnVssrZAqRMjrCnweYYTOJkH+ZLjlohNBcGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741396; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mP3j3evq86lhHlL3nhlSwnDw7BkQlXrJv1c8ym7QLnQ=; b=fIxITK7+STCKMrcXK/vSG6VrAYVKDytrK/+QSMNv6esHkH8aguhbJPE45uMGffNJKGf3wbynSiyw6NW1VJYhw2VYrtBWxkcQ5nu1sWjD7eoWK1lGj5DdpVTLbwgPV1AaHufsKc9ovJ4klFHce8T6ivXbALpJFBeeroxh9P8WFeA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741396627888.3414707027669; Mon, 4 Nov 2024 09:29:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80rt-0005A0-78; Mon, 04 Nov 2024 12:27:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rs-00058u-1N for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80ro-0000F4-Ui for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:55 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-dpAiKVBpNYma5k7JJBm-9Q-1; Mon, 04 Nov 2024 12:27:49 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315a0f25afso30782255e9.3 for ; Mon, 04 Nov 2024 09:27:49 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5ab2aasm159229815e9.6.2024.11.04.09.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mP3j3evq86lhHlL3nhlSwnDw7BkQlXrJv1c8ym7QLnQ=; b=GC5+Xrlu7UxGHa3wtjioCx9SFZnEcWOh7qkA4OYT3+WcEfRanRFqGZ+tyUP4m2N7ErTsSI vDBp/e4WcG1xckqYNDCaKxcp/o0bOgauv3vPHZsZCHj1PO8My7lnMWxdvfLM1MvCzUTbVn +vsx3hmQ4lxXY6S6LUN+4xF3VSqhbEw= X-MC-Unique: dpAiKVBpNYma5k7JJBm-9Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741268; x=1731346068; 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=mP3j3evq86lhHlL3nhlSwnDw7BkQlXrJv1c8ym7QLnQ=; b=wuj7FARpTPdtJax1iPusjc4oatSBQe5A8zF4bQj06PNCCAav/XtzD9oYYcSwPNPYyq rFWNA0RGoyBj4J/8i15VTFpfWuScMCdNgARSjPk8VVVf6kOrjv7UPHf6m0jb/+dabjhi luNLIGqBGUtOa3VrFQyfS9pZmCCR8+DmqSR2sT2OYoeVojdrRtZJkWMEKfjdoJ+3xoZ3 GXVlAF8pj4eBtUua9OCIyJoqPvXZTLkxwybeyABIkTtBfUyMR9WhSSEiMqNhM9LXScxQ faciA3pp4quw+C5ameKmwJG6N5y6Kv/MBm/HVBy4Ce8cxJ+jPpffYod9jNqQvSBQE0Ym op+g== X-Gm-Message-State: AOJu0YwV4hZwItZeXSgkZx9EVYEQgoYRDsZcu2t5fcZDTl0TROH/Af7z eScM/SE1MczA8F9HA/cK/VRlLcvS3xzHgns/53FXWb5/IEFIwSVninzduVMhJgmQrczUf96FN91 e2U34/7csxpY/R6dfxlK+pAExP8YCw9zxI1qkLwYd4+EyZbi28/OSM5oKy7aAbXJYdjYf1r2Lgd umXwbfAzyYUKxRQdS+Z7gYReVJLrWWSx6PijttyQo= X-Received: by 2002:a05:600c:45cd:b0:431:5eeb:2214 with SMTP id 5b1f17b1804b1-4319ad363eamr270835845e9.33.1730741267783; Mon, 04 Nov 2024 09:27:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDt2bahnHtLFrwePwW6kfkxzDFdriaiVVUuijGKMBoP0pQ6+DQoZl9yA8nDdNn8I5NY8LjKg== X-Received: by 2002:a05:600c:45cd:b0:431:5eeb:2214 with SMTP id 5b1f17b1804b1-4319ad363eamr270835565e9.33.1730741267387; Mon, 04 Nov 2024 09:27:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 11/40] rust: modernize link_section usage for ELF platforms Date: Mon, 4 Nov 2024 18:26:50 +0100 Message-ID: <20241104172721.180255-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741397994116600 Content-Type: text/plain; charset="utf-8" Some newer ABI implementations do not provide .ctors; and while some linkers rewrite .ctors into .init_array, not all of them do. Use the newer .init_array ABI, which works more reliably, and apply it to all non-Apple, non-Windows platforms. This is similar to how the ctor crate operates; without this change, "#[derive(Object)]" does not work on Fedora 41. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/src/lib.rs | 7 +++++-- rust/qemu-api/src/definitions.rs | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 59aba592d9a..70e3f920460 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -16,8 +16,11 @@ pub fn derive_object(input: TokenStream) -> TokenStream { let expanded =3D quote! { #[allow(non_upper_case_globals)] #[used] - #[cfg_attr(target_os =3D "linux", link_section =3D ".ctors")] - #[cfg_attr(target_os =3D "macos", link_section =3D "__DATA,__mod_i= nit_func")] + #[cfg_attr( + not(any(target_vendor =3D "apple", target_os =3D "windows")), + link_section =3D ".init_array" + )] + #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA,__m= od_init_func")] #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] pub static #module_static: extern "C" fn() =3D { extern "C" fn __register() { diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitio= ns.rs index 49ac59af123..3323a665d92 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -31,8 +31,11 @@ pub trait Class { macro_rules! module_init { ($func:expr, $type:expr) =3D> { #[used] - #[cfg_attr(target_os =3D "linux", link_section =3D ".ctors")] - #[cfg_attr(target_os =3D "macos", link_section =3D "__DATA,__mod_i= nit_func")] + #[cfg_attr( + not(any(target_vendor =3D "apple", target_os =3D "windows")), + link_section =3D ".init_array" + )] + #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA,__m= od_init_func")] #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() =3D { extern "C" fn __load() { @@ -48,8 +51,11 @@ extern "C" fn __load() { // NOTE: To have custom identifiers for the ctor func we need to e= ither supply // them directly as a macro argument or create them with a proc ma= cro. #[used] - #[cfg_attr(target_os =3D "linux", link_section =3D ".ctors")] - #[cfg_attr(target_os =3D "macos", link_section =3D "__DATA,__mod_i= nit_func")] + #[cfg_attr( + not(any(target_vendor =3D "apple", target_os =3D "windows")), + link_section =3D ".init_array" + )] + #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA,__m= od_init_func")] #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] pub static LOAD_MODULE: extern "C" fn() =3D { extern "C" fn __load() { --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741630; cv=none; d=zohomail.com; s=zohoarc; b=KQLyc4dMBXEkqaFe0Hq2xVH54TzYN9PZFjRJN603nsHOpsmGvOEkekOpUYXHcNUWGgaZiBIR+hAy+Zu9GlcXfbomPtujtCkYI1+iIvjK3fUovu44UvWQXjrnBEXoNtK7CU0RWm2/0NBVmkkqlkpqotLiQReSFSENgpMJw5fNrxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741630; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=15gJocChv51sOFhNt0S0HtN1Adkbm8Pf6dpwy6uwFWE=; b=FY3/qsnhJ+tRDMk5DzhCrmg3dRuvwqG1NYGEvuUXkVhGpR7VsoIJFOu68IMjRLr8/wR10g46oCR3XXNmEw1p559Q1uU4mOSyHXWJSX7Tk3jOMv5vk0feYv+1wEjjjsP7OucqOykIDDvDuTdW9kwwlinfbgJek0QaXVPRmLT29Oo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741630134848.4269675940407; Mon, 4 Nov 2024 09:33:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80ry-0005Cg-3X; Mon, 04 Nov 2024 12:28:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rv-0005BO-Im for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rq-0000FP-5e for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:27:59 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-la0HymNlNgajKtrHGSUNfA-1; Mon, 04 Nov 2024 12:27:51 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37d563a1af4so2141142f8f.2 for ; Mon, 04 Nov 2024 09:27:51 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c116c13asm13663253f8f.109.2024.11.04.09.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=15gJocChv51sOFhNt0S0HtN1Adkbm8Pf6dpwy6uwFWE=; b=FB2sBxSZGxbz4Frbq/rOZoDjTU9mAu1awLIPCpnEYAzw383OFspKrH0nNsWBkmVUwdun5C a+GNDx6c+/6Dte0TUpO1QklnqyY80bDf7VkF7+14gc+UcPwlI+2415Rg1Eopu5ZeGWR6SO /X0/q8Ks34MWBD5nfeazReybPeUnlIA= X-MC-Unique: la0HymNlNgajKtrHGSUNfA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741270; x=1731346070; 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=15gJocChv51sOFhNt0S0HtN1Adkbm8Pf6dpwy6uwFWE=; b=gLZIHElhgsR5HelwQuw5OVo2LmY31ExW0nrmqX5yuE9CKmbFAq05fYvmCw1PSR/PPd bOWBzn7ibn9i+qcsqx/CmPaRHMrXPpRvnHQWmj6PS8DL60e8lIl+IOeTXJQniEhhym9y OPfdccX9ol2E9N2c5wMUv4fhBr9zOKpt8i4xA/EubtR7d0Y4DdcP+0okrWG2E7Vo3yWp sD9asXXlui/oTL9sVX3KZ1vuTmXSJcl6lGzlXxfuDV8jhfQyTy+3ZFI81qdqVZjJcbNM l+tk6uqNl5HOs8/r+BWQISi0UHNEYTuKUTQcGDfubUlYPxs0uJaZCqa1aPnPEgL957wi Fvzw== X-Gm-Message-State: AOJu0YxM7hU+uclRZ7EgoGfU5EkP62YxalnuMj00W4esbAOwuFcyZh/a 32q3XbzK3crFN7Or53/M5I7YwHMr8Ifd2GXdYxr4h9NPFIKdS4JbJBeN5HPznxIXaTyUEgl7+B0 2avwiT8n5SPYqCojIEWHpoUtGRMta7xrTRnEoA8wDDwC4MdTX+uzFMtbq1LCeQFC6g8M6l4a8rq ZQUFqEx2xqQTcjAtEudgx172/mpKl1ZzBDF+p1Xu8= X-Received: by 2002:a05:6000:1569:b0:37d:3985:8871 with SMTP id ffacd0b85a97d-381c7aa4867mr11416891f8f.39.1730741269785; Mon, 04 Nov 2024 09:27:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFK4zkkwxfeHDhJ11Uh0NLykYPjtHtoeqROzyPy0xCnWH6wDBP8UJ1R8aL/rX5uMd5eUnXweg== X-Received: by 2002:a05:6000:1569:b0:37d:3985:8871 with SMTP id ffacd0b85a97d-381c7aa4867mr11416865f8f.39.1730741269338; Mon, 04 Nov 2024 09:27:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 12/40] rust: build integration test for the qemu_api crate Date: Mon, 4 Nov 2024 18:26:51 +0100 Message-ID: <20241104172721.180255-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741630732116600 Content-Type: text/plain; charset="utf-8" Adjust the integration test to compile with a subset of QEMU object files, and make it actually create an object of the class it defines. Follow the Rust filesystem conventions, where tests go in tests/ if they use the library in the same way any other code would. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- meson.build | 10 ++++- rust/qemu-api/meson.build | 26 ++++++++++-- rust/qemu-api/src/lib.rs | 3 -- rust/qemu-api/src/tests.rs | 49 ---------------------- rust/qemu-api/tests/tests.rs | 78 ++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 56 deletions(-) delete mode 100644 rust/qemu-api/src/tests.rs create mode 100644 rust/qemu-api/tests/tests.rs diff --git a/meson.build b/meson.build index 34328f7394c..d360120b233 100644 --- a/meson.build +++ b/meson.build @@ -3340,7 +3340,15 @@ if have_rust and have_system =20 # Prohibit code that is forbidden in Rust 2024 rustc_args +=3D ['-D', 'unsafe_op_in_unsafe_fn'] - add_project_arguments(rustc_args, native: false, language: 'rust') + + # Apart from procedural macros, our Rust executables will often link + # with C code, so include all the libraries that C code needs. This + # is safe; https://github.com/rust-lang/rust/pull/54675 says that + # passing -nodefaultlibs to the linker "was more ideological to + # start with than anything". + add_project_arguments(rustc_args + ['-C', 'default-linker-libraries'], + native: false, language: 'rust') + add_project_arguments(rustc_args, native: true, language: 'rust') endif =20 diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 42ea815fa5a..1fc36078027 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -14,11 +14,31 @@ _qemu_api_rs =3D static_library( '--cfg', 'MESON', # '--cfg', 'feature=3D"allocator"', ], - dependencies: [ - qemu_api_macros, - ], ) =20 qemu_api =3D declare_dependency( link_with: _qemu_api_rs, + dependencies: qemu_api_macros, ) + +# Rust executables do not support objects, so add an intermediate step. +rust_qemu_api_objs =3D static_library( + 'rust_qemu_api_objs', + objects: [libqom.extract_all_objects(recursive: false), + libhwcore.extract_all_objects(recursive: false)]) + +test('rust-qemu-api-integration', + executable( + 'rust-qemu-api-integration', + 'tests/tests.rs', + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_args: ['--test'], + install: false, + dependencies: [qemu_api, qemu_api_macros], + link_whole: [rust_qemu_api_objs, libqemuutil]), + args: [ + '--test', + '--format', 'pretty', + ], + protocol: 'rust', + suite: ['unit', 'rust']) diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e72fb4b4bb1..6bc68076aae 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -30,9 +30,6 @@ unsafe impl Sync for bindings::VMStateDescription {} pub mod definitions; pub mod device_class; =20 -#[cfg(test)] -mod tests; - use std::alloc::{GlobalAlloc, Layout}; =20 #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] diff --git a/rust/qemu-api/src/tests.rs b/rust/qemu-api/src/tests.rs deleted file mode 100644 index df54edbd4e2..00000000000 --- a/rust/qemu-api/src/tests.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2024, Linaro Limited -// Author(s): Manos Pitsidianakis -// SPDX-License-Identifier: GPL-2.0-or-later - -use crate::{ - bindings::*, declare_properties, define_property, device_class_init, v= m_state_description, -}; - -#[test] -fn test_device_decl_macros() { - // Test that macros can compile. - vm_state_description! { - VMSTATE, - name: c"name", - unmigratable: true, - } - - #[repr(C)] - pub struct DummyState { - pub char_backend: CharBackend, - pub migrate_clock: bool, - } - - declare_properties! { - DUMMY_PROPERTIES, - define_property!( - c"chardev", - DummyState, - char_backend, - unsafe { &qdev_prop_chr }, - CharBackend - ), - define_property!( - c"migrate-clk", - DummyState, - migrate_clock, - unsafe { &qdev_prop_bool }, - bool - ), - } - - device_class_init! { - dummy_class_init, - props =3D> DUMMY_PROPERTIES, - realize_fn =3D> None, - reset_fn =3D> None, - vmsd =3D> VMSTATE, - } -} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs new file mode 100644 index 00000000000..aa1e0568c69 --- /dev/null +++ b/rust/qemu-api/tests/tests.rs @@ -0,0 +1,78 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +use core::ffi::CStr; + +use qemu_api::{ + bindings::*, + declare_properties, define_property, + definitions::{Class, ObjectImpl}, + device_class_init, vm_state_description, +}; + +#[test] +fn test_device_decl_macros() { + // Test that macros can compile. + vm_state_description! { + VMSTATE, + name: c"name", + unmigratable: true, + } + + #[repr(C)] + #[derive(qemu_api_macros::Object)] + pub struct DummyState { + pub _parent: DeviceState, + pub migrate_clock: bool, + } + + #[repr(C)] + pub struct DummyClass { + pub _parent: DeviceClass, + } + + declare_properties! { + DUMMY_PROPERTIES, + define_property!( + c"migrate-clk", + DummyState, + migrate_clock, + unsafe { &qdev_prop_bool }, + bool + ), + } + + device_class_init! { + dummy_class_init, + props =3D> DUMMY_PROPERTIES, + realize_fn =3D> None, + legacy_reset_fn =3D> None, + vmsd =3D> VMSTATE, + } + + impl ObjectImpl for DummyState { + type Class =3D DummyClass; + const TYPE_INFO: qemu_api::bindings::TypeInfo =3D qemu_api::type_i= nfo! { Self }; + const TYPE_NAME: &'static CStr =3D c"dummy"; + const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(TYPE_DEVICE= ); + const ABSTRACT: bool =3D false; + const INSTANCE_INIT: Option =3D None; + const INSTANCE_POST_INIT: Option =3D None; + const INSTANCE_FINALIZE: Option =3D None; + } + + impl Class for DummyClass { + const CLASS_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core:= :ffi::c_void), + > =3D Some(dummy_class_init); + const CLASS_BASE_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core:= :ffi::c_void), + > =3D None; + } + + unsafe { + module_call_init(module_init_type::MODULE_INIT_QOM); + object_unref(object_new(DummyState::TYPE_NAME.as_ptr()) as *mut _); + } +} --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741303; cv=none; d=zohomail.com; s=zohoarc; b=cobncsb78b4CyQWYrDqAmdXpoNF/V3NXVivjoEAnduP++NbAOLZ0cxlBkDG0vNxPDcDMvqI71n12ltlyHU7R0I6eQP3YMHJMDTKaKI78mjdaAJO7RHXxiUDUajSxfZB02yFUws18qPVPBS+XA34QoI7YdZwsI2fjhao2+F5u0wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741303; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A9+GxjZBE101yDjjA0Qt1X0NpiGdJaUq+zHWXHIOAas=; b=JQbbm+1k1HZCLLCKZtHw3QiU2SIbbzRDgLQUlYNrSfC+uUN39YuytfkiYL2fheLd0BcmxkoSp7kCyLIq1em1GoqeSynduAfYhQEHe1RS6jQMjmvTgLLhrqwQ1pk1lO6FPErU+znbGiGOy8yL+LeOGWLV6pH61EAD6UqeY7zbaHA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741303720327.0896442777969; Mon, 4 Nov 2024 09:28:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s0-0005Dv-Vn; Mon, 04 Nov 2024 12:28:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80ry-0005Cw-SF for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rs-0000Fw-Hl for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:02 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-i3ccn-fhPW6Mxt2xkEjaSw-1; Mon, 04 Nov 2024 12:27:54 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43157cff1d1so33012305e9.2 for ; Mon, 04 Nov 2024 09:27:53 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd8e8466sm190429555e9.2.2024.11.04.09.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9+GxjZBE101yDjjA0Qt1X0NpiGdJaUq+zHWXHIOAas=; b=G9fzXmuHaKOhZtbXcKgYs/WNKntcLRDjDIL4ghNtqGCL+329xsT3K6wV6oRQbob/CMELiC kXTozOg350RI2H7YbpOhJ6TqT/VHpkv024Q8/M6pK01/m7RSDsICXcJJxnwMGbdBkLynYJ nagRLHFRA17SFYjJb8Lb6woFuAFkTOg= X-MC-Unique: i3ccn-fhPW6Mxt2xkEjaSw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741272; x=1731346072; 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=A9+GxjZBE101yDjjA0Qt1X0NpiGdJaUq+zHWXHIOAas=; b=WO98hqJTp9JmSwWNl7TuG4693nSsLPJ31I9dtMXG0LHnBuMFdd8nmKAwaSixLfGVaX ejtAtHhKJfAKwNXGb650TPgUTVnFpMxuLOr88QgzbBitlSdX7UZ64olx3j4ifuFXyBvR kSgMGBuMx1zVbvkImyOV3b5Ax2QhpVWpdtGGAIAQ/Kids5QNdX0TjRml4tM1ZDbETRTA SjtbSL/HxQR68BSiJqDnWesXl4eUOtZWcpsFKg6F/VL37m6SRCDgCp2NpUhuwDU2OoIt 8Q28NUawhonUIt3GCBb/TvMwAajY+gK+PqEE5sjvtgWr/XRpdhCDrsxNxbsk78+whNZF T5wQ== X-Gm-Message-State: AOJu0YyEFC73lCDwWY+VAfrczlb/nV8rP3E+ayW1Y7n3wVNiHgvgpfs2 ApXW2uN6THoNJn4pxi/q8QuMBEYs8CfL+4z0nfM4OVldfYibjaI80BmVhs4Kowa3a7aAY0zILVM i05iPD8KDjqGmj/vOMcXbBE09/wE+WxVaRyqeLy04lcroB/bYOLkcDrQ82pDLFs5g6NYj03+qz9 K+w0ChOtXU4MfDecT2DSEGZog8qMrnHP3crcejq4E= X-Received: by 2002:a05:600c:1396:b0:430:582f:3a9d with SMTP id 5b1f17b1804b1-4327b80d1a9mr152247555e9.26.1730741272065; Mon, 04 Nov 2024 09:27:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7hmlApj1LQZ4Rj7bpAn4i0fx0kKZFEK8dvqvgNwd7dSLiYyfO8asezG1r2QowDbtsYp8hxw== X-Received: by 2002:a05:600c:1396:b0:430:582f:3a9d with SMTP id 5b1f17b1804b1-4327b80d1a9mr152247245e9.26.1730741271614; Mon, 04 Nov 2024 09:27:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 13/40] rust: cleanup module_init!, use it from #[derive(Object)] Date: Mon, 4 Nov 2024 18:26:52 +0100 Message-ID: <20241104172721.180255-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741305556116600 Content-Type: text/plain; charset="utf-8" Remove the duplicate code by using the module_init! macro; at the same time, simplify how module_init! is used, by taking inspiration from the implement= ation of #[derive(Object)]. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/src/lib.rs | 33 +++------------- rust/qemu-api/src/definitions.rs | 65 +++++++++++++------------------- 2 files changed, 32 insertions(+), 66 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 70e3f920460..a4bc5d01ee8 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -3,43 +3,20 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use proc_macro::TokenStream; -use quote::{format_ident, quote}; +use quote::quote; use syn::{parse_macro_input, DeriveInput}; =20 #[proc_macro_derive(Object)] pub fn derive_object(input: TokenStream) -> TokenStream { let input =3D parse_macro_input!(input as DeriveInput); - let name =3D input.ident; - let module_static =3D format_ident!("__{}_LOAD_MODULE", name); =20 let expanded =3D quote! { - #[allow(non_upper_case_globals)] - #[used] - #[cfg_attr( - not(any(target_vendor =3D "apple", target_os =3D "windows")), - link_section =3D ".init_array" - )] - #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA,__m= od_init_func")] - #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] - pub static #module_static: extern "C" fn() =3D { - extern "C" fn __register() { - unsafe { - ::qemu_api::bindings::type_register_static(&<#name as = ::qemu_api::definitions::ObjectImpl>::TYPE_INFO); - } + ::qemu_api::module_init! { + MODULE_INIT_QOM =3D> unsafe { + ::qemu_api::bindings::type_register_static(&<#name as ::qe= mu_api::definitions::ObjectImpl>::TYPE_INFO); } - - extern "C" fn __load() { - unsafe { - ::qemu_api::bindings::register_module_init( - Some(__register), - ::qemu_api::bindings::module_init_type::MODULE_INI= T_QOM - ); - } - } - - __load - }; + } }; =20 TokenStream::from(expanded) diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitio= ns.rs index 3323a665d92..064afe60549 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -29,51 +29,40 @@ pub trait Class { =20 #[macro_export] macro_rules! module_init { - ($func:expr, $type:expr) =3D> { - #[used] - #[cfg_attr( - not(any(target_vendor =3D "apple", target_os =3D "windows")), - link_section =3D ".init_array" - )] - #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA,__m= od_init_func")] - #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] - pub static LOAD_MODULE: extern "C" fn() =3D { - extern "C" fn __load() { - unsafe { - $crate::bindings::register_module_init(Some($func), $t= ype); - } - } - - __load - }; - }; - (qom: $func:ident =3D> $body:block) =3D> { - // NOTE: To have custom identifiers for the ctor func we need to e= ither supply - // them directly as a macro argument or create them with a proc ma= cro. - #[used] - #[cfg_attr( - not(any(target_vendor =3D "apple", target_os =3D "windows")), - link_section =3D ".init_array" - )] - #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA,__m= od_init_func")] - #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU")] - pub static LOAD_MODULE: extern "C" fn() =3D { - extern "C" fn __load() { - unsafe extern "C" fn $func() { + ($type:ident =3D> $body:block) =3D> { + const _: () =3D { + #[used] + #[cfg_attr( + not(any(target_vendor =3D "apple", target_os =3D "windows"= )), + link_section =3D ".init_array" + )] + #[cfg_attr(target_vendor =3D "apple", link_section =3D "__DATA= ,__mod_init_func")] + #[cfg_attr(target_os =3D "windows", link_section =3D ".CRT$XCU= ")] + pub static LOAD_MODULE: extern "C" fn() =3D { + extern "C" fn init_fn() { $body } =20 - unsafe { - $crate::bindings::register_module_init( - Some($func), - $crate::bindings::module_init_type::MODULE_INIT_QO= M, - ); + extern "C" fn ctor_fn() { + unsafe { + $crate::bindings::register_module_init( + Some(init_fn), + $crate::bindings::module_init_type::$type, + ); + } } - } =20 - __load + ctor_fn + }; }; }; + + // shortcut because it's quite common that $body needs unsafe {} + ($type:ident =3D> unsafe $body:block) =3D> { + $crate::module_init! { + $type =3D> { unsafe { $body } } + } + }; } =20 #[macro_export] --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741671; cv=none; d=zohomail.com; s=zohoarc; b=gRIFq7U7ILVXnGTKa47Vh+8Fts3/nuzCH7Oq3vCVfGeP6i1KqIU62uNrR3A/0vSrW4Va+jJLdAIreY4UGiVoiqis3Hj7AdXSxZ8oxhdJqz1Z0AarWQ0beuEB30/dP/2NpoBrpRARX0+r9njucF1fRbsHVf2D+m/ElnPXvLuYMp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741671; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pk/ExTQ6ucVRc/G0SIy96rszaYTtvZQeQUouajsdp/c=; b=PvAshuLN+fN84K9laPHW6Qu+yaUlmIBPsZ/ZfVLU55bY4Psh+SXhAjby0O7l+K9+p+C9mFJFm3+t63hNTAT9zu2N0Il/aTORaoxcQAdkRcqQtReOO0gRV/OzBREvZxuvw5idqfYD5Hs5Qir8o1wRI1vkpmvtRRlQz07VCq5H7mU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173074167168788.61993880781574; Mon, 4 Nov 2024 09:34:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s8-0005IN-Th; Mon, 04 Nov 2024 12:28:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s7-0005Hw-Lb for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rt-0000GW-Vu for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:11 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358--fCdCgH8Ow-mL7AQPVzcvA-1; Mon, 04 Nov 2024 12:27:56 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d462b64e3so2205463f8f.3 for ; Mon, 04 Nov 2024 09:27:56 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e7387sm13668758f8f.51.2024.11.04.09.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pk/ExTQ6ucVRc/G0SIy96rszaYTtvZQeQUouajsdp/c=; b=WbOJjC5O594iEUlYuS+BqGG8xJjNdg/HX/vkDDY1SHnCX0PiSwxvBxgF4VnrYTIoil030t bH/ya23m+f2AL/lplNz10No/w+UWd6nCahEeZT3WSNEq1UrkNzLmpdW2uhnZAJvkKbcvtz LRriz5aD4MV85KrOMUKcRoWUWZqabpY= X-MC-Unique: -fCdCgH8Ow-mL7AQPVzcvA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741274; x=1731346074; 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=Pk/ExTQ6ucVRc/G0SIy96rszaYTtvZQeQUouajsdp/c=; b=GUfzGOhBkfUFpmy62zsh47iX9drkjB8Fc1qdVMUObafFbwzQTMpGErP7DQ5Tm+ohvZ ExxvLW2t1cBPH41tadyAX/kTdq86r/FsSVfbgAyLKaTsTSJXw1NwEEv9vyGyYKifm8ZF ciYERUnYUhgZ+ecg7WjF5/AZLFHpkzMjKWNV8EO1B2Yzkg3ZP7ary984xJ6+3kfgNkvZ sVu1nHNKodjLVjNdVDUn63W7TiUyfZaDU3DMku3eMgQjufQA+V0FmvwAjTogt4Flxly9 EPWOmrOWMfaB5S2kS1Hyu9iK8HK3hmpzc2dPGTi0k0bw4PrtxapnHIPsooP16XipbfkR 84yw== X-Gm-Message-State: AOJu0Yw3Vy1dockVmCiMNLRgeuRvdMlH5jiNqOrrC8yHl1VRb4kCxvyG JVgjaPY0Rv5PeWCMwBLmV3qhNeYb0ys8xZOfSd3rDFwut/YWmgWGOQLYsM33kSHu6DEmde/iJL7 prWBAP+XQYKOjGcLzs2O5yTs2OvUD8or2xLpD8lTgOQ2AOrVwk9s+wEVIZVB/p9/Y5sfZtdeMtK w3+FALVTHfmsrU73abj6GWk6j5ol46+c6tg70ubjA= X-Received: by 2002:a5d:59ae:0:b0:37d:4436:4505 with SMTP id ffacd0b85a97d-381c7a6da29mr11183512f8f.32.1730741274161; Mon, 04 Nov 2024 09:27:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5OD0chnnFJNh9oI3nKMGx+drihViu2NxC6XbMhte5HIU3oQ1YFjnJIpz9F384EgrbBzmZmA== X-Received: by 2002:a5d:59ae:0:b0:37d:4436:4505 with SMTP id ffacd0b85a97d-381c7a6da29mr11183471f8f.32.1730741273702; Mon, 04 Nov 2024 09:27:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 14/40] rust: clean up define_property macro Date: Mon, 4 Nov 2024 18:26:53 +0100 Message-ID: <20241104172721.180255-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741672994116600 Content-Type: text/plain; charset="utf-8" Use the "struct update" syntax to initialize most of the fields to zero, and simplify the handmade type-checking of $name. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/device_class.rs | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index 2219b9f73d0..aab60484096 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -29,44 +29,27 @@ macro_rules! device_class_init { macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = =3D $defval:expr$(,)*) =3D> { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr =3D $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: true, - defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.= into() }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) =3D>= { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr =3D $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: false, - defval: $crate::bindings::Property__bindgen_ty_1 { i: 0 }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } } }; } --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741372; cv=none; d=zohomail.com; s=zohoarc; b=f3Ah7eftq/yYDNEuz4h3/TDhkx7gXYr+F5IODWH8gBH05OO5SUQ+eDeZqQbV6613d16ywS73wWnAyNqRPy/BKPIf0dJDyf6SgIKMli+KX0LcAYMlElBfN4gtEr6/qWQ6Eb2PiZJ4ceTZVaf0pklE6LR2u+A61dlvbjjWND/DXfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741372; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=l2dZTvoQGa7EAtC2HDpwzcBQ7yI0kzC/1TBZHRMxmWE=; b=nbW6A5Yt9Yjt8bONpYkrdjtpNbyKvVDcS2LMNtKh3EtlnQaAeZtAnedJa5cLmsHxZDb3ePkxEFyZMxeNbD4FbHn1PcKZUFEq0x5USYv7XCtyEd26ZDe8teLMffYt+iFIeioap9/a4dsgK7Spqyf1/eLT4dDNXTBheFIRTfunz8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173074137294375.6513898206548; Mon, 4 Nov 2024 09:29:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s2-0005F8-Ma; Mon, 04 Nov 2024 12:28:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s0-0005Do-MP for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rw-0000Ha-ND for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:04 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-Rhrniya9ORGFWAj38NzPhQ-1; Mon, 04 Nov 2024 12:27:58 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-431518ae047so29613035e9.0 for ; Mon, 04 Nov 2024 09:27:58 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c113e528sm13831378f8f.78.2024.11.04.09.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l2dZTvoQGa7EAtC2HDpwzcBQ7yI0kzC/1TBZHRMxmWE=; b=fovK47NhSV7WXgJZRIp/tFvL29j5SzI13ea4R0yTpwL6aOSw5QfXdimtGL68S+LMs1BLLK qmZLJZt9EXVhbT41jJFuCe22VIVDjSZAfZixmqnhlZOzzcbQSi9MsbINaki1LMzyr9OCNO FcwvBIAwcQajFqMLBZU8Kx12bwBheak= X-MC-Unique: Rhrniya9ORGFWAj38NzPhQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741276; x=1731346076; 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=l2dZTvoQGa7EAtC2HDpwzcBQ7yI0kzC/1TBZHRMxmWE=; b=CopJMaXNyH/gL6/PUAxo6vNgGznxoPfLxN1a+Heav5TgNegZ5jAzMIFNYzA8PadLxc 7w6CeyixfUc9JDxB4a/FYMdVqiUiGh1zW1a3v7//yU7iQ3NY4HoGJ+wNV0o8YRmDW33i /a8gc2J7DDjMb1jnqH1volYjU+XQElbMfLjDN4BorXugyi9KOCzQ1sdjkGRfBI1IiNMH 93fZOEj4AgDIBdxkZeh2rSHH8qDHmUGtzYMdbIkqxG8dlYvysT+VlXX5N0O+4rm03/Vs 5z+EK04ps9ikYWeUl4yb9l5AZ7nIskG+SOtHdGs4BycMUj1XAiM5o0NUELJuvYbF06lJ rQ9A== X-Gm-Message-State: AOJu0Yy2gHVb1DQvJbZFvGjfbSVv4nbuZM9uFL3EBbi+bKt6pSKHOCdf aiWb3BJ0pS1lGU+v4NvowEHofGpXNWy/i9WWdWIN0+sb4ziyrZJf+RWZP6EU78DRFXft+Fg8xWS vkP4oABF6WfM7nWEVKdrdlkcbbpX1h1E2K7/arytHOMMAzBH0gMbU0Krm7eiOX2PnVKAjZ0Pn0x BT5j+m+JRLlH/uS42QRSeOjaXgVq2R9cgAI90IM2g= X-Received: by 2002:a5d:59a6:0:b0:37d:3baa:9f34 with SMTP id ffacd0b85a97d-381c1305999mr16042051f8f.1.1730741276392; Mon, 04 Nov 2024 09:27:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmLmGZYoBGhTIsj+v6S0YXVk3wLRcqjHy0osvNlF9rcOn8KgMc6WZMD3KyU0HJ+Efn/iF3rw== X-Received: by 2002:a5d:59a6:0:b0:37d:3baa:9f34 with SMTP id ffacd0b85a97d-381c1305999mr16042012f8f.1.1730741275869; Mon, 04 Nov 2024 09:27:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 15/40] rust: make properties array immutable Date: Mon, 4 Nov 2024 18:26:54 +0100 Message-ID: <20241104172721.180255-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741373805116600 Content-Type: text/plain; charset="utf-8" Now that device_class_set_props() takes a const pointer, the only part of "define_property!" that needs to be non-const is the call to try_into(). This in turn will only break if offset_of returns a value with the most significant bit set (i.e. a struct size that is >=3D2^31 or >=3D 2^63, respectively on 32- and 64-bit system), which is impossible. Just use a cast and clean everything up to remove the run-time initialization. This also removes a use of OnceLock, which was only stabilized in 1.70.0. Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/device_class.rs | 42 ++++++------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index aab60484096..4b14cb3ffd6 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,10 +2,6 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 -use std::sync::OnceLock; - -use crate::bindings::Property; - #[macro_export] macro_rules! device_class_init { ($func:ident, props =3D> $props:ident, realize_fn =3D> $realize_fn:exp= r, legacy_reset_fn =3D> $legacy_reset_fn:expr, vmsd =3D> $vmsd:ident$(,)*) = =3D> { @@ -19,7 +15,7 @@ macro_rules! device_class_init { dc.as_mut().realize =3D $realize_fn; dc.as_mut().vmsd =3D &$vmsd; $crate::bindings::device_class_set_legacy_reset(dc.as_mut(= ), $legacy_reset_fn); - $crate::bindings::device_class_set_props(dc.as_mut(), $pro= ps.as_mut_ptr()); + $crate::bindings::device_class_set_props(dc.as_mut(), $pro= ps.as_ptr()); } } }; @@ -32,9 +28,7 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::core::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) - .try_into() - .expect("Could not fit offset value to type"), + offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } @@ -45,47 +39,27 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::core::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) - .try_into() - .expect("Could not fit offset value to type"), + offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } } }; } =20 -#[repr(C)] -pub struct Properties(pub OnceLock<[Property; N]>, pub fn(= ) -> [Property; N]); - -impl Properties { - pub fn as_mut_ptr(&mut self) -> *mut Property { - _ =3D self.0.get_or_init(self.1); - self.0.get_mut().unwrap().as_mut_ptr() - } -} - #[macro_export] macro_rules! declare_properties { ($ident:ident, $($prop:expr),*$(,)*) =3D> { - - const fn _calc_prop_len() -> usize { + pub static $ident: [$crate::bindings::Property; { let mut len =3D 1; $({ _ =3D stringify!($prop); len +=3D 1; })* len - } - const PROP_LEN: usize =3D _calc_prop_len(); - - fn _make_properties() -> [$crate::bindings::Property; PROP_LEN] { - [ - $($prop),*, - unsafe { ::core::mem::MaybeUninit::<$crate::bindings::= Property>::zeroed().assume_init() }, - ] - } - - pub static mut $ident: $crate::device_class::Properties = =3D $crate::device_class::Properties(::std::sync::OnceLock::new(), _make_pr= operties); + }] =3D [ + $($prop),*, + unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property= >::zeroed().assume_init() }, + ]; }; } =20 --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741696; cv=none; d=zohomail.com; s=zohoarc; b=a13nROl69hLsd6heAUpinTvVn+oXbY+gsBczRWr20TT/VeJrlTakRDOcElQaGYm4lYCd5FIRrfsvfHM4eOTdhV2gH9ZLQxguXkdTHsE9XFHKO5VIzREGGgJvyJtSLzT+lRMxUNw6+hT//7JyX600YSKFzyiFRQB/HxbX2iHbfd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741696; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XJKy0xe3JNrrE6/anLJ268ol41o+r1HxLKUij6otdYI=; b=Ya9cdiOkum34e3TSvWGigDIQiVx/hMsalhxHLhynw5jMjroZ67L9zy4nnj+ELUj0htpmjZ9elEClsSVdWIKEshQIxKO1dP7yJWn+ccWbfAfZgdh5G4UHglupy+8ANhO0jFcTsiITQwdzC4VTQn07DtvHFFLXaM8vLdaGh/flIOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741696374823.0395372553045; Mon, 4 Nov 2024 09:34:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s3-0005FP-7f; Mon, 04 Nov 2024 12:28:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s1-0005EL-9K for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rz-0000IK-4v for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:04 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-134-msrIovsNMGm1YRnELr-LHA-1; Mon, 04 Nov 2024 12:28:01 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315544642eso33004235e9.3 for ; Mon, 04 Nov 2024 09:28:00 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd9a9faesm189516705e9.35.2024.11.04.09.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XJKy0xe3JNrrE6/anLJ268ol41o+r1HxLKUij6otdYI=; b=QsexUUcuZTBxgSZXmpx7ru/0V29yose8c/lVQJ+aOJ/yWxfgHqgyqY7NI9K1V5Li3oXWh2 LaPtUVWA+7D0VG6YSMnNEtXZaHpOFfzkYuFzY2woWlKE8rd4WXQd/p+N/GYMY1uVZ6ZrLA 8p+Jcowhh6ZJ46yYvjWurgNwM2fM/XI= X-MC-Unique: msrIovsNMGm1YRnELr-LHA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741279; x=1731346079; 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=XJKy0xe3JNrrE6/anLJ268ol41o+r1HxLKUij6otdYI=; b=Wyopf6mu2BYmGsB8PiK3BO7oy/o707qIAf5sne+j/8+XLnOKfYOgswQdNmS425LRQ8 fiBgpI7mE3mWMwe+AyRo/EED6AQTjV1CLSIWWQz03znZ7VGX6CTVIgWfaTF9Fqrx/unp 40n6ufzP6pPEZNHyt+QoYF6w7e8USBqoYJ9Xp0HyE7vr4aAtRYjG3kzBc1dDS8W7Pcxk B7NGZ19quZTPGfWUx4eFaIcpK4UoZbHfki1lkq2ioBJUAUnHmIea8jbNJcegt+kxkAuA oLtF7LN2CbDRWeG6FWQIDNTtLrrLulwpBNiOmKDxqnz/HL6yY0kbQ/7ZuDz3Avu4oupQ vfbw== X-Gm-Message-State: AOJu0YwFidpqiLHUbB4jeljb8ujrxfth+yU6HRTCXsrV+QW2Op/wkHHg 816IkvrWtLSTrMBXfEBti+Yqf1Ex6DlxpZdL4uuYgmHA7TBe0niQ46Urb/U3cnw8PK2Q9nxob/W t1lMeXBTkxSWkxYk+g3Qdnwysk1Yprb32KEo31Gl7GaeFzU6t9K266Nl+rbCNOoxilj+/jw5Fb3 6202hT+XC1MkP1VDGTVVBlg5Aq+3wB8dn7jJHjxJo= X-Received: by 2002:a05:600c:3ca8:b0:431:52b7:a499 with SMTP id 5b1f17b1804b1-4327b7019ddmr133802315e9.20.1730741279009; Mon, 04 Nov 2024 09:27:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtJsOfk/ExGhk8VkKisxCH+ZTfwQAioW/TB1c5ruDXm2kgBjGPtQBu8TDGXNoK4fCLD9Mt1g== X-Received: by 2002:a05:600c:3ca8:b0:431:52b7:a499 with SMTP id 5b1f17b1804b1-4327b7019ddmr133801965e9.20.1730741278520; Mon, 04 Nov 2024 09:27:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 16/40] rust: provide safe wrapper for MaybeUninit::zeroed() Date: Mon, 4 Nov 2024 18:26:55 +0100 Message-ID: <20241104172721.180255-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741697305116600 Content-Type: text/plain; charset="utf-8" MaybeUninit::zeroed() is handy, but it introduces unsafe (and has a pretty heavy syntax in general). Introduce a trait that provides the same functionality while staying within safe Rust. In addition, MaybeUninit::zeroed() is not available as a "const" function until Rust 1.75.0, so this also prepares for having handwritten implementations of the trait until we can assume that version. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device_class.rs | 4 ++-- rust/hw/char/pl011/src/memory_ops.rs | 8 ++++---- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/device_class.rs | 8 ++++---- rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/zeroable.rs | 23 +++++++++++++++++++++++ 6 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 rust/qemu-api/src/zeroable.rs diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index 2ad80451e87..08c846aa482 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -4,7 +4,7 @@ =20 use core::ptr::NonNull; =20 -use qemu_api::{bindings::*, definitions::ObjectImpl}; +use qemu_api::{bindings::*, definitions::ObjectImpl, zeroable::Zeroable}; =20 use crate::device::PL011State; =20 @@ -12,7 +12,7 @@ pub static VMSTATE_PL011: VMStateDescription =3D VMStateDescription { name: PL011State::TYPE_INFO.name, unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::::zeroed().as= sume_init() } + ..Zeroable::ZERO }; =20 qemu_api::declare_properties! { diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/= memory_ops.rs index 5a5320e66c3..fc69922fbf3 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -2,9 +2,9 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 -use core::{mem::MaybeUninit, ptr::NonNull}; +use core::ptr::NonNull; =20 -use qemu_api::bindings::*; +use qemu_api::{bindings::*, zeroable::Zeroable}; =20 use crate::device::PL011State; =20 @@ -14,11 +14,11 @@ read_with_attrs: None, write_with_attrs: None, endianness: device_endian::DEVICE_NATIVE_ENDIAN, - valid: unsafe { MaybeUninit::::zeroed()= .assume_init() }, + valid: Zeroable::ZERO, impl_: MemoryRegionOps__bindgen_ty_2 { min_access_size: 4, max_access_size: 4, - ..unsafe { MaybeUninit::::zeroed().= assume_init() } + ..Zeroable::ZERO }, }; =20 diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1fc36078027..1b0fd406378 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,6 +5,7 @@ _qemu_api_rs =3D static_library( 'src/lib.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/zeroable.rs', ], {'.' : bindings_rs}, ), diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index 4b14cb3ffd6..aa6088d9d3d 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -31,7 +31,7 @@ macro_rules! define_property { offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) =3D>= { @@ -41,7 +41,7 @@ macro_rules! define_property { info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO } }; } @@ -58,7 +58,7 @@ macro_rules! declare_properties { len }] =3D [ $($prop),*, - unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Property= >::zeroed().assume_init() }, + $crate::zeroable::Zeroable::ZERO, ]; }; } @@ -79,7 +79,7 @@ macro_rules! vm_state_description { $vname.as_ptr() },)* unmigratable: true, - ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::VMStat= eDescription>::zeroed().assume_init() } + ..$crate::zeroable::Zeroable::ZERO }; } } diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 6bc68076aae..e94a15bb823 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -29,6 +29,7 @@ unsafe impl Sync for bindings::VMStateDescription {} =20 pub mod definitions; pub mod device_class; +pub mod zeroable; =20 use std::alloc::{GlobalAlloc, Layout}; =20 diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs new file mode 100644 index 00000000000..45ec95c9f70 --- /dev/null +++ b/rust/qemu-api/src/zeroable.rs @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/// Encapsulates the requirement that +/// `MaybeUninit::::zeroed().assume_init()` does not cause +/// undefined behavior. +/// +/// # Safety +/// +/// Do not add this trait to a type unless all-zeroes is +/// a valid value for the type. In particular, remember that raw +/// pointers can be zero, but references and `NonNull` cannot +/// unless wrapped with `Option<>`. +pub unsafe trait Zeroable: Default { + /// SAFETY: If the trait was added to a type, then by definition + /// this is safe. + const ZERO: Self =3D unsafe { ::core::mem::MaybeUninit::::zeroed= ().assume_init() }; +} + +unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::Property {} +unsafe impl Zeroable for crate::bindings::VMStateDescription {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {} --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741552; cv=none; d=zohomail.com; s=zohoarc; b=Y3UYXa5Xnvx0/2Mc2ErnyY4BZiKPPqDyjeNgJhVOC+hjReFF8QUi5MdIQ1OWIfkUfnuqnEq/CdnBEiPlWS04Jx44DzilnokvIQOKz+7yx8KFhRmQSHsmRtCp0tvYr8S1rLG0qLH9wjJBABKD5VHaH1VIur965/xkTdUx3Mp1ig4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741552; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cnNbN2/GG/cHatir8SHvYVVNQ8/dSXQusHp7oYcZdJw=; b=jSGlCHdtuWHSn3JOLOIWl6eFO8BmB7IbGp0HmBhgcxL4Q4dgC5CqRUVE5gZTbt1GsoO78/u4IJHrqtg2hTIoQ5ont7PlNywCZkzFt4v6yNd1op/YwdHtnrbtzPm+BqrsktfoXLX9VVw6a5rBvKdx30oJN3l5/9OamOuSJWLH724= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741552548218.13717407989634; Mon, 4 Nov 2024 09:32:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s7-0005HE-NS; Mon, 04 Nov 2024 12:28:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s4-0005Gj-Lx for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s1-0000JH-Kd for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:08 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-en6nXlSyP4Kw2r6bJ1346A-1; Mon, 04 Nov 2024 12:28:03 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4317391101aso29007865e9.2 for ; Mon, 04 Nov 2024 09:28:03 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm163506775e9.42.2024.11.04.09.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741285; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cnNbN2/GG/cHatir8SHvYVVNQ8/dSXQusHp7oYcZdJw=; b=fLHHwqP9QsscfVzxCkIRfvWUod0DFsv0bjMCkVO3m0qJ2Nr1etjK/m2NFT8XX4TfH2kx/q 2vdKjdav5xyxZ3wcL+jf1Uh8uVMoBDB5silNQokf69dazxCA/Mkt5yM2vezlCdabQ0XoL+ bDY/VX1hTqTKtHOjOagjkAYk8amcK+o= X-MC-Unique: en6nXlSyP4Kw2r6bJ1346A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741281; x=1731346081; 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=cnNbN2/GG/cHatir8SHvYVVNQ8/dSXQusHp7oYcZdJw=; b=mSGeCQGj63l0cmB/KVD6UkDCOLwnEheWIqnLC3OLNR27HpGHF+nkVeepEaQqWLGRFk SN3aB/4hUeqCN3kxkWUqS5O0ujwsszmOqDiHY7DB5fImIXlAfQCGViQQrZPhuTZIU8Cl n6iNdcT2uY/KuESG6rP1tJ+Zhc8gkhTTfkK+ybF0+wZEBIpi8mh1/lRR6JXBe20KCW7/ zLRTh5wz4VSLbRhQXyt42HE+DzT9m0WBanYZscb4LrkP3UNbAks/nIucHZamAGMyGFdS 15VItKyyqL0xydfDe61LXqO3QEA9g0+WRJQHfSkgPLjmI7aB7qxOo+n2UXQYilDxql4I 2BYg== X-Gm-Message-State: AOJu0YxHHOtSdHMebwemepvqU8+odVt2y/cXSVCcaEfis3gAoY1rc0Os 0GnfJ5kSlDJCMvoZ4qNIkQbSG/7COUcvxszA3FUbQbtQvFMxjbqupTjQk9Iy/NL2VdJN0fPp6BL MAaBVn4qZ1L22ueI6XiGixUHBS0OKJggA1lJGA99lQXdL0rym6PJJWvgMHoCealc8EUSxPhJrO1 1tUMinWNTloEP4V+H/onVcu0Wm9c2rPL7UpAuEzrY= X-Received: by 2002:a05:600c:16ca:b0:431:5847:f63f with SMTP id 5b1f17b1804b1-43283246cb4mr109632935e9.13.1730741281454; Mon, 04 Nov 2024 09:28:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfxSOey6TZyJjVfmDTDe9k/TwZjeQYQc92a9I03gILRXMQw/VCMGkfvUlxrdaiJYLpFJrBpA== X-Received: by 2002:a05:600c:16ca:b0:431:5847:f63f with SMTP id 5b1f17b1804b1-43283246cb4mr109632615e9.13.1730741281071; Mon, 04 Nov 2024 09:28:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 17/40] rust: do not use TYPE_CHARDEV unnecessarily Date: Mon, 4 Nov 2024 18:26:56 +0100 Message-ID: <20241104172721.180255-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741554333116600 Content-Type: text/plain; charset="utf-8" In the invocation of qdev_prop_set_chr(), "chardev" is the name of a property rather than a type and has to match the name of the property in device_class.rs. Do not use TYPE_CHARDEV here, just like in the C version of pl011_create. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 0347a027c5f..b3d8bc004e0 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -573,7 +573,7 @@ pub fn update(&self) { let dev: *mut DeviceState =3D qdev_new(PL011State::TYPE_INFO.name); let sysbus: *mut SysBusDevice =3D dev.cast::(); =20 - qdev_prop_set_chr(dev, bindings::TYPE_CHARDEV.as_ptr(), chr); + qdev_prop_set_chr(dev, c"chardev".as_ptr(), chr); sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mu= t Error); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq); --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741669; cv=none; d=zohomail.com; s=zohoarc; b=jA9zPVFKLM5fjP4wNQTyO0OqVLBZCgS4ewGJDo3eIgSzRF0UuVGZnzHZ/+V2YVpfdGFZggnAIuBnVDXPjJq5yjnrXSsZ5guLp8NW6iPpIgx9MQ0IFfMGcmemUMBlrEbimnaxNB86TxL4GUSiEPBHVXqgm1gFdtGd2M4uzepX7KU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741669; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y7G8bk7MyTkiYNKpQlNw/iAAoDfnCCinR0B/3jOuQkg=; b=a9P4X5O5dD3GTijpgG1gGUmqrYCwcvTE9vQorRcaaYqEOUl5Ekve0cSYvOe5iSfAgoHy+TL24wNIK4+VhOAhAyNJHf+ZHk8tzp9tRhZ81FqN21PYq7iiqFCQjoAeUgVKOSuf42ZqFYlylUbujRPKV9rtat1tzmbd460STb8fJ88= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741669233145.62314460077357; Mon, 4 Nov 2024 09:34:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sA-0005L3-Og; Mon, 04 Nov 2024 12:28:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s9-0005Is-Kp for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s7-0000KK-0S for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:13 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-10-cA88tIBVM2CIWzwOyEuW_w-1; Mon, 04 Nov 2024 12:28:06 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315e8e9b1cso25240365e9.1 for ; Mon, 04 Nov 2024 09:28:06 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c113e595sm13749411f8f.77.2024.11.04.09.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y7G8bk7MyTkiYNKpQlNw/iAAoDfnCCinR0B/3jOuQkg=; b=jRAFYmtA8rNP9UxuKeeQ8Ms5FR2tuRAy+jQK2KEyu+x6cOxoz0CRLGb5O8IHTpuQjRyyh+ d4xD95o73ThL5B6bToJoobCDzi6w6cmSxDR9EZH3glOrY7ilsmH6F96bItHAeJT4BVgsI8 d1EwXFWn66663dpH3MXeyHlaHXAlHz4= X-MC-Unique: cA88tIBVM2CIWzwOyEuW_w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741284; x=1731346084; 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=Y7G8bk7MyTkiYNKpQlNw/iAAoDfnCCinR0B/3jOuQkg=; b=OCuVKL1Tw6ybtAZxSDedcBqV9KEo/F4SmH7tdtDXHpR5Y0a3UxRdK/hC14I/1mfFF0 kQGyH3TVVchJfBXqJODUjom9WnSCa56FZCwtJjp3et1Ir3lpBMYcCPs1hH7DRDzEIQWM X6Z/jKbREuqlq8XnciHOJJuHhjjmW+P/oorQD49KveZ7zi5ltyahkJIRVS2e2F0Nk1lu SP6bH00lVPOzLYWAWpIHEUB/vB4vEwX+Py65dV7RSDydRu+Jw0Zni5NjxxxI6BBbo2nB Gu+hwQ8g0OWvNEaFfSFaGIrJ+UiyMzcUrb4o3eEPmL1sWqtXLwA81XmwAUe25o5+ZUay LQHQ== X-Gm-Message-State: AOJu0Yw1Xtlql0+mDTi2FczA84/7AfWp/dbzI+IIUJntaIM6YwtgKYY4 cduFzQldh4FmxzkMFNdbY3d6VMQLrexZzwzp1b/okxLkknV+EEjTPryM2vqOiAeg7xc83gjM2VT rCWqCY8ROIxqvZX64hWVTxU0PRkDCn6hyjmHpW+se4m2mna4jKnH5VK7yo/xp9v3k9/WDH/T/zr FLJv3x8Dt3oeuaLRpEysCCY7NIqmfHhZAlcbLprF0= X-Received: by 2002:a05:600c:45cd:b0:42c:b98d:b993 with SMTP id 5b1f17b1804b1-4327da72175mr123428885e9.2.1730741283890; Mon, 04 Nov 2024 09:28:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNi0wbQoV6HSZqqYkmrrFKL+OWxEhm0kDbnYYs8RUBtwgGn8HtUDlLQmvSbUUsYDQq9Zu+Ww== X-Received: by 2002:a05:600c:45cd:b0:42c:b98d:b993 with SMTP id 5b1f17b1804b1-4327da72175mr123428565e9.2.1730741283375; Mon, 04 Nov 2024 09:28:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 18/40] rust: add definitions for vmstate Date: Mon, 4 Nov 2024 18:26:57 +0100 Message-ID: <20241104172721.180255-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741671300116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Add a new qemu_api module, `vmstate`. Declare a bunch of Rust macros declared that are equivalent in spirit to the C macros in include/migration/vmstate.h. For example the Rust of equivalent of the C macro: VMSTATE_UINT32(field_name, struct_name) is: vmstate_uint32!(field_name, StructName) This breathtaking development will allow us to reach feature parity between the Rust and C pl011 implementations. Extracted from a patch by Manos Pitsidianakis (https://lore.kernel.org/qemu-devel/20241024-rust-round-2-v1-4-051e7a25b978= @linaro.org/). Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/device_class.rs | 21 -- rust/qemu-api/src/lib.rs | 3 + rust/qemu-api/src/vmstate.rs | 360 ++++++++++++++++++++++++++++++ rust/qemu-api/tests/tests.rs | 11 +- 5 files changed, 370 insertions(+), 26 deletions(-) create mode 100644 rust/qemu-api/src/vmstate.rs diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 1b0fd406378..3b849f7c413 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,6 +5,7 @@ _qemu_api_rs =3D static_library( 'src/lib.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/vmstate.rs', 'src/zeroable.rs', ], {'.' : bindings_rs}, diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index aa6088d9d3d..3d40256f60f 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -62,24 +62,3 @@ macro_rules! declare_properties { ]; }; } - -#[macro_export] -macro_rules! vm_state_description { - ($(#[$outer:meta])* - $name:ident, - $(name: $vname:expr,)* - $(unmigratable: $um_val:expr,)* - ) =3D> { - #[used] - $(#[$outer])* - pub static $name: $crate::bindings::VMStateDescription =3D $crate:= :bindings::VMStateDescription { - $(name: { - #[used] - static VMSTATE_NAME: &::core::ffi::CStr =3D $vname; - $vname.as_ptr() - },)* - unmigratable: true, - ..$crate::zeroable::Zeroable::ZERO - }; - } -} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e94a15bb823..10ab3d7e639 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -26,9 +26,12 @@ unsafe impl Send for bindings::Property {} unsafe impl Sync for bindings::Property {} unsafe impl Sync for bindings::TypeInfo {} unsafe impl Sync for bindings::VMStateDescription {} +unsafe impl Sync for bindings::VMStateField {} +unsafe impl Sync for bindings::VMStateInfo {} =20 pub mod definitions; pub mod device_class; +pub mod vmstate; pub mod zeroable; =20 use std::alloc::{GlobalAlloc, Layout}; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs new file mode 100644 index 00000000000..0c1197277f9 --- /dev/null +++ b/rust/qemu-api/src/vmstate.rs @@ -0,0 +1,360 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +//! Helper macros to declare migration state for device models. +//! +//! Some macros are direct equivalents to the C macros declared in +//! `include/migration/vmstate.h` while +//! [`vmstate_subsections`](crate::vmstate_subsections) and +//! [`vmstate_fields`](crate::vmstate_fields) are meant to be used when +//! declaring a device model state struct. + +#[doc(alias =3D "VMSTATE_UNUSED_BUFFER")] +#[macro_export] +macro_rules! vmstate_unused_buffer { + ($field_exists_fn:expr, $version_id:expr, $size:expr) =3D> {{ + $crate::bindings::VMStateField { + name: c"unused".as_ptr(), + err_hint: ::core::ptr::null(), + offset: 0, + size: $size, + start: 0, + num: 0, + num_offset: 0, + size_offset: 0, + info: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate= _info_unused_buffer) }, + flags: VMStateFlags::VMS_BUFFER, + vmsd: ::core::ptr::null(), + version_id: $version_id, + struct_version_id: 0, + field_exists: $field_exists_fn, + } + }}; +} + +#[doc(alias =3D "VMSTATE_UNUSED_V")] +#[macro_export] +macro_rules! vmstate_unused_v { + ($version_id:expr, $size:expr) =3D> {{ + $crate::vmstate_unused_buffer!(None, $version_id, $size) + }}; +} + +#[doc(alias =3D "VMSTATE_UNUSED")] +#[macro_export] +macro_rules! vmstate_unused { + ($size:expr) =3D> {{ + $crate::vmstate_unused_v!(0, $size) + }}; +} + +#[doc(alias =3D "VMSTATE_SINGLE_TEST")] +#[macro_export] +macro_rules! vmstate_single_test { + ($field_name:ident, $struct_name:ty, $field_exists_fn:expr, $version_i= d:expr, $info:expr, $size:expr) =3D> {{ + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), 0) + .as_bytes() + .as_ptr() as *const ::core::ffi::c_char, + err_hint: ::core::ptr::null(), + offset: ::core::mem::offset_of!($struct_name, $field_name), + size: $size, + start: 0, + num: 0, + num_offset: 0, + size_offset: 0, + info: unsafe { $info }, + flags: VMStateFlags::VMS_SINGLE, + vmsd: ::core::ptr::null(), + version_id: $version_id, + struct_version_id: 0, + field_exists: $field_exists_fn, + } + }}; +} + +#[doc(alias =3D "VMSTATE_SINGLE")] +#[macro_export] +macro_rules! vmstate_single { + ($field_name:ident, $struct_name:ty, $version_id:expr, $info:expr, $si= ze:expr) =3D> {{ + $crate::vmstate_single_test!($field_name, $struct_name, None, $ver= sion_id, $info, $size) + }}; +} + +#[doc(alias =3D "VMSTATE_UINT32_V")] +#[macro_export] +macro_rules! vmstate_uint32_v { + ($field_name:ident, $struct_name:ty, $version_id:expr) =3D> {{ + $crate::vmstate_single!( + $field_name, + $struct_name, + $version_id, + ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32), + ::core::mem::size_of::() + ) + }}; +} + +#[doc(alias =3D "VMSTATE_UINT32")] +#[macro_export] +macro_rules! vmstate_uint32 { + ($field_name:ident, $struct_name:ty) =3D> {{ + $crate::vmstate_uint32_v!($field_name, $struct_name, 0) + }}; +} + +#[doc(alias =3D "VMSTATE_INT32_V")] +#[macro_export] +macro_rules! vmstate_int32_v { + ($field_name:ident, $struct_name:ty, $version_id:expr) =3D> {{ + $crate::vmstate_single!( + $field_name, + $struct_name, + $version_id, + ::core::ptr::addr_of!($crate::bindings::vmstate_info_int32), + ::core::mem::size_of::() + ) + }}; +} + +#[doc(alias =3D "VMSTATE_INT32")] +#[macro_export] +macro_rules! vmstate_int32 { + ($field_name:ident, $struct_name:ty) =3D> {{ + $crate::vmstate_int32_v!($field_name, $struct_name, 0) + }}; +} + +#[doc(alias =3D "VMSTATE_ARRAY")] +#[macro_export] +macro_rules! vmstate_array { + ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr, $= info:expr, $size:expr) =3D> {{ + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), 0) + .as_bytes() + .as_ptr() as *const ::core::ffi::c_char, + err_hint: ::core::ptr::null(), + offset: ::core::mem::offset_of!($struct_name, $field_name), + size: $size, + start: 0, + num: $length as _, + num_offset: 0, + size_offset: 0, + info: unsafe { $info }, + flags: VMStateFlags::VMS_ARRAY, + vmsd: ::core::ptr::null(), + version_id: $version_id, + struct_version_id: 0, + field_exists: None, + } + }}; +} + +#[doc(alias =3D "VMSTATE_UINT32_ARRAY_V")] +#[macro_export] +macro_rules! vmstate_uint32_array_v { + ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr) = =3D> {{ + $crate::vmstate_array!( + $field_name, + $struct_name, + $length, + $version_id, + ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32), + ::core::mem::size_of::() + ) + }}; +} + +#[doc(alias =3D "VMSTATE_UINT32_ARRAY")] +#[macro_export] +macro_rules! vmstate_uint32_array { + ($field_name:ident, $struct_name:ty, $length:expr) =3D> {{ + $crate::vmstate_uint32_array_v!($field_name, $struct_name, $length= , 0) + }}; +} + +#[doc(alias =3D "VMSTATE_STRUCT_POINTER_V")] +#[macro_export] +macro_rules! vmstate_struct_pointer_v { + ($field_name:ident, $struct_name:ty, $version_id:expr, $vmsd:expr, $ty= pe:ty) =3D> {{ + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), 0) + .as_bytes() + .as_ptr() as *const ::core::ffi::c_char, + err_hint: ::core::ptr::null(), + offset: ::core::mem::offset_of!($struct_name, $field_name), + size: ::core::mem::size_of::<*const $type>(), + start: 0, + num: 0, + num_offset: 0, + size_offset: 0, + info: ::core::ptr::null(), + flags: VMStateFlags(VMStateFlags::VMS_STRUCT.0 | VMStateFlags:= :VMS_POINTER.0), + vmsd: unsafe { $vmsd }, + version_id: $version_id, + struct_version_id: 0, + field_exists: None, + } + }}; +} + +#[doc(alias =3D "VMSTATE_ARRAY_OF_POINTER")] +#[macro_export] +macro_rules! vmstate_array_of_pointer { + ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $inf= o:expr, $type:ty) =3D> {{ + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), 0) + .as_bytes() + .as_ptr() as *const ::core::ffi::c_char, + version_id: $version_id, + num: $num as _, + info: unsafe { $info }, + size: ::core::mem::size_of::<*const $type>(), + flags: VMStateFlags(VMStateFlags::VMS_ARRAY.0 | VMStateFlags::= VMS_ARRAY_OF_POINTER.0), + offset: ::core::mem::offset_of!($struct_name, $field_name), + err_hint: ::core::ptr::null(), + start: 0, + num_offset: 0, + size_offset: 0, + vmsd: ::core::ptr::null(), + struct_version_id: 0, + field_exists: None, + } + }}; +} + +#[doc(alias =3D "VMSTATE_ARRAY_OF_POINTER_TO_STRUCT")] +#[macro_export] +macro_rules! vmstate_array_of_pointer_to_struct { + ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $vms= d:expr, $type:ty) =3D> {{ + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), 0) + .as_bytes() + .as_ptr() as *const ::core::ffi::c_char, + version_id: $version_id, + num: $num as _, + vmsd: unsafe { $vmsd }, + size: ::core::mem::size_of::<*const $type>(), + flags: VMStateFlags( + VMStateFlags::VMS_ARRAY.0 + | VMStateFlags::VMS_STRUCT.0 + | VMStateFlags::VMS_ARRAY_OF_POINTER.0, + ), + offset: ::core::mem::offset_of!($struct_name, $field_name), + err_hint: ::core::ptr::null(), + start: 0, + num_offset: 0, + size_offset: 0, + vmsd: ::core::ptr::null(), + struct_version_id: 0, + field_exists: None, + } + }}; +} + +#[doc(alias =3D "VMSTATE_CLOCK_V")] +#[macro_export] +macro_rules! vmstate_clock_v { + ($field_name:ident, $struct_name:ty, $version_id:expr) =3D> {{ + $crate::vmstate_struct_pointer_v!( + $field_name, + $struct_name, + $version_id, + ::core::ptr::addr_of!($crate::bindings::vmstate_clock), + $crate::bindings::Clock + ) + }}; +} + +#[doc(alias =3D "VMSTATE_CLOCK")] +#[macro_export] +macro_rules! vmstate_clock { + ($field_name:ident, $struct_name:ty) =3D> {{ + $crate::vmstate_clock_v!($field_name, $struct_name, 0) + }}; +} + +#[doc(alias =3D "VMSTATE_ARRAY_CLOCK_V")] +#[macro_export] +macro_rules! vmstate_array_clock_v { + ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr) =3D>= {{ + $crate::vmstate_array_of_pointer_to_struct!( + $field_name, + $struct_name, + $num, + $version_id, + ::core::ptr::addr_of!($crate::bindings::vmstate_clock), + $crate::bindings::Clock + ) + }}; +} + +#[doc(alias =3D "VMSTATE_ARRAY_CLOCK")] +#[macro_export] +macro_rules! vmstate_array_clock { + ($field_name:ident, $struct_name:ty, $num:expr) =3D> {{ + $crate::vmstate_array_clock_v!($field_name, $struct_name, $name, 0) + }}; +} + +/// Helper macro to declare a list of +/// ([`VMStateField`](`crate::bindings::VMStateField`)) into a static and = return +/// a pointer to the array of values it created. +#[macro_export] +macro_rules! vmstate_fields { + ($($field:expr),*$(,)*) =3D> {{ + static _FIELDS: &[$crate::bindings::VMStateField] =3D &[ + $($field),*, + $crate::bindings::VMStateField { + name: ::core::ptr::null(), + err_hint: ::core::ptr::null(), + offset: 0, + size: 0, + start: 0, + num: 0, + num_offset: 0, + size_offset: 0, + info: ::core::ptr::null(), + flags: VMStateFlags::VMS_END, + vmsd: ::core::ptr::null(), + version_id: 0, + struct_version_id: 0, + field_exists: None, + } + ]; + _FIELDS.as_ptr() + }} +} + +/// A transparent wrapper type for the `subsections` field of +/// [`VMStateDescription`](crate::bindings::VMStateDescription). +/// +/// This is necessary to be able to declare subsection descriptions as sta= tics, +/// because the only way to implement `Sync` for a foreign type (and `*con= st` +/// pointers are foreign types in Rust) is to create a wrapper struct and +/// `unsafe impl Sync` for it. +/// +/// This struct is used in the +/// [`vm_state_subsections`](crate::vmstate_subsections) macro implementat= ion. +#[repr(transparent)] +pub struct VMStateSubsectionsWrapper(pub &'static [*const crate::bindings:= :VMStateDescription]); + +unsafe impl Sync for VMStateSubsectionsWrapper {} + +/// Helper macro to declare a list of subsections +/// ([`VMStateDescription`](`crate::bindings::VMStateDescription`)) into a +/// static and return a pointer to the array of pointers it created. +#[macro_export] +macro_rules! vmstate_subsections { + ($($subsection:expr),*$(,)*) =3D> {{ + static _SUBSECTIONS: $crate::vmstate::VMStateSubsectionsWrapper = =3D $crate::vmstate::VMStateSubsectionsWrapper(&[ + $({ + static _SUBSECTION: $crate::bindings::VMStateDescription = =3D $subsection; + ::core::ptr::addr_of!(_SUBSECTION) + }),*, + ::core::ptr::null() + ]); + _SUBSECTIONS.0.as_ptr() + }} +} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index aa1e0568c69..37c4dd44f81 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -8,17 +8,18 @@ bindings::*, declare_properties, define_property, definitions::{Class, ObjectImpl}, - device_class_init, vm_state_description, + device_class_init, + zeroable::Zeroable, }; =20 #[test] fn test_device_decl_macros() { // Test that macros can compile. - vm_state_description! { - VMSTATE, - name: c"name", + pub static VMSTATE: VMStateDescription =3D VMStateDescription { + name: c"name".as_ptr(), unmigratable: true, - } + ..Zeroable::ZERO + }; =20 #[repr(C)] #[derive(qemu_api_macros::Object)] --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741339; cv=none; d=zohomail.com; s=zohoarc; b=jmftPFcN/bXsAXYjn9cgJLBS7ktYE75NxcqawhJa3hk5apncv44Tm+qtIuoUTS+8JpsfDGMv+7jQ1K5ae2IYrmxgBVC/s8zTlJ9iKyATN3CBy+MhLbRtX5ZciSD9lNhU6fSHpz4uNcKm6SBRhXFjlrvrKhMUun/q3jsxj+giVk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741339; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U6hzpadmFMiM+zfoWH0oKGs9+Uf4D6zyZQRtFbQa8FU=; b=BgiB3EWV9o5xKZqvAX3wObDjOv6uDa7qlvrxEh1+I3zFRDzQRo4Xjc3CIXUj2paqYU9HIdiw42hjEkfMLlUtQc1zRWVtoQT7bc3npYG0KSGZogmJgM8gkQ8FwKjUkNJIe6VoZ3P8M3PDyd6X7oimZp63GU7I3pnovY61nU5e6Fg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741339687204.8461513054059; Mon, 4 Nov 2024 09:28:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s9-0005IX-62; Mon, 04 Nov 2024 12:28:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s7-0005Hk-8A for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s5-0000Jy-QO for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:11 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-6Ql_pNm4Mtidrl-Hvgm-DQ-1; Mon, 04 Nov 2024 12:28:07 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315d98a75fso30791875e9.2 for ; Mon, 04 Nov 2024 09:28:06 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6852efsm159511445e9.30.2024.11.04.09.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U6hzpadmFMiM+zfoWH0oKGs9+Uf4D6zyZQRtFbQa8FU=; b=SMf69HN86uzSrAQO/eH32oGKpojRs3tODpNviA1fQyoGH7Wg+Q+cyq1GuKcChdNcLt0HKA NijUNQcsjaIdQg9OM0Mzcxx7bvUz4UNaLOEfj8VWqq9Q87Zou6TJ5/cWblpRcgtOni/+5Q SP+XvJwBGgQk0XOLJQzwl8nHgZCoxy8= X-MC-Unique: 6Ql_pNm4Mtidrl-Hvgm-DQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741285; x=1731346085; 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=U6hzpadmFMiM+zfoWH0oKGs9+Uf4D6zyZQRtFbQa8FU=; b=rzEX8NSqDRHQ7BcOf3C89UfnWYJQQJalz9nRQFpLGECZztQHIr5fJIWRIYgLwNs6Dj RoCCAb6VRFMZF67XGeMQqefb31RjoANjeg0GVZvlqr8hyknU/gYysr1V058zh8hfHjOr nxMc4haPjhsWvnK8fM1Lvfc3veLMqPERTVWXEFYvcKKDlUsvcMySsBbKGoxGXryR77DV 5QsHJjMb4+XUniX/85YOjJNsUze1chfT3ty3lnlnzuxlHHsW0vGb05raOSsgqg8kN08x Zl/4beai9MmmdRT/WfUuudxFxGUu72vgKAPY9LWkM38fyunzsEvN8vk/lk6vNEvveDrA dLEg== X-Gm-Message-State: AOJu0YwJ8QcI5dvpQhWcpOqloML5ao6FZDDrEyv81UNAfizg8SA4C55P vYGungwSDE76JOf99S7fp7J5mkLeTZ7SUngTI1aYfk/fqlkatEWkJGFy0DQopCIGovYbGQMItk4 Z79WuRu2Gjr6WF73z1IiOrDusWO5RQk3azpBnsMKPIPMJBuvhr3rhpFsYU2nAA2FEjD0fgKKi7O IR22AdKKm9Z/GCuePdxlYI9QPsZqpo9qpppPCTx80= X-Received: by 2002:a05:600c:3514:b0:431:4880:3120 with SMTP id 5b1f17b1804b1-4319aca55a6mr272666855e9.11.1730741284991; Mon, 04 Nov 2024 09:28:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvZwBC0mxCI/3SmtB+bC3sFEpSyQUqL5OLpoP5sa7CsP6olNc438zsZAokKVj7tK8gIjUyTQ== X-Received: by 2002:a05:600c:3514:b0:431:4880:3120 with SMTP id 5b1f17b1804b1-4319aca55a6mr272666545e9.11.1730741284556; Mon, 04 Nov 2024 09:28:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 19/40] rust/pl011: fix default value for migrate-clock Date: Mon, 4 Nov 2024 18:26:58 +0100 Message-ID: <20241104172721.180255-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741341523116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device_class.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index 08c846aa482..9282dc4d151 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -29,7 +29,8 @@ PL011State, migrate_clock, unsafe { &qdev_prop_bool }, - bool + bool, + default =3D true ), } =20 --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741363; cv=none; d=zohomail.com; s=zohoarc; b=Cp0U/WWxS36cGPQamlTuPr+nu4MDRsq5E8qq4VCKl1JuVqXCOojF4v7ECf/w1+XbeyK23prkQVdGnRstCA2KaBUVqz68gjhYgsriUMYDtlA5NDRysu1w8i5AKGgTIjtyvfy2wkOUJJGikuztHdKUt9vibSJmUOjchEEf1Z5CxcM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741363; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OqkXxw1bduZ43gp4lqA3txKBa+8d8snHV/hj05OBUDY=; b=F68P3b7IGlpeqL8idulpBdPb2iHM3WsCy2U1MTtjWmsUhjcSjX7ZyGVpYNScy4gzSlgss/EO3ocazfkwkBzd0pkyaznHF3Zq1l2ICbWUH5gvQqS1H6QAWN/wu04RmxmNCSWh4igE5j0E852/gvcF3poKSk+w1/CxORGnvS5IZ1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741363949193.75012559963614; Mon, 4 Nov 2024 09:29:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sC-0005N4-IZ; Mon, 04 Nov 2024 12:28:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s9-0005Iq-G1 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80s7-0000Kg-Hn for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:13 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-vtGrVKQUO0Sy8bkKKxuRpA-1; Mon, 04 Nov 2024 12:28:09 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4317391101aso29008745e9.2 for ; Mon, 04 Nov 2024 09:28:09 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd8e853esm193969385e9.8.2024.11.04.09.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OqkXxw1bduZ43gp4lqA3txKBa+8d8snHV/hj05OBUDY=; b=eg9DyoTLZ3bybLM0OFqqxAxn4ZCE+aIUhOvukHyWlEnjzEZKNhVzhoXhpz0K9OjSVKzDVe mYAhcYtPxmvx6oLvx0TgrhqCJBW8MGQjxRQmjn4gQr2F9s02z71hdDKXXPs8M7YHVlBCzi rBRkUaqJ7UOoa8EJwGpJh+u28Eg81/4= X-MC-Unique: vtGrVKQUO0Sy8bkKKxuRpA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741288; x=1731346088; 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=OqkXxw1bduZ43gp4lqA3txKBa+8d8snHV/hj05OBUDY=; b=FiwMO6to0Ul98h1HVh3+XemOOysXYLHkCnspGOXl2oSFqyBW+GzVa6fHo2eG4STDBZ xIwAQkfrfrfx7TJBvmWemZx0qohMAKzJ20eglldK7swrDs2CxbdxrCv/Ipbc4nRWOU8n YOHsf+F06lSYX/1nWbee0te8MyFLx49/I8ZewbGjb3mW8Al7BhPh7vqw46baizvGlMNY jtuH7CfYb6QNWoXNb7KL35+rCmsURI4C/+FI+zJurn49Ow/MrSL+X8ZdGCCgRtrBZCMo 7K1xFqnHt+yfO+6dlLiWgOsUGmFqLc22+/HHGcxRS6y3E5kJMIpmPBtb7KMqVAxATAsc QDbQ== X-Gm-Message-State: AOJu0Yxqu2aJKSLAVreaxbNBHMDbN8dwB7/IYzaTkGp2S4A4aYKVRqKx 8ESNIocunwqKfvvTIcfq765onmmbbSHvP5g6YqjmSl5Z6g9ppVTvQ/FIYJHJkfIWNOFgTrBho+w /XZCF8XKWUmpgDq0fgJlWb8UlUdDuCM4UrtlNoexnu8TGwpZKy8eyAUk/Aqz0KrZ2mp6ph4c7zV 3P4aXR8xnj32mbKCqpdTCM1y1EvEaI/sOQ/nlIs5k= X-Received: by 2002:a05:600c:5492:b0:431:251a:9dc9 with SMTP id 5b1f17b1804b1-4328328481dmr115241165e9.25.1730741287598; Mon, 04 Nov 2024 09:28:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF627EkzTNHR41jLSPP1AztaSa8/xZraM0fCiAnCN6KBp6k6u1Cls1P17UZpjh3Edesg+Y2Dg== X-Received: by 2002:a05:600c:5492:b0:431:251a:9dc9 with SMTP id 5b1f17b1804b1-4328328481dmr115240805e9.25.1730741287172; Mon, 04 Nov 2024 09:28:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 20/40] rust/pl011: add support for migration Date: Mon, 4 Nov 2024 18:26:59 +0100 Message-ID: <20241104172721.180255-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741365849116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Declare the vmstate description of the PL011 device. Based on a patch by Manos Pitsidianakis (https://lore.kernel.org/qemu-devel/20241024-rust-round-2-v1-4-051e7a25b978= @linaro.org/). Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-4-051e7a25b978@lin= aro.org --- rust/hw/char/pl011/src/device.rs | 27 ++++++++++ rust/hw/char/pl011/src/device_class.rs | 73 +++++++++++++++++++++++--- rust/hw/char/pl011/src/lib.rs | 1 + 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index b3d8bc004e0..dd9145669dc 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -20,6 +20,12 @@ =20 static PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0,= 0x05, 0xb1]; =20 +/// Integer Baud Rate Divider, `UARTIBRD` +const IBRD_MASK: u32 =3D 0x3f; + +/// Fractional Baud Rate Divider, `UARTFBRD` +const FBRD_MASK: u32 =3D 0xffff; + const DATA_BREAK: u32 =3D 1 << 10; =20 /// QEMU sourced constant. @@ -492,6 +498,27 @@ pub fn update(&self) { unsafe { qemu_set_irq(*irq, i32::from(flags & i !=3D 0)) }; } } + + pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { + /* Sanity-check input state */ + if self.read_pos >=3D self.read_fifo.len() || self.read_count > se= lf.read_fifo.len() { + return Err(()); + } + + if !self.fifo_enabled() && self.read_count > 0 && self.read_pos > = 0 { + // Older versions of PL011 didn't ensure that the single + // character in the FIFO in FIFO-disabled mode is in + // element 0 of the array; convert to follow the current + // code's assumptions. + self.read_fifo[0] =3D self.read_fifo[self.read_pos]; + self.read_pos =3D 0; + } + + self.ibrd &=3D IBRD_MASK; + self.fbrd &=3D FBRD_MASK; + + Ok(()) + } } =20 /// Which bits in the interrupt status matter for each outbound IRQ line ? diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index 9282dc4d151..6a554ad7926 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -2,16 +2,77 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 -use core::ptr::NonNull; +use core::{ + ffi::{c_int, c_void}, + ptr::NonNull, +}; =20 -use qemu_api::{bindings::*, definitions::ObjectImpl, zeroable::Zeroable}; +use qemu_api::{ + bindings::*, vmstate_clock, vmstate_fields, vmstate_int32, vmstate_sub= sections, vmstate_uint32, + vmstate_uint32_array, vmstate_unused, zeroable::Zeroable, +}; =20 -use crate::device::PL011State; +use crate::device::{PL011State, PL011_FIFO_DEPTH}; + +extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { + unsafe { + debug_assert!(!opaque.is_null()); + let state =3D NonNull::new_unchecked(opaque.cast::()); + state.as_ref().migrate_clock + } +} + +/// Migration subsection for [`PL011State`] clock. +pub static VMSTATE_PL011_CLOCK: VMStateDescription =3D VMStateDescription { + name: c"pl011/clock".as_ptr(), + version_id: 1, + minimum_version_id: 1, + needed: Some(pl011_clock_needed), + fields: vmstate_fields! { + vmstate_clock!(clock, PL011State), + }, + ..Zeroable::ZERO +}; + +extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c= _int { + unsafe { + debug_assert!(!opaque.is_null()); + let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); + let result =3D state.as_mut().post_load(version_id as u32); + if result.is_err() { + -1 + } else { + 0 + } + } +} =20 -#[used] pub static VMSTATE_PL011: VMStateDescription =3D VMStateDescription { - name: PL011State::TYPE_INFO.name, - unmigratable: true, + name: c"pl011".as_ptr(), + version_id: 2, + minimum_version_id: 2, + post_load: Some(pl011_post_load), + fields: vmstate_fields! { + vmstate_unused!(core::mem::size_of::()), + vmstate_uint32!(flags, PL011State), + vmstate_uint32!(line_control, PL011State), + vmstate_uint32!(receive_status_error_clear, PL011State), + vmstate_uint32!(control, PL011State), + vmstate_uint32!(dmacr, PL011State), + vmstate_uint32!(int_enabled, PL011State), + vmstate_uint32!(int_level, PL011State), + vmstate_uint32_array!(read_fifo, PL011State, PL011_FIFO_DEPTH), + vmstate_uint32!(ilpr, PL011State), + vmstate_uint32!(ibrd, PL011State), + vmstate_uint32!(fbrd, PL011State), + vmstate_uint32!(ifl, PL011State), + vmstate_int32!(read_pos, PL011State), + vmstate_int32!(read_count, PL011State), + vmstate_int32!(read_trigger, PL011State), + }, + subsections: vmstate_subsections! { + VMSTATE_PL011_CLOCK + }, ..Zeroable::ZERO }; =20 diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 2939ee50c99..73474a07e7c 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -36,6 +36,7 @@ clippy::cognitive_complexity, clippy::missing_safety_doc, )] +#![allow(clippy::result_unit_err)] =20 extern crate bilge; extern crate bilge_impl; --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741674; cv=none; d=zohomail.com; s=zohoarc; b=Ek6I0/figpIQSLf00+RzpnP7sb0+VItCHt6T3FNQVkKEHR+2YNFlNufV27Sm4jJgKm5/E9F5rJ4PfFGqQKwcdA0193WfkCNnfTWg61AqoeGLC9k4F58GFHHMK21KBKQGvwQO1GYIBzDINaWg4uqMrMXrwOH56fw1wZ9ah659ras= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741674; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4mcZD6E6f+0cy1tj4iIQ7hxtvKuCBvQujdLmN6nvks4=; b=SfqblC7UoC0yVVaYAqfYzhUAGgzfEYLJi9f6xZ3nKCkXHDskwegJmv8P8FC02mokk+2mA01hzZI0KPQb7IMakLljNFWa2P8g3Ry9nP9n2Ammjp6ZLGYAeqMhbx4bDTseJC9BGxo9S4g1AH03D54bmpYP9klWTQ05mAORaWfsj+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741674001875.6986053588006; Mon, 4 Nov 2024 09:34:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sG-0005OV-9M; Mon, 04 Nov 2024 12:28:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sD-0005N5-K5 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sA-0000La-TT for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:16 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-fg93quK1NLWEfICovJ4BUQ-1; Mon, 04 Nov 2024 12:28:11 -0500 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-37d4cf04be1so2355515f8f.2 for ; Mon, 04 Nov 2024 09:28:11 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e74casm13686402f8f.65.2024.11.04.09.28.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4mcZD6E6f+0cy1tj4iIQ7hxtvKuCBvQujdLmN6nvks4=; b=QE0uu6zKFdFWWAj/Z5P6PXgNItN0FQrmRZPqVGnZBr4DGDk2p39X1rKZhrml7+g4dxicdr vQrP/000U4LhYy7Nder5Ch2b8OKxmM8kqbbQb5KsjC7IQO6yQ61pbcpqI9BoqdssweoIp/ Qa+Iy1vwT66uHG8eyGC+o1el/3JRhJE= X-MC-Unique: fg93quK1NLWEfICovJ4BUQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741290; x=1731346090; 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=4mcZD6E6f+0cy1tj4iIQ7hxtvKuCBvQujdLmN6nvks4=; b=Au7VcbWwovJycrthgdSfBzNP8ILul6HVv9Fvvv4oKZ5Kg2iaqy1HA/iRyDJbpio4eB Zakp8Bf2Fc4tb687xkJGIOa2P2yQzErWQmQLO/d2A+wAgp9I8eb+WooNGtnsp4KyBg3B r1zSTguUvntimPthtAjKNbdEZ7MX7Zxoc7vOCcdnJvIqWODWuqAWxjTUZiBHgtJ0cl2p ThJojuwfDDwRhxUZX5owVIl7COyy5Jh9FW9hzztj2yeG15kwgV5k3crfJ+f1HK51m/t0 qTx1dJCUzBAaKA8iDksOEZSIjQSyU8d6D9wR3wNIsduWWdeV99+lFcCY4Iwz91e+zKaM BJqg== X-Gm-Message-State: AOJu0Yy5trrd7ZKnLLXNDM0Kusk+ZzCBCEoh86/oO0ABJ5U0fJdr4otV xXgH9du967XHpcLJ6xpyOehbFU+5I6s8MpebmsYMQgc3Kb8nBK9PmVW1SDlXL3zWPiLX1hAWrW/ KTaAD7f04Xq2B1E2U0NRbIOqX2g15VogD+S2c2Z7q1OwD4Jsnv6Q5O+IAf+sro0RZVJ+Xm/Cquu 3X9uZdgAImDSjM25lx+QO0fUOqGvAoWH9pzfMICUs= X-Received: by 2002:a05:6000:1541:b0:37d:4e9d:34d1 with SMTP id ffacd0b85a97d-381bea1bbaamr12916852f8f.37.1730741289784; Mon, 04 Nov 2024 09:28:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGejlL5lNi07Qp5ReauSa/W4LCvFqWXjZ4hzhSldNaliNL22gpp1OU8mblMpOJvft7Q+Iu19Q== X-Received: by 2002:a05:6000:1541:b0:37d:4e9d:34d1 with SMTP id ffacd0b85a97d-381bea1bbaamr12916816f8f.37.1730741289272; Mon, 04 Nov 2024 09:28:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 21/40] rust/pl011: move CLK_NAME static to function scope Date: Mon, 4 Nov 2024 18:27:00 +0100 Message-ID: <20241104172721.180255-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741675020116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis We do not need to have CLK_NAME public nor a static. No functional change. Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-5-051e7a25b978@lin= aro.org --- rust/hw/char/pl011/src/device.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index dd9145669dc..f91790ff185 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -102,9 +102,6 @@ impl qemu_api::definitions::Class for PL011Class { > =3D None; } =20 -#[used] -pub static CLK_NAME: &CStr =3D c"clk"; - impl PL011State { /// Initializes a pre-allocated, unitialized instance of `PL011State`. /// @@ -114,7 +111,9 @@ impl PL011State { /// `PL011State` type. It must not be called more than once on the same /// location/instance. All its fields are expected to hold unitialized /// values with the sole exception of `parent_obj`. - pub unsafe fn init(&mut self) { + unsafe fn init(&mut self) { + const CLK_NAME: &CStr =3D c"clk"; + let dev =3D addr_of_mut!(*self).cast::(); // SAFETY: // --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741393; cv=none; d=zohomail.com; s=zohoarc; b=O39NH/ko6KOnM8L578jpn9NxHbUVLQxlZRAAorq/Rs1e/dzSwSI5x3hb/O51DdP0rFhC3MaiiLyaqVSZHF2EX/mdVAQCBcV+V8wiRt7LaZHcaqbecv+GvkKnNP55MPLRUFfzxiTJsBpmL1sGPbpOUuZRcp+04zoViAeq566P5t8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741393; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eshy0bLvRcQ1KvRtKV33AyzKUgcVVdJsaiv+wKMFE00=; b=UW5rfkCAGnIQ0JNwvEmkWZKB5Kr/l0i1stpa0utw2B0FhlTzNKNiatEAclR5tklkNdmueyQpceruNeD5XJcMt5z6dR5khtNq0VDHcBsgUHCJJzsdpjGSS8npMnr1CWrT64j3p+BtEH1H0b9SM2sjH146zKvV1eAqIRZwot8y+ds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741393861746.8686652703202; Mon, 4 Nov 2024 09:29:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sF-0005OU-RC; Mon, 04 Nov 2024 12:28:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sD-0005Nb-Om for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sB-0000Lp-PZ for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:17 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-qVeMWcAmMoiNXDX1mtf8qw-1; Mon, 04 Nov 2024 12:28:14 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso25372475e9.0 for ; Mon, 04 Nov 2024 09:28:13 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5e7c51sm158346805e9.25.2024.11.04.09.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eshy0bLvRcQ1KvRtKV33AyzKUgcVVdJsaiv+wKMFE00=; b=gE3W7j1zmVX5DYJcm7vevePybeeMAqGD3IVd9VEYgx91fjH1svY6mTVbo9BRWWkmHc3Qlm Y86+SROBAx/yRXEuYsGKwoTfLa0EmFeKrRFd8cShNwaiSyzL5w7z7Bkjtzr16H44bEEsdd 8zG8RZLn/3GANvfYJ0/BNFk6Zx8/Et8= X-MC-Unique: qVeMWcAmMoiNXDX1mtf8qw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741292; x=1731346092; 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=eshy0bLvRcQ1KvRtKV33AyzKUgcVVdJsaiv+wKMFE00=; b=kBTRCbqGzvEVvQcnCJUVXgY5CAyOEA26xerm+LphDFvHycjzDRL1IrhH+tpCisBSxO Js2+ayQV//2VM+kNapaC3IiUj7+myQbHCO+SXJL4zKAEAL4ztb+Wsqa8Jo+2OX22zGr1 72gJiiQrkdC+B8tbVNR8t5kyLJZHlkZOZIXghU9t6Pz4va+NroZ7Msqhv7xrtIBXTCCv pqYmOk8oUEXjny5R06CChA7j0sSBI0EnzUyyI25zNAiZjxIQBI4ySf6i0FOqVFpO7bPM I9GXt9ylXB1jdOkYCbzWHGVoBYaE1BrsYxGy+CVOtV4oFegF9XTUa5+egZMYdkYuqkh1 ysEA== X-Gm-Message-State: AOJu0YwuUBw+sq3MMVIV1u52D0405HTR8hhoBTz1Rnvv5IdoqKhnUufa zAsR+X+/h7Pv0VTQZDb6fSrq28gCXv0ULCENNSP8MD4XJf0gzDKT5xyOpaJUkFRG0a6s1MOoW5U I5xW7JgqFJK2c3IGYk2OoB41u3fDWPEwGi2KtR5eEGmxIfUS9PQrHdY6Owt3I79G2K43IAuORlY F7DsdhAgQRHPvup2iOZvEUSEP6SZSHPQhiWFo2DEI= X-Received: by 2002:a05:600c:35c5:b0:431:9340:77e0 with SMTP id 5b1f17b1804b1-4327dab3f6cmr135328865e9.9.1730741291970; Mon, 04 Nov 2024 09:28:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXqUQwrfnl5jp6cwl5MdfqD1MjtfQacpApsIjZ8qKFN9r6cHcXj03LTq9Q19rl4wD3srIODQ== X-Received: by 2002:a05:600c:35c5:b0:431:9340:77e0 with SMTP id 5b1f17b1804b1-4327dab3f6cmr135328485e9.9.1730741291408; Mon, 04 Nov 2024 09:28:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 22/40] rust/pl011: add TYPE_PL011_LUMINARY device Date: Mon, 4 Nov 2024 18:27:01 +0100 Message-ID: <20241104172721.180255-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741395949116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Add a device specialization for the Luminary UART device. This commit adds a DeviceId enum that utilizes the Index trait to return different bytes depending on what device id the UART has (Arm -default- or Luminary) Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Tested-by: Zhao Liu Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-6-051e7a25b978@lin= aro.org --- rust/hw/char/pl011/src/device.rs | 77 ++++++++++++++++++++++++++++++-- rust/hw/char/pl011/src/lib.rs | 1 + 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index f91790ff185..051c59f39ae 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -18,8 +18,6 @@ RegisterOffset, }; =20 -static PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0,= 0x05, 0xb1]; - /// Integer Baud Rate Divider, `UARTIBRD` const IBRD_MASK: u32 =3D 0x3f; =20 @@ -31,6 +29,29 @@ /// QEMU sourced constant. pub const PL011_FIFO_DEPTH: usize =3D 16_usize; =20 +#[derive(Clone, Copy, Debug)] +enum DeviceId { + #[allow(dead_code)] + Arm =3D 0, + Luminary, +} + +impl std::ops::Index for DeviceId { + type Output =3D c_uchar; + + fn index(&self, idx: hwaddr) -> &Self::Output { + match self { + Self::Arm =3D> &Self::PL011_ID_ARM[idx as usize], + Self::Luminary =3D> &Self::PL011_ID_LUMINARY[idx as usize], + } + } +} + +impl DeviceId { + const PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0x= f0, 0x05, 0xb1]; + const PL011_ID_LUMINARY: [c_uchar; 8] =3D [0x11, 0x00, 0x18, 0x01, 0x0= d, 0xf0, 0x05, 0xb1]; +} + #[repr(C)] #[derive(Debug, qemu_api_macros::Object)] /// PL011 Device Model in QEMU @@ -75,6 +96,8 @@ pub struct PL011State { pub clock: NonNull, #[doc(alias =3D "migrate_clk")] pub migrate_clock: bool, + /// The byte string that identifies the device. + device_id: DeviceId, } =20 impl ObjectImpl for PL011State { @@ -162,7 +185,7 @@ pub fn read( =20 std::ops::ControlFlow::Break(match RegisterOffset::try_from(offset= ) { Err(v) if (0x3f8..0x400).contains(&v) =3D> { - u64::from(PL011_ID_ARM[((offset - 0xfe0) >> 2) as usize]) + u64::from(self.device_id[(offset - 0xfe0) >> 2]) } Err(_) =3D> { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset = 0x%x\n", (int)offset); @@ -619,3 +642,51 @@ pub fn post_load(&mut self, _version_id: u32) -> Resul= t<(), ()> { state.as_mut().init(); } } + +#[repr(C)] +#[derive(Debug, qemu_api_macros::Object)] +/// PL011 Luminary device model. +pub struct PL011Luminary { + parent_obj: PL011State, +} + +#[repr(C)] +pub struct PL011LuminaryClass { + _inner: [u8; 0], +} + +/// Initializes a pre-allocated, unitialized instance of `PL011Luminary`. +/// +/// # Safety +/// +/// We expect the FFI user of this function to pass a valid pointer, that = has +/// the same size as [`PL011Luminary`]. We also expect the device is +/// readable/writeable from one thread at any time. +pub unsafe extern "C" fn pl011_luminary_init(obj: *mut Object) { + unsafe { + debug_assert!(!obj.is_null()); + let mut state =3D NonNull::new_unchecked(obj.cast::= ()); + let state =3D state.as_mut(); + state.parent_obj.device_id =3D DeviceId::Luminary; + } +} + +impl qemu_api::definitions::Class for PL011LuminaryClass { + const CLASS_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), + > =3D None; + const CLASS_BASE_INIT: Option< + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), + > =3D None; +} + +impl ObjectImpl for PL011Luminary { + type Class =3D PL011LuminaryClass; + const TYPE_INFO: qemu_api::bindings::TypeInfo =3D qemu_api::type_info!= { Self }; + const TYPE_NAME: &'static CStr =3D crate::TYPE_PL011_LUMINARY; + const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(crate::TYPE_PL0= 11); + const ABSTRACT: bool =3D false; + const INSTANCE_INIT: Option = =3D Some(pl011_luminary_init); + const INSTANCE_POST_INIT: Option =3D None; + const INSTANCE_FINALIZE: Option =3D None; +} diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 73474a07e7c..fb33110d3d8 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -47,6 +47,7 @@ pub mod memory_ops; =20 pub const TYPE_PL011: &::core::ffi::CStr =3D c"pl011"; +pub const TYPE_PL011_LUMINARY: &::core::ffi::CStr =3D c"pl011_luminary"; =20 /// Offset of each register from the base memory address of the device. /// --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741677; cv=none; d=zohomail.com; s=zohoarc; b=XvJPlGIgKg0x+cFAutIhOZoV04yVRQozNhsDuly1CgTHog9+zZi50jVqGhHZdwfRD+87n9iZC4jmUOu+uCFD0ukjxW8ZRdIm2FsiJfQ8hY3LxSSP4BrpPKf28f03hB5Ae0MLXtKsfbP8RlyinYBfFlMoAPzq2iWCLveAdBjVrTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741677; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CxXq4sNnvBqcxAcyP5/LFmCvhOPA1QvyNHAcrsKDVpE=; b=XjOK9f+53WVJcwJy8/qxFKSswlwbyhkvmv4hgq2BpzBZlqvvDvK+RRc52QSMcdv7iyHJ+XOxzPgxsQ3eVFHs2bjw1tuSMq3Bel4hYXn1X8niisxYJwa2XIOB41IpRRnTfcZtqBnklDNSLkbfhUj7o6dwsdHTXDbmzP31/1C56dY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741677494169.9206405600213; Mon, 4 Nov 2024 09:34:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sM-0005Tj-55; Mon, 04 Nov 2024 12:28:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sJ-0005Qy-8w for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sD-0000M5-QU for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:22 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-6CI_PGD3NmWFV-kTnGmGlg-1; Mon, 04 Nov 2024 12:28:16 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4314f1e0f2bso29049145e9.1 for ; Mon, 04 Nov 2024 09:28:15 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd91096asm194447775e9.13.2024.11.04.09.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CxXq4sNnvBqcxAcyP5/LFmCvhOPA1QvyNHAcrsKDVpE=; b=LJlMWePJGepDKB82KZ+NHSLOkMTOZuM1tGPneFDuhcZ8nrIJloMC409DtUUBWEFK5HxfdH LUYxi6pftyiJPUJcog+77Kw3VSLi9fo1AYiQiQlTNGxxO9znXcQjnwYrq0v+/IoxXBl2cB ZCQzp+dRvYawQA9vtyPHO2UIVoIcuFk= X-MC-Unique: 6CI_PGD3NmWFV-kTnGmGlg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741294; x=1731346094; 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=CxXq4sNnvBqcxAcyP5/LFmCvhOPA1QvyNHAcrsKDVpE=; b=R9NtEwURyAtDTzwGqvWjHGxDSC5rCJWCzaJMBC+OqRmAQHwQgjXwT2EviNH2MniWCV tZ8+hbZ53VaUzm0Rk54GQXyCm6NTZLVD5vwqv9D31dusoVE+XkWhFcrWbS7wD4ki3fgg yZV2YpmvH7Cb1PCkoFiPi1V3w97xtGG2tAOUkG+irp6pRVvGtt9ngjKtRoXIkmVcj/Jg KnBaYs+ys1z174LkRFT5Zoyb/JWj6wyoFbpfQ/hdJSRJRDyg50+cIAEHHbhflfvAdfx+ PD0xnBfgWa/PQuUxQVnbnUCrbBoXLjztIFQAGQvCQYc9vAo0ZmGyW1AtmdN54GPAT9yJ 1FEg== X-Gm-Message-State: AOJu0YziHFWCXmm8HTXzlawmgV6V4als4sfIPWaWr3PRGzbPnsHn0ZsH cbNwO7JdI3HoTauMTkH1QnkCBBHcUqKXrGiUu831jGfmySRxyeX0Lfzc6mfUeHzv10l5J9UYoah u1sDpsNNzpG2m1BPqrY39oSr9kAAGpqmzeYWXKvOUt4mB/8ibeYbR8DUVvCNt+qcliQoUmsOlLY CHsVQaNJoJOZEQMtAVxlN7TRyZl4kiojYFWnT9h8k= X-Received: by 2002:a05:600c:1d27:b0:431:52a3:d9ea with SMTP id 5b1f17b1804b1-432831c1ff1mr118529595e9.0.1730741294030; Mon, 04 Nov 2024 09:28:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMILYGsmvvv+3hE9LiKBc+hzuPrz4wymD4pf61/j3m7fhpdMHMI21QLlirS5Sxm9CcMOSvow== X-Received: by 2002:a05:600c:1d27:b0:431:52a3:d9ea with SMTP id 5b1f17b1804b1-432831c1ff1mr118529225e9.0.1730741293606; Mon, 04 Nov 2024 09:28:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 23/40] rust/pl011: remove commented out C code Date: Mon, 4 Nov 2024 18:27:02 +0100 Message-ID: <20241104172721.180255-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741679035116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis This code juxtaposed what should be happening according to the C device model but is not needed now that this has been reviewed (I hope) and its validity checked against what the C device does (I hope, again). No functional change. Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-8-051e7a25b978@lin= aro.org --- rust/hw/char/pl011/src/device.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 051c59f39ae..98357db04e8 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -192,7 +192,6 @@ pub fn read( 0 } Ok(DR) =3D> { - // s->flags &=3D ~PL011_FLAG_RXFF; self.flags.set_receive_fifo_full(false); let c =3D self.read_fifo[self.read_pos]; if self.read_count > 0 { @@ -200,11 +199,9 @@ pub fn read( self.read_pos =3D (self.read_pos + 1) & (self.fifo_dep= th() - 1); } if self.read_count =3D=3D 0 { - // self.flags |=3D PL011_FLAG_RXFE; self.flags.set_receive_fifo_empty(true); } if self.read_count + 1 =3D=3D self.read_trigger { - //self.int_level &=3D ~ INT_RX; self.int_level &=3D !registers::INT_RX; } // Update error bits. @@ -374,13 +371,6 @@ fn loopback_mdmctrl(&mut self) { * dealt with here. */ =20 - //fr =3D s->flags & ~(PL011_FLAG_RI | PL011_FLAG_DCD | - // PL011_FLAG_DSR | PL011_FLAG_CTS); - //fr |=3D (cr & CR_OUT2) ? PL011_FLAG_RI : 0; - //fr |=3D (cr & CR_OUT1) ? PL011_FLAG_DCD : 0; - //fr |=3D (cr & CR_RTS) ? PL011_FLAG_CTS : 0; - //fr |=3D (cr & CR_DTR) ? PL011_FLAG_DSR : 0; - // self.flags.set_ring_indicator(self.control.out_2()); self.flags.set_data_carrier_detect(self.control.out_1()); self.flags.set_clear_to_send(self.control.request_to_send()); @@ -391,10 +381,6 @@ fn loopback_mdmctrl(&mut self) { let mut il =3D self.int_level; =20 il &=3D !Interrupt::MS; - //il |=3D (fr & PL011_FLAG_DSR) ? INT_DSR : 0; - //il |=3D (fr & PL011_FLAG_DCD) ? INT_DCD : 0; - //il |=3D (fr & PL011_FLAG_CTS) ? INT_CTS : 0; - //il |=3D (fr & PL011_FLAG_RI) ? INT_RI : 0; =20 if self.flags.data_set_ready() { il |=3D Interrupt::DSR as u32; @@ -500,10 +486,8 @@ pub fn put_fifo(&mut self, value: c_uint) { let slot =3D (self.read_pos + self.read_count) & (depth - 1); self.read_fifo[slot] =3D value; self.read_count +=3D 1; - // s->flags &=3D ~PL011_FLAG_RXFE; self.flags.set_receive_fifo_empty(false); if self.read_count =3D=3D depth { - //s->flags |=3D PL011_FLAG_RXFF; self.flags.set_receive_fifo_full(true); } =20 --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741771; cv=none; d=zohomail.com; s=zohoarc; b=JaIDRtBSAAZ4wyUcd3DuUIfwBxKrfKRhH07THQo8G4ZCBFcvlw9I7fXeledEGEgKxYSE8/+czuYDRFeMu02+4PpCKUr66d+d8JiGa3uXZaQVtj1TApYqqGyejEw286kVafvxpylMw2+1nrtvQEOjDULxBvDoeYEwmXQjo83ZlvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741771; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rJilloWL9v8Cwa9SjhS4DIAn5GcNqvslur8KE0ijG6o=; b=C1hM55EQd6Di/smAoRAFZYZefmNUwC7QQ9e3qAtoNuyXHcKMrM9ThnFp7q7UDo0pQT7FpqUcMSJvwslxnT43Hb/qqt0GS1UPeGIqVXdYeav79AQl9N201aJvOhR/SojeC40vfHqOk75+Lx2s6z8mmaLFmaAPvUBUGmcEYYb44S0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741771164441.38997237304693; Mon, 4 Nov 2024 09:36:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sO-0005UC-GM; Mon, 04 Nov 2024 12:28:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sL-0005S9-9o for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sH-0000Mq-Ao for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:24 -0500 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-0j2yRt_-OgCveL_uA15gkQ-1; Mon, 04 Nov 2024 12:28:19 -0500 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539eb3416cdso4699051e87.1 for ; Mon, 04 Nov 2024 09:28:18 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d698055sm160636155e9.40.2024.11.04.09.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rJilloWL9v8Cwa9SjhS4DIAn5GcNqvslur8KE0ijG6o=; b=X4xrpexINvbFFDL0da4aJr9LvX22u3f+YRIfoDPfMDs7LA8A9x/Z3hyr+ko3DigPh2Yebk /NNRI2U+sYtWaiVWQcNcEMyaRyhydFC93fhLd3+v6arpJRjo7Ejz1Wycnf7OjF7rLwQ3te 2uQeFPdp9BfgBCCswIZvhoHInaXK508= X-MC-Unique: 0j2yRt_-OgCveL_uA15gkQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741296; x=1731346096; 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=rJilloWL9v8Cwa9SjhS4DIAn5GcNqvslur8KE0ijG6o=; b=EkGAH5XITy13LYgqf0nNcwYG+/i2SS0volPvcNG8bxZhbbxIDDPbcrbZDnHUQzfFVw tAJQR0a6awqHAtt1C9t56yGh85QkkXH40WLRddsWQrDLhSXIb2/4FmIRnW9tOlktf9ya SqDuY+EIRT/nQ0+A8ffMu0mXaafjiWYAkhmlIKd1/sN/QVhtjNAcfRAZ6SfLgWwmzSZo FBqmRbibNPcK5WVosr9myyvFT4dLau2WXLgv3m8jffXD/4bDa+d70q+HWs+btOlv5/jB ng/KSQ98V3xMekC7r4eJBFLyGyBT+IH2pEtdzHPr8fdTrKW/u6EIU0kzbkNLZLJx0y4F uwcA== X-Gm-Message-State: AOJu0YyvKIljqv2HH4WBzQJv2b1S52W+iODbcWaEVBp9loX/X25J+kn6 6Ir49rmKF/31I8lGA1UfVFjYQzW6y+aFJWFOfowUL+hAoxx+4Oy2Gpc9/BCZsgXXRf4xgNc9PFj C50ubNBm183/uQBCXumA1B9fBsH1KUZPYRd1n/tR5+LLoA7yEKDhsHhiuhiycWU7NaJlTdWztJi ldzFFas0EIiGnLJFw1yY7fvhj311EmrUOWVTrG9dk= X-Received: by 2002:a05:6512:6ca:b0:539:e88f:2398 with SMTP id 2adb3069b0e04-53b34a19082mr15881384e87.39.1730741296178; Mon, 04 Nov 2024 09:28:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5/G5lHJETWS/M2/T7irkPpf7iLkrl4EKM+E9y/4r8NpxspclCOoSsZkRoSxKxTKO27xMHtg== X-Received: by 2002:a05:6512:6ca:b0:539:e88f:2398 with SMTP id 2adb3069b0e04-53b34a19082mr15881347e87.39.1730741295631; Mon, 04 Nov 2024 09:28:15 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 24/40] rust/pl011: Use correct masks for IBRD and FBRD Date: Mon, 4 Nov 2024 18:27:03 +0100 Message-ID: <20241104172721.180255-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741771459116600 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Port fix from commit cd247eae16ab1b9ce97fd34c000c1b883feeda45 "hw/char/pl011: Use correct masks for IBRD and FBRD" Related issue: Signed-off-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241024-rust-round-2-v1-9-051e7a25b978@lin= aro.org --- rust/hw/char/pl011/src/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 98357db04e8..788b47203b1 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -19,10 +19,10 @@ }; =20 /// Integer Baud Rate Divider, `UARTIBRD` -const IBRD_MASK: u32 =3D 0x3f; +const IBRD_MASK: u32 =3D 0xffff; =20 /// Fractional Baud Rate Divider, `UARTFBRD` -const FBRD_MASK: u32 =3D 0xffff; +const FBRD_MASK: u32 =3D 0x3f; =20 const DATA_BREAK: u32 =3D 1 << 10; =20 --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741511; cv=none; d=zohomail.com; s=zohoarc; b=NKpslNAWtOOW7h4+7D3T9DYtJGqm0ddw8tyCNjCYFU5bqwfwuUgMNTUQ8DT5k7Sc1ekL194QJWnNb4fegsY7HqzrS8xkkZF6c78eaNUiSUAYlV2UIxjLg8fU3e8eT/kntzXu+YQsooaAdHh5q5tlFGnOnB4pC/sir4Uto1UO354= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741511; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3UmgO9fsqdEmWzMoi61XEIn14aScetkmk6rxlD4mFVQ=; b=VxIfrSXzwJiSMS8ocBZssRcOCbmGKXvMoRWxxEiA640nM7qMgVIDeumkKmb4Ud/2JicQU/I/H1Rj8OqxjZkAWLpVNECAszA8LiU8dSIcM2if0yVmyGyafttfApITkjIiZrVJxNkGdVU9pIBMYcqfGfTn7PpmGJD6tlu+uXKkPs8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741511233729.4913115632372; Mon, 4 Nov 2024 09:31:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sP-0005UY-6J; Mon, 04 Nov 2024 12:28:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sL-0005SB-AC for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sJ-0000Mx-78 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:24 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-8pGi4Gn3MGi8B1cLc40y4Q-1; Mon, 04 Nov 2024 12:28:19 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-381d07c377cso1637134f8f.1 for ; Mon, 04 Nov 2024 09:28:19 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10b7c08sm13779745f8f.17.2024.11.04.09.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UmgO9fsqdEmWzMoi61XEIn14aScetkmk6rxlD4mFVQ=; b=dLI8b/AQ/hWMRD4qUtTfY00KD+h56omXSk8ktPAKVNudqhwOC+f+5XTwTsSs8L8YpSi7Xm GCyzFUN5JWFtCdhZQWMzOCvXZmBtcfMcDvvn7b+H/kEGTrqdci/AFXKDP73SMjnDXShPUD WWLzA38DmxIqqjkyMoPHHpWhUN1+VkE= X-MC-Unique: 8pGi4Gn3MGi8B1cLc40y4Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741297; x=1731346097; 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=3UmgO9fsqdEmWzMoi61XEIn14aScetkmk6rxlD4mFVQ=; b=t5a3cvXqvuzKDAVsSjcRQMq+ySQwbSnUn1WfFMFok+3G6WDFlcCTr9HacbPRn/DDH7 CT82JY40BvRvTvmlHxJ5CmR9OWlTgUw6+HkgBD9Nmic/8riaod3a/K+S0RX9CuCVxUlc mNjaHckOJeuGWYBDHbZnk0vKfk37un8D295fOXZnuF/HGHl20L+aFVVaurEkkhpoTAGR t5dhH+F7vXO9q4pb8b+rf6OLB7Q8llpyd6mObRKjDcqyjdFUiRyY6FGRE0okfBvIXkRY 8jczNBFj42C3A1u25l1HBe55TB0qWzDCRC+amM0Hw+ug07qbK1Qgev1ibpbdKT1KqYh8 qT8g== X-Gm-Message-State: AOJu0YwAg+4LbxSUVrRgZhYXkxba/A5wA/eAoO99R7Juw64NjNvBhlZ7 kcfdB4thjm7oFplygMARvFPEwY2ajFkY+ndknAt02BKrPiwcftFIoQggSfaATysmH7pN5PZ/xrX GfYW9yTNthpiAQUEnrpGN5nWHpNqThxT5ivHafFTHBwTNj+oD3waLRLSJ63OO1o4Yfp2+FgfTgE vhow3ogKcCFhBZ/6tZFR7aAqwf9+hDy3AIfRbNmZY= X-Received: by 2002:a5d:47ac:0:b0:37d:48f2:e749 with SMTP id ffacd0b85a97d-381c7a4636cmr13690109f8f.10.1730741297402; Mon, 04 Nov 2024 09:28:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpMPJYcg9oY5gWVVg3kGldS68WlxPrUKLExniUyJ3JWSOfRtU6X6FWHRWIW7Ku9YYH8bymVQ== X-Received: by 2002:a5d:47ac:0:b0:37d:48f2:e749 with SMTP id ffacd0b85a97d-381c7a4636cmr13690078f8f.10.1730741296938; Mon, 04 Nov 2024 09:28:16 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 25/40] rust: patch bilge-impl to allow compilation with 1.63.0 Date: Mon, 4 Nov 2024 18:27:04 +0100 Message-ID: <20241104172721.180255-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741512139116600 Content-Type: text/plain; charset="utf-8" Apply a patch that removes "let ... else" constructs, replacing them with "if let ... else" or "let ... =3D match ...". "let ... else" was stabilize= d in Rust 1.65.0. Reviewed-by: Junjie Mao Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- .gitattributes | 2 + subprojects/bilge-impl-0.2-rs.wrap | 1 + .../packagefiles/bilge-impl-1.63.0.patch | 45 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 subprojects/packagefiles/bilge-impl-1.63.0.patch diff --git a/.gitattributes b/.gitattributes index 6dc6383d3d1..9ce7a19581a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,3 +5,5 @@ *.rs diff=3Drust *.rs.inc diff=3Drust Cargo.lock diff=3Dtoml merge=3Dbinary + +*.patch -text -whitespace diff --git a/subprojects/bilge-impl-0.2-rs.wrap b/subprojects/bilge-impl-0.= 2-rs.wrap index eefb10c36c2..b24c34a9043 100644 --- a/subprojects/bilge-impl-0.2-rs.wrap +++ b/subprojects/bilge-impl-0.2-rs.wrap @@ -5,3 +5,4 @@ source_filename =3D bilge-impl-0.2.0.tar.gz source_hash =3D feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000= adb2d8 #method =3D cargo patch_directory =3D bilge-impl-0.2-rs +diff_files =3D bilge-impl-1.63.0.patch diff --git a/subprojects/packagefiles/bilge-impl-1.63.0.patch b/subprojects= /packagefiles/bilge-impl-1.63.0.patch new file mode 100644 index 00000000000..987428a6d65 --- /dev/null +++ b/subprojects/packagefiles/bilge-impl-1.63.0.patch @@ -0,0 +1,45 @@ +--- a/src/shared/discriminant_assigner.rs ++++ b/src/shared/discriminant_assigner.rs +@@ -26,20 +26,20 @@ + let discriminant_expr =3D &discriminant.1; + let variant_name =3D &variant.ident; +=20 +- let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) =3D discriminan= t_expr else { ++ if let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) =3D discrimi= nant_expr { ++ let discriminant_value: u128 =3D int.base10_parse().unwrap_or= _else(unreachable); ++ if discriminant_value > self.max_value() { ++ abort!(variant, "Value of variant exceeds the given numbe= r of bits") ++ } ++ ++ Some(discriminant_value) ++ } else { + abort!( + discriminant_expr, + "variant `{}` is not a number", variant_name; + help =3D "only literal integers currently supported" + ) +- }; +- +- let discriminant_value: u128 =3D int.base10_parse().unwrap_or_els= e(unreachable); +- if discriminant_value > self.max_value() { +- abort!(variant, "Value of variant exceeds the given number of= bits") + } +- +- Some(discriminant_value) + } +=20 + fn assign(&mut self, variant: &Variant) -> u128 { +--- a/src/shared/fallback.rs ++++ b/src/shared/fallback.rs +@@ -22,8 +22,9 @@ + } + Unnamed(fields) =3D> { + let variant_fields =3D fields.unnamed.iter(); +- let Ok(fallback_value) =3D variant_fields.exactly_one() e= lse { +- abort!(variant, "fallback variant must have exactly o= ne field"; help =3D "use only one field or change to a unit variant") ++ let fallback_value =3D match variant_fields.exactly_one()= { ++ Ok(ok) =3D> ok, ++ _ =3D> abort!(variant, "fallback variant must have ex= actly one field"; help =3D "use only one field or change to a unit variant") + }; +=20 + if !is_last_variant { --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741542; cv=none; d=zohomail.com; s=zohoarc; b=k1gY4tXT7TgpORkLdsbtWV6zg2yv174XBM/U74K0WuQIw8xM1oFOnbWkJFJGm00J4u7Dqwc9TalEuqLHsQbfnJtxkLE2V0nDlR/jLT4LQi8ePL7w4kwgdhlaT6vJasy99CtXlazUweflv5JC7v5yqn8DeXAY71TP61xyL5l12SM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741542; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XKH82Qv7Oy514F5AxGk5rkT73airVJkv+YqHS8mBhzc=; b=fBDYHcMp4VcmF/H7lt2OOaOp/0BM9Qug1aRKOLd4jrXvEqsxlXrUZJBLCTUlHmQPzV0pmFX771f/umRR7EFHNZYGVP6Fn3aJDYPVkNzaK/nWNIRCHS3Rerq1+c2uM5QgY/GGyLk3ofCPzxZ9L9vpHG5SYwKHwWO7S5XMmp8rGGQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741542473635.6391886342575; Mon, 4 Nov 2024 09:32:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sV-00065v-8v; Mon, 04 Nov 2024 12:28:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sS-0005tU-Rh for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sO-0000O7-7A for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:32 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-vb3FHSVmM5q89lGvqFXEaA-1; Mon, 04 Nov 2024 12:28:22 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315eaa3189so38366125e9.1 for ; Mon, 04 Nov 2024 09:28:21 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983ddsm162048755e9.44.2024.11.04.09.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XKH82Qv7Oy514F5AxGk5rkT73airVJkv+YqHS8mBhzc=; b=OzaDCKdUGYRc9G51U+qcq93ITvfRDEbXFHbIp83qXYXdWlQ3s84C56g3VNTFLUxk7EscLA JIAt5nUL88ZZbEVg/0CSzTBE9YSIuCSrQALZQ+tJPLJlhBhDJ5QmXZz7ecs7dRP1vOI1pD zwFxBWwtGHm6TUPOO8tyFcPACTPbMmo= X-MC-Unique: vb3FHSVmM5q89lGvqFXEaA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741300; x=1731346100; 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=XKH82Qv7Oy514F5AxGk5rkT73airVJkv+YqHS8mBhzc=; b=ISvmqN3hQ5+NUHVh5zMyJbNK+LCDqwvgXcuSQRybGS1yAnloRs3y1fzFxLhHDWGQtO 20LXHOGPVBGeu3IT//XSGuVicLL8Zau072WzpFjdq2hqWIShJmW7eUjy4EtojSwxbl40 78XJg86MnUTN7rRAGUg6qVlc32Z83et0BthHFQrqaF5TuVdaV/G/3eSlEQWxKZMCBOVC cYY+qL/On667XFm5sRBpGbbwAfLjkrHITvZbUC1ftrvfRiKM8s61k8AVuuqn7/vo4xyR QEauDrLSpJrR2SOW/CJ0WUdzKGnl0NgN/+cU1voJQe1Iq9NTbYp5R15ep/8aenJy8aFc i9YQ== X-Gm-Message-State: AOJu0YxF6bTkAR/hNG7oS2HHvyl7W3/TqT8y5rM1vuDRobObJafvWf6a sS5Fb5gSONB3RRDS3eJmm0dbbuy4IHTibGKaA6Ukr1Vg7h7onve1A8lzjAy8Foflk5Z4ZIcHRyo i00iIrKu4YQ3RPW+MopF6x6D1L6KbJQpGhasWmO85+/yjTxjh/lq5TTxmpBuk0BWUZxW6MMxo8/ UUj6wDafRIGR9T/4MWZJBX8W0zFTtX1DshoALvRI0= X-Received: by 2002:a05:600c:4f8a:b0:42c:ba83:3f00 with SMTP id 5b1f17b1804b1-43283242bbamr141805085e9.1.1730741299982; Mon, 04 Nov 2024 09:28:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5aHIxoHJ7zck4IgvTDUbw7/dLCy8G5i0lBS4Fj7R6SagkTPs/9YNojWhckxu034F6CNQECw== X-Received: by 2002:a05:600c:4f8a:b0:42c:ba83:3f00 with SMTP id 5b1f17b1804b1-43283242bbamr141804785e9.1.1730741299563; Mon, 04 Nov 2024 09:28:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 26/40] rust: fix cfgs of proc-macro2 for 1.63.0 Date: Mon, 4 Nov 2024 18:27:05 +0100 Message-ID: <20241104172721.180255-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741544291116600 Content-Type: text/plain; charset="utf-8" Replay the configuration that would be computed by build.rs when compiling on a 1.63.0 compiler. Reviewed-by: Junjie Mao Signed-off-by: Paolo Bonzini --- subprojects/packagefiles/proc-macro2-1-rs/meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subprojects/packagefiles/proc-macro2-1-rs/meson.build b/subpro= jects/packagefiles/proc-macro2-1-rs/meson.build index 818ec59336b..8e601b50ccc 100644 --- a/subprojects/packagefiles/proc-macro2-1-rs/meson.build +++ b/subprojects/packagefiles/proc-macro2-1-rs/meson.build @@ -15,7 +15,9 @@ _proc_macro2_rs =3D static_library( rust_abi: 'rust', rust_args: [ '--cfg', 'feature=3D"proc-macro"', - '--cfg', 'span_locations', + '--cfg', 'no_literal_byte_character', + '--cfg', 'no_literal_c_string', + '--cfg', 'no_source_text', '--cfg', 'wrap_proc_macro', ], dependencies: [ --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741537; cv=none; d=zohomail.com; s=zohoarc; b=SKpXlTBxQlVJzhUo2Zeddr1RbME8FBaNHjXf6JyUok8PCk4KcYr93mxjP8JAqUtztHGWii+8EbXXsMchAUlY/kztMb/KgGHgyWsT/l50QhoEHztk6nyk5G4O4fMxsq/5zeZ410dHp0a/C5gzzUrEXDHQiKjv9gloLtMRbOBRThY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741537; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oeACifbCFLCHko0mFSBbcv0dEN3Keg1lZLZXzqzwC4Y=; b=GYvB7UaduZUgisR5BsSaMUY3p4o9c+gveQHmgVoGssIJDeLzFUkB7LAIbeWqCwt8y0IQatK2Z4fKlGl5ysKNbMOPi4pwgPiDaZw53v3IxiS25tivJNH1imREC34WB09IP0YnZRyWknuzyvnmWVla2PD1N317w6B3LlD4z3r4p98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741537172723.800861112066; Mon, 4 Nov 2024 09:32:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sU-000633-Bt; Mon, 04 Nov 2024 12:28:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sS-0005ru-Bi for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sN-0000Nx-4h for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:31 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-eg-Pve9dPA28lkgodWEgKQ-1; Mon, 04 Nov 2024 12:28:24 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-431518e6d8fso29102445e9.0 for ; Mon, 04 Nov 2024 09:28:24 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d698144sm164522305e9.39.2024.11.04.09.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741305; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oeACifbCFLCHko0mFSBbcv0dEN3Keg1lZLZXzqzwC4Y=; b=ADrErDDNyJrPdvO0E/OXEZuzGY2qAzE+4rXKuFLq/Q4QyMhJsOUmRXK7qYQCRmZ1rit5s2 7zHZ/Icsa1165wt9ChrUqJ5gepWEiz4/ilxhYDVtfoAdr+sIkf9RMGsX6BNde1gN7uQ0OH K/7VfzPXyh45rHuk9mLR7WK8L1zSvwM= X-MC-Unique: eg-Pve9dPA28lkgodWEgKQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741302; x=1731346102; 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=oeACifbCFLCHko0mFSBbcv0dEN3Keg1lZLZXzqzwC4Y=; b=mIDcEpTrTE+Weh2FGV/+titGkfmsZzXCGmxHuNB1cPpiPbYwm/KiWbN5M++00uqwDY 3xOx6CwjttSdO1dNpJmaAPAGgZOkyETRQKcrFkqot7cTKhaq7PNJ0FxzsmFY5mpQSbO/ v4m3d642P1o/ifWGTu9HUJS1d6RaeaDTB9bICy9mzJfOXCE8fHB/C2JeF0UD2GM4Fs0w 3DjUP5eBnZdauaUVRjQvomJ0uewjqruW+BpotzauL9DDrW26tFyf4fcl88wbE+eteFMS LguNAWuaamLcoYUuZMoPZb4jmzZhswHPih1VfAB2bUc6DgwUf2L1QNgc6Qk6q7v14rnq FIkA== X-Gm-Message-State: AOJu0YwyAkxzjA8KUJ1BvKJsHKbxNbNFvIrAil1OOEl/kIxNxTwnOvAJ Z9su8jsDbtf8X7n0qpwmQZH9muiRxpdOttjqdyS+GsIvRgwtj/iZ61Fc3b06XR5eOIWp6USWagK isLMHoiSi+E+X2asZk9Qua+XUCh7EH0vLnTlHGof0bKddhSf/CgtipoDNMoNCSm5kKboqeIznr8 /9R8Wo4AxYjn4a0bhW6Y2GjPFdjCC6KzMToEMNzGc= X-Received: by 2002:a05:600c:3b83:b0:431:5ba1:a513 with SMTP id 5b1f17b1804b1-43283244db4mr104214475e9.10.1730741302139; Mon, 04 Nov 2024 09:28:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8tN8ySatGtD1LXrRTQod/wYVFKxtqYOVj3mcgD18rn9nxfate/Q+JAT4K8H14libNs7yjkw== X-Received: by 2002:a05:600c:3b83:b0:431:5ba1:a513 with SMTP id 5b1f17b1804b1-43283244db4mr104214065e9.10.1730741301616; Mon, 04 Nov 2024 09:28:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 27/40] rust: use std::os::raw instead of core::ffi Date: Mon, 4 Nov 2024 18:27:06 +0100 Message-ID: <20241104172721.180255-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741538284116600 Content-Type: text/plain; charset="utf-8" core::ffi::c_* types were introduced in Rust 1.64.0. Use the older types in std::os::raw, which are now aliases of the types in core::ffi. There is no need to compile QEMU as no_std, so this is acceptable as long as we supp= ort a version of Debian with Rust 1.63.0. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- meson.build | 3 +-- rust/hw/char/pl011/src/device.rs | 35 +++++++++++----------------- rust/hw/char/pl011/src/lib.rs | 4 ++-- rust/hw/char/pl011/src/memory_ops.rs | 14 +++-------- rust/qemu-api/src/definitions.rs | 2 +- rust/qemu-api/src/device_class.rs | 6 ++--- rust/qemu-api/src/lib.rs | 11 +++++---- rust/qemu-api/src/vmstate.rs | 10 ++++---- rust/qemu-api/tests/tests.rs | 9 ++++--- 9 files changed, 39 insertions(+), 55 deletions(-) diff --git a/meson.build b/meson.build index d360120b233..aa0b0fc5584 100644 --- a/meson.build +++ b/meson.build @@ -3947,14 +3947,13 @@ if have_rust and have_system bindgen_args =3D [ '--disable-header-comment', '--raw-line', '// @generated', - '--ctypes-prefix', 'core::ffi', + '--ctypes-prefix', 'std::os::raw', '--formatter', 'rustfmt', '--generate-block', '--generate-cstr', '--impl-debug', '--merge-extern-blocks', '--no-doc-comments', - '--use-core', '--with-derive-default', '--no-layout-tests', '--no-prepend-enum-name', diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 788b47203b1..036757f7f3a 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -2,9 +2,10 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 -use core::{ - ffi::{c_int, c_uchar, c_uint, c_void, CStr}, - ptr::{addr_of, addr_of_mut, NonNull}, +use core::ptr::{addr_of, addr_of_mut, NonNull}; +use std::{ + ffi::CStr, + os::raw::{c_int, c_uchar, c_uint, c_void}, }; =20 use qemu_api::{ @@ -117,11 +118,10 @@ pub struct PL011Class { } =20 impl qemu_api::definitions::Class for PL011Class { - const CLASS_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), - > =3D Some(crate::device_class::pl011_class_init); + const CLASS_INIT: Option =3D + Some(crate::device_class::pl011_class_init); const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), > =3D None; } =20 @@ -176,11 +176,7 @@ unsafe fn init(&mut self) { } } =20 - pub fn read( - &mut self, - offset: hwaddr, - _size: core::ffi::c_uint, - ) -> std::ops::ControlFlow { + pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::Con= trolFlow { use RegisterOffset::*; =20 std::ops::ControlFlow::Break(match RegisterOffset::try_from(offset= ) { @@ -562,11 +558,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Resul= t<(), ()> { /// readable/writeable from one thread at any time. /// /// The buffer and size arguments must also be valid. -pub unsafe extern "C" fn pl011_receive( - opaque: *mut core::ffi::c_void, - buf: *const u8, - size: core::ffi::c_int, -) { +pub unsafe extern "C" fn pl011_receive(opaque: *mut c_void, buf: *const u8= , size: c_int) { unsafe { debug_assert!(!opaque.is_null()); let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); @@ -585,7 +577,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result= <(), ()> { /// We expect the FFI user of this function to pass a valid pointer, that = has /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. -pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event= : QEMUChrEvent) { +pub unsafe extern "C" fn pl011_event(opaque: *mut c_void, event: QEMUChrEv= ent) { unsafe { debug_assert!(!opaque.is_null()); let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); @@ -656,11 +648,10 @@ pub struct PL011LuminaryClass { } =20 impl qemu_api::definitions::Class for PL011LuminaryClass { - const CLASS_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), - > =3D None; + const CLASS_INIT: Option =3D + None; const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core::ffi= ::c_void), + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void), > =3D None; } =20 diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index fb33110d3d8..69e96d72854 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -46,8 +46,8 @@ pub mod device_class; pub mod memory_ops; =20 -pub const TYPE_PL011: &::core::ffi::CStr =3D c"pl011"; -pub const TYPE_PL011_LUMINARY: &::core::ffi::CStr =3D c"pl011_luminary"; +pub const TYPE_PL011: &::std::ffi::CStr =3D c"pl011"; +pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr =3D c"pl011_luminary"; =20 /// Offset of each register from the base memory address of the device. /// diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/= memory_ops.rs index fc69922fbf3..169d485a4d2 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use core::ptr::NonNull; +use std::os::raw::{c_uint, c_void}; =20 use qemu_api::{bindings::*, zeroable::Zeroable}; =20 @@ -22,11 +23,7 @@ }, }; =20 -unsafe extern "C" fn pl011_read( - opaque: *mut core::ffi::c_void, - addr: hwaddr, - size: core::ffi::c_uint, -) -> u64 { +unsafe extern "C" fn pl011_read(opaque: *mut c_void, addr: hwaddr, size: c= _uint) -> u64 { assert!(!opaque.is_null()); let mut state =3D unsafe { NonNull::new_unchecked(opaque.cast::()) }; let val =3D unsafe { state.as_mut().read(addr, size) }; @@ -43,12 +40,7 @@ } } =20 -unsafe extern "C" fn pl011_write( - opaque: *mut core::ffi::c_void, - addr: hwaddr, - data: u64, - _size: core::ffi::c_uint, -) { +unsafe extern "C" fn pl011_write(opaque: *mut c_void, addr: hwaddr, data: = u64, _size: c_uint) { unsafe { assert!(!opaque.is_null()); let mut state =3D NonNull::new_unchecked(opaque.cast::= ()); diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitio= ns.rs index 064afe60549..26597934bbd 100644 --- a/rust/qemu-api/src/definitions.rs +++ b/rust/qemu-api/src/definitions.rs @@ -4,7 +4,7 @@ =20 //! Definitions required by QEMU when registering a device. =20 -use ::core::ffi::{c_void, CStr}; +use std::{ffi::CStr, os::raw::c_void}; =20 use crate::bindings::{Object, ObjectClass, TypeInfo}; =20 diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index 3d40256f60f..cb4573ca6ef 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -7,7 +7,7 @@ macro_rules! device_class_init { ($func:ident, props =3D> $props:ident, realize_fn =3D> $realize_fn:exp= r, legacy_reset_fn =3D> $legacy_reset_fn:expr, vmsd =3D> $vmsd:ident$(,)*) = =3D> { pub unsafe extern "C" fn $func( klass: *mut $crate::bindings::ObjectClass, - _: *mut ::core::ffi::c_void, + _: *mut ::std::os::raw::c_void, ) { let mut dc =3D ::core::ptr::NonNull::new(klass.cast::<$crate::bindings::D= eviceClass>()).unwrap(); @@ -26,7 +26,7 @@ macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = =3D $defval:expr$(,)*) =3D> { $crate::bindings::Property { // use associated function syntax for type checking - name: ::core::ffi::CStr::as_ptr($name), + name: ::std::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: true, @@ -37,7 +37,7 @@ macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) =3D>= { $crate::bindings::Property { // use associated function syntax for type checking - name: ::core::ffi::CStr::as_ptr($name), + name: ::std::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) as isize, set_default: false, diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 10ab3d7e639..ed840ee2f72 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -34,7 +34,10 @@ unsafe impl Sync for bindings::VMStateInfo {} pub mod vmstate; pub mod zeroable; =20 -use std::alloc::{GlobalAlloc, Layout}; +use std::{ + alloc::{GlobalAlloc, Layout}, + os::raw::c_void, +}; =20 #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] extern "C" { @@ -48,8 +51,8 @@ fn g_aligned_alloc0( =20 #[cfg(not(HAVE_GLIB_WITH_ALIGNED_ALLOC))] extern "C" { - fn qemu_memalign(alignment: usize, size: usize) -> *mut ::core::ffi::c= _void; - fn qemu_vfree(ptr: *mut ::core::ffi::c_void); + fn qemu_memalign(alignment: usize, size: usize) -> *mut c_void; + fn qemu_vfree(ptr: *mut c_void); } =20 extern "C" { @@ -114,7 +117,7 @@ fn default() -> Self { } =20 // Sanity check. -const _: [(); 8] =3D [(); ::core::mem::size_of::<*mut ::core::ffi::c_void>= ()]; +const _: [(); 8] =3D [(); ::core::mem::size_of::<*mut c_void>()]; =20 unsafe impl GlobalAlloc for QemuAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 0c1197277f9..4e06e40505f 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -56,7 +56,7 @@ macro_rules! vmstate_single_test { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), 0) .as_bytes() - .as_ptr() as *const ::core::ffi::c_char, + .as_ptr() as *const ::std::os::raw::c_char, err_hint: ::core::ptr::null(), offset: ::core::mem::offset_of!($struct_name, $field_name), size: $size, @@ -133,7 +133,7 @@ macro_rules! vmstate_array { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), 0) .as_bytes() - .as_ptr() as *const ::core::ffi::c_char, + .as_ptr() as *const ::std::os::raw::c_char, err_hint: ::core::ptr::null(), offset: ::core::mem::offset_of!($struct_name, $field_name), size: $size, @@ -181,7 +181,7 @@ macro_rules! vmstate_struct_pointer_v { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), 0) .as_bytes() - .as_ptr() as *const ::core::ffi::c_char, + .as_ptr() as *const ::std::os::raw::c_char, err_hint: ::core::ptr::null(), offset: ::core::mem::offset_of!($struct_name, $field_name), size: ::core::mem::size_of::<*const $type>(), @@ -206,7 +206,7 @@ macro_rules! vmstate_array_of_pointer { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), 0) .as_bytes() - .as_ptr() as *const ::core::ffi::c_char, + .as_ptr() as *const ::std::os::raw::c_char, version_id: $version_id, num: $num as _, info: unsafe { $info }, @@ -231,7 +231,7 @@ macro_rules! vmstate_array_of_pointer_to_struct { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), 0) .as_bytes() - .as_ptr() as *const ::core::ffi::c_char, + .as_ptr() as *const ::std::os::raw::c_char, version_id: $version_id, num: $num as _, vmsd: unsafe { $vmsd }, diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 37c4dd44f81..c7089f0cf21 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -2,7 +2,7 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 -use core::ffi::CStr; +use std::{ffi::CStr, os::raw::c_void}; =20 use qemu_api::{ bindings::*, @@ -64,11 +64,10 @@ impl ObjectImpl for DummyState { } =20 impl Class for DummyClass { - const CLASS_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core:= :ffi::c_void), - > =3D Some(dummy_class_init); + const CLASS_INIT: Option =3D + Some(dummy_class_init); const CLASS_BASE_INIT: Option< - unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut core:= :ffi::c_void), + unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_voi= d), > =3D None; } =20 --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741504; cv=none; d=zohomail.com; s=zohoarc; b=E4KBRdJoT3IAsbUKJZ02rHz9prNHUsPQbW/2+OUrh0CBX72Tr0nyfXRLvU9I3AfKGG2rktjPQqCHPIde9+wSmhtIYAOGHxz2Spjt9JE1xD+6LyXKeMVckFWsOIor6t0HJ6LTkkFAGNKY1CkevRhchqNM1I+COpWFbMvRf/P8bio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741504; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d+sxt4oLLbOzLQhV8QoJ8Ld4Rd8cnl0CfYwHxwv+BjE=; b=MJP12MJjR14HY2A2XeViiqgwfZJ3sy0+DNqHyiPrTxllzbx0c/WCO/HDNuga7G98Tr4IM4/k5XXxym5WigLlKZdLMJvE6oTqKB6mXmwKqjhF6WYo6NkEah3DKRYkx3qnz/O8ewHL8NfCnXw6itSovxueEcObRdfYx15GAdCkDII= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741504886964.7031618051444; Mon, 4 Nov 2024 09:31:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sS-0005sf-PC; Mon, 04 Nov 2024 12:28:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sQ-0005eN-Lh for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sO-0000OH-GM for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:30 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-delg9ghcNmSXSnHoyF17iQ-1; Mon, 04 Nov 2024 12:28:26 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d47127e69so1916045f8f.1 for ; Mon, 04 Nov 2024 09:28:26 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10b7d15sm13913397f8f.8.2024.11.04.09.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d+sxt4oLLbOzLQhV8QoJ8Ld4Rd8cnl0CfYwHxwv+BjE=; b=iFDkvD3k+9s/YtU+EBHeM/eR7zpADXKfXguXK/i3zZ5yKYACujdcbQAx8NFNsIeOrhgkWd J1HjofJ3h5gYk2zDfMDbTyt+t9iKlxAPjpVfBxM2dpH6aBmiGQxyPMAbDXaXIGS+hdM7XY 8pZdCEaOFqac7kMxpVrXX28zqyaRALw= X-MC-Unique: delg9ghcNmSXSnHoyF17iQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741305; x=1731346105; 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=d+sxt4oLLbOzLQhV8QoJ8Ld4Rd8cnl0CfYwHxwv+BjE=; b=iv27EWQWsZytJwezdvDuAmJiZOAD8NCe/qpCuaQ+blU+RuDOn4GJgOwV9t8qFsaUSp cWHphhFQhLeiLaZdsX7GZnALgjOHrnO61RAXD6yEfZvVVkIz9dZ2lflWkaw7Iw7Jsr4R a0beZ6OGQwtgsiCpcDmptIT/FKRZbQM3MJMEPc8tM+rsNoVa/8YgeuKRDJi0LfGJiIsH OfculRHwDxls+XT9RCIpZUddozboMQUIWyY+2EPhkParajKz6rj/6RGTILC9FGMBq0BV kQ+Nz7/rjcL5WmrykiRrINfdlgvjkd1hNcS4KW3mNQ9fplKOS4rG/AnTfMDeE9oU0lNx 68OA== X-Gm-Message-State: AOJu0YyTkcDimOhdt94OhXFPpgMMjAVP+bqi972fqxZlgkVV/kae8Hps q0vuUbI1gEYP1pbOnFkVQFbPAsTj94ulTJiyagea3u9aCOZqaERhXJTzB9HJOgEP3GWAaBvZQc7 qOsCHymkftb4CAgMBCivOo2A49RXMargmE9gPZQZRoivN3lzHA2O1HZjz6JuMSHx2rDOzcjoEjt e9jQRngBlfP3Ilyo117Ewshb/G8+7BHF+mafGbWzw= X-Received: by 2002:adf:ae1a:0:b0:37d:4cd6:6f2f with SMTP id ffacd0b85a97d-380610f7ecbmr22267897f8f.3.1730741304421; Mon, 04 Nov 2024 09:28:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrgnXUyvLvadgHma+rIwC5AFtq8WJOHKKkWlVmoyPdEK8Jvp9dICYLg82sC6CyucWhGrta4g== X-Received: by 2002:adf:ae1a:0:b0:37d:4cd6:6f2f with SMTP id ffacd0b85a97d-380610f7ecbmr22267870f8f.3.1730741303830; Mon, 04 Nov 2024 09:28:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 28/40] rust: introduce a c_str macro Date: Mon, 4 Nov 2024 18:27:07 +0100 Message-ID: <20241104172721.180255-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741506333116600 This allows CStr constants to be defined easily on Rust 1.63.0, while checking that there are no embedded NULs. c"" literals were only stabilized in Rust 1.77.0. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 5 ++- rust/hw/char/pl011/src/device_class.rs | 18 ++++----- rust/hw/char/pl011/src/lib.rs | 6 ++- rust/qemu-api/meson.build | 4 ++ rust/qemu-api/src/c_str.rs | 53 ++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/vmstate.rs | 2 +- rust/qemu-api/tests/tests.rs | 8 ++-- 8 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 rust/qemu-api/src/c_str.rs diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 036757f7f3a..2d225d544de 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -10,6 +10,7 @@ =20 use qemu_api::{ bindings::{self, *}, + c_str, definitions::ObjectImpl, }; =20 @@ -135,7 +136,7 @@ impl PL011State { /// location/instance. All its fields are expected to hold unitialized /// values with the sole exception of `parent_obj`. unsafe fn init(&mut self) { - const CLK_NAME: &CStr =3D c"clk"; + const CLK_NAME: &CStr =3D c_str!("clk"); =20 let dev =3D addr_of_mut!(*self).cast::(); // SAFETY: @@ -598,7 +599,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result= <(), ()> { let dev: *mut DeviceState =3D qdev_new(PL011State::TYPE_INFO.name); let sysbus: *mut SysBusDevice =3D dev.cast::(); =20 - qdev_prop_set_chr(dev, c"chardev".as_ptr(), chr); + qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr); sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mu= t Error); sysbus_mmio_map(sysbus, 0, addr); sysbus_connect_irq(sysbus, 0, irq); diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index 6a554ad7926..a707fde1384 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -2,14 +2,12 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 -use core::{ - ffi::{c_int, c_void}, - ptr::NonNull, -}; +use core::ptr::NonNull; +use std::os::raw::{c_int, c_void}; =20 use qemu_api::{ - bindings::*, vmstate_clock, vmstate_fields, vmstate_int32, vmstate_sub= sections, vmstate_uint32, - vmstate_uint32_array, vmstate_unused, zeroable::Zeroable, + bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_int32, vmst= ate_subsections, + vmstate_uint32, vmstate_uint32_array, vmstate_unused, zeroable::Zeroab= le, }; =20 use crate::device::{PL011State, PL011_FIFO_DEPTH}; @@ -24,7 +22,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> = bool { =20 /// Migration subsection for [`PL011State`] clock. pub static VMSTATE_PL011_CLOCK: VMStateDescription =3D VMStateDescription { - name: c"pl011/clock".as_ptr(), + name: c_str!("pl011/clock").as_ptr(), version_id: 1, minimum_version_id: 1, needed: Some(pl011_clock_needed), @@ -48,7 +46,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, versio= n_id: c_int) -> c_int { } =20 pub static VMSTATE_PL011: VMStateDescription =3D VMStateDescription { - name: c"pl011".as_ptr(), + name: c_str!("pl011").as_ptr(), version_id: 2, minimum_version_id: 2, post_load: Some(pl011_post_load), @@ -79,14 +77,14 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, vers= ion_id: c_int) -> c_int { qemu_api::declare_properties! { PL011_PROPERTIES, qemu_api::define_property!( - c"chardev", + c_str!("chardev"), PL011State, char_backend, unsafe { &qdev_prop_chr }, CharBackend ), qemu_api::define_property!( - c"migrate-clk", + c_str!("migrate-clk"), PL011State, migrate_clock, unsafe { &qdev_prop_bool }, diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 69e96d72854..cd0a49acb91 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -42,12 +42,14 @@ extern crate bilge_impl; extern crate qemu_api; =20 +use qemu_api::c_str; + pub mod device; pub mod device_class; pub mod memory_ops; =20 -pub const TYPE_PL011: &::std::ffi::CStr =3D c"pl011"; -pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr =3D c"pl011_luminary"; +pub const TYPE_PL011: &::std::ffi::CStr =3D c_str!("pl011"); +pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr =3D c_str!("pl011_luminar= y"); =20 /// Offset of each register from the base memory address of the device. /// diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 3b849f7c413..c950b008d59 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -3,6 +3,7 @@ _qemu_api_rs =3D static_library( structured_sources( [ 'src/lib.rs', + 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', 'src/vmstate.rs', @@ -18,6 +19,9 @@ _qemu_api_rs =3D static_library( ], ) =20 +rust.test('rust-qemu-api-tests', _qemu_api_rs, + suite: ['unit', 'rust']) + qemu_api =3D declare_dependency( link_with: _qemu_api_rs, dependencies: qemu_api_macros, diff --git a/rust/qemu-api/src/c_str.rs b/rust/qemu-api/src/c_str.rs new file mode 100644 index 00000000000..4cd96da0b45 --- /dev/null +++ b/rust/qemu-api/src/c_str.rs @@ -0,0 +1,53 @@ +// Copyright 2024 Red Hat, Inc. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +#[macro_export] +/// Given a string constant _without_ embedded or trailing NULs, return +/// a `CStr`. +/// +/// Needed for compatibility with Rust <1.77. +macro_rules! c_str { + ($str:expr) =3D> {{ + const STRING: &str =3D concat!($str, "\0"); + const BYTES: &[u8] =3D STRING.as_bytes(); + + // "for" is not allowed in const context... oh well, + // everybody loves some lisp. This could be turned into + // a procedural macro if this is a problem; alternatively + // Rust 1.72 makes CStr::from_bytes_with_nul a const function. + const fn f(b: &[u8], i: usize) { + if i =3D=3D b.len() - 1 { + } else if b[i] =3D=3D 0 { + panic!("c_str argument contains NUL") + } else { + f(b, i + 1) + } + } + f(BYTES, 0); + + // SAFETY: absence of NULs apart from the final byte was checked a= bove + unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(BYTES) } + }}; +} + +#[cfg(test)] +mod tests { + use std::ffi::CStr; + + use crate::c_str; + + #[test] + fn test_cstr_macro() { + let good =3D c_str!("=F0=9F=A6=80"); + let good_bytes =3D b"\xf0\x9f\xa6\x80\0"; + assert_eq!(good.to_bytes_with_nul(), good_bytes); + } + + #[test] + fn test_cstr_macro_const() { + const GOOD: &CStr =3D c_str!("=F0=9F=A6=80"); + const GOOD_BYTES: &[u8] =3D b"\xf0\x9f\xa6\x80\0"; + assert_eq!(GOOD.to_bytes_with_nul(), GOOD_BYTES); + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index ed840ee2f72..e6bd953e10b 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -29,6 +29,7 @@ unsafe impl Sync for bindings::VMStateDescription {} unsafe impl Sync for bindings::VMStateField {} unsafe impl Sync for bindings::VMStateInfo {} =20 +pub mod c_str; pub mod definitions; pub mod device_class; pub mod vmstate; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 4e06e40505f..9c252ce18ef 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -15,7 +15,7 @@ macro_rules! vmstate_unused_buffer { ($field_exists_fn:expr, $version_id:expr, $size:expr) =3D> {{ $crate::bindings::VMStateField { - name: c"unused".as_ptr(), + name: c_str!("unused").as_ptr(), err_hint: ::core::ptr::null(), offset: 0, size: $size, diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index c7089f0cf21..381ac84657b 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -6,7 +6,7 @@ =20 use qemu_api::{ bindings::*, - declare_properties, define_property, + c_str, declare_properties, define_property, definitions::{Class, ObjectImpl}, device_class_init, zeroable::Zeroable, @@ -16,7 +16,7 @@ fn test_device_decl_macros() { // Test that macros can compile. pub static VMSTATE: VMStateDescription =3D VMStateDescription { - name: c"name".as_ptr(), + name: c_str!("name").as_ptr(), unmigratable: true, ..Zeroable::ZERO }; @@ -36,7 +36,7 @@ pub struct DummyClass { declare_properties! { DUMMY_PROPERTIES, define_property!( - c"migrate-clk", + c_str!("migrate-clk"), DummyState, migrate_clock, unsafe { &qdev_prop_bool }, @@ -55,7 +55,7 @@ pub struct DummyClass { impl ObjectImpl for DummyState { type Class =3D DummyClass; const TYPE_INFO: qemu_api::bindings::TypeInfo =3D qemu_api::type_i= nfo! { Self }; - const TYPE_NAME: &'static CStr =3D c"dummy"; + const TYPE_NAME: &'static CStr =3D c_str!("dummy"); const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(TYPE_DEVICE= ); const ABSTRACT: bool =3D false; const INSTANCE_INIT: Option =3D None; --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741553; cv=none; d=zohomail.com; s=zohoarc; b=nttp0ZVXvwNPLZMiTtyRmLtTkDdaRSy7z8CHCjqjZF2gPsEAp3VSk7o4d+zIE6UW3l6bW59pZAwhc/zHH+KJInEJVfFjRBD2cRl/HQUhe0L4irqR0Fdp/OuD8zGagCEq179lYYw+UHDnCoesyoWzZB4h+hE7Z36dpLDX+N4tXLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741553; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3lFu90NjWg0SYteCDLmbz/R+IMonQxZkD/nPXECqYIo=; b=Nl+eQQDAD0ypShIm2JV8zZS7IwRi7whXaX5a1DLOg7BJoWsoZ80d41IbGNg6ZZcgbsuXHew8hN+X0kc9ZVN3xPhoaUr21Ajt2tdcj+M/15VAXyegQs7tPq1gOR1iekNZaAHxsbp2/Y8tE0E+TJ7UcD3jVdS8roEefYsw8u2RqJQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741553618567.021312668772; Mon, 4 Nov 2024 09:32:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sa-0006V0-6P; Mon, 04 Nov 2024 12:28:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sT-0005vw-5n for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sQ-0000OU-Pl for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:32 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-ZBIq9ld6Ma--gUdGCqix-Q-1; Mon, 04 Nov 2024 12:28:28 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d5116f0a6so2225260f8f.0 for ; Mon, 04 Nov 2024 09:28:28 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10b7bf7sm13917889f8f.9.2024.11.04.09.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3lFu90NjWg0SYteCDLmbz/R+IMonQxZkD/nPXECqYIo=; b=QiBIU70+cphWbGy/HUEP43RTU4Xnywzfnp2xThjIKYJeHoIq2srCjVwe70EqcNh4lBLW0a TXizQw4o13m1cEBBI8/4hKykeWttFnNtQ7+yHc75l8C8jpskZAjaiI7J9B1/eOul6D3PWf FmxqH4L1xHz1iox2NBo70mfdjCPzMy8= X-MC-Unique: ZBIq9ld6Ma--gUdGCqix-Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741307; x=1731346107; 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=3lFu90NjWg0SYteCDLmbz/R+IMonQxZkD/nPXECqYIo=; b=vVKcG/BK9ZzH/Dp93zbNhTMQ6yAC8CNBRajSMVBPj4oqpNNfy3ImMTEsbLFpKBoffs acjfGuI2RvPcpfObQjWlRtskD4qKt3jPLQz9mxA12xzmuUt8NJLkoNWaoXaHiIoBcvxL zwujGQ7/wbumR6Ev3tTfEiE26N9IgYc9+WYpFzQZ4e0VHWSsvkSTeG6sNVSoZcClr8pn bQU2C7dxVxbYNrp+tulbmonNNNdw9RHR8KmI7iSjiyP9qOd/NDmBx8MTHrWK2Xux+4EM gwk+UOUCkfXYsuBrpaEY2rN7KH7McRLB27sV/37qC+63PGzljbG7j9kiJmaUU2q/oZQ/ /nAw== X-Gm-Message-State: AOJu0YzYWFWxOZ/UCQKl6Fjg9k/QtUqGwGXO/41u5IzRZS5NUMZW5wHW 8fi34JaDILpuVp9m/HFzG/Aji9O/Sh6FSx1GM2cJUV+SZtbuJNj7R3yGDcpzxrNDb+5yu53NJ11 fXmCY5gHvgkHiAOAdjThAXHrgeVVgzwNOAsvDY6Mug0jVP8hzXM2imxdfLq3dOr91Wh/lvlC/7L ZXsB7Op1jbtPy/2APhHBST/V0rV2XZMy+ZU7+cKT4= X-Received: by 2002:a05:6000:4027:b0:37d:4ebe:164a with SMTP id ffacd0b85a97d-381c7ac7704mr11244110f8f.50.1730741306752; Mon, 04 Nov 2024 09:28:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWX9YvBoN2s2gc9thcdztDytmiVtAAfFVQut6N7TQ2ig1lwfrSbQvrt0IfyY4vpP1XrneOig== X-Received: by 2002:a05:6000:4027:b0:37d:4ebe:164a with SMTP id ffacd0b85a97d-381c7ac7704mr11244067f8f.50.1730741306273; Mon, 04 Nov 2024 09:28:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 29/40] rust: silence unknown warnings for the sake of old compilers Date: Mon, 4 Nov 2024 18:27:08 +0100 Message-ID: <20241104172721.180255-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741554446116600 Content-Type: text/plain; charset="utf-8" Occasionally, we may need to silence warnings and clippy lints that were only introduced in newer Rust compiler versions. However, this would fail when compiling with an older rustc: error: unknown lint: `non_local_definitions` --> rust/qemu-api/rust-qemu-api-tests.p/structured/offset_of.rs:79:17 So by default we need to block the unknown_lints warning. To avoid misspelled lints or other similar issues, re-enable it in the CI job that uses nightly rust. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- meson.build | 8 ++++++++ .gitlab-ci.d/buildtest.yml | 2 +- meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index aa0b0fc5584..2f7e0550105 100644 --- a/meson.build +++ b/meson.build @@ -3341,6 +3341,14 @@ if have_rust and have_system # Prohibit code that is forbidden in Rust 2024 rustc_args +=3D ['-D', 'unsafe_op_in_unsafe_fn'] =20 + # Occasionally, we may need to silence warnings and clippy lints that + # were only introduced in newer Rust compiler versions. Do not croak + # in that case; a CI job with rust_strict_lints =3D=3D true ensures that + # we do not have misspelled allow() attributes. + if not get_option('strict_rust_lints') + rustc_args +=3D ['-A', 'unknown_lints'] + endif + # Apart from procedural macros, our Rust executables will often link # with C code, so include all the libraries that C code needs. This # is safe; https://github.com/rust-lang/rust/pull/54675 says that diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 19ba5b9c818..aba65ff833a 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -128,7 +128,7 @@ build-system-fedora-rust-nightly: job: amd64-fedora-rust-nightly-container variables: IMAGE: fedora-rust-nightly - CONFIGURE_ARGS: --disable-docs --enable-rust + CONFIGURE_ARGS: --disable-docs --enable-rust --enable-strict-rust-lints TARGETS: aarch64-softmmu MAKE_CHECK_ARGS: check-build allow_failure: true diff --git a/meson_options.txt b/meson_options.txt index 0ee4d7bb86b..e46199a3232 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -376,3 +376,5 @@ option('x86_version', type : 'combo', choices : ['0', '= 1', '2', '3', '4'], value =20 option('rust', type: 'feature', value: 'disabled', description: 'Rust support') +option('strict_rust_lints', type: 'boolean', value: false, + description: 'Enable stricter set of Rust warnings') diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 6d08605b771..e898b20307d 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -47,6 +47,8 @@ meson_options_help() { printf "%s\n" ' getrandom()' printf "%s\n" ' --enable-safe-stack SafeStack Stack Smash Protecti= on (requires' printf "%s\n" ' clang/llvm and coroutine backe= nd ucontext)' + printf "%s\n" ' --enable-strict-rust-lints' + printf "%s\n" ' Enable stricter set of Rust wa= rnings' printf "%s\n" ' --enable-strip Strip targets on install' printf "%s\n" ' --enable-tcg-interpreter TCG with bytecode interpreter = (slow)' printf "%s\n" ' --enable-trace-backends=3DCHOICES' @@ -490,6 +492,8 @@ _meson_option_parse() { --disable-spice-protocol) printf "%s" -Dspice_protocol=3Ddisabled ;; --enable-stack-protector) printf "%s" -Dstack_protector=3Denabled ;; --disable-stack-protector) printf "%s" -Dstack_protector=3Ddisabled ;; + --enable-strict-rust-lints) printf "%s" -Dstrict_rust_lints=3Dtrue ;; + --disable-strict-rust-lints) printf "%s" -Dstrict_rust_lints=3Dfalse ;; --enable-strip) printf "%s" -Dstrip=3Dtrue ;; --disable-strip) printf "%s" -Dstrip=3Dfalse ;; --sysconfdir=3D*) quote_sh "-Dsysconfdir=3D$2" ;; --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741585; cv=none; d=zohomail.com; s=zohoarc; b=MdS4bRu9Tfnl7WKGBNAOmsNfdc2vSEViqCco9LHb6kAVJ4FtARqrNGC7ANflIGei145iLL8jcnNeia+8WuixBLFir0OGmThQkyjnPqOVGXOVgv1cqvkCBoWzEOP05fMQfTwuskAWz0IkezrUbZOW4uUyd9iTZDnjny/9Ievw9YQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741585; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LdHMmVfohK45Fr50VMfZShEdcQTZfzv07i8pTppE0kM=; b=M+j6b2LBdRbTr6aMbLW43WbTlVzN+xkWa/XtKIpEmkiwnft8FAJuRPI0wGi9Tu4I2iNnMc7NSEzluH3sWbfLEPnECuBWLu3c6ks05IRCtRsfICmIpbJIpdsOsOxd6zPPetQ59jEFTAc22wMzSehrPBXMdiTFZz4febVGZPKlMAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741585409922.1247874019774; Mon, 4 Nov 2024 09:33:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sW-0006FW-Ti; Mon, 04 Nov 2024 12:28:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sU-00065m-RZ for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sS-0000Or-Rs for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:34 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-tW6MRQIuM2Se0cMouWuQVQ-1; Mon, 04 Nov 2024 12:28:30 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4316e2dde9eso38309135e9.2 for ; Mon, 04 Nov 2024 09:28:30 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5bf225sm158612575e9.11.2024.11.04.09.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LdHMmVfohK45Fr50VMfZShEdcQTZfzv07i8pTppE0kM=; b=GQY2Hw1ux5HE/piWQFJZoAbU4w9m1kmNPIPYjjj37uJnc3gVslSJD74XpI9+4YHmmCbymb bxUzK1AFlNmXeFS2zwC1ZQloUVPAGYGJ32ak6EKsf3AsqBeOoWvY5hWXot+iAEoTK4I3IG d91ZEtU7zmJ0it6iFkQpYdR4KLdW+uY= X-MC-Unique: tW6MRQIuM2Se0cMouWuQVQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741309; x=1731346109; 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=LdHMmVfohK45Fr50VMfZShEdcQTZfzv07i8pTppE0kM=; b=o3T98bYjx4iE9RF2PRVshqDx40O3tP7YVGfJien5yulvxT+7QXF3jNA6+HS4HqszKD SdJondPGLqDnTdYTZ4qaAVvXAcpsSZJ2B0adJ/0w8671xHgvHgHVNeqtMh2yv5uGJeMz gHa/+FS0x7XXT6womu6PTOoZZ1BPTAQv/JwSC69nV9gqXr1r6/xHbFBLWap3YVTCRiHT O+P94VSiEmmKJRHaW07V+qypzGYUDLHqsKAZeD/U8KkZiNOiyeJ4J/FQSUyg9uwx91ot IIyla+xkZkG2De2whbIvGkD1r7YmQPdAcE9QCPzzl4SFbkskHUCUYZ99+JIWp1BAtD9B aUdg== X-Gm-Message-State: AOJu0YwBgNt12Ez//8bwf+p6aRsRB7p8393Q1OlOnuY2SnseNIgf3Z+b h/2Fgd2RvBydFNtYZPk4tFQO6WLv5CnHgo7C8Gw7u15uF8r/zMzD1A6kYFS4SBBI8U//0YzPQnz yycXmujoO8ockhCExYIHW74LHZ7tuDXTr+k9AMvhd3n3d2h5XTor+nv/vpmVmUJqGzakLUj2AGs m1gyqbnCKejpuyOCEBOYwRJ+3WjhGQMFCefUd3DNk= X-Received: by 2002:a05:600c:4f03:b0:431:4847:47c0 with SMTP id 5b1f17b1804b1-43283242c79mr132381675e9.7.1730741308732; Mon, 04 Nov 2024 09:28:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3U3PhA9oiqybUevLrWXLbkRca0oltLj3nmErSUOHX/BRWgfJUQgQYWGgKrFO6uWOOYEX+1Q== X-Received: by 2002:a05:600c:4f03:b0:431:4847:47c0 with SMTP id 5b1f17b1804b1-43283242c79mr132381335e9.7.1730741308303; Mon, 04 Nov 2024 09:28:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 30/40] rust: synchronize dependencies between subprojects and Cargo.lock Date: Mon, 4 Nov 2024 18:27:09 +0100 Message-ID: <20241104172721.180255-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741586649116600 Content-Type: text/plain; charset="utf-8" The next commit will introduce a new build.rs dependency for rust/qemu-api, version_check. Before adding it, ensure that all dependencies are synchronized between the Meson- and cargo-based build systems. Note that it's not clear whether in the long term we'll use Cargo for anything; it seems that the three main uses (clippy, rustfmt, rustdoc) can all be invoked manually---either via glue code in QEMU, or by extending Meson to gain the relevant functionality. However, for the time being we're stuck with Cargo so it should at least look at the same code as the rest of the build system. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/Cargo.lock | 3 +++ rust/qemu-api-macros/Cargo.lock | 8 +++--- rust/qemu-api/Cargo.lock | 47 +++++++++++++++++++++++++++++++++ rust/qemu-api/Cargo.toml | 1 + 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/rust/hw/char/pl011/Cargo.lock b/rust/hw/char/pl011/Cargo.lock index b58cebb186e..9f43b33e8b8 100644 --- a/rust/hw/char/pl011/Cargo.lock +++ b/rust/hw/char/pl011/Cargo.lock @@ -91,6 +91,9 @@ dependencies =3D [ [[package]] name =3D "qemu_api" version =3D "0.1.0" +dependencies =3D [ + "qemu_api_macros", +] =20 [[package]] name =3D "qemu_api_macros" diff --git a/rust/qemu-api-macros/Cargo.lock b/rust/qemu-api-macros/Cargo.l= ock index fdc0fce116c..73c334e7ce9 100644 --- a/rust/qemu-api-macros/Cargo.lock +++ b/rust/qemu-api-macros/Cargo.lock @@ -4,9 +4,9 @@ version =3D 3 =20 [[package]] name =3D "proc-macro2" -version =3D "1.0.86" +version =3D "1.0.84" source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae10= 3b77" +checksum =3D "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a= 49d6" dependencies =3D [ "unicode-ident", ] @@ -31,9 +31,9 @@ dependencies =3D [ =20 [[package]] name =3D "syn" -version =3D "2.0.72" +version =3D "2.0.66" source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7= a8af" +checksum =3D "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cd= cff5" dependencies =3D [ "proc-macro2", "quote", diff --git a/rust/qemu-api/Cargo.lock b/rust/qemu-api/Cargo.lock index e9c51a243a8..e407911cdd1 100644 --- a/rust/qemu-api/Cargo.lock +++ b/rust/qemu-api/Cargo.lock @@ -2,6 +2,53 @@ # It is not intended for manual editing. version =3D 3 =20 +[[package]] +name =3D "proc-macro2" +version =3D "1.0.84" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a= 49d6" +dependencies =3D [ + "unicode-ident", +] + [[package]] name =3D "qemu_api" version =3D "0.1.0" +dependencies =3D [ + "qemu_api_macros", +] + +[[package]] +name =3D "qemu_api_macros" +version =3D "0.1.0" +dependencies =3D [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name =3D "quote" +version =3D "1.0.36" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208ac= aca7" +dependencies =3D [ + "proc-macro2", +] + +[[package]] +name =3D "syn" +version =3D "2.0.66" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cd= cff5" +dependencies =3D [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name =3D "unicode-ident" +version =3D "1.0.12" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0f= ee4b" diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index 3677def3fe2..db594c64083 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -14,6 +14,7 @@ keywords =3D [] categories =3D [] =20 [dependencies] +qemu_api_macros =3D { path =3D "../qemu-api-macros" } =20 [features] default =3D [] --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741549; cv=none; d=zohomail.com; s=zohoarc; b=KLo56KOmyDuAG6nWCXsdRkieMDpktBBw1sghe/5H0ctvYfH+x3Mjf/icu1pATtsmBQ2bmnTQThTyoCRUu+wHmcj48BmZ6X3cng64oJF1QNhmGetpwwd4s5lpM3qkA1QvhQrLRBs5aLNixCsEj+UA9IOZSXJuWlIX88Dw1Swfemo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741549; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i5EXyRcUQif7nOV98F3C2ZSKwIXfW163NZDTMaMuIdQ=; b=j5QJpU8dEgla+MXLZM1pYhh2cYfVLRUr/5lGWW0VUMplmW4v6Fn0bwJmiUHQk15XDVAdp3K+UE7UDHJfsi5E521QUpZbu3L9BfJGC0f6HSPjhbQA/S/nZN2O2PIzVqo7eMcX563R20pH2Ik5syNm/kIAnn9qlcmEfPtRaOe7F6c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741549293792.5633092683327; Mon, 4 Nov 2024 09:32:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sb-0006f1-QY; Mon, 04 Nov 2024 12:28:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sa-0006VD-51 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sX-0000Q4-Tk for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:39 -0500 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-geyZ2jz9N-G6LlupS4zAwg-1; Mon, 04 Nov 2024 12:28:35 -0500 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-53a0b48e8d4so3103590e87.3 for ; Mon, 04 Nov 2024 09:28:35 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5ab305sm160311675e9.7.2024.11.04.09.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i5EXyRcUQif7nOV98F3C2ZSKwIXfW163NZDTMaMuIdQ=; b=DxXLjt+BxnzWnrO4WBb6eAXn5R8ydT7hWe5b31/vMA7ABUAgov9qo+f2js9t1oyC2+ihug 4bzIZmH7EV3fpZ2m60j5BP3jX0irCGTayfU0dsm47AXT8YS+f6gNY2Wfu0FnWEyZ8AHPDn heX0FEP2aIJ6/+YOOhxy76K7HEhpWME= X-MC-Unique: geyZ2jz9N-G6LlupS4zAwg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741313; x=1731346113; 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=i5EXyRcUQif7nOV98F3C2ZSKwIXfW163NZDTMaMuIdQ=; b=LjwMMGYwRgk+CF2FW6u8Vg7PaJRRSdzFn3f1RnZgf92j8sOf8iXZik6fpd2qUUDI7N Nbtona75dvlf4OBcrY3I312TPTVMibnU5uQYhTtOgMnAVDhEcXrZp7OIrBP6AGlCc9fi a4YSMxwr0yXEzu6sl3Mm6iPKwiIxsF/X4frLzmG2aVPF4zvlXdvoWXLZFWSaHlCg6CJE 48uG6/dCBwGOUZwgXdQtWeFceTibKCd3KhYkue6EWriMATj+yhXtXVKHb4TTNRgL9KTZ WIJTbnFmGEx8MmmeFoagIUH+eQnvk8GP+tgIJNh0aHMYCBnKDV5nM2JlV11LT3tUZrYa OkkQ== X-Gm-Message-State: AOJu0YzOKtwBWYKqZp/lFjzGvTIedoZuvNcEyOR90CS6dnfL56iIwW0n 6fzVIv/PUzwFoUcxdmMCO4LlsbXJYidM1aVf61cGRcHstt1ohvC1dwigYfyOnl/A1nZ8t25lhiJ 3MY8yqccz0KxmRhE+cMoQ9wmhVv3188KQ1RErqzglTbahSB+z+e3j4YiYOJk4SyJovpBEtruKx7 taFQitC5HEI5lu5+BxQ8hHAMF4hE5sPtplLu1K/xM= X-Received: by 2002:a05:6512:3c90:b0:539:ea54:8d22 with SMTP id 2adb3069b0e04-53b348d2696mr16218755e87.18.1730741313041; Mon, 04 Nov 2024 09:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+4TF0klWwjC++tT5Q3AKWlPykLZMVYN8aV3eYhr2+pHl/8fFl3HU/EDRIG4tTCgJ1b4yTSQ== X-Received: by 2002:a05:6512:3c90:b0:539:ea54:8d22 with SMTP id 2adb3069b0e04-53b348d2696mr16218722e87.18.1730741312508; Mon, 04 Nov 2024 09:28:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 31/40] rust: create a cargo workspace Date: Mon, 4 Nov 2024 18:27:10 +0100 Message-ID: <20241104172721.180255-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741550531116600 Content-Type: text/plain; charset="utf-8" Workspaces allows tracking dependencies for multiple crates at once, by having a single Cargo.lock file at the top of the rust/ tree. Because QEMU's Cargo.lock files have to be synchronized with the versions of crates in subprojects/, using a workspace avoids the need to copy over the Cargo.lock file when adding a new device (and thus a new crate) under rust/hw/. In addition, workspaces let cargo download and build dependencies just once. While right now we have one leaf crate (hw/char/pl011), this will not be the case once more devices are added. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/{hw/char/pl011 =3D> }/Cargo.lock | 0 rust/Cargo.toml | 7 ++++ rust/hw/char/pl011/Cargo.toml | 3 -- rust/qemu-api-macros/Cargo.lock | 47 ------------------------- rust/qemu-api-macros/Cargo.toml | 3 -- rust/qemu-api/Cargo.lock | 54 ----------------------------- rust/qemu-api/Cargo.toml | 3 -- 7 files changed, 7 insertions(+), 110 deletions(-) rename rust/{hw/char/pl011 =3D> }/Cargo.lock (100%) create mode 100644 rust/Cargo.toml delete mode 100644 rust/qemu-api-macros/Cargo.lock delete mode 100644 rust/qemu-api/Cargo.lock diff --git a/rust/hw/char/pl011/Cargo.lock b/rust/Cargo.lock similarity index 100% rename from rust/hw/char/pl011/Cargo.lock rename to rust/Cargo.lock diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 00000000000..0c94d5037da --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] +resolver =3D "2" +members =3D [ + "qemu-api-macros", + "qemu-api", + "hw/char/pl011", +] diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index b089e3dded6..a373906b9fb 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -21,6 +21,3 @@ bilge =3D { version =3D "0.2.0" } bilge-impl =3D { version =3D "0.2.0" } qemu_api =3D { path =3D "../../../qemu-api" } qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } - -# Do not include in any global workspace -[workspace] diff --git a/rust/qemu-api-macros/Cargo.lock b/rust/qemu-api-macros/Cargo.l= ock deleted file mode 100644 index 73c334e7ce9..00000000000 --- a/rust/qemu-api-macros/Cargo.lock +++ /dev/null @@ -1,47 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version =3D 3 - -[[package]] -name =3D "proc-macro2" -version =3D "1.0.84" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a= 49d6" -dependencies =3D [ - "unicode-ident", -] - -[[package]] -name =3D "qemu_api_macros" -version =3D "0.1.0" -dependencies =3D [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name =3D "quote" -version =3D "1.0.36" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208ac= aca7" -dependencies =3D [ - "proc-macro2", -] - -[[package]] -name =3D "syn" -version =3D "2.0.66" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cd= cff5" -dependencies =3D [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name =3D "unicode-ident" -version =3D "1.0.12" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0f= ee4b" diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.t= oml index 144cc3650fa..f8d6d03609f 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -20,6 +20,3 @@ proc-macro =3D true proc-macro2 =3D "1" quote =3D "1" syn =3D "2" - -# Do not include in any global workspace -[workspace] diff --git a/rust/qemu-api/Cargo.lock b/rust/qemu-api/Cargo.lock deleted file mode 100644 index e407911cdd1..00000000000 --- a/rust/qemu-api/Cargo.lock +++ /dev/null @@ -1,54 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version =3D 3 - -[[package]] -name =3D "proc-macro2" -version =3D "1.0.84" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a= 49d6" -dependencies =3D [ - "unicode-ident", -] - -[[package]] -name =3D "qemu_api" -version =3D "0.1.0" -dependencies =3D [ - "qemu_api_macros", -] - -[[package]] -name =3D "qemu_api_macros" -version =3D "0.1.0" -dependencies =3D [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name =3D "quote" -version =3D "1.0.36" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208ac= aca7" -dependencies =3D [ - "proc-macro2", -] - -[[package]] -name =3D "syn" -version =3D "2.0.66" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cd= cff5" -dependencies =3D [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name =3D "unicode-ident" -version =3D "1.0.12" -source =3D "registry+https://github.com/rust-lang/crates.io-index" -checksum =3D "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0f= ee4b" diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index db594c64083..e092f61e8f3 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -20,8 +20,5 @@ qemu_api_macros =3D { path =3D "../qemu-api-macros" } default =3D [] allocator =3D [] =20 -# Do not include in any global workspace -[workspace] - [lints.rust] unexpected_cfgs =3D { level =3D "warn", check-cfg =3D ['cfg(MESON)', 'cfg(= HAVE_GLIB_WITH_ALIGNED_ALLOC)'] } --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741697; cv=none; d=zohomail.com; s=zohoarc; b=QUNwx6EQXn78Bf1PqaD06Jvzh9TeKt0J+kdarE8KtA4SiE+Qs/M7+cnkfr/FpEuOY4JvCcJyWo2jiusPQmOeuX910Dwzwc9UFLjasLdE/czkwHRt7/yCEhbGQeLAEoX2lTMATfImdAca7CHSTVLZfPQXY0JwYSytUqu8KCWU/uI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741697; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RzUqD1o8XG9OcJ1drSA6m/SQAI0bRYTrCcBia/InCEI=; b=dx8k9yRhby6DwTYJQ1VkIOGZ5uWIgJRE9ONarcYa+/j22aJO18zReCPxSJQ/8mdxCUAIq3BXeUhajneUHe6L6nMZoX2fzcoR3GqXxLRGytWa7kx4E5pCsCDvWMubMIVOgm9RIt3x/kD+xhlHR77kEyEeMSro7VPbWN9hVXRXAf4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741697826811.1534386237407; Mon, 4 Nov 2024 09:34:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sf-00073y-8j; Mon, 04 Nov 2024 12:28:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sd-0006qq-4h for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sZ-0000QO-Ea for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:42 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-z8CmHG9sOBysFCyYjaWKlQ-1; Mon, 04 Nov 2024 12:28:37 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43159c07193so38455695e9.0 for ; Mon, 04 Nov 2024 09:28:37 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10b7c13sm13921096f8f.13.2024.11.04.09.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RzUqD1o8XG9OcJ1drSA6m/SQAI0bRYTrCcBia/InCEI=; b=VSgGv/U888H3ogIK5aYkvHK9Zyuhq4Cz4DPZtO3qojd03fxheJSEkJZ5vzeOLRF/jtVEPr c1OTaeaMaKNFK9aavr/f3LKzkcZaBQzoDBb/KqtpK+3tz3+fXJSp6ezgMVhBPLjRbInMwd J0IQg6uGiBHiTfilAnaNaHWwU3RFXDQ= X-MC-Unique: z8CmHG9sOBysFCyYjaWKlQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741316; x=1731346116; 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=RzUqD1o8XG9OcJ1drSA6m/SQAI0bRYTrCcBia/InCEI=; b=FnOjMtQR9nBvj6KZrPWlupczpkqkqla63SIIfniAUg+BYzjK/phOB+9flY8TpmzgvS yf/+CETUQS91KOZaOZiQ7/YzIuvHHM6GHDE7/p1+I2vJkADYiSxO+Wkng98C0aFnWjCs g1zNKRmUdFlNWbz3F70fqNJTG6snsS7k+aBiWi7HOs/l8gwlOBOKksvaUwGZaSmn8xaa 4oWOuuwFEiAotFbkCiQHqKIjzmJVKQqIil6kaOAhJDks8xNHsKRAOTbg2IYK6ixcJjHx J1S1k7tcoMKClvrQm3EMZ11GeSTfaWfAhTMmNPsJmSnYGD4j0iBB8193kb37QhbS7R5j haRQ== X-Gm-Message-State: AOJu0YyN59jQiZSsd8JA8SC4ML2a2h8iSDYPKjZ6GuCOIbygzru1Od44 DevtTNcWIlaO7Gdoc5w+2kBOUBD0N2gIwCYHX2LSJ1aqtM7s/0NDsD2I/9z3D100If1ktXIKQgb jTJtO3p6C8JSgFCLBN2lvOQGHcohIrZkBgbtl4hYEtSz6Jeuqy1Mrsewc+eZ4ws+pBWsfIotA+g AfNY/Kfccen4Xa3otbzFzYF78oe7kkQcjGgPxMxX8= X-Received: by 2002:a05:600c:4e8a:b0:431:54f3:11ab with SMTP id 5b1f17b1804b1-43283296051mr139126595e9.33.1730741315413; Mon, 04 Nov 2024 09:28:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDu7f8A0bXAUoqlNkMnVw9bPJK57e55BLdxta9kMLozBSvgQlRTqWF+7GrkMTl9jiQEanJwg== X-Received: by 2002:a05:600c:4e8a:b0:431:54f3:11ab with SMTP id 5b1f17b1804b1-43283296051mr139126215e9.33.1730741314773; Mon, 04 Nov 2024 09:28:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 32/40] rust: introduce alternative implementation of offset_of! Date: Mon, 4 Nov 2024 18:27:11 +0100 Message-ID: <20241104172721.180255-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741699370116600 Content-Type: text/plain; charset="utf-8" From: Junjie Mao offset_of! was stabilized in Rust 1.77.0. Use an alternative implemenation that was found on the Rust forums, and whose author agreed to license as MIT for use in QEMU. The alternative allows only one level of field access, but apart from this can be used just by replacing core::mem::offset_of! with qemu_api::offset_of!. The actual implementation of offset_of! is done in a declarative macro, but for simplicity and to avoid introducing an extra level of indentation, the trigger is a procedural macro #[derive(offsets)]. The procedural macro is perhaps a bit overengineered, but it helps introducing some idioms that will be useful in the future as well. Signed-off-by: Junjie Mao Co-developed-by: Paolo Bonzini Signed-off-by: Paolo Bonzini --- rust/Cargo.lock | 1 + rust/hw/char/pl011/src/device.rs | 2 +- rust/qemu-api-macros/Cargo.toml | 2 +- rust/qemu-api-macros/src/lib.rs | 75 +++++++- rust/qemu-api/Cargo.toml | 6 +- rust/qemu-api/build.rs | 9 + rust/qemu-api/meson.build | 12 +- rust/qemu-api/src/device_class.rs | 8 +- rust/qemu-api/src/lib.rs | 4 + rust/qemu-api/src/offset_of.rs | 161 ++++++++++++++++++ rust/qemu-api/src/vmstate.rs | 10 +- rust/qemu-api/tests/tests.rs | 1 + subprojects/packagefiles/syn-2-rs/meson.build | 1 + 13 files changed, 274 insertions(+), 18 deletions(-) create mode 100644 rust/qemu-api/src/offset_of.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 9f43b33e8b8..c0c6069247a 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -93,6 +93,7 @@ name =3D "qemu_api" version =3D "0.1.0" dependencies =3D [ "qemu_api_macros", + "version_check", ] =20 [[package]] diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 2d225d544de..bca727e37f0 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -55,7 +55,7 @@ impl DeviceId { } =20 #[repr(C)] -#[derive(Debug, qemu_api_macros::Object)] +#[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)] /// PL011 Device Model in QEMU pub struct PL011State { pub parent_obj: SysBusDevice, diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.t= oml index f8d6d03609f..a8f7377106b 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -19,4 +19,4 @@ proc-macro =3D true [dependencies] proc-macro2 =3D "1" quote =3D "1" -syn =3D "2" +syn =3D { version =3D "2", features =3D ["extra-traits"] } diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index a4bc5d01ee8..cf99ac04b8f 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -3,8 +3,34 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, DeriveInput}; +use proc_macro2::Span; +use quote::{quote, quote_spanned}; +use syn::{ + parse_macro_input, parse_quote, punctuated::Punctuated, token::Comma, = Data, DeriveInput, Field, + Fields, Ident, Type, Visibility, +}; + +struct CompileError(String, Span); + +impl From for proc_macro2::TokenStream { + fn from(err: CompileError) -> Self { + let CompileError(msg, span) =3D err; + quote_spanned! { span =3D> compile_error!(#msg); } + } +} + +fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), CompileError> { + let expected =3D parse_quote! { #[repr(C)] }; + + if input.attrs.iter().any(|attr| attr =3D=3D &expected) { + Ok(()) + } else { + Err(CompileError( + format!("#[repr(C)] required for {}", msg), + input.ident.span(), + )) + } +} =20 #[proc_macro_derive(Object)] pub fn derive_object(input: TokenStream) -> TokenStream { @@ -21,3 +47,48 @@ pub fn derive_object(input: TokenStream) -> TokenStream { =20 TokenStream::from(expanded) } + +fn get_fields(input: &DeriveInput) -> Result<&Punctuated, Co= mpileError> { + if let Data::Struct(s) =3D &input.data { + if let Fields::Named(fs) =3D &s.fields { + Ok(&fs.named) + } else { + Err(CompileError( + "Cannot generate offsets for unnamed fields.".to_string(), + input.ident.span(), + )) + } + } else { + Err(CompileError( + "Cannot generate offsets for union or enum.".to_string(), + input.ident.span(), + )) + } +} + +#[rustfmt::skip::macros(quote)] +fn derive_offsets_or_error(input: DeriveInput) -> Result { + is_c_repr(&input, "#[derive(offsets)]")?; + + let name =3D &input.ident; + let fields =3D get_fields(&input)?; + let field_names: Vec<&Ident> =3D fields.iter().map(|f| f.ident.as_ref(= ).unwrap()).collect(); + let field_types: Vec<&Type> =3D fields.iter().map(|f| &f.ty).collect(); + let field_vis: Vec<&Visibility> =3D fields.iter().map(|f| &f.vis).coll= ect(); + + Ok(quote! { + ::qemu_api::with_offsets! { + struct #name { + #(#field_vis #field_names: #field_types,)* + } + } + }) +} + +#[proc_macro_derive(offsets)] +pub fn derive_offsets(input: TokenStream) -> TokenStream { + let input =3D parse_macro_input!(input as DeriveInput); + let expanded =3D derive_offsets_or_error(input).unwrap_or_else(Into::i= nto); + + TokenStream::from(expanded) +} diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index e092f61e8f3..cc716d75d46 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -16,9 +16,13 @@ categories =3D [] [dependencies] qemu_api_macros =3D { path =3D "../qemu-api-macros" } =20 +[build-dependencies] +version_check =3D "~0.9" + [features] default =3D [] allocator =3D [] =20 [lints.rust] -unexpected_cfgs =3D { level =3D "warn", check-cfg =3D ['cfg(MESON)', 'cfg(= HAVE_GLIB_WITH_ALIGNED_ALLOC)'] } +unexpected_cfgs =3D { level =3D "warn", check-cfg =3D ['cfg(MESON)', 'cfg(= HAVE_GLIB_WITH_ALIGNED_ALLOC)', + 'cfg(has_offset_of)'] } diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 419b154c2d2..20f8f718b90 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -4,6 +4,8 @@ =20 use std::path::Path; =20 +use version_check as rustc; + fn main() { if !Path::new("src/bindings.rs").exists() { panic!( @@ -11,4 +13,11 @@ fn main() { (`ninja bindings.rs`) and copy them to src/bindings.rs, or bu= ild through meson." ); } + + // Check for available rustc features + if rustc::is_min_version("1.77.0").unwrap_or(false) { + println!("cargo:rustc-cfg=3Dhas_offset_of"); + } + + println!("cargo:rerun-if-changed=3Dbuild.rs"); } diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index c950b008d59..6f637af7b1b 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -1,3 +1,9 @@ +_qemu_api_cfg =3D ['--cfg', 'MESON'] +# _qemu_api_cfg +=3D ['--cfg', 'feature=3D"allocator"'] +if rustc.version().version_compare('>=3D1.77.0') + _qemu_api_cfg +=3D ['--cfg', 'has_offset_of'] +endif + _qemu_api_rs =3D static_library( 'qemu_api', structured_sources( @@ -6,6 +12,7 @@ _qemu_api_rs =3D static_library( 'src/c_str.rs', 'src/definitions.rs', 'src/device_class.rs', + 'src/offset_of.rs', 'src/vmstate.rs', 'src/zeroable.rs', ], @@ -13,10 +20,7 @@ _qemu_api_rs =3D static_library( ), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', - rust_args: [ - '--cfg', 'MESON', - # '--cfg', 'feature=3D"allocator"', - ], + rust_args: _qemu_api_cfg, ) =20 rust.test('rust-qemu-api-tests', _qemu_api_rs, diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index cb4573ca6ef..56608c7f7fc 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -23,23 +23,23 @@ macro_rules! device_class_init { =20 #[macro_export] macro_rules! define_property { - ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = =3D $defval:expr$(,)*) =3D> { + ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr, default = =3D $defval:expr$(,)*) =3D> { $crate::bindings::Property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) as isize, + offset: $crate::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, ..$crate::zeroable::Zeroable::ZERO } }; - ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) =3D>= { + ($name:expr, $state:ty, $field:ident, $prop:expr, $type:expr$(,)*) =3D= > { $crate::bindings::Property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: ::core::mem::offset_of!($state, $field) as isize, + offset: $crate::offset_of!($state, $field) as isize, set_default: false, ..$crate::zeroable::Zeroable::ZERO } diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index e6bd953e10b..aa8d16ec94b 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -32,6 +32,7 @@ unsafe impl Sync for bindings::VMStateInfo {} pub mod c_str; pub mod definitions; pub mod device_class; +pub mod offset_of; pub mod vmstate; pub mod zeroable; =20 @@ -169,3 +170,6 @@ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { } } } + +#[cfg(has_offset_of)] +pub use core::mem::offset_of; diff --git a/rust/qemu-api/src/offset_of.rs b/rust/qemu-api/src/offset_of.rs new file mode 100644 index 00000000000..075e98f986b --- /dev/null +++ b/rust/qemu-api/src/offset_of.rs @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: MIT + +/// This macro provides the same functionality as `core::mem::offset_of`, +/// except that only one level of field access is supported. The declarat= ion +/// of the struct must be wrapped with `with_offsets! { }`. +/// +/// It is needed because `offset_of!` was only stabilized in Rust 1.77. +#[cfg(not(has_offset_of))] +#[macro_export] +macro_rules! offset_of { + ($Container:ty, $field:ident) =3D> { + <$Container>::OFFSET_TO__.$field + }; +} + +/// A wrapper for struct declarations, that allows using `offset_of!` in +/// versions of Rust prior to 1.77 +#[macro_export] +macro_rules! with_offsets { + // This method to generate field offset constants comes from: + // + // https://play.rust-lang.org/?version=3Dstable&mode=3Ddebug&editi= on=3D2018&gist=3D10a22a9b8393abd7b541d8fc844bc0df + // + // used under MIT license with permission of Yandros aka Daniel Henry-= Mantilla + ( + $(#[$struct_meta:meta])* + $struct_vis:vis + struct $StructName:ident { + $( + $(#[$field_meta:meta])* + $field_vis:vis + $field_name:ident : $field_ty:ty + ),* + $(,)? + } + ) =3D> ( + #[cfg(not(has_offset_of))] + const _: () =3D { + struct StructOffsetsHelper(std::marker::PhantomData); + const END_OF_PREV_FIELD: usize =3D 0; + + // populate StructOffsetsHelper with associated consts, + // one for each field + $crate::with_offsets! { + @struct $StructName + @names [ $($field_name)* ] + @tys [ $($field_ty ,)*] + } + + // now turn StructOffsetsHelper's consts into a single stru= ct, + // applying field visibility. This provides better error mess= ages + // than if offset_of! used StructOffsetsHelper:: directly. + pub + struct StructOffsets { + $( + $field_vis + $field_name: usize, + )* + } + impl $StructName { + pub + const OFFSET_TO__: StructOffsets =3D StructOffsets { + $( + $field_name: StructOffsetsHelper::<$StructName>::$= field_name, + )* + }; + } + }; + ); + + ( + @struct $StructName:ident + @names [] + @tys [] + ) =3D> (); + + ( + @struct $StructName:ident + @names [$field_name:ident $($other_names:tt)*] + @tys [$field_ty:ty , $($other_tys:tt)*] + ) =3D> ( + #[allow(non_local_definitions)] + #[allow(clippy::modulo_one)] + impl StructOffsetsHelper<$StructName> { + #[allow(nonstandard_style)] + const $field_name: usize =3D { + const ALIGN: usize =3D std::mem::align_of::<$field_ty>(); + const TRAIL: usize =3D END_OF_PREV_FIELD % ALIGN; + END_OF_PREV_FIELD + (if TRAIL =3D=3D 0 { 0usize } else { A= LIGN - TRAIL }) + }; + } + const _: () =3D { + const END_OF_PREV_FIELD: usize =3D + StructOffsetsHelper::<$StructName>::$field_name + + std::mem::size_of::<$field_ty>() + ; + $crate::with_offsets! { + @struct $StructName + @names [$($other_names)*] + @tys [$($other_tys)*] + } + }; + ); +} + +#[cfg(test)] +mod tests { + use crate::offset_of; + + #[repr(C)] + struct Foo { + a: u16, + b: u32, + c: u64, + d: u16, + } + + #[repr(C)] + struct Bar { + pub a: u16, + pub b: u64, + c: Foo, + d: u64, + } + + crate::with_offsets! { + #[repr(C)] + struct Bar { + pub a: u16, + pub b: u64, + c: Foo, + d: u64, + } + } + + #[repr(C)] + pub struct Baz { + b: u32, + a: u8, + } + crate::with_offsets! { + #[repr(C)] + pub struct Baz { + b: u32, + a: u8, + } + } + + #[test] + fn test_offset_of() { + const OFFSET_TO_C: usize =3D offset_of!(Bar, c); + + assert_eq!(offset_of!(Bar, a), 0); + assert_eq!(offset_of!(Bar, b), 8); + assert_eq!(OFFSET_TO_C, 16); + assert_eq!(offset_of!(Bar, d), 40); + + assert_eq!(offset_of!(Baz, b), 0); + assert_eq!(offset_of!(Baz, a), 4); + } +} diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 9c252ce18ef..bedcf1e8f39 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -58,7 +58,7 @@ macro_rules! vmstate_single_test { .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, err_hint: ::core::ptr::null(), - offset: ::core::mem::offset_of!($struct_name, $field_name), + offset: $crate::offset_of!($struct_name, $field_name), size: $size, start: 0, num: 0, @@ -135,7 +135,7 @@ macro_rules! vmstate_array { .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, err_hint: ::core::ptr::null(), - offset: ::core::mem::offset_of!($struct_name, $field_name), + offset: $crate::offset_of!($struct_name, $field_name), size: $size, start: 0, num: $length as _, @@ -183,7 +183,7 @@ macro_rules! vmstate_struct_pointer_v { .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, err_hint: ::core::ptr::null(), - offset: ::core::mem::offset_of!($struct_name, $field_name), + offset: $crate::offset_of!($struct_name, $field_name), size: ::core::mem::size_of::<*const $type>(), start: 0, num: 0, @@ -212,7 +212,7 @@ macro_rules! vmstate_array_of_pointer { info: unsafe { $info }, size: ::core::mem::size_of::<*const $type>(), flags: VMStateFlags(VMStateFlags::VMS_ARRAY.0 | VMStateFlags::= VMS_ARRAY_OF_POINTER.0), - offset: ::core::mem::offset_of!($struct_name, $field_name), + offset: $crate::offset_of!($struct_name, $field_name), err_hint: ::core::ptr::null(), start: 0, num_offset: 0, @@ -241,7 +241,7 @@ macro_rules! vmstate_array_of_pointer_to_struct { | VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_ARRAY_OF_POINTER.0, ), - offset: ::core::mem::offset_of!($struct_name, $field_name), + offset: $crate::offset_of!($struct_name, $field_name), err_hint: ::core::ptr::null(), start: 0, num_offset: 0, diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 381ac84657b..7442f695646 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -21,6 +21,7 @@ fn test_device_decl_macros() { ..Zeroable::ZERO }; =20 + #[derive(qemu_api_macros::offsets)] #[repr(C)] #[derive(qemu_api_macros::Object)] pub struct DummyState { diff --git a/subprojects/packagefiles/syn-2-rs/meson.build b/subprojects/pa= ckagefiles/syn-2-rs/meson.build index a53335f3092..9f56ce1c24d 100644 --- a/subprojects/packagefiles/syn-2-rs/meson.build +++ b/subprojects/packagefiles/syn-2-rs/meson.build @@ -24,6 +24,7 @@ _syn_rs =3D static_library( '--cfg', 'feature=3D"printing"', '--cfg', 'feature=3D"clone-impls"', '--cfg', 'feature=3D"proc-macro"', + '--cfg', 'feature=3D"extra-traits"', ], dependencies: [ quote_dep, --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741629; cv=none; d=zohomail.com; s=zohoarc; b=dMdCK8GUfhq8mSc3sRwMvkJFHppcjyAMNDF9YbvFaUZQgR9q3T5wmmAqf7/9bwaJrSU91yqaaydQSuAaxT5x/Mg/nBdTxSE+cxLo9Z4xLUS5eXYU3cinry9Zez/gT0eFYU5KA79Np67M4p+gBYuvsklFi2BBs2s3dO9F8wW2km4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eq5qbzLPKG4WD2CsQZHh3f809/48MMF72sDvSN7iEVo=; b=Auu6VrSCu6N6+Jmatad5hZzL55gsgTC2aora6RIYMvFmio2npVmOvsa5usAC1jlqmVKC+pftYjrhO7ISCsdgdFFuffRSwDPVzB3GGlEPACFDBkRvNH/h2U/5TdU7Ag2RqdpHPJb92uYV0kjA7Wfz9fdtmn03PD4bxufxlxNXyW8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741629569874.7933291200616; Mon, 4 Nov 2024 09:33:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sg-0007Br-4A; Mon, 04 Nov 2024 12:28:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sd-0006w0-LI for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sb-0000Qf-OT for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:43 -0500 Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-ln8lSviuMhiTKz45rdcugg-1; Mon, 04 Nov 2024 12:28:39 -0500 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2fb55e102b6so27509781fa.1 for ; Mon, 04 Nov 2024 09:28:39 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd917fa7sm187323265e9.18.2024.11.04.09.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eq5qbzLPKG4WD2CsQZHh3f809/48MMF72sDvSN7iEVo=; b=JaYdjpfH9poUalcBJg4/Acr+SiPaSbbMnxqWLbVvd9W8T5WQO061cczV20+yqfXz8tLUJA Ic9QUQ7eq2APaLy5WQZVw1zTuj6uLWA41JzG6+/6ZHuLXhFxAtMGJtLHwzZA8wwfNBwnnK DlNSlFzcZ3FVcPDir6nrXyMN6yi44W8= X-MC-Unique: ln8lSviuMhiTKz45rdcugg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741317; x=1731346117; 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=eq5qbzLPKG4WD2CsQZHh3f809/48MMF72sDvSN7iEVo=; b=lohfIF5NJrr1X+JLf5N6f0Kgkh6FcfnfC8+YxZ/SutdXEpwguabk3pkKcRkOLgYLHl HFYmPfKEQ1+oCBWGmk+9NODOuxZEJUtviae9/Gr0fvla0LYIQK4YiE3sAzVevY5hiVt1 f1JRKWvLhdgowkmbtnEEUiisyIJJ87t/5dgOto+ib0MchAZo/VGkOABuQCw+Byipt0Tv 2tjWfdHXmpCZcGW7ZAYPgUZadrw3S8OZrTFKPYWEIHcJoX4YH1KiNAU1bHJNjCPTu4FP 8zlY/9ldZRuXMrMReJYJAtk0Bow/H2MwLo0wCGaveHaCYqAGwjDu4+8MtiFHWCSGhc/d 9jcA== X-Gm-Message-State: AOJu0YzXp4oVdCgM1q9j9jQFpuBmE0PYSTKpcBHBHsQcBH1AUYcCJshD sNKtUgenOu0zZvyQmF4YC0iTd4p/PoCeSqtgBwMGltJNE+9W36qx5xXyoAJoVVKccEuDRdsJQux J8Nazv97MwBdqhqBAfAXT/xPiOiFojTZX8lhNfVQWEPvgAgKlQ73g94x+tGj/CAz7guhNPu1Y// Ik5WD2bAu0JRkRVg1jXX4KcjX9wh/CaR7HQH3TC+s= X-Received: by 2002:a05:651c:1508:b0:2fa:ddb5:77f9 with SMTP id 38308e7fff4ca-2fedb7ec448mr66869711fa.40.1730741316623; Mon, 04 Nov 2024 09:28:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHENFgBbFtPZcrXOhpsL/Kt0hDBbVz4KNDOgXigmEFmYVxLZcBKOeqwjS2FVGp7keKsNSehqQ== X-Received: by 2002:a05:651c:1508:b0:2fa:ddb5:77f9 with SMTP id 38308e7fff4ca-2fedb7ec448mr66869441fa.40.1730741316076; Mon, 04 Nov 2024 09:28:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 33/40] rust: do not use MaybeUninit::zeroed() Date: Mon, 4 Nov 2024 18:27:12 +0100 Message-ID: <20241104172721.180255-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741630884116600 Content-Type: text/plain; charset="utf-8" MaybeUninit::zeroed() is handy but is not available as a "const" function until Rust 1.75.0. Remove the default implementation of Zeroable::ZERO, and write by hand the definitions for those types that need it. It may be possible to add automatic implementation of the trait, via a procedural macro and/or a trick similar to offset_of!, but do it the easy way for now. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/zeroable.rs | 91 +++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 45ec95c9f70..13cdb2ccba5 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -1,23 +1,86 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 +use std::ptr; + /// Encapsulates the requirement that -/// `MaybeUninit::::zeroed().assume_init()` does not cause -/// undefined behavior. +/// `MaybeUninit::::zeroed().assume_init()` does not cause undefined +/// behavior. This trait in principle could be implemented as just: +/// +/// ``` +/// const ZERO: Self =3D unsafe { +/// ::core::mem::MaybeUninit::<$crate::bindings::Property>::zeroed= ().assume_init() +/// }, +/// ``` +/// +/// The need for a manual implementation is only because `zeroed()` cannot +/// be used as a `const fn` prior to Rust 1.75.0. Once we can assume a new +/// enough version of the compiler, we could provide a `#[derive(Zeroable)= ]` +/// macro to check at compile-time that all struct fields are Zeroable, and +/// use the above blanket implementation of the `ZERO` constant. /// /// # Safety /// -/// Do not add this trait to a type unless all-zeroes is -/// a valid value for the type. In particular, remember that raw -/// pointers can be zero, but references and `NonNull` cannot -/// unless wrapped with `Option<>`. +/// Because the implementation of `ZERO` is manual, it does not make +/// any assumption on the safety of `zeroed()`. However, other users of t= he +/// trait could use it that way. Do not add this trait to a type unless +/// all-zeroes is a valid value for the type. In particular, remember that +/// raw pointers can be zero, but references and `NonNull` cannot pub unsafe trait Zeroable: Default { - /// SAFETY: If the trait was added to a type, then by definition - /// this is safe. - const ZERO: Self =3D unsafe { ::core::mem::MaybeUninit::::zeroed= ().assume_init() }; + const ZERO: Self; } =20 -unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} -unsafe impl Zeroable for crate::bindings::Property {} -unsafe impl Zeroable for crate::bindings::VMStateDescription {} -unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {} -unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {} +unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 { + const ZERO: Self =3D Self { i: 0 }; +} + +unsafe impl Zeroable for crate::bindings::Property { + const ZERO: Self =3D Self { + name: ptr::null(), + info: ptr::null(), + offset: 0, + bitnr: 0, + bitmask: 0, + set_default: false, + defval: Zeroable::ZERO, + arrayoffset: 0, + arrayinfo: ptr::null(), + arrayfieldsize: 0, + link_type: ptr::null(), + }; +} + +unsafe impl Zeroable for crate::bindings::VMStateDescription { + const ZERO: Self =3D Self { + name: ptr::null(), + unmigratable: false, + early_setup: false, + version_id: 0, + minimum_version_id: 0, + priority: crate::bindings::MigrationPriority::MIG_PRI_DEFAULT, + pre_load: None, + post_load: None, + pre_save: None, + post_save: None, + needed: None, + dev_unplug_pending: None, + fields: ptr::null(), + subsections: ptr::null(), + }; +} + +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 { + const ZERO: Self =3D Self { + min_access_size: 0, + max_access_size: 0, + unaligned: false, + accepts: None, + }; +} + +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 { + const ZERO: Self =3D Self { + min_access_size: 0, + max_access_size: 0, + unaligned: false, + }; +} --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741679; cv=none; d=zohomail.com; s=zohoarc; b=NboL6V+8ZjkJvFY5NeLMYmfr6ODFyXtZ01wpRU2aJydaHvT2smcwdq8x20SM7r1C3V4FJesTIXi1Let8SU1/21Qj0M77fqnhb4HLoDRXMqKIMyR35NUGyudD1O4sWdm/O0O+TNyRyf7aDBD0tuBU102AeAH+KhsmIxazyTJZpW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741679; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+15v7Qrucllbz0DgQ1LDJqDSgy9GhWKZdsSY2VjeTjI=; b=UTq9ZkwID8ccWT0I+Z/nKqZDXpjJROcBnFRXQwrPgy9cyi7pN5DzIKXgvlcttbEH+AEU2xfOj9HYU8r0UKxz2BrtnLX2XRTJsGgOUuNdiJGBzrjsKMsOwz5dv20GmfZZ7VvLJKI/4tY5Mau2Sn8kTwTyCOaMONhDmZ/8k6R5uc8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741679163276.48460237854886; Mon, 4 Nov 2024 09:34:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sg-0007Ij-VF; Mon, 04 Nov 2024 12:28:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80se-00073J-PY for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sc-0000Qk-CG for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:44 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-5cGXQCyaPZeqyfsDxwnVZA-1; Mon, 04 Nov 2024 12:28:40 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37d49887a2cso2359475f8f.0 for ; Mon, 04 Nov 2024 09:28:40 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5e7c9asm164887845e9.21.2024.11.04.09.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+15v7Qrucllbz0DgQ1LDJqDSgy9GhWKZdsSY2VjeTjI=; b=IXN0uX9dNEvD2jOxT2I2jlb3mlMTFB6u9abTQbQ1ycfCzbHtbX4nBBZ4bdKIuC9TvN5fI1 dKrhmdvLtyR3vKKKBiKVkrXN7ZaUGLzOh5Z+KD78cPCqC47jQYVBJe2s5CUwhhUoaUtSQh iGrlsGPmok9wstfo1i1vEUtp2+0O1UE= X-MC-Unique: 5cGXQCyaPZeqyfsDxwnVZA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741318; x=1731346118; 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=+15v7Qrucllbz0DgQ1LDJqDSgy9GhWKZdsSY2VjeTjI=; b=G4J6rhlchzsgmRFo8QMR3/JbdmvLVFZTc1ayHE4jv7d1VAbU06nGA+2Jq2E46w/g4u k0utAqoqr1iY3nR2o+xOd9oJblEOqyfmJitXs/mwlHW9/Dk4EoV8LqP2vnb9BRTABtFu 41kctfhbBwB8xcRe6W3kdKklrs/s+IBfaXjQ3pdXTiGFhSFoEiLqO4zQCRHzqfKvSY4O 7QvQAT1ZOqOnUT2lTxLPgHi9rauvOUGkICRJtLyZQWU+F1S02etSuVh+Q5/mF4TUepDJ 9xptT1EbZTvHaznEUTfCJ27kT9p8IGZsfIprBQIhtl9FdU9+S9dMX0n4irm+hFPTqpfd ljDQ== X-Gm-Message-State: AOJu0YzSICaNAzgUALP4Bo+8b4mg2pGRal2RPjeB50wH91v2WQRxjSsL +D4sAXlzeRELAK3C7Od+sXnkm+fsh5cMWH073VKOPrDPFP3DkFKl2lc2a1Z7D2mk154rgbwa3YO jTooBVrN2T/yEy0jtvg4OYp8RgEFAQ2CJe5wkUbDnt9M3+ZD4BB0knu2XEdKan+/sGZYAY9vlnC aqx+SP/f/DTSYa08Hj+UlpR9lrIycaqPhYY47lPF0= X-Received: by 2002:a05:6000:4013:b0:37d:39ff:a9cf with SMTP id ffacd0b85a97d-381c7967346mr9277967f8f.5.1730741317810; Mon, 04 Nov 2024 09:28:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFv88MBT4vDsy6UijKzdu367JhoQS8rp5XfdbtWrWKNORzDhBFNSveZwYoR62ROS7pGRONGLg== X-Received: by 2002:a05:6000:4013:b0:37d:39ff:a9cf with SMTP id ffacd0b85a97d-381c7967346mr9277953f8f.5.1730741317402; Mon, 04 Nov 2024 09:28:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 34/40] rust: clean up detection of the language Date: Mon, 4 Nov 2024 18:27:13 +0100 Message-ID: <20241104172721.180255-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741681077116600 Content-Type: text/plain; charset="utf-8" Disable the detection code altogether if have_system =3D=3D false. Signed-off-by: Paolo Bonzini --- meson.build | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/meson.build b/meson.build index 2f7e0550105..eb5660a0836 100644 --- a/meson.build +++ b/meson.build @@ -53,6 +53,17 @@ cpu =3D host_machine.cpu_family() =20 target_dirs =3D config_host['TARGET_DIRS'].split() =20 +# type of binaries to build +have_linux_user =3D false +have_bsd_user =3D false +have_system =3D false +foreach target : target_dirs + have_linux_user =3D have_linux_user or target.endswith('linux-user') + have_bsd_user =3D have_bsd_user or target.endswith('bsd-user') + have_system =3D have_system or target.endswith('-softmmu') +endforeach +have_user =3D have_linux_user or have_bsd_user + ############ # Programs # ############ @@ -71,11 +82,13 @@ if host_os =3D=3D 'darwin' and \ all_languages +=3D ['objc'] objc =3D meson.get_compiler('objc') endif -have_rust =3D false -if not get_option('rust').disabled() and add_languages('rust', required: g= et_option('rust'), native: false) \ - and add_languages('rust', required: get_option('rust'), native: true) + +have_rust =3D add_languages('rust', native: false, + required: get_option('rust').disable_auto_if(not have_system)) +have_rust =3D have_rust and add_languages('rust', native: true, + required: get_option('rust').disable_auto_if(not have_system)) +if have_rust rustc =3D meson.get_compiler('rust') - have_rust =3D true if rustc.version().version_compare('<1.80.0') if get_option('rust').enabled() error('rustc version ' + rustc.version() + ' is unsupported: Please = upgrade to at least 1.80.0') @@ -186,17 +199,6 @@ have_vhost_net_vdpa =3D have_vhost_vdpa and get_option= ('vhost_net').allowed() have_vhost_net_kernel =3D have_vhost_kernel and get_option('vhost_net').al= lowed() have_vhost_net =3D have_vhost_net_kernel or have_vhost_net_user or have_vh= ost_net_vdpa =20 -# type of binaries to build -have_linux_user =3D false -have_bsd_user =3D false -have_system =3D false -foreach target : target_dirs - have_linux_user =3D have_linux_user or target.endswith('linux-user') - have_bsd_user =3D have_bsd_user or target.endswith('bsd-user') - have_system =3D have_system or target.endswith('-softmmu') -endforeach -have_user =3D have_linux_user or have_bsd_user - have_tools =3D get_option('tools') \ .disable_auto_if(not have_system) \ .allowed() @@ -3331,7 +3333,7 @@ endif =20 genh +=3D configure_file(output: 'config-host.h', configuration: config_ho= st_data) =20 -if have_rust and have_system +if have_rust rustc_args =3D run_command( find_program('scripts/rust/rustc_args.py'), '--config-headers', meson.project_build_root() / 'config-host.h', @@ -3951,7 +3953,7 @@ common_all =3D static_library('common', implicit_include_directories: false, dependencies: common_ss.all_dependencies()) =20 -if have_rust and have_system +if have_rust bindgen_args =3D [ '--disable-header-comment', '--raw-line', '// @generated', @@ -4105,7 +4107,7 @@ foreach target : target_dirs arch_srcs +=3D target_specific.sources() arch_deps +=3D target_specific.dependencies() =20 - if have_rust and have_system + if have_rust and target_type =3D=3D 'system' target_rust =3D rust_devices_ss.apply(config_target, strict: false) crates =3D [] foreach dep : target_rust.dependencies() @@ -4467,9 +4469,9 @@ else endif summary_info +=3D {'Rust support': have_rust} if have_rust - summary_info +=3D {'rustc version': rustc.version()} - summary_info +=3D {'rustc': ' '.join(rustc.cmd_array())} summary_info +=3D {'Rust target': config_host['RUST_TARGET_TRIPLE']} + summary_info +=3D {'rustc': ' '.join(rustc.cmd_array())} + summary_info +=3D {'rustc version': rustc.version()} endif option_cflags =3D (get_option('debug') ? ['-g'] : []) if get_option('optimization') !=3D 'plain' --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741666; cv=none; d=zohomail.com; s=zohoarc; b=AxaI5ujNp9GeosSN1BYhHN1MolYWuNiI5AEQADV8zvXGg1tVhsy2ksRRVa0qeS8IWb7fIoTUv1jsAUCxjPQVrPaORhvb3bwBb7G3TdRQ1razZqTmAAzAFLAQ1q0F2WD+rmOA3d/4ty+Qp/g7KfVB59+H7xF+Xp1K0YZF73YSTwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741666; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xCtG4s+R0hvYDBK1+6HaDNZNUOk+9107L2jl9gNn/a4=; b=gyAyfaUZpZh9QiktWJ+OhaCpa0lEdvMZpX7Z63dCLGs8mq5hqEgG9vjTuJh+OVvHNSGmWArJafeuXD49aauVH26pVZYsV72SkvSNR92SYaXoKE+/yNyv82drrWGKBqoDs0Ri1J8hyIqZ/sYdIcJY2XR+gfGfYqy/4Ze5xT5OW6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741666394204.96414616010998; Mon, 4 Nov 2024 09:34:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80si-0007cV-Nh; Mon, 04 Nov 2024 12:28:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sg-0007GI-9C for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80se-0000RD-Lb for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:45 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-323-_eO2TMXLOxeCsI2glCDcMw-1; Mon, 04 Nov 2024 12:28:42 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso25377485e9.0 for ; Mon, 04 Nov 2024 09:28:42 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd8e853esm193984035e9.8.2024.11.04.09.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xCtG4s+R0hvYDBK1+6HaDNZNUOk+9107L2jl9gNn/a4=; b=A+wz3QXdusZUvs09PjdpsjUGpyz+dWhgEUrFYd0kXLz6rmhA8rjiD91d80OrVRkEApBZ4S MAy6kHMHh6hx6IFuMzGKtvAlCrsdIPuwURInZKgSD+f/5mkFvDf4vZR2Qn2HUl96SROIv0 uWsyd2u6ahz/FAgUsM/AGUZdA9a40CY= X-MC-Unique: _eO2TMXLOxeCsI2glCDcMw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741320; x=1731346120; 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=xCtG4s+R0hvYDBK1+6HaDNZNUOk+9107L2jl9gNn/a4=; b=syB2qlIAxjZMgwJ4ZHE9LCyaghDX0F6o3HqoZFRE0SljO29v4/8U/PNT7hpQ5mszNZ 1lE+HM7JLDZnC1R0jRjEHyAbzpmcFKWoPXRtRMUieqOfNHN6fuEV/SuGuKqjhsnEyJYN lsEJhGRAu48yeVb9qGj4gmC5TzJr6I7s+sFHSBzB9u72buI+hOKJLoYVz/aov5xdqSkX 7WcfI1bJxRE11OJ5pKY4LgmD4G3GrkO7shYUCywSb/gkTm7IMnENtOcrSid2JCkfcf6W kiXTofZPQc43mkZnjW8FQAaEVkuw8+zNUcYGRyC7HXA99PRzGQzR+lqUs9TZZNbr9zS6 ZA0A== X-Gm-Message-State: AOJu0Yw3c/sXWdPJzMMzmb8pvpLGaZWckimAkS2QJbWdz726dpl/16ju aM3eu5YVbJauu0CHWpyrWHzYpKbcW7SqopgHqZvCiK/7btSEabrklCd8/z1ppBIXNy4GTeaIzu2 p7BR2gBxMoiKFXE1uJNThF24BS4kgkHzKYkCs0bjJ9HsfYMwvnQCHYQpl+/NfmYiBCOhlzWpiA4 d2MfM56VCZFedL5zGO/2uJ+gAjS+iGAW74CiaKKFk= X-Received: by 2002:a05:600c:4f41:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-4327dabab21mr125207725e9.10.1730741320332; Mon, 04 Nov 2024 09:28:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJ275ZT/Y3EvRaVSlN0VoNka0QqVeaEKQ8Ru8vqReBVa1RCh3qPItkpblg2u2+77nDu8z6DA== X-Received: by 2002:a05:600c:4f41:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-4327dabab21mr125207525e9.10.1730741319881; Mon, 04 Nov 2024 09:28:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 35/40] rust: allow version 1.63.0 of rustc Date: Mon, 4 Nov 2024 18:27:14 +0100 Message-ID: <20241104172721.180255-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741666980116600 Content-Type: text/plain; charset="utf-8" All constructs introduced by newer versions of Rust have been removed. Apart from Debian 12, all other supported Linux distributions have rustc 1.75.0 or newer. This means that they only lack c"" literals and stable offset_of!. Tested-by: Zhao Liu Signed-off-by: Paolo Bonzini --- meson.build | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index eb5660a0836..95b612e0b77 100644 --- a/meson.build +++ b/meson.build @@ -89,11 +89,12 @@ have_rust =3D have_rust and add_languages('rust', nativ= e: true, required: get_option('rust').disable_auto_if(not have_system)) if have_rust rustc =3D meson.get_compiler('rust') - if rustc.version().version_compare('<1.80.0') + if rustc.version().version_compare('<1.63.0') if get_option('rust').enabled() - error('rustc version ' + rustc.version() + ' is unsupported: Please = upgrade to at least 1.80.0') + error('rustc version ' + rustc.version() + ' is unsupported. Please = upgrade to at least 1.63.0') else - warning('rustc version ' + rustc.version() + ' is unsupported: Disab= ling Rust compilation. Please upgrade to at least 1.80.0 to use Rust.') + warning('rustc version ' + rustc.version() + ' is unsupported, disab= ling Rust compilation.') + message('Please upgrade to at least 1.63.0 to use Rust.') have_rust =3D false endif endif --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741562; cv=none; d=zohomail.com; s=zohoarc; b=VMRXGm/7F9YGdBq6b/fVfX1FJZejUiLTHsKOQpqkUgC9/LXo47MP8HM/jAkCCNDvXAe0KzIWx9B0ikrRUsgbSDfBjxVfZQ3IMuJMaG/3N2SkxBj68gH4D9+SQTNIlwsSc2/18n3nN0gyc69Mo6O8boS7197cSwiCfkZg9PQkvaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741562; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=w5RpplVRrrCi592oN/VMJy7hw/XAeFSdLKK/OTlMsMs=; b=BB5EhCH8deZTnArg2ZylnOO0UlThTohHaH9ShqmLtpyK5HEslij/uREayBlHZA2ONT4PY7gKSX2ly0a+FtYTKlFYYe+IuoF3u6GwEhhIOwKRYQ5wl/RuybheEKGF0la8K9yWrHMb1W33d1BGA6RgS50H/tm1+hkK7OItfS7r4FM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17307415621821001.7008492337404; Mon, 4 Nov 2024 09:32:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80sk-0007ld-0U; Mon, 04 Nov 2024 12:28:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80si-0007cA-2N for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sg-0000RW-8Q for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:47 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-Jme_JV-dMsGPHXW0Aj6Xfw-1; Mon, 04 Nov 2024 12:28:44 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315a0f25afso30788895e9.3 for ; Mon, 04 Nov 2024 09:28:44 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10d49c9sm13807647f8f.37.2024.11.04.09.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741325; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w5RpplVRrrCi592oN/VMJy7hw/XAeFSdLKK/OTlMsMs=; b=bI/jhC6/uZf6Ey+0q1o8O9F90436oiz3v1w7+F+Gpa/xHWsnW3Hzulu2+bnrrH2ID6I6cU 4mbmtERDylYyymvviWC87x88cpYS5F8l3/UN1BhIv8nFuGXz61D+tSdMK73+bPQeq1eaz8 vUC5TgwpG8JKX8Fylhtjza4UQdeykHQ= X-MC-Unique: Jme_JV-dMsGPHXW0Aj6Xfw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741323; x=1731346123; 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=w5RpplVRrrCi592oN/VMJy7hw/XAeFSdLKK/OTlMsMs=; b=rsW94U2rgNQitax0HQAgu73ng7hcUFTXg6I44shKh27whO/2j8G31JswjdmFGt+unv cv3XbdKR8pe9p031WsTDZpATP0kwmjuQ+OpK0ESgfa6X0exI+EnQfRI+2ch36dE/lz8L GT0JSVvW5BjWsD1uCWc+XXapGcFIHdrVbIYfJ9dOvkCy+0ADlq9v/H1GAqjDzEUwYDYc vbFDrlU68iqwI2hzMU/y6XCkMuRtb0NHEwDmy2SdxMmAj6Vck/8kkFpmwwjH9lvO28Qx mkv4OiMUJM+oUDuvunJx1eRApKtjf89JB6e9B1+DaWfLZGCnGIzbx4eiKmCvEZwviU+3 rdpg== X-Gm-Message-State: AOJu0YyjV02ITEfHR0DNS9uGTWr/BpScEKvITm2aj0klJAhYW/fLSNT8 MvloT+oSLnX0uv+lRIiPnzMJj0tz4gksFcte/Uz9+p4vvqpcpjdgnXurf6A2Qj+HGhzKWnr8qFM 0OP1VhL4GjOgBCAeYSi6aN7VtFJU56UdltJyGrzreiuhBzTmAPcf+KG/4+MW0n9Q6xvle03Y168 HrKKxvCni4TxeDz9meN32DiLCqXI2wKHy0cLciPjs= X-Received: by 2002:adf:e5c4:0:b0:37d:4846:42c3 with SMTP id ffacd0b85a97d-38061137468mr22348763f8f.22.1730741322864; Mon, 04 Nov 2024 09:28:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHtAkNeyRIqh1r3lg6iKaaRe9U8hIRD60uYR/uFluQbUacO2B4LGcpJjRbpyEBmDRIsijv5Q== X-Received: by 2002:adf:e5c4:0:b0:37d:4846:42c3 with SMTP id ffacd0b85a97d-38061137468mr22348733f8f.22.1730741322434; Mon, 04 Nov 2024 09:28:42 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 36/40] rust: do not use --generate-cstr Date: Mon, 4 Nov 2024 18:27:15 +0100 Message-ID: <20241104172721.180255-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741564496116600 Content-Type: text/plain; charset="utf-8" --generate-cstr is a good idea and generally the right thing to do, but it is not available in Debian 12 and Ubuntu 22.04. Work around the absence. Signed-off-by: Paolo Bonzini --- meson.build | 4 +++- rust/hw/char/pl011/src/device.rs | 1 + rust/qemu-api/src/device_class.rs | 10 ++++++++++ rust/qemu-api/tests/tests.rs | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 95b612e0b77..07f7e5f8f64 100644 --- a/meson.build +++ b/meson.build @@ -3955,13 +3955,15 @@ common_all =3D static_library('common', dependencies: common_ss.all_dependencies()) =20 if have_rust + # We would like to use --generate-cstr, but it is only available + # starting with bindgen 0.66.0. The oldest supported versions + # are in Ubuntu 22.04 (0.59.1) and Debian 12 (0.60.1). bindgen_args =3D [ '--disable-header-comment', '--raw-line', '// @generated', '--ctypes-prefix', 'std::os::raw', '--formatter', 'rustfmt', '--generate-block', - '--generate-cstr', '--impl-debug', '--merge-extern-blocks', '--no-doc-comments', diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index bca727e37f0..2a85960b81f 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -12,6 +12,7 @@ bindings::{self, *}, c_str, definitions::ObjectImpl, + device_class::TYPE_SYS_BUS_DEVICE, }; =20 use crate::{ diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index 56608c7f7fc..0ba798d3e3c 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -2,6 +2,10 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later =20 +use std::ffi::CStr; + +use crate::bindings; + #[macro_export] macro_rules! device_class_init { ($func:ident, props =3D> $props:ident, realize_fn =3D> $realize_fn:exp= r, legacy_reset_fn =3D> $legacy_reset_fn:expr, vmsd =3D> $vmsd:ident$(,)*) = =3D> { @@ -62,3 +66,9 @@ macro_rules! declare_properties { ]; }; } + +// workaround until we can use --generate-cstr in bindgen. +pub const TYPE_DEVICE: &CStr =3D + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_DEVICE) }; +pub const TYPE_SYS_BUS_DEVICE: &CStr =3D + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DE= VICE) }; diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 7442f695646..43a4827de12 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -8,7 +8,7 @@ bindings::*, c_str, declare_properties, define_property, definitions::{Class, ObjectImpl}, - device_class_init, + device_class, device_class_init, zeroable::Zeroable, }; =20 @@ -57,7 +57,7 @@ impl ObjectImpl for DummyState { type Class =3D DummyClass; const TYPE_INFO: qemu_api::bindings::TypeInfo =3D qemu_api::type_i= nfo! { Self }; const TYPE_NAME: &'static CStr =3D c_str!("dummy"); - const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(TYPE_DEVICE= ); + const PARENT_TYPE_NAME: Option<&'static CStr> =3D Some(device_clas= s::TYPE_DEVICE); const ABSTRACT: bool =3D false; const INSTANCE_INIT: Option =3D None; const INSTANCE_POST_INIT: Option =3D None; --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741353; cv=none; d=zohomail.com; s=zohoarc; b=MOqIgXkOl0toX9auPAtXlCwcUstMbD3ak3E9jivcszP05XkEIxOl6oCghr1OtjacoK8j6cyguYOkNY9kPfrwlylXInPV4B/U1lDXWvZze/NYcS79q+CVFjof2P1LciMhs0XkbN0lUf7PmCBrLO3fDLPMJAJp0dZw9b3dvSiC/SY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741353; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d0Yrz32tZ191PDxJl2kf+DfSdg5bbOVpXeDrYos7+QE=; b=gh0rGDjQs8HJKjqDVh6jpwUg0utfnAFxqcIuR5nJxp8BVEchPWIOZ3Mo37iXTaQNRzs1NxcFlpf6wHzaOjPgdhCDKfDgAPL1fc8SMUIxMYmR72rsta5IRAuPKhRIf5XQYuoRmT/nZ2G7UiPvF0jK+ekvfNe0yCVHrqcewnr7MQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741353815727.6409081485122; Mon, 4 Nov 2024 09:29:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80su-0008Bj-Un; Mon, 04 Nov 2024 12:29:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sr-000869-Bi for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80so-0000TH-I2 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:56 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-Dp9oAbddMCaOFRDtnQ4k5w-1; Mon, 04 Nov 2024 12:28:47 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4316ac69e6dso30915705e9.0 for ; Mon, 04 Nov 2024 09:28:47 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e747csm13743212f8f.64.2024.11.04.09.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d0Yrz32tZ191PDxJl2kf+DfSdg5bbOVpXeDrYos7+QE=; b=FFIQU4UaqsEneX7oDan8T3fAjfNp/iFmMQJPwetwVVyXQz1PF9suQqFJ3bvpqyWvboqNSW jSm6wLWoaU8CcrL86rX4D1v4FzAbHWWIMfd0k/E27tbsUOaHVJXZkMuEQQyg7MQ/W3dCDh LunKzjW0ExD4ljj3eptP6ctTqXf2zss= X-MC-Unique: Dp9oAbddMCaOFRDtnQ4k5w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741325; x=1731346125; 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=d0Yrz32tZ191PDxJl2kf+DfSdg5bbOVpXeDrYos7+QE=; b=gbZlip/oyhGiLFhot98tdpJs+0PPwa7yROEftc9jrAe8g1KOlM30uEHrR5eLJWKozO LwDdVOhjVqccrPEyQ5a3/BUFoe6dYBCdgy4SCQJaX1ht91BHo2PS6TGydI+XnHD6TP4V d99DhhXx+i2aunl+aGPE2lz55dDMc9aibQWue1dNRyEEdqXrNptH0Q6g5Y5U15DHznJc GlYwNg8H69J9L3+2C8VdntaUe4WO6GLB8AMR+itT1xNDFCg6MQBFeDwixKxh2v4L03K0 XF+kGAwsVbZzVMHRFjAG3U/zBHPgu8AR1WfZR9iOx1aV/H2jY7BkPt8sUotkEWFu+HOY QKOQ== X-Gm-Message-State: AOJu0Yw6nIeeNPQLhGdROZyjQme0J5cyNUdXUvoguzRaEv8KWzF+YtMi Rm0WaFfi0axFgGb+PeY69p4zSX8Yu8ta3XrNjazbsdMD3WJGB1LvEOJuFPi+VbdSINtD4pb9eNy whGz1rkksa44Tn9EXOFrggOnzSLwIsu/kEdrnNnZvbfKYyFtiNetK9/nyPidRX5lbB+lYC0/KK6 wjmBy/etciMqihStPWpc0d3Q+njgMjcptzTW6KAk8= X-Received: by 2002:adf:a353:0:b0:37d:5113:cdef with SMTP id ffacd0b85a97d-380611e4e39mr23027189f8f.43.1730741325100; Mon, 04 Nov 2024 09:28:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2S7aoGcikVlYGzL1mWNK5adpZ+cnW6jlzmaEwlXRLnJXwvLcCBut6nBHOmaPtoisplFZPtw== X-Received: by 2002:adf:a353:0:b0:37d:5113:cdef with SMTP id ffacd0b85a97d-380611e4e39mr23027156f8f.43.1730741324541; Mon, 04 Nov 2024 09:28:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 37/40] rust: allow older version of bindgen Date: Mon, 4 Nov 2024 18:27:16 +0100 Message-ID: <20241104172721.180255-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741355761116600 Content-Type: text/plain; charset="utf-8" Cope with the old version that is provided in Debian 12. --size_t-is-usize is needed on bindgen <0.61.0, and it was removed in bindgen 0.65.0, so check for it in meson.build. --merge-extern-blocks was added in 0.61.0. --formatter rustfmt was added in 0.65.0 and is the default, so remove it. Apart from Debian 12 and Ubuntu 22.04, all other supported distros have version 0.66.x of bindgen or newer (or do not have bindgen at all). Signed-off-by: Paolo Bonzini --- docs/about/build-platforms.rst | 12 ++++++++++++ meson.build | 29 +++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index 8fd7da140a3..ff56091078e 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -107,6 +107,18 @@ Python build dependencies required, it may be necessary to fetch python modules from the Python Package Index (PyPI) via ``pip``, in order to build QEMU. =20 +Rust build dependencies + QEMU is generally conservative in adding new Rust dependencies, and all + of them are included in the distributed tarballs. One exception is the + bindgen tool, which is too big to package and distribute. The minimum + supported version of bindgen is 0.60.x. For distributions that do not + include bindgen or have an older version, it is recommended to install + a newer version using ``cargo install bindgen-cli``. + + Developers may want to use Cargo-based tools in the QEMU source tree; + this requires Cargo 1.74.0. Note that Cargo is not required in order + to build QEMU. + Optional build dependencies Build components whose absence does not affect the ability to build QEMU may not be available in distros, or may be too old for QEMU's diff --git a/meson.build b/meson.build index 07f7e5f8f64..fffdeef8c80 100644 --- a/meson.build +++ b/meson.build @@ -100,6 +100,21 @@ if have_rust endif endif =20 +bindgen =3D find_program('bindgen', required: get_option('rust').disable_a= uto_if(not have_rust)) +if not bindgen.found() or bindgen.version().version_compare('<0.60.0') + if get_option('rust').enabled() + error('bindgen version ' + bindgen.version() + ' is unsupported. You c= an install a new version with "cargo install bindgen-cli"') + else + if bindgen.found() + warning('bindgen version ' + bindgen.version() + ' is unsupported, d= isabling Rust compilation.') + else + warning('bindgen not found, disabling Rust compilation.') + endif + message('To use Rust you can install a new version with "cargo install= bindgen-cli"') + have_rust =3D false + endif +endif + dtrace =3D not_found stap =3D not_found if 'dtrace' in get_option('trace_backends') @@ -3957,15 +3972,13 @@ common_all =3D static_library('common', if have_rust # We would like to use --generate-cstr, but it is only available # starting with bindgen 0.66.0. The oldest supported versions - # are in Ubuntu 22.04 (0.59.1) and Debian 12 (0.60.1). + # is 0.60.x (Debian 12 has 0.60.1) which introduces --allowlist-file. bindgen_args =3D [ '--disable-header-comment', '--raw-line', '// @generated', '--ctypes-prefix', 'std::os::raw', - '--formatter', 'rustfmt', '--generate-block', '--impl-debug', - '--merge-extern-blocks', '--no-doc-comments', '--with-derive-default', '--no-layout-tests', @@ -3974,6 +3987,12 @@ if have_rust '--allowlist-file', meson.project_source_root() + '/.*', '--allowlist-file', meson.project_build_root() + '/.*' ] + if bindgen.version().version_compare('<0.61.0') + # default in 0.61+ + bindgen_args +=3D ['--size_t-is-usize'] + else + bindgen_args +=3D ['--merge-extern-blocks'] + endif c_enums =3D [ 'DeviceCategory', 'GpioPolarity', @@ -4009,7 +4028,7 @@ if have_rust dependencies: common_ss.all_dependencies(), output: 'bindings.rs', include_directories: include_directories('.', 'include'), - bindgen_version: ['>=3D0.69.4'], + bindgen_version: ['>=3D0.60.0'], args: bindgen_args, ) subdir('rust') @@ -4475,6 +4494,8 @@ if have_rust summary_info +=3D {'Rust target': config_host['RUST_TARGET_TRIPLE']} summary_info +=3D {'rustc': ' '.join(rustc.cmd_array())} summary_info +=3D {'rustc version': rustc.version()} + summary_info +=3D {'bindgen': bindgen.full_path()} + summary_info +=3D {'bindgen version': bindgen.version()} endif option_cflags =3D (get_option('debug') ? ['-g'] : []) if get_option('optimization') !=3D 'plain' --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741456; cv=none; d=zohomail.com; s=zohoarc; b=Gcp9+OJZA0HXil/y7J+QOzr5EE1zLcXn04Ie0/TWs/ZELtaJHdzld2g4RDn0+XiAVJGoJj5AQpP3/lP47maCIBfFYxomSPv/gOyE+u9zkk5yncYX/Oco0B6aijG0QN806yMGZZ/450y0E+f3JXK9tMTwIhJBGx41LUGBGZ76NjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741456; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QK+LcKwTEsZTC5wwU8k/6aVDIU/PlZ/5smfW6kbLSso=; b=dPmLPsLbEZkQEA61zurIOqnM/zlTwGG/hLA2XkgSLYpg8CRjxCjU8nFCCBjbL9Ck+omUEZk0AmRPZor5KdC4a+GmtIrVv6JiUPyOftG8t1W71w7ngZ3txkPLsf/09fVLXN8GxHLvFWyJTODaQcjHNhigezTZt9l25PsV9IXbv7g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741456633316.2381164277991; Mon, 4 Nov 2024 09:30:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80so-0007wi-49; Mon, 04 Nov 2024 12:28:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sm-0007uT-25 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sk-0000Sj-IQ for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:51 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-b8Lz2dacPye40Ik_ZpNvSQ-1; Mon, 04 Nov 2024 12:28:48 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4317391101aso29014585e9.2 for ; Mon, 04 Nov 2024 09:28:48 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5ab254sm159391945e9.3.2024.11.04.09.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QK+LcKwTEsZTC5wwU8k/6aVDIU/PlZ/5smfW6kbLSso=; b=f/ve0QrLxj7wPNbJPXmu3QDSUcUDrbg3iUpNY6LyzLOafkVR3QL62/tlXFOztGMfEU0WzH ERsiLMtCkzj11h000Zc2k6hUMVCrtUGdTLcvFJROu96kYX/atZRuLALsAKMfGtoUg6efgv 6Yk4cwR0HwkCOiJ0hZTakQR4O+gpgAE= X-MC-Unique: b8Lz2dacPye40Ik_ZpNvSQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741327; x=1731346127; 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=QK+LcKwTEsZTC5wwU8k/6aVDIU/PlZ/5smfW6kbLSso=; b=VwGkWZ00r3qJPBmbjslFv0zL9ZboFDVcJWIyjSU3Mbew7+gkMT3xJrYDw+WlO4N6U7 ZAKn5TtNs8BVn4WmLMfQo49InBwzqSCF76DXGhuSXBlnGa8fEgyMF6lwcCbK6XPuQZXz cviXh2cprMdoMloprSSx9IcS9I1dhXImEeNYdZKuhgpVW/wfsZGtIG/NDUKbekJWIJ0E aig0xHE7bav8dvkPgIErpFOGVquAdB/rSmmjcokvOY38qBppn8nNQ9mTUxSzEw58123c fsENdVlrIPbxhliC5j+5Nr58B16OwT8kPWVWhnYhq/d8otF7+B8w/lXkmrqEuhp5/LLM xhKw== X-Gm-Message-State: AOJu0Yz+Ge3nt0uOjcXGVYWT6NelCujNTa8p0w9xYufRoldYt3EX1Pbr /sGCJyRVKRbNLLGi8LNrv593h4i+5QCb7Kpd6hFxMVju7MoTlTtgprA1xcoYYw3pa69gH52vXWl aORDtVRRz9YyQ9P1mmRoouimq53smPSNW9EcROyWMO1KJuallJNL8dmRnlt972vXbWIWf+VDmt/ VQ/Je2oviTR4+3wdYQkQJP1Tvy473gHnOaR1F75q0= X-Received: by 2002:a05:600c:35cf:b0:431:3b53:105e with SMTP id 5b1f17b1804b1-43283244e02mr114578565e9.9.1730741327227; Mon, 04 Nov 2024 09:28:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFi1o2sbXYlIEhoE0F3gvtkYiuXjnxDYtY7Uli/ywTdRbnC7z34yPvIrCNJWy+opltzwi/gdA== X-Received: by 2002:a05:600c:35cf:b0:431:3b53:105e with SMTP id 5b1f17b1804b1-43283244e02mr114578215e9.9.1730741326790; Mon, 04 Nov 2024 09:28:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 38/40] rust: make rustfmt optional Date: Mon, 4 Nov 2024 18:27:17 +0100 Message-ID: <20241104172721.180255-39-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741457604116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- meson.build | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/meson.build b/meson.build index fffdeef8c80..a0ae56c9625 100644 --- a/meson.build +++ b/meson.build @@ -115,6 +115,10 @@ if not bindgen.found() or bindgen.version().version_co= mpare('<0.60.0') endif endif =20 +if have_rust + rustfmt =3D find_program('rustfmt', required: false) +endif + dtrace =3D not_found stap =3D not_found if 'dtrace' in get_option('trace_backends') @@ -3987,6 +3991,13 @@ if have_rust '--allowlist-file', meson.project_source_root() + '/.*', '--allowlist-file', meson.project_build_root() + '/.*' ] + if not rustfmt.found() + if bindgen.version().version_compare('<0.65.0') + bindgen_args +=3D ['--no-rustfmt-bindings'] + else + bindgen_args +=3D ['--formatter', 'none'] + endif + endif if bindgen.version().version_compare('<0.61.0') # default in 0.61+ bindgen_args +=3D ['--size_t-is-usize'] --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741468; cv=none; d=zohomail.com; s=zohoarc; b=XK8DBrilDXCW04kGnbvxoCRJoCeUq3baREEiw3MSi2wdZUW7VUGKmbiI3TnXV1kse/7jF7D4BR+mIg7mW7Fny8vmh+9iSnscMyG+f+TNtYfe1dPX+PbixSLEqkj4F/ovVS13QodsdKOY8AWgqsrHXM5ZPVIyJxrGOXbufSwUeGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741468; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qtmTBH9nUwoIxrYW0EKHYqdJrQ1Dt9cCZWdrafrESwA=; b=cn0ir8Pw7mo4H/A2Hy878gfJvJPilmGv928vT9NFsV1Qq5Qz1fo512TqN70G4maaxsO4MU5GG99xIKlBvt6B9UuHah58CO9bVBINcNH7Fs5bVReHDyxqFDwFAeneceR7I3/YLR6hbHPGbmuVQZlfNembYVBTSF6SU94zrjNZEKA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741468886651.4892856635104; Mon, 4 Nov 2024 09:31:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80tJ-0000Hz-41; Mon, 04 Nov 2024 12:29:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sp-00083J-GT for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sn-0000TE-Rj for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:55 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-JcAfapVyNQCF0NnhWHFVAw-1; Mon, 04 Nov 2024 12:28:50 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4314c6ca114so33071255e9.1 for ; Mon, 04 Nov 2024 09:28:50 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5ac387sm164540165e9.1.2024.11.04.09.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qtmTBH9nUwoIxrYW0EKHYqdJrQ1Dt9cCZWdrafrESwA=; b=KGIWyau7ORsBR64NVCWtZJbI2HmgQbQdyJkeWeVykFbiANeBH9sxM+b580bYvLZlC470I4 T0pZe8Ks5UgSFZcW5ROoHamP8ulGwK07KdDBNUC7jurClDSZE0ahXwr0W3rLIOU3u8PmkX sLtPaEn4Wtnxm7oHBJ2rcfY4smCZgSk= X-MC-Unique: JcAfapVyNQCF0NnhWHFVAw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741329; x=1731346129; 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=qtmTBH9nUwoIxrYW0EKHYqdJrQ1Dt9cCZWdrafrESwA=; b=JP9VxfRjD0wdfe5NHunUSOPYAAQHtjh8iColdKvxMA0WzCYVPrOFZfE/h6wmEBg7Ru GLNJrlvy/h6jxIBpAEh71yxaPyJkuKCR6bdzK7R1zrQJm9ppyimo2V+OKADQI+SRDoN/ vNjAUT8SDBCDinBQfyxacUg4kTg857iupTHdLljwUqOV8FOOiwVGh1fX82YP6s8sySct 2HMOpStpAZMKcSJoijVrJPAvRJ/dtwHqG0Ew0neCX/HjG9nlU7sD0wIx4l5SpSyx7ubx iRubuV9tn0jrunUBMM9SE0Qb0bBni+zzELjl9dW4fuc1LG3nH1UmdkOm3AEMWZNRNOEW RgHA== X-Gm-Message-State: AOJu0YyzfCuWXdC5YNZJ6CJuERs5z7cOjffF1LP3jJ5pRxBOxFoKPcG4 iyONj/zvajX28u1GY/J8CuZS6PmwNCOVSeMn1Oq2faJTws2+vGAv4Hlg2+WuP688gEMFs+cdDst /gJ6f4JCnAACYf99MSP7+51WBZOZuoxC/v8aH1AhC4KgrTgznBlp5mUCy9LQYTYLKhBb5OWXplf Ic6ND0at2djqHEWrYMu9EmJtSiwEnwR6NpG51gDFE= X-Received: by 2002:a05:600c:4f04:b0:42c:acb0:dda5 with SMTP id 5b1f17b1804b1-4327b6f9574mr141362675e9.1.1730741329259; Mon, 04 Nov 2024 09:28:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAHuBStURnLfYbcKDuQlvcoWwYo7TPZLJ9DbvsDyYolksHHUu89Hum8zQqG3RneWh745AqPw== X-Received: by 2002:a05:600c:4f04:b0:42c:acb0:dda5 with SMTP id 5b1f17b1804b1-4327b6f9574mr141362405e9.1.1730741328821; Mon, 04 Nov 2024 09:28:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 39/40] dockerfiles: install bindgen from cargo on Ubuntu 22.04 Date: Mon, 4 Nov 2024 18:27:18 +0100 Message-ID: <20241104172721.180255-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741469749116600 Content-Type: text/plain; charset="utf-8" Because Ubuntu 22.04 has a very old version of bindgen, that does not have the important option --allowlist-file, it will not be able to use --enable-rust out of the box. Instead, install the latest version of bindgen-cli via "cargo install" in the container, following QEMU's own documentation. Reviewed-by: Pierrick Bouvier Signed-off-by: Paolo Bonzini --- scripts/ci/setup/ubuntu/ubuntu-2204-aarch64.yaml | 1 - scripts/ci/setup/ubuntu/ubuntu-2204-s390x.yaml | 1 - tests/docker/dockerfiles/ubuntu2204.docker | 6 +++++- tests/lcitool/mappings.yml | 4 ++++ tests/lcitool/refresh | 11 ++++++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/ci/setup/ubuntu/ubuntu-2204-aarch64.yaml b/scripts/ci/= setup/ubuntu/ubuntu-2204-aarch64.yaml index dd89ba1b3a7..31078f96462 100644 --- a/scripts/ci/setup/ubuntu/ubuntu-2204-aarch64.yaml +++ b/scripts/ci/setup/ubuntu/ubuntu-2204-aarch64.yaml @@ -7,7 +7,6 @@ packages: - bash - bc - - bindgen - bison - bsdextrautils - bzip2 diff --git a/scripts/ci/setup/ubuntu/ubuntu-2204-s390x.yaml b/scripts/ci/se= tup/ubuntu/ubuntu-2204-s390x.yaml index 74f14d8d0fe..fdd50d03e88 100644 --- a/scripts/ci/setup/ubuntu/ubuntu-2204-s390x.yaml +++ b/scripts/ci/setup/ubuntu/ubuntu-2204-s390x.yaml @@ -7,7 +7,6 @@ packages: - bash - bc - - bindgen - bison - bsdextrautils - bzip2 diff --git a/tests/docker/dockerfiles/ubuntu2204.docker b/tests/docker/dock= erfiles/ubuntu2204.docker index ce3aa39d4f3..5f8a811788a 100644 --- a/tests/docker/dockerfiles/ubuntu2204.docker +++ b/tests/docker/dockerfiles/ubuntu2204.docker @@ -13,7 +13,6 @@ RUN export DEBIAN_FRONTEND=3Dnoninteractive && \ eatmydata apt-get install --no-install-recommends -y \ bash \ bc \ - bindgen \ bison \ bsdextrautils \ bzip2 \ @@ -149,6 +148,11 @@ ENV LANG "en_US.UTF-8" ENV MAKE "/usr/bin/make" ENV NINJA "/usr/bin/ninja" ENV PYTHON "/usr/bin/python3" +ENV CARGO_HOME=3D/usr/local/cargo +ENV PATH=3D$CARGO_HOME/bin:$PATH +RUN DEBIAN_FRONTEND=3Dnoninteractive eatmydata \ + apt install -y --no-install-recommends cargo +RUN cargo install bindgen-cli # As a final step configure the user (if env is defined) ARG USER ARG UID diff --git a/tests/lcitool/mappings.yml b/tests/lcitool/mappings.yml index 9c5ac87c1c2..c90b23a00f1 100644 --- a/tests/lcitool/mappings.yml +++ b/tests/lcitool/mappings.yml @@ -1,4 +1,8 @@ mappings: + # Too old on Ubuntu 22.04; we install it from cargo instead + bindgen: + Ubuntu2204: + flake8: OpenSUSELeap15: =20 diff --git a/tests/lcitool/refresh b/tests/lcitool/refresh index 0f16f4d525c..a46cbbdca41 100755 --- a/tests/lcitool/refresh +++ b/tests/lcitool/refresh @@ -137,6 +137,14 @@ fedora_rustup_nightly_extras =3D [ 'RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli= \n', ] =20 +ubuntu2204_bindgen_extras =3D [ + "ENV CARGO_HOME=3D/usr/local/cargo\n", + 'ENV PATH=3D$CARGO_HOME/bin:$PATH\n', + "RUN DEBIAN_FRONTEND=3Dnoninteractive eatmydata \\\n", + " apt install -y --no-install-recommends cargo\n", + 'RUN cargo install bindgen-cli\n', +] + def cross_build(prefix, targets): conf =3D "ENV QEMU_CONFIGURE_OPTS --cross-prefix=3D%s\n" % (prefix) targets =3D "ENV DEF_TARGET_LIST %s\n" % (targets) @@ -157,7 +165,8 @@ try: trailer=3D"".join(debian12_extras)) generate_dockerfile("fedora", "fedora-40") generate_dockerfile("opensuse-leap", "opensuse-leap-15") - generate_dockerfile("ubuntu2204", "ubuntu-2204") + generate_dockerfile("ubuntu2204", "ubuntu-2204", + trailer=3D"".join(ubuntu2204_bindgen_extras)) =20 # # Non-fatal Rust-enabled build --=20 2.47.0 From nobody Sat Nov 23 19:20:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741633; cv=none; d=zohomail.com; s=zohoarc; b=N/z0YOwUpee/mCVx1OF7QNkIxHegJF+57iHbdnThkCMb1PnzBwTV1FEpEQu7WibPm2W1UiLSNdDaktWktdlTac4NasQNP9YkEF2cQWpDRWmB4q6ygFgfv0O++KfnmJdmMU00NPp8HJ0AvdENwrY/M+4bUEnSOkGsy5DfHkP6prU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741633; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CGWRmX3rMWBrx19dauoWAvIXhk+Rz6c9rIxN6h0dBpU=; b=Dt3DZrObaLRIY8BMNJ88hcupkW42Pj2DRQHD+6ck5NAp1YtUbI3kAofyldPLZC7K9a3KkzjZMw4q0achwAEleKJFVLrPggDS5ez1eomKShDt9PphJE5WEIMzSPVpoGKZfDu1JfcW6TZKMpEMq/3rGVHOd5sA0uwZGghseKl/G4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730741633778443.7139328489757; Mon, 4 Nov 2024 09:33:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80tA-0008PH-9R; Mon, 04 Nov 2024 12:29:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80ss-00089b-Oq for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80sr-0000TW-5v for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:58 -0500 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-IF2r7xVjPWilAdXzkf7O9Q-1; Mon, 04 Nov 2024 12:28:54 -0500 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539eb3416cdso4699779e87.1 for ; Mon, 04 Nov 2024 09:28:53 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c113e51csm13814117f8f.79.2024.11.04.09.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CGWRmX3rMWBrx19dauoWAvIXhk+Rz6c9rIxN6h0dBpU=; b=TwgtsqUXExU/5sTO32eeAjhqeThoARY0FDVn/1bjNpWZePY9Th0bXaMfzQjj7ZNy70WK9O cW44Yx+j2ZFA1vk3GzT3hNE9QRS+KChFn0llnmJDtYl2OWVjX6ExwvO06mvo8HqC3VTu6Q X7UIC5Zsv0aB7W+DYQnZNW8YzN2/f+4= X-MC-Unique: IF2r7xVjPWilAdXzkf7O9Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741332; x=1731346132; 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=CGWRmX3rMWBrx19dauoWAvIXhk+Rz6c9rIxN6h0dBpU=; b=Djp5W9WWVdIG9hOXBjmptyA8pfWjaYXaR/k3w2M1DojmyAFi/QScbXNSJtbIi5n5IN rH7j6/Zffc3iDQwaVKD2vY55zBGCeFPvAwrqGbeKHnVKNTIyDKCdDtoT6kk/sy1ky3jl PJ7rBoVpPtHYWefqPJ7vatJlF6AEunSvtBnyvO1QBh7Y2ojcLPr0eqVJvmVWP6Tf6/5F 09oEV2FKumxEVUYelYEOBdi6wQJhH4yqVZOu13wfEu/tBUMMS4vvR9fiM/n5iUZnPp8b Wl5xh7FGmC91Y/5aqSnVbXMJSuyamkHk8vFFVzWYh4E/LrvNqTp7QiffqmPL4x2PTZBn FNeg== X-Gm-Message-State: AOJu0Yztwww3osktU1PTCUG2pe0g62RWWJV0X0nbro9dq2hOVKT+q/X2 6t/Lm0KdG+mHpDOSlIvw70tWUNdj7a3KMMAc4u8yo1MS/HkeoQajPUuDTXStytqEJAtW7CpbM84 hDKeb6Gp4UKwTY1CQh6Qq0ZRHir4NuA5ePdew7dSPLT6+hKYXT2SuRxxodLV4DkUiawColq14j1 UdYNlYcxGsvlE7LM44FLDoQHOhGHYxiVQdoy4ASFY= X-Received: by 2002:a05:6512:12d3:b0:539:fb49:c47a with SMTP id 2adb3069b0e04-53b348c38b0mr18004264e87.4.1730741331763; Mon, 04 Nov 2024 09:28:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvXcC5nQC1vtlOzI2/O8BSyCzrrLMkJgRWoPoLQ1i66qToryZaXzmr1qtCNt7nPD7Ov/Nv8A== X-Received: by 2002:a05:6512:12d3:b0:539:fb49:c47a with SMTP id 2adb3069b0e04-53b348c38b0mr18004212e87.4.1730741330923; Mon, 04 Nov 2024 09:28:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 40/40] ci: enable rust in the Debian and Ubuntu system build job Date: Mon, 4 Nov 2024 18:27:19 +0100 Message-ID: <20241104172721.180255-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730741634772116600 Content-Type: text/plain; charset="utf-8" We have fixed all incompatibilities with older versions of rustc and bindgen. Enable Rust on Debian to check that the minimum supported version of Rust is indeed 1.63.0, and 0.60.x for bindgen. Reviewed-by: Pierrick Bouvier Signed-off-by: Paolo Bonzini --- .gitlab-ci.d/buildtest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index aba65ff833a..8deaf9627cb 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -40,7 +40,7 @@ build-system-ubuntu: job: amd64-ubuntu2204-container variables: IMAGE: ubuntu2204 - CONFIGURE_ARGS: --enable-docs + CONFIGURE_ARGS: --enable-docs --enable-rust TARGETS: alpha-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build =20 @@ -71,7 +71,7 @@ build-system-debian: job: amd64-debian-container variables: IMAGE: debian - CONFIGURE_ARGS: --with-coroutine=3Dsigaltstack + CONFIGURE_ARGS: --with-coroutine=3Dsigaltstack --enable-rust TARGETS: arm-softmmu i386-softmmu riscv64-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu MAKE_CHECK_ARGS: check-build --=20 2.47.0