From patchwork Tue Jun 13 17:47:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 9784455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04A42602C9 for ; Tue, 13 Jun 2017 17:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E218E283C5 for ; Tue, 13 Jun 2017 17:48:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D685F2857B; Tue, 13 Jun 2017 17:48:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81BF2283C5 for ; Tue, 13 Jun 2017 17:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/6mqQMOASqCJNz19DUeCbWMoGz47FsIzKgVs6c+DnDA=; b=AFQiAfO89z2rY0 EvcDCTLZaSzjkFGF4cvHm7WSsHhKaIPx20zClQpOZQSvGRniQHrDdXuWeROIUpNuq/vmLfvpTND33 /s6R6tfwJD4C8mr7jp/jZ3YDpETXMQOweH4G0/x2YfEdX2neoLgmxMlP6W9rjkeuZ0UPSusTzXN8T miIF9LLy4OZ1KXid/B8JLNTtV7WHUXXFrsBS6mJO3CFT4OK3aPLNQGop88xBTXc4qUGR/PtFNhWl1 jklZCKjk38kMQ02y+k7vyZh7ylMGo9sg5jNijaB4p5Wle9NIEb9X7mo16H+aYSUwL8fAN7Wc9brga ci1s5X8Vvw8+4lxaR7+w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dKpvG-0006yS-E4; Tue, 13 Jun 2017 17:48:10 +0000 Received: from ale.deltatee.com ([207.54.116.67]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKpvC-0006xQ-S6 for linux-arm-kernel@lists.infradead.org; Tue, 13 Jun 2017 17:48:08 +0000 Received: from guinness.priv.deltatee.com ([172.16.1.111]) by ale.deltatee.com with esmtp (Exim 4.84_2) (envelope-from ) id 1dKpud-00026T-Ig; Tue, 13 Jun 2017 11:47:32 -0600 To: Greg Kroah-Hartman References: <5933fe2d.V33ODGPU9noDVuyF%fengguang.wu@intel.com> <20170606175552.GA12672@bhelgaas-glaptop.roam.corp.google.com> <20170612200852.GA28578@bhelgaas-glaptop.roam.corp.google.com> <61e11e67-6c1b-ef1e-5fb8-a7c9efb17666@deltatee.com> <20170613041842.GA13308@kroah.com> <20170613043416.GB14217@kroah.com> <20170613043518.GA14621@kroah.com> <8462abee-0a7f-00fb-6111-1f78362ea3f7@deltatee.com> <20170613163508.GA31961@kroah.com> From: Logan Gunthorpe Message-ID: Date: Tue, 13 Jun 2017 11:47:30 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170613163508.GA31961@kroah.com> X-SA-Exim-Connect-IP: 172.16.1.111 X-SA-Exim-Rcpt-To: daniel.vetter@ffwll.ch, dh.herrmann@gmail.com, airlied@linux.ie, linus.walleij@linaro.org, arnd@arndb.de, alan@linux.intel.com, wfg@linux.intel.com, bhelgaas@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-doc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, lkp@01.org, torvalds@linux-foundation.org, fengguang.wu@intel.com, helgaas@kernel.org, gregkh@linuxfoundation.org X-SA-Exim-Mail-From: logang@deltatee.com Subject: Re: [Merge tag 'pci-v4.12-changes' of git] 857f864014: BUG: unable to handle kernel NULL pointer dereference at 00000000000000a8 X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170613_104806_952849_8F6B8C0F X-CRM114-Status: GOOD ( 17.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Arnd Bergmann , linux-doc@vger.kernel.org, David Airlie , LKP , Linus Walleij , David Herrmann , linux-kernel@vger.kernel.org, Daniel Vetter , Bjorn Helgaas , linux-pci@vger.kernel.org, Bjorn Helgaas , wfg@linux.intel.com, kernel test robot , Linus Torvalds , linux-arm-kernel@lists.infradead.org, Alan Cox Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 13/06/17 10:35 AM, Greg Kroah-Hartman wrote: > For char devices, I doubt it, but we can't take the chance, which is why > you make it an option. Then, it's enabled for 'allmodconfig' builds, > which helps testers out. Well I took a look at this and it looks like a lot of work to modify all the drivers to support a possible dynamic allocation and I'm not really able to do all that right now. However, correct me if I'm missing something, but it looks fairly straightforward to extend the dynamic region above 256 in cases like this. There are already fixed major numbers above 255 and the infrastructure appears to support it. So what are your thoughts on the change below? I'd be happy to clean it up into a proper patch if you agree it's a workable option. Thanks, Logan extern int __register_chrdev(unsigned int major, unsigned int baseminor, ---- This results in char devices like this (another patch might be prudent to fix the ordering): Character devices: 510 ttySLM 1 mem 511 noz 4 /dev/vc/0 4 tty 4 ttyS 5 /dev/tty 5 /dev/console 5 /dev/ptmx 7 vcs 9 st 10 misc 13 input 21 sg 29 fb 43 ttyI 45 isdn 68 capi20 86 ch 90 mtd 99 ppdev 108 ppp 128 ptm 136 pts 152 aoechr 153 spi 161 ircomm 172 ttyMX 174 ttyMI 202 cpu/msr 203 cpu/cpuid 204 ttyJ 204 ttyMAX 206 osst 226 drm 235 ttyS 236 ttyRP 237 ttyARC 238 ttyPS 239 ttyIFX 494 rio_cm 240 ttySC 495 cros_ec 241 ipmidev 496 hidraw 242 rio_mport 497 ttySDIO 243 xz_dec_test 498 uio 244 bsg 499 firewire 245 pvfs2-req 500 nvme 246 watchdog 501 aac 247 iio 502 mei 248 ptp 503 phantom 249 pps 504 aux 250 dax 505 cmx 251 dimmctl 506 cmm 252 ndctl 507 ttySLP 253 tpm 508 ttyIPWp 254 gpiochip 509 ttySL diff --git a/fs/char_dev.c b/fs/char_dev.c index fb8507f521b2..539352425d95 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -59,6 +59,29 @@ void chrdev_show(struct seq_file *f, off_t offset) #endif /* CONFIG_PROC_FS */ +static int find_dynamic_major(void) +{ + int i; + struct char_device_struct **cp; + + for (i = ARRAY_SIZE(chrdevs)-1; i > CHRDEV_MAJOR_DYN_END; i--) { + if (chrdevs[i] == NULL) + return i; + } + + for (i = CHRDEV_MAJOR_DYN_EXT_START; + i > CHRDEV_MAJOR_DYN_EXT_END; i--) { + for (cp = &chrdevs[major_to_index(i)]; *cp; cp = &(*cp)->next) + if ((*cp)->major == i) + break; + + if (*cp == NULL || (*cp)->major != i) + return i; + } + + return -EBUSY; +} + /* * Register a single major with a specified minor range. * @@ -84,22 +107,11 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, mutex_lock(&chrdevs_lock); - /* temporary */ if (major == 0) { - for (i = ARRAY_SIZE(chrdevs)-1; i > 0; i--) { - if (chrdevs[i] == NULL) - break; - } - - if (i < CHRDEV_MAJOR_DYN_END) - pr_warn("CHRDEV \"%s\" major number %d goes below the dynamic allocation range\n", - name, i); - - if (i == 0) { - ret = -EBUSY; + ret = find_dynamic_major(); + if (ret < 0) goto out; - } - major = i; + major = ret; } cd->major = major; diff --git a/include/linux/fs.h b/include/linux/fs.h index 249dad4e8d26..5780d69034ca 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2448,6 +2448,9 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, #define CHRDEV_MAJOR_HASH_SIZE 255 /* Marks the bottom of the first segment of free char majors */ #define CHRDEV_MAJOR_DYN_END 234 +#define CHRDEV_MAJOR_DYN_EXT_START 511 +#define CHRDEV_MAJOR_DYN_EXT_END 384 + extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); extern int register_chrdev_region(dev_t, unsigned, const char *);