Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2444527pxb; Mon, 19 Apr 2021 06:01:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTOYBHA2CCj67tF0Us3cj/wnAO1dV6Qla8xPtlDxYDZ+lWA7g+5qzXT5KTSCZpYiXHY7Xf X-Received: by 2002:a17:906:4eda:: with SMTP id i26mr21937268ejv.301.1618837311621; Mon, 19 Apr 2021 06:01:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618837311; cv=none; d=google.com; s=arc-20160816; b=CUn+dl+yv7ZTjmbZb46LuvCqZQY9Dg9SZB4m8ay1tWZpG1SzCNrJ2u+cm85/KKOTQX zA5EJcNHs9vJyoCp9DSScFdEPiZ9zbcFVSACskhXvaIMRUBHXkd7ChXMMZ9XX0tBgxxh cr4tkaZBHHPGj/Dl+FuV5kK+Sq+xYiqtbvKmM0athA8FNzWb3K/maMcOhsBqG1XSqajH 1GBCIZVuTkzCBjkVxk/S99GIkzb8fFeP4/v3oEBJqBccHy7+8fA5i8x0Y+TOGdtbyEqx y8CKp5Y64fufXx4jzzn+DX4qAsReeOSOAtnRziAdqVKm8CGaSlK1TldqtMhRL6o7cwsV 0ivw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nitggrP0xRKevJNitjMdZZF9gGxfx3q/C1mur/zTDM4=; b=AkDww2WZRiaBXoaNkfTdh4TB/KZmNKdp1yAvhekRcyrEhIGy7vJZDCl7AnyBzX0lpa 7oAL0LIqNc4x0q15sFZB3dBHBBRvV0ShmI7Pi4rjYZuLcYI8WBGGPAu64OeBx1/F2+// tHKILLzSe/33vdcG8auzUY//l12hfugi15bWNcgDnMKMP7zk6gx8/Kk5Llmt6tV1zTnt sgbufSNiZjZ3dqjy93ryjBTvuO0sO7EJ9VOm/d4lIS5qsqZyZx65UjLrORZbmr7Xpccq ra2lwUt5A6P4kd1ppYr1rKlJLfcvGM9JM/nVEw5M1kaAXhg82zolhskR7+J7OMiE9xrW 16wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SnrQH8zn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f27si13648916ejf.327.2021.04.19.06.01.20; Mon, 19 Apr 2021 06:01:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SnrQH8zn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbhDSJtr (ORCPT + 99 others); Mon, 19 Apr 2021 05:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbhDSJtr (ORCPT ); Mon, 19 Apr 2021 05:49:47 -0400 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83677C06174A for ; Mon, 19 Apr 2021 02:49:16 -0700 (PDT) Received: by mail-oo1-xc34.google.com with SMTP id m25-20020a4abc990000b02901ed4500e31dso631172oop.1 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=p1cTxVOyqxJ0xmVHN1OCTMAaiJjxZlbRZTQtvdjnjIVCOfN7bK8JzfwulH4TyQ4xY+ ZiMUXkxqUUV1naNxSibEqowYWJyZ8amg2JmRJIpPfmlnTNGRW7jivatzoiMXGukGP2P9 PHuVE1kXJ8a70Rs5Bink2LwfU+AttMEyRryNRfciPPNJr52TPRYX2lZJ+ehdAtEUKroX imhJPXUXSHQI3LZTLQzogNf294h6cqhkK8PULUIlW7ndG34lgGycZahArRhUJ5Qd1m9F p/G2kVwUn97BuvN8VgOhXSnMWvFlGbLB/3CEuR2hN1e+fBmbTL71TmTIeJdfptKHR9lN q0mg== X-Gm-Message-State: AOAM531O+c8qXAqEMvYgswP1afGaxr9JjsmM7lgadQDaARz2xT8HKsnp oj2gnR9tQSjVk2KF+by4xpXhPzLlFaF9UIKblF007A== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). */ > > > +