From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641921786814910.4182573435437; Tue, 11 Jan 2022 09:23:06 -0800 (PST) Received: from localhost ([::1]:57510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7KrR-00025k-Pr for importer@patchew.org; Tue, 11 Jan 2022 12:23:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kff-0005AV-NN for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:56 -0500 Received: from [2a00:1450:4864:20::42b] (port=41770 helo=mail-wr1-x42b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfe-0007HR-2r for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:55 -0500 Received: by mail-wr1-x42b.google.com with SMTP id v6so34157753wra.8 for ; Tue, 11 Jan 2022 09:10:52 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ob5bbn/w0TzbvNqJivAvBR3jtD/48+Yhebkf8RVzKMw=; b=sWVfeHV953skZ1ANSKtB6LVaJUAudCwVCsUQs+r8/tdWImub794kbVVD3TW1Opdqed 9TfNlbHkP6MPWkT8mstz6mmXvnb/vAkns130luOY4YUZiyW5TOLZxYryuQeT4kSiWNql 135tWjwhc6Wvk9DnHXG74LTAJu97ZKHm6aF4UsDscpnT6pE8ZRPmBlI5ZpNFPk46ZXWl G+NPPFsxqr/kGaIfATL2Y++B3o6dKYEO/mV+ut3avaXtfh6ldGyTXeKCKaz0jM5NZqdL ewkV+j0LzkBLV8mbRbNUTKa9tX37Fn6Oz/Oqi2ND6V66W3vEawcLQ3+goAW3nbt+CeIg teWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ob5bbn/w0TzbvNqJivAvBR3jtD/48+Yhebkf8RVzKMw=; b=Ztus0ilw6ciVLNOacqMoBtvKFsOczhgzNCbm1wseiPATYrzICrEvU1p8cz6O/NHp0K Zsh9j0ppik+1XoBOUF3Fjz+C/vZookZqs0FTVESwmzr6+fyIJKL2IVRE5bk4UwsrRXBg bhDEJiDvNYXziz432bBGpMByVFgrCM4yYFin149go7SPhGBkveKGDR0My9KTZsFLPVqG 26Ld3qFlXyk6Dv19jJxOi9pVfeSPsTDenmhTlzHZW3ZBa0A/0zhSRwhYYQj+Fz8KC9xm OAl/s8cp/lHLhl+AtX2u9KF61IUrMDLQXk+rnkx71HcpXgknjzJWlEgho1rAPbHq8aGK PuXA== X-Gm-Message-State: AOAM530YaZfO0TPpG7SZXW5NLgxB6YaUUlGf0N6wX8wvNs+QzW8wmynv gk6iqwFyqraeIur4ULCMoZbNew== X-Google-Smtp-Source: ABdhPJz+6tiYN8uN+ZbhGRQryNbfTu0AoimJeMiEJLMOi/9RtBm49pzsvfHk65PpTpam9N0/qNZdXQ== X-Received: by 2002:a05:6000:1883:: with SMTP id a3mr4811160wri.565.1641921051657; Tue, 11 Jan 2022 09:10:51 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 01/13] hw/intc/arm_gicv3_its: Fix event ID bounds checks Date: Tue, 11 Jan 2022 17:10:36 +0000 Message-Id: <20220111171048.3545974-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42b (failed) 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=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641921788970100001 Content-Type: text/plain; charset="utf-8" In process_its_cmd() and process_mapti() we must check the event ID against a limit defined by the size field in the DTE, which specifies the number of ID bits minus one. Convert this code to our num_foo convention: * change the variable names * use uint64_t and 1ULL when calculating the number of valid event IDs, because DTE.SIZE is 5 bits and so num_eventids may be up to 2^32 * fix the off-by-one error in the comparison Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index fa3cdb57554..6d11fa02040 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -225,7 +225,7 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t = value, uint32_t offset, MemTxResult res =3D MEMTX_OK; bool dte_valid; uint64_t dte =3D 0; - uint32_t max_eventid; + uint64_t num_eventids; uint16_t icid =3D 0; uint32_t pIntid =3D 0; bool ite_valid =3D false; @@ -258,7 +258,7 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t = value, uint32_t offset, dte_valid =3D FIELD_EX64(dte, DTE, VALID); =20 if (dte_valid) { - max_eventid =3D 1UL << (FIELD_EX64(dte, DTE, SIZE) + 1); + num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); =20 ite_valid =3D get_ite(s, eventid, dte, &icid, &pIntid, &res); =20 @@ -299,10 +299,11 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_= t value, uint32_t offset, dte_valid ? "valid" : "invalid", ite_valid ? "valid" : "invalid", cte_valid ? "valid" : "invalid"); - } else if (eventid > max_eventid) { + } else if (eventid >=3D num_eventids) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: eventid %d > %d\n", - __func__, eventid, max_eventid); + "%s: invalid command attributes: eventid %d >=3D %" + PRId64 "\n", + __func__, eventid, num_eventids); } else { /* * Current implementation only supports rdbase =3D=3D procnum @@ -336,7 +337,8 @@ static bool process_mapti(GICv3ITSState *s, uint64_t va= lue, uint32_t offset, AddressSpace *as =3D &s->gicv3->dma_as; uint32_t devid, eventid; uint32_t pIntid =3D 0; - uint32_t max_eventid, max_Intid; + uint64_t num_eventids; + uint32_t max_Intid; bool dte_valid; MemTxResult res =3D MEMTX_OK; uint16_t icid =3D 0; @@ -376,11 +378,11 @@ static bool process_mapti(GICv3ITSState *s, uint64_t = value, uint32_t offset, return result; } dte_valid =3D FIELD_EX64(dte, DTE, VALID); - max_eventid =3D 1UL << (FIELD_EX64(dte, DTE, SIZE) + 1); + num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); max_Intid =3D (1ULL << (GICD_TYPER_IDBITS + 1)) - 1; =20 if ((devid >=3D s->dt.num_ids) || (icid >=3D s->ct.num_ids) - || !dte_valid || (eventid > max_eventid) || + || !dte_valid || (eventid >=3D num_eventids) || (((pIntid < GICV3_LPI_INTID_START) || (pIntid > max_Intid)) && (pIntid !=3D INTID_SPURIOUS))) { qemu_log_mask(LOG_GUEST_ERROR, --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641921688785422.3950845742485; Tue, 11 Jan 2022 09:21:28 -0800 (PST) Received: from localhost ([::1]:53574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7Kpr-0007bk-PL for importer@patchew.org; Tue, 11 Jan 2022 12:21:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfg-0005Ah-DJ for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:57 -0500 Received: from [2a00:1450:4864:20::329] (port=52151 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 1n7Kfe-0007HX-30 for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:56 -0500 Received: by mail-wm1-x329.google.com with SMTP id e5so11561076wmq.1 for ; Tue, 11 Jan 2022 09:10:53 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wHSwNCH5vyw/b88YEepKg5paQSwMAnG4i0aTBoYVuiw=; b=ZTvx+Hz7MBeBL22NrZgMLVo//79SaBUYmYIgtrMR2m9UHU9/QoyB2O64wyjw0UKSIg vK+2bEOoi5LKg6n0PrVNucArdssVVmWfZgHU4Zb0TVd7WM6U7q7iEmAjqoIXpmJJIr/5 7KOTlCo7iw+pwYM7MgGa3oz0f5KDOytZu9l91LIm6VNWTTFyzMVAHJ4McfVY0+Pmbh56 cnvF8ZSUYXhfO/ZJD3eCw4tgyynJxUORNkAE4sOxTSH0LjAj6GR4ic+z1mUrhhRSe5nH JDHcg19K4UKhK1Xoe+FJtPpeguoDIYTxYbuLP2Jdi0rwFveWeVelooIk7Hps9bqZGwj2 aPCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wHSwNCH5vyw/b88YEepKg5paQSwMAnG4i0aTBoYVuiw=; b=HPNuJwaRnDoKpFpbY7hBUU/BtkNyWmqKizX6JwUTHNj6jGWS3ch9UGql7CLYZKrOvH hI17M7VfBJRQQPdaLd40PqtPm/ZHvvTABoONoM9MPJ/cDRvVcRsvKio5wKfXZXGE2zZL mV13yy6e9bWwlaM6PQTj9UKkTticgTfJ6p8iY+t3jWzbKmPbfOTAO8GKAYjC5XaiSPYI WCbP3tO6KWrijrDXnLwNU0yJbyRsaBlZOb7S3pYREU2Eyh6prxFHTdCTtyKS3MKf/cTv fa67eDrdVaBhY0vNQ4Vmlv7O7vBPHEFLRoq5i/FcGQvTEC0Ig8XksaFHVgkUttqjAaOL S6dQ== X-Gm-Message-State: AOAM533eghEU72ShKW9XweTRliICVoAZqH4ph/FKQOvHDwCpw419t14+ 4IiD+LIWRzlCc0uSgmQ9oRb1Ng== X-Google-Smtp-Source: ABdhPJw5qVogQuV2jfl44pTTyWdbG8j5iw5wsCvNEMk6lgEECGetxx6byLLluFpVWtvh92+0sOOf8g== X-Received: by 2002:a05:600c:22da:: with SMTP id 26mr3292021wmg.121.1641921052374; Tue, 11 Jan 2022 09:10:52 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 02/13] hw/intc/arm_gicv3_its: Convert int ID check to num_intids convention Date: Tue, 11 Jan 2022 17:10:37 +0000 Message-Id: <20220111171048.3545974-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::329 (failed) 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=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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641921690361100001 The bounds check on the number of interrupt IDs is correct, but doesn't match our convention; change the variable name, initialize it to the 2^n value rather than (2^n)-1, and use >=3D instead of > in the comparison. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 6d11fa02040..5919b1a3b7f 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -338,7 +338,7 @@ static bool process_mapti(GICv3ITSState *s, uint64_t va= lue, uint32_t offset, uint32_t devid, eventid; uint32_t pIntid =3D 0; uint64_t num_eventids; - uint32_t max_Intid; + uint32_t num_intids; bool dte_valid; MemTxResult res =3D MEMTX_OK; uint16_t icid =3D 0; @@ -379,11 +379,11 @@ static bool process_mapti(GICv3ITSState *s, uint64_t = value, uint32_t offset, } dte_valid =3D FIELD_EX64(dte, DTE, VALID); num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); - max_Intid =3D (1ULL << (GICD_TYPER_IDBITS + 1)) - 1; + num_intids =3D 1ULL << (GICD_TYPER_IDBITS + 1); =20 if ((devid >=3D s->dt.num_ids) || (icid >=3D s->ct.num_ids) || !dte_valid || (eventid >=3D num_eventids) || - (((pIntid < GICV3_LPI_INTID_START) || (pIntid > max_Intid)) && + (((pIntid < GICV3_LPI_INTID_START) || (pIntid >=3D num_intids)= ) && (pIntid !=3D INTID_SPURIOUS))) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes " --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164192244559412.511484917912185; Tue, 11 Jan 2022 09:34:05 -0800 (PST) Received: from localhost ([::1]:48316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7L24-000887-1l for importer@patchew.org; Tue, 11 Jan 2022 12:34:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfi-0005Au-M4 for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:01 -0500 Received: from [2a00:1450:4864:20::32c] (port=41489 helo=mail-wm1-x32c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfe-0007I5-6Z for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:56 -0500 Received: by mail-wm1-x32c.google.com with SMTP id q141-20020a1ca793000000b00347b48dfb53so13664wme.0 for ; Tue, 11 Jan 2022 09:10:53 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JYYFGFnkCFT6+fa4EaAq6TzfkXiIkABdM4xMZSz4G4w=; b=yDCdAjWsHofW7aXSfx2hOBhoDBo6vW8AltwWXoe+9zEI6gepGK5xZBVbP/XK58hGMv 26YrTLZQsxGGFjYLFEdRpbZQg68p3rlxI2N9DHRGY9VQ/aCaWQfyKVhv2WdMB7VfSrpy MMnJQB2C3W71ALNxT8Jrf5G23hxVs7ecR1vRXn7Oe5lQUVdqGs4cAg9gnZwsONpAUCoD 05Y0Cm2jkGnes1R3hiDNrzgxPJ+NxIBG4RTEbjsTeMpOMD9lvbKALalnkPaWwdEVXBOJ wagTEmRMOnvxmxcDqfxOaQBp9zUav5t0r8xxwhLgLHAWGL6onivzWn+oL/hJaPOr+Ja4 V4aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JYYFGFnkCFT6+fa4EaAq6TzfkXiIkABdM4xMZSz4G4w=; b=0PeIjbIWKviIG8jxDosqvqxI1bK215zFcPVOOSzirivLEOWCIzvnH01/Zn9XPhBpxL SW/gT/hmc5mAuCis2rOovDfYhNDZuCIssq2+SP4WiaWkOGFxTzrD66tELJyJ+7x12sD7 /z6po8UQDF0Gaq0lo1duHnHYXfudn4kc4kL21M8yEy3FV0y0bUTMzUpSrKPB4nPwZEjh TpqEdJYeU5y/Unb3wsdrin6lminYZ1BWGkG4ts/jm5eQU43UqocdX5uJ1i1PDmFle+9k 21SUeDp/90CUIm6xjQPOgxRDYkJTyTJV9vHZUAws1rsu31XWUeo/Kk1TxgHmGZWkHKsQ baWQ== X-Gm-Message-State: AOAM533KwzkHEUKk2K7BOhRfEswfxkxJB7u+qBip4nhHQR8nFe3fiEsW MOfGbn+S8QEnhicfyEJnxm9baQ== X-Google-Smtp-Source: ABdhPJyx94xPengilqitMoTf/ROuezr2toRSHBVsJwv/GjhkudQF5+eH5bO/yMRooWQPpMPj7gWkbQ== X-Received: by 2002:a1c:7415:: with SMTP id p21mr3389055wmc.114.1641921052948; Tue, 11 Jan 2022 09:10:52 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 03/13] hw/intc/arm_gicv3_its: Fix handling of process_its_cmd() return value Date: Tue, 11 Jan 2022 17:10:38 +0000 Message-Id: <20220111171048.3545974-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32c (failed) 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=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641922447577100001 process_its_cmd() returns a bool, like all the other process_ functions. However we were putting its return value into 'res', not 'result', which meant we would ignore it when deciding whether to continue or stall the command queue. Fix the typo. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/intc/arm_gicv3_its.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 5919b1a3b7f..a6c2299a091 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -678,10 +678,10 @@ static void process_cmdq(GICv3ITSState *s) =20 switch (cmd) { case GITS_CMD_INT: - res =3D process_its_cmd(s, data, cq_offset, INTERRUPT); + result =3D process_its_cmd(s, data, cq_offset, INTERRUPT); break; case GITS_CMD_CLEAR: - res =3D process_its_cmd(s, data, cq_offset, CLEAR); + result =3D process_its_cmd(s, data, cq_offset, CLEAR); break; case GITS_CMD_SYNC: /* --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641922058462999.790349647133; Tue, 11 Jan 2022 09:27:38 -0800 (PST) Received: from localhost ([::1]:38068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7Kvp-0008Vo-7s for importer@patchew.org; Tue, 11 Jan 2022 12:27:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfh-0005Av-Rs for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:58 -0500 Received: from [2a00:1450:4864:20::434] (port=35467 helo=mail-wr1-x434.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfe-0007Ia-Oi for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:57 -0500 Received: by mail-wr1-x434.google.com with SMTP id e9so32744976wra.2 for ; Tue, 11 Jan 2022 09:10:54 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/jGnsJVkg/+ZfygtKsHgjGO+aK46tFljwLWJ8e5maX8=; b=yWLipiECET/cot1mlylKu2t4xZrle1fGHWd8s6LzUC6OpEnFsU/tyoGmikcgFA8NWu QMRyydSle5YEo4JzLjYEQMehizqkz3+WAgxm9HcBmD9lAyA1RUDX5JFtejATwegvuMw0 40E7hpizwFFW4nfp2CGTh7ni0nkwnbTMO2zHjS9JJPvs0fosZJxfy6uxZ44s95ANa2LZ rgrq9MiKJ99ZsijvsWMTiE7obSODLIOkFzje6DqFFHcCGhBOcO4mTKvjgoxTsqyUIMi3 Wz8m5xjuh1EF9a6euCHw8SIvbkUdzzg5MOPuTDEVyfoE/lZgqkmxoztp74r8P8gB9ZHW PHwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/jGnsJVkg/+ZfygtKsHgjGO+aK46tFljwLWJ8e5maX8=; b=tsxFHTShB7DCqPGkijgitquo2X9LFF00rBNNxOl/2ldJ9OWBW4T16id1OyuD9PkPyH cRYIp2K1I1C609UYmYRQofrfMdsUQrrh0bQEPSvRuMOnxO4sMk1lSlSX96hV6ku+vUvi ToimJXEEm0Z0PYpY43uR5ecWFiIxYLjmSVP2wiwgRQuFjrDYiYStbZQSY2UWIbaxKu+w 3552etiALaiBAR3BSkaY5N4TpS24Ny3puZH8FBWsKHotyNZicJ2Ljzmz15yyJ6gy655S 7hLp/oIIZiTh46WDpL7wAKUzAJ7BtQ+gW9jXpTM5iwnsW1U3PLTEVWkyzmouFFE2uQ5b rGOg== X-Gm-Message-State: AOAM5326rjmMRzaEnJpG0KekGhSaBqOJKXpVL0bfyOeLaUv4NbmvyVTh xpEAwbz8+nGvCU+ppt46EhrqIQ/4pOJOLQ== X-Google-Smtp-Source: ABdhPJyvn6tBb6S5A9iO+h9I16uzPLqIZX3vR3VTFjJ5p2sq3b6yqdOodR4Dzky4E3Wct4LNjiQl+g== X-Received: by 2002:a05:6000:18cd:: with SMTP id w13mr4744849wrq.199.1641921053538; Tue, 11 Jan 2022 09:10:53 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 04/13] hw/intc/arm_gicv3_its: Don't use data if reading command failed Date: Tue, 11 Jan 2022 17:10:39 +0000 Message-Id: <20220111171048.3545974-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::434 (failed) 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=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641922060118100003 In process_cmdq(), we read 64 bits of the command packet, which contain the command identifier, which we then switch() on to dispatch to an appropriate sub-function. However, if address_space_ldq_le() reports a memory transaction failure, we still read the command identifier out of the data and switch() on it. Restructure the code so that we stop immediately (stalling the command queue) in this case. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index a6c2299a091..c1f76682d04 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -672,8 +672,13 @@ static void process_cmdq(GICv3ITSState *s) data =3D address_space_ldq_le(as, s->cq.base_addr + cq_offset, MEMTXATTRS_UNSPECIFIED, &res); if (res !=3D MEMTX_OK) { - result =3D false; + s->creadr =3D FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1); + qemu_log_mask(LOG_GUEST_ERROR, + "%s: could not read command at 0x%" PRIx64 "\n", + __func__, s->cq.base_addr + cq_offset); + break; } + cmd =3D (data & CMD_MASK); =20 switch (cmd) { --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641922945753570.8453942836954; Tue, 11 Jan 2022 09:42:25 -0800 (PST) Received: from localhost ([::1]:37872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LA8-0004K2-Fd for importer@patchew.org; Tue, 11 Jan 2022 12:42:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfm-0005CN-Et for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:03 -0500 Received: from [2a00:1450:4864:20::332] (port=34403 helo=mail-wm1-x332.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kff-0007Is-N2 for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:02 -0500 Received: by mail-wm1-x332.google.com with SMTP id bg19-20020a05600c3c9300b0034565e837b6so999427wmb.1 for ; Tue, 11 Jan 2022 09:10:55 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BFQHZs/9RH00d4p+SGa4ONXVkeFMreYGGrbWyj+yUJQ=; b=sRGzxppK0CVZpo3DwmGDhKmGqTyklwhik1ijePBdJL9knV6Q/qcRZgIRZbYsKwEosK JiCq+aM6rrHA5g7vsf+3FqRoRqAM+6FPa/gr9KssacX9iObim8ao088I0rEV1s5v/TC2 2b4++e+HcTeE6i7YWJpouLqhhaoOER2Vn2PNLaZ7vsrMEpQo/n7k7xt27RWrMA6qFK0Z +idhF1AQNfr6IFrHfereaTrvjb8qawUTl7YBQh41PMiw9yefnDXlrsbs/tRCoKjIV3NX reIyrgQlgEmXFvL5fQN6vrXmpVzG1l4lUg4nivC6BCnBDxQzm/uH7V/zsg2SZSwMtNUk 6GNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFQHZs/9RH00d4p+SGa4ONXVkeFMreYGGrbWyj+yUJQ=; b=e1Ca7BXXMrQuFct6Zcr0d5WzcoatMAl3C0BSNfE638HUl6YPcGz/ySxZmYys0E+W8z 5MQ2f7T+NV4Bs7KUNNrxqWMTI27+nWYOUOw3ShPXRV3YiCtjK2ht1KVn1D3D6obz0IsG 9OA3Z2p7FzBrWzEUTcNcO0bpI/GJcVv4gBOVj2DcEGj1dxeh/lpde7P2Z2K8Yisn8Z8T IH0M0P7Y3jxY6AW84x8xBNDgmJX8bGx+V6ax84UzVVuVNd8Lz11JXC3BMv0rQKGmS8Qe s2uPGlqAI81mDZ3h7ZglkuAHWEgG/ZGTD0TstSSqZnlluAb3GvzSn7svadyiIFnf8V6A c4uw== X-Gm-Message-State: AOAM530X/r+gAatS0yIVULZq5nm4tjReP5z3jy5Hfp2PcnYqKx065oFi x5Vpz55LPxAo48ADoCku2MZHxkfileOD6w== X-Google-Smtp-Source: ABdhPJyvPn/YOova4KWHZdwJdW/qIXMbFBhuOvb6W9+JLB38UL/OmCq5TO5Dagz85dVYdLqfj6vffQ== X-Received: by 2002:a05:600c:1f18:: with SMTP id bd24mr3260908wmb.174.1641921054326; Tue, 11 Jan 2022 09:10:54 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 05/13] hw/intc/arm_gicv3_its: Use enum for return value of process_* functions Date: Tue, 11 Jan 2022 17:10:40 +0000 Message-Id: <20220111171048.3545974-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::332 (failed) 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=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.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, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641922946374100001 When an ITS detects an error in a command, it has an implementation-defined (CONSTRAINED UNPREDICTABLE) choice of whether to ignore the command, proceeding to the next one in the queue, or to stall the ITS command queue, processing nothing further. The behaviour required when the read of the command packet from memory fails is less clearly documented, but the same set of choices as for command errors seem reasonable. The intention of the QEMU implementation, as documented in the comments, is that if we encounter a memory error reading the command packet or one of the various data tables then we should stall, but for command parameter errors we should ignore the queue and continue. However, we don't actually do this. To get the desired behaviour, the various process_* functions need to return true to cause process_cmdq() to advance to the next command and keep processing, and false to stall command processing. What they mostly do is return false for any kind of error. To make the code clearer, replace the 'bool' return from the process_ functions with an enum which may be either CMD_STALL or CMD_CONTINUE. In this commit no behaviour changes; in subsequent commits we will adjust the error-return paths for the process_ functions one by one. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/intc/arm_gicv3_its.c | 59 ++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index c1f76682d04..10901a5e709 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -45,6 +45,23 @@ typedef struct { uint64_t itel; } IteEntry; =20 +/* + * The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options + * if a command parameter is not correct. These include both "stall + * processing of the command queue" and "ignore this command, and + * keep processing the queue". In our implementation we choose that + * memory transaction errors reading the command packet provoke a + * stall, but errors in parameters cause us to ignore the command + * and continue processing. + * The process_* functions which handle individual ITS commands all + * return an ItsCmdResult which tells process_cmdq() whether it should + * stall or keep going. + */ +typedef enum ItsCmdResult { + CMD_STALL =3D 0, + CMD_CONTINUE =3D 1, +} ItsCmdResult; + static uint64_t baser_base_addr(uint64_t value, uint32_t page_sz) { uint64_t result =3D 0; @@ -217,8 +234,8 @@ static uint64_t get_dte(GICv3ITSState *s, uint32_t devi= d, MemTxResult *res) * 3. handling of ITS CLEAR command * 4. handling of ITS DISCARD command */ -static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t off= set, - ItsCmdType cmd) +static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, + uint32_t offset, ItsCmdType cmd) { AddressSpace *as =3D &s->gicv3->dma_as; uint32_t devid, eventid; @@ -231,7 +248,7 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t = value, uint32_t offset, bool ite_valid =3D false; uint64_t cte =3D 0; bool cte_valid =3D false; - bool result =3D false; + ItsCmdResult result =3D CMD_STALL; uint64_t rdbase; =20 if (cmd =3D=3D NONE) { @@ -324,15 +341,15 @@ static bool process_its_cmd(GICv3ITSState *s, uint64_= t value, uint32_t offset, if (cmd =3D=3D DISCARD) { IteEntry ite =3D {}; /* remove mapping from interrupt translation table */ - result =3D update_ite(s, eventid, dte, ite); + result =3D update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : C= MD_STALL; } } =20 return result; } =20 -static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offse= t, - bool ignore_pInt) +static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, + uint32_t offset, bool ignore_pInt) { AddressSpace *as =3D &s->gicv3->dma_as; uint32_t devid, eventid; @@ -343,7 +360,7 @@ static bool process_mapti(GICv3ITSState *s, uint64_t va= lue, uint32_t offset, MemTxResult res =3D MEMTX_OK; uint16_t icid =3D 0; uint64_t dte =3D 0; - bool result =3D false; + ItsCmdResult result =3D CMD_STALL; =20 devid =3D ((value & DEVID_MASK) >> DEVID_SHIFT); offset +=3D NUM_BYTES_IN_DW; @@ -404,7 +421,7 @@ static bool process_mapti(GICv3ITSState *s, uint64_t va= lue, uint32_t offset, ite.itel =3D FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); ite.iteh =3D FIELD_DP32(ite.iteh, ITE_H, ICID, icid); =20 - result =3D update_ite(s, eventid, dte, ite); + result =3D update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_S= TALL; } =20 return result; @@ -472,14 +489,14 @@ static bool update_cte(GICv3ITSState *s, uint16_t ici= d, bool valid, } } =20 -static bool process_mapc(GICv3ITSState *s, uint32_t offset) +static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset) { AddressSpace *as =3D &s->gicv3->dma_as; uint16_t icid; uint64_t rdbase; bool valid; MemTxResult res =3D MEMTX_OK; - bool result =3D false; + ItsCmdResult result =3D CMD_STALL; uint64_t value; =20 offset +=3D NUM_BYTES_IN_DW; @@ -509,7 +526,7 @@ static bool process_mapc(GICv3ITSState *s, uint32_t off= set) * command in the queue */ } else { - result =3D update_cte(s, icid, valid, rdbase); + result =3D update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD= _STALL; } =20 return result; @@ -578,7 +595,8 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid= , bool valid, } } =20 -static bool process_mapd(GICv3ITSState *s, uint64_t value, uint32_t offset) +static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value, + uint32_t offset) { AddressSpace *as =3D &s->gicv3->dma_as; uint32_t devid; @@ -586,7 +604,7 @@ static bool process_mapd(GICv3ITSState *s, uint64_t val= ue, uint32_t offset) uint64_t itt_addr; bool valid; MemTxResult res =3D MEMTX_OK; - bool result =3D false; + ItsCmdResult result =3D CMD_STALL; =20 devid =3D ((value & DEVID_MASK) >> DEVID_SHIFT); =20 @@ -623,7 +641,7 @@ static bool process_mapd(GICv3ITSState *s, uint64_t val= ue, uint32_t offset) * command in the queue */ } else { - result =3D update_dte(s, devid, valid, size, itt_addr); + result =3D update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTI= NUE : CMD_STALL; } =20 return result; @@ -641,7 +659,6 @@ static void process_cmdq(GICv3ITSState *s) uint64_t data; AddressSpace *as =3D &s->gicv3->dma_as; MemTxResult res =3D MEMTX_OK; - bool result =3D true; uint8_t cmd; int i; =20 @@ -668,6 +685,8 @@ static void process_cmdq(GICv3ITSState *s) } =20 while (wr_offset !=3D rd_offset) { + ItsCmdResult result =3D CMD_CONTINUE; + cq_offset =3D (rd_offset * GITS_CMDQ_ENTRY_SIZE); data =3D address_space_ldq_le(as, s->cq.base_addr + cq_offset, MEMTXATTRS_UNSPECIFIED, &res); @@ -726,18 +745,16 @@ static void process_cmdq(GICv3ITSState *s) default: break; } - if (result) { + if (result =3D=3D CMD_CONTINUE) { rd_offset++; rd_offset %=3D s->cq.num_entries; s->creadr =3D FIELD_DP64(s->creadr, GITS_CREADR, OFFSET, rd_of= fset); } else { - /* - * in this implementation, in case of dma read/write error - * we stall the command processing - */ + /* CMD_STALL */ s->creadr =3D FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1); qemu_log_mask(LOG_GUEST_ERROR, - "%s: %x cmd processing failed\n", __func__, cmd); + "%s: 0x%x cmd processing failed, stalling\n", + __func__, cmd); break; } } --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641922780473869.0995695539533; Tue, 11 Jan 2022 09:39:40 -0800 (PST) Received: from localhost ([::1]:58158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7L7S-0007M4-La for importer@patchew.org; Tue, 11 Jan 2022 12:39:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0005CF-Ka for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:03 -0500 Received: from [2a00:1450:4864:20::429] (port=34625 helo=mail-wr1-x429.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfg-0007J8-9z for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:58 -0500 Received: by mail-wr1-x429.google.com with SMTP id h10so24085322wrb.1 for ; Tue, 11 Jan 2022 09:10:55 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=77Xvvb93kRuq0kwxqLtAzTJqRqACUWX5HzdBepSqjy8=; b=fB1udekkew8p9fl1lMj8nTubohB41kthGpHkzhz96ijoAwJs56H5h7fvkBXnS86AGS dlVSZUn8jhIT1uHjjiZUR41Y0RgYtWE5xpufZbOyDnYt+j9aYtfQ677xzgKcR0BRgus8 dexklcYGB1CHJTIfXtPkR2mMaBK83LeHfPMU5PE5Tz+CmCrmuhBHX7qIT2ymJdJtJxbe nVLxbXlqGkL360D6GUzWrYMOn60gbnxJpOj46fP1Y1WzoIL1CGIEElNldKRZgHeKwW15 bfTm3W2brplHZ6ar3WA2NrxdntReNkCFkUfMNwE9YVS8wUnpxd51IcNCLKvnB70UeaAd YtGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=77Xvvb93kRuq0kwxqLtAzTJqRqACUWX5HzdBepSqjy8=; b=Y2uSxxsXfjwE6MfrdxrDBD4t4sVYvhRt8E0g7rtjuGa8cXLIfkeBC0/og5+J+BKK/K XVVOIciFeRIegYJyCGlwmWkTY2v/i1lrlrbEIFbtaCssPDtDkxl+vc7ZlIpYrmPJ7Qo7 QO4vEshcuOQ40oKBnswUH/UhQVqEsRQXPOkO2YH0Y6QaNbMqi0Q8VaU2voSIe+UiN8wr i/Bktk3b7Y6D+CdLhaB9opMm13FPHhzrWd4Uf+wEQWP0C4YArxT8XCYVvBtA14zHMZEW RC1Tido0Eax1+GhhJcPDbqQHZ9nroTV5TgOMwQWM+xNgnAWQ9TduqTDgn/Bptov0J9wB OyKQ== X-Gm-Message-State: AOAM531SFJ3g6Ms01I/cbVdrsGYldew1+vSFsMo560p3MNekHUgsvhN8 UFH9C0X+Emso9kCUWk/wAqmziw== X-Google-Smtp-Source: ABdhPJznJ9+oka+YpbyoUZdjte7wkJrizD1mRILeW9z63s3EIZofOzDGmCeYJUH4ZWWHeoUnyMXnNw== X-Received: by 2002:adf:dd88:: with SMTP id x8mr4719929wrl.586.1641921055060; Tue, 11 Jan 2022 09:10:55 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 06/13] hw/intc/arm_gicv3_its: Fix return codes in process_its_cmd() Date: Tue, 11 Jan 2022 17:10:41 +0000 Message-Id: <20220111171048.3545974-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::429 (failed) 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=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641922782395100001 Fix process_its_cmd() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 10901a5e709..0929116c0fe 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -248,7 +248,6 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, u= int64_t value, bool ite_valid =3D false; uint64_t cte =3D 0; bool cte_valid =3D false; - ItsCmdResult result =3D CMD_STALL; uint64_t rdbase; =20 if (cmd =3D=3D NONE) { @@ -262,7 +261,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, u= int64_t value, } =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 eventid =3D (value & EVENTID_MASK); @@ -270,7 +269,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, u= int64_t value, dte =3D get_dte(s, devid, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } dte_valid =3D FIELD_EX64(dte, DTE, VALID); =20 @@ -280,7 +279,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, u= int64_t value, ite_valid =3D get_ite(s, eventid, dte, &icid, &pIntid, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 if (ite_valid) { @@ -288,14 +287,14 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s,= uint64_t value, } =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } } else { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " "invalid dte: %"PRIx64" for %d (MEM_TX: %d)\n", __func__, dte, devid, res); - return result; + return CMD_CONTINUE; } =20 =20 @@ -307,7 +306,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, u= int64_t value, qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: devid %d>=3D%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: " @@ -316,11 +315,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s,= uint64_t value, dte_valid ? "valid" : "invalid", ite_valid ? "valid" : "invalid", cte_valid ? "valid" : "invalid"); + return CMD_CONTINUE; } else if (eventid >=3D num_eventids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: eventid %d >=3D %" PRId64 "\n", __func__, eventid, num_eventids); + return CMD_CONTINUE; } else { /* * Current implementation only supports rdbase =3D=3D procnum @@ -329,7 +330,7 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, u= int64_t value, rdbase =3D FIELD_EX64(cte, CTE, RDBASE); =20 if (rdbase >=3D s->gicv3->num_cpu) { - return result; + return CMD_CONTINUE; } =20 if ((cmd =3D=3D CLEAR) || (cmd =3D=3D DISCARD)) { @@ -341,11 +342,10 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s,= uint64_t value, if (cmd =3D=3D DISCARD) { IteEntry ite =3D {}; /* remove mapping from interrupt translation table */ - result =3D update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : C= MD_STALL; + return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_S= TALL; } + return CMD_CONTINUE; } - - return result; } =20 static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641923118318724.9651096996719; Tue, 11 Jan 2022 09:45:18 -0800 (PST) Received: from localhost ([::1]:44730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LCv-0000cZ-4B for importer@patchew.org; Tue, 11 Jan 2022 12:45:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfn-0005CR-0n for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:03 -0500 Received: from [2a00:1450:4864:20::32d] (port=50723 helo=mail-wm1-x32d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfi-0007JW-Bt for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:02 -0500 Received: by mail-wm1-x32d.google.com with SMTP id w26so5695481wmi.0 for ; Tue, 11 Jan 2022 09:10:56 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w59aiHtlS+UEJYF8KG6CIWjpdLxn3MFz4XhHlwys/7I=; b=EQ+HaxxkduJVaWIsuKcg1SxL4RTwBCXV5plq9SlbUL8ohC0krpLXg8Pssj6yfstU4R d1y5kPTVwGPB496iu9MYGoHNLGk4zryoSeQrXasNnUWX9toiE/IweRudNA3Kxp77J/Pw f13f3brJUkyddCOISRQtigWmSz1LKed5T74MHVG/lDEMDhmdKhb7h2Z+kOUs4HVq4tgc i7ftvRhC2o1wcC9JPRiObFVUEXKlZaoXv7gRHR53I1BCCGFFyhN0YJ0jpO5ce8LGB5h5 6yD9387mHQKh0lb/MKM2XZWwnZcN4tqnkU9QUrmIskjadylTs3Jy7j0ZTKePiBHeu5n+ MPKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w59aiHtlS+UEJYF8KG6CIWjpdLxn3MFz4XhHlwys/7I=; b=r+EUdOFt8VvA4XukSIiWVXhPoFk5NfrwpAs1MYrYb90HPmBR2LsZdqm7wcj1zV0hsh EuVJ4NAfma6FCSe33XfL+Mogq5rbhPKEigyc7sEsPg4aJDUsH1ywjdQegQxb8Jo94h4n lICgDBPrr9bR+YJEOrbKF84IJU52KzIKSocVogMrtEzFNatZpUKVcOZkIAy4xc15ZcMS Fqu6soGisHq8nl7Zjt15oWgkgb8sdmVmXETZ8Y9Zs0Lh0fHwe+23aRmnK7IIPiLdCwTI 0kt/ab3oQ8v/gDsqy3rXrXqB0lxudEo6J/LTheohNTKR9Ch7etpzCBzRUYDG/Fpyy1ma awEA== X-Gm-Message-State: AOAM533LRHCfMgTmDolTSznv5Md2+/fCV5ZyjyT9MjipWmuSsyiLMa+P tNmMyRReM5yEQiNN86E6PI1QWA== X-Google-Smtp-Source: ABdhPJy5wwNA5pen3pENXQDKZ4eHqaBzBw5BvpAxZLTBze0RV666OtoGDfexZe/ZNC1IJcMCm3Kn4w== X-Received: by 2002:a1c:9803:: with SMTP id a3mr3251538wme.47.1641921055800; Tue, 11 Jan 2022 09:10:55 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 07/13] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting Date: Tue, 11 Jan 2022 17:10:42 +0000 Message-Id: <20220111171048.3545974-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32d (failed) 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=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641923119222100003 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=C3=A9e Reviewed-by: Richard Henderson --- 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 =3D FIELD_EX64(dte, DTE, VALID); =20 - if (dte_valid) { - num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); - - ite_valid =3D get_ite(s, eventid, dte, &icid, &pIntid, &res); - - if (res !=3D MEMTX_OK) { - return CMD_STALL; - } - - if (ite_valid) { - cte_valid =3D get_cte(s, icid, &cte, &res); - } - - if (res !=3D 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; } =20 + num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); + + ite_valid =3D get_ite(s, eventid, dte, &icid, &pIntid, &res); + if (res !=3D 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 =3D get_cte(s, icid, &cte, &res); + if (res !=3D 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; + } =20 - /* - * In this implementation, in case of guest errors we ignore the - * command and move onto the next command in the queue. - */ if (devid >=3D s->dt.num_ids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: devid %d>=3D%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 >=3D num_eventids) { + } + if (eventid >=3D num_eventids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: eventid %d >=3D %" PRId64 "\n", __func__, eventid, num_eventids); return CMD_CONTINUE; - } else { - /* - * Current implementation only supports rdbase =3D=3D procnum - * Hence rdbase physical address is ignored - */ - rdbase =3D FIELD_EX64(cte, CTE, RDBASE); + } =20 - if (rdbase >=3D s->gicv3->num_cpu) { - return CMD_CONTINUE; - } + /* + * Current implementation only supports rdbase =3D=3D procnum + * Hence rdbase physical address is ignored + */ + rdbase =3D FIELD_EX64(cte, CTE, RDBASE); =20 - if ((cmd =3D=3D CLEAR) || (cmd =3D=3D DISCARD)) { - gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0); - } else { - gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1); - } - - if (cmd =3D=3D DISCARD) { - IteEntry ite =3D {}; - /* remove mapping from interrupt translation table */ - return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_S= TALL; - } + if (rdbase >=3D s->gicv3->num_cpu) { return CMD_CONTINUE; } + + if ((cmd =3D=3D CLEAR) || (cmd =3D=3D DISCARD)) { + gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0); + } else { + gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1); + } + + if (cmd =3D=3D DISCARD) { + IteEntry ite =3D {}; + /* remove mapping from interrupt translation table */ + return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; + } + return CMD_CONTINUE; } =20 static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641921595889245.02260825309088; Tue, 11 Jan 2022 09:19:55 -0800 (PST) Received: from localhost ([::1]:51336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7KoM-00063E-Fr for importer@patchew.org; Tue, 11 Jan 2022 12:19:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0005CH-L5 for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:03 -0500 Received: from [2a00:1450:4864:20::32f] (port=41492 helo=mail-wm1-x32f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfi-0007Ju-7L for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:10:59 -0500 Received: by mail-wm1-x32f.google.com with SMTP id q141-20020a1ca793000000b00347b48dfb53so13771wme.0 for ; Tue, 11 Jan 2022 09:10:57 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dMGaDtUlyJEJ3dvWwIKR4xUcpNypUeqgEu0z6OQaSkc=; b=F1l2anL8f77Vvt7h8eVK7CskwcxalUSFMqfDWrXQosjsMABIWsCe3xh84tk2HjE8qY SIlrlne48Qb4jz5TpxR8L5PbdZFvLQ6Ro2h01DxBTbPMwu+RXgcNx7cxzET/727ome6d gGQCUMb+ih3xNUkuxC9zKiGauScd3Rrvud/byoTLpRKn5b7ouE5QLndtHU0jqce6jaKZ Ng+whuiPwvmQr2R1DQfZcI7CLaC9nIjUY7hseo+bBsm1bB9Zmeq3R3ucgc6DOEWyDZcc rjHBrGJ9bjVwpOs7gCkgvuQy7etUq1KAo2HhIAbq89qr22eixdJ9wCX34u6buEqedzO8 K+cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dMGaDtUlyJEJ3dvWwIKR4xUcpNypUeqgEu0z6OQaSkc=; b=J8C8S1YrVCrp9UMLRCYw/4CGAoex7+o57ztQI4KjSDX8tpbYoZCciGDRrvUIBHFECS x7WgNOlB8vHJDkwK2qMc8EePH4DeP8UzStS3zFw5UL/No1awBZ+lKpKBGS3GV+SvF4EJ B4rS52X68k0gvBt0r9H9HuSqDWLPvzxvw2qhvFxJi/7nxPeZKdm8PNgpi4dYfXcvq2in RNZBf86aPeKeMKuV0vY4qDKVXTLK/aw+7FELazBvbxlqWTwZ12RV1jjXVf7uufj1FnV/ fwAzkRR2PC2yRy78cGuTn6SAiwOSkJskmzXGWFqunsaLA+Z+O/ioV/GT7UGNt4ibBOw9 dwhA== X-Gm-Message-State: AOAM5339X5CQQU3adGPU2UJ+sFqkPWAn4JDgrrsRGtbgnloTmtgTgOzq 0WKwfgnT57lgN+rZ9B9jJ9Yo+Q== X-Google-Smtp-Source: ABdhPJw5FCGHS7+hLkLNRSMtOGkoTY8eqPRfCKpwshyaDQrD9tFOlyA66/s4N79zb7D4hjfoXslJhQ== X-Received: by 2002:a05:600c:5025:: with SMTP id n37mr3315436wmr.18.1641921056521; Tue, 11 Jan 2022 09:10:56 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 08/13] hw/intc/arm_gicv3_its: Fix return codes in process_mapti() Date: Tue, 11 Jan 2022 17:10:43 +0000 Message-Id: <20220111171048.3545974-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32f (failed) 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=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641921598203100001 Fix process_mapti() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 5dc6846fe3f..010779a9fdc 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -357,7 +357,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uin= t64_t value, MemTxResult res =3D MEMTX_OK; uint16_t icid =3D 0; uint64_t dte =3D 0; - ItsCmdResult result =3D CMD_STALL; + IteEntry ite =3D {}; =20 devid =3D ((value & DEVID_MASK) >> DEVID_SHIFT); offset +=3D NUM_BYTES_IN_DW; @@ -365,7 +365,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uin= t64_t value, MEMTXATTRS_UNSPECIFIED, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 eventid =3D (value & EVENTID_MASK); @@ -381,7 +381,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uin= t64_t value, MEMTXATTRS_UNSPECIFIED, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 icid =3D value & ICID_MASK; @@ -389,7 +389,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uin= t64_t value, dte =3D get_dte(s, devid, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } dte_valid =3D FIELD_EX64(dte, DTE, VALID); num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); @@ -409,19 +409,17 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, u= int64_t value, * we ignore this command and move onto the next * command in the queue */ - } else { - /* add ite entry to interrupt translation table */ - IteEntry ite =3D {}; - ite.itel =3D FIELD_DP64(ite.itel, ITE_L, VALID, dte_valid); - ite.itel =3D FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYS= ICAL); - ite.itel =3D FIELD_DP64(ite.itel, ITE_L, INTID, pIntid); - ite.itel =3D FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); - ite.iteh =3D FIELD_DP32(ite.iteh, ITE_H, ICID, icid); - - result =3D update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_S= TALL; + return CMD_CONTINUE; } =20 - return result; + /* add ite entry to interrupt translation table */ + ite.itel =3D FIELD_DP64(ite.itel, ITE_L, VALID, dte_valid); + ite.itel =3D FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL= ); + ite.itel =3D FIELD_DP64(ite.itel, ITE_L, INTID, pIntid); + ite.itel =3D FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); + ite.iteh =3D FIELD_DP32(ite.iteh, ITE_H, ICID, icid); + + return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; } =20 static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641923324560296.62268366565013; Tue, 11 Jan 2022 09:48:44 -0800 (PST) Received: from localhost ([::1]:51546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LGF-0005Jt-Hd for importer@patchew.org; Tue, 11 Jan 2022 12:48:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfn-0005D5-NM for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:08 -0500 Received: from [2a00:1450:4864:20::432] (port=34634 helo=mail-wr1-x432.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0007KB-9z for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:03 -0500 Received: by mail-wr1-x432.google.com with SMTP id h10so24085531wrb.1 for ; Tue, 11 Jan 2022 09:10:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M+19OihughmoJEL8u1lX7s3OdjR7r5E5GvgmNdTNC5k=; b=NcnspWi5FCgsfZ0IvLq/25en3LBApDx+u0lRl8aY8aUxyLL+QdyZKubivzOt5frFUq Uk+lrymARDw+sCAmIahgrzWmptzHJoMfwdbLdRYtLdmfDoh3enkZgrQM5+SGIeyXxtq1 P8+lhwepXlXno9Ku6d3+WN1u1AJE7ZxU198Ug047AdyUEaKxg6cSJo1arC7MtGLbkBbz 4SrapmHJxM3YY2ex1ck34Egxjxfaoz+mGvvsxG0DyZ2QagP/m/NZkoXFAVLnEc40gMI8 +GSr4IZSa7SoHnJMa9XS6d0VjOCCnlGO17bzH5oE6u59IjyzRjT1F9ve+muZZ+grWkZp ztrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M+19OihughmoJEL8u1lX7s3OdjR7r5E5GvgmNdTNC5k=; b=xAUR6wGNybt6GguB4bcYHM/D4O0RfEbNoOemK6yIa26rBb/ayxg2nYNZn3NlOlTFEH UQS05gq20BV1nWc5I2bWeQmlgGBoGgJXjQ7P1mx7Nj3jCIQFb69ZCwIM4IKKcq0IU1wB ho/MfKTEGlGuYqeqxhZykgmzVw1Hm+lNK2xL9eLOWOzDsAP/ZFDLyggg7+MqwrT8WRJJ LLRz23o6LKhMXET3nQPlu2/8nlcal5dEigmtqc3/l7ccgW2ZX97fW5fCLbxunvzUZlTh dlSyxZsIhh+lKL4+v9pd/Cwu7dfAyhoYhs7FITuY62QUEvqHC4ZL4Vip3d51427/IZ4I YBEg== X-Gm-Message-State: AOAM531cn808axngxTBaiepRoukqcpS7Hd66Gd2Ge/ga5fH5BKXTnduW ypahwPwSvSfO9A5P4QikgbNRqQ== X-Google-Smtp-Source: ABdhPJwSI+hJ+bxdT8wCvrZjCueZwfcBpeE8qa+x5MksGyRxYKE3kD7ZYmWQhr6V+UW2TTCKUaFIqw== X-Received: by 2002:a05:6000:15cd:: with SMTP id y13mr4763157wry.28.1641921057153; Tue, 11 Jan 2022 09:10:57 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 09/13] hw/intc/arm_gicv3_its: Fix return codes in process_mapc() Date: Tue, 11 Jan 2022 17:10:44 +0000 Message-Id: <20220111171048.3545974-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::432 (failed) 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=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641923325491100001 Fix process_mapc() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 010779a9fdc..80ef4dbcadf 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -491,7 +491,6 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint= 32_t offset) uint64_t rdbase; bool valid; MemTxResult res =3D MEMTX_OK; - ItsCmdResult result =3D CMD_STALL; uint64_t value; =20 offset +=3D NUM_BYTES_IN_DW; @@ -501,7 +500,7 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint= 32_t offset) MEMTXATTRS_UNSPECIFIED, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 icid =3D value & ICID_MASK; @@ -520,11 +519,10 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, ui= nt32_t offset) * we ignore this command and move onto the next * command in the queue */ - } else { - result =3D update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD= _STALL; + return CMD_CONTINUE; } =20 - return result; + return update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD_STALL; } =20 static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid, --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641923485848851.4070556048056; Tue, 11 Jan 2022 09:51:25 -0800 (PST) Received: from localhost ([::1]:55684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LIq-000859-IH for importer@patchew.org; Tue, 11 Jan 2022 12:51:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfq-0005DA-4i for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:11 -0500 Received: from [2a00:1450:4864:20::42c] (port=41772 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0007KQ-FV for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:05 -0500 Received: by mail-wr1-x42c.google.com with SMTP id v6so34158293wra.8 for ; Tue, 11 Jan 2022 09:10:58 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K3C/kFYJ4QIEIUS4ZNsrIp8SeCMyQxIhNuKfg2+o/Ik=; b=y7VCa6wd0XAg2p685ZFaOrkrHBL0lZ16qiWl1hmgnpFEuNl0OfJW5cxFaIyZaQ8J0H 7yMZsZAJfA/XiIZ9N3WQwjvyhKB518gffWz7yl5FqXEYvBZWwoYcRW77PPc1a8ZJW0eF FO4niUwbqAvz8aDWnxV+Q6wSZIhdx5yCPNI0p5R1742lxLsyHAYaD9gWcB6fxqUeKFDB JNmfhJEuHatpWiWxbd31RCPTLwOkbdAPp27b32PRRjYy8++DRQ7ETECsGW7r7gFfJCJk mL9u2bdD3iGbCVy8kUsoHIYjeK/+kIPvKeSyht7THnEq5oF/ULBEwspguus/GBoMBdnb 7LNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K3C/kFYJ4QIEIUS4ZNsrIp8SeCMyQxIhNuKfg2+o/Ik=; b=aOkktgYeitm/PODQFPY6kNypsj/4u/Yt+bGm3XFnBuEMZBHwltv745OBq6VC+mlQPj U6WJCQ6+kUWKwv6Pdtef9HN1WLwjeTUIPYexChQ1H4Eed14QP03nH6dOOF1M2vlm7Nz3 wlxcUurGFoWRC6JgltUVLTEnNutwjiVaI4b9GeJDVeS4lv+DMwSlrizmzjFnuNdbMmpN RihkPxKr7hV7t7k7tYRyRjtUhLGXVvHUCK/V2A4OyHoJdBeWJFIddPasMINh5Dg0iQz0 FAsG0vDfNuD/PP5Rhp5WLfCxiRfz7a0k2pw8yozzLCgbDXHlU2393Wmi10S7H5wo2XHn n3iw== X-Gm-Message-State: AOAM532LpCtTCnkes6lEbKDfYtUxxnM9tmqmXjeBC5cD1bUwNlVlr0PB v5jv5K/SzlJAUZ0f+CWnUYG20w== X-Google-Smtp-Source: ABdhPJyycWI9z4ECuzRcHLgpjusbTQ6WQxy+9sZXqod+9Kdkw7tHbHtflVH45+avr5fw2/54Whr69w== X-Received: by 2002:a05:6000:1d89:: with SMTP id bk9mr4525198wrb.561.1641921057733; Tue, 11 Jan 2022 09:10:57 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 10/13] hw/intc/arm_gicv3_its: Fix return codes in process_mapd() Date: Tue, 11 Jan 2022 17:10:45 +0000 Message-Id: <20220111171048.3545974-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) 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=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641923487061100003 Fix process_mapd() to consistently return CMD_STALL for memory errors and CMD_CONTINUE for parameter errors, as we claim in the comments that we do. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 80ef4dbcadf..917201c148f 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -597,7 +597,6 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint= 64_t value, uint64_t itt_addr; bool valid; MemTxResult res =3D MEMTX_OK; - ItsCmdResult result =3D CMD_STALL; =20 devid =3D ((value & DEVID_MASK) >> DEVID_SHIFT); =20 @@ -606,7 +605,7 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint= 64_t value, MEMTXATTRS_UNSPECIFIED, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 size =3D (value & SIZE_MASK); @@ -616,7 +615,7 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint= 64_t value, MEMTXATTRS_UNSPECIFIED, &res); =20 if (res !=3D MEMTX_OK) { - return result; + return CMD_STALL; } =20 itt_addr =3D (value & ITTADDR_MASK) >> ITTADDR_SHIFT; @@ -633,11 +632,10 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, ui= nt64_t value, * we ignore this command and move onto the next * command in the queue */ - } else { - result =3D update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTI= NUE : CMD_STALL; + return CMD_CONTINUE; } =20 - return result; + return update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTINUE : CM= D_STALL; } =20 /* --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641922002546150.05846694096454; Tue, 11 Jan 2022 09:26:42 -0800 (PST) Received: from localhost ([::1]:36494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7Kuv-00075J-E3 for importer@patchew.org; Tue, 11 Jan 2022 12:26:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfo-0005D7-VA for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:11 -0500 Received: from [2a00:1450:4864:20::42d] (port=36473 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0007Km-FC for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:04 -0500 Received: by mail-wr1-x42d.google.com with SMTP id r28so5850592wrc.3 for ; Tue, 11 Jan 2022 09:10:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TcSrMUtkOV3RqL4wrKJvnNxFBlAibhPM/vlIAuMO/t8=; b=eMxTpkGafOaw4kNWdf91zhPvqeDcGg1njaCz5KvGL/1V5iT9kaTCRI5B+5SwRNjHVn kraY2s4m+UXxmHHqqvpuOSuMji5VIGYsP2SIwOHSk22JXZ06YEFB/pNrb7x7kyPfb+8K xTkN0npX9l72q8y/xlOFUMDyRllegkm4jpctWhWJe1jtp2ddxWRW21QqULDICFz27t/n UJnpLKKkuzvGY3yC0VQFbLmH77mVC0v3IJWRD30p3k+TwLDRzds0LYrZB3Gqv64RppXV tLOfI2H+U3//5mAnjEC4osscEEb/8ZrMY6IBFTvnZK9uLkFzswnreIMLEW9qFvY71YeX jHOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TcSrMUtkOV3RqL4wrKJvnNxFBlAibhPM/vlIAuMO/t8=; b=VQSmxO3g8ghuyqbypVZUfXiPeMLSBs6tZyY/+qBdHGZooUfQKHlY2V8m1USbKwlyeP T6/czJaG/fiwE5SBA9Lu5nGwtFmWf/Zuz4+VONOpfQJp+ZzdmbAcMRIAK1CnKaXaGr5E iO1fgTmWyboQ+ILkBx9rZPGr0G1XzBs9E1FBDJ6HqvuYy5gp+A+L+xl6+CeRTzBaGJF1 UCIIOl54rlfjtVECPgDEdBowH2esK0b+qpvhJBoidoTRWKyRG6nhJLikmbPEVC67G7vN 0QufN/wjBu6xW+3HaT2VFVXYKRww3m7xtlTYkYw1swgQ/AYtYTOlw+EMjy67vB4zXYqt UcZg== X-Gm-Message-State: AOAM530Ixy2KU9qpkg6fNgQ0DHWxMAIvqBKyNJNIffJjIqnwnda4kq6D Cq9hxBz91SGA2NTKfmyNDAy5GA== X-Google-Smtp-Source: ABdhPJyw/7nC+Raev98J0T5dd0gsb7RAfBPHSDDDoWkqTqQ/IBD50FsZ0hzrVVYmtxRdyw7L0jAdww== X-Received: by 2002:a5d:63d1:: with SMTP id c17mr4680181wrw.522.1641921058519; Tue, 11 Jan 2022 09:10:58 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 11/13] hw/intc/arm_gicv3_its: Factor out "find address of table entry" code Date: Tue, 11 Jan 2022 17:10:46 +0000 Message-Id: <20220111171048.3545974-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) 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=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641922003835100002 Content-Type: text/plain; charset="utf-8" The ITS has several tables which all share a similar format, described by the TableDesc struct: the guest may configure them to be a single-level table or a two-level table. Currently we open-code the process of finding the table entry in all the functions which read or write the device table or the collection table. Factor out the "get the address of the table entry" logic into a new function, so that the code which needs to read or write a table entry only needs to call table_entry_addr() and then perform a suitable load or store to that address. Note that the error handling is slightly complicated because we want to handle two cases differently: * failure to read the L1 table entry should end up causing a command stall, like other kinds of DMA error * an L1 table entry that says there is no L2 table for this index (ie whose valid bit is 0) must result in us treating the table entry as not-valid on read, and discarding writes (this is mandated by the spec) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e --- This is a worthwhile refactoring on its own, but still more so given that GICv4 adds another table in this format. --- hw/intc/arm_gicv3_its.c | 212 +++++++++++++--------------------------- 1 file changed, 70 insertions(+), 142 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 917201c148f..985e316eda9 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -83,44 +83,62 @@ static uint64_t baser_base_addr(uint64_t value, uint32_= t page_sz) return result; } =20 +static uint64_t table_entry_addr(GICv3ITSState *s, TableDesc *td, + uint32_t idx, MemTxResult *res) +{ + /* + * Given a TableDesc describing one of the ITS in-guest-memory + * tables and an index into it, return the guest address + * corresponding to that table entry. + * If there was a memory error reading the L1 table of an + * indirect table, *res is set accordingly, and we return -1. + * If the L1 table entry is marked not valid, we return -1 with + * *res set to MEMTX_OK. + * + * The specification defines the format of level 1 entries of a + * 2-level table, but the format of level 2 entries and the format + * of flat-mapped tables is IMPDEF. + */ + AddressSpace *as =3D &s->gicv3->dma_as; + uint32_t l2idx; + uint64_t l2; + uint32_t num_l2_entries; + + *res =3D MEMTX_OK; + + if (!td->indirect) { + /* Single level table */ + return td->base_addr + idx * td->entry_sz; + } + + /* Two level table */ + l2idx =3D idx / (td->page_sz / L1TABLE_ENTRY_SIZE); + + l2 =3D address_space_ldq_le(as, + td->base_addr + (l2idx * L1TABLE_ENTRY_SIZE), + MEMTXATTRS_UNSPECIFIED, res); + if (*res !=3D MEMTX_OK) { + return -1; + } + if (!(l2 & L2_TABLE_VALID_MASK)) { + return -1; + } + + num_l2_entries =3D td->page_sz / td->entry_sz; + return (l2 & ((1ULL << 51) - 1)) + (idx % num_l2_entries) * td->entry_= sz; +} + static bool get_cte(GICv3ITSState *s, uint16_t icid, uint64_t *cte, MemTxResult *res) { AddressSpace *as =3D &s->gicv3->dma_as; - uint64_t l2t_addr; - uint64_t value; - bool valid_l2t; - uint32_t l2t_id; - uint32_t num_l2_entries; + uint64_t entry_addr =3D table_entry_addr(s, &s->ct, icid, res); =20 - if (s->ct.indirect) { - l2t_id =3D icid / (s->ct.page_sz / L1TABLE_ENTRY_SIZE); - - value =3D address_space_ldq_le(as, - s->ct.base_addr + - (l2t_id * L1TABLE_ENTRY_SIZE), - MEMTXATTRS_UNSPECIFIED, res); - - if (*res =3D=3D MEMTX_OK) { - valid_l2t =3D (value & L2_TABLE_VALID_MASK) !=3D 0; - - if (valid_l2t) { - num_l2_entries =3D s->ct.page_sz / s->ct.entry_sz; - - l2t_addr =3D value & ((1ULL << 51) - 1); - - *cte =3D address_space_ldq_le(as, l2t_addr + - ((icid % num_l2_entries) * GITS_CTE_SI= ZE), - MEMTXATTRS_UNSPECIFIED, res); - } - } - } else { - /* Flat level table */ - *cte =3D address_space_ldq_le(as, s->ct.base_addr + - (icid * GITS_CTE_SIZE), - MEMTXATTRS_UNSPECIFIED, res); + if (entry_addr =3D=3D -1) { + return false; /* not valid */ } =20 + *cte =3D address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, = res); return FIELD_EX64(*cte, CTE, VALID); } =20 @@ -189,41 +207,12 @@ static bool get_ite(GICv3ITSState *s, uint32_t eventi= d, uint64_t dte, static uint64_t get_dte(GICv3ITSState *s, uint32_t devid, MemTxResult *res) { AddressSpace *as =3D &s->gicv3->dma_as; - uint64_t l2t_addr; - uint64_t value; - bool valid_l2t; - uint32_t l2t_id; - uint32_t num_l2_entries; + uint64_t entry_addr =3D table_entry_addr(s, &s->dt, devid, res); =20 - if (s->dt.indirect) { - l2t_id =3D devid / (s->dt.page_sz / L1TABLE_ENTRY_SIZE); - - value =3D address_space_ldq_le(as, - s->dt.base_addr + - (l2t_id * L1TABLE_ENTRY_SIZE), - MEMTXATTRS_UNSPECIFIED, res); - - if (*res =3D=3D MEMTX_OK) { - valid_l2t =3D (value & L2_TABLE_VALID_MASK) !=3D 0; - - if (valid_l2t) { - num_l2_entries =3D s->dt.page_sz / s->dt.entry_sz; - - l2t_addr =3D value & ((1ULL << 51) - 1); - - value =3D address_space_ldq_le(as, l2t_addr + - ((devid % num_l2_entries) * GITS_DTE_SI= ZE), - MEMTXATTRS_UNSPECIFIED, res); - } - } - } else { - /* Flat level table */ - value =3D address_space_ldq_le(as, s->dt.base_addr + - (devid * GITS_DTE_SIZE), - MEMTXATTRS_UNSPECIFIED, res); + if (entry_addr =3D=3D -1) { + return 0; /* a DTE entry with the Valid bit clear */ } - - return value; + return address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, re= s); } =20 /* @@ -426,11 +415,7 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid= , bool valid, uint64_t rdbase) { AddressSpace *as =3D &s->gicv3->dma_as; - uint64_t value; - uint64_t l2t_addr; - bool valid_l2t; - uint32_t l2t_id; - uint32_t num_l2_entries; + uint64_t entry_addr; uint64_t cte =3D 0; MemTxResult res =3D MEMTX_OK; =20 @@ -444,44 +429,18 @@ static bool update_cte(GICv3ITSState *s, uint16_t ici= d, bool valid, cte =3D FIELD_DP64(cte, CTE, RDBASE, rdbase); } =20 - /* - * The specification defines the format of level 1 entries of a - * 2-level table, but the format of level 2 entries and the format - * of flat-mapped tables is IMPDEF. - */ - if (s->ct.indirect) { - l2t_id =3D icid / (s->ct.page_sz / L1TABLE_ENTRY_SIZE); - - value =3D address_space_ldq_le(as, - s->ct.base_addr + - (l2t_id * L1TABLE_ENTRY_SIZE), - MEMTXATTRS_UNSPECIFIED, &res); - - if (res !=3D MEMTX_OK) { - return false; - } - - valid_l2t =3D (value & L2_TABLE_VALID_MASK) !=3D 0; - - if (valid_l2t) { - num_l2_entries =3D s->ct.page_sz / s->ct.entry_sz; - - l2t_addr =3D value & ((1ULL << 51) - 1); - - address_space_stq_le(as, l2t_addr + - ((icid % num_l2_entries) * GITS_CTE_SIZE), - cte, MEMTXATTRS_UNSPECIFIED, &res); - } - } else { - /* Flat level table */ - address_space_stq_le(as, s->ct.base_addr + (icid * GITS_CTE_SIZE), - cte, MEMTXATTRS_UNSPECIFIED, &res); - } + entry_addr =3D table_entry_addr(s, &s->ct, icid, &res); if (res !=3D MEMTX_OK) { + /* memory access error: stall */ return false; - } else { + } + if (entry_addr =3D=3D -1) { + /* No L2 table for this index: discard write and continue */ return true; } + + address_space_stq_le(as, entry_addr, cte, MEMTXATTRS_UNSPECIFIED, &res= ); + return res =3D=3D MEMTX_OK; } =20 static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset) @@ -529,11 +488,7 @@ static bool update_dte(GICv3ITSState *s, uint32_t devi= d, bool valid, uint8_t size, uint64_t itt_addr) { AddressSpace *as =3D &s->gicv3->dma_as; - uint64_t value; - uint64_t l2t_addr; - bool valid_l2t; - uint32_t l2t_id; - uint32_t num_l2_entries; + uint64_t entry_addr; uint64_t dte =3D 0; MemTxResult res =3D MEMTX_OK; =20 @@ -548,44 +503,17 @@ static bool update_dte(GICv3ITSState *s, uint32_t dev= id, bool valid, return true; } =20 - /* - * The specification defines the format of level 1 entries of a - * 2-level table, but the format of level 2 entries and the format - * of flat-mapped tables is IMPDEF. - */ - if (s->dt.indirect) { - l2t_id =3D devid / (s->dt.page_sz / L1TABLE_ENTRY_SIZE); - - value =3D address_space_ldq_le(as, - s->dt.base_addr + - (l2t_id * L1TABLE_ENTRY_SIZE), - MEMTXATTRS_UNSPECIFIED, &res); - - if (res !=3D MEMTX_OK) { - return false; - } - - valid_l2t =3D (value & L2_TABLE_VALID_MASK) !=3D 0; - - if (valid_l2t) { - num_l2_entries =3D s->dt.page_sz / s->dt.entry_sz; - - l2t_addr =3D value & ((1ULL << 51) - 1); - - address_space_stq_le(as, l2t_addr + - ((devid % num_l2_entries) * GITS_DTE_SIZE= ), - dte, MEMTXATTRS_UNSPECIFIED, &res); - } - } else { - /* Flat level table */ - address_space_stq_le(as, s->dt.base_addr + (devid * GITS_DTE_SIZE), - dte, MEMTXATTRS_UNSPECIFIED, &res); - } + entry_addr =3D table_entry_addr(s, &s->dt, devid, &res); if (res !=3D MEMTX_OK) { + /* memory access error: stall */ return false; - } else { + } + if (entry_addr =3D=3D -1) { + /* No L2 table for this index: discard write and continue */ return true; } + address_space_stq_le(as, entry_addr, dte, MEMTXATTRS_UNSPECIFIED, &res= ); + return res =3D=3D MEMTX_OK; } =20 static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value, --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641923562089672.5482571117897; Tue, 11 Jan 2022 09:52:42 -0800 (PST) Received: from localhost ([::1]:60020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7LK5-0002c4-04 for importer@patchew.org; Tue, 11 Jan 2022 12:52:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfq-0005D8-4a for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:11 -0500 Received: from [2a00:1450:4864:20::431] (port=46927 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0007L0-FQ for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:04 -0500 Received: by mail-wr1-x431.google.com with SMTP id l25so23366634wrb.13 for ; Tue, 11 Jan 2022 09:11:00 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WpU33ZVGPAyCC9DTXzdZDHcDLe8eur6K3oHNtIfAuUs=; b=szDT6OJxANgIElJmFK6SuaPQKe0pFaJNPg6rQJcpyRqt4rkVYc8gi/9uevnCpm6/Jv pFMVFbnE4JMdXffnwMk7kF2OPsQPM+ChH+wEhiz4f296p9kOpA1n3sDIv7p65aK4Mn4E AyqXkD1Ugij3w4/DBOiBo8jocTT578lM/9PqB6sjMfLbNhDhV4VyNUN68psUoEl/TOl2 BoKl3408EHGcd4xdnrGViO0R8h8/7/nHzi2l0ifYAV3rCP1kaOltRKEwOPLzc6KNNc1M ZdNiOOqAqQT97Z/SIYsFnZ5ugpTNDgx/az//LOzhOvyT5aKjqQLZR9CKqWZD+tWdhfrH QdSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WpU33ZVGPAyCC9DTXzdZDHcDLe8eur6K3oHNtIfAuUs=; b=0wQVjsYCwzwqdw7FAi9pELS/VXAI3opsm6H9Yuqtz4/S0s2KCLSw4BnFf32G86X07f e5SJrehs5CBxiFGf9ZElihVlSa6JpLkaa3i6LumjNUyMihHWkmOLWwE8IhyZqxkCqu65 nSFrWFYy+qqgwv5K7MPwthhtsrrMn976DyaUKo+8YHvXxCgkmQdVaeSkkUTHHGEAM9qw aBbHhUM/9XT1SjNfFaMyJ9g8FTM1jh+5fka2vpshEmM9pC8lLmFz1YExiWW26W8FURso 28Dx85PoTDVIWK24EmH1vHjLHg9YGy1AndZPNtO4pyy3UDVlqOa4E0nwhc2v1DwDUQ73 PwIw== X-Gm-Message-State: AOAM530d5ARXt1XIXZna6Jpd9xbmIc82sg4WstQxuug339tJG1aNQZSr CulnlVGQoyECaTZyJCQkAnwZTn/dSkx8pg== X-Google-Smtp-Source: ABdhPJztl3iR9W5DfAB4WXN8g0TqV8VKRn2H0FGsK8nBXHXm3jg+Lt0RNUNtM+1tF9xQdAQxGiObKw== X-Received: by 2002:adf:f390:: with SMTP id m16mr4659738wro.651.1641921059252; Tue, 11 Jan 2022 09:10:59 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 12/13] hw/intc/arm_gicv3_its: Check indexes before use, not after Date: Tue, 11 Jan 2022 17:10:47 +0000 Message-Id: <20220111171048.3545974-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) 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=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641923563029100003 Content-Type: text/plain; charset="utf-8" In a few places in the ITS command handling functions, we were doing the range-check of an event ID or device ID only after using it as a table index; move the checks to before the uses. This misordering wouldn't have very bad effects because the tables are in guest memory anyway. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 42 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 985e316eda9..ef6c0f55ff9 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -255,6 +255,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, = uint64_t value, =20 eventid =3D (value & EVENTID_MASK); =20 + if (devid >=3D s->dt.num_ids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: devid %d>=3D%d", + __func__, devid, s->dt.num_ids); + return CMD_CONTINUE; + } + dte =3D get_dte(s, devid, &res); =20 if (res !=3D MEMTX_OK) { @@ -272,6 +279,14 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, = uint64_t value, =20 num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); =20 + if (eventid >=3D num_eventids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: eventid %d >=3D %" + PRId64 "\n", + __func__, eventid, num_eventids); + return CMD_CONTINUE; + } + ite_valid =3D get_ite(s, eventid, dte, &icid, &pIntid, &res); if (res !=3D MEMTX_OK) { return CMD_STALL; @@ -296,20 +311,6 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, = uint64_t value, return CMD_CONTINUE; } =20 - if (devid >=3D s->dt.num_ids) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: devid %d>=3D%d", - __func__, devid, s->dt.num_ids); - return CMD_CONTINUE; - } - if (eventid >=3D num_eventids) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: eventid %d >=3D %" - PRId64 "\n", - __func__, eventid, num_eventids); - return CMD_CONTINUE; - } - /* * Current implementation only supports rdbase =3D=3D procnum * Hence rdbase physical address is ignored @@ -375,6 +376,13 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, ui= nt64_t value, =20 icid =3D value & ICID_MASK; =20 + if (devid >=3D s->dt.num_ids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: devid %d>=3D%d", + __func__, devid, s->dt.num_ids); + return CMD_CONTINUE; + } + dte =3D get_dte(s, devid, &res); =20 if (res !=3D MEMTX_OK) { @@ -384,14 +392,14 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, u= int64_t value, num_eventids =3D 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); num_intids =3D 1ULL << (GICD_TYPER_IDBITS + 1); =20 - if ((devid >=3D s->dt.num_ids) || (icid >=3D s->ct.num_ids) + if ((icid >=3D s->ct.num_ids) || !dte_valid || (eventid >=3D num_eventids) || (((pIntid < GICV3_LPI_INTID_START) || (pIntid >=3D num_intids)= ) && (pIntid !=3D INTID_SPURIOUS))) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes " - "devid %d or icid %d or eventid %d or pIntid %d or" - "unmapped dte %d\n", __func__, devid, icid, eventid, + "icid %d or eventid %d or pIntid %d or" + "unmapped dte %d\n", __func__, icid, eventid, pIntid, dte_valid); /* * in this implementation, in case of error --=20 2.25.1 From nobody Sun May 5 12:06:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1641921857312742.6492130922342; Tue, 11 Jan 2022 09:24:17 -0800 (PST) Received: from localhost ([::1]:59936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7Ksa-0003mw-6A for importer@patchew.org; Tue, 11 Jan 2022 12:24:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7Kfq-0005DC-4g for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:11 -0500 Received: from [2a00:1450:4864:20::42c] (port=44655 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7Kfl-0007LC-GO for qemu-devel@nongnu.org; Tue, 11 Jan 2022 12:11:05 -0500 Received: by mail-wr1-x42c.google.com with SMTP id k18so34173169wrg.11 for ; Tue, 11 Jan 2022 09:11:00 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id c7sm11157941wri.21.2022.01.11.09.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bD0PDqtOotm00lmQT/lZs8XVkkqOyVklOaZCqmm8ZmM=; b=F1eAfaZphieMMS6rwNRSadXE8oXaLTNK69dQf8YByZA/0xfinJyFTO4mtV8l+7RtGA +RwXEAQOq0F+jwLc7/U+CcScBu8+SaiVPW5C+thjq8f2dJtu09fdfYXchac4HJt3LNUW cKk8JldGCgR/J+Iv6Fh9MTtoUHpl4JEmzYoI5VdBQgJwjHPdcYXkPYFDJvLu3cSnCFdn k3jBTIS8/eKC5drfU0zkPY5vHB5o/3Ed62Wsi1CDs6IlL/rUUM2HLJFURBh+jWlDvB4H Tkd3PXjcqDI6O17E53WSce029r7oymx3rkdNSXO9wd5R5XyK+VoUqcBjtIl9iUEK7KBA sRMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bD0PDqtOotm00lmQT/lZs8XVkkqOyVklOaZCqmm8ZmM=; b=Jew02HBwzk0onzpJ7MhVDHa80JF/6DefWcffOYePiE+DS/6Afs0kA3Rl4VszwZ3H6x b1qkTly6HGKYUmUMrfZbmHCwTW4aH8kyeJDvQRKznZ6reFA1nqLQAftwrkx3GjN/oaCr KfEZw5GoRzW4UJ78FZB15SLr3QFiVoNcBbGINBXOw3UeUY5lVPmHJTCI3+6eyB/RE+jL ACVy6j9vtFJM3m7m+mV6ov5ZljJsYH2bJ/cPoWeYxw2Bb0Z2o3kCQGOVhOrEffSRVkN3 U592fWNtvujoP5JdtTbJ/oYeoNP6jkewZPUUczB+p6cMYwmWuRm1BJDNyGQoQdw9obvU aQGg== X-Gm-Message-State: AOAM533smX6uxAHTDlr0+fFh+Cal3yBb8rkAqmR6dAAaIbYzUA9u2fbI iecnhTLBM0pzKDV/R23BaciMyQ== X-Google-Smtp-Source: ABdhPJykDA7kA5IWu0h4RQX0vFDYTzyfOXYbLxTWO0HxsPRbZiE6YhSKnJFVYAUC568hZUoV+hYIaw== X-Received: by 2002:a05:6000:1883:: with SMTP id a3mr4811662wri.565.1641921059907; Tue, 11 Jan 2022 09:10:59 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 13/13] hw/intc/arm_gicv3_its: Range-check ICID before indexing into collection table Date: Tue, 11 Jan 2022 17:10:48 +0000 Message-Id: <20220111171048.3545974-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220111171048.3545974-1-peter.maydell@linaro.org> References: <20220111171048.3545974-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) 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=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.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, 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: , Cc: Shashi Mallela , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641921858661100001 Content-Type: text/plain; charset="utf-8" In process_its_cmd(), we read an ICID out of the interrupt table entry, and then use it as an index into the collection table. Add a check that it is within range for the collection table first. This check is not strictly necessary, because: * we range check the ICID from the guest before writing it into the interrupt table entry, so the the only way to get an out of range ICID in process_its_cmd() is if a badly-behaved guest is writing directly to the interrupt table memory * the collection table is in guest memory, so QEMU won't fall over if we read off the end of it However, it seems clearer to include the check. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index ef6c0f55ff9..b2f6a8c7f00 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -299,6 +299,13 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, = uint64_t value, return CMD_CONTINUE; } =20 + if (icid >=3D s->ct.num_ids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid ICID 0x%x in ITE (table corrupted?)\n", + __func__, icid); + return CMD_CONTINUE; + } + cte_valid =3D get_cte(s, icid, &cte, &res); if (res !=3D MEMTX_OK) { return CMD_STALL; --=20 2.25.1