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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1ED8BC55ABD for ; Tue, 10 Nov 2020 21:03:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 686EE207D3 for ; Tue, 10 Nov 2020 21:03:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="kqiYQYL/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731772AbgKJVDV (ORCPT ); Tue, 10 Nov 2020 16:03:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727836AbgKJVDV (ORCPT ); Tue, 10 Nov 2020 16:03:21 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F188C0613D1; Tue, 10 Nov 2020 13:03:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jXrVumA1i2kZezBmOTg1+6kfgcCy4jVb7CD/Abz9u0k=; b=kqiYQYL/NsgXXqkSd+EGls3rwZ v1Za/W32bJuLl8briOhT1rGbbS8A/dCgir4neGS2PWrd8O5PMgQXhYbeFQkvyZNWjrUV4ayMPQoEn BTbd2YFwnw3nIgg9NM2k+44zIfRdmms3ixHO6UyIwHlTbwZ0PgRusNtP1gSHn73ikpZeHgKLIQqD5 w7KG/AIqajPFv3r9uaTVmgB9bCFgj+Mi5Uoe+ILglcuQkkSafyzex34gt2OYw+keNd+Et12DoONza O0V3N6JRVP4/ixegnsQRH0YEOmz+tGSOLTN9B36UmwrDltgPc+fBcPg9q78/kTJQLW9GS/UEc3GTV ZRDrV/Tw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcanM-0003Jb-UG; Tue, 10 Nov 2020 21:03:17 +0000 Date: Tue, 10 Nov 2020 21:03:16 +0000 From: Matthew Wilcox To: Shuah Khan Cc: corbet@lwn.net, keescook@chromium.org, gregkh@linuxfoundation.org, peterz@infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/13] seqnum_ops: Introduce Sequence Number Ops Message-ID: <20201110210316.GO17076@casper.infradead.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 10, 2020 at 12:53:27PM -0700, Shuah Khan wrote: > Sequence Numbers wrap around to INT_MIN when it overflows and should not Why would sequence numbers be signed? I know they're built on top of atomic_t, which is signed, but conceptually a sequence number is unsigned. > +++ b/Documentation/core-api/seqnum_ops.rst > @@ -0,0 +1,117 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +.. include:: > + > +.. _seqnum_ops: > + > +========================== > +Sequence Number Operations > +========================== > + > +:Author: Shuah Khan > +:Copyright: |copy| 2020, The Linux Foundation > +:Copyright: |copy| 2020, Shuah Khan > + > +There are a number of atomic_t usages in the kernel where atomic_t api > +is used strictly for counting sequence numbers and other statistical > +counters and not for managing object lifetime. You start by describing why this was introduced. I think rather, you should start by describing what this is. You can compare and contrast it with atomic_t later. Also, I don't think it's necessary to describe its implementation in this document. This document should explain to someone why they want to use this. > +Read interface > +-------------- > + > +Reads and returns the current value. :: > + > + seqnum32_read() --> atomic_read() > + seqnum64_read() --> atomic64_read() > + > +Increment interface > +------------------- > + > +Increments sequence number and doesn't return the new value. :: > + > + seqnum32_inc() --> atomic_inc() > + seqnum64_inc() --> atomic64_inc() That seems odd to me. For many things, I want to know what the sequence number was incremented to. Obviously seqnum_inc(); followed by seqnum_read(); is racy. Do we really want to be explicit about seqnum32 being 32-bit? I'd be inclined to have seqnum/seqnum64 instead of seqnum32/seqnum64. > +static inline int seqnum32_read(const struct seqnum32 *seq) > +{ > + return atomic_read(&seq->seqnum); > +} > + > +/* > + * seqnum32_set() - set seqnum value > + * @seq: struct seqnum32 pointer > + * @val: new value to set > + * > + */ > +static inline void > +seqnum32_set(struct seqnum32 *seq, int val) You have some odd formatting like the above line split. > +static inline void seqnum64_dec( > + struct seqnum64 *seq) That one is particularly weird.