From patchwork Tue Jul 9 00:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 13727141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC636C3DA45 for ; Tue, 9 Jul 2024 00:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=l7Aak+D48UnpzWsnhb9d4cGQ6es6fJHU6XxSEuHqzBQ=; b=myBudEluU67SqVUITRDNvBziwS MHtPLt5DQG1kz0TvCjYTMQeKog42nxHkvGQzDwaIA1go8Vz+7Mg6Q36yjiO3OcJWiCU5D8aJW1Yv3 AKTeLH1C45qh3NwrcUHNLYYEYQnfrimwfrQLOjaqS+V0gHxGm7TI8XaZMSFk/+Gv4gu4eP96+XNw8 ZkezsG6ohk4L2rtfgmlZl6dhn+x8uyN0GR7xvLlqfEk1FuIM3AenYQSZ+Qfx0U5oeE7wvlPl4w2jH ItdUaY+t33ZrwkUtjH4g6aIq4TZSXZjeBIqfty+mhnXcZ3Jcbf9TOpnJk3ikQoG2LFLGKAmTYlcJO rNK9iK/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQyia-00000005RQS-1hhn; Tue, 09 Jul 2024 00:28:28 +0000 Received: from mail-sn1nam02on2070f.outbound.protection.outlook.com ([2a01:111:f400:7ea9::70f] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQyiL-00000005RLw-0AJZ for linux-arm-kernel@lists.infradead.org; Tue, 09 Jul 2024 00:28:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OOnA3o40zg8prF2VuX4KtYcfGTD3Z6n202CvX2ZqHSpJqduOIygRtkYqTvs7xVUTP0tuHufCqw0XpWNlOe9JfMgkVS/b01h18iQ4RWBr7gf62kbKfsjeuyrPP8u/O77HksOgtG0kYNZlFy0o8MX0ZYJlSr1GnGBvkyMLUEbpiYbd1V4jAeMtrcDre9ctqbr2XFVDeGeyY7Nhc71tdbYrjVwfwBQqihH8HZRymrowlbX5KpRHOWIVBl+DwPpo87r1ImjBOcPA4v37ix2FGFuRh2VaFkbJl7+G2sPiBR8a5FV/3KMXJ0kHVynGx8ufhNE/D51OpWVqfxlIQVq0A1+MoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=l7Aak+D48UnpzWsnhb9d4cGQ6es6fJHU6XxSEuHqzBQ=; b=KNdgn94+9jfSFegMyJ0vQlXDvLRcRca8psSAB3qf0iecLULyu9KDW/Cmvek/+Y/6owmadVA/Y3E8jR+Tj4BoFZl/s8t57eJDf5bXg2v0cHQjxTcQ34XiffMTDOoEY1P2DA8oOydsJt8KYViAxFgnl7dzK9KmdANZ3T2GaqCSE+FD+YPk/38DK/d/FBJXl3prhgsJtuQd7FCGh+XgMsyOZNLnbmL0Gylp67/OABxTRI5/QSef0Wt15S6VxEEzN1oy71mDN6qfaR84c/BfmDMUneJ23Q3wH8tFIjDJknVklz7AHfVwoW1l2tPKaE49g20kQnMqZcbXxmIuCqsyimULDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l7Aak+D48UnpzWsnhb9d4cGQ6es6fJHU6XxSEuHqzBQ=; b=pP+T8rJsJVlhYbJxzricib2GHOOivJjHbta7BhjHMLHoM7QdbyYsMnOPP7k3JdB4Emd+jLttvlsijXEmRsyBVp55wunaXN/V98VY7p2MkgDSeTMQASqgyBr7a0pmATbjbDzL1WLMfPxQZf9PwA4raSSpGHOCbZr/+Jd5N7dyh6s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from LV2PR01MB7792.prod.exchangelabs.com (2603:10b6:408:14f::10) by SA3PR01MB7986.prod.exchangelabs.com (2603:10b6:806:319::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Tue, 9 Jul 2024 00:28:01 +0000 Received: from LV2PR01MB7792.prod.exchangelabs.com ([fe80::2349:ebe6:2948:adb9]) by LV2PR01MB7792.prod.exchangelabs.com ([fe80::2349:ebe6:2948:adb9%3]) with mapi id 15.20.7741.033; Tue, 9 Jul 2024 00:28:01 +0000 From: D Scott Phillips To: Greg Kroah-Hartman , Andy Shevchenko , AKASHI Takahiro , Alison Schofield , Dan Williams , Baoquan He , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Andrew Morton , "Kirill A. Shutemov" , patches@amperecomputing.com Subject: [PATCH v2] resource: limit request_free_mem_region based on arch_get_mappable_range Date: Mon, 8 Jul 2024 17:27:57 -0700 Message-ID: <20240709002757.2431399-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: CH3P221CA0006.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1e7::32) To LV2PR01MB7792.prod.exchangelabs.com (2603:10b6:408:14f::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR01MB7792:EE_|SA3PR01MB7986:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e520e8f-94a1-474d-e5d0-08dc9fadfdb7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|7416014|1800799024|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: 1A7Tix5Zwve+Zup9/2jFv1R0g8qOpj9njB+S//T+Kktp+5ZjXR/rqSWhnIR+4yCLWWeDHVkZ8OhtmX1E2fLp7UO88pIYgY18v1sFHQQRylMpAM2zjHjoy4aP62uDARsQzw/A805m2EVaU51xgx2iiWayWt8H+f+R/jhquJTuD9Ky9696dcpuHLmo9IrFbUQtKYzhXmhbVx5gbPLdOi2h3q8dNLTBVyVBBnRXrI0aJwTF3j4OdRnehrrrziIDW60+Yd8M9jdHjgTSRkJ4KECXB0AmU/U086799uSdR9JmvDyWxmnPCiTJIo1LGJiJjJbqgyd2KjNXhxFSn9mjfL4URRuNZrdUF0jJ09U3OLYMVedHNzFGhW/PNFkNU+iis+ZLtOcgiL1MvqR5kswmMg3mJHsrYyzZoBOiNvcP34uldrWyIIDvFCBF/ngROdniYvVrHKkxbB5EbOn2L0LzZgQVaOvHwoul0clVN6UZly7Zxq0SY9Cq5vFYJm6NCdcl9rXyEkYs/axrCcIlvA8sILKaUgnu+QU1w0HeWHLwq4DbNvpEjoYEK/zjCJLNqcv4jv9BkeSCxk/KXaBpRFCIir7XY0DZPn6IU0uFsJ+whDlJ82fT2ZhLTC4uoMDoJGltv6KzBc5F4wcjWKIwfe7l9o0t+UqQkbNxNbVgiRvUM43eqvRgG1cAcUaJxN3GZq1qq+MFf59lpe0R/4DveAvFAZC7snro+Y+QPkePeK7fFwD3X88XHStycay1Lx0wnZssiU0Y7T9ALl6rsJiZNUONtIUnorHq62Ekaa7qInS63FkM2jmRSmz1WqJdhG1gGQvf+Vdllsg6cbaC7Foie5L4Nyx2tCqJyUNtje1Hp0YBdqSqdViLcfRsFvoNGVBAkqNOWiaALTxLwKBzHbRy1QGxmOoECCgr1URICWX2PF3ovjNUC/Hv1fVQN8zDI9P93BXNNKkAYn3RvuVA8uSPCbWdNkGy0ek19A44laSeIZp0wUqHD+ZxYL5Y6L8+hPw8JufVlhn+Fv7+7vEDp1C4ABEr1ykELMEhrf56tg2dNkjljkCS9sy/PP8X8HfmnoQdF9lWIc2Q78e//XstZAJOINN6oXI+llbTwcB4rpMRfXmoD9owT9g5lOLgJ7evj5pPmBSBPErGQYXlt15/2df96X97elMUoKrdmTYscyptmA2dWaje0bgPweuP1RF6Ohuognici+2X3LTOGRUqLXbNxTSAwXaa5A6TY1rxGPSYHx6iZW7X7DmZVHK/Ekhh7wCiwdH+s2qQfWQMV4c8fBTt7mJgFH884hmjq7s+yFw2d6L0Ot+SWv9UkC0kFe79fGFPJkLla2iuNdsGIUpZR55YpVSkj9TCTBYgTSU1/CNsoFbPAQhgB9A= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR01MB7792.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(7416014)(1800799024)(376014)(366016)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pUg9bLrI1lzRGXYqqFA6HkEjGFeGJ0o7DoDZw3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O/UJ+5GGtcHzjxImB8w8lEiQN33Zi/1Mef86czTcTGi2ezYcdLUcfbY9g7BS8rlx7PviMJoqg7LqzKdRO3e/8WTtpb2spwmsy4PR9YaofwLmP8KlcSDPSHkuKQdYHs5tRLmq4Wz37vXf/hqHxNLpO4Ya76Fz5ugBmpRCREukGfTvpW/4dcbtDlJCpvlKGuKN/jj5eIC4dxCdTXaW9FPBs8Yo9z5yOMreVe9R1eGT30+oQDx4044S+dORSMI/apr68zdvEQhUPNSwxcfbOGVFQEC4bTld648IjHAwqLHs/AEFHTUARSvmBGCnHUnriBu0i1iXMJgnoAIerVJmre/JF2p3ypga7i22JFnIvd5/wWqkmmWI0lobP8ZBDwaORzfa/9a5JFC5SBYbZKr4IGCDHM0t3QNXZ4ag2fXGw4ObYczCn2y5KheSp1O2cbu2BR/Jqxn2Z7oj3yviNn1dktOmePygpdW6Pqz13sdRTE2YaRX2uEFFJd64fF5vqhUGbm1V+m1gqbuba8RMY/i+g4vA4= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e520e8f-94a1-474d-e5d0-08dc9fadfdb7 X-MS-Exchange-CrossTenant-AuthSource: LV2PR01MB7792.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 00:28:01.6374 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OtGTmKBzC/PVvLXuoaVqdtTlEiZP1HTpvh3TjYycCVZ1aMK+MTajqCborqZmwIBYLvgHxue28PP3HdTiBma8nJtCzwoIpP33nbbdnHc2/p6HKIayrj9CNPinug9oyS5q X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR01MB7986 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240708_172813_107720_10CEE443 X-CRM114-Status: GOOD ( 14.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On arm64 prior to commit 32697ff38287 ("arm64: vmemmap: Avoid base2 order of struct page size to dimension region"), the amdgpu driver could trip over the warning of: `WARN_ON((start < VMEMMAP_START) || (end > VMEMMAP_END));` in vmemmap_populate()[1]. After that commit, it becomes a translation fault and panic[2]. The cause is that the amdgpu driver allocates some unused space from iomem_resource and claims it as MEMORY_DEVICE_PRIVATE and devm_memremap_pages() it. An address above those backed by the arm64 vmemmap is picked. Limit request_free_mem_region() so that only addresses within the arch_get_mappable_range() can be chosen as device private addresses. [1]: Call trace: vmemmap_populate+0x30/0x48 __populate_section_memmap+0x40/0x90 sparse_add_section+0xfc/0x3e8 __add_pages+0xb4/0x168 pagemap_range+0x300/0x410 memremap_pages+0x184/0x2d8 devm_memremap_pages+0x30/0x90 kgd2kfd_init_zone_device+0xe0/0x1f0 [amdgpu] amdgpu_device_ip_init+0x674/0x888 [amdgpu] amdgpu_device_init+0x7bc/0xed8 [amdgpu] amdgpu_driver_load_kms+0x28/0x1c0 [amdgpu] amdgpu_pci_probe+0x194/0x580 [amdgpu] local_pci_probe+0x48/0xb8 work_for_cpu_fn+0x24/0x40 process_one_work+0x170/0x3e0 worker_thread+0x2ac/0x3e0 kthread+0xf4/0x108 ret_from_fork+0x10/0x20 [2]: Unable to handle kernel paging request at virtual address 000001ffa6000034 Mem abort info: ESR = 0x0000000096000044 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x04: level 0 translation fault Data abort info: ISV = 0, ISS = 0x00000044, ISS2 = 0x00000000 CM = 0, WnR = 1, TnD = 0, TagAccess = 0 GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 user pgtable: 4k pages, 48-bit VAs, pgdp=000008000287c000 [000001ffa6000034] pgd=0000000000000000, p4d=0000000000000000 Call trace: __init_zone_device_page.constprop.0+0x2c/0xa8 memmap_init_zone_device+0xf0/0x210 pagemap_range+0x1e0/0x410 memremap_pages+0x18c/0x2e0 devm_memremap_pages+0x30/0x90 kgd2kfd_init_zone_device+0xf0/0x200 [amdgpu] amdgpu_device_ip_init+0x674/0x888 [amdgpu] amdgpu_device_init+0x7a4/0xea0 [amdgpu] amdgpu_driver_load_kms+0x28/0x1c0 [amdgpu] amdgpu_pci_probe+0x1a0/0x560 [amdgpu] local_pci_probe+0x48/0xb8 work_for_cpu_fn+0x24/0x40 process_one_work+0x170/0x3e0 worker_thread+0x2ac/0x3e0 kthread+0xf4/0x108 ret_from_fork+0x10/0x20 Signed-off-by: D Scott Phillips --- Link to v1: https://lore.kernel.org/all/20240703210707.1986816-1-scott@os.amperecomputing.com/ Changes since v1: - Change from fiddling the architecture's MAX_PHYSMEM_BITS to checking arch_get_mappable_range(). kernel/resource.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index fcbca39dbc450..6f256aa0191b4 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1832,25 +1832,28 @@ static resource_size_t gfr_start(struct resource *base, resource_size_t size, if (flags & GFR_DESCENDING) { resource_size_t end; - end = min_t(resource_size_t, base->end, + end = min3(base->end, arch_get_mappable_range().end, (1ULL << MAX_PHYSMEM_BITS) - 1); return end - size + 1; } - return ALIGN(base->start, align); + return ALIGN(max_t(resource_size_t, base->start, + arch_get_mappable_range().start), align); } static bool gfr_continue(struct resource *base, resource_size_t addr, resource_size_t size, unsigned long flags) { + if (flags & GFR_DESCENDING) - return addr > size && addr >= base->start; + return addr > size && addr >= base->start && + addr >= arch_get_mappable_range().start; /* * In the ascend case be careful that the last increment by * @size did not wrap 0. */ return addr > addr - size && - addr <= min_t(resource_size_t, base->end, + addr <= min3(base->end, arch_get_mappable_range().end, (1ULL << MAX_PHYSMEM_BITS) - 1); }