From patchwork Fri Jan 21 21:18:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Schlabbach X-Patchwork-Id: 12720302 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25692C433F5 for ; Fri, 21 Jan 2022 21:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229625AbiAUVSv (ORCPT ); Fri, 21 Jan 2022 16:18:51 -0500 Received: from mout.gmx.net ([212.227.17.21]:44979 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiAUVSv (ORCPT ); Fri, 21 Jan 2022 16:18:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1642799930; bh=GyuEgoPJpaigtO6G3guV16gCj/T62drFBhDmR6Tm/Nw=; h=X-UI-Sender-Class:From:To:Subject:Date; b=NUMAYFvsXKT1WZCWUNB4fhNDdzF7BnomLJjyYu0+2meUvVqx2ErSY9/IumvqUu299 Vbdn2M89XLhhw7NN+e19SVB6eUmkLSeyczt98DP3IQP1bnZA+7zuwEEEP6gjw419/j Hdev+9W4YwhEpSrw6NnTafhlLAA51rFWBlAKrg8o= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [91.65.109.130] ([91.65.109.130]) by web-mail.gmx.net (3c-app-gmx-bap04.server.lan [172.19.172.74]) (via HTTP); Fri, 21 Jan 2022 22:18:49 +0100 MIME-Version: 1.0 Message-ID: From: Robert Schlabbach To: linux-media@vger.kernel.org Subject: [PATCH 1/1] media: dvb-core: Enhance shared multi-frontend support Date: Fri, 21 Jan 2022 22:18:49 +0100 Importance: normal Sensitivity: Normal X-Priority: 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UipllzTLIy7sL2oJMiAyH+Wn46iap WGRGp3IkfUw8ITfcyzAQphb2DVRDFjl7Lik2uy1uvimaJGpAZZwn1zHZHygro072lnbzDPsQo yG6Dsvu Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Drivers for devices with multiple frontends which cannot be used concurrently due to hardware limitations which enforce that restriction by setting the mfe_shared field to 1 exhibit rather unfriendly behavior towards applications: The unavailable frontend devices cannot be opened at all, not even for read-only access to query information. Even worse, any open call is blocked for 5 seconds by default. Allow drivers for such devices to behave like regular busy frontend devices instead, i.e. still allowing concurrent read access to the unavailable frontend and denying concurrent write access with -EBUSY without delay. This patch does not alter the behavior of any existing driver to avoid regressions. Driver developers who wish to take advantage of this must ensure their driver can handle all read-only accesses to the unavailable frontend, and indicate the capability by setting the mfe_shared field to 2 instead of 1. Add a check to dvb-usb-init.c when automatically setting the mfe_shared field that when a driver has already set the field to 2, it is not overwritten. Document the additional capability in the code comment about mfe_shared. Signed-off-by: Robert Schlabbach Tested-by: Robert Schlabbach --- drivers/media/dvb-core/dvb_frontend.c | 12 +++++++++++- drivers/media/usb/dvb-usb/dvb-usb-init.c | 2 +- include/media/dvbdev.h | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c index 48e735cdbe6b..24c268b20661 100644 --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -2754,7 +2754,17 @@ static int dvb_frontend_open(struct inode *inode, struct file *file) if (fe->exit == DVB_FE_DEVICE_REMOVED) return -ENODEV; - if (adapter->mfe_shared) { + if (adapter->mfe_shared == 2) { + mutex_lock(&adapter->mfe_lock); + if ((file->f_flags & O_ACCMODE) != O_RDONLY) { + if (adapter->mfe_dvbdev && + !adapter->mfe_dvbdev->writers) { + mutex_unlock(&adapter->mfe_lock); + return -EBUSY; + } + adapter->mfe_dvbdev = dvbdev; + } + } else if (adapter->mfe_shared) { mutex_lock(&adapter->mfe_lock); if (!adapter->mfe_dvbdev) diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c index 61439c8f33ca..341d6c7a6bba 100644 --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c @@ -92,7 +92,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs) goto frontend_init_err; /* use exclusive FE lock if there is multiple shared FEs */ - if (adap->fe_adap[1].fe) + if (adap->fe_adap[1].fe && adap->dvb_adap.mfe_shared < 1) adap->dvb_adap.mfe_shared = 1; d->num_adapters_initialized++; diff --git a/include/media/dvbdev.h b/include/media/dvbdev.h index 2f6b0861322a..6ccff7c6fa6b 100644 --- a/include/media/dvbdev.h +++ b/include/media/dvbdev.h @@ -87,7 +87,11 @@ struct dvb_frontend; * @device: pointer to struct device * @module: pointer to struct module * @mfe_shared: indicates mutually exclusive frontends. - * Use of this flag is currently deprecated. + * 1 = legacy exclusion behavior: blocking any open() call + * 2 = enhanced exclusion behavior, emulating the standard + * behavior of busy frontends: allowing read-only sharing + * and otherwise returning immediately with -EBUSY when any + * of the frontends is already opened with write access. * @mfe_dvbdev: Frontend device in use, in the case of MFE * @mfe_lock: Lock to prevent using the other frontends when MFE is * used.