Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1098376pxb; Wed, 29 Sep 2021 17:14:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9T84jjlrGiGub+QLpk4KL3+A+zgfNkhFS+w65nOystouliCIu/kqYV6M0mP7l+jN9xWVJ X-Received: by 2002:a17:90a:dc81:: with SMTP id j1mr2906120pjv.155.1632960854300; Wed, 29 Sep 2021 17:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632960854; cv=none; d=google.com; s=arc-20160816; b=ZM+1jFKuIBCQt3z08WadmLM/RTeK2orS/sof67DUa6VE6qtzNfmbRgyNPWW/3hgs2j B3mpWmr379r/NOkRYAm4vbxZcI1XbpCICFnI5kT+U6waaoyFlOMXnW4cLLdDl4GK64VS /DQB2PuMnu0lmiX7P7sYh4A10QXDZqBSrA7PouoIBwqEALUScCgiYByq0Y6Nam880Dwd RQWGa8ktXlu5+ijgR2xhw9lXFQqZVUcsAjaKeyOwDYJFC4ysLngiAmykxz0K13mh/61i 7ORuOliqZu6otzvgf4wFuOnpO560JcyGDaOIOo9Gv5jOQnBjZ34zePznAnASxUZmtZAO MR4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gVTN4z2TbdkjzoiEYbbpBZcTjRaexZ0esJy63w+W1Vc=; b=Ll/IY+THsijIgUyOUq9dYEYOsC21VS1RevF6zRp0nY5a+siJdPwF+6gbpDOYeFXD7L IuikGleepmltBhulWc11PxPB4mMf0iE2sIR5IXSwaFhb4u+KVscG1/9bXWM0xnJ0rukF cb9YJ1GmSp3bhvrndK+PHf23Fg6k8SZXPkMYM5KjtORRjFA05H2TfTa9pRjeFX2b68fT 0RFJO/SYTn5Xda4YGnaj4pJRsid4qNfxX/FDSKuEKlA4baBEVj7mfWnOrhNwV1BOu+yc XxBrW8qbC/Szyt1lspbdl5ZpUMdwkmyMKaDJOpOAn75TtV+yYHbw1VJhxxUNl+QI1IVU v2cA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b2si1409471plx.384.2021.09.29.17.14.01; Wed, 29 Sep 2021 17:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347390AbhI2XCb (ORCPT + 99 others); Wed, 29 Sep 2021 19:02:31 -0400 Received: from mga09.intel.com ([134.134.136.24]:47376 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347367AbhI2XCO (ORCPT ); Wed, 29 Sep 2021 19:02:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10122"; a="225097217" X-IronPort-AV: E=Sophos;i="5.85,334,1624345200"; d="scan'208";a="225097217" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 16:00:31 -0700 X-IronPort-AV: E=Sophos;i="5.85,334,1624345200"; d="scan'208";a="617768036" Received: from rhweight-mobl2.amr.corp.intel.com (HELO rhweight-mobl2.ra.intel.com) ([10.255.230.76]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 16:00:30 -0700 From: Russ Weight To: mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: trix@redhat.com, lgoncalv@redhat.com, yilun.xu@intel.com, hao.wu@intel.com, matthew.gerlach@intel.com, Russ Weight Subject: [PATCH v17 3/5] fpga: image-load: signal eventfd when complete Date: Wed, 29 Sep 2021 16:00:23 -0700 Message-Id: <20210929230025.68961-4-russell.h.weight@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210929230025.68961-1-russell.h.weight@intel.com> References: <20210929230025.68961-1-russell.h.weight@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Amend the FPGA_IMAGE_LOAD_WRITE IOCTL implementation to include an eventfd file descriptor as a parameter. The eventfd will be triggered when the image upload completes. Signed-off-by: Russ Weight --- v17: - More documentation cleanup. v16: - Some cleanup of documentation for the FPGA_IMAGE_LOAD_WRITE IOCTL. v15: - This patch is new to the patch-set, and adds an eventfd to the FPGA_IMAGE_LOAD_WRITE IOCTL. The eventfd is signalled upon completion of an update. --- Documentation/fpga/fpga-image-load.rst | 8 +++++--- drivers/fpga/fpga-image-load.c | 22 ++++++++++++++++++++-- include/linux/fpga/fpga-image-load.h | 2 ++ include/uapi/linux/fpga-image-load.h | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Documentation/fpga/fpga-image-load.rst b/Documentation/fpga/fpga-image-load.rst index f6b0e1624a05..487b5466f67c 100644 --- a/Documentation/fpga/fpga-image-load.rst +++ b/Documentation/fpga/fpga-image-load.rst @@ -28,6 +28,8 @@ FPGA_IMAGE_LOAD_WRITE: Start an image upload with the provided image buffer. This IOCTL returns immediately after starting a kernel worker thread to process the image -upload which could take as long as 40 minutes depending on the actual -device being updated. This is an exclusive operation; an attempt to start -concurrent image uploads for the same device will fail with EBUSY. +upload which could take as long as 40 minutes depending on the actual device +being updated. This is an exclusive operation; an attempt to start +concurrent image uploads for the same device will fail with EBUSY. An +eventfd file descriptor parameter is provided to this IOCTL. It will be +signalled at the completion of the image upload. diff --git a/drivers/fpga/fpga-image-load.c b/drivers/fpga/fpga-image-load.c index 4c2571e3b26f..f04dfc71c190 100644 --- a/drivers/fpga/fpga-image-load.c +++ b/drivers/fpga/fpga-image-load.c @@ -26,6 +26,7 @@ static void fpga_image_prog_complete(struct fpga_image_load *imgld) { mutex_lock(&imgld->lock); imgld->progress = FPGA_IMAGE_PROG_IDLE; + eventfd_signal(imgld->finished, 1); mutex_unlock(&imgld->lock); } @@ -96,6 +97,8 @@ static void fpga_image_do_load(struct work_struct *work) vfree(imgld->data); imgld->data = NULL; fpga_image_prog_complete(imgld); + eventfd_ctx_put(imgld->finished); + imgld->finished = NULL; } static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld, @@ -103,6 +106,7 @@ static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld, { struct fpga_image_write wb; unsigned long minsz; + int ret; u8 *buf; if (imgld->driver_unload || imgld->progress != FPGA_IMAGE_PROG_IDLE) @@ -115,13 +119,23 @@ static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld, if (wb.flags) return -EINVAL; + if (wb.evtfd < 0) + return -EINVAL; + buf = vzalloc(wb.size); if (!buf) return -ENOMEM; if (copy_from_user(buf, u64_to_user_ptr(wb.buf), wb.size)) { - vfree(buf); - return -EFAULT; + ret = -EFAULT; + goto exit_free; + } + + imgld->finished = eventfd_ctx_fdget(wb.evtfd); + if (IS_ERR(imgld->finished)) { + ret = PTR_ERR(imgld->finished); + imgld->finished = NULL; + goto exit_free; } imgld->data = buf; @@ -131,6 +145,10 @@ static int fpga_image_load_ioctl_write(struct fpga_image_load *imgld, queue_work(system_long_wq, &imgld->work); return 0; + +exit_free: + vfree(buf); + return ret; } static long fpga_image_load_ioctl(struct file *filp, unsigned int cmd, diff --git a/include/linux/fpga/fpga-image-load.h b/include/linux/fpga/fpga-image-load.h index 7b445f489644..77b3c91ce073 100644 --- a/include/linux/fpga/fpga-image-load.h +++ b/include/linux/fpga/fpga-image-load.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,7 @@ struct fpga_image_load { u32 progress; u32 err_code; /* image load error code */ bool driver_unload; + struct eventfd_ctx *finished; void *priv; }; diff --git a/include/uapi/linux/fpga-image-load.h b/include/uapi/linux/fpga-image-load.h index 20eae3bb10d8..8d2d3db92e87 100644 --- a/include/uapi/linux/fpga-image-load.h +++ b/include/uapi/linux/fpga-image-load.h @@ -37,7 +37,7 @@ * struct fpga_image_write) * * Upload a data buffer to the target device. The user must provide the - * data buffer and size. + * data buffer, size, and an eventfd file descriptor. * * Return: 0 on success, -errno on failure. */ @@ -45,6 +45,7 @@ struct fpga_image_write { /* Input */ __u32 flags; /* Zero for now */ __u32 size; /* Data size (in bytes) to be written */ + __s32 evtfd; /* File descriptor for completion signal */ __u64 buf; /* User space address of source data */ }; -- 2.25.1