Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6900394rdb; Tue, 2 Jan 2024 18:59:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqAXwql834pFdWx+A39P7UMV6yr2pdOZv3kwnmpTt5PuRGblqfKuuQLhRSNd4FxceG02yc X-Received: by 2002:a17:906:da05:b0:a26:6e93:491b with SMTP id fi5-20020a170906da0500b00a266e93491bmr8994528ejb.35.1704250790017; Tue, 02 Jan 2024 18:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704250790; cv=none; d=google.com; s=arc-20160816; b=yBihlV626Dd3qDe6U6BS98kuFoNwR0rDE9MLWb4YJAln/tksZ8zPWuc+0yAAUcXh+i iTZik7LrG9h1x5eU+nQGaS/5w4BQ14AI/FMlVoTdhU19/vMAUt2ksGhgFxu2gWy7l3b1 zLtnqkH6jkPVuKggZYGlb0n23s+9z5saqusbViZKkJXxkPrkd/MPV7I2o1tPBDJSDUen U4VMj//3HCihIdv9YgUvVk7IYNcgkdxoRZmdrwBfVQj20Xt5eTQcqvI8ABIVn7yYGJ3a RlJkpMz6SESuTelnL84htiwP4JT8305CzQqKxpQ6RfprH2W57SV2/OzOSWCOiuFWh6nS wqaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=78wPF0LpF+mCsihLbL7RxjqIwFhHSG0CJebLE27EJ7A=; fh=rfo2gk6/fb3sHvKUJNt0bPTwARcEmrgKm0Gc9JOKobg=; b=nxzplqqQW/Uclny4m+CSS/Fd+C4J7IvdBnTRpwWQwyIsGQAkB8f6QlK65C2/87MX2/ Cgp8ToH/mFSQ9C+nnXaionbHJkav3A5gFVY7c81ma0k0Dqd4Lw+c+ynUufNwWhmW/D6x LMDLA6SejvG2e35WLhyZdpuKxbM8K/XT82sT/8XrNA6+HNHTDce7pp/FVrCge06ybPEs PFf1bq1/uQAGwJYt4vX2bcnr4Bki8Xx+/EeY0nqzSmODFCbu/ouXZcAXFmyszQlQp6LV LTUNcfKFKbnfG8ZDogfjRcZ9E62tKJy6qgMTyL/+2dPf3kOchTd+5jNL44O1WMfJUhyU /X3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SWPbE308; spf=pass (google.com: domain of linux-kernel+bounces-15107-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15107-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id yr9-20020a170907334900b00a27e0f3d006si2443555ejb.646.2024.01.02.18.59.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 18:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15107-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SWPbE308; spf=pass (google.com: domain of linux-kernel+bounces-15107-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15107-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6E15E1F237AB for ; Wed, 3 Jan 2024 02:59:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A53F413AE5; Wed, 3 Jan 2024 02:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="SWPbE308" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 536C0171CA; Wed, 3 Jan 2024 02:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 4031rH8u024488; Wed, 3 Jan 2024 02:58:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=78wPF0LpF+mCsihLbL7RxjqIwFhHSG0CJebLE27EJ7A=; b=SW PbE308oFm1Ak4hQC8cEqwf2AhPJ80ppP7abzkSVekcxti4PSosah7eey0EEu/PEy yfWQJzsm/7tRl39xuUt4fsdh/Wo3x/exEZEI6U+qWAtMfKd1BD1KeE6yjnWwNnLe yPjSJ92bZB6O6pU8keh332ZEuT09Sr96A/C2Gz0CJZFMh1nI8zVSVohhJV/tbTaZ 4w0z5lwARisQ6isgho6xp9iGMbvO5u7aIJzjVaAuIekuop+B40GH3ZC9Qt8ZZ4RV ycrZcfXDbUKRH4MovRH6BfvOCwlSp6J889HDfshPaWcs2NisHTLKdiqTTzELHjos lmvfu/e6DlH7vJdim0GA== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vcgku9t91-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 03 Jan 2024 02:58:46 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 4032wj23031959 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 02:58:45 GMT Received: from [10.239.132.150] (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 2 Jan 2024 18:58:35 -0800 Message-ID: <99c44790-5f1b-4535-9858-c5e9c752159c@quicinc.com> Date: Wed, 3 Jan 2024 10:58:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Content-Language: en-US To: Matthew Wilcox CC: "Eric W. Biederman" , Hillf Danton , , , , , , , , , , , , , , , , , References: <20231213101745.4526-1-quic_aiquny@quicinc.com> <87o7eu7ybq.fsf@email.froward.int.ebiederm.org> From: "Aiqun Yu (Maria)" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 6nIpjVYtECWvlGZA32t55-3fW4z4m_OS X-Proofpoint-ORIG-GUID: 6nIpjVYtECWvlGZA32t55-3fW4z4m_OS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1011 phishscore=0 mlxlogscore=645 lowpriorityscore=0 priorityscore=1501 impostorscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401030023 On 1/2/2024 5:14 PM, Matthew Wilcox wrote: > On Tue, Jan 02, 2024 at 10:19:47AM +0800, Aiqun Yu (Maria) wrote: >> On 12/29/2023 6:20 AM, Matthew Wilcox wrote: >>> On Wed, Dec 13, 2023 at 12:27:05PM -0600, Eric W. Biederman wrote: >>>> 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. >>>> >>>> Yes. It seems to make sense to distinguish between write_lock_irq and >>>> write_lock_irqsave and fix this for all of write_lock_irq. >>> >>> I wasn't planning on doing anything here, but Hillf kind of pushed me into >>> it. I think it needs to be something like this. Compile tested only. >>> If it ends up getting used, >> Happy new year! > > Thank you! I know your new year is a few weeks away still ;-) Yeah, Chinese new year will come about 5 weeks later. :) > >>> -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. * this is the new state with _QW_WAITING set, lock->wait_lock locked, interrupt enabled. * 3. cpu0 in-interrupt context and want to do write_lock_irqsave. 4. cpu0 tried to acquire lock->wait_lock again. 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. > >> So needed to be done in release path. This is to address Hillf's concern on >> possibility of deadlock. > > Hillf's concern is invalid. > >>> /* When no more readers or writers, set the locked flag */ >>> do { >>> + if (irq) >>> + local_irq_enable(); >> I think write_lock_irqsave also needs to be take account. So >> loal_irq_save(flags) should be take into account here. > > If we did want to support the same kind of spinning with interrupts > enabled for write_lock_irqsave(), we'd want to pass the flags in > and do local_irq_restore(), but I don't know how we'd support > write_lock_irq() if we did that -- can we rely on passing in 0 for flags > meaning "reenable" on all architectures? And ~0 meaning "don't > reenable" on all architectures? What about for all write_lock_irq, pass the real flags from local_irq_save(flags) into the queued_write_lock_slowpath? Arch specific valid flags won't be !0 limited then. > > That all seems complicated, so I didn't do that. This is complicated. Also need test verify to ensure. More careful design more better. Fixed previous wrong email address. ^-^! > -- Thx and BRs, Aiqun(Maria) Yu