From mboxrd@z Thu Jan 1 00:00:00 1970 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 3FBC2C433F5 for ; Wed, 18 May 2022 14:32:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FB6D6B0071; Wed, 18 May 2022 10:32:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A9766B0073; Wed, 18 May 2022 10:32:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3717F6B0074; Wed, 18 May 2022 10:32:05 -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 274D96B0071 for ; Wed, 18 May 2022 10:32:05 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D6AC92078E for ; Wed, 18 May 2022 14:32:04 +0000 (UTC) X-FDA: 79479103368.26.0B371A3 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf09.hostedemail.com (Postfix) with ESMTP id 25BFB1400C5 for ; Wed, 18 May 2022 14:31:53 +0000 (UTC) Received: by mail-lf1-f52.google.com with SMTP id bq30so3997961lfb.3 for ; Wed, 18 May 2022 07:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/o8jxVzJHrKnQPYDyUAFY3NEjQoX1p3FxNxyj6gs2jo=; b=bXqsD/5OKiD06afoIxdd1RhVMAV2zjqVL4xb7Xr54EBlsylyb9Wkk1QlqHJEdwHgRE 9rwcacTUnE/upPhQpvGq9LsbYdhP1B9Bg72S/dRXj8nEpgd7l0ZM+ujjwQxRRGnkFcGD mNXhIoVNgPnHoTQr7WuMD+i4pUl5aQ0jSHN0u7D3UsVKfBPHYVPkjTTa3oY7IHad2pHE Gx6+UTsexYvbkSkzn/wNS9wqQlDv3pNBNfgBiyADqiu3vrBwdAqtfCsPDdb8omg337qz gNQesHwQLsKQ06lU3wT9xijpTl3I4rwKTbq2eOFC0euMekwhzEfSDPYlk0zGcWLSBpvD KEMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/o8jxVzJHrKnQPYDyUAFY3NEjQoX1p3FxNxyj6gs2jo=; b=nIK6EMZaT4REfJIvhFMy9Bk3NwyD/486YShHQYufe8yEhLXMXk5m3zOFMpI3TTOMAI NmLGObFDhurvl83SY53kSwiqo7j9J2hvr5PkNtcoaoKaFnxgZNQHFc+I29J54fnQN0wx rEoP1kIwfhl7sQBiJ2cIk3a4huNj52KZVlNhSkZ8BOqiX09R3VFet3z62WE0wOpbxadX 59j6BsTewl2HxCJVGGIaM/9wi7n8qLL8EDwYj2+bGcbHHWEsdapNQS8lFgYTvBS4wjYB trNpJ2Dgzuh0wEE9fZOwiKlvC4r18ds/xcpsRfcLP+ufnQn7fV8qCkzMEQmaQe6BBjHB YA6A== X-Gm-Message-State: AOAM532WB7s4bFU85BY6ryjnmLFKWYY/Ekpqno/+TT6H8uMasveqWm6e MPoB+xleoCyMlDRlXKgNsyIRaB4FvDmJNRLF6Oa6Jg== X-Google-Smtp-Source: ABdhPJwvHhNIm1ioaXivr1UG6rcLmkD8H6VcQUQxqzau9d3Y7/VhluB9oHhC+sEH5vKG0dLaXf6ExZQK4mJaVcn1YIw= X-Received: by 2002:a05:6512:260d:b0:445:c06e:8242 with SMTP id bt13-20020a056512260d00b00445c06e8242mr19938085lfb.157.1652884322270; Wed, 18 May 2022 07:32:02 -0700 (PDT) MIME-Version: 1.0 References: <20220517092701.1662641-1-xu.xin16@zte.com.cn> In-Reply-To: <20220517092701.1662641-1-xu.xin16@zte.com.cn> From: Jann Horn Date: Wed, 18 May 2022 16:31:26 +0200 Message-ID: Subject: Re: [PATCH] mm/ksm: introduce ksm_enabled for each process To: cgel.zte@gmail.com Cc: akpm@linux-foundation.org, ammarfaizi2@gnuweeb.org, oleksandr@natalenko.name, willy@infradead.org, linux-mm@kvack.org, corbet@lwn.net, linux-kernel@vger.kernel.org, xu xin , Yang Yang , Ran Xiaokai , wangyong , Yunkai Zhang , Jiang Xuexin , Michal Hocko , Hugh Dickins , Linux API , Daniel Gruss Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 7thjoxpc58tkekztz61a3zjad7q3ahdg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 25BFB1400C5 X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="bXqsD/5O"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of jannh@google.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=jannh@google.com X-HE-Tag: 1652884313-948642 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: On Tue, May 17, 2022 at 11:27 AM wrote: > For now, if we want to use KSM to merge pages of some apps, we have to > explicitly call madvise() in application code, which means installed > apps on OS needs to be uninstall and source code needs to be modified. > It is very inconvenient because sometimes users or app developers are not > willing to modify their app source codes for any reasons. As a sidenote: If you're going to enable KSM on your devices, I hope you're aware that KSM significantly reduces security - when cloud providers were using KSM, there were a bunch of papers that abused it for attacks. In particular, KSM inherently creates significant information leaks, because an attacker can determine whether a memory page with specific content exists in other apps through timing side channels. In the worst case, this could lead to an attacker being able to steal things like authentication tokens out of other apps. If you see significant memory savings from enabling KSM, it might be a good idea to look into where exactly those savings are coming from, and look into whether there is a better way to reduce memory utilization that doesn't rely on comparing entire pages against each other. See https://arxiv.org/pdf/2111.08553.pdf for a recent research paper that shows that memory deduplication can even make it possible to remotely (!) leak memory contents out of a machine, over the internet. (On top of that, KSM can also make it easier to pull off Rowhammer attacks in some contexts - see https://www.usenix.org/system/files/conference/usenixsecurity16/sec16_paper_razavi.pdf .)