Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp269262rdb; Mon, 22 Jan 2024 03:47:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEw0n6W4zT47vveful6mkHW5I6kNyppYefuHxl5JhuXhgGtUOe0ZCvlzKI5qLMuzmEHzcEM X-Received: by 2002:a05:6808:b17:b0:3bd:3d83:9507 with SMTP id s23-20020a0568080b1700b003bd3d839507mr4502638oij.65.1705924063964; Mon, 22 Jan 2024 03:47:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705924063; cv=pass; d=google.com; s=arc-20160816; b=C6g19yuwT00OdqlEenTdcl1Zy7tVxqHG+bO+/q71OCob/w0L1SMnzS68HUT0hKQ9f1 yzFk3s4XtlA4+x8hSK1OKN7xYZNvu4z95KxWKgblOXqqUV/6VFAHxS4PpQBl+Yyx9zCz zWEq9rrCr69gEb/52N2GqAEVKk1YFDRoYRff46h0ZrlJlS7PFEqyIszZ+e7v6szc7ddz SsbB3r+Io86kgF+0MIb3ld0oivc0s2ILLwSCZMuBh/WmlEs5sqqss6pyNQEnn7tP/S81 oW0MwSjZ8GW6q4GhtACDjctkAgOpDVn0H1vhS430Df+THWPB9qs0x30FbchiE0AEoeWY Assw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=TfyLpP3d/MRU3A74X7vhNU0+jYV1Cj/jicCgovvMfTg=; fh=4LIu5opAwLV7NEWuWaesW8kxXXZagKTitwg1cEZexpE=; b=Dj7SaMgLgQI8Aikf5kljAZFafdYLeqVmq+lh3t7GKDuMq0Uxusv+dvWIYVY+Q6qo9F 5B5hvIP2gPpWGHS7UvijMqAwEsjaI/DCtH0ALTDRfEiahtqmtmotfoFUs+O3U6Nq0/HL ba/KTwZwqQp44FfuPbfyO3mAmKuyynDliz4R/LHpVlvIN3VNm5zS8xOHPk1jGvg0LGf3 z0WYmHewqLcdOkyzXPgcT5ihXsgdownJFEtTm3wfXlfNbLXfukQz2wEcX5e1Ox6Whp4s EWeVQVuGOxKxzOMOqTycSrfY7/UQLhMBa7tlPys851TzhhElqyZipT10JLQPsxi9bCb2 nTOg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-32948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32948-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f25-20020a37ad19000000b0078392d4cf6csi4882418qkm.234.2024.01.22.03.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:47:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-32948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32948-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E08FE1C23C4D for ; Mon, 22 Jan 2024 11:45:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08C1F3CF79; Mon, 22 Jan 2024 11:44:31 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (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 B60ED3BB2D; Mon, 22 Jan 2024 11:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705923870; cv=none; b=Xjk4nnVX2ZXwGjvX4AECHr2+Qae4LluQc+5To6GazjmWxePYhLOcjUaTI6ZoZqHMqQAs02K4Y2QH1fwMBq0H3dK2cc3s/pYM7vaXbtln8p/wQVMWeiCv6YpnaK/Pqoun5BDoSEj+FDLwVzt2T/QkwxyxjBf5gWW/D9URxyIGKdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705923870; c=relaxed/simple; bh=CxPWEItIqkP3rza59OPyafonJL7J+WNzKVFT4RdtkXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RCPfzATFjD7jzZu0iFqwxU3L6LqW1U6Ky7Xsare5ocgDjIwCKqqP8vKtEcwzyST0EpTshhliPFMPGBk+plJe5D/4GGfbn3apIPQeCFjqCnSSqjfAz7vPFJX5YTzD8ZRLjjzFxX4e+acZiL3D87BOakJ6maFZeT2YCIfxAHPKfnk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id 9756b4d4305953bb; Mon, 22 Jan 2024 12:44:24 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 086D6669540; Mon, 22 Jan 2024 12:44:24 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Ulf Hansson , Stanislaw Gruszka Subject: [PATCH v1 08/12] PM: sleep: stats: Use locking in dpm_save_failed_dev() Date: Mon, 22 Jan 2024 12:33:53 +0100 Message-ID: <3798847.kQq0lBPeGt@kreacher> In-Reply-To: <5760158.DvuYhMxLoT@kreacher> References: <5760158.DvuYhMxLoT@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekiedgfedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepgedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehsthgrnhhishhlrgifrdhgrhhushiikhgrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 From: Rafael J. Wysocki Because dpm_save_failed_dev() may be called simultaneously by multiple failing device PM functions, the state of the suspend_stats fields updated by it may become inconsistent. Prevent that from happening by using a lock in dpm_save_failed_dev(). Signed-off-by: Rafael J. Wysocki --- kernel/power/main.c | 5 +++++ 1 file changed, 5 insertions(+) Index: linux-pm/kernel/power/main.c =================================================================== --- linux-pm.orig/kernel/power/main.c +++ linux-pm/kernel/power/main.c @@ -323,13 +323,18 @@ struct suspend_stats { }; static struct suspend_stats suspend_stats; +static DEFINE_MUTEX(suspend_stats_lock); void dpm_save_failed_dev(const char *name) { + mutex_lock(&suspend_stats_lock); + strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev], name, sizeof(suspend_stats.failed_devs[0])); suspend_stats.last_failed_dev++; suspend_stats.last_failed_dev %= REC_FAILED_NUM; + + mutex_unlock(&suspend_stats_lock); } void dpm_save_failed_step(enum suspend_stat_step step)