Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1289986rdb; Fri, 16 Feb 2024 10:45:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0hwJBy4tfemAqoHDX0/9NrGf4Yk3kHKjRd/wX/GSjPC13Nb4OKakRk/XcC6Gulr55ttNlCXZkcU9v+YTS2DQXUi7pYWui33n+Fjb5Yw== X-Google-Smtp-Source: AGHT+IHSVGnRypQntEKoDtrLZqLIQ6HSzxclL3G0sdJM7gwMMXEC1TKRLHg5MCYLdu/Kr38nKNFC X-Received: by 2002:a81:91d5:0:b0:604:a3d3:fb68 with SMTP id i204-20020a8191d5000000b00604a3d3fb68mr5817089ywg.52.1708109156006; Fri, 16 Feb 2024 10:45:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708109155; cv=pass; d=google.com; s=arc-20160816; b=ABEv8XfpaVAwspk1iWInFjN4ut41o7P4sN0ftI6c8qI/GcHlk/pE1vrUiabvGj6Rkk Nxoi7afiL47/M7LzlKQUIa28suBPVBPTxS+5ak62lI+GhN990cyGODWxZt5mbzKfeT2w uyFcraPgGS40CWBlCD1qEmKI17juHA9Il4BnnBhRmvIibXaO7Kap/nKtZ557jt7jLp8u X2ivMuPEjttej3GC3ubsvEv1l3l41ihTZKep16oDo3Oegr9ui74vHziPQ9sSwf1l5hFb kbuU+5/PxZJDN+mGcZEQBZrCKpuhHhRdCAMUIR85hAtY7Gzgjp6M+toz078mKnw8XnG7 Lbbg== 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=+6/2b6cdY93cfhwg+wgl1iJpv6T7icr8cPzff5WRiiM=; fh=OGIcGdyoke6ohfCedcQQ3UJr3JDRxZcQDHVG7x10Yg0=; b=LtybuOgRoZ2TJsTxi5cAzH/iqXqLGDi0Oi33dLYef7yimUl+MHW235/mft1rv7+y9O JZKyxuJNiKN++FLXIxG0dUScu4oiHiJLT7xRS2BMt1jEL3yUz9OfCnFyOY/lMcUm22ZG Hs7Q3Yz6N8rmtopK4eyrG+tDlSRuAW0F8y+bi6YrZZBOr422emvHMrY+mhZDm9D0LAa9 BTO9hRZwdfxCkWj7/9A8Fj+hltgOETdAGv5TsIXn532Bq15JVJjuD02Z52z4wUTxP3dR nYynowD4hlcdSSEGZ12JqgFJ+gsaHO8inXwwgEX+ZbOS3x5CAAX+A9bgU6Hc03vUzNtK ezSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=DLxdkdtb; 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-69191-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s8-20020a05622a178800b0042db680d768si467205qtk.646.2024.02.16.10.45.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69191-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=@linux.dev header.s=key1 header.b=DLxdkdtb; 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-69191-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69191-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B2EEC1C22A97 for ; Fri, 16 Feb 2024 18:45:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60A0F1487D8; Fri, 16 Feb 2024 18:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DLxdkdtb" Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 02FEC146912 for ; Fri, 16 Feb 2024 18:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108947; cv=none; b=CHmiclOoAkWP923z5vcbSMwyrTR5syGmEPmfklcX5yZuGb5q9ZvlfxMo8rAchqilRAQ3bWwN3HgsvVquWLSGYLOWviAFaPTH/AeXJgGg8RJObmAB8ukkRAUWD4+4rZpAYyDwEj6XeeI1BMs27jBZwOLQUQMmgFlDzz8lJ1wNf94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108947; c=relaxed/simple; bh=YOt99fgiOeGafpp1nEhSIUqA34CgCiK6op8GicPElws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c6cL/+krNqC6ZHADvOpE+9t9GJwdBOllN0Ya0Yt+Lo9Zl0N9i8PX0P427XgVE6sPNMcUk0SD1+f/TFx6T5se5d25JxGbncLDgHuCIVXVr44iHl3WO8s8u8RPo4JuZ47kYAaz4VWNBUnWqtqelVz32ByeKkyCY64R4K1E3M6ToTo= 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=DLxdkdtb; arc=none smtp.client-ip=91.218.175.174 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=1708108944; 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=+6/2b6cdY93cfhwg+wgl1iJpv6T7icr8cPzff5WRiiM=; b=DLxdkdtbNwcuA4gLo4jd1yD05qIOD+omQNvakwfPpgTo6UMoTeIbl9XzhWZhJZwtRffA+j S6COGILK/oPKkNX85TmWz314nYUf1N7NFk3Rob9ONKeUXrHUuFrI9W4PpXWgZer+wkhrb/ NjTdniGek0pEoQhqcV0ARz6GeS0cHrQ= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , linux-kernel@vger.kernel.org, Oliver Upton Subject: [PATCH v3 10/10] KVM: arm64: vgic: Don't acquire the lpi_list_lock in vgic_put_irq() Date: Fri, 16 Feb 2024 18:41:53 +0000 Message-ID: <20240216184153.2714504-11-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT The LPI xarray's xa_lock is sufficient for synchronizing writers when freeing a given LPI. Furthermore, readers can only take a new reference on an IRQ if it was already nonzero. Stop taking the lpi_list_lock unnecessarily and get rid of __vgic_put_lpi_locked(). Signed-off-by: Oliver Upton --- arch/arm64/kvm/vgic/vgic-its.c | 4 ++-- arch/arm64/kvm/vgic/vgic.c | 21 ++++----------------- arch/arm64/kvm/vgic/vgic.h | 1 - 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index c3d1bca0b458..d84cb7618c59 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -647,7 +647,7 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its, * was in the cache, and increment it on the new interrupt. */ if (cte->irq) - __vgic_put_lpi_locked(kvm, cte->irq); + vgic_put_irq(kvm, cte->irq); /* * The irq refcount is guaranteed to be nonzero while holding the @@ -684,7 +684,7 @@ void vgic_its_invalidate_cache(struct kvm *kvm) if (!cte->irq) break; - __vgic_put_lpi_locked(kvm, cte->irq); + vgic_put_irq(kvm, cte->irq); cte->irq = NULL; } diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c index 2a288d6c0be7..c8208f81fdc8 100644 --- a/arch/arm64/kvm/vgic/vgic.c +++ b/arch/arm64/kvm/vgic/vgic.c @@ -110,13 +110,13 @@ static void vgic_irq_release(struct kref *ref) { } -/* - * Drop the refcount on the LPI. Must be called with lpi_list_lock held. - */ -void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq) +void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) { struct vgic_dist *dist = &kvm->arch.vgic; + if (irq->intid < VGIC_MIN_LPI) + return; + if (!kref_put(&irq->refcount, vgic_irq_release)) return; @@ -126,19 +126,6 @@ void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq) kfree_rcu(irq, rcu); } -void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) -{ - struct vgic_dist *dist = &kvm->arch.vgic; - unsigned long flags; - - if (irq->intid < VGIC_MIN_LPI) - return; - - raw_spin_lock_irqsave(&dist->lpi_list_lock, flags); - __vgic_put_lpi_locked(kvm, irq); - raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags); -} - void vgic_flush_pending_lpis(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h index f874b9932c5a..0c2b82de8fa3 100644 --- a/arch/arm64/kvm/vgic/vgic.h +++ b/arch/arm64/kvm/vgic/vgic.h @@ -180,7 +180,6 @@ vgic_get_mmio_region(struct kvm_vcpu *vcpu, struct vgic_io_device *iodev, gpa_t addr, int len); struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 intid); -void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq); void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq); bool vgic_get_phys_line_level(struct vgic_irq *irq); void vgic_irq_set_phys_pending(struct vgic_irq *irq, bool pending); -- 2.44.0.rc0.258.g7320e95886-goog