)]}' { "commit": "cfe8d7614910a1aa360a4e66ac9a7a854e88b372", "tree": "b9228efa9b0bfe4fa587482c4dffa016edc5d121", "parents": [ "e57ed07d5321dd2ceeaba2ed890c5057b7d1a34d" ], "author": { "name": "Alexander Dahl", "email": "post@lespocky.de", "time": "Tue May 26 19:57:49 2020 +0200" }, "committer": { "name": "Greg Kroah-Hartman", "email": "gregkh@linuxfoundation.org", "time": "Wed Jun 03 08:19:43 2020 +0200" }, "message": "x86/dma: Fix max PFN arithmetic overflow on 32 bit systems\n\ncommit 88743470668ef5eb6b7ba9e0f99888e5999bf172 upstream.\n\nThe intermediate result of the old term (4UL * 1024 * 1024 * 1024) is\n4 294 967 296 or 0x100000000 which is no problem on 64 bit systems.\nThe patch does not change the later overall result of 0x100000 for\nMAX_DMA32_PFN (after it has been shifted by PAGE_SHIFT). The new\ncalculation yields the same result, but does not require 64 bit\narithmetic.\n\nOn 32 bit systems the old calculation suffers from an arithmetic\noverflow in that intermediate term in braces: 4UL aka unsigned long int\nis 4 byte wide and an arithmetic overflow happens (the 0x100000000 does\nnot fit in 4 bytes), the in braces result is truncated to zero, the\nfollowing right shift does not alter that, so MAX_DMA32_PFN evaluates to\n0 on 32 bit systems.\n\nThat wrong value is a problem in a comparision against MAX_DMA32_PFN in\nthe init code for swiotlb in pci_swiotlb_detect_4gb() to decide if\nswiotlb should be active. That comparison yields the opposite result,\nwhen compiling on 32 bit systems.\n\nThis was not possible before\n\n 1b7e03ef7570 (\"x86, NUMA: Enable emulation on 32bit too\")\n\nwhen that MAX_DMA32_PFN was first made visible to x86_32 (and which\nlanded in v3.0).\n\nIn practice this wasn\u0027t a problem, unless CONFIG_SWIOTLB is active on\nx86-32.\n\nHowever if one has set CONFIG_IOMMU_INTEL, since\n\n c5a5dc4cbbf4 (\"iommu/vt-d: Don\u0027t switch off swiotlb if bounce page is used\")\n\nthere\u0027s a dependency on CONFIG_SWIOTLB, which was not necessarily\nactive before. That landed in v5.4, where we noticed it in the fli4l\nLinux distribution. We have CONFIG_IOMMU_INTEL active on both 32 and 64\nbit kernel configs there (I could not find out why, so let\u0027s just say\nhistorical reasons).\n\nThe effect is at boot time 64 MiB (default size) were allocated for\nbounce buffers now, which is a noticeable amount of memory on small\nsystems like pcengines ALIX 2D3 with 256 MiB memory, which are still\nfrequently used as home routers.\n\nWe noticed this effect when migrating from kernel v4.19 (LTS) to v5.4\n(LTS) in fli4l and got that kernel messages for example:\n\n Linux version 5.4.22 (buildroot@buildroot) (gcc version 7.3.0 (Buildroot 2018.02.8)) #1 SMP Mon Nov 26 23:40:00 CET 2018\n …\n Memory: 183484K/261756K available (4594K kernel code, 393K rwdata, 1660K rodata, 536K init, 456K bss , 78272K reserved, 0K cma-reserved, 0K highmem)\n …\n PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n software IO TLB: mapped [mem 0x0bb78000-0x0fb78000] (64MB)\n\nThe initial analysis and the suggested fix was done by user \u0027sourcejedi\u0027\nat stackoverflow and explicitly marked as GPLv2 for inclusion in the\nLinux kernel:\n\n https://unix.stackexchange.com/a/520525/50007\n\nThe new calculation, which does not suffer from that overflow, is the\nsame as for arch/mips now as suggested by Robin Murphy.\n\nThe fix was tested by fli4l users on round about two dozen different\nsystems, including both 32 and 64 bit archs, bare metal and virtualized\nmachines.\n\n [ bp: Massage commit message. ]\n\nFixes: 1b7e03ef7570 (\"x86, NUMA: Enable emulation on 32bit too\")\nReported-by: Alan Jenkins \u003calan.christopher.jenkins@gmail.com\u003e\nSuggested-by: Robin Murphy \u003crobin.murphy@arm.com\u003e\nSigned-off-by: Alexander Dahl \u003cpost@lespocky.de\u003e\nSigned-off-by: Borislav Petkov \u003cbp@suse.de\u003e\nReviewed-by: Greg Kroah-Hartman \u003cgregkh@linuxfoundation.org\u003e\nCc: stable@vger.kernel.org\nLink: https://unix.stackexchange.com/q/520065/50007\nLink: https://web.nettworks.org/bugs/browse/FFL-2560\nLink: https://lkml.kernel.org/r/20200526175749.20742-1-post@lespocky.de\nSigned-off-by: Greg Kroah-Hartman \u003cgregkh@linuxfoundation.org\u003e\n\n", "tree_diff": [ { "type": "modify", "old_id": "00f7cf45e6999b8edb776784effcb6bcda778ddb", "old_mode": 33188, "old_path": "arch/x86/include/asm/dma.h", "new_id": "8e95aa4b0d172362263c178de77c7b324de39263", "new_mode": 33188, "new_path": "arch/x86/include/asm/dma.h" } ] }