From patchwork Sat Nov 30 23:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13889333 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8223FD7361B for ; Sat, 30 Nov 2024 23:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dVandmEjl29fQ2g5/xmh15AXnmnKHqPEzmZef3xU4Eo=; b=ulchiC0Q07ZQm0u97/q4ls9dee YKIsPgH/SJ/LbJiZ3RKxXyGfi1HYD4t664tKpDX/KfVEQ+pB8t36NESqPPqk9GoPG+DB68rJAObVU X27YCm32Mlze0FUmpa7K5rxfkmVWmoX38ouEmZPh7Kdl9Uka+qJkpZP7wrlAcLvVQ6ozNzVdPdUqw oS+rsRfjWKi/YpBsfnUqtDTLpl5mbtAhgzxCpd4bOFa8cnKxBF7hmjywMxyLgwxlztGPn8GYz/lku UGN1vMPuNJTLpMjevfrAz8N+zSk83C54ILcaQjRSHPge20z9JsFznnl+jN9sMoXnANrDAIZx5Uxgd 8eWmPERg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tHXLB-00000002lVq-1cAE; Sat, 30 Nov 2024 23:57:33 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tHXJF-00000002kmC-314X for linux-arm-kernel@lists.infradead.org; Sat, 30 Nov 2024 23:55:34 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2ffdbc0c103so42653691fa.3 for ; Sat, 30 Nov 2024 15:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733010932; x=1733615732; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=dVandmEjl29fQ2g5/xmh15AXnmnKHqPEzmZef3xU4Eo=; b=xRMFzmkZCAf4/C8/+lb84YdOYCBZTXSVePKFc8Rrn76DLndUv68kKUcNATTkRAZqiG zGqwAHlR/g8zSJLGv48wURJAEZDAd8sSz7AV/PtI27XXPTLLTjUX5dcMNPrW9vIyur+A /Ej+tgbu1tHsdbVKKgFRItG2Zp486f6wplKau4gp5wBv1qT+HtmrHXlpS18dVEu+jyB3 /zrEpU1O3ED0WQmaVXD+4XJXN7euShrcuW8MsopSmyfKK8TwkF5qXp5sYtYx+aqzbAB7 YW+gl5A+NlZLbC8yMxwO8bTD1NkeP9kBOu6g+l6HXu1uJoXjHn465516UZLCfJv41DOX pxJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733010932; x=1733615732; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dVandmEjl29fQ2g5/xmh15AXnmnKHqPEzmZef3xU4Eo=; b=h1vGET8MTOsZRv5S/1Xwgl+qcfFmRoAVlZ1AvhE4gg7eZ5lN/IZBJ4aU8L9U40CRhy 4OF7g1AcMmhpEYOoR9zVxgKxV17zmpD++Izg7zz4LUhsWN3xZpz9zYr2KAGqVcqJOoUK m0fDgaO1Np78yKT4rPF5vz7dh76YCiLstQwye2wz6I6Jb5Gt9vXXiSzZB8XC9J46J05j QIypsPbblRdsNvdIPRg7ZgQic543z/IhYkCZgsQGne8+RNy6ebf0O3nXkv3n+aVj2xyz 0MYcA3d+2cgat7TBZaQrSypxUHtdUkkgHwJxLtJuLsRF6eZZvv70e8YRqDEJXyyVSrj4 OUrw== X-Forwarded-Encrypted: i=1; AJvYcCXwwIeKHd+OEy/QPv2Vp+cU1jpwzmiOUIIxvAasplTz0C1VYqjk7DYsMqROYf8VZTop0dNJTC5wF62TgzDG+41C@lists.infradead.org X-Gm-Message-State: AOJu0YyydsUIgn/e2dwdAeyURoymobWS1GYBR+t+IS04/Fw20K/A4DYZ 8WfPBx82pu4frQnmsZis1L1xZjrIi5Z3QnlP524KdXfawTyRbDUujyI6XOkFuZI= X-Gm-Gg: ASbGnctsmdDycGl57rBTS7Wok0cInBDAHN5h5151crNOWBpZ3LkiU59aeWc/kiwegVY rRss5XPvLEJ3xJZNX8HOtvS+OHVFeKZvPZklAig/iP4rOujOcIbXiVsgsU/g5D+G02Y2ImHBsqg uPba5C1FBIm13uqyFwF7m6qYOLtDmxboUA5wxljPhFlE0suk5reytRQP7nlHWyIbMqBJXhGz2OE bsEUD3cpLK5MffmSfH6t5jqoC/iUq1q0QcICuOKy4OimF70nQv2H/T1pQ== X-Google-Smtp-Source: AGHT+IFxIGZTCl2+FV0phQXK3nZn1ZVOLyIwEd2xBNXTWsJOfxd6ufDjErhJ/Bt/Wlo7yiHe3hXNJg== X-Received: by 2002:a05:6512:2316:b0:53d:dc3c:2595 with SMTP id 2adb3069b0e04-53df010b113mr13994153e87.44.1733010931778; Sat, 30 Nov 2024 15:55:31 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53df649647dsm900706e87.195.2024.11.30.15.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2024 15:55:30 -0800 (PST) From: Dmitry Baryshkov Date: Sun, 01 Dec 2024 01:55:18 +0200 Subject: [PATCH 01/10] drm/connector: add mutex to protect ELD from concurrent access MIME-Version: 1.0 Message-Id: <20241201-drm-connector-eld-mutex-v1-1-ba56a6545c03@linaro.org> References: <20241201-drm-connector-eld-mutex-v1-0-ba56a6545c03@linaro.org> In-Reply-To: <20241201-drm-connector-eld-mutex-v1-0-ba56a6545c03@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Harry Wentland , Leo Li , Rodrigo Siqueira , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , Xinhui Pan , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Phong LE , Inki Dae , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Alim Akhtar , Jani Nikula , Rodrigo Vivi , Joonas Lahtinen , Tvrtko Ursulin , Rob Clark , Abhinav Kumar , Sean Paul , Marijn Suijten , Alain Volmat , Raphael Gallais-Pou , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2918; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=dRMlgzQ8g4adZeqAK73JToeVmDq3hWsW88+VTTxsaX4=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ7r30refv/TKFDs8Y2WIFPVQT4z9p9Ztb63x/CrnBwOpu 9X8J3Z0MhqzMDByMciKKbL4FLRMjdmUHPZhx9R6mEGsTCBTGLg4BWAiMjXs/4xDs4XudBZPNPqn kCpyM6RdQOWzeLBy8ZPpGxftDLy97qNmD6N3i6urZu4ODovJnRfad3DHVKg/ur1et6Vl+2EZu0e yxsFXpq526Q8JCdBwub7SsPv3+VQt9zlV4VNuM1ZNmV8c+7DodCpXyU7/vuWHrAQTr0qLTuNJfi 7+yf7LHPf/M7MW/7y1/o8Gc8MR93DzonOcBczZHvd3Lw7grt9wxPWA+kK1QFnfw27Ndcwznj48a nBgd8lz5tieNl+W3a6z98Q22chfUj3lPm/rWpttiy+c9vhvfVDCs6/vap3TuncOXcc5NpTp6qxe uz/kevSCnWG2aS7lyg2/S68xCj6sOHHJgUnIzND4q0scAA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241130_155533_761776_49DB1412 X-CRM114-Status: GOOD ( 16.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The connector->eld is accessed by the .get_eld() callback. This access can collide with the drm_edid_to_eld() updating the data at the same time. Add drm_connector.eld_mutex to protect the data from concurrenct access. Individual drivers are not updated (to reduce possible issues while applying the patch), maintainers are to find a best suitable way to lock that mutex while accessing the ELD data. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/drm_connector.c | 1 + drivers/gpu/drm/drm_edid.c | 4 ++++ include/drm/drm_connector.h | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index fc35f47e2849ed6786d6223ac9c69e1c359fc648..bbdaaf7022b62d84594a29f1b60144920903a99a 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -277,6 +277,7 @@ static int __drm_connector_init(struct drm_device *dev, INIT_LIST_HEAD(&connector->probed_modes); INIT_LIST_HEAD(&connector->modes); mutex_init(&connector->mutex); + mutex_init(&connector->eld_mutex); mutex_init(&connector->edid_override_mutex); mutex_init(&connector->hdmi.infoframes.lock); connector->edid_blob_ptr = NULL; diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 855beafb76ffbecf5c08d58e2f54bfb76f30b930..f0ca77bd42fd518d505d0db78557e0c8d83efb29 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -5657,6 +5657,8 @@ static void drm_edid_to_eld(struct drm_connector *connector, if (!drm_edid) return; + mutex_lock(&connector->eld_mutex); + mnl = get_monitor_name(drm_edid, &eld[DRM_ELD_MONITOR_NAME_STRING]); drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] ELD monitor %s\n", connector->base.id, connector->name, @@ -5717,6 +5719,8 @@ static void drm_edid_to_eld(struct drm_connector *connector, drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] ELD size %d, SAD count %d\n", connector->base.id, connector->name, drm_eld_size(eld), total_sad_count); + + mutex_unlock(&connector->eld_mutex); } static int _drm_edid_to_sad(const struct drm_edid *drm_edid, diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index e3fa43291f449d70f3b92a00985336c4f2237bc6..1e2b25e204cb523d61d30f5409faa059bf2b86eb 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -2001,8 +2001,11 @@ struct drm_connector { struct drm_encoder *encoder; #define MAX_ELD_BYTES 128 - /** @eld: EDID-like data, if present */ + /** @eld: EDID-like data, if present, protected by @eld_mutex */ uint8_t eld[MAX_ELD_BYTES]; + /** @eld_mutex: protection for concurrenct access to @eld */ + struct mutex eld_mutex; + /** @latency_present: AV delay info from ELD, if found */ bool latency_present[2]; /**