Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp690880imm; Wed, 22 Aug 2018 10:53:34 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzNIrlExOug5vHusvDllPQQRfSuimyWBNS8Ff/O5izq3yT+htQiIv5dtP3NcyE7jx21eDt/ X-Received: by 2002:a63:6b03:: with SMTP id g3-v6mr22869484pgc.57.1534960414715; Wed, 22 Aug 2018 10:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534960414; cv=none; d=google.com; s=arc-20160816; b=qnHpeu3iW8nDFlk6YRzke81uSHNVyk5FWenZpupamQrTIAg4imMdZjRLwFMLTYkDOY QioPPO8Jx2YRVuEpx3LiNEGr1vW+6po9NEoMFyUGvQg7W2BLBARHXi5x58iYoW8H7FkW Cau/OljO0gbv747vTFQKkPImwwUSIvJCnlnJAmvjnbPfSIFAs2Qe2P6GEI+nZdPmWp+w cpB7HJgHJGXycfy3B1ClB+5Sv9jiX/o9n+LqZ/yEDgd2KjYQp5+vlV8hB8u7FKHEQMDa yXAKdukIJeOdWKMPKDpPZdKgW/CTjsWdvexcyirmO6gXCGn9O6W0hhzzC/Qc6X2JkWMt K7jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=1mFCdIkZygQloDCIJwcLgP9XXVHsmC34+eGkOMt/s1U=; b=eYM3fqwh6QsUurNmGC6TM8rkxlCTj3xEcoZMm0eRYpUw6upiCS8etZi8ONd2PqlQ4c i40KtCfVJe3VvjGj3l2VIS8aePhZDveLBchxOT/CvkycPP2SPbcL6WH2HndzwmU3byW7 7ZC3b8N41Kip3TKmHpp59oHDtVKftPQeXyJMUYSnKiKo2L8vi5Pzk8SAXQ3ZiZJY9IAA LgV6KZVL6h+c9zGodDDHO2WZmxgZXXBDpsL7rPQ7y++zriWws6Kd3AdBEPcJosR4G4xI J2GH3ojVbNBRhZq7kqEZhk88stO5Dto0CzDm1AJ0Cz6jk44Ha94GPabXuHm5hYtd4GmA E8uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@compulab.co.il header.s=default header.b="m/Me6wJV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17-v6si2214142pgg.628.2018.08.22.10.53.19; Wed, 22 Aug 2018 10:53:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@compulab.co.il header.s=default header.b="m/Me6wJV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727747AbeHVVRg (ORCPT + 99 others); Wed, 22 Aug 2018 17:17:36 -0400 Received: from softlayer.compulab.co.il ([50.23.254.55]:41877 "EHLO compulab.co.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727468AbeHVVRg (ORCPT ); Wed, 22 Aug 2018 17:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=compulab.co.il; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1mFCdIkZygQloDCIJwcLgP9XXVHsmC34+eGkOMt/s1U=; b=m/Me6wJV0cBGPcEfqvLeualXvA ZbD4T8p8VAIp3VOoCWi32nvs7pVZvlMFEg4lgjWOLAnGQ2uX5TcbonqJ7xihnjlPmQ/iiJ+izCPEg GhTMvmvVMtYPMhp2P2Z/Jv4X8EtRp/6T076jCMTHD4dMcO0+gk3V7X8SvAGzcQN/cP2UORKY8rrog VDQnsc0L8Yj02nznYmWlfTPwVlrw0sNjkQ0iJXR9AOlUNJkgXnwfOYyJabfqhG79jluB5DSmo3GFc buHoNhQ3mSXzFwRdpiwhGWVUzOaUXtVCqQThw/gKypk/YGez0CBCimF1w4sjBvag0VSLCnp0qP411 RlfS+P5g==; Received: from [37.142.126.90] (port=43737 helo=zimbra-mta.compulab.co.il) by softlayer.compulab.co.il with esmtp (Exim 4.87) (envelope-from ) id 1fsXIF-000084-5P; Wed, 22 Aug 2018 20:51:43 +0300 Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id E594D4826BF; Wed, 22 Aug 2018 20:51:41 +0300 (IDT) Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id pJHqDBE3xlLy; Wed, 22 Aug 2018 20:51:41 +0300 (IDT) Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 7BF114826C2; Wed, 22 Aug 2018 20:51:41 +0300 (IDT) X-Virus-Scanned: amavisd-new at zimbra-mta.compulab.co.il Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JI12KLHdogm9; Wed, 22 Aug 2018 20:51:41 +0300 (IDT) Received: from [192.168.11.10] (lifshitz-linux.compulab.local [192.168.11.10]) by zimbra-mta.compulab.co.il (Postfix) with ESMTPSA id 227B64826BF; Wed, 22 Aug 2018 20:51:41 +0300 (IDT) Subject: Re: [PATCH -next] spi: Fix double IDR allocation with DT aliases To: Geert Uytterhoeven Cc: Mark Brown , linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20180821095303.27664-1-geert+renesas@glider.be> From: Kirill Kapranov Organization: CompuLab Ltd. Message-ID: <35fbd3ae-3ac3-f6ef-874b-3d99c4d4d29a@compulab.co.il> Date: Wed, 22 Aug 2018 20:51:40 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180821095303.27664-1-geert+renesas@glider.be> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - softlayer.compulab.co.il X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - compulab.co.il X-Get-Message-Sender-Via: softlayer.compulab.co.il: acl_c_recent_authed_mail_ips_text_entry: kirill.kapranov@compulab.co.il|compulab.co.il X-Authenticated-Sender: softlayer.compulab.co.il: kirill.kapranov@compulab.co.il Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert Thank you for keeping me informed. I have to point at the following threat: a dynamically allocated ID may 'squat' a bus ID that intended for a device with statically allocated ID. This scenario is possible since module loading order is uncertain. This threat seems to be inevitable... -- Best regards, Kirill. On 08/21/2018 12:53 PM, Geert Uytterhoeven wrote: > If the SPI bus number is provided by a DT alias, idr_alloc() is called > twice, leading to: > > WARNING: CPU: 1 PID: 1 at drivers/spi/spi.c:2179 spi_register_controller+0x11c/0x5d8 > couldn't get idr > > Fix this by moving the handling of fixed SPI bus numbers up, before the > DT handling code fills in ctlr->bus_num. > > Fixes: 1a4327fbf4554d5b ("spi: fix IDR collision on systems with both fixed and dynamic SPI bus numbers") > Signed-off-by: Geert Uytterhoeven > --- > Seen on e.g. r8a7791/koelsch, breaking both RSPI and MSIOF. > --- > drivers/spi/spi.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c > index a00d006d4c3a1c5a..9da0bc5a036cfff6 100644 > --- a/drivers/spi/spi.c > +++ b/drivers/spi/spi.c > @@ -2143,8 +2143,17 @@ int spi_register_controller(struct spi_controller *ctlr) > */ > if (ctlr->num_chipselect == 0) > return -EINVAL; > - /* allocate dynamic bus number using Linux idr */ > - if ((ctlr->bus_num < 0) && ctlr->dev.of_node) { > + if (ctlr->bus_num >= 0) { > + /* devices with a fixed bus num must check-in with the num */ > + mutex_lock(&board_lock); > + id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num, > + ctlr->bus_num + 1, GFP_KERNEL); > + mutex_unlock(&board_lock); > + if (WARN(id < 0, "couldn't get idr")) > + return id == -ENOSPC ? -EBUSY : id; > + ctlr->bus_num = id; > + } else if (ctlr->dev.of_node) { > + /* allocate dynamic bus number using Linux idr */ > id = of_alias_get_id(ctlr->dev.of_node, "spi"); > if (id >= 0) { > ctlr->bus_num = id; > @@ -2170,15 +2179,6 @@ int spi_register_controller(struct spi_controller *ctlr) > if (WARN(id < 0, "couldn't get idr")) > return id; > ctlr->bus_num = id; > - } else { > - /* devices with a fixed bus num must check-in with the num */ > - mutex_lock(&board_lock); > - id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num, > - ctlr->bus_num + 1, GFP_KERNEL); > - mutex_unlock(&board_lock); > - if (WARN(id < 0, "couldn't get idr")) > - return id == -ENOSPC ? -EBUSY : id; > - ctlr->bus_num = id; > } > INIT_LIST_HEAD(&ctlr->queue); > spin_lock_init(&ctlr->queue_lock); >