From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120928; cv=none; d=zohomail.com; s=zohoarc; b=Yyocv2BM9lRIJQgnlWQx0Rj1guB8XNK8dYDSV1dTu61ICWDfCjWiZ/zTHkCJyfDD0p5cBPrB8NxO9POHc1kl0+PJhxx+SOJ9O4hPbbRSuESwwaF9HIVoqX2lXGMG8ba7FTHU5/SkvIUp38TeiPfybfUaPl7h+NcTxspUE+X8Pcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120928; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1MgJ0yPm3ToTqOR/tn/By3XWvH0ZNAU51N+FqVYYj+A=; b=IpIxkC+YoSx6t2EoWTsVza73piobygxlhh+2Gi8hrYHuA5isbF6rDUpxIxgYZJ2+FGP6/W+xWY3PH3CldGQNW6PGRfW4zg2CykKkdvvJ+mabTmZ2Y6ZmLXipGM4JDA2ZYXrIB6KDp52+UCclBAouhckvfquVaD2mFvJ0opY2AxY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120928038699.720978327009; Wed, 28 Feb 2024 03:48:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQR-0002Rd-QV; Wed, 28 Feb 2024 06:48:39 -0500 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 1rfIQ9-0001yt-KW for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:24 -0500 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 1rfIQ5-0002yB-Hl for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:21 -0500 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-48-bub-RQRTP4Ge1EjB9H71Pw-1; Wed, 28 Feb 2024 06:48:14 -0500 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-68facaf1c37so63772696d6.2 for ; Wed, 28 Feb 2024 03:48:14 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id og17-20020a056214429100b0068fe3170b0esm5168982qvb.11.2024.02.28.03.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120895; 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=1MgJ0yPm3ToTqOR/tn/By3XWvH0ZNAU51N+FqVYYj+A=; b=NTUCzFSBeENMQ0pw1IpyjPUIIMJuqu74x0lCZBjjLq7Xt+MYEplaWl7gd8o9UWGFHfephI wDKhbUmqhhFz+L9zyQDrW/eDxm1NcSc/J7ZUWGVd6rfGu7GBZVPzGYvKjV7cuS1N1CMo0A ropuwsX/s/MY6FuOYPc2XLJ67DK7H3A= X-MC-Unique: bub-RQRTP4Ge1EjB9H71Pw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120893; x=1709725693; 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=1MgJ0yPm3ToTqOR/tn/By3XWvH0ZNAU51N+FqVYYj+A=; b=eQayJ3l2ojGJXXWglfbA8E28xy2jHdbYDY2gMomvRfWHFPe2oknbvTFNT0IrPhudkR UgarQlMrfaLL1gfhm6QULxfvt9EEIHooT4kICMUuMCP42tRZNkjIbmZD6l0dxrJUSF1R kBcnDlcDPJL94QJytsCA9yosY85xeoqaLpR+VZtgwxGySeHg+fgU4roXxjD85abmfVaz hjYZKAdhD1sXkvqWom1WzQYMMI409MXkg8OVvQWSm1NWxYJNEUeFVLCdmBnOCh7ybVfV 9Q+d99djd3RD7HTf28++I+F1OBaFQ+lm/jy4sRQHHMtJpr4pylVQuYJYDuXHtqy88Sw4 JozQ== X-Gm-Message-State: AOJu0YyA+g7CrWvEDUcqNKk7NAxVFIN4+Rwwc5/BFNhmOVldMJ/Ra8wO i3I9MhuMhHzDx9/2bh6LftujpE6g8pkyOCqpXjJmeT3+5ZGbEhjrl82ZnG1AwlY5aZmu14ruuAG ngqyGIkztRLSr5mXdry5NZxtJlY0WnMK5TA3LLXptjVy/a1BroX21aa9lA0U3iru6HYrDgIdNlc 9Rzv2u3mvuMIr2CScTqi5sGoi+QB7QfyEANHhQ X-Received: by 2002:a0c:b55a:0:b0:68f:3a7b:acde with SMTP id w26-20020a0cb55a000000b0068f3a7bacdemr5767703qvd.41.1709120893531; Wed, 28 Feb 2024 03:48:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IFh5j+33195MLcwMYVLgDq21ulPQrd9yO0i820OvlHkq7/w48sElOO7s98RYQZETG5tvWX6/A== X-Received: by 2002:a0c:b55a:0:b0:68f:3a7b:acde with SMTP id w26-20020a0cb55a000000b0068f3a7bacdemr5767668qvd.41.1709120893157; Wed, 28 Feb 2024 03:48:13 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella , Stefano Garzarella Subject: [PATCH 1/9] libvhost-user: set msg.msg_control to NULL when it is empty Date: Wed, 28 Feb 2024 12:47:51 +0100 Message-ID: <20240228114759.44758-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120929586100002 Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella 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 --- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index a3b158c671..b9c18eee53 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -387,6 +387,7 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg = *vmsg) memcpy(CMSG_DATA(cmsg), vmsg->fds, fdsize); } else { msg.msg_controllen =3D 0; + msg.msg_control =3D NULL; } =20 do { --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120962; cv=none; d=zohomail.com; s=zohoarc; b=WNTEze2goVDWjF3Fi7ppdQGarKwIWP+9x/cq+94rXNZrhPgEwnZw1QjQMmJfDXQ/EvDj1hbdviN4tSoAx3f1CsJOdf/ooBmM0jytjOktg57vI5jQ7pOuxB+v+hcGg2N1/aQs9xK25279oWUe3riL7R6MewqKPsoahF/ex2GJvAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120962; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ERqbbN2GBkLZQ1HHjRaVA+d7aKobFGUJTjgGsOPEJxA=; b=T2CXxawLEFtHpiVlDKOOqH02SJjCE9FElhFsuArobvVcF5aeuK4Rdrwq1rE9Z1gtWu9dzsZXwOfkNJ4o+vurMWGO131wW5i3MyQmUz1st7qmi4A6lkp4+85j50DgV6OfIK46mxUSTnk0jBtMNaJoKbRAA34s93EkefulL73QMhc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120962561149.2145917579736; Wed, 28 Feb 2024 03:49:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQT-0002ev-6n; Wed, 28 Feb 2024 06:48:41 -0500 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 1rfIQE-000239-Ch for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:28 -0500 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 1rfIQB-00034K-9J for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:26 -0500 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-fMnTfEsRNmO7mpEDIiNY5g-1; Wed, 28 Feb 2024 06:48:21 -0500 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7830ab8fb5aso690667985a.2 for ; Wed, 28 Feb 2024 03:48:21 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id j25-20020a05620a147900b00787ad5ca70fsm4469892qkl.122.2024.02.28.03.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120902; 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=ERqbbN2GBkLZQ1HHjRaVA+d7aKobFGUJTjgGsOPEJxA=; b=aSdK6AlyQLHRnTwars/mXsL8Cr743H7+ni0W3JO33wBIYr/md/mCVIkRwJGAEa7WCzzEMo CEHURWrGBCDdbeHS3F8yFNLh+kIlB6VZIrnEY2Ga5VxatphyHb2Mpla+dCMf5OWEvEEaU3 OlA4Qb4sN6JAlmTBXLqoJbr6Z0hKZIM= X-MC-Unique: fMnTfEsRNmO7mpEDIiNY5g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120900; x=1709725700; 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=ERqbbN2GBkLZQ1HHjRaVA+d7aKobFGUJTjgGsOPEJxA=; b=IvviR/Vl/io5UJX7c3PoxtH5yb2D4heBNkAv/Nzhe3AIGW/Ao0KNoP5z1Xy3WaZaYx np32kEjm5GI+y9Hsd26cpUx3s4mjAcblXWIIxPsNGsiKDklAWMOywmTYaHSePe+z+t7j 0Rs9nOOtFBqM27YkwO6WPYGiYUJivUB5Kdfbab7BpKONAh8+ALTIng6oWzph2id2OxGS DHk0nH6ocHBrSL35zOMpVbIxZ96lTbvBXXufZptrQlC9Vs/xy76H5CiSotPjbVDSB9M8 /Uvm0tA2yAJ0DkL/RQLWYwnxnRseoufQYFb1U4IbZECMqWxdWpKm77Q98hrqZetvdQCe xVqw== X-Gm-Message-State: AOJu0YycjTLOwn7ewRR8pKf8+m3tgAvUfCx187hJrYPzrH2yqNV29gXq dFRRb/Cefg8x5BhxCai6bafqGuR9gFWu6OlU/PQJlHNDm7A8MEI4stLY71uuVsm78mCoD5BnxZl vSfB9EA7Cq7GJtYlKsLyVWkTwo/VnSu4jEJpCaED53UhIO7aNlsfi6IQ86nPk+NZg5kRV9FAPM8 djoLpZlDFHU85MilJmGEgD2GROs6GyboAPU8WC X-Received: by 2002:a05:620a:2994:b0:787:870b:3021 with SMTP id r20-20020a05620a299400b00787870b3021mr6252027qkp.25.1709120900619; Wed, 28 Feb 2024 03:48:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWCFBKAKLh2a9z+1xczZ5ji44WuCsPiijnvIyXIlLgM8olszwBXmmUP6TBWWSYAvrhcOd1GA== X-Received: by 2002:a05:620a:2994:b0:787:870b:3021 with SMTP id r20-20020a05620a299400b00787870b3021mr6251988qkp.25.1709120900261; Wed, 28 Feb 2024 03:48:20 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 2/9] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Wed, 28 Feb 2024 12:47:52 +0100 Message-ID: <20240228114759.44758-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120963673100003 Content-Type: text/plain; charset="utf-8" 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/libvho= st-user/libvhost-user.c index b9c18eee53..527a550345 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -394,6 +394,11 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg= *vmsg) rc =3D sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); =20 + if (rc <=3D 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) { --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120957; cv=none; d=zohomail.com; s=zohoarc; b=fMAybcQSOGUvTswwGsQyEd4CndEr+jWZSo78h/SVTLQPqFL5TX1Ur0a7ZKncNlWO9JRTZR8CC2gctnwfKS5QtWuJkNriUxlnmbcC06/P/iA9mz4qoMiKVYgTxCfzgqsUPmY3Omes7bjZ8pJYkoZRO21s5D9OfUC3hvhFjn8NQNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120957; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HcqLXsmQSW+XhXUFfJdTCoScF/qNMU2I0anlwbmVxFw=; b=DIaCqOVp9fg53b8x1BaB8z6ib4qUJlOhipPjbS/GD6m0X0ACEK/eIDM7+KlFYI0Beqd0FG5SxrarF8pKhJlX37Srp4oxoxPwMBOkR3cbxdtrtwszsJv7U5rNl6qqw86lsldQ+tqKF3ZmpzpsIoVTp+F1m3ew+ZBYeGycnaZ9c04= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120957056865.9558489419309; Wed, 28 Feb 2024 03:49:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQX-00031E-Eq; Wed, 28 Feb 2024 06:48:45 -0500 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 1rfIQV-0002v5-Ol for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:43 -0500 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 1rfIQI-0003Iv-Gj for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:43 -0500 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-311-TiHA3CcIMt2NwpSmUDCt4w-1; Wed, 28 Feb 2024 06:48:28 -0500 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-68f740ea9a8so11727186d6.0 for ; Wed, 28 Feb 2024 03:48:28 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id mw6-20020a05621433c600b0068ffde5efb0sm3957832qvb.49.2024.02.28.03.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120909; 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=HcqLXsmQSW+XhXUFfJdTCoScF/qNMU2I0anlwbmVxFw=; b=YJhGWHCpajDD8bBR6W2hYU+nIFp2L/zhdc5IizcLz/jmckeR7E//iEpABIA9T0YOtmb3gx aJXmdmBL7ogowCqWCcSPeLZQkhR0QXwNu4gUDdk2UZ6KHGGEzWV8MLFfMmjBD9+JyA6I2g Xuae0eECPax8eKcO3ImGfOpihCxqwWc= X-MC-Unique: TiHA3CcIMt2NwpSmUDCt4w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120908; x=1709725708; 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=HcqLXsmQSW+XhXUFfJdTCoScF/qNMU2I0anlwbmVxFw=; b=rXPknTO+V5Js2ync1nT//bwb498eiPU+5vnWW5BD9BfbKvkdILVXmj/5dL6eaIbYow eFDEHfk85rbLEp0ZmHR8sNrS9bUn9l6WMy09JfOubZo3ve9nw91lzR6z2zH3R58QjJbj X6JQ34LUbA3ttdvM1/9RspVEVEFTcatVuBG7NjyOJKmre0RvMdn8jJpXLMsygBcBmSTM zRz+4w3LI45mgGGNwhKvrIJkOxS3tOrvscL1K1hKZJR3YhCZ/T3h8whfiX4IW2XItGMq 7nJlssit2pY5dISwT5nZCTupxjncOVZbkNn+EDOVz72CiuMYWlFlOTCZv9C49rTFBDEp JGsA== X-Gm-Message-State: AOJu0YwULBGrHGxzXoDEo9ua65LKP0GR8eOzk5PHRMQqOcdCumP4ONNg 7l8sm1jq6GfpmITBwgafeX/7V5kPcq22/HcovSTrbUXkRBdimpAkCoI1XSxSgpLj4oX1F9JfwhA pmg5AjCCuMPDGyd3N8ha6qMbac8RSTHajDy9K7Cti2nsuq9OQMHjtNKOjFXonVztR2OQDOm7fap gHm9+NA55CH4kqUq0ZI1pdtYjR44DY7ZYkxCJq X-Received: by 2002:ad4:5a41:0:b0:690:2eed:46ae with SMTP id ej1-20020ad45a41000000b006902eed46aemr2309886qvb.14.1709120907922; Wed, 28 Feb 2024 03:48:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbh77SomaA0xNQxroyCaIwf9dvwgV7Y8SHz6KMLB/UZiYo4s+G+gKY2WUkhagLIeUQAiIA2Q== X-Received: by 2002:ad4:5a41:0:b0:690:2eed:46ae with SMTP id ej1-20020ad45a41000000b006902eed46aemr2309856qvb.14.1709120907628; Wed, 28 Feb 2024 03:48:27 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 3/9] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Wed, 28 Feb 2024 12:47:53 +0100 Message-ID: <20240228114759.44758-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120957676100003 Content-Type: text/plain; charset="utf-8" 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/libvho= st-user/libvhost-user.c index 527a550345..5da8de838b 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1610,6 +1610,16 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserM= sg *vmsg) features |=3D dev->iface->get_protocol_features(dev); } =20 + /* + * 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 &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); +#endif vmsg_set_reply_u64(vmsg, features); return true; } --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120948; cv=none; d=zohomail.com; s=zohoarc; b=knMVc3TAXuYmsR2uCT7fAeXdUweyRn6GzguK/AN+4NCnRdBl55OHBY36vkg5gYfnrH9nv3/o/JgdEMqKoN9sYHa2QOW2hihFW13Qwgv3RWn+CGhqEhYso6D7Vkpj+0uJooB7xYAn2Dz33MBTYYe2Fgw+/SQBQlANemBi5e6zmRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120948; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8odq6HkFwljgpCpDbS6c4Z23ZlZa/5hXAt8C67LMRrQ=; b=D4I+zAube465VAmh41n8gzSr0FTJb7r0gF2oD9BPggk+kIlpf8AaGT0wToV3/ghUUT96uZDOVUMZGU+EsN5Csi8hl+24sC89F/3A85jGOupdQWvuhQ/OJ4dOVD7Z1x6PGLdNZgygJzx5oFv3VJOaMIEQjkUcUWg1K0ewDfel+P0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120948721644.5602060802406; Wed, 28 Feb 2024 03:49:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQT-0002jQ-Q3; Wed, 28 Feb 2024 06:48:41 -0500 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 1rfIQS-0002WW-7G for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:40 -0500 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 1rfIQQ-0003d4-HJ for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:39 -0500 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-322-Gz558MA7P0KdPR47mwwaHQ-1; Wed, 28 Feb 2024 06:48:36 -0500 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-68f71d9992cso72053786d6.2 for ; Wed, 28 Feb 2024 03:48:36 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id oj7-20020a056214440700b0068d05b81fb2sm5178666qvb.15.2024.02.28.03.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120918; 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=8odq6HkFwljgpCpDbS6c4Z23ZlZa/5hXAt8C67LMRrQ=; b=bPlTHmi9ATd+Uuh5JT45eKhxJvEdFvjk7Sdtm1pM0ob/6zlYTKoUpA6STbsDrH+Q9ZD3C0 1BrpjLoQ9ukG1OGoH8xceAXNrSp9h4SwVOQjKxrwv4gZ+5sImwRkuRYUI/C39K0HosRgF+ hBtgxJXuRODDyMkXUnUzPHwwe/TIPEQ= X-MC-Unique: Gz558MA7P0KdPR47mwwaHQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120915; x=1709725715; 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=8odq6HkFwljgpCpDbS6c4Z23ZlZa/5hXAt8C67LMRrQ=; b=kn2HAP41jroBipWRSzRGWHYqoIrikgnKrq8CeOA7IO/5NcNDXFxnIpjedl/HaDaIXO tGJhPjVVVBC2qU3MEjuPOuXpfHyF+WKcwC8AzHidGRfnPKUDZASQvjksaLUQ/jOrJnWb 2IMwssXZAkMHuyvpZqnUkY9LCaQh8gFPy5MqSgovE0I5lUS+4G56iarfEh3pK7Ol2+Oo 8T3S9twcBUguj6IFTnfDpLpUEVbcOY8r9ieNITxHtuFp/RzTPy/SAG90bnDox4jwMzW7 LaZ6SZgIfi8deVpxitoFX0gzWzLTgVZXTkwhyLRGs1UuhBQLOxSIvaRnt38Axn8mL8Jb 3tKw== X-Gm-Message-State: AOJu0Yz5TSSrCA5R8vyK5PnbWStNafailsKWX/bRKEvMicCl4poUwNK5 i3ElERDs/VKAK2nabam6r8dUWs3Cw/ti1M/pK0hIocNwGlcyAmYrT4FweAF4mrmWyKMNbY5xlRk DBiTSw+3tLSHnkL+XhK2c3wyE9ag4+DB0Q8FNebqX7XzKzF3sj2m0Sb187FG32UyiCcTtvyvMRL pAy/gQbU9SPTKKJ0xSjLh863/2k0Pq6IIE4Xdw X-Received: by 2002:a0c:cc90:0:b0:68f:e766:5ee4 with SMTP id f16-20020a0ccc90000000b0068fe7665ee4mr4846630qvl.25.1709120915570; Wed, 28 Feb 2024 03:48:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfNtXpzxbRm7H86tnWp9FQG4Uky3KM/o6Dl1PW1hGvW9zSmLrj+xdPSMGILOBiVLnkbqoRbQ== X-Received: by 2002:a0c:cc90:0:b0:68f:e766:5ee4 with SMTP id f16-20020a0ccc90000000b0068fe7665ee4mr4846585qvl.25.1709120914969; Wed, 28 Feb 2024 03:48:34 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella , Stefano Garzarella Subject: [PATCH 4/9] vhost-user-server: don't abort if we can't set fd non-blocking Date: Wed, 28 Feb 2024 12:47:54 +0100 Message-ID: <20240228114759.44758-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120949705100003 Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella 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 =3D 0; i < vmsg->fd_num; i++) { - qemu_socket_set_nonblock(vmsg->fds[i]); + int ret =3D 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)); + } } } =20 --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120952; cv=none; d=zohomail.com; s=zohoarc; b=C5eHrXF+qPv/jZQDdZ2HzRUBRE2uHd0RzRwm7IzxSIZd5bN9f4xSAioNU/OY/Harc8/kiaSmgguDQYaTZa8sBshbUwpyFAygMXNGNeq6/Wv/fP7hNFB+ksilKvDQrlWvt0WoCfzZtIle5EurhqLSkKHpbaaJOXRL7xLzVqRvktk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120952; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NRTzpSwWeHQaZAkZ1Wju0ZZmvS1Y/8DKVkOU0OKpskE=; b=iEkIhFo7iwlBTyZ58nkYoGWcZ1iYDAHuqYaP9/igyRLmyM21bKbx075Nk/iNbi7VSYCfEyraRcGlTfDHaOqC5aDmB90UI1U1xfEXP72JK5tAgtEKEa9X7++z46LMz4IN3HgECK1bKAFGLmguLQRZigDYBoXCv0RpNiYl9BkHdZ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120952928750.0826972109114; Wed, 28 Feb 2024 03:49:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQb-00037O-Iy; Wed, 28 Feb 2024 06:48:49 -0500 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 1rfIQa-00034o-5B for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:48 -0500 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 1rfIQX-0003jp-Se for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:47 -0500 Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-q1JW1NmIMvm8Mus24gmZ6Q-1; Wed, 28 Feb 2024 06:48:44 -0500 Received: by mail-yb1-f197.google.com with SMTP id 3f1490d57ef6-dc64b659a9cso8465890276.3 for ; Wed, 28 Feb 2024 03:48:44 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id h8-20020ac81388000000b0042e5603b9aasm4484980qtj.75.2024.02.28.03.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120925; 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=NRTzpSwWeHQaZAkZ1Wju0ZZmvS1Y/8DKVkOU0OKpskE=; b=JzxR4ajEVa1MVeCDg8KU6cJZLAUvXgUC1WxZrmEsHsdx3xSPatktvXgOz2BX9Vx9NLd/IP PSNdviqZT94m7bezNtpVP3xfNoBffUDQtPEmADwwgpomu8JKQDLdo8lemFNzAKxicCEd1N sTTIcwX16lmuKJeL6b9asFNbzUaIm2g= X-MC-Unique: q1JW1NmIMvm8Mus24gmZ6Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120923; x=1709725723; 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=NRTzpSwWeHQaZAkZ1Wju0ZZmvS1Y/8DKVkOU0OKpskE=; b=GRd8dqxCykb+o3B1MxD9L/yIfLwNhrDvvb/V2csMMOIu4NJZfrYwH3J4cfEeQcAREZ 6TWTuz3QakS7iho0rKoKuIPCJAz83wChw1b0mCOUZa5+Ihwou6If1ltRjtTl2LXVlu0X Z+iIdBvTlCePmgHdCSWmyW+44yIUhj7evrNiEWpiEUj11mswwZdNAnqaGcUaxbXxzxnN f1dSMcfFCw1ACROONCFFg9zJ0CqK21s9VnwW07+zxh6oef0LOW8XQYn5LykSmysdBckv 1bQeLQJdq4aHFoRskWeKPB+M6kQCVtDUfSkQZJpnf0wzIoLJwgG9C1VuloriHGdCvRsm erkA== X-Gm-Message-State: AOJu0Yw8vY0OlW+7hqSrUyi8LzWY2aaCDKahL5YcEaChHzsxMOEVRH+l 7EhGRKqMxaO8PpU3sHdJMS2W1xAAFONcDk5NiKMzW7kqbU82Kn80mfnpQ+QhsRTgSF6A/MGCTLn 7omJ/Y+RUQC9mSbtdT4+zTFoOALJpmI88V20C2Dpqhqd/X7wF1bUhHhaVh4eGmgHrFUVRrhmz0S iM3J+bNtMpJlna6yi1cTpYR1dKpztGJDL97COm X-Received: by 2002:a25:86c5:0:b0:dcf:b5ba:1403 with SMTP id y5-20020a2586c5000000b00dcfb5ba1403mr2145468ybm.6.1709120922877; Wed, 28 Feb 2024 03:48:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfcYHyti9LUIfZ8xO1TKBvsS9yvqRVL1XZY5agcCZwmdzBYf+l7q1Rwk6v0CYLXrz2hafcKQ== X-Received: by 2002:a25:86c5:0:b0:dcf:b5ba:1403 with SMTP id y5-20020a2586c5000000b00dcfb5ba1403mr2145430ybm.6.1709120922454; Wed, 28 Feb 2024 03:48:42 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella , Stefano Garzarella Subject: [PATCH 5/9] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Wed, 28 Feb 2024 12:47:55 +0100 Message-ID: <20240228114759.44758-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.102, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120953686100003 From: Stefano Garzarella 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: =E2=80=A2 The pathname in sun_path should be null-terminated. =E2=80=A2 The length of the pathname, including the terminating null byte, should not exceed the size of sun_path. =E2=80=A2 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-b= lk/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; =20 assert(unix_fn); =20 @@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn) =20 un.sun_family =3D AF_UNIX; (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); - len =3D sizeof(un.sun_family) + strlen(un.sun_path); =20 (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; } --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120988; cv=none; d=zohomail.com; s=zohoarc; b=g3DbErfFzldmPJ1G4nDBU7JJY6ubGCWjvEyqW57SsiygUIMqDpKwm03lCfny7FPOogBYuRsvOCDTKK/xkl77Bu9/rvPaq5MEj2PoPksRE8Nm9jJv1awJRdUD4+Zkb8VVMX5TJ2qDMiSDeZCjf1FULPLDm5wILfOafMKMhh7m5jA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120988; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SuW2yr1ErTnpygHzGqWIClqySdaMuavIYT9oyHG6O0E=; b=ZGZywYkwBuK6Icz8J2yQCf1eOOwCGP0w+XLni5pZZ24gtm1/6+PfHZ1q24VljeBVsRL2ppoUoGzHDQeIolLtvKKXh//g/RWAFVh9pa2NKiwGyNIagjTu+kFSBtB+hgI65BDOJyoc+QKzX+aJ2wy2r2EHhvu7gORHxOcpVzA+ink= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17091209882694.957147842357244; Wed, 28 Feb 2024 03:49:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQp-000476-9Z; Wed, 28 Feb 2024 06:49:03 -0500 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 1rfIQm-0003rm-D9 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:01 -0500 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 1rfIQf-0003nT-Lr for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:59 -0500 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-SnIwnUTWNAOS4BwXfGZkeA-1; Wed, 28 Feb 2024 06:48:51 -0500 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-787ac304610so623434985a.2 for ; Wed, 28 Feb 2024 03:48:51 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id df24-20020a05622a0ed800b0042e5da69d93sm4520029qtb.1.2024.02.28.03.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120932; 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=SuW2yr1ErTnpygHzGqWIClqySdaMuavIYT9oyHG6O0E=; b=VHCCsM4DOnp8txzcAg+zCnDO+NKrJWzj4k8gQm9WGlvU2NCg8telFryh+5/4KCas576rlu 7rMlI/aCoEp3FmdVPF7jy9Pu/ZaUzAowcHO452AKE+0caJfSmNdpS5guXPwbiurOVFnzdq 50rp3Rfly//IFQCgmsIMs5WWuiTWs5g= X-MC-Unique: SnIwnUTWNAOS4BwXfGZkeA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120930; x=1709725730; 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=SuW2yr1ErTnpygHzGqWIClqySdaMuavIYT9oyHG6O0E=; b=QScqqvGRZLLkzw1MhRqtQz7h48Kn3vVbq0PVrQaPvHgOxoUJxPmJ1yGB5vUBKWDTYK nHhasWB7lh0dqZpSYuyZDnacc61zfCdlNxFn7LJSwE0pYnmhgaEjiHifuVoypqsFUqxD dAHE4ziUZiq4BOXEhXERrKqW5VnzEhXiwy6A5rcQzxGX0Sy649Ncgsyh+6Z0MxhE7NlF KHFBQvdV0G0IsGw79yjyo9TB7Fw8gWjg0Uryy0oqKjI/21a7BsWSEaT1ozB3dL6irO/K evR1k5wskVUBN9Pw2QT5CdJW2u0/Q3V4KXsgkJMOqmlhTUt590lIp0ZhZYMDRJXKbJtF CxsA== X-Gm-Message-State: AOJu0YxKwQeUuUvdu6b1HIyosMahyRuryGr6DN0RNsuFzgneqg32awuF oFx97y+cXqywarHWl0Yx8TywjpA+n9bexKywKoTUjBcFjoJrI+4ZAL4awb7oFgxv5L02jNXsBDs V1u7oJqHtPFeJVb/6F8pObco5Vh/lQBzDrcJWGO8PDHtV9xRc9nJN/VYHutZBubpgppc7nvtLqT X2qO22bkGBx7p6q5z+fPyhKiXjH4kruMQzdtq6 X-Received: by 2002:a05:622a:1b9f:b0:42e:58c6:bc9e with SMTP id bp31-20020a05622a1b9f00b0042e58c6bc9emr14402109qtb.60.1709120930260; Wed, 28 Feb 2024 03:48:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSD7p68tHuqEcO9TQtrqscvTt0IR5KWQZFI7nOUE+yM97FuOub0zEb4zMVUezJpGvEmZPRRg== X-Received: by 2002:a05:622a:1b9f:b0:42e:58c6:bc9e with SMTP id bp31-20020a05622a1b9f00b0042e58c6bc9emr14402075qtb.60.1709120929907; Wed, 28 Feb 2024 03:48:49 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 6/9] vhost-user: enable frontends on any POSIX system Date: Wed, 28 Feb 2024 12:47:56 +0100 Message-ID: <20240228114759.44758-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120989765100003 Content-Type: text/plain; charset="utf-8" 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 --- If we want to be more conservative, maybe we can leave `have_vhost_user` auto only on linux. I removed it more to test with CI if we have any problems in the other POSIX systems. In hw/net/vhost_net.c maybe we can just do: #ifndef VHOST_FILE_UNBIND #define VHOST_FILE_UNBIND -1 #endif Any suggestion? Thanks, Stefano --- meson.build | 1 - hw/net/vhost_net.c | 8 +++++++- hw/block/Kconfig | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 0ef1654e86..462f2d7593 100644 --- a/meson.build +++ b/meson.build @@ -151,7 +151,6 @@ have_tpm =3D get_option('tpm') \ =20 # vhost have_vhost_user =3D get_option('vhost_user') \ - .disable_auto_if(host_os !=3D 'linux') \ .require(host_os !=3D 'windows', error_message: 'vhost-user is not available on Windows').allowe= d() have_vhost_vdpa =3D get_option('vhost_vdpa') \ diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index e8e1661646..346ef74eb1 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -34,8 +34,14 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" -#include "linux-headers/linux/vhost.h" =20 +#if defined(__linux__) +#include "linux-headers/linux/vhost.h" +#else +#ifndef VHOST_FILE_UNBIND +#define VHOST_FILE_UNBIND -1 +#endif +#endif =20 /* Features supported by host kernel. */ static const int kernel_feature_bits[] =3D { 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 =20 config SWIM bool --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120993; cv=none; d=zohomail.com; s=zohoarc; b=KaVncjYYG2hxXgkgt+1KjOCgMR5JikcjBxyGw3yE0/YM6a3h7ZS8ST0tXQZxh00l/1iCzpqPa4jfZ+hKRg+89qszVd1OMfnnyqQ+0tAbBFAJwiNtexbsxLczIK33uXkukLGhwefdBkA97UBVvgkP2wQwXKRqwMICHb1E4ks1iQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120993; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KwzcXy+YqtjSTOiLxTxsvP3DT1VDsjM8bZULtaq2AAU=; b=jxlAviO9hDSKqcNjQ7nUIO6VJcjMiaOEWTRyUbpbM/lsgsW8wYza1AewsZ5GO6W82b9/XbD9TWRjP98TxBGCUh0BCD5Apyy63+VhgYO+sO2oV5PUZ5uBWx1h2s/pBt5Nf6CrL2leiDlUyF0Ig3Vu0UDc2C5kuzMOnQAzRfRnuc4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120993435920.3575317917179; Wed, 28 Feb 2024 03:49:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQr-0004GB-5Y; Wed, 28 Feb 2024 06:49:05 -0500 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 1rfIQp-0004BH-O4 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:03 -0500 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 1rfIQn-0003uQ-Ov for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:03 -0500 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-176-soCxqwNvPvK5q08SrLlMlg-1; Wed, 28 Feb 2024 06:48:58 -0500 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-68f71d9992cso72057186d6.2 for ; Wed, 28 Feb 2024 03:48:58 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id lv4-20020a056214578400b0068f9c181fc0sm4715254qvb.113.2024.02.28.03.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120939; 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=KwzcXy+YqtjSTOiLxTxsvP3DT1VDsjM8bZULtaq2AAU=; b=FPzF6xteeQe3Fn9pLbdDdZr/tio8qh3+FHJqDaYBt4wRU2fmHBMhcxkk8FSOO50QYkyJnd ndww0HtwQt5FvJJQ8mU70baa/oFeYkMn5EhU8D3wbVl0KjzvAr/BILu1+snVyVw9wZasP5 h2FfHpd86Ye05QGVkKQc9dbiAZJYK6I= X-MC-Unique: soCxqwNvPvK5q08SrLlMlg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120938; x=1709725738; 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=KwzcXy+YqtjSTOiLxTxsvP3DT1VDsjM8bZULtaq2AAU=; b=pf3BL9fmp0sSFgD85Ta8RYSbl96UbqoRj0Djicsr3/yRKhxfWh4q6OwSu4OREPFSsl 00QB/qTZwBv0o8eBw8q9f2uakIXOKakh+UHjcVWZXSJlJRLeiBmWislYeRKXxR4WuEAs 7+da9dEYc26oI75ui8LnYjw/AxR7rulx0OMAbOzXU0c2feqzMjDOmYjpQkkYCZ/BjOMZ J4JOWgZWCNWNcXXqGmwh1fL92omK3WU58FnKZPH7fet+uqba1slDCNgNeArrTskDVI/5 dqBJ1YFY8N40wLGgX+a3C9nKeCCsOkppm9J22XeSHuPGlc3eLbCBjHgOXpNwyfgF3Gou CH+w== X-Gm-Message-State: AOJu0YzMJXA73LFz4O5aWuDHmq0iWqkSId2bHvfF9GyDRc9iLpV2+KaE lXsDlkklei4uERMyEZHV2PV2i3tFqRNPFUpWogKHg92OwDRj0V87lCSbYZq0IOl52ZJv+pjbSyR YtdQi/upm3DEXUSnpJGtnA83xEaMFkwx8zxiu5nr1FIRS2M8gQzYL1QIInwUrqWQE/Tj4dauBfj q50+bMM+Rlgkv9ofcCGZPF0JyCO5WBPxe2JXXB X-Received: by 2002:a0c:f012:0:b0:68f:74f3:d571 with SMTP id z18-20020a0cf012000000b0068f74f3d571mr5024394qvk.16.1709120937771; Wed, 28 Feb 2024 03:48:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtr6Qgec/Mncv/nO92N5SUo8bcRvvFkpwWX0mQZ3OXmX7lo/S7vhT1vTI8cTTv+GKik+MVDw== X-Received: by 2002:a0c:f012:0:b0:68f:74f3:d571 with SMTP id z18-20020a0cf012000000b0068f74f3d571mr5024354qvk.16.1709120937213; Wed, 28 Feb 2024 03:48:57 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 7/9] libvhost-user: enable it on any POSIX system Date: Wed, 28 Feb 2024 12:47:57 +0100 Message-ID: <20240228114759.44758-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120993879100003 Content-Type: text/plain; charset="utf-8" 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 462f2d7593..af15178969 100644 --- a/meson.build +++ b/meson.build @@ -3188,7 +3188,7 @@ endif config_host_data.set('CONFIG_FDT', fdt.found()) =20 vhost_user =3D not_found -if host_os =3D=3D 'linux' and have_vhost_user +if have_vhost_user libvhost_user =3D subproject('libvhost-user') vhost_user =3D libvhost_user.get_variable('vhost_user_dep') endif diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index c2352904f0..e684b999b4 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" =20 /* 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/libvho= st-user/libvhost-user.c index 5da8de838b..1075fd3147 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 =20 /* 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" =20 #if defined(__linux__) +#include #include -#include #include #include =20 @@ -50,6 +48,62 @@ =20 #endif =20 +#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)) =3D=3D sizeof(value)) ? 0 : -= 1; +} + +int eventfd_read(int fd, eventfd_t *value) +{ + return (read(fd, value, sizeof(*value)) =3D=3D 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" =20 #include "libvhost-user.h" --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120983; cv=none; d=zohomail.com; s=zohoarc; b=hC4VJ0VUarFsZcZrdh1rJCPbJFQ25PgSCVZi3D+GwG+VYxOtlhOJGgUeCP4NSZnv0KRN64I9/gdydUGr7hbHMTuUQiZMI4BVxJ+Yr7ltygnOfJzeoXOLT+uRrwHM8UVY3nv6TTUmcRMXJkiNQjGpc8y4aR0CfXUVW5c1kyb1kpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120983; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TLg7okLmDrwykRkhT6hlbl5ORhkxyjg/0KKKGfeq0JU=; b=cBkOx2BELLmUFxDQXTjMMP0DVcR/N995ArdL+VTTJjVcVJXNBaa3S0SM3jY5kwOvIk/+Cse7oFhF3b7VwWxeANx624i87HSCfADduyDGVB9+IwtsdoDcZyXMZRlOlW6VVcAZGLB4gQ/eQFj41QUsvkAMXaqLgbLX9rgoi14ftlY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170912098351621.999239699463146; Wed, 28 Feb 2024 03:49:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIR1-0004wb-Ih; Wed, 28 Feb 2024 06:49:15 -0500 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 1rfIQz-0004m3-AX for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:13 -0500 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 1rfIQx-00040K-IV for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:13 -0500 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-8ApzNfZYP3GFiRwONsmYnA-1; Wed, 28 Feb 2024 06:49:09 -0500 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3c02a63d499so9377492b6e.3 for ; Wed, 28 Feb 2024 03:49:09 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id pd5-20020a056214490500b0068f9592f381sm5184581qvb.10.2024.02.28.03.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:49:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120950; 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=TLg7okLmDrwykRkhT6hlbl5ORhkxyjg/0KKKGfeq0JU=; b=ffSFARpZbUmm7Zja4e6+ajEzaFhDvU85f3scPhRgUc6kOkLSUF9i5re1qF7ctpAHUhPf3o 7IoglWlDitrHD60mNkbaD03pjJ/kUWZwcVgIMZbYjytscyTjO16Dlw+Ze2gbjcqfB6mzYx 8Knbt3z4q8Ev+A9cvH0u413pyZ/l3Ls= X-MC-Unique: 8ApzNfZYP3GFiRwONsmYnA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120945; x=1709725745; 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=TLg7okLmDrwykRkhT6hlbl5ORhkxyjg/0KKKGfeq0JU=; b=RrIBSxgl7OjuuQJXXh2neCNxGo1DEAFLAztXo3pjCku3u4Pg5Ltbs9Z4gh9+ZNDeSQ yMclz/1sXgxjmsxwgJu7dkSolr3DVAmo0VaiesD1HbLceaBYqRZJZaFJw370Xy3yVahz FwVGVE9skoozWH3o3R8h06b99waAvclFwaLsbC5n5jY34B9OiKqJAP1B3CM/B5GDS2oy YwbO3dlLs/oHAKHtsIE6lYJWcwfoQSu2uTeVKlI0fQRBkANhlIZINSpthY6BxqR4Jl2K zJAa89Aibl+xyxDO3yKca8SFr5Wwvd5ubPIkTzYZXKndgjYAnbid0qIB73MCc3aa/gwF v/Ng== X-Gm-Message-State: AOJu0YwUu06y/nYp4azftHbayThK6NGmCxzkJUrasjd19jp8GLtEvBPG IPHMj+Zlo85FW4AHmpbo+DTuFuiPPxXb/uHsNolXBH/cDxczCDgImzuDAYjM18OxWClI5aByaij qhD2rN5eq/92H5EA+gTYAfy4frUCG108aYkuEluL7cqle4oTERSCHcicLAHXf3oaS/JRw1j6orc x3HJ6fOIwFNPfHbeTg2uHyCHrcmPH2W+4fjAGV X-Received: by 2002:a05:6358:541a:b0:178:e2b3:98da with SMTP id u26-20020a056358541a00b00178e2b398damr16355713rwe.28.1709120944865; Wed, 28 Feb 2024 03:49:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHKAfcJVb6B10yOsJ+Uj2GvaLy5ffB1SRAVsgtZby8PB8+cwyPAzX+9O/DuB/UIwJE+05mlA== X-Received: by 2002:a05:6358:541a:b0:178:e2b3:98da with SMTP id u26-20020a056358541a00b00178e2b398damr16355684rwe.28.1709120944532; Wed, 28 Feb 2024 03:49:04 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 8/9] contrib/vhost-user-blk: enabled it on any POSIX system Date: Wed, 28 Feb 2024 12:47:58 +0100 Message-ID: <20240228114759.44758-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.102, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120983748100001 Content-Type: text/plain; charset="utf-8" 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 af15178969..8afda86d3d 100644 --- a/meson.build +++ b/meson.build @@ -1954,8 +1954,6 @@ has_statx =3D cc.has_header_symbol('sys/stat.h', 'STA= TX_BASIC_STATS', prefix: gnu_ has_statx_mnt_id =3D cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', pr= efix: gnu_source_prefix) =20 have_vhost_user_blk_server =3D get_option('vhost_user_blk_server') \ - .require(host_os =3D=3D 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user suppo= rt') \ .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-b= lk/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 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" =20 @@ -24,6 +25,20 @@ #include #endif =20 +/* 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 =3D 8, }; @@ -267,13 +282,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk, req->in =3D (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_bas= e; in_num--; =20 - type =3D le32toh(req->out->type); + type =3D 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 =3D 0; bool is_write =3D type & VIRTIO_BLK_T_OUT; - req->sector_num =3D le64toh(req->out->sector); + req->sector_num =3D le64_to_cpu(req->out->sector); if (is_write) { ret =3D 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 =3D=3D '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 !=3D 'windows' + util_ss.add(files('vhost-user-server.c'), vhost_user) + endif endif =20 if cpu =3D=3D 'aarch64' --=20 2.43.2 From nobody Tue Nov 26 06:28:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120978; cv=none; d=zohomail.com; s=zohoarc; b=VUA6pZNmplGaUJ8B2VtMG9qQ0pC0GwcIOX0bl49/OcQNe88yBXC823IOaaMOtWnUKYeDcR6VmPQPERfuvDOpNMP4PzttEN31ANNn4l8LzBmrgqv+YPU89tQeGLv43i6qpTaE12H6KiXNIXqAwD+0xKZnQ5o9u/MhxmjJ1jKtxSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120978; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fLM8N8KufGIAXLoDANm2UQXu1s3D3+QLrZtKYGXzVoE=; b=LTV6kY8IYTtDQZiBMUqOs6fG0M6dICi6/J1BXvugGTIDMbfAhIkerUZBPA2mC+KtmzBOVMXRNc3hydDgbIu+Vl8RRtv9MKlooH9oTqLIK1ve9iQ/nHWCF3uAloCt4it5rev6CmseGX+w9QQLA5+uWDkhSK8jppVlwO3+x05ArPc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709120978590100.65173468772048; Wed, 28 Feb 2024 03:49:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIRI-0006Bh-AK; Wed, 28 Feb 2024 06:49:32 -0500 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 1rfIRF-0005z6-OC for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:29 -0500 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 1rfIR0-00043G-MM for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:29 -0500 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-664-ATKOrPTgMVq0db0zGoDf_g-1; Wed, 28 Feb 2024 06:49:12 -0500 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-69033ba441fso6424406d6.3 for ; Wed, 28 Feb 2024 03:49:12 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id qj24-20020a056214321800b0068f9fd1d688sm5121717qvb.21.2024.02.28.03.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:49:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120954; 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=fLM8N8KufGIAXLoDANm2UQXu1s3D3+QLrZtKYGXzVoE=; b=L2SuMPT3hUFWfsW7ZNxQyChGYGn+C1HTWcXC/Hkn+dRMiFgTx/31rqM2OocoPaFoYwGvMI S9jsO+eSU8Qm+RR3T/S1X1Htm4rg2aIu/zjz0lRXOzCU3ah3brfJYzcNsUW1d5yl7X7/Rs rRwKkH+q6Y3FndexKiAsiG4HHjLjQVk= X-MC-Unique: ATKOrPTgMVq0db0zGoDf_g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120952; x=1709725752; 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=fLM8N8KufGIAXLoDANm2UQXu1s3D3+QLrZtKYGXzVoE=; b=xAn6Jv8ZrS+RxIp1I5vWA+jEiJrwv5MuCquxwHiyn+dOu9rjfWyPbubxau4sOKin+O x/a9knjAJk/MOSFKPyGSGO9ACGMshj/y8+1FnA+LZdT5CT+dpprrJtX+i+qfmyWrzBxv yFIAd84xSjI6xSOpRpINKcSrUMzgM6H3rCe8X4o5RXHWtOzdm80JfvwpNlEy3yJlogaG 0H4Mq/OEiRot1Dv8er/Yjupq9M9UVEOWw3CfUFSGLln5fBVjvNvstX3FymKm/xGEZoXk V3IgCWAzxsPN6KdJKuLQfeAq9RF6je/FVvDzPWALpX7AUTngeTg3+8ZNAf0E4KGK0X+e HwBQ== X-Gm-Message-State: AOJu0YxfBOH2aeK/8BOhSFpqdO0MiD9eFqYzWrfFUo7bYxck8r5kYiLM OU5DsTXpXb1CkLfsw2MU9jFNSlRHyrIhfcwtBBeUdw1EBkiCJXeuW8Jfy6X4bObyUolvUSXwpNp GO4FdcxXilqIqe2Xz//7mSLKKAzI8dXSRzKKbonpx9si2S4/s23HdUCyCgPIQmTu8ZamSsPsYB2 cUdY5LwAeXOOig230qvyP5IRYVsfIqUL+DGIUx X-Received: by 2002:a05:6214:3019:b0:690:b3f:8a1 with SMTP id ke25-20020a056214301900b006900b3f08a1mr5770451qvb.53.1709120951936; Wed, 28 Feb 2024 03:49:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFH1Xe9yloE9WF1xN62J37kqng1CId0u7Gqr9fCNzmg+QWyugEloWRMBvLpAyAPZ4B95+bZ0Q== X-Received: by 2002:a05:6214:3019:b0:690:b3f:8a1 with SMTP id ke25-20020a056214301900b006900b3f08a1mr5770418qvb.53.1709120951591; Wed, 28 Feb 2024 03:49:11 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 9/9] hostmem-file: support POSIX shm_open() Date: Wed, 28 Feb 2024 12:47:59 +0100 Message-ID: <20240228114759.44758-10-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120979760100002 Content-Type: text/plain; charset="utf-8" Add a new `shm` bool option for `-object memory-backend-file`. When this option is set to true, the POSIX shm_open(3) is used instead of open(2). So a file will not be created in the filesystem, but a "POSIX shared memory object" will be instantiated. In Linux this turns into a file in /dev/shm, but in other OSes this may not happen (for example in macOS or FreeBSD nothing is shown in any filesystem). This new feature is useful when we need to share guest memory with another process (e.g. vhost-user backend), but we don't have memfd_create() or any special filesystems (e.g. /dev/shm) available as in macOS. Signed-off-by: Stefano Garzarella --- I am not sure this is the best way to support shm_open() in QEMU. Other solutions I had in mind were: - create a new memory-backend-shm - extend memory-backend-memfd to use shm_open() on systems where memfd is not available (problem: shm_open wants a name to assign to the object, but we can do a workaround by using a random name and do the unlink right away) Any preference/suggestion? Thanks, Stefano --- qapi/qom.json | 4 +++ backends/hostmem-file.c | 57 ++++++++++++++++++++++++++++++++++++++++- backends/meson.build | 2 +- qemu-options.hx | 10 +++++++- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index 2a6e49365a..bfb01b909f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -682,6 +682,9 @@ # writable RAM instead of ROM, and want to set this property to 'off= '. # (default: auto, since 8.2) # +# @shm: if true, shm_open(3) is used to create/open POSIX shared memory +# object; if false, an open(2) is used. (default: false) (since 9.0) +# # Since: 2.1 ## { 'struct': 'MemoryBackendFileProperties', @@ -692,6 +695,7 @@ 'mem-path': 'str', '*pmem': { 'type': 'bool', 'if': 'CONFIG_LIBPMEM' }, '*readonly': 'bool', + '*shm': 'bool', '*rom': 'OnOffAuto' } } =20 ## diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index ac3e433cbd..9d60375c1f 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -34,6 +34,7 @@ struct HostMemoryBackendFile { bool is_pmem; bool readonly; OnOffAuto rom; + bool shm; }; =20 static bool @@ -86,7 +87,37 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) ram_flags |=3D fb->rom =3D=3D ON_OFF_AUTO_ON ? RAM_READONLY : 0; ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; ram_flags |=3D fb->is_pmem ? RAM_PMEM : 0; + /* TODO: check if this should be enabled if shm is enabled */ ram_flags |=3D RAM_NAMED_FILE; + + if (fb->shm) { + mode_t mode =3D S_IRUSR | S_IWUSR; + int fd, oflag =3D 0; + + oflag |=3D fb->readonly ? O_RDONLY : O_RDWR; + oflag |=3D O_CREAT; + + fd =3D shm_open(fb->mem_path, oflag, mode); + if (fd < 0) { + error_setg_errno(errp, errno, + "failed to create POSIX shared memory"); + return false; + } + + if (ftruncate(fd, backend->size) =3D=3D -1) { + error_setg_errno(errp, errno, + "failed to resize POSIX shared memory to %" P= RIu64, + backend->size); + shm_unlink(fb->mem_path); + return false; + } + + return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend= ), + name, backend->size, ram_fla= gs, + fd, fb->offset, errp); + + } + return memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),= name, backend->size, fb->align, ram_= flags, fb->mem_path, fb->offset, errp= ); @@ -254,17 +285,36 @@ static void file_memory_backend_set_rom(Object *obj, = Visitor *v, visit_type_OnOffAuto(v, name, &fb->rom, errp); } =20 +static bool file_memory_backend_get_shm(Object *obj, Error **errp) +{ + return MEMORY_BACKEND_FILE(obj)->shm; +} + +static void file_memory_backend_set_shm(Object *obj, bool value, + Error **errp) +{ + MEMORY_BACKEND_FILE(obj)->shm =3D value; +} + static void file_backend_unparent(Object *obj) { HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(obj); =20 - if (host_memory_backend_mr_inited(backend) && fb->discard_data) { + if (!host_memory_backend_mr_inited(backend)) { + return; + } + + if (fb->discard_data) { void *ptr =3D memory_region_get_ram_ptr(&backend->mr); uint64_t sz =3D memory_region_size(&backend->mr); =20 qemu_madvise(ptr, sz, QEMU_MADV_REMOVE); } + + if (fb->shm) { + shm_unlink(fb->mem_path); + } } =20 static void @@ -300,6 +350,11 @@ file_backend_class_init(ObjectClass *oc, void *data) file_memory_backend_get_rom, file_memory_backend_set_rom, NULL, NU= LL); object_class_property_set_description(oc, "rom", "Whether to create Read Only Memory (ROM)"); + object_class_property_add_bool(oc, "shm", + file_memory_backend_get_shm, + file_memory_backend_set_shm); + object_class_property_set_description(oc, "shm", + "Use shm_open(3) to create/open POSIX shared memory objects"); } =20 static void file_backend_instance_finalize(Object *o) diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..64520c0a7e 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -12,7 +12,7 @@ system_ss.add([files( =20 if host_os !=3D 'windows' system_ss.add(files('rng-random.c')) - system_ss.add(files('hostmem-file.c')) + system_ss.add([files('hostmem-file.c'), rt]) endif if host_os =3D=3D 'linux' system_ss.add(files('hostmem-memfd.c')) diff --git a/qemu-options.hx b/qemu-options.hx index 9be1e5817c..da96ee506d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5079,7 +5079,7 @@ SRST they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path. =20 - ``-object memory-backend-file,id=3Did,size=3Dsize,mem-path=3Ddir,share= =3Don|off,discard-data=3Don|off,merge=3Don|off,dump=3Don|off,prealloc=3Don|= off,host-nodes=3Dhost-nodes,policy=3Ddefault|preferred|bind|interleave,alig= n=3Dalign,offset=3Doffset,readonly=3Don|off,rom=3Don|off|auto`` + ``-object memory-backend-file,id=3Did,size=3Dsize,mem-path=3Ddir,share= =3Don|off,discard-data=3Don|off,merge=3Don|off,dump=3Don|off,prealloc=3Don|= off,host-nodes=3Dhost-nodes,policy=3Ddefault|preferred|bind|interleave,alig= n=3Dalign,offset=3Doffset,readonly=3Don|off,rom=3Don|off|auto,shm=3Don|off`` Creates a memory file backend object, which can be used to back the guest RAM with huge pages. =20 @@ -5183,6 +5183,14 @@ SRST (``share=3Doff``). For this use case, we need writable RAM instead of ROM, and want to also set ``rom=3Doff``. =20 + The ``shm`` option specifies whether to create/open a POSIX shared + memory object identified by ``mem-path``. + If set to ``on``, use shm_open(3); if set to ``off`` (default), + use open(2); For portable use, a shared memory object should be + identified by a name of the form ``/somename``; consisting of an + initial slash, followed by one or more characters, none of which + are slashes. + ``-object memory-backend-ram,id=3Did,merge=3Don|off,dump=3Don|off,shar= e=3Don|off,prealloc=3Don|off,size=3Dsize,host-nodes=3Dhost-nodes,policy=3Dd= efault|preferred|bind|interleave`` Creates a memory backend object, which can be used to back the guest RAM. Memory backend objects offer more control than the --=20 2.43.2