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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00C8AC433EF for ; Tue, 12 Oct 2021 16:13:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 959B16101D for ; Tue, 12 Oct 2021 16:13:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 959B16101D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E7345900003; Tue, 12 Oct 2021 12:13:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E21DC900002; Tue, 12 Oct 2021 12:13:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1032900003; Tue, 12 Oct 2021 12:13:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id C2538900002 for ; Tue, 12 Oct 2021 12:13:02 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 80B3032605 for ; Tue, 12 Oct 2021 16:13:02 +0000 (UTC) X-FDA: 78688279404.20.833B598 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id CE4DBD0362A6 for ; Tue, 12 Oct 2021 16:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=K6whvL8I1DlofICaXpFqgDgteddqID/uIRsVmCRo/a4=; b=CmBGsUsZ8zZhMlbotHWPJAPIiO mOkdtVnMopbj3lSmubkFUTQ/uZmJXMTbEeIxQvvmSw2As43N6v0hOokc3a5gEFTIv+OprKxFIbDeu XbmJjDjAng2zOW1JuwGi3iKv5evuIbDinNcctf3ER4RzIWxwBEw5DiFcasJivcIlEl/xI4vHLtLBO KKa9OldeZgjuin9K+93wz3bt4syXwO4npHyF1/JFBz1eTj4dugecCeRY/5ihpELovmR2lTZB7F6de pVxK1qECe0AtyKnwtsT91JEe9ng9Tl4F4F8XabK8mQJSYhRnfUtFhqnLwKCBPSbwQrV0IG0w8Qr6S K75NLgDQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1maKN5-006deh-NX; Tue, 12 Oct 2021 16:11:47 +0000 Date: Tue, 12 Oct 2021 17:11:19 +0100 From: Matthew Wilcox To: Rasmus Villemoes Cc: linux-mm@kvack.org, Vlastimil Babka Subject: Re: [PATCH] vsprintf: Make %pGp print the hex value Message-ID: References: <20211008193829.849532-1-willy@infradead.org> <1093c8db-5d96-18ff-cb27-e74cddb757a4@rasmusvillemoes.dk> <2b8bd086-f0cc-80ff-b36a-83b49c523482@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2b8bd086-f0cc-80ff-b36a-83b49c523482@rasmusvillemoes.dk> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CE4DBD0362A6 X-Stat-Signature: fxmkxweuypzdkgiuyr1fq5cokt5q4kr1 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=CmBGsUsZ; dmarc=none; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1634055181-261414 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 Tue, Oct 12, 2021 at 01:57:09PM +0200, Rasmus Villemoes wrote: > On 12/10/2021 13.32, Matthew Wilcox wrote: > > On Tue, Oct 12, 2021 at 11:55:50AM +0200, Rasmus Villemoes wrote: > >> ...default_flag_spec has '.flags = SPECIAL | SMALL,', i.e. what one > >> would get from %#x . I'm guessing that's what upsets 0-day. > >> > >> Geez it would be nice if 0day actually reported the "Expected foo, but > >> bar was emitted to the buffer". > > > > It's there; you just have to dive into the dmesg.xz to get it: > > > > [ 48.607787][ T1214] test_printf: vsnprintf(buf, 256, "%pGp", ...) returned 33, expected 29 > > [ 48.616106][ T1214] test_printf: vsnprintf(buf, 18, "%pGp", ...) returned 33, expected 29 > > [ 48.624292][ T1214] test_printf: vsnprintf(buf, 0, "%pGp", ...) returned 33, expected 29 > > [ 48.632403][ T1214] test_printf: kvasprintf(..., "%pGp", ...) returned '0x0(node=0|zone=0|lastcpupid=0x0)', expected 'node=0|zone=0|lastcpupid=0x0)' > > [ 48.645741][ T1214] test_printf: vsnprintf(buf, 256, "%pGp", ...) returned 33, expected 29 > > [ 48.654023][ T1214] test_printf: vsnprintf(buf, 23, "%pGp", ...) returned 33, expected 29 > > [ 48.662218][ T1214] test_printf: vsnprintf(buf, 0, "%pGp", ...) returned 33, expected 29 > > [ 48.670327][ T1214] test_printf: kvasprintf(..., "%pGp", ...) returned '0x0(node=0|zone=0|lastcpupid=0x0)', expected 'node=0|zone=0|lastcpupid=0x0)' > > [ 48.683670][ T1214] test_printf: vsnprintf(buf, 256, "%pGp", ...) returned 88, expected 71 > > [ 48.691937][ T1214] test_printf: vsnprintf(buf, 64, "%pGp", ...) returned 88, expected 71 > > [ 48.700128][ T1214] test_printf: vsnprintf(buf, 0, "%pGp", ...) returned 88, expected 71 > > [ 48.708249][ T1214] test_printf: kvasprintf(..., "%pGp", ...) returned '0x4fffffc008003c(uptodate|dirty|lru|active|swapbacked|node=1|zone=1|lastcpupid=0x1fffff)', expected 'uptodate|dirty|lru|active|swapbacked|node=1|zone=1|lastcpupid=0x1fffff)' > > [ 48.730275][ T1214] test_printf: failed 12 out of 420 tests > > > > So you're right, it's missing the 0x, > > Ah, it's actually missing the whole '0xfoo(' because you're not updating > 'size' after the first > > + snprintf(cmp_buf + size, BUF_SIZE - size, "%x(", flags); > > so the next write to cmp_buf overwrites whatever you wrote here. > > > but I still don't know how to run this self-test. > > Neither do I, when I created test_printf.c I made sure it ran on boot if > built-in, and that's certainly how I've been testing vsprintf.c patches > in the past. Maybe the kstm crowd can explain how to get that to work as > expected. Got it. It was running; just wasn't being captured by the kernel messages output on my test system. If I ssh in to the test system and examine dmesg, it's there. Now, this isn't quite enough; - snprintf(cmp_buf + size, BUF_SIZE - size, "%x(", flags); + snprintf(cmp_buf + size, BUF_SIZE - size, "%#x(", flags); + size = strlen(cmp_buf); The problem is that the test suite doesn't pass in a full flags. It passes in some pageflags and then ORs in the zone, nid, etc after printing some of the flags. So I had to restructure the test a bit to print the full hex number. What do you think? +++ b/lib/test_printf.c @@ -610,11 +610,15 @@ page_flags_test(int section, int node, int zone, int last_cpupid, { unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag}; unsigned long page_flags = 0; + unsigned long test_flags = flags & PAGEFLAGS_MASK; unsigned long size = 0; bool append = false; int i; - snprintf(cmp_buf + size, BUF_SIZE - size, "%x(", flags); + for (i = 0; i < ARRAY_SIZE(values); i++) + test_flags |= (values[i] & pft[i].mask) << pft[i].shift; + snprintf(cmp_buf + size, BUF_SIZE - size, "%#lx(", test_flags); + size = strlen(cmp_buf); flags &= PAGEFLAGS_MASK; if (flags) { page_flags |= flags; It's a bit duplicative of what's below, and I'm far from sure about the testing of bits that fall outside PAGEFLAGS_MASK. It doesn't feel like a great test in that it's not testing how pGp would get used. Maybe that points to a small defect in pGp -- shouldn't it print something for unknown bits being set?