From patchwork Mon Sep 7 18:16:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359179 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=MpDV4ocF; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 ozlabs.org (Postfix) with ESMTPS id 4Blc2Y3Ypmz9sT6 for ; Tue, 8 Sep 2020 04:17:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ED3F9824FA; Mon, 7 Sep 2020 20:17:21 +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="MpDV4ocF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E94CE824B1; Mon, 7 Sep 2020 20:17:19 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 83DFA824B1 for ; Mon, 7 Sep 2020 20:17:17 +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-qk1-x742.google.com with SMTP id v123so1808294qkd.9 for ; Mon, 07 Sep 2020 11:17:17 -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=PqGXUMGj+UZtyjA66eKl4BulkyJk1ilGhvaBq7ZBBrU=; b=MpDV4ocFj7QNdjxup+7KpYjqKcBGZ/NRVdsA1BEOcXpG/4TQLhQnZt2CIqxC5e1cJA IP/avNmaYqHXnyEOBnlSKRprhEZlD16k+8ef2nAx8hIKxo5r2D9KPp+NcBOUbTfWaFRW QJ1kezT5RQLzubvnJcKLKf8ghdvJQ5xGqQm9kbS/jlkLNaEL4Qc0IyyWniD63uDgFV5J nhUrQYKjmeQHx+4hNKbWFWhTTGgx6q3eJJzEV391JZCGCeWrDITsKlR//kN8uHfJIZ8/ SgsQpsBXsGT5mkUGTT1Ds7wV1BViYKY+tB/zKgk1SprJXInEYj8hTzVnW3FdsRH4QJpj lc+A== 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=PqGXUMGj+UZtyjA66eKl4BulkyJk1ilGhvaBq7ZBBrU=; b=MMFvP0sq1NybsUlXCbwoIu5EtqXAnpa4A19vCeqer9SHYaKLXiR0GRUthhYs6iVp5Z FQlzEgcZhWyapFl9rgjA2VX82Hbj14Xxywpr2iCWTmQBArMF3d8f4EPGtlGL5ZpIQBEy fIL+s1kDUprRuDC8+sFR24ifmEJGAKIHXOCN4O2mbTSOecrEclV+KGPeOpVyC+P/uR18 wFbAUZb5O45QyyhMZdCX67Ja2V7w++MOTbRceJwHD108cVi/q1u5yjXpJMoN+fqUrdVq 8gOlXSSYkd3LiLB/WroCoOWrv8pHa8rDtiEBqVnSVzGeXLj/befQwfO8dG9e9NFlq9eg Svxw== X-Gm-Message-State: AOAM532VqDFPSgfinxePuIB6R+U/XgjR50jPcqfRhimMThsX35G6u6cu gpg5johU48N2w/eEKdh8MI8oyGJxI1E5LA== X-Google-Smtp-Source: ABdhPJwYO+KUFjqhfJbQw0f+0cKv0b30pft2pWomnSrAgXxUJnvf3F0oVkn5QoeMp75K7GG0dWjs6w== X-Received: by 2002:a37:4711:: with SMTP id u17mr19522858qka.54.1599502636336; Mon, 07 Sep 2020 11:17:16 -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 w3sm11577212qkc.10.2020.09.07.11.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:15 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 1/7] Revert "riscv: Clear pending interrupts before enabling IPIs" Date: Mon, 7 Sep 2020 14:16:53 -0400 Message-Id: <20200907181659.92449-2-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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 Clearing MIP doesn't do anything. Whoops. The following commits should tackle this problem in a more robust manner. This reverts commit 9472630337e7c4ac442066b5a752aaa8c3b4d4a6. Signed-off-by: Sean Anderson --- arch/riscv/cpu/start.S | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index bf9fdf369b..e3222b1ea7 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -65,8 +65,6 @@ _start: #else li t0, SIE_SSIE #endif - /* Clear any pending IPIs */ - csrc MODE_PREFIX(ip), t0 csrs MODE_PREFIX(ie), t0 #endif From patchwork Mon Sep 7 18:16:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359180 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=TEzybVBA; 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 4Blc2f1q43z9sT6 for ; Tue, 8 Sep 2020 04:17:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17A4A82502; Mon, 7 Sep 2020 20:17:24 +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="TEzybVBA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCB2D824F6; Mon, 7 Sep 2020 20:17:21 +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 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 8B064824B3 for ; Mon, 7 Sep 2020 20:17:18 +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 p65so10309487qtd.2 for ; Mon, 07 Sep 2020 11:17:18 -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=qz55qPE5Kuhk+n2i5gJHk7HTy11orZR7kqBdgfkVlZ0=; b=TEzybVBAWhNnhD8NMxcTd4beo9Nl6HXi31t6Q8MxLHKdvSPY4BX6Y9WUeZpvozpRUF ugsOu/UGEy0MbTKREwKBfXpcrlMsZX2UnZ2kFj7LlPwrODhWQRcdcG83CAyywsjtTDJO muosDZAmGiiKJyR2cChGrUXJbZWWOQQoF6pUqOhIBeJinaczU5QrfS9/aQOVikQLejZe ljngDn1dNnA1A6VJ+llkMRg+q+W6LREAYhMD0LAtj13BWO/Tc4dQhFPlJYqM8uNcB5J3 Ub+EtyksRppJHyCX5pB22ZhS1UGxf3dYjpnEbXHijKCO+VBP00uswrOEsOvVf0js+RdT OeAA== 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=qz55qPE5Kuhk+n2i5gJHk7HTy11orZR7kqBdgfkVlZ0=; b=ZxrtXJ4lupa5fm+gxj6vRvJDf1iBggERjKnkFh10VHuZfAfXNjPIJtXDUIhJUPxMlO qAbLVAMZSNXfk9NFlwnCtQYWeCJ2dvUnDjkQgC3rs1vW4yBHJEsoB4bCmbrRxevJQPbK IOMqKRntNcVMb/KINGqsu9N699ZNbNlYhB3xdt0XHKZyOXjY62YBhhoF47kXNFNND+/F dj80O13YvYWrwlNXH+0AN50Oeipq2NIPJRwFztwEhRAtp1+nkCjFzIasIeSvcggYeh1T zZcBQYPqC/8EXJqFi1QE1QIcHZx9jxI/wJzkaljx/E6jueFHmvv1xhn65/R7HP4/Gqj/ n0Tg== X-Gm-Message-State: AOAM531FEi7o6fMrhdkO27r+L4o2o+hhlndll1iaiLHXN9OYsDFvxW1i 8oSLsVH3eeJYkhCY9LIHmJjQmNx8OHQ5vA== X-Google-Smtp-Source: ABdhPJwQF+k+Im16ORpLYXdnUnzaKxlBG/q9Rafg+KfYxyvIF/GLzHlCMuHNAYzdoPBHSNMfieNCew== X-Received: by 2002:ac8:794f:: with SMTP id r15mr5975888qtt.147.1599502637222; Mon, 07 Sep 2020 11:17:17 -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 w3sm11577212qkc.10.2020.09.07.11.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:16 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 2/7] riscv: Match memory barriers between send_ipi_many and handle_ipi Date: Mon, 7 Sep 2020 14:16:54 -0400 Message-Id: <20200907181659.92449-3-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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 Without a matching barrier on the write side, the barrier in handle_ipi does nothing. It was entirely possible for the boot hart to write to addr, arg0, and arg1 *after* sending the IPI, because there was no barrier on the sending side. Fixes: 90ae28143700bae4edd23930a7772899ad259058 Signed-off-by: Sean Anderson Reviewed-by: Bin Meng --- arch/riscv/lib/smp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c index ac22136314..ab6d8bd7fa 100644 --- a/arch/riscv/lib/smp.c +++ b/arch/riscv/lib/smp.c @@ -54,6 +54,8 @@ 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(); + ret = riscv_send_ipi(reg); if (ret) { pr_err("Cannot send IPI to hart %d\n", reg); From patchwork Mon Sep 7 18:16:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359182 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=pOtYfUfP; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Blc354GZVz9sT6 for ; Tue, 8 Sep 2020 04:18:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6B16A82512; Mon, 7 Sep 2020 20:17:26 +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="pOtYfUfP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1D2D7824B3; Mon, 7 Sep 2020 20:17:23 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 6D3B8824DC for ; Mon, 7 Sep 2020 20:17:19 +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-x844.google.com with SMTP id y11so4207683qtn.9 for ; Mon, 07 Sep 2020 11:17:19 -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=errZh4VSVfmLn0YdLdLXN0jIae9Ncf+kxEhAN/5/Jsw=; b=pOtYfUfPffeGYiDmBKaUNCPuXtlnIYjbCO6dzp1Zym9NShvlVNTt0j+JlB4ynEO8Ir Ur7hKlEIG4tLluLTMIpQm64V6nszwjIrAVsHLlC4kJWNU62nbEfnKXZfDQXWm18vNbpQ bhWl9TiHukmWo6KHPEFkA1kwjN9DlLoYcvd1Ww84SY/2yqNtPVqBY4gQ7QkBD/gsVZuq kWBa9s9S7BFNRQ2UdzqywE2Z8WrwB0ksC7LpuzGwJ58Vu0/1PHKvSbybZyeUTyJmaR5u 3BAKtyh/7Us2TySgPYJOT5WIZ9oyfpnezh5NMNqSyIkwTjDNUjvUnBIF5X2XeODVsigL Kv7Q== 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=errZh4VSVfmLn0YdLdLXN0jIae9Ncf+kxEhAN/5/Jsw=; b=d/fDBn+nUhuMXxFLzqGOXZ39/6MqgF+T+RiW7CNWwbCL+cdxmQn3OowyFpdxRl9Yw7 8jo8D5NhseI0KnuIrG/h64HRql1qOBHVKmoE5PTxcz5MfAGXThFJaNcf50uV3p3XSVdQ TTNr1X1wfRlhvrYbyVnx3MyEONR3IAIgfYXrLo7XOAyUGZhG4Zsqc7slJ0xcqmoRxE3G PgVt6QyP8pbnJBdqXZ8fUpQhgrgYZrr3URpyvhPHbr9NjaKpv8sxGvkr0cKU93axNwbC pyiuwACQjqjW81r4LSzxUNdttFx4xxALhameDxjYMyYTfFO+gvOFD28qxJEHazSwFHqx Nx5w== X-Gm-Message-State: AOAM5317NGEPhUq4DWCkEVSFyaZ+GrNi7RMpt23LgboA9yQ3X5B/DNmp YgyFsu+N5rkSytPsH/EKoCiOqAJnUEaxRA== X-Google-Smtp-Source: ABdhPJyQkuUaIC8ynmxU7fFNEidC4uyZMIA9u0eGaYISDh+c4OK3WJ4kztZQ56g8Zm8KsfvE2V/GQw== X-Received: by 2002:ac8:5b09:: with SMTP id m9mr21763536qtw.12.1599502638145; Mon, 07 Sep 2020 11:17:18 -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 w3sm11577212qkc.10.2020.09.07.11.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:17 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 3/7] riscv: Use NULL as a sentinel value for smp_call_function Date: Mon, 7 Sep 2020 14:16:55 -0400 Message-Id: <20200907181659.92449-4-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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. This commit uses NULL as a sentinel for secondary harts so they know when the IPI is initialized, and it is safe to use the IPI API. The smp addr parameter is initialized to NULL by board_init_f_init_reserve. Before this, secondary harts wait in wait_for_gd_init. This imposes a minor restriction because harts may no longer jump to NULL. However, given that the RISC-V debug device is likely to be located at 0x400, it is unlikely for any RISC-V implementation to have usable ram located at 0x0. Signed-off-by: Sean Anderson Reviewed-by: Bin Meng --- arch/riscv/lib/smp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c index ab6d8bd7fa..8c25755330 100644 --- a/arch/riscv/lib/smp.c +++ b/arch/riscv/lib/smp.c @@ -18,6 +18,12 @@ static int send_ipi_many(struct ipi_data *ipi, int wait) u32 reg; int ret, pending; + /* NULL is used as a sentinel value */ + if (!ipi->addr) { + pr_err("smp_function cannot be set to 0x0\n"); + return -EINVAL; + } + cpus = ofnode_path("/cpus"); if (!ofnode_valid(cpus)) { pr_err("Can't find cpus node!\n"); @@ -50,11 +56,16 @@ static int send_ipi_many(struct ipi_data *ipi, int wait) continue; #endif - gd->arch.ipi[reg].addr = ipi->addr; gd->arch.ipi[reg].arg0 = ipi->arg0; gd->arch.ipi[reg].arg1 = ipi->arg1; - __smp_mb(); + /* + * Ensure addr only becomes non-NULL when arg0 and arg1 are + * valid. 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].addr, ipi->addr); ret = riscv_send_ipi(reg); if (ret) { @@ -83,9 +94,16 @@ void handle_ipi(ulong hart) if (hart >= CONFIG_NR_CPUS) return; - __smp_mb(); + smp_function = (void (*)(ulong, ulong, ulong)) + __smp_load_acquire(&gd->arch.ipi[hart].addr); + /* + * If the function is NULL, 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_function) + return; - smp_function = (void (*)(ulong, ulong, ulong))gd->arch.ipi[hart].addr; invalidate_icache_all(); /* From patchwork Mon Sep 7 18:16:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359181 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=enV/WvpR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Blc2s526Kz9sT6 for ; Tue, 8 Sep 2020 04:17:57 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 671C882507; Mon, 7 Sep 2020 20:17:25 +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="enV/WvpR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C383782502; Mon, 7 Sep 2020 20:17:22 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (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 46879824A5 for ; Mon, 7 Sep 2020 20:17:20 +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-qk1-x741.google.com with SMTP id f142so13196495qke.13 for ; Mon, 07 Sep 2020 11:17:20 -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=MXwKOunM97C9D2WjWVRGFLYx9crG8gCnFBIk4m5omHY=; b=enV/WvpRrwUllmQZSk/veySM6UWJ5BsmGD/veIkdOSIbYuavGQdKG8lUpO6TaL9sOO u7nWP+uHAMDXC88L1EoktIFf8lZt2Z6JricDKVGPiYVELY0nR7v6YOZ0JB73jVj4hEJw yFfRH9w7prs44DkXDhPsPIYQ2iuv6qpQM9B4R4s43EfvV0x7RLh1MB/iQwcn1YkSe93D Tx3Y+fmwgC9i24jCW8c23zoyQhchy+XLc2GYeaXf60itSV0TV2/DP11MGQC1Wg/Nfb/l c0we2PSPLmchZlIHj71uOsFh3vwhuwVM/hzunxHJSXHayOAYlnXFuDRiKgCdSMK+XFkf jsaQ== 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=MXwKOunM97C9D2WjWVRGFLYx9crG8gCnFBIk4m5omHY=; b=O8w/jG5vRRw8Lkee+TIO0SCWd7sAjl0ZWhoG3wl8XabGsXM7gzOddv6nbhNKTwgoZC lEJroGDwNh4C9kCmnzuYXWJxNExPUZLTA/C9lZz+TWAybZpI9w3AHmYAL6wm+ZjJW+k2 wOtmF3PH/GTosYuaKxPxMP2AYL7WFV8v4fLC9LkkJtf8hw/S/1fPOJMZHoHfRVlKtRlV T9gQ5HvYJLZ4iE+ua2TjzE6cp9/wfD/YqGYiZFv1xAerGj33fxNqbhKHyRYtiAWGvo9b edARE/T6PTfXNhwzgQ5rKVpjN4OyrwndLDjjN8O8DqjZSP4GL9EH/2hzt2Q7cwQcV8Ry qvLA== X-Gm-Message-State: AOAM5333+91W3VMpH+ofLJ2ZA/aRZTWGrNuupk1I+zlZiX6r7re6ITon zQ2hlcEYyhVNMv5qvOnPOpf05Kg2zVdkGQ== X-Google-Smtp-Source: ABdhPJxQT6kZ5KT5pVfybvZgIrikM6lU4Cz43eJ6M3Y+RD5sSzIin2rJ7vLpBdHfhvIGU4UnOkyejw== X-Received: by 2002:a37:9f52:: with SMTP id i79mr19806540qke.109.1599502639043; Mon, 07 Sep 2020 11:17:19 -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 w3sm11577212qkc.10.2020.09.07.11.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:18 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 4/7] riscv: Clear pending IPIs on initialization Date: Mon, 7 Sep 2020 14:16:56 -0400 Message-Id: <20200907181659.92449-5-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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 Even though we no longer call smp_function if an IPI was not sent by U-Boot, we still need to clear any IPIs which were pending from the execution environment. Otherwise, secondary harts will busy-wait in secondary_hart_loop, instead of relaxing. Signed-off-by: Sean Anderson Reviewed-by: Bin Meng --- arch/riscv/cpu/cpu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c index bfa2d4a426..ad94744c0f 100644 --- a/arch/riscv/cpu/cpu.c +++ b/arch/riscv/cpu/cpu.c @@ -72,6 +72,15 @@ static int riscv_cpu_probe(void) return 0; } +/* + * This is called on secondary harts just after the IPI is init'd. Currently + * there's nothing to do, since we just need to clear any existing IPIs, and + * that is handled by the sending of an ipi itself. + */ +void riscv_ipi_init_secondary_hart(ulong hart, ulong arg0, ulong arg1) +{ +} + int arch_cpu_init_dm(void) { int ret; @@ -111,6 +120,15 @@ int arch_cpu_init_dm(void) ret = riscv_init_ipi(); if (ret) return ret; + + /* + * Clear all pending IPIs on secondary harts. We don't do anything on + * the boot hart, since we never send an IPI to ourselves, and no + * interrupts are enabled + */ + ret = smp_call_function((ulong)riscv_ipi_init_secondary_hart, 0, 0, 0); + if (ret) + return ret; #endif return 0; From patchwork Mon Sep 7 18:16:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359183 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=sxA/mtnZ; 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 4Blc3J1G6hz9sT6 for ; Tue, 8 Sep 2020 04:18:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8640D82503; Mon, 7 Sep 2020 20:17:28 +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="sxA/mtnZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2EE3F82503; Mon, 7 Sep 2020 20:17:24 +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-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 30DA1824EC for ; Mon, 7 Sep 2020 20:17:21 +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-qk1-x742.google.com with SMTP id g72so13220392qke.8 for ; Mon, 07 Sep 2020 11:17:21 -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=hXZVTZz++OaddOgdkonu6AZZI1oHB3jOIlzerLEmemw=; b=sxA/mtnZONVIvIosm4SEhL5L75yoqSOqSEBzZHUubRy5MR3LdKyrNVFlqTCbK7IhUb JhGvqIiCG4i2WtbhzM0RIHsJRt7Hq1oNYZH7STIzR1s67cyfesFSEN0U3o0YaaAZ6j5S GkiZBDD98+SVmkWf64GE0amdWh0Pfdq5kjgM7MbtUn2lCFak/yzIo5NxLU0bm/Gah/oe rTvUKKI6q7g7OmKyOX6WhHQfsISKxJIr+Fc4oPjjxaWYLc61tdPsvv63021YzAfLZkdp jYLCjLNG4nu9onPQb4mktWVyK+UQi9MWzbBd8x9oP44/7ywDJILKsfjPLWyHUEdlgmhx yYUA== 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=hXZVTZz++OaddOgdkonu6AZZI1oHB3jOIlzerLEmemw=; b=Pdkywu2p1zPuG3VoGNe1Y0hKv43Wt67uNaloAK7QesAmh98ZJBKN7KO+fBJn7AVEWj k87/lGhtXRWAmjMHlbMTdS3DKLYbxIfclghB3eX+W7ukPKg8KaHbFJy75v1O6MNqnIW1 mhLbPW6ubW9az7s0JrWcQvZe7L9RIYsVvoPh+v/e3bqhuC/0FhNIhUol1jkoHXBu5Jlv aOnUKjkfGMA/Hs4B42mf+x0veH6DwnNbotLfGmm3jJlxPtQXxcWnMB0+JQWtea/Zrqcz RR+1OYnK2NmqitFjqsxTywgUfEVcSUdGaQKruxpTRMBoIgtSjGUIILjH6Bbv0uPKskaa +qFw== X-Gm-Message-State: AOAM5318OdMpqOhSWi7f929w3XE2y8YpgYiEAbEQO5/1OSxsxdNmXTdO CfWkMBLP56GW69dAlRZXUE4Kwl/GOkAeGg== X-Google-Smtp-Source: ABdhPJzBZMU9WBFVp9aByE5hVIMsLA7uW6DOx3FP1Uhf1aIbmeZf4PAiLnH7i8KepYVL2ikqPqTkzQ== X-Received: by 2002:a05:620a:129b:: with SMTP id w27mr6574153qki.41.1599502640002; Mon, 07 Sep 2020 11:17:20 -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 w3sm11577212qkc.10.2020.09.07.11.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:19 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 5/7] riscv: Add fence to available_harts_lock Date: Mon, 7 Sep 2020 14:16:57 -0400 Message-Id: <20200907181659.92449-6-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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 Without these fences, it is perfectly valid for an out-of-order core to re-order memory accesses to outside of the available_harts_lock critical section. Signed-off-by: Sean Anderson --- arch/riscv/cpu/start.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index e3222b1ea7..ad18e746b6 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -126,12 +126,12 @@ call_board_init_f_0: #ifndef CONFIG_XIP la t0, available_harts_lock fence rw, w - amoswap.w zero, zero, 0(t0) + amoswap.w.rl zero, zero, 0(t0) wait_for_gd_init: la t0, available_harts_lock li t1, 1 -1: amoswap.w t1, t1, 0(t0) +1: amoswap.w.aq t1, t1, 0(t0) fence r, rw bnez t1, 1b @@ -143,7 +143,7 @@ wait_for_gd_init: SREG t2, GD_AVAILABLE_HARTS(gp) fence rw, w - amoswap.w zero, zero, 0(t0) + amoswap.w.rl zero, zero, 0(t0) /* * Continue on hart lottery winner, others branch to From patchwork Mon Sep 7 18:16:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359184 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=YLWJkz4O; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Blc3T5n9nz9sTK for ; Tue, 8 Sep 2020 04:18:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CF27E8251B; Mon, 7 Sep 2020 20:17:29 +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="YLWJkz4O"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0C45782507; Mon, 7 Sep 2020 20:17:25 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) (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 30646824FB for ; Mon, 7 Sep 2020 20:17:22 +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-x841.google.com with SMTP id z2so10254254qtv.12 for ; Mon, 07 Sep 2020 11:17:22 -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=qrFwyKBkB/hNwmBWHaFxqD37Cm/8AFGYiJdPn6/ZQBY=; b=YLWJkz4ONNyKCBD959eUiN3bW5EKf/QU7MQEZoYjvnTnVQmNA7tjTWzVDZ7jbRbad8 z5V/dXfe3WGnHcdWTDIDPeVbT3ew3dyRxR+hChd/8nzrdptfO/EC/q5WB8Av/dG/vp0Z 6jjRHHjholQV2OdpKHw9h2pKsr6wHU4s0AqCFTGudyz57i8uFtn0jCw1vu4jx+g+1LBG Llnfs7TBSAmAOkpUnJYGv9xdGnk/j2+TNOAbibWA8Tebo1p5rL5lbwuv4gEG13PVxMKg GAn7vV75cFVWFQVjNblRTxpr7GHhlosCL5/TmoQ2qY9qz/HCj9YJH2BvQ3S8vOwRmCI+ tJ0Q== 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=qrFwyKBkB/hNwmBWHaFxqD37Cm/8AFGYiJdPn6/ZQBY=; b=FXyVsIsJTErCNmwsB2vucQlaBadGVUdVDwJv5+i2DPbQ2ehbKgBB7ylJ80Oj+wAFbj eidkrKvibnLZ9BX6FrcfLl5pYgaRehbAPKOnFVxeHlvCrk62+wGH71KgRUyh5IYtYMAg OVBiAKMzCUEPiiAd9+bTCwbvgmB+671+jk9xxueLKkvDJrGofJmOTD/4tPMeazFS0XFk FLotZSl0un2wg4OsWEg/YABQbG1YUYM91LAABhQWLUV5PFdQbWylxlacgG3JYnq5sC6g xA4AS2+/B3l0+vNVbZr8cvcQvAz1uBHdaCPDqmDILyISGye5bA/LJekkgZTalvdToOl9 VPfQ== X-Gm-Message-State: AOAM531pz5s9bOQ21UjWbdIaC9TUx11OuMObYARCcrnAevXskQ3kkwh9 hpsv0MT0yjOLz6freNgdrbcFXTFxOFB7MA== X-Google-Smtp-Source: ABdhPJwwzujmn0PrPChNUMOAyxj6QMavHcYylgB11aMDZUSyJIcN5FYrlrKHBylFZo9US2ElMFftZg== X-Received: by 2002:ac8:6f21:: with SMTP id i1mr5608411qtv.89.1599502640891; Mon, 07 Sep 2020 11:17:20 -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 w3sm11577212qkc.10.2020.09.07.11.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:20 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 6/7] riscv: Ensure gp is NULL or points to valid data Date: Mon, 7 Sep 2020 14:16:58 -0400 Message-Id: <20200907181659.92449-7-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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 This allows code to use a construct like `if (gd & gd->...) { ... }` when accessing the global data pointer. Without this change, it was possible for a very early trap to cause _exit_trap to read arbitrary memory. This could cause a second trap, preventing show_regs from being printed. Fixes: 7c6ca03eaed0035ca6676e9bc7f5f1dfcaae7e8f Signed-off-by: Sean Anderson --- arch/riscv/cpu/start.S | 20 +++++++++++++++++--- arch/riscv/lib/interrupts.c | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index ad18e746b6..59d3d7bbf4 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -47,6 +47,13 @@ _start: mv tp, a0 mv s1, a1 + /* + * Set the global data pointer to a known value in case we get a very + * early trap. The global data pointer will be set its actual value only + * after it has been initialized. + */ + mv gp, zero + la t0, trap_entry csrw MODE_PREFIX(tvec), t0 @@ -85,10 +92,10 @@ call_board_init_f_0: jal board_init_f_alloc_reserve /* - * Set global data pointer here for all harts, uninitialized at this - * point. + * Save global data pointer for later. We don't set it here because it + * is not initialized yet. */ - mv gp, a0 + mv s0, a0 /* setup stack */ #if CONFIG_IS_ENABLED(SMP) @@ -135,6 +142,13 @@ wait_for_gd_init: fence r, rw bnez t1, 1b + /* + * Set the global data pointer only when gd_t has been initialized. + * This was already set by arch_setup_gd on the boot hart, but all other + * harts' global data pointers gets set here. + */ + mv gp, s0 + /* register available harts in the available_harts mask */ li t1, 1 sll t1, t1, tp diff --git a/arch/riscv/lib/interrupts.c b/arch/riscv/lib/interrupts.c index cd47e64487..ad870e98d8 100644 --- a/arch/riscv/lib/interrupts.c +++ b/arch/riscv/lib/interrupts.c @@ -78,7 +78,8 @@ static void _exit_trap(ulong code, ulong epc, ulong tval, struct pt_regs *regs) printf("EPC: " REG_FMT " RA: " REG_FMT " TVAL: " REG_FMT "\n", epc, regs->ra, tval); - if (gd->flags & GD_FLG_RELOC) + /* Print relocation adjustments, but only if gd is initialized */ + if (gd && gd->flags & GD_FLG_RELOC) printf("EPC: " REG_FMT " RA: " REG_FMT " reloc adjusted\n\n", epc - gd->reloc_off, regs->ra - gd->reloc_off); From patchwork Mon Sep 7 18:16:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1359185 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=AoRsMekK; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Blc3f6Klxz9sT6 for ; Tue, 8 Sep 2020 04:18:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF04882525; Mon, 7 Sep 2020 20:17:30 +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="AoRsMekK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B465D82512; Mon, 7 Sep 2020 20:17:25 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 2784C824A5 for ; Mon, 7 Sep 2020 20:17:23 +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-qk1-x742.google.com with SMTP id 16so3918484qkf.4 for ; Mon, 07 Sep 2020 11:17:23 -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=V/DPVA13siXrNoLS1XJH2bIp1oug8hJX+iDYYtn2Y/M=; b=AoRsMekK7rMe2+BErZ+BVpyqY3n+4ZLe3/su8vG+nwL+9vBwNQ8NWAYauv3plalYJn I81I/Gepv8nIPwZp/wk6GZElx/cdlF/y4m1RNTQzwtszPzZbXOCRhSWfoREfMZMXYgOz Y4QAWbMyMFDiywhtpm3wauNFlB+tmHNnDbwXnILogG6EF461I0PUXatEcmsMKYd7mpec XAKOm+b2C5xBVG2XufJI13yqko6cx/XOIn3VGglO465eYJzkldBX49zPKtqEgylUwG+F lXJdJVN60f/9OwphER5nACCWD9AfZCgyF0dlRk8+RB6jn8qgFIzb4Wb2bp4OLxA3qOCA Zamg== 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=V/DPVA13siXrNoLS1XJH2bIp1oug8hJX+iDYYtn2Y/M=; b=Pkg673h3+E9xTzCQAXwr/h3hnVqA82het3oWL1dFJ1K6ic1HlCInn5dflVjoFn3tBA O7n7ERwqVTINMJ7j9fmO8+ALnRhRrfG7CzuGFp1cFzu34LwZilUobn9PAbYq3g/BsrpH SsvXwT8ysYiaKZsJZ0UWs/nvo7wUzEYvhljDRhdDekVolSt+uFZvm+gNU2bzXCqmKlvo nTNGLnnEyTiyJl3oH9TTn8GAxQB+fisNkAXejERYVU99pN+T9I2H+3ZgbIJWoc6kzgWL EaIhxL0RT7AD4SWGnNx/27rtlT6x4HSzlAzkr5GNYaFudFbyLG0gvsFmdXdToCYQm448 wVyA== X-Gm-Message-State: AOAM531YsoynR2azkxqLz4Tc/yB4flY7WblCDX3+cZLofVtMz9vWh8ny Ogejvt0OIqIN+2ti1YtvIVvAfiY88aGSiA== X-Google-Smtp-Source: ABdhPJxLk6tO0EJbPUS0Qb+RRjj9mp462oAjhnPc/+A7fF0YmR7JCdQixOB7fE89TZv0AoYGlzUO4A== X-Received: by 2002:a05:620a:220f:: with SMTP id m15mr5893321qkh.255.1599502641810; Mon, 07 Sep 2020 11:17:21 -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 w3sm11577212qkc.10.2020.09.07.11.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 11:17:21 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Heinrich Schuchardt , Bin Meng , Sean Anderson Subject: [PATCH 7/7] riscv: Add some comments to start.S Date: Mon, 7 Sep 2020 14:16:59 -0400 Message-Id: <20200907181659.92449-8-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907181659.92449-1-seanga2@gmail.com> References: <20200907181659.92449-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 This adds comments regarding the ordering and purpose of certain instructions as I understand them. Signed-off-by: Sean Anderson --- arch/riscv/cpu/start.S | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index 59d3d7bbf4..c659c6df53 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -43,7 +43,10 @@ _start: csrr a0, CSR_MHARTID #endif - /* save hart id and dtb pointer */ + /* + * Save hart id and dtb pointer. The thread pointer register is not + * modified by C code, and may be used in trap handlers. + */ mv tp, a0 mv s1, a1 @@ -54,10 +57,18 @@ _start: */ mv gp, zero + /* + * Set the trap handler. This must happen after initializing tp and gp + * because the handler may use these registers. + */ la t0, trap_entry csrw MODE_PREFIX(tvec), t0 - /* mask all interrupts */ + /* + * Mask all interrupts. Interrupts are disabled globally (in m/sstatus) + * for U-Boot, but we will need to read m/sip to determine if we get an + * IPI + */ csrw MODE_PREFIX(ie), zero #if CONFIG_IS_ENABLED(SMP) @@ -407,6 +418,10 @@ secondary_hart_relocate: mv gp, a2 #endif +/* + * Interrupts are disabled globally, but they can still be read from m/sip. The + * wfi function will wake us up if we get an IPI, even if we do not trap. + */ secondary_hart_loop: wfi