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=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 3F69FCA9ECB for ; Wed, 30 Oct 2019 22:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 13CA720862 for ; Wed, 30 Oct 2019 22:38:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.b="g33Q4U/Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727402AbfJ3Win (ORCPT ); Wed, 30 Oct 2019 18:38:43 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36586 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbfJ3Win (ORCPT ); Wed, 30 Oct 2019 18:38:43 -0400 Received: by mail-wr1-f66.google.com with SMTP id w18so4159349wrt.3 for ; Wed, 30 Oct 2019 15:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qfICZRpjv9MzZUR3Km31YoPnMoXWt4BCtsBGyOPs+MA=; b=g33Q4U/Y/PsWl2LTH18JY6gpMyFVmPxV9qqWkrT57lR2a/GCy9kyBDrbLXWbaa2fps tOVndw1p6l/7VQHVRvGpLmhpFDr4RJXRgrTPx4hhh43FE6ruFdAPV73fa0XTmGA/7rmy ly6YasutyEzFhYEmiEDQkruKueLdPUY1jDjaw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qfICZRpjv9MzZUR3Km31YoPnMoXWt4BCtsBGyOPs+MA=; b=ZRQnSg7HVtd9HvyhMbneG7Z7FkTSSYK8z1NKyw1X+K/YksrnZ+jqNJHL/3HVxH94Zr ZHabXVns1tyl29puessFAnizq2QPTaOI9G1FH5DLcunQDtZOMckVfevG5aj7Mz4PVS/I LtMqqfeJK6N1qJv6spKhHBzEVs3ly/QXWHt9j8FBPn3ugs2FsRZIkYgfUwMCx6kL5V5v iDQtKKIveuJLsraZFT8bKkZPG6t0RjpPPZureWcgP/twDRJ5w3xFbpztuec0TlpbmG48 WF9AGVxTyeX8WKGdq5FooxLya5iqdahlEvIa0io9YVZecZVfwgJCpNBLkOinGTtY3WS5 kaig== X-Gm-Message-State: APjAAAU+udQopxpNbAU06csKTN8uIomkmZKIiQ/QRelk2h4rbnFO6bWH nD7w0R/BnrsA0pEmE0Cvn4wQLA== X-Google-Smtp-Source: APXvYqwy8Lp9RkPFYIcCKVwNc4bwfuBSBiCYr98GupWsvuOSYztGZY5yvtxoKwr5rWH+K4PLLBTR+g== X-Received: by 2002:adf:d1a3:: with SMTP id w3mr2258782wrc.9.1572475121267; Wed, 30 Oct 2019 15:38:41 -0700 (PDT) Received: from [192.168.1.149] (ip-5-186-115-54.cgn.fibianet.dk. [5.186.115.54]) by smtp.gmail.com with ESMTPSA id t24sm1858665wra.55.2019.10.30.15.38.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Oct 2019 15:38:40 -0700 (PDT) Subject: Re: [RFC PATCH 04/10] pipe: Use head and tail pointers for the ring, not cursor and length [ver #2] To: Ilya Dryomov Cc: David Howells , Linus Torvalds , Greg Kroah-Hartman , Peter Zijlstra , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-block , linux-security-module@vger.kernel.org, linux-fsdevel , linux-api@vger.kernel.org, LKML References: <157186182463.3995.13922458878706311997.stgit@warthog.procyon.org.uk> <157186186167.3995.7568100174393739543.stgit@warthog.procyon.org.uk> <4892d186-8eb0-a282-e7e6-e79958431a54@rasmusvillemoes.dk> From: Rasmus Villemoes Message-ID: Date: Wed, 30 Oct 2019 23:38:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On 30/10/2019 23.16, Ilya Dryomov wrote: > On Wed, Oct 30, 2019 at 9:35 PM Rasmus Villemoes > wrote: >> >> On 30/10/2019 17.19, Ilya Dryomov wrote: >>> On Thu, Oct 24, 2019 at 11:49 AM David Howells wrote: >>>> /* >>>> - * We use a start+len construction, which provides full use of the >>>> - * allocated memory. >>>> - * -- Florian Coosmann (FGC) >>>> - * >>>> + * We use head and tail indices that aren't masked off, except at the point of >>>> + * dereference, but rather they're allowed to wrap naturally. This means there >>>> + * isn't a dead spot in the buffer, provided the ring size < INT_MAX. >>>> + * -- David Howells 2019-09-23. >>> >>> Hi David, >>> >>> Is "ring size < INT_MAX" constraint correct? >> >> No. As long as one always uses a[idx % size] to access the array, the >> only requirement is that size is representable in an unsigned int. Then >> because one also wants to do the % using simple bitmasking, that further >> restricts one to sizes that are a power of 2, so the end result is that >> the max size is 2^31 (aka INT_MAX+1). > > I think the fact that indices are free running and wrap at a power of > two already restricts you to sizes the are a power of two, Ah, yes, of course. When reducing indices mod n that may already have been implicitly reduced mod N, N must be a multiple of n for the result to be well-defined. Rasmus