Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1149106lqm; Thu, 2 May 2024 06:45:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHnVoRm4A1i6baZjxgJoVw1AwqBQ5O85C7xlZ2UtaLCTnJ0JR6mtBa3cXFB5kYgwVW1TWQsOpBv6hJvvTsHOT114Y3qo8LLeUXOi6PBQ== X-Google-Smtp-Source: AGHT+IHZXXkAcLEgoNft0YEEoh4pzT5JRGK/HvIJGENRmDKcbiU6vuf1fn0j5UiVRxT0RA5TkYI5 X-Received: by 2002:a05:6214:240b:b0:6a0:b905:97ba with SMTP id fv11-20020a056214240b00b006a0b90597bamr6184759qvb.44.1714657533730; Thu, 02 May 2024 06:45:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714657533; cv=pass; d=google.com; s=arc-20160816; b=AbjNXIyf25b7XuOWTfpFiNJ+uFAzj9cx3Ho+6sPz9ynXXeQOBViO8XShKBmheApOg8 zIjIxWJvOmB86wcLGAu+G/6+BQF/nZfCfOXeSx5r4nRdQfmnos0Glh2myIDuQtcwwtF/ GdC6XWWBhVKH42jAHBiPe0DLBaoRH3SrG1tK9EfO16E0lXQJyI/Uno6WoPG7AKevmoG6 k2zq86jZhrw/6xM0Ns8aSPlTVIJmpU/ddPwzaLcrXoJebSrTbIR/uimfPmdTG7D48vTy PCpBZ8B5aapvIT1lSP89TXpVqutkf6mK3o0XMU1HSrK7MXorU1GQ0fJYCmVRWtQD5iAY x9mQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=e0GHO9vMhHLeDphNtn8yGjWWwrGHlouNxeIuchibEvw=; fh=ibdFeplQ8Q2GvtN3isCJ0d/5S8LTZa2dXZuQJo7RNQ0=; b=CPJwXTdbaxLrnxckRqdEQfjR+M5jPfHjBgiVw/vEaZgTD29b9zX7s8/1HTjng2G/uI NNK6o9Qk88Rg0IBq+sLROPftgqjTYZIbpnLySwJuNEUz8AIpKyAzW6uYnhEV1BAIQeqv vhZVw5r9iEo2iitrL+prnQlyW9YHP6jiHKkwQ80jYzs6SzHwIARJDNzjuoR0Cx7QZTLd RqU8t+lLFzZ5QSqi9BJfSX8Lx4WXxMCFAdbMgjCjfrszzmxVzebMkSB8u4J+cIPh6+/+ 7BnxakyThkSERfjWUzIjh6JHa6qfC8nIdFlenhao7bZtMSY6gyE6ClxPB/+nJ5+MDH0T OBag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-166522-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166522-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q12-20020ad45cac000000b006a065ac280csi937904qvh.613.2024.05.02.06.45.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 06:45:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166522-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-166522-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166522-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 61B5F1C2151A for ; Thu, 2 May 2024 13:45:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A97413C67E; Thu, 2 May 2024 13:45:28 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90A5E12DDBF; Thu, 2 May 2024 13:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714657527; cv=none; b=sqYzeVSoyeS685C8aRJ/yravFiKGq/hewj2Fw9g1lGzOV0Arc3kr9CFrbs8ZVXK/KUBbqqv/vBo6MHraz1/XWX5/ExYCbpk9vtBWQGJkDRNdhCMTEtApbv7mwFqOVZz21K7H3ZkpFfRpmLFVoipAN9lWIOdJPjW1j6Vd3sbPimw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714657527; c=relaxed/simple; bh=0crVSpQ2cRq8IdCQmQ+23c21kGzUGsODa4EJXn+Y3sM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q0KsdJbjg9i8lCfK58Y6IdBc4HZ1OV8bVIq0m9eF+db1+stfqAxDUJzJqaiqXWkE2zPlGKvMArhlGN5iyeshUsNQPrABlX/0qwiYeRa+4JUW42JV+4d5Fw5/bCxX880kL46KOWNk4mNtuG83pBt/0l7FVeh9vMka5BV1dJLEDsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F32CC113CC; Thu, 2 May 2024 13:45:26 +0000 (UTC) Date: Thu, 2 May 2024 09:46:12 -0400 From: Steven Rostedt To: Vincent Donnefort Cc: David Hildenbrand , mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, kernel-team@android.com, rdunlap@infradead.org, rppt@kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v22 2/5] ring-buffer: Introducing ring-buffer mapping functions Message-ID: <20240502094612.7f92a3e4@gandalf.local.home> In-Reply-To: References: <20240430111354.637356-1-vdonnefort@google.com> <20240430111354.637356-3-vdonnefort@google.com> <78e20e98-bdfc-4d7b-a59c-988b81fcc58b@redhat.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 2 May 2024 14:38:32 +0100 Vincent Donnefort wrote: > > > + while (s < nr_subbufs && p < nr_pages) { > > > + struct page *page = virt_to_page(cpu_buffer->subbuf_ids[s]); > > > + int off = 0; > > > + > > > + for (; off < (1 << (subbuf_order)); off++, page++) { > > > + if (p >= nr_pages) > > > + break; > > > + > > > + pages[p++] = page; > > > + } > > > + s++; > > > + } > > > + > > > + err = vm_insert_pages(vma, vma->vm_start, pages, &nr_pages); > > > > Nit: I did not immediately understand if we could end here with p < nr_pages > > (IOW, pages[] not completely filled). > > > > One source of confusion is the "s < nr_subbufs" check in the while loop: why > > is "p < nr_pages" insufficient? > > Hum, indeed, the "s < nr_subbufs" check is superfluous, nr_pages, is already > capped by the number of subbufs, there's no way we can overflow subbuf_ids[]. We can keep it as is, or perhaps change it to: while (p < nr_pages) { struct page *page; int off = 0; if (WARN_ON_ONCE(s >= nr_subbufs)) break; page = virt_to_page(cpu_buffer->subbuf_ids[s]); for (; off < (1 << (subbuf_order)); off++, page++) { if (p >= nr_pages) break; pages[p++] = page; } s++; } I don't like having an unchecked dependency between s and p. -- Steve