Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2159250rdb; Tue, 20 Feb 2024 21:11:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWUJff6IZj9ffFksETeJBCYMErcWWrEY4GNtbgDFnPAv/B4DISQrkQRxqJnfKaVeJLz80nzXt4Me8d8zTHei81LCjccmtgqToj5PjFOyg== X-Google-Smtp-Source: AGHT+IGntOMQL74wsVE+Ye+Og2inYD4plhbuygaX1QRQbbW0lLbkJavTcVc4KZFVWY2bugD+FUbE X-Received: by 2002:a05:622a:4b:b0:42e:1a:75f2 with SMTP id y11-20020a05622a004b00b0042e001a75f2mr11670199qtw.43.1708492289493; Tue, 20 Feb 2024 21:11:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708492289; cv=pass; d=google.com; s=arc-20160816; b=zT4y9NDelkESy46r2pFTXOkFF61SImn1W1el+IUYMp1NZKUi3vpnwoY3LplYgYiliX ljNCrVSYeRCUBuBuLnTvLmqnrPDSysHzksrmPn6ZNLaBM5e4EHykjPyoAM8a6POtk8b3 Zutm8XoM7KVhKlOopJgcrEyFG7TNYY8IzS++om9qUKFlsv2Ul99B78QUEkH83xa9hdJV qXBppNSgI8f+NWtq+3HtoEyVjmOh6L6urjdgXOSuUDWCtfozUAOuNXyhv1Hz27L7dWxn H8xo5fFf6FjPCjvvOcU975wducM9W/ufzgXQmF2Hu3vpa1o3TNMlQCnMOTHbWf1y/LC2 0sKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=gNjUe0ec0PbwZXCxnKG3Dj5DCZRUsI2QdgKQ33Ei/To=; fh=Y91vXH30kSg0GErwVuL7VOHxZ4fzvESpr/EuUSNUt4Y=; b=xjvdt0KqMEqHpm9VVJITjQM+36KVidVZSBq52gKEPjGmsg3yYFjMuRRf++NE3bmm3h z899YaSumTRcjr0mn7WxpEv5EdPp52y9rbF6B5+qG6N6HnenAlxQxWxHoGo3OmK6W+Qf k4zNtzzu/ebofyJaV1FGUp2U4Ui/WO6gk5b/znWMMsRPJZT8/4ShrazQiwJ/T6vF4GPc 5Nw6pDd+n8Hr7w6iodX/UxrF9VhDUzspzDy180C2H/UPTPxOgKxMJzwbioT5ClDWX98z handlCi2lTDLNnQuFXjL1QYqZgmpcAIW8OssF9MCA3LuB3K222r63n9svF+K/ZeCY9fr BCNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-74059-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74059-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c39-20020a05620a26a700b00785da4b0aefsi11854086qkp.776.2024.02.20.21.11.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 21:11:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74059-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; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-74059-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74059-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 278601C22564 for ; Wed, 21 Feb 2024 05:11:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3161D39FD7; Wed, 21 Feb 2024 05:11:11 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 1C49339AEA; Wed, 21 Feb 2024 05:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708492270; cv=none; b=aOra4cCuLyL1+Qzn2klzvGDSgX2dKd6YF2LQ1OOaf2fhvtXi36Xiv/iQ/FhzEFRhCz6cgDsJTh6/l2nbLOlVBnspO2Eff+YJh2jjlylZlC9kcXTnDLB2ixvDb+LnPyHRlIxhuAJBW1Q7nV5ODzWRhsADSehgTvZJ6cLs71+GbRY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708492270; c=relaxed/simple; bh=C8vIAvgGnmc3tyaLFs7slFsNmar/kQJlvJ3tLWIOELA=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=ssmqIG+xG4L9EPQJ+GBXgGc0WURc2iv6Pmuz6xGh6KpivmS9KPEk5Em0p+bE5F2lgnPWk+nTNvUn3iXGPD6f+zeE4UtSdrLnetvR6fyycqUmMNB385FM4EKtK2k0YE5iUCDev0qHfu3iaGzhd2P4nlrW34Fv+M+uxCCIDSoyMFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Tfknz6g6Xz2Bd0f; Wed, 21 Feb 2024 13:08:55 +0800 (CST) Received: from kwepemm600007.china.huawei.com (unknown [7.193.23.208]) by mail.maildlp.com (Postfix) with ESMTPS id 9233C18005F; Wed, 21 Feb 2024 13:11:04 +0800 (CST) Received: from [10.174.185.179] (10.174.185.179) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 21 Feb 2024 13:11:03 +0800 Subject: Re: [PATCH v3 01/10] KVM: arm64: vgic: Store LPIs in an xarray To: Oliver Upton CC: Zenghui Yu , , , Marc Zyngier , James Morse , Suzuki K Poulose , References: <20240216184153.2714504-1-oliver.upton@linux.dev> <20240216184153.2714504-2-oliver.upton@linux.dev> From: Zenghui Yu Message-ID: <8c3e4679-08e7-c2bd-2fa4-c6851d080208@huawei.com> Date: Wed, 21 Feb 2024 13:11:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600007.china.huawei.com (7.193.23.208) On 2024/2/21 1:15, Oliver Upton wrote: > Hi Zenghui, > > On Wed, Feb 21, 2024 at 12:30:24AM +0800, Zenghui Yu wrote: >> On 2024/2/17 02:41, Oliver Upton wrote: >>> Using a linked-list for LPIs is less than ideal as it of course requires >>> iterative searches to find a particular entry. An xarray is a better >>> data structure for this use case, as it provides faster searches and can >>> still handle a potentially sparse range of INTID allocations. >>> >>> Start by storing LPIs in an xarray, punting usage of the xarray to a >>> subsequent change. >>> >>> Signed-off-by: Oliver Upton >> >> [..] >> >>> diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c >>> index db2a95762b1b..c126014f8395 100644 >>> --- a/arch/arm64/kvm/vgic/vgic.c >>> +++ b/arch/arm64/kvm/vgic/vgic.c >>> @@ -131,6 +131,7 @@ void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq) >>> return; >>> list_del(&irq->lpi_list); >>> + xa_erase(&dist->lpi_xa, irq->intid); >> >> We can get here *after* grabbing the vgic_cpu->ap_list_lock (e.g., >> vgic_flush_pending_lpis()/vgic_put_irq()). And as according to vGIC's >> "Locking order", we should disable interrupts before taking the xa_lock >> in xa_erase() and we would otherwise see bad things like deadlock.. > > Nice catch! > > Yeah, the general intention was to disable interrupts outside of the > xa_lock, however: > >> It's not a problem before patch #10, where we drop the lpi_list_lock and >> start taking the xa_lock with interrupts enabled. Consider switching to >> use xa_erase_irq() instead? > > I don't think this change is safe until #10, as the implied xa_unlock_irq() > would re-enable interrupts before the lpi_list_lock is dropped. Or do I > have wires crossed? No, you're right. My intention was to fix it in patch #10. And as you've both pointed out, using xa_erase_irq() can hardly be the correct fix. My mistake :-( . Thanks, Zenghui