From patchwork Thu Jan 20 12:36:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 533560 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1758186imu; Thu, 20 Jan 2022 09:01:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMxmO+gUDdigqibQfELfSagVm4373MQIpzRXT/d2maLOFHhmVCOUFcVVXwt6f2y2emfXAv X-Received: by 2002:a25:4205:: with SMTP id p5mr16851300yba.622.1642698081432; Thu, 20 Jan 2022 09:01:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642698081; cv=none; d=google.com; s=arc-20160816; b=YEkMsAc1KSuYR6H6GpZAr1S7n/LwDQS8CxBRT1ix06/9KirCYHBmKVWa4WSMid2CO3 gfqCMLC9TO94n5k0/rzvjB7jcqBVtaAtiu7IngyCvEDXI/4NsQqY3/a6WKDXslcRz/Bs WQY8iHp8zxZ9xwSjEaWVKc6pWs1yMn1+J8PyfDg6hoTSZ8svhzGlisnR0nd6/vjdwRDk TwVCpslSUV1y0EQ+yoDeDoRcO7owXVI5K2ibhymZLld8pEAryT1/WEUSMP3zgXdkZeQj BXescVAGc4rDg1vJWl2Wg8chsvBRZqAUdUmklbYx7CQyQw6SE/VoMmeZsAGWueLvhivu AKFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:to:from :dkim-signature; bh=OmJMxXznZtS6wxSHqrH87o5Ap9DXYL7I0ggwF5gqjkw=; b=pU5XH5IyI6kfmebg52XNUgRAUT5GF0KCMuFCzXzv215pZQGtCUwaXoEJ4vLTeLw8Zz 7OhEiJ7kHBrvelQcBUmWqoUT2sRPTF7N+bwaShfUciQYGKRyDOPCCPEtcaL3h1YE0wN4 flT61nGjkyuH4jhgn558wR718QnZ5a7DiNSA270CYIV0VRrygHmsSmbySr9h15e+s6zB 8hxP3t4EMyE3+spadtk2uWmiG7ezi/Pn8QeijTe90Drgdg6NMaHHb/OXYJ+qpbJoAy4b gg9LiEuVq+iOlKds7NjLG7Gpz+Z5i1YaRRQVPKcfq/8d+DclF5jloE+MM0if8f5WlQzI HLPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NEEkt/Xk"; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j11si3259361ybj.264.2022.01.20.09.01.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jan 2022 09:01:21 -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="NEEkt/Xk"; 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 Received: from localhost ([::1]:55506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAaoK-0006XO-Nz for patch@linaro.org; Thu, 20 Jan 2022 12:01:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAWgm-0004Jq-3q for qemu-devel@nongnu.org; Thu, 20 Jan 2022 07:37:16 -0500 Received: from [2a00:1450:4864:20::329] (port=44979 helo=mail-wm1-x329.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAWgi-0003Jf-Nw for qemu-devel@nongnu.org; Thu, 20 Jan 2022 07:37:15 -0500 Received: by mail-wm1-x329.google.com with SMTP id l35-20020a05600c1d2300b0034d477271c1so13353929wms.3 for ; Thu, 20 Jan 2022 04:37:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OmJMxXznZtS6wxSHqrH87o5Ap9DXYL7I0ggwF5gqjkw=; b=NEEkt/XkeLRErhDUz+LFpWSKSzuj+wyvUehnwiBfb3R0pfjXHspkXuUQTtQ+Xeyzom sOqFI9TglvY7kV4sQBiYm0pwGz3JUhhoMFuWiWIoqTDpCrtfhP6DKlFBAkPuWCL6Wb+8 4k1dL5duvYDvLnCqIjQFTX+q0eOqfyk2M9jt+4m6eSFtGNVE7KJDIxDee83wrer8K8zI 7SNOnD17HbHKDkbCmaMXkbKHPlp+gS1eE4WDmMZFiDdjbYI16LifzEMavAvzaqLpLXvF yJP6b6S94iSjga1yRfjWtCPcTPssaiUxDzHrDrnIgwUbH8iMXYjgagM9ERJYxd/sGPP+ SRbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OmJMxXznZtS6wxSHqrH87o5Ap9DXYL7I0ggwF5gqjkw=; b=pr1H7CsxMgIL5aWTcPeIl5oCj9t6LpDBrfRHMgnZn8f0H3FVvp+eYbnsEc+cQUjjBh C1WJ0jOCKVl8u1FS2fHmDHGqhwJCtizuWwrEF2M1Y7QC+jyA8xaU40p7XDZGMBA7IgWM 7cW/g/t4bjOUnQnbgFbrkdbpr1JiOma/pGu1gpMfNl3Gk9JWJBKiSe19PCg5SJK9XsDC KgP7r9bkVD8e1a/heVuw6USt51faW8JsaudgYFq0b3sAebrPBZGI1834rREJYB2RQPem +S23p67cTs1Bn2k75xIcGPufN80Gflv9+oiIvsFaUTUBDAHJDLv0Dpy90hsBbTgwelea OiFA== X-Gm-Message-State: AOAM533H/DfXGHWQG5Rpz2KfWXqQ5j7Z3fHADPNN+ijmuD3Yaihc14xI 5inOsmaivpa0/Vsa8HRhNnuclZ+Tw69FEg== X-Received: by 2002:a05:6000:154c:: with SMTP id 12mr18212812wry.380.1642682226544; Thu, 20 Jan 2022 04:37:06 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t8sm7993324wmq.43.2022.01.20.04.37.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 04:37:06 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 31/38] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting Date: Thu, 20 Jan 2022 12:36:23 +0000 Message-Id: <20220120123630.267975-32-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220120123630.267975-1-peter.maydell@linaro.org> References: <20220120123630.267975-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::329 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" Refactor process_its_cmd() so that it consistently uses the structure do thing; if (error condition) { return early; } do next thing; rather than doing some of the work nested inside if (not error) code blocks. Signed-off-by: Peter Maydell Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20220111171048.3545974-8-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 103 +++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 0929116c0fe..5dc6846fe3f 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -273,79 +273,76 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, } dte_valid = FIELD_EX64(dte, DTE, VALID); - if (dte_valid) { - num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); - - ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res); - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - if (ite_valid) { - cte_valid = get_cte(s, icid, &cte, &res); - } - - if (res != MEMTX_OK) { - return CMD_STALL; - } - } else { + if (!dte_valid) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " - "invalid dte: %"PRIx64" for %d (MEM_TX: %d)\n", - __func__, dte, devid, res); + "invalid dte: %"PRIx64" for %d\n", + __func__, dte, devid); return CMD_CONTINUE; } + num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); + + ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res); + if (res != MEMTX_OK) { + return CMD_STALL; + } + + if (!ite_valid) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: invalid ITE\n", + __func__); + return CMD_CONTINUE; + } + + cte_valid = get_cte(s, icid, &cte, &res); + if (res != MEMTX_OK) { + return CMD_STALL; + } + if (!cte_valid) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: " + "invalid cte: %"PRIx64"\n", + __func__, cte); + return CMD_CONTINUE; + } - /* - * In this implementation, in case of guest errors we ignore the - * command and move onto the next command in the queue. - */ if (devid >= s->dt.num_ids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: devid %d>=%d", __func__, devid, s->dt.num_ids); return CMD_CONTINUE; - } else if (!dte_valid || !ite_valid || !cte_valid) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: " - "dte: %s, ite: %s, cte: %s\n", - __func__, - dte_valid ? "valid" : "invalid", - ite_valid ? "valid" : "invalid", - cte_valid ? "valid" : "invalid"); - return CMD_CONTINUE; - } else if (eventid >= num_eventids) { + } + if (eventid >= num_eventids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: eventid %d >= %" PRId64 "\n", __func__, eventid, num_eventids); return CMD_CONTINUE; - } else { - /* - * Current implementation only supports rdbase == procnum - * Hence rdbase physical address is ignored - */ - rdbase = FIELD_EX64(cte, CTE, RDBASE); + } - if (rdbase >= s->gicv3->num_cpu) { - return CMD_CONTINUE; - } + /* + * Current implementation only supports rdbase == procnum + * Hence rdbase physical address is ignored + */ + rdbase = FIELD_EX64(cte, CTE, RDBASE); - if ((cmd == CLEAR) || (cmd == DISCARD)) { - gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0); - } else { - gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1); - } - - if (cmd == DISCARD) { - IteEntry ite = {}; - /* remove mapping from interrupt translation table */ - return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; - } + if (rdbase >= s->gicv3->num_cpu) { return CMD_CONTINUE; } + + if ((cmd == CLEAR) || (cmd == DISCARD)) { + gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0); + } else { + gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1); + } + + if (cmd == DISCARD) { + IteEntry ite = {}; + /* remove mapping from interrupt translation table */ + return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; + } + return CMD_CONTINUE; } static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,