Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2823949pxv; Mon, 12 Jul 2021 02:50:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP9MFD0vlkx6ov6t66TsnW2L+U1hV1z10cUORvqsnnH1/g8Qc4TVmaBdA7mVnOgw6phEWU X-Received: by 2002:a02:90d0:: with SMTP id c16mr32355399jag.106.1626083420844; Mon, 12 Jul 2021 02:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626083420; cv=none; d=google.com; s=arc-20160816; b=u+DLFipj0GgRayQi8/edHRiKVapfP8N7YE5CANoLxfmt3ThQNjps65zIZuyn5uQJXy s0h1RkAv4q+ajsD+10EDj0eEROotMnN4WC7TWjQXtHsQt82ds4croGnK8GzSWLW0CfKZ u1cg9KAimeFqEO8N/HHZdJY0exe/Z2w6PoSJvvjFcSrj6p5aLC/LlIRbDztqRKHtSOOr CbzIQJpIM3fCNzB5qgzgJDHn3cRgr5FRw7hAcI+o0bsAhqbBmO9vHAVrZs00JYPqL2Rn xwArFLp1ifggdOumU0+3faHdxGkv4rNHCZgz65HxvOuRX8MWdWPiFWiWdqlKAVvnIn2C YbhQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Aw4bmXBLdlzjJLcdALzMS4A4NPijlh2Qo4Y5StZ+1mQ=; b=lAlwwv58E6a4VfVFfYURyZDXS4HlWqhtL5hoOJDXONXkzC1+pkY9k0QD67G/zPMSQq 5A7u/dxgJtL1OG93L++f3ioSB05Bb5nFxkUZHUIwQ76MrKVxmeMJQS15737o3D7W0Uwv UGRwCcC6XSYRqimoyXzBaiT5p66LKWUn44lRwt7SoqNNuWUuctYhtsCb+4xhzcIq1yFE KuIWp9vc69p93nNd6LjoZARdH7xWv2b7ktCRbACNvYBmSVwLWVS/ipsaMTt0YbT7ywXk zhOAezKqIuqFgoLAz3+OQvLGukxbGxhk6SG2MQTWsg8wliOF25ePC4C9PqXZnLqBw7yR k5rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ClIv2Bih; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si20750190ilu.53.2021.07.12.02.50.09; Mon, 12 Jul 2021 02:50:20 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ClIv2Bih; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237064AbhGLGqI (ORCPT + 99 others); Mon, 12 Jul 2021 02:46:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:55424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236227AbhGLGfa (ORCPT ); Mon, 12 Jul 2021 02:35:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 27ED2610D0; Mon, 12 Jul 2021 06:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071559; bh=QscHBCdwyz845ByNO9AmsX1v5TFqG9DVE99wooaq7oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ClIv2BihJ3wlJxCdLlt+Ac7WNn+QUjBtyPJamXqekR1EYbBpTGFgAEIqqFQtee1xK baYs5MnwPicu+vAb35wU6pHLzpKRluokTjRVxNHrhOQKnc9/BnYdrvlBqIBbZE+xwm zOOqbupj1Tfz01t5LijJI4J9Bj+e8npdYX90B0v8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.10 123/593] media: cobalt: fix race condition in setting HPD Date: Mon, 12 Jul 2021 08:04:43 +0200 Message-Id: <20210712060856.696488657@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil [ Upstream commit 3d37ef41bed0854805ab9af22c422267510e1344 ] The cobalt_s_bit_sysctrl reads the old register value over PCI, then changes a bit and sets writes the new value to the register. This is used among other things for setting the HPD output pin. But if the HPD is changed for multiple inputs at the same time, then this causes a race condition where a stale value is read. Serialize this function with a mutex. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/cobalt/cobalt-driver.c | 1 + drivers/media/pci/cobalt/cobalt-driver.h | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c index 0695078ef812..1bd8bbe57a30 100644 --- a/drivers/media/pci/cobalt/cobalt-driver.c +++ b/drivers/media/pci/cobalt/cobalt-driver.c @@ -667,6 +667,7 @@ static int cobalt_probe(struct pci_dev *pci_dev, return -ENOMEM; cobalt->pci_dev = pci_dev; cobalt->instance = i; + mutex_init(&cobalt->pci_lock); retval = v4l2_device_register(&pci_dev->dev, &cobalt->v4l2_dev); if (retval) { diff --git a/drivers/media/pci/cobalt/cobalt-driver.h b/drivers/media/pci/cobalt/cobalt-driver.h index bca68572b324..12c33e035904 100644 --- a/drivers/media/pci/cobalt/cobalt-driver.h +++ b/drivers/media/pci/cobalt/cobalt-driver.h @@ -251,6 +251,8 @@ struct cobalt { int instance; struct pci_dev *pci_dev; struct v4l2_device v4l2_dev; + /* serialize PCI access in cobalt_s_bit_sysctrl() */ + struct mutex pci_lock; void __iomem *bar0, *bar1; @@ -320,10 +322,13 @@ static inline u32 cobalt_g_sysctrl(struct cobalt *cobalt) static inline void cobalt_s_bit_sysctrl(struct cobalt *cobalt, int bit, int val) { - u32 ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE); + u32 ctrl; + mutex_lock(&cobalt->pci_lock); + ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE); cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE, (ctrl & ~(1UL << bit)) | (val << bit)); + mutex_unlock(&cobalt->pci_lock); } static inline u32 cobalt_g_sysstat(struct cobalt *cobalt) -- 2.30.2