From patchwork Fri Apr 8 14:15:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 558813 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp368727map; Fri, 8 Apr 2022 07:24:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz5Zyk3X6+fgXaWaiYDZAG2iwLgekbVWdKwoG7sXhFSZDCUwdRFXK55BQsBhKKjsXdzOV0 X-Received: by 2002:a81:6d05:0:b0:2ea:cb7f:9fc0 with SMTP id i5-20020a816d05000000b002eacb7f9fc0mr16454001ywc.297.1649427868228; Fri, 08 Apr 2022 07:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649427868; cv=none; d=google.com; s=arc-20160816; b=jCmLa0oNi4DVqwbadMMVBMPLFce9NlvX/9Z9NegKQKET7ShnCYl3Vx4t9rOGr+XOJ+ yQH+ZUCFJ9l9RxHTYeSno4ioCnGTXL3dqgz8EqMb4Wk4pSjeUZzVhS1VRRRZlYNoAB+E 4a9v7ZXop2R97guXCKKPGqKs8koBtKI4oizCFBh+4kOBFGvbxL99fmc8oyzhn3im+fQ6 fMgAGTc8B8ryzBH50F80tSPP2nfjfGT/e39nT165qvOEFwKaKSJzkf0MxH7U6rjpSO2P rqOGO02m/QUclTwXrffZF3ho3ICJAP0b3Zh5LQWpqOjwGgt2QyuTOArNqjdUsiATiJ1H VBcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=JOex7zXlNRw0uzuroIWAH3oSHzCyU5BsmZyuU+iBsAg=; b=V+X9gvhXpcg7I4NrDqJju9kMT3Kizz8gMTOCeNtSu7LRLKF0Wj6iLFqMd39uotOkxX SGKTlGxHkbTYBvPbjguU+QCOC/tkZzX6mA+edcno5LGhKusxdI2wrcqLBBF93kfVUL9f BeJ3FuyogMLOWxl3Ledvm2ep6exDFEJFzxQHR+7f2F6aEM62kepZKCR9pbL2SjYwp1CY WYakdHX0IZQenii83lMeIdV4CDkoMQuULXSGRQEijYIHfzozmJzvO5GKjmuNQp+ggkIY kT4j2oSFHDcnDQembmkpATD+pfku6RlWEGh8GEjHH4y4eph6pqH4ZPgGRNJ+YR1hrt0n 8cCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z5xyUyJt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n141-20020a254093000000b00640abf88026si596616yba.501.2022.04.08.07.24.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Apr 2022 07:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z5xyUyJt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncpXH-00053h-LV for patch@linaro.org; Fri, 08 Apr 2022 10:24:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncpPE-0006tL-I7 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 10:16:08 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:41559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncpPB-0002Gs-JM for qemu-devel@nongnu.org; Fri, 08 Apr 2022 10:16:08 -0400 Received: by mail-wr1-x436.google.com with SMTP id k23so13058702wrd.8 for ; Fri, 08 Apr 2022 07:16:05 -0700 (PDT) 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=JOex7zXlNRw0uzuroIWAH3oSHzCyU5BsmZyuU+iBsAg=; b=Z5xyUyJtVHYr9slW6m5SYyXHiJXuuJ75Gqwz4Y24DRViQ8IrkcFmponXZVr34+OPDV I53o/9vqqxp+TRsFWBTJ5wQIOJ4eHdZIZy/PPldaoS6PfzM9QfzwYZdUr6+H9kt0v7Qr p0mniG4q3pQ1as/bJD6LaySREhYsUWxq/PLaU0BVX8OEQ5O0qwVdqETYTZsWcxKH9Uk4 dNaP9oYuDyEb5OqP7tBS3nNphBZxqFO82WJao+2olauMfTGEvPaoLzmXJqaiPjB/80cp ZCsZV8iOhDJtUgfWw78p4gBwJHISqK4fAe0ZjX/YRASYFlvG+hpRFmYEUeB8EyYyElY7 Uw6Q== 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=JOex7zXlNRw0uzuroIWAH3oSHzCyU5BsmZyuU+iBsAg=; b=sPAkho2Kfht2pK2VcdEce2Fqp/uH5S4ozzM87O1ppLSsCCrUXJaJWW6DzA60X0snk0 GtR76eFFH81u3WZxZBRA+ZWriiIQNsUzHjj3TNAiKxWx3+xfINSJ8Es88BcVeQORxmRF EeRQ0wx3MTZgH9SwYr+AG70m8BaxPsrsPc4eJNOzj1KdK0GBeit2EmHHrxWFwHFejbQZ ZdY5kYKUEg0FFpl1NOFhvmVyistxexld+xUyf1g7gSAtXYoW7im6I7qp0422hugGyLhA 2l04lnmdGyfm4bUQwp7OroXmHCjP7LMkz4H2MwqXuAU+hn4wCLmQeARWdMejheZJcs6w bmbg== X-Gm-Message-State: AOAM531DJTteLXwIJtyJNJIr2fMrY0xADmsORqI1XcBkcAEeMpNnYoTI o6/dqdUbiPaoKOZefXldDoqeZkNPXWZdvQ== X-Received: by 2002:a05:6000:1866:b0:204:cce:c89e with SMTP id d6-20020a056000186600b002040ccec89emr16011389wri.601.1649427364248; Fri, 08 Apr 2022 07:16:04 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i3-20020adffc03000000b0020616ee90dbsm11498849wrr.42.2022.04.08.07.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 07:16:03 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 11/41] hw/intc/arm_gicv3_its: Factor out "find ITE given devid, eventid" Date: Fri, 8 Apr 2022 15:15:20 +0100 Message-Id: <20220408141550.1271295-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220408141550.1271295-1-peter.maydell@linaro.org> References: <20220408141550.1271295-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The operation of finding an interrupt table entry given a (DeviceID, EventID) pair is necessary in multiple different ITS commands. The process requires first using the DeviceID as an index into the device table to find the DTE, and then useng the EventID as an index into the interrupt table specified by that DTE to find the ITE. We also need to handle all the possible error cases: indexes out of range, table memory not readable, table entries not valid. Factor this out into a separate lookup_ite() function which we can then call from the places where we were previously open-coding this sequence. We'll also need this for some of the new GICv4.0 commands. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/intc/arm_gicv3_its.c | 124 +++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index ba1893c072b..fe1bea2dd81 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -314,6 +314,60 @@ out: return res; } +/* + * Given a (DeviceID, EventID), look up the corresponding ITE, including + * checking for the various invalid-value cases. If we find a valid ITE, + * fill in @ite and @dte and return CMD_CONTINUE_OK. Otherwise return + * CMD_STALL or CMD_CONTINUE as appropriate (and the contents of @ite + * should not be relied on). + * + * The string @who is purely for the LOG_GUEST_ERROR messages, + * and should indicate the name of the calling function or similar. + */ +static ItsCmdResult lookup_ite(GICv3ITSState *s, const char *who, + uint32_t devid, uint32_t eventid, ITEntry *ite, + DTEntry *dte) +{ + uint64_t num_eventids; + + if (devid >= s->dt.num_entries) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: devid %d>=%d", + who, devid, s->dt.num_entries); + return CMD_CONTINUE; + } + + if (get_dte(s, devid, dte) != MEMTX_OK) { + return CMD_STALL; + } + if (!dte->valid) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: " + "invalid dte for %d\n", who, devid); + return CMD_CONTINUE; + } + + num_eventids = 1ULL << (dte->size + 1); + if (eventid >= num_eventids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: eventid %d >= %" + PRId64 "\n", who, eventid, num_eventids); + return CMD_CONTINUE; + } + + if (get_ite(s, eventid, dte, ite) != MEMTX_OK) { + return CMD_STALL; + } + + if (!ite->valid) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid command attributes: invalid ITE\n", who); + return CMD_CONTINUE; + } + + return CMD_CONTINUE_OK; +} + /* * This function handles the processing of following commands based on * the ItsCmdType parameter passed:- @@ -325,42 +379,17 @@ out: static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, uint32_t eventid, ItsCmdType cmd) { - uint64_t num_eventids; DTEntry dte; CTEntry cte; ITEntry ite; + ItsCmdResult cmdres; - if (devid >= s->dt.num_entries) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: devid %d>=%d", - __func__, devid, s->dt.num_entries); - return CMD_CONTINUE; + cmdres = lookup_ite(s, __func__, devid, eventid, &ite, &dte); + if (cmdres != CMD_CONTINUE_OK) { + return cmdres; } - if (get_dte(s, devid, &dte) != MEMTX_OK) { - return CMD_STALL; - } - if (!dte.valid) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: " - "invalid dte for %d\n", __func__, devid); - return CMD_CONTINUE; - } - - num_eventids = 1ULL << (dte.size + 1); - if (eventid >= num_eventids) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: eventid %d >= %" - PRId64 "\n", - __func__, eventid, num_eventids); - return CMD_CONTINUE; - } - - if (get_ite(s, eventid, &dte, &ite) != MEMTX_OK) { - return CMD_STALL; - } - - if (!ite.valid || ite.inttype != ITE_INTTYPE_PHYSICAL) { + if (ite.inttype != ITE_INTTYPE_PHYSICAL) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: invalid ITE\n", __func__); @@ -740,10 +769,10 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) { uint32_t devid, eventid; uint16_t new_icid; - uint64_t num_eventids; DTEntry dte; CTEntry old_cte, new_cte; ITEntry old_ite; + ItsCmdResult cmdres; devid = FIELD_EX64(cmdpkt[0], MOVI_0, DEVICEID); eventid = FIELD_EX64(cmdpkt[1], MOVI_1, EVENTID); @@ -751,37 +780,12 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) trace_gicv3_its_cmd_movi(devid, eventid, new_icid); - if (devid >= s->dt.num_entries) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: devid %d>=%d", - __func__, devid, s->dt.num_entries); - return CMD_CONTINUE; - } - if (get_dte(s, devid, &dte) != MEMTX_OK) { - return CMD_STALL; + cmdres = lookup_ite(s, __func__, devid, eventid, &old_ite, &dte); + if (cmdres != CMD_CONTINUE_OK) { + return cmdres; } - if (!dte.valid) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: " - "invalid dte for %d\n", __func__, devid); - return CMD_CONTINUE; - } - - num_eventids = 1ULL << (dte.size + 1); - if (eventid >= num_eventids) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: eventid %d >= %" - PRId64 "\n", - __func__, eventid, num_eventids); - return CMD_CONTINUE; - } - - if (get_ite(s, eventid, &dte, &old_ite) != MEMTX_OK) { - return CMD_STALL; - } - - if (!old_ite.valid || old_ite.inttype != ITE_INTTYPE_PHYSICAL) { + if (old_ite.inttype != ITE_INTTYPE_PHYSICAL) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: invalid ITE\n", __func__);