Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3785197rwl; Mon, 10 Apr 2023 00:36:35 -0700 (PDT) X-Google-Smtp-Source: AKy350YqZxx0ZaVyFi707kf8jKWOFJrZRcwyv0cePyY9EzrMgFyQEvy11unmBUJY0H6MstpdSHj8 X-Received: by 2002:a17:906:3710:b0:94a:62e7:70e1 with SMTP id d16-20020a170906371000b0094a62e770e1mr3203710ejc.68.1681112195223; Mon, 10 Apr 2023 00:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681112195; cv=none; d=google.com; s=arc-20160816; b=meqac97aUOPJT8yyTfoKpA8X4l60LG0lyVDEBzLN87n6WP7bPIcYcyd98JW7Os6Z9w NsTjEDxa8mD51GQXQ96FWe7ujgQyNJzm+KDeevFXKAhs4uEwbk4Jg/F7n0Nf7gfu/b7P I8TUjJMeNx+nKk5tsQpEv/OeiFIiBWl0BiBbd6yQeNLkbk/kpusvp40cvvQ96T6SbWbS 8R6ADJdCbLWZZK9cpnt70Tfrbue3MRYGHc6mtXE7yhW9jP5GpTNW/2uDlSpep+Ctk1ml vkXSwjFyJg7bcpqSFj7cXcZXbg/sjG9J0vKjZWJ34yc4pVDmGJnkRkcFKx/skJbkxtjR 4snQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=rsovILUPhHbLtudYoqSFmxIi68SG8tpj2BrJCHGqcIo=; b=rSs5UmId088tcdWl8zyDHe1gMTbFsNt8XyENOvM33It0akU+QxExZGLPyY+la8nf8u UHS1XvylUs1NL18n8oDA3aptdkA9/QZ10HGKaCXRA8V951tGWvG8SMl3WIubxew2Un5F rS2FsFRT0i8JOzmJjp0t1IJzw/VlGFYRwg3Z56ZIj/tBbeIXetC3eDqzb3N4M1zfDT0x eW6TQc6OltgPh9QrkO/NJprW6y3GSfv7IitAOo0y5VO8M4a4vVN31vrd54Rn0pU66CTY 8XuSME8HmLQBOyt/tUfAdS0QwtE/MnnpK/3dWeWGyl4V6gX0pICHOzftjkll2+zW4mcn +JUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="X4K6lcN/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb1-20020a1709071c8100b0094a90a26a74si1952696ejc.358.2023.04.10.00.36.11; Mon, 10 Apr 2023 00:36:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="X4K6lcN/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229764AbjDJHdV (ORCPT + 99 others); Mon, 10 Apr 2023 03:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjDJHdS (ORCPT ); Mon, 10 Apr 2023 03:33:18 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F5A74681 for ; Mon, 10 Apr 2023 00:33:09 -0700 (PDT) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230410073305epoutp0265331e9a3402d8b00ccaca6e3b4461be~UgnG6yaXK0452104521epoutp02h for ; Mon, 10 Apr 2023 07:33:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230410073305epoutp0265331e9a3402d8b00ccaca6e3b4461be~UgnG6yaXK0452104521epoutp02h 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 wUThigOXZ7E2MP7h72Lk5JAQMJGYtfM7exc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q9di0qpPNY9OnSewed67tYfM4MeM3i0ffllWMHp83yQVwRXHZpKTm ZJalFunbJXBlvF54jL1gonDFgcuzWBsY//B3MXJwSAiYSFw9Yd3FyMkhJLCbUeLU6jgQW0JA RuLN+acsECXCEocPF3cxcgGVfGWU2Nt8kwWkhk1AW+L9gkmsIAkRgdWMEh+e72EESTALVEr8 u32LFcQWFvCUWLSkEyzOIqAqse/pBiYQm1fAVuLAnpOMEMvkJVZvOMA8gZFnASPDKkbJ1ILi 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 Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230410073304epcas1p4cf3079b096994d69472b7801bd530bc7 References: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1