From nobody Mon Nov 25 04:51:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717528025; cv=none; d=zohomail.com; s=zohoarc; b=fbCAePL5xHfRv5L19HeNs5zpb3dqNBBqQ6+8OsIzb9W3t6vOYGn7p635gvScDo81qsdI2ynyyP7dxOivCb9nbunFpT431w4tR2pjBfjA+tC+T37jAAKcfrv5tcoFqCt4UYJDId5/X1X5nWqRQs4J69PAcrEJnDpACkk4PBDZ/es= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717528025; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gfd+vfybB3O3+4pkXHRWr1BbxFsd2M2r8td4r0aSbjQ=; b=VkVXaP0CQIGx0w6scuQhuBPd6sxOS695DxxRZ+3vlgeCMz0/OsP6v+k2kbkR+SF68AfCmrpf6tSKgSBJXW/PT846/Ztm3q9zMDrKw4FeHczKMqy88dFgCGD5J0Rw5B3EVI5kswnNu1cHRlpGeY/K8HmylR+pJWYBIGr3giNypc4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717528025438222.6223050947566; Tue, 4 Jun 2024 12:07:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEZU5-0004xz-H7; Tue, 04 Jun 2024 15:06:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEZU2-0004xH-Us for qemu-devel@nongnu.org; Tue, 04 Jun 2024 15:06:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEZU1-0000gr-Am for qemu-devel@nongnu.org; Tue, 04 Jun 2024 15:06:10 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-hArG0UZaOTagcJQ8XjIjYg-1; Tue, 04 Jun 2024 15:06:07 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-35dca355ffaso3517561f8f.1 for ; Tue, 04 Jun 2024 12:06:07 -0700 (PDT) Received: from redhat.com ([2a0d:6fc7:552:cf5c:2b13:215c:b9df:f231]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35e7e07d7besm2777211f8f.18.2024.06.04.12.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 12:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717527968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gfd+vfybB3O3+4pkXHRWr1BbxFsd2M2r8td4r0aSbjQ=; b=GdHye96uTOtEpCtgGtHa1xVgQ1i7cSXRSSzdb22g475+UHNfO2u2RvySIHWHq799sd9iFA PO8B+lL2M7HBpRK2Vs1bsHYMMstXkfVZF4Vz3fmKlr9uIgZPBqRoLajpkSvBa7qwriG63l CtO+F9AcrzpxDwUAHG+wusAlxL9n+Qc= X-MC-Unique: hArG0UZaOTagcJQ8XjIjYg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717527965; x=1718132765; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gfd+vfybB3O3+4pkXHRWr1BbxFsd2M2r8td4r0aSbjQ=; b=UkdPE7RGMP4Vh/ZW7zd0ttra8G6T8eDeULppt7Hu9wKUwk97SHpWeJWJER/7REp2tr SEs08TcG6XERq+VUeRlWJwpbiJtgdboz2yketX+RCyEiuzWCfCyYLFNkYdMaRXnEUohQ cfj5vdnvNYEMQZdT6yH5dgvPFbGHfxcYi96kwoLCZLsgy6P1/4am54wCHFWdGic7vmD/ rkzCZ8BNHBnxX7tEjeZmDxbscB5NeHkefCSITKgRDSu5XqOEZ/nc3rnOslMMNo7jMIpD ybZh2AvA2YPHQay686CENtKsRdG04E2McrRKTkW+jnJZTFWfEdkcc97sZsMlD8771dm4 ZfxQ== X-Gm-Message-State: AOJu0YzU/4xnwbEKYKuPIM0bDamQmw/stCR3oRMcjrfps4Fm/LbEVwJI HZsdiuiWrLct5ReEjFOTUT55Q5dwpHDPUps6YgUIjj/4Jap3kHiZHe2JdOR8xyFwHnblPtqf4qB 8oL7OxXURQ1fZPV1+JcGXqf/dLyR50Qt6crhLjQdDvYhn8Db4qxJopbYkeIErzkHfzwMZXxIMvq rcfCsEIDzMnuZF8U/AZBPeen5qMUiT9A== X-Received: by 2002:a5d:4e8f:0:b0:35e:5b2a:1191 with SMTP id ffacd0b85a97d-35e840678f7mr230996f8f.18.1717527965345; Tue, 04 Jun 2024 12:06:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOlKd+Sx9HuvNacLdaJyPkWeq0f6MFm6oxM6nspWlljSJryAxVZnZo6ksCGJhsM0n5My5Ixg== X-Received: by 2002:a5d:4e8f:0:b0:35e:5b2a:1191 with SMTP id ffacd0b85a97d-35e840678f7mr230969f8f.18.1717527964668; Tue, 04 Jun 2024 12:06:04 -0700 (PDT) Date: Tue, 4 Jun 2024 15:06:01 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu Subject: [PULL 01/46] vhost: dirty log should be per backend type Message-ID: <0b7ca10a059089caef535e86c6523991240e5f29.1717527933.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717528025675100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Si-Wei Liu There could be a mix of both vhost-user and vhost-kernel clients in the same QEMU process, where separate vhost loggers for the specific vhost type have to be used. Make the vhost logger per backend type, and have them properly reference counted. Suggested-by: Michael S. Tsirkin Signed-off-by: Si-Wei Liu Message-Id: <1710448055-11709-1-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 4acd77e890..a1e8b79e1a 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -43,8 +43,8 @@ do { } while (0) #endif =20 -static struct vhost_log *vhost_log; -static struct vhost_log *vhost_log_shm; +static struct vhost_log *vhost_log[VHOST_BACKEND_TYPE_MAX]; +static struct vhost_log *vhost_log_shm[VHOST_BACKEND_TYPE_MAX]; =20 /* Memslots used by backends that support private memslots (without an fd)= . */ static unsigned int used_memslots; @@ -287,6 +287,10 @@ static int vhost_set_backend_type(struct vhost_dev *de= v, r =3D -1; } =20 + if (r =3D=3D 0) { + assert(dev->vhost_ops->backend_type =3D=3D backend_type); + } + return r; } =20 @@ -319,16 +323,22 @@ static struct vhost_log *vhost_log_alloc(uint64_t siz= e, bool share) return log; } =20 -static struct vhost_log *vhost_log_get(uint64_t size, bool share) +static struct vhost_log *vhost_log_get(VhostBackendType backend_type, + uint64_t size, bool share) { - struct vhost_log *log =3D share ? vhost_log_shm : vhost_log; + struct vhost_log *log; + + assert(backend_type > VHOST_BACKEND_TYPE_NONE); + assert(backend_type < VHOST_BACKEND_TYPE_MAX); + + log =3D share ? vhost_log_shm[backend_type] : vhost_log[backend_type]; =20 if (!log || log->size !=3D size) { log =3D vhost_log_alloc(size, share); if (share) { - vhost_log_shm =3D log; + vhost_log_shm[backend_type] =3D log; } else { - vhost_log =3D log; + vhost_log[backend_type] =3D log; } } else { ++log->refcnt; @@ -340,11 +350,20 @@ static struct vhost_log *vhost_log_get(uint64_t size,= bool share) static void vhost_log_put(struct vhost_dev *dev, bool sync) { struct vhost_log *log =3D dev->log; + VhostBackendType backend_type; =20 if (!log) { return; } =20 + assert(dev->vhost_ops); + backend_type =3D dev->vhost_ops->backend_type; + + if (backend_type =3D=3D VHOST_BACKEND_TYPE_NONE || + backend_type >=3D VHOST_BACKEND_TYPE_MAX) { + return; + } + --log->refcnt; if (log->refcnt =3D=3D 0) { /* Sync only the range covered by the old log */ @@ -352,13 +371,13 @@ static void vhost_log_put(struct vhost_dev *dev, bool= sync) vhost_log_sync_range(dev, 0, dev->log_size * VHOST_LOG_CHUNK -= 1); } =20 - if (vhost_log =3D=3D log) { + if (vhost_log[backend_type] =3D=3D log) { g_free(log->log); - vhost_log =3D NULL; - } else if (vhost_log_shm =3D=3D log) { + vhost_log[backend_type] =3D NULL; + } else if (vhost_log_shm[backend_type] =3D=3D log) { qemu_memfd_free(log->log, log->size * sizeof(*(log->log)), log->fd); - vhost_log_shm =3D NULL; + vhost_log_shm[backend_type] =3D NULL; } =20 g_free(log); @@ -376,7 +395,8 @@ static bool vhost_dev_log_is_shared(struct vhost_dev *d= ev) =20 static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t si= ze) { - struct vhost_log *log =3D vhost_log_get(size, vhost_dev_log_is_shared(= dev)); + struct vhost_log *log =3D vhost_log_get(dev->vhost_ops->backend_type, + size, vhost_dev_log_is_shared(de= v)); uint64_t log_base =3D (uintptr_t)log->log; int r; =20 @@ -2044,7 +2064,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) uint64_t log_base; =20 hdev->log_size =3D vhost_get_log_size(hdev); - hdev->log =3D vhost_log_get(hdev->log_size, + hdev->log =3D vhost_log_get(hdev->vhost_ops->backend_type, + hdev->log_size, vhost_dev_log_is_shared(hdev)); log_base =3D (uintptr_t)hdev->log->log; r =3D hdev->vhost_ops->vhost_set_log_base(hdev, --=20 MST