From patchwork Mon Sep 21 11:51:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1368298 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ThNdYv5V; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bw2qh2Wj4z9sV0 for ; Mon, 21 Sep 2020 21:52:32 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AA3FB8255D; Mon, 21 Sep 2020 13:52:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ThNdYv5V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DDC48255D; Mon, 21 Sep 2020 13:52:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EBA0F82525 for ; Mon, 21 Sep 2020 13:51:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x843.google.com with SMTP id p65so11920068qtd.2 for ; Mon, 21 Sep 2020 04:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/d21Imbmsi+AnJb6SY6eTwSMHfpXNj0ALmGNqMGzOck=; b=ThNdYv5VFNZ+U5u/UGH1rOgcDsTcqA2DyVGlGQf5UEUcTnJJzO2BLHv5P3X0GXFmmE xqudkBjUu7dECElroaqzf/f4LRnKy3nV2G9sXNhnEJq+1iMchdL3yVAGvJO1twHMrlZ5 ohFUp465EUWAdUnxiHExMzovn2Hlt0x/y/1ptfeZHON7dluewR9A3zwmMuw4b+KsyErm wQF1i8PQFiPt6Z8zFmHy+ljfPOOlaRBIlrPNz9uwqwiCGoAwGJCGZVaoS8WS1DXdu7YG fXcpTSLadWHXAiy7LwycfkjfDZNgWMu6VWw8KdILwy7pvO3pv6Ojop09NZJUBoYXhaZw 32qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/d21Imbmsi+AnJb6SY6eTwSMHfpXNj0ALmGNqMGzOck=; b=ooSJmx5BslESjFOMeu92Jmh47kYX9Qof6q+5+fzbc/jr3csI4lX80wh4y6JDIEdH8D Xj55+H1P9vNMeXUQHS6xLwxhML1Kc78qB6D/E6DxiK9VmtpUn73qd7z3wlOpw6jfk3V+ b+Q7xndGaxtC5b2jWZGzYChWjK1bMXy441GY9fM0VChoF7z6AaA7is514EwNKK/+H/lz lWUjIa4drXTyMUzuisBlHlUm3Rn54xlLKDAVn9CPi/Q26t9EIKfxEmcZ1CgJAz2TT/Al lWE4ZJ+9RWkbwRzNyPz6M2xoD8k9+aSvBqS2zVXSVoFsUF2Fe/EE8/MQLzFg1FsYM+Fs Rotw== X-Gm-Message-State: AOAM532FOpq6cGurTz1qV54Jap+Qg8B74Em37LjqLUyezXvt+bIG5E+u 4XjSIOS9eKeBwmjHDOErCHxi8Y6ZVMjvjQ== X-Google-Smtp-Source: ABdhPJz9YCL8pKFFlFjadq/HWlJB4rzdFK7ZFm6vtuikvuAFZn6f+r8pm6LUnZuXQpylsIFhNGmvMg== X-Received: by 2002:aed:2c61:: with SMTP id f88mr33035110qtd.388.1600689117665; Mon, 21 Sep 2020 04:51:57 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id c70sm8658105qkg.4.2020.09.21.04.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 04:51:57 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Rick Chen , alankao@andestech.com, Leo Liang , Bin Meng , Sean Anderson , Bin Meng , Rick Chen Subject: [PATCH v3 3/7] riscv: Use a valid bit to ignore already-pending IPIs Date: Mon, 21 Sep 2020 07:51:37 -0400 Message-Id: <20200921115141.70598-4-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921115141.70598-1-seanga2@gmail.com> References: <20200921115141.70598-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Some IPIs may already be pending when U-Boot is started. This could be a problem if a secondary hart tries to handle an IPI before the boot hart has initialized the IPI device. To be specific, the Kendryte K210 ROM-based bootloader does not clear IPIs before passing control to U-Boot. Without this patch, the secondary hart jumps to address 0x0 as soon as it enters secondary_hart_loop, and then hangs in its trap handler. This commit introduces a valid bit so secondary harts know when and IPI originates from U-Boot, and it is safe to use the IPI API. The valid bit is initialized to 0 by board_init_f_init_reserve. Before this, secondary harts wait in wait_for_gd_init. Signed-off-by: Sean Anderson Reviewed-by: Bin Meng Reviewed-by: Rick Chen Reviewed-by: Leo Liang --- (no changes since v2) Changes in v2: - Use a valid bit instead of addr to validate IPIs arch/riscv/include/asm/smp.h | 7 +++++++ arch/riscv/lib/smp.c | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 1b428856b2..2dae0800ce 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -18,14 +18,21 @@ * IPI data structure. The hart ID is inserted by the hart handling the IPI and * calling the function. * + * @valid is used to determine whether a sent IPI originated from U-Boot. It is + * initialized to zero by board_init_f_alloc_reserve. When U-Boot sends its + * first IPI, it is set to 1. This prevents already-pending IPIs not sent by + * U-Boot from being taken. + * * @addr: Address of function * @arg0: First argument of function * @arg1: Second argument of function + * @valid: Whether this IPI is valid */ struct ipi_data { ulong addr; ulong arg0; ulong arg1; + unsigned int valid; }; /** diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c index ab6d8bd7fa..8f33ce1fe3 100644 --- a/arch/riscv/lib/smp.c +++ b/arch/riscv/lib/smp.c @@ -54,7 +54,13 @@ static int send_ipi_many(struct ipi_data *ipi, int wait) gd->arch.ipi[reg].arg0 = ipi->arg0; gd->arch.ipi[reg].arg1 = ipi->arg1; - __smp_mb(); + /* + * Ensure valid only becomes set when the IPI parameters are + * set. An IPI may already be pending on other harts, so we + * need a way to signal that the IPI device has been + * initialized, and that it is ok to call the function. + */ + __smp_store_release(&gd->arch.ipi[reg].valid, 1); ret = riscv_send_ipi(reg); if (ret) { @@ -83,7 +89,13 @@ void handle_ipi(ulong hart) if (hart >= CONFIG_NR_CPUS) return; - __smp_mb(); + /* + * If valid is not set, then U-Boot has not requested the IPI. The + * IPI device may not be initialized, so all we can do is wait for + * U-Boot to initialize it and send an IPI + */ + if (!__smp_load_acquire(&gd->arch.ipi[hart].valid)) + return; smp_function = (void (*)(ulong, ulong, ulong))gd->arch.ipi[hart].addr; invalidate_icache_all();