From patchwork Fri Oct 11 07:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13832168 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C7AACEDDBD for ; Fri, 11 Oct 2024 07:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD6596B0099; Fri, 11 Oct 2024 03:23:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5FBD6B009A; Fri, 11 Oct 2024 03:23:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB3E16B009B; Fri, 11 Oct 2024 03:23:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 863A86B0099 for ; Fri, 11 Oct 2024 03:23:34 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1B200120F1B for ; Fri, 11 Oct 2024 07:23:30 +0000 (UTC) X-FDA: 82660481106.29.0E39197 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf07.hostedemail.com (Postfix) with ESMTP id B955640007 for ; Fri, 11 Oct 2024 07:23:28 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iztMqpOz; spf=pass (imf07.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728631228; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cFXU0lQKXMNLX0e10iqDZMzQn21Hy9EUBSVtGclHKC0=; b=5HNJam+t+SAXTb1/U97uGdpfVWC9TFGYRVIVw0DOe/6SsvCF54gg7/Y4+h8gbgHsYzlqpl 2KwwtAY8vAaSdcpbqFCwnXd7zpBpfSNRJdh81ZUHmhdGsNzr0f98W+Y1uIS7yHCGUwO+ix Cfo6L7IYlnSxtUJfpBIn3IQgUHUUZlc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iztMqpOz; spf=pass (imf07.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728631228; a=rsa-sha256; cv=none; b=LT42FrY4Jg5eg8r8kJVctil/ZQawZZJZr2y8oAYn5QzQxXlvYsD+aOBfXQOEY+wWQIQZwL IY2OlpIb1marVvygWi1SD+zwHswBKSTGrBL+AxSPgeiBvC+AyMYr4I2taZ1GCmhWJVATLO 485+Sb+nmQoxNrSqWVL5yzisH6mCqDU= Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20c544d34bcso16337825ad.1 for ; Fri, 11 Oct 2024 00:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728631411; x=1729236211; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cFXU0lQKXMNLX0e10iqDZMzQn21Hy9EUBSVtGclHKC0=; b=iztMqpOzHMmWZkhctzxzbRNuNUDFgXDGFkZT/Q0kHFeqfDWEQeNA8AGGbXeN7IVeur adgcjutSU73JXgtvxJ8URNxso1TADjDYL97YqW/BK6+eZdpaoHTVtzDAkw0hHZFCes7d hTbipKMh7/BJtVU3vo8rhbIkgNXp/zQEVw1Ku+VtgEGKSxDo3vKYaZsRxxtWfjk9MrRA z+o63Ncs3bUAkhemlTY7CmEEfBm4m/96kDivrwqJZvssrc/HWnwbvtrt/4J6O+g1hd/a ovLiMnuidIRx99ogKUbQ7v9IAB8iOliiq9cHjAWV0QBvAEl6rYCaPEFtaVI7C9wwkNfq TTRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631411; x=1729236211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cFXU0lQKXMNLX0e10iqDZMzQn21Hy9EUBSVtGclHKC0=; b=dgjaFX63ZZcvO+X5hVuhWPx6950spt27Dg7ApM3k+iEFiHxQGWW/wyvAvVx3SzY0xZ T7XaXm8QH84B5Lr1k9+4F252LGLfy1X5DfgUoh1oSmV75TAGJVbDeU4JAXRdLmJZGRRr ggoXuoPKgYAGAY/9gVBQ13DeK6gtxP7tr/WJm6PWbikPTrzpZVT/N8LQg/1GrM+W2LGs JxgmO+zcyobQnQX4KE8EG3V26yR5x89w2WRSxRDDW6kG/6Xm1WcHBrhclH7yTYtEIUNb xv4kpTCbD05C5DY6visNoAoxejsarYx2qY9Sd8vgPs4rFpD+UKqTlmV395JmswLPP9yc E9EQ== X-Gm-Message-State: AOJu0Yzklj73enmlZbjvBmFMS5pfMMaMcG39f+raxryQDYUHteIQe4NZ 5T89kisDIzjrOuo7UffU+P0m/C0TKW67cZdc5RXNwyD3eUYGGPb3 X-Google-Smtp-Source: AGHT+IGQ8iq1sir1NebxPCSK/DS4CJ2zGOXIXoa+HRwjhD+gjsmYWNAElhY1mGxdYNMN7u4TdJpehw== X-Received: by 2002:a17:902:d2c8:b0:206:96bf:b0cf with SMTP id d9443c01a7336-20ca1315240mr25369385ad.0.1728631410877; Fri, 11 Oct 2024 00:23:30 -0700 (PDT) Received: from dw-tp.ibmuc.com ([49.205.218.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8bad335dsm18825155ad.50.2024.10.11.00.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 00:23:30 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: linux-mm@kvack.org, Sourabh Jain , Hari Bathini , Zi Yan , David Hildenbrand , "Kirill A . Shutemov" , Mahesh J Salgaonkar , Michael Ellerman , Madhavan Srinivasan , "Aneesh Kumar K . V" , Donet Tom , LKML , Sachin P Bappalige , "Ritesh Harjani (IBM)" Subject: [RFC v2 1/4] cma: Enforce non-zero pageblock_order during cma_init_reserved_mem() Date: Fri, 11 Oct 2024 12:53:09 +0530 Message-ID: <8579f887412720bd6f2fbce513c1c9904772ead4.1728585512.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B955640007 X-Stat-Signature: sjhb9n79ytf1jkj9uq1qqifycqyeoi1b X-Rspam-User: X-HE-Tag: 1728631408-97627 X-HE-Meta: U2FsdGVkX18FXjJHWphfOnHxPVGWUb8rMDoWamLoTObVoV7PMbej4R9W8O7azbbaTtoC3mYt+phmXDj9kVhz7WPOKaRs4pqjHL9L+M1+38uYE13pW6RlVE60hZ4+livIY/POwCHNPknHa/ylTcOdfBjaLaH0C7L94iNpS1Wbv22+kvTHf5Ab70hVSdZKqm9KbgYf1BWwh+6yr3SLsS6g5jcfl2BMrQGKyNEt2vEDF9O0o7Hea7m3U121uFWtOxftdZMxLU4AjQuBSA/0b+MhaaZvEnXx9mbmORjmzd7EkV53tqcpKoL0z/UlI5L9hPSb2DZHeys76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DSeRxeT1KP/plSo0xSS0oJZ6jRooZicW6nrDgZSksmhxJmfuYH3RS2cZTxzidD4KbYBvtHahOGhCjoY/IS3sPDfCmZ6MzVo5FpyjqeE+BfYZrF+prHdA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: cma_init_reserved_mem() checks base and size alignment with CMA_MIN_ALIGNMENT_BYTES. However, some users might call this during early boot when pageblock_order is 0. That means if base and size does not have pageblock_order alignment, it can cause functional failures during cma activate area. So let's enforce pageblock_order to be non-zero during cma_init_reserved_mem(). Signed-off-by: Ritesh Harjani (IBM) Acked-by: David Hildenbrand --- mm/cma.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index 3e9724716bad..36d753e7a0bf 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -182,6 +182,15 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, if (!size || !memblock_is_region_reserved(base, size)) return -EINVAL; + /* + * CMA uses CMA_MIN_ALIGNMENT_BYTES as alignment requirement which + * needs pageblock_order to be initialized. Let's enforce it. + */ + if (!pageblock_order) { + pr_err("pageblock_order not yet initialized. Called during early boot?\n"); + return -EINVAL; + } + /* ensure minimal alignment required by mm core */ if (!IS_ALIGNED(base | size, CMA_MIN_ALIGNMENT_BYTES)) return -EINVAL;