Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp661337lqp; Wed, 12 Jun 2024 12:13:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUDpF120DysvYIRyefJAsioR8uZGBYntUkvzjCG4ACuKmAmyhFhLEOp24LoqDE1QVwxIDDQHUJMU7WOMEtuORos3r5O7xffKDgqLKXlyQ== X-Google-Smtp-Source: AGHT+IHb5BBdzHyT2f2tGV8HoYEEQQobXvVdPWjXlqMQqFS1iFBCWJ8+zGUKbHvOKUYsmAa7YWwA X-Received: by 2002:a05:6a00:2e29:b0:702:2749:6097 with SMTP id d2e1a72fcca58-705bcdcc663mr2980351b3a.1.1718219631129; Wed, 12 Jun 2024 12:13:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718219631; cv=pass; d=google.com; s=arc-20160816; b=wwCZjp3dyBINrl2sOwu01nyCkEIqRmDsVybt0LdBQZfGDwH0eLv489VgrzYLiE1RHJ uOmFCqH1PvmrI179Su4hsPBAwyPub8EiTMeN2YJti4+jpwh7wG/CeG3HhY9mXO7wAte6 kTtY63FIZTlGHdjxMXaVDRhwHY4G3vEybB3FQp2RkOvDNdpSWEQGOP7/ZJV0i9juMl7b VCO440FhcDqfIE/stP5/gr9OC0EJYLMaBk+XUiAP9G1ez7YP9ukEFlAMZLVjb3ZYlzdB UUlteu+Uia8mLkupMJMOIM2adTkdTvLmC+EwTbgkDrqwhcOlpoolhfjYz7HWDvgAByiF eMyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=2vLx8l/3Bbfbnv9jtOZcdiwXnPjhOPqR32th3903ZDk=; fh=W+JAQGdFVWaqy57b3oVbRo5M62F9luiORHNl0oadPNI=; b=lcCWyolAOXRRVyZtLdaEG6cSFNShIzoee62R7H7m3DWEcAQUL8uRusOcPC1nWlariA XE4lBhd8mX9oOxxJHiRhpxUbAIP61vcb0TTzNMERR7iH73uM7b4L4wSLLOomhZeuQZWb VDpQ2NgGla17Jx/0P4/pF7zz27BoyQ7SfzzS+mOi5AF54PSMdJBkT1T5hUtBa8cWFA4c 8YTmq8DmTnoa3Ky3ZmTHK+pqq/dBw7E11ci3pQDOsBWT+ypdsRsQW7EviRiJCy6MGiM+ NFXDn1nxoz4VtbBhhY0k//90ZkmyZPOgyN6pOGtAlM3g1ikj6vZAUI9TMHvZiKrF/KZo gKYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Sm1lqskG; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-212116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212116-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6f9fa2e6056si2252267a12.648.2024.06.12.12.13.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 12:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Sm1lqskG; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-212116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212116-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 01CA3B21B21 for ; Wed, 12 Jun 2024 18:47:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A55154CDF9; Wed, 12 Jun 2024 18:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Sm1lqskG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A15282F3B; Wed, 12 Jun 2024 18:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718218069; cv=none; b=kkKU8ySej+TCKgbKh7KawwyAQYrJuIEBCNXu52Rqkk93M9m/GCcHe2AV8FoKoZDIk2LvoSGvdJu56Les5cokXXTZrKZWwsv7AW3SoiD29JTfxvNNPqMRTCNaWUgYVRZHfDHwZuKpDEGNEsPWcBS1njIlBL2rSJftdDtsWz5TST4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718218069; c=relaxed/simple; bh=WAdPbpV16su/L/nLL1I9OCKFq9jqJsizJUL/5Q609jU=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=q7wWlFgdLy4kCyITZpTTLKZerisVYkixfTV/IesSB/GSebK7/Gkqj4zvIn2AJ3vBbbeu6HSc8VJ5VXTCenAqkFLAf2CMif1uuGDBjWNQbjmaxztLLZ8iB9tE31gHAO/Vauz/ewRQbrzPjbt0w3e+X1IhgmK4o1x6OY5lt1NLY+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Sm1lqskG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B53EDC116B1; Wed, 12 Jun 2024 18:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1718218069; bh=WAdPbpV16su/L/nLL1I9OCKFq9jqJsizJUL/5Q609jU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Sm1lqskGRET2keI9nUnBWAo9NHejyLojU8nIbdRINQDTbTFnHquXRBI3amEYYfRqf MHr0NVCg3m01gJr8LppX/w5oXog83ISpT/eeV4yrRIZimnxBuRdW1qLNYfTy7IEt4I JHmCDvtnsf7cXRN+5v4SiohSXp6hI5njlG4cKRtI= Date: Wed, 12 Jun 2024 11:47:48 -0700 From: Andrew Morton To: "zhai.he" Cc: sboyd@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, zhipeng.wang_1@nxp.com, jindong.yue@nxp.com, Barry Song , Christoph Hellwig Subject: Re: [PATCH v2] Supports to use the default CMA when the device-specified CMA memory is not enough. Message-Id: <20240612114748.bf5983b50634f23d674bc749@linux-foundation.org> In-Reply-To: <20240612081216.1319089-1-zhai.he@nxp.com> References: <20240612081216.1319089-1-zhai.he@nxp.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 headers? 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. > > ... > > --- a/kernel/dma/contiguous.c > +++ b/kernel/dma/contiguous.c > @@ -357,8 +357,13 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp) > /* CMA can be used only in the context which permits sleeping */ > if (!gfpflags_allow_blocking(gfp)) > return NULL; > - if (dev->cma_area) > - return cma_alloc_aligned(dev->cma_area, size, gfp); > + if (dev->cma_area) { > + struct page *page = NULL; > + > + page = cma_alloc_aligned(dev->cma_area, size, gfp); > + if (page) > + return page; > + } > if (size <= PAGE_SIZE) > return NULL; The dma_alloc_contiguous() kerneldoc should be updated for this. The patch prompts the question "why does the device-specified CMA area exist?". Why not always allocate from the global pool? If the device-specified area exists to prevent one device from going crazy and consuming too much contiguous memory, this patch violates that intent? > @@ -406,6 +411,8 @@ void dma_free_contiguous(struct device *dev, struct page *page, size_t size) > if (dev->cma_area) { > if (cma_release(dev->cma_area, page, count)) > return; > + if (cma_release(dma_contiguous_default_area, page, count)) > + return; > } else { > /* > * otherwise, page is from either per-numa cma or default cma > diff --git a/mm/cma.c b/mm/cma.c > index 3e9724716bad..6e12faf1bea7 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -495,8 +495,8 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > } > > if (ret && !no_warn) { > - pr_err_ratelimited("%s: %s: alloc failed, req-size: %lu pages, ret: %d\n", > - __func__, cma->name, count, ret); > + pr_debug("%s: alloc failed, req-size: %lu pages, ret: %d, try to use default cma\n", > + cma->name, count, ret); > cma_debug_show_areas(cma); > }