Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3303041rdb; Wed, 27 Dec 2023 03:10:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUE6bzaa16sDelcN04cEC/xrPvFpLGFbabWk+6m3r5mvHAQs9MnoBf6sb9Rhl1FLswRn0x X-Received: by 2002:a9d:7e82:0:b0:6d9:dfa5:1c8d with SMTP id m2-20020a9d7e82000000b006d9dfa51c8dmr4147386otp.47.1703675425700; Wed, 27 Dec 2023 03:10:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703675425; cv=none; d=google.com; s=arc-20160816; b=z0jnEjegsdTw5e7KbvPvIIG2hNjF0a8GNQv6GZwLKamChNI3/JUlFfDvZD4nhGX7qn nQ8zY2bOaRqmvwG0RE0DtOu8AASIQaHOjmI0jfpjqd4AHSjluOEBTfBZCxPo4v3iTWjn LhcJ+eqw090/fXcj9Irk7eYIr4lbS09u4au+IkKS0B1j5vF+S2k2Lf6CE2QmxdIEY8TZ IyDnzr/v2bZZ/647ZqztO11cyJOK80bdXm6hS77jECUBCZEIV6gvbRFVgW10lel66/TA qnB64nyh2Q/w5hnpIUgfMxB6YAz6Xql6I9ZmkZPIQdC4h5hour1zTDVgJNNKmlbbIFrS ohFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=CJF11wj2W3xuzaJ5OX1kv+MLugSxKAfh9cSDK60cTdE=; fh=GFKx5GS5Z21R0JSv0nN/feUTam2fh3EFp7QMjERW6uc=; b=R+pO2X/htmIQgmBoG7QDz8+eZXfug6k+uAI+qbDxojoMtmb64hMS+iWfk3/OzSSzZJ LF2GEMHkaew/3anSbptVE+k1C6FG74JOp3rhHiqCVQtp3+ZABImZzT0yenR6V2rkl+vo Uq/aYI2SHdWHxJBYrRfIi2Ad1dqaxEUWDNmqwWh+sHAsEnmGSo2kl1cLptbURpNVt2w5 WSTCFrbVgCigfWsJiFtDUNcbK/LQcfBW+W6zjqej2Qa3nbIbbuAuZPjdww7OmwdtCz0v z7+gz7Vzd3e1VNTQdAluR+oInPS03255eOshd6JlfVW3X8ceuuqnPhNqfIio3ouex2rJ rmdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11983-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j11-20020ac85f8b000000b00427eef11426si737837qta.654.2023.12.27.03.10.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 03:10:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11983-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11983-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 6E7E21C2241A for ; Wed, 27 Dec 2023 11:10:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97376446A4; Wed, 27 Dec 2023 11:10:19 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail115-24.sinamail.sina.com.cn (mail115-24.sinamail.sina.com.cn [218.30.115.24]) (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 F3F2B44370 for ; Wed, 27 Dec 2023 11:10:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([113.88.49.138]) by sina.com (10.75.12.45) with ESMTP id 658C057900006A4D; Wed, 27 Dec 2023 19:07:40 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=hdanton@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=hdanton@sina.com X-SMAIL-MID: 19226231457834 X-SMAIL-UIID: 4A2157A538B04E3C8B67991E9A073358-20231227-190740-1 From: Hillf Danton To: Matthew Wilcox Cc: "Eric W. Biederman" , Maria Yu , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Date: Wed, 27 Dec 2023 19:07:27 +0800 Message-Id: <20231227110727.1546-1-hdanton@sina.com> In-Reply-To: References: <20231213101745.4526-1-quic_aiquny@quicinc.com> <20231226104652.1491-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-Transfer-Encoding: 8bit On Tue, 26 Dec 2023 20:49:38 +0000 Matthew Wilcox > On Tue, Dec 26, 2023 at 06:46:52PM +0800, Hillf Danton wrote: > > On Wed, 13 Dec 2023 12:27:05 -0600 Eric W. Biederman > > > Matthew Wilcox writes: > > > > I think the right way to fix this is to pass a boolean flag to > > > > queued_write_lock_slowpath() to let it know whether it can re-enable > > > > interrupts while checking whether _QW_WAITING is set. > > > > lock(&lock->wait_lock) > > enable irq > > int > > lock(&lock->wait_lock) > > > > You are adding chance for recursive locking. > > Did you bother to read queued_read_lock_slowpath() before writing this email? Nope but it matters nothing in this case. > > if (unlikely(in_interrupt())) { > /* > * Readers in interrupt context will get the lock immediately > * if the writer is just waiting (not holding the lock yet), > * so spin with ACQUIRE semantics until the lock is available > * without waiting in the queue. > */ > atomic_cond_read_acquire(&lock->cnts, !(VAL & _QW_LOCKED)); > return; This is the lock acquirer for read in irq context, and it rolls out the red carpet for write acquirer in irq, right Willy? 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; 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));