From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA461C4332F for ; Thu, 13 Jan 2022 12:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234814AbiAMM55 (ORCPT ); Thu, 13 Jan 2022 07:57:57 -0500 Received: from mga09.intel.com ([134.134.136.24]:35525 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234818AbiAMM5x (ORCPT ); Thu, 13 Jan 2022 07:57:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642078673; x=1673614673; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=iycjm2C+Mf7QsOANPLMYnMeG7Nklub2C0BsuRJJMnhc=; b=jJaTHLTlG0OEH0zaRjpsLlQH+DyQNr0GXLCZYehDZZDSYYusknLhP+Jx 8kB9plpM8nWZdADWsMkC5ytTLBgiAmuXWhJjxO6oTgeKcvWW5IBNoEGqB IrSwW+1VsXsU9iWCgKOGGXz51JNJ8/40upNCVq5u/FdDze4eXo4yYPGPX SKQ/DB02yx/X1Zfip2DTfNGaZLeiFxZtmSANgxJRuTtyYXYzk2hOqXG8s 9L6W5Nfah3I0WmcifJ3iKJdK9+adGXo4J6UZZuEcc8YjyNQuYuiNJ5aqk S3yV7rlLtD3g8pnAXMMwFroM6YW8cgt77eEZtFsdEmvQpsiO8XRCDTx+3 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="243798547" X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="243798547" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 04:57:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="691791936" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga005.jf.intel.com with ESMTP; 13 Jan 2022 04:57:52 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com ([10.22.229.24]) by ORSMSX611.amr.corp.intel.com ([10.22.229.24]) with mapi id 15.01.2308.020; Thu, 13 Jan 2022 04:57:51 -0800 From: "Ruhl, Michael J" To: "guangming.cao@mediatek.com" , "sumit.semwal@linaro.org" CC: "linux-arm-kernel@lists.infradead.org" , "mingyuan.ma@mediatek.com" , "wsd_upstream@mediatek.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linaro-mm-sig@lists.linaro.org" , "yf.wang@mediatek.com" , "libo.kang@mediatek.com" , "benjamin.gaignard@linaro.org" , "bo.song@mediatek.com" , "matthias.bgg@gmail.com" , "linux-mediatek@lists.infradead.org" , "lmark@codeaurora.org" , "labbott@redhat.com" , "christian.koenig@amd.com" , "jianjiao.zeng@mediatek.com" , "linux-media@vger.kernel.org" Subject: RE: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Topic: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Index: AQHYCHnKJjUnVmCmlECrXD1d8qRuLKxg6T0Q Date: Thu, 13 Jan 2022 12:57:51 +0000 Message-ID: <4f88205c1b344aea8608960e2f85b8f4@intel.com> References: <20220113123406.11520-1-guangming.cao@mediatek.com> In-Reply-To: <20220113123406.11520-1-guangming.cao@mediatek.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 x-originating-ip: [10.1.200.100] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >-----Original Message----- >From: dri-devel On Behalf Of >guangming.cao@mediatek.com >Sent: Thursday, January 13, 2022 7:34 AM >To: sumit.semwal@linaro.org >Cc: linux-arm-kernel@lists.infradead.org; mingyuan.ma@mediatek.com; >Guangming ; >wsd_upstream@mediatek.com; linux-kernel@vger.kernel.org; dri- >devel@lists.freedesktop.org; linaro-mm-sig@lists.linaro.org; >yf.wang@mediatek.com; libo.kang@mediatek.com; >benjamin.gaignard@linaro.org; bo.song@mediatek.com; >matthias.bgg@gmail.com; linux-mediatek@lists.infradead.org; >lmark@codeaurora.org; labbott@redhat.com; christian.koenig@amd.com; >jianjiao.zeng@mediatek.com; linux-media@vger.kernel.org >Subject: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation > >From: Guangming > >Add a size check for allocation since the allocation size is >always less than the total DRAM size. > >Without this check, once the invalid size allocation runs on a process tha= t >can't be killed by OOM flow(such as "gralloc" on Android devices), it will >cause a kernel exception, and to make matters worse, we can't find who are >using >so many memory with "dma_buf_debug_show" since the relevant dma-buf >hasn't exported. > >To make OOM issue easier, maybe need dma-buf framework to dump the >buffer size >under allocating in "dma_buf_debug_show". > >Signed-off-by: Guangming >Signed-off-by: jianjiao zeng >--- >v3: 1. update patch, use right shift to replace division. > 2. update patch, add reason in code and commit message. >v2: 1. update size limitation as total_dram page size. > 2. update commit message >--- > drivers/dma-buf/dma-heap.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > >diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c >index 56bf5ad01ad5..1fd382712584 100644 >--- a/drivers/dma-buf/dma-heap.c >+++ b/drivers/dma-buf/dma-heap.c >@@ -55,6 +55,16 @@ static int dma_heap_buffer_alloc(struct dma_heap >*heap, size_t len, > struct dma_buf *dmabuf; > int fd; > >+ /* >+ * Invalid size check. The "len" should be less than totalram. >+ * >+ * Without this check, once the invalid size allocation runs on a proces= s >that >+ * can't be killed by OOM flow(such as "gralloc" on Android devices), it >will >+ * cause a kernel exception, and to make matters worse, we can't find >who are using >+ * so many memory with "dma_buf_debug_show" since the relevant >dma-buf hasn't exported. >+ */ >+ if (len >> PAGE_SHIFT > totalram_pages()) If your "heap" is from cma, is this still a valid check? M >+ return -EINVAL; > /* > * Allocations from all heaps have to begin > * and end on page boundaries. >-- >2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 1431AC433EF for ; Thu, 13 Jan 2022 12:57:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45A8410FB51; Thu, 13 Jan 2022 12:57:54 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id F031410FB4B for ; Thu, 13 Jan 2022 12:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642078672; x=1673614672; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=iycjm2C+Mf7QsOANPLMYnMeG7Nklub2C0BsuRJJMnhc=; b=ni5R2nlehrpoAQSDhBaLinXVBoWcMIMrR6nHCJElpinvysZ8Ei5K0wC5 7UpeCUvCEXieHLxWDk3rWvLluJSLU7x9kzPo/3W/EJT7QUMNjyvpcDXgh Uv3NAtwjK5sssAdk2HMIZsZeWk2y1zCiKPcSHR2VVmHmvAto60dt0XOmU I+fBrec6SCgvGlpECOEUfmdGum6Je5BriZR+Ux80HTJqUR95dDA5crKiT TKmEqNVUqsvWCOj0FQihnEE6yxrloDAWGG8/TVg8USsci7e+Gz+lBv1vt MwJQ09PGKvYjE9ttlTP39RylZCmm+iHHdY3CY0QQmj9NBMi9NZzO6MvM1 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="224690091" X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="224690091" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 04:57:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="691791936" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga005.jf.intel.com with ESMTP; 13 Jan 2022 04:57:52 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com ([10.22.229.24]) by ORSMSX611.amr.corp.intel.com ([10.22.229.24]) with mapi id 15.01.2308.020; Thu, 13 Jan 2022 04:57:51 -0800 From: "Ruhl, Michael J" To: "guangming.cao@mediatek.com" , "sumit.semwal@linaro.org" Subject: RE: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Topic: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Index: AQHYCHnKJjUnVmCmlECrXD1d8qRuLKxg6T0Q Date: Thu, 13 Jan 2022 12:57:51 +0000 Message-ID: <4f88205c1b344aea8608960e2f85b8f4@intel.com> References: <20220113123406.11520-1-guangming.cao@mediatek.com> In-Reply-To: <20220113123406.11520-1-guangming.cao@mediatek.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 x-originating-ip: [10.1.200.100] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "jianjiao.zeng@mediatek.com" , "lmark@codeaurora.org" , "wsd_upstream@mediatek.com" , "christian.koenig@amd.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "yf.wang@mediatek.com" , "linaro-mm-sig@lists.linaro.org" , "linux-mediatek@lists.infradead.org" , "libo.kang@mediatek.com" , "benjamin.gaignard@linaro.org" , "bo.song@mediatek.com" , "matthias.bgg@gmail.com" , "labbott@redhat.com" , "mingyuan.ma@mediatek.com" , "linux-arm-kernel@lists.infradead.org" , "linux-media@vger.kernel.org" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" >-----Original Message----- >From: dri-devel On Behalf Of >guangming.cao@mediatek.com >Sent: Thursday, January 13, 2022 7:34 AM >To: sumit.semwal@linaro.org >Cc: linux-arm-kernel@lists.infradead.org; mingyuan.ma@mediatek.com; >Guangming ; >wsd_upstream@mediatek.com; linux-kernel@vger.kernel.org; dri- >devel@lists.freedesktop.org; linaro-mm-sig@lists.linaro.org; >yf.wang@mediatek.com; libo.kang@mediatek.com; >benjamin.gaignard@linaro.org; bo.song@mediatek.com; >matthias.bgg@gmail.com; linux-mediatek@lists.infradead.org; >lmark@codeaurora.org; labbott@redhat.com; christian.koenig@amd.com; >jianjiao.zeng@mediatek.com; linux-media@vger.kernel.org >Subject: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation > >From: Guangming > >Add a size check for allocation since the allocation size is >always less than the total DRAM size. > >Without this check, once the invalid size allocation runs on a process tha= t >can't be killed by OOM flow(such as "gralloc" on Android devices), it will >cause a kernel exception, and to make matters worse, we can't find who are >using >so many memory with "dma_buf_debug_show" since the relevant dma-buf >hasn't exported. > >To make OOM issue easier, maybe need dma-buf framework to dump the >buffer size >under allocating in "dma_buf_debug_show". > >Signed-off-by: Guangming >Signed-off-by: jianjiao zeng >--- >v3: 1. update patch, use right shift to replace division. > 2. update patch, add reason in code and commit message. >v2: 1. update size limitation as total_dram page size. > 2. update commit message >--- > drivers/dma-buf/dma-heap.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > >diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c >index 56bf5ad01ad5..1fd382712584 100644 >--- a/drivers/dma-buf/dma-heap.c >+++ b/drivers/dma-buf/dma-heap.c >@@ -55,6 +55,16 @@ static int dma_heap_buffer_alloc(struct dma_heap >*heap, size_t len, > struct dma_buf *dmabuf; > int fd; > >+ /* >+ * Invalid size check. The "len" should be less than totalram. >+ * >+ * Without this check, once the invalid size allocation runs on a proces= s >that >+ * can't be killed by OOM flow(such as "gralloc" on Android devices), it >will >+ * cause a kernel exception, and to make matters worse, we can't find >who are using >+ * so many memory with "dma_buf_debug_show" since the relevant >dma-buf hasn't exported. >+ */ >+ if (len >> PAGE_SHIFT > totalram_pages()) If your "heap" is from cma, is this still a valid check? M >+ return -EINVAL; > /* > * Allocations from all heaps have to begin > * and end on page boundaries. >-- >2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 6E52DC433F5 for ; Thu, 13 Jan 2022 12:59:17 +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:In-Reply-To:References: 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: List-Owner; bh=pZKykl6rTxUa64xHAvAqTpV6O1Sje66RHgArWTF88SE=; b=g6JYFMZRJnqmUI 2Fc2xi9/ahPNSvfSGNcEx4Bqs+EQljeGaBJjyLxr8ZMt7WgQk2b5wGmecdK1iGuqrim+8yKdXqgty xjB+cK+hYqgiqkH9Ab3Iiyc1MKC/RYNxnJPLOXSQm+8JhtVnzQHw99Rfx62g/1R0RkoMrvcHno+xJ Xj+weG6F2GeVmljdWHHp84CgQAYLokIaUhklhUJcLyoVMj3oAx2L0HZV6L/nl7MONQoPM5kcphThT b0oVY9qt39PiK8AhMX05cg4nNaBQnigmdPQRVpnusAfZRj69H/xlkZJj6L1S169BbTEUEtPj69haN oxvHC5ocuxM3LkEVaZKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7zh7-005ypN-Gu; Thu, 13 Jan 2022 12:59:09 +0000 Received: from mga12.intel.com ([192.55.52.136]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7zfv-005yS4-8G; Thu, 13 Jan 2022 12:57:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642078675; x=1673614675; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=iycjm2C+Mf7QsOANPLMYnMeG7Nklub2C0BsuRJJMnhc=; b=IwQYXJRlETiq21CGn7bs86++TkahFiU5lR9elaqwp88EAFEC9ob2M5js uR/kgre9UFSIHy6AmJxL3xZMiAPEkPaXaqOERaPNxJO8lmathLXsnDGUk sZYyS1GrRBy78CDaSVWfkSVXGcgyQz83ghFiTO9WOMwwTul5fuCNydkre qNcM3tmbVP8a0XLVZK2wH99qSBS2GtxNGc5koVBvWloUjFCLeLGh/4UC3 qN6chg3tsKmDj1iZ5ZqvrpMIJOI2ACk0mgKlEQ0RZzOFRZ/5bfZIXCwG6 Q0UOUrfG8xjgjnTgS3xc37uc/cpBOySS2ZD47faf+HC7TZOJCXOfCtJA9 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="223982892" X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="223982892" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 04:57:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="691791936" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga005.jf.intel.com with ESMTP; 13 Jan 2022 04:57:52 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com ([10.22.229.24]) by ORSMSX611.amr.corp.intel.com ([10.22.229.24]) with mapi id 15.01.2308.020; Thu, 13 Jan 2022 04:57:51 -0800 From: "Ruhl, Michael J" To: "guangming.cao@mediatek.com" , "sumit.semwal@linaro.org" CC: "linux-arm-kernel@lists.infradead.org" , "mingyuan.ma@mediatek.com" , "wsd_upstream@mediatek.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linaro-mm-sig@lists.linaro.org" , "yf.wang@mediatek.com" , "libo.kang@mediatek.com" , "benjamin.gaignard@linaro.org" , "bo.song@mediatek.com" , "matthias.bgg@gmail.com" , "linux-mediatek@lists.infradead.org" , "lmark@codeaurora.org" , "labbott@redhat.com" , "christian.koenig@amd.com" , "jianjiao.zeng@mediatek.com" , "linux-media@vger.kernel.org" Subject: RE: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Topic: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Index: AQHYCHnKJjUnVmCmlECrXD1d8qRuLKxg6T0Q Date: Thu, 13 Jan 2022 12:57:51 +0000 Message-ID: <4f88205c1b344aea8608960e2f85b8f4@intel.com> References: <20220113123406.11520-1-guangming.cao@mediatek.com> In-Reply-To: <20220113123406.11520-1-guangming.cao@mediatek.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 x-originating-ip: [10.1.200.100] MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220113_045755_364300_186229F7 X-CRM114-Status: GOOD ( 12.77 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org >-----Original Message----- >From: dri-devel On Behalf Of >guangming.cao@mediatek.com >Sent: Thursday, January 13, 2022 7:34 AM >To: sumit.semwal@linaro.org >Cc: linux-arm-kernel@lists.infradead.org; mingyuan.ma@mediatek.com; >Guangming ; >wsd_upstream@mediatek.com; linux-kernel@vger.kernel.org; dri- >devel@lists.freedesktop.org; linaro-mm-sig@lists.linaro.org; >yf.wang@mediatek.com; libo.kang@mediatek.com; >benjamin.gaignard@linaro.org; bo.song@mediatek.com; >matthias.bgg@gmail.com; linux-mediatek@lists.infradead.org; >lmark@codeaurora.org; labbott@redhat.com; christian.koenig@amd.com; >jianjiao.zeng@mediatek.com; linux-media@vger.kernel.org >Subject: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation > >From: Guangming > >Add a size check for allocation since the allocation size is >always less than the total DRAM size. > >Without this check, once the invalid size allocation runs on a process that >can't be killed by OOM flow(such as "gralloc" on Android devices), it will >cause a kernel exception, and to make matters worse, we can't find who are >using >so many memory with "dma_buf_debug_show" since the relevant dma-buf >hasn't exported. > >To make OOM issue easier, maybe need dma-buf framework to dump the >buffer size >under allocating in "dma_buf_debug_show". > >Signed-off-by: Guangming >Signed-off-by: jianjiao zeng >--- >v3: 1. update patch, use right shift to replace division. > 2. update patch, add reason in code and commit message. >v2: 1. update size limitation as total_dram page size. > 2. update commit message >--- > drivers/dma-buf/dma-heap.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > >diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c >index 56bf5ad01ad5..1fd382712584 100644 >--- a/drivers/dma-buf/dma-heap.c >+++ b/drivers/dma-buf/dma-heap.c >@@ -55,6 +55,16 @@ static int dma_heap_buffer_alloc(struct dma_heap >*heap, size_t len, > struct dma_buf *dmabuf; > int fd; > >+ /* >+ * Invalid size check. The "len" should be less than totalram. >+ * >+ * Without this check, once the invalid size allocation runs on a process >that >+ * can't be killed by OOM flow(such as "gralloc" on Android devices), it >will >+ * cause a kernel exception, and to make matters worse, we can't find >who are using >+ * so many memory with "dma_buf_debug_show" since the relevant >dma-buf hasn't exported. >+ */ >+ if (len >> PAGE_SHIFT > totalram_pages()) If your "heap" is from cma, is this still a valid check? M >+ return -EINVAL; > /* > * Allocations from all heaps have to begin > * and end on page boundaries. >-- >2.17.1 _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 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 1841EC433F5 for ; Thu, 13 Jan 2022 13:01:22 +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:In-Reply-To:References: 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: List-Owner; bh=91aFeMTG9d0Cl2M8HiBamlVrQQIAPgo5W4/0HnoUuRs=; b=pO0Kf7gItw70Cf oQu4M2Jz2z0vcUMALmLywy/s5C+k6a6i4j9prmTD+1kLtLzcD5yaCrsRKG19bJGaL4l0QYWvty+6v wd5QX7m5g3a47femje7QyKMqqYIzaCPf2qed7rQbYyWjdhLOi3KHeg3rBLUvTDySiCqpl9bwtsOBf ya3UVv7CaT9jEWdn3HDfudAfnSd4kfOfRbUuEHhn8vHj5btNMmiwoH6CWKYyeIO9HWM0lF/uIEZtD +BX32+BRs/j8JTXH5LeVmWzjiI32OzcZCF1Q7TZrslVen0eAxzVAUpkL3bOzMr/jy7J5n7fZ5qE6a xgt324fHa79EUIQr+Z/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7zhH-005yrG-QC; Thu, 13 Jan 2022 12:59:22 +0000 Received: from mga12.intel.com ([192.55.52.136]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7zfv-005yS4-8G; Thu, 13 Jan 2022 12:57:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642078675; x=1673614675; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=iycjm2C+Mf7QsOANPLMYnMeG7Nklub2C0BsuRJJMnhc=; b=IwQYXJRlETiq21CGn7bs86++TkahFiU5lR9elaqwp88EAFEC9ob2M5js uR/kgre9UFSIHy6AmJxL3xZMiAPEkPaXaqOERaPNxJO8lmathLXsnDGUk sZYyS1GrRBy78CDaSVWfkSVXGcgyQz83ghFiTO9WOMwwTul5fuCNydkre qNcM3tmbVP8a0XLVZK2wH99qSBS2GtxNGc5koVBvWloUjFCLeLGh/4UC3 qN6chg3tsKmDj1iZ5ZqvrpMIJOI2ACk0mgKlEQ0RZzOFRZ/5bfZIXCwG6 Q0UOUrfG8xjgjnTgS3xc37uc/cpBOySS2ZD47faf+HC7TZOJCXOfCtJA9 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10225"; a="223982892" X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="223982892" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 04:57:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,286,1635231600"; d="scan'208";a="691791936" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga005.jf.intel.com with ESMTP; 13 Jan 2022 04:57:52 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 04:57:51 -0800 Received: from orsmsx611.amr.corp.intel.com ([10.22.229.24]) by ORSMSX611.amr.corp.intel.com ([10.22.229.24]) with mapi id 15.01.2308.020; Thu, 13 Jan 2022 04:57:51 -0800 From: "Ruhl, Michael J" To: "guangming.cao@mediatek.com" , "sumit.semwal@linaro.org" CC: "linux-arm-kernel@lists.infradead.org" , "mingyuan.ma@mediatek.com" , "wsd_upstream@mediatek.com" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linaro-mm-sig@lists.linaro.org" , "yf.wang@mediatek.com" , "libo.kang@mediatek.com" , "benjamin.gaignard@linaro.org" , "bo.song@mediatek.com" , "matthias.bgg@gmail.com" , "linux-mediatek@lists.infradead.org" , "lmark@codeaurora.org" , "labbott@redhat.com" , "christian.koenig@amd.com" , "jianjiao.zeng@mediatek.com" , "linux-media@vger.kernel.org" Subject: RE: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Topic: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation Thread-Index: AQHYCHnKJjUnVmCmlECrXD1d8qRuLKxg6T0Q Date: Thu, 13 Jan 2022 12:57:51 +0000 Message-ID: <4f88205c1b344aea8608960e2f85b8f4@intel.com> References: <20220113123406.11520-1-guangming.cao@mediatek.com> In-Reply-To: <20220113123406.11520-1-guangming.cao@mediatek.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 x-originating-ip: [10.1.200.100] MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220113_045755_364300_186229F7 X-CRM114-Status: GOOD ( 12.77 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org >-----Original Message----- >From: dri-devel On Behalf Of >guangming.cao@mediatek.com >Sent: Thursday, January 13, 2022 7:34 AM >To: sumit.semwal@linaro.org >Cc: linux-arm-kernel@lists.infradead.org; mingyuan.ma@mediatek.com; >Guangming ; >wsd_upstream@mediatek.com; linux-kernel@vger.kernel.org; dri- >devel@lists.freedesktop.org; linaro-mm-sig@lists.linaro.org; >yf.wang@mediatek.com; libo.kang@mediatek.com; >benjamin.gaignard@linaro.org; bo.song@mediatek.com; >matthias.bgg@gmail.com; linux-mediatek@lists.infradead.org; >lmark@codeaurora.org; labbott@redhat.com; christian.koenig@amd.com; >jianjiao.zeng@mediatek.com; linux-media@vger.kernel.org >Subject: [PATCH v3] dma-buf: dma-heap: Add a size check for allocation > >From: Guangming > >Add a size check for allocation since the allocation size is >always less than the total DRAM size. > >Without this check, once the invalid size allocation runs on a process that >can't be killed by OOM flow(such as "gralloc" on Android devices), it will >cause a kernel exception, and to make matters worse, we can't find who are >using >so many memory with "dma_buf_debug_show" since the relevant dma-buf >hasn't exported. > >To make OOM issue easier, maybe need dma-buf framework to dump the >buffer size >under allocating in "dma_buf_debug_show". > >Signed-off-by: Guangming >Signed-off-by: jianjiao zeng >--- >v3: 1. update patch, use right shift to replace division. > 2. update patch, add reason in code and commit message. >v2: 1. update size limitation as total_dram page size. > 2. update commit message >--- > drivers/dma-buf/dma-heap.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > >diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c >index 56bf5ad01ad5..1fd382712584 100644 >--- a/drivers/dma-buf/dma-heap.c >+++ b/drivers/dma-buf/dma-heap.c >@@ -55,6 +55,16 @@ static int dma_heap_buffer_alloc(struct dma_heap >*heap, size_t len, > struct dma_buf *dmabuf; > int fd; > >+ /* >+ * Invalid size check. The "len" should be less than totalram. >+ * >+ * Without this check, once the invalid size allocation runs on a process >that >+ * can't be killed by OOM flow(such as "gralloc" on Android devices), it >will >+ * cause a kernel exception, and to make matters worse, we can't find >who are using >+ * so many memory with "dma_buf_debug_show" since the relevant >dma-buf hasn't exported. >+ */ >+ if (len >> PAGE_SHIFT > totalram_pages()) If your "heap" is from cma, is this still a valid check? M >+ return -EINVAL; > /* > * Allocations from all heaps have to begin > * and end on page boundaries. >-- >2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel