From patchwork Fri Jan 17 01:30:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13942779 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 43250C02188 for ; Fri, 17 Jan 2025 01:31:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBBE06B0093; Thu, 16 Jan 2025 20:31:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7D066B0098; Thu, 16 Jan 2025 20:31:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4CE6280002; Thu, 16 Jan 2025 20:31:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 939CB6B0093 for ; Thu, 16 Jan 2025 20:31:12 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2676FA1411 for ; Fri, 17 Jan 2025 01:31:12 +0000 (UTC) X-FDA: 83015215584.28.A70BCC0 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf30.hostedemail.com (Postfix) with ESMTP id 913498000E for ; Fri, 17 Jan 2025 01:31:10 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LaQoBjWA; spf=pass (imf30.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737077470; 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:in-reply-to:references:references:dkim-signature; bh=Sl/n7tMIYUVbrjQmIpH54kIXy3INbLjVgCRDXXa2xCI=; b=YNLfAnYtizazPLPeiJ/MWXUs2YsGRZseoF2nb1FBgLvAiX+4LbFyYiNvFlKc86OqOVEbkR FC08fdl3pfJdIk6XNCe7oieWeTIq06ols4bEEP5lsIvqGGp91y0N6dpnFXzNY2clme2oAI zENwNVmSEBc6w75H3/nZ6i6c80OrFIg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737077470; a=rsa-sha256; cv=none; b=EBYGdY8z6kycB9FUK4JS7dnT1ZIF3iIundTAJFjS4xBbjrsXgnYdX3g0xz1usiL0UdDOrF 4Lu7jYxZBGQeB2xzqprza7MUvqT7fFx/i1OZLlGMqhuUW5ruub9P4Ens301xUZR8A/t/YP l8P+pb4t9i3LMAtuJ61mb4AAuxXoOXo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LaQoBjWA; spf=pass (imf30.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id EBBD3A4175B; Fri, 17 Jan 2025 01:29:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 488AEC4CEDF; Fri, 17 Jan 2025 01:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737077469; bh=kwZzbvixIZEJHWiCRUl/KCUq+QQFe5aGtgrwZ2gLoJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LaQoBjWAhd/EZqsQlNeeWk8Iq3YfhRWsz6t9O3+vGwhYiSbDIUeBcwX5LHqcLSsjv t8ol4WiiNn4qz92p4G27mXp6HGL1MaI/dWr9q6MAvm1laS5nkwsEN+Cm2QCjEd6z/L 6A6p4QuxQ81N8R9kVLQ5RWpZNXbYUBFXqknxScIda+VnhJlOuC3KzFOeDNDNwh+cjk c2a031uobFUPFKbiuy28X0pyr4Mjb8HlZa8Ky6DRCGmGYEnaYfUqs80Nox2PQCPPnK /pUZTG4iY5Y+8Gm3OPFYblxubRvjqZNiUKAgJHnVcQ5piFykpazRKWKEZWy2gFWgVh ZmjwsOn/eXpBQ== From: SeongJae Park To: Cc: SeongJae Park , "Liam R. Howlett" , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Shakeel Butt , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 3/4] mm/madvise: split out madvise() behavior execution Date: Thu, 16 Jan 2025 17:30:57 -0800 Message-Id: <20250117013058.1843-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250117013058.1843-1-sj@kernel.org> References: <20250117013058.1843-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 913498000E X-Stat-Signature: tax1fqh4nsy9fhgqsqfrcen8g6eoipwg X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1737077470-491547 X-HE-Meta: U2FsdGVkX1+ADZjcF+4g1B0aSDGQ5iSFwiakSWUK16UmkgYEM2exlnZUuKrXTi6e40D1QvKAJcj1AsKP6O/WYAcGSd4dIu2y/CLb4JpydqDiut5xtBDH1V/cGNi35d9vNPeBs9AAxrh5G3h5FQVkOOhTuF3AvmWQSjTn4CBZ1bBDnTYWorqz0Cnv0i6zcaRN3EEpkfS47ughMT33cS1jewWXK7u8326RAcKxUftVV42wMHaJDRPtMJLe+FOQprYh5/DDPCBIvF6AaOJ90EZZMwaZ1ebeIeLZRJ1I8gPjupS3uYOTjQZ5PdrqKdxWkbALKwEnM3qdzfWhGcQUh2zX46LfzGyfEwrE0szRlSflcu2u5VHdCBEd61cwmeO/VLKg4LNDZJT9m0ZzkB1NZPBpwbDNLOXE9kMA3Vts+kVzUgR5YzyqzTgUGpD1rAppH7Fa/B7UioDi1gQ8YhKfFweiyRWY1oQmEEDMSHfNWjK4D0x+saolcE43ex35TzBQPR+hYZEN+KFXZZX20M+Wqn8wMDL/WPClGxZGeofgEKgzdH4nAAc+dM52hwey+RRuEPf16ae+i8GxDIZtmtbGu/92vG0YvO1Rf/mmd+me9WJ8oG5thZVbAMqK9lUOW8omDbYi4/3N3GKLA81YQ0Cc5/O2H9TPayEGBSADRiJFBvDaoOY3wR4KcWRVQTxNFwFoe5zlqaR+STguyj1no674qS8wRGHge8c8FsoATceyO9vMbCSAr6vlJPiYMj2e5D1nOrSygGw8sl1O5PrNLZ/8K+XyeRo9niX9IpCWYtosIrThNN81PKSC4N+SpGzB9h1GjbBI1bTY68ZwM6ySi+tC0qdYRAXnTVOk3FMrViYu7frJAmthibAR6DZYqUKNYG4TxwlDjkTP/Gt95GvgyOUJlKN4/jTjS2PsSh6Q7SIs+eDJWPAeX4lkP9hirlRLwfQYwx4m96bSuks4037WBR52Byw gSop448Z RTTA3IBzM3fICEDFOU957NjiZMbFXv/i5Uh5KUE9diMwKNC3pVWgl6c81jEI1uUIz4H6N/DGhvtNKybWHVE8mobuBfES+hjMECwQi2E2knpYPUkvNuWIXxFHMdfeyHaH+eNTYyR2IzdYprM9qco+IpvM9Om5dKWrnFjTzK4WPzCSVOqtDFvJX/wb2kTDvNhKY8/aFBYDdJZcfrYBB/jOWr2yH3Z88oEJcBH+xjPJawZKYJbA= 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: Split out the madvise behavior applying logic from do_madvise() to make it easier to reuse from the following change. Signed-off-by: SeongJae Park --- mm/madvise.c | 53 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 9cc31efe875a..913936a5c353 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1613,6 +1613,35 @@ static bool is_valid_madvise(unsigned long start, size_t len_in, int behavior) return true; } +static int madvise_do_behavior(struct mm_struct *mm, + unsigned long start, size_t len_in, size_t len, int behavior) +{ + struct blk_plug plug; + unsigned long end; + int error; + +#ifdef CONFIG_MEMORY_FAILURE + if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE) + return madvise_inject_error(behavior, start, start + len_in); +#endif + start = untagged_addr_remote(mm, start); + end = start + len; + + blk_start_plug(&plug); + switch (behavior) { + case MADV_POPULATE_READ: + case MADV_POPULATE_WRITE: + error = madvise_populate(mm, start, end, behavior); + break; + default: + error = madvise_walk_vmas(mm, start, end, behavior, + madvise_vma_behavior); + break; + } + blk_finish_plug(&plug); + return error; +} + /* * The madvise(2) system call. * @@ -1690,7 +1719,6 @@ int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int beh unsigned long end; int error; size_t len; - struct blk_plug plug; if (!is_valid_madvise(start, len_in, behavior)) return -EINVAL; @@ -1704,28 +1732,7 @@ int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int beh error = madvise_lock(mm, behavior); if (error) return error; - -#ifdef CONFIG_MEMORY_FAILURE - if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE) - return madvise_inject_error(behavior, start, start + len_in); -#endif - - start = untagged_addr_remote(mm, start); - end = start + len; - - blk_start_plug(&plug); - switch (behavior) { - case MADV_POPULATE_READ: - case MADV_POPULATE_WRITE: - error = madvise_populate(mm, start, end, behavior); - break; - default: - error = madvise_walk_vmas(mm, start, end, behavior, - madvise_vma_behavior); - break; - } - blk_finish_plug(&plug); - + error = madvise_do_behavior(mm, start, len_in, len, behavior); madvise_unlock(mm, behavior); return error;