From patchwork Mon Mar 18 09:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjiang Tu X-Patchwork-Id: 13595090 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 78BE6C54E5D for ; Mon, 18 Mar 2024 08:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0CA26B0085; Mon, 18 Mar 2024 04:10:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBCC56B0087; Mon, 18 Mar 2024 04:10:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A87426B0088; Mon, 18 Mar 2024 04:10:43 -0400 (EDT) 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 957CE6B0085 for ; Mon, 18 Mar 2024 04:10:43 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 212B01C04A7 for ; Mon, 18 Mar 2024 08:10:43 +0000 (UTC) X-FDA: 81909438366.15.01EC5FD Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf27.hostedemail.com (Postfix) with ESMTP id 92E4940009 for ; Mon, 18 Mar 2024 08:10:40 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710749441; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=CP0Yjvl3vjV7csJzOrkVtt8cVeh4bk3H+4+xaZUDZcc=; b=8mnFHvh87troCn9B4PODOvS5kYy/CR5XuvE1dSzq1zAUsn46dQbvAB6f/aCK751AzVI0Fc 5VVaERUNgr4079DoA45Qcp4bR6pjIMnRExt1jbnfUpxfydZfVvif+IU555ELxwQgsE9zo5 valb3Lxq+JTdmlgam+HBXOZDNAQ0TUk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710749441; a=rsa-sha256; cv=none; b=B4BfWQd0QJlHUenRB92P3Nh+DlFtmda/nOZ4xnTpn43QxvmJCeEfDOWS8p+QqZQTJ7X7FZ +GvvjZCvABcZlXc5hZdQWPjNOjPjFSJ291b4LCiqMyAWtaP0AtzkmMWi7GG8u3An2MfFUI jGCFE6iyZT7jQ8Xec+d4nAdhafd82nY= Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4TynYT4wVhzNm7Q; Mon, 18 Mar 2024 16:08:45 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id B0C5B18006C; Mon, 18 Mar 2024 16:10:36 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 18 Mar 2024 16:10:36 +0800 From: Jinjiang Tu To: , , , , , , , CC: Subject: [PATCH v3] mm/ksm: fix ksm exec support for prctl Date: Mon, 18 Mar 2024 17:04:41 +0800 Message-ID: <20240318090441.179486-1-tujinjiang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500011.china.huawei.com (7.185.36.84) X-Rspamd-Queue-Id: 92E4940009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: tby7wjqe88oyrsw9rp36bu7c7xsmjos5 X-HE-Tag: 1710749440-728417 X-HE-Meta: U2FsdGVkX1/aMJL6tZ5pvvFosF/NpRItBNRQBSGPntZ8Ibh8m6O+M1nKOm0xu9cJRTNbvN86GbO0tSJnTnuO03CsQVdXNKQV87RxINQUVyhDYV3HmrUWGRg4hllvJOK2+QUA6qXnPcnlYToxMgupTU+AXCF/f0lyISa5gstVHOxT1OGbcBz+wPTc72rsOLiXUlH+WT8cwBmvCXpMkRC+18SIGaKNk7wvCQxVz3WILMT+KLTuWBg4lpqmT0x40yMX/sVWawBnI5pKN1CBFQbTfZ/XJGwEHFgH13JkJ0a8G1c4E7yB5EvPCBi/gf/XbW77W/N571Uzx4sfN75v8B338ZkX3YonapCOvaq/QAoHVLTKPxWOqCsr/ZnVn1ll10JRqkdzLj/+OHrX0RmQ6tT7YcquSMDZl2GkV01F80XrUvmPrwjQcqb4o7mmGOORE1rPjm9VqZThFc1OHJTkJA1Dq/RCJvDyVbOC4n01JzcskuIiVyxKAPFVug+V8dJHWufr1uK6Fif1FdPsI09A8Nq595UDLQhh8sl+wvFun1cqBR/koCqaGEdT/wI6n+hQs+LlzNSNhaF+Q8pUk+wJHX21HgS97EyCveL0SgHP1Q0H4cqrIP2EYvqo3Auvu4E67GgwY26AK0qfYqI7PIbQBLvjjhVb1C5w3l34JxUotD2YgVDTr6h/m5oWg2s44t8UcXk77OToRvC+3zk2w5l6Z42vke373FL3NqUQRAF9q2rJG88AKFdBm48EZ6Qf1UY1FbNJRDJvbraKgxGA+DqonSlXc0ivTNvcjxKXR71t0i1u+K2aaJw2NY82DkqgkJWQBSA4jh4PFw62Phh2j1m6Qt5WNqQUfcFSEyFT439ISYrSHJx24E3JfqCP+S9bTYCCm3dzjxxERxawwivpxHf8CnLXGF7bQlHeYrwTMG1qbuYXjxK7kLd08W/A3rRFcQ3hCH763g+brHFkeb74OUDwFGk FjgJkXKO Zc+D2GTU1ZXpEb8wQFz5Um5NbR0oRYtTGsPz2n0MeghN49tpJQTFuEK3wnRsC+Myw49RVO5l1SPxz6oCc9o5aNMqMKzt9JynC/EoWV2EoM3dehPKOxnzw3fsPvDPe9Laur2b0DEyZbiV0Z9cXqZ1nRTDbL+AId+iBDuZuqTepTNM6wocGlPp+Oq38DA== 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: commit 3c6f33b7273a ("mm/ksm: support fork/exec for prctl") inherits MMF_VM_MERGE_ANY flag when a task calls execve(). Howerver, it doesn't create the mm_slot, so ksmd will not try to scan this task. To fix it, allocate and add the mm_slot to ksm_mm_head in __bprm_mm_init() when the mm has MMF_VM_MERGE_ANY flag. Fixes: 3c6f33b7273a ("mm/ksm: support fork/exec for prctl") Signed-off-by: Jinjiang Tu --- fs/exec.c | 4 ++++ include/linux/ksm.h | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index ff6f26671cfc..00f40163cc12 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -267,6 +268,9 @@ static int __bprm_mm_init(struct linux_binprm *bprm) goto err_free; } + if (ksm_execve(mm)) + goto err; + /* * Place the stack at the largest stack address the architecture * supports. Later, we'll move this to an appropriate place. We don't diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 401348e9f92b..7e2b1de3996a 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -59,6 +59,14 @@ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) return 0; } +static inline int ksm_execve(struct mm_struct *mm) +{ + if (test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + return __ksm_enter(mm); + + return 0; +} + static inline void ksm_exit(struct mm_struct *mm) { if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) @@ -107,6 +115,11 @@ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) return 0; } +static inline int ksm_execve(struct mm_struct *mm) +{ + return 0; +} + static inline void ksm_exit(struct mm_struct *mm) { }