From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B2C7C77B76 for ; Mon, 17 Apr 2023 18:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qa3yns6p4bf09rPniF3pPKgdeE8LD3hIdDrMwZuQ/2s=; b=ZNoqmWxOgIFtdO k4ASrc4vX9vGTFPayMHuoQUsrmZXQj1vpiWYXtjmhhATBq/o03Q7lEzmQgDZViwEec7wr5hK+oeEB cHWarcE+QKkDu1nCEoFlbg94uE/hoLYygyEGwS2K+RYbe4sDTESARCEOYlcHcxIYqG+KgH52c3nci 3sfrQLz7fX/dpnmk5QmoirLVlXOfRrigsyuA7Wleqh/3vpJ8/KtjLKvG4uYJZEGhTO/dViq5UbnVm H1UFE1A0Hthj6L48v0hXMhP0ITmtFWBlgCM5GgFu6GpJFcsFiIuxrxK8W9dSCOolsM7U7oDAoo++1 a34WZ95sqos28Jsrde2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1poTAP-00HFcp-0O; Mon, 17 Apr 2023 18:01:29 +0000 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1poTAK-00HFbX-0L for linux-arm-kernel@lists.infradead.org; Mon, 17 Apr 2023 18:01:27 +0000 Received: by mail-qv1-xf29.google.com with SMTP id oo30so12135305qvb.12 for ; Mon, 17 Apr 2023 11:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681754478; x=1684346478; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=r4rWaDRbIsEYCkJ4JgcLhembW9iS0xspLr0fhQH37Sw=; b=La+bbbCoAyu+27ta7XGSfN08k5ypKB78xHNEUTMDDzMGc4t9JuxiLD8bPx1wxqoazh 2ClgJMoCeRfDpNR+yK0/AeEKv3mIEy3iXXkctN+sfe7WiRo2qV6LaumeL/1JtXIiPOPS 7BP6cY7jNwQ/Rj+IYjFIJcQOp1G0TfWLlkVK719xaxjue9Hy8nnFIXirEfx6vcewwDUk oZwqtHvKqq8urXp41tMRtGe5eBT+o3jPdN9/fAs4ZVrfL+7XRbQNg3EiyyjziX32UA0m lL41EfNBFqtiszSzYtWVvGdmg+OczINwa/Kn4tAJwrpT+gghXnVJWWNBZ97vqsABxRiK 9dZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681754478; x=1684346478; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r4rWaDRbIsEYCkJ4JgcLhembW9iS0xspLr0fhQH37Sw=; b=HlaN5FtyVNTX2iE12fNNHhMX3Lv4jZRfpUK75iHi63qGQjcLfDVenLGW42IrYlKX72 8GHbr3JSCegvr/GBfDHB2ho1Cwfh8BsMa9tgG4WYD4dpM/tVZ6LuCb9eBtrp4qOGtsrr IajkiDxYrdSIQXnIc73AcFzaKkYGaiKbEZi9hvKvu6D5LSCiuoztKnRYC5rgFrC563+R uqvBMwR9YDhdNBEKq+HKfJRWVzaxo0jCNyxDsh7TjamMzWYyYrsj02iLidGexH5x1Qyo nvU8WfYdONmflCHCz1TCUz+y6FG2WXfL7DbYqVs7kl/6IzwoVl4I9r0KWVgjbKVPZ7gr 93dg== X-Gm-Message-State: AAQBX9cX2iuoHHlwscHxDLVj+ylCwLaqw/pySL9MV7I+lmOrHxEG1BCa wXQlFjHfDzDoX643Uyqtjlw= X-Google-Smtp-Source: AKy350ZOA7j6Z/Q3tebjfx452OZg5qJsoggSPjaIHDa83M8wEqY2gtjujdlJqtfF2jkRJIlihZ2KOw== X-Received: by 2002:a05:6214:1c86:b0:5ef:4435:f1cd with SMTP id ib6-20020a0562141c8600b005ef4435f1cdmr13827361qvb.27.1681754477735; Mon, 17 Apr 2023 11:01:17 -0700 (PDT) Received: from [10.67.48.245] ([192.19.223.252]) by smtp.googlemail.com with ESMTPSA id c204-20020a379ad5000000b0074ced3e0004sm723041qke.63.2023.04.17.11.01.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Apr 2023 11:01:17 -0700 (PDT) Message-ID: <02b34c80-f37e-deee-29cd-de7db902797d@gmail.com> Date: Mon, 17 Apr 2023 11:01:13 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v3 2/2] firmware: arm_scmi: Augment SMC/HVC to allow optional parameter Content-Language: en-US To: Nikunj Kela , sudeep.holla@arm.com Cc: cristian.marussi@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230409181918.29270-1-quic_nkela@quicinc.com> <20230417174401.19563-1-quic_nkela@quicinc.com> <20230417174401.19563-3-quic_nkela@quicinc.com> From: Florian Fainelli In-Reply-To: <20230417174401.19563-3-quic_nkela@quicinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230417_110124_170698_84C5D4FF X-CRM114-Status: GOOD ( 32.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 4/17/23 10:44, Nikunj Kela wrote: > This patch add support for passing shmem channel address as parameter > in smc/hvc call. This patch is useful when multiple scmi instances are > using same smc-id and firmware needs to distiguish among the instances. Typo: distinguish. It really would have been a lot clearer and made a whole lot more sense to encode a VM ID/channel number within some of the SMCCC parameters, possibly as part of the function ID itself. > > Signed-off-by: Nikunj Kela > --- > drivers/firmware/arm_scmi/driver.c | 1 + > drivers/firmware/arm_scmi/smc.c | 25 ++++++++++++++++++++++++- > 2 files changed, 25 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c > index e7d97b59963b..b5957cc12fee 100644 > --- a/drivers/firmware/arm_scmi/driver.c > +++ b/drivers/firmware/arm_scmi/driver.c > @@ -2914,6 +2914,7 @@ static const struct of_device_id scmi_of_match[] = { > #endif > #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC > { .compatible = "arm,scmi-smc", .data = &scmi_smc_desc}, > + { .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc}, > #endif > #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO > { .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc}, > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c > index 93272e4bbd12..e28387346d33 100644 > --- a/drivers/firmware/arm_scmi/smc.c > +++ b/drivers/firmware/arm_scmi/smc.c > @@ -20,6 +20,9 @@ > > #include "common.h" > > +#define lower32(x) ((u32)((x) & 0xffffffff)) > +#define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff)) Cannot you use the existing lower_32_bits and upper_32_bits macros from kernel.h here? > + > /** > * struct scmi_smc - Structure representing a SCMI smc transport > * > @@ -30,6 +33,8 @@ > * @inflight: Atomic flag to protect access to Tx/Rx shared memory area. > * Used when operating in atomic mode. > * @func_id: smc/hvc call function id > + * @is_smc64: smc/hvc calling convention type 64 vs 32 > + * @param: physical address of the shmem channel > */ > > struct scmi_smc { > @@ -40,6 +45,8 @@ struct scmi_smc { > #define INFLIGHT_NONE MSG_TOKEN_MAX > atomic_t inflight; > u32 func_id; > + bool is_smc64; > + phys_addr_t param; > }; > > static irqreturn_t smc_msg_done_isr(int irq, void *data) > @@ -137,6 +144,8 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, > if (ret < 0) > return ret; > > + if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) > + scmi_info->param = res.start; There is not even a check that this is going to be part of the kernel's view of memory, that seems a bit brittle and possibly a security hole, too. Your hypervisor presumably needs to have carved out some amount of memory in order for the messages to be written to/read from, and so would the VM kernel, so eventually we should have a 'reserved-memory' entry of some sort, no? > /* > * If there is an interrupt named "a2p", then the service and > * completion of a message is signaled by an interrupt rather than by > @@ -156,6 +165,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, > } > > scmi_info->func_id = func_id; > + scmi_info->is_smc64 = ARM_SMCCC_IS_64(func_id); > scmi_info->cinfo = cinfo; > smc_channel_lock_init(scmi_info); > cinfo->transport_info = scmi_info; > @@ -188,7 +198,20 @@ static int smc_send_message(struct scmi_chan_info *cinfo, > > shmem_tx_prepare(scmi_info->shmem, xfer, cinfo); > > - arm_smccc_1_1_invoke(scmi_info->func_id, 0, 0, 0, 0, 0, 0, 0, &res); > +#ifdef CONFIG_ARM64 > + /* > + * if SMC32 convention is used, pass 64 bit address in > + * two parameters > + */ > + if (!scmi_info->is_smc64) There is no need for scmi_info to store is_smc64, just check the func_id here and declare is_smc64 as a local variable to the function. Also, another way to approach this would be to encode the parameters region in 4KB units such that event on a 32-bit system with LPAE you are guaranteed to fit the region into a 32-bit unsigned long. AFAIR virtualization and LPAE are indistinguishable on real CPUs? > + arm_smccc_1_1_invoke(scmi_info->func_id, > + lower32(scmi_info->param), > + upper32(scmi_info->param), > + 0, 0, 0, 0, 0, &res); > + else > +#endif > + arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param, > + 0, 0, 0, 0, 0, 0, &res); > > /* Only SMCCC_RET_NOT_SUPPORTED is valid error code */ > if (res.a0) { -- Florian _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel