From patchwork Mon Aug 28 05:22:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13367529 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 8FF97C83F11 for ; Mon, 28 Aug 2023 05:22:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABF9C280010; Mon, 28 Aug 2023 01:22:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A70668E0001; Mon, 28 Aug 2023 01:22:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95E28280010; Mon, 28 Aug 2023 01:22:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 81E858E0001 for ; Mon, 28 Aug 2023 01:22:20 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 18BD0C02F9 for ; Mon, 28 Aug 2023 05:22:20 +0000 (UTC) X-FDA: 81172367640.26.E025E8E Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 5D3E5140002 for ; Mon, 28 Aug 2023 05:22:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.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=1693200138; 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=LhL6nYGXGm21Z/o3jLH6G+a37QwFscFZoKQfSU6B/nc=; b=QZ0K+vEXMMpFxzYjUPmglkmVCLELLZ2LgQE0Dyiz6A3JmRKkH2gz11VSxGK9hC2lliEhq2 QGvPoJZKnRPKw3WRbgr83fdGfnJh4LWwFC1/+yMVJTzAHVUL5cKKG3BYmcnkf3wCizXhih 828rzhMHB7e6fNpm7S9KfK8Ee3EQh3M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693200138; a=rsa-sha256; cv=none; b=kQjl55PZ9Ecw7lnzU+BMGn/hR+nYjbyGEtJYrcnAvFed7DBfmsybiD+CFh6j0YD/m/nS+4 T+SEe9ePCjX3ihEAXwE+l2ivixugB+bSVl4M7jrHoaXlu5BD5XrArf6Pyd17BKf6aETo/p 9xdt7uZM15lwZdYSep2f26AfqY1gbMc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.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 919222F4; Sun, 27 Aug 2023 22:22:57 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.57.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 47D9E3F738; Sun, 27 Aug 2023 22:22:15 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH] mm/mmap: Tighten up cmdline_parse_stack_guard_gap() Date: Mon, 28 Aug 2023 10:52:12 +0530 Message-Id: <20230828052212.748872-1-anshuman.khandual@arm.com> X-Mailer: git-send-email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lJnTCxeTtJ3KUwqE33YMyzPUuJqYowSxPXwopU5lwDA52p8 lEJ3oT7n /AXq3lfPjYhSNp9lzSkIZBqWETWpy51eDVmUifEFdAAtXUii0ASl+KsFyGy50VchcFbpdpDyyQW5LlwWn1Aa+PsXZSqcZ5w9nrK72fDk9TU+Z3Up1/eb21Gd3HjTPrddHXW3a8UUSF4aK4SVVKxxKL2B4++IL0CUUelQRJu8mHoPoBVuKW/SFjNrUdNtM/0EJC0iW6AzYT1RBHkiRgkqYGRLuKb0HVjIdIqWS+Hgnh3zEkq2yRjLFIsu0qpNLGd67ZwvHxHxvZL1me/oZIdFMvrgFiphfk1mAVX/Ww0ln58+f+V12/0yGdfTQRym9ZSaLM19s2gPTyX1RomqdteOaZXD12QJsPVimbA7FjJT7PIxCIeX++ucTHpky2VpP08flD2Ta 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: Currently kernel command line 'stack_guard_gap=', which does not provide an explicit pages gap value, still assigns 0 to 'stack_guard_gap', which would not have been expected. In such cases it should just retain the default gap value (DEFAULT_STACK_GUARD_GAP). Instead let's assert a positive value for input gap pages before proceeding any further. While here, this tightens up cmdline_parse_stack_guard_gap() for other scenarios, where the command line parameter 'stack_guard_gap' is not successfully handled as expected. Cc: Andrew Morton Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Anshuman Khandual --- Depends on the following patch. https://lore.kernel.org/all/20230828035248.678960-1-anshuman.khandual@arm.com/ mm/mmap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 8679750333bb..adaa81d95518 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2122,16 +2122,19 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address) /* enforced gap between the expanding stack and other mappings. */ unsigned long stack_guard_gap = DEFAULT_STACK_GUARD_GAP; -static int __init cmdline_parse_stack_guard_gap(char *p) +static int __init cmdline_parse_stack_guard_gap(char *str) { unsigned long val; - char *endptr; - val = simple_strtoul(p, &endptr, 10); - if (!*endptr) - stack_guard_gap = val << PAGE_SHIFT; + if (!str) + return 0; - return 1; + val = simple_strtoul(str, &str, 10); + if (!*str && val) { + stack_guard_gap = val << PAGE_SHIFT; + return 1; + } + return 0; } __setup("stack_guard_gap=", cmdline_parse_stack_guard_gap);