Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp886910lqc; Fri, 8 Mar 2024 15:07:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVcbu+zzd9GvE8Li7snUkNtNq1jzSgXJ6vPLQRuSsYalnLbMlwveeQzRWeA5XKJTPnZUDP29nG5CYUx4laBWscSPg9ALZbHlAHhm730hQ== X-Google-Smtp-Source: AGHT+IEfbQI5VONRyScqmhTsJ1UgbFDgBhFhMJ/cjcKrsN8bOKPQr3pJf8+HRZEaCyYcJn6J1K5S X-Received: by 2002:a05:6a20:12cb:b0:1a1:66cf:b0ef with SMTP id v11-20020a056a2012cb00b001a166cfb0efmr140795pzg.49.1709939228672; Fri, 08 Mar 2024 15:07:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709939228; cv=pass; d=google.com; s=arc-20160816; b=gZ9P1TnGBOKaJLbSHXBCadjquEczF32pExQF5i6grPDrtVgZeoyWkHw5esqaERJfuq tp5Sy2kre/4b4G8UYcRluDfjdckcnMnqdQsy/+FSB/CQNif8j+pRyEmxvVCbBOPHGafq 2Ni3RZeeoxgppzGLawWDT4SOvWEcfjZ+SXpjI6OP2jrHAVLSg9Bap/JeW4GpRtvJduvK sYYSX7bAqJpjPyB5zeHDYYOTFAcxi1bxzz3FpbsOj1aSmVTs8i6etUrbgVmHDDuIYsR1 fFQ1nBNaCc2QiiQ2alwyxqVU28MeZFzrPSSUJW7JqJxdFPVGGgHCjkIC2Md5YDYAfs6T tfqw== 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=eXn3Gg6N1f84hEIo4OgYVMjxq/BUaA1ykSSynr+HxW0=; fh=MHJMY1O5a4FZClgQgDgk5IZb0BNqewtXeQgzD9Gumuk=; b=yi6wl5yrkVs0VF0xi6RWsjtVOs307hleafk0mh41E6mYk3/TPmTjFeh7jlSI28d+vH TUtUBWgsycUTsZasM8E5RMqT7EK2BJ1W4+Vpx3hzfxXxVuDvfgIZYrzstg9QpmOEb1i5 EMsAe0ohhrklYRebuwMogKIYODOdml7qzFzc6VUmiAOS+wwxjjWMo0OKG8H9tBQWcbem 1gSqx3eQ6pYBFqovUbSwI7+NasmcBj6Nw22hDmMJsYQX8AsYcp3IEuxjtrl7CLrvVCln v34S82DR6HUliNNZm6vVAZnPpZcIvniYGsrNia36qHFtyHq6J2U0ZY3k3G0jqS3bWYAf /b6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TVTXhvwy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-97678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n12-20020a170903110c00b001dd6524161fsi310657plh.552.2024.03.08.15.07.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 15:07:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TVTXhvwy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-97678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 58619282DF4 for ; Fri, 8 Mar 2024 23:07:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 30AD0495CB; Fri, 8 Mar 2024 23:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TVTXhvwy" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 967B53E480 for ; Fri, 8 Mar 2024 23:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709939175; cv=none; b=o9j3RPIy6T2ONL1A1BYu1oH1v9UzQ7FvbGYBbLzvI9wAzWVSnTVndatd/SALX+A6fmwLksJlD7B/52rgxH11mK5uvwHhDRUZqxUCgTgFi+CGzBUePdfwFTc6IZcwFHdoe7572GQ2cdFZNDlyrLgPPVfXukmXXCCLD82xAUA8rsM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709939175; c=relaxed/simple; bh=k+R2VROY6vUH5PdEi8jgrtrsikXwjab0c1hYvgZZfOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yn/dtcPI0sDAXLhK1YI8qVy6xwPQdd6pHd/Zj3kgNY7pPhK9EBLcJWkQc2gXMJO/LfihM6Ben4Qj6gvyDzz8+vCLCCgmTUcPT9AN9cbCbc0HX4nb0mjyoYHRPGjBq89zJxQM3/ai4n2WCzIXygcoJjaZB22MKjX5zGt/8TZdvd4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TVTXhvwy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709939172; 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=eXn3Gg6N1f84hEIo4OgYVMjxq/BUaA1ykSSynr+HxW0=; b=TVTXhvwyBdK7MOP3GubiPjihk4R11TTKBhDTY1Fsp3FZEpZOeG6NFFw3o6fCAnfGegPqNV EtR3+CxRyb4DQH6PgJkW1wd9v515uKT/U3sWBg15Yqi3OCVFvB10fN/x3Pq4PritkKCMTf ph3UmvFZUk9U51hd0aeHRG2g0F4fAYY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-BEWV8FfbPm64jqF_xRnC2A-1; Fri, 08 Mar 2024 18:06:09 -0500 X-MC-Unique: BEWV8FfbPm64jqF_xRnC2A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E230C86D4C1; Fri, 8 Mar 2024 23:06:08 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.8.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E861547CB; Fri, 8 Mar 2024 23:06:07 +0000 (UTC) From: Alex Williamson To: alex.williamson@redhat.com Cc: kvm@vger.kernel.org, eric.auger@redhat.com, clg@redhat.com, reinette.chatre@intel.com, linux-kernel@vger.kernel.org, kevin.tian@intel.com Subject: [PATCH v2 3/7] vfio: Introduce interface to flush virqfd inject workqueue Date: Fri, 8 Mar 2024 16:05:24 -0700 Message-ID: <20240308230557.805580-4-alex.williamson@redhat.com> In-Reply-To: <20240308230557.805580-1-alex.williamson@redhat.com> References: <20240308230557.805580-1-alex.williamson@redhat.com> 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-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 In order to synchronize changes that can affect the thread callback, introduce an interface to force a flush of the inject workqueue. The irqfd pointer is only valid under spinlock, but the workqueue cannot be flushed under spinlock. Therefore the flush work for the irqfd is queued under spinlock. The vfio_irqfd_cleanup_wq workqueue is re-used for queuing this work such that flushing the workqueue is also ordered relative to shutdown. Reviewed-by: Kevin Tian Reviewed-by: Reinette Chatre Signed-off-by: Alex Williamson --- drivers/vfio/virqfd.c | 21 +++++++++++++++++++++ include/linux/vfio.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/drivers/vfio/virqfd.c b/drivers/vfio/virqfd.c index 29c564b7a6e1..532269133801 100644 --- a/drivers/vfio/virqfd.c +++ b/drivers/vfio/virqfd.c @@ -101,6 +101,13 @@ static void virqfd_inject(struct work_struct *work) virqfd->thread(virqfd->opaque, virqfd->data); } +static void virqfd_flush_inject(struct work_struct *work) +{ + struct virqfd *virqfd = container_of(work, struct virqfd, flush_inject); + + flush_work(&virqfd->inject); +} + int vfio_virqfd_enable(void *opaque, int (*handler)(void *, void *), void (*thread)(void *, void *), @@ -124,6 +131,7 @@ int vfio_virqfd_enable(void *opaque, INIT_WORK(&virqfd->shutdown, virqfd_shutdown); INIT_WORK(&virqfd->inject, virqfd_inject); + INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject); irqfd = fdget(fd); if (!irqfd.file) { @@ -213,3 +221,16 @@ void vfio_virqfd_disable(struct virqfd **pvirqfd) flush_workqueue(vfio_irqfd_cleanup_wq); } EXPORT_SYMBOL_GPL(vfio_virqfd_disable); + +void vfio_virqfd_flush_thread(struct virqfd **pvirqfd) +{ + unsigned long flags; + + spin_lock_irqsave(&virqfd_lock, flags); + if (*pvirqfd && (*pvirqfd)->thread) + queue_work(vfio_irqfd_cleanup_wq, &(*pvirqfd)->flush_inject); + spin_unlock_irqrestore(&virqfd_lock, flags); + + flush_workqueue(vfio_irqfd_cleanup_wq); +} +EXPORT_SYMBOL_GPL(vfio_virqfd_flush_thread); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 89b265bc6ec3..8b1a29820409 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -356,6 +356,7 @@ struct virqfd { wait_queue_entry_t wait; poll_table pt; struct work_struct shutdown; + struct work_struct flush_inject; struct virqfd **pvirqfd; }; @@ -363,5 +364,6 @@ int vfio_virqfd_enable(void *opaque, int (*handler)(void *, void *), void (*thread)(void *, void *), void *data, struct virqfd **pvirqfd, int fd); void vfio_virqfd_disable(struct virqfd **pvirqfd); +void vfio_virqfd_flush_thread(struct virqfd **pvirqfd); #endif /* VFIO_H */ -- 2.44.0