From patchwork Thu Apr 20 15:06:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13218902 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 A05EAC77B72 for ; Thu, 20 Apr 2023 15:07:25 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OOaUBnfM8NYkVjzxYJYSoqWh7fNQSmIdEv57A4KPm4g=; b=OpqoEllEWzPt1K OUs+fhAqowB8qxOM/cswZ3XSwKJ3XtfIkKD7FbFSdZ8C7PdN451aOiysY1OvFblKkltAomXkBQeSM yzZaHdd75LyTXO6tjD4di9IjKY3Dd+MyPnCY5GASLOq130VqlyCFBu5EufhfEniCVbN/gs8qH4+mz 74hQUDQMbDI/ZDQvSvg8lqhVr+hOY24I8ga+bDSWMKef1tgLHYN8mwdOfUDavRMjnbP8Jas3vfKbq l1jz68BA50oQeJzRkMlp8hb363EaxHvt1AlWtnhvhGxRkchOrz5udsx+Ksmgc4yPmnk/j/5RqAN+x UL+dti7/MWrM+8+z8R8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppVru-008NAC-2s; Thu, 20 Apr 2023 15:06:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppVrf-008N7e-2c for linux-arm-kernel@lists.infradead.org; Thu, 20 Apr 2023 15:06:30 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E99C152B; Thu, 20 Apr 2023 08:07:08 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1C88E3F6C4; Thu, 20 Apr 2023 08:06:24 -0700 (PDT) From: Sudeep Holla Date: Thu, 20 Apr 2023 16:06:01 +0100 Subject: [PATCH v2 1/3] firmware: arm_ffa: Check if ffa_driver remove is present before executing MIME-Version: 1.0 Message-Id: <20230419-ffa_fixes_6-4-v2-1-d9108e43a176@arm.com> References: <20230419-ffa_fixes_6-4-v2-0-d9108e43a176@arm.com> In-Reply-To: <20230419-ffa_fixes_6-4-v2-0-d9108e43a176@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , Marc Bonnici , Jens Wiklander , Lucian Paul-Trifu X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2280; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=qYbYM/pIaMZFKMylpLoSG/+dQuTtfE41funwQ886cMU=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBkQVTuWDfmhXAEPEgZ7xS0zZEZKoIashOLgdbxl BWV7d7a3DGJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZEFU7gAKCRAAQbq8MX7i mPRYEADWL/qDt0uI6fF2L3EqnIoaVX7uRNETXjPa0viYR3eCZfGEdRnM6Fl7cKY7EKzG3KySaCs sQKPsHcAhx+T4Nxe96CNMASWTeOvzbMGM65U19xDKD2mZzJrlBZiDSnFoyrjiTlzyp/kkhqu7z3 yIe1tMztupfafZ0MdY51fRj1JQcxLQmtfs5ttU2YBGyw0xKCDQvdwKjNF6aI2ap0J3NYqUwIvKs tErhaZnJBMXD1ID6BkHaGT3nqaigwrbcVeALbu3vtgZ4+qA11tlbC9RUembUWAUCEqcNoUVzSj+ bYCww3Lrnv3tYx15ARgIn6eOYgvdSkfcFVu6ZmNdnoFvlM6svEi24tStODJwO4ar1ccT9G98EiZ 5bNJbSpRowsoRGrgeZdBFk4tqG3As1UnLUIwdrDGJW2OOZzdQhhAoM1biRvOB13NBSLVhbLj3JB MHIOM/12AvmwD+QTJhfdu6P85B9/ZlbfQIKonl/Cxaz4b1QbW5O2oQTKHuPnhbvkTf8FtJozk+v NBE0ZRJ14FjjY9Fhlm6C6kpIIhKEggyIblWt7jtIJgtpdSD0vOX2kDOTRK8SjoY9cNDJgm+okpZ aht4jX+Jpzqo7500qc9pEBjN9riTHYVl32pFAsL5WACRXqt/8Bfrj12TuNc76/zMi3TIza38VPN D0Fax9c7Ig3qHqA== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230420_080627_962887_534CE085 X-CRM114-Status: GOOD ( 11.48 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently ffa_drv->remove() is called unconditionally from ffa_device_remove(). Since the driver registration doesn't check for it and allows it to be registered without .remove callback, we need to check for the presence of it before executing it from ffa_device_remove() to above a NULL pointer dereference like the one below: | Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 | Mem abort info: | ESR = 0x0000000086000004 | EC = 0x21: IABT (current EL), IL = 32 bits | SET = 0, FnV = 0 | EA = 0, S1PTW = 0 | FSC = 0x04: level 0 translation fault | user pgtable: 4k pages, 48-bit VAs, pgdp=0000000881cc8000 | [0000000000000000] pgd=0000000000000000, p4d=0000000000000000 | Internal error: Oops: 0000000086000004 [#1] PREEMPT SMP | CPU: 3 PID: 130 Comm: rmmod Not tainted 6.3.0-rc7 #6 | Hardware name: FVP Base RevC (DT) | pstate: 63402809 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=-c) | pc : 0x0 | lr : ffa_device_remove+0x20/0x2c | Call trace: | 0x0 | device_release_driver_internal+0x16c/0x260 | driver_detach+0x90/0xd0 | bus_remove_driver+0xdc/0x11c | driver_unregister+0x30/0x54 | ffa_driver_unregister+0x14/0x20 | cleanup_module+0x18/0xeec | __arm64_sys_delete_module+0x234/0x378 | invoke_syscall+0x40/0x108 | el0_svc_common+0xb4/0xf0 | do_el0_svc+0x30/0xa4 | el0_svc+0x2c/0x7c | el0t_64_sync_handler+0x84/0xf0 | el0t_64_sync+0x190/0x194 Fixes: 244f5d597e1e ("firmware: arm_ffa: Add missing remove callback to ffa_bus_type") Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c index f29d77ecf72d..36bd5423c2f0 100644 --- a/drivers/firmware/arm_ffa/bus.c +++ b/drivers/firmware/arm_ffa/bus.c @@ -53,7 +53,8 @@ static void ffa_device_remove(struct device *dev) { struct ffa_driver *ffa_drv = to_ffa_driver(dev->driver); - ffa_drv->remove(to_ffa_dev(dev)); + if (ffa_drv->remove) + ffa_drv->remove(to_ffa_dev(dev)); } static int ffa_device_uevent(const struct device *dev, struct kobj_uevent_env *env) From patchwork Thu Apr 20 15:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13218901 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 047D7C77B73 for ; Thu, 20 Apr 2023 15:07: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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iNOLj4tx2n3m8JUHkymL46pD+2ZQEXmVqDSBb+Z4WhE=; b=JYkPqGdX/lDcrj pdkdlO23HXurDfeySbG8sMPFgamgk3RmnIiuYSuj29cPDPlLe5eN+7ydf6jt+7AvCPk+EDkfApEbp qRDAvdcgGbciASh2jvKTmsAXIoLIdyrH1f3TzoGBP3U7Ugn/ZOEdu6hJTcOvPch5iDADKuNlBAcfa HDjXLjVKhbp2wZmWQ09t+K0TShjTJtr5LNOVAJdJJxf0kkohJZ/pPDhekgZ7EwbnLO27w4wbre8u6 33r4qamF48zyt4jyCn/vJtw6aQsGrhIYntXgAyquf1CcTXZuoPo5WOvPaujGWKPgdSsTHHoMyCUcx afkvC9+PoIvY4kQYNC7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppVri-008N8w-21; Thu, 20 Apr 2023 15:06:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppVrf-008N7b-2c for linux-arm-kernel@lists.infradead.org; Thu, 20 Apr 2023 15:06:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F2B81595; Thu, 20 Apr 2023 08:07:09 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F13493F6C4; Thu, 20 Apr 2023 08:06:24 -0700 (PDT) From: Sudeep Holla Date: Thu, 20 Apr 2023 16:06:02 +0100 Subject: [PATCH v2 2/3] firmware: arm_ffa: Fix usage of partition info get count flag MIME-Version: 1.0 Message-Id: <20230419-ffa_fixes_6-4-v2-2-d9108e43a176@arm.com> References: <20230419-ffa_fixes_6-4-v2-0-d9108e43a176@arm.com> In-Reply-To: <20230419-ffa_fixes_6-4-v2-0-d9108e43a176@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , Marc Bonnici , Jens Wiklander , Lucian Paul-Trifu X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1724; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=KD0BembRM3K0Vn1WqbMtK1d3oXGcdslUVZPlLwtZpPs=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBkQVTuaqnzN9N9kXsFhjKq29OrvQXM+APRnYs3f q7sKyLa5SuJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZEFU7gAKCRAAQbq8MX7i mDimEACBA4gPYaLh5eHZK99gPu5QL0GT0LOKiITmgv+IFfvB7PDYBoaNyOYywmwGa8wBEb+NQss P7ogo4nFkT9TbtHT1nwIjkKG90R7Deci7Y00OvjAvCRJgUjckN+pmmTD988ikA13ud33nBgg8eA YydSF3eYLwY2uCp5Qrdeirl9qEztBxiUsdd1ZderIIQLVy8fHq+UU4sD5nG+ukxtXSSQpgzUwWY pbqoN7KYQQ/dh1HOgEsCoRsv//rPefYCxkSE0tldq1nx3fANV5PlF+PJDjjIViJj1hc1pN0e9ns LyCL1JHzJ9X97oJFCLsvjg2SwXg7V+xWJEsRMilcFwVlv8S/if/08KdKybvBBpwsGPHIBuvb0Mz BKDcVJBnkUi2O4yQqNdzDgTZqqNfJoRrTXgUejpVffdM10YPyVMchcCH38LcyPF4ejs+vJWSVy4 UchCwigI0anvzLswPZb5m9UfMGmOwBPKTSDJS+c56FEjB0DoESnM7dylQfXMEtmtnebmQqY/Eix o+5QusxEInvDZ9wmEigKvJUHOMlccOIc1cZfKhZuY4OWawIg+vhxjaABuBUPurEI2LMNaBJzOsW ghN/KPhJO27xp1mTkacAvy2m2TV8YBQt3hxBfBk0m0WU1vC+9BERcUgUkb8X/Cyim3/wFWV4ssR qe6s3dG340fqlrg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230420_080627_918844_52C7CE1A X-CRM114-Status: GOOD ( 12.24 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit bb1be7498500 ("firmware: arm_ffa: Add v1.1 get_partition_info support") adds support to discovery the UUIDs of the partitions or just fetch the partition count using the PARTITION_INFO_GET_RETURN_COUNT_ONLY flag. However the commit doesn't handle the fact that the older version doesn't understand the flag and must be MBZ which results in firmware returning invalid parameter error. That results in the failure of the driver probe which is in correct. Limit the usage of the PARTITION_INFO_GET_RETURN_COUNT_ONLY flag for the versions above v1.0(i.e v1.1 and onwards) which fixes the issue. Fixes: bb1be7498500 ("firmware: arm_ffa: Add v1.1 get_partition_info support") Reported-by: Jens Wiklander Reported-by: Marc Bonnici Tested-by: Jens Wiklander Reviewed-by: Jens Wiklander Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index fa85c64d3ded..4aced2e5b772 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -193,7 +193,8 @@ __ffa_partition_info_get(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3, int idx, count, flags = 0, sz, buf_sz; ffa_value_t partition_info; - if (!buffer || !num_partitions) /* Just get the count for now */ + if (drv_info->version > FFA_VERSION_1_0 && + (!buffer || !num_partitions)) /* Just get the count for now */ flags = PARTITION_INFO_GET_RETURN_COUNT_ONLY; mutex_lock(&drv_info->rx_lock); From patchwork Thu Apr 20 15:06:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13218904 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 B8C8DC77B73 for ; Thu, 20 Apr 2023 15:07:36 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hkYBsr4uFCJAuijhSpqT/egpSDIJfr3/rdHapxexdfs=; b=kNStCyzmJxT7pa S2YdbCXgXxPN6OfEBRI3FvXaj8rUJVABUteQAdjVc9Cf5jrgr9YZuJZUzco6btpnb9u+1TG1gJ+WQ XVWzTpb+Pkjb+xOpaHFhZ3aR+kuta12FGe8n1ASQMR68/ixNgCNLfrpzHDkfmvhC3P66Hdgvn+F3M IMwLWITy0sUUcj+p4WEUbgDLdA1/TtGSt/Jr0GR9wLvVq49WG0KZ8GTb/whZW+rfWr3kuUhRCVnd9 7w3mfiq7sIJ3k1ayC5jw1vjzyFoZXShtDRkXXuWvIxWSxMIK+FRgD0SKBRFFEcpJm/K9c4DpLtI7r 6M63Jkhcsqpc62mfyUjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppVrv-008NAm-2x; Thu, 20 Apr 2023 15:06:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppVrf-008N7a-2c for linux-arm-kernel@lists.infradead.org; Thu, 20 Apr 2023 15:06:30 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4FD321596; Thu, 20 Apr 2023 08:07:10 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D1E373F6C4; Thu, 20 Apr 2023 08:06:25 -0700 (PDT) From: Sudeep Holla Date: Thu, 20 Apr 2023 16:06:03 +0100 Subject: [PATCH v2 3/3] firmware: arm_ffa: Fix FFA device names for logical partitions MIME-Version: 1.0 Message-Id: <20230419-ffa_fixes_6-4-v2-3-d9108e43a176@arm.com> References: <20230419-ffa_fixes_6-4-v2-0-d9108e43a176@arm.com> In-Reply-To: <20230419-ffa_fixes_6-4-v2-0-d9108e43a176@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , Marc Bonnici , Jens Wiklander , Lucian Paul-Trifu X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4456; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=eYTVSa5inVy3QVVU4ZswPkCb1d+/k2FvXqe7Mbrk+7Q=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBkQVTuB+iZbFtmfmKoj+286sn8i1MjvWh+LSHI0 SP76v0Ze/+JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZEFU7gAKCRAAQbq8MX7i mBsLEACoj6DdLZPk/+nw1m5x7Dxq0CQ/J7A7pdYp7VWH4ns7o3th1gTjXHDVEtHmSLeWcNHoYWo ujssED1MviyWs1S5mza7VISvKQj7RixfbA8sH+F75EMy0boS7PyFO7Av2tujzDhK+UzQUF7Q1ht +sBya7o9A6WV+xUbSq9Xb1eiN9LiRDv0Fue2eY9ab9u+J48mwBn717H7nah0auzMxE3tQD4yMAJ YEFFSdkxOPopfsudTyvj52ezyLC0U+7PqyNd0Pu2rK7/cfWfEnG7EE8G9S7ulmCqchrf4zBmgQe bcZKMY6bAahQsuCBkbNMO0buv1aK7WVAh1RRjNxM1OJ55l0HDzngOVj/zhHuxVzu4jvJ2JkZp3b q4I4uYqIcbhF9z/gOZxnZ50c60OGGEfGaA2zNio7QszdNgWFSiSxSq7aobBuo99LVbCBfZhypDD HsfQ9bBgrSSJW3NueSCJC29xkGvAYHg1jFREEFxZ6BrEVDm1foUWLt1ycBiIsflI4wMbo0snS2F fOar4mQGFmEfajk57q7G+EE6FnkvxTQxq1nKRb16M41XoylaQamDO7LhQY7YvD3/F8/DNDaj0l/ E5A3CQox590WilyJE+U+DvVx2eCaBsNUvMlDxMikE6kuRPOzjO4xIVsyfccqfyfcLgU6IO5RJm3 JMtU5WaSLX28B5g== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230420_080627_967284_5007D049 X-CRM114-Status: GOOD ( 21.26 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Each physical partition can provide multiple services each with UUID. Each such service can be presented as logical partition with a unique combination of VM ID and UUID. The number of distinct UUID in a system will be less than or equal to the number of logical partitions. However, currently it fails to register more than one logical partition or service within a physical partition as the device name contains only VM ID while both VM ID and UUID are maintained in the partition information. The kernel complains with the below message: | sysfs: cannot create duplicate filename '/devices/arm-ffa-8001' | CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.3.0-rc7 #8 | Hardware name: FVP Base RevC (DT) | Call trace: | dump_backtrace+0xf8/0x118 | show_stack+0x18/0x24 | dump_stack_lvl+0x50/0x68 | dump_stack+0x18/0x24 | sysfs_create_dir_ns+0xe0/0x13c | kobject_add_internal+0x220/0x3d4 | kobject_add+0x94/0x100 | device_add+0x144/0x5d8 | device_register+0x20/0x30 | ffa_device_register+0x88/0xd8 | ffa_setup_partitions+0x108/0x1b8 | ffa_init+0x2ec/0x3a4 | do_one_initcall+0xcc/0x240 | do_initcall_level+0x8c/0xac | do_initcalls+0x54/0x94 | do_basic_setup+0x1c/0x28 | kernel_init_freeable+0x100/0x16c | kernel_init+0x20/0x1a0 | ret_from_fork+0x10/0x20 | kobject_add_internal failed for arm-ffa-8001 with -EEXIST, don't try to | register things with the same name in the same directory. | arm_ffa arm-ffa: unable to register device arm-ffa-8001 err=-17 | ARM FF-A: ffa_setup_partitions: failed to register partition ID 0x8001 By virtue of being random enough to avoid collisions when generated in a distributed system, there is no way to compress UUID keys to the number of bits required to identify each. We can eliminate '-' in the name but it is not worth eliminating 4 bytes and add unnecessary logic for doing that. Also v1.0 doesn't provide the UUID of the partitions which makes it hard to use the same for the device name. So to keep it simple, let us alloc an ID using ida_alloc() and append the same to "arm-ffa" to make up a unique device name. Also stash the id value in ffa_dev to help freeing the ID later when the device is destroyed. Fixes: e781858488b9 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration") Reported-by: Lucian Paul-Trifu Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/bus.c | 16 +++++++++++++--- include/linux/arm_ffa.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c index 36bd5423c2f0..2b8bfcd010f5 100644 --- a/drivers/firmware/arm_ffa/bus.c +++ b/drivers/firmware/arm_ffa/bus.c @@ -15,6 +15,8 @@ #include "common.h" +static DEFINE_IDA(ffa_bus_id); + static int ffa_device_match(struct device *dev, struct device_driver *drv) { const struct ffa_device_id *id_table; @@ -131,6 +133,7 @@ static void ffa_release_device(struct device *dev) { struct ffa_device *ffa_dev = to_ffa_dev(dev); + ida_free(&ffa_bus_id, ffa_dev->id); kfree(ffa_dev); } @@ -171,18 +174,24 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev) struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id, const struct ffa_ops *ops) { - int ret; + int id, ret; struct device *dev; struct ffa_device *ffa_dev; + id = ida_alloc_min(&ffa_bus_id, 1, GFP_KERNEL); + if (id < 0) + return NULL; + ffa_dev = kzalloc(sizeof(*ffa_dev), GFP_KERNEL); - if (!ffa_dev) + if (!ffa_dev) { + ida_free(&ffa_bus_id, id); return NULL; + } dev = &ffa_dev->dev; dev->bus = &ffa_bus_type; dev->release = ffa_release_device; - dev_set_name(&ffa_dev->dev, "arm-ffa-%04x", vm_id); + dev_set_name(&ffa_dev->dev, "arm-ffa-%d", id); ffa_dev->vm_id = vm_id; ffa_dev->ops = ops; @@ -218,4 +227,5 @@ void arm_ffa_bus_exit(void) { ffa_devices_unregister(); bus_unregister(&ffa_bus_type); + ida_destroy(&ffa_bus_id); } diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index c87aeecaa9b2..583fe3b49a49 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -96,6 +96,7 @@ /* FFA Bus/Device/Driver related */ struct ffa_device { + u32 id; int vm_id; bool mode_32bit; uuid_t uuid;