From nobody Mon Feb 9 19:53:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1677499827; cv=none; d=zohomail.com; s=zohoarc; b=K7tL0URU7DxMf58evXAf7p9sYAakE1eoHW7yTMhfoFUusGv56JQ1jkdNORe9LPaEe/T0zW+EaWOeuNjCLHrlyW/HGMdOns4EVRekbd+OyChP4WzeH9R4cSu7SKTCRvxGgGVLRCvwE1XcztK28ggY6pjpkLfwuW266GOGgDFwync= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677499827; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ie1ECZIy0vs3ZjCA8d3JTPcaE1XIqDwSIQ7h6WLxykU=; b=ln5FnnxnaTdh5iHb6i7QQuiunQv70qx3Z6NgzyTPQ1oCGj0brbwWFnD3ewKlNm5bdriKJaBf5rYnHo0dezgu+w6NG85zNtW51UB8L1nlXUpEqBX9lKD8JnxI8S8X+jLdxqpSntNuCDOLAVJDjnT06roiASjsyngVCYE/js5dxiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1677499827976427.0815155369894; Mon, 27 Feb 2023 04:10:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.502456.774272 (Exim 4.92) (envelope-from ) id 1pWcKa-0003Zc-Gb; Mon, 27 Feb 2023 12:10:12 +0000 Received: by outflank-mailman (output) from mailman id 502456.774272; Mon, 27 Feb 2023 12:10:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pWcKa-0003ZV-DA; Mon, 27 Feb 2023 12:10:12 +0000 Received: by outflank-mailman (input) for mailman id 502456; Mon, 27 Feb 2023 12:10:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pWcKY-00039C-TG for xen-devel@lists.xenproject.org; Mon, 27 Feb 2023 12:10:11 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ae5d68ee-b697-11ed-88bb-e56d68cac8db; Mon, 27 Feb 2023 13:10:10 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E49FA1FD63; Mon, 27 Feb 2023 12:10:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AA54813912; Mon, 27 Feb 2023 12:10:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rQ1OKKGd/GPeNAAAMHmgww (envelope-from ); Mon, 27 Feb 2023 12:10:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ae5d68ee-b697-11ed-88bb-e56d68cac8db DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1677499809; h=from:from:reply-to: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=ie1ECZIy0vs3ZjCA8d3JTPcaE1XIqDwSIQ7h6WLxykU=; b=ChPKJbdiSyCpbkH3pPsThXCZB/GMcMpnBKMWxXxnY62nXuG1Z3i1/UZk3b/YX1z5h0wqzH CUnbSMUt3x4fr9Mjn8JorgFtDrYsJVuf9+YmEVDbu1x9k0IVhaIzdGJnsNoJuDyLKWz7tJ LqxHNftYfpfzbwRVDVcksWtxZIv4VjQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Anthony PERARD , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall Subject: [PATCH 1/3] tools: add container_of() macro to xen-tools/libs.h Date: Mon, 27 Feb 2023 13:09:55 +0100 Message-Id: <20230227120957.10037-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230227120957.10037-1-jgross@suse.com> References: <20230227120957.10037-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1677499829508100003 Content-Type: text/plain; charset="utf-8" Instead of having 4 identical copies of the definition of a container_of() macro in different tools header files, add that macro to xen-tools/libs.h and use that instead. Delete the other copies of that macro. Signed-off-by: Juergen Gross --- There is a similar macro CONTAINER_OF() defined in tools/include/xentoolcore_internal.h, which allows to not only use a type for the 2nd parameter, but a variable, too. I'd like to get rid of that macro as well, but there are lots of use cases especially in libxl. Any thoughts regarding that macro? I could either: - don't touch it at all - enhance container_of() like CONTAINER_OF() and replace all use cases of CONTAINER_OF() with container_of() - replace the few CONTAINER_OF() users outside libxl with container_of() and define CONTAINER_OF() in e.g. libxl_internal.h - replace all CONTAINER_OF() use cases with container_of(), including the change from (.., var, ..) to (.., type, ...). Signed-off-by: Juergen Gross --- tools/include/xen-tools/libs.h | 4 ++++ tools/tests/vhpet/emul.h | 3 --- tools/tests/vpci/emul.h | 6 +----- tools/tests/x86_emulator/x86-emulate.h | 5 ----- tools/xenstore/list.h | 6 ++---- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tools/include/xen-tools/libs.h b/tools/include/xen-tools/libs.h index bafc90e2f6..3672486daa 100644 --- a/tools/include/xen-tools/libs.h +++ b/tools/include/xen-tools/libs.h @@ -67,4 +67,8 @@ #define __must_check __attribute__((__warn_unused_result__)) #endif =20 +#define container_of(ptr, type, member) ({ \ + typeof( ((type *)0)->member ) *__mptr =3D (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + #endif /* __XEN_TOOLS_LIBS__ */ diff --git a/tools/tests/vhpet/emul.h b/tools/tests/vhpet/emul.h index b022cc0eab..7db47c5beb 100644 --- a/tools/tests/vhpet/emul.h +++ b/tools/tests/vhpet/emul.h @@ -125,9 +125,6 @@ enum #define max_t(type, x, y) \ ({ type __x =3D (x); type __y =3D (y); __x > __y ? __x : __y; }) #define offsetof(t, m) ((unsigned long )&((t *)0)->m) -#define container_of(ptr, type, member) ({ \ - typeof( ((type *)0)->member ) *__mptr =3D (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) ); }) =20 struct domain; =20 diff --git a/tools/tests/vpci/emul.h b/tools/tests/vpci/emul.h index f03e3a56d1..237edb4e95 100644 --- a/tools/tests/vpci/emul.h +++ b/tools/tests/vpci/emul.h @@ -27,11 +27,7 @@ #include #include =20 -#define container_of(ptr, type, member) ({ \ - typeof(((type *)0)->member) *mptr =3D (ptr); \ - \ - (type *)((char *)mptr - offsetof(type, member)); \ -}) +#include =20 #define smp_wmb() #define prefetch(x) __builtin_prefetch(x) diff --git a/tools/tests/x86_emulator/x86-emulate.h b/tools/tests/x86_emula= tor/x86-emulate.h index 18ae40d017..0849c07dbc 100644 --- a/tools/tests/x86_emulator/x86-emulate.h +++ b/tools/tests/x86_emulator/x86-emulate.h @@ -56,11 +56,6 @@ =20 #define cf_check /* No Control Flow Integriy checking */ =20 -#define container_of(ptr, type, member) ({ \ - typeof(((type *)0)->member) *mptr__ =3D (ptr); \ - (type *)((char *)mptr__ - offsetof(type, member)); \ -}) - #define AC_(n,t) (n##t) #define _AC(n,t) AC_(n,t) =20 diff --git a/tools/xenstore/list.h b/tools/xenstore/list.h index b17d13e0ec..1f469eafaf 100644 --- a/tools/xenstore/list.h +++ b/tools/xenstore/list.h @@ -3,6 +3,8 @@ /* Taken from Linux kernel code, but de-kernelized for userspace. */ #include =20 +#include + #undef LIST_HEAD_INIT #undef LIST_HEAD #undef INIT_LIST_HEAD @@ -15,10 +17,6 @@ #define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON2 ((void *) 0x00200200) =20 -#define container_of(ptr, type, member) ({ \ - typeof( ((type *)0)->member ) *__mptr =3D (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - /* * Simple doubly linked list implementation. * --=20 2.35.3