Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1547943rdb; Wed, 20 Sep 2023 12:13:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGh/d7Ro9LXZ3B94bba1U1ByXbJq4rjQCY2I+CxR4gR2+ump/yUNsaJi+zME+Xi5hOEYmEK X-Received: by 2002:a17:90a:af96:b0:274:2efc:2fe5 with SMTP id w22-20020a17090aaf9600b002742efc2fe5mr3315357pjq.7.1695237197203; Wed, 20 Sep 2023 12:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695237197; cv=none; d=google.com; s=arc-20160816; b=D73l8ILtc7N8H+dxNjjNo0PCp958gwAyDx87TmqNtu2mfTwDjZ6xUGVAsnfuU695KK WDOFT58xNvH1oadJ852dnd6fhb6LirRyikNVgHt3t73O0txpWW5pGdszFxjUNahvHibs f3pBhevuxkXa0DMG06NHOnRjG+A29Kfd7lOhB/xPrtV1zUgow4acu9AQA9GSao5eND+F WsrGwwFBMapr2PD3wvzyaefb0+PboYp70Vwq0+T/J/Xv7S2VnCwdBp+fJtI04zNYe5JW wFGHqv5jkSWboSM4000FKjUkizHJa3Me9McUUIE+Bz8M+lzqp+aDKhu0nu/hLTAsG7Q1 oDiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2Ui9HQp2pxPJ3NIxebx6kuSf7rRkN1tIaYoms9ZvXGw=; fh=trQN94Iqca1GMQF1AkSOofuqg8pe0AKHPTTlJaXdYFw=; b=lgU0wdiISV0xNQ9/aGfqSeWyQBOUcovYO79b0dmTKzYCDNskqrpAQErfq5QOAWjMZS fpqntdNzR4IfkEPfftMyvcTvD4M0I8QTmlDnIKeYpfU5M+UPwQk2vj1mxoASHp9LCRxS YQlQAfn4QHb6rzoRXVq+LZPi6763Md2JTlh4Ckp6/m9Zmdqpf22CFBNrlRgJzDtijjjD ORhPzj4LvVpLC5nSOYyqq1XNKzdu3ZoZgbGYPc8qwy9j4JhrNeq4s4ZkXeR0FlsQjawx CG1nxCXZ/D4agYcwbazquE1QOUJG94cbNWMCTajcC9hBmKMrtdW+YS9Ef+EpgCETM5D3 6aRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id mj18-20020a17090b369200b00273fc50cf8dsi1982295pjb.156.2023.09.20.12.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:13:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E53CE80560DC; Wed, 20 Sep 2023 12:01:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbjITTBo (ORCPT + 99 others); Wed, 20 Sep 2023 15:01:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbjITTBm (ORCPT ); Wed, 20 Sep 2023 15:01:42 -0400 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D56DBCF for ; Wed, 20 Sep 2023 12:01:35 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 12:01:49 -0700 (PDT) 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/coredum= p.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) =20 #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) =20 +#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) =20 -#define MMF_VM_MERGE_ANY 29 #endif /* _LINUX_SCHED_COREDUMP_H */ --=20 2.39.3