Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2776249rdd; Sat, 13 Jan 2024 01:13:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnspxMjxkPBIX2dXR+f2FMNioS0Az8rl05x1GxS4WDdAA1EZWJOtKKu2lSUCce6rBT29PH X-Received: by 2002:a05:6808:bd0:b0:3bd:4d17:c251 with SMTP id o16-20020a0568080bd000b003bd4d17c251mr2917167oik.0.1705137186915; Sat, 13 Jan 2024 01:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705137186; cv=none; d=google.com; s=arc-20160816; b=cjKQ+QEzTCHbkHpb6EqgfyQSaJYwvcBdJ+09w5wNuPI02ggPZYV4mnLGvRYNk/edle qHLehpw1mKloc3kE30831eoBvJTugoPYYlvYaZxGoYfbHdd0n+QmI2FHlT2QA9eSd+Um FTNOm6d8jNoSQrVTjB1NZ1nIC1CnAd3Q7i40gZLMon3hbEy+hx8XE89HeBNnFuaYylbt MpaHiT+NR4oyMeSnSuFI/Yx75MuLqj7+MuUc4hgSGZYZxAAzCofH6HrpsgXVbT+8rNRv 6Xe02g22t1aTwWr8Q1Psh8NMDNbmFMDUgshM48YoLA6IpSgwe3SMd+MHY7flNu1V+pUT Bcng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=Yo3t4e6P0WumxGPjlAvUPSxdP7muYs1O7d3R9moE3Qk=; fh=KtmuM4t+2D/0bgkLGSGV2OTdmeV3Sg+Pwv69Xxa5wIY=; b=QnODPeCaNPFFh69Cun1xu3a0AXgNzNEsuiMe7NnddI7G8MGZ6qVdEqoXRObQqCAp+D aL/mQw8Ob2J/8S/iLsLiOBPCxcXxV0u55soN1SOMPBGZamMx3kOLoMr7STCF/yxXwIMv nQDnrR5CT3OFMFpHMwTFh85LlqIc5fW/IVU9gC8Kn1iOPc4sNuJYB8Njcn6SxHx8yluL lVMOXmgZOMDzN0mLKKPnNxyc5nNNlK2eXgvhFGI885d0PaaO7/bMlaSKldlucI6ATAE8 VK+0YrcQCLcyXln+5CBbC9w6is9HU6KskMA9fJjePC6+rBYwqrbWm+UNq6cTUyJLypvw 61Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=L0od8ezP; spf=pass (google.com: domain of linux-kernel+bounces-25229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c10-20020a170902c1ca00b001d48a75a6d4si4667549plc.623.2024.01.13.01.13.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 01:13:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=L0od8ezP; spf=pass (google.com: domain of linux-kernel+bounces-25229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BEFBE2851BF for ; Sat, 13 Jan 2024 09:13:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B58EA48; Sat, 13 Jan 2024 09:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L0od8ezP" Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04D0D7E9 for ; Sat, 13 Jan 2024 09:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-7cc9da9995bso2301259241.3 for ; Sat, 13 Jan 2024 01:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705137177; x=1705741977; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Yo3t4e6P0WumxGPjlAvUPSxdP7muYs1O7d3R9moE3Qk=; b=L0od8ezPtEo8KAfaAqNNIh872tuq9ZJbcjp0uBzzTsib6XOOK0wI/fNuUa8m4Rb2XQ h4dvQBlXiXHXHyRsh11lJT7iTs7s8GEPs2W6l26UailS+n2zcQsVwsojl01qSZnZi6F3 OKQWnwf7GB9ahH2kPvpajfqn/Do8pncYXrEF/a2dHEndK/B2dQyWLaXmTiyzJyypsYQY EgduWljuaBivFNTutZEDpoc/IjLvQXM0IBbY6Iqn7ryFOuVqb6gqYydUd/TE92c4UoSN Ii/D/YMbeIk5uPyHJClKPQ4ipRHNOPiWMSFSqLC9gga63WeO82C5THjJmOCbxXoMZs2x +k4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705137177; x=1705741977; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Yo3t4e6P0WumxGPjlAvUPSxdP7muYs1O7d3R9moE3Qk=; b=GhmAzRFMFWoA9/4C30zc/DK1CDsffNLO4QLKuTZInwhVjWArdUKHBhYOmV4PNwOOWB g//7p5qb0laVXG49lLkS7lhfHEg0/jpIjFR3t04xNAEdWf9IK0yuWwQwpG6LVf9m5l4W l6NNV0zNXZz2NWG6KUuQzI36p/FyaVW+3shGn4EJyrw0d1W0Acp+PwSvztV6B9iUm4jj SEdG6dVZc2J9ENnzF1YIOMItn/2az0Ne8Ge7rp81tnI2nzQKEUw6sYXp2lCmPD09GDxV wF4Tf82BgQWePo4j+5w6R1QPSpBALv0QC0WW75YibqeCoMU4IidjOYRXlVP7duUubLpm ouFQ== X-Gm-Message-State: AOJu0Yzl7Vhg6pBadw96s0BLAW5V3tXKT3xEhaUGd96qhFfBpa/n0v/9 l3ENbIQoRg2DtxMA4XzR7XveveM1itWzR6ml6kJulT1VzT2Z X-Received: by 2002:a67:ea53:0:b0:468:e16:1cf9 with SMTP id r19-20020a67ea53000000b004680e161cf9mr1822608vso.60.1705137177555; Sat, 13 Jan 2024 01:12:57 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <9f81ffcc4bb422ebb6326a65a770bf1918634cbb.1700502145.git.andreyknvl@google.com> <87sf34lrn3.fsf@linux.intel.com> In-Reply-To: From: Marco Elver Date: Sat, 13 Jan 2024 10:12:21 +0100 Message-ID: Subject: Re: [PATCH v4 12/22] lib/stackdepot: use read/write lock To: Andi Kleen Cc: Andrey Konovalov , Oscar Salvador , andrey.konovalov@linux.dev, Andrew Morton , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" On Sat, 13 Jan 2024 at 02:24, Andi Kleen wrote: > > On Fri, Jan 12, 2024 at 11:15:05PM +0100, Marco Elver wrote: > > + /* > > + * Stack traces of size 0 are never saved, and we can simply use > > + * the size field as an indicator if this is a new unused stack > > + * record in the freelist. > > + */ > > + stack->size = 0; > > I would use WRITE_ONCE here too, at least for TSan. This is written with the pool_lock held. > > + return NULL; > > + > > + /* > > + * We maintain the invariant that the elements in front are least > > + * recently used, and are therefore more likely to be associated with an > > + * RCU grace period in the past. Consequently it is sufficient to only > > + * check the first entry. > > + */ > > + stack = list_first_entry(&free_stacks, struct stack_record, free_list); > > + if (stack->size && !poll_state_synchronize_rcu(stack->rcu_state)) > > READ_ONCE (also for TSan, and might be safer long term in case the > compiler considers some fancy code transformation) And this is also only read with the pool_lock held, so it's impossible that there'd be a data race due to size. (And if there is a data race, I'd want KCSAN to tell us because that'd be a bug then.) depot_pop_free() can't be used w/o the lock because it's manipulating the freelist. To be sure, I'm adding a lockdep_assert_held() to depot_pop_free(). > > + return NULL; > > > > + stack = depot_pop_free(); > > + if (WARN_ON(!stack)) > > Won't you get nesting problems here if this triggers due to the print? > I assume the nmi safe printk won't consider it like an NMI. > > > counters[DEPOT_COUNTER_FREELIST_SIZE]++; > > counters[DEPOT_COUNTER_FREES]++; > > counters[DEPOT_COUNTER_INUSE]--; > > + > > + printk_deferred_exit(); > > Ah this handles the WARN_ON? Should be ok then. Yes, the pool_lock critical sections are surrounded by printk_deferred. Thanks, -- Marco