Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp539307imu; Thu, 22 Nov 2018 01:23:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vt/b/Iq/OZGFyaROh6U5ykNcw47AVA4IcHxud6iPxMgyrdS11+lwD17iX6UsQ2pVi9icJB X-Received: by 2002:a17:902:2969:: with SMTP id g96mr10394073plb.295.1542878624733; Thu, 22 Nov 2018 01:23:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542878624; cv=none; d=google.com; s=arc-20160816; b=WliIqKWaDv5A007+UAz69OhdDYnoxCdiNmLF/Fx7Qiz0xBLuNgPLeQyT0ImgPiOXUZ DEgbGIKgT3NbG00LQp87A6/c5yeNBC6Ey4JUTA/cmD7NQ1b8OlWtP0NcGRdbjEasmHW5 hCbhvatwFyl6Qzorhp+EBC8sJ+ZoqeNfT8WqM5fGkanFAKGuRpXLWibTK/dF4V1oYkiw Ge9rXGveAJJhpNtMdMQ3korPfyrkau+khBkVXCypxyJIupMafsUODCYr/R9clFTjlfXm oeO4ynmuG2Ap6cQl/lOBtDu4ZOduIP7rinh0DEsr7ehaYnvvgUwpa+kZIOICi2dgmoxv gEYQ== 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=P3FMEDsZInXhnswagiHhBthQ6heysrNaLGS/9ZfO7uw=; b=aUFr+42wYQk1fTt5iygzV7gGgLU1Z9eyPaGERxo1YMTNCwxRWf9zO0BYYWONqur1L4 SB1KtnInztl2o+z9eYo5Boh3m/gG1xlBf2VCnLSZFSqBV3br+Tm+ix7jHFQy4FQ5kXRp fS7n8LtiqSnZElvQ65Iszp8H09qXUYP5sDwlp6DGLKYvZEz9mbSdfQL56Ex6XnkISm9u Nr2bnkYS5+NMoV7m5jNemYSAH026aCtwqOo6gZ+OHPNNFy69X8jKzUxmiNrqqj2LcawL 5XgXl5Hex9xoxpRCN1WqnOCqqpT4qm2s78mme3HHf7bwwOpq4ITVj6B+w0WlZP0/o115 6HPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VzS47Rt6; 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 c81si33846888pfc.196.2018.11.22.01.23.29; Thu, 22 Nov 2018 01:23:44 -0800 (PST) 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=VzS47Rt6; 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 S2390297AbeKVJZi (ORCPT + 99 others); Thu, 22 Nov 2018 04:25:38 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:33887 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390288AbeKVJZi (ORCPT ); Thu, 22 Nov 2018 04:25:38 -0500 Received: by mail-oi1-f193.google.com with SMTP id h25so5950629oig.1 for ; Wed, 21 Nov 2018 14:49:12 -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=P3FMEDsZInXhnswagiHhBthQ6heysrNaLGS/9ZfO7uw=; b=VzS47Rt66GFvNWfCDJ1DW/b0qFkwE7ib46Do+PS92hb5mTKPxFPj0KwoGl2+V/1nuP GojHCWtpSuW0JtcEnCk15qGvA/XiDmlNL6xQ9OD82Lc69vdfWTXsmvpUqWWU1fwGcQn0 7iG6mmLB8nSSC8bpaxQMHMaYuROj9hML44D1ixk5fDbjXUNInYbnkm6fvKHqpkoUdnor PqywlqMs3oyKhdJSVL1CyfbBBwTqOLTpU3FZFOimqQxD6kvALu04ekmXu9pHpwHdQw3K gSMfDQqX+WhdmqjpvtsmFK/MWFvkvvj2N6U8uL9WHTDDEXSYEPcb1h2ucumFBHIBHXuc SHNg== 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=P3FMEDsZInXhnswagiHhBthQ6heysrNaLGS/9ZfO7uw=; b=auPLNRK9k7OLkiFJGrjyj5jRZy/3AgPQQPW9gx1g+71ym2WaWMxyXMOcL9fA6FwZHy w51XV7TWKPS6iwF/heJHRV4m+GEE9ki24f/qOfA5PFr30KDPnoELUDPeWSC+Vmu6p+4l hYVkAhvPQcpAv51ktBKhvLHTYMioNowXuq68PN+GQs/RuIUiPF5PNQVwgke2XPE3lbMj AQA0HDj0v1q26AVZVO+NAzEJKfnQ12yG8dGAX+t25ZKrWnelU++jLLspEns54WuYaDv3 7kIBS9Dy46RlnNGMj2Ic4UaxV+seCdhVQyr1lUVPY4XnhbJlxI588xlMPTnfXECA85qV ccNg== X-Gm-Message-State: AGRZ1gJhcqzdPZPfS+KGN0vGVd0F8j6Pkzce8jJmYcfdYh9Gh+v8CixB brJAdqAtZf4K4ahzEIWJjhgxgFf8zLwY+cszGE9CPrW+BdQ= X-Received: by 2002:aca:c413:: with SMTP id u19mr4484546oif.209.1542840551558; Wed, 21 Nov 2018 14:49:11 -0800 (PST) MIME-Version: 1.0 References: <20181121201452.77173-1-dancol@google.com> <20181121205428.165205-1-dancol@google.com> <20181121141220.0e533c1dcb4792480efbf3ff@linux-foundation.org> In-Reply-To: From: Jann Horn Date: Wed, 21 Nov 2018 23:48:45 +0100 Message-ID: Subject: Re: [PATCH v2] Add /proc/pid_gen To: Daniel Colascione Cc: Andrew Morton , kernel list , Linux API , Tim Murray , primiano@google.com, Joel Fernandes , Jonathan Corbet , Mike Rapoport , Vlastimil Babka , guro@fb.com, pdhamdhe@redhat.com, dennisszhou@gmail.com, "Eric W. Biederman" , Steven Rostedt , Thomas Gleixner , Ingo Molnar , linux@dominikbrodowski.net, Josh Poimboeuf , Ard Biesheuvel , Michal Hocko , Stephen Rothwell , ktsanaktsidis@zendesk.com, David Howells , linux-doc@vger.kernel.org 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 Wed, Nov 21, 2018 at 11:40 PM Daniel Colascione wrote: > On Wed, Nov 21, 2018 at 2:12 PM Andrew Morton wrote: > > On Wed, 21 Nov 2018 12:54:20 -0800 Daniel Colascione wrote: > > > +u64 read_pid_generation(struct pid_namespace *ns) > > > +{ > > > + u64 generation; > > > + > > > + > > > + spin_lock_irq(&pidmap_lock); > > > + generation = ns->generation; > > > + spin_unlock_irq(&pidmap_lock); > > > + return generation; > > > +} > > > > What is the spinlocking in here for? afaict the only purpose it serves > > is to make the 64-bit read atomic, so it isn't needed on 32-bit? > > ITYM the spinlock is necessary *only* on 32-bit, since 64-bit > architectures have atomic 64-bit reads, and 64-bit reads on 32-bit > architectures can tear. This function isn't a particularly hot path, > so I thought consistency across architectures would be more valuable > than avoiding the lock on some systems. Linux has atomic64_t/atomic64_read()/atomic64_inc() for this, which should automatically do the right thing - processor-supported atomic ops when possible, spinlock otherwise.