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 X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96A92C4361B for ; Sat, 12 Dec 2020 01:13:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B93B2336F for ; Sat, 12 Dec 2020 01:13:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B93B2336F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 99DFC6B005D; Fri, 11 Dec 2020 19:17:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94F586B0068; Fri, 11 Dec 2020 19:17:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8175D6B006C; Fri, 11 Dec 2020 19:17:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 690056B005D for ; Fri, 11 Dec 2020 19:17:26 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 36423181AEF1E for ; Sat, 12 Dec 2020 00:17:26 +0000 (UTC) X-FDA: 77582716092.26.actor50_241325127405 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 157DA1803F1A6 for ; Sat, 12 Dec 2020 00:17:26 +0000 (UTC) X-HE-Tag: actor50_241325127405 X-Filterd-Recvd-Size: 7198 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Sat, 12 Dec 2020 00:17:25 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id h19so15732827lfc.12 for ; Fri, 11 Dec 2020 16:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=k6oIUvn/IBCxtIINsfT27es3SVZ5FJQGfE7GX4CvWQ0=; b=TykSgSbxK85MbhpzI4vYR/Ri9l5a7iWwL/pohJU4OO7DKhs3wk/uimaqizBaM/vpqZ SLw9ET5otvLqzWxt2X2B6pr+mgjxbjz6Bz1pa7hJhwiuK0Uh0/0TMc2++bjFX3TDb2RP IXJNDzNKImgMO/uZzJPvYpY/2ozgdpzLga1lFK/BZS+i7CJ4O6YTbzYoExtQxEOdGEgn kLr1zpS3dIMo18HYlCQpCHP0JJEHk7ySvfa5C4oE/KT8pZZ2cNfouecTekbNVwbTjsZM EgujEd051O8tPdCxYWalo7PJKCuDMT2BsOKWYCX/y8Bla7ybS8qH3q58wLgpJujOB+qz KdCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=k6oIUvn/IBCxtIINsfT27es3SVZ5FJQGfE7GX4CvWQ0=; b=S18USbS0rUD/q+pW0B+QfqBy7qSy12AUlAQ7yq2v+CLYIss+HyX5G7CFoq0vyJ9zuO P3vEq6QXGwkq3/+YzL80q5lO43AlBQiA7bv1gYxpHwDXN3OHmBQtWiZ8CIMNXU7bb57Z 31wOmcwUQccS92V7SZfyqUr+8BFTfX4CC4PMUSpx2ctQqSaEY7XQK1CHnvwYvsk6G6Ug bhELkYdOoI/Jfbvqgrr+hjTah+Q9bKIX0dt0oDDzJ0+SHkZ5cMUmrD9dxwVVvSMoHn5Y cbjyzUEKQqDi9YoYqyiVG4eaR0WQnhuZCjW0xIAV3QqP3CU5hwfeM/UJ+OHIHZUAzHNi 0s1A== X-Gm-Message-State: AOAM530Pov9kA1DAN3VluRQ4eH4kankvSrqbKGNUN0L0Ts9FffvAbd2Z v16lmmrKuOI67J+Se9az3qi9ODYiUBG5K9t+rGc4Ng== X-Google-Smtp-Source: ABdhPJwn8/rXUEFnVDx91D7syH2qUxybJmjPMept6dleKna4tEdWQz/TUZBPUsQAlRjCuv+5Sr61kt/PjAJPgf4zF9M= X-Received: by 2002:a19:8cb:: with SMTP id 194mr5438253lfi.463.1607732243934; Fri, 11 Dec 2020 16:17:23 -0800 (PST) MIME-Version: 1.0 References: <20201124053943.1684874-1-surenb@google.com> <20201124053943.1684874-2-surenb@google.com> <20201125231322.GF1484898@google.com> In-Reply-To: From: Jann Horn Date: Sat, 12 Dec 2020 01:16:57 +0100 Message-ID: Subject: Re: [PATCH 1/2] mm/madvise: allow process_madvise operations on entire memory range To: Minchan Kim Cc: Christoph Hellwig , Suren Baghdasaryan , Andrew Morton , Michal Hocko , Michal Hocko , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Rik van Riel , Christian Brauner , Oleg Nesterov , Tim Murray , Linux API , Linux-MM , kernel list , kernel-team Content-Type: text/plain; charset="UTF-8" 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 Sat, Dec 12, 2020 at 12:01 AM Minchan Kim wrote: > On Fri, Dec 11, 2020 at 09:27:46PM +0100, Jann Horn wrote: > > +CC Christoph Hellwig for opinions on compat > > > > On Thu, Nov 26, 2020 at 12:22 AM Minchan Kim wrote: > > > On Mon, Nov 23, 2020 at 09:39:42PM -0800, Suren Baghdasaryan wrote: > > > > process_madvise requires a vector of address ranges to be provided for > > > > its operations. When an advice should be applied to the entire process, > > > > the caller process has to obtain the list of VMAs of the target process > > > > by reading the /proc/pid/maps or some other way. The cost of this > > > > operation grows linearly with increasing number of VMAs in the target > > > > process. Even constructing the input vector can be non-trivial when > > > > target process has several thousands of VMAs and the syscall is being > > > > issued during high memory pressure period when new allocations for such > > > > a vector would only worsen the situation. > > > > In the case when advice is being applied to the entire memory space of > > > > the target process, this creates an extra overhead. > > > > Add PMADV_FLAG_RANGE flag for process_madvise enabling the caller to > > > > advise a memory range of the target process. For now, to keep it simple, > > > > only the entire process memory range is supported, vec and vlen inputs > > > > in this mode are ignored and can be NULL and 0. > > > > Instead of returning the number of bytes that advice was successfully > > > > applied to, the syscall in this mode returns 0 on success. This is due > > > > to the fact that the number of bytes would not be useful for the caller > > > > that does not know the amount of memory the call is supposed to affect. > > > > Besides, the ssize_t return type can be too small to hold the number of > > > > bytes affected when the operation is applied to a large memory range. > > > > > > Can we just use one element in iovec to indicate entire address rather > > > than using up the reserved flags? > > > > > > struct iovec { > > > .iov_base = NULL, > > > .iov_len = (~(size_t)0), > > > }; > > > > In addition to Suren's objections, I think it's also worth considering > > how this looks in terms of compat API. If a compat process does > > process_madvise() on another compat process, it would be specifying > > the maximum 32-bit number, rather than the maximum 64-bit number, so > > you'd need special code to catch that case, which would be ugly. > > > > And when a compat process uses this API on a non-compat process, it > > semantically gets really weird: The actual address range covered would > > be larger than the address range specified. > > > > And if we want different access checks for the two flavors in the > > future, gating that different behavior on special values in the iovec > > would feel too magical to me. > > > > And the length value SIZE_MAX doesn't really make sense anyway because > > the length of the whole address space would be SIZE_MAX+1, which you > > can't express. > > > > So I'm in favor of a new flag, and strongly against using SIZE_MAX as > > a magic number here. > > Can't we simply pass NULL as iovec as special id, then? AFAIK in theory NULL can be a valid userspace pointer (although that basically never happens and, on MMU systems, requires root to explicitly do it). On the other hand, there are some parts of the UAPI that already special-case NULL, so maybe that's considered acceptable? Also, special-casing NULL slightly increases the chance that userspace messes up and accidentally triggers completely different behavior because an allocation failed or something like that. So while I'm not strongly against using NULL here, I don't exactly like the idea.