From patchwork Thu Oct 14 12:43:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Fiergolski X-Patchwork-Id: 1540899 X-Patchwork-Delegate: trini@ti.com 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; unprotected) header.d=fastree3d-com.20210112.gappssmtp.com header.i=@fastree3d-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=gk7qY4R2; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVTd30rTqz9s1l for ; Thu, 14 Oct 2021 23:44:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D35B835F5; Thu, 14 Oct 2021 14:44:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=fastree3d.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=fastree3d-com.20210112.gappssmtp.com header.i=@fastree3d-com.20210112.gappssmtp.com header.b="gk7qY4R2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DBFD283651; Thu, 14 Oct 2021 14:44:41 +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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 A277C835CE for ; Thu, 14 Oct 2021 14:44:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=fastree3d.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=adrian.fiergolski@fastree3d.com Received: by mail-ed1-x52f.google.com with SMTP id a25so23793584edx.8 for ; Thu, 14 Oct 2021 05:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastree3d-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=O2eg0J1JjNtYEjxnlCoGL+Rsvtpgd86VugfSQzX8U3g=; b=gk7qY4R21qeHvLtaOg7wRtD6Wq83mcnuBkRQKy8tb4W5/VEUmWM/Ayt+hkIZXHfFmx vxprcKPhRBP14NpQqukqo2JZOUOZVm12jBTNKAHgQf8OTt75yAgP9/YL7lwx5rK8Ic3g +DlHeK9YLfpe+XTWYlVxWKK0hrc6KtPVXPdLzwhMT7eDNbUkBPVPcePaRUM6wN8ZQwZY DSYsE+5bhzwkHRVGS2j4cJhgSq+qGZKKRlVM8ZSQ0N+URTHHFD2fupUkAn+w/KpVyyjk PXdG1dVYeox8wh5UDVh/EtgEct7PrMZnrEX0OYoaeX0Lctc0kq6bU4hMJPQxYR3mxY6D b/Hw== 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:mime-version :content-transfer-encoding; bh=O2eg0J1JjNtYEjxnlCoGL+Rsvtpgd86VugfSQzX8U3g=; b=G/oPu02jjV4srUVRvSIMYs7Dkv7GI4laWv6Fx9qlJ6eyZcZUnzFxNOKH4pA+g114Wl qGkHCdgihLRjR729ucyR+tPe+yP3RlobGFGSFlYgxq0ujNlJ+Y3E1zZpBI2+pIu1pytL Xoer4GE+E5ulmVhOhkynojK0loxjKQUys6Zs2NojCqTfaMDW9VVbdndy+m4X4vkk7fxn HWZkwBEJqPZtNfhxojVu4i5n+nIrLoR/vQOCKXPToEtKFmFdCkaLt9Y8nV4zH8uKkY4v M1Paop2p/E4BLEfi8PrcDJOOWDa8a6uHoje0N38jdOdKJApd27opjEYN5RQcvg8QVMFk 1QmA== X-Gm-Message-State: AOAM530gEwj7zkoB1W0qL/XO7uwgNZW5FAeB/tOlKC+mP7l2aXudF1x/ PGbX54Ci+zqYudglcuzDDHgeOJhSAS6h X-Google-Smtp-Source: ABdhPJwgMojbzx2f2JaDwaMVYQ4zhGH4VyQLSHWH5+gUjZXwLsdsnaeiSkUDu0oL1KbWJb0JGfoOmg== X-Received: by 2002:a17:906:4d04:: with SMTP id r4mr3706980eju.252.1634215478182; Thu, 14 Oct 2021 05:44:38 -0700 (PDT) Received: from localhost.localdomain (fastree1.epfl.ch. [192.26.37.52]) by smtp.gmail.com with ESMTPSA id t19sm1913747ejb.115.2021.10.14.05.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 05:44:37 -0700 (PDT) From: Adrian Fiergolski To: u-boot@lists.denx.de Cc: michal.simek@xilinx.com, Adrian Fiergolski Subject: [PATCH v5 1/2] firmware: zynqmp: fix write to an uninitialised pointer in xilinx_pm_request Date: Thu, 14 Oct 2021 14:43:49 +0200 Message-Id: <20211014124349.1429696-1-adrian.fiergolski@fastree3d.com> X-Mailer: git-send-email 2.33.0 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.103.2 at phobos.denx.de X-Virus-Status: Clean When a caller is not interested in the returned message, the ret_payload pointer is set to NULL in the u-boot-sources. In this case, under EL3, the memory from address 0x0 would be overwritten by xilinx_pm_request with the returned IPI message, damaging the original data under this address. The patch, in case ret_payload is NULL, assigns the pointer to the array holding the IPI message being sent. Signed-off-by: Adrian Fiergolski --- Fix casting of ret (ingore v4). drivers/firmware/firmware-zynqmp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c index d4dc856baf..8273437dd9 100644 --- a/drivers/firmware/firmware-zynqmp.c +++ b/drivers/firmware/firmware-zynqmp.c @@ -154,6 +154,8 @@ U_BOOT_DRIVER(zynqmp_power) = { int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 *ret_payload) { + int ret; + debug("%s at EL%d, API ID: 0x%0x\n", __func__, current_el(), api_id); if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) { @@ -165,6 +167,12 @@ int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, */ u32 regs[] = {api_id, arg0, arg1, arg2, arg3}; + /* + * Use regs array in case ret_payload is NULL + */ + if (ret_payload == NULL) + ret_payload = regs; + if (api_id == PM_FPGA_LOAD) { /* Swap addr_hi/low because of incompatibility */ u32 temp = regs[1]; @@ -174,6 +182,8 @@ int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, } ipi_req(regs, PAYLOAD_ARG_CNT, ret_payload, PAYLOAD_ARG_CNT); + + ret = (int)ret_payload[0]; #else return -EPERM; #endif @@ -198,8 +208,9 @@ int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, ret_payload[4] = (u32)regs.regs[2]; } + ret = (ret_payload) ? ret_payload[0] : 0; } - return (ret_payload) ? ret_payload[0] : 0; + return ret; } static const struct udevice_id zynqmp_firmware_ids[] = { From patchwork Thu Oct 14 12:43:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Fiergolski X-Patchwork-Id: 1540900 X-Patchwork-Delegate: trini@ti.com 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; unprotected) header.d=fastree3d-com.20210112.gappssmtp.com header.i=@fastree3d-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=r7v5PjI3; dkim-atps=neutral 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=) 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) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVTdL0CMZz9s1l for ; Thu, 14 Oct 2021 23:45:09 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF840836CA; Thu, 14 Oct 2021 14:45:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=fastree3d.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=fastree3d-com.20210112.gappssmtp.com header.i=@fastree3d-com.20210112.gappssmtp.com header.b="r7v5PjI3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 338D3836E0; Thu, 14 Oct 2021 14:45:00 +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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 7E24283651 for ; Thu, 14 Oct 2021 14:44:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=fastree3d.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=adrian.fiergolski@fastree3d.com Received: by mail-ed1-x52f.google.com with SMTP id a25so23796677edx.8 for ; Thu, 14 Oct 2021 05:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastree3d-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AxP1FBM139oAxH6/gp3TrPV645YFXrQo5hl+ip49GyQ=; b=r7v5PjI3G2jMZymmqKNT4GQ+Z/oV3OcoFSmBpuQOU05qW4MneUwxdyupgpWknNk4YM zyxUFZtMpkU5D2IJGCVaHcHjRVtfyNH1fjXzFFVbMx7d+EM20lttSKtkiL410RpbRs/2 wAuaD5pmt8LpfUls4GvXX83+7wChJuXpbLT/7ankOFGhLwoOD/1pcx1xXDQFVM5HUzoO Lk3gfOvXv6YnL4rtqPXTnV9/D2AhDa6joFhRh2MB3yCzu3MODF1Xu5vZ8RuW219/O6kE 8oWmmzG0P1EAkrYIxsL6XSrTg/qK5UU0kn8467AgNyPAbyEo5QZYksiyNRHWRJihlJHm d3fQ== 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=AxP1FBM139oAxH6/gp3TrPV645YFXrQo5hl+ip49GyQ=; b=aU1ER0ubLz2U7ADDNoly7DgcJ1wg2zEM/3gYDBzyAFlCPkLvmAgZOEyb4tpOYCOntA sbC0ZzZzjgdUroU6TFffTvetOL5htTzCegfuk7Ain5Q0PaN40r596X4n690q8Wumfws4 WEfrvZsIAVSIGYRGztaxWYSEcYOb1wXOOMlCmKM7gtl+tfpySAo2bydj9toLHJ5MyK4r 2xBnwHk6aQDq5ajTd9dxjdnNb98ExYLozddkaIP+MdK9lkh3WGl4epWvddADY0fOXY3U Ngal41SynR4rvDgPsyt+BJ5CGvsUAcOMemtfyDWo5TZfbkNG88loSD9coYcGd6bZqvbk 1BMA== X-Gm-Message-State: AOAM530mi+oE1uqHMbfiqNzFgp7u4ZngZKcXYv8b35E5BPus0YZtplPa pHdrp7DMUSJ8tIVE8ti87qDSW66jXakU X-Google-Smtp-Source: ABdhPJxSgt9B7PcpkNyHowWKgVSJDFGLXjaJ/sOYQc1UGvrJQxqt+H+uT+hWdd9PX3dJpUWNGAaZNw== X-Received: by 2002:a17:907:1199:: with SMTP id uz25mr3501193ejb.470.1634215493888; Thu, 14 Oct 2021 05:44:53 -0700 (PDT) Received: from localhost.localdomain (fastree1.epfl.ch. [192.26.37.52]) by smtp.gmail.com with ESMTPSA id t19sm1913747ejb.115.2021.10.14.05.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 05:44:53 -0700 (PDT) From: Adrian Fiergolski To: u-boot@lists.denx.de Cc: michal.simek@xilinx.com, Adrian Fiergolski Subject: [PATCH v5 2/2] firmware: zynqmp: return status in EL2 from xilinx_pm_request. Date: Thu, 14 Oct 2021 14:43:51 +0200 Message-Id: <20211014124349.1429696-2-adrian.fiergolski@fastree3d.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014124349.1429696-1-adrian.fiergolski@fastree3d.com> References: <20211014124349.1429696-1-adrian.fiergolski@fastree3d.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.103.2 at phobos.denx.de X-Virus-Status: Clean This patch fixes xilinx_pm_request to return a valid status from xilinx_pm_request in EL2. Signed-off-by: Adrian Fiergolski --- drivers/firmware/firmware-zynqmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c index 8273437dd9..34ad7fb985 100644 --- a/drivers/firmware/firmware-zynqmp.c +++ b/drivers/firmware/firmware-zynqmp.c @@ -208,7 +208,7 @@ int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, ret_payload[4] = (u32)regs.regs[2]; } - ret = (ret_payload) ? ret_payload[0] : 0; + ret = (int)regs.regs[0]; } return ret; }