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 3D477C433EF for ; Fri, 1 Jul 2022 10:32:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 929DF6B0071; Fri, 1 Jul 2022 06:32:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DBC56B0073; Fri, 1 Jul 2022 06:32:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A21A6B0074; Fri, 1 Jul 2022 06:32:31 -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 6B6B16B0071 for ; Fri, 1 Jul 2022 06:32:31 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2846934796 for ; Fri, 1 Jul 2022 10:32:31 +0000 (UTC) X-FDA: 79638166902.26.BC6DCFD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id B410EA0036 for ; Fri, 1 Jul 2022 10:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656671550; h=from:from: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:in-reply-to:references:references; bh=4td92aFJQKg+sJntCcVWvWuQk8fqytpXxmE8au2sJjk=; b=CR/mon9Gy0uxLSgVOW3ZS/7wy33ZhyV0ZtULQvnIqe+sPkEW+mS5NnWQoQQeqrABieaTy1 5seppQXA3iERAgY3xhreJHSmHiziwSGh8WsfEKs+xly+FxHKnkETypFGpSBUN1NYJqTatn 6l7MYpyaPJTS4c8KYEyigXFUTwUy1f0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-MyKNBXlHN1SG_SmdAhLXdQ-1; Fri, 01 Jul 2022 06:32:29 -0400 X-MC-Unique: MyKNBXlHN1SG_SmdAhLXdQ-1 Received: by mail-wr1-f72.google.com with SMTP id w12-20020adf8bcc000000b0021d20a5b24fso291000wra.22 for ; Fri, 01 Jul 2022 03:32:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=4td92aFJQKg+sJntCcVWvWuQk8fqytpXxmE8au2sJjk=; b=ioy1YctO5O2jC3zmbaYHNm2Pljrxt/khmR1IrQ8PXCHDqsho7Rpd+gF7TznK/JiWxv 7FK6ZAPZc3R1jeWp54Gc8vEC9lCQRWQErJMSgWFtHgb5G6+AIhqtxm40PEp6TXQJSK3W kWCv26Cnb5ptrvU7QfwGmufcsFBhJckerxcP3C7JlO0qkjK1S2C9vq7Y1CYY2FR1RQc8 THPatcqE3G4pB/Ws76w5TwjnXTtflj5tiSLgBBMOlFNOvSkHQRoCrprWcOgCqbvzjijO IPrseKICwy39+Fvmtync/PEoUEwtjCFjmk9D6Wh/1g4TpR0VlwYaG3B4Voxhg+H3uNHi VXSQ== X-Gm-Message-State: AJIora9UnFhOSCXIcUsLCkkad3KHUomUBJ61jImxqnQ4k9nhqjGzOh95 22E4KmQQkhxtMmRzFbQUL1C3ni7CsWr5sF9KO1KEjuC6paBD6DHRWUWqDpEEvgN+Fkj1szI/MRL PBRDSowQhY5A= X-Received: by 2002:a05:600c:a04:b0:39e:e392:ec22 with SMTP id z4-20020a05600c0a0400b0039ee392ec22mr17220742wmp.158.1656671547662; Fri, 01 Jul 2022 03:32:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sxgzfk67USL9MoveUOgUm0gnB/TEMJrBWpLPlvIJyLdbnI/1lrw5z5DuZUFb9Dd1fhLpS5KQ== X-Received: by 2002:a05:600c:a04:b0:39e:e392:ec22 with SMTP id z4-20020a05600c0a0400b0039ee392ec22mr17220709wmp.158.1656671547393; Fri, 01 Jul 2022 03:32:27 -0700 (PDT) Received: from ?IPV6:2003:cb:c709:e300:d7a0:7fc3:8428:43e5? (p200300cbc709e300d7a07fc3842843e5.dip0.t-ipconnect.de. [2003:cb:c709:e300:d7a0:7fc3:8428:43e5]) by smtp.gmail.com with ESMTPSA id g14-20020a05600c4ece00b0039c99f61e5bsm6727996wmq.5.2022.07.01.03.32.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Jul 2022 03:32:26 -0700 (PDT) Message-ID: <93e1e19a-deff-2dad-0b3c-ef411309ec58@redhat.com> Date: Fri, 1 Jul 2022 12:32:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH linux-next] mm/madvise: allow KSM hints for process_madvise To: Michal Hocko , cgel.zte@gmail.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz, minchan@kernel.org, oleksandr@redhat.com, xu xin , Jann Horn References: <20220701084323.1261361-1-xu.xin16@zte.com.cn> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CR/mon9G"; spf=none (imf15.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656671550; 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:in-reply-to:references:references:dkim-signature; bh=4td92aFJQKg+sJntCcVWvWuQk8fqytpXxmE8au2sJjk=; b=QMys2etRLxZO3rxGq2fD+sZtUwgoqxMo0R99FNAZE62oXCwOlgMRrN2DSrNuWLWYBOExOG rCxPWgx4X4DQGFEHIZpCdEbhslkmwyOe9rctfK/vMpT/NOXtfwGoaJ20AQqEo2sTUzs8nW ygp3g0IRG1ORO7i1Ts8lwHaO6P9d/lg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656671550; a=rsa-sha256; cv=none; b=2O8usmBJY/DWQk4P6VPMvwBaXYmbVe3+BDI2d182eP9vPV98MGHac0q3ABageIBo1vdWQ6 tmBkGghgjCgR1QQR2+ev/uOIrh+g7xSakFQ0xXcJsMZqoXq39/THw4P225O0Zjx7QGETJn CltK2QFbx/jl5IKCm+8yyeLIY3elcwM= X-Stat-Signature: jrs9fq3cot7e1mbfi79rkiphp41eiuc3 X-Rspamd-Queue-Id: B410EA0036 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CR/mon9G"; spf=none (imf15.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1656671550-453077 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 01.07.22 11:11, Michal Hocko wrote: > [Cc Jann] > > On Fri 01-07-22 08:43:23, cgel.zte@gmail.com wrote: >> From: xu xin >> >> The benefits of doing this are obvious because using madvise in user code >> is the only current way to enable KSM, which is inconvenient for those >> compiled app without marking MERGEABLE wanting to enable KSM. > > I would rephrase: > " > KSM functionality is currently available only to processes which are > using MADV_MERGEABLE directly. This is limiting because there are > usecases which will benefit from enabling KSM on a remote process. One > example would be an application which cannot be modified (e.g. because > it is only distributed as a binary). MORE EXAMPLES WOULD BE REALLY > BENEFICIAL. > " > >> Since we already have the syscall of process_madvise(), then reusing the >> interface to allow external KSM hints is more acceptable [1]. >> >> Although this patch was released by Oleksandr Natalenko, but it was >> unfortunately terminated without any conclusions because there was debate >> on whether it should use signal_pending() to check the target task besides >> the task of current() when calling unmerge_ksm_pages of other task [2]. > > I am not sure this is particularly interesting. I do not remember > details of that discussion but checking signal_pending on a different > task is rarely the right thing to do. In this case the check is meant to > allow bailing out from the operation so that the caller could be > terminated for example. > >> I think it's unneeded to check the target task. For example, when we set >> the klob /sys/kernel/mm/ksm/run from 1 to 2, >> unmerge_and_remove_all_rmap_items() doesn't use signal_pending() to check >> all other target tasks either. >> >> I hope this patch can get attention again. > > One thing that the changelog is missing and it is quite important IMHO > is the permission model. As we have discussed in previous incarnations > of the remote KSM functionality that KSM has some security implications. > It would be really great to refer to that in the changelog for the > future reference (http://lkml.kernel.org/r/CAG48ez0riS60zcA9CC9rUDV=kLS0326Rr23OKv1_RHaTkOOj7A@mail.gmail.com) > > So this implementation requires PTRACE_MODE_READ_FSCREDS and > CAP_SYS_NICE so the remote process would need to be allowed to > introspect the address space. This is the same constrain applied to the > remote momory reclaim. Is this sufficient? > > I would say yes because to some degree KSM mergning can have very > similar effect to memory reclaim from the side channel POV. But it > should be really documented in the changelog so that it is clear that > this has been a deliberate decision and thought through. > > Other than that this looks like the most reasonable approach to me. > >> [1] https://lore.kernel.org/lkml/YoOrdh85+AqJH8w1@dhcp22.suse.cz/ >> [2] https://lore.kernel.org/lkml/2a66abd8-4103-f11b-06d1-07762667eee6@suse.cz/ >> I have various concerns, but the biggest concern is that this modifies VMA flags and can possibly break applications. process_madvise must not modify remote process state. That's why we only allow a very limited selection that are merely hints. So nack from my side. -- Thanks, David / dhildenb