From patchwork Thu May 23 14:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6FD6C25B75 for ; Thu, 23 May 2024 14:56:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9r6-00023t-DA; Thu, 23 May 2024 10:55:44 -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 1sA9r4-00023I-LO for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:42 -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 1sA9r3-0003vu-8k for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476140; 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=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=SWm2p/yZkDQdAghm/EciTkr+tMc/A/AQXqUV2gBGpy/jelV8R5VtfYx7ewqUnVCKqmAIB4 zQ/LULxF2BgHzRy6AtpaC++qNEyJoFfHorBt4d0bKL8OoEAin8N76v7z2huYQr4taU10Zt VAGdGGBOd8umwL3KGRvSnTDtKIP82aw= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-6-wDqsn7PGKMeGaig2Fp3A-1; Thu, 23 May 2024 10:55:39 -0400 X-MC-Unique: 6-wDqsn7PGKMeGaig2Fp3A-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6ab8c89adb6so2524986d6.1 for ; Thu, 23 May 2024 07:55:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476138; x=1717080938; 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=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=tBcOJdo8IQc8IdO+Oq/8BAu72swdw8EcMQw4u3m+lbgvWH8lVNdhKOqLh+5fnXH58R +1AYAGjfARa6wXnlcXJR54pLiiKKc5q04SknfAEoqcLJ9mq9I22812/YaQg8RZwYyAvt r/WcgnWFclxHWDo3B4THww/e2jesMy/gZnt9QW3n5Cg/UT2Ufn6FmFs5hYNm8G7bFM6I GNB4naMDR6C6E+peZWTKzhydS+KNZKFO9Vg1G8M/LoYq8Yza07cZNpdrkblvL/S6ZZLB SkESY7SgJQ53m18uORBWH5m+Vr/4lzBEseqbisT8WSAvFlpunGX7V4Qqp+8OXtoQu6yN IbpQ== X-Gm-Message-State: AOJu0Yzbhws8Tkfy8PY8L3di2OUGPNENbF4tN77zffrEgZcZlroLbI3z rBXycQnhgu9QnSaxamMJwSGrcStoRJvTkrh5RiztocPh7BHGM0G5L+f35oyTqpglFZYjQduNT4/ ipXetPYNYfM+8TnMQfNytvWjL9oJA/6EhpqI9VfeOy3juqnaEUva6D0D8QcM2AYIDTIH6az6BMX 2ICW4gi5KDJWqtso3+IyVdmhjKzHrEwsJ0zo5d X-Received: by 2002:a05:6214:3f8f:b0:6ab:6d0b:eceb with SMTP id 6a1803df08f44-6ab7f3726b7mr73177596d6.37.1716476138015; Thu, 23 May 2024 07:55:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQS3U9wm4xFEmU29SUT+Muh3mdHUdkEn8zwkTLSuLOn3D4YxnpDFhuLoaecn9NzLmB1Dt7yg== X-Received: by 2002:a05:6214:3f8f:b0:6ab:6d0b:eceb with SMTP id 6a1803df08f44-6ab7f3726b7mr73177066d6.37.1716476137468; Thu, 23 May 2024 07:55:37 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab8676b583sm14666736d6.61.2024.05.23.07.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:36 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 01/13] libvhost-user: set msg.msg_control to NULL when it is empty Date: Thu, 23 May 2024 16:55:10 +0200 Message-ID: <20240523145522.313012-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Thu May 23 14:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04CDDC25B75 for ; Thu, 23 May 2024 14:57:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rd-0002Hq-7s; Thu, 23 May 2024 10:56:20 -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 1sA9rB-00025V-KQ for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:59 -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 1sA9rA-0003wl-6O for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476147; 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=+xyelDCWIlCX+PAbwFYWN2GP5CDp4IfKR8S4cYw8b0U=; b=O0bOI/VfYu2d6Q6CQAAXuONMA1q/srKcrR8VK307QRcOiFU+S14BLFv4EQCQ9slsYq186g aHwHDuTIcanakR/qr8ptaQ1iSUiAHedvKGWKTp7/MFT9yEw6wJxysC42YjisJvQfpcFneA +6sNGwAgMwc2mRzLwTI6WNe3stc4/Nk= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-wfWtd-OsO46aucllNvrvzA-1; Thu, 23 May 2024 10:55:46 -0400 X-MC-Unique: wfWtd-OsO46aucllNvrvzA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6ab8e7f5f8dso3968516d6.1 for ; Thu, 23 May 2024 07:55:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476145; x=1717080945; 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=+xyelDCWIlCX+PAbwFYWN2GP5CDp4IfKR8S4cYw8b0U=; b=waMJv+dUInW7ggBBRNPf98sU3Rm+AulKTzFtfu/NR+H0DfAN36CFKWohVQ0uX4Ix/K agjPzUN2Q/Pb2CYVfvZCePQilA4luHpn1zcVgAt9IjhRulhhFNJJnxW3s0FLNlRU3MyA sT2IWMkxj6DNWYsnoJzPkwp9qgC+wmc3tmSUdDi6LZ8CYBhQSPVkpIak+5jpfPFaqWQ9 YlhQkVBzCYexndgnAJGvrISKz2Lf/z7FSJfdXanC6QswA4G5mEb0fUeG08jBZ89R/Ety JVo+HqrRf4yZ3Az2OzfJabjBgrPSYckgeNNI9n+jsiSDjtSV6PX8IrlzlpKLpQWRnP+1 BZJw== X-Gm-Message-State: AOJu0Yxgvx8zsXnFxUftJ3kuTuiFVgkFywnXwDF7Qhmm+YyOOU4q9edM tkVgOKc7TdcMbDhvl61B5ew4bNYzVUVIJyNMj/letZ4C2Zwr3ygEoC2REkWP7km4X69THzpGSHA 27OQbw1Iyn53BX/t2by9eJnZvLAThcmyHnbWIx5Rs8VJDklKGrdIA3ileOghfzMxhdjP2hS8X/X KOJ8jwjb31uIz+3/YFLTlzmFmc3pHQtEhl/+TB X-Received: by 2002:ad4:4487:0:b0:6aa:206f:c2e with SMTP id 6a1803df08f44-6ab8f5bce70mr36215116d6.15.1716476145616; Thu, 23 May 2024 07:55:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPLyumh+jE/AutlVpcVipemoO5BlwX8gs6pHLiiSy/sDzeH/XtwPUAVKoaIpJXaHb3J49sgw== X-Received: by 2002:ad4:4487:0:b0:6aa:206f:c2e with SMTP id 6a1803df08f44-6ab8f5bce70mr36214506d6.15.1716476145081; Thu, 23 May 2024 07:55:45 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab93c15e1esm5250716d6.4.2024.05.23.07.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:44 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 02/13] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Thu, 23 May 2024 16:55:11 +0200 Message-ID: <20240523145522.313012-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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 Thu May 23 14:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5109C25B7C for ; Thu, 23 May 2024 14:56:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rp-0002eg-Iu; Thu, 23 May 2024 10:56:29 -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 1sA9rM-0002BI-S2 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:02 -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 1sA9rJ-0003ym-S0 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476155; 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=JAQwZsc8cKAlH0q2kUc7Sw/ErfWrVXpWDlOF1f/YOjk=; b=YVwGjMDWzH4Xek+ghegA/VORyrl9uHyK+jhqg/FMcIAXHeZD3VYP+KgSW/0S6JmfOA1X2c ICLSzvGZoRBJT/moWCtFpqJ5hmNV4W3kXy1fyoLeDqig+C/Tib1Ouav8l7yFLBz8EzGgVs PyHoUiFen3ug9NEnDAi2W9xfXlSiZn8= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-10W5v2GiNry_d9v1GW7BQQ-1; Thu, 23 May 2024 10:55:54 -0400 X-MC-Unique: 10W5v2GiNry_d9v1GW7BQQ-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-43e096020baso2516431cf.3 for ; Thu, 23 May 2024 07:55:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476153; x=1717080953; 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=JAQwZsc8cKAlH0q2kUc7Sw/ErfWrVXpWDlOF1f/YOjk=; b=BntRTPMD/POqHjGa6gXXWlX0mN/0u5gMZa7naXK3ZN/s0SMacm+cW47offtpoYwfsd ka3/DN/5V6vKBGY1Es/8DoIgOrbPvtVWEwIRUtpj0WwVcEnM0EODiias74cFBiXUh/ki p7j9HFaYlmHlAWgxDXv9kBK6tb1RkTanU91h6cN0bGAkczi7JDZTsZ374PUESBAJ2B+e AknVNNiXu1/PexVOOP0GAdhD7snghkZiDbCrqBzikEnwfFZWW0wxgm8b+Qy0DDCq5ayE ItkyMDYz+8iJBthUGmiKh7XqvljV4Kq2+mSg3ykagXE4+mq2zsdIxpJPlurBMNxM7lE1 2vFg== X-Gm-Message-State: AOJu0YwEm1xfN9M5g7OYC27AYS25si/moH+qm+PE8o+Q6YNhf2BuU+ki xXv7MPrOCl/vQ48iGpu+FC89Fb0oSPo3Wh4DwLm54cySVarj379DaaeO5prAyAabaJrgoBQtjS4 OtGxOCqXwyBL6vrVqQ4CDwbO3+wUisNE8H7RSHHW7bKtk5ClYxpUa3cbjYl2zTbhkGl2Mztd2i7 fp/K2irNtyFUKN7sLVyIUzYrVCbk/tp/yvaqLl X-Received: by 2002:ac8:5dc8:0:b0:43a:43dc:f5e0 with SMTP id d75a77b69052e-43f9e089d65mr59625581cf.9.1716476153273; Thu, 23 May 2024 07:55:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4Dfku7jRiy/tU2GetMzIMaF0liT1J8UGbSy7sP31dqk4PdtJh/rzTfx5m4mvlqRrZcS18nQ== X-Received: by 2002:ac8:5dc8:0:b0:43a:43dc:f5e0 with SMTP id d75a77b69052e-43f9e089d65mr59625151cf.9.1716476152803; Thu, 23 May 2024 07:55:52 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e12f41a0asm148192191cf.48.2024.05.23.07.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:52 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 03/13] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Thu, 23 May 2024 16:55:12 +0200 Message-ID: <20240523145522.313012-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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 Thu May 23 14:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D42FC25B79 for ; Thu, 23 May 2024 14:58:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rq-0002iC-Gq; Thu, 23 May 2024 10:56: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 1sA9rS-0002I4-4g for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:15 -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 1sA9rP-0003zQ-Cs for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476162; 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=hN/AM+u5Z+nLunf2Rn+i5MH2xtaDn5R44afvB9no9H8=; b=Krie9YBayxWKzy+uzdLHzd2eYitjNpY+i8DYzZG7bvVTOUHO2xJxGFmR4cS3ZTe0cA599K vNgYQQ+Nav34nZEJzyeN0Mpj2wpdRsMP5CoWUTwQsWsweqCfjDZ16eyts3wo8tnwk+s8gp yBSSklP8r7n7IWnUdlegpsglPxGUn7I= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-227-RWgf_cylNmaV6ZoCUsnj-Q-1; Thu, 23 May 2024 10:56:01 -0400 X-MC-Unique: RWgf_cylNmaV6ZoCUsnj-Q-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6ab7b258941so3344926d6.0 for ; Thu, 23 May 2024 07:56:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476161; x=1717080961; 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=hN/AM+u5Z+nLunf2Rn+i5MH2xtaDn5R44afvB9no9H8=; b=r+r+8TRCu5FP69qT4hWdmi9QR1aoVnVZ7dr8q1MYDYdL86aj3FhDRMoRXF2C4TGdKM /7/TzRLnBGRId0CY5JzOOEF+W5GSSvCZ9uh/SNw7zMsQ81hPkdQrWxUjDhY2u7rYLG0F OOkCTOG0eCEFl26mWJnCm+X1e9D5/zsRvTEp+mPTcjnDaVcpZeRcYWHe4FIgbSMI5DIS 7ro6DGF1NFiNuBewo38aQC/dS1to2pCsFg9t1zowpUrPwMVkuFWZPhWgSpgU8tCThIzl aVTRm6pKOjUKzPTLcYfrh9j+gug7mHaihoxQonRhmJwmpnqjowTxk48jZvhBdzpmliYL 87YQ== X-Gm-Message-State: AOJu0YxtGqwGdpZeMbwWWrT9cBJ13rCp3qx73hoihgH6n46PjiKwOcTl yvj9Dh5GLlJ+OobBDcjqXmD2tcOoSeO+/frFsvGxyoQjYQ/LOMY1Mf9refbIpizm3rKGo+x13Q2 qz0i82CMC+reRHUCgoyvqwrcxrRYSqG6QYaYF+pSQsTp1Eg6ZQcwjSjezZ3k0bQ/4zqEnXd7lr5 BAMvWkRii6Og2qhSROkMOoks7N3prsFP2SY54s X-Received: by 2002:ad4:4f54:0:b0:6ab:8a1b:6941 with SMTP id 6a1803df08f44-6ab8a1b6b1bmr35374436d6.7.1716476161073; Thu, 23 May 2024 07:56:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYM6uGiT4bQfpAzvCAcmG6s6un94sj/pZW+pZmEpB7DSlUh5LBB6cJ2/hoTPcTM92uGDVcrg== X-Received: by 2002:ad4:4f54:0:b0:6ab:8a1b:6941 with SMTP id 6a1803df08f44-6ab8a1b6b1bmr35374046d6.7.1716476160643; Thu, 23 May 2024 07:56:00 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab8b361681sm11824566d6.84.2024.05.23.07.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:59 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 04/13] vhost-user-server: do not set memory fd non-blocking Date: Thu, 23 May 2024 16:55:13 +0200 Message-ID: <20240523145522.313012-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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 Thu May 23 14:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88082C25B79 for ; Thu, 23 May 2024 14:58:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rt-0002kb-AE; Thu, 23 May 2024 10:56:33 -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 1sA9rd-0002Os-Cf for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:20 -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 1sA9rX-00040H-W3 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476171; 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=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=gsTrVkhdQ5T6u1Ub/wibKHk+3YK0my6WsActOfUHLASS31nfjlXCudjjqBwKEIO7jPc3yF xp40sxTTl9Obcfbvmw8ATAjHQP4AY2742v5LxfIGLz4ntVtS++eek2HjAnQsyN4QDZKsTv gUHP+Jsv2Lag1iDb1EJ5QIwsdXc+/Z8= 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-605-Q-9nhn3YN5aDdWTJOR2o-g-1; Thu, 23 May 2024 10:56:09 -0400 X-MC-Unique: Q-9nhn3YN5aDdWTJOR2o-g-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-43e349c3983so2218661cf.2 for ; Thu, 23 May 2024 07:56:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476169; x=1717080969; 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=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=jmpAV36N4WXjkg0E6Lt680k8YEflLGfhiL158YLta186Lm3J9lX+8RmPLEVVlqpP38 BPFn4BSnIlbzdw+beGArowB53Jp/llcx5csCIPAlcfvuuNgovJZssugdIieFZxX3BwPS qIVnXjl1ljgEM32AsYevh1ayo+yzHuy8BfxpKCfvL6EBEB4YzPzZyHWQ7HTE53R+z6zP pEXNp+Ca9TBvdkmTRAFtszz8MRoOGN+YnFc7B4S8WI0RJwKfp95C2Hkjd91n4zWVMyUZ rdINTMhZdg8FwFd9D2JmdNNTxafPooL+Y5JBCmstWYaOusJLSOotpPjMy4Yd4b7lglqG SYbg== X-Gm-Message-State: AOJu0Yx4APf9tJpqf0OhNorgdbIhxDCpeJnWl6nt/u9IjUWFhkutyuto n7Ww7YWUGAdKKc9IjXj1PLWKVp7FhDRcWbWPEXZ5ax6w1KvY5Ld2qBos5bl5817JnZDF/Rlf7By MjwhNEpCTgsK0aSFVyXNq2/SWjsuS56S2r6Y0Iu7GEta9yDLMlayvYUKHDd1gRhCEadn2c6ppZP OlGYQlTNHmMhI9asb7c0lVPgdd8Sh+8StIj5HL X-Received: by 2002:a05:622a:1305:b0:43d:f4d3:8990 with SMTP id d75a77b69052e-43f9e0c04cfmr53940431cf.40.1716476168848; Thu, 23 May 2024 07:56:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4knHCI1y7ZQ8UZ51KzryHPvknrU7ndeoKWFHCJZ8XCXb84ppDg0sZIsRtAfZHzmWbF8zKPQ== X-Received: by 2002:a05:622a:1305:b0:43d:f4d3:8990 with SMTP id d75a77b69052e-43f9e0c04cfmr53939981cf.40.1716476168398; Thu, 23 May 2024 07:56:08 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43f86a12d71sm56614101cf.17.2024.05.23.07.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:07 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 05/13] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Thu, 23 May 2024 16:55:14 +0200 Message-ID: <20240523145522.313012-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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 Thu May 23 14:55:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0886C25B7D for ; Thu, 23 May 2024 14:56:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rr-0002jT-TQ; Thu, 23 May 2024 10:56:31 -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 1sA9ro-0002bY-BF for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:28 -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 1sA9rj-00041A-Fy for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476182; 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=aZ6f2Wy9JZAIyu5wRg6z9P9zvSbVeUQdfiHCy8ESziQ=; b=Gzxbb3LOnsRpbxN0D+sfTJ/FP7Swzcdv17IUwHXGZTsv3CqqJeBSHnnO3Q8OgdTR4ICn4p P4jj/og3jn2HeENP1kZUvdI3+QSdwlEKfWzR0tJQnvPb0qBjlGMh4T+d0MtI6iGiS3VahD wKbAX8z4GduXHi6TTrM47+xXeF/MO30= 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-232-Z2MGVX3CN9CGjLg5sWTOXQ-1; Thu, 23 May 2024 10:56:21 -0400 X-MC-Unique: Z2MGVX3CN9CGjLg5sWTOXQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-43df9a3fc0fso2383831cf.0 for ; Thu, 23 May 2024 07:56:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476177; x=1717080977; 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=aZ6f2Wy9JZAIyu5wRg6z9P9zvSbVeUQdfiHCy8ESziQ=; b=UGU9U8J/zZieXBk74OP4QwyxcgMaYN/MRkWrEW19fLcThOtIf69ZnYBmNUztZdN9mp jdvOIcmYf5nE1XxKQOzJ2TIFUZpXr/q5DWVIQmu9+56J0LqTOZacv5JB+UbtZPOYKO3t oEDtVrHTZH+E5VPvyOypGrobf3a5085ZSJausGfgrU3+viMQBPwt86qGD4fNFRMRGX+C xER4/j1pNr/HPEWfI48ni9gnTm9ZAeQ9j0s6SFy028LydY6B8IN7pR+X9LEGJLujXhyC c90pbxDK+8v25zyIUUg8cnk2+MoartGX7ONAWNedDRp1tSMBLxYLPoHyEOs/1dzLwD7y Yw2w== X-Gm-Message-State: AOJu0YxZym20arxOgjnvCm/0wdSPxMGSrTzzwp/OrtaywEz225D/2X6O i7+sXoOsQprJDeG/nl0Bvwv5+1Y6KvZ2uBIJDV9MhM55jvrQq4Zph4+zq9ZhcU57YLHfKP8zP2W 1Wc36xlMkX9iOQUYGLXOL7RCtALhRjuHjbmjP26YwWUqrMLVibpVZwOp3343c8vCEh/7OA+/sS7 2nltz//WJlIUrP5fKtUbELF06eA4Jhya3QTb1m X-Received: by 2002:a05:622a:1a1e:b0:43a:ed8b:75b1 with SMTP id d75a77b69052e-43f9e0f3220mr60046981cf.43.1716476176884; Thu, 23 May 2024 07:56:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBOgeLvfyvxxo1WQ91OSaQxysuTauL71eZuvZYFDk4b9lBg6eKujg38dT6UQ4V+k2bfI7hQg== X-Received: by 2002:a05:622a:1a1e:b0:43a:ed8b:75b1 with SMTP id d75a77b69052e-43f9e0f3220mr60046581cf.43.1716476176298; Thu, 23 May 2024 07:56:16 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e0a4bdce8sm159322281cf.18.2024.05.23.07.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:15 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 06/13] contrib/vhost-user-*: use QEMU bswap helper functions Date: Thu, 23 May 2024 16:55:15 +0200 Message-ID: <20240523145522.313012-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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 Thu May 23 14:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 306A3C25B75 for ; Thu, 23 May 2024 14:58:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rx-0002nM-OC; Thu, 23 May 2024 10:56:37 -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 1sA9rw-0002mh-Ae for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:36 -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 1sA9rt-00042J-Qs for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476192; 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=8Qg0j+YK7VRBZmAY9zpmey1/lx7IRhJZZvR9stxcVsk=; b=fWt8z2YcMxRFV1BrAVeXMLRsm42tq1UxU19t5R5/wRfg5gaQa9kp/EK1UwPdUsfiNztRPq 71iqFLslRx8SGwMdUsqqOwg0wq/skrTakfHqrNap9fArXgLW6u2AcE5rQQz0qAb3RXKMQn RztEp7R4+jqy4wUOI679LMzDvsg+fns= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-o5hEtvDgNWKAzxev31ZE9Q-1; Thu, 23 May 2024 10:56:31 -0400 X-MC-Unique: o5hEtvDgNWKAzxev31ZE9Q-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-24540b99e23so1682882fac.2 for ; Thu, 23 May 2024 07:56:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476189; x=1717080989; 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=8Qg0j+YK7VRBZmAY9zpmey1/lx7IRhJZZvR9stxcVsk=; b=FeAfdfkcjwV1ceBifnlZM4vOFDkpwAEFif9ybTUsMlYC+PB5TM8N2vDRDXfwJMr7EL dcBtBtblgDnJeBiGWekOsqm7j2FW4K5N4EcAHKrcewsjfEcORlyOcjd0PFPIvyWsAI+B MZ/tphfVP2Kk0fSZg4flcjPgIL/KcMs1yVLiWH07cG6U0yUHlyMzYFBPN0GlAnzMSwcW DPXmbTFPpP4+E4hjfrnOtESIROe3c3swOpp8gHRqEyzlvPQM90CPoFlf3ydQXapn2yY2 9y76C/q8lBAeZOOjRJyahWWStEGvsA/BJqiqnaj7Hwz7ubC7BvKv0EDt2bizFlpbIRKq KsYQ== X-Gm-Message-State: AOJu0Yy4tEtB/lstU0zDg9HfBHmHlJ1oxHeTq6sbhth9Z7UM0CKnekt5 y/UtNacifaY5aw6Ost1ZGZN82AQ9T5JAjUmSHB+6ARVd4rC2UqR7L4cyVdTuPFX9vP4lka/X4rv I2BZ4yCe5TPXigmzb8KFrKb+CNUmM4AEXuC9GD+ZLQ3XjUsiq34anIzfPDYjCj62k4zzh4j9RZL 9lYtZYT4uVv58axbbPp9CywIevszZgGdsQPFps X-Received: by 2002:a05:6871:5214:b0:245:4477:e9ed with SMTP id 586e51a60fabf-24c68aa76d1mr7798614fac.17.1716476189022; Thu, 23 May 2024 07:56:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEb6trD4nmHXJcjOEZGki5/Pkw4kzLac+sW4oiUM9BobY12st8spR+5ei897Gtpqi+R2K2DYA== X-Received: by 2002:a05:6871:5214:b0:245:4477:e9ed with SMTP id 586e51a60fabf-24c68aa76d1mr7798483fac.17.1716476187003; Thu, 23 May 2024 07:56:27 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e046467a4sm168864281cf.83.2024.05.23.07.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:23 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 07/13] vhost-user: enable frontends on any POSIX system Date: Thu, 23 May 2024 16:55:16 +0200 Message-ID: <20240523145522.313012-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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 a9de71d450..5a6f7a36eb 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 Thu May 23 14:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F708C25B75 for ; Thu, 23 May 2024 14:57:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9s7-00031j-RV; Thu, 23 May 2024 10:56: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 1sA9s4-00030c-VP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:44 -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 1sA9s0-00043E-QD for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476200; 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=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=HfxUAllZPGHl3whgv5YUq//NUnuq2tnnvNGFx/dns3UPlzNlEuh0r2Eq5fXd2p+ZkcTMMk g1eCqgognrvzHqGhzQ+OKL+H0rD7AlXYHJnBT1oPVdBfcPkOqODfU5u0P12gfNjf8lqXUP yPtBkhpFAfcgLcvu5mTEGUuqLRSaSbA= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-DzeDc88yP4WBruWdu44NVA-1; Thu, 23 May 2024 10:56:39 -0400 X-MC-Unique: DzeDc88yP4WBruWdu44NVA-1 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-5b27fcd20ebso1526087eaf.1 for ; Thu, 23 May 2024 07:56:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476197; x=1717080997; 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=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=jgPBzhEZ/4otFWGw1xWIBrm8TeUSG1xx4KyvCQ2gmDA5FlOIXQ+koayfnGFRIQAEwR qjppRsv0Qeb8S4dnvHx9F7wa4VlgImwCIbTRYPYQQsWq0Jsj5Uy9J0jdyEwj8Hes1LIB prpKCYmEtAPUNZih94VdNCqiAx2faWrQQTscImGm+A+vqF4Fr5t05ofbGmd2MhZpOlrg MUpOd3cy9UUi4dVWUB71dyj7BvRiHXISoDO3CNEQy4WzUPhA3ncy9t7utI7ihwA/171C xtr5uvnPcq01I9Kd8em5ZXFPtwpLz2hLJxF/PZU+0PBW46na7kqXjJb/l5ela8oNOt36 cVqg== X-Gm-Message-State: AOJu0Ywig0ivQV8QT1sHbk2DB6kJmE7tV1NPrFxLmfB1IyS5JpCZ+Im8 XCBuTnAFfn1UFfWu9ZV4p4ucR7HfAMQNJG4TTfNF9Zfukp167TdsEBBUfAEdR6B61W1p6RcITjH hUmwxLXAXiwZxq9K6h8GyZ1kE7tGku7TbHfxw1dKFAlhg6x6goadsbd0gxPhv2mpLzwaCqff9Q0 CUtryabwuM4aqFLUJme0kV/+8VUYHLOi3roCM7 X-Received: by 2002:a05:6358:a08:b0:192:8eec:3280 with SMTP id e5c5f4694b2df-1979213fd5amr401872355d.29.1716476196623; Thu, 23 May 2024 07:56:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHg8MltlA9GvC1ZpHWRCt5JxW7+kyPlmn9hVQ7/1VFxvoowgNrC3TzwYmjfT55P06G3gkn/7Q== X-Received: by 2002:a05:6358:a08:b0:192:8eec:3280 with SMTP id e5c5f4694b2df-1979213fd5amr401869455d.29.1716476196033; Thu, 23 May 2024 07:56:36 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab840e24eesm15842686d6.135.2024.05.23.07.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:34 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 08/13] libvhost-user: enable it on any POSIX system Date: Thu, 23 May 2024 16:55:17 +0200 Message-ID: <20240523145522.313012-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 5a6f7a36eb..543105af2a 100644 --- a/meson.build +++ b/meson.build @@ -3155,7 +3155,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 Thu May 23 14:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DDC50C25B79 for ; Thu, 23 May 2024 14:58:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9sK-0003Xy-Qc; Thu, 23 May 2024 10:57:01 -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 1sA9sB-0003CG-4W for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:51 -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 1sA9s9-00043u-5V for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476208; 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=edUAbB6FYQtNYztKJ8aeeDlCGuti83HdzsdflmaIRq4=; b=cOEm6KoQjGyWc1HcwWbM5I+kuP+ZZ+3L6yn5HtuDPaTjy3YOeMvT8hqcAvZzHxLj2Qv/9I LASCk2p8WhS2nW5RR18fEZ66ul/DqfXPYCfaRckIMuP8uvHkcCKyweggc3fWdJKzwdAPC4 JNObbiDDHXBOkYIxmvDt2+CUX0y/aJ8= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-CiM65WmPNMWilqxtYX_PVw-1; Thu, 23 May 2024 10:56:47 -0400 X-MC-Unique: CiM65WmPNMWilqxtYX_PVw-1 Received: by mail-ua1-f69.google.com with SMTP id a1e0cc1a2514c-803178218b3so106604241.2 for ; Thu, 23 May 2024 07:56:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476206; x=1717081006; 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=edUAbB6FYQtNYztKJ8aeeDlCGuti83HdzsdflmaIRq4=; b=goDSgezTk2xvvMftC7W/3Slk2WLCI3sM5HG3JhfOm1xgORySyokTniYc19n6Fc8X7M 0nZW1jtknxBgKviU2yPWWkylzpfuRFJkqlkFY14xhiNhdIThx4+K1pUPta8ek+EzPKNU wBT0EcxIXjz7lXsQGzMO6Y3N38l6+yFJ4haNbrAHiCuWUk1SEs5YRVWZ19A2FR4IwJIk Bn9AivEPhEzIgwizzqpL5QAwLcDekMDyuzQChpewl1DvjljR+mjm4skBkcDYhslmkcvB eivoFf1NRBp6cNXZYhRLN6rd1tF7ixGE6F/1Fj8RZwz7h7ZEPSqBqH6/FkfpkJti1Dgq /lKA== X-Gm-Message-State: AOJu0YyMRZLrHI8xPPC7oEykHvLqKjlp7fhBNDW4yBrZuj9mD6BUxhfn ZkuyUOjcF3WHmoSXy8akjdFKGV07xq/QPeXeMiuzkqMhB/xAHZqsiYlT6Rztq1l2g9jDmZrSizH pAHKoGPZNGxDQNERtU0Mrar6538ImPp08fvbgrLekztVggaow2xZLx3dlEEHhtiv9prNiyZq0Ow ojkmOnJchmMCSptGKZBvuammKtbUJrHmL5qOMu X-Received: by 2002:a05:6122:1829:b0:4dc:b486:e4a5 with SMTP id 71dfb90a1353d-4e212f1b787mr5172789e0c.0.1716476205928; Thu, 23 May 2024 07:56:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmySploH/h2W6a6HnRYeB4E6EpdvHnDW61lCXGKV1+O0F44Qy1IHPHfbppgWanotLDjKsH6w== X-Received: by 2002:a05:6122:1829:b0:4dc:b486:e4a5 with SMTP id 71dfb90a1353d-4e212f1b787mr5172737e0c.0.1716476205360; Thu, 23 May 2024 07:56:45 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1d704dsm143641646d6.116.2024.05.23.07.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:43 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 09/13] osdep: move O_DSYNC and O_DIRECT defines from file-posix Date: Thu, 23 May 2024 16:55:18 +0200 Message-ID: <20240523145522.313012-10-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These defines are also useful for vhost-user-blk when it is compiled in some POSIX systems that do not define them, so let's move them to “qemu/osdep.h”. Suggested-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella --- include/qemu/osdep.h | 14 ++++++++++++++ block/file-posix.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index f61edcfdc2..e165b5cb1b 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -325,6 +325,20 @@ void QEMU_ERROR("code path is reachable") #define ESHUTDOWN 4099 #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 + #define RETRY_ON_EINTR(expr) \ (__extension__ \ ({ typeof(expr) __result; \ diff --git a/block/file-posix.c b/block/file-posix.c index 35684f7e21..7a196a2abf 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -110,20 +110,6 @@ #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 - #define FTYPE_FILE 0 #define FTYPE_CD 1 From patchwork Thu May 23 14:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C274C25B7C for ; Thu, 23 May 2024 14:57:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9se-00045u-Kp; Thu, 23 May 2024 10:57:22 -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 1sA9sN-0003oJ-Mb for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:04 -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 1sA9sK-00045p-Ng for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476219; 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=zZczhXGl9TGqY4DRFWizTO3f/10y7CBxCovWDPv4GOo=; b=BPn0yU0LiPF6sQwwCC1WOYBzF8PCpRwxFLndPrTQ2yUaSedGQyj0DOBTGat9UYorQgAkWu JgGi9byFuHpyy+1diVEOplWo3PghBqbT0t9+KU6n2MUFQ1L89jz9MQAy897sN/JLDf1Gh1 O8TXucjR5lz6Oaebj+Elzku22pxg+N8= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-LRgyzyCJNeabMvak--grIg-1; Thu, 23 May 2024 10:56:58 -0400 X-MC-Unique: LRgyzyCJNeabMvak--grIg-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3c9ac6d3bf6so1217006b6e.2 for ; Thu, 23 May 2024 07:56:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476216; x=1717081016; 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=zZczhXGl9TGqY4DRFWizTO3f/10y7CBxCovWDPv4GOo=; b=NFFspqzUY4NAl5oTq6ajIs0Ot5d6BSCwKHrSrdg1YGj9WS5lHqkLp+MwI60d7ssZB4 zDMppeU3MD3ZA+h6u37+7OnVseZ2cXDerMG2d7l7frIDtl3zdKdItinffgcNW5DtEBY3 2y5KUWES4LLSgD+i6fClLfpq9jCUm3FYlSSjDQ8MpZTMTIXbZddH9X1IIbVkKq4LFR4W o86Vp3fCXXfoCmRkyjPEiky1rfiSYEvERAYTkGMuv97oQNGaApgo8PxEyvBzC2FaTGaW dmOlDD3hqrfqWZ+CqrlmDjdvBZC5nc61EQmDvyzZWYPq90MF8L+bGAFET4R0gGJKHfLO SRpg== X-Gm-Message-State: AOJu0Yx6esA4SbiWEdsfvvqXgr9dC7Kq5CbAPKEQx5WGWU31OZzqI59k n04c8WINRLpC4Y2o3M359kyZTdWjHHBMkLQubtioBCo5ll5g+a6QTdI36kRk3gUVfeVyRsMeZnp bhKV3GqBXL865/mEGWtCR98Ug0KUM9L6EYlcbKukGvvfBDFfuqM+zvmxk1ZGHzFQk0KHbl1Lh+m sgFNEJJ+mSW/bilbKOae00gb6wkNU62mXdJJ68 X-Received: by 2002:a05:6359:5f06:b0:186:131e:822 with SMTP id e5c5f4694b2df-19791dded6cmr581440755d.3.1716476216058; Thu, 23 May 2024 07:56:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExActTSjAj/wN/d05Xe/g/oADokunszHmJ6OxbWJtgD5bbKHoaoMylS4WESHfNPf1t0lqpZQ== X-Received: by 2002:a05:6359:5f06:b0:186:131e:822 with SMTP id e5c5f4694b2df-19791dded6cmr581435255d.3.1716476215441; Thu, 23 May 2024 07:56:55 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e3a57b396sm101182851cf.24.2024.05.23.07.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:53 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 10/13] contrib/vhost-user-blk: enable it on any POSIX system Date: Thu, 23 May 2024 16:55:19 +0200 Message-ID: <20240523145522.313012-11-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Previous patches made the vhost-user-blk application and the vhost-user-server.c dependency buildable for any POSIX system. Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella --- 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 -- util/meson.build | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 543105af2a..06a1835a09 100644 --- a/meson.build +++ b/meson.build @@ -1974,8 +1974,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/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 Thu May 23 14:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA835C25B7D for ; Thu, 23 May 2024 14:57:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9st-0004aT-HG; Thu, 23 May 2024 10:57:36 -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 1sA9sZ-00047v-Lb for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:20 -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 1sA9sU-00046V-BP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476228; 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=JLEKuIjNUE0upngVj1w8ZNUIo5SFQUiVbbxpLKuiIHs=; b=Ar0SqJATGvN7kvTR1/7P6Wp6/uA6UNHmqBr9OYWAMd7rM07sxwaG2KHo4mtFkmRZxZM1QE +lmIMmm1QzabTtXBq2y8cLPz+UGKwKLVo4ecjZYztWIT7oW9cuT9cgnX22YOV5Z6ZTvpR5 u57UiizuUU1aWIrJ2lPFIi5a40wPgDw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-6aLYO5ioPeS2aJZnWQnSOw-1; Thu, 23 May 2024 10:57:07 -0400 X-MC-Unique: 6aLYO5ioPeS2aJZnWQnSOw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6ab8e73bc89so4070006d6.0 for ; Thu, 23 May 2024 07:57:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476225; x=1717081025; 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=JLEKuIjNUE0upngVj1w8ZNUIo5SFQUiVbbxpLKuiIHs=; b=SiWJ89+MMN+QpU2Ci53Yr67W6VNRmWOwNxL0gVP6Zb51dVYDo771QgTPUWI6RXB0Rk qNJpcM/5KQvfIkNZUqsZmIZnpp2WdbBDNt+zKjA9CeaOgdEr6HRJPIerPP8dOQ6rDOhI tl+eoNfwCE3NeCQalCJRU+J0EQdjmCCOUZ6pdaOespmNsdFf6K3RnFJ62thjC7Nkbsw6 TjmD1C6QwWzzVYtXwTPics+wvYZ/tSkCNhZ3zeMeYJvCGtan2tHVsDbF/Cezc55aU6zb NhvXNN1qVfNtuXJT85MhU+Xk2yglmppxPuSGCxqYJEY0Wduj0n14kE/RaeaZ8c1v/XQS ytaA== X-Gm-Message-State: AOJu0Yy5WHLlf5Ly6e5jhq5mo6gDZNuXPqI04cavE0u3WvAq88Fxfl4D d3hk9PnmGDkytHZPKckg/I6h3DzBwkMk6CSr0OAJHIm3peBnWFblMr9Cb2wdyMXtGUUkFe2ieyx yuPxqW/UIvKb3qg76+kKe3yOs6z2PzzmiyLcxJhEdWiVYvGNr/tGtKVuyt7OXg8yeYydBREjEWd /hxt8lD23THouOtjTbnE+KUddeAMQsAUjXHE/F X-Received: by 2002:a05:6214:230e:b0:6ab:756b:5d57 with SMTP id 6a1803df08f44-6ab8f5cfcf5mr49998646d6.27.1716476225253; Thu, 23 May 2024 07:57:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6rDafkvUCgDEofvxExqDpXfr7GtX4pogk6X0aXYMFcGCUs2uMXA4GX122Suzyo47SljP9nw== X-Received: by 2002:a05:6214:230e:b0:6ab:756b:5d57 with SMTP id 6a1803df08f44-6ab8f5cfcf5mr49997836d6.27.1716476224571; Thu, 23 May 2024 07:57:04 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab8a05170dsm12949046d6.139.2024.05.23.07.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:57:02 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 11/13] hostmem: add a new memory backend based on POSIX shm_open() Date: Thu, 23 May 2024 16:55:20 +0200 Message-ID: <20240523145522.313012-12-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 --- 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 | 19 +++++ backends/hostmem-shm.c | 123 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 16 ++++ 5 files changed, 162 insertions(+), 2 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 38dde6d785..d40592d863 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -721,6 +721,21 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# The @share boolean option is true by default with shm. Setting it to false +# will cause a failure during allocation because it is not supported by this +# backend. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { } } + ## # @MemoryBackendEpcProperties: # @@ -985,6 +1000,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' }, @@ -1056,6 +1073,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 4d19660336..982751cb35 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5238,6 +5238,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 Thu May 23 14:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8810DC25B7C for ; Thu, 23 May 2024 14:58:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9t2-0004sn-6m; Thu, 23 May 2024 10:57:46 -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 1sA9se-0004J0-RP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:22 -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 1sA9sc-000471-G9 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476237; 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=oz7CXmEGB8H9CB1Ih3mY/njvC8uRis0RohRSCchlBSc=; b=JGgKpUkzA5nx3ijmFyCNVPdJ23Zixzw7MCBJpFfqNClzLVIxEq5TR91zERYZbG92Eda5Sj 6CBq225jok1zB3aaPjfsUop00zL0hnk4nyAVXbSs8gzkCD/eZgbfQ5Xkd6gwCSMmkfYNh9 72SF68XV5YAeABEHxVDrVKwB8h3dZKw= 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-82-qIjrN6TbPpmFyLqa2uTP4A-1; Thu, 23 May 2024 10:57:16 -0400 X-MC-Unique: qIjrN6TbPpmFyLqa2uTP4A-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-43f7dba5d72so2162851cf.3 for ; Thu, 23 May 2024 07:57:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476234; x=1717081034; 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=oz7CXmEGB8H9CB1Ih3mY/njvC8uRis0RohRSCchlBSc=; b=LtQJRhPkgcos9IgqkWmXi+z3NqvN3MqOR0DRar+zyjRL0Tc/xY52I8An6Tk0o1x5SV kBzRzTKbJ15oCET2VAfJmYADwBbDSysARQghG/remjMDDMFtNy3kKTBquL4LnBoHoNj2 GGPkY5+djXDGu1GBdPPNLSoP2GqX23m524fjdbQ7MFEoYRsL3HQnAkvm7uNO4XIZVxDP 1aEfcTzagKJ1b8qippTZnAl/fHEwACYVhk0UsrZMWEes2ZXJFwBZcuPYNqNh+Wr88vys /ltitezrRNvhzs/iZU0CS/Q4VNiMuH19tm5JUAJqDtpFtVq79IqhvNMmJZwx+gIBhCoH 8JzA== X-Gm-Message-State: AOJu0YxIfMsNCuxTH+10JJJcVAsN8MYV4fJTrHS8pXtjlg2tX4B8imHs EyOG9wmENr0RYabG+UYxMvy4Wbc9n2TMjVSn4WlCO1yBPji15TW+4CLR2CEEmLn/b67P8j6Jfus nYhM9asLRemNk+GpKkHxB6fhDjJ8IP1w4/FzEC/aPXZmvOE4ZrBBGauauIRszKzSjucluynw9wk ttCHiEI0jy8sqRrjEH5KyZzUjNLofOMbPBHOcm X-Received: by 2002:a05:622a:242:b0:43a:d7a9:390 with SMTP id d75a77b69052e-43f9e0ae4e7mr49036421cf.29.1716476234169; Thu, 23 May 2024 07:57:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9o75zA1DWnxNJTkg2uWIN9fVcZCsH1LHayMVQzL8KVSF8dzDS1Tkmu+0m0U9wE2qF+ecaag== X-Received: by 2002:a05:622a:242:b0:43a:d7a9:390 with SMTP id d75a77b69052e-43f9e0ae4e7mr49036051cf.29.1716476233803; Thu, 23 May 2024 07:57:13 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43fa1a906eesm18405351cf.20.2024.05.23.07.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:57:12 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 12/13] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Thu, 23 May 2024 16:55:21 +0200 Message-ID: <20240523145522.313012-13-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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. Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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..e945f6abf2 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,share=on " " -M memory-backend=mem -m 256M "); for (i = 0; i < vus_instances; i++) { From patchwork Thu May 23 14:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13671900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67920C25B75 for ; Thu, 23 May 2024 14:58:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9tX-0005Zj-Pw; Thu, 23 May 2024 10:58:16 -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 1sA9sp-0004UQ-36 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:32 -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 1sA9sm-00047X-1a for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476247; 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=4qTvP6lxIhuzEFJYH1iq7oEMz1Xbgzhb1MVJySeq+gQ=; b=Qtdq3f8MYy1K2TxgNiATrCqAm1J1YvjyCgtwudKi4vMJ4pTLCgGKMbpwCKU5SV1GEVuGWd ZysACbjf7bure5iv/djae2hG40mcisctfLJaK16FpqEYE46j5AhH4zwJIcjyP5YH0wCmDN /VherCTeXCYYD5ChT3VVhXPcMxEXsQM= 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-317-pHZsB537NzyHQUcHcbFddg-1; Thu, 23 May 2024 10:57:26 -0400 X-MC-Unique: pHZsB537NzyHQUcHcbFddg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-792bd1dc658so35998585a.1 for ; Thu, 23 May 2024 07:57:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476244; x=1717081044; 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=4qTvP6lxIhuzEFJYH1iq7oEMz1Xbgzhb1MVJySeq+gQ=; b=jIEoKZrlEynE6fSspqLo9QaPBdpCshvLjZHu0bQcDYHzAM/eqn6K7D/Q1jQEKVOFXT ypyabMwMfRR5A15dLH4jBMK2fHgvoRPaWQKVQAOEGf1JXP65vB0RZHLHc/XIDhyG0qho Cm/fusx4e9tegKPvRFWsHP4fAp02I25WtRfijpbuhz+mxXoxaEevPZQK6CA0dG6idKGS 6EFfHDJsLMSsQqaKtvGegUY+zJnPIIrkI1RIzxWOgLXYoKa8drIZOXdSf9mvMjK6QjUB 7RPLqZmR6e7sIKM8bhKmBsRLaLDe99OFattARPMeWAT1Cfsv1yYSmNqj81gtMP/sPRCZ zU5w== X-Gm-Message-State: AOJu0YwJrL35O7trIU5TNJihF7eu05QXRsrF7IUxDTapmzByIcwiXAh+ wLDnez83HYCxOalC6FbbIQaoKkJiTQKmmQ3DdJxynNqgCI6CHSLYRwc5poQbwvQYJYPOexkfLPI pRl0YO/Ow+0ZJFLWHW871/46e481GGl5SBHgNkDU0C2hOpZaYlfI4+M9j28J8YitbeZjEm8CH0o yPx+sE9EPNWA+FS9kePXGnY+g2hLBZXRHBH5m+ X-Received: by 2002:a05:620a:2443:b0:794:9a59:351e with SMTP id af79cd13be357-794a0a424b1mr439564085a.38.1716476244169; Thu, 23 May 2024 07:57:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHp1yk4jpZXBC7fK6rr6gmRwWPbVRC83ZwhgPHVBlqcc9fA+mWGWGswNg8LMwlL6pRnDDgiXA== X-Received: by 2002:a05:620a:2443:b0:794:9a59:351e with SMTP id af79cd13be357-794a0a424b1mr439558585a.38.1716476243673; Thu, 23 May 2024 07:57:23 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792db4083c1sm1185772885a.76.2024.05.23.07.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:57:21 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 13/13] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Thu, 23 May 2024 16:55:22 +0200 Message-ID: <20240523145522.313012-14-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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",