Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1400686iog; Tue, 14 Jun 2022 05:30:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7wFaGwpFrodmbNyjJI4DGXu7VaHxndyiGAXlUqA8hChZ+MYMVKRy6tQIng2G5/ZUXou/T X-Received: by 2002:aa7:c990:0:b0:42d:e15f:e65a with SMTP id c16-20020aa7c990000000b0042de15fe65amr5774444edt.221.1655209848533; Tue, 14 Jun 2022 05:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209848; cv=none; d=google.com; s=arc-20160816; b=ev3C0wnEFWcIQErMRhxZge9pQysyfM/r4h9lCcjVBG7oF2ocsZZ0XqFPAWs6u1zTaE rhZFIvZjQrPjNo6DfU6MGdsv2QpKE1O33Q7Xpl2iGLBzdoMNgvy85O85WHInMbjRkZuA PZ+okjtMjzHKVHNOBksMA0DneyOkcTk7xD0SnbVlFBq6sQKUgEW1F/iGhgKdys5mAdKD UGLdYPjeigrW6e1jpWIkTWl9BZS2GFZGEv4K+W4Uc/vZ5f5H9VTqfQFlRSZOkm8ULPgs qX7BZpPn9b3vMb/tNImWozl+hSrZ90dPfCu3MW9QZjZbAH9o6jpacWaar+yMV6MLWhwQ rwnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=gdQNv3H02tLJyNTWKuZB1Pun4d0Yppvy9PsduYHadVU=; b=LCWt3ieqqDw+1JKOlnyHhEhJLjQ8tZMonLh/zvkXqci6mrYPiP/n74C6YbWBmtT8wX M42fKRCVEUUWT8GV74/PLCFl+/HGPULom+QRjzVuoElUxHtSaWvOw9s5X8fU0xTEFkti fS3Wigq/h2UPiJlMPxzxhiYgHC57+nldnNTWZm9kDZzsLiVaNDcmLhNVfgb8jZsnxUUw PwPrO3jQxIzokGP+4RjKXwwaqHl9gaJUiTVm8D/Og5t+BD7m/v9GVeymyrdIS5y8XSYh RFm4j3j/GnuU7eS/36nQAotH3gLVaAOrvGE461erC+gfF0IMwtZKlRGRvv7vLQM3LoSb +liA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=htPwzWNB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a056402358b00b0042888eee944si12581812edc.471.2022.06.14.05.30.18; Tue, 14 Jun 2022 05:30:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=htPwzWNB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356866AbiFNMM1 (ORCPT + 99 others); Tue, 14 Jun 2022 08:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356814AbiFNMMR (ORCPT ); Tue, 14 Jun 2022 08:12:17 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A7B24A3CD; Tue, 14 Jun 2022 05:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gdQNv3H02tLJyNTWKuZB1Pun4d0Yppvy9PsduYHadVU=; b=htPwzWNBUQ+6KH93emBqdgCHcP edy5Qq3D4SjFxNnxqapMHYEdX0urLwxC2lK+BXnvXyNZ8X23OjsD74VManmBvG1InroTibh4lpoGU cvQnb0eWImOz5GP0GRt8zhwrQBWZXTkfsG6SEH/jAbeq2ngYXZPM8Dgu3dM6TseTrgiBWQkb9+Tz+ sBJE5C+n6WbZaxvleQ4u6kbq+vwvZwOmxxeWu/HGjRqufgpVDM7/CbaGdiqdWkA5Pkxp4DkL4fO94 nsi3GX3uEAHaeD/U80bOI8UOwQpw5z+HtFSYtuwLyUja3Jk0xNftGRqfvcDADCpyOR4ORR+8mi1Zg 1XiE6cGw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o15Oh-000Gd2-Px; Tue, 14 Jun 2022 12:11:51 +0000 Date: Tue, 14 Jun 2022 13:11:51 +0100 From: Al Viro To: David Howells Cc: Linus Torvalds , Dan Williams , Linux Kernel Mailing List , linux-fsdevel , nvdimm@lists.linux.dev Subject: Re: [RFC][PATCH] fix short copy handling in copy_mc_pipe_to_iter() Message-ID: References: <1586153.1655188579@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1586153.1655188579@warthog.procyon.org.uk> Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 14, 2022 at 07:36:19AM +0100, David Howells wrote: > Al Viro wrote: > > > What's wrong with > > p_occupancy = pipe_occupancy(head, tail); > > if (p_occupancy >= pipe->max_usage) > > return 0; > > else > > return pipe->max_usage - p_occupancy; > > Because "pipe->max_usage - p_occupancy" can be negative. Sure can. And in that case you return 0; no problem wiht that. It's what happens when occupancy is below max_usage that is weird. > post_one_notification() is limited by pipe->ring_size, not pipe->max_usage. > > The idea is to allow some slack in a watch pipe for the watch_queue code to > use that userspace can't. Sure. And if this function is supposed to report how many times would userspace be able to grab a slot, it's returning the wrong value. Look: 32-slot ring. max_usage is 16. 14 slots are already occupied. Userland (sure as hell, anything in iov_iter.c) will be able to occupy two more before it runs into the pipe_full(). And your function returns min(32 - 14, 16), i.e. 16. What am I missing here?