From patchwork Sun Feb 11 03:42:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 10210709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E44D360247 for ; Sun, 11 Feb 2018 03:42:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3EC8285B6 for ; Sun, 11 Feb 2018 03:42:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B418D285BA; Sun, 11 Feb 2018 03:42:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6693285B6 for ; Sun, 11 Feb 2018 03:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=uX2JMrMfW2KyzEjcdXlttGHIAarbexVYyRhcIbyvT+k=; b=Btit9Ah7lhcGBHpiwoCl3bZAzp Gn0oneB7qYrBMH1Xf7kIN1jt5DITQhOXC0bjQ+ebBvIKq59spAlR3FNoogx6BhuDFAX28L17aDN0X Ro/SgPHGP2P0O95v6J0IXFouD9FAo1AqXmF+9azrIiRnltzthRGF4l8Q1KETPJ+5gBnuPKNWuC3jy oB7BRKP43KVWmBoVIppBSxKS6IdIAxgg2e2mzKyu8YLZOBJ1DIninscchUVoNMwKB4nXzxX/5X+fe tYRD0CToVi4R7ab/QLr2xrWEBffbajAptPsTitXANtXgbkB9iGjR7ZQovvhrO/2LDCKun7ic8eIbG F08QKd5g==; Received: from [198.137.202.133] (helo=bombadil.infradead.org) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ekiXG-0007xz-KW for patchwork-linux-arm@patchwork.kernel.org; Sun, 11 Feb 2018 03:42:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=uX2JMrMfW2KyzEjcdXlttGHIAarbexVYyRhcIbyvT+k=; b=T19iWACMhRlqk7 PUSjC+rH71yN8i0EEZkIkxjXY9o0Aj5Xve8pf9Ht6Dco9/QxI+W5SAxB9VwfkSfAQymWUjlV3eq5q eHelh9t5W55iJxF4rPzGXzzL1GZTSLNelFpRDQ0OQ3dWNBV6VCQtO2Y+a1wSEIWS0lbeaa1tQ+EHd iMJb7O9dIHeYoPK7uFOFVRnAcZVKIBOsa7xaOlBoz0bJvpr7C33J6NBOW0/ZMXYhwms9/uHV182Lx Tl76PevQ6g+x7o3PbOZZ7yKzCgzPS6gP2GXjrMob3eXF2hYijIR2sXqVBdiia5oNTIUDeRw9M6zQJ edobB9+jA58Z1gF8TITw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ekiXE-0006Dn-ML; Sun, 11 Feb 2018 03:42:36 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ekiXA-0006Dd-Be for linux-arm-kernel@lists.infradead.org; Sun, 11 Feb 2018 03:42:34 +0000 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7E2319B147DA5; Sun, 11 Feb 2018 11:42:03 +0800 (CST) Received: from localhost (10.177.19.219) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.361.1; Sun, 11 Feb 2018 11:41:56 +0800 From: Yang Yingliang To: , Subject: [PATCH] irqchip/gic-v3-its: handle rd_idx wrapping in its_wait_for_range_completion() Date: Sun, 11 Feb 2018 11:42:01 +0800 Message-ID: <1518320521-12536-1-git-send-email-yangyingliang@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.177.19.219] X-CFilter-Loop: Reflected X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yangyingliang@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In direct case, rd_idx will wrap if other cpus post commands that make rd_idx increase. When rd_idx wrapped, the driver prints timeout messages but in fact the command is finished. To handle this case by adding last_rd_id to check rd_idx whether wrapped. Signed-off-by: Yang Yingliang --- drivers/irqchip/irq-gic-v3-its.c | 84 ++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 06f025f..d7176d1 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -713,7 +713,8 @@ static void its_flush_cmd(struct its_node *its, struct its_cmd_block *cmd) static int its_wait_for_range_completion(struct its_node *its, struct its_cmd_block *from, - struct its_cmd_block *to) + struct its_cmd_block *to, + u64 last_rd_idx) { u64 rd_idx, from_idx, to_idx; u32 count = 1000000; /* 1s! */ @@ -724,9 +725,14 @@ static int its_wait_for_range_completion(struct its_node *its, while (1) { rd_idx = readl_relaxed(its->base + GITS_CREADR); - /* Direct case */ - if (from_idx < to_idx && rd_idx >= to_idx) - break; + + /* + * Direct case. In this case, rd_idx may wrapped, + * because other cpus may post commands that make + * rd_idx increase. + */ + if (from_idx < to_idx && (rd_idx >= to_idx || rd_idx < last_rd_idx)) + break; /* Wrapped case */ if (from_idx >= to_idx && rd_idx >= to_idx && rd_idx < from_idx) @@ -746,40 +752,42 @@ static int its_wait_for_range_completion(struct its_node *its, } /* Warning, macro hell follows */ -#define BUILD_SINGLE_CMD_FUNC(name, buildtype, synctype, buildfn) \ -void name(struct its_node *its, \ - buildtype builder, \ - struct its_cmd_desc *desc) \ -{ \ - struct its_cmd_block *cmd, *sync_cmd, *next_cmd; \ - synctype *sync_obj; \ - unsigned long flags; \ - \ - raw_spin_lock_irqsave(&its->lock, flags); \ - \ - cmd = its_allocate_entry(its); \ - if (!cmd) { /* We're soooooo screewed... */ \ - raw_spin_unlock_irqrestore(&its->lock, flags); \ - return; \ - } \ - sync_obj = builder(its, cmd, desc); \ - its_flush_cmd(its, cmd); \ - \ - if (sync_obj) { \ - sync_cmd = its_allocate_entry(its); \ - if (!sync_cmd) \ - goto post; \ - \ - buildfn(its, sync_cmd, sync_obj); \ - its_flush_cmd(its, sync_cmd); \ - } \ - \ -post: \ - next_cmd = its_post_commands(its); \ - raw_spin_unlock_irqrestore(&its->lock, flags); \ - \ - if (its_wait_for_range_completion(its, cmd, next_cmd)) \ - pr_err_ratelimited("ITS cmd %ps failed\n", builder); \ +#define BUILD_SINGLE_CMD_FUNC(name, buildtype, synctype, buildfn) \ +void name(struct its_node *its, \ + buildtype builder, \ + struct its_cmd_desc *desc) \ +{ \ + struct its_cmd_block *cmd, *sync_cmd, *next_cmd; \ + synctype *sync_obj; \ + unsigned long flags; \ + u64 last_rd_idx; \ + \ + raw_spin_lock_irqsave(&its->lock, flags); \ + \ + cmd = its_allocate_entry(its); \ + if (!cmd) { /* We're soooooo screewed... */ \ + raw_spin_unlock_irqrestore(&its->lock, flags); \ + return; \ + } \ + sync_obj = builder(its, cmd, desc); \ + its_flush_cmd(its, cmd); \ + \ + if (sync_obj) { \ + sync_cmd = its_allocate_entry(its); \ + if (!sync_cmd) \ + goto post; \ + \ + buildfn(its, sync_cmd, sync_obj); \ + its_flush_cmd(its, sync_cmd); \ + } \ + \ +post: \ + next_cmd = its_post_commands(its); \ + last_rd_idx = readl_relaxed(its->base + GITS_CREADR); \ + raw_spin_unlock_irqrestore(&its->lock, flags); \ + \ + if (its_wait_for_range_completion(its, cmd, next_cmd, last_rd_idx)) \ + pr_err_ratelimited("ITS cmd %ps failed\n", builder); \ } static void its_build_sync_cmd(struct its_node *its,