Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4448476imw; Tue, 19 Jul 2022 06:51:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t3t9rynQTH/yT38l9LRJ4+98hewyTRNkozxhzODRgPsn2P93CjSk9dFmsP0z4y/vAalQuO X-Received: by 2002:a05:6402:510e:b0:43a:c671:7cd0 with SMTP id m14-20020a056402510e00b0043ac6717cd0mr44242857edd.103.1658238686609; Tue, 19 Jul 2022 06:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238686; cv=none; d=google.com; s=arc-20160816; b=Z/+d4TZsRGpFHgayBUHtZ2WCDfe9zsNpe4eAfxTUTm/uYLUTqqmC16Uy4ZVBztUXQt 3rw+gH+1XqWgjvmfCthLoLA7NfkJW6CCfMrVBboq5arLPI2vTJaV5N2kJF6WSzc9jJqg VZIl848l3+Yk0QqO4+5L+nLEx9hp5AHHdXA60qgp3wsNuIL9etadO/N3zqhzE8tilCgl wP53Wk9nxCeonpB8sG1NYDqNvB8WApE/m1NUFoz/F0Wzy+muCG4MovaKJcxaYUtwiIY1 c7u6hych2HeHhT8HhXs30H6ESa1BS1ykyErG5eTiWvi++ToNQWvvxLVi8bMf8dJJhtDE h74w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7ADaVue+OlijsLO8H7/41BnS2cXqFGPAC1LE4njJ1G4=; b=HPK4OlXn9Ev5s9kDLtGI+/2J8n05ul5iqhw0Z6kYYo39tA/4jNLuFgg/dc+5qWM8H8 FyzneiAXeKxnGRa9ZJFc/L8wAVARCpPUxU7FZnqiVL6Qji5JSqG6EHyfBlKM9hi2qx3c xMyqqOg33yarhnkM/ZL134Q5tjDUje6+CDaTAGZcAyM4fwPElbUR7ALDzAQlAkNaNWZK xLD1xSco0dxsmzfqvgZJX3NV6VaxTP/rivgNY4qeyIMB3ZH2xxDv+3Xy0M0R/YSgn2mD tWmkh8RdJBXUY6oY8tNkl7KO3U/jOqPagD4378efeTUSoTKndn2hpwZUVVMCet0/LKvg NwbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SfAU/Ki1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u25-20020a509519000000b004376b600290si2996727eda.350.2022.07.19.06.51.02; Tue, 19 Jul 2022 06:51:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SfAU/Ki1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239222AbiGSMQh (ORCPT + 99 others); Tue, 19 Jul 2022 08:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239673AbiGSMOz (ORCPT ); Tue, 19 Jul 2022 08:14:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D8FE53D26; Tue, 19 Jul 2022 05:05:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1FDAC6163C; Tue, 19 Jul 2022 12:05:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0001FC341CA; Tue, 19 Jul 2022 12:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232345; bh=DAD+Pjwh8/AMSXxjKUmXsLwsZvgalbFQCH6aTqtkqc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SfAU/Ki1FMI4hUsR6uzGFjCKat1emWo5crystVE+D2rmXe5905aLVNuKa6Rw+rPXI kI7ZDPqzakuSGXd1Pt5+sSroo/3BwXvUPjhm7+7L2PHuNWP3+HQoLGuhcwhewpbhOQ PzbVIgF5foMXePJGXaUjJuTJ8s/xP5m4He6DPXYQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anastasios Vacharakis , Cristian Ciocaltea , Mark Brown , Sasha Levin Subject: [PATCH 5.10 026/112] spi: amd: Limit max transfer and message size Date: Tue, 19 Jul 2022 13:53:19 +0200 Message-Id: <20220719114628.562665124@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Cristian Ciocaltea [ Upstream commit 6ece49c56965544262523dae4a071ace3db63507 ] Enabling the SPI CS35L41 audio codec driver for Steam Deck [1] revealed a problem with the current AMD SPI controller driver implementation, consisting of an unrecoverable system hang. The issue can be prevented if we ensure the max transfer size and the max message size do not exceed the FIFO buffer size. According to the implementation of the downstream driver, the AMD SPI controller is not able to handle more than 70 bytes per transfer, which corresponds to the size of the FIFO buffer. Hence, let's fix this by setting the SPI limits mentioned above. [1] https://lore.kernel.org/r/20220621213819.262537-1-cristian.ciocaltea@collabora.com Reported-by: Anastasios Vacharakis Fixes: bbb336f39efc ("spi: spi-amd: Add AMD SPI controller driver support") Signed-off-by: Cristian Ciocaltea Link: https://lore.kernel.org/r/20220706100626.1234731-2-cristian.ciocaltea@collabora.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-amd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index 7f629544060d..a027cfd49df8 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -28,6 +28,7 @@ #define AMD_SPI_RX_COUNT_REG 0x4B #define AMD_SPI_STATUS_REG 0x4C +#define AMD_SPI_FIFO_SIZE 70 #define AMD_SPI_MEM_SIZE 200 /* M_CMD OP codes for SPI */ @@ -245,6 +246,11 @@ static int amd_spi_master_transfer(struct spi_master *master, return 0; } +static size_t amd_spi_max_transfer_size(struct spi_device *spi) +{ + return AMD_SPI_FIFO_SIZE; +} + static int amd_spi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -278,6 +284,8 @@ static int amd_spi_probe(struct platform_device *pdev) master->flags = SPI_MASTER_HALF_DUPLEX; master->setup = amd_spi_master_setup; master->transfer_one_message = amd_spi_master_transfer; + master->max_transfer_size = amd_spi_max_transfer_size; + master->max_message_size = amd_spi_max_transfer_size; /* Register the controller with SPI framework */ err = devm_spi_register_master(dev, master); -- 2.35.1