Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2550596imu; Thu, 29 Nov 2018 06:46:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/WSEEMyHSh7ZY73KMEDMTArVulKYZ56gmHLwpV+sVkd3CPLxqLGBLOAq3xXWoAgHEb0jFZa X-Received: by 2002:a17:902:9a07:: with SMTP id v7mr1674167plp.247.1543502760933; Thu, 29 Nov 2018 06:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502760; cv=none; d=google.com; s=arc-20160816; b=OlkuaE3Xp/fTgx5ECLDJlaO94nut+FFs8koJDI1mKRpV6QdhHW1F2YSmeo0rPFcqxz eeswyDyZV2JhRMm90YUdhaVl1+wt3DXhkA5VxBbIjnWw7YgjCtvks26AWdNixf5QoMkN I4XDuV602Nl7wgOdLV/dfwTAwGf2J42twKJv9XGtrpDsYNm4YqkIFmeqqwpKQB4vzGnM 4Z6eMElX82Wavsr+ZkLFvb6/yQQGHXnFe0+3CjE5fQARiyoe1672aGT5u7e3G7ZrKSsB ECzXPT+AnQpPNMiEirlUHogEgZja7YtT//3ApERd9SjtzbV9nUd57DLbM87ifpuHa+5o UxUw== 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=UDC+CbwclzmFm4yoLEvmyCnKwB/nSjunoyKAuANg/9Q=; b=pR3u1Qyeofs58XxYWxIakz3MO9LUoOfOF0syi1rVMc1gvSt14ioztRP28Lr4wCKRFs RHO56EIly7ZhvRzdMZ5QCGM+Pw5Hbpdgn0WFMQ6mPGhoGIwI4FWPk0BCes+WDxpBNWnz ggmSFMePOTYBqA1P8fhdJ+e1ese24qzARwuDawPs6wk31ZGrYChLijuH/1e4iR+8Jmnc +CVHDaVnF1Qsbf2AqRb/1TCaoplxTMJWfp6bFOobZIH1fSjoNhhvR6V0kSETVjv66A7G jWy7qXfpJxVeznDXBL2jRCMRywgy/5S42xYb7LQU5TZPXhfbh5SNG46ax/qFxsO6mwQ4 B5SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L8eP1AGB; 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 s73si2214717pfs.54.2018.11.29.06.45.44; Thu, 29 Nov 2018 06:46:00 -0800 (PST) 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=pass header.i=@kernel.org header.s=default header.b=L8eP1AGB; 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 S2387739AbeK3BdF (ORCPT + 99 others); Thu, 29 Nov 2018 20:33:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:33456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731824AbeK3BdF (ORCPT ); Thu, 29 Nov 2018 20:33:05 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 C4A4C2133F; Thu, 29 Nov 2018 14:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501652; bh=RnYrChlWkzp7quSKwlrVv5ADiEG0WVivLpoZX+ydl3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L8eP1AGBFYBhZ3cn2FG/RRrE+ALa5Io5opGTHZIuM4Og0dZT2KnCiYMcJVM7Do8Fr SHiU6j3XdAcrCq8Xq1D+SodAUYgbsE0tYFGBOypP0qt2kuw9Qk1vHhIJ7V2qho432B IV1e8TDQlQUBZamiRQODT5WCPIUKQl8H6suVmg5s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Sasha Levin Subject: [PATCH 4.14 052/100] powerpc/io: Fix the IO workarounds code to work with Radix Date: Thu, 29 Nov 2018 15:12:22 +0100 Message-Id: <20181129140103.714909513@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 43c6494fa1499912c8177e71450c0279041152a6 ] Back in 2006 Ben added some workarounds for a misbehaviour in the Spider IO bridge used on early Cell machines, see commit 014da7ff47b5 ("[POWERPC] Cell "Spider" MMIO workarounds"). Later these were made to be generic, ie. not tied specifically to Spider. The code stashes a token in the high bits (59-48) of virtual addresses used for IO (eg. returned from ioremap()). This works fine when using the Hash MMU, but when we're using the Radix MMU the bits used for the token overlap with some of the bits of the virtual address. This is because the maximum virtual address is larger with Radix, up to c00fffffffffffff, and in fact we use that high part of the address range for ioremap(), see RADIX_KERN_IO_START. As it happens the bits that are used overlap with the bits that differentiate an IO address vs a linear map address. If the resulting address lies outside the linear mapping we will crash (see below), if not we just corrupt memory. virtio-pci 0000:00:00.0: Using 64-bit direct DMA at offset 800000000000000 Unable to handle kernel paging request for data at address 0xc000000080000014 ... CFAR: c000000000626b98 DAR: c000000080000014 DSISR: 42000000 IRQMASK: 0 GPR00: c0000000006c54fc c00000003e523378 c0000000016de600 0000000000000000 GPR04: c00c000080000014 0000000000000007 0fffffff000affff 0000000000000030 ^^^^ ... NIP [c000000000626c5c] .iowrite8+0xec/0x100 LR [c0000000006c992c] .vp_reset+0x2c/0x90 Call Trace: .pci_bus_read_config_dword+0xc4/0x120 (unreliable) .register_virtio_device+0x13c/0x1c0 .virtio_pci_probe+0x148/0x1f0 .local_pci_probe+0x68/0x140 .pci_device_probe+0x164/0x220 .really_probe+0x274/0x3b0 .driver_probe_device+0x80/0x170 .__driver_attach+0x14c/0x150 .bus_for_each_dev+0xb8/0x130 .driver_attach+0x34/0x50 .bus_add_driver+0x178/0x2f0 .driver_register+0x90/0x1a0 .__pci_register_driver+0x6c/0x90 .virtio_pci_driver_init+0x2c/0x40 .do_one_initcall+0x64/0x280 .kernel_init_freeable+0x36c/0x474 .kernel_init+0x24/0x160 .ret_from_kernel_thread+0x58/0x7c This hasn't been a problem because CONFIG_PPC_IO_WORKAROUNDS which enables this code is usually not enabled. It is only enabled when it's selected by PPC_CELL_NATIVE which is only selected by PPC_IBM_CELL_BLADE and that in turn depends on BIG_ENDIAN. So in order to hit the bug you need to build a big endian kernel, with IBM Cell Blade support enabled, as well as Radix MMU support, and then boot that on Power9 using Radix MMU. Still we can fix the bug, so let's do that. We simply use fewer bits for the token, taking the union of the restrictions on the address from both Hash and Radix, we end up with 8 bits we can use for the token. The only user of the token is iowa_mem_find_bus() which only supports 8 token values, so 8 bits is plenty for that. Fixes: 566ca99af026 ("powerpc/mm/radix: Add dummy radix_enabled()") Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/io.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h index 422f99cf9924..e6d33eed8202 100644 --- a/arch/powerpc/include/asm/io.h +++ b/arch/powerpc/include/asm/io.h @@ -287,19 +287,13 @@ extern void _memcpy_toio(volatile void __iomem *dest, const void *src, * their hooks, a bitfield is reserved for use by the platform near the * top of MMIO addresses (not PIO, those have to cope the hard way). * - * This bit field is 12 bits and is at the top of the IO virtual - * addresses PCI_IO_INDIRECT_TOKEN_MASK. + * The highest address in the kernel virtual space are: * - * The kernel virtual space is thus: + * d0003fffffffffff # with Hash MMU + * c00fffffffffffff # with Radix MMU * - * 0xD000000000000000 : vmalloc - * 0xD000080000000000 : PCI PHB IO space - * 0xD000080080000000 : ioremap - * 0xD0000fffffffffff : end of ioremap region - * - * Since the top 4 bits are reserved as the region ID, we use thus - * the next 12 bits and keep 4 bits available for the future if the - * virtual address space is ever to be extended. + * The top 4 bits are reserved as the region ID on hash, leaving us 8 bits + * that can be used for the field. * * The direct IO mapping operations will then mask off those bits * before doing the actual access, though that only happen when @@ -311,8 +305,8 @@ extern void _memcpy_toio(volatile void __iomem *dest, const void *src, */ #ifdef CONFIG_PPC_INDIRECT_MMIO -#define PCI_IO_IND_TOKEN_MASK 0x0fff000000000000ul -#define PCI_IO_IND_TOKEN_SHIFT 48 +#define PCI_IO_IND_TOKEN_SHIFT 52 +#define PCI_IO_IND_TOKEN_MASK (0xfful << PCI_IO_IND_TOKEN_SHIFT) #define PCI_FIX_ADDR(addr) \ ((PCI_IO_ADDR)(((unsigned long)(addr)) & ~PCI_IO_IND_TOKEN_MASK)) #define PCI_GET_ADDR_TOKEN(addr) \ -- 2.17.1