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 3AC97C433FE for ; Thu, 10 Nov 2022 09:40:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 686DA6B0071; Thu, 10 Nov 2022 04:40:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 635D26B0072; Thu, 10 Nov 2022 04:40:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5248B6B0074; Thu, 10 Nov 2022 04:40:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4462F6B0071 for ; Thu, 10 Nov 2022 04:40:55 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0F21E40B62 for ; Thu, 10 Nov 2022 09:40:55 +0000 (UTC) X-FDA: 80117038470.12.8EC2B30 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf14.hostedemail.com (Postfix) with ESMTP id 4BAA3100002 for ; Thu, 10 Nov 2022 09:40:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BB3141FE99; Thu, 10 Nov 2022 09:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1668073252; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QqANZU+pw5gBuNdePRxF8GAA+MvsR3exid0Kwc/0Xo0=; b=Oz3a1AeNtTRxZNZpnqPjGwghw2xra9e0bS75O1suM2Voh4lJCNJPFLk3OCjOd/1r/jbaxV XVKcyCtPQQpPmRZXzPq/t7/gQ90qr3rjKBNetH10HADWZBD4VN258ekbcmpMDIi+Mi1h2A Kxm/vbFYnz9YkSiQZRk2Vo0vybN3A1k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1668073252; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QqANZU+pw5gBuNdePRxF8GAA+MvsR3exid0Kwc/0Xo0=; b=aBuPR8nCMneM2ITwXNxurc082i7quPt/l0JvnOMktmWv3sp8xoeh2X+wSc+0v3J/RC69cw G7mHUGno8hEOziDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8FC061346E; Thu, 10 Nov 2022 09:40:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sJeGIiTHbGN4bAAAMHmgww (envelope-from ); Thu, 10 Nov 2022 09:40:52 +0000 Message-ID: Date: Thu, 10 Nov 2022 10:40:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error Content-Language: en-US To: Rong Tao , akpm@linux-foundation.org Cc: Rong Tao , =?UTF-8?Q?St=c3=a9phane_Graber?= , Yuanzheng Song , linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , "linux-mm@kvack.org" , Joonsoo Kim , Pekka Enberg , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin References: From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668073254; a=rsa-sha256; cv=none; b=zHQ16qakcKtnKB3U7e03yeyfW2FhrwHutD7dPSGlr4GsdGq6tlMG5UvFhsfN5Y67WcHNfp 44f9RxK5+ZAqFXX+Lj48jOaYUOpKCAZGM76Q2+hfnwKIb73Vf68kTDpDPUBR4r3gw3cTfW KVxxaZM9W1EBBl/mmBD/1J5YeOknoXU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Oz3a1AeN; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aBuPR8nC; dmarc=none; spf=pass (imf14.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668073254; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QqANZU+pw5gBuNdePRxF8GAA+MvsR3exid0Kwc/0Xo0=; b=pOLeGo6/s6Aa0R9ppF+kwRHm2YNXW1DGjuu5Pd4/C1YAKGrlUxlLARdEvvpHHPpLKhsbpK 0xr39V7Je8VkVqwNWhl2U7wYX5s1062oJmdPRH8eMUQydAOr8Fe8sGue8l9nXOe2Dm0pMi BlNZXZelBxxQXUtB9Ov8ySgqAKWKnOs= Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Oz3a1AeN; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aBuPR8nC; dmarc=none; spf=pass (imf14.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-Stat-Signature: fzbfm69ppwzsrtd18p7infmxhwnr7i8o X-Rspamd-Queue-Id: 4BAA3100002 X-Rspamd-Server: rspam05 X-HE-Tag: 1668073254-443575 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 11/8/22 13:47, Rong Tao wrote: > From: Rong Tao > > If you don't run slabinfo with a superuser, return 0 when read_slab_dir() > reads get_obj_and_str("slabs", &t), because fopen() fails (sometimes > EACCES), causing slabcache() to return directly, without any error during > this time, we should tell the user about the EACCES problem instead of > running successfully($?=0) without any error printing. > > For example: > $ ./slabinfo > Permission denied, Try using superuser <== What this submission did > $ sudo ./slabinfo > Name Objects Objsize Space Slabs/Part/Cpu O/S O %Fr %Ef Flg > Acpi-Namespace 5950 48 286.7K 65/0/5 85 0 0 99 > Acpi-Operand 13664 72 999.4K 231/0/13 56 0 0 98 > ... > > Signed-off-by: Rong Tao Thanks, added to slab.git slab/for-6.2/tools > --- > tools/vm/slabinfo.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c > index 0fffaeedee76..cfaeaea71042 100644 > --- a/tools/vm/slabinfo.c > +++ b/tools/vm/slabinfo.c > @@ -157,9 +157,11 @@ static unsigned long read_obj(const char *name) > { > FILE *f = fopen(name, "r"); > > - if (!f) > + if (!f) { > buffer[0] = 0; > - else { > + if (errno == EACCES) > + fatal("%s, Try using superuser\n", strerror(errno)); > + } else { > if (!fgets(buffer, sizeof(buffer), f)) > buffer[0] = 0; > fclose(f);