From patchwork Tue Feb 13 09:32:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 200293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp424808dyb; Tue, 13 Feb 2024 01:37:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW5a5SUAahU3mJb6crH7RgM0/pQO9hoTQQy0pC3LvsWZvjgKzqglBRMFCRawgBZDK9dSePRxzVO22FeiKz6Fuxxq5EYkQ== X-Google-Smtp-Source: AGHT+IGOozcAUPtGpy7uEzx6IBWv/B7VTDBXzNWXjaWcm5pH+MwQElh5OHX+kt4XbgsrKbRHoXzx X-Received: by 2002:a50:ee8b:0:b0:560:799:f802 with SMTP id f11-20020a50ee8b000000b005600799f802mr5456305edr.21.1707817064117; Tue, 13 Feb 2024 01:37:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707817064; cv=pass; d=google.com; s=arc-20160816; b=YNiY6PJnieEWusESPDFaAMhUxQvaZleFFusmRMVsWFNVnj8ZiQaLVYN3KtVTWCbACU sZCNrwLZWhOPPaGCg8VV5OEmSgjm7eA3kkvgLy5jb8wN4M6z/lRHqFO3+2h4n8XKGPoo K3qc07CCMdUvatMpdpKWbGoc0CclU2N+DsM0SNIZQwGmHJ9oForqGpGvW26l0zRmd1F4 xAx1jyPN6VF81K5YtK29Q6BEklnABdLlxEWjPuVwSpjj0OUG+j63JKYvj8e2odLd4KrA bNhpzT06+sNDjo5xTO0TfZosJMvIXLuWm+AdQynRQHuPPsbKrh2CwgF9oMlghZa8gxEW X/Gg== 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=/NKiyUPOAHZp+4seCuTeFdtHdSqB+Sryj+FB70LZ6SE=; fh=Cu0vbI7dT0j1msF8y22bJmmP2K9Hyp3x9Aq81evchps=; b=Wl6nopOLLPCN+a7CIRT2CgLKiUwhU6qa9zo4LJiHHVHmZ7lbCGzClrQz2fmjoHE5qr ga72eRKz2BHTwUI78hS2rDY3ktsuuE+VDBlpThL1GOaJmOgJ0EBPiFJpD0M1mX4RD7fx 5+xvGT0dfd0VEJNp6/uesGxmGzyyW98Vdvd0QhABqBw8TTxT6E0b2WOnpFbDjzijj33I +69bUbglthx66wmGaxE5fADA2Pz+eKf2CFkqk3jrT9Pd0oJ81d0OC/NfPZui18PCYX8o OYQEvIpZtMkFhsbUK4lmPEQDg+oGuQAPsUAn0JEpldeXwLgLBKFZMnFXrN/P952l1urW cRQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=m39rFo3b; 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-63216-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63216-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCVuj+Sw5HIWQrncyx+HO1LD92YCN/Gs6EM2RiXEAKvfwARQNB43ULjVM0E+9ANJK6Yxke9JeUs5G3hHDWodWMCaJW5bpQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i7-20020a05640242c700b00562003baaafsi228363edc.611.2024.02.13.01.37.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:37:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63216-ouuuleilei=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=@linux.dev header.s=key1 header.b=m39rFo3b; 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-63216-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63216-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 B74321F25582 for ; Tue, 13 Feb 2024 09:37:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 206914F88D; Tue, 13 Feb 2024 09:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="m39rFo3b" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 2EA9D487B6 for ; Tue, 13 Feb 2024 09:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816816; cv=none; b=bz854QMqMne67P48FemRx/txDZLmCoLc3rsLD0UM4NEu5Sf3s9S1Y6N3L8hHPLFqRlxRuxR3qq6Chq4mnRXqGq5CXanRENSYQzhP5N8JCugOVexatPMfhaQ0E8Rsg0Zd346xumoSmR/cZG+MonB6p3liI5DgSRhfJAYBbmMvEjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816816; c=relaxed/simple; bh=AMfprxM0/ut1EJb/0zCW90BuRmzW+XprxTWpT1Elo/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=afnPKU/osgFWl03695mo+7B/YxVh9ig/Io4FtlR2ksFxOdKxHJPhrsvnL+vqygBrCK6Druc6xhAmu7VO2zK+kjJw9fpLDuQDucMyRhAFLiqipSyHsVjvBheij9uCs6xGNiz2EHN2ggYKnpoSF6OpJOO5t1tyWxg4xpaE9l/79f8= 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=m39rFo3b; arc=none smtp.client-ip=95.215.58.176 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=1707816812; 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=/NKiyUPOAHZp+4seCuTeFdtHdSqB+Sryj+FB70LZ6SE=; b=m39rFo3bZXhcOOKgVqA1OtqG/2d1pFKH3ESY4PlhbvCQIcBN54j3NLFr67rLVEi8hX3kPX +q0pAZguXIU08yRGInEPzoZMrySX58rpD1cqqK0rjeppMroPaI6tLWSaEP3gEVq7FbS382 U6z1mj8LlFCVXClGb2NJU7VJE0DhZlw= 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 v2 11/23] KVM: arm64: vgic: Don't acquire the lpi_list_lock in vgic_put_irq() Date: Tue, 13 Feb 2024 09:32:48 +0000 Message-ID: <20240213093250.3960069-12-oliver.upton@linux.dev> In-Reply-To: <20240213093250.3960069-1-oliver.upton@linux.dev> References: <20240213093250.3960069-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 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790775986066906690 X-GMAIL-MSGID: 1790775986066906690 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 6b9634cec77f..50a9addebeed 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -650,7 +650,7 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its, if (cte->irq) { KVM_VM_TRACE_EVENT(kvm, vgic_its_trans_cache_victim, cte->db, cte->devid, cte->eventid, cte->irq->intid); - __vgic_put_lpi_locked(kvm, cte->irq); + vgic_put_irq(kvm, cte->irq); } /* @@ -688,7 +688,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);