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=-14.8 required=3.0 tests=BAYES_00,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_AGENT_SANE_1, 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 D09B9C433B4 for ; Wed, 21 Apr 2021 10:27:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6317C6140F for ; Wed, 21 Apr 2021 10:27:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6317C6140F 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 630866B0075; Wed, 21 Apr 2021 06:27:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 598DE6B007D; Wed, 21 Apr 2021 06:27:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 301006B007E; Wed, 21 Apr 2021 06:27:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id E73566B0078 for ; Wed, 21 Apr 2021 06:27:12 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A3840181AEF3C for ; Wed, 21 Apr 2021 10:27:12 +0000 (UTC) X-FDA: 78055996704.17.E8E067A Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by imf23.hostedemail.com (Postfix) with ESMTP id 6ADF5A0000FD for ; Wed, 21 Apr 2021 10:27:10 +0000 (UTC) Received: by mail-wm1-f52.google.com with SMTP id p10-20020a1c544a0000b02901387e17700fso949241wmi.2 for ; Wed, 21 Apr 2021 03:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DfB1PskyNKQQCJWiqpnf2aCTUFDtX+OVVcg4l3dtuu0=; b=JLKCps/Zcs/UvWNUG+U/E5lImOR0QsazxPixbpLZqvjVJxq6y7XQpCKo78ErdmZ+tP au6+Neik1wA/a5fgngjhC5e/u+Oklcj0cpsDP7S4MaoCRMfjzdL8Z85wJ7vah/7UhxgT WmdR1RDjkQVIeI//3jaYhsBRpKg+2oBueWfLy66YT387t5TskbFddEaWRAhBe2ZemoBj PtxePg7gsA5DBG/aiCOInZrULgu5pT7CkcQ1bY/TrH7lA6i7H+Hc2ujyWdnDV3IvHOT3 0IVVBf5AIPrDZ+fMwvgKRgNdUIjVTHrWgUUaRCtLxZHdASBh1LT11ZylKug6Ru4Z8QFA oquA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=DfB1PskyNKQQCJWiqpnf2aCTUFDtX+OVVcg4l3dtuu0=; b=m1a+0t2sLqJKDDQSvVVe6bMeVgu4Mr36RRGICevX6KCA7BIMCUCZpIjvxFfnwA68Ev O8Jw67D0dT4z1lsUWgsAi0Mf+xr52uMIfMozBbohm964d4RUwS5BCSbUwvRquxsiR3M2 srIQZLSKKK21LWEkCRPRxMlBcUXiEFPSPJAerAkwIfgpY1UQDLWn4WMNtLF5XV8RLSYG 5dLNIGaK87R/0YS/LxzsTFSckIKxPFKYAK8KILPyfwfdmCmCKGqdtYRQY9n72Ri/jXd1 +O530RoIy+ylob21lCeudcD6gtVfco+FR1hS/98mJHeCXshf8Vy9Ur8O2Md8KJVPLyZZ muMw== X-Gm-Message-State: AOAM530DY3DZxqQB/iGL6Kzlyh1ay9au5S+lOqtbr669MWB6uzhUMnX4 qW0c31x5BBSgiZchr+Vtqj+9mw== X-Google-Smtp-Source: ABdhPJx2FR9qi1jPU3sc3SVulZmm3AqTBeSEZoS6yKvAGaiKSJTgvJh0l87+4A0BR45YF0U2jce86A== X-Received: by 2002:a05:600c:4fce:: with SMTP id o14mr9054440wmq.121.1619000830626; Wed, 21 Apr 2021 03:27:10 -0700 (PDT) Received: from elver.google.com ([2a00:79e0:15:13:c552:ee7c:6a14:80cc]) by smtp.gmail.com with ESMTPSA id c12sm2655220wro.6.2021.04.21.03.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 03:27:09 -0700 (PDT) Date: Wed, 21 Apr 2021 12:27:04 +0200 From: Marco Elver To: Hillf Danton Cc: Andrew Morton , Alexander Potapenko , Dmitry Vyukov , Jann Horn , Mark Rutland , LKML , Linux Memory Management List , kasan-dev Subject: Re: [PATCH 1/3] kfence: await for allocation using wait_event Message-ID: References: <20210419085027.761150-1-elver@google.com> <20210419085027.761150-2-elver@google.com> <20210419094044.311-1-hdanton@sina.com> <20210421091120.1244-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210421091120.1244-1-hdanton@sina.com> User-Agent: Mutt/2.0.5 (2021-01-21) X-Stat-Signature: c8boo8edrxqj5bf7iwhoednqnakufckj X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6ADF5A0000FD Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail-wm1-f52.google.com; client-ip=209.85.128.52 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619000830-868984 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, Apr 21, 2021 at 05:11PM +0800, Hillf Danton wrote: > On Mon, 19 Apr 2021 11:49:04 Marco Elver wrote: > >On Mon, 19 Apr 2021 at 11:44, Marco Elver wrote: > >> On Mon, 19 Apr 2021 at 11:41, Hillf Danton wrote: > >> > On Mon, 19 Apr 2021 10:50:25 Marco Elver wrote: > >> > > + > >> > > + WRITE_ONCE(kfence_timer_waiting, true); > >> > > + smp_mb(); /* See comment in __kfence_alloc(). */ > >> > > >> > This is not needed given task state change in wait_event(). > >> > >> Yes it is. We want to avoid the unconditional irq_work in > >> __kfence_alloc(). When the system is under load doing frequent > >> allocations, at least in my tests this avoids the irq_work almost > >> always. Without the irq_work you'd be correct of course. > > > >And in case this is about the smp_mb() here, yes it definitely is > >required. We *must* order the write of kfence_timer_waiting *before* > >the check of kfence_allocation_gate, which wait_event() does before > >anything else (including changing the state). > > One of the reasons why wait_event() checks the wait condition before anything > else is no waker can help waiter before waiter gets themselves on the > wait queue head list. Nor can waker without scheduling on the waiter > side, even if the waiter is sitting on the list. So the mb cannot make sense > without scheduling, let alone the mb in wait_event(). You are right of course. I just went and expanded wait_event(): do { if (atomic_read(&kfence_allocation_gate)) break; init_wait_entry(...); for (;;) { long __int = prepare_to_wait_event(...); if (atomic_read(&kfence_allocation_gate)) break; ... schedule(); } finish_wait(...); } while (0); I just kept looking at the first check. Before the wait entry setup and finally the second re-check after the mb() in prepare_to_wait_event(). So removing the smp_mb() is indeed fine given the second re-check is ordered after the write per state change mb(). And then I just saw we should just use waitqueue_active() anyway, which documents this, too. I'll send a v2. Thank you! -- Marco