Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2580639rdg; Mon, 16 Oct 2023 08:33:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAajDnk06J2FxGE3jeKgaI1HKRcb2UxhNGOGXkc64HuxVXJmE9NGRhsh44okPdCMgvkZx0 X-Received: by 2002:a05:6a20:1584:b0:155:2359:e28c with SMTP id h4-20020a056a20158400b001552359e28cmr34509032pzj.9.1697470383119; Mon, 16 Oct 2023 08:33:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697470383; cv=pass; d=google.com; s=arc-20160816; b=Z7yj7pl+/GTMmL9vSGAUZ2CShJtd+n9lCSUS/dTIkDbW5p9xGtNZg8mtAoE614Lwp2 Kg2QYpHxODBB/R4RROoC3J6RECP+04YFxSxaDKZH4FkRNuQEjadE4Dq3eyU6m0+3cC/A Sl/k+WCTCnO9wNzRNx6cCMHfIeS0wRM3tc992sz2/5KV1rrO7GzptitGyRAB4b6Q/pQf znPXsf6w+QBnNwTyAlHqfmxF3XauP969ipp6EvMPcr0gcPOJcKHxkebXowgdJEZ45y/E sKc4gkhbA1BfQhGLJ2S12pbInidTj+3GewY88aLDQNd+HNXkXlHYZo8popHNaQlBZwEb IhQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Xn4mPAvhPGdHiiCr3YwVziVD/SfIEV3x+7h8xcqcUzA=; fh=bn4KwJ7hiZC6iHD6ocv1YpB9R5Bd8J/ZarfJ7QImr28=; b=0+LJuXaBpJgyYKEyw9JH0cAWbGMRN+oO8o3eSjtsWW/3B/DJ0m/rl3tao5RBnDvVGJ qjf4kmsoJeVinUc3sqDoRXDD64QPVkIo2EhB4CHIJXTLgvAb+4/pW8bZpdAtnL9kI++x p4dLmsa2TlHZEpJbZxTXnuiE8kZowilsDx6iYWIsLY1YNpBqFmyf61fybr1V/3I8VQ2Z e+7op0GBraAJtFNtv2Kn6K5cHK9rTLh7T64DjROIxuj6k0TwqvFS/SBRXRHFrZVQcVHX yaY1kzxoNsXZxqG2JRKEH4F5k0Ef6H+fqyWuiC22n6RqRyBLxHDZ/q+ZDDrd3MHaHr5C uofw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=p1NSuLfZ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s194-20020a6377cb000000b00578b6e2f462si6910594pgc.351.2023.10.16.08.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 08:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=p1NSuLfZ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0B3B7803047E; Mon, 16 Oct 2023 08:33:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233564AbjJPPcx (ORCPT + 99 others); Mon, 16 Oct 2023 11:32:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233425AbjJPPcv (ORCPT ); Mon, 16 Oct 2023 11:32:51 -0400 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2073.outbound.protection.outlook.com [40.107.104.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4941ED9 for ; Mon, 16 Oct 2023 08:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mN4dSZsYVnxL3yEn+1Kji+In1KAgNTJsvRx+MMC5xBxx+wn4esucUjpSmlRqd72uDWtf2JsuWZESxFVYqnbdifKjIL0Ov77sM7zC1SqeruP/814FbwE+x3t2YhEfccTy1u99gJZJqjXwt3R3lWMR2ArJVWjWlWM2R3pmWn799B/F5xxDSZlAmrmsuG2KHcXa2iUSBlXqq3xdPgnZ/Ag9eY5EvGsAEQepYrWFGsl1NX/wYSSNewpDfZPvk6Y+49aBGpWHgm9CZCleFTJeIwY7bLHBlTGezDVXXsFYac4ydV1/xCriFSqUpsjMUewhlYTX8moONXST5sXNRFrdA5BZ6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Xn4mPAvhPGdHiiCr3YwVziVD/SfIEV3x+7h8xcqcUzA=; b=QOyDe1gCVqTaCwcsFgHJNVKH1/gNWX3SdhWoOzzJg24DodPKd1EcPSKn1eXqw1TqkZAa/D1oChXav7RyXSu0Cq0P28KkkRDoOmGiAWa4oFBjPjf3neEEiVeHsdEmw2JIR3voBNZCdAk3tBxEboDcUclxiJEF7MLpfeNuV4LP03rQwM/UPsYR/EVhhe83UE5L5pzbFQ0GmicwcHMJBGrxgYZDY75PCPO9IvTF7cV/9Frjlay6RHE1W31Vjho8VlLZfJS3GjuT/x9RYj0ntdI0THBaneC11n5nUVWxDfJB/n3gPbFZd4Tvo0GC2ormHANTK13h2e3GUaBQT5B67H+/cQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xn4mPAvhPGdHiiCr3YwVziVD/SfIEV3x+7h8xcqcUzA=; b=p1NSuLfZ6oQTyKP3Z5Fm/Hv+mRMq1tb4vLUeksDExBeNen66yxM/v7Qx+dz7YiBMUb93WeNiVGuk+ZABBpe8Yw/LCF0DDzkOPVqE0m5kBomFdePjIvMEM3bStJcs9pcxJ/EpIi/ozRQptEGT/nwx+/hWy+QpF5bJ0ubQ4ZuWiyo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by AS8PR04MB7592.eurprd04.prod.outlook.com (2603:10a6:20b:23f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Mon, 16 Oct 2023 15:32:48 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::1774:e25f:f99:aca2]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::1774:e25f:f99:aca2%4]) with mapi id 15.20.6886.034; Mon, 16 Oct 2023 15:32:48 +0000 From: Frank Li To: miquel.raynal@bootlin.com, conor.culhane@silvaco.com, alexandre.belloni@bootlin.com, joe@perches.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev Subject: [PATCH 1/6] i3c: master: svc: fix race condition in ibi work thread Date: Mon, 16 Oct 2023 11:32:27 -0400 Message-Id: <20231016153232.2851095-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016153232.2851095-1-Frank.Li@nxp.com> References: <20231016153232.2851095-1-Frank.Li@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0P220CA0029.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::13) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB7592:EE_ X-MS-Office365-Filtering-Correlation-Id: 26d73f0e-e4e4-4fa2-cd0e-08dbce5d26b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AABSY/doIXSuIx+laH/eQ1V61vf/gnpQIoxEa/IbMyvRDq+iu/X9s+BwH1Un+PGxXii0CYzdZRSAq62jIjfWGvSbupgD1gx+SKmeC4tZTWaGS/wkSZlcR/Rcpqpl9Kd+25J+Vq48dnupXMV4UB1PqjBzoI7nb8tbbSPK7wRCIW2GVvW9imBGMgt6dBwTEQGZ6ZMVcADTqSz2bBPBbZpD38tsF4X2HBTrT5T1RMbrTFX6MBWxXNlwgnKKYhWHiCCIqgHvPcxHhTYBSWEac4aMipcVwavtYQ4pT1B5CqN4oZwSYVQvABKpz33cRXGRA3vvpgqPsOsRc4DMtT79td0t5l5UExLhC4tkFOeRCvgP4Rkc12Kjq6Io5U0ZwH4bs9hUhwq3bUwFOxsc94tWPiM/GxFNxMU2b6zvEwLE+jiW5xf3SSn6Y1ssgoH7TnVsbUyCtlxDBsaYC/+1rjmUP52qJqKWJxgKoCQHjdFkOODmPqBb5ObDVdsimjbGRiYRkpfQEWWN59vY6vWVhFUtWDs4Sfl5acmb0CrLjFZ7QzY6n/rvuYvp9rAcb0MLZxmRZJ155qu0QY3hrbnGszfQnLoWQjQoUpRVsvcpQq8MM45ULb8tZIhw+GNqNDakLOjz4jQd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(136003)(376002)(366004)(39860400002)(396003)(230922051799003)(451199024)(64100799003)(1800799009)(186009)(6486002)(38350700005)(36756003)(38100700002)(83380400001)(6666004)(6512007)(26005)(6506007)(316002)(66946007)(66556008)(66476007)(478600001)(1076003)(2616005)(52116002)(2906002)(41300700001)(86362001)(5660300002)(8936002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6Hb7fQ/bCrQpNyRFy3eS7Ipvehe6iM90xZtvB2BiY6/nnLDfLd4E245GcMLA?= =?us-ascii?Q?0qxmkuPZHSQ66klwvF6IWLUOfvpzLz1wXLD6zla5mrK+kCpYi1VglYK7ZHbR?= =?us-ascii?Q?N8i1kCVS+mxk/dOdKb3Su1sKr9EZWzkEYaDl4SlyBIKjn86fYj7kjMzJvxdv?= =?us-ascii?Q?hzc0xHqrB1+8jhFl3s47ObAGHvu5gscfiisTmzNix6q96OmfvmvPlCGKMWK8?= =?us-ascii?Q?Xa1J9qqTU3nPrvw4vkvV2LfZKY6px14U6LI7Zf+M/u9vlhp+0RaRFn9P2KIo?= =?us-ascii?Q?+BrnBKVdkSObqLkqIQaa5miJLLTkuJdDHTvzngdwnePlS789AM776lYRR5r9?= =?us-ascii?Q?/zZ3RwUtiwJlHyA0QicHKj2H0891uM96lC6IFT3lUy4rafCJ4+a0MR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AdhQRnbJUbhPFoNiLWWuOWMaK4e1491HQHD?= =?us-ascii?Q?Vc90JskRm3iKLNpTBnIjAUSUaFyuUqgpEK5LBCKIzuCrxieHLqxmzUNWix6u?= =?us-ascii?Q?BW/cspn+C0sh0NEljmh5UOcm7afY/hwv05NJmYbg2TeSOVb6rLkKYOZYYnWN?= =?us-ascii?Q?QYXPy0OVXqpmhJuwJ0SMqMCisWfXhCwYBbXPlEAWZRDe/t/8ElftDQoeKrW2?= =?us-ascii?Q?tjf/TPMCeqqIfQifbRPCL7FHYe1rKSpaE9vIFfB0wBUoTdARF1SeMK9B1rAP?= =?us-ascii?Q?90h2EY+uHb3g18IQ9BI=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26d73f0e-e4e4-4fa2-cd0e-08dbce5d26b8 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 15:32:48.1604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: q3XSOQmhczwsxHwqXMiJuWtIEs8HCTFdcCACjloCZHpkxHGjXMzkX/x9Ltzt2bUySyIzJPRJe/hun17mjCEgEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7592 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 08:33:02 -0700 (PDT) The ibi work thread operates asynchronously with other transfers, such as svc_i3c_master_priv_xfers(). Introduces mutex protection to ensure the completion of the entire i3c/i2c transaction. Fixes: dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver") Cc: stable@vger.kernel.org Signed-off-by: Frank Li --- drivers/i3c/master/svc-i3c-master.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index c308e22f0ac5..ebdb3ea1af9d 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -202,6 +202,7 @@ struct svc_i3c_master { /* Prevent races within IBI handlers */ spinlock_t lock; } ibi; + struct mutex lock; }; /** @@ -383,6 +384,7 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) u32 status, val; int ret; + mutex_lock(&master->lock); /* Acknowledge the incoming interrupt with the AUTOIBI mechanism */ writel(SVC_I3C_MCTRL_REQUEST_AUTO_IBI | SVC_I3C_MCTRL_IBIRESP_AUTO, @@ -459,6 +461,7 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) reenable_ibis: svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); + mutex_unlock(&master->lock); } static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id) @@ -1203,9 +1206,11 @@ static int svc_i3c_master_send_bdcast_ccc_cmd(struct svc_i3c_master *master, cmd->read_len = 0; cmd->continued = false; + mutex_lock(&master->lock); svc_i3c_master_enqueue_xfer(master, xfer); if (!wait_for_completion_timeout(&xfer->comp, msecs_to_jiffies(1000))) svc_i3c_master_dequeue_xfer(master, xfer); + mutex_unlock(&master->lock); ret = xfer->ret; kfree(buf); @@ -1249,9 +1254,11 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, cmd->read_len = read_len; cmd->continued = false; + mutex_lock(&master->lock); svc_i3c_master_enqueue_xfer(master, xfer); if (!wait_for_completion_timeout(&xfer->comp, msecs_to_jiffies(1000))) svc_i3c_master_dequeue_xfer(master, xfer); + mutex_unlock(&master->lock); if (cmd->read_len != xfer_len) ccc->dests[0].payload.len = cmd->read_len; @@ -1308,9 +1315,11 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, cmd->continued = (i + 1) < nxfers; } + mutex_lock(&master->lock); svc_i3c_master_enqueue_xfer(master, xfer); if (!wait_for_completion_timeout(&xfer->comp, msecs_to_jiffies(1000))) svc_i3c_master_dequeue_xfer(master, xfer); + mutex_unlock(&master->lock); ret = xfer->ret; svc_i3c_master_free_xfer(xfer); @@ -1346,9 +1355,11 @@ static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev, cmd->continued = (i + 1 < nxfers); } + mutex_lock(&master->lock); svc_i3c_master_enqueue_xfer(master, xfer); if (!wait_for_completion_timeout(&xfer->comp, msecs_to_jiffies(1000))) svc_i3c_master_dequeue_xfer(master, xfer); + mutex_unlock(&master->lock); ret = xfer->ret; svc_i3c_master_free_xfer(xfer); @@ -1539,6 +1550,8 @@ static int svc_i3c_master_probe(struct platform_device *pdev) INIT_WORK(&master->hj_work, svc_i3c_master_hj_work); INIT_WORK(&master->ibi_work, svc_i3c_master_ibi_work); + mutex_init(&master->lock); + ret = devm_request_irq(dev, master->irq, svc_i3c_master_irq_handler, IRQF_NO_SUSPEND, "svc-i3c-irq", master); if (ret) -- 2.34.1