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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCDA3CA9EB6 for ; Wed, 23 Oct 2019 18:00:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F8EC2086D for ; Wed, 23 Oct 2019 18:00:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MbQJamyX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F8EC2086D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3AB2B6B0003; Wed, 23 Oct 2019 14:00:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35BA56B0006; Wed, 23 Oct 2019 14:00:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 272D46B0008; Wed, 23 Oct 2019 14:00:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 05D066B0003 for ; Wed, 23 Oct 2019 14:00:21 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 8B72E83E4 for ; Wed, 23 Oct 2019 18:00:21 +0000 (UTC) X-FDA: 76075813842.11.mist49_5a5cc180c072f X-HE-Tag: mist49_5a5cc180c072f X-Filterd-Recvd-Size: 6626 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Oct 2019 18:00:20 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id o28so23086198wro.7 for ; Wed, 23 Oct 2019 11:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=8G2umJM4WcwrrRf5bQ91zvdUPJT2GLoNohTzCfqnwfQ=; b=MbQJamyXerrXo6MENbUDZfuN4+OnHIokNmnXacGrKtXh0qeAXJbCDkNCLWWUqExfdo x7idevgOw1gsPkyrcY/021fRR6NSMT+baVVdF5L6VpvhTWmSBEkhjQmof88U37NI5O37 h2SeWIofWWykzMs0EmKmytPvjp0MtC1Rk5hteiYAqYixYSEUvWUPzetdlC20arAbmis8 AERiYJLReEUE122/Or5szsZMAAJKa1raC/X9n4ifsivMHgObZ2OFgt3CAJgEW/fZ23AQ BymS67D3ExTjkEIXz68o8DPODFAs8W1PPNLx/KkXHeBpCUesC86/Lj5W6zCdMLDPBL/7 FHIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=8G2umJM4WcwrrRf5bQ91zvdUPJT2GLoNohTzCfqnwfQ=; b=OafEdmebe1fnxtdn6vPZJkviTu67vWRUJ0C8dkaXcbVkPLNmIwO6R41hXaHDkKvrbZ ypysVDGnV0fiGh0/sGykgB4pTdesHulfNRkUl9LED/sElhvDzJfpMRwNF5OUlf3YRsjs ctdmi3Wke/rG/ySDZ8r8rFCgf4J+s7Pbs5XOaIioCvGh04zSuyVGjqC7ClxEhmxnHVMX In849+kbu9KH5OaG2ei4yutINZUwirbuvhr4+pT82eLbtSCWOrOywP38kGp8fMHy/C4h 1SbNk7CVokjZJtzCjHKsEs3/meyjcS7jIBYBpnhdFShCVm+mA0vt/DCCAIsiFYXdkiav qhvQ== X-Gm-Message-State: APjAAAVFQr0PnZfrT0erHGrxadXdiUfXwiKd9aEhce+a2eoWM7RvV4wn RKlylOzElRtiVJuit3uvhnJV6LkPYuDCmqj0GOkbPA== X-Google-Smtp-Source: APXvYqw3FM9aRJbhNMMwxWpfg37gcBVS/EqV18VZ+Fsj3UZ2GE7UYZErRkI8Ah2U0U3hMhKg5GZeg/mguJ9iampTv9s= X-Received: by 2002:a5d:4b42:: with SMTP id w2mr12205wrs.360.1571853619352; Wed, 23 Oct 2019 11:00:19 -0700 (PDT) MIME-Version: 1.0 References: <20191018094304.37056-1-glider@google.com> <20191018094304.37056-6-glider@google.com> <20191021090925.3dcqukovauqsyw5w@pathway.suse.cz> In-Reply-To: From: Alexander Potapenko Date: Wed, 23 Oct 2019 20:00:08 +0200 Message-ID: Subject: Re: [PATCH RFC v1 05/26] printk_safe: externalize printk_context To: Petr Mladek Cc: Vegard Nossum , Sergey Senozhatsky , Steven Rostedt , Dmitry Vyukov , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Wed, Oct 23, 2019 at 7:57 PM Alexander Potapenko wro= te: > > On Mon, Oct 21, 2019 at 11:09 AM Petr Mladek wrote: > > > > On Fri 2019-10-18 11:42:43, glider@google.com wrote: > > > Petr Mladek suggested we use > > > this_cpu_read(printk_context) & PRINTK_SAFE_CONTEXT_MASK > > > instead of checking the spinlock status in kmsan_pr_err() > > > > I would like to understand why the check is needed. > > > > My guess is that it prevents a infinite recursion. > > Is this the case? It might be possible to debug this using > > trace_printk(). > This indeed used to prevent infinite recursion, however looks like the > check isn't needed anymore. > When I remove it, KMSAN doesn't hang, probably because printk is doing > a better job at deadlock prevention. > > What I'm seeing now is that e.g. in the following case: > ptr =3D kmalloc(sizeof(int), GFP_KERNEL); > if (ptr) > pr_info("true\n"); > else > pr_info("false\n"); > > KMSAN detects errors within pr_info(), namely in vprintk_store(). > If I understand correctly, printing from that point causes printk to > use the per-cpu buffer, which is flushed once we're done with the > original printing: > > [ 58.984971][ T8390] BUG: KMSAN: uninit-value in > kmsan_handle_vprintk+0xa0/0xf0 > ... > [ 59.061976][ C0] BUG: KMSAN: uninit-value in vsnprintf+0x3276/0x32b= 0 > ... > [ 59.062457][ C0] BUG: KMSAN: uninit-value in format_decode+0x17f/0x= 1900 > ... > [ 59.062961][ C0] BUG: KMSAN: uninit-value in format_decode+0x17f/0x= 1900 > ... > [ 59.063338][ C0] Lost 6207 message(s)! > > So it turns out we'd better disable reporting under logbuf_lock, > otherwise these lost messages will confuse the developers. > Because the first pr_info() isn't called by KMSAN itself, the tool > still needs a way to know it's running inside printk. > > > It is important. If it is the recursion then there are > > two possibilities how to prevent it. Either prevent > > calling the recursive printk(). Or prevent calling > > the memory checker recursive. I am not sure what makes > > more sense. > > > > Is printk() the only piece of code where you need to avoid > > recursion? I wonder how it is prevented in the other cases. > > > > > This appears to be less intrusive, although we'll need to declare > > > printk_context in some printk header. > > > > It is easier than the original approach. But the main motivation > > is that it is more reliable. The spinlock is a global lock. > > But it seems that it is enough to check the state of the local > > CPU. > > > > Finally, could you please CC me to the patch(es) that are using > > this variable? I would actually prefer to be in CC of entire > > patchsets so that I see the full context. I am very sorry about this. I'm going to re-send the patches soon and CC everyone on every patch. What I thought to be reducing the email burden on every reviewer turned out to be really inconvenient. > > Best Regards, > > Petr > > > > -- > Alexander Potapenko > Software Engineer > > Google Germany GmbH > Erika-Mann-Stra=C3=9Fe, 33 > 80636 M=C3=BCnchen > > Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg