Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7283379rdb; Wed, 3 Jan 2024 10:18:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFS8zGRauu01dutEv3UBcVLPS60XFtTXRlvFG+Skwx/DaKyU3Kf7t7kyWAf1ebr6txYu1Nx X-Received: by 2002:a05:6a00:138f:b0:6d9:bf50:1c94 with SMTP id t15-20020a056a00138f00b006d9bf501c94mr6463338pfg.9.1704305933585; Wed, 03 Jan 2024 10:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704305933; cv=none; d=google.com; s=arc-20160816; b=Ek9Q7JaJ+0cc+lMwq0x+SIBNC+IhQGoP9h52zeorIRMfVyK4QayR7v/wf/qIRVKtth Dc5UOGWMfzwV7SURLlpSQYIepRVUOv1/MUPdkYM9fdW/8aBBO3wZ9CW1DxSPtVPhvGb+ Kc+rWIwk0DVK/mBQiREpwZKRAXUqkKBh6pRbRIxUAZWCq2Awb+Hgi4ues2FfCUn/TUmB kYQRYXmNp5SpCExr89zO3LvmL6FMHs0FXNVTezXf+vz+foMDNRmgiUNEco+Zxw9Hadi7 GSYIPrEX0UA6iRvQiQI+IGeUhqK/NUpbhqihPVl1+kIzEZCiibIS+zihB1Jfaj24FwCM kQDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FmcnlJXDQ98odN/WIJ37kgFC20dlWMFiiPEysBR0RLo=; fh=foMwSGoekPaBR4LHtzVZDeajsi49hy+Y1EeLJUCwgwk=; b=GM1zqjF1m8Vk3rX3pYLqQ3oxU9m2YyH8RfUS4tDtEgba97o70iKlrp2Nz7Yr7HKjkp llRPrXIPpT9g5sWmd30zGNNyH28GqJzK0CqhFIn4SNssQMhSLRJmWXR91fXUo+7ovWGx QLu7jacX7xBZi0mUia3EsrpeUHrl7MiUeWyT+HuPKtW3+yHR+utC20mJu9gEhsR8mKLZ H33u3M/MajVsxUUXD374aRL3ucj89of996h3CkAGKLMsqzeDVSDmwUFBNTZxlHGysIDu sDN1oN9m99nWN7w1kHD7hd4vBM1jnJYSjnTqk/4Nxz/9fULlcOmBtb6P6jheMFF6OQxy TwBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="mNYekl/c"; spf=pass (google.com: domain of linux-kernel+bounces-15846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15846-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g4-20020a056a000b8400b006d60bb449e0si17270068pfj.361.2024.01.03.10.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 10:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15846-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=@infradead.org header.s=casper.20170209 header.b="mNYekl/c"; spf=pass (google.com: domain of linux-kernel+bounces-15846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15846-linux.lists.archive=gmail.com@vger.kernel.org" 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 B19B5286D3F for ; Wed, 3 Jan 2024 18:18:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 434751C6AB; Wed, 3 Jan 2024 18:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="mNYekl/c" X-Original-To: linux-kernel@vger.kernel.org Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDF831CA81; Wed, 3 Jan 2024 18:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FmcnlJXDQ98odN/WIJ37kgFC20dlWMFiiPEysBR0RLo=; b=mNYekl/cRuUCgREXI6BMiAqoL/ WKPwXmHicaLj/SoyAyhEl4lwc1JY9ho99XeqYCADJfovFEgcmKtKxbzHtZ23d0x+GrjTXAp/nAXYg 6m55AvIuQOxvVhpkh70jRdbDVoJuollTmjQmR5eqGNyq6/mm5fwDk6fn4LwBqgrBstcXYATXDKTwf P6+NOcN82q5Xp9FeAKjKuLv52WprkRqG/XUtFj8Pm35WDZ3lKo1SrK/w7C5LJRZCNiokxNKao0itW ILPXteBeUi1q+KqxjWo30XinMlvhI0WgyRJGkhNj/qbivwdDJuv/kTYK34e+83w4UBYTiiG03sIGY 1lnCH5JQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rL5od-00DHx5-Kt; Wed, 03 Jan 2024 18:18:07 +0000 Date: Wed, 3 Jan 2024 18:18:07 +0000 From: Matthew Wilcox To: "Aiqun Yu (Maria)" Cc: "Eric W. Biederman" , Hillf Danton , kernel@quicinc.com, quic_pkondeti@quicinc.com, keescook@chromium.org, viro@zeniv.linux.org.uk, brauner@kernel.org, oleg@redhat.com, dhowells@redhat.com, jarkko@kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Message-ID: References: <20231213101745.4526-1-quic_aiquny@quicinc.com> <87o7eu7ybq.fsf@email.froward.int.ebiederm.org> <99c44790-5f1b-4535-9858-c5e9c752159c@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <99c44790-5f1b-4535-9858-c5e9c752159c@quicinc.com> On Wed, Jan 03, 2024 at 10:58:33AM +0800, Aiqun Yu (Maria) wrote: > On 1/2/2024 5:14 PM, Matthew Wilcox wrote: > > > > -void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock) > > > > +void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock, bool irq) > > > > { > > > > int cnts; > > > > @@ -82,7 +83,11 @@ void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock) > > > Also a new state showed up after the current design: > > > 1. locked flag with _QW_WAITING, while irq enabled. > > > 2. And this state will be only in interrupt context. > > > 3. lock->wait_lock is hold by the write waiter. > > > So per my understanding, a different behavior also needed to be done in > > > queued_write_lock_slowpath: > > > when (unlikely(in_interrupt())) , get the lock directly. > > > > I don't think so. Remember that write_lock_irq() can only be called in > > process context, and when interrupts are enabled. > In current kernel drivers, I can see same lock called with write_lock_irq > and write_lock_irqsave in different drivers. > > And this is the scenario I am talking about: > 1. cpu0 have task run and called write_lock_irq.(Not in interrupt context) > 2. cpu0 hold the lock->wait_lock and re-enabled the interrupt. Oh, I missed that it was holding the wait_lock. Yes, we also need to release the wait_lock before spinning with interrupts disabled. > I was thinking to support both write_lock_irq and write_lock_irqsave with > interrupt enabled together in queued_write_lock_slowpath. > > That's why I am suggesting in write_lock_irqsave when (in_interrupt()), > instead spin for the lock->wait_lock, spin to get the lock->cnts directly. Mmm, but the interrupt could come in on a different CPU and that would lead to it stealing the wait_lock from the CPU which is merely waiting for the readers to go away.