Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp590737imu; Thu, 22 Nov 2018 02:20:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/X8JkdFZ4RHVVUvHOGrRo3vdTF2JEPWX2GAFbXFXyUZEK+xzctO+7Zt+QeftSJSOR4dfVXE X-Received: by 2002:a17:902:9a04:: with SMTP id v4-v6mr10359356plp.247.1542882041658; Thu, 22 Nov 2018 02:20:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542882041; cv=none; d=google.com; s=arc-20160816; b=YD9dsTuhtk8CStulTG3roEoaLP05vcQ+qm2n+TxwUm3fZ1nJeHg/qwS7Err+6mV5Q3 912IfNMIct2Kjtd+gAEMo6miQqgtDMjTIBvNCsBI+Oylmv4VKzJKNKcZ0gnX4D6nXCDQ UrvitB8HwfDTKl/VRZcBPpsdW+iZfChbu6LG1OVaVzlLODpML+pCI3nvRfq6DKFe1xfc 2Hb8WcW0tjCg1D9rVCWtU/epSIue+ry2Dfvl8eUDeszn0fbXwYXpqggF825W3dA4cpXh SudL+QAi1yqNj04Ez/A70SwOtsrp7ScuphkPh+zzGK1/Sipe77aHOclJQ2aK1VGisbQc aokQ== 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=o23S7xtxzBQk8WzRwVhA8U0qrvy0Ap95NL75oi/N7gA=; b=WDEiU/s/LAoNJJ5YkaPphVoPkTM/V4dzHasukaOfsNDdRbwsmvrD+pqD3MplODz6ba 1iOvi+JuRLnhZIIriURoVQUs7C6Qr/VLUaog09vKsIQiBiU8HSq2B+7N8leaMRnylECJ JEGJp3SNu4QACRhmTePDc7agie7AIMqlGt4WZupct8yvKqxnCm7WwFvPECiZn0RcHJAf aKuDcytYiKFfTEa6qdPjJUweG3g84NSUNCkk8iBE/xPntPidRbBg0v954ugVMNBcOBg3 Z5gmnpjW3+05JZEcdiH40+ewsNUcikxUijfUAAfYxcFRTFmVfpxTsMDEb81YahHLR+4S y+/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=b+ndBDgr; 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 a5si47729685pgg.120.2018.11.22.02.20.26; Thu, 22 Nov 2018 02:20:41 -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=b+ndBDgr; 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 S2390328AbeKVJ3U (ORCPT + 99 others); Thu, 22 Nov 2018 04:29:20 -0500 Received: from mail-ua1-f66.google.com ([209.85.222.66]:40323 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387758AbeKVJ3U (ORCPT ); Thu, 22 Nov 2018 04:29:20 -0500 Received: by mail-ua1-f66.google.com with SMTP id n7so2504361uao.7 for ; Wed, 21 Nov 2018 14:52:53 -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=o23S7xtxzBQk8WzRwVhA8U0qrvy0Ap95NL75oi/N7gA=; b=b+ndBDgrx9paBwOIKFj0/SUQ8n24/m5kOtIWtJWSxT4X+VRvsGB0UJPvVggbva/G7b ScGvBU/IqHYd3cQOAXhctTmYRVsAlQ+kIj7iPRLN7Ga9Vx5b4XbGQ/hf23AsZrpYtOJY V6vWXkRgYIIzYVvZ73BndsY+9ajEIrKMteGoO0sBaBS4gjWIV96Rb5/bs55C5XiDhHjS yUSXPQB0aWVQ4a1Wm6zN5aOEQnPMTAN1cIEC17bCEg3j1EAh9GsV1ULHvqWxhTAe7MhT yejNwFno+TBqKpYmKKjFncNn62smbg4K6+mA9R4YLYOi0lcRPr1ravRAhET/hEPAAK4H nqTw== 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=o23S7xtxzBQk8WzRwVhA8U0qrvy0Ap95NL75oi/N7gA=; b=OTmRO4eVoBea8WI3ZYSWs6AVFnLAK9jDk5qx4/DF0qJIclxFrPIdcRX34ZZ4ch2/Gg p1mWZtxO3RlZHBZWY0TvMtzNjuu7OA1p2KnqziSOhlsedJflgh5574dw+QBGu8XUZ1vw +zCiHyU0bkYMZrgs+3Z1jyyNh+1LiUi2USb2JmFljqRTGIibJolAonyXUrtGtHcz0PKp xmqSzX1eUzTU8WQWO6pYab3nWoGGX+xdoFrotf4a+zcxmqrEw7yRJbWuh6NdHp3BGb5u Cr1g/dsiMxZp/6rUTyua9Mis1RTIwAI7Wc8PlmnyNQMM2psgxLvdt+3V6erpxMfta7Gl CAOw== X-Gm-Message-State: AA+aEWY/AIthqmk9ZTToDH3YqJVTW2USDgBwDMWxlCdTF0aPb/4Vn3ae EZVIkhPhfklPkpTZk4t7b244JC+J19bDUYNM1GbEcg== X-Received: by 2002:ab0:225a:: with SMTP id z26mr230497uan.100.1542840772383; Wed, 21 Nov 2018 14:52:52 -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: Daniel Colascione Date: Wed, 21 Nov 2018 14:52:40 -0800 Message-ID: Subject: Re: [PATCH v2] Add /proc/pid_gen To: Jann Horn Cc: Andrew Morton , linux-kernel , Linux API , Tim Murray , Primiano Tucci , Joel Fernandes , Jonathan Corbet , Mike Rapoport , Vlastimil Babka , Roman Gushchin , Prashant Dhamdhere , "Dennis Zhou (Facebook)" , "Eric W. Biederman" , rostedt@goodmis.org, tglx@linutronix.de, mingo@kernel.org, linux@dominikbrodowski.net, jpoimboe@redhat.com, Ard Biesheuvel , Michal Hocko , sfr@canb.auug.org.au, ktsanaktsidis@zendesk.com, David Howells , "open list:DOCUMENTATION" 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 2:49 PM Jann Horn wrote: > > 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. I wanted to take advantage of the existing spinlock to synchronize instead of adding more atomic operations to the rollover path.