Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3783733pxb; Tue, 17 Nov 2020 03:32:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzverwS0R6OF1DQOHv9mQ8ej4WBfz8h1dc7MO9BM1pTZNFxCBQz0MqGfXeqYnO2LWv6F3cG X-Received: by 2002:a17:906:c41:: with SMTP id t1mr18852456ejf.19.1605612728654; Tue, 17 Nov 2020 03:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605612728; cv=none; d=google.com; s=arc-20160816; b=eYVG3KiD3NkK6REmB8DcXM0Lr2+fzh/bxfwrVHdCYOS0cbCNl4hLaSoqSOLs9QCmxS GtgjuSdybC239uhpXTXkUcdqCRNyFBjqDkue66uz8Bqpjm19WNQi0ADY6CPrFCPl0/MG ljTRBggbHaQCrvVQtuxUr8afIA7HHsE0m2lA6WgB39QsfXxLa4LJ0Cf+QhnQhx/vjCp+ /2X8exPVHei//y+VGTrkl7BxISIKNVuL+9QVLHf5BuQOSf80rdE0P0mTsdadefcTL5jv r2Im1Yr9i45p3H8VF/yNn2qvr/9494Suw1D7KvciXUEhtRdJL5+8H/rxO86t1qUS9ewk HW6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=lFu6pIH/5NY9WbSSgP/nznLK8GRNc+ncPhr433Bq41I=; b=Pc5DeXhf2BUz6YqREBuSgAY0RnuYVFBIOH/F3gqthGuctTl8nkNHKtWotmDv3ik16n ngdmSQ9R4i1yOFitH8puO5wJbCdrROtrXOa97N0AEMSA73cKHaAdU1ZoOdHp04KdkDc6 yngIRkRrg1UE6n6SZXjW51gcZKtZuCS27cdRPWM6YtY33FW5f8NziGhvON4UPgKKDgGo 54UkeAvKVZFa3UxYG6SqJN43bxq5D9p5ShOR3VjZozFwRIAFTjqrKom/5qxF66f3GW9z XqULpC4YOxPCP2BwB+WNPlR+JVzSZqvCxWB2xZAKSXIV3h1B8frB9FnUi8pSyObvNNse MlBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c19si12839456ejz.274.2020.11.17.03.31.45; Tue, 17 Nov 2020 03:32:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbgKQL22 (ORCPT + 99 others); Tue, 17 Nov 2020 06:28:28 -0500 Received: from mail.baikalelectronics.com ([87.245.175.226]:42262 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgKQL22 (ORCPT ); Tue, 17 Nov 2020 06:28:28 -0500 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 3A926803071C; Tue, 17 Nov 2020 11:28:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3b7RSBy8AN_V; Tue, 17 Nov 2020 14:28:23 +0300 (MSK) Date: Tue, 17 Nov 2020 14:28:23 +0300 From: Serge Semin To: Andy Shevchenko CC: Serge Semin , Mark Brown , Alexey Malahov , Ramil Zaripov , Pavel Parkhomenko , linux-spi , Linux Kernel Mailing List Subject: Re: [RFC PATCH] spi: Take the SPI IO-mutex in the spi_setup() method Message-ID: <20201117112823.fwadsn5ld7ovjqun@mobilestation> References: <20201117094517.5654-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 17, 2020 at 12:56:44PM +0200, Andy Shevchenko wrote: > On Tue, Nov 17, 2020 at 11:45 AM Serge Semin > wrote: > > > > I've discovered that due to the recent commit 49d7d695ca4b ("spi: dw: > > Explicitly de-assert CS on SPI transfer completion") a concurrent usage of > > the spidev devices with different chip-selects causes the "SPI transfer > > timed out" error. > > I'll read this later... > > > + mutex_lock(&spi->controller->io_mutex); > > + > > if (spi->controller->setup) > > status = spi->controller->setup(spi); > > > > if (spi->controller->auto_runtime_pm && spi->controller->set_cs) { > > status = pm_runtime_get_sync(spi->controller->dev.parent); > > I didn't check what this lock is protecting, It is used to protect the SPI io operations. So it's locked only during the SPI memory operations and the SPI-message execution. That's the time when the core toggles the controller chip-selects by calling the spi_set_cs() method and the set_cs callback. > but have you checked all > PM runtime callbacks if they are not taking the lock. When you call PM > runtime functions with 'sync' it may include a lot of work, some of > which may sleep (not a problem for mutex) and may take arbitrary locks > (might be a deadlock in case of trying the same lock). Yeah, I understand that. Simple grepping hasn't showed anyone else but the SPI-core using it. So unless the controllers PM methods also call spi_setup() or request SPI-transfers, there shouldn't be a deadlock. Moreover as I can see from the __spi_pump_messages() method the IO-mutex is locked during the sync-suffixed PM-methods invocation. AFAICS locking io_mutex around the PM-methods here shouldn't cause problems. But of course testing it in various platforms/controllers is always welcome. -Sergey > > > if (status < 0) { > > + mutex_unlock(&spi->controller->io_mutex); > > pm_runtime_put_noidle(spi->controller->dev.parent); > > dev_err(&spi->controller->dev, "Failed to power device: %d\n", > > status); > > @@ -3354,6 +3357,8 @@ int spi_setup(struct spi_device *spi) > > spi_set_cs(spi, false); > > } > > > > + mutex_unlock(&spi->controller->io_mutex); > > + > > > -- > With Best Regards, > Andy Shevchenko