From patchwork Fri Sep 6 07:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13793501 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 7CB43CE7AE0 for ; Fri, 6 Sep 2024 07:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QPU0MmVO6vMHi9YqxFMyW+RGtd4b38BtKJhpEbN+iYA=; b=yLL7bQVBhcb38aDDMO8AiLjwKd YQh8A2sTeoDoFlVjorucNhw9I4y2tQrGePIln9YUx6MT/evM0IPj4XFAcVI1ph3xxFclyeKrvNJrL ItcX4oIL/pnmpl57ulpIWQ7SOezIfHHsQSxNknW28AqxJ7cDbBoy/2oU626iKwq50Ndt3qVu40zTZ J+zxNiQ396mDsRa8HTs1uuTBV0JoBDzqOooFnGWqEB4Saf1+JU2MkpTyE0gFkupAUz8vcGOHlgyYK xt57ZtiOOFpcxJyxiDnsLyobAHEMpGcgE+6Uoe9oo1qK2Hub3hm97dAmSzoJ/tUKOLD0RHsEe3BTE SyEBJwQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smTPR-0000000B5RP-3x9v; Fri, 06 Sep 2024 07:29:33 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smTLP-0000000B4Li-07Vc; Fri, 06 Sep 2024 07:25:24 +0000 Received: from umang.jain (unknown [IPv6:2405:201:2015:f873:c173:4b:4a04:3a21]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 75BBBFEF; Fri, 6 Sep 2024 09:24:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1725607446; bh=h6MYM/yBuO6U3NBFZ8tXuWNXdaS3S22/P0/XKjqxOmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vAoBrlplOdEv/Wvjwv3YTuFwPw+Mfy3mfkL8GEx2YYSru5O/A3Ss7CTadJT+LbMYY 7La2RCxLHQ+s+Y43V05D/+SBfxH/JYeGBQ4/HihItN8g45q4cL4wxz6EOLYHzNuxFX T7uoGAW/OPuTLNKdMoQOKNSZKjqIl2nKlT6sYvzg= From: Umang Jain To: Florian Fainelli , Broadcom internal kernel review list , Greg Kroah-Hartman Cc: linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Kieran Bingham , Arnd Bergmann , Stefan Wahren , Dave Stevenson , Phil Elwell , Laurent Pinchart , Umang Jain Subject: [PATCH v4 1/7] staging: vchiq: Factor out bulk transfer for VCHIQ_BULK_MODE_WAITING Date: Fri, 6 Sep 2024 12:55:00 +0530 Message-ID: <20240906072506.174026-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240906072506.174026-1-umang.jain@ideasonboard.com> References: <20240906072506.174026-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_002523_229906_059E7B03 X-CRM114-Status: GOOD ( 15.58 ) 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 The bulk transfer is VCHIQ_BULK_MODE_WAITING is used by VCHIQ ioctl interface. It is factored out to a separate function from vchiq_bulk_transfer() to bulk_xfer_waiting_interruptible(). This is a part of vchiq_bulk_transfer refactoring. Each bulk mode will have their dedicated functions to execute bulk transfers. Each mode will be handled separately in subsequent patches. bulk_xfer_waiting_interruptible() is suffixed with "_interruptible" to denote that it can be interrupted when a signal is received. -EAGAIN maybe returned in those cases, similar to what vchiq_bulk_transfer() does. Adjust the vchiq_irq_queue_bulk_tx_rx() in the vchiq-dev.c to call bulk_xfer_waiting_interruptible() for waiting mode. A temporary goto label has been introduced to jump the call execution over vchiq_bulk_transfer() for waiting mode only. When all dedicated bulk transfer calls are introduced, this label shall be dropped. No function changes intended in this patch. Signed-off-by: Umang Jain --- .../interface/vchiq_arm/vchiq_core.c | 53 ++++++++++++++++--- .../interface/vchiq_arm/vchiq_core.h | 4 ++ .../interface/vchiq_arm/vchiq_dev.c | 5 ++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c index 50af04b217f4..2239f59519be 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -3023,10 +3023,6 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, bulk_waiter->actual = 0; bulk_waiter->bulk = NULL; break; - case VCHIQ_BULK_MODE_WAITING: - bulk_waiter = userdata; - bulk = bulk_waiter->bulk; - goto waiting; default: goto error_exit; } @@ -3115,11 +3111,8 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, state->id, service->localport, dir_char, queue->local_insert, queue->remote_insert, queue->process); -waiting: vchiq_service_put(service); - status = 0; - if (bulk_waiter) { bulk_waiter->bulk = bulk; if (wait_for_completion_interruptible(&bulk_waiter->event)) @@ -3128,7 +3121,7 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, status = -EINVAL; } - return status; + return 0; unlock_both_error_exit: mutex_unlock(&state->slot_mutex); @@ -3143,6 +3136,50 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, return status; } +/* + * This function is called by VCHIQ ioctl interface and is interruptible. + * It may receive -EAGAIN to indicate that a signal has been received + * and the call should be retried after being returned to user context. + */ +int +vchiq_bulk_xfer_waiting_interruptible(struct vchiq_instance *instance, + unsigned int handle, struct bulk_waiter *userdata) +{ + struct vchiq_service *service = find_service_by_handle(instance, handle); + struct bulk_waiter *bulk_waiter; + int status = -EINVAL; + + if (!service) + return -EINVAL; + + if (!userdata) + goto error_exit; + + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) + goto error_exit; + + if (vchiq_check_service(service)) + goto error_exit; + + bulk_waiter = userdata; + + vchiq_service_put(service); + + status = 0; + + if (wait_for_completion_interruptible(&bulk_waiter->event)) + return -EAGAIN; + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED) + return -EINVAL; + + return status; + +error_exit: + vchiq_service_put(service); + + return status; +} + int vchiq_queue_message(struct vchiq_instance *instance, unsigned int handle, ssize_t (*copy_callback)(void *context, void *dest, diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h index 77cc4d7ac077..985d9ea3a06a 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -470,6 +470,10 @@ vchiq_shutdown_internal(struct vchiq_state *state, struct vchiq_instance *instan extern void remote_event_pollall(struct vchiq_state *state); +extern int +vchiq_bulk_xfer_waiting_interruptible(struct vchiq_instance *instance, + unsigned int handle, struct bulk_waiter *userdata); + extern int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *offset, void __user *uoffset, int size, void *userdata, enum vchiq_bulk_mode mode, diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index 9cd2a64dce5e..550838d2863b 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -324,6 +324,10 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance, dev_dbg(service->state->dev, "arm: found bulk_waiter %pK for pid %d\n", waiter, current->pid); userdata = &waiter->bulk_waiter; + + status = vchiq_bulk_xfer_waiting_interruptible(instance, args->handle, userdata); + + goto bulk_transfer_handled; } else { userdata = args->userdata; } @@ -331,6 +335,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance, status = vchiq_bulk_transfer(instance, args->handle, NULL, args->data, args->size, userdata, args->mode, dir); +bulk_transfer_handled: if (!waiter) { ret = 0; goto out;