Message ID | 20240216184153.2714504-5-oliver.upton@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-69185-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp713097dyb; Fri, 16 Feb 2024 10:44:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWlpzGvP+kzMDyg5o03WnvIXbtTHiavFXu16NRFcPfr51D9ZhoY0TbBEXH4pKIxkoT3HcyDeUcPtPFR0w09bH87Lw7yLQ== X-Google-Smtp-Source: AGHT+IEminWlm8cUuUpV7zwUHAIzINBWbkRbLZY726dSOExPbCkxv3Y/AOf94gxl9Y6u8JhxnpVH X-Received: by 2002:a05:6402:602:b0:564:1035:b0 with SMTP id n2-20020a056402060200b00564103500b0mr539004edv.18.1708109048721; Fri, 16 Feb 2024 10:44:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708109048; cv=pass; d=google.com; s=arc-20160816; b=KJj3EAbjHVgwzpi8MHN/nX5BHLi3vULkV3FMJdRAhyoh8zlQvdCDuE9Q7E9HZ7u39l ms0OQZXPXYFU4bqzeCcuOEKAAtl2F63ElOKCVqgF7q4UXAm/FdefmbAxGmQ4cP1Moeys 2y8lDVqj46cF0EVzWDVoSSoMCyXlJQw2vRk154sNmKBdGhANsK3VY+tJE+agfqi+rXgT AyihYGw7w4zH/OjaSmzUlaBb0L6/uo2PDrGMT2k2HUAEbekhnW64is5H0NWaUz6YUZNh R8WYKnd9WlxjFwVI3BdsXRsns2mk31kkedD7p1DEHrVwq9Ghq8F8N682P5OeDftlNlnD oFrA== ARC-Message-Signature: i=2; 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:dkim-signature; bh=ZQGaJWYKQGMmTnU81XUm3LbLxD/nkGmlez2wBi9FY5g=; fh=OGIcGdyoke6ohfCedcQQ3UJr3JDRxZcQDHVG7x10Yg0=; b=yVJ3l/QgGpBu6Z/+to63E2e4qYqAVNfOcXTyaO+7T47QIzEz+jl0rQs0Q36b6sxkIF p1HcXrwD/mnIG2/OR8IQoPV3/oCZnHJ2TCFOk9/RD5zJiT7sVBGiEyaRH6jqCd4qKLTV r7PvLWESkiamEZEXhrilqdKmecEIeMFx/DdfTwl2Gp+uHNElE+y9o6q7x381culORnYi vMzDJrYXYH5FMpXOwVGBdSBP/hYvJbIksdG/gwwq2+0r7l2Ludgjhu/cg68Y6HIWl6SS zblLa6Sdf8/03oD67kmP99Eil/+mPMbigM+Lt9Nsjsea9ueaPcs4TBXyDL2p++4xMosF gaEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=n1FUOVlE; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-69185-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69185-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bd21-20020a056402207500b00563ab30ab84si191724edb.85.2024.02.16.10.44.08 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:44:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69185-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=n1FUOVlE; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-69185-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69185-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 550A51F22212 for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 18:44:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 786A7145FFD; Fri, 16 Feb 2024 18:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="n1FUOVlE" Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 18B5F139573; Fri, 16 Feb 2024 18:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108936; cv=none; b=sb+lKRfkaGhNwhD6Ou8wfjWe2aZVMGr4LY+qk9Z3a6ZiOC2Mg/TBb3qFbyB2FN3lZKPl20JXJS7ZMZ3+dOgr7rbVS7T6V4zRN2ysBapYzWyNAEGFvwQtDaD0WbVBKYPupHeKFUEC8sK/3SnJWmbApkPOzC0T3SrO3Hms0FL/4oQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108936; c=relaxed/simple; bh=kWOvmd79TSBa85yZMhQxLashdvnOQitPJm7fzCmDhgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNtqmsL5ZEwoKFeBZB5I2rhDGOhnucNWd/Z3W2ugC4D/4eyGOfbOuBQdzXCYmCmhVZ++Tkkr0tFhgNLi9VP25ELnjgjURtu0aJvsjYCKoc0YudtXMfOhKW+Ss0bHPWPeMYekcrfptr4pvKdIel/ojUeL1AZkunaptMaxJ1Oiuhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=n1FUOVlE; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708108933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZQGaJWYKQGMmTnU81XUm3LbLxD/nkGmlez2wBi9FY5g=; b=n1FUOVlE36G2VVZcvP+dqcFaQP/pVkYnqUcaLYGdtm9/lxWqLZYHUlFvWZz/JpQPNCRJP6 1wTx7GgFkHB6w/xSy6Ht/4/qxBloxyYg8mhMIejHWFi/xDFcNVBqjzuUqKKH/EJ2liryZJ wRYPIDA1qMmkaeagAY7w1JT56E90o40= From: Oliver Upton <oliver.upton@linux.dev> To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Zenghui Yu <yuzenghui@huawei.com>, linux-kernel@vger.kernel.org, Oliver Upton <oliver.upton@linux.dev> Subject: [PATCH v3 04/10] KVM: arm64: vgic-its: Walk the LPI xarray in vgic_copy_lpi_list() Date: Fri, 16 Feb 2024 18:41:47 +0000 Message-ID: <20240216184153.2714504-5-oliver.upton@linux.dev> In-Reply-To: <20240216184153.2714504-1-oliver.upton@linux.dev> References: <20240216184153.2714504-1-oliver.upton@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791082153768720388 X-GMAIL-MSGID: 1791082153768720388 |
Series |
KVM: arm64: Avoid serializing LPI get() / put()
|
|
Commit Message
Oliver Upton
Feb. 16, 2024, 6:41 p.m. UTC
Start iterating the LPI xarray in anticipation of removing the LPI
linked-list.
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
arch/arm64/kvm/vgic/vgic-its.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On 2024/2/17 2:41, Oliver Upton wrote: > Start iterating the LPI xarray in anticipation of removing the LPI > linked-list. > > Signed-off-by: Oliver Upton <oliver.upton@linux.dev> > --- > arch/arm64/kvm/vgic/vgic-its.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c > index fb2d3c356984..9ce2edfadd11 100644 > --- a/arch/arm64/kvm/vgic/vgic-its.c > +++ b/arch/arm64/kvm/vgic/vgic-its.c > @@ -335,6 +335,7 @@ static int update_lpi_config(struct kvm *kvm, struct vgic_irq *irq, > int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > { > struct vgic_dist *dist = &kvm->arch.vgic; > + XA_STATE(xas, &dist->lpi_xa, GIC_LPI_OFFSET); > struct vgic_irq *irq; > unsigned long flags; > u32 *intids; > @@ -353,7 +354,9 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > return -ENOMEM; > > raw_spin_lock_irqsave(&dist->lpi_list_lock, flags); > - list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { > + rcu_read_lock(); > + > + xas_for_each(&xas, irq, INTERRUPT_ID_BITS_ITS) { We should use '1 << INTERRUPT_ID_BITS_ITS - 1' to represent the maximum LPI interrupt ID. > if (i == irq_count) > break; > /* We don't need to "get" the IRQ, as we hold the list lock. */ > @@ -361,6 +364,8 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > continue; > intids[i++] = irq->intid; > } > + > + rcu_read_unlock(); > raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags); > > *intid_ptr = intids; Thanks, Zenghui
On Sun, 18 Feb 2024 08:46:53 +0000, Zenghui Yu <yuzenghui@huawei.com> wrote: > > On 2024/2/17 2:41, Oliver Upton wrote: > > Start iterating the LPI xarray in anticipation of removing the LPI > > linked-list. > > > > Signed-off-by: Oliver Upton <oliver.upton@linux.dev> > > --- > > arch/arm64/kvm/vgic/vgic-its.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c > > index fb2d3c356984..9ce2edfadd11 100644 > > --- a/arch/arm64/kvm/vgic/vgic-its.c > > +++ b/arch/arm64/kvm/vgic/vgic-its.c > > @@ -335,6 +335,7 @@ static int update_lpi_config(struct kvm *kvm, struct vgic_irq *irq, > > int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > > { > > struct vgic_dist *dist = &kvm->arch.vgic; > > + XA_STATE(xas, &dist->lpi_xa, GIC_LPI_OFFSET); > > struct vgic_irq *irq; > > unsigned long flags; > > u32 *intids; > > @@ -353,7 +354,9 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > > return -ENOMEM; > > raw_spin_lock_irqsave(&dist->lpi_list_lock, flags); > > - list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { > > + rcu_read_lock(); > > + > > + xas_for_each(&xas, irq, INTERRUPT_ID_BITS_ITS) { > > We should use '1 << INTERRUPT_ID_BITS_ITS - 1' to represent the maximum > LPI interrupt ID. Huh, well caught! I'm not even sure how it works, as that's way smaller than the start of the walk (8192). Probably doesn't. An alternative would be to use max_lpis_propbaser(), but I'm not sure we always have a valid PROPBASER value set when we start using this function. Worth investigating though. Thanks, M.
On Sun, Feb 18, 2024 at 10:28:19AM +0000, Marc Zyngier wrote: > On Sun, 18 Feb 2024 08:46:53 +0000, > Zenghui Yu <yuzenghui@huawei.com> wrote: > > > > On 2024/2/17 2:41, Oliver Upton wrote: > > > Start iterating the LPI xarray in anticipation of removing the LPI > > > linked-list. > > > > > > Signed-off-by: Oliver Upton <oliver.upton@linux.dev> > > > --- > > > arch/arm64/kvm/vgic/vgic-its.c | 7 ++++++- > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c > > > index fb2d3c356984..9ce2edfadd11 100644 > > > --- a/arch/arm64/kvm/vgic/vgic-its.c > > > +++ b/arch/arm64/kvm/vgic/vgic-its.c > > > @@ -335,6 +335,7 @@ static int update_lpi_config(struct kvm *kvm, struct vgic_irq *irq, > > > int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > > > { > > > struct vgic_dist *dist = &kvm->arch.vgic; > > > + XA_STATE(xas, &dist->lpi_xa, GIC_LPI_OFFSET); > > > struct vgic_irq *irq; > > > unsigned long flags; > > > u32 *intids; > > > @@ -353,7 +354,9 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) > > > return -ENOMEM; > > > raw_spin_lock_irqsave(&dist->lpi_list_lock, flags); > > > - list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { > > > + rcu_read_lock(); > > > + > > > + xas_for_each(&xas, irq, INTERRUPT_ID_BITS_ITS) { > > > > We should use '1 << INTERRUPT_ID_BITS_ITS - 1' to represent the maximum > > LPI interrupt ID. /facepalm Thanks Zenghui! > Huh, well caught! I'm not even sure how it works, as that's way > smaller than the start of the walk (8192). Probably doesn't. > > An alternative would be to use max_lpis_propbaser(), but I'm not sure > we always have a valid PROPBASER value set when we start using this > function. Worth investigating though. Given the plans to eventually replace this with xarray marks, I'd vote for doing the lazy thing and deciding this at compile time. I can squash this in when I apply the series if the rest of it isn't offensive, otherwise respin with the change.
diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index fb2d3c356984..9ce2edfadd11 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -335,6 +335,7 @@ static int update_lpi_config(struct kvm *kvm, struct vgic_irq *irq, int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) { struct vgic_dist *dist = &kvm->arch.vgic; + XA_STATE(xas, &dist->lpi_xa, GIC_LPI_OFFSET); struct vgic_irq *irq; unsigned long flags; u32 *intids; @@ -353,7 +354,9 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) return -ENOMEM; raw_spin_lock_irqsave(&dist->lpi_list_lock, flags); - list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { + rcu_read_lock(); + + xas_for_each(&xas, irq, INTERRUPT_ID_BITS_ITS) { if (i == irq_count) break; /* We don't need to "get" the IRQ, as we hold the list lock. */ @@ -361,6 +364,8 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) continue; intids[i++] = irq->intid; } + + rcu_read_unlock(); raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags); *intid_ptr = intids;