Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1581920pxu; Sat, 12 Dec 2020 18:47:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLeSka7bQF5AgCRtgXhJ8dawEgt9TcxHieH2N3TLtdNToRyxXlEo7xZpMrDYOYyC7kWyM4 X-Received: by 2002:a17:906:5912:: with SMTP id h18mr16968590ejq.261.1607827623031; Sat, 12 Dec 2020 18:47:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607827623; cv=none; d=google.com; s=arc-20160816; b=StqBnSs2UMCOz68wP4D9B4SKbFKuik3+xJNJ+h+RiqfOElRqOwn352hhJ/bmOWAW1K E14nkZ59k8/Lv97DW8ORUhKH7fbLjfhO/UI6iQHtMWy4wP0F6A+B0x8Ljhmx6EdcIfVN riei2oVREJklySTd3Xv1LAFysiprY+sR+bpU6pC5Q4F0dWfFqc3mzt1Ba4m9JM4YIlqc F1M8XXVZl9MjQ5mfnZGL7Qo8ygnTbo2crW1b12nE6twfWnMuhGR9BZlZywlGJ4kYpQDC /FodszbNZgDj7NXR+RQlLihMjMeo7R1bDvscEfAYAN8cO+4VZBE7ZxtbI3ZIcX/t0Pm2 vzkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Ov6E9ovGP4O2PjufZFcQsFjtRg7X8nEmJMclI/QMkDc=; b=pDVZQ6vrpX+NAFQ9lr/cu9WSMhBoC3luk4BFCNSAsEhDpI6kurgjs9b6MeW/buVk97 8bW5ruG/rZVdda6+kM2tMxZbzhcJEL1cb6kgVRxU8kKb7LRY5UP+DmCH1CGQrJFEowEs Ae08Rvsh8ETTzqPAeB5rCuIzmoh+JgLQENd1NNJanJF9XANmaPFJ2Rb8cU4Unk8djT26 w/sCx7UMM8oPn6tpdE5LpIyfiNmX4b2zclPKgfyq0KiuPjqZUCHKwvSPnlQuvUaEZTlj 3KHnXLZm3UqS7j+k2v+8bQxaJPmY2P1agrxdIqxbmJ21kuMxKGkMiDhF6ISfKWe1w6vl gW7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VfeB05Tn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si7922227ejr.672.2020.12.12.18.46.40; Sat, 12 Dec 2020 18:47:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VfeB05Tn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391086AbgLKU3b (ORCPT + 99 others); Fri, 11 Dec 2020 15:29:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391336AbgLKU2z (ORCPT ); Fri, 11 Dec 2020 15:28:55 -0500 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3394C061793 for ; Fri, 11 Dec 2020 12:28:14 -0800 (PST) Received: by mail-lj1-x241.google.com with SMTP id f11so12419499ljn.2 for ; Fri, 11 Dec 2020 12:28:14 -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=Ov6E9ovGP4O2PjufZFcQsFjtRg7X8nEmJMclI/QMkDc=; b=VfeB05TnKzT8k7qG5j2JTqEgnpHRx5eZuwRx+iOAq1g+qyYfZiMWKMjO8Llh9nqFzr oBwQa/TyPS7dFNb+g5BnVbBGnIjcGbutrSaIksGWvSLTWa/qN0ExWBDcxWasRBDUAhzK 4HHKzvyL2den97oJb15WqZGhvdblNNDCNJRLU6ughgfsxVSUdgQPuf/pTY/Nuo0ZAoo+ FsUQRvVTpLHZ/4Mfq1mK+FudM2gmfdv4uUBi1F5zhCw0pxC8AAQ3SUBmumOkQWGc39Dr rn00dPvBmIs6+JE58NWHwjSrID3zEcVVOV1fPyqFi3ijl3q4zYn9ZCk+R6M1De4MbcAw cMfA== 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=Ov6E9ovGP4O2PjufZFcQsFjtRg7X8nEmJMclI/QMkDc=; b=Y7t4IihI84bx5Gr+sN8qWZd7OfHn7v3kYT57fsM/t98fEWxreUm8CnTESNEPn/Mpax N/pEO0JsDLfzm09hSt2jlbPUSczvL5GGG5I8rxP5VNWFU/UXBgZ6P+EjmG4eJ4C3hh67 3bfpvPo/x5TJUYuz44HPOa7Mmot/JmHS583F00szWayWjuQMZCl5DOLp+7+qC92UXs8E 3Olm7qfT9unsMGYj/h2msGNmxtDHNZfizZclclAjV8jNL30uKMjxCweAssyozN9MCn0I pQ1ts39G5eQLGcmgi8c5OLeIyO/lex9/k+kwHHlNEZdRKB/1yShZgsSBufsqnlLjBXx4 ud6w== X-Gm-Message-State: AOAM531LLvrVr7424fCn3vYk/7+3U7LphPt9FtddvCRqMHBAQ0389J1Y 2fpw2sKyVQB2Lxi6nc9JrcvsSN8jV1h6aED3tXpLqA== X-Received: by 2002:a2e:593:: with SMTP id 141mr5908685ljf.86.1607718493088; Fri, 11 Dec 2020 12:28:13 -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: <20201125231322.GF1484898@google.com> From: Jann Horn Date: Fri, 11 Dec 2020 21:27:46 +0100 Message-ID: Subject: Re: [PATCH 1/2] mm/madvise: allow process_madvise operations on entire memory range To: Minchan Kim , Christoph Hellwig Cc: 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +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.