From patchwork Mon Apr 10 07:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13206121 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 94A08C76196 for ; Mon, 10 Apr 2023 07:33:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEC48280004; Mon, 10 Apr 2023 03:33:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9CF3280002; Mon, 10 Apr 2023 03:33:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3D2A280004; Mon, 10 Apr 2023 03:33:14 -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 A3E64280002 for ; Mon, 10 Apr 2023 03:33:14 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 543E5120914 for ; Mon, 10 Apr 2023 07:33:14 +0000 (UTC) X-FDA: 80664665508.26.B532B7B Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 7F77F180016 for ; Mon, 10 Apr 2023 07:33:09 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="X4K6lcN/"; spf=pass (imf16.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681111990; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=rsovILUPhHbLtudYoqSFmxIi68SG8tpj2BrJCHGqcIo=; b=I5Q0duqMxfvWX5D31yXshMziTMKlTYf8w9T/iCU7kfIImDyasUvz8l3KyN4xDHO7RS5v2F mkw/O8PDaRMOHNjkCWh2jrcYuOhMQzDiTPnxgkKJZBbkeclXyOCwuYjXD00N/Su0ns8QeM pZu1x6CQGVO2m9/H14dQSG0Qd+FMCkU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="X4K6lcN/"; spf=pass (imf16.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681111990; a=rsa-sha256; cv=none; b=6L3AQdVTX1FaBaxVQ4lVQe0tibD8Lkvm409t7eAftmaDOZnYhsCIiG+JwDNGEGN5vtnrEt 5J2PKj/CCCKHxxqkgJAIBqNgnXr7W3IZzg803Pr9ofD00COsUHCE730fm42pYpkke50UZ5 LyXa6ogqqLq8Wy915gE24XnjfdVAt60= Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230410073305epoutp047bfdd5a6ca92afc5e1ffe2f68eae29e5~UgnG69Lgj0285802858epoutp04E for ; Mon, 10 Apr 2023 07:33:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230410073305epoutp047bfdd5a6ca92afc5e1ffe2f68eae29e5~UgnG69Lgj0285802858epoutp04E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1681111985; bh=rsovILUPhHbLtudYoqSFmxIi68SG8tpj2BrJCHGqcIo=; h=From:To:Cc:Subject:Date:References:From; b=X4K6lcN/ThscWXzHQHEgA9rR1MaSlyLT8OPbyCX0+oSnDqftrsRN3QI+5zScQKgQ5 Mn07rzGNqDkMqjVEr1l4uYjKylZnPWiTKJNCOTG+BwOxPTDjJRnbDU7eoWrwY4jvNb Ja45GZeHTcXWrqMlrv7bK8oxJTLDyFQ2nE1LqQ8E= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20230410073305epcas1p1dbe8fad5b60877dd55eec55de5fe16b7~UgnGT_QVk1604316043epcas1p1B; Mon, 10 Apr 2023 07:33:05 +0000 (GMT) Received: from epsmges1p2.samsung.com (unknown [182.195.38.242]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4Pw10c66DJz4x9Q1; Mon, 10 Apr 2023 07:33:04 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 19.89.09668.0BBB3346; Mon, 10 Apr 2023 16:33:04 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20230410073304epcas1p4cf3079b096994d69472b7801bd530bc7~UgnFoBuv30391403914epcas1p4K; Mon, 10 Apr 2023 07:33:04 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230410073304epsmtrp22cd48a4a910597eaa22087d210333409~UgnFm9uQK2134621346epsmtrp2I; Mon, 10 Apr 2023 07:33:04 +0000 (GMT) X-AuditID: b6c32a36-b27fa700000025c4-04-6433bbb04d35 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id AC.2F.08279.0BBB3346; Mon, 10 Apr 2023 16:33:04 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.104.99]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230410073304epsmtip299d48e8026f4ea3095fdf54964a1c621~UgnFX_4kM1803118031epsmtip23; Mon, 10 Apr 2023 07:33:04 +0000 (GMT) From: Jaewon Kim To: jstultz@google.com, tjmercier@google.com, sumit.semwal@linaro.org, daniel.vetter@ffwll.ch, akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH v3] dma-buf/heaps: system_heap: avoid too much allocation Date: Mon, 10 Apr 2023 16:32:28 +0900 Message-Id: <20230410073228.23043-1-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFKsWRmVeSWpSXmKPExsWy7bCmge6G3cYpBjN36lvMWb+GzWLhw7vM Fqs3+Vp0b57JaNH7/hWTxZ8TG9ksLu+aw2Zxb81/VovX35YxW5y6+5nd4t36L2wO3B6H37xn 9tj7bQGLx85Zd9k9Fmwq9di0qpPNY9OnSewed67tYfM4MeM3i0ffllWMHp83yQVwRWXbZKQm pqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoqufgE6Lpl5gBdrKRQlphTChQK SCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fLSy2xMjQwMDIFKkzIzni98Bh7 wUThigOXZ7E2MP7h72Lk5JAQMJGYtfM7excjF4eQwA5GiUsT57BAOJ8YJY5dfsUM4XxjlFh7 4z+QwwHWcvWENUR8L6PEjemvoYq+M0q8vtfFCjKXTUBb4v2CSawgCRGBxYwSb258YQZJMAuU Srx9cwLMFhbwlFi0pJMRxGYRUJXY93QDE4jNK2ArcWDPSUaIA+UlVm84ALZBQuAru8TuORPY IRIuEhd2HWaCsIUlXh3fAhWXkvj8bi8bhJ0vceHiKyaIs2skFk40hAjbS+z6OoMVJMwsoCmx fpc+RFhRY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ILi 3PTcYsMCw7zUcr3ixNzi0rx0veT83E2M4MDU0tzBuH3VB71DjEwcjIcYJTiYlUR4bbgNUoR4 UxIrq1KL8uOLSnNSiw8xSnOwKInzXug6GS8kkJ5YkpqdmlqQWgSTZeLglGpgms3av7DKIvLW R3M3ha23Qy8pPg3hXr346w2PX+KbBFXUvSRXvkgUzHK6Z2Iit/xikuGJzvbj9g7q07gDF7F4 OCnXT/l+7K7i8yaWxA27ovc1fZfZUD4pnr/ui+rZqckeqxiiZZqPv36ydG6cVszKHysYv72V vFFpXzrZTEFm5YWnzyOuFTe9uuNuwGl0xfH3YsnpxcUuWn9+3o3zUXhjIZN5WGZlAN/8Qr4H jF1P1895/lGuQVVL4cQTf4cZ7nzlkRxCYZ/kD8erx96a8rreIP6w8PrH8yeqrk05//bKk+iC lV+kDqmqb114wtC/8nkKt7/5InutL/K2Lfc7fjw79Gf/011MbqyX0pS27772WYmlOCPRUIu5 qDgRAE6zmym7AgAA X-CMS-MailID: 20230410073304epcas1p4cf3079b096994d69472b7801bd530bc7 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230410073304epcas1p4cf3079b096994d69472b7801bd530bc7 References: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7F77F180016 X-Rspam-User: X-Stat-Signature: wmngmyg5g59oguywhkgnaoudffefx6y8 X-HE-Tag: 1681111989-650946 X-HE-Meta: U2FsdGVkX1+cfaVLu0hx46Y0VOmEisBUGhEt4sMgWprPhZTk5JG60zMhceRKHcshumVRNXmS2jWsmRRIji4A2MFTLGpb6O/yXaScvrgIg89kzg1AoLSzBI/fx7MakCiU5tfOag+p35R5Dym9sF7bOQrueZbESqxQsAHHaf1qOyyEkeqq5/Oi0nA2pms46uw4koPw6hWvsOlmsIfKgO5DoEJsMH8MFcipVyOhunvVWCgOWYztjFtsm0XBRJKFGMa3KIxzOnVhZPkqFpieye4bl3ySuOCOA1WyoSIoUkFSvOySP15YNWj6O6PWvLOsg1OYZXsNpWR4tzQrsKwOX5DoNdKhYw7VzCrVQKXX2b985OelXXQP2560/Pb5Y95CbuLkjEMIBKU30t1aCTlwsR30STbC/nJ7pdIboYr2o7eY2FK0vg97l1DHwxt/j14OOmeysLKb80TXZzvdkxzW/VB6gyFvhge5q+zTWo1PmUjR77GoSFVR4/4YMKVFLukzVaUvBMgN4Ujo/6TRTKbk5lCSSPlEqVWYj4V53BApPJH162WTq2aOfSQnq300x3upRdZ+FhksKzRPC5plYRZrjM8mv/ZzTVtIZOiLZOc3CRjJCmaSEGErDxbNQO/j7Wnz03i65raZ8Y9sJn2XZS0NvzVQ5vv7sF3I6bRor9ykoFqI7h9Q86kiKux7+SeR7NNIKVdsNV+j8x+PHK7i3smWBu5GL9f2GVfuCMnJqOyrIFvtA5fo5QQfEv01WT/j7mPgHN+uSChWksvPIW0m8P4O3r1LUn37+cbSw19JRw/kOnI2CxUasUR/deZ5BDDZCpntdMUJi8PrgUpMU0y1rRjYwyfYhvrpZoQfbIkTya+sPwYPXS7ujyffAadtawDeftUAojr5yFi7bcKryJSiRWbtV2Ew/7tjhSqmbRCOia+XPZ6j/a0QZzGafpILzO5O/ZEOWpnbff5VV2YZ5xB1RvFnuMN jqw3euvZ kSVFnfBMTXgYRwa+DsVwYBUkNWmSLxKtqdSRgQGmS2GFCrab8cVwzNxl9J67EqG0cZXv156CLeToMnwCl4hKSIChSmCTsc7IsQfIv/1EYpqDzr1ds45nZRzO86S1Ap4daOrQandH/ni/VaIaZ2qYupfe64PCx9Fx3462+xe/bt3BZUPmSbx+6JAw3ySmlNLoepM/O1OVWIMtuhXUAY4R28Md1W1plNeiJ+SiDKThy35tHkJwRB6FFO7DCQOsg44csLf45blQrEFG5EHg= 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: Normal free:212600kB min:7664kB low:57100kB high:106536kB reserved_highatomic:4096KB active_anon:276kB inactive_anon:180kB active_file:1200kB inactive_file:0kB unevictable:2932kB writepending:0kB present:4109312kB managed:3689488kB mlocked:2932kB pagetables:13600kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:200844kB Out of memory and no killable processes... Kernel panic - not syncing: System is deadlocked on memory An OoM panic was reported. The log shows there were only native processes which are non-killable as OOM_SCORE_ADJ_MIN. After looking into the dump, I've found the dma-buf system heap was trying to allocate a huge size. It seems to be a signed negative value. dma_heap_ioctl_allocate(inline) | heap_allocation = 0xFFFFFFC02247BD38 -> ( | len = 0xFFFFFFFFE7225100, To avoid this invalid request, check if the requested size is bigger than system total memory. Actually the old ion system heap had similar policy with commit c9e8440eca61 ("staging: ion: Fix overflow and list bugs in system heap"). Even with this sanity check, there is still risk of too much allocations from the system_heap. Allocating multiple big size buffers may cause oom. Add __GFP_RETRY_MAYFAIL. With this gfp, the allocation may fail, but we can avoid oom panic. Signed-off-by: Jaewon Kim Acked-by: John Stultz Reviewed-by: T.J. Mercier --- drivers/dma-buf/heaps/system_heap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 920db302a273..583da8948679 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -41,7 +41,7 @@ struct dma_heap_attachment { bool mapped; }; -#define LOW_ORDER_GFP (GFP_HIGHUSER | __GFP_ZERO) +#define LOW_ORDER_GFP (GFP_HIGHUSER | __GFP_ZERO | __GFP_RETRY_MAYFAIL) #define HIGH_ORDER_GFP (((GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN \ | __GFP_NORETRY) & ~__GFP_RECLAIM) \ | __GFP_COMP) @@ -350,6 +350,9 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, struct page *page, *tmp_page; int i, ret = -ENOMEM; + if (len / PAGE_SIZE > totalram_pages()) + return ERR_PTR(-ENOMEM); + buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) return ERR_PTR(-ENOMEM);