Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1196613ybl; Tue, 13 Aug 2019 08:49:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8OyQFPGevlHQPvFrQgZzR+gxszjEiReCLz5BnmIz+Eti2XHUw0Tz3bwuI1XkbGlrKZbAP X-Received: by 2002:a17:90a:224e:: with SMTP id c72mr2892389pje.9.1565711369604; Tue, 13 Aug 2019 08:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565711369; cv=none; d=google.com; s=arc-20160816; b=xCmtfDi9YXOb2iPX/43Zpb+e4YNXJtlL8WrK2TotaIHw8pfVcqS4QlZUONu/G2oHvC qaF3ueAl4oteZkhb7KG3BnQt1lU6KNlvfKYp/T4E6IZxg3sdoXvH2DWVTAEqwo4uE3fK c5t2IZHsbxkJmqsjHshE3qwRNQB4+rIKb0bgSOZvpS/88m8Foo4PFMXYITcZyfRz4elp ZWWM5aiLjhR1Zc+mw8j7SmCT6QmNQudDeTF6zcbZ/6G8/WMXx7nkIqZQzV6LOVBY08Md rYwRW6mIBtoo9ol7HxQQJdrxqBV1VPfUAfU4uQqasb3TzLsaDmHCqCNm45Z+hvVvjYQ4 VzNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MTdtKCAFd9Jy/7ibMRAuyCjCVrja1NtEGRgDRccZP3s=; b=ZVxycvuOTrSbtlP9x+O4RO3VB4MC5G+s75CqhxbRO7YFVq7SmFuWpl2fI1qa7hzkFJ x5vO9NwXwdOS8CUp09GiGgQTx/GDMP8AvP/LumhpMfYy7E4LOCx0m4N1ItEUPsOgGfoR vJ+KBco0rJ5haJ6PNIjFxWoD6iT0zUY9p6i3f/jQhW5L4gMXvOEjSF9x7N+dpgxyXc7/ ZfdK5Ax2NZbCyyVPdc9D02KKtkNUpHv42T1k6foqsAo8XFik+jNWfzZ9UQDCNhbwdclO UEPxpX2d9v6U7mZMTSnxHpuVK9UaUOgpQny2fzOCC3l18gXL6+yaXED+5lmBVndDeN7o tIjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="uw9/eV5N"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id f1si16866816pld.12.2019.08.13.08.49.13; Tue, 13 Aug 2019 08:49:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="uw9/eV5N"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1730090AbfHMPl0 (ORCPT + 99 others); Tue, 13 Aug 2019 11:41:26 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:42745 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727177AbfHMPl0 (ORCPT ); Tue, 13 Aug 2019 11:41:26 -0400 Received: by mail-ot1-f67.google.com with SMTP id j7so29409418ota.9 for ; Tue, 13 Aug 2019 08:41:25 -0700 (PDT) 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=MTdtKCAFd9Jy/7ibMRAuyCjCVrja1NtEGRgDRccZP3s=; b=uw9/eV5N0ZExRUVoCgJf8G+srilhjSZQGDy5IBC5b4v/wcuzr+Uw4cZNlYPOWtRP+l 3o5dtvf03dScoKE2SWAEtOoXv0C9YjnC0pVbiJQifIrMpUSH/roSYaqja1BcWza3cNqn tmQ70HlvmL5aGUkwVK4o0q2+NXAi3mdOjN/SjouEdsZmGxcCFsCYBAfdP0Vz0NoXuURd AkEbJUG2f5dTQNDs3ypBfxleNmvcO65GGXpuhvQZ4i3yRffgE/U5TP19aBcLzVtQVxu/ oAv467iy4QAb744hHdwVvgVVHO1RAhbxc35afTD2zkqXAXWulAa0c4vJA27HYjBSRElo 5e/g== 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=MTdtKCAFd9Jy/7ibMRAuyCjCVrja1NtEGRgDRccZP3s=; b=NRI/wN3D6jk+e73uVLvtGSrJTYnFWH+Seb21K/E3EdS/uYfh7zqMrLZhtFF3HNVnq8 Gngg+ztRgbfgYRgUVHngFDTKmbAzMq6Xw0Z3agWxzkQQKGWxFqRsM0KgptZBU5QNXfbd pNxWhptF7wNRyDFDk60A71ewLU1NshZ+W+mGtTtjVvT+9xcl1j6TlEjp5pas6cC0/7kk O84iHIH6SMamBub0dbOf3DseRsYvtKvHp7FyAb3vUswgoctzJyMt0h4zVQ0Y6Yp1TIxn CJc/Z3BqqSPlt8TdwASOz+yiOv/Sr15/jFugjK7uR59wAg24Z3vh/LOsJYVhhkcgcw4J Vfpg== X-Gm-Message-State: APjAAAVh/pAVkuB1hOAvCRgcuJjBKvoWBO160JgGzKJuphn1vWGyXt3X mnnR2ezKfaIgYTqyd/4BK4n81xLq0cVS55utM5BVfqFyBFIgZQ== X-Received: by 2002:aca:dd55:: with SMTP id u82mr2003223oig.68.1565710885153; Tue, 13 Aug 2019 08:41:25 -0700 (PDT) MIME-Version: 1.0 References: <20190807171559.182301-1-joel@joelfernandes.org> <20190813153020.GC14622@google.com> In-Reply-To: <20190813153020.GC14622@google.com> From: Jann Horn Date: Tue, 13 Aug 2019 17:40:58 +0200 Message-ID: Subject: Re: [PATCH v5 1/6] mm/page_idle: Add per-pid idle page tracking using virtual index To: Joel Fernandes Cc: kernel list , Alexey Dobriyan , Andrew Morton , Borislav Petkov , Brendan Gregg , Catalin Marinas , Christian Hansen , Daniel Colascione , fmayer@google.com, "H. Peter Anvin" , Ingo Molnar , Jonathan Corbet , Kees Cook , kernel-team , Linux API , linux-doc@vger.kernel.org, linux-fsdevel , Linux-MM , Michal Hocko , Mike Rapoport , Minchan Kim , namhyung@google.com, "Paul E. McKenney" , Robin Murphy , Roman Gushchin , Stephen Rothwell , Suren Baghdasaryan , Thomas Gleixner , Todd Kjos , Vladimir Davydov , Vlastimil Babka , Will Deacon Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 13, 2019 at 5:30 PM Joel Fernandes wrote: > On Mon, Aug 12, 2019 at 08:14:38PM +0200, Jann Horn wrote: > [snip] > > > +/* Helper to get the start and end frame given a pos and count */ > > > +static int page_idle_get_frames(loff_t pos, size_t count, struct mm_struct *mm, > > > + unsigned long *start, unsigned long *end) > > > +{ > > > + unsigned long max_frame; > > > + > > > + /* If an mm is not given, assume we want physical frames */ > > > + max_frame = mm ? (mm->task_size >> PAGE_SHIFT) : max_pfn; > > > + > > > + if (pos % BITMAP_CHUNK_SIZE || count % BITMAP_CHUNK_SIZE) > > > + return -EINVAL; > > > + > > > + *start = pos * BITS_PER_BYTE; > > > + if (*start >= max_frame) > > > + return -ENXIO; > > > + > > > + *end = *start + count * BITS_PER_BYTE; > > > + if (*end > max_frame) > > > + *end = max_frame; > > > + return 0; > > > +} > > > > You could add some overflow checks for the multiplications. I haven't > > seen any place where it actually matters, but it seems unclean; and in > > particular, on a 32-bit architecture where the maximum user address is > > very high (like with a 4G:4G split), it looks like this function might > > theoretically return with `*start > *end`, which could be confusing to > > callers. > > I could store the multiplication result in unsigned long long (since we are > bounds checking with max_frame, start > end would not occur). Something like > the following (with extraneous casts). But I'll think some more about the > point you are raising. check_mul_overflow() exists and could make that a bit cleaner. > > This means that BITMAP_CHUNK_SIZE is UAPI on big-endian systems, > > right? My opinion is that it would be slightly nicer to design the > > UAPI such that incrementing virtual addresses are mapped to > > incrementing offsets in the buffer (iow, either use bytewise access or > > use little-endian), but I'm not going to ask you to redesign the UAPI > > this late. > > That would also be slow and consume more memory in userspace buffers. > Currently, a 64-bit (8 byte) chunk accounts for 64 pages worth or 256KB. I still wanted to use one bit per page; I just wanted to rearrange the bits. So the first byte would always contain 8 bits corresponding to the first 8 pages, instead of corresponding to pages 56-63 on some systems depending on endianness. Anyway, this is a moot point, since as you said... > Also I wanted to keep the interface consistent with the global > /sys/kernel/mm/page_idle interface. Sorry, I missed that this is already UAPI in the global interface. I agree, using a different API for the per-process interface would be a bad idea.