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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDA5DC47079 for ; Wed, 3 Jan 2024 18:18:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2291E6B03BB; Wed, 3 Jan 2024 13:18:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D7E76B03BC; Wed, 3 Jan 2024 13:18:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 051266B03BD; Wed, 3 Jan 2024 13:18:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E43BD6B03BB for ; Wed, 3 Jan 2024 13:18:39 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BA2AC1203A2 for ; Wed, 3 Jan 2024 18:18:39 +0000 (UTC) X-FDA: 81638810358.05.05E4228 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 975D81C0016 for ; Wed, 3 Jan 2024 18:18:37 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="mNYekl/c"; dmarc=none; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704305918; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FmcnlJXDQ98odN/WIJ37kgFC20dlWMFiiPEysBR0RLo=; b=LhnTcprDIURwlaBifJxBD30n7seTUMWEH63vn8C6ueSe8eFSYil1aL1ngONrrQ0J+wT1sE GCFm+xC49M2qKLKIPipCEG0guHickWJZa7hAQsjBBfs2CVvUTXfEYlNxKAB57y7MRw2jVH GS73qg9WUxz1Bz80NUrf9mvXgKagI6s= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="mNYekl/c"; dmarc=none; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704305918; a=rsa-sha256; cv=none; b=IdZIPUL5s6C5+6E5PD71ynRuF01xXGyw/2dcPhBehwL8yvLKVn3Gp6662BiXmfVwqv7P9A ChDyJ/6ywo+gRQktnAXPJMuNDky18HspPnjm3D2jh2Oau+2bH3aHJk11wkQ3bA4jSiR77W l63qd0GydFZn+HI1cqAZLdemc7FpuqI= 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <99c44790-5f1b-4535-9858-c5e9c752159c@quicinc.com> X-Rspamd-Queue-Id: 975D81C0016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xz8in5ybuka4y7q8mccpyi7hewprpm3z X-HE-Tag: 1704305917-378735 X-HE-Meta: U2FsdGVkX1/GonKAu8wGXO8KcwnmqSm4wMEHHbkc9RpzmIkSUi7VEg7Tib30fRKqxLPG44r+xIa4NT6FvBO6UNe1uNcpa5PK4bG07J7ZBuvKbNhsTzSP9VMZcnitugXk3pSnYkSeWSi7KdUIuF6lcOJG/3NHFXg3GpXBBDTvesytpJ02H9GvgyzlEiujKdKkwfuvU6iex4wghqrzHExKbFNwSzkwRQv3uwah58ih7iByk9FWV1bOCTs0emJ8Jxfs0p85zVY3VTNpmw648NDUZpTNkurCDLlWZU/xCpdt7F3RX7xMnWLVxmuWfFKB/2Oq0VpUyUnzm3jtBrfkn5UP62p0OE9+soqJ1Y837OrwhkLHQzeIyWm8ROzs7egAyZRHviT+l/1noOpjxUXtHmBerEteohoH/DqFnFVDkVPtwIH08JHpWqvbkmXfnJUMvjCxuqB4NyzYuxlojaQhNAxgCmnEHmFaS6Kgn7RWWQfZxkU0e8GDn4TNUKa08Gyh6bd2s/pkThBuml0Z4fOz3elS/jY1RruAcml9GOZ6VC9xLqCeF5RUzy5hAcbivzpn8tMjiH1LjjD0+MOZkmVQHqFYtEjvoDzPOv71T0xFZASegLdjmrKCCX2EQDePGCZhJeRHvRHM9h8uppqsr4zgxuE7KGjrpSONYoa5P8ZNCSyWKpO0kDd+ePcTAig5Cy/78Zk44MzlOHvoXYC6OLkPbTNDhg+wcXC93VVCGOhfJI4xZglM7FxaK7XpJ/45yupGtKgn3v2WvvcKq9h5283PUW/Vq8VAT3m6d09BuPsNLBd4lST5yBzvMTXJe6XuTXugYFXn1H7YTJw9ylvfqxGYrfgpQ8/e2Uywux08h70s+hHMoNypNI0shOVPsXnc3kdaDFNt8Ze510Br1HNSVwTjRVIEG1pyvHohPvvca2QYJF96vW0IQ1K0reNdsZFaFMpkqUsEZepOLWKq5iBHaqIEflL LgRh0dzR TAAAIrTT3IFvZ+fBm22+sLZtu6X3egLlXtCh5lVhElAtAfT/1RUqS1GdG7aoDpwapZ0+kdA68kCwIAtsUHq3iTX42cq+RAQatNE2Z5ziOYqo3Y7qFmWsjLMEEMxY51R1/MH1DJ68jrTxULkAT4A71mN5+VDevSAjPTcJbwaC6iqp6LOohNbndZEIAeg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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.