From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A26B728A1F5 for ; Mon, 16 Jun 2025 20:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750104900; cv=none; b=jzwsSS6K2A4ayGl2P9wIV1Z0iN9IiX9vyNdwZ/2p6LBzi4rtJjEVtW4WeLF/xIt1B/7qriegEvkU68Qzgm41b0yGuglG9oHF0dZlE5+UccEl69Xhol612U9/ybbyMpXFXCoPm+sAChlF0cvrOmobZP/Yyn002tnY0Eg3auckDIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750104900; c=relaxed/simple; bh=4KUzpSMWG3g9IuCPuhaljwtDZbmm+RMgcvIPQFtfMUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AgeXjnwSxxeqprm5LRnMgPRXuTvgSDBGMD15zjHEObXgITgMI4mNkPXMNs+7eH89xFGLDHjCGEMGjrbsF0FQT8eyZEsV/mFNHl6Mx4Jjbz6ME5UtxOqJ3Unh+rIzxMlxZXduWqEzxs5vHivrqPBrVfT6rCKQ7ygMSjDYulunbeU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cXj3HLyz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cXj3HLyz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750104897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EMnYd1npq1nHTWpIVvhBB0Ev585m/kdvaOzQpI3Jbqs=; b=cXj3HLyzxKftXEI6Gy8VFJ76wG96LcO+yvLhglh2z7cxkPTRKDmxHhJplB4nBmFIw/tsJw nGFiwiqrH7mJYibfasjJhl5LNRu6h7IQVRYSKN/x7bhJP2UVin9D39s5IyaeFmc7Ao/qxt KDuh8Ts6SB2SpjYj23okwEcAS0uWInQ= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-SHSfLIyZPvG5QBvYaKXO2w-1; Mon, 16 Jun 2025 16:14:54 -0400 X-MC-Unique: SHSfLIyZPvG5QBvYaKXO2w-1 X-Mimecast-MFC-AGG-ID: SHSfLIyZPvG5QBvYaKXO2w_1750104892 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E84B219560B5; Mon, 16 Jun 2025 20:14:51 +0000 (UTC) Received: from p16v.luc.cera.cz (unknown [10.45.224.53]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 778C830001B1; Mon, 16 Jun 2025 20:14:45 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Prathosh Satish , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Jason Gunthorpe , Shannon Nelson , Dave Jiang , Jonathan Cameron , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Michal Schmidt , Petr Oros Subject: [PATCH net-next v11 05/14] dpll: zl3073x: Protect operations requiring multiple register accesses Date: Mon, 16 Jun 2025 22:13:55 +0200 Message-ID: <20250616201404.1412341-6-ivecera@redhat.com> In-Reply-To: <20250616201404.1412341-1-ivecera@redhat.com> References: <20250616201404.1412341-1-ivecera@redhat.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Registers located on page 10 and above are called mailbox-type registers. Each page represents a mailbox and is used to read from and write to configuration of a specific object (DPLL, output, reference or synth). Each mailbox page contains a mask register, which selects an index of the target object to interact with and a semaphore register, which indicates the requested operation. The remaining registers within the page are latch registers, which are populated by the firmware during read operations or by the driver prior to write operations. Operations with these registers requires multiple register reads, writes and polls and all of them need to be done atomically. So add multiop_lock mutex to protect such operations and check the mutex is held by the caller when it's accessing registers from page 10 and above. Signed-off-by: Ivan Vecera --- drivers/dpll/zl3073x/core.c | 14 ++++++++++++++ drivers/dpll/zl3073x/core.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/drivers/dpll/zl3073x/core.c b/drivers/dpll/zl3073x/core.c index 3269cea8b4073..60344761545d8 100644 --- a/drivers/dpll/zl3073x/core.c +++ b/drivers/dpll/zl3073x/core.c @@ -122,6 +122,12 @@ EXPORT_SYMBOL_NS_GPL(zl3073x_regmap_config, "ZL3073X"); static bool zl3073x_check_reg(struct zl3073x_dev *zldev, unsigned int reg, size_t size) { + /* Check that multiop lock is held when accessing registers + * from page 10 and above. + */ + if (ZL_REG_PAGE(reg) >= 10) + lockdep_assert_held(&zldev->multiop_lock); + /* Check the index is in valid range for indexed register */ if (ZL_REG_OFFSET(reg) > ZL_REG_MAX_OFFSET(reg)) { dev_err(zldev->dev, "Index out of range for reg 0x%04lx\n", @@ -537,6 +543,14 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev, FIELD_GET(GENMASK(15, 8), cfg_ver), FIELD_GET(GENMASK(7, 0), cfg_ver)); + /* Initialize mutex for operations where multiple reads, writes + * and/or polls are required to be done atomically. + */ + rc = devm_mutex_init(zldev->dev, &zldev->multiop_lock); + if (rc) + return dev_err_probe(zldev->dev, rc, + "Failed to initialize mutex\n"); + /* Register the device as devlink device */ devlink = priv_to_devlink(zldev); devlink_register(devlink); diff --git a/drivers/dpll/zl3073x/core.h b/drivers/dpll/zl3073x/core.h index 75f68bc9a52ee..1a77a69f85a26 100644 --- a/drivers/dpll/zl3073x/core.h +++ b/drivers/dpll/zl3073x/core.h @@ -3,6 +3,7 @@ #ifndef _ZL3073X_H #define _ZL3073X_H +#include #include struct device; @@ -12,10 +13,12 @@ struct regmap; * struct zl3073x_dev - zl3073x device * @dev: pointer to device * @regmap: regmap to access device registers + * @multiop_lock: to serialize multiple register operations */ struct zl3073x_dev { struct device *dev; struct regmap *regmap; + struct mutex multiop_lock; }; enum zl3073x_chip_type { -- 2.49.0