From patchwork Wed Sep 20 19:01:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13393221 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 88975C04FEA for ; Wed, 20 Sep 2023 19:01:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01BC66B0197; Wed, 20 Sep 2023 15:01:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E98AD6B0198; Wed, 20 Sep 2023 15:01:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D10046B0199; Wed, 20 Sep 2023 15:01:40 -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 C1BE36B0197 for ; Wed, 20 Sep 2023 15:01:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 30905A0B1E for ; Wed, 20 Sep 2023 19:01:40 +0000 (UTC) X-FDA: 81257894760.06.58A3AB1 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf11.hostedemail.com (Postfix) with ESMTP id 0336040004 for ; Wed, 20 Sep 2023 19:01:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf11.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695236498; 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=zDMnVkJ395bMMgNnWMMCV3Ohuwpcna8KJO1NY/PB2sxZ37jLz71FpV55miJJrlHTjdhk7W I5kiBv8Z/G65SP5LS5rePwPaQRbRvFQP+JYmS8I1gKMkD/rbPYXn0/uFez+qcQKzc84elX x4zakRgmenAjGyXmUWVfGwYOAZVUotc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf11.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695236498; a=rsa-sha256; cv=none; b=idW5rVjXga5KPAgw6wZHFAPbCbCLuw3EvbxaARLdsn/JsAQvQl5MJ4Bzyqlhc1zlJyqvbw VOGVPro4vMi/Qp/qAummhWhBeDa55QbOcYdZZA5iALutLnPrLNelnRCNny003kRKv2gUQw Jlywch06n5nq4nnrUButerihDx7Gwnc= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 33BFBC4363F6; Wed, 20 Sep 2023 12:01:22 -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 v2 1/2] mm/ksm: support fork/exec for prctl Date: Wed, 20 Sep 2023 12:01:16 -0700 Message-Id: <20230920190117.784151-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230920190117.784151-1-shr@devkernel.io> References: <20230920190117.784151-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-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JWgenGiJ 1kjrvyZIZgyITzATHblTWX0751IBZ4sKIlpvZe1RPw3O2j2wl6YCHzM5rdo8+7HtrjSp9uSEtFAW2d/OqQi+xiMu0fQaLPs6Em4I3yV0/Vspqmnc+RdQTRYW7hu1HShwnKQoc/Ef0HfusuzQjpOf2jySQynxybSDSpiccLCbcEQ5ht0aPpfTiJaKbUnQRVZreH+eg 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 */