Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4880838pjb; Mon, 27 Jul 2020 07:29:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPStH0ZlLXUJuDk9KFn/9E1Mqv/Z9r3pSsF9nvxSgcITbgYyUoK+Pd6oQLnT2sZQUaHTn+ X-Received: by 2002:a17:906:e46:: with SMTP id q6mr20302364eji.234.1595860167159; Mon, 27 Jul 2020 07:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860167; cv=none; d=google.com; s=arc-20160816; b=DkHRKML0dwFoXvULnk1Sjd8t7VQi0xYGBOa+Q9wL3w0/MMBoOrldLaTT1lvSAkGJVC uPRitaEYIPM5bxmHucpjInW6DwLJdIhU38x9Czv/tdJq4bghxn4wtUF2yYrHePIZQ2ve +KYcvij+iNmzFSqe8jNTdd8ylsIIckzcZYNyUUCWJ7lgRMNLBsaJYiAsdYEah6v9OO7J irvlEsBuM1IGQUWKLPHO5I60DkFJhzH5NTGrzVbe7+D66cxpdHpIwWNm5TfG1gQLXfqt ZiM8t62cVMAvLoRPjPNmO5AZnDH0y1RVW6LS1k4VQQ0sarH0eh9pRGYcXRqgwSyWUOnh dASw== 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=J0ZH6GU9BtORG/khq/AXrSl3X7q0GwPUObij3oeSZpA=; b=NOXdrDT+ihczEdRuN8PFU46wa3o+iV81W4O16Oo6XjHoQZCJHCdUgG4XHXO54k+wJF IXGNfPseX8hqIX1P4hwF7C6/vHrnyQVmThy9Av6NkielTWZBW/iefP1EsGfu3MxblaqT LCYsPFbUUbypdzIwQ1YMDlqK6kx/Z2GH/zdzbIZ1ctzEkM+5HMJJ1PMJKUPbD0tyUsdB eckedIF1Zzu6Lk17vFjogN1T4DlosME6m9akQU1vxyPdGGPxKU2CPmW0Iw/lGVP6ZTn/ edS2KaPrd5e46puVP4pN/7aWb+xU/U3AbgFtfZoG3SWSZzPvZVdxvZVk5ueS2gRwpysr 9Wrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e4syDZ+H; 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 bf5si3609496edb.155.2020.07.27.07.29.04; Mon, 27 Jul 2020 07:29:27 -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=e4syDZ+H; 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 S1732510AbgG0OZs (ORCPT + 99 others); Mon, 27 Jul 2020 10:25:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:55752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732493AbgG0OZm (ORCPT ); Mon, 27 Jul 2020 10:25:42 -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 775222083E; Mon, 27 Jul 2020 14:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859942; bh=Rc3LqmVNrUoUef3e4HgaTNJPrptVc3bY/lS8DI5SHkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e4syDZ+HT1e9k/mijVs17xVKnI4LN+HZAQQQVYOJKf2s7RiyE4j2+oQsIeknTLJcD Wey4CLyjAtGUrUqWNk/Z6Nxd88h5bSJKmOHyHbEmAl2xOFCkU1HE1vn6JCNjITGFSK EmHfjCtrwD9dmei2AXrvrneMuW+g9VPGfMklk2yw= 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 5.7 165/179] io-mapping: indicate mapping failure Date: Mon, 27 Jul 2020 16:05:40 +0200 Message-Id: <20200727134940.703288031@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@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 @@ -107,9 +107,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)