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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03AD0C433EF for ; Tue, 8 Feb 2022 10:51:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F8B56B0075; Tue, 8 Feb 2022 05:51:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A8A36B0078; Tue, 8 Feb 2022 05:51:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 798096B007B; Tue, 8 Feb 2022 05:51:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 6B4FD6B0075 for ; Tue, 8 Feb 2022 05:51:45 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1D3D8181EBF15 for ; Tue, 8 Feb 2022 10:51:45 +0000 (UTC) X-FDA: 79119296970.28.C88F0AB Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf15.hostedemail.com (Postfix) with ESMTP id 9691DA0008 for ; Tue, 8 Feb 2022 10:51:44 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4E47A1F387; Tue, 8 Feb 2022 10:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1644317503; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Xfvi4t6v0E3o8m/BrX7OSyshdoPR/okbuDAi6c9K9Rc=; b=By/NatfU9q5/32V4vpdjlTTwvMuHnRPEfjJni8g4r2EgT6xLl48+zn+/fJ0VU9xgEr9zWa HW1oGFPuTLIoHd7m+IShMeqYSY+XUU/aeUGXBT7k6ly/qyW/AEaS0oJmdcMw4fMrG/xB0W iJ9ZbifzVS3EPlo+CS0nhO3K00YBGWc= Received: from suse.cz (unknown [10.100.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id DA181A3B91; Tue, 8 Feb 2022 10:51:42 +0000 (UTC) Date: Tue, 8 Feb 2022 11:51:42 +0100 From: Petr Mladek To: Waiman Long Cc: Vlastimil Babka , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Mike Rapoport , David Rientjes , Roman Gushchin , Rafael Aquini Subject: Re: [PATCH v4 2/4] mm/page_owner: Use scnprintf() to avoid excessive buffer overrun check Message-ID: References: <20220131192308.608837-5-longman@redhat.com> <20220202203036.744010-3-longman@redhat.com> <5c03fa31-35a5-4cbc-6b0e-872d5db82a41@suse.cz> <42cca916-d4c8-daa1-4a91-60738c499c89@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42cca916-d4c8-daa1-4a91-60738c499c89@redhat.com> X-Rspamd-Queue-Id: 9691DA0008 X-Stat-Signature: o1oikgeywpxk1ybfia5kz54ughiqd1u1 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b="By/NatfU"; spf=pass (imf15.hostedemail.com: domain of pmladek@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=pmladek@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspamd-Server: rspam05 X-HE-Tag: 1644317504-302824 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 2022-02-03 13:49:02, Waiman Long wrote: > On 2/3/22 10:46, Vlastimil Babka wrote: > > On 2/2/22 21:30, Waiman Long wrote: > > > The snprintf() function can return a length greater than the given > > > input size. That will require a check for buffer overrun after each > > > invocation of snprintf(). scnprintf(), on the other hand, will never > > > return a greater length. By using scnprintf() in selected places, we > > > can avoid some buffer overrun checks except after stack_depot_snprint() > > > and after the last snprintf(). > > > > > > Signed-off-by: Waiman Long > > > Acked-by: David Rientjes > > > Reviewed-by: Sergey Senozhatsky > > Looks like this will work, but note that if the purpose of patch 1/4 was > > that after the first scnprintf() that overflows the following calls will be > > short-cut thanks to passing the size as 0, AFAICS that won't work. Because > > scnprintf() returns the number without trailing zero, 'ret' will be 'count - > > 1' after the overflow, so 'count - ret' will be 1, never 0. > > Yes, I am aware of that. Patch 1 is just a micro-optimization for the very > rare case. In theory, we might micro-optimize also the case when "size == 1". Well, I am not sure if it is worth it. After all, the primary use-case is to print the message into a big-enough buffer. Lost information is a bigger problem than the speed ;-) Best Regards, Petr