Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp504823pxb; Mon, 7 Feb 2022 17:10:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJymqBJ7NhBcBgJBLxJKSfIOEY77TFyUbQIvDlwBbrJcmSKzbcM+yNP5gI8joL7SH1moFdaL X-Received: by 2002:a17:906:58c7:: with SMTP id e7mr1642351ejs.743.1644282646445; Mon, 07 Feb 2022 17:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644282646; cv=none; d=google.com; s=arc-20160816; b=wTjLQnqZPkz09JFukuLo/FTD2RoRT9K0Wbf3xuCW097w6T3vXi96x12hzIHmD6E/EQ 1wJXv30Uaop9sYE/lJmosE4tfPrELhMDjA7wxztwObaAfxHLSnZErWu/wCBCevJeiikV 67d6kRTBaGG/RFhrjP+QGGNWORdTw6saM4lco2q1uOztHv8iemiEItHW4hij1XiYAINc 2ajVyyQ+WzapFfmIHTVhybiDqUsmFNdsaV2QvJZa6Gi0h8tGxW9v3Rw8hu43uhydaItL A7AML2PcHp+bGJpjqg1KNy/ZcBQVN8V4iqs+QPPO/jB8OgndlyTeBbyDCM+wh0p5KgQs pPQA== 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=MK2v0Nt4cCV21YTIg8dlF+1LBbs9TTGPuFsltjIOmZY=; b=GC7701xIsTx1dSDP+S8SQ+umRa1uRH6FDByUHANIQECeyzQdSDUr5eN34FLXS4zOmW LtjJbfSJhqnWrmxf8DjHOqq+SF/2KMKZdrDJHc3V61S6z5nbU2FQ92FzVAIt7QNP55v2 A2fBTa+XZPdbIaIO7MJQqThEzA90E8EwW96Zaf3xx5QjID5NxBo6KkD62oW2Dj9IFk0X cpMit2pELJCK8K++j5O6g7maFRG5t0PfSETTfoxDPGR2LhnLers8Tu12+Bszo/pwVyCi SBAYsnXOWT8PMBws7lMq66XYafMLOaZ/oEh7l0Wqkblgth+glzqgfooMPFXE+eqGDkTA 4Tqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rMiweCVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go12si4002415ejc.881.2022.02.07.17.10.21; Mon, 07 Feb 2022 17:10:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rMiweCVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238083AbiBGTdr (ORCPT + 99 others); Mon, 7 Feb 2022 14:33:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240812AbiBGTby (ORCPT ); Mon, 7 Feb 2022 14:31:54 -0500 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F99C0401E6 for ; Mon, 7 Feb 2022 11:31:50 -0800 (PST) Received: by mail-yb1-xb2a.google.com with SMTP id m6so43126786ybc.9 for ; Mon, 07 Feb 2022 11:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MK2v0Nt4cCV21YTIg8dlF+1LBbs9TTGPuFsltjIOmZY=; b=rMiweCVJx+urv7AcwZojioWaGyvA45MimmXZ4nW0za2fZ/cduytjm2OQZyHtYp+tPx 1HrHmPCebzKnd6tfbU9efn7x6cPgg2Ts12sYH1bDkvdoffD8pp5XtzMRdtBkI3j8bFgF YF8jFpySNTXhHpbW0iLLaZ4Xdtr7HVgrurfwh05TUxgliW41tE3zDiMNBC92jvKeZe2h BS7mTS5MFOFRAbgaP/GIIe5MrNQy5/9MDgN3RIjeirtsr0eY6VsPOsClYYcVlnZCqq2l 1iBhLbmjaF6IPhNqDof1RAmK2+93XkctSjr/Btdd8oUPy7U+M6KqcYX7XZFxPvWMb/zn ooHw== 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=MK2v0Nt4cCV21YTIg8dlF+1LBbs9TTGPuFsltjIOmZY=; b=Yd0saLbsOH0LIlq8J//E47k5GvTWNZiXXIc31HJ9IaXEBEH1VfPbCfzrv8xETMMA2A 4W+KPJWCigKmc4siY3kb35IcrSHz0BZ6zSGOiuOdeI1ANt/AEUayhG5u/OyBEUl/Hrnj yrbGqFsWZlYY4+RT7le7hrAT4HZfdkgrW6Lt9bjIurvBdfzgWGLBZA9pppGSDHp+7X3m yt36vT7DOkujZwpyQ+NG9qW/ZbyrquRkjdrPc8G2PUSA1e6o2K6WlI25bQB6tiGSweKm /3Wi/wSg0zSXOkzmNRD+LVamClN5QpuVQYguSYh3iC1z5hP68PWQEcuutpD21AWD41QJ mQOw== X-Gm-Message-State: AOAM5338/sHNBBPRAiCCqZrlgJLsXzSrlrJOuKGxDKiyN/F3QSVGvTwJ zOi0BzSWNGVasOrJEiaV3Wy+DrNY4n5jVOBBeXNmK1EuL41fNvYi X-Received: by 2002:a25:d7d0:: with SMTP id o199mr1316951ybg.34.1644262309574; Mon, 07 Feb 2022 11:31:49 -0800 (PST) MIME-Version: 1.0 References: <20220128131006.67712-1-michel@lespinasse.org> <20220128131006.67712-23-michel@lespinasse.org> <20220129121319.3593-1-hdanton@sina.com> <20220201020958.3720-1-hdanton@sina.com> In-Reply-To: <20220201020958.3720-1-hdanton@sina.com> From: Suren Baghdasaryan Date: Mon, 7 Feb 2022 11:31:38 -0800 Message-ID: Subject: Re: [PATCH v2 22/35] percpu-rwsem: enable percpu_sem destruction in atomic context To: Hillf Danton Cc: Michel Lespinasse , Linux-MM , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 6:10 PM Hillf Danton wrote: > > On Mon, 31 Jan 2022 10:04:16 -0800 Suren Baghdasaryan wrote: > > On Sat, Jan 29, 2022 at 4:13 AM Hillf Danton wrote: > > > > > > On Fri, 28 Jan 2022 05:09:53 -0800 Michel Lespinasse wrote: > > > > + > > > > +static LIST_HEAD(destroy_list); > > > > +static DEFINE_SPINLOCK(destroy_list_lock); > > > > > > static bool destroyer_running; > > > > > > > + > > > > +static void destroy_list_workfn(struct work_struct *work) > > > > +{ > > > > + struct percpu_rw_semaphore *sem, *sem2; > > > > + LIST_HEAD(to_destroy); > > > > + > > > > > > again: > > > > > > > + spin_lock(&destroy_list_lock); > > > > > > if (list_empty(&destroy_list)) { > > > destroyer_running = false; > > > spin_unlock(&destroy_list_lock); > > > return; > > > } > > > destroyer_running = true; > > > > > > > + list_splice_init(&destroy_list, &to_destroy); > > > > + spin_unlock(&destroy_list_lock); > > > > + > > > > + if (list_empty(&to_destroy)) > > > > + return; > > > > + > > > > + list_for_each_entry_safe(sem, sem2, &to_destroy, destroy_list_entry) { > > > > > > list_del(&sem->destroy_list_entry); > > > > > > > + percpu_free_rwsem(sem); > > > > + kfree(sem); > > > > + } > > > > > > goto again; > > > > +} > > > > + > > > > +static DECLARE_WORK(destroy_list_work, destroy_list_workfn); > > > > + > > > > +void percpu_rwsem_async_destroy(struct percpu_rw_semaphore *sem) > > > > +{ > > > > + spin_lock(&destroy_list_lock); > > > > + list_add_tail(&sem->destroy_list_entry, &destroy_list); > > > > + spin_unlock(&destroy_list_lock); > > > > + schedule_work(&destroy_list_work); > > > > > > Nits > > > spin_lock(&destroy_list_lock); > > > 1/ /* LIFO */ > > > list_add(&sem->destroy_list_entry, &destroy_list); > > > 2/ /* spawn worker if it is idle */ > > > if (!destroyer_running) > > > 3/ /* this is not critical work */ > > > queue_work(system_unbound_wq, &destroy_list_work); > > > spin_unlock(&destroy_list_lock); > > > > Thanks for the review! Just to clarify, are you suggesting > > simplifications to the current patch or do you see a function issue? > > Apart from the nits that can be safely ignored in usual spins, I wonder if > the async destroy can be used in the contexts wrt raw_spin_lock. > > Hillf > > raw_spin_lock_irq(&foo->lock); > ... > percpu_rwsem_async_destroy(*sem); > ... > raw_spin_unlock_irq(&foo->lock); Sorry for the delay. Are you concerned about the use of spin_lock() inside percpu_rwsem_async_destroy() which would become a sleeping lock in case of PREEMPT_RT? If so, we can use raw_spin_lock() when locking destroy_list_lock. Please confirm. Thanks! >