From nobody Mon Nov 25 07:55:32 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=1716476200; cv=none; d=zohomail.com; s=zohoarc; b=JihI3jLqaIMiJp6l4gtSF147mAaN0nXRab/Rj70/1f8itiezs9gHrbscuz6LKR4Ngk/NNRXQQQw6TVfz8uVFTdPRteMRiuyBu3mTFAfht44CKGk1sOJo36vHnA/omJMHMDVeQcTvlKe5sbxu5/oQovcOIb2+qTU+OOOwaCiidXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476200; 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=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=n6YF/bivs24H2mzHN7nE+/OodfKEkW+cOmAvM6SYfTaFSbN7tIVg7OuAidN9qZpjAjFAMH+LlZVLrvEZc8UCzN94EhsJAf4jiQz1J/Ag/oe29XbcEvQrWmhXszuHp02dYs/AQxY2R0Bd3Ua3AbzEsKNIt4dPbJM7dMWj0ov4w6w= 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 1716476200956929.0886348565504; Thu, 23 May 2024 07:56:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9r6-00023t-DA; Thu, 23 May 2024 10:55:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9r4-00023I-LO for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9r3-0003vu-8k for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:42 -0400 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-6-wDqsn7PGKMeGaig2Fp3A-1; Thu, 23 May 2024 10:55:39 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6ab8c89adb6so2524986d6.1 for ; Thu, 23 May 2024 07:55:39 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab8676b583sm14666736d6.61.2024.05.23.07.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=SWm2p/yZkDQdAghm/EciTkr+tMc/A/AQXqUV2gBGpy/jelV8R5VtfYx7ewqUnVCKqmAIB4 zQ/LULxF2BgHzRy6AtpaC++qNEyJoFfHorBt4d0bKL8OoEAin8N76v7z2huYQr4taU10Zt VAGdGGBOd8umwL3KGRvSnTDtKIP82aw= X-MC-Unique: 6-wDqsn7PGKMeGaig2Fp3A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476138; x=1717080938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=tBcOJdo8IQc8IdO+Oq/8BAu72swdw8EcMQw4u3m+lbgvWH8lVNdhKOqLh+5fnXH58R +1AYAGjfARa6wXnlcXJR54pLiiKKc5q04SknfAEoqcLJ9mq9I22812/YaQg8RZwYyAvt r/WcgnWFclxHWDo3B4THww/e2jesMy/gZnt9QW3n5Cg/UT2Ufn6FmFs5hYNm8G7bFM6I GNB4naMDR6C6E+peZWTKzhydS+KNZKFO9Vg1G8M/LoYq8Yza07cZNpdrkblvL/S6ZZLB SkESY7SgJQ53m18uORBWH5m+Vr/4lzBEseqbisT8WSAvFlpunGX7V4Qqp+8OXtoQu6yN IbpQ== X-Gm-Message-State: AOJu0Yzbhws8Tkfy8PY8L3di2OUGPNENbF4tN77zffrEgZcZlroLbI3z rBXycQnhgu9QnSaxamMJwSGrcStoRJvTkrh5RiztocPh7BHGM0G5L+f35oyTqpglFZYjQduNT4/ ipXetPYNYfM+8TnMQfNytvWjL9oJA/6EhpqI9VfeOy3juqnaEUva6D0D8QcM2AYIDTIH6az6BMX 2ICW4gi5KDJWqtso3+IyVdmhjKzHrEwsJ0zo5d X-Received: by 2002:a05:6214:3f8f:b0:6ab:6d0b:eceb with SMTP id 6a1803df08f44-6ab7f3726b7mr73177596d6.37.1716476138015; Thu, 23 May 2024 07:55:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQS3U9wm4xFEmU29SUT+Muh3mdHUdkEn8zwkTLSuLOn3D4YxnpDFhuLoaecn9NzLmB1Dt7yg== X-Received: by 2002:a05:6214:3f8f:b0:6ab:6d0b:eceb with SMTP id 6a1803df08f44-6ab7f3726b7mr73177066d6.37.1716476137468; Thu, 23 May 2024 07:55:37 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 01/13] libvhost-user: set msg.msg_control to NULL when it is empty Date: Thu, 23 May 2024 16:55:10 +0200 Message-ID: <20240523145522.313012-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476202168100004 On some OS (e.g. macOS) sendmsg() returns -1 (errno EINVAL) if the `struct msghdr` has the field `msg_controllen` set to 0, but `msg_control` is not NULL. Reviewed-by: Eric Blake Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-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 =3D 0; + msg.msg_control =3D NULL; } =20 do { --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476260; cv=none; d=zohomail.com; s=zohoarc; b=RBPC3XYYUc3cqYETknEqPtilwOZbCRfiBzLqhUitDBP5uml448MReYIql7TfxS90NaggBJ5dfYRbHyujkakNHi0HxuyKEnl8US6kV+rtpsFtfNNITWwi8N6KXj3d+FM/KKccJzwAnS9sf9jEUS8A8wKXyENTiuTppZeCbc3FTVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476260; 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=+xyelDCWIlCX+PAbwFYWN2GP5CDp4IfKR8S4cYw8b0U=; b=i9+HXPlhXFpn8B9kcf9vlsCNdJmHI4dJZSbE7+5v9PWWPe4leLSz1iC6IxTh14hv8jDpfcMcffhCP/saZFB6m5CyuIJ/eVOin34I7T2gWFBAVAhWv39OrtqWvsBJbzxvzZkG8XYfToN/MOOXFIcAGpkBZGD3hjGHNxJ4PBJCwMg= 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 1716476260067115.01987195990228; Thu, 23 May 2024 07:57:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rd-0002Hq-7s; Thu, 23 May 2024 10:56:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rB-00025V-KQ for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rA-0003wl-6O for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:49 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-wfWtd-OsO46aucllNvrvzA-1; Thu, 23 May 2024 10:55:46 -0400 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6ab8e7f5f8dso3968516d6.1 for ; Thu, 23 May 2024 07:55:46 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab93c15e1esm5250716d6.4.2024.05.23.07.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+xyelDCWIlCX+PAbwFYWN2GP5CDp4IfKR8S4cYw8b0U=; b=O0bOI/VfYu2d6Q6CQAAXuONMA1q/srKcrR8VK307QRcOiFU+S14BLFv4EQCQ9slsYq186g aHwHDuTIcanakR/qr8ptaQ1iSUiAHedvKGWKTp7/MFT9yEw6wJxysC42YjisJvQfpcFneA +6sNGwAgMwc2mRzLwTI6WNe3stc4/Nk= X-MC-Unique: wfWtd-OsO46aucllNvrvzA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476145; x=1717080945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+xyelDCWIlCX+PAbwFYWN2GP5CDp4IfKR8S4cYw8b0U=; b=waMJv+dUInW7ggBBRNPf98sU3Rm+AulKTzFtfu/NR+H0DfAN36CFKWohVQ0uX4Ix/K agjPzUN2Q/Pb2CYVfvZCePQilA4luHpn1zcVgAt9IjhRulhhFNJJnxW3s0FLNlRU3MyA sT2IWMkxj6DNWYsnoJzPkwp9qgC+wmc3tmSUdDi6LZ8CYBhQSPVkpIak+5jpfPFaqWQ9 YlhQkVBzCYexndgnAJGvrISKz2Lf/z7FSJfdXanC6QswA4G5mEb0fUeG08jBZ89R/Ety JVo+HqrRf4yZ3Az2OzfJabjBgrPSYckgeNNI9n+jsiSDjtSV6PX8IrlzlpKLpQWRnP+1 BZJw== X-Gm-Message-State: AOJu0Yxgvx8zsXnFxUftJ3kuTuiFVgkFywnXwDF7Qhmm+YyOOU4q9edM tkVgOKc7TdcMbDhvl61B5ew4bNYzVUVIJyNMj/letZ4C2Zwr3ygEoC2REkWP7km4X69THzpGSHA 27OQbw1Iyn53BX/t2by9eJnZvLAThcmyHnbWIx5Rs8VJDklKGrdIA3ileOghfzMxhdjP2hS8X/X KOJ8jwjb31uIz+3/YFLTlzmFmc3pHQtEhl/+TB X-Received: by 2002:ad4:4487:0:b0:6aa:206f:c2e with SMTP id 6a1803df08f44-6ab8f5bce70mr36215116d6.15.1716476145616; Thu, 23 May 2024 07:55:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPLyumh+jE/AutlVpcVipemoO5BlwX8gs6pHLiiSy/sDzeH/XtwPUAVKoaIpJXaHb3J49sgw== X-Received: by 2002:ad4:4487:0:b0:6aa:206f:c2e with SMTP id 6a1803df08f44-6ab8f5bce70mr36214506d6.15.1716476145081; Thu, 23 May 2024 07:55:45 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 02/13] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Thu, 23 May 2024 16:55:11 +0200 Message-ID: <20240523145522.313012-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476260532100001 In vu_message_write() we use sendmsg() to send the message header, then a write() to send the payload. If sendmsg() fails we should avoid sending the payload, since we were unable to send the header. Discovered before fixing the issue with the previous patch, where sendmsg() failed on macOS due to wrong parameters, but the frontend still sent the payload which the backend incorrectly interpreted as a wrong header. Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-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 =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.45.1 From nobody Mon Nov 25 07:55:32 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=1716476198; cv=none; d=zohomail.com; s=zohoarc; b=iSM0bSfvCrFPsHCkatL6ofvfC8tv9RA3Ma0qhalfM+uWVP6aQguT9AifPOJUeerxy1U+HgCy/0xAccbx/S3eHbHV1DQS+Rqpswd9aauR/B6SInuVJUGbjHS9hfNKuxwBvLJpEPCuZ0JA3GO4c3A9yMdcOrO8dj0wccS1Xf1F3g0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476198; 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=JAQwZsc8cKAlH0q2kUc7Sw/ErfWrVXpWDlOF1f/YOjk=; b=D8ec675z2ueFmCygFh4/FwROQ7z/lewxmIBwBwtjHNvPEtvGILxuk5KqOCikN4thUm8FAuU5632OAKsxfbwjwi8jfv56IQTBrP66V2PfGIsVMboyTm2HWPXkTmUszfT5K6rlmIB7dmft6yiNCGqI2L/mT12mMXh0kZhcTW/F29o= 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 171647619889899.28046914136519; Thu, 23 May 2024 07:56:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rp-0002eg-Iu; Thu, 23 May 2024 10:56:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rM-0002BI-S2 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rJ-0003ym-S0 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:55:59 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-10W5v2GiNry_d9v1GW7BQQ-1; Thu, 23 May 2024 10:55:54 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-43e096020baso2516431cf.3 for ; Thu, 23 May 2024 07:55:54 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e12f41a0asm148192191cf.48.2024.05.23.07.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JAQwZsc8cKAlH0q2kUc7Sw/ErfWrVXpWDlOF1f/YOjk=; b=YVwGjMDWzH4Xek+ghegA/VORyrl9uHyK+jhqg/FMcIAXHeZD3VYP+KgSW/0S6JmfOA1X2c ICLSzvGZoRBJT/moWCtFpqJ5hmNV4W3kXy1fyoLeDqig+C/Tib1Ouav8l7yFLBz8EzGgVs PyHoUiFen3ug9NEnDAi2W9xfXlSiZn8= X-MC-Unique: 10W5v2GiNry_d9v1GW7BQQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476153; x=1717080953; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JAQwZsc8cKAlH0q2kUc7Sw/ErfWrVXpWDlOF1f/YOjk=; b=BntRTPMD/POqHjGa6gXXWlX0mN/0u5gMZa7naXK3ZN/s0SMacm+cW47offtpoYwfsd ka3/DN/5V6vKBGY1Es/8DoIgOrbPvtVWEwIRUtpj0WwVcEnM0EODiias74cFBiXUh/ki p7j9HFaYlmHlAWgxDXv9kBK6tb1RkTanU91h6cN0bGAkczi7JDZTsZ374PUESBAJ2B+e AknVNNiXu1/PexVOOP0GAdhD7snghkZiDbCrqBzikEnwfFZWW0wxgm8b+Qy0DDCq5ayE ItkyMDYz+8iJBthUGmiKh7XqvljV4Kq2+mSg3ykagXE4+mq2zsdIxpJPlurBMNxM7lE1 2vFg== X-Gm-Message-State: AOJu0YwEm1xfN9M5g7OYC27AYS25si/moH+qm+PE8o+Q6YNhf2BuU+ki xXv7MPrOCl/vQ48iGpu+FC89Fb0oSPo3Wh4DwLm54cySVarj379DaaeO5prAyAabaJrgoBQtjS4 OtGxOCqXwyBL6vrVqQ4CDwbO3+wUisNE8H7RSHHW7bKtk5ClYxpUa3cbjYl2zTbhkGl2Mztd2i7 fp/K2irNtyFUKN7sLVyIUzYrVCbk/tp/yvaqLl X-Received: by 2002:ac8:5dc8:0:b0:43a:43dc:f5e0 with SMTP id d75a77b69052e-43f9e089d65mr59625581cf.9.1716476153273; Thu, 23 May 2024 07:55:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4Dfku7jRiy/tU2GetMzIMaF0liT1J8UGbSy7sP31dqk4PdtJh/rzTfx5m4mvlqRrZcS18nQ== X-Received: by 2002:ac8:5dc8:0:b0:43a:43dc:f5e0 with SMTP id d75a77b69052e-43f9e089d65mr59625151cf.9.1716476152803; Thu, 23 May 2024 07:55:52 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 03/13] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Thu, 23 May 2024 16:55:12 +0200 Message-ID: <20240523145522.313012-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476200366100001 libvhost-user will panic when receiving VHOST_USER_GET_INFLIGHT_FD message if MFD_ALLOW_SEALING is not defined, since it's not able to create a memfd. VHOST_USER_GET_INFLIGHT_FD is used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is negotiated. So, let's mask that feature if the backend is not able to properly handle these messages. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- subprojects/libvhost-user/libvhost-user.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index a11afd1960..2c20cdc16e 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1674,6 +1674,17 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserM= sg *vmsg) features |=3D dev->iface->get_protocol_features(dev); } =20 +#ifndef MFD_ALLOW_SEALING + /* + * If MFD_ALLOW_SEALING is not defined, we are not able to handle + * VHOST_USER_GET_INFLIGHT_FD messages, since we can't create a memfd. + * Those messages are used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD + * is negotiated. A device implementation can enable it, so let's mask + * it to avoid a runtime panic. + */ + features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); +#endif + vmsg_set_reply_u64(vmsg, features); return true; } --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476316; cv=none; d=zohomail.com; s=zohoarc; b=PFgGLPiz++aP4RL/2Lguhjhn3H0VyLEWCYvnUp7WwwY0e24rnlN1ycQH25QWQ03XmMDrAFZUEBYkBYbOE+xVOhbFU4vfAvyndZlNLV4o5INy0rCWZxqLWCYXM3my+n4sT2iwIh3UH1vHtNkCkwEKmpHOwSfR/yZdokP/NofAT9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476316; 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=hN/AM+u5Z+nLunf2Rn+i5MH2xtaDn5R44afvB9no9H8=; b=EcrkYq22xlFKpL/gPg2yWm3gTf6qqz7UrN54jKT7MoHS3YVFRC4SwKzJuJwzj9O8jXniEsXCiQOHM17ILLd0o/hkfVSWLUrfj/uTvSqz8BwEslm+7UVq8EZpPfuRXU78aK+cubQjJzC0ZBh3kfsK8AhGNb2x7LWojsFoX9621yc= 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 1716476316606525.0743563650698; Thu, 23 May 2024 07:58:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rq-0002iC-Gq; Thu, 23 May 2024 10:56:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rS-0002I4-4g for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rP-0003zQ-Cs for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:04 -0400 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-227-RWgf_cylNmaV6ZoCUsnj-Q-1; Thu, 23 May 2024 10:56:01 -0400 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6ab7b258941so3344926d6.0 for ; Thu, 23 May 2024 07:56:01 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab8b361681sm11824566d6.84.2024.05.23.07.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hN/AM+u5Z+nLunf2Rn+i5MH2xtaDn5R44afvB9no9H8=; b=Krie9YBayxWKzy+uzdLHzd2eYitjNpY+i8DYzZG7bvVTOUHO2xJxGFmR4cS3ZTe0cA599K vNgYQQ+Nav34nZEJzyeN0Mpj2wpdRsMP5CoWUTwQsWsweqCfjDZ16eyts3wo8tnwk+s8gp yBSSklP8r7n7IWnUdlegpsglPxGUn7I= X-MC-Unique: RWgf_cylNmaV6ZoCUsnj-Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476161; x=1717080961; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hN/AM+u5Z+nLunf2Rn+i5MH2xtaDn5R44afvB9no9H8=; b=r+r+8TRCu5FP69qT4hWdmi9QR1aoVnVZ7dr8q1MYDYdL86aj3FhDRMoRXF2C4TGdKM /7/TzRLnBGRId0CY5JzOOEF+W5GSSvCZ9uh/SNw7zMsQ81hPkdQrWxUjDhY2u7rYLG0F OOkCTOG0eCEFl26mWJnCm+X1e9D5/zsRvTEp+mPTcjnDaVcpZeRcYWHe4FIgbSMI5DIS 7ro6DGF1NFiNuBewo38aQC/dS1to2pCsFg9t1zowpUrPwMVkuFWZPhWgSpgU8tCThIzl aVTRm6pKOjUKzPTLcYfrh9j+gug7mHaihoxQonRhmJwmpnqjowTxk48jZvhBdzpmliYL 87YQ== X-Gm-Message-State: AOJu0YxtGqwGdpZeMbwWWrT9cBJ13rCp3qx73hoihgH6n46PjiKwOcTl yvj9Dh5GLlJ+OobBDcjqXmD2tcOoSeO+/frFsvGxyoQjYQ/LOMY1Mf9refbIpizm3rKGo+x13Q2 qz0i82CMC+reRHUCgoyvqwrcxrRYSqG6QYaYF+pSQsTp1Eg6ZQcwjSjezZ3k0bQ/4zqEnXd7lr5 BAMvWkRii6Og2qhSROkMOoks7N3prsFP2SY54s X-Received: by 2002:ad4:4f54:0:b0:6ab:8a1b:6941 with SMTP id 6a1803df08f44-6ab8a1b6b1bmr35374436d6.7.1716476161073; Thu, 23 May 2024 07:56:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYM6uGiT4bQfpAzvCAcmG6s6un94sj/pZW+pZmEpB7DSlUh5LBB6cJ2/hoTPcTM92uGDVcrg== X-Received: by 2002:ad4:4f54:0:b0:6ab:8a1b:6941 with SMTP id 6a1803df08f44-6ab8a1b6b1bmr35374046d6.7.1716476160643; Thu, 23 May 2024 07:56:00 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 04/13] vhost-user-server: do not set memory fd non-blocking Date: Thu, 23 May 2024 16:55:13 +0200 Message-ID: <20240523145522.313012-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476318625100007 In vhost-user-server we set all fd received from the other peer in non-blocking mode. For some of them (e.g. memfd, shm_open, etc.) it's not really needed, because we don't use these fd with blocking operations, but only to map memory. In addition, in some systems this operation can fail (e.g. in macOS setting an fd returned by shm_open() non-blocking fails with errno =3D ENOTTY). So, let's avoid setting fd non-blocking for those messages that we know carry memory fd (e.g. VHOST_USER_ADD_MEM_REG, VHOST_USER_SET_MEM_TABLE). Reviewed-by: Daniel P. Berrang=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- v3: - avoiding setting fd non-blocking for messages where we have memory fd (Eric) --- util/vhost-user-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 3bfb1ad3ec..b19229074a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -65,6 +65,18 @@ static void vmsg_close_fds(VhostUserMsg *vmsg) static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; + + /* + * These messages carry fd used to map memory, not to send/receive mes= sages, + * so this operation is useless. In addition, in some systems this + * operation can fail (e.g. in macOS setting an fd returned by shm_ope= n() + * non-blocking fails with errno =3D ENOTTY) + */ + if (vmsg->request =3D=3D VHOST_USER_ADD_MEM_REG || + vmsg->request =3D=3D VHOST_USER_SET_MEM_TABLE) { + return; + } + for (i =3D 0; i < vmsg->fd_num; i++) { qemu_socket_set_nonblock(vmsg->fds[i]); } --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476304; cv=none; d=zohomail.com; s=zohoarc; b=AD1ThI+b3azd0pTUb9KAGEWi7tsCboJKqFo42SkeE6L87pRvOTbZrzG/viNqeBxr4RLBDEe6QGot2eYvZrOynFVOuiT3mHkctUU/3hki1+LBg+O0jcnWG00QoVrLVcRowC5pLcJLlQW55H4e6gpvT2l9uuvSl5R8FCVgUdFjamo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476304; 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=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=JToDLYlbg8FB3U4wPhFQnPLNWnOwmE5ciwtc2EhutO6LXroQUDBUqRPrNDJsBp7EbLk6NzrCnBdlZhJZivdM4UFhxG8eRQTbiDx8bSBzj44tGq35yMiGdprCS1pngt6Lih9CFnzqChi4J/PpkQkfyvyRw1g0AqGcMB1Dzrz4qoI= 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 1716476304834812.7261899141824; Thu, 23 May 2024 07:58:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rt-0002kb-AE; Thu, 23 May 2024 10:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rd-0002Os-Cf for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rX-00040H-W3 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:17 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-Q-9nhn3YN5aDdWTJOR2o-g-1; Thu, 23 May 2024 10:56:09 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-43e349c3983so2218661cf.2 for ; Thu, 23 May 2024 07:56:09 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43f86a12d71sm56614101cf.17.2024.05.23.07.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=gsTrVkhdQ5T6u1Ub/wibKHk+3YK0my6WsActOfUHLASS31nfjlXCudjjqBwKEIO7jPc3yF xp40sxTTl9Obcfbvmw8ATAjHQP4AY2742v5LxfIGLz4ntVtS++eek2HjAnQsyN4QDZKsTv gUHP+Jsv2Lag1iDb1EJ5QIwsdXc+/Z8= X-MC-Unique: Q-9nhn3YN5aDdWTJOR2o-g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476169; x=1717080969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=jmpAV36N4WXjkg0E6Lt680k8YEflLGfhiL158YLta186Lm3J9lX+8RmPLEVVlqpP38 BPFn4BSnIlbzdw+beGArowB53Jp/llcx5csCIPAlcfvuuNgovJZssugdIieFZxX3BwPS qIVnXjl1ljgEM32AsYevh1ayo+yzHuy8BfxpKCfvL6EBEB4YzPzZyHWQ7HTE53R+z6zP pEXNp+Ca9TBvdkmTRAFtszz8MRoOGN+YnFc7B4S8WI0RJwKfp95C2Hkjd91n4zWVMyUZ rdINTMhZdg8FwFd9D2JmdNNTxafPooL+Y5JBCmstWYaOusJLSOotpPjMy4Yd4b7lglqG SYbg== X-Gm-Message-State: AOJu0Yx4APf9tJpqf0OhNorgdbIhxDCpeJnWl6nt/u9IjUWFhkutyuto n7Ww7YWUGAdKKc9IjXj1PLWKVp7FhDRcWbWPEXZ5ax6w1KvY5Ld2qBos5bl5817JnZDF/Rlf7By MjwhNEpCTgsK0aSFVyXNq2/SWjsuS56S2r6Y0Iu7GEta9yDLMlayvYUKHDd1gRhCEadn2c6ppZP OlGYQlTNHmMhI9asb7c0lVPgdd8Sh+8StIj5HL X-Received: by 2002:a05:622a:1305:b0:43d:f4d3:8990 with SMTP id d75a77b69052e-43f9e0c04cfmr53940431cf.40.1716476168848; Thu, 23 May 2024 07:56:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4knHCI1y7ZQ8UZ51KzryHPvknrU7ndeoKWFHCJZ8XCXb84ppDg0sZIsRtAfZHzmWbF8zKPQ== X-Received: by 2002:a05:622a:1305:b0:43d:f4d3:8990 with SMTP id d75a77b69052e-43f9e0c04cfmr53939981cf.40.1716476168398; Thu, 23 May 2024 07:56:08 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 05/13] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Thu, 23 May 2024 16:55:14 +0200 Message-ID: <20240523145522.313012-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476306642100010 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. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- contrib/vhost-user-blk/vhost-user-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-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.45.1 From nobody Mon Nov 25 07:55:32 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=1716476201; cv=none; d=zohomail.com; s=zohoarc; b=kbFSFc2JwlJGU5UQ2aeEr4bKgjFfjLm3nhafSk/o/kXgac91OUHid/y5JLUxetDnhx4+bCIByzKZ0raP8ga+L5+Ikoav9+V/lrSRLu/IeE7xfXPepevyDO+vG9DFjTs2QIz39q+EX2nfvv032Ym80y9blnB43xObwGoTdWJCXHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476201; 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=aZ6f2Wy9JZAIyu5wRg6z9P9zvSbVeUQdfiHCy8ESziQ=; b=ZGbY06UXLvRaROhHD0LzwVOfARWEgVCPVcJEBz//YvbsjQWp2znaIptfLFiygcrQtsXjw/2s67BS5aElyCFv0jI8TcAnAQdA5vatxIKlc2cj9Ye3VHyhypy9rOImOv7Nsw6zFB5KeWBNdpSYuDa2rcRDrvzcBNLLVjPZ2hxPSlM= 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 1716476201795603.7706693397163; Thu, 23 May 2024 07:56:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rr-0002jT-TQ; Thu, 23 May 2024 10:56:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9ro-0002bY-BF for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rj-00041A-Fy for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:25 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-232-Z2MGVX3CN9CGjLg5sWTOXQ-1; Thu, 23 May 2024 10:56:21 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-43df9a3fc0fso2383831cf.0 for ; Thu, 23 May 2024 07:56:21 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e0a4bdce8sm159322281cf.18.2024.05.23.07.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aZ6f2Wy9JZAIyu5wRg6z9P9zvSbVeUQdfiHCy8ESziQ=; b=Gzxbb3LOnsRpbxN0D+sfTJ/FP7Swzcdv17IUwHXGZTsv3CqqJeBSHnnO3Q8OgdTR4ICn4p P4jj/og3jn2HeENP1kZUvdI3+QSdwlEKfWzR0tJQnvPb0qBjlGMh4T+d0MtI6iGiS3VahD wKbAX8z4GduXHi6TTrM47+xXeF/MO30= X-MC-Unique: Z2MGVX3CN9CGjLg5sWTOXQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476177; x=1717080977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aZ6f2Wy9JZAIyu5wRg6z9P9zvSbVeUQdfiHCy8ESziQ=; b=UGU9U8J/zZieXBk74OP4QwyxcgMaYN/MRkWrEW19fLcThOtIf69ZnYBmNUztZdN9mp jdvOIcmYf5nE1XxKQOzJ2TIFUZpXr/q5DWVIQmu9+56J0LqTOZacv5JB+UbtZPOYKO3t oEDtVrHTZH+E5VPvyOypGrobf3a5085ZSJausGfgrU3+viMQBPwt86qGD4fNFRMRGX+C xER4/j1pNr/HPEWfI48ni9gnTm9ZAeQ9j0s6SFy028LydY6B8IN7pR+X9LEGJLujXhyC c90pbxDK+8v25zyIUUg8cnk2+MoartGX7ONAWNedDRp1tSMBLxYLPoHyEOs/1dzLwD7y Yw2w== X-Gm-Message-State: AOJu0YxZym20arxOgjnvCm/0wdSPxMGSrTzzwp/OrtaywEz225D/2X6O i7+sXoOsQprJDeG/nl0Bvwv5+1Y6KvZ2uBIJDV9MhM55jvrQq4Zph4+zq9ZhcU57YLHfKP8zP2W 1Wc36xlMkX9iOQUYGLXOL7RCtALhRjuHjbmjP26YwWUqrMLVibpVZwOp3343c8vCEh/7OA+/sS7 2nltz//WJlIUrP5fKtUbELF06eA4Jhya3QTb1m X-Received: by 2002:a05:622a:1a1e:b0:43a:ed8b:75b1 with SMTP id d75a77b69052e-43f9e0f3220mr60046981cf.43.1716476176884; Thu, 23 May 2024 07:56:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBOgeLvfyvxxo1WQ91OSaQxysuTauL71eZuvZYFDk4b9lBg6eKujg38dT6UQ4V+k2bfI7hQg== X-Received: by 2002:a05:622a:1a1e:b0:43a:ed8b:75b1 with SMTP id d75a77b69052e-43f9e0f3220mr60046581cf.43.1716476176298; Thu, 23 May 2024 07:56:16 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 06/13] contrib/vhost-user-*: use QEMU bswap helper functions Date: Thu, 23 May 2024 16:55:15 +0200 Message-ID: <20240523145522.313012-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476202197100005 Let's replace the calls to le*toh() and htole*() with qemu/bswap.h helpers to make the code more portable. Suggested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- contrib/vhost-user-blk/vhost-user-blk.c | 9 +++++---- contrib/vhost-user-input/main.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index a8ab9269a2..9492146855 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -16,6 +16,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" =20 @@ -194,8 +195,8 @@ vub_discard_write_zeroes(VubReq *req, struct iovec *iov= , uint32_t iovcnt, #if defined(__linux__) && defined(BLKDISCARD) && defined(BLKZEROOUT) VubDev *vdev_blk =3D req->vdev_blk; desc =3D buf; - uint64_t range[2] =3D { le64toh(desc->sector) << 9, - le32toh(desc->num_sectors) << 9 }; + uint64_t range[2] =3D { le64_to_cpu(desc->sector) << 9, + le32_to_cpu(desc->num_sectors) << 9 }; if (type =3D=3D VIRTIO_BLK_T_DISCARD) { if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) =3D=3D 0) { g_free(buf); @@ -267,13 +268,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/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/mai= n.c index 081230da54..f3362d41ac 100644 --- a/contrib/vhost-user-input/main.c +++ b/contrib/vhost-user-input/main.c @@ -51,8 +51,8 @@ static void vi_input_send(VuInput *vi, struct virtio_inpu= t_event *event) vi->queue[vi->qindex++].event =3D *event; =20 /* ... until we see a report sync ... */ - if (event->type !=3D htole16(EV_SYN) || - event->code !=3D htole16(SYN_REPORT)) { + if (event->type !=3D cpu_to_le16(EV_SYN) || + event->code !=3D cpu_to_le16(SYN_REPORT)) { return; } =20 @@ -103,9 +103,9 @@ vi_evdev_watch(VuDev *dev, int condition, void *data) =20 g_debug("input %d %d %d", evdev.type, evdev.code, evdev.value); =20 - virtio.type =3D htole16(evdev.type); - virtio.code =3D htole16(evdev.code); - virtio.value =3D htole32(evdev.value); + virtio.type =3D cpu_to_le16(evdev.type); + virtio.code =3D cpu_to_le16(evdev.code); + virtio.value =3D cpu_to_le32(evdev.value); vi_input_send(vi, &virtio); } } @@ -124,9 +124,9 @@ static void vi_handle_status(VuInput *vi, virtio_input_= event *event) =20 evdev.input_event_sec =3D tval.tv_sec; evdev.input_event_usec =3D tval.tv_usec; - evdev.type =3D le16toh(event->type); - evdev.code =3D le16toh(event->code); - evdev.value =3D le32toh(event->value); + evdev.type =3D le16_to_cpu(event->type); + evdev.code =3D le16_to_cpu(event->code); + evdev.value =3D le32_to_cpu(event->value); =20 rc =3D write(vi->evdevfd, &evdev, sizeof(evdev)); if (rc =3D=3D -1) { --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476303; cv=none; d=zohomail.com; s=zohoarc; b=gopEV0JIls1Np7kYf2hr9ZTh9dKb1ftBS61HW2quOB4LcKbxfPlV5gCeXHGxKWTxnpTQtTCyUlskRucQ0Y/kmaNMflJAl7TfAaErL7f3dSKY1HPjEsBnci90PKAdhNbGUdk1gQyQ335ZKcD5/ZEr4LruwgHdwKWNx3cBzh/jtF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476303; 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=8Qg0j+YK7VRBZmAY9zpmey1/lx7IRhJZZvR9stxcVsk=; b=lSIruUGe6ZdvdM5qydJlEvdezcthPUQeWSWco9GpDKEGvOo5uODl2nQcQ9JDqM5M+rj1A01GHkWAGLpKgZDpdzSWHPOssAF2C1/aI3KK0/4t+2dq8vSWx7TomJ4oRfYRUkCaoMMde7wy7YFMuz9YySA7KCMZvkWjOIEPlvqzGH0= 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 1716476303355702.7646726888669; Thu, 23 May 2024 07:58:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rx-0002nM-OC; Thu, 23 May 2024 10:56:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rw-0002mh-Ae for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9rt-00042J-Qs for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:35 -0400 Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-o5hEtvDgNWKAzxev31ZE9Q-1; Thu, 23 May 2024 10:56:31 -0400 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-24540b99e23so1682882fac.2 for ; Thu, 23 May 2024 07:56:31 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e046467a4sm168864281cf.83.2024.05.23.07.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Qg0j+YK7VRBZmAY9zpmey1/lx7IRhJZZvR9stxcVsk=; b=fWt8z2YcMxRFV1BrAVeXMLRsm42tq1UxU19t5R5/wRfg5gaQa9kp/EK1UwPdUsfiNztRPq 71iqFLslRx8SGwMdUsqqOwg0wq/skrTakfHqrNap9fArXgLW6u2AcE5rQQz0qAb3RXKMQn RztEp7R4+jqy4wUOI679LMzDvsg+fns= X-MC-Unique: o5hEtvDgNWKAzxev31ZE9Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476189; x=1717080989; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Qg0j+YK7VRBZmAY9zpmey1/lx7IRhJZZvR9stxcVsk=; b=FeAfdfkcjwV1ceBifnlZM4vOFDkpwAEFif9ybTUsMlYC+PB5TM8N2vDRDXfwJMr7EL dcBtBtblgDnJeBiGWekOsqm7j2FW4K5N4EcAHKrcewsjfEcORlyOcjd0PFPIvyWsAI+B MZ/tphfVP2Kk0fSZg4flcjPgIL/KcMs1yVLiWH07cG6U0yUHlyMzYFBPN0GlAnzMSwcW DPXmbTFPpP4+E4hjfrnOtESIROe3c3swOpp8gHRqEyzlvPQM90CPoFlf3ydQXapn2yY2 9y76C/q8lBAeZOOjRJyahWWStEGvsA/BJqiqnaj7Hwz7ubC7BvKv0EDt2bizFlpbIRKq KsYQ== X-Gm-Message-State: AOJu0Yy4tEtB/lstU0zDg9HfBHmHlJ1oxHeTq6sbhth9Z7UM0CKnekt5 y/UtNacifaY5aw6Ost1ZGZN82AQ9T5JAjUmSHB+6ARVd4rC2UqR7L4cyVdTuPFX9vP4lka/X4rv I2BZ4yCe5TPXigmzb8KFrKb+CNUmM4AEXuC9GD+ZLQ3XjUsiq34anIzfPDYjCj62k4zzh4j9RZL 9lYtZYT4uVv58axbbPp9CywIevszZgGdsQPFps X-Received: by 2002:a05:6871:5214:b0:245:4477:e9ed with SMTP id 586e51a60fabf-24c68aa76d1mr7798614fac.17.1716476189022; Thu, 23 May 2024 07:56:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEb6trD4nmHXJcjOEZGki5/Pkw4kzLac+sW4oiUM9BobY12st8spR+5ei897Gtpqi+R2K2DYA== X-Received: by 2002:a05:6871:5214:b0:245:4477:e9ed with SMTP id 586e51a60fabf-24c68aa76d1mr7798483fac.17.1716476187003; Thu, 23 May 2024 07:56:27 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 07/13] vhost-user: enable frontends on any POSIX system Date: Thu, 23 May 2024 16:55:16 +0200 Message-ID: <20240523145522.313012-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476304530100001 The vhost-user protocol is not really Linux-specific so let's enable vhost-user frontends for any POSIX system. In vhost_net.c we use VHOST_FILE_UNBIND which is defined in a Linux specific header, let's define it for other systems as well. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- meson.build | 1 - hw/net/vhost_net.c | 5 +++++ hw/block/Kconfig | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index a9de71d450..5a6f7a36eb 100644 --- a/meson.build +++ b/meson.build @@ -151,7 +151,6 @@ have_tpm =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 fd1a93701a..fced429813 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -34,8 +34,13 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" +#if defined(__linux__) #include "linux-headers/linux/vhost.h" +#endif =20 +#ifndef VHOST_FILE_UNBIND +#define VHOST_FILE_UNBIND -1 +#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.45.1 From nobody Mon Nov 25 07:55:32 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=1716476264; cv=none; d=zohomail.com; s=zohoarc; b=cyz1K3y27gB8EcNqtwR+JVEDbXUilsI9E3/i42w/4oVyqF8Ikmd27dbX4IYUwQNOFS5uCZ1ifIzsHtYeTJDosfUr937H2qA7+CrO1PIkYOMasq5KVLOvqSlEzyc0Sj1N8FFDMI3XmDisIcY4VsdKY3OpGUmJFrgTxlGsgqSKTbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476264; 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=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=Vte/3bI92hEySkoMy9KCjSUmmTJ7JJL98d7/ixSYRsXqRYiT2ZZ4/HQ85gzvZMsvP287LRlQ1lC5KVaOhtVE8wFLXWGnj6WtU0muRLtgltX545PlcES2Ioyeh168Av4oa/EG6CHNhYDBj0SWSCUDpAp6PReMVqj1+wijiJQX+1Q= 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 1716476264104584.284180004537; Thu, 23 May 2024 07:57:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9s7-00031j-RV; Thu, 23 May 2024 10:56:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9s4-00030c-VP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9s0-00043E-QD for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:44 -0400 Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-DzeDc88yP4WBruWdu44NVA-1; Thu, 23 May 2024 10:56:39 -0400 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-5b27fcd20ebso1526087eaf.1 for ; Thu, 23 May 2024 07:56:38 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab840e24eesm15842686d6.135.2024.05.23.07.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=HfxUAllZPGHl3whgv5YUq//NUnuq2tnnvNGFx/dns3UPlzNlEuh0r2Eq5fXd2p+ZkcTMMk g1eCqgognrvzHqGhzQ+OKL+H0rD7AlXYHJnBT1oPVdBfcPkOqODfU5u0P12gfNjf8lqXUP yPtBkhpFAfcgLcvu5mTEGUuqLRSaSbA= X-MC-Unique: DzeDc88yP4WBruWdu44NVA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476197; x=1717080997; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=jgPBzhEZ/4otFWGw1xWIBrm8TeUSG1xx4KyvCQ2gmDA5FlOIXQ+koayfnGFRIQAEwR qjppRsv0Qeb8S4dnvHx9F7wa4VlgImwCIbTRYPYQQsWq0Jsj5Uy9J0jdyEwj8Hes1LIB prpKCYmEtAPUNZih94VdNCqiAx2faWrQQTscImGm+A+vqF4Fr5t05ofbGmd2MhZpOlrg MUpOd3cy9UUi4dVWUB71dyj7BvRiHXISoDO3CNEQy4WzUPhA3ncy9t7utI7ihwA/171C xtr5uvnPcq01I9Kd8em5ZXFPtwpLz2hLJxF/PZU+0PBW46na7kqXjJb/l5ela8oNOt36 cVqg== X-Gm-Message-State: AOJu0Ywig0ivQV8QT1sHbk2DB6kJmE7tV1NPrFxLmfB1IyS5JpCZ+Im8 XCBuTnAFfn1UFfWu9ZV4p4ucR7HfAMQNJG4TTfNF9Zfukp167TdsEBBUfAEdR6B61W1p6RcITjH hUmwxLXAXiwZxq9K6h8GyZ1kE7tGku7TbHfxw1dKFAlhg6x6goadsbd0gxPhv2mpLzwaCqff9Q0 CUtryabwuM4aqFLUJme0kV/+8VUYHLOi3roCM7 X-Received: by 2002:a05:6358:a08:b0:192:8eec:3280 with SMTP id e5c5f4694b2df-1979213fd5amr401872355d.29.1716476196623; Thu, 23 May 2024 07:56:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHg8MltlA9GvC1ZpHWRCt5JxW7+kyPlmn9hVQ7/1VFxvoowgNrC3TzwYmjfT55P06G3gkn/7Q== X-Received: by 2002:a05:6358:a08:b0:192:8eec:3280 with SMTP id e5c5f4694b2df-1979213fd5amr401869455d.29.1716476196033; Thu, 23 May 2024 07:56:36 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 08/13] libvhost-user: enable it on any POSIX system Date: Thu, 23 May 2024 16:55:17 +0200 Message-ID: <20240523145522.313012-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476264379100008 The vhost-user protocol is not really Linux-specific so let's enable libvhost-user for any POSIX system. Compiling it on macOS and FreeBSD some problems came up: - avoid to include linux/vhost.h which is available only on Linux (vhost_types.h contains many of the things we need) - macOS doesn't provide sys/endian.h, so let's define them (note: libvhost-user doesn't include QEMU's headers, so we can't use use "qemu/bswap.h") - define eventfd_[write|read] as write/read wrapper when system doesn't provide those (e.g. macOS) - copy SEAL defines from include/qemu/memfd.h to make the code works on FreeBSD where MFD_ALLOW_SEALING is defined - define MAP_NORESERVE if it's not defined (e.g. on FreeBSD) Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v5: - fixed typos in the commit description [Phil] --- meson.build | 2 +- subprojects/libvhost-user/libvhost-user.h | 2 +- subprojects/libvhost-user/libvhost-user.c | 60 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 5a6f7a36eb..543105af2a 100644 --- a/meson.build +++ b/meson.build @@ -3155,7 +3155,7 @@ if have_system and vfio_user_server_allowed endif =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 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" =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 2c20cdc16e..57e58d4adb 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -28,9 +28,7 @@ #include #include #include -#include #include -#include =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 #include @@ -52,6 +50,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.45.1 From nobody Mon Nov 25 07:55:32 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=1716476298; cv=none; d=zohomail.com; s=zohoarc; b=KEH8FKlOQlE9jqG813Dmj5BzoSa1ad061vd9Y8iIjS9tTxrZfkDFBwJUXEXT53WJNqeVqsLnZCZUD4cIJZnBNgxYDHiKfwHkvyMRcYM3Q3hbxmcmrET0DAk4B4y2AhxoOykWxkI+lUz4edzT2C7IcDSTGExAj3UxYfXmWtDR4JM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476298; 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=edUAbB6FYQtNYztKJ8aeeDlCGuti83HdzsdflmaIRq4=; b=YptXNnV1Gzmo6SCKsTZq/siQmxdW9/z2AqrAamQWIXcPCs54woBkCrwRZfes/21natNlaL4T+PXkEuSpgMUct7DecMfanuv/6V6g/C07Lw9DlPg13oWgUK4NmVae5dFU9jUCN6SkdLvsOtAJe+KctWYqGF/xoGAYj33Xbdy+j9Q= 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 171647629835388.61766067344445; Thu, 23 May 2024 07:58:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9sK-0003Xy-Qc; Thu, 23 May 2024 10:57:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sB-0003CG-4W for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9s9-00043u-5V for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:50 -0400 Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-CiM65WmPNMWilqxtYX_PVw-1; Thu, 23 May 2024 10:56:47 -0400 Received: by mail-ua1-f69.google.com with SMTP id a1e0cc1a2514c-803178218b3so106604241.2 for ; Thu, 23 May 2024 07:56:47 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1d704dsm143641646d6.116.2024.05.23.07.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=edUAbB6FYQtNYztKJ8aeeDlCGuti83HdzsdflmaIRq4=; b=cOEm6KoQjGyWc1HcwWbM5I+kuP+ZZ+3L6yn5HtuDPaTjy3YOeMvT8hqcAvZzHxLj2Qv/9I LASCk2p8WhS2nW5RR18fEZ66ul/DqfXPYCfaRckIMuP8uvHkcCKyweggc3fWdJKzwdAPC4 JNObbiDDHXBOkYIxmvDt2+CUX0y/aJ8= X-MC-Unique: CiM65WmPNMWilqxtYX_PVw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476206; x=1717081006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=edUAbB6FYQtNYztKJ8aeeDlCGuti83HdzsdflmaIRq4=; b=goDSgezTk2xvvMftC7W/3Slk2WLCI3sM5HG3JhfOm1xgORySyokTniYc19n6Fc8X7M 0nZW1jtknxBgKviU2yPWWkylzpfuRFJkqlkFY14xhiNhdIThx4+K1pUPta8ek+EzPKNU wBT0EcxIXjz7lXsQGzMO6Y3N38l6+yFJ4haNbrAHiCuWUk1SEs5YRVWZ19A2FR4IwJIk Bn9AivEPhEzIgwizzqpL5QAwLcDekMDyuzQChpewl1DvjljR+mjm4skBkcDYhslmkcvB eivoFf1NRBp6cNXZYhRLN6rd1tF7ixGE6F/1Fj8RZwz7h7ZEPSqBqH6/FkfpkJti1Dgq /lKA== X-Gm-Message-State: AOJu0YyMRZLrHI8xPPC7oEykHvLqKjlp7fhBNDW4yBrZuj9mD6BUxhfn ZkuyUOjcF3WHmoSXy8akjdFKGV07xq/QPeXeMiuzkqMhB/xAHZqsiYlT6Rztq1l2g9jDmZrSizH pAHKoGPZNGxDQNERtU0Mrar6538ImPp08fvbgrLekztVggaow2xZLx3dlEEHhtiv9prNiyZq0Ow ojkmOnJchmMCSptGKZBvuammKtbUJrHmL5qOMu X-Received: by 2002:a05:6122:1829:b0:4dc:b486:e4a5 with SMTP id 71dfb90a1353d-4e212f1b787mr5172789e0c.0.1716476205928; Thu, 23 May 2024 07:56:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmySploH/h2W6a6HnRYeB4E6EpdvHnDW61lCXGKV1+O0F44Qy1IHPHfbppgWanotLDjKsH6w== X-Received: by 2002:a05:6122:1829:b0:4dc:b486:e4a5 with SMTP id 71dfb90a1353d-4e212f1b787mr5172737e0c.0.1716476205360; Thu, 23 May 2024 07:56:45 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 09/13] osdep: move O_DSYNC and O_DIRECT defines from file-posix Date: Thu, 23 May 2024 16:55:18 +0200 Message-ID: <20240523145522.313012-10-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476300513100003 These defines are also useful for vhost-user-blk when it is compiled in some POSIX systems that do not define them, so let's move them to =E2=80=9Cqemu/osdep.h=E2=80=9D. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella --- include/qemu/osdep.h | 14 ++++++++++++++ block/file-posix.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index f61edcfdc2..e165b5cb1b 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -325,6 +325,20 @@ void QEMU_ERROR("code path is reachable") #define ESHUTDOWN 4099 #endif =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 + #define RETRY_ON_EINTR(expr) \ (__extension__ \ ({ typeof(expr) __result; \ diff --git a/block/file-posix.c b/block/file-posix.c index 35684f7e21..7a196a2abf 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -110,20 +110,6 @@ #include #endif =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 - #define FTYPE_FILE 0 #define FTYPE_CD 1 =20 --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476262; cv=none; d=zohomail.com; s=zohoarc; b=i5TuT8Kp/5lU1w/4A/7qnaSE+tVcTZuNNSAu9uf3SoJE3NzKyk/08lKFWta1eI7A9TE92s4t5iI8uB+aDwom4lRpyRvM06rW6Jue3BW7P9yDs1OsCeJGlCSNY+9aAy+Lo3NcLBAraMyYeRzuQ9oHeC5De7yptit5qKPr/jyDx4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476262; 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=zZczhXGl9TGqY4DRFWizTO3f/10y7CBxCovWDPv4GOo=; b=KdyDcvD/fbw5LUyxZulwXEjV2WgDpd9CvYSRx13u7jI4SKio8SXoU6O8413uC3y4hbx3iI8jXJxbF2K1T0fd1Fp3LQZJ8DLy8yYju4zwEBLizDJB4IfmcbzIVlulvJL/q2Q2MEMS+lXi/uHL5gfdPfMbk4xuM6DhlkyfiNUyyVs= 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 1716476262922463.4893739503606; Thu, 23 May 2024 07:57:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9se-00045u-Kp; Thu, 23 May 2024 10:57:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sN-0003oJ-Mb for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sK-00045p-Ng for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:02 -0400 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-LRgyzyCJNeabMvak--grIg-1; Thu, 23 May 2024 10:56:58 -0400 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3c9ac6d3bf6so1217006b6e.2 for ; Thu, 23 May 2024 07:56:58 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e3a57b396sm101182851cf.24.2024.05.23.07.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zZczhXGl9TGqY4DRFWizTO3f/10y7CBxCovWDPv4GOo=; b=BPn0yU0LiPF6sQwwCC1WOYBzF8PCpRwxFLndPrTQ2yUaSedGQyj0DOBTGat9UYorQgAkWu JgGi9byFuHpyy+1diVEOplWo3PghBqbT0t9+KU6n2MUFQ1L89jz9MQAy897sN/JLDf1Gh1 O8TXucjR5lz6Oaebj+Elzku22pxg+N8= X-MC-Unique: LRgyzyCJNeabMvak--grIg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476216; x=1717081016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zZczhXGl9TGqY4DRFWizTO3f/10y7CBxCovWDPv4GOo=; b=NFFspqzUY4NAl5oTq6ajIs0Ot5d6BSCwKHrSrdg1YGj9WS5lHqkLp+MwI60d7ssZB4 zDMppeU3MD3ZA+h6u37+7OnVseZ2cXDerMG2d7l7frIDtl3zdKdItinffgcNW5DtEBY3 2y5KUWES4LLSgD+i6fClLfpq9jCUm3FYlSSjDQ8MpZTMTIXbZddH9X1IIbVkKq4LFR4W o86Vp3fCXXfoCmRkyjPEiky1rfiSYEvERAYTkGMuv97oQNGaApgo8PxEyvBzC2FaTGaW dmOlDD3hqrfqWZ+CqrlmDjdvBZC5nc61EQmDvyzZWYPq90MF8L+bGAFET4R0gGJKHfLO SRpg== X-Gm-Message-State: AOJu0Yx6esA4SbiWEdsfvvqXgr9dC7Kq5CbAPKEQx5WGWU31OZzqI59k n04c8WINRLpC4Y2o3M359kyZTdWjHHBMkLQubtioBCo5ll5g+a6QTdI36kRk3gUVfeVyRsMeZnp bhKV3GqBXL865/mEGWtCR98Ug0KUM9L6EYlcbKukGvvfBDFfuqM+zvmxk1ZGHzFQk0KHbl1Lh+m sgFNEJJ+mSW/bilbKOae00gb6wkNU62mXdJJ68 X-Received: by 2002:a05:6359:5f06:b0:186:131e:822 with SMTP id e5c5f4694b2df-19791dded6cmr581440755d.3.1716476216058; Thu, 23 May 2024 07:56:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExActTSjAj/wN/d05Xe/g/oADokunszHmJ6OxbWJtgD5bbKHoaoMylS4WESHfNPf1t0lqpZQ== X-Received: by 2002:a05:6359:5f06:b0:186:131e:822 with SMTP id e5c5f4694b2df-19791dded6cmr581435255d.3.1716476215441; Thu, 23 May 2024 07:56:55 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 10/13] contrib/vhost-user-blk: enable it on any POSIX system Date: Thu, 23 May 2024 16:55:19 +0200 Message-ID: <20240523145522.313012-11-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476264360100007 Previous patches made the vhost-user-blk application and the vhost-user-server.c dependency buildable for any POSIX system. Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella --- v5: - O_DSYNC and O_DIRECT definition are now in osdep [Phil] - commit updated since we moved out all code changes v4: - moved using of "qemu/bswap.h" API in a separate patch [Phil] --- meson.build | 2 -- util/meson.build | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 543105af2a..06a1835a09 100644 --- a/meson.build +++ b/meson.build @@ -1974,8 +1974,6 @@ has_statx =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/util/meson.build b/util/meson.build index 72b505df11..c414178ace 100644 --- a/util/meson.build +++ b/util/meson.build @@ -112,10 +112,12 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif if host_os =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 util_ss.add(files('yank.c')) endif =20 --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476264; cv=none; d=zohomail.com; s=zohoarc; b=bSc+q3HIaN+VrwHjKsmCg16f2L6qZj0GDreYwKOCOuy9Yv6N4cnlR42PTvQv3nc6tSmPm1NO3t2Hy281EDlxIbg7SnqTbkFm/OSjnLlQdWq35akC/K7VtXYiPWspZqvJ3Ya7vqp5/2cNQBtcO643NzC7blxWaPa1iJv9kC/6kyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476264; h=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=JLEKuIjNUE0upngVj1w8ZNUIo5SFQUiVbbxpLKuiIHs=; b=N4FClcFbUS3uncDBwKlcU/s64q97Jj1C2wpZNg0UfEFOFBEvsOjlUF4coiup51eLaDrJ4D4bMmbaIrZficnFg84oP37R15m2Om4teNcDpcjkDXi9AECWwSvGgYnqhkDMRkLETS778n6ybmmlRL7ze7dGHty5LRGj+CpECMFm0ow= 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 1716476264924970.1890899972029; Thu, 23 May 2024 07:57:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9st-0004aT-HG; Thu, 23 May 2024 10:57:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sZ-00047v-Lb for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sU-00046V-BP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:13 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-6aLYO5ioPeS2aJZnWQnSOw-1; Thu, 23 May 2024 10:57:07 -0400 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6ab8e73bc89so4070006d6.0 for ; Thu, 23 May 2024 07:57:07 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab8a05170dsm12949046d6.139.2024.05.23.07.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JLEKuIjNUE0upngVj1w8ZNUIo5SFQUiVbbxpLKuiIHs=; b=Ar0SqJATGvN7kvTR1/7P6Wp6/uA6UNHmqBr9OYWAMd7rM07sxwaG2KHo4mtFkmRZxZM1QE +lmIMmm1QzabTtXBq2y8cLPz+UGKwKLVo4ecjZYztWIT7oW9cuT9cgnX22YOV5Z6ZTvpR5 u57UiizuUU1aWIrJ2lPFIi5a40wPgDw= X-MC-Unique: 6aLYO5ioPeS2aJZnWQnSOw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476225; x=1717081025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JLEKuIjNUE0upngVj1w8ZNUIo5SFQUiVbbxpLKuiIHs=; b=SiWJ89+MMN+QpU2Ci53Yr67W6VNRmWOwNxL0gVP6Zb51dVYDo771QgTPUWI6RXB0Rk qNJpcM/5KQvfIkNZUqsZmIZnpp2WdbBDNt+zKjA9CeaOgdEr6HRJPIerPP8dOQ6rDOhI tl+eoNfwCE3NeCQalCJRU+J0EQdjmCCOUZ6pdaOespmNsdFf6K3RnFJ62thjC7Nkbsw6 TjmD1C6QwWzzVYtXwTPics+wvYZ/tSkCNhZ3zeMeYJvCGtan2tHVsDbF/Cezc55aU6zb NhvXNN1qVfNtuXJT85MhU+Xk2yglmppxPuSGCxqYJEY0Wduj0n14kE/RaeaZ8c1v/XQS ytaA== X-Gm-Message-State: AOJu0Yy5WHLlf5Ly6e5jhq5mo6gDZNuXPqI04cavE0u3WvAq88Fxfl4D d3hk9PnmGDkytHZPKckg/I6h3DzBwkMk6CSr0OAJHIm3peBnWFblMr9Cb2wdyMXtGUUkFe2ieyx yuPxqW/UIvKb3qg76+kKe3yOs6z2PzzmiyLcxJhEdWiVYvGNr/tGtKVuyt7OXg8yeYydBREjEWd /hxt8lD23THouOtjTbnE+KUddeAMQsAUjXHE/F X-Received: by 2002:a05:6214:230e:b0:6ab:756b:5d57 with SMTP id 6a1803df08f44-6ab8f5cfcf5mr49998646d6.27.1716476225253; Thu, 23 May 2024 07:57:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6rDafkvUCgDEofvxExqDpXfr7GtX4pogk6X0aXYMFcGCUs2uMXA4GX122Suzyo47SljP9nw== X-Received: by 2002:a05:6214:230e:b0:6ab:756b:5d57 with SMTP id 6a1803df08f44-6ab8f5cfcf5mr49997836d6.27.1716476224571; Thu, 23 May 2024 07:57:04 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 11/13] hostmem: add a new memory backend based on POSIX shm_open() Date: Thu, 23 May 2024 16:55:20 +0200 Message-ID: <20240523145522.313012-12-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476266412100015 Content-Type: text/plain; charset="utf-8" shm_open() creates and opens a new POSIX shared memory object. A POSIX shared memory object allows creating memory backend with an associated file descriptor that can be shared with external processes (e.g. vhost-user). The new `memory-backend-shm` can be used as an alternative when `memory-backend-memfd` is not available (Linux only), since shm_open() should be provided by any POSIX-compliant operating system. This backend mimics memfd, allocating memory that is practically anonymous. In theory shm_open() requires a name, but this is allocated for a short time interval and shm_unlink() is called right after shm_open(). After that, only fd is shared with external processes (e.g., vhost-user) as if it were associated with anonymous memory. In the future we may also allow the user to specify the name to be passed to shm_open(), but for now we keep the backend simple, mimicking anonymous memory such as memfd. Acked-by: David Hildenbrand Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v5 - fixed documentation in qapi/qom.json and qemu-options.hx [Markus] v4 - fail if we find "share=3Doff" in shm_backend_memory_alloc() [David] v3 - enriched commit message and documentation to highlight that we want to mimic memfd (David) --- docs/system/devices/vhost-user.rst | 5 +- qapi/qom.json | 19 +++++ backends/hostmem-shm.c | 123 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 16 ++++ 5 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 backends/hostmem-shm.c diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost= -user.rst index 9b2da106ce..35259d8ec7 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -98,8 +98,9 @@ Shared memory object =20 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. =20 Currently the shared memory object needs to match the size of the main diff --git a/qapi/qom.json b/qapi/qom.json index 38dde6d785..d40592d863 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -721,6 +721,21 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } =20 +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# The @share boolean option is true by default with shm. Setting it to fal= se +# will cause a failure during allocation because it is not supported by th= is +# backend. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { } } + ## # @MemoryBackendEpcProperties: # @@ -985,6 +1000,8 @@ { 'name': 'memory-backend-memfd', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', + { 'name': 'memory-backend-shm', + 'if': 'CONFIG_POSIX' }, 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' }, @@ -1056,6 +1073,8 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdPropertie= s', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', + 'if': 'CONFIG_POSIX' }, 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', diff --git a/backends/hostmem-shm.c b/backends/hostmem-shm.c new file mode 100644 index 0000000000..374edc3db8 --- /dev/null +++ b/backends/hostmem-shm.c @@ -0,0 +1,123 @@ +/* + * QEMU host POSIX shared memory object backend + * + * Copyright (C) 2024 Red Hat Inc + * + * Authors: + * Stefano Garzarella + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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 =3D g_string_new(NULL); + g_autofree char *backend_name =3D NULL; + uint32_t ram_flags; + int fd, oflag; + mode_t mode; + + if (!backend->size) { + error_setg(errp, "can't create shm backend with size 0"); + return false; + } + + if (!backend->share) { + error_setg(errp, "can't create shm backend with `share=3Doff`"); + return false; + } + + /* + * Let's use `mode =3D 0` because we don't want other processes to ope= n our + * memory unless we share the file descriptor with them. + */ + mode =3D 0; + oflag =3D O_RDWR | O_CREAT | O_EXCL; + backend_name =3D 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 =3D 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 lon= g as + * there are file descriptors pointing to it. + */ + shm_unlink(shm_name->str); + + if (ftruncate(fd, backend->size) =3D=3D -1) { + error_setg_errno(errp, errno, + "failed to resize POSIX shared memory to %" PRIu6= 4, + backend->size); + close(fd); + return false; + } + + ram_flags =3D RAM_SHARED; + ram_flags |=3D 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 =3D MEMORY_BACKEND_SHM(obj); + + MEMORY_BACKEND(m)->share =3D true; +} + +static void +shm_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); + + bc->alloc =3D shm_backend_memory_alloc; +} + +static const TypeInfo shm_backend_info =3D { + .name =3D TYPE_MEMORY_BACKEND_SHM, + .parent =3D TYPE_MEMORY_BACKEND, + .instance_init =3D shm_backend_instance_init, + .class_init =3D shm_backend_class_init, + .instance_size =3D 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 !=3D '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 =3D=3D 'linux' system_ss.add(files('hostmem-memfd.c')) diff --git a/qemu-options.hx b/qemu-options.hx index 4d19660336..982751cb35 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5238,6 +5238,22 @@ SRST =20 The ``share`` boolean option is on by default with memfd. =20 + ``-object memory-backend-shm,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 POSIX shared memory backend object, which allows + QEMU to share the memory with an external process (e.g. when + using vhost-user). + + ``memory-backend-shm`` is a more portable and less featureful vers= ion + of ``memory-backend-memfd``. It can then be used in any POSIX syst= em, + especially when memfd is not supported. + + Please refer to ``memory-backend-file`` for a description of the + options. + + The ``share`` boolean option is on by default with shm. Setting it= to + off will cause a failure during allocation because it is not suppo= rted + by this backend. + ``-object iommufd,id=3Did[,fd=3Dfd]`` Creates an iommufd backend which allows control of DMA mapping through the ``/dev/iommu`` device. --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476304; cv=none; d=zohomail.com; s=zohoarc; b=Kemnn3cYFCnYKu4Rz18MvDNBsthRo3XBuN5EUOAmSKfpEieYiUBd2JbIFUXOHEjF2euI29RQXtKNBu19GZW1sIN0rrtS0/VK4KEsSE0CRk6wzvSrIHMKSb5LQ6NWTplWoKSEAvrMvDG2k1Ev9FOj1HSpvnkFpQ87rb+odGVH75Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476304; 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=oz7CXmEGB8H9CB1Ih3mY/njvC8uRis0RohRSCchlBSc=; b=JwXwkP4p6EkscE1tD7UhDFpuNV1f+pmx5HloIRukxsu0wTsZ1ZemRT7pupTcWGJZ9nL6KNhxKMIyhB8+X3kMD3oOJYRn1riwEayxdGGgmPFLgCYD/rbBg22P06sozsRSsCEZGj4MpGtY8Z1yzwkKXugBjtDiFZNp5qD8SF34SS8= 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 1716476304639956.9890764396923; Thu, 23 May 2024 07:58:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9t2-0004sn-6m; Thu, 23 May 2024 10:57:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9se-0004J0-RP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sc-000471-G9 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:19 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-82-qIjrN6TbPpmFyLqa2uTP4A-1; Thu, 23 May 2024 10:57:16 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-43f7dba5d72so2162851cf.3 for ; Thu, 23 May 2024 07:57:16 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43fa1a906eesm18405351cf.20.2024.05.23.07.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oz7CXmEGB8H9CB1Ih3mY/njvC8uRis0RohRSCchlBSc=; b=JGgKpUkzA5nx3ijmFyCNVPdJ23Zixzw7MCBJpFfqNClzLVIxEq5TR91zERYZbG92Eda5Sj 6CBq225jok1zB3aaPjfsUop00zL0hnk4nyAVXbSs8gzkCD/eZgbfQ5Xkd6gwCSMmkfYNh9 72SF68XV5YAeABEHxVDrVKwB8h3dZKw= X-MC-Unique: qIjrN6TbPpmFyLqa2uTP4A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476234; x=1717081034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oz7CXmEGB8H9CB1Ih3mY/njvC8uRis0RohRSCchlBSc=; b=LtQJRhPkgcos9IgqkWmXi+z3NqvN3MqOR0DRar+zyjRL0Tc/xY52I8An6Tk0o1x5SV kBzRzTKbJ15oCET2VAfJmYADwBbDSysARQghG/remjMDDMFtNy3kKTBquL4LnBoHoNj2 GGPkY5+djXDGu1GBdPPNLSoP2GqX23m524fjdbQ7MFEoYRsL3HQnAkvm7uNO4XIZVxDP 1aEfcTzagKJ1b8qippTZnAl/fHEwACYVhk0UsrZMWEes2ZXJFwBZcuPYNqNh+Wr88vys /ltitezrRNvhzs/iZU0CS/Q4VNiMuH19tm5JUAJqDtpFtVq79IqhvNMmJZwx+gIBhCoH 8JzA== X-Gm-Message-State: AOJu0YxIfMsNCuxTH+10JJJcVAsN8MYV4fJTrHS8pXtjlg2tX4B8imHs EyOG9wmENr0RYabG+UYxMvy4Wbc9n2TMjVSn4WlCO1yBPji15TW+4CLR2CEEmLn/b67P8j6Jfus nYhM9asLRemNk+GpKkHxB6fhDjJ8IP1w4/FzEC/aPXZmvOE4ZrBBGauauIRszKzSjucluynw9wk ttCHiEI0jy8sqRrjEH5KyZzUjNLofOMbPBHOcm X-Received: by 2002:a05:622a:242:b0:43a:d7a9:390 with SMTP id d75a77b69052e-43f9e0ae4e7mr49036421cf.29.1716476234169; Thu, 23 May 2024 07:57:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9o75zA1DWnxNJTkg2uWIN9fVcZCsH1LHayMVQzL8KVSF8dzDS1Tkmu+0m0U9wE2qF+ecaag== X-Received: by 2002:a05:622a:242:b0:43a:d7a9:390 with SMTP id d75a77b69052e-43f9e0ae4e7mr49036051cf.29.1716476233803; Thu, 23 May 2024 07:57:13 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 12/13] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Thu, 23 May 2024 16:55:21 +0200 Message-ID: <20240523145522.313012-13-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476306620100009 `memory-backend-memfd` is available only on Linux while the new `memory-backend-shm` can be used on any POSIX-compliant operating system. Let's use it so we can run the test in multiple environments. Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- tests/qtest/vhost-user-blk-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk= -test.c index 117b9acd10..e945f6abf2 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -906,7 +906,7 @@ static void start_vhost_user_blk(GString *cmd_line, int= vus_instances, vhost_user_blk_bin); =20 g_string_append_printf(cmd_line, - " -object memory-backend-memfd,id=3Dmem,size=3D256M,share=3Don= " + " -object memory-backend-shm,id=3Dmem,size=3D256M,share=3Don " " -M memory-backend=3Dmem -m 256M "); =20 for (i =3D 0; i < vus_instances; i++) { --=20 2.45.1 From nobody Mon Nov 25 07:55:32 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=1716476315; cv=none; d=zohomail.com; s=zohoarc; b=BMYXsaMalajISVcK3yWQ5pgpzEpbm9w0d+7DEnF5R81d1V+ulIf3uU58yxCwixbxdOnxtKcHPJC5il75tou+Qx7zcBFGT1S81t4LamWAU2C0jr79b1sVONZn1LNiKGqEz46ByJinS9WKCZ8kcrzu8XMACOjcgXGiNtxDn3o95Bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476315; h=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=4qTvP6lxIhuzEFJYH1iq7oEMz1Xbgzhb1MVJySeq+gQ=; b=KiAx7g7Gnbs88eEB6MR9ZkFrPz0FLKEhBFlzlhH/5SuANxMwT0dMQMNCYKIm5yVmuC872K2FnhTe/F8p9AxLqcP5+dzYcqZhH8wAqFezqyW85HjUgbNRculOWvGvjIG2js1RnwRY4kaRiKgy4i9dGLKbKpUVcFPbc8oadQD8o6k= 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 1716476315414125.54050458074028; Thu, 23 May 2024 07:58:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9tX-0005Zj-Pw; Thu, 23 May 2024 10:58:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sp-0004UQ-36 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9sm-00047X-1a for qemu-devel@nongnu.org; Thu, 23 May 2024 10:57:30 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-pHZsB537NzyHQUcHcbFddg-1; Thu, 23 May 2024 10:57:26 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-792bd1dc658so35998585a.1 for ; Thu, 23 May 2024 07:57:26 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792db4083c1sm1185772885a.76.2024.05.23.07.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4qTvP6lxIhuzEFJYH1iq7oEMz1Xbgzhb1MVJySeq+gQ=; b=Qtdq3f8MYy1K2TxgNiATrCqAm1J1YvjyCgtwudKi4vMJ4pTLCgGKMbpwCKU5SV1GEVuGWd ZysACbjf7bure5iv/djae2hG40mcisctfLJaK16FpqEYE46j5AhH4zwJIcjyP5YH0wCmDN /VherCTeXCYYD5ChT3VVhXPcMxEXsQM= X-MC-Unique: pHZsB537NzyHQUcHcbFddg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476244; x=1717081044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4qTvP6lxIhuzEFJYH1iq7oEMz1Xbgzhb1MVJySeq+gQ=; b=jIEoKZrlEynE6fSspqLo9QaPBdpCshvLjZHu0bQcDYHzAM/eqn6K7D/Q1jQEKVOFXT ypyabMwMfRR5A15dLH4jBMK2fHgvoRPaWQKVQAOEGf1JXP65vB0RZHLHc/XIDhyG0qho Cm/fusx4e9tegKPvRFWsHP4fAp02I25WtRfijpbuhz+mxXoxaEevPZQK6CA0dG6idKGS 6EFfHDJsLMSsQqaKtvGegUY+zJnPIIrkI1RIzxWOgLXYoKa8drIZOXdSf9mvMjK6QjUB 7RPLqZmR6e7sIKM8bhKmBsRLaLDe99OFattARPMeWAT1Cfsv1yYSmNqj81gtMP/sPRCZ zU5w== X-Gm-Message-State: AOJu0YwJrL35O7trIU5TNJihF7eu05QXRsrF7IUxDTapmzByIcwiXAh+ wLDnez83HYCxOalC6FbbIQaoKkJiTQKmmQ3DdJxynNqgCI6CHSLYRwc5poQbwvQYJYPOexkfLPI pRl0YO/Ow+0ZJFLWHW871/46e481GGl5SBHgNkDU0C2hOpZaYlfI4+M9j28J8YitbeZjEm8CH0o yPx+sE9EPNWA+FS9kePXGnY+g2hLBZXRHBH5m+ X-Received: by 2002:a05:620a:2443:b0:794:9a59:351e with SMTP id af79cd13be357-794a0a424b1mr439564085a.38.1716476244169; Thu, 23 May 2024 07:57:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHp1yk4jpZXBC7fK6rr6gmRwWPbVRC83ZwhgPHVBlqcc9fA+mWGWGswNg8LMwlL6pRnDDgiXA== X-Received: by 2002:a05:620a:2443:b0:794:9a59:351e with SMTP id af79cd13be357-794a0a424b1mr439558585a.38.1716476243673; Thu, 23 May 2024 07:57:23 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 13/13] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Thu, 23 May 2024 16:55:22 +0200 Message-ID: <20240523145522.313012-14-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716476316607100001 Content-Type: text/plain; charset="utf-8" `memory-backend-shm` can be used with vhost-user devices, so let's add a new test case for it. Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- tests/qtest/vhost-user-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index d4e437265f..8c1d903b2a 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -44,6 +44,8 @@ "mem-path=3D%s,share=3Don -numa node,memdev=3Dmem" #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=3Dmem,size= =3D%dM," \ " -numa node,memdev=3Dmem" +#define QEMU_CMD_SHM " -m %d -object memory-backend-shm,id=3Dmem,size= =3D%dM," \ + " -numa node,memdev=3Dmem" #define QEMU_CMD_CHR " -chardev socket,id=3D%s,path=3D%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=3Dhs0,chardev=3D%s,vhostfo= rce=3Don" =20 @@ -195,6 +197,7 @@ enum test_memfd { TEST_MEMFD_AUTO, TEST_MEMFD_YES, TEST_MEMFD_NO, + TEST_MEMFD_SHM, }; =20 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, =20 if (memfd =3D=3D TEST_MEMFD_YES) { g_string_append_printf(cmd_line, QEMU_CMD_MEMFD, size, size); + } else if (memfd =3D=3D TEST_MEMFD_SHM) { + g_string_append_printf(cmd_line, QEMU_CMD_SHM, size, size); } else { const char *root =3D init_hugepagefs() ? : server->tmpfs; =20 @@ -788,6 +793,19 @@ static void *vhost_user_test_setup_memfd(GString *cmd_= line, void *arg) return server; } =20 +static void *vhost_user_test_setup_shm(GString *cmd_line, void *arg) +{ + TestServer *server =3D 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 *all= oc) { TestServer *server =3D arg; @@ -1081,6 +1099,11 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); =20 + opts.before =3D 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 =3D vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd", --=20 2.45.1