Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3833469rdb; Thu, 28 Dec 2023 01:07:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWw2VI64R7CQmWQdRqsmuHbPYEPteFvcxA0whhvCpT+hzkAeAKlf/9Km6DmUSCwMnmPMJQ X-Received: by 2002:a0d:e585:0:b0:5d7:3444:3fb2 with SMTP id o127-20020a0de585000000b005d734443fb2mr6524895ywe.65.1703754473171; Thu, 28 Dec 2023 01:07:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703754473; cv=none; d=google.com; s=arc-20160816; b=cj06X7uw7thC5wXSdrbTnDceF/2Tuv5eAAld1QDVNX0Kf0rnkGYIPVhCH+mvJZ6MFo HpfUxFihGPnyx1EGW1dzUccalnkR5AO2hICVppyYjDllNY8DflvzPUatx9Qf06kCirWN FwjONH9QFxkIYFnaOS7PY5kvRq07tPXHDkdCxLbQbvRSA6Obbp7bhdX9zXdf/42pRKLi nOv5Xdizta8nOkhVcGLJtw1rjn0HOj3Jkm1K/VmW0a76WJ8RDcQ9mnvFK1SIKGZUZ9Uu hsslETOQ3l45u5aopJ+Knkp5k/ZNeclBg8MXR5sn41xouDV9IJFw1iN7qJrqnUH94Xhm txIg== 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=Uqg6vQn+spXvmoZWu9//v883CUlzXLAEBegc3S1fc2o=; fh=3h5sTaBzGfo4zswZM2mAperOvf8LtWEEVurzkZ9rOA0=; b=Kxp78twdv5lDpfCfbTpzuqqiXCUHkntWcpvnpTYyEpNRpBBqul1kJrXGCCZWUNzL/N 6DkUeLkPvNUJogSgltuj11hUUdBfVYoI9rANwqiy81ZZHsOY0s5gJKemyzOzwRrof2Ch aBSgvHefdx5xBsnH2dEUx1E8wz8qux0CLtEA96vUnomZbpOD2x2UoZeVV3blGsle+hfM 82ds79exJEpKtjWJjRD+/RF6W3VDrRoH5Ph8TiAqSNFT8YI+i/mvymlVvtLSyKk5hMvS tFmvKzQEgce8W9AMGJSBwskFnGP547xZwOzlnjP69irmkCHxoacAttniV7xpnVVgpKfl xaJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iXRtuiXt; spf=pass (google.com: domain of linux-kernel+bounces-12529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12529-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q15-20020a0ce20f000000b0067f92936d78si14225658qvl.599.2023.12.28.01.07.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 01:07:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iXRtuiXt; spf=pass (google.com: domain of linux-kernel+bounces-12529-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12529-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C7A181C21C75 for ; Thu, 28 Dec 2023 09:07:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21FE363C6; Thu, 28 Dec 2023 09:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iXRtuiXt" 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 B85DA63A8 for ; Thu, 28 Dec 2023 09:07:43 +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=Uqg6vQn+spXvmoZWu9//v883CUlzXLAEBegc3S1fc2o=; b=iXRtuiXtAEEm9LUzL6aMPP8J+v UMenAwgG8TdvKET5HpB8OdG3FdgTBb5GG2l42J607TDq8zx7XqAe/IegBM1YaUh9nBrdUdp5kReW6 pEgCq0uEHqYqyDboGNxlH006q0pJT26KJTcZHOYD06xqp8JAwvMqoAtvEMheIsh0ZjwsWONk7Zb5H 9++hyH+Rs6+jjgLQuMUIN+YSSiktgRpplUkMeFQoqmAJbca8A581h4jpvX+FfSXR/LTwkpZ1jFyhU g9SnM0tUtVdwfl1sYD5Zsv+KgcIBTthnhl0BPKTZwHip/6xt/+17IxqlBpGXIQFs/tTPc+QXt+Qmy RRqGgQkQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rImMI-004YuM-KY; Thu, 28 Dec 2023 09:07:18 +0000 Date: Thu, 28 Dec 2023 09:07:18 +0000 From: Matthew Wilcox To: Hillf Danton Cc: "Eric W. Biederman" , Maria Yu , linux-kernel@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> <20231226104652.1491-1-hdanton@sina.com> <20231227110727.1546-1-hdanton@sina.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: <20231227110727.1546-1-hdanton@sina.com> On Wed, Dec 27, 2023 at 07:07:27PM +0800, Hillf Danton wrote: > Feel free to ignore the following leg works. > > /* Set the waiting flag to notify readers that a writer is pending */ > atomic_or(_QW_WAITING, &lock->cnts); > > enable irq; > > /* When no more readers or writers, set the locked flag */ > do { > cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING); > } while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)); > > int > atomic_cond_read_acquire(&lock->cnts, !(VAL & _QW_LOCKED)); > deadlock > disable irq; That would be a buggy implementation, and would not be what I was thinking. > Though the case below is safe, it looks not pretty but clumsy. > > /* Set the waiting flag to notify readers that a writer is pending */ > atomic_or(_QW_WAITING, &lock->cnts); > > /* When no more readers or writers, set the locked flag */ > do { > enable irq; > > cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING); > > disable irq; > > } while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)); Why do you think it looks clumsy? It's more or less what I was thinking. -void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock) +void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock, bool irq) ... do { + if (irq) + local_irq_enable(); cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING); + if (irq) + local_irq_disable(); } while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED));