Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3343888pxv; Sun, 4 Jul 2021 16:06:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm2+0OfkYKcGn6enaPOie+zrzgfQnfu+nL3hWOa7pLh1tuDbhEJMhfPCHovVH3DOD2/d1M X-Received: by 2002:a6b:6f0d:: with SMTP id k13mr9503316ioc.189.1625439978972; Sun, 04 Jul 2021 16:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625439978; cv=none; d=google.com; s=arc-20160816; b=EbiPOCCHX18GaVxq1mjy8Nv84K5Gc9Qo8J57A5v+B4CvFbUjoDqDDwSt4IfWAbyJXA d92srbEtYMBLgWNs6fhR4rI2QlEN/7Jf1wt9Jsdb8XIvxCcG/tXRgqU8BfiA5Mx9VYRM fsiEt7Ouxyki6b2KxIcXXCZOWgPuO8xEvWIu8vQ6mQEJPSzXR0PKfFHFcnR3OZ7FSQOb OBwPzcF+4JUBOjLeBIgsT5lIFmazWzRdGVwYBWTw+cmvHHOCFSNyQz7sDSHpbrEnvKGj ap78gwFBxbrUagLzO4zYKFsMrm7JY80+f7MzV1hqwwY/hYcBzAOa8MO/IntqNywLraBH sgzw== 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 :dkim-signature; bh=HrpnRtCh4BpHwcSOH8GxQ/7xUosayMeHtM8ozwYwqrg=; b=FISrwaLdgeJnuiA7iXxqyVxQ4eX5/Thu6nMHo/AwW7tpkft0ekN9iLYDya6yN2vjiP /HmyMw3MI8tkMuJuzO8X43NlfYk5CvjxKC7aZvotO4iLDpn+GBu/aNZgELY57SAKq4+W RUwNwzQW4bOpKNK7S+cjKrcSKjSXo4noVFPqpVujB5pYkaPFTXFgQ+uvOoAMv24440HX OlX4LqSZrF53PzyBCmJbBy0w8rVmp4Y1kTalFjUxkYTWNyBbQyJhYZUXMrx0pyFw5ydf Ztyo73TFoJBnmZ/4YiORVQZFUNBcD6u5AGDht2Hu8YYlcKgm7hogMkfajsdmRZtzG+QS N/SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JVYQX3rt; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si12569431jal.92.2021.07.04.16.06.07; Sun, 04 Jul 2021 16:06:18 -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=@kernel.org header.s=k20201202 header.b=JVYQX3rt; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230366AbhGDXHz (ORCPT + 99 others); Sun, 4 Jul 2021 19:07:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:45910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbhGDXHe (ORCPT ); Sun, 4 Jul 2021 19:07:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CE86261364; Sun, 4 Jul 2021 23:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439898; bh=rT9ZupC3uWa9FL/U6VfWmOl0JrhYgfdVrBd7FrXQQwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVYQX3rtYLYy4L2E7arsCF3h3kv89zOKGXIC8AGU8o2emL8VgIrQEm74e9HXgiQB2 biBFufx6iPVgUDgTqfvJm9aijIQuavOqeDiBxqN3ezBLUGs05k3CGxnbZqLuudG359 rCCo22752OIppjBLssdzJ80KJpaReCChnmXArfXjkHnt1Ha0vHK6vcCDFvXfRL400D WnFaQyL2/Wya/6t1zVLwNIdTZD0tQI9vrjxdKm7Tire+6IXAMBoxGgWxDflZCC9RhX VtkPur42FEV+L0gJS//FPq03zj19c7XERPSfq05TF9IdJmd4PWJmYVnb7J7mmtin4D Kmbn8H2+Ac1ug== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.13 27/85] media: cobalt: fix race condition in setting HPD Date: Sun, 4 Jul 2021 19:03:22 -0400 Message-Id: <20210704230420.1488358-27-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 839503e654f4..16af58f2f93c 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