From patchwork Thu Sep 21 16:47:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13394034 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 E7EC9E71094 for ; Thu, 21 Sep 2023 16:47:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 857AF6B0204; Thu, 21 Sep 2023 12:47:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BA146B0206; Thu, 21 Sep 2023 12:47:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A8486B0207; Thu, 21 Sep 2023 12:47:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5E4CB6B0204 for ; Thu, 21 Sep 2023 12:47:27 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 30D06C0B0B for ; Thu, 21 Sep 2023 16:47:27 +0000 (UTC) X-FDA: 81261185334.05.AF2ABA6 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf25.hostedemail.com (Postfix) with ESMTP id 8883DA0021 for ; Thu, 21 Sep 2023 16:47:25 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=neutral (imf25.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695314845; a=rsa-sha256; cv=none; b=0fby5DSfP/9RC9YE+v6H+T0CDcyIHycJbtu3OHmL/lArxRYjBqer9jwkZxMXGiH/sZ4y71 nrkAaMZYdAT2/mZomBOzBP0/nd8sLXQEXcAIo5PF1l89XrogKViZRIuQJzT4uuK2gAGnHt nPHGyX6uyzB6qDFZH9IcU9oFBgy5qnQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=neutral (imf25.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695314845; 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; bh=2Ui9HQp2pxPJ3NIxebx6kuSf7rRkN1tIaYoms9ZvXGw=; b=bpdu/egjJzZCdO5MaTmibNJPmgXIQdgxHgSo29nLK7eGsv8vJCQ3sJ5z2lMHySi1puBexP HhEdjLVOZD/aTj+XD12d0hVuzf6Xwo8uTehjl6rj+eqlgeuho5WE9Cg9nXkC3Bwry7eriV ZVVWlyC0RP8n0mSywMLpGlcVGw8Z+v4= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 74B35C502489; Thu, 21 Sep 2023 09:47:11 -0700 (PDT) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Carl Klemm Subject: [PATCH v3 1/2] mm/ksm: support fork/exec for prctl Date: Thu, 21 Sep 2023 09:47:08 -0700 Message-Id: <20230921164709.3627565-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230921164709.3627565-1-shr@devkernel.io> References: <20230921164709.3627565-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rsp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7Fl MrKUhtdn cF98YDYvc/EBF3C6Vs432bCrnGT2XCEUQZBgRtI5tt38gW23M3USVkOIN0icDazPFLFk68cw3wFK8LB9ULThp7yMsCFze+t6l7xcqrBmkEHsZSkNGlxiOcheoNMpx2E3/SqaujpH3TxWaZpADYzp3LIOh/LKGfvzeVs1nYCyrb/Iw15immTQPuTRF6A== 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: A process can enable KSM with the prctl system call. When the process is forked the KSM flag is inherited by the child process. However if the process is executing an exec system call directly after the fork, the KSM setting is cleared. This patch addresses this problem. Signed-off-by: Stefan Roesch Fixes: d7597f59d1d3 ("mm: add new api to enable ksm per process") Reviewed-by: David Hildenbrand Reported-by: Carl Klemm Tested-by: Carl Klemm --- include/linux/sched/coredump.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h index 0ee96ea7a0e9..205aa9917394 100644 --- a/include/linux/sched/coredump.h +++ b/include/linux/sched/coredump.h @@ -87,8 +87,11 @@ static inline int get_dumpable(struct mm_struct *mm) #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) +#define MMF_VM_MERGE_ANY 29 +#define MMF_VM_MERGE_ANY_MASK (1 << MMF_VM_MERGE_ANY) + #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ - MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK) + MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\ + MMF_VM_MERGE_ANY_MASK) -#define MMF_VM_MERGE_ANY 29 #endif /* _LINUX_SCHED_COREDUMP_H */