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 8C179C433EF for ; Wed, 5 Jan 2022 18:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB1C96B0071; Wed, 5 Jan 2022 13:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A60716B0073; Wed, 5 Jan 2022 13:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 928936B0074; Wed, 5 Jan 2022 13:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 7F56F6B0071 for ; Wed, 5 Jan 2022 13:50:55 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 35D7594FDF for ; Wed, 5 Jan 2022 18:50:55 +0000 (UTC) X-FDA: 78997125270.12.E6C8F7D Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf23.hostedemail.com (Postfix) with ESMTP id BEFA1140005 for ; Wed, 5 Jan 2022 18:50:40 +0000 (UTC) Received: by mail-ed1-f44.google.com with SMTP id z29so162649edl.7 for ; Wed, 05 Jan 2022 10:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cfHNQGe03MWFiDjULzVbgtf6gbGg6JH50kN5fzPFHfA=; b=ewSSp59OgURps0hS/LbW55Aq+2LDBhNRyITlsFPwMv1qN0xdjkSe8cJKmF/NCk/WBt R58wzWpaldO8LqJhB/qpMqjiN9D3/kGtQKNirCRALgXZp5BNYKxw1hgUKICOPRv6gKDu Ljv/jlukGMuGKpoZcZe1iXxy98uqcnQ97Dx4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cfHNQGe03MWFiDjULzVbgtf6gbGg6JH50kN5fzPFHfA=; b=ZYFFCfcvr17ALMbYcz/C5B7NcZje+GaZEBxMWPs5uciEipBuIoQsrYT4nLWGiXnD0h Rcf4U4bwE6tkOyStfz9GWlPYXCOX/tMPrFK06AcII4DnG1t/GmQoq6o79ADYR3Rs9HUv UrN5OR7RHrgf/Vikx0c8dZt6LX86Zhwn8v44innyNJFynW3fRiu880combqIn10w1eEs To/4KOOcNStxTmjBuYZbiJXUhg7nooS8K43Uj8gfJYWl7JvcG85EdpX4SXcwl433RQAi tu71pegor/I7Q2WRoffHchT5n67ZyS2IT0atjx1e9wnWFasWs0flC3kZ3N9PKI/QqsJ4 0xFA== X-Gm-Message-State: AOAM5307564WKtRYHN5J8s7L54Gc1W0QzlBMje5jW2DNbvO+lapc53pY oJ284Tx3xkRCkDP8o+QvW4Cimbkib4h7JX0qzNA= X-Google-Smtp-Source: ABdhPJw93b/nztIT1+wlErONUjsSCxY7g7adAYcrFkzFyMFiRgyVI5XGHY3SHQKgpmwJaj8hv0iz7w== X-Received: by 2002:a17:907:3e8f:: with SMTP id hs15mr42900615ejc.340.1641408652308; Wed, 05 Jan 2022 10:50:52 -0800 (PST) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com. [209.85.128.49]) by smtp.gmail.com with ESMTPSA id di18sm12436826ejc.56.2022.01.05.10.50.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jan 2022 10:50:50 -0800 (PST) Received: by mail-wm1-f49.google.com with SMTP id n19-20020a7bc5d3000000b003466ef16375so2473001wmk.1 for ; Wed, 05 Jan 2022 10:50:49 -0800 (PST) X-Received: by 2002:a7b:c305:: with SMTP id k5mr4008893wmj.144.1641408649511; Wed, 05 Jan 2022 10:50:49 -0800 (PST) MIME-Version: 1.0 References: <000000000000e8f8f505d0e479a5@google.com> <20211211015620.1793-1-hdanton@sina.com> In-Reply-To: From: Linus Torvalds Date: Wed, 5 Jan 2022 10:50:33 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: psi_trigger_poll() is completely broken To: Eric Biggers Cc: Johannes Weiner , Peter Zijlstra , Juri Lelli , Vincent Guittot , Ingo Molnar , Hillf Danton , syzbot , linux-fsdevel , Linux Kernel Mailing List , syzkaller-bugs , Linux-MM Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=ewSSp59O; spf=pass (imf23.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.44 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BEFA1140005 X-Stat-Signature: aw15o51ym7zqbr48gxuw8k7m1pw9saey X-HE-Tag: 1641408640-582471 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, Jan 5, 2022 at 7:21 AM Eric Biggers wrote: > > [changed subject line to hopefully get people to stop ignoring this] > > Please see my message below where I explained the problem in detail. Any > response from the maintainers of kernel/sched/psi.c? There are a lot of you: Ok, this one is clearly a kernel/sched/psi.c bug, since the lifetime isn't even maintained by the fiel reference. I think the proper thing to do is to move the whole "get kref to trigger pointer" in the open/close code, and keep the ref around that way. The natural thing to do would be to look up the trigger at open time, save the pointer in seq->private, and release it at close time. Sadly, right now the code actually uses that 'seq->private' as an indirect rcu-pointer to the trigger data, instead of as the trigger data itself. And that seems very much on purpose and inherent to that 'psi_write()' model, where it changes the trigger pointer very much on purpose. So I agree 100% - the PSI code is fundamentally broken. psi_write() seems to be literally _designed_ to do the wrong thing. I don't know who - if anybody - uses this. My preference would be to just disable the completely broken poll support. Another alternative is to just make 'psi_write()' return -EBUSY if there are existing poll waiters (ie t->event_wait not being empty. At least then the open file would keep the kref to the trigger. That would require that 'psi_trigger_replace()' serialize with the waitqueue lock (easy), but all callers would also have to check the return value of it The cgroup code does psi_trigger_replace(&of->priv, NULL); in the release function, but I guess that might work since at release time there shouldn't be any pending polls anyway. But it would also mean that anybody who can open the file for reading (so that they can poll it) would be able to keep people from changing it. But yes, I think that unless we get some reply from the PSI maintainers, we will have to just disable polling entirely. I hope there are no users that would break, but considering that the current code is clearly too broken to live, this may be one of those "we have no choice" cases. Linus