From patchwork Fri Feb 11 11:11:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Shubin X-Patchwork-Id: 1591574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hTBCS9rK; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=maquefel.me header.i=@maquefel.me header.a=rsa-sha256 header.s=mail header.b=XVIzjGMx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jw9v64yXDz9sFw for ; Fri, 11 Feb 2022 22:12:34 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nBObLj4EcpPRRznCIAKIf/zAbXDZ+UthGBCAdKwKC60=; b=hTBCS9rKaKzOLX 35lfU553XK3L8vVgPir/UrOy1P7Og6eoVUEkSkW2j7l45VPh8MQ14O9Qs6t2qG6fFZtelhT728QbW hLewt/NjNwbc9QfAywJ+teNKBWq3eXHS1UGw8+C0KGT6ua2qFxM8VWSMbghCeH7MhhWUhpDqpvbBh SB1We1uEX5yuSmf5D+KdUAKOkL29Nf1yJymAQf42K9P23OBqDTBKp5eCxY3a3txMpOZnevmNO/UO5 sLfVAbDkzkXe0xCML1xGKV5U/ByGeV7X0p+0lnW3bru93411+a1E0ChIrJgN+X5prn5ITQ139k9qd 3FaXTABNdR9sfdn+1sxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nITqf-006pwW-9a; Fri, 11 Feb 2022 11:12:21 +0000 Received: from forward500p.mail.yandex.net ([77.88.28.110]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nITqR-006poO-9s for opensbi@lists.infradead.org; Fri, 11 Feb 2022 11:12:15 +0000 Received: from sas1-f446987054ad.qloud-c.yandex.net (sas1-f446987054ad.qloud-c.yandex.net [IPv6:2a02:6b8:c08:bf8a:0:640:f446:9870]) by forward500p.mail.yandex.net (Yandex) with ESMTP id D77FDF0164C; Fri, 11 Feb 2022 14:11:58 +0300 (MSK) Received: from sas2-34ddad429748.qloud-c.yandex.net (sas2-34ddad429748.qloud-c.yandex.net [2a02:6b8:c08:b787:0:640:34dd:ad42]) by sas1-f446987054ad.qloud-c.yandex.net (mxback/Yandex) with ESMTP id Nrnm4PkSGq-Bwc4SWVN; Fri, 11 Feb 2022 14:11:58 +0300 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1644577918; bh=Th7mFCfDjiTR1VnpiC+BJm1/0FBL8vRYDyFrM3a/KCY=; h=In-Reply-To:References:Date:Subject:To:From:Message-Id:Cc; b=XVIzjGMxcj/ucrnzlhV4ShvIy0zgc5aOfGFGwyqbGP66k6APoyF2RItST75D9Ha1i l2kpbawBCUctI3z0vOKrOk29lCtsvVW++hUHFjQSDR7eb0rZ/rrneJYnsaIm5bnCHg LettMEQkw6ZTe1aS/Yt8A50nLxcWtszoaFQcP1T8= Authentication-Results: sas1-f446987054ad.qloud-c.yandex.net; dkim=pass header.i=@maquefel.me Received: by sas2-34ddad429748.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id t07H4YKf8b-BvI04Or2; Fri, 11 Feb 2022 14:11:57 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Nikita Shubin To: opensbi@lists.infradead.org Cc: linux@yadro.com, Nikita Shubin Subject: [PATCH 3/3] lib: utils/timer: check if addr exists Date: Fri, 11 Feb 2022 14:11:55 +0300 Message-Id: <20220211111155.16121-4-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220211111155.16121-1-nikita.shubin@maquefel.me> References: <20220211111155.16121-1-nikita.shubin@maquefel.me> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220211_031207_765000_4C630330 X-CRM114-Status: GOOD ( 14.21 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Nikita Shubin In case we want shared time addr register for different mtimer's, we need to check if region was already added to domain, otherwise sbi_domain_root_add_memregion will fail and will couse init to fail [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Nikita Shubin In case we want shared time addr register for different mtimer's, we need to check if region was already added to domain, otherwise sbi_domain_root_add_memregion will fail and will couse init to fail with: init_coldboot: timer init failed (error -3) Signed-off-by: Nikita Shubin --- lib/utils/timer/aclint_mtimer.c | 51 ++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/lib/utils/timer/aclint_mtimer.c b/lib/utils/timer/aclint_mtimer.c index a957b1c..2c90e22 100644 --- a/lib/utils/timer/aclint_mtimer.c +++ b/lib/utils/timer/aclint_mtimer.c @@ -175,6 +175,9 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, { u32 i; int rc; + struct aclint_mtimer_data *last_mt = NULL; + bool skip_time_addr = false; + bool skip_timecmp_addr = false; /* Sanity checks */ if (!mt || !mt->mtime_size || @@ -206,27 +209,53 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, for (i = 0; i < mt->hart_count; i++) mtimer_hartid2data[mt->first_hartid + i] = mt; + /* Check if timer or timercmp addr already exists + * otherwise aclint_mtimer_add_regions will fail + * becouse of regions conflict. + */ + for (i = 0; i < mt->first_hartid; i++) { + if (last_mt && last_mt == mtimer_hartid2data[i]) + continue; + + if (mtimer_hartid2data[i]->mtime_addr == mt->mtime_addr) + skip_time_addr = true; + + if (mtimer_hartid2data[i]->mtimecmp_addr == mt->mtimecmp_addr) + skip_timecmp_addr = true; + + if (skip_time_addr && skip_timecmp_addr) + break; + + last_mt = mtimer_hartid2data[i]; + } + /* Add MTIMER regions to the root domain */ - if (mt->mtime_addr == (mt->mtimecmp_addr + mt->mtimecmp_size)) { + if ((mt->mtime_addr == (mt->mtimecmp_addr + mt->mtimecmp_size)) && + !skip_timecmp_addr) { rc = aclint_mtimer_add_regions(mt->mtimecmp_addr, mt->mtime_size + mt->mtimecmp_size); if (rc) return rc; - } else if (mt->mtimecmp_addr == (mt->mtime_addr + mt->mtime_size)) { + } else if (mt->mtimecmp_addr == (mt->mtime_addr + mt->mtime_size) && + !skip_time_addr) { rc = aclint_mtimer_add_regions(mt->mtime_addr, mt->mtime_size + mt->mtimecmp_size); if (rc) return rc; } else { - rc = aclint_mtimer_add_regions(mt->mtime_addr, - mt->mtime_size); - if (rc) - return rc; - - rc = aclint_mtimer_add_regions(mt->mtimecmp_addr, - mt->mtimecmp_size); - if (rc) - return rc; + if (!skip_time_addr) { + rc = aclint_mtimer_add_regions(mt->mtime_addr, + mt->mtime_size); + if (rc) + return rc; + } + + if (!skip_timecmp_addr) { + rc = aclint_mtimer_add_regions(mt->mtimecmp_addr, + mt->mtimecmp_size); + if (rc) + return rc; + } } mtimer.timer_freq = mt->mtime_freq;