From patchwork Fri Oct 13 07:47:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 13420238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 563AFCDB47E for ; Fri, 13 Oct 2023 07:51:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrCvg-0004Bk-L5; Fri, 13 Oct 2023 03:49:52 -0400 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 1qrCvc-0004AW-CE for qemu-devel@nongnu.org; Fri, 13 Oct 2023 03:49:48 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrCvW-00043f-AP for qemu-devel@nongnu.org; Fri, 13 Oct 2023 03:49:48 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4066241289bso19037125e9.0 for ; Fri, 13 Oct 2023 00:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697183380; x=1697788180; 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=WLlr5rM7K7HFMOYaMZw1hwvaelBo6N2zKwQvcIMTzLA=; b=aIoAMCMyn+5tj1twT6Q/jFL29e373pXlJpEjRVKdUMJ9oqvryhw5zMEDtfL61TVFUq mFsbedIo4EeAkbCoB/bnmwny4yW9vFrUmZPc/4VSr7MQE3iiIkNkLN8hSEZ4apFjr7Zc zpr3pzjE7gYdt+2z3huA3PAJVF1ZBiWrUMKhnm4IBYq8Xtmkiy70EZJ3M9NZWJnuhj8F 46sJEgeZCN4kCF5nAboDO4Kqbc1XVhXnOGveerfurcYv+gl/Rw2vM8rnX/3Llr6yLVLE 4t7PBWkgRY/lKDuf7kPw/XjzljgHwEbb4VSbtGNaXtE5JN3dXm8JtFBd35F7pf4vyiQp wzKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697183380; x=1697788180; 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=WLlr5rM7K7HFMOYaMZw1hwvaelBo6N2zKwQvcIMTzLA=; b=PyGcNXu+WcMPdV441szhQLelHJJitpuohbcO+MYXjjLf5/ZKPQdaDL3+JHAvOsIMCi Erw+jSwUjIVX8fa0ezyv3yu+KT2DCk/GiDITlnmBeHkS/2X2G+iE1hNtC1fWujsria+6 YSx60t8+UMjREKd48dafLI6t+G3B3XuWfD+EVY69KpF0IrS6aW4w2XCNjLnraqpJNqvp Y7dzaH4/U0i1atWaNkkB84MlbDrKnDbcj9gCxsVTZS1auYIB+w6XcbwJRTcVA7MWeneK ERWTXbealTadEtD2iOfOAKpm1y9hAbSvjE5zfGNXNmV1lUbX+vtZqnbZXlmCH62JczeK jx3A== X-Gm-Message-State: AOJu0YwnbEL4En78vL9RC2RuTm9JF+5UO//X0PIA//Is1Qvm2Sy0QwiI BbYyOCHtIH3ikO2+U22GX+xo8I5dSUaRxqYh1kc= X-Google-Smtp-Source: AGHT+IEAzlVEPkj4W+fpne4f9k3Fs0QGLPylRgEbh614MOjSVMZQUSPj32cGAmMn4IDhYhfNU7BpYg== X-Received: by 2002:a05:600c:28c:b0:405:e492:8aef with SMTP id 12-20020a05600c028c00b00405e4928aefmr23009846wmk.40.1697183380279; Fri, 13 Oct 2023 00:49:40 -0700 (PDT) Received: from localhost.localdomain (adsl-170.109.242.226.tellas.gr. [109.242.226.170]) by smtp.gmail.com with ESMTPSA id m8-20020adfa3c8000000b0032d7fde2d3csm7990663wrb.79.2023.10.13.00.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 00:49:39 -0700 (PDT) From: Emmanouil Pitsidianakis To: qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-block@nongnu.org Cc: Emmanouil Pitsidianakis , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Eric Auger , Peter Maydell , Song Gao , Xiaojuan Yang , Richard Henderson Subject: [RFC PATCH 01/78] include/qemu/compiler.h: replace QEMU_FALLTHROUGH with fallthrough Date: Fri, 13 Oct 2023 10:47:05 +0300 Message-Id: <2e08cff874b2f9fc4143bdcde87ebba9b70b356c.1697183082.git.manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm1-x32e.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=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Emmanouil Pitsidianakis --- audio/pwaudio.c | 8 ++++---- hw/arm/smmuv3.c | 2 +- include/qemu/compiler.h | 30 +++++++++++++++++++++++------- include/qemu/osdep.h | 4 ++-- target/loongarch/cpu.c | 4 ++-- target/loongarch/translate.c | 2 +- tcg/optimize.c | 8 ++++---- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/audio/pwaudio.c b/audio/pwaudio.c index 3ce5f6507b..bf26fadb06 100644 --- a/audio/pwaudio.c +++ b/audio/pwaudio.c @@ -1,29 +1,29 @@ /* * QEMU PipeWire audio driver * * Copyright (c) 2023 Red Hat Inc. * * Author: Dorinda Bassey * * SPDX-License-Identifier: GPL-2.0-or-later */ +#include +#include +#include +#include #include "qemu/osdep.h" #include "qemu/module.h" #include "audio.h" #include #include "qemu/error-report.h" #include "qapi/error.h" -#include -#include -#include -#include #include #include "trace.h" #define AUDIO_CAP "pipewire" #define RINGBUFFER_SIZE (1u << 22) #define RINGBUFFER_MASK (RINGBUFFER_SIZE - 1) #include "audio_int.h" diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 6f2b2bd45f..545d82ff04 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1166,210 +1166,210 @@ smmuv3_invalidate_ste(gpointer key, gpointer value, gpointer user_data) static int smmuv3_cmdq_consume(SMMUv3State *s) { SMMUState *bs = ARM_SMMU(s); SMMUCmdError cmd_error = SMMU_CERROR_NONE; SMMUQueue *q = &s->cmdq; SMMUCommandType type = 0; if (!smmuv3_cmdq_enabled(s)) { return 0; } /* * some commands depend on register values, typically CR0. In case those * register values change while handling the command, spec says it * is UNPREDICTABLE whether the command is interpreted under the new * or old value. */ while (!smmuv3_q_empty(q)) { uint32_t pending = s->gerror ^ s->gerrorn; Cmd cmd; trace_smmuv3_cmdq_consume(Q_PROD(q), Q_CONS(q), Q_PROD_WRAP(q), Q_CONS_WRAP(q)); if (FIELD_EX32(pending, GERROR, CMDQ_ERR)) { break; } if (queue_read(q, &cmd) != MEMTX_OK) { cmd_error = SMMU_CERROR_ABT; break; } type = CMD_TYPE(&cmd); trace_smmuv3_cmdq_opcode(smmu_cmd_string(type)); qemu_mutex_lock(&s->mutex); switch (type) { case SMMU_CMD_SYNC: if (CMD_SYNC_CS(&cmd) & CMD_SYNC_SIG_IRQ) { smmuv3_trigger_irq(s, SMMU_IRQ_CMD_SYNC, 0); } break; case SMMU_CMD_PREFETCH_CONFIG: case SMMU_CMD_PREFETCH_ADDR: break; case SMMU_CMD_CFGI_STE: { uint32_t sid = CMD_SID(&cmd); IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid); SMMUDevice *sdev; if (CMD_SSEC(&cmd)) { cmd_error = SMMU_CERROR_ILL; break; } if (!mr) { break; } trace_smmuv3_cmdq_cfgi_ste(sid); sdev = container_of(mr, SMMUDevice, iommu); smmuv3_flush_config(sdev); break; } case SMMU_CMD_CFGI_STE_RANGE: /* same as SMMU_CMD_CFGI_ALL */ { uint32_t sid = CMD_SID(&cmd), mask; uint8_t range = CMD_STE_RANGE(&cmd); SMMUSIDRange sid_range; if (CMD_SSEC(&cmd)) { cmd_error = SMMU_CERROR_ILL; break; } mask = (1ULL << (range + 1)) - 1; sid_range.start = sid & ~mask; sid_range.end = sid_range.start + mask; trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, sid_range.end); g_hash_table_foreach_remove(bs->configs, smmuv3_invalidate_ste, &sid_range); break; } case SMMU_CMD_CFGI_CD: case SMMU_CMD_CFGI_CD_ALL: { uint32_t sid = CMD_SID(&cmd); IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid); SMMUDevice *sdev; if (CMD_SSEC(&cmd)) { cmd_error = SMMU_CERROR_ILL; break; } if (!mr) { break; } trace_smmuv3_cmdq_cfgi_cd(sid); sdev = container_of(mr, SMMUDevice, iommu); smmuv3_flush_config(sdev); break; } case SMMU_CMD_TLBI_NH_ASID: { uint16_t asid = CMD_ASID(&cmd); if (!STAGE1_SUPPORTED(s)) { cmd_error = SMMU_CERROR_ILL; break; } trace_smmuv3_cmdq_tlbi_nh_asid(asid); smmu_inv_notifiers_all(&s->smmu_state); smmu_iotlb_inv_asid(bs, asid); break; } case SMMU_CMD_TLBI_NH_ALL: if (!STAGE1_SUPPORTED(s)) { cmd_error = SMMU_CERROR_ILL; break; } - QEMU_FALLTHROUGH; + fallthrough; case SMMU_CMD_TLBI_NSNH_ALL: trace_smmuv3_cmdq_tlbi_nh(); smmu_inv_notifiers_all(&s->smmu_state); smmu_iotlb_inv_all(bs); break; case SMMU_CMD_TLBI_NH_VAA: case SMMU_CMD_TLBI_NH_VA: if (!STAGE1_SUPPORTED(s)) { cmd_error = SMMU_CERROR_ILL; break; } smmuv3_range_inval(bs, &cmd); break; case SMMU_CMD_TLBI_S12_VMALL: { uint16_t vmid = CMD_VMID(&cmd); if (!STAGE2_SUPPORTED(s)) { cmd_error = SMMU_CERROR_ILL; break; } trace_smmuv3_cmdq_tlbi_s12_vmid(vmid); smmu_inv_notifiers_all(&s->smmu_state); smmu_iotlb_inv_vmid(bs, vmid); break; } case SMMU_CMD_TLBI_S2_IPA: if (!STAGE2_SUPPORTED(s)) { cmd_error = SMMU_CERROR_ILL; break; } /* * As currently only either s1 or s2 are supported * we can reuse same function for s2. */ smmuv3_range_inval(bs, &cmd); break; case SMMU_CMD_TLBI_EL3_ALL: case SMMU_CMD_TLBI_EL3_VA: case SMMU_CMD_TLBI_EL2_ALL: case SMMU_CMD_TLBI_EL2_ASID: case SMMU_CMD_TLBI_EL2_VA: case SMMU_CMD_TLBI_EL2_VAA: case SMMU_CMD_ATC_INV: case SMMU_CMD_PRI_RESP: case SMMU_CMD_RESUME: case SMMU_CMD_STALL_TERM: trace_smmuv3_unhandled_cmd(type); break; default: cmd_error = SMMU_CERROR_ILL; break; } qemu_mutex_unlock(&s->mutex); if (cmd_error) { if (cmd_error == SMMU_CERROR_ILL) { qemu_log_mask(LOG_GUEST_ERROR, "Illegal command type: %d\n", CMD_TYPE(&cmd)); } break; } /* * We only increment the cons index after the completion of * the command. We do that because the SYNC returns immediately * and does not check the completion of previous commands */ queue_cons_incr(q); } if (cmd_error) { trace_smmuv3_cmdq_consume_error(smmu_cmd_string(type), cmd_error); smmu_write_cmdq_err(s, cmd_error); smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, R_GERROR_CMDQ_ERR_MASK); } trace_smmuv3_cmdq_consume_out(Q_PROD(q), Q_CONS(q), Q_PROD_WRAP(q), Q_CONS_WRAP(q)); return 0; } diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 1109482a00..959982805d 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -1,215 +1,231 @@ /* compiler.h: macros to abstract away compiler specifics * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ #ifndef COMPILER_H #define COMPILER_H #define HOST_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) /* HOST_LONG_BITS is the size of a native pointer in bits. */ #define HOST_LONG_BITS (__SIZEOF_POINTER__ * 8) #if defined __clang_analyzer__ || defined __COVERITY__ #define QEMU_STATIC_ANALYSIS 1 #endif #ifdef __cplusplus #define QEMU_EXTERN_C extern "C" #else #define QEMU_EXTERN_C extern #endif #if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__)) # define QEMU_PACKED __attribute__((gcc_struct, packed)) #else # define QEMU_PACKED __attribute__((packed)) #endif #define QEMU_ALIGNED(X) __attribute__((aligned(X))) #ifndef glue #define xglue(x, y) x ## y #define glue(x, y) xglue(x, y) #define stringify(s) tostring(s) #define tostring(s) #s #endif /* Expands into an identifier stemN, where N is another number each time */ #define MAKE_IDENTFIER(stem) glue(stem, __COUNTER__) #ifndef likely #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #endif #ifndef container_of #define container_of(ptr, type, member) ({ \ const typeof(((type *) 0)->member) *__mptr = (ptr); \ (type *) ((char *) __mptr - offsetof(type, member));}) #endif #define sizeof_field(type, field) sizeof(((type *)0)->field) /* * Calculate the number of bytes up to and including the given 'field' of * 'container'. */ #define endof(container, field) \ (offsetof(container, field) + sizeof_field(container, field)) /* Convert from a base type to a parent type, with compile time checking. */ #define DO_UPCAST(type, field, dev) ( __extension__ ( { \ char __attribute__((unused)) offset_must_be_zero[ \ -offsetof(type, field)]; \ container_of(dev, type, field);})) #define typeof_field(type, field) typeof(((type *)0)->field) #define type_check(t1,t2) ((t1*)0 - (t2*)0) #define QEMU_BUILD_BUG_ON_STRUCT(x) \ struct { \ int:(x) ? -1 : 1; \ } #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg) #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x) #define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \ sizeof(QEMU_BUILD_BUG_ON_STRUCT(x))) #if !defined(__clang__) && defined(_WIN32) /* * Map __printf__ to __gnu_printf__ because we want standard format strings even * when MinGW or GLib include files use __printf__. */ # define __printf__ __gnu_printf__ #endif #ifndef __has_warning #define __has_warning(x) 0 /* compatibility with non-clang compilers */ #endif #ifndef __has_feature #define __has_feature(x) 0 /* compatibility with non-clang compilers */ #endif #ifndef __has_builtin #define __has_builtin(x) 0 /* compatibility with non-clang compilers */ #endif #if __has_builtin(__builtin_assume_aligned) || !defined(__clang__) #define HAS_ASSUME_ALIGNED #endif #ifndef __has_attribute #define __has_attribute(x) 0 /* compatibility with older GCC */ #endif #if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) # define QEMU_SANITIZE_ADDRESS 1 #endif #if defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer) # define QEMU_SANITIZE_THREAD 1 #endif /* * GCC doesn't provide __has_attribute() until GCC 5, but we know all the GCC * versions we support have the "flatten" attribute. Clang may not have the * "flatten" attribute but always has __has_attribute() to check for it. */ #if __has_attribute(flatten) || !defined(__clang__) # define QEMU_FLATTEN __attribute__((flatten)) #else # define QEMU_FLATTEN #endif /* * If __attribute__((error)) is present, use it to produce an error at * compile time. Otherwise, one must wait for the linker to diagnose * the missing symbol. */ #if __has_attribute(error) # define QEMU_ERROR(X) __attribute__((error(X))) #else # define QEMU_ERROR(X) #endif /* * The nonstring variable attribute specifies that an object or member * declaration with type array of char or pointer to char is intended * to store character arrays that do not necessarily contain a terminating * NUL character. This is useful in detecting uses of such arrays or pointers * with functions that expect NUL-terminated strings, and to avoid warnings * when such an array or pointer is used as an argument to a bounded string * manipulation function such as strncpy. */ #if __has_attribute(nonstring) # define QEMU_NONSTRING __attribute__((nonstring)) #else # define QEMU_NONSTRING #endif /* * Forced inlining may be desired to encourage constant propagation * of function parameters. However, it can also make debugging harder, * so disable it for a non-optimizing build. */ #if defined(__OPTIMIZE__) #define QEMU_ALWAYS_INLINE __attribute__((always_inline)) #else #define QEMU_ALWAYS_INLINE #endif -/** - * In most cases, normal "fallthrough" comments are good enough for - * switch-case statements, but sometimes the compiler has problems - * with those. In that case you can use QEMU_FALLTHROUGH instead. +/* + * Add the pseudo keyword 'fallthrough' so case statement blocks + * must end with any of these keywords: + * break; + * fallthrough; + * continue; + * goto