From patchwork Wed Mar 9 17:51:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12775406 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 D02BDC433EF for ; Wed, 9 Mar 2022 18:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=Js5k6wDmGe6Sn5sJXKtlRyW0yBUq0DG5G6qUTOpJfz8=; b=o7HlMH4BfcKKlo GiGJEpCoHWG97PfbQrQuv4DVnlDRpw9jhIf0PhiWy68ikAGjg+mfodDxKABewdg8uKfVFvYE6Fq3Z ViRlf5YwGdJeczdvTRXd4oL/RGV6kiHJ1ujjmmARI1o1GHbLlBmFAE/0fx3A+Zor/u/NA3DrvXN73 rcdohede4PkxZRGbiv+D5kA1dxhqSbflX9ub3ZN9rXTCD+8XbyPn7U8rNVqut7ufZv4jjO+N19e6M +V48oXRqLhANj7r4tD/iM/HRb0TQqZdxZXs+3HqBzmwUSzR7UmV7TSgULzyfwM0uRgQP51qqBx/UI CB/c5JYcHCo8kaGWgmsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS0bM-009xKh-8e; Wed, 09 Mar 2022 17:59:57 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS0Su-009u1c-PI for linux-arm-kernel@lists.infradead.org; Wed, 09 Mar 2022 17:51:14 +0000 Received: by mail-pf1-x42d.google.com with SMTP id a5so2980565pfv.2 for ; Wed, 09 Mar 2022 09:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1yNYR6W1i4K4Ni/CEkCJxcHbOKXs3UUsttBs1JtTk6Y=; b=jIEsTXXHOL/3WBA46SZ+xVsvPUwVlvkPR83xqF364uw3fOstQEXIg7PNaRvulvK03A tKPuLIGHfMaA42450CMpl56T2/WUhVqfKsMsVxW7w94v2E/M75FTi9jPfBohjhDQhKxN 0zhPeP03dnynoqGZXLIevLRNA+3k+r8pKihok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1yNYR6W1i4K4Ni/CEkCJxcHbOKXs3UUsttBs1JtTk6Y=; b=ChcI6uVGWZQEol2FDjUc/s/g8BOl4jpsybp/rnXaB52XGr15/35GaR5G74nQZetohp BdefdXQ93ihWTI/2UTNDRao6zQ0uVCg/mg1W5KqhNrRY6KRA/PtuZbnAH/g0fvh+83yo 6JCwjXsJajRMX6C90fn1Hu/N/AopOZYN2TDw1L6wpWAR1zZFypT5sOE8C5pY5K67NX+O VxPDUIUroKUEBGtsczK09TuanZHrIVCe4vqEzwBD1tx/vWlkR0xITLJR+IEcTPNBa7QI l6PPbmVUAShpVHKpdblk8m5y75D7iXs55jIC/H4Zoq4ytuXpEybEU8CEkNjmUY+Slz1q ee7g== X-Gm-Message-State: AOAM532ti0GaZ8Svenw4dJEVggAkae5AprxB9BEJGkRi3SV1ZolWGJvk EmCfd0/Pb1Rz+HD1rrkhhlDgyQ== X-Google-Smtp-Source: ABdhPJyombZYcJq2FvqfjICN50veoCiqVO9vyey0648MfcJxzdmqQ7x8AAlHqzTHca5fJWquoks42g== X-Received: by 2002:a63:f50d:0:b0:374:5e19:d9cb with SMTP id w13-20020a63f50d000000b003745e19d9cbmr689622pgh.475.1646848271660; Wed, 09 Mar 2022 09:51:11 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z2-20020aa79902000000b004f75842c97csm3984234pff.209.2022.03.09.09.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Mar 2022 09:51:11 -0800 (PST) From: Kees Cook To: Russell King Cc: Kees Cook , Logan Gunthorpe , Martin Oliveira , David Hildenbrand , Andrew Morton , Stephen Rothwell , Zi Yan , Hari Bathini , Minchan Kim , Mike Kravetz , linux-arm-kernel@lists.infradead.org, Christoph Hellwig , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA Date: Wed, 9 Mar 2022 09:51:07 -0800 Message-Id: <20220309175107.195182-1-keescook@chromium.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2789; h=from:subject; bh=AxSCzKOCweLxS0BQOyfRE0iLV6xSDiEfJpdMxUbtuhE=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBiKOkKInLTtFRKbblukaLzGwFzn73QyxUhgMKDwRAe 0c/kqUmJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYijpCgAKCRCJcvTf3G3AJlseEA CTd4WlF7KPauHdT3S0Tjwsxt1nl1iXDAxf1QskpK9OdWeFkVkmj8YKNJTsm1GbBKwYqoZDOVRXXuEY KT13rBujSgJoo1RMwonHMObE+H+IAmDV2hVp4qoMlXSrFMlELpwOURU4DmSWJ/0L/bE8CpJAvkhTV6 w8ZYdA15XDW4fT3cfyQ/P52d1Hl3LC4iVFsUlSA3mgdtK6Che4uew9uwoaN+sg9gQRK3djU4li7rQY itE7rOeziJ8PA5bt5yD5qd2qqwbXNMzWQz+TphCQLbQxS4/KIQBG8TvchkYst9HC42UPPElblUOP+U XN76rxodQe/1uSZZFgML8zw8hcGfL5OLWeMQWA0umXjtvx0II3xn0gPpVGTZr3QMHuPID8onigj2EI wxGeyK3j8TSS3l09TL8TM7GBDiBErAbCXeLVMIVQA/Icrm9LoqYCM0divB0mZMjZ1hjj6hyyC4Tfvo XlOstkuVQD1LeetY8Z4+AvFvD5HmVwAMthTchqyreOXFivejFpYGDYWzIg6tVLyMSia52YCZzFwMRZ 5wv5+NCovMvvgldkhPzfcnHEYzIi3IK4jAIh9mOHoRmjBscb2jC/+UbwcYUHVL1x4nO+/AfGSh8J3c KietDv7g3gJuqwp9N5AlmeIUDTLEGg5fqIuCp2iYDIDGOr+UANBp24aWT7RA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220309_095112_868201_751C353C X-CRM114-Status: GOOD ( 17.59 ) 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 The MAX_CMA_AREAS could be set to 0, which would result in code that would attempt to operate beyond the end of a zero-sized array. If CONFIG_CMA is disabled, just remove this code entirely. Found when building with -Warray-bounds: arch/arm/mm/dma-mapping.c:396:22: warning: array subscript is outside array bounds of 'str uct dma_contig_early_reserve[0]' [-Warray-bounds] 396 | dma_mmu_remap[dma_mmu_remap_num].size = size; | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ arch/arm/mm/dma-mapping.c:389:40: note: while referencing 'dma_mmu_remap' 389 | static struct dma_contig_early_reserve dma_mmu_remap[MAX_CMA_AREAS] __initdata; | ^~~~~~~~~~~~~ Cc: Russell King Cc: Logan Gunthorpe Cc: Martin Oliveira Cc: David Hildenbrand Cc: Andrew Morton Cc: Stephen Rothwell Cc: Zi Yan Cc: Hari Bathini Cc: Minchan Kim Cc: Mike Kravetz Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- arch/arm/mm/dma-mapping.c | 2 ++ arch/arm/mm/mm.h | 4 ++++ include/linux/cma.h | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 4b61541853ea..82ffac621854 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -381,6 +381,7 @@ static int __init atomic_pool_init(void) */ postcore_initcall(atomic_pool_init); +#ifdef CONFIG_CMA_AREAS struct dma_contig_early_reserve { phys_addr_t base; unsigned long size; @@ -435,6 +436,7 @@ void __init dma_contiguous_remap(void) iotable_init(&map, 1); } } +#endif static int __dma_update_pte(pte_t *pte, unsigned long addr, void *data) { diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h index 9ff683612f2a..d7ffccb7fea7 100644 --- a/arch/arm/mm/mm.h +++ b/arch/arm/mm/mm.h @@ -88,6 +88,10 @@ extern phys_addr_t arm_lowmem_limit; void __init bootmem_init(void); void arm_mm_memblock_reserve(void); +#ifdef CONFIG_CMA_AREAS void dma_contiguous_remap(void); +#else +static inline void dma_contiguous_remap(void) { } +#endif unsigned long __clear_cr(unsigned long mask); diff --git a/include/linux/cma.h b/include/linux/cma.h index 90fd742fd1ef..a6f637342740 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -12,10 +12,6 @@ */ #ifdef CONFIG_CMA_AREAS #define MAX_CMA_AREAS (1 + CONFIG_CMA_AREAS) - -#else -#define MAX_CMA_AREAS (0) - #endif #define CMA_MAX_NAME 64