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=-13.3 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_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 839B3C433B4 for ; Mon, 19 Apr 2021 09:49:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E724560FF1 for ; Mon, 19 Apr 2021 09:49:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E724560FF1 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 76FC46B006E; Mon, 19 Apr 2021 05:49:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F88C6B0070; Mon, 19 Apr 2021 05:49:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54AA56B0071; Mon, 19 Apr 2021 05:49:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 320CB6B006E for ; Mon, 19 Apr 2021 05:49:17 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DA503824999B for ; Mon, 19 Apr 2021 09:49:16 +0000 (UTC) X-FDA: 78048643512.39.0EE48CE Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) by imf04.hostedemail.com (Postfix) with ESMTP id 6E8EC13A for ; Mon, 19 Apr 2021 09:49:14 +0000 (UTC) Received: by mail-oo1-f44.google.com with SMTP id p12-20020a4a2f0c0000b02901ecdbb16887so695417oop.5 for ; Mon, 19 Apr 2021 02:49:16 -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; bh=nitggrP0xRKevJNitjMdZZF9gGxfx3q/C1mur/zTDM4=; b=SnrQH8znT2PnsSAqn0jXpHSmCspkH0VVBOSQegOGOyXENQDZaw59x840LwuilNQe+L TKgVMlImiglbkLDoP6FzmSzTMU7We1xNNNR4lwb6yd7RP5gE9T6UEdJZS1x6byCQyiuK oivTvlDGePHJgoizjxX+ip7vSAxMBfmumdb0NB0Mbqz0R7x0whQ3bAib84SZTSY5cbsa j0bxgF91OhwJUDBta4spTK92YGdQiOrEsiGwLnWtj/r2+sP1VFXUN0gAOEUa3vHbhEi5 c6cz8AalBDd4qvdOiCjiEhd1xaETwZaPyKBuZg2GdikqsiyhXlSWwH34sFvKEpZrUN6k wgLA== 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; bh=nitggrP0xRKevJNitjMdZZF9gGxfx3q/C1mur/zTDM4=; b=kW/IEjqgT1aQjJJioMsPrDIWJuLfes+vvSYPx+awtd0ggxpxmYmYOyIzaREjSHRJCf KcHwxRl4IQaPcIW6T77V1Cakv3tHrWRdobEwPu5v5tBtcRYEBQbB27KAocaS5zleS/JP sJr/ZqR+S2QfrvOlQLBXHeDSUzwEHwMzBTWw8cCZvDSjTAkX2gcXrfpDczCm/vCpbuhW xMIb5kEMwgrU1xR0UKtH7Q52FmfNESrGqDCKWymW3t7iAH5LUTYKkVSrATfWAowGmYoK qYsSikv10iMQKjT/RM6OeKr9AGQXeuP+hPJKHCm1nY7ZBU7lZoFSfk9pWv33rRYPzE2h 4cZA== X-Gm-Message-State: AOAM53079UkwVm3j+90LtPHfR1e5LsWvGfw4+dbyZc3VrpR5QxoUZjCl PJy4P98ABKyGHgXGh+Yq++lmiach3UU17azUcOfF0g== X-Google-Smtp-Source: ABdhPJyK0p5DKT8g7HVkLdNNo5TjSC69kgdPjyM/tw685tNXp7o0tBnV2rd+RRqciPsuO8a/EdxlE8c1zvZKS2jKS5Y= X-Received: by 2002:a4a:eb02:: with SMTP id f2mr12729819ooj.36.1618825755725; Mon, 19 Apr 2021 02:49:15 -0700 (PDT) MIME-Version: 1.0 References: <20210419085027.761150-1-elver@google.com> <20210419085027.761150-2-elver@google.com> <20210419094044.311-1-hdanton@sina.com> In-Reply-To: From: Marco Elver Date: Mon, 19 Apr 2021 11:49:04 +0200 Message-ID: Subject: Re: [PATCH 1/3] kfence: await for allocation using wait_event To: Hillf Danton Cc: Andrew Morton , Alexander Potapenko , Dmitry Vyukov , Jann Horn , Mark Rutland , LKML , Linux Memory Management List , kasan-dev Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6E8EC13A X-Stat-Signature: brgwh4y6nbht5ebnskfcewgxdydbji73 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=mail-oo1-f44.google.com; client-ip=209.85.161.44 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618825754-35881 X-Bogosity: Ham, tests=bogofilter, spamicity=0.015048, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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). Otherwise the write may be reordered after the read, and we could potentially never wake up because __kfence_alloc() not waking us. This is documented in __kfence_alloc(). > > > + wait_event_timeout(allocation_wait, atomic_read(&kfence_allocation_gate), HZ); > > > + smp_store_release(&kfence_timer_waiting, false); /* Order after wait_event(). */ > > > +