Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4870586pjb; Mon, 27 Jul 2020 07:15:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/n5/KB94Fu9FY39N0PiAZWUqBYgnam3ZEQjYOBdCoLDtzCxw94h4p0ywkXVHpyawJC+M7 X-Received: by 2002:a05:6402:1687:: with SMTP id a7mr21131963edv.358.1595859358075; Mon, 27 Jul 2020 07:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859358; cv=none; d=google.com; s=arc-20160816; b=Dg26Yym4AP7vpxwHB0uOSg2GBOjdLh3DqYvMsy+T87tRopxY77Pdmzf7z7SMu/qW+D zwXMhelsXq54gmu8n0IKIIi3+zU4Wjf06Sn4hTV+UI30zsh6LMYpGiPG0UpUmarsVTdv aDjpSrWzE51edVSu/z5RmgtJjs0L/fFVI/L+9ZGel43GWJHVMptDkhRw4imnoAes4DPK 1FpgrYqxwF/HmRytKAhUXDmPszbdKD5To4EUqNZNXxxY6ZrxXakLiFMJlH7/OAqeTKVo y6Fg/IuCEfjg+CHPyjVSewp1h/DPB+lBr+UsOdT5p7zBmhF64y54e2VZG5zsgXsvEy0D nd6w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i+PKNdICQSvG+ZPX2Ag+4tIIRbXmkJN2y3fda4TO8xw=; b=j2DeD61taH/ntDJfZJ2rFssj053SuMAYvwvJS1vQ2aon6bXYzmpfJC01s6rxMk9AFe SnlY/kV7MH3CgthQ53rw8JdUGdVl++fStjdEKIKjO5vLEPMeqoR6WCgupGLyKydgs0ei +pVr4fGKDXwTlFYrWDGuIgK5Q9AIlF/8oH0P36XiQXGBQBIbV/wZMZP2/L/oUCCXyUCi NuCJUMOtt28VGmOMTxfz5x5Yr6u6y2VRoFaSHKXT12nFVkYa2hjoMvlnb3ejdPrJPy+9 mRfgzCM7umrRVXQJBYcdPddJVCw3HCMlNJ+Z+dihDxImRfsiWbs+bQn8QZr1n7jESUYt jb5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="uGzB/uur"; 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 d6si3841668ejp.151.2020.07.27.07.15.35; Mon, 27 Jul 2020 07:15:58 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b="uGzB/uur"; 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 S1730148AbgG0OMM (ORCPT + 99 others); Mon, 27 Jul 2020 10:12:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:36292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730138AbgG0OMK (ORCPT ); Mon, 27 Jul 2020 10:12:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB38121775; Mon, 27 Jul 2020 14:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859130; bh=29cjQnjSC+wuvHtG+20VVuSfXqeNY9zwFB/jMOukLSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uGzB/uurOdrp52J/izWLlqdoh9PYXKjgSXoD/lEmq4IHbt+ihIzwRQ4hRhpTzVzBK bVa8hV5h3wYM05EYpvOwFgDlDdQ7vjllJ/dq9ahreOy1ns6ZV5B2aSBtOWWgsYjg7s peuHZJyKxZB6Dsoy8XnZ9QuMDkhApnjApBKQRNwY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael J. Ruhl" , Andrew Morton , Mike Rapoport , Andy Shevchenko , Chris Wilson , Daniel Vetter , Linus Torvalds Subject: [PATCH 4.19 77/86] io-mapping: indicate mapping failure Date: Mon, 27 Jul 2020 16:04:51 +0200 Message-Id: <20200727134918.255432367@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134914.312934924@linuxfoundation.org> References: <20200727134914.312934924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael J. Ruhl commit e0b3e0b1a04367fc15c07f44e78361545b55357c upstream. The !ATOMIC_IOMAP version of io_maping_init_wc will always return success, even when the ioremap fails. Since the ATOMIC_IOMAP version returns NULL when the init fails, and callers check for a NULL return on error this is unexpected. During a device probe, where the ioremap failed, a crash can look like this: BUG: unable to handle page fault for address: 0000000000210000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page Oops: 0002 [#1] PREEMPT SMP CPU: 0 PID: 177 Comm: RIP: 0010:fill_page_dma [i915] gen8_ppgtt_create [i915] i915_ppgtt_create [i915] intel_gt_init [i915] i915_gem_init [i915] i915_driver_probe [i915] pci_device_probe really_probe driver_probe_device The remap failure occurred much earlier in the probe. If it had been propagated, the driver would have exited with an error. Return NULL on ioremap failure. [akpm@linux-foundation.org: detect ioremap_wc() errors earlier] Fixes: cafaf14a5d8f ("io-mapping: Always create a struct to hold metadata about the io-mapping") Signed-off-by: Michael J. Ruhl Signed-off-by: Andrew Morton Reviewed-by: Andrew Morton Cc: Mike Rapoport Cc: Andy Shevchenko Cc: Chris Wilson Cc: Daniel Vetter Cc: Link: http://lkml.kernel.org/r/20200721171936.81563-1-michael.j.ruhl@intel.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/io-mapping.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/include/linux/io-mapping.h +++ b/include/linux/io-mapping.h @@ -120,9 +120,12 @@ io_mapping_init_wc(struct io_mapping *io resource_size_t base, unsigned long size) { + iomap->iomem = ioremap_wc(base, size); + if (!iomap->iomem) + return NULL; + iomap->base = base; iomap->size = size; - iomap->iomem = ioremap_wc(base, size); #if defined(pgprot_noncached_wc) /* archs can't agree on a name ... */ iomap->prot = pgprot_noncached_wc(PAGE_KERNEL); #elif defined(pgprot_writecombine)