From patchwork Tue Mar 26 13:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604194 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 01664CD11DD for ; Tue, 26 Mar 2024 13:40:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp71w-00078B-S4; Tue, 26 Mar 2024 09:39:56 -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 1rp71q-00075n-0g for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:39:51 -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 1rp71o-0004uc-NL for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:39:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460388; 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=zQ/XWWXh4XW3dUXwm+qOVxK0ZPm+OgSJNqqiqFOv16A=; b=d5ZizVkSYJeK4Zxi8e0eYi6StV004fRj00ExexjPoWG5lciNdeBC9JcMssRccHoFyZ9wYa 9y4ibJz1Kr/ypWg6L7Be/hNy+9vHOGV0AhdQM1llYMsmNpr/84VxY9rcn8tpFgmvExP2nZ qtYozriNlP9LrlaD2wtNiKlBGmkMagA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-O9n9iaKSNLy1pVREdcM0VA-1; Tue, 26 Mar 2024 09:39:46 -0400 X-MC-Unique: O9n9iaKSNLy1pVREdcM0VA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-41407fd718dso30621605e9.1 for ; Tue, 26 Mar 2024 06:39:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460385; x=1712065185; 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=zQ/XWWXh4XW3dUXwm+qOVxK0ZPm+OgSJNqqiqFOv16A=; b=KwC6xEgNZfO6WUNrOi33ISbHmTDNxXOTxGCJmbYU0urSxXedcGZKonNbq69+IeTQdj 1eWhBrqZLrQIxa65AvyYwEzG1QrItZXWz6jkHOc0+TMx7HfyCiXpjgncPrxPYbPpTeHF am1JMHeutqH6yjDx4GRF8KK1/DFQ5xjSjLuRp06lCFqtoMa+dTxiuR6PcwbRaBlgR3ak dAGzua+dsJbqM31mtl2WugRXpcxOCIQ41OUANPQoTC3K7OlHwqe9pqLfU/CWf31uUaKb Lqy8iHmWzx7rs6Z8pmkldNS7gQYVN7u4ebA/IxAGYn1OAQ7+8gCrVPl4XwbNJf84d/gf 43+g== X-Gm-Message-State: AOJu0YyX8eZ2Aj9rhZlXdbtH+7MyDyh/mzPKz+v5AfgqVv6VZVWznnaB vPxFgbOX2vXKq1E36bdaEFoRCrpmNWZyybSELzyHqiQOoDyTW+lw2h3RasNH7jfeF5Vi9pGMX0N jlemPo0vabyCpGcJsuBC1v8vmgUiIrXREtcKXPdaQaZIqyGIj4uoVcZpysUw0OrEP8CTdDorP6n ftw7Y+OfkSsbNjA+WSgOQbJc+N3eQslk0UOFL2 X-Received: by 2002:a05:600c:3c8c:b0:414:7e91:a992 with SMTP id bg12-20020a05600c3c8c00b004147e91a992mr7110723wmb.3.1711460385120; Tue, 26 Mar 2024 06:39:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcuTVUAVz3+ongCHaVJuO2UGjdpPG6N8IXZQzaAYvQjIYxDMzFMO5d9D5hABaxiYGjmz9B3Q== X-Received: by 2002:a05:600c:3c8c:b0:414:7e91:a992 with SMTP id bg12-20020a05600c3c8c00b004147e91a992mr7110679wmb.3.1711460384636; Tue, 26 Mar 2024 06:39:44 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id d8-20020a05600c34c800b00414903d20aesm1169213wmq.11.2024.03.26.06.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:39:43 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 01/11] libvhost-user: set msg.msg_control to NULL when it is empty Date: Tue, 26 Mar 2024 14:39:26 +0100 Message-ID: <20240326133936.125332-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 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. Signed-off-by: Stefano Garzarella Reviewed-by: Eric Blake Reviewed-by: David Hildenbrand --- 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 Tue Mar 26 13:39:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604195 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 2DB4EC6FD1F for ; Tue, 26 Mar 2024 13:40:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72A-0007Ei-6J; Tue, 26 Mar 2024 09:40:10 -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 1rp71v-00078Q-Po for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:39:56 -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 1rp71u-0004v4-BV for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:39:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460393; 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=e0qQ06PVKFywP7ew4GM4yPpqWIJ6sbW+Ybg5PYCFH7A=; b=Gq5/dk0czLKZ2uTJLYJqzu5nrTgUlXjaWRJlblWrUDHGydplh9mvrsisO2y/mVVSlOjGRV zENUBu6qBH38iy0L4CKZbk+O6e3WJ5f7Ic7cp4Xu4NQMGArxe3tCdTVmPjxfDYUOtp0nyo 9RpOogz9G1PgIFL+tp7l+Z1wB9j6m74= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-Ao2HqfbuMgOC6Cxx5xRBUA-1; Tue, 26 Mar 2024 09:39:52 -0400 X-MC-Unique: Ao2HqfbuMgOC6Cxx5xRBUA-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d6ebaf2199so6059011fa.3 for ; Tue, 26 Mar 2024 06:39:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460390; x=1712065190; 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=e0qQ06PVKFywP7ew4GM4yPpqWIJ6sbW+Ybg5PYCFH7A=; b=Qpi0uhhWAYaCCWNFyecEucjiyfQdd1qvcAITH1mHB7ScvSRO2YVYmUaMunPnpYTr3T 3fQ10nIq3/2MUUXxGLIBqbIzP86c0WHf3HKeXOIT9Q8aXPAfqe0eDEceueKFK+rIt4Qq PdeNQgcwwKdPwbihnwIBBwXm9RARTfHjUHrZ0XLEXQ3Xkyeo/0rIfnZtcVJ84l6xirXe ImpZzuhPveId5i4PZP5iQukXnfyGR2BFwVpLaJKkLZsq2jDF1nNj5YJx5UUT+wPL0vo+ V+aFs/jKWV9JUZ89K1rSU+ZeEvWRVvPoGRHHksSFBQ1J+8wjxuT6GRxOUb5MeIaU98Uf j7wg== X-Gm-Message-State: AOJu0YwBZLEZQ/L0q6JpsitVoc1joHvo27Z2Ge6LGQ44kCSfYBJD6knK pyQUdLHi6lpPf8xrZhmynm0REzHK0Qit346kNLmfMDkuMB23RjStKWyiAfSXHEVijIqo7FHTxRr W1iNy07MFfLlmQyH0ixXCOsP5dA1P85QZAp52gq0XQavn9GjfVoxvBbzSa/6MjxMPp4f77ejcP0 TV/CLzLy3BF0GWOvNU8/efNZzZ+evlstw1Vddj X-Received: by 2002:ac2:5b84:0:b0:515:a733:2e21 with SMTP id o4-20020ac25b84000000b00515a7332e21mr1113572lfn.44.1711460390481; Tue, 26 Mar 2024 06:39:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXMeJVb9UNLsatjzLHXHQe7s0tIPjM0905G3cw1On4yVBwzqvNnkiZe3GmStKAhEVLe2/27w== X-Received: by 2002:ac2:5b84:0:b0:515:a733:2e21 with SMTP id o4-20020ac25b84000000b00515a7332e21mr1113541lfn.44.1711460389979; Tue, 26 Mar 2024 06:39:49 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id h19-20020a05600c315300b004147c8dd13fsm11603766wmo.30.2024.03.26.06.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:39:48 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 02/11] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Tue, 26 Mar 2024 14:39:27 +0100 Message-ID: <20240326133936.125332-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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. Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 22bea0c775..a11afd1960 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -639,6 +639,11 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) rc = sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc <= 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) { From patchwork Tue Mar 26 13:39:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604193 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 92DDAC6FD1F for ; Tue, 26 Mar 2024 13:40:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72A-0007Gn-UI; Tue, 26 Mar 2024 09:40:10 -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 1rp720-0007AI-9N for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:01 -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 1rp71y-0004vX-Vp for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460398; 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=ZpxLxEjZKPolHxK9jEBltREEiUiPHa29JLrUzO0K+0U=; b=Xx9PvlQMYlv4Rpa3qtl3wdo5lY1/0pbMqTsxS0VJTwBhnP9zkuuDUawvVrg4A8rXQ8W/DB poRG1m0saHM5JIrxlE0YjtMbagvXpnnBxvsgF/0dP4xJi7s9mWdeRDB/0dv+wqKvb5v9hE HL/W3QeUBTcjsjFwMcyA6Dz7j0Qj89g= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-FQeY9lvwOYizEE9S2MGk4g-1; Tue, 26 Mar 2024 09:39:56 -0400 X-MC-Unique: FQeY9lvwOYizEE9S2MGk4g-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3416632aeffso2894368f8f.1 for ; Tue, 26 Mar 2024 06:39:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460395; x=1712065195; 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=ZpxLxEjZKPolHxK9jEBltREEiUiPHa29JLrUzO0K+0U=; b=LAKZj5fcWLsHdyPEfmc9KoplNHWpfsLNGDB6oH5SG+Hp604xdKfdwI+Gyb3oalrQFR 04f35UTm4GZI/rsHZNwABH2Uz/ozzMlH8QXg3Zv6gaJHC/vJX+3S+pmpjFXjuIxFevpP Y+M+Qhye4p24Itp6Sfh6Mxm6Xi4Gi/IbaQ/XEnis4usR3XZl71EteElPmc/a3zR9R0ZZ +Kv7AU88c95F0X0Bl6Oh5/TxFgqx6tOUFpqHphli9Jw5r8878FrCMa60HKGrtt+NVOeh 9JexoixU6jacyTKxGAt6jx5Q0wBCCeTGx5QtLUfr+rnQiSXZsl9oOov8p4efntZz3FRr 0I4w== X-Gm-Message-State: AOJu0Ywom82LZGHk16+BAcl0qpzAFbfYrJmFnocoprqrDF3/OycUl0EZ xRkTIkSb5G/LMEREHHl1PhKMcPa7Ay6KxyUy74wd5CKatj9VphLgN/fd9/6xoyEQ4XB+dqanqu4 GsoyAjbmzSJbBwSwAmqBXVJgjC96pKztsIWOnmigfjKeMIhb9YVrpD0lYseHXQChAsXUinpGMUI wA0f9LFCx6nkahzUHH/bNt4r2GTY42X/9beHuR X-Received: by 2002:a5d:47cc:0:b0:33e:7f51:c2f8 with SMTP id o12-20020a5d47cc000000b0033e7f51c2f8mr1312641wrc.36.1711460395369; Tue, 26 Mar 2024 06:39:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsfbF75YQvyd3MpA4mQ/dmq+lcrj3CNMZvjVZRgsQYppIUmvrrcYLHzpdXAhGGlhaUPqUMsQ== X-Received: by 2002:a5d:47cc:0:b0:33e:7f51:c2f8 with SMTP id o12-20020a5d47cc000000b0033e7f51c2f8mr1312605wrc.36.1711460395020; Tue, 26 Mar 2024 06:39:55 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id t21-20020a05600c451500b004146e58cc35sm11706050wmo.46.2024.03.26.06.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:39:54 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 03/11] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Tue, 26 Mar 2024 14:39:28 +0100 Message-ID: <20240326133936.125332-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 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. Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a11afd1960..1c361ffd51 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1674,6 +1674,16 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) features |= dev->iface->get_protocol_features(dev); } + /* + * 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. + */ +#ifndef MFD_ALLOW_SEALING + features &= ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); +#endif vmsg_set_reply_u64(vmsg, features); return true; } From patchwork Tue Mar 26 13:39:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604202 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 82E59CD11DD for ; Tue, 26 Mar 2024 13:41:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72B-0007H6-8A; Tue, 26 Mar 2024 09:40:11 -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 1rp725-0007C3-OX for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:08 -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 1rp724-00057o-CD for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460403; 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=UGDk8t1Sssy5sr3pI6FPbTNJvoJDpa2GRLWLlgFnCCg=; b=UVjme058wOxU/fljnSmAdZZWT/i9etsyAIIm6ZNDTrvfKWmNi4N7qjKoox7xt61khD6eG/ 4RDt5jIRGQh8Pvm4aNaLvxqno+tLuZDvFXqn1tMYGmDO9mxcZa518BfmnQUZaa3cOuHMe7 58xHxwTNo517CgIkeEyzzPjc0zowh1E= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-p81ApJd_Orm_MuSPdfsdrw-1; Tue, 26 Mar 2024 09:40:02 -0400 X-MC-Unique: p81ApJd_Orm_MuSPdfsdrw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3417fa3f143so1322597f8f.2 for ; Tue, 26 Mar 2024 06:40:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460400; x=1712065200; 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=UGDk8t1Sssy5sr3pI6FPbTNJvoJDpa2GRLWLlgFnCCg=; b=iG8RuVAfmZH/WgrJtawxI/RB4/mVddR5eACuPEWCTPvaKcfesdjJgsZAofjTm/Z7Vo tKjlpdBDeL0uo+ghQO5fzXLDmKVriyG9JV0KReJcC7Lg3cvU89TJOx2z5WNg6zR99tJY vEWviHn9VQ8R7JYqKKVutbjorWEavgB7uCpbs3lTeRRzAQZD9Z3Q1Ge1YqmQrI77lfkx y46sMon9rUL2jvGxFZhbqLK3yI5uBv20rUGHgxPtgXAlQN6c4VT9ME0y2A59HAx2NG8H k7m78SzGihyCc13VcAWubX8RQNdmrm9DKQvvqnyDgmWQqquI3Z5IVQDIIR0Av9YqiWE5 w1EQ== X-Gm-Message-State: AOJu0Yxj7bvwKNkx1z7cxKmFTNzO/mc53TsQH7syLJWxuu6P2tLK0mkd zkyYghAh5LTKm8mDHAVVzAyrXrCk3ww7yO78eyTA4ZSsTCbDkNP3XNG9VYo5NILllJuIyJwF+sE I29w9aqmablDHzWigjyd+d+Btx7Q37ABRNXro1+ivAyPMVYlRhDShCbBjd5YRk5thDXEvUXyabL QVUPCASdQQU7NDaerRtLMCBfTKnHKqiOk/VY31 X-Received: by 2002:adf:fd07:0:b0:33e:7c3f:ee0f with SMTP id e7-20020adffd07000000b0033e7c3fee0fmr6615247wrr.28.1711460400441; Tue, 26 Mar 2024 06:40:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFImdrA8cehgHQjACL3IkcO9h+idapOlwMAutQ+pb3b6l8BdOECajlEwjWrV55g/onVxx/g8Q== X-Received: by 2002:adf:fd07:0:b0:33e:7c3f:ee0f with SMTP id e7-20020adffd07000000b0033e7c3fee0fmr6615209wrr.28.1711460400033; Tue, 26 Mar 2024 06:40:00 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id w6-20020a05600c474600b0041490d1cd06sm577179wmo.40.2024.03.26.06.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:39:59 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 04/11] vhost-user-server: don't abort if we can't set fd non-blocking Date: Tue, 26 Mar 2024 14:39:29 +0100 Message-ID: <20240326133936.125332-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 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.) if we fail, it's not really a problem, because we don't use these fd with blocking operations, but only to map memory. In these cases a failure is not bad, so let's just report a warning instead of panicking if we fail to set some fd in non-blocking mode. This for example occurs in macOS where setting shm_open() fd non-blocking is failing (errno: 25). Signed-off-by: Stefano Garzarella --- util/vhost-user-server.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 3bfb1ad3ec..064999f0b7 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -66,7 +66,11 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; for (i = 0; i < vmsg->fd_num; i++) { - qemu_socket_set_nonblock(vmsg->fds[i]); + int ret = qemu_socket_try_set_nonblock(vmsg->fds[i]); + if (ret) { + warn_report("Failed to set fd %d nonblock for request %d: %s", + vmsg->fds[i], vmsg->request, strerror(-ret)); + } } } From patchwork Tue Mar 26 13:39:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604201 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 07221C6FD1F for ; Tue, 26 Mar 2024 13:41:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72H-0007VQ-OI; Tue, 26 Mar 2024 09:40:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rp72E-0007RV-FI for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:14 -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 1rp72C-0005Ab-7m for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460411; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QKw7wwOpcT5LAk2fX9NUDEtqgiO584+Et0vV37YJJRo=; b=MElvr9m0N3+DzlPFs+YmV8FRcT2WHrHJQa6J2t6xbHXZY4hL2t5asUVxN5klurNkwtAE9Y 2Tp3HCkPITXmUdbddrHM5MyL91SElsUyKiYjuMhEbNVME66xu5Qht+yqWBgNDCRGRhwMnu Pee14tE5+QwKhldPDHwqGTHZE/duJpI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-O-WKnm5sPqmSkwwk8aQm3A-1; Tue, 26 Mar 2024 09:40:07 -0400 X-MC-Unique: O-WKnm5sPqmSkwwk8aQm3A-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3418f237c0bso2807342f8f.3 for ; Tue, 26 Mar 2024 06:40:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460405; x=1712065205; 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=QKw7wwOpcT5LAk2fX9NUDEtqgiO584+Et0vV37YJJRo=; b=QnU90EDVz6179UiZNINlVOc9zyjfewbLB+qz0Y4umfAS2AEgQZPrE3zeuvWV9YSffb H7zPQD3SmFw2691YEjpHftd88VVHHCs91q99s3KgaYDteZkc/iRe4v7G+CMDVUKV/wse JLfMqOr+rnLi+B8GBo3Q1oU5+uk8QkvI5XG8ez8ZQ0FLBztDm3t+jYy2FwhqLtw7CD/F neafRngV0A0JN906xlx1eKPnUzD1c8E7JOUGjM5N6ROJz7WMrCkpEcKbRz5p/Di4e+4k Prdopt9dsHYGpH29JBi9N+h5bclejDvZK5dmCQhDiP+ndkHuyFcJZeJWSs2hggCAvcid suCg== X-Gm-Message-State: AOJu0YzViYGBIyLLiKCkD3GTVXg5bX3vEbHE33CyBbjIQZx2iyJ2oqAm bn3gz3VfD1CLPYaFijZwuAtEpYwNWOxV9XLK3vrQYtsT3X3jAe3ExiRnlMZray6KhueSMtvXDWA F9aLgxde/pUgmeUJy/826Dx7sKUCDgeLe+lUFP4xp9CeAFOrDe6oAlp09bJRRX3MhG4tAQtRWJ5 ROaoyjSKQM3nxCBYvVoiSrN0IFswlNoQ0d4PLm X-Received: by 2002:a5d:6e88:0:b0:33e:bf11:a007 with SMTP id k8-20020a5d6e88000000b0033ebf11a007mr1015446wrz.31.1711460405408; Tue, 26 Mar 2024 06:40:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtcEO0M9lq6C75Hqd6uCy0EDmER4gQXhoRzLyt0r3wluU94R3XlnCfYqFXYdF9WX/VBCfkVQ== X-Received: by 2002:a5d:6e88:0:b0:33e:bf11:a007 with SMTP id k8-20020a5d6e88000000b0033ebf11a007mr1015413wrz.31.1711460405139; Tue, 26 Mar 2024 06:40:05 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id t13-20020a5d42cd000000b0033ec312cd8asm12230707wrr.33.2024.03.26.06.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:04 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 05/11] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Tue, 26 Mar 2024 14:39:30 +0100 Message-ID: <20240326133936.125332-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.001, 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 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. Signed-off-by: Stefano Garzarella --- contrib/vhost-user-blk/vhost-user-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 89e5f11a64..a8ab9269a2 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -469,7 +469,6 @@ static int unix_sock_new(char *unix_fn) { int sock; struct sockaddr_un un; - size_t len; assert(unix_fn); @@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn) un.sun_family = AF_UNIX; (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); - len = sizeof(un.sun_family) + strlen(un.sun_path); (void)unlink(unix_fn); - if (bind(sock, (struct sockaddr *)&un, len) < 0) { + if (bind(sock, (struct sockaddr *)&un, sizeof(un)) < 0) { perror("bind"); goto fail; } From patchwork Tue Mar 26 13:39:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604197 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 4638ECD11DD for ; Tue, 26 Mar 2024 13:40:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72N-0007fi-2B; Tue, 26 Mar 2024 09:40:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rp72I-0007a2-WB for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rp72F-0005BF-9V for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460414; 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=ZLHU20NRBQ76xezXp9bkU7y0kQWcZN7heXquiWWVeRM=; b=NhBVH5LOrSdU32m/T4fTKJLIMi8+++RM1y7Fj2FAD0Ts2yUBrwuHyWgCNFfFZ0b+gdVHS/ sDyBmGN8JzC3n7uBR6JdF0SiwAKgjnTYWWcmbeJVAeWqwCbfVbr7ARmynbK3dtfQrXvgvh DbqxWdxH/+2cGezIiWQTf2TZtRbRh9c= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-qEiSwiSRMAurawsKK9DbKg-1; Tue, 26 Mar 2024 09:40:12 -0400 X-MC-Unique: qEiSwiSRMAurawsKK9DbKg-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4147e733d20so16595045e9.1 for ; Tue, 26 Mar 2024 06:40:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460410; x=1712065210; 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=ZLHU20NRBQ76xezXp9bkU7y0kQWcZN7heXquiWWVeRM=; b=GeepkuXlKhQOFWKcPRKjo/hUcLq/Od7SUKYDlkVxLP37xmwVH8M6isXkeS0kJ4YHwZ MUnuKjo52FXz2SwCqfcyXv/n77DPAzGduTSchLZANQGzsPfxzBkVHe1L+7t0KnVBDK2g NlOfs+WkvwXU0idnacPMGV1tSxQjXBAgFBMHd5mhGOMr8VMmB3OiGfXNmMfkio/w5B8b MJ8bwMOKDqOA9RIGROcSOJnT974uYf8ts+q9TY7VPj88+4TmB9jgUBy+iJHCFrInRTq5 H/tmM+IfjHmGaNmqhTX1VeUvPYFXuyV0C75l3Yy+P1H85JJ+IOReNttYhLt1mNBio0jU deig== X-Gm-Message-State: AOJu0YyPqevpufPWzl1Le9phBrjCjrysxlGtLNWImFx7euhB8IaWvGCH AtBQHVIxkjxcyCr6H+v+Z4JBoBfKJpkeCIfizBcpVSv4OlaygcSjpl+ihCG7gUvjKoFyO3lP+eP oirlP6Xb3IhthskjeAp1KxSU/d3j/V6X6JyoMvkiAyqXlntyTt65HbI85C2xgDghbttudNrMO9Q n4Mw3JZoUh5AIX8v8WpZRGSdP8TgDQLuCBZ4za X-Received: by 2002:a05:600c:1f84:b0:414:80c0:d352 with SMTP id je4-20020a05600c1f8400b0041480c0d352mr7884414wmb.23.1711460410522; Tue, 26 Mar 2024 06:40:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvK8Z+IcoZI8+ejYdJnPU9jAHSxe72Y/bKpOGH6fRPBbYkySktCd2ZmilnC6fQc8G6bgJS7w== X-Received: by 2002:a05:600c:1f84:b0:414:80c0:d352 with SMTP id je4-20020a05600c1f8400b0041480c0d352mr7884374wmb.23.1711460410212; Tue, 26 Mar 2024 06:40:10 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id b22-20020a05600c4e1600b004148ff6ef54sm1318659wmq.29.2024.03.26.06.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:09 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 06/11] vhost-user: enable frontends on any POSIX system Date: Tue, 26 Mar 2024 14:39:31 +0100 Message-ID: <20240326133936.125332-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 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. Signed-off-by: Stefano Garzarella --- meson.build | 1 - hw/net/vhost_net.c | 5 +++++ hw/block/Kconfig | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index c9c3217ba4..c19d51501a 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 e8e1661646..b8a59b9e90 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 Tue Mar 26 13:39:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604196 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 BFBBBC6FD1F for ; Tue, 26 Mar 2024 13:40:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72T-0007qN-2B; Tue, 26 Mar 2024 09:40: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 1rp72M-0007fG-Pg for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40: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 1rp72K-0005Bf-Nm for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460418; 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=7su9FVCHZgY5W4CseWaTDVux0tjQnk92YCDB/2U9JF8=; b=Hysc5W/1w9oaVfJdto3MzDFnHSlL4cly7f1fxLTC19x1rGxCoD65wWHRMis0mOLc/rFnce BqcBjevfBg5Pe37dT2OEEmT7897XVs71V8PfgC+OCXeomNKTN//hRGvE02xj06DHucuGHr Y7X7tGXouk01V6QoyKrcd44JmKo7cqU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-f6KyqsNfNKK9lYpI3W0gmw-1; Tue, 26 Mar 2024 09:40:17 -0400 X-MC-Unique: f6KyqsNfNKK9lYpI3W0gmw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-33ed2555b61so3025951f8f.3 for ; Tue, 26 Mar 2024 06:40:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460415; x=1712065215; 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=7su9FVCHZgY5W4CseWaTDVux0tjQnk92YCDB/2U9JF8=; b=FAaQ2FpKGUzmBxNrH783LqlZv/72EaIXFTm1AoV3Re4p34OVQ3L3kaZvHVtV/4eVWc KNuqB4ugYf5NvwpRXw9x4LqypUK1MH5OQz8rIJr8LxW2hwZOXkc1HLRD3ailoOqeELRw AWAgrflTczIWkxgqnXULUYEcLOZWYYbiQwgCnnVxImKFNc6q5hfDfA7PUK/eahKi3qO+ Uy5C70sPsJkAe0BBsL4NYwNYZxYZtmtdoe57Ks4AmjsXxi6VBbkdH8BIa5Y0LvFRxCoL tbSocF8Dpp56EuneOLQgQyr89bwj0PlDaj6fDPzOR4Fc03BQSIkEqrXp8QX72i3NjUhT qItA== X-Gm-Message-State: AOJu0Yzg/5xFes76A007YKbFUGJCLMnXgMwyj5rIkrMlbOnzsFviMFMU KXIDVb1CfhCZqsn2vaHogIBiFkamg7UG0NBGYhqJwjpsr/K0Bh1MiaLjh5fN1NpUBe/lg8/+Dd8 HVmGFOI3EYn2lcUGjzXtOKagfET8DYx8Ckituw4if/ryKWIbyK5x1zQD3TY3ZfQ4qLwx7ik9f+G sAvpDtX+BR1vZGYcygc601RCAcyZbhcovib+yE X-Received: by 2002:a05:6000:151:b0:33e:c03e:62 with SMTP id r17-20020a056000015100b0033ec03e0062mr1222115wrx.40.1711460415515; Tue, 26 Mar 2024 06:40:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+vrtdSqfVW5LepjfmQo0yObYwg/nk6kHX4OepH3ROAphzNTgzs2wlRG59CBc8zYpMOEDBPg== X-Received: by 2002:a05:6000:151:b0:33e:c03e:62 with SMTP id r17-20020a056000015100b0033ec03e0062mr1222081wrx.40.1711460415232; Tue, 26 Mar 2024 06:40:15 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id bu14-20020a056000078e00b00341d2728e02sm3688526wrb.37.2024.03.26.06.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:14 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 07/11] libvhost-user: enable it on any POSIX system Date: Tue, 26 Mar 2024 14:39:32 +0100 Message-ID: <20240326133936.125332-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 avaibale 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) Signed-off-by: Stefano Garzarella --- 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 c19d51501a..3197a2f62e 100644 --- a/meson.build +++ b/meson.build @@ -3194,7 +3194,7 @@ endif config_host_data.set('CONFIG_FDT', fdt.found()) 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 1c361ffd51..03edb4bf64 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 Tue Mar 26 13:39:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604198 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 1E1ADC6FD1F for ; Tue, 26 Mar 2024 13:40:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72W-0008Bp-P7; Tue, 26 Mar 2024 09:40:32 -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 1rp72Q-0007qE-RE for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:28 -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 1rp72O-0005CP-Gm for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460423; 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=hUBleTHPhrTzw3WOX5ng8C0tTB6CO+fZECbVOwKbaZ0=; b=VaOV40AOh0pZ9wTldhwKRjm6FlZbi0/FgDNGzxQGz3H8B1wnPMHJMdAQ+l/yaf+WOB7Mq2 /rDkORyiyJZ6/HYEGmzdpwmUlTJLitj7emBdJRZAq/g91vVTz0Dx+pamg9RPXvMEY0rhC+ sXZNjmAoL4rq5QbsPTcq0NSV4Ypi7Gw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-1Aldew32OyiTOx_q3Zm5zw-1; Tue, 26 Mar 2024 09:40:22 -0400 X-MC-Unique: 1Aldew32OyiTOx_q3Zm5zw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4147faf154cso15296575e9.2 for ; Tue, 26 Mar 2024 06:40:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460420; x=1712065220; 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=hUBleTHPhrTzw3WOX5ng8C0tTB6CO+fZECbVOwKbaZ0=; b=t3UtzpgjTQKgXEhuq4BN1IOd2B4apLVB1aYXYkmFflb5B44BFcT+cgD253qNkLV2vL vcwsfvnZUmX9pvxJpIlQ94hAdsibeF5K+nEPT9gvLGhayrThQFkdAxiT/Ti2LBY5k5vW WJiNixoMlyQ7rG7+2psus7TKIhybXfzj4fPhUdCHnVVWrUCXvvxjYtNxbdr8qZwf5C3W 0EVkg4LPJvxhMSEdxr3nAMM8gASOOhWK+fT0ebKGEea3YOEWMHGxtbTJsVv5QlYtaNBe AA2WC6b/AE8Nydo0xg0rMoSuO1oXm7LhG6LZzi6E/bKWe7FJ8MezDECqGx9Bhj2CHLfj Qf0g== X-Gm-Message-State: AOJu0Yzkaaqe+fGxK40ivhZsJaxlIfFFuzK2Iuf7gxXZsBFPfGpQT7LO mZueP3fH8Y24lweeOg08ixk3ldDOvlGNyw/2H3hh1N/T3Rlvm8D511M72Vdt6l7Zi7eqaH7s3XP uKFZ2AuPCDGFOvjqOU4LTXu8xVQFO08EiqUWp9iYUDswy0j31qC03Y/NxYRM1H5o/p3QQor2uXc RE3Z7FOe+M/pQPEpI4lGc77FdW3Jmv8s5pzDWm X-Received: by 2002:a05:600c:20d4:b0:413:f75f:98b6 with SMTP id y20-20020a05600c20d400b00413f75f98b6mr8041019wmm.26.1711460420417; Tue, 26 Mar 2024 06:40:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENBCYEnyolENDPrD0XLGY8+imkwQqrI2doLTdNAeye59lPXhPiOafM2isJnWFNkIdtw2KQMA== X-Received: by 2002:a05:600c:20d4:b0:413:f75f:98b6 with SMTP id y20-20020a05600c20d400b00413f75f98b6mr8040976wmm.26.1711460420068; Tue, 26 Mar 2024 06:40:20 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id n31-20020a05600c501f00b004148bfe1b37sm4125385wmr.23.2024.03.26.06.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:19 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 08/11] contrib/vhost-user-blk: enable it on any POSIX system Date: Tue, 26 Mar 2024 14:39:33 +0100 Message-ID: <20240326133936.125332-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 Let's make the code more portable by using the "qemu/bswap.h" API and adding defines from block/file-posix.c to support O_DIRECT in other systems (e.g. macOS). vhost-user-server.c is a dependency, let's enable it for any POSIX system. Signed-off-by: Stefano Garzarella --- meson.build | 2 -- contrib/vhost-user-blk/vhost-user-blk.c | 19 +++++++++++++++++-- util/meson.build | 4 +++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 3197a2f62e..b541e5c875 100644 --- a/meson.build +++ b/meson.build @@ -1956,8 +1956,6 @@ has_statx = cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', prefix: gnu_ has_statx_mnt_id = cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', prefix: gnu_source_prefix) have_vhost_user_blk_server = get_option('vhost_user_blk_server') \ - .require(host_os == 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user support') \ .disable_auto_if(not have_tools and not have_system) \ diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index a8ab9269a2..462e584857 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" @@ -24,6 +25,20 @@ #include #endif +/* OS X does not have O_DSYNC */ +#ifndef O_DSYNC +#ifdef O_SYNC +#define O_DSYNC O_SYNC +#elif defined(O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +#endif + +/* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ +#ifndef O_DIRECT +#define O_DIRECT O_DSYNC +#endif + enum { VHOST_USER_BLK_MAX_QUEUES = 8, }; @@ -267,13 +282,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/util/meson.build b/util/meson.build index 0ef9886be0..f52682ce96 100644 --- a/util/meson.build +++ b/util/meson.build @@ -113,10 +113,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 endif if cpu == 'aarch64' From patchwork Tue Mar 26 13:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604199 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 A4991CD11DD for ; Tue, 26 Mar 2024 13:40:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72a-0008LT-DD; Tue, 26 Mar 2024 09:40: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 1rp72W-0008Aa-IF for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:32 -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 1rp72U-0005FV-FF for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460429; 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=RTpxY9sVKAa1TjG2Q5l8JHWOtdy2byARIHISthkoJF8=; b=DlLlYu5KqpvwyB1OAf/VoYZGE1mFfeqz/avmTXjhDcfdtM4XErxO6e1FOq0exBu/uUrlXT PBGgCymN1FW47fafe0mNkgksUY9L4mbK5MPUO3euHtFtQySGlkVJs013tBSG8yFMk4lSCw qlsLnwD8c3oXRJdLs9/3kNQ1hb+oSUM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-QWhaZxV3NX6awBu4Z9O6Tg-1; Tue, 26 Mar 2024 09:40:27 -0400 X-MC-Unique: QWhaZxV3NX6awBu4Z9O6Tg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-414913bd7c9so229885e9.2 for ; Tue, 26 Mar 2024 06:40:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460426; x=1712065226; 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=RTpxY9sVKAa1TjG2Q5l8JHWOtdy2byARIHISthkoJF8=; b=AqUKKH6O1EzP7dAj5bZ9UGS7cSoGi0klh5LjtmLGFYhpQ6OGR3jib1ycgkll1VX++Z b3TCo7TKTedpawV/lfXO89Y+x4g9oSBQ7V9x4M6KoGzczuA5uGnRlnQ71IdGrTg2MuqN iDxmuI6xo1k1d41Ztw/xROgRviSZM1WU1bMvC0yqnxB7SpJH9Do3yGv2S0fN1BuXD6fO 5wzGS+Lhtf08W7/PjrxZQDRDm6sElOsXpGtos4nt+cgkR1X6CCeE6XykQQQwDn3mdXBl IgeHY/ZB52d6xL2RtF5vIM4ylVZN20jYNwCIU1Tq84L0isohjSWg556Hnyq5+njreOl/ PdaA== X-Gm-Message-State: AOJu0Yyxne0NXceH4AwsVNiX9EuwxEj7JVoHY6yXexnGBITzSd8uENrl /E4VXx+FKF3x71MxsSrXEm2dLXJ7h2gi80ZVRIQMewPoUxKYOtNAGFl9jqHUQcywHR44KSatnG4 W4nYd9rypIfE8IrVPo5eXuAVOCxmAfa1EWAaG7EYyWJ7lD0DVESpds+q9ryPwyv7x6AZy+BLE8u 9GVlU3Xi1at1/pZN5475eT1+gp6PFyg2ylWxGv X-Received: by 2002:a05:600c:474d:b0:414:9048:40ba with SMTP id w13-20020a05600c474d00b00414904840bamr881450wmo.0.1711460425738; Tue, 26 Mar 2024 06:40:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEiqc4JKJHmFMgiyD0X5TC8bFNQF9HaL+UGQuWpamWW6UgXsYMD4fOS0qHNC8VBbVUNd6BsA== X-Received: by 2002:a05:600c:474d:b0:414:9048:40ba with SMTP id w13-20020a05600c474d00b00414904840bamr881410wmo.0.1711460425329; Tue, 26 Mar 2024 06:40:25 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id g9-20020a05600c4ec900b00414659ba8c2sm11794460wmq.37.2024.03.26.06.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:24 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 09/11] hostmem: add a new memory backend based on POSIX shm_open() Date: Tue, 26 Mar 2024 14:39:34 +0100 Message-ID: <20240326133936.125332-10-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 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. Signed-off-by: Stefano Garzarella --- docs/system/devices/vhost-user.rst | 5 +- qapi/qom.json | 17 +++++ backends/hostmem-shm.c | 118 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 10 +++ 5 files changed, 149 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 baae3a183f..88136b861d 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -720,6 +720,19 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# The @share boolean option is true by default with shm. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { } } + ## # @MemoryBackendEpcProperties: # @@ -976,6 +989,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' }, @@ -1047,6 +1062,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..7595204d29 --- /dev/null +++ b/backends/hostmem-shm.c @@ -0,0 +1,118 @@ +/* + * 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 backend with size 0"); + 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 = backend->share ? RAM_SHARED : 0; + 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 7fd1713fa8..70fa98ba19 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5230,6 +5230,16 @@ 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). + + Please refer to ``memory-backend-file`` for a description of the + options. + + The ``share`` boolean option is on by default with shm. + ``-object iommufd,id=id[,fd=fd]`` Creates an iommufd backend which allows control of DMA mapping through the ``/dev/iommu`` device. From patchwork Tue Mar 26 13:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604200 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 860F5CD11DD for ; Tue, 26 Mar 2024 13:41:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72b-00005J-PV; Tue, 26 Mar 2024 09:40: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 1rp72Z-0008LW-P5 for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:36 -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 1rp72Y-0005Id-EJ for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460433; 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=c2fIVWILzKzQaFbqxYLTu1zrjB/5hVEGYyQqHDi9HUo=; b=Q4eFfIxbBMCroOLdMdb6Xya7ej1+3K8UmxpImQxjpE9CMJD+GVDdUBOJzgvlf+/O9BdqqN kBJuJK1Wz4Wz0SwQKJSUYLsjMMxWsonB5nTXc4SuLB8EveBphR/BtT0IadYFT8jT3P+gAk 6RMr5eQlI9zyhWxI6iq2igqHOdhOmJg= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-142-PpOBSzWqOt2OL9sFGSz8wQ-1; Tue, 26 Mar 2024 09:40:32 -0400 X-MC-Unique: PpOBSzWqOt2OL9sFGSz8wQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-33ed44cb765so3110952f8f.2 for ; Tue, 26 Mar 2024 06:40:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460430; x=1712065230; 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=c2fIVWILzKzQaFbqxYLTu1zrjB/5hVEGYyQqHDi9HUo=; b=gpVIiyWRJPoepQRJ6uGnOWChugYzheYByP5qGw/DvK0RUknR2HY46OmAtcHfg54yD0 Iw7cKuNBcUgHGnnhzl8aGiur0NKPIAcwQR2I6fkcivR4S3INsC3ZAfiW9RT4XEvrA5Cq 67++Dn8BgHyferto+rpGnkruepmWbZ65bmJ8+xwh+GtHIaIUfxSCX2Nv8yH6vM+HyhAR v9Q7woP/fZpcHQKMPHO5nBk6JULmRu3eYo+qm1mJB/5Mop7+8wJPT/ZCoDkCOgG/m++I RBRoQkbBUDTVDKYU1RdoYt24dWYH0CvCjVHq+aYtxJDZt5NP1XjFPdbeF0OlmaQua9mw 7IDQ== X-Gm-Message-State: AOJu0YxH4ldRvLLL6yWFaQ6kWuLg5w/m0X1xuFSwG1PPv7SciwcROatR oBxYPBT9xwqIQCDmTGVmp+uNV1tb3x5F3NTfjTXOV4edwTmwOiugINmmDsbDOmwLkt8VId0qmoC 5Zrho2XCdzgGt411qZ+e4NDVLFE2NUPNILEeO6tPwchmCD2JuvsXf8U/Ia5xBlaZ4j6udyOFbDF RXKCQuzaDW6i7n+eaBzvJoAPKHrHWEuHSY9dwt X-Received: by 2002:adf:f247:0:b0:33e:c3dd:3fc5 with SMTP id b7-20020adff247000000b0033ec3dd3fc5mr6749438wrp.42.1711460430652; Tue, 26 Mar 2024 06:40:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5Z0TWihqlQsjKToAKPi7u/YUyF0V4G4uV9X6cLYYr9d0KldAmFZOrU0VUNULbb4LjtEUKpQ== X-Received: by 2002:adf:f247:0:b0:33e:c3dd:3fc5 with SMTP id b7-20020adff247000000b0033ec3dd3fc5mr6749404wrp.42.1711460430330; Tue, 26 Mar 2024 06:40:30 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id a13-20020a056000050d00b0033e239040d8sm12211009wrf.84.2024.03.26.06.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:29 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 10/11] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Tue, 26 Mar 2024 14:39:35 +0100 Message-ID: <20240326133936.125332-11-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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-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. Signed-off-by: Stefano Garzarella --- 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 Tue Mar 26 13:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13604203 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 26ADDCD11DD for ; Tue, 26 Mar 2024 13:41:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rp72l-0000MD-2r; Tue, 26 Mar 2024 09:40: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 1rp72e-0000Ak-SJ for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:41 -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 1rp72c-0005JS-SK for qemu-devel@nongnu.org; Tue, 26 Mar 2024 09:40:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711460438; 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=R1WyM23yZC7OHPkKjODH8U9UyVky6gI6o4OQy8pzYy0=; b=XamxSrbcknmMXynymWXWyABJZj7TakuW5QmNvWlJqz/CavAV+ubwzBHC9HSWY2J4tNaqhO O6PSyUgf8Y4yZspUoxsoXMTFkVcuaXMYeSFhC4DeUjA5FsJcyOHrFSbW3P98oPSGJWv9Yd bVIR+u+NYOKmDxjzdJ4SAp1byyF0jQE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-8z9fqjWCM8GwDTBYOpJULQ-1; Tue, 26 Mar 2024 09:40:37 -0400 X-MC-Unique: 8z9fqjWCM8GwDTBYOpJULQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-33ed26afd99so3028542f8f.0 for ; Tue, 26 Mar 2024 06:40:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711460435; x=1712065235; 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=R1WyM23yZC7OHPkKjODH8U9UyVky6gI6o4OQy8pzYy0=; b=f0E4enwhPh+w9beyppVAQokkr37oXyWy9lbX4xx5oWWTxC4SraNYXAsSIeYffNujVe eoEEUrjD4XNLh13U5JW7zUh4J/dPdEEwr9lpvIeSCEuLa5xaPvUhCbvJSkhlia/ENYKX bjmRCxglilQDR36Y6lGGaEQCbyI8JUEZ7bubf6MJV16SHtZjZmOg4wHe7iPNv4oiYh8M NNuePueOdfbeyEfTN1it2tk/koVnguY4glsrEVjqNxwqB3ldE57Ma0ci6/AlxFwaesM+ 4Iy00zi5TiVsEAusbneYaXNwr6usReJUTbffcMg9Zx/7hY9BkGN/a/Li1y1SU0cax4+K uprQ== X-Gm-Message-State: AOJu0Yx63Bn4mwQMhPfJ28ergx6oOVrt/fCK5Qs8xKEfC5paIRmTqWDe tN/liONg1XdqA6eTdimEvvcM+1OmDXXfgdyTNWwfcb+vW+LK+ZpQMtRNIUPtEDNC0ImP0VHCPCB z0isr7v+WwB7H9WVra9NoiKhLi7h/dj2gj2yjX/JHryu82CfKvbxQLqOVol+1HDCHvPQ1V3/lA1 0AWxKNJLlIRWsvd3NnzQPka6AGUzBcLCIYhMzw X-Received: by 2002:a05:6000:183:b0:33e:9292:b194 with SMTP id p3-20020a056000018300b0033e9292b194mr6738439wrx.14.1711460435542; Tue, 26 Mar 2024 06:40:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6mIgSTpyQ0Km2N2hF7JemQsv6sAt7ZdtszCF106i+8SR/HsHHnFwygvRT/znoxYpamVAOfg== X-Received: by 2002:a05:6000:183:b0:33e:9292:b194 with SMTP id p3-20020a056000018300b0033e9292b194mr6738407wrx.14.1711460435268; Tue, 26 Mar 2024 06:40:35 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-33.business.telecomitalia.it. [87.12.25.33]) by smtp.gmail.com with ESMTPSA id n10-20020adfe34a000000b0033de10c9efcsm12194551wrj.114.2024.03.26.06.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 06:40:34 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , gmaglione@redhat.com, Eric Blake , Eduardo Habkost , Hanna Reitz , stefanha@redhat.com, Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mammedov , Jason Wang , Raphael Norwitz , slp@redhat.com, =?utf-8?q?Marc-And?= =?utf-8?q?r=C3=A9_Lureau?= , David Hildenbrand , Laurent Vivier , Markus Armbruster , Thomas Huth , Brad Smith , qemu-block@nongnu.org, Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Kevin Wolf , Stefano Garzarella Subject: [PATCH for-9.1 v2 11/11] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Tue, 26 Mar 2024 14:39:36 +0100 Message-ID: <20240326133936.125332-12-sgarzare@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326133936.125332-1-sgarzare@redhat.com> References: <20240326133936.125332-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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 `memory-backend-shm` can be used with vhost-user devices, so let's add a new test case for it. Signed-off-by: Stefano Garzarella --- tests/qtest/vhost-user-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index d4e437265f..8c1d903b2a 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -44,6 +44,8 @@ "mem-path=%s,share=on -numa node,memdev=mem" #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ " -numa node,memdev=mem" +#define QEMU_CMD_SHM " -m %d -object memory-backend-shm,id=mem,size=%dM," \ + " -numa node,memdev=mem" #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on" @@ -195,6 +197,7 @@ enum test_memfd { TEST_MEMFD_AUTO, TEST_MEMFD_YES, TEST_MEMFD_NO, + TEST_MEMFD_SHM, }; static void append_vhost_net_opts(TestServer *s, GString *cmd_line, @@ -228,6 +231,8 @@ static void append_mem_opts(TestServer *server, GString *cmd_line, if (memfd == TEST_MEMFD_YES) { g_string_append_printf(cmd_line, QEMU_CMD_MEMFD, size, size); + } else if (memfd == TEST_MEMFD_SHM) { + g_string_append_printf(cmd_line, QEMU_CMD_SHM, size, size); } else { const char *root = init_hugepagefs() ? : server->tmpfs; @@ -788,6 +793,19 @@ static void *vhost_user_test_setup_memfd(GString *cmd_line, void *arg) return server; } +static void *vhost_user_test_setup_shm(GString *cmd_line, void *arg) +{ + TestServer *server = test_server_new("vhost-user-test", arg); + test_server_listen(server); + + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_SHM); + server->vu_ops->append_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); + + return server; +} + static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *alloc) { TestServer *server = arg; @@ -1081,6 +1099,11 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); + opts.before = vhost_user_test_setup_shm; + qos_add_test("vhost-user/read-guest-mem/shm", + "virtio-net", + test_read_guest_mem, &opts); + if (qemu_memfd_check(MFD_ALLOW_SEALING)) { opts.before = vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd",