From patchwork Fri Jan 10 20:34:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 856287 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp416259wrc; Fri, 10 Jan 2025 12:35:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW0jFw2O+LbhbtrXH+04njwQYa9n8rXI8fmIO8rqu/Yo1H9/NRrPXeRRe5QwLBNVnVJ6J81dA==@linaro.org X-Google-Smtp-Source: AGHT+IFvCd/s1NMxxkg2JSgPxxm4ntBC2DYdShmKYZ8FRqTQiygKxZ1rDt9tOQ6ewwRM8F/Z7LLH X-Received: by 2002:ac8:580a:0:b0:466:ad0d:f0ca with SMTP id d75a77b69052e-46c7108edb5mr230586221cf.50.1736541323516; Fri, 10 Jan 2025 12:35:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736541323; cv=none; d=google.com; s=arc-20240605; b=GeUIn25jSnQsXT1LVP9WFGJ5Smii8b4/NjGGbarcGeavGgjHRznIL9LSiDXyZwPLA/ qdLSzo0W1lPrbmQuWyo7nIwv3uUS48xgwaVVUk7cgVH+42bPAj4HlavuzE6QCZBow3Nf SNLsrxqrP4g7O/+3jFF9VNh7kpbJpz8kyYs/5w1xWCF74dYfYvMCYEnQEr7jJ2x3CaeI DltoG9ambVcOUSdObUDIj31L7pI2Qli6IWPFH86KD78zxBGUgCt0tcYrloyVFB5FaWvy DNRPeNRR3qZs7Ak8xBEKOHIfZSS9wWep9UjjQKQFK8jVL17GT6huKaDBLX9b5VSs8uZ1 UI5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=g9R9dQpF5UbzJZ6Kb11hyvYzYtKnLXxRBjcuMGn4NXM=; fh=osDf24rzdulpcwbZBTbZONJdn+PQhsfeRkrfsSE4xK0=; b=D9S+OHZkLgeQb+nSZHawvYbFOk6mPBNMHNs01nPR0RmebitfyBkxvZcAS5GXqeftfN Qi5GkVsqcyBS8Mb3ODaM3KqeT8TGoCWmsQehWAa6ycJkT3DNLbXkIDMXkvnzZNsGs1BY ZWaJCrvIVckOmJ+IkvnZ5XU5yUNHsx0Ud2s5a5U1ydhFXK3OP9j1p4qe/d+fFKXap158 sxW2rzzTMGkBY6p258SVdIAcDf9F9bey6vT2c4Tvp8uq6iAhQNwBgp37l7Qzer9kIRv2 W3RD2+ELi6JOFWESjrF2Jl0fAHwMaVKIgMUpcrP0MY0dB9LFY5bs32QHyCZfzE4cRm8L y2rQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VtIpE3p5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-46c873fae64si31131281cf.384.2025.01.10.12.35.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jan 2025 12:35:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VtIpE3p5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWLhz-0000WE-S4; Fri, 10 Jan 2025 15:34: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 1tWLhw-0000VK-Tv for qemu-devel@nongnu.org; Fri, 10 Jan 2025 15:34:16 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWLhv-0005f2-4Z for qemu-devel@nongnu.org; Fri, 10 Jan 2025 15:34:16 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2165cb60719so44203015ad.0 for ; Fri, 10 Jan 2025 12:34:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736541253; x=1737146053; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g9R9dQpF5UbzJZ6Kb11hyvYzYtKnLXxRBjcuMGn4NXM=; b=VtIpE3p59kQ0rOFVvsvhaAI+1nZgwi+N18g5A94+9znPjDvH9aWuheNf3HW896hPFJ FjAOibPt0pYM3F8aTPp/NJqg/oShxQs+kUeSFStQS/CYtCEAgZBSWKCICA/HtTURvaCR 6GGR3bKZp46zX/60Mw0GYsbTg+RJYfG6/C9S7XjcpHzOdZguJzKVCNV0KG3Lji5oL0+Z G9qNQIJ8iu/9n7NOVZGs864I2EbQHx07utJydSJvORos2dtnFz3odLzbcovAEV5lOZcg ZBiEtROVJwIX1LOFy4QDzeSAmNQSc0kWuGEHMu052IaGa2/Z0zzdYDamVwVW8VFqumcs ipiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736541253; x=1737146053; 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=g9R9dQpF5UbzJZ6Kb11hyvYzYtKnLXxRBjcuMGn4NXM=; b=X20JFfmV5aWRlwpLwHZAbhEf15tpts1uWQACgjnv9D90H4M4bzaDeuB4TZpWloWDHA 6tO1EyxNmLVC+ud0KXPIoOQ2rTRe5ixMUH/vckyFTqsb5BCTDTI9OMIrXAR1AMTiBjJK 7ROFQ7N5deTFEbbjE9Hvd/hiDLxWMh/MmsISdyVfUwO69XV8Cba39LJHghrOQvTmUxxK pjepPhkhG7a/QDx1FQIwhaCi2fdWDH+jHXn5G3ptgyWl0ermTyVCbkETIf/nTGGCUsCf jj5k0sLOnAfwoFWfHSnkgKN1irFuyBvzunpywAkc3rt9EZYLJYDfCBGXw7lilBfWXgX+ FgMA== X-Gm-Message-State: AOJu0Yw/1OzLZw1ks9rFCmMUdbQmUgaf0n9xCsiMDi169wWC6hVTlklE K1UVlFHORw6gEeRIWVoHhxnTbiC2vjN5IkR7w3NqmkpD1ZP91t2wDvTOjk20K8o4WvkSVhWdyx1 ujwVCgA== X-Gm-Gg: ASbGncs0q0UM1DisrQSLMpnk6/IYSmS7zyiDsUxl4ecp9TiiIyJZ0JBs+u1K0Cfqr3V jli9Kgl6siQb1w5c8r4ArGFZa6Q6Ec+7dJ44kmhkkO2CVejMhwSoSHil62vFQ7WVQbPZrMaOOH7 l6Jtsq6N2g8EXJ9qJeDZhbfRBgHuBWb0tFU1Dx+ItyoOzs/j1Ua3q0SFuM1WYfnz+hTaTikBnhZ mGv/Fo3g4VM92v1hNlwQYfGdtuqLveV6B8Ncl/+YTJss+4qgaD1eWvQ X-Received: by 2002:aa7:88cd:0:b0:725:f097:ed21 with SMTP id d2e1a72fcca58-72d21f471d6mr17088257b3a.15.1736541253266; Fri, 10 Jan 2025 12:34:13 -0800 (PST) Received: from pc.. ([38.39.164.180]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a318e8ecacfsm3215947a12.38.2025.01.10.12.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 12:34:12 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Mahmoud Mandour , Markus Armbruster , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Thomas Huth , Paolo Bonzini , Pierrick Bouvier , Stefano Garzarella , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , "Michael S. Tsirkin" , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Alexandre Iooss , Richard Henderson Subject: [PATCH v4 2/3] docs/devel/style: add a section about bitfield, and disallow them for packed structures Date: Fri, 10 Jan 2025 12:34:00 -0800 Message-Id: <20250110203401.178532-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110203401.178532-1-pierrick.bouvier@linaro.org> References: <20250110203401.178532-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- docs/devel/style.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 2f68b500798..d025933808e 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -416,6 +416,26 @@ definitions instead of typedefs in headers and function prototypes; this avoids problems with duplicated typedefs and reduces the need to include headers from other headers. +Bitfields +--------- + +C bitfields can be a cause of non-portability issues, especially under windows +where `MSVC has a different way to lay them out than GCC +`_, or where +endianness matters. + +For this reason, we disallow usage of bitfields in packed structures and in any +structures which are supposed to exactly match a specific layout in guest +memory. Some existing code may use it, and we carefully ensured the layout was +the one expected. + +We also suggest avoiding bitfields even in structures where the exact +layout does not matter, unless you can show that they provide a significant +usability benefit. + +We encourage the usage of ``include/hw/registerfields.h`` as a safe replacement +for bitfields. + Reserved namespaces in C and POSIX ----------------------------------