From patchwork Thu Feb 1 02:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13540574 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 A29ABC47258 for ; Thu, 1 Feb 2024 02:37:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08F376B0075; Wed, 31 Jan 2024 21:37:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03FD56B007B; Wed, 31 Jan 2024 21:37:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E97886B007D; Wed, 31 Jan 2024 21:37:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D8F736B0075 for ; Wed, 31 Jan 2024 21:37:26 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A03CC80679 for ; Thu, 1 Feb 2024 02:37:26 +0000 (UTC) X-FDA: 81741673692.15.6A8E02C Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP id C613E4000C for ; Thu, 1 Feb 2024 02:37:24 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706755045; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=pd/32MUSrY1gBkpmQkuJYIKuNNFzEUgBnIy7gvO5S5I=; b=6K/3bTn9JV6XUQhF6nfWPpLoVeNFhRhucaxKArhh1t6x4fCFhs9uorAB1VjmQQ8+o3b0N4 GTqoBo+RmuHdIalsZjz5WL1ZEYdxL54Ai1u1h78m2fiw28KeB7Eayz/7VZQiELq9LS20Ox ggFjyBaWVJg45N2JTEE1xh2uX9yXDgs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706755045; a=rsa-sha256; cv=none; b=l/b+HxWwEpq0Triy+mTjp/S9tRr8RNlqPF8ybpO6CmCL1HtjQHTUA0MG9y7OkGKYXMa7LM OTphuyUHIMNIMnXjr2u+eds6l0inDhfQFI1Qx+xt8a3VFksVSBxKhnXejpqnC9jLgcSdyw LFyaIJN62grIBEQARa7fxdVPyrltpL8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96DD1DA7; Wed, 31 Jan 2024 18:38:06 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.42.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C87B23F738; Wed, 31 Jan 2024 18:37:21 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH] mm/cma: Don't treat bad input arguments for cma_alloc() as its failure Date: Thu, 1 Feb 2024 08:07:14 +0530 Message-Id: <20240201023714.3871061-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Stat-Signature: bf3jukou5ietyhtexpczhyn9a3m686k8 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C613E4000C X-Rspam-User: X-HE-Tag: 1706755044-188007 X-HE-Meta: U2FsdGVkX1/3OoWZvFOoV5Z5E+J79wG5PM04Bvsv1YJ1FYKohIC6/MDGRHlf73zwdrj5+pkVReI5rxeEGK3VTk25qRXXmqNIoo3AjZYE2H1uvP3JVLKaSidFPYkqPOzaY/GI+AA1LEOt2gtApPt7hqOEApJBW1IITorU/qE+vF7ZRr7Pm8FqpMPmeG99BU52ZpfaMuRCm069s9LJnWACDbJVio71xCohPBlu0iQA9OceVKLGJMm7KVjoCI0yjGI9bO+ej5Q6gPz55t6BLPt9rKbdCWnu+9o8qOOI9TzC03MCZHXP2QTlsCZpNtdtwOBFElWn+W51VSI5/IvM915wTlQsXgiIYiEmkXUf8eXDvFEY0uQUMU7XPgjaN2u57/xM6j7EOOycVX6naX5veG8KCCCzv9vrmMz8rP1hU015NdgDs6n+hivQK+G4YERKPQ5I0j4JihuB7zXLfYsfQSPxq7zElX/1KvlVz0HSpJQrnyzvqo4TPfIhPPV4xYANHKDjXC+6G4SjOtCABo8NMfdMFJIw7m84+2X9gVPUwJr8iI0RHJO9bkh/4oRC4zjuzNOSQMue1EbcdPWxHZY51iMvtxQwmOzGCg5yWC7WRf4D08OdsgMrEEP9MY1U/XhWQOCLdayTsnNE3vXTfyg6I5zqWLl5yUX+r6iYerBJ4TLcJFdjtxxll28/5XsOC1ZOukkpE8EP0SoShvccufxYjr+ecZvQVFCCQ47iCyFPiIB0LiRLtbLahX72VXnd6sYnrwgfNebsYrtn4pbdTx8y66HSR8+3ln3ecQ5hI5r5hjc7ifw8auo78V8bID/3qdkiRbkQybY0dsqlGqQebeBDB3lfVMcOpA99h6XPHCoEkIwcrJ2hEC9G2O+smNcIpS5pTPdF/XyGSIXOGmya+SZ5ujg0070PApRpe553v7cT/ZKkhgBPXUUAUKoQ+5Q/ic1mq7o0SoCZolKbYzSyuWrNZUG rHqF3c/9 /bDgxLNhNsX4GVgIPNdZjqnoky0CeJ5+SXz1oukpS6QpJOLrIDDDpWT8LAncZ/CQtiS0zRfpk7KZv9FkkOPE41Kj4OR/0t0XkkHaLBB6RH2G6EHCRqgcfyLVSMZig8G0UFlslKFErhfobsyCa5sOTIHKLKPX59VciF6WvO+tHAXtkwQSWzHfBj16dnuHBwt+WjAmfcZ61bGlqyiyjlMiS6uEV5Q3yK9R8wemKWdUv//Y12spZFJgvAbN58G5a8IRxlGhmzgdHPRAbA8vI0Eh33lbhmi+0RFx3DTMb7DW4q0NDhBp61VD95bVmBxicJMnSXiqFkejkugU+FwaFoSDYgjY6Nt3vu6VNtkCAJbjW82B8Up1E5hO6jqhHsBeH6cc6eQJl 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: List-Subscribe: List-Unsubscribe: Invalid cma_alloc() input scenarios - including excess allocation request should neither be counted as CMA_ALLOC_FAIL nor 'cma->nr_pages_failed' be updated when applicable with CONFIG_CMA_SYSFS. This also drops 'out' jump label which has become redundant. Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- Also inclined to fold (!count) check into the first one i.e (!cma || ..) before the pr_debug() output. This applies on v6.8-rc2. mm/cma.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 7c09c47e530b..464fb4c8b4f0 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -438,13 +438,13 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, int ret = -ENOMEM; if (!cma || !cma->count || !cma->bitmap) - goto out; + return page; pr_debug("%s(cma %p, name: %s, count %lu, align %d)\n", __func__, (void *)cma, cma->name, count, align); if (!count) - goto out; + return page; trace_cma_alloc_start(cma->name, count, align); @@ -454,7 +454,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, bitmap_count = cma_bitmap_pages_to_bits(cma, count); if (bitmap_count > bitmap_maxno) - goto out; + return page; for (;;) { spin_lock_irq(&cma->lock); @@ -515,14 +515,12 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, } pr_debug("%s(): returned %p\n", __func__, page); -out: if (page) { count_vm_event(CMA_ALLOC_SUCCESS); cma_sysfs_account_success_pages(cma, count); } else { count_vm_event(CMA_ALLOC_FAIL); - if (cma) - cma_sysfs_account_fail_pages(cma, count); + cma_sysfs_account_fail_pages(cma, count); } return page;