From patchwork Mon Dec 9 05:36:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jackson.lee" X-Patchwork-Id: 13898937 Received: from SLXP216CU001.outbound.protection.outlook.com (mail-koreacentralazon11021102.outbound.protection.outlook.com [40.107.42.102]) (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 A55CB1C0DED; Mon, 9 Dec 2024 05:37:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.42.102 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733722630; cv=fail; b=ey5S0HjYIDkEyiUvSnzIJOnp7t83h30CrgsetNi6OgunDeMty+O4wpu248w6VDycXGt5mmcPjQYDOAOVyUOmIoz9/FKvHj0PbwuNQ63qCAGUwoRfRhWHGBueFOx2auxeq+vp78NJi1r4yINyO546EtcnXC2nbY1TJRdsHKb7leU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733722630; c=relaxed/simple; bh=yvEX9kLTXiGl1IHcoffjzsUsLxKTj7HHrndozi0qKO0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=q0MMwGjdI3sS/K6nN6NaiFK1lf+TlKipcyaqGiXo+T6B9ZmMci3rgSactqNiOreowtuaajhVXjnvDjkKOvMKAwCvN7TmHfW+OipAEN+xwXWBY1Mhtt8FEjoIhrBaNqEJnFuiakXt7Rxk54zSOEC3dI4QwxWTjqZSKv4ISKiR+k8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com; spf=fail smtp.mailfrom=chipsnmedia.com; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b=URE9/W0i; arc=fail smtp.client-ip=40.107.42.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=chipsnmedia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chipsnmedia.com header.i=@chipsnmedia.com header.b="URE9/W0i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vgdZYchqYRUDtRzWfiEcCuNnubC4dVOEiZ3UhlBRvubntisdAQqmGC8NrsvRVVYqzxRFNR/fTUBMcDr6ne3wH5hzvFCZHodvW+pr/U97U/HzWO9p4f+PFKO3JyAcRHeA5/1U+8IoziulUFot9tQeyBeb3mvFfCiS/XSeT72EHdHIi46fCDKOScKI4bD8Ikyn9XkltmTBZmKQa09f2q5oBGc/SgWB2gUPrtJ29eWTbFSjTN1nS1JvrPFZGs/Z/ShzZXT3OjGOgyHtWemcayk+GCVAsLGY0N9oWaegHus0P0qj/9D5QtbqD9vrOM8g3sNF9lK9HCYd64B6VbxKPr+xJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N86sxHpu0ZmI+36m85EhEa8AuGXjwCSEGGlTjuc7HhI=; b=l5oPPx/1EiiRm+FX6YdtBLdaljDutrVtFIXvKuOtNmRiVJ9IhODDJxFuwfdS0TsZJqZ+jDQLUwjG3dloIsrBMnMvcQA2mLekv+lWa7eAZxu3FRQmqOiBr6cqtSNcNGZ5FoRLb/0XBHPmuMDA42PPO8JL4LPbUQKWnlQIL/auOOT4IoR4o3hTmoVHbLNPRkIHgL3vb2MA0mwSUSMLpGv5LS6nbWXWNgzT+EfE2eUa7lys4ez4K/1ii+szuLJcTwrgzIwwIrcf6CAMhoMTYk3z/n4WPFZ4BqosuWZLqYrphhh+8kK/id56Bxc+bTgw988wj/M1d8rLOSLvjcmcXFJpFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=chipsnmedia.com; dmarc=pass action=none header.from=chipsnmedia.com; dkim=pass header.d=chipsnmedia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chipsnmedia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N86sxHpu0ZmI+36m85EhEa8AuGXjwCSEGGlTjuc7HhI=; b=URE9/W0iee+GX5wv/TGx1De5JVpBoPytsMEVNiBfU8n4fDrgnw6tC3xPYIgsT741S6SEXVIDmCBOMHQFGDSYQZ6v68eyfF0N/0AqPNITJEXdSzH0VMBBJhN6r4AVxGLMvt8EdT5CC32QJ+PngPfdqmVgybgN2YPGsos3hGLogCQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=chipsnmedia.com; Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) by SE2P216MB1966.KORP216.PROD.OUTLOOK.COM (2603:1096:101:f9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 05:37:04 +0000 Received: from SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b]) by SE1P216MB1303.KORP216.PROD.OUTLOOK.COM ([fe80::b711:5ab1:b5a4:d01b%6]) with mapi id 15.20.8230.016; Mon, 9 Dec 2024 05:37:04 +0000 From: "Jackson.lee" To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, sebastian.fricke@collabora.com, nicolas.dufresne@collabora.com, bob.beckett@collabora.com, dafna.hirschfeld@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, jackson.lee@chipsnmedia.com, lafley.kim@chipsnmedia.com, b-brnich@ti.com, hverkuil@xs4all.nl, nas.chung@chipsnmedia.com Subject: [PATCH v1 2/5] media: chips-media: wave5: Avoid race condition for interrupt handling Date: Mon, 9 Dec 2024 14:36:51 +0900 Message-Id: <20241209053654.52-3-jackson.lee@chipsnmedia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241209053654.52-1-jackson.lee@chipsnmedia.com> References: <20241209053654.52-1-jackson.lee@chipsnmedia.com> X-ClientProxiedBy: SL2P216CA0219.KORP216.PROD.OUTLOOK.COM (2603:1096:101:18::18) To SE1P216MB1303.KORP216.PROD.OUTLOOK.COM (2603:1096:101:15::5) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SE1P216MB1303:EE_|SE2P216MB1966:EE_ X-MS-Office365-Filtering-Correlation-Id: 16c82ca1-95f2-4267-6521-08dd18138383 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|7416014|1800799024|376014|38350700014; X-Microsoft-Antispam-Message-Info: n2HB05KSTDOk25Wln7wgVTs/59Mvz8JISIDRDfyxhcNPFDYTfHroYT7rMLktmwL/P+qwkncm0RK1olYbP+gFhVnE8NmKymFSKZ3COsIpUSdHs6KcxlY1Cq12xBfIAnDI96Q6cpEforJb2ZaknYh3cEe+Q9iBnfzx1Ra3WKXjzH5ewIgPTXd+yn9cyTnVXWT63fqoa6/6qnyBD6SpABHoOen2RKpu3aonmiXeWKmGkDI6K01M+lzqPHHLMsVogFnGXMoMoR+sq4avV9pQzZc58G4FpVtK8TJqg5OoHYeh+rmISV/N6i3Ngo2H+YNw51pCne/DfowaIFKB+F4LRHJ4Krl1dCoOPl0O2nESsWaMNXE7iFzz0eIuok2wSjIp8Q00ihz0xyX5NZzFKSSJYCwMcfOxBt5uYNhmGp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ORP216.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(1800799024)(376014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QvWvyDF41gcasiVTQHPNWPZju2bUGATm4jVBNMFKdPCaidaXCnL3k1tzZorp7pmlBSFX0can1MjX+1s8xQrkI0aAOnoHs/K471yiDP9DkY9AnDcIxsrRhLzW2wzfYr/hN6sGL/gzaG3PlTeKdBwxGiOIokFwmUduIVbiaX94ddZDWeIWlXcdlPbIOEk8RZwe5PIjj96eJQNCcP5BT/OTI8NMWO/O97ZuycTsYyNkDi1+OCTAZh2Qq3I5ieZvU/BHbqDpHDn1CDle/G8E2XmGGfIgr3dtjOC4YxdF9JnKwBzcXA/we72TdROL2zborVaU24nTVQE5bHeOTafx6iBT1kAGnzgmiMKzEOpzIinISfXS/0d3f/5eO5nkmIgOF3OQq7zMokVRyMC5BXp04nU+YF/BhjGDxib2vG9rRuUuXPvCcsaC7xdAFjbxZxfDnnnSLSShgjMPKd4Ot6bsfCF2duTwjbr4LzA0L34OhBEMv9o0yTciKh12TrWER1iYEn3/DrBqnKnMLcf2/u4I+3YgXZUQHhMKcyb5BNuKYuANk8/7pMcaAAl1kF1bCqRrPQ6QtxlV2ql5ZDAvcuqYgrsyxRQ0hdfMHm+kXM1l+YX+YOJl8jOLVBwxHb/MN4oyMFEYvWXjnuztRFbrf7iG4HL1yJHXkYcWSLBuD4z1VfgVppR9LdThamRq2pOIHwLED7isqI3PtyB97ghbV7FHn0HWAJe+x1gtuSRcoxoyQc/AMqZlkmBPFn3W32ZdwXvMS2N+Mp20z9WlYUNrtLtTWLFc4bo/VqZLwXnz0LgSHAOjjQWHLQrhSYi2KP/Idss4CIYlXX9Ymwyb3zWekJnIHBCORyQL16R/CoQ8/YP0ZaDKKeWD/BwEgoCv4ASz+el5Jq5fCV0zMKU9SFOHOyStBm4AqBTDkArur1C0/ZfcG+ZSjvKtLo7oT0mSOIcJhgshNbN/h+ZnltFApzYaZ1+yK80hAfxr6a0wbLRdBfnJpEYSKU0sZIadzmW2ragtf02bAG+vIqu7u+GHpw1ixELyyIowu8ff4ISxf934qqiktC8yuTDWBGiGCaRa6yJwtGv7lqPV7e/Vqrx4q658jpdRCUiZ72AWKaHYBraMjddSgYLmDYxFMyrorJrWY94HBlsjdAuXTuQXRwpI7WTofSXzkNOHnU6CeZ9WHTsjGUvCbuRE4lWViummy3fUDyIdwWScIBPgYPoL5NhUx0SVKvRZ/1BESYBDk46SDtjcrSCm3zA2b+tiCD36diUCn9nzyUUMdUNHNKr89frd6MYqK7VWnJy1K1AwyIEfONdDQck1ZxD4CnSVmBSfBhv4SX1YdnNpNnDTl6GVyosCPUWbC8Lseavy6gF1qGYz+nMMq/oefn4iQX7f9PnaStXp9V6KU75BOxOdzqk30ae2BCtPIBqe+Z8h3zEuEXv6lOCpc1rnYT7Ng1BW5oxTVaDeGn0cwjhJ58Ds4qKCclyJ4Cg40mAt3NttWs3RtsBJ8Oc9YJP6hmaZ059Wty5ia2kuspaGisnd5iiUVorDgkNGAr9ts48T4TkYWOw6xj14sJO7cISk5bRgNt0b4YWnIADGCQPvS8UgaNUo3XfXb32/gaF33OsSUh3WUw== X-OriginatorOrg: chipsnmedia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 16c82ca1-95f2-4267-6521-08dd18138383 X-MS-Exchange-CrossTenant-AuthSource: SE1P216MB1303.KORP216.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 05:37:04.7267 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4d70c8e9-142b-4389-b7f2-fa8a3c68c467 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xJajTe0GZle/8L8wcplqkZkkrf9oiu/IUU8HfExRPvzdZOxKGwbCwtG/5RFwR+9RaZfWkWUUVbX2aE11ha0FobYzcJb2HMe9SVjUDAveMGQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SE2P216MB1966 In case of multi instance, interrupts can occurr for other instances as soon as interrupt is cleared. If driver reads the instance_info after clearing the interrupt, it is not guaranteed that the instance_info is valid for the current interrupt. Read the instance_info register for each interrupt before clearing the interrupt. Signed-off-by: Jackson.lee Signed-off-by: Nas Chung Reviewed-by: Nicolas Dufresne --- drivers/media/platform/chips-media/wave5/wave5-vpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c index 6b294a2d6717..63a607d10433 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c @@ -55,12 +55,12 @@ static void wave5_vpu_handle_irq(void *dev_id) struct vpu_device *dev = dev_id; irq_reason = wave5_vdi_read_register(dev, W5_VPU_VINT_REASON); + seq_done = wave5_vdi_read_register(dev, W5_RET_SEQ_DONE_INSTANCE_INFO); + cmd_done = wave5_vdi_read_register(dev, W5_RET_QUEUE_CMD_DONE_INST); wave5_vdi_write_register(dev, W5_VPU_VINT_REASON_CLR, irq_reason); wave5_vdi_write_register(dev, W5_VPU_VINT_CLEAR, 0x1); list_for_each_entry(inst, &dev->instances, list) { - seq_done = wave5_vdi_read_register(dev, W5_RET_SEQ_DONE_INSTANCE_INFO); - cmd_done = wave5_vdi_read_register(dev, W5_RET_QUEUE_CMD_DONE_INST); if (irq_reason & BIT(INT_WAVE5_INIT_SEQ) || irq_reason & BIT(INT_WAVE5_ENC_SET_PARAM)) {