From patchwork Wed Jun 12 13:01:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I65DlcJE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzmDV4DpKz20Wd for ; Wed, 12 Jun 2024 23:12:42 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNcN-0003Pt-84; Wed, 12 Jun 2024 09:02:23 -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 1sHNcH-0003E9-0i for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNcC-00081J-OO for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197328; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eYivD0Oj8DZaeGa3x1w3lr0EcGpbXryh/Rf51uyXwz4=; b=I65DlcJETzLir7+clst40ZMnfg2cU4df8ZddcsK6u1MjcbxgYq181MsFUi8GB7Rz7zfz03 LxzGN3hjs2DfTB3qkA3VVxxEof0fPPqryASSv/3VPI7SCqd42MjyX9F21y1fgJUV9rXkom kR29MNVuCipL7HMUlUTYDpLfgnevsC0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-jsxu35nMMYmewaa1_-fouA-1; Wed, 12 Jun 2024 09:02:06 -0400 X-MC-Unique: jsxu35nMMYmewaa1_-fouA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7955f448a2dso318725585a.0 for ; Wed, 12 Jun 2024 06:02:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197326; x=1718802126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eYivD0Oj8DZaeGa3x1w3lr0EcGpbXryh/Rf51uyXwz4=; b=IthXSICLH4SmHGKM2wo23cJoVT3qE1gU67cst2UN8OpzI4a87XQ7EcHDeqR0onAwD/ FMlgs66egces+CzqFJdBrzTk1gj3Pbq2WxFkjCcwyoZ9sJ23/n7IRp/gr0Wg8zCMoiKU Jekgo3xVFuxk9Yf6ME2cG9OkagtsWJ0S+Mf5Hju3XOeVeevuzL8iZbChCxcndSmEKRVD 4YdjOz0hEdaVhaeabZHtk8D84TKIZMLnzvkfq/qtaeP1JM8HNWaLqGC+rxkH3aDB3F1u 7y40lyxOyPzDmooebHBGu1EzQPKPyOewFtWAU66oL3aCQi8CxlTwL48ZX7xSHYNvVpUi T90w== X-Forwarded-Encrypted: i=1; AJvYcCUEOm0zIKVS+Elu3M68XSUMF/HDi4KAHzR7Sr79cSEKYSFtbz0qbPoj3m4rlkETbjyOwehhgMCurRhMSs4jhgM9X95c54Y= X-Gm-Message-State: AOJu0Yxor2nxJ1N7RoTLMLU8zf7HbUF1jISJZKJUivK0FtMiPxotkAX5 B1hJRDTYp6CSnfYJfUZIpuQVBhZp2TZQxvufHjrx9fcmycVPjBimbOFLg5CV0LgzWcjtVqvUOT5 QyxXrgXeLE/tj7hFFht1TBlU0HMBsJm+NWgxGUOpNEodMbhVLolH9 X-Received: by 2002:a05:6214:448e:b0:6ae:116b:ef6a with SMTP id 6a1803df08f44-6b1a7ebb170mr17694556d6.60.1718197325604; Wed, 12 Jun 2024 06:02:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRitwQKscCqag0PsLNFeOtfDq3MX8L34TOG54quvOa1DAibTb69ENOFsIyuxrR3KqtkY8ySQ== X-Received: by 2002:a05:6214:448e:b0:6ae:116b:ef6a with SMTP id 6a1803df08f44-6b1a7ebb170mr17694036d6.60.1718197325178; Wed, 12 Jun 2024 06:02:05 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b04f69adeasm67464446d6.44.2024.06.12.06.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:00 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 01/12] libvhost-user: set msg.msg_control to NULL when it is empty Date: Wed, 12 Jun 2024 15:01:29 +0200 Message-ID: <20240612130140.63004-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On some OS (e.g. macOS) sendmsg() returns -1 (errno EINVAL) if the `struct msghdr` has the field `msg_controllen` set to 0, but `msg_control` is not NULL. Reviewed-by: Eric Blake Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a879149fef..22bea0c775 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -632,6 +632,7 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) memcpy(CMSG_DATA(cmsg), vmsg->fds, fdsize); } else { msg.msg_controllen = 0; + msg.msg_control = NULL; } do { From patchwork Wed Jun 12 13:01:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946853 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g/Jjp/MU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm1Y75gCz20Pb for ; Wed, 12 Jun 2024 23:03:13 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNcP-0003Td-U9; Wed, 12 Jun 2024 09:02:25 -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 1sHNcN-0003RE-HM for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNcL-00082k-TQ for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197341; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Su7ClX2VsFIEko0OXJVvgHI4Li50SabFJTO7o/P9fMs=; b=g/Jjp/MUT9cmEymAuu1oTMstFVioDCArQ905CPOg/xCIWPiVO4kqfop+5hIe5DWU/a4O0p cLd5+EPPM/qZQQEYc5MpIeUZBoH8sVkETse+Eqp6cuLMCt+M8lp7cI/8yTTD+qy91vp5OQ +JU47zf5fn94goL6XumAL+q80qvNoUE= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-otdwcqrwNoeLinQ4Gj14OA-1; Wed, 12 Jun 2024 09:02:19 -0400 X-MC-Unique: otdwcqrwNoeLinQ4Gj14OA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4406476507cso20626791cf.3 for ; Wed, 12 Jun 2024 06:02:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197339; x=1718802139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Su7ClX2VsFIEko0OXJVvgHI4Li50SabFJTO7o/P9fMs=; b=UB6PqWib4hJuOVuxNe1wEWEPVe8u8w0iu4Oqr26OBAC3IUr33md37MF496kg+Rd7P+ IUvSzHG/+ETlxN/IyJWnHyoWx+DAfiRBLmbdgskdQPt1Lb7vRMA/Vj63ICf31NG7gmw7 ZRy07zPv1GskjSmpaYrWhyZFxMFRQkAcEiXq5GLf7o506cFVb6klN6O5V145lqTsD34a bp539VWUVTEp4oMQPAecbTCxYWt8i2F7RpFAIqk1ct0CmMEqfXnUmuqnSyWM2mituwE3 aMTtfiiLXLQiYjB42gbGXICKpwhHdm4ShHNKOTHPgHTutEiKb9ioUELTKgFLWJBTkRVa KBGA== X-Forwarded-Encrypted: i=1; AJvYcCVfZnz/Gk9fImFCbbZcLWB4U6bYWPq4BpWJ3y8Qb79qks268l3kokhySLvNFMxpfqULPW+7+2uabWLtEZx/ILFOCgovBrc= X-Gm-Message-State: AOJu0YwFaGqMp4YWVtf/zmKTkjbnSWIwhZvnmFgGCd5ODD66GN+rUpDG gUy0qMF3QgZH8ZPfAcGZRsn7sHRKxY+aPHuIIsImu8y1PgW108AaooNvmWUYZmL3lbszZv6ozS0 LL9f7qJU1jES6R0/17arvAvlyg9027wPTOUwWaaVZadTdgs00WAyC X-Received: by 2002:a05:6214:3291:b0:6b0:8b40:c7e0 with SMTP id 6a1803df08f44-6b1a731b7d6mr18097986d6.44.1718197338850; Wed, 12 Jun 2024 06:02:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEderl/MfePzFiHQ2ncxEuElJrm+4BKYlXdhuE/JLFmI8+4UqTQNNgTmOVLm1w6aUl87AC0UQ== X-Received: by 2002:a05:6214:3291:b0:6b0:8b40:c7e0 with SMTP id 6a1803df08f44-6b1a731b7d6mr18097576d6.44.1718197338326; Wed, 12 Jun 2024 06:02:18 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b07a727eb8sm33527016d6.9.2024.06.12.06.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:16 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 02/12] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Wed, 12 Jun 2024 15:01:30 +0200 Message-ID: <20240612130140.63004-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In vu_message_write() we use sendmsg() to send the message header, then a write() to send the payload. If sendmsg() fails we should avoid sending the payload, since we were unable to send the header. Discovered before fixing the issue with the previous patch, where sendmsg() failed on macOS due to wrong parameters, but the frontend still sent the payload which the backend incorrectly interpreted as a wrong header. Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 22bea0c775..a11afd1960 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -639,6 +639,11 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) rc = sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc <= 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) { From patchwork Wed Jun 12 13:01:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZTWZXThC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm3Z2g1Cz20Pb for ; Wed, 12 Jun 2024 23:04:58 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNcg-0004Ly-UI; Wed, 12 Jun 2024 09:02:42 -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 1sHNca-0004Ac-Dd for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNcY-00083H-U3 for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197354; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lCSYM/hkoNpk10raw3aulgVh0FcgzvIKh+wFjcoj8Zs=; b=ZTWZXThCX5gnEnzpb5s+hccsFbytTf+/abWe5zmWZaaB/7u8bLhbybfZa6gKXIPby3qyNv qtS/LaVc0nJvxvNr/D4Yt5zNJ9/PmrHpvT5Qd7g7OkndrY00thWG9KIiGhUoW4JYkvLu/s j6bpiQ+W22yFgtHk1tWKIdjWgt4rHEY= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-471-D9tDz7aCO96wnUHxmQZJIQ-1; Wed, 12 Jun 2024 09:02:33 -0400 X-MC-Unique: D9tDz7aCO96wnUHxmQZJIQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7955f8b4bcfso247153185a.3 for ; Wed, 12 Jun 2024 06:02:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197350; x=1718802150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lCSYM/hkoNpk10raw3aulgVh0FcgzvIKh+wFjcoj8Zs=; b=PLp9K2CUpu7zpvzLt96q+0Vja5EX/aW+1IoGyqmtwbYjmeZkiigKwbQpsyYObOoykM bKMALLljWwyDlmk49SYkeV511cnPb7pgd95JyoV27/ohwzW8C2lvfd5U6hJM8QrLG0+x Rep2F70QG1S+nUg9FzRJlCHOAALlKkz7HOWg09V5EpRRo6Cq3K41JLZl8ISY4IixvoED HcXlzj8xkegpQmu1tsZz24OhdXpuBqbP+O/0f2S/L/9WnR716P10xBsGcXUbttxe00ze RkPZs9KanpnKh55rfaFmYH/NzO4/meQ1pAgOztSp+NF9tHbmhASs3+KVKWHF94SwwlFk vLJg== X-Forwarded-Encrypted: i=1; AJvYcCUoSJ5gzxxKsWGqrVr2bon42zd5tUD27IkfBPHquaS0Qd/MsI9zBWDMTpUZ6BLFbTudIL/QpZW+Y6y5OmGHrECQJASoR9Q= X-Gm-Message-State: AOJu0YzNR3qxK9gD6674wWDZ3n8dGCT23Vo7b2OkOB24slb3NrfwWRp/ VwsM2Q4TYJm+cM74dVwOU/X64HHacHIkSGO1T4C/K0LW/3+2uYYYHUa1ZBBJ+jN2GpBm6/KTCWN glta4sa/1do4cKdVPONpkURIkLzSkJlNa//NRDAXR/mv3v2g/3I3x3YE9AOcR X-Received: by 2002:a05:620a:468c:b0:795:5ad1:a218 with SMTP id af79cd13be357-797f6037e2cmr175909185a.17.1718197350385; Wed, 12 Jun 2024 06:02:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsSt0RZcRr9OnR/vocJe+Xf951H24BU/vf4cjqFxivopk9gMGwG0l+M54Y6TKmUFpaT1EfIw== X-Received: by 2002:a05:620a:468c:b0:795:5ad1:a218 with SMTP id af79cd13be357-797f6037e2cmr175904785a.17.1718197349908; Wed, 12 Jun 2024 06:02:29 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7978863766dsm233919685a.5.2024.06.12.06.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:27 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 03/12] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Wed, 12 Jun 2024 15:01:31 +0200 Message-ID: <20240612130140.63004-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org libvhost-user will panic when receiving VHOST_USER_GET_INFLIGHT_FD message if MFD_ALLOW_SEALING is not defined, since it's not able to create a memfd. VHOST_USER_GET_INFLIGHT_FD is used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is negotiated. So, let's mask that feature if the backend is not able to properly handle these messages. Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a11afd1960..2c20cdc16e 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1674,6 +1674,17 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) features |= dev->iface->get_protocol_features(dev); } +#ifndef MFD_ALLOW_SEALING + /* + * If MFD_ALLOW_SEALING is not defined, we are not able to handle + * VHOST_USER_GET_INFLIGHT_FD messages, since we can't create a memfd. + * Those messages are used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD + * is negotiated. A device implementation can enable it, so let's mask + * it to avoid a runtime panic. + */ + features &= ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); +#endif + vmsg_set_reply_u64(vmsg, features); return true; } From patchwork Wed Jun 12 13:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=C36yp+Pn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm6R18Pbz20KL for ; Wed, 12 Jun 2024 23:07:27 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNcl-0004z9-Hw; Wed, 12 Jun 2024 09:02:47 -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 1sHNcj-0004oV-To for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:45 -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 1sHNci-00085L-Ap for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:02:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197363; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=C36yp+PngYLGI6xRkp5rEyOE8wq6Mzw9O/l8gJ1ijZ2iBMY+9Su7rlnj5o4j86uUcIGKau 68Z2Wn44rEIMv66ons+0vz5MkP4Ke8itpNNF+9zqNArQ66mXIcIOL9HFSudGzBMMj6qFS7 8SpzqWDYF/Yr0ztIx+o+KcPp8CHGqOQ= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-CBramQ5bNLKYikemXjWDvg-1; Wed, 12 Jun 2024 09:02:42 -0400 X-MC-Unique: CBramQ5bNLKYikemXjWDvg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7955f8b4bcfso247174785a.3 for ; Wed, 12 Jun 2024 06:02:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197361; x=1718802161; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=B5TWH9rF72l1iK1fDNu5LDPUmJ1NqgSNm0Nf0S1AD/bWkojMC4yRIIYn19A21+L1D1 pkeB53jTocN6Ql/kqCuqLxMgm4tJrM+pZ3XC/dOHRRPWYKN63df6rs29vvSkpf+hjJ98 nqQ9mQKKQTcce1illJUyLeJ+eZX43Ziq3DeMXiwEm4C/H4ENKbriYV+p5EOpQntsc1Tc 2dG70gkg+Ylx+JQHjKt0Az+d2ncRKoBgaeiIXH6WD3b6wU7JLBEHGx8IqcUY9Yekl/bj qOpO77K71b4/LetxoyubHrGHFETXfmVQ/F5T1qkqErAIR4o1rCQD4orUW271Po76OsNp Tljg== X-Forwarded-Encrypted: i=1; AJvYcCXYGB7vumvkH5RFQBefoWl1a2PZxOyklnlEHclwH9W4Nz3vZw7vOnMPCiqxRIm4gPyDk1NM8P4lveK5NQhv2/jL8i8y604= X-Gm-Message-State: AOJu0Yyomteqw8VTS5qeZak19DFUbjOveU2UxzWs1KvL8qbtdMGrxfdu PyJXXzW0dmSsjhjjx42FTbEyu7V/c9umsw+GI88rfn63i6l+VUe+dLf5PbnRzySQPOZzDjp9tP8 UDa6vCcxzPsF8C+pXyunkwmvp2SS14DH8jk0OoRlxc5wQVeiTO+p7 X-Received: by 2002:a05:620a:258b:b0:795:5d6f:8bbd with SMTP id af79cd13be357-797f613d22emr202984985a.73.1718197361323; Wed, 12 Jun 2024 06:02:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHpTjWc/xjAx6/et7Wama94T4aqW8tZbAGLUMl7jPrJ5idIez/XUss2R4MdT1ntNwZU9N9xA== X-Received: by 2002:a05:620a:258b:b0:795:5d6f:8bbd with SMTP id af79cd13be357-797f613d22emr202980385a.73.1718197360870; Wed, 12 Jun 2024 06:02:40 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79532813a4fsm599132885a.13.2024.06.12.06.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:39 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 04/12] vhost-user-server: do not set memory fd non-blocking Date: Wed, 12 Jun 2024 15:01:32 +0200 Message-ID: <20240612130140.63004-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In vhost-user-server we set all fd received from the other peer in non-blocking mode. For some of them (e.g. memfd, shm_open, etc.) it's not really needed, because we don't use these fd with blocking operations, but only to map memory. In addition, in some systems this operation can fail (e.g. in macOS setting an fd returned by shm_open() non-blocking fails with errno = ENOTTY). So, let's avoid setting fd non-blocking for those messages that we know carry memory fd (e.g. VHOST_USER_ADD_MEM_REG, VHOST_USER_SET_MEM_TABLE). Reviewed-by: Daniel P. Berrangé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- v3: - avoiding setting fd non-blocking for messages where we have memory fd (Eric) --- util/vhost-user-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 3bfb1ad3ec..b19229074a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -65,6 +65,18 @@ static void vmsg_close_fds(VhostUserMsg *vmsg) static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; + + /* + * These messages carry fd used to map memory, not to send/receive messages, + * so this operation is useless. In addition, in some systems this + * operation can fail (e.g. in macOS setting an fd returned by shm_open() + * non-blocking fails with errno = ENOTTY) + */ + if (vmsg->request == VHOST_USER_ADD_MEM_REG || + vmsg->request == VHOST_USER_SET_MEM_TABLE) { + return; + } + for (i = 0; i < vmsg->fd_num; i++) { qemu_socket_set_nonblock(vmsg->fds[i]); } From patchwork Wed Jun 12 13:01:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L6QH9wy3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm8x5wf0z20KL for ; Wed, 12 Jun 2024 23:09:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNd3-00062r-M8; Wed, 12 Jun 2024 09:03:05 -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 1sHNd1-00062K-Un for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:03 -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 1sHNcz-0008Bk-07 for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197380; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Iv4GZfjfSmrbe9mbetH0GZZLouN4MvBd3gnn16kx+E=; b=L6QH9wy3hBUZZgA/mTT43HafJJoioMVcEbqMXU8I5MDChVYMA9CtAZQay3TGVIZL3Q4NJZ Ut4q3Jmdzpy6/zMFnDX9ENJQXcTK+TYarYRc3+2/95CTkKIiFVC/WN8+VfaZBsduelkn/S yPslW5zX7i+9/Qw9lwl+S1YD18nXPFE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-190-PY2O2vAVMRWMaHoite9i5g-1; Wed, 12 Jun 2024 09:02:59 -0400 X-MC-Unique: PY2O2vAVMRWMaHoite9i5g-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4405b0b5720so41552751cf.0 for ; Wed, 12 Jun 2024 06:02:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197378; x=1718802178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Iv4GZfjfSmrbe9mbetH0GZZLouN4MvBd3gnn16kx+E=; b=UmFJOUivccJ0DVN3I1egO3F66/fJELfnCBY1Ku0xbO2MejIRDdS4u2qod/V61lQ8Zg WT8j4Tz6CAz4udBViTruPUiqqvxGdhHckgPPo3H8CTMweIBcY8gHPQwkBrqAndIx2f+T +EjwOlQyvh9Lub4y3TFM3qbgbNbsKZUPEHHpFwX/w4ILE28VQifteQYNaU8IlCrZZNyQ g8CXKDMCp07fkKguk/jPJAodl09DPoOj9nBzIQhk2ZfFKf0anhSAZHhMKgBIlEGtcDWG JnaSzyJFx1aOEGWbmUMdh6lU9bUmpSiAHFY0Kyoa+WSlcT945zq0XIRMPghSMzTQa88j uJvg== X-Forwarded-Encrypted: i=1; AJvYcCVZ0bT5ZKor6BKsxR8FjrwU/0yYTDQcwNBsQHPFyjUml0FWtjJ+8KPa/kCBU7SnKBhLgPd3s2SRDhO30/h0l0AwlAaPVbY= X-Gm-Message-State: AOJu0YzrRAZrosktTKHOG746TNLw0ZUKu+gevOczWaxjx6kZelbZrAyV TpPFLSTfaY9GyR0Wos74g6obQnSEmlXzD5ScpANTexuYMLFLAIR8CALt9vaIaEDvy6hTABWfJae n3OEVP4HHdMaR8WSJRF000WWsTUW+dOX4YE5xht0ybTgJtDrUD0nS X-Received: by 2002:a05:622a:1105:b0:440:384a:2dd2 with SMTP id d75a77b69052e-4415abf7c7amr22329591cf.30.1718197373377; Wed, 12 Jun 2024 06:02:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvcv33Lq5iBdUj6iY5q3QyxaG/S+PFcfONjZLUF8jxPkPzL9CRBGfgN1zxblg+VOzACo35gw== X-Received: by 2002:a05:622a:1105:b0:440:384a:2dd2 with SMTP id d75a77b69052e-4415abf7c7amr22328941cf.30.1718197372832; Wed, 12 Jun 2024 06:02:52 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44057ffdbcbsm39647481cf.79.2024.06.12.06.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:50 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 05/12] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Wed, 12 Jun 2024 15:01:33 +0200 Message-ID: <20240612130140.63004-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On macOS passing `-s /tmp/vhost.socket` parameter to the vhost-user-blk application, the bind was done on `/tmp/vhost.socke` pathname, missing the last character. This sounds like one of the portability problems described in the unix(7) manpage: Pathname sockets When binding a socket to a pathname, a few rules should be observed for maximum portability and ease of coding: • The pathname in sun_path should be null-terminated. • The length of the pathname, including the terminating null byte, should not exceed the size of sun_path. • The addrlen argument that describes the enclosing sockaddr_un structure should have a value of at least: offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)+1 or, more simply, addrlen can be specified as sizeof(struct sockaddr_un). So let's follow the last advice and simplify the code as well. Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- contrib/vhost-user-blk/vhost-user-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 89e5f11a64..a8ab9269a2 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -469,7 +469,6 @@ static int unix_sock_new(char *unix_fn) { int sock; struct sockaddr_un un; - size_t len; assert(unix_fn); @@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn) un.sun_family = AF_UNIX; (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); - len = sizeof(un.sun_family) + strlen(un.sun_path); (void)unlink(unix_fn); - if (bind(sock, (struct sockaddr *)&un, len) < 0) { + if (bind(sock, (struct sockaddr *)&un, sizeof(un)) < 0) { perror("bind"); goto fail; } From patchwork Wed Jun 12 13:01:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dlJRHFi4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm3y6kQ7z20KL for ; Wed, 12 Jun 2024 23:05:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNdF-0006bz-1L; Wed, 12 Jun 2024 09:03:17 -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 1sHNdD-0006ZX-Kp for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:15 -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 1sHNdB-0008DO-Nn for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197393; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+P1PLaujH+XkcZwoLm4xtgpPOnPZM5w6BOv7shY81Ks=; b=dlJRHFi4PwQDKHh1wj1dZ8K7Yepa6abUjTQQBpn+FXPFTkRqm9ViU1U7yWOwzBGl3JYTVq SpiRoTTbB7JU9tcuV+mqVAAksyAHW86SEvw0UX6iuuFl9oq1CPT/0Co66DzD/wZf7DeyZQ NDCwfxG2+KDweimEznMGvoCFSByfaJ4= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-yNSQfBPXOoySzWD0c4DGBQ-1; Wed, 12 Jun 2024 09:03:11 -0400 X-MC-Unique: yNSQfBPXOoySzWD0c4DGBQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-797d167a402so139558185a.2 for ; Wed, 12 Jun 2024 06:03:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197386; x=1718802186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+P1PLaujH+XkcZwoLm4xtgpPOnPZM5w6BOv7shY81Ks=; b=rYSlMgdxiVpN6TQ01+eAyInXFQiQgA3SvtZA0Q1dutM4stn0XFmRsyx1hpvaXdEQX2 uKnADIolTkAu0qT8J8WVsSA80kTTXdkOWj8M68gr1M+8w2ubt7c0Q51HKYPyvBulGBhP i/tS09xRRqZiyBs55aobEt3dwIgift8jtSEr/OrTA65CQt/7ddW2tM5MWuCYmCG5fJG5 s2ynNTbBUl0H94Q5+PYfVyiD2H/52aIUROQSUOF0ib/5uVuJqeR+a8YncKSMAhAcha0M xIi0ruXjNPL1ZJVSt3Wg5T0AMdcYNQPR0iZpuj2nvY/NKddcnw6dN1d+9K17UvJPvhSv A0rg== X-Forwarded-Encrypted: i=1; AJvYcCUdY6ruVQHkvxJzxaFanLFJN8Hk8/ksvPTnRdifNoAEd7d8dD+YdZtXvJQbUx3sd7bvuTOO8rLHKotO9tJMMRNdJmW5yXo= X-Gm-Message-State: AOJu0YwOVx1dymV/eYD6DCWW386Giq+WRITnPsLrctdAXi3v4X9HDW6/ +HUM2M5KVaikN1GPqyaxotxCncK5qo5FX6sOMXDFZ+Ab+E9STbMkYZBl6Nrn3/s3yKGEVtLwErd PI93z5twNS/rksyygkubNBM6e1l/hgng9mLGWroC1Ky/SPo4BYCUy X-Received: by 2002:a05:620a:4711:b0:795:59bb:ccbe with SMTP id af79cd13be357-797f619ff77mr162367585a.74.1718197386458; Wed, 12 Jun 2024 06:03:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLD2u3eQYKzlnXhr9Nz7KnLuuGj97fZ/pn3bFDAc6ScjutUXxhDusL43WzAmCbpU00xc9iiw== X-Received: by 2002:a05:620a:4711:b0:795:59bb:ccbe with SMTP id af79cd13be357-797f619ff77mr162364485a.74.1718197386080; Wed, 12 Jun 2024 06:03:06 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-795518c1ff5sm416653485a.70.2024.06.12.06.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:03:04 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 06/12] contrib/vhost-user-*: use QEMU bswap helper functions Date: Wed, 12 Jun 2024 15:01:34 +0200 Message-ID: <20240612130140.63004-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Let's replace the calls to le*toh() and htole*() with qemu/bswap.h helpers to make the code more portable. Suggested-by: Philippe Mathieu-Daudé Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- contrib/vhost-user-blk/vhost-user-blk.c | 9 +++++---- contrib/vhost-user-input/main.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index a8ab9269a2..9492146855 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -16,6 +16,7 @@ */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" @@ -194,8 +195,8 @@ vub_discard_write_zeroes(VubReq *req, struct iovec *iov, uint32_t iovcnt, #if defined(__linux__) && defined(BLKDISCARD) && defined(BLKZEROOUT) VubDev *vdev_blk = req->vdev_blk; desc = buf; - uint64_t range[2] = { le64toh(desc->sector) << 9, - le32toh(desc->num_sectors) << 9 }; + uint64_t range[2] = { le64_to_cpu(desc->sector) << 9, + le32_to_cpu(desc->num_sectors) << 9 }; if (type == VIRTIO_BLK_T_DISCARD) { if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) == 0) { g_free(buf); @@ -267,13 +268,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk, req->in = (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_base; in_num--; - type = le32toh(req->out->type); + type = le32_to_cpu(req->out->type); switch (type & ~VIRTIO_BLK_T_BARRIER) { case VIRTIO_BLK_T_IN: case VIRTIO_BLK_T_OUT: { ssize_t ret = 0; bool is_write = type & VIRTIO_BLK_T_OUT; - req->sector_num = le64toh(req->out->sector); + req->sector_num = le64_to_cpu(req->out->sector); if (is_write) { ret = vub_writev(req, &elem->out_sg[1], out_num); } else { diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c index 081230da54..f3362d41ac 100644 --- a/contrib/vhost-user-input/main.c +++ b/contrib/vhost-user-input/main.c @@ -51,8 +51,8 @@ static void vi_input_send(VuInput *vi, struct virtio_input_event *event) vi->queue[vi->qindex++].event = *event; /* ... until we see a report sync ... */ - if (event->type != htole16(EV_SYN) || - event->code != htole16(SYN_REPORT)) { + if (event->type != cpu_to_le16(EV_SYN) || + event->code != cpu_to_le16(SYN_REPORT)) { return; } @@ -103,9 +103,9 @@ vi_evdev_watch(VuDev *dev, int condition, void *data) g_debug("input %d %d %d", evdev.type, evdev.code, evdev.value); - virtio.type = htole16(evdev.type); - virtio.code = htole16(evdev.code); - virtio.value = htole32(evdev.value); + virtio.type = cpu_to_le16(evdev.type); + virtio.code = cpu_to_le16(evdev.code); + virtio.value = cpu_to_le32(evdev.value); vi_input_send(vi, &virtio); } } @@ -124,9 +124,9 @@ static void vi_handle_status(VuInput *vi, virtio_input_event *event) evdev.input_event_sec = tval.tv_sec; evdev.input_event_usec = tval.tv_usec; - evdev.type = le16toh(event->type); - evdev.code = le16toh(event->code); - evdev.value = le32toh(event->value); + evdev.type = le16_to_cpu(event->type); + evdev.code = le16_to_cpu(event->code); + evdev.value = le32_to_cpu(event->value); rc = write(vi->evdevfd, &evdev, sizeof(evdev)); if (rc == -1) { From patchwork Wed Jun 12 13:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946895 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IMHSQGsR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzmBb4xKxz20Wd for ; Wed, 12 Jun 2024 23:11:03 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNdP-0006lb-Gb; Wed, 12 Jun 2024 09:03:27 -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 1sHNdN-0006kT-UP for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNdM-0008ER-BU for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197403; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W9nNY1euX5/uZx9rZmDV5gA5I22VILqEg+kz3/RnvbQ=; b=IMHSQGsRYQUMPysNYgjB3BYAjNf/p+jCQr89GV/1ZjEjhVFz+JvdkZCjCEzoqDJOno1vNB ADM6EtpOf7cNk8Cb6A8C+yJmd8nI/+ZC9h31GFT2cnd5HL5IS7pkhUM3dI4PlhZE45YcsX HzJKzOi4SRiY30n10bHf3YZpP/cHBa4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-0H2dSwAcMIaUN0o7OE7q_A-1; Wed, 12 Jun 2024 09:03:21 -0400 X-MC-Unique: 0H2dSwAcMIaUN0o7OE7q_A-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-795d19c522eso326860185a.1 for ; Wed, 12 Jun 2024 06:03:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197401; x=1718802201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W9nNY1euX5/uZx9rZmDV5gA5I22VILqEg+kz3/RnvbQ=; b=I42ryJ00RaHdnG0wtNJ84mcgGMqkkJLtKeVLuFZLoMztVVJ13wkj2n2//IQIlxqc2N nFSrbnn31C2q4E6LRKRG7bdJ7b5cDgEDgP0K/QuA61vUrLo38BubefT4w7iSmdsw1cey +3ASTApgIHhRXGHo1CKnHRO2HhHoPAU4Ro7liXwNe4xQeF4mgSkKW4OutWwrS205vUWj aYyCJFolo3XQGVfled5BZBZ2fNNDROSYo3Yc1dgwJEDU7f7nZr3x3N//kzeJL9Vx2MFC QlSY9tbWHV8S1rvVmkqfU2GbaD+bdK6uOxkBHW6QsB32tjUWKn1wOBVPj1Uk9oz9KNTs FYLQ== X-Forwarded-Encrypted: i=1; AJvYcCVS0evorTOs5Y53xiDQ3PQewMxxdgRDPw48sViNdPOxaAkv2z+tMWufHZoRB1bdkQOlDDrwGcRshKC3sQoGtli7VDXvu3o= X-Gm-Message-State: AOJu0YyAmWR85ek4gI6ku5UzwKPC57OavG1fsUXfbJFNJnegPCyWQYKv N91QsndexxKOAHeS8T1nREBiha+R8glnsa3b95MLlRXkhPrimvJNThtv/9jbFBs85VEenWFflGm C+EpFloJ0JmizTSnUBYEnY0jNdVTDGrcjdBIedR3JfFMGdYnMRZlM X-Received: by 2002:a05:620a:3193:b0:795:5de4:662e with SMTP id af79cd13be357-797f5f00567mr225193485a.12.1718197400668; Wed, 12 Jun 2024 06:03:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFam35WX5YR7D+kjZ2CAmAzS8qpFT9IWRPbjmsn4XijrL6t7TgyWQU97gaGUhGnxegZzaDHPw== X-Received: by 2002:a05:620a:3193:b0:795:5de4:662e with SMTP id af79cd13be357-797f5f00567mr225188285a.12.1718197400184; Wed, 12 Jun 2024 06:03:20 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-797e8f4906bsm122609285a.80.2024.06.12.06.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:03:16 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 07/12] vhost-user: enable frontends on any POSIX system Date: Wed, 12 Jun 2024 15:01:35 +0200 Message-ID: <20240612130140.63004-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The vhost-user protocol is not really Linux-specific so let's enable vhost-user frontends for any POSIX system. In vhost_net.c we use VHOST_FILE_UNBIND which is defined in a Linux specific header, let's define it for other systems as well. Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- meson.build | 1 - hw/net/vhost_net.c | 5 +++++ hw/block/Kconfig | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index ec59effca2..239044070f 100644 --- a/meson.build +++ b/meson.build @@ -151,7 +151,6 @@ have_tpm = get_option('tpm') \ # vhost have_vhost_user = get_option('vhost_user') \ - .disable_auto_if(host_os != 'linux') \ .require(host_os != 'windows', error_message: 'vhost-user is not available on Windows').allowed() have_vhost_vdpa = get_option('vhost_vdpa') \ diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index fd1a93701a..fced429813 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -34,8 +34,13 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" +#if defined(__linux__) #include "linux-headers/linux/vhost.h" +#endif +#ifndef VHOST_FILE_UNBIND +#define VHOST_FILE_UNBIND -1 +#endif /* Features supported by host kernel. */ static const int kernel_feature_bits[] = { diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 9e8f28f982..29ee09e434 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -40,7 +40,7 @@ config VHOST_USER_BLK bool # Only PCI devices are provided for now default y if VIRTIO_PCI - depends on VIRTIO && VHOST_USER && LINUX + depends on VIRTIO && VHOST_USER config SWIM bool From patchwork Wed Jun 12 13:01:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O54Z620+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm4B5TYZz20KL for ; Wed, 12 Jun 2024 23:05:30 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNde-000737-AG; Wed, 12 Jun 2024 09:03:42 -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 1sHNdc-00072d-PB for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNda-0008H8-Sb for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197418; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GInn3FUattzKGx0ezQM5ug8ksWvzzKsxpJo2YJfBDjs=; b=O54Z620+v9HzkkNDBKbBc7enMPBsiPsxTM3SwhErRN6ExVBQF8Xrhzy3r1mMXrQr4+CYQj C7I98lMixnl1dAu+IZFoJJBmai7tapNzdM6C4oQcxc/wq71WkkZISaBwY5ysAe9/uEHXlw 4LRNrxdda+qOjFRHJIbmdzyxplVNb1M= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-uxiaq-bGOXaSQsMDlCOR9g-1; Wed, 12 Jun 2024 09:03:36 -0400 X-MC-Unique: uxiaq-bGOXaSQsMDlCOR9g-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7955ab105d5so369312785a.3 for ; Wed, 12 Jun 2024 06:03:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197416; x=1718802216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GInn3FUattzKGx0ezQM5ug8ksWvzzKsxpJo2YJfBDjs=; b=vJ07ofrngXPeLYdTQspVAKmk0YsXYdGF1GkiEc47GisSUEehw5uqVaRJXqvQ4jQwik WWAVBOPlnmeNzgntViWjzF6BSJPczPQ59d6ALdYJzNSgM3Dwj/YhzjHqdH9nS62/jD5M +pS5WfLPBwY7M7zm6/vzH46v6z+tLTbHg+wIqMYnAy002fPoBIYIdUhGaqKS5ZTM0Bet FItbMGtFSiwb0/XE/FozKqJdCuADp9gYeFDsgIfjAVz8hj+K62T+WomP2xOv/O2oI1Rm ONvuTsMq/bUWun1g56awazZCtYrijvUmqqkZ9ArHNTxgWYmFMwfopUSCWf3WprAsL1no fvag== X-Forwarded-Encrypted: i=1; AJvYcCUD2qaz4zLPVhT3y7U8jkP/X4QW3G425mm++3SNQLYJi3BB3BhkTVtzs/PqwkbSOn5+VHHZ2v0WHOs+n3QDno9IQpXqEo0= X-Gm-Message-State: AOJu0YyeoCA+9ge7wl+wWruS6eLY86677PcDZcYfKm8JC/nORnrnywD6 VtK+l0ZtVVtNAaHsvFOR2DN0d9jyt9WFWxerNVbtnkByZwTbkPQmdptfSFghnr8J09IPvvGseiM o148lLx4YvF461mAaNioFtmW0I5MIIG2ik0MbHVykGT4eVXl37/2+ X-Received: by 2002:a05:620a:2684:b0:795:6016:bdb6 with SMTP id af79cd13be357-797f60367cfmr188863385a.46.1718197415973; Wed, 12 Jun 2024 06:03:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfBZZdO8+Nlk5qDjFRrbiIc3gscoF9YHIeHjgrHsN4jO6aj0OHzOFGiQY2bLb9aGogfkUa3Q== X-Received: by 2002:a05:620a:2684:b0:795:6016:bdb6 with SMTP id af79cd13be357-797f60367cfmr188851885a.46.1718197414859; Wed, 12 Jun 2024 06:03:34 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7955b9b88acsm347034285a.1.2024.06.12.06.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:03:31 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 08/12] libvhost-user: enable it on any POSIX system Date: Wed, 12 Jun 2024 15:01:36 +0200 Message-ID: <20240612130140.63004-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The vhost-user protocol is not really Linux-specific so let's enable libvhost-user for any POSIX system. Compiling it on macOS and FreeBSD some problems came up: - avoid to include linux/vhost.h which is available only on Linux (vhost_types.h contains many of the things we need) - macOS doesn't provide sys/endian.h, so let's define them (note: libvhost-user doesn't include QEMU's headers, so we can't use use "qemu/bswap.h") - define eventfd_[write|read] as write/read wrapper when system doesn't provide those (e.g. macOS) - copy SEAL defines from include/qemu/memfd.h to make the code works on FreeBSD where MFD_ALLOW_SEALING is defined - define MAP_NORESERVE if it's not defined (e.g. on FreeBSD) Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v5: - fixed typos in the commit description [Phil] --- meson.build | 2 +- subprojects/libvhost-user/libvhost-user.h | 2 +- subprojects/libvhost-user/libvhost-user.c | 60 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 239044070f..6413e858ea 100644 --- a/meson.build +++ b/meson.build @@ -3172,7 +3172,7 @@ if have_system and vfio_user_server_allowed endif vhost_user = not_found -if host_os == 'linux' and have_vhost_user +if have_vhost_user libvhost_user = subproject('libvhost-user') vhost_user = libvhost_user.get_variable('vhost_user_dep') endif diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h index deb40e77b3..e13e1d3931 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -18,9 +18,9 @@ #include #include #include -#include #include #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/vhost_types.h" /* Based on qemu/hw/virtio/vhost-user.c */ #define VHOST_USER_F_PROTOCOL_FEATURES 30 diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 2c20cdc16e..57e58d4adb 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -28,9 +28,7 @@ #include #include #include -#include #include -#include /* Necessary to provide VIRTIO_F_VERSION_1 on system * with older linux headers. Must appear before @@ -39,8 +37,8 @@ #include "standard-headers/linux/virtio_config.h" #if defined(__linux__) +#include #include -#include #include #include #include @@ -52,6 +50,62 @@ #endif +#if defined(__APPLE__) && (__MACH__) +#include +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#endif + +#ifdef CONFIG_EVENTFD +#include +#else +#define eventfd_t uint64_t + +int eventfd_write(int fd, eventfd_t value) +{ + return (write(fd, &value, sizeof(value)) == sizeof(value)) ? 0 : -1; +} + +int eventfd_read(int fd, eventfd_t *value) +{ + return (read(fd, value, sizeof(*value)) == sizeof(*value)) ? 0 : -1; +} +#endif + +#ifdef MFD_ALLOW_SEALING +#include + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#endif +#endif + +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif + #include "include/atomic.h" #include "libvhost-user.h" From patchwork Wed Jun 12 13:01:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h0GKmY3d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm6h1gLFz20KL for ; Wed, 12 Jun 2024 23:07:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNdt-0007Z5-Nd; Wed, 12 Jun 2024 09:03:57 -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 1sHNdp-0007Rn-R8 for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:53 -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 1sHNdo-0008Hz-1E for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:03:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197431; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/P3j+V5YbDeu0o1n73tFmGj5F2fn9U/2HDvEhcAiiyg=; b=h0GKmY3d98bvTNKrFqpokFBFSZCPv26+/WYjhyOYZIhWjyVR7JoOl+omcqCqR1dSKJd1V0 NFx3nZftw5lOxbR8Bt3sgqDp3+PksDHgC69DVioJEX5HiQ3kn0lT+YRHOkQJYx6cu8JlFF ikLAYI4DehQk1FwncX5h4yIniTNO37E= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-sSLlmqxiMnaKxUSqaD9MOQ-1; Wed, 12 Jun 2024 09:03:50 -0400 X-MC-Unique: sSLlmqxiMnaKxUSqaD9MOQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4405784484eso46245351cf.3 for ; Wed, 12 Jun 2024 06:03:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197426; x=1718802226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/P3j+V5YbDeu0o1n73tFmGj5F2fn9U/2HDvEhcAiiyg=; b=aJoRuzXEnnLiAkY06ZuDnrIV1zKFYgjabrK8CnkT6pBTANgroJ8P7j3YSXCQWBWlNB kxp7oJ3lDPI8yUbQ9kaV2Z6k5f4XkUlAtJUmzYmnn8RNfTJuoh7Ti1qPMG/JBmO+U3XZ JVRKUyzWCZ6BzEukjMbIROCHYluyuIuEzLZOCWjRXkeMW/M2YP3e423WEuAFPPeDC0Lb FBKO3twtFliPXWhLymzJ9T7FM6MjCUqMkmzDA9O4vhT0fibSzgD+Dn7IzA9qJLf0xHjq PoIci1UxvbW1aeDLuTO1STLujG72+OwwMNEn9CVgxXDLq0PFfTdcWvVCJ2NLfrV89eBF xiyg== X-Forwarded-Encrypted: i=1; AJvYcCUX3ujjYzx4goXR/KL+RHs78b92dC42oOAx95rY9m2s1WQaCckiQImJBS8Hczw5RmEbpixvp/Gc/PPo9O+IfZRMeqlHmUk= X-Gm-Message-State: AOJu0Yzw2gdj/whtjTjUun5mRxVRJj3FMnefnl79s22fP+uAGvQtFubq 6rew52KrLHAjlGOuBE5s234Ss51DkAA555CpJ6ebNwoLeJMII867a6ZWU7OXxhVA/PWF6ZaIuoi mpt5C39BYIZ2uLA8cYL0qmIu7wdyb9mSQVWcMnr6vUmKKJSiTBmkB X-Received: by 2002:a05:6214:498c:b0:6b0:6d7c:da02 with SMTP id 6a1803df08f44-6b19158d45amr19617216d6.11.1718197426329; Wed, 12 Jun 2024 06:03:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEicCYzJOU6VP1vjIhb7Vn0kPFI8CMTuJW5Z/I6H4tPfdnlJRidFjhjohpLb3SkReX3sv/Qag== X-Received: by 2002:a05:6214:498c:b0:6b0:6d7c:da02 with SMTP id 6a1803df08f44-6b19158d45amr19616666d6.11.1718197425953; Wed, 12 Jun 2024 06:03:45 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b0928c508dsm10616236d6.78.2024.06.12.06.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:03:44 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 09/12] contrib/vhost-user-blk: enable it on any POSIX system Date: Wed, 12 Jun 2024 15:01:37 +0200 Message-ID: <20240612130140.63004-10-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Let's make the code more portable by adding defines from block/file-posix.c to support O_DIRECT in other systems (e.g. macOS). vhost-user-server.c is a dependency, let's enable it for any POSIX system. Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella --- v6: - reverted v5 changes since we can't move O_DSYNC and O_DIRECT in osdep [Daniel, failing tests on Windows] v5: - O_DSYNC and O_DIRECT definition are now in osdep [Phil] - commit updated since we moved out all code changes v4: - moved using of "qemu/bswap.h" API in a separate patch [Phil] --- meson.build | 2 -- contrib/vhost-user-blk/vhost-user-blk.c | 14 ++++++++++++++ util/meson.build | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 6413e858ea..8436e0c3d6 100644 --- a/meson.build +++ b/meson.build @@ -1985,8 +1985,6 @@ has_statx = cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', prefix: gnu_ has_statx_mnt_id = cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', prefix: gnu_source_prefix) have_vhost_user_blk_server = get_option('vhost_user_blk_server') \ - .require(host_os == 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user support') \ .disable_auto_if(not have_tools and not have_system) \ diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 9492146855..a450337685 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -25,6 +25,20 @@ #include #endif +/* OS X does not have O_DSYNC */ +#ifndef O_DSYNC +#ifdef O_SYNC +#define O_DSYNC O_SYNC +#elif defined(O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +#endif + +/* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ +#ifndef O_DIRECT +#define O_DIRECT O_DSYNC +#endif + enum { VHOST_USER_BLK_MAX_QUEUES = 8, }; diff --git a/util/meson.build b/util/meson.build index 72b505df11..c414178ace 100644 --- a/util/meson.build +++ b/util/meson.build @@ -112,10 +112,12 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif if host_os == 'linux' - util_ss.add(files('vhost-user-server.c'), vhost_user) util_ss.add(files('vfio-helpers.c')) util_ss.add(files('chardev_open.c')) endif + if host_os != 'windows' + util_ss.add(files('vhost-user-server.c'), vhost_user) + endif util_ss.add(files('yank.c')) endif From patchwork Wed Jun 12 13:01:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IFo53V7K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzmB54kzRz20Wd for ; Wed, 12 Jun 2024 23:10:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNe8-00006U-Ee; Wed, 12 Jun 2024 09:04:12 -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 1sHNe2-00084g-F2 for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:04:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNdz-0008JE-FW for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:04:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197442; 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=XuILcjmt+IGqqrmCWfNyApHFZ1jwMwhtnj49lIqwDgo=; b=IFo53V7KSRmPFDT7VSsZqnpdG+LvhKhbc3U3HfWYROgfogC+o3BS9U+S8/QhJnFzR0nj4N UfMLAVGmKAHoHm6ttgICo7AUbnahgk/tg7AyVf9d6JQuf7R4FnSQsaOwz5WcyC/peUOTLg oBF2/yV/lLJftUfc3gSU7Lytfg2FCl8= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-kyQvt4Y6NrGJX6hzGVGtww-1; Wed, 12 Jun 2024 09:04:01 -0400 X-MC-Unique: kyQvt4Y6NrGJX6hzGVGtww-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6f96e58ad4aso4994891a34.0 for ; Wed, 12 Jun 2024 06:03:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197438; x=1718802238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XuILcjmt+IGqqrmCWfNyApHFZ1jwMwhtnj49lIqwDgo=; b=Rh469nttouQBUcqfrWkrWyVyH+lFo1El/3qsuq6oVUcXKKyu99B0NAlyS/y9YgubpQ lX469t3n6asUSbwlDjQjqK/xwKmVHgSyYhA/nyeJz392jbcRfeRP/qEZfuMeVy8hK7no mf0EbgS2MAtrRIUuu65Xy7yd9m6xfAZagdlnw7tl/b7tNiA1JQDhS9HGlmEr/yyWJPIY wbHAe2y2M1YBWP8Uj2z7ZrzOK5OqJdPHcgAHP8/n+JFO9yn69CZPhqQdy8z4hl58sZCU 4f1OwZdLK2YcmazAc7/L5WT7VTAiO7WPFP09Fj6gqaN6FvAJQf//5yXF7Xe5CA3LNQwq DGRg== X-Forwarded-Encrypted: i=1; AJvYcCXs3h/FXOR0rhArCvD0sz8S/z8k1iTowgpFI5gscfm1wpg1r91f7gJLaxQ1/Mqo2HKbH47amD6W/UJF6+Mp1oSYj5P5qws= X-Gm-Message-State: AOJu0YzDEkwk0MACZrZwAXHFz2wHyuDEY/4RsezsNbuySLhXGGfI7ZUb VlypaL9lKKMIlkxf3hr1kQB+likiwnSI0pp1QLc1HB7P2CcY8KOAMOcGHjRMFlxprF7jLdGPrKw mOHgJAkvTLerIwOe3M1oHcZAh/gUZOiy8rk3LHlkDdmlXOntDngh5tqYhPL4a X-Received: by 2002:a9d:6b0c:0:b0:6f9:64f1:5b14 with SMTP id 46e09a7af769-6fa1c222cb2mr1909724a34.27.1718197438148; Wed, 12 Jun 2024 06:03:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDjkDDd6RjonXndaapuLxB4HBfdCMvqXtpm1GxyQkLBKjROIVCXG0LC2eK96fR+kd7sBMoow== X-Received: by 2002:a9d:6b0c:0:b0:6f9:64f1:5b14 with SMTP id 46e09a7af769-6fa1c222cb2mr1909687a34.27.1718197437669; Wed, 12 Jun 2024 06:03:57 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4415df952d9sm3334201cf.88.2024.06.12.06.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:03:55 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 10/12] hostmem: add a new memory backend based on POSIX shm_open() Date: Wed, 12 Jun 2024 15:01:38 +0200 Message-ID: <20240612130140.63004-11-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org shm_open() creates and opens a new POSIX shared memory object. A POSIX shared memory object allows creating memory backend with an associated file descriptor that can be shared with external processes (e.g. vhost-user). The new `memory-backend-shm` can be used as an alternative when `memory-backend-memfd` is not available (Linux only), since shm_open() should be provided by any POSIX-compliant operating system. This backend mimics memfd, allocating memory that is practically anonymous. In theory shm_open() requires a name, but this is allocated for a short time interval and shm_unlink() is called right after shm_open(). After that, only fd is shared with external processes (e.g., vhost-user) as if it were associated with anonymous memory. In the future we may also allow the user to specify the name to be passed to shm_open(), but for now we keep the backend simple, mimicking anonymous memory such as memfd. Acked-by: David Hildenbrand Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Acked-by: Markus Armbruster --- v7 - changed default value documentation for @share rebasing on 20240611130231.83152-1-sgarzare@redhat.com [Markus] - used `memory-backend-shm` instead of `shm` and wrapped to 70 columns [Markus] - added 'if': 'CONFIG_POSIX' to MemoryBackendShmProperties [Markus] v5 - fixed documentation in qapi/qom.json and qemu-options.hx [Markus] v4 - fail if we find "share=off" in shm_backend_memory_alloc() [David] v3 - enriched commit message and documentation to highlight that we want to mimic memfd (David) --- docs/system/devices/vhost-user.rst | 5 +- qapi/qom.json | 24 +++++- backends/hostmem-shm.c | 123 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 16 ++++ 5 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 backends/hostmem-shm.c diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost-user.rst index 9b2da106ce..35259d8ec7 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -98,8 +98,9 @@ Shared memory object In order for the daemon to access the VirtIO queues to process the requests it needs access to the guest's address space. This is -achieved via the ``memory-backend-file`` or ``memory-backend-memfd`` -objects. A reference to a file-descriptor which can access this object +achieved via the ``memory-backend-file``, ``memory-backend-memfd``, or +``memory-backend-shm`` objects. +A reference to a file-descriptor which can access this object will be passed via the socket as part of the protocol negotiation. Currently the shared memory object needs to match the size of the main diff --git a/qapi/qom.json b/qapi/qom.json index 9b8f6a7ab5..94e4458288 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -601,8 +601,8 @@ # # @share: if false, the memory is private to QEMU; if true, it is # shared (default false for backends memory-backend-file and -# memory-backend-ram, true for backends memory-backend-epc and -# memory-backend-memfd) +# memory-backend-ram, true for backends memory-backend-epc, +# memory-backend-memfd, and memory-backend-shm) # # @reserve: if true, reserve swap space (or huge pages) if applicable # (default: true) (since 6.1) @@ -721,6 +721,22 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# Setting @share boolean option (defined in the base type) to false +# will cause a failure during allocation because it is not +# supported by this backend. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { }, + 'if': 'CONFIG_POSIX' } + ## # @MemoryBackendEpcProperties: # @@ -1049,6 +1065,8 @@ { 'name': 'memory-backend-memfd', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', + { 'name': 'memory-backend-shm', + 'if': 'CONFIG_POSIX' }, 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' }, @@ -1121,6 +1139,8 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdProperties', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', + 'if': 'CONFIG_POSIX' }, 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', diff --git a/backends/hostmem-shm.c b/backends/hostmem-shm.c new file mode 100644 index 0000000000..374edc3db8 --- /dev/null +++ b/backends/hostmem-shm.c @@ -0,0 +1,123 @@ +/* + * QEMU host POSIX shared memory object backend + * + * Copyright (C) 2024 Red Hat Inc + * + * Authors: + * Stefano Garzarella + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/hostmem.h" +#include "qapi/error.h" + +#define TYPE_MEMORY_BACKEND_SHM "memory-backend-shm" + +OBJECT_DECLARE_SIMPLE_TYPE(HostMemoryBackendShm, MEMORY_BACKEND_SHM) + +struct HostMemoryBackendShm { + HostMemoryBackend parent_obj; +}; + +static bool +shm_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) +{ + g_autoptr(GString) shm_name = g_string_new(NULL); + g_autofree char *backend_name = NULL; + uint32_t ram_flags; + int fd, oflag; + mode_t mode; + + if (!backend->size) { + error_setg(errp, "can't create shm backend with size 0"); + return false; + } + + if (!backend->share) { + error_setg(errp, "can't create shm backend with `share=off`"); + return false; + } + + /* + * Let's use `mode = 0` because we don't want other processes to open our + * memory unless we share the file descriptor with them. + */ + mode = 0; + oflag = O_RDWR | O_CREAT | O_EXCL; + backend_name = host_memory_backend_get_name(backend); + + /* + * Some operating systems allow creating anonymous POSIX shared memory + * objects (e.g. FreeBSD provides the SHM_ANON constant), but this is not + * defined by POSIX, so let's create a unique name. + * + * From Linux's shm_open(3) man-page: + * For portable use, a shared memory object should be identified + * by a name of the form /somename;" + */ + g_string_printf(shm_name, "/qemu-" FMT_pid "-shm-%s", getpid(), + backend_name); + + fd = shm_open(shm_name->str, oflag, mode); + if (fd < 0) { + error_setg_errno(errp, errno, + "failed to create POSIX shared memory"); + return false; + } + + /* + * We have the file descriptor, so we no longer need to expose the + * POSIX shared memory object. However it will remain allocated as long as + * there are file descriptors pointing to it. + */ + shm_unlink(shm_name->str); + + if (ftruncate(fd, backend->size) == -1) { + error_setg_errno(errp, errno, + "failed to resize POSIX shared memory to %" PRIu64, + backend->size); + close(fd); + return false; + } + + ram_flags = RAM_SHARED; + ram_flags |= backend->reserve ? 0 : RAM_NORESERVE; + + return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + backend_name, backend->size, + ram_flags, fd, 0, errp); +} + +static void +shm_backend_instance_init(Object *obj) +{ + HostMemoryBackendShm *m = MEMORY_BACKEND_SHM(obj); + + MEMORY_BACKEND(m)->share = true; +} + +static void +shm_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc); + + bc->alloc = shm_backend_memory_alloc; +} + +static const TypeInfo shm_backend_info = { + .name = TYPE_MEMORY_BACKEND_SHM, + .parent = TYPE_MEMORY_BACKEND, + .instance_init = shm_backend_instance_init, + .class_init = shm_backend_class_init, + .instance_size = sizeof(HostMemoryBackendShm), +}; + +static void register_types(void) +{ + type_register_static(&shm_backend_info); +} + +type_init(register_types); diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..3867b0d363 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -13,6 +13,7 @@ system_ss.add([files( if host_os != 'windows' system_ss.add(files('rng-random.c')) system_ss.add(files('hostmem-file.c')) + system_ss.add([files('hostmem-shm.c'), rt]) endif if host_os == 'linux' system_ss.add(files('hostmem-memfd.c')) diff --git a/qemu-options.hx b/qemu-options.hx index 8ca7f34ef0..ad6521ef5e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5240,6 +5240,22 @@ SRST The ``share`` boolean option is on by default with memfd. + ``-object memory-backend-shm,id=id,merge=on|off,dump=on|off,share=on|off,prealloc=on|off,size=size,host-nodes=host-nodes,policy=default|preferred|bind|interleave`` + Creates a POSIX shared memory backend object, which allows + QEMU to share the memory with an external process (e.g. when + using vhost-user). + + ``memory-backend-shm`` is a more portable and less featureful version + of ``memory-backend-memfd``. It can then be used in any POSIX system, + especially when memfd is not supported. + + Please refer to ``memory-backend-file`` for a description of the + options. + + The ``share`` boolean option is on by default with shm. Setting it to + off will cause a failure during allocation because it is not supported + by this backend. + ``-object iommufd,id=id[,fd=fd]`` Creates an iommufd backend which allows control of DMA mapping through the ``/dev/iommu`` device. From patchwork Wed Jun 12 13:01:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=M+NNAAAX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzm9q0Rhsz20Wd for ; Wed, 12 Jun 2024 23:10:23 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNeE-0000xZ-VW; Wed, 12 Jun 2024 09:04:19 -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 1sHNeC-0000dz-5R for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:04:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNeA-0008Jd-FP for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:04:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197453; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bLmIFJnBiZstRbWMCttQ1B85eqiav2i7bnLQ8L9RWs8=; b=M+NNAAAXPhug8xMgD+ua1UWfi8JtCB+6DUYtPme8blXg9xvFnFV7Y2mQgfkEO4T8AFzxTa JEtkRTe1KfzNIjV8NvRLsLNWgB+P4qUQvMJuyr9TWhofC8Os+ZP1VpWBm74koc5B0a9459 IHlvU3CijwugP46gCbk+8vbwJl50HwA= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-269-TZh3dgHfM_qVPuegyCi0jQ-1; Wed, 12 Jun 2024 09:04:12 -0400 X-MC-Unique: TZh3dgHfM_qVPuegyCi0jQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7979055b950so180782285a.3 for ; Wed, 12 Jun 2024 06:04:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197452; x=1718802252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bLmIFJnBiZstRbWMCttQ1B85eqiav2i7bnLQ8L9RWs8=; b=f0btQTxysIC3ME6nY7Q6o6E4NJ3Q6yClUB6oLe263ie0mehDKk0QwoEmyfbgBngnL1 p+mqyd1YjFwCLoxD6dx+TL3CwTx19+EHRM5G1IMzRzoVBTk0K4GwE6x8yl288vGeBVgH YCdSVYy2VPh/0CjVpIEdKHsuiFFZpPXTk9Zjt8mf2e8Zxh1jMKXkhbedK+QDKLlVoUSK bM/CBpC5gzK48GXBmkE/CtZDvqRx3AaaBanJd5wQmniGgOS74iZir2gAw8fZGxHNVti/ U4IxENmVQ6poa/gOJ108uiREkWp+aVd/oRHSnEohK/S7K9KA6ExmVAFI5rbzLWFoLAh5 ul7g== X-Forwarded-Encrypted: i=1; AJvYcCVM7fQlSFvU7jNzgSe9J0YN5cUj8ju4WXIT4/kb/7bruKd998q7d8osMsn6k4IoiZQAywTbuUdtYwBCUx5yKBs5VUV71p4= X-Gm-Message-State: AOJu0YxgF7vIElho3NLQlcHL3VKnWI0+80FyrT6VlTle9jOXwreGA94b /a35FFQpSZhjbX6UoNW0iPBiF4N/h6Jk4pqY1sybLqLIG88tfSWH40euwnnFsJE5BqGeGdRBvkH iiOSaUEfV9cH2i21iBU2tvq6KBJDiOOujf+CJX5IX8TtUQSa3W/vQ X-Received: by 2002:a05:620a:254e:b0:795:570a:b9e3 with SMTP id af79cd13be357-797f603bcfbmr154119985a.34.1718197451863; Wed, 12 Jun 2024 06:04:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDk0TROvQ8Cw4FccfFx4OhllQv9drIYA2Pqi+0faMWI8dzIjiuR3Gfddh+gx5Xhmf05qUBbA== X-Received: by 2002:a05:620a:254e:b0:795:570a:b9e3 with SMTP id af79cd13be357-797f603bcfbmr154110785a.34.1718197450872; Wed, 12 Jun 2024 06:04:10 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-795331c88d6sm600125585a.115.2024.06.12.06.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:04:06 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 11/12] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Wed, 12 Jun 2024 15:01:39 +0200 Message-ID: <20240612130140.63004-12-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org `memory-backend-memfd` is available only on Linux while the new `memory-backend-shm` can be used on any POSIX-compliant operating system. Let's use it so we can run the test in multiple environments. Since we are here, let`s remove `share=on` which is the default for shm (and also for memfd). Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- v6 - removed `share=on` since it's the default [David] --- tests/qtest/vhost-user-blk-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index 117b9acd10..ea90d41232 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -906,7 +906,7 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances, vhost_user_blk_bin); g_string_append_printf(cmd_line, - " -object memory-backend-memfd,id=mem,size=256M,share=on " + " -object memory-backend-shm,id=mem,size=256M " " -M memory-backend=mem -m 256M "); for (i = 0; i < vus_instances; i++) { From patchwork Wed Jun 12 13:01:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1946900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gh07k2mt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzmBx5srQz20Wd for ; Wed, 12 Jun 2024 23:11:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNeQ-0001af-Jj; Wed, 12 Jun 2024 09:04:30 -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 1sHNeP-0001ZW-40 for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:04:29 -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 1sHNeM-0008Nh-Lh for qemu-devel@nongnu.org; Wed, 12 Jun 2024 09:04:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718197465; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CNfNqVgiPACxEos23z/KKmFGM3slQs8eIq4L2oKEPI8=; b=Gh07k2mtdYco7sYT1ea34wJHSQY83NpCI3KQ9SPoahXGgyvQIdxRnuSEbTOoyB9Dtnbuu5 BgeELFk20plS3g8AQUH8BoMCW/b1wXOMz0QkGXxro1H7GEsS9EWXY69vDXIWVRJQFNdVbP +PvstDRGhu354Ytgfn7/9AHrb5uIaVQ= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-jfPk6O73Ote8RQq93H_QrA-1; Wed, 12 Jun 2024 09:04:24 -0400 X-MC-Unique: jfPk6O73Ote8RQq93H_QrA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-79557d418e0so131003685a.1 for ; Wed, 12 Jun 2024 06:04:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197464; x=1718802264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CNfNqVgiPACxEos23z/KKmFGM3slQs8eIq4L2oKEPI8=; b=L0EYmE39n7iOvj1HMgB/dxZ/Pc9Jzpx+wVab/DpxToK/A6+JO0ISWYT92Lo9P9CIWA dOsM2BzD9zc1rEBKxSBzU51wgmGPud4MRt8VVclggOS2Eq9VCWIYEvd4PWKuklbBYU65 pFcOuqypFmsW7Nb7QAlNxXjOFX2bdVduG9Gt+1WWTthPbwAXg552Kum8x8iNsAxYaypf q3FwgMjsjQt7YqbxIZ2VpfMsKWnxEgj/4IVWiEEkAo5tHU8pTb6S4QQGzr4CmgkNFK/j YT2G0RRx1VtnajMzk9renFJLvcSEDR6U0kGFGR0SF4Eab1sB4HJ8ZD1FHxtL/MaErsLw nunw== X-Forwarded-Encrypted: i=1; AJvYcCVeAEG53k2YOK4aUPAV1KcwYXZ2tDbUeJ9vLX/2cHoYy8917PTes9ZFenv3ETsx1wKvyyMYewUrPPPEBwxwv5eOpVAhf+4= X-Gm-Message-State: AOJu0YxIU2TS9jJ7uu5dxXujoJjK6UNh0Zk61mLh40S0qxu7FER572wU 606HcYAXsrwaISFAPloraSBebVsn9P5uag69OxvIcncE5dfe65QnlaCG3gPX7UF9ks4swH2tJwr ITtA10mnrnpz7YCKDj4melFbHvwr7peMtp8sVZrL/7BN410x2x+O3 X-Received: by 2002:a05:620a:248f:b0:796:de79:f577 with SMTP id af79cd13be357-797f4db46a5mr305670185a.7.1718197463884; Wed, 12 Jun 2024 06:04:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES+eNDH7l0fcQFSgjZd9Cgd67bs3haFZfc6vWAj9INn10tsrsp40myO8ciHKmvP6uZ+4jnYQ== X-Received: by 2002:a05:620a:248f:b0:796:de79:f577 with SMTP id af79cd13be357-797f4db46a5mr305663385a.7.1718197463336; Wed, 12 Jun 2024 06:04:23 -0700 (PDT) Received: from step1.redhat.com ([193.207.132.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-797e8f4906bsm122685485a.80.2024.06.12.06.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:04:21 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Hanna Reitz , Brad Smith , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Laurent Vivier , gmaglione@redhat.com, stefanha@redhat.com, Coiby Xu , Gerd Hoffmann , slp@redhat.com, Igor Mammedov , Raphael Norwitz , Thomas Huth , Eduardo Habkost , David Hildenbrand , Kevin Wolf , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH RESEND v7 12/12] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Wed, 12 Jun 2024 15:01:40 +0200 Message-ID: <20240612130140.63004-13-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612130140.63004-1-sgarzare@redhat.com> References: <20240612130140.63004-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org `memory-backend-shm` can be used with vhost-user devices, so let's add a new test case for it. Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella --- tests/qtest/vhost-user-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index d4e437265f..8c1d903b2a 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -44,6 +44,8 @@ "mem-path=%s,share=on -numa node,memdev=mem" #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ " -numa node,memdev=mem" +#define QEMU_CMD_SHM " -m %d -object memory-backend-shm,id=mem,size=%dM," \ + " -numa node,memdev=mem" #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on" @@ -195,6 +197,7 @@ enum test_memfd { TEST_MEMFD_AUTO, TEST_MEMFD_YES, TEST_MEMFD_NO, + TEST_MEMFD_SHM, }; static void append_vhost_net_opts(TestServer *s, GString *cmd_line, @@ -228,6 +231,8 @@ static void append_mem_opts(TestServer *server, GString *cmd_line, if (memfd == TEST_MEMFD_YES) { g_string_append_printf(cmd_line, QEMU_CMD_MEMFD, size, size); + } else if (memfd == TEST_MEMFD_SHM) { + g_string_append_printf(cmd_line, QEMU_CMD_SHM, size, size); } else { const char *root = init_hugepagefs() ? : server->tmpfs; @@ -788,6 +793,19 @@ static void *vhost_user_test_setup_memfd(GString *cmd_line, void *arg) return server; } +static void *vhost_user_test_setup_shm(GString *cmd_line, void *arg) +{ + TestServer *server = test_server_new("vhost-user-test", arg); + test_server_listen(server); + + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_SHM); + server->vu_ops->append_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); + + return server; +} + static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *alloc) { TestServer *server = arg; @@ -1081,6 +1099,11 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); + opts.before = vhost_user_test_setup_shm; + qos_add_test("vhost-user/read-guest-mem/shm", + "virtio-net", + test_read_guest_mem, &opts); + if (qemu_memfd_check(MFD_ALLOW_SEALING)) { opts.before = vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd",