From patchwork Fri Oct 11 14:56: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: 13832624 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 2AA31D0D7B3 for ; Fri, 11 Oct 2024 14:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 970106B00A0; Fri, 11 Oct 2024 10:56:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9202B6B00A2; Fri, 11 Oct 2024 10:56:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E7306B00A3; Fri, 11 Oct 2024 10:56:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 615856B00A0 for ; Fri, 11 Oct 2024 10:56:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 23224C0D0A for ; Fri, 11 Oct 2024 14:56:20 +0000 (UTC) X-FDA: 82661622246.02.8154DA1 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf26.hostedemail.com (Postfix) with ESMTP id 80025140017 for ; Fri, 11 Oct 2024 14:56:21 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZwSB1s73; spf=pass (imf26.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.179 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=1728658444; 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:references:dkim-signature; bh=nF9Cu1yFnAPbe7jbcVtURgq11ehq1BMyC9tPOtmnXf4=; b=NTF+t7EHq2umDiyGmrJ20JXArVNTDZLu2l/ZUziTRHhqiHOXRcCG3l50V2Z3I9YXH6fo+n m6790lStrqXk585e/ByzQpcKMixfChgMlDBbLi5wir9VO2670pRWDEkIZJDXYJH+Smh+av /fjj2wiZ42y9tVObPTbDBI63SLZm2fk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728658444; a=rsa-sha256; cv=none; b=E/HzvifiApykfNvEpAR0ZNH2LUOlmlEd+svY15tNiPhtNFfPWWlX1icIK3Q2IdpXbZ9Sej 3x+OKTBgk0smrM/lG/lJH2VT4DZnTs5/NjqU/qYtvfICYR7s7YhIm0h/bxoGtQHdqErMBf beOGbmL7YKGpH+RZU+v9lLYdE8izReI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZwSB1s73; spf=pass (imf26.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71df04d3cd1so1848775b3a.2 for ; Fri, 11 Oct 2024 07:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728658581; x=1729263381; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nF9Cu1yFnAPbe7jbcVtURgq11ehq1BMyC9tPOtmnXf4=; b=ZwSB1s73Us4uBeX7v1RMRCxP8II8sEVcT8Rya0w3C5b49kto16KYK6wpBlDN/9TsnA OOmN+Z7ibKFHDst7CyCJWmvT2ryUrzHxjaCTpef0Gw8pQISIe4zjecW4RhmKGDIA0i5Z F8qMv1eSJowdl3LqKWGQJXnYZz7HdZj/49l6Y5kvrtt6nPJdRrGGpsx1swVwTFR0XebK EtPpxR1jDgm2WiQc3x5X8S785Xulh/hQXcSPpuF6jC8QMsaFNATL0x2Cvp64Fl/e2Ym4 nfkY1LnDe1UT1IGWx2X35U4sdgHcMsG1W2okQ1b5YMNnE0TxKDyY6o/B/ul7FRsPOkMo NqsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728658581; x=1729263381; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nF9Cu1yFnAPbe7jbcVtURgq11ehq1BMyC9tPOtmnXf4=; b=wvkeSGTqeE89nGt5TKQaNGI/mjL8mLWu7psnFpgWpXt8SurkfiznIarfsgB/n5+gj4 pS8EaTW1ISKRKqlHa0q5IsBphyv7LHMS5EVctLqYJaRVi2vzHiboYSCiKTwRp/6CYA+x mtlyWptijbJznchCAHfuZDvQnyPtlRleHVEMTtf/CYLapIXeBvSW8FOz1ErpHUzTNxP0 xNc6MjMEVmWyWODl3SDJT7oJ0tnQ8aMjbAdpr/LLfJw0BO4RiyjDT2Ncr6BIsB2iwq3x ykneZLDj+Q71oVIB8VWORKe7G/229VlMgjXigeXVT/aUwPG8l5MuCwBwEfQpXnaZ4yBt felw== X-Gm-Message-State: AOJu0YyGATyo7/qsTI8NGNJnZTajzXZJacoOlP2Ts2tRqBH1ricwczEa 77LJhA3pXMPUwG/QBVQTkNcWgLKxXM6FWisrhlSkh6DHj3yoRW3FVw8UNA== X-Google-Smtp-Source: AGHT+IEXGk4fmDBJI2QlMnEoAr5L68GZy2LrPDTs+tXSqId4T0CHY5gRz/s/XHjy78yvizjoCrCv3w== X-Received: by 2002:a05:6a00:1954:b0:71e:13ac:d835 with SMTP id d2e1a72fcca58-71e37e4ff69mr5482147b3a.11.1728658581305; Fri, 11 Oct 2024 07:56:21 -0700 (PDT) Received: from dw-tp.. ([171.76.85.106]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2a9e979bsm2674320b3a.2.2024.10.11.07.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 07:56:20 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-mm@kvack.org Cc: linuxppc-dev@lists.ozlabs.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 v3 -next] cma: Enforce non-zero pageblock_order during cma_init_reserved_mem() Date: Fri, 11 Oct 2024 20:26:09 +0530 Message-ID: <054b416302486c2d3fdd5924b624477929100bf6.1728656994.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 80025140017 X-Stat-Signature: m5mw5iyg3kf1x3sg1oxdhwggdcs45wtc X-HE-Tag: 1728658581-921899 X-HE-Meta: U2FsdGVkX1+tcsGBBTN03PVMYXyg0IbOa5WTZWXSsVGtXv1nSRxTbzh/+EPSo/yGrLM8Pxh9r2ps+8XK+8xemtwEjHF8NFQveo838kdqjxmofMt2sGx0Th7OAYlTsFTYwcT/KfGBJ3cR09Z/Li8XSUDeGduk997DWtY/KmIbeNyvrIvxwk2vMBnsTc2/t02xEtP3Exxg0Yi6JckVhisnjT/bfvioF+jH12vLifrj2JcWAnHRen7+Y5N9M/LoBmdKvoq6n4+NNIxHLmuoFyOcGj6jZLEQG6WAFSCuGhOKTC03mxCQRLUwdCG8PGezNkSAM0PAmBjN63ouyA8PvaqwZLSE74Tl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a9jyYCoj1xHfKvuu8f6rSjulQOTTP8IeQ9lblCEb3yRQozKTfk2lW30AMgghp5j1pS7wG4mnQrShkLadPPdTY/HN+43aQm2a5RAWSaLgHtG7hIM14xA2GBd/9UOPEMT8VH7UCUylxRS 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(). Acked-by: David Hildenbrand Signed-off-by: Ritesh Harjani (IBM) Acked-by: Zi Yan Reviewed-by: Anshuman Khandual --- v2 -> v3: Separated the series into 2 as discussed in v2. [v2]: https://lore.kernel.org/linuxppc-dev/cover.1728585512.git.ritesh.list@gmail.com/ mm/cma.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.46.0 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;