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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42C5DC27C75 for ; Thu, 13 Jun 2024 07:38:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C59746B008C; Thu, 13 Jun 2024 03:38:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C125E6B00A0; Thu, 13 Jun 2024 03:38:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A83B36B00A1; Thu, 13 Jun 2024 03:38:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 865786B008C for ; Thu, 13 Jun 2024 03:38:06 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 25C8E140728 for ; Thu, 13 Jun 2024 07:38:06 +0000 (UTC) X-FDA: 82225061772.16.C23D42E Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) by imf15.hostedemail.com (Postfix) with ESMTP id 6E0ADA0003 for ; Thu, 13 Jun 2024 07:38:03 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718264283; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MymSWJYhL1v+2rUurUeDUD4VHdSslicZc71deUFMgPU=; b=U1r7ez5EAyIrhxGzqgPGASGVxWz88FsiCICSZWbquNbJl5q24d++p0Bat27F8WXENXM6NL 8auxmX8lSHhEJ5AviGCShiU4rDQOXIiXa7WeNWHp/wGIp/FZXK0BtUOzU03veKZ6P3RKAa rG76AWDYl7Mz80OkAR9IpMWgpyZ0UtU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718264283; a=rsa-sha256; cv=none; b=bMB3hdVJ6o9HNxCWK4QkTuJaz72HepfSrM/VXqIYEVTmnv7YPyx3+03wvHJNYWj7VXshk7 Q6EB7mDFNBwTkmLzu4f8gZCZlNuPb4AvI4eDHis6DqYmmF+PxxIhmVgcyhmFuO2qC9KXAz Xx4IRx9OLKq+FlKhGFGj2AOoiOR47fo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=21cnbao@gmail.com Received: by mail-vs1-f51.google.com with SMTP id ada2fe7eead31-48c3957a7c5so287160137.0 for ; Thu, 13 Jun 2024 00:38:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718264282; x=1718869082; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MymSWJYhL1v+2rUurUeDUD4VHdSslicZc71deUFMgPU=; b=Ax/FtZ+7gDYD769Ccsqx1BmCWdbsbcg83jD3u4i5dVh/zUrYKzPOk9hnzQPRH+1lwF UdcpIA9OFIoUdObOtPsXp1jNZTTr+vy+4HzmTZPBkTRaSM92Y4slybr2L+1pdfQu5ShW iT8Jvb7na8SmoKFvorXU5cS+19WJlNAi5l8ILPVV5xNBWlPDgDNt1HnCnOHNWmECVsCq BNw/kQpc5y4sJcOci5hsV8mnlKhY69CKajiBT4u/TnnT2LnoWa6HUB/+R4G9Q4WXDX+H l0XZtj4mf+OdBaTDnoS9P7y+iKhuGUu6P6NHKkpxJMJmNXd9sGJqhPHre6hG0gtD2jll 0vFA== X-Forwarded-Encrypted: i=1; AJvYcCU8A2OPCP6WqEUZ1+JE8yJ0l62Yt5T/WJnOd9lJlMpjazPQOouIgWIfjd4ZqSClk0HGi/zaxFwEoz9sDpoVE/hwW4Q= X-Gm-Message-State: AOJu0YxRoX/iE+PGFJ8fOu/bn0dBzGrAYkojoG0lODhdttAjIxXkdYHF SSz75aBti7PTIHQC6tiDVImVKqTz1AbHoDZ71ZPBdhLt+k7W8KhB842/GJhqLr4S1oy61y6tVTE RnfUhFHdh28lGjTBEsHD9O3WgRLk= X-Google-Smtp-Source: AGHT+IH9yKYZaGt2hz2gcwrMgyDuNqcuFmZFwtpgbnrWk3ZNTmQGrkR98Gsv/5NDV00wmOKLM/Km8+XXdCvyHxDi2H4= X-Received: by 2002:a05:6102:a4f:b0:48c:2f38:fd3 with SMTP id ada2fe7eead31-48d91db98b1mr5325731137.10.1718264282437; Thu, 13 Jun 2024 00:38:02 -0700 (PDT) MIME-Version: 1.0 References: <20240612081216.1319089-1-zhai.he@nxp.com> <20240612114748.bf5983b50634f23d674bc749@linux-foundation.org> In-Reply-To: From: Barry Song Date: Thu, 13 Jun 2024 19:37:51 +1200 Message-ID: Subject: Re: [EXT] Re: [PATCH v2] Supports to use the default CMA when the device-specified CMA memory is not enough. To: Zhai He Cc: Andrew Morton , "sboyd@kernel.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Zhipeng Wang , Jindong Yue , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 6E0ADA0003 X-Stat-Signature: gqkwt9eg4ezyq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MEaCs9Jayuit6vCwidWFmdomB+XzV4gl96/l4CI264SACbMm+FcxL61TTrkoJSiZYSkz7CK1BJud3oUg9Fi8H+fKE8ksD8xgiONudDIAbuFtRqWNVl6ZqG+hj5Vai8y6SNSxqLsx3KeZSp9Xy01NTqysl0UUEWtt/I31BD29zUeqUj2uItss3YwYA3rgBO36jnp09n+lOLkRoftA1BloQFW7Kv/z0TuTBsmrixt4/8nbHZJNHyJIJkxqwAAJT59GYEicZQRStmuZd0/5J6R1BF4H7ht4EDwngz7j8qW93TWXt233GyJXHz4RVaB61VnjNZrvF6T8k82XVJJx7lvQI30s9UOsNvA1+yqDWb93BbZvd8j8DLjGjuihljQPfGHQ0zscWDvm9eVDqx/3tyTbVe1Fj0seLc98PcGQKpqQBU7pmjTH6mvG48bijIXQSGKDYjdLP0+OEPv0iIRZ0V+CXI2Ca1hxalVfypBJFRm1ID07FxxDi5Z9df6xDKyY/r40VmPvfFhDadJPjDGinCd0Dz2vyWrKkFAeqTaQh8/PzIYT+B0LT/yzJymKVwHI5Q= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jun 13, 2024 at 7:11=E2=80=AFPM Zhai He wrote: > > > -----Original Message----- > > From: Barry Song > > Sent: Thursday, June 13, 2024 2:15 PM > > To: Zhai He > > Cc: Andrew Morton ; sboyd@kernel.org; > > linux-mm@kvack.org; linux-kernel@vger.kernel.org; Zhipeng Wang > > ; Jindong Yue ; Christoph > > Hellwig > > Subject: Re: [EXT] Re: [PATCH v2] Supports to use the default CMA when = the > > device-specified CMA memory is not enough. > > > > Caution: This is an external email. Please take care when clicking link= s or > > opening attachments. When in doubt, report the message using the 'Repor= t > > this email' button > > > > > > On Thu, Jun 13, 2024 at 5:32=E2=80=AFPM Zhai He wrote= : > > > > > > > -----Original Message----- > > > > From: Barry Song > > > > Sent: Thursday, June 13, 2024 11:28 AM > > > > To: Zhai He > > > > Cc: Andrew Morton ; sboyd@kernel.org; > > > > linux-mm@kvack.org; linux-kernel@vger.kernel.org; Zhipeng Wang > > > > ; Jindong Yue ; > > > > Christoph Hellwig > > > > Subject: Re: [EXT] Re: [PATCH v2] Supports to use the default CMA > > > > when the device-specified CMA memory is not enough. > > > > > > > > Caution: This is an external email. Please take care when clicking > > > > links or opening attachments. When in doubt, report the message > > > > using the 'Report this email' button > > > > > > > > > > > > On Thu, Jun 13, 2024 at 2:34=E2=80=AFPM Zhai He w= rote: > > > > > > > > > > > -----Original Message----- > > > > > > From: Barry Song > > > > > > Sent: Thursday, June 13, 2024 5:37 AM > > > > > > To: Andrew Morton > > > > > > Cc: Zhai He ; sboyd@kernel.org; > > > > > > linux-mm@kvack.org; linux-kernel@vger.kernel.org; > > > > > > stable@vger.kernel.org; Zhipeng Wang ; > > > > > > Jindong Yue ; Christoph Hellwig > > > > > > > > > > > > Subject: [EXT] Re: [PATCH v2] Supports to use the default CMA > > > > > > when the device-specified CMA memory is not enough. > > > > > > > > > > > > Caution: This is an external email. Please take care when > > > > > > clicking links or opening attachments. When in doubt, report th= e > > > > > > message using the 'Report this email' button > > > > > > > > > > > > > > > > > > On Thu, Jun 13, 2024 at 6:47=E2=80=AFAM Andrew Morton > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > On Wed, 12 Jun 2024 16:12:16 +0800 "zhai.he" > > > > wrote: > > > > > > > > > > > > > > > From: He Zhai > > > > > > > > > > > > > > (cc Barry & Christoph) > > > > > > > > > > > > > > What was your reason for adding cc:stable to the email header= s? > > > > > > > Does this address some serious problem? If so, please fully > > > > > > > describe that problem. > > > > > > > > > > > > > > > In the current code logic, if the device-specified CMA > > > > > > > > memory allocation fails, memory will not be allocated from = the > > default CMA area. > > > > > > > > This patch will use the default cma region when the device'= s > > > > > > > > specified CMA is not enough. > > > > > > > > > > > > > > > > In addition, the log level of allocation failure is changed= to debug. > > > > > > > > Because these logs will be printed when memory allocation > > > > > > > > from the device specified CMA fails, but if the allocation > > > > > > > > fails, it will be allocated from the default cma area. It > > > > > > > > can easily mislead > > > > developers' > > > > > > > > judgment. > > > > > > > > > > > > I am not convinced that this patch is correct. If > > > > > > device-specific CMA is too small, why not increase it in the de= vice tree? > > > > > > Conversely, if the default CMA size is too large, why not reduc= e > > > > > > it via the cmdline? CMA offers all kinds of flexible > > > > > > configuration options based > > > > on users=E2=80=99 needs. > > > > > > > > > > > > One significant benefit of device-specific CMA is that it helps > > > > > > decrease fragmentation in the common CMA pool. While many > > > > > > devices allocate memory from the same pool, they have different > > > > > > memory requirements in terms of sizes and alignments. Occasions > > > > > > of memory allocation and release can lead to situations where > > > > > > the CMA pool has enough free space, yet someone fails to obtain > > contiguous memory from it. > > > > > > > > > > > > This patch entirely negates the advantage we gain from device-s= pecific > > CMA. > > > > > > My point is that instead of modifying the core code, please > > > > > > consider correcting your device tree or cmdline configurations. > > > > > > > > > > > Because we enabled secure heap to support widevine DRM, and secur= e > > > > > heap requires security configuration, its starting address cannot > > > > > be specified arbitrarily, which causes the default CMA to be > > > > > reduced. So we > > > > reduced the CMA, but in order to avoid the impact of reducing the > > > > CMA, we used a multi-segment CMA and gave one segment to the VPU. > > > > > > > > > > However, under our memory configuration, the device-specific CMA > > > > > is not > > > > enough to support the VPU decoding high-resolution code streams, so > > > > this patch is added so that the VPU can work properly. > > > > > Thanks. > > > > > > > > I don=E2=80=99t quite understand what you are saying. Why can=E2=80= =99t you increase > > > > VPU=E2=80=99s CMA size? > > > Thanks for your quick reply. > > > Because we added a secure heap to support Widevine DRM, this heap > > requires hardware protection, so its starting address cannot be specifi= ed > > arbitrarily. This causes the secure heap to occupy part of the default = CMA, and > > the default CMA is therefore reduced, so in order to avoid default CMA > > Shrinking introduces other problems. We added a specific CMA area for t= he > > VPU. However, due to the large size of the secure heap and default CMA,= There > > is no remaining memory available to increase specific CMA for VPU. > > > > I assume the secure heap you are referring to is a section of memory th= at > > should only be accessed by TrustZone and not be visible to Linux runnin= g in > > non-secure mode. How do you allocate this secure heap from the default = CMA? > > No, secure heap is a reserved memory, secure heap is not allocated from C= MA, secure heap has been reserved during the kernel startup phase. > And this reserved memory is protected by hardware. Only specific hardware= and secure world can accessed it. > For example: > &{/reserved-memory/} { > secure_region: secure { > compatible =3D "imx-secure-ion-pool"; > reg =3D <0x0 0xA0000000 0 0x1EF00000>; > }; > }; > > > Do you use the cma_alloc() APIs or the dma_alloc_coherent() APIs? Given= that > > the VPU has its own device-specific CMA, why is this secure heap alloca= ted > > from the default CMA instead of the VPU's CMA? > > > The VPU driver will use dma_alloc_coherent() to allocate contiguous memor= y. The secure heap is not allocated from the CMA, but because the secure he= ap is enabled, it occupies some contiguous memory, causing the default CMA = to be reduced. > > > If this secure heap was allocated before the kernel booted, why did the > > kernel(your dts) fail to mark this area as nomap/reserved to prevent th= e > > default CMA from intersecting with it? > > > Secure heap does not intersect with the CMA. > for example: > before secure heap enabled: > 0xA000 0000 ~ 0xFFFFFFFF: default CMA > after secure heap enabled: > 0x9000 0000 ~0x9FFF FFFF is the CMA specified by VPU, > 0xA000 0000 ~0xAFFF FFFF is secure heap, (the start address cannot be spe= cified arbitrarily, because this memory is protected by hardware, if the st= art address is 0x9000 0000, uboot will use this memory, but uboot can't acc= ess this memory because of hardware protection. So we find a section of mem= ory that UBOOT will not use as secure heap. > Note: The memory of uboot can be adjusted, but avoiding the secure heap w= ill limit the memory range that uboot can use, causing problems such as the= uboot stack) > 0xB000 0000 ~0xFFFFFFFF is default CMA. > So default CMA is reduced. How is that related to your patch? I assume the default CMA is reduced beca= use you modified it in the DTS after enabling the secure heap, as the CMA size is set by you. The default CMA size won't automatically decrease due to the secure heap. To me, 0xB0000000-0xFFFFFFFF(1.25GiB) is still too large a CMA. > > > > > > > > It seems you mean that only in some corner cases do you need a larg= e > > > > CMA, but most of the time, you don=E2=80=99t need it to be this big= ? So you have > > to "borrow" > > > > memory from the > > > > default CMA. but why not move that portion from the default CMA to > > > > your VPU=E2=80=99s CMA? > > > > > > > This is a method, but because for VPU, the continuous memory size all= ocated > > by the driver is based on the video stream, we cannot determine the max= imum > > size of memory required by the VPU. This makes it impossible for us to > > determine the size of the specific CMA assigned to the VPU. Thanks. > > > > I don't understand how this can happen. You should precisely know the > > maximum size required for the VPU based on your multimedia pipeline and > > resolutions. > > > We cannot estimate the maximum contiguous memory required by the VPU beca= use it depends on how the video is encoded. > Thanks very much. Yes, you can. Please ask your multimedia team; they will give you a number. > > > I still don't understand your scenarios or the problem you are facing. > > Thanks Barry