From patchwork Tue Jun 18 10:00:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE658C2BA15 for ; Tue, 18 Jun 2024 10:02:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVeG-0006Q4-0u; Tue, 18 Jun 2024 06:01:08 -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 1sJVeD-0006Ov-7I for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:06 -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 1sJVeB-0000m9-GS for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718704862; 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=OZzF4vYQ9JKiaNwEPTfXs/7RsEVvYmnAzAweasViLfU=; b=Vt1SSP+k9g5jkUjzvTzeJ+UAJ/LdpjUMV+Rpn0zC9VVV5Smg7RYUXEeYUrCcJccMIkhWz4 x5k5xaa3Wo8tnQR4RVf2pmUU7lH2oglXMeC20kNkf5ZSAr+maOLmbB8OI/F9yhff0csYCg zh5OzSkh6/O0FpXGPC8y3+DD+6mXyLY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-3yaBzg8POmanToADcECiMA-1; Tue, 18 Jun 2024 06:01:00 -0400 X-MC-Unique: 3yaBzg8POmanToADcECiMA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4246e5fd996so6350875e9.0 for ; Tue, 18 Jun 2024 03:01:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718704856; x=1719309656; 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=OZzF4vYQ9JKiaNwEPTfXs/7RsEVvYmnAzAweasViLfU=; b=eCavaAe7ZB5xaer5hufk37/KVqbgn+8CSrUOMotb2F1wQI94Ckhbx4YFcAnYWV7KH5 5iJScNif7PXaAfVfltMEOffLqrOwC9TyuEo710tHl2mnLEhLvmeBr/cXbCrG/KCu2BN9 NJSGh/fN+NkGq8cngFoVKx7oTqWzX26/3qd/Fks3mjCIwISMMKV2MWT+iQX0i9lZAVt4 d1Jv6GSPKPWohwAVKQ0+jJEDSBW78Nu4FiWPxOKPJGZjScW5lHNPnxRX5PZY0qJn4uIG jS8do0JZKo4xwLoX/8CME96me5R1UGusaUKIopzIhUb6hB2io103Ii+rPsTGX7JkgZBj nBlA== X-Gm-Message-State: AOJu0YydCE5jXjxkjx5cFUq64p5mLnNyyAcZDiMaqTFP0TgJzDsXITUE I9wflgWiE8XSq2giYqFDYYDZsK+mYlErjRYObXD2aRuMYewqftmpPpYx7dg0Vzw9OeJk98Uu+v/ bdYhcVrpAcByZ+NC8N8wUMyOHI6BVL4ZoiSISOEA0qROXw+WzJThz09TjEuQCxjcWQmZTdInlNU X7/pTDXLO3tv/jCTdSaGSaQ5/y4I5QfjYI3MMh X-Received: by 2002:adf:fe50:0:b0:360:6fd3:6f07 with SMTP id ffacd0b85a97d-3607a7e202cmr8526818f8f.45.1718704856065; Tue, 18 Jun 2024 03:00:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1lsSX7kKh2TJovAJCG+VHlfHrsAIaxyKZ2c2cTga1XjtS6ZcevWp0ayACAQn4ku/+qrnAjA== X-Received: by 2002:adf:fe50:0:b0:360:6fd3:6f07 with SMTP id ffacd0b85a97d-3607a7e202cmr8526784f8f.45.1718704855658; Tue, 18 Jun 2024 03:00:55 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36094fa7ea8sm5206343f8f.80.2024.06.18.03.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:00:53 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org, mst@redhat.com Cc: Coiby Xu , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , stefanha@redhat.com, Markus Armbruster , slp@redhat.com, Eduardo Habkost , David Hildenbrand , Raphael Norwitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Igor Mammedov , Gerd Hoffmann , Thomas Huth , qemu-block@nongnu.org, Brad Smith , Hanna Reitz , Eric Blake , gmaglione@redhat.com, Paolo Bonzini , Jason Wang , Laurent Vivier , Stefano Garzarella Subject: [PATCH v8 01/13] qapi: clarify that the default is backend dependent Date: Tue, 18 Jun 2024 12:00:31 +0200 Message-ID: <20240618100043.144657-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The default value of the @share option of the @MemoryBackendProperties really depends on the backend type, so let's document the default values in the same place where we define the option to avoid dispersing the information. Cc: David Hildenbrand Suggested-by: Markus Armbruster Reviewed-by: Markus Armbruster Signed-off-by: Stefano Garzarella Reviewed-by: Philippe Mathieu-Daudé --- v2: https://patchew.org/QEMU/20240611130231.83152-1-sgarzare@redhat.com/ v1: https://patchew.org/QEMU/20240523133302.103858-1-sgarzare@redhat.com/ --- qapi/qom.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index 8bd299265e..9b8f6a7ab5 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -600,7 +600,9 @@ # preallocation threads (default: none) (since 7.2) # # @share: if false, the memory is private to QEMU; if true, it is -# shared (default: false) +# shared (default false for backends memory-backend-file and +# memory-backend-ram, true for backends memory-backend-epc and +# memory-backend-memfd) # # @reserve: if true, reserve swap space (or huge pages) if applicable # (default: true) (since 6.1) @@ -700,8 +702,6 @@ # # Properties for memory-backend-memfd objects. # -# The @share boolean option is true by default with memfd. -# # @hugetlb: if true, the file to be created resides in the hugetlbfs # filesystem (default: false) # @@ -726,8 +726,6 @@ # # Properties for memory-backend-epc objects. # -# The @share boolean option is true by default with epc -# # The @merge boolean option is false by default with epc # # The @dump boolean option is false by default with epc From patchwork Tue Jun 18 10:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C0337C2BA1A for ; Tue, 18 Jun 2024 10:02:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVeO-0006St-K3; Tue, 18 Jun 2024 06:01: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 1sJVeH-0006Qx-Is for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:13 -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 1sJVeG-0000mn-63 for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718704867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eYivD0Oj8DZaeGa3x1w3lr0EcGpbXryh/Rf51uyXwz4=; b=d3xuxWIr2xWn1Fz3g78CQC+AKaRxR4KAxbaZRc05NTd4vQUbFTpkntOdWo8jHcOVst47PS LOjOk/EVTgFk+erXgMYNpdDlMLpljBdLiDbEqmfw3pgPdzVTO2SgfSd0aFwniPVFWs7/5C 7s/vqCmfC6n88BBE/NEOpg0muRBZ8fw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-44-Wpz5d1NdPRCKETkRsMs6gw-1; Tue, 18 Jun 2024 06:01:06 -0400 X-MC-Unique: Wpz5d1NdPRCKETkRsMs6gw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4212e2a3a1bso34589945e9.3 for ; Tue, 18 Jun 2024 03:01:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718704863; x=1719309663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eYivD0Oj8DZaeGa3x1w3lr0EcGpbXryh/Rf51uyXwz4=; b=aJbOTzVrvWgsJpDCUgbpRk4XEqTA5bEI2i09wd6xMLAHDm1HJRgqouoHhsL4guZuAG LG4u0BlNA/8dsWCMF2qt72ue39NiPZuEVzRgpyHnGPPpHsCF3ijD7fZSllv006Z2NVLe nJPHxOwgYHJme/+qTRNwC1QjZS9eReQuc5bOxpYOQffHog+BJNKHGFOOookFoRvZN/VH s5W4FmoHRyONIKxHYWq7JotCB8VMrgz3TMGUbwgg5Gfm1malpQJdAAvcuAzFqB3wG8xn YWzpXhZgtoxxRgDUcoV3oSqn6cUQ66W5tvwmSv0MnCMKfvHKghaFxQIno5jrXrB+OZQc wdYw== X-Gm-Message-State: AOJu0YwyffHbXioYxWgVw6uErQm2H+RtMF05SA5SiEw/QquekN4RWnH4 QjkYiy57Gc9RBrzJCoHzP35rln2erlpmur0+ZpG+/r2L6nh+56/vlTJ7V2VOuJYND2r5PG5MeTe e/lzL1wDwYg8V5Va91mpcGsHYENBF9xECbwluB/S3XXm8KpV9XCVTKd+CfyeOHH8eNZLVWH1l2L FTEfwrxVIDkILLnaRD2PecVvJopw6xFOc4ukAh X-Received: by 2002:a05:600c:3492:b0:422:720a:1bef with SMTP id 5b1f17b1804b1-42304825b7amr83208035e9.24.1718704863550; Tue, 18 Jun 2024 03:01:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQ+vAj6lu23qAiopYx9ERsQ1Lgp25YRq6ksq8ZfSPrx1enqhTSTiTcPr8D1YTQX3ncN22zMg== X-Received: by 2002:a05:600c:3492:b0:422:720a:1bef with SMTP id 5b1f17b1804b1-42304825b7amr83207605e9.24.1718704863097; Tue, 18 Jun 2024 03:01:03 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422874de5d5sm221194775e9.33.2024.06.18.03.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:01:00 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org, mst@redhat.com Cc: Coiby Xu , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , stefanha@redhat.com, Markus Armbruster , slp@redhat.com, Eduardo Habkost , David Hildenbrand , Raphael Norwitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Igor Mammedov , Gerd Hoffmann , Thomas Huth , qemu-block@nongnu.org, Brad Smith , Hanna Reitz , Eric Blake , gmaglione@redhat.com, Paolo Bonzini , Jason Wang , Laurent Vivier , Stefano Garzarella Subject: [PATCH v8 02/13] libvhost-user: set msg.msg_control to NULL when it is empty Date: Tue, 18 Jun 2024 12:00:32 +0200 Message-ID: <20240618100043.144657-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On some OS (e.g. macOS) sendmsg() returns -1 (errno EINVAL) if the `struct msghdr` has the field `msg_controllen` set to 0, but `msg_control` is not NULL. Reviewed-by: Eric Blake Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a879149fef..22bea0c775 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -632,6 +632,7 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) memcpy(CMSG_DATA(cmsg), vmsg->fds, fdsize); } else { msg.msg_controllen = 0; + msg.msg_control = NULL; } do { From patchwork Tue Jun 18 10:00:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0140AC27C4F for ; Tue, 18 Jun 2024 10:01:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVeR-0006Uo-Hj; Tue, 18 Jun 2024 06:01:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVeO-0006T0-JD for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVeM-0000nO-Vd for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718704874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Su7ClX2VsFIEko0OXJVvgHI4Li50SabFJTO7o/P9fMs=; b=h0msHDIrYr9ABL3a2TY5xt3PAlN28S6sJtMWlKyHo0Zu+j7yQfvzSjYVFM0o1MZ5kJvlfb FJzp15cBXlClwHSVZk5I2Z5WZ0Rt7DyMn0apRoCHJJX4TOZ30RhIko78ZQk/EafBA6QJew n5YSFeIfxryqRe5Oh9dcSbzV10B55rM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-hii3cQ5FOR-kNP5R8G8LbQ-1; Tue, 18 Jun 2024 06:01:13 -0400 X-MC-Unique: hii3cQ5FOR-kNP5R8G8LbQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4217a6a00d8so34761745e9.0 for ; Tue, 18 Jun 2024 03:01:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718704871; x=1719309671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Su7ClX2VsFIEko0OXJVvgHI4Li50SabFJTO7o/P9fMs=; b=HrkPAlcaSRjGtnwiJbiCanvcw6Q3f/JPBzi8bWDsGhS0vm326EVvRHfpa2ztfKGrCD R21BsMaF6vNosOZfcWAix0coazci2OPahP9El4DiRHVD9B1KnADijzTBJhDGUBHRsT25 XOu9TzDtPMqpXAXgHX6TyYdQ6y8hWDhEb56cUns1+NUPGlic3myL+lfQZev/db+741tB QqgMosa7GCQpXkFUBlAECObaWd5RbKhZLZEgctb0UJOR3cVhgry5sAm1LtvttrvAJ2UQ Zwb77XTfwuPKfESDk8eH4vgsPWhGfoT3bsmHXyxuIgTuRZCOuJCq7VkVIuvdDvcgTxbr 6DnA== X-Gm-Message-State: AOJu0YxNRJ2YXhXsr74UZ0rbQLDs0T9+Yfvnejj1qCG+YcaSmTosO7wZ 2cjj5i8ceIGdw0iX/P5OBIZQ3hkfWwDdxfPT2xrhniR0Nq6LU+g6WwWrne387q8mskgljL5DUBv eJamn4HkkGA0tvur/4IfQBIL5LcsNYgU9lVtoCWH3LZgXan9E9Trx3IelkmLanlDyD3ryYkTuBt Hay1Gyj/dUYmmcG5v4CCKON9DaFTn7NR0jgKAU X-Received: by 2002:a5d:678a:0:b0:360:7829:bb93 with SMTP id ffacd0b85a97d-3607a759cadmr9333683f8f.21.1718704871317; Tue, 18 Jun 2024 03:01:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwb7KX/o+IDXnpfK9XhGo2Pf+0iOdH/yhEnjTmDxufGt/jJUMMca+XHPdNilpVwZ2l3BRTKQ== X-Received: by 2002:a5d:678a:0:b0:360:7829:bb93 with SMTP id ffacd0b85a97d-3607a759cadmr9333643f8f.21.1718704870995; Tue, 18 Jun 2024 03:01:10 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c688sm13814617f8f.42.2024.06.18.03.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:01:08 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org, mst@redhat.com Cc: Coiby Xu , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , stefanha@redhat.com, Markus Armbruster , slp@redhat.com, Eduardo Habkost , David Hildenbrand , Raphael Norwitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Igor Mammedov , Gerd Hoffmann , Thomas Huth , qemu-block@nongnu.org, Brad Smith , Hanna Reitz , Eric Blake , gmaglione@redhat.com, Paolo Bonzini , Jason Wang , Laurent Vivier , Stefano Garzarella Subject: [PATCH v8 03/13] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Tue, 18 Jun 2024 12:00:33 +0200 Message-ID: <20240618100043.144657-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In vu_message_write() we use sendmsg() to send the message header, then a write() to send the payload. If sendmsg() fails we should avoid sending the payload, since we were unable to send the header. Discovered before fixing the issue with the previous patch, where sendmsg() failed on macOS due to wrong parameters, but the frontend still sent the payload which the backend incorrectly interpreted as a wrong header. Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 22bea0c775..a11afd1960 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -639,6 +639,11 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) rc = sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc <= 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) { From patchwork Tue Jun 18 10:00:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1124EC27C4F for ; Tue, 18 Jun 2024 10:02:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVee-0006bv-1a; Tue, 18 Jun 2024 06:01:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVea-0006YK-G1 for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:29 -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 1sJVeY-0000pP-Jk for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718704885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lCSYM/hkoNpk10raw3aulgVh0FcgzvIKh+wFjcoj8Zs=; b=F5hg5InnEARCDFDb+AKcFpNOz4G7hmLhz8Egp592KSFza7YrCbnk/9K/Rnr9TNz4e/rFZp OET7Rnpb6JsrMD68BtJ7Y+L8KuFI9XN/WwmxR/GD5RAbKrfrTvqKew+TtoxElRFmTSlXWu aBgQ/Qr2fJqFAO8YeKAejzo1tKiA8B8= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-7fJrjY_POYaEYalwh7U8AA-1; Tue, 18 Jun 2024 06:01:24 -0400 X-MC-Unique: 7fJrjY_POYaEYalwh7U8AA-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2eaec29f8e3so41808581fa.1 for ; Tue, 18 Jun 2024 03:01:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718704882; x=1719309682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lCSYM/hkoNpk10raw3aulgVh0FcgzvIKh+wFjcoj8Zs=; b=RKmpm8riGvhjxo88JqDkMFAUqlEyAAYUnBN2z+jDcZd+Qrkgv/a2wE9MSTWmz5Xl11 tzui9qx1wcrwrFceKDrEQAY1vSlE7u21WUted37gyqBCTdLZwaAzrlOo6/Dee4gNOzWS kCbYx6jc5lZRX5g0IZD7etzP5KEitL8jzqZ3klk+5qJzx1NsLSk6hbpzBcvHfcsVHFCJ q/lXZRuEU9UgKtaF0Hp79F/Ut5uAjuIVm64BpjLDloYAYrnzAbfaI3mGwe/BCTODd4ZY znP58YHQnhPfjl5pbi8pGYfjz6Rbxs1VkNfvAPoUhhuGoxpv+i0c4H/ijhqEFblOhqtB Hp+A== X-Gm-Message-State: AOJu0YwKXxhN4DcRTQPlcVGQ8ARx3NiGuJpgFMl0RDXKN/RH5P/FqTkh uBfEJko7SwYykIc+p44MEI8JIQH2O0Rdperszz3QW3rXQSN+q78DkaHDdSzDVCw8RryrQJUi+yW W07I1yRwedBdwunQst54OuKZGi2Fns++Qf38gdbeiFIaEgzgwsli2IrJyFRpDYHjTagBtp/YdNR rnQ0WL11sDOQhG9T5w8huhuG6PsW3VBrEtWJb+ X-Received: by 2002:a2e:a603:0:b0:2ec:1b9a:6981 with SMTP id 38308e7fff4ca-2ec1b9a6a5amr66199711fa.7.1718704881775; Tue, 18 Jun 2024 03:01:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmtXszET61iFbPQN51P1efzJtKtJvKWlDgM6gA6jKyWAFKYbF2w3oZEwnOgXPh4rlS/UKAyA== X-Received: by 2002:a2e:a603:0:b0:2ec:1b9a:6981 with SMTP id 38308e7fff4ca-2ec1b9a6a5amr66199201fa.7.1718704881259; Tue, 18 Jun 2024 03:01:21 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422874de623sm222365115e9.31.2024.06.18.03.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:01:18 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org, mst@redhat.com Cc: Coiby Xu , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , stefanha@redhat.com, Markus Armbruster , slp@redhat.com, Eduardo Habkost , David Hildenbrand , Raphael Norwitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Igor Mammedov , Gerd Hoffmann , Thomas Huth , qemu-block@nongnu.org, Brad Smith , Hanna Reitz , Eric Blake , gmaglione@redhat.com, Paolo Bonzini , Jason Wang , Laurent Vivier , Stefano Garzarella Subject: [PATCH v8 04/13] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Tue, 18 Jun 2024 12:00:34 +0200 Message-ID: <20240618100043.144657-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org libvhost-user will panic when receiving VHOST_USER_GET_INFLIGHT_FD message if MFD_ALLOW_SEALING is not defined, since it's not able to create a memfd. VHOST_USER_GET_INFLIGHT_FD is used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is negotiated. So, let's mask that feature if the backend is not able to properly handle these messages. Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- subprojects/libvhost-user/libvhost-user.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a11afd1960..2c20cdc16e 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1674,6 +1674,17 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg) features |= dev->iface->get_protocol_features(dev); } +#ifndef MFD_ALLOW_SEALING + /* + * If MFD_ALLOW_SEALING is not defined, we are not able to handle + * VHOST_USER_GET_INFLIGHT_FD messages, since we can't create a memfd. + * Those messages are used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD + * is negotiated. A device implementation can enable it, so let's mask + * it to avoid a runtime panic. + */ + features &= ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); +#endif + vmsg_set_reply_u64(vmsg, features); return true; } From patchwork Tue Jun 18 10:00:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DFF3EC2BA15 for ; Tue, 18 Jun 2024 10:02:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVeq-0006l1-91; Tue, 18 Jun 2024 06:01: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 1sJVeh-0006jC-TH for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01: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 1sJVeg-0000qB-Av for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718704893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=aZr5Wlctk8b1mxFPd4AgeoQLly05AMaQIO46BY1UaTNGsdXgWGMtP05x3dEjBthmGcQ5RU 3s+vZzHW0YnfaL3V5LEvUEAFfr2ILbZB3tRyS2DTWw1UidqJdp/Ih4EKyz18OidVVZtQsx EyKs/f2P1jFGgAOCIfEyuwTOsYW0evs= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-tMtTOpasMnypUW6DSVXa4w-1; Tue, 18 Jun 2024 06:01:32 -0400 X-MC-Unique: tMtTOpasMnypUW6DSVXa4w-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-421f3b7b27eso47390165e9.1 for ; Tue, 18 Jun 2024 03:01:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718704889; x=1719309689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=kBaS88iKkRhMpVZaoR1e1Pmxsj9s24S2Q69Halk3A2D49sEG5HFdbV9ZZyM4WjIA7t Z7is7e9QuyC/413YjI/x4bfGqbkvNgecelJm0tEpo2sl/ItQDePxoTyNmqAKEv7U4EpC 9CzhTGxYTWUwrqHhYYGeoO2+H0PZYbV+gIU3blO1QNuRGRX+0a9S35TfR3LOGfAY2y/f NknCHpxMiAeGpWDWjeuraxkrWbQ4mV+jOm6X5FEGLlD2lnru7Lt8oa8AwYAKgGBNaB0y 0sZaR4w+MbVzCjhOD3mJK+8RwUVA7xQRbHVXqkpG89LmY2rnY4du7OTQwa6PWLyEmfYa y10g== X-Gm-Message-State: AOJu0YyxdmUkw91Si3lU0/c3u9thNkoT+bEeSLHKiEGVWFxs9ddL9P8R dRAV8apJ1MxzoF2KDcJ1nm6hf/oi9UwLrWszOijQh2+PCyNsRbrzweyhL0azpBEbQrhF5UdXnc9 dYZczo5QBDxYpXQYoBhCgeIZr7nFgpb2XGAu73xdNKlZ87c9aGq6r/lF7naKUqD681tFFaJVsBt mNQUfTGXa9WWU7LC2W2/ghJ0dKKpIYfPKfOV+l X-Received: by 2002:a05:600c:460a:b0:422:fa63:33c1 with SMTP id 5b1f17b1804b1-423b6042b14mr85155035e9.3.1718704889303; Tue, 18 Jun 2024 03:01:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHz/n6EkirxnAOJq5rTblqIlHIMDurzatdzRs3nNi9adNaPfP2xl/YDqcTsIttfk38Ssr3cpw== X-Received: by 2002:a05:600c:460a:b0:422:fa63:33c1 with SMTP id 5b1f17b1804b1-423b6042b14mr85154465e9.3.1718704888769; Tue, 18 Jun 2024 03:01:28 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4246b67f0aesm52531845e9.45.2024.06.18.03.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:01:26 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org, mst@redhat.com Cc: Coiby Xu , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , stefanha@redhat.com, Markus Armbruster , slp@redhat.com, Eduardo Habkost , David Hildenbrand , Raphael Norwitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Igor Mammedov , Gerd Hoffmann , Thomas Huth , qemu-block@nongnu.org, Brad Smith , Hanna Reitz , Eric Blake , gmaglione@redhat.com, Paolo Bonzini , Jason Wang , Laurent Vivier , Stefano Garzarella Subject: [PATCH v8 05/13] vhost-user-server: do not set memory fd non-blocking Date: Tue, 18 Jun 2024 12:00:35 +0200 Message-ID: <20240618100043.144657-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In vhost-user-server we set all fd received from the other peer in non-blocking mode. For some of them (e.g. memfd, shm_open, etc.) it's not really needed, because we don't use these fd with blocking operations, but only to map memory. In addition, in some systems this operation can fail (e.g. in macOS setting an fd returned by shm_open() non-blocking fails with errno = ENOTTY). So, let's avoid setting fd non-blocking for those messages that we know carry memory fd (e.g. VHOST_USER_ADD_MEM_REG, VHOST_USER_SET_MEM_TABLE). Reviewed-by: Daniel P. Berrangé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- v3: - avoiding setting fd non-blocking for messages where we have memory fd (Eric) --- util/vhost-user-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 3bfb1ad3ec..b19229074a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -65,6 +65,18 @@ static void vmsg_close_fds(VhostUserMsg *vmsg) static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; + + /* + * These messages carry fd used to map memory, not to send/receive messages, + * so this operation is useless. In addition, in some systems this + * operation can fail (e.g. in macOS setting an fd returned by shm_open() + * non-blocking fails with errno = ENOTTY) + */ + if (vmsg->request == VHOST_USER_ADD_MEM_REG || + vmsg->request == VHOST_USER_SET_MEM_TABLE) { + return; + } + for (i = 0; i < vmsg->fd_num; i++) { qemu_socket_set_nonblock(vmsg->fds[i]); } From patchwork Tue Jun 18 10:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702048 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90C00C2BA15 for ; Tue, 18 Jun 2024 10:05:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVhs-0003WY-De; Tue, 18 Jun 2024 06:04:52 -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 1sJVhq-0003Vx-Ii for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:04:50 -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 1sJVho-0001Bu-Vq for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:04:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Iv4GZfjfSmrbe9mbetH0GZZLouN4MvBd3gnn16kx+E=; b=O+vdnpPQ8KeVpYzEecBMXorGv89b/IozUw9nPLBKbWQpVDx0Svho0IIbNtCkbXw10MUCrC sh+KmPhCDqceNBqk3IGATm7UjmXAPx0D0i26kyjMAg6zTZ764JqjXZGPKmO915h4N9N3bG vkgdHZaYjA+bWuWXoJbuUGVysfaeJ7E= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-0mK8aASjPeyJaGLrpFHv0w-1; Tue, 18 Jun 2024 06:04:46 -0400 X-MC-Unique: 0mK8aASjPeyJaGLrpFHv0w-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42181c64596so32024695e9.1 for ; Tue, 18 Jun 2024 03:04:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705085; x=1719309885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Iv4GZfjfSmrbe9mbetH0GZZLouN4MvBd3gnn16kx+E=; b=umwyvDbWPICGqSpPWn3LAaEQU15CsxgaOasb7BJcmSI9S7IZ/VPRJ0XI0KeIkW2X4C TjMGmWIY3muKXy9j6s97/Xxikh5Mbk564j37nVvr+edCZG66ECO1pjEqyt0Ynv0f1YD4 Jl/dgNp8qVsCEbwn6u+zIQt7uGBAF8q85yVtlhfncz8n8T2iDNvNfqH2kq0wmh/3KbSI SfN9z64UyOtrgdb3ZelXPAAz61pHQNr1GJvUt5PHSyesqjVyTmm0+VjkuJILUQ/Erwm3 ZZbtbnjgF+8j7EZaUkYbHxcq8HfGZ25INOV5IjuyNzvmBoN04+Esli1lvyV400A9RJAB P6xg== X-Forwarded-Encrypted: i=1; AJvYcCXU220lLt9o61gS1cArJouY+4NA2eJ+lq08MzlgE3si1YTNRKhU2Xsn0ZzCr9fhLSWq6E1ATo5zYdKDtKhTCkqPyrqi5ig= X-Gm-Message-State: AOJu0YygCL/rkLWvuBPd1kJ9mlK8pAm+e2v7CiIbxQZqEUPl6ttWmZgm xqFoWyT4Or1Byy0LX/rnjVxFzoOrbSsNZrXo2AY8K1f3STv6v4jH5xxjj8NHAdRLjstRAwT3JMM 0nj+Ge9XRa/E56hwo7oKCYTVMGlqKWeJ8fMiPQxmOaFS9Vf804GFo X-Received: by 2002:a05:6000:18af:b0:35f:2256:1722 with SMTP id ffacd0b85a97d-3607a7622aemr12290153f8f.33.1718705085651; Tue, 18 Jun 2024 03:04:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2b0tg9SYAZ02QJF7y7JVz7gyuCyH/CzZJE7spMUKO6IIIbB9FDId7s6Qc5j0duGnSO0qNFw== X-Received: by 2002:a05:6000:18af:b0:35f:2256:1722 with SMTP id ffacd0b85a97d-3607a7622aemr12290111f8f.33.1718705084968; Tue, 18 Jun 2024 03:04:44 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36075104bd1sm13809681f8f.113.2024.06.18.03.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:04:43 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 06/13] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Tue, 18 Jun 2024 12:04:39 +0200 Message-ID: <20240618100440.145664-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On macOS passing `-s /tmp/vhost.socket` parameter to the vhost-user-blk application, the bind was done on `/tmp/vhost.socke` pathname, missing the last character. This sounds like one of the portability problems described in the unix(7) manpage: Pathname sockets When binding a socket to a pathname, a few rules should be observed for maximum portability and ease of coding: • The pathname in sun_path should be null-terminated. • The length of the pathname, including the terminating null byte, should not exceed the size of sun_path. • The addrlen argument that describes the enclosing sockaddr_un structure should have a value of at least: offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)+1 or, more simply, addrlen can be specified as sizeof(struct sockaddr_un). So let's follow the last advice and simplify the code as well. Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- contrib/vhost-user-blk/vhost-user-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 89e5f11a64..a8ab9269a2 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -469,7 +469,6 @@ static int unix_sock_new(char *unix_fn) { int sock; struct sockaddr_un un; - size_t len; assert(unix_fn); @@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn) un.sun_family = AF_UNIX; (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); - len = sizeof(un.sun_family) + strlen(un.sun_path); (void)unlink(unix_fn); - if (bind(sock, (struct sockaddr *)&un, len) < 0) { + if (bind(sock, (struct sockaddr *)&un, sizeof(un)) < 0) { perror("bind"); goto fail; } From patchwork Tue Jun 18 10:04:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 811F0C27C4F for ; Tue, 18 Jun 2024 10:05:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVi8-0003lA-Fk; Tue, 18 Jun 2024 06:05:08 -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 1sJVi6-0003i2-Lv for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:06 -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 1sJVi4-0001EE-3Y for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+P1PLaujH+XkcZwoLm4xtgpPOnPZM5w6BOv7shY81Ks=; b=QzecCnjaQmfbkuefU8tU3WQ2I1+aos+rv58eyITZXufykKkRFOO1O4yPSJ6vJcC1rU5VFp /uPEQSMT9YPlMRivtayEW/QyZlKN3HdtfqCqSOUsKv005ia86pz23er9gWkbLSKPPSqPDD pRP8g+/4Taxuevh2k6YQ/eS1QfXQptI= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140--36eIY9BPSqtgPVc7THyXg-1; Tue, 18 Jun 2024 06:04:58 -0400 X-MC-Unique: -36eIY9BPSqtgPVc7THyXg-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-52c9894a547so4275395e87.1 for ; Tue, 18 Jun 2024 03:04:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705093; x=1719309893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+P1PLaujH+XkcZwoLm4xtgpPOnPZM5w6BOv7shY81Ks=; b=qZQdhcEv+5QgSMNkNBgOpguvxYAanaOcXz22GZjJFiduOJaDBsXCjaWwz2t6U/P9Zo 6QRi7T3ZlTzXe98XCswv4gKeV+Q337drRshcph31TKgQ3zitNZhJYKAegMSn3HNm+qf1 zrcOmASqcyLFXaW9tHRkbLYMpkxANcqemflnEBm6r1YKSY5AOsyvOx5NZKYjP2x9Z6pt TcxOfFlhrQ3nzOlKDZfuXO9YFXHiWpU1q06PuMivJ3toBDGj0KVLHClj/MKeFPUo9BfW bVIxrKe7W1DQrdkwJKNL6pMVqqjSU5XQ+7FnSP82dc9EE7xXyd8wRE8+73QutV4+yHAa N80w== X-Forwarded-Encrypted: i=1; AJvYcCWeRSoHN1zsuQPdtxalAXVGAGxkOmoLnJQnP6vOcqz6XTCJaOvtJG6Z3rekJ0TC47ozWOTi66gWqqvqCLvKKGnZPdXjcS8= X-Gm-Message-State: AOJu0YyoomQMt7GFw3sM9dlbyBkDeqpnjzhJ5ioLv5eiGEbXO0EqXz/k TjHz7lpOavdT8MBVzI+tjKNZsmRBEHZdl7RQEQY+LlS8+Sq6FkRK1Qp10U7GjHWgz4S/PMsJ+9N wbLldhhlTx+IYvvHSU1rRQgy3N1OGHMqyyHe8Jmd354HRQgatiox+ X-Received: by 2002:a19:7718:0:b0:52c:8449:d82e with SMTP id 2adb3069b0e04-52ca6e656bdmr7423649e87.15.1718705092906; Tue, 18 Jun 2024 03:04:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECieEGYIai0CEE1d6i+8w18YR6MuyTbNX5DtFji561t2/jvM2DQAiWL3qua+EeZFRDm7TJ5Q== X-Received: by 2002:a19:7718:0:b0:52c:8449:d82e with SMTP id 2adb3069b0e04-52ca6e656bdmr7423615e87.15.1718705092484; Tue, 18 Jun 2024 03:04:52 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f61280f6sm184113045e9.27.2024.06.18.03.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:04:50 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 07/13] contrib/vhost-user-*: use QEMU bswap helper functions Date: Tue, 18 Jun 2024 12:04:47 +0200 Message-ID: <20240618100447.145697-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let's replace the calls to le*toh() and htole*() with qemu/bswap.h helpers to make the code more portable. Suggested-by: Philippe Mathieu-Daudé Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- contrib/vhost-user-blk/vhost-user-blk.c | 9 +++++---- contrib/vhost-user-input/main.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index a8ab9269a2..9492146855 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -16,6 +16,7 @@ */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" @@ -194,8 +195,8 @@ vub_discard_write_zeroes(VubReq *req, struct iovec *iov, uint32_t iovcnt, #if defined(__linux__) && defined(BLKDISCARD) && defined(BLKZEROOUT) VubDev *vdev_blk = req->vdev_blk; desc = buf; - uint64_t range[2] = { le64toh(desc->sector) << 9, - le32toh(desc->num_sectors) << 9 }; + uint64_t range[2] = { le64_to_cpu(desc->sector) << 9, + le32_to_cpu(desc->num_sectors) << 9 }; if (type == VIRTIO_BLK_T_DISCARD) { if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) == 0) { g_free(buf); @@ -267,13 +268,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk, req->in = (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_base; in_num--; - type = le32toh(req->out->type); + type = le32_to_cpu(req->out->type); switch (type & ~VIRTIO_BLK_T_BARRIER) { case VIRTIO_BLK_T_IN: case VIRTIO_BLK_T_OUT: { ssize_t ret = 0; bool is_write = type & VIRTIO_BLK_T_OUT; - req->sector_num = le64toh(req->out->sector); + req->sector_num = le64_to_cpu(req->out->sector); if (is_write) { ret = vub_writev(req, &elem->out_sg[1], out_num); } else { diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c index 081230da54..f3362d41ac 100644 --- a/contrib/vhost-user-input/main.c +++ b/contrib/vhost-user-input/main.c @@ -51,8 +51,8 @@ static void vi_input_send(VuInput *vi, struct virtio_input_event *event) vi->queue[vi->qindex++].event = *event; /* ... until we see a report sync ... */ - if (event->type != htole16(EV_SYN) || - event->code != htole16(SYN_REPORT)) { + if (event->type != cpu_to_le16(EV_SYN) || + event->code != cpu_to_le16(SYN_REPORT)) { return; } @@ -103,9 +103,9 @@ vi_evdev_watch(VuDev *dev, int condition, void *data) g_debug("input %d %d %d", evdev.type, evdev.code, evdev.value); - virtio.type = htole16(evdev.type); - virtio.code = htole16(evdev.code); - virtio.value = htole32(evdev.value); + virtio.type = cpu_to_le16(evdev.type); + virtio.code = cpu_to_le16(evdev.code); + virtio.value = cpu_to_le32(evdev.value); vi_input_send(vi, &virtio); } } @@ -124,9 +124,9 @@ static void vi_handle_status(VuInput *vi, virtio_input_event *event) evdev.input_event_sec = tval.tv_sec; evdev.input_event_usec = tval.tv_usec; - evdev.type = le16toh(event->type); - evdev.code = le16toh(event->code); - evdev.value = le32toh(event->value); + evdev.type = le16_to_cpu(event->type); + evdev.code = le16_to_cpu(event->code); + evdev.value = le32_to_cpu(event->value); rc = write(vi->evdevfd, &evdev, sizeof(evdev)); if (rc == -1) { From patchwork Tue Jun 18 10:04:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4E72C41513 for ; Tue, 18 Jun 2024 10:05:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJViB-0003rM-KG; Tue, 18 Jun 2024 06:05:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVi8-0003mJ-NT for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:08 -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 1sJVi5-0001Hq-Oo for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705104; 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=Pp5ZUnNz+rNIrlfHLcPwbuNGbQD2zU63dazbFM6gki4=; b=Ll8Erg7wCkOnHvy4b1AULX3OG4IFHus8caHszIS+3wlmCrtauVXWW4c8Wi9p7saKT5IQic B5HgguOekhVYMOfnE3Goxv1+5CaShfsesaDmsXW/OVzsL+tmwkkQj0RTMEz3kD84uj7Ck0 KJOnVgafFmR8avjuJf0SiDWJaGnc3Mk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-958x5cM8McOP4vAH9wB2dw-1; Tue, 18 Jun 2024 06:05:02 -0400 X-MC-Unique: 958x5cM8McOP4vAH9wB2dw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-421e17ae038so39569055e9.0 for ; Tue, 18 Jun 2024 03:05:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705101; x=1719309901; 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=Pp5ZUnNz+rNIrlfHLcPwbuNGbQD2zU63dazbFM6gki4=; b=McvAM6/AyddfTFNCUdooWx/pkoXvu/yRlc8fQUQGPvKF+AwiMJ/F1ZtwhpckNw3dFh hqz5eVRdHYZ1qTDZhDXsq2HiBPQCEec6OB8djtz/mof6YEiI8tl0npJznrZcloT2hfci L+p3yI4+ANvJfIhSBnfhiYNGtNlZErBcRg0hYV0OvxNI44GHgGGRX2KJhD4jcWzg2tjs LPFOs/vumn4cA+a7Hk5sKaX4bHcdNbcnwBqgnbAz8bv6XsmbRbSIZHgYPyJ/fdC+8YM+ S5dXgoWUt8WzScyqBNaSP1OQf2cwiTaKT0Kw0CeMMNRaFiF81qAOM4bJ3MIiZOdIWInA cdEQ== X-Forwarded-Encrypted: i=1; AJvYcCWb2RqHavs9GfCSFRaHWOBUCXrTpwT3Wn7ZdkjheXtRi8B1WgCN0Ma8P4DyoxRNmcK22CnrXPvsvIOrYWJs5nG84k0vxlk= X-Gm-Message-State: AOJu0YzVUT78PUpWcAxLpIEWk+QbbNXydh9Kgaut20XeGPltJj28Iz1G pkb6UzoRb1btqOCnIBhJgUYpS5RV8DiW6IlbtyUkiknD/kFiS1vE3OT23Kyan53bzVE4+zFWOXU NuJu6+0Uod0ircVLVJ6Ru1RBj3G5gyWIeh7J/+C8LKs4Cfqo1rvt9 X-Received: by 2002:a05:600c:154d:b0:421:8028:a507 with SMTP id 5b1f17b1804b1-4230482b872mr79833525e9.18.1718705101609; Tue, 18 Jun 2024 03:05:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeuNQflOeD45AxbnD6s/40Ybo2KWrQFi6pETp60VQUIo3zbgsA9sIzpjjUDDJUkpTL9WDPnA== X-Received: by 2002:a05:600c:154d:b0:421:8028:a507 with SMTP id 5b1f17b1804b1-4230482b872mr79833145e9.18.1718705101190; Tue, 18 Jun 2024 03:05:01 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422a1e68d04sm200747465e9.36.2024.06.18.03.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:04:59 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 08/13] vhost-user: enable frontends on any POSIX system Date: Tue, 18 Jun 2024 12:04:55 +0200 Message-ID: <20240618100455.145733-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The vhost-user protocol is not really Linux-specific so let's enable vhost-user frontends for any POSIX system. In vhost_net.c we use VHOST_FILE_UNBIND which is defined in a Linux specific header, let's define it for other systems as well. Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- meson.build | 1 - hw/net/vhost_net.c | 5 +++++ hw/block/Kconfig | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 97e00d6f59..2ba95a8c35 100644 --- a/meson.build +++ b/meson.build @@ -151,7 +151,6 @@ have_tpm = get_option('tpm') \ # vhost have_vhost_user = get_option('vhost_user') \ - .disable_auto_if(host_os != 'linux') \ .require(host_os != 'windows', error_message: 'vhost-user is not available on Windows').allowed() have_vhost_vdpa = get_option('vhost_vdpa') \ diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index fd1a93701a..fced429813 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -34,8 +34,13 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" +#if defined(__linux__) #include "linux-headers/linux/vhost.h" +#endif +#ifndef VHOST_FILE_UNBIND +#define VHOST_FILE_UNBIND -1 +#endif /* Features supported by host kernel. */ static const int kernel_feature_bits[] = { diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 9e8f28f982..29ee09e434 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -40,7 +40,7 @@ config VHOST_USER_BLK bool # Only PCI devices are provided for now default y if VIRTIO_PCI - depends on VIRTIO && VHOST_USER && LINUX + depends on VIRTIO && VHOST_USER config SWIM bool From patchwork Tue Jun 18 10:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC209C27C4F for ; Tue, 18 Jun 2024 10:05:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJViJ-0004EZ-0K; Tue, 18 Jun 2024 06:05:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJViE-0003wp-D3 for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJViC-0001QT-FV for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705111; 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=jgaOjflpOpBuAI2lV6r/qh89MXpXI4bCCUZiaqoxz58=; b=KOksklpPeDcKnEa7/TTkCLB2dumvALy4ivr8JgzoV6zyiROBC9gC681V2u5FVCxejfyw7f PvGjlmmHWLm5fJ/ObOEeQVCjZ3ftyj6d9nzasmarRW8dNl3lhWIGR1htP6Togn1Pdj4/Uh yJUe+v8bs4MjRYRliS499Kq4jycX5rA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-rh1jE8RIPXin7h6W1e74OQ-1; Tue, 18 Jun 2024 06:05:10 -0400 X-MC-Unique: rh1jE8RIPXin7h6W1e74OQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-421eed70e30so39490625e9.1 for ; Tue, 18 Jun 2024 03:05:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705109; x=1719309909; 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=jgaOjflpOpBuAI2lV6r/qh89MXpXI4bCCUZiaqoxz58=; b=OlI99KiEiVG3QaiL97rVlfLQFObnvPtIhdhq/604RpuWxsrzt/3Myu0tMM/O+Dow7Z 4mZEv24544OclJgHxqwlWa0V9kQrvvhkqvY2wO4t6uyNZkdePMrDR6imk1ScG6Ze8gnP 02APl8MZNksGl5QTxgTu7tSyJykeUVwJw7oZcze3L2P7WTPZI5uXp0cL9nv/Y/GQEOOW Y0ke6/PHt9ovcSYRrT1q2L0acP4Y7c+dmXr/3nFo50qxhrFTA9MVZfXH4FqNpeeNz7Eo mEmJQ0dIxcAvE+SDqO8ggcKN83FWQ2cBKDZFkiam4YleqpOdZzZfKdCK96vVxg2TIcE8 /gIA== X-Forwarded-Encrypted: i=1; AJvYcCUv3RGVQAmGFtXk9obsvpBQNvfHVeaWO+P5ieJH9z3gM914fZoym2466K3dJFeR3waOd3BoXUqtr3D16nEdGXtJs6s96Rk= X-Gm-Message-State: AOJu0Yx/RiTp5skVoy+8y4F1xpWZjb+kPggPmH0OADSM05Go2IVakhzm ApPMxma1+JWE4XgnHgmQR2/8JHiJp57kbsA3mhwmQTHAErkHolZ7hyKL7iyv5yAXr9DkmrzkrDO rDjJkZwslRTM01eHm+5mRoxipRkThUZC8mMiFBMNOPW2F5KD13e53 X-Received: by 2002:a05:600c:4444:b0:421:2df2:2850 with SMTP id 5b1f17b1804b1-4230484d098mr102880805e9.31.1718705109201; Tue, 18 Jun 2024 03:05:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKPfNRwSQ07kyXWR6CCxKPHeLXT8NdJ9G5M7igfFGflsxfDywbpaHKsTRhpIyf3bl0HEaWUw== X-Received: by 2002:a05:600c:4444:b0:421:2df2:2850 with SMTP id 5b1f17b1804b1-4230484d098mr102880585e9.31.1718705108860; Tue, 18 Jun 2024 03:05:08 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f6320c2csm183925985e9.36.2024.06.18.03.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:05:06 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 09/13] libvhost-user: enable it on any POSIX system Date: Tue, 18 Jun 2024 12:05:03 +0200 Message-ID: <20240618100503.145768-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The vhost-user protocol is not really Linux-specific so let's enable libvhost-user for any POSIX system. Compiling it on macOS and FreeBSD some problems came up: - avoid to include linux/vhost.h which is available only on Linux (vhost_types.h contains many of the things we need) - macOS doesn't provide sys/endian.h, so let's define them (note: libvhost-user doesn't include QEMU's headers, so we can't use use "qemu/bswap.h") - define eventfd_[write|read] as write/read wrapper when system doesn't provide those (e.g. macOS) - copy SEAL defines from include/qemu/memfd.h to make the code works on FreeBSD where MFD_ALLOW_SEALING is defined - define MAP_NORESERVE if it's not defined (e.g. on FreeBSD) Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v5: - fixed typos in the commit description [Phil] --- meson.build | 2 +- subprojects/libvhost-user/libvhost-user.h | 2 +- subprojects/libvhost-user/libvhost-user.c | 60 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 2ba95a8c35..487153a431 100644 --- a/meson.build +++ b/meson.build @@ -3190,7 +3190,7 @@ if have_system and vfio_user_server_allowed endif vhost_user = not_found -if host_os == 'linux' and have_vhost_user +if have_vhost_user libvhost_user = subproject('libvhost-user') vhost_user = libvhost_user.get_variable('vhost_user_dep') endif diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h index deb40e77b3..e13e1d3931 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -18,9 +18,9 @@ #include #include #include -#include #include #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/vhost_types.h" /* Based on qemu/hw/virtio/vhost-user.c */ #define VHOST_USER_F_PROTOCOL_FEATURES 30 diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 2c20cdc16e..57e58d4adb 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -28,9 +28,7 @@ #include #include #include -#include #include -#include /* Necessary to provide VIRTIO_F_VERSION_1 on system * with older linux headers. Must appear before @@ -39,8 +37,8 @@ #include "standard-headers/linux/virtio_config.h" #if defined(__linux__) +#include #include -#include #include #include #include @@ -52,6 +50,62 @@ #endif +#if defined(__APPLE__) && (__MACH__) +#include +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#endif + +#ifdef CONFIG_EVENTFD +#include +#else +#define eventfd_t uint64_t + +int eventfd_write(int fd, eventfd_t value) +{ + return (write(fd, &value, sizeof(value)) == sizeof(value)) ? 0 : -1; +} + +int eventfd_read(int fd, eventfd_t *value) +{ + return (read(fd, value, sizeof(*value)) == sizeof(*value)) ? 0 : -1; +} +#endif + +#ifdef MFD_ALLOW_SEALING +#include + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#endif +#endif + +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif + #include "include/atomic.h" #include "libvhost-user.h" From patchwork Tue Jun 18 10:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B46CDC27C4F for ; Tue, 18 Jun 2024 10:06:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJViT-0004cW-1Y; Tue, 18 Jun 2024 06:05: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 1sJViQ-0004ah-Sd for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:27 -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 1sJViP-0001RP-6M for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705124; 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=D23sE3AgRotCDX4TIxE04BnGZoCJyb8IC4yJhLAVexA=; b=ARRVy217AYEau2famaNWQ3OjVuDkRh1jNEyrshgkcqL/aVPJ89eOw0wkoaEAcvoJDrVHX9 4m3BtCV1pzyrVWDlBgY4ygHZNRLF9J6yuBO7FI45BAt7KeU6Km7xs2VB03Brjm/QGQqaEf 7n+O2r9Q+4RUT1XMunZj6q70pf2NKlk= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-9ap91TqdMBuQ1dNcNMXp4g-1; Tue, 18 Jun 2024 06:05:22 -0400 X-MC-Unique: 9ap91TqdMBuQ1dNcNMXp4g-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2ec1709d233so27777691fa.3 for ; Tue, 18 Jun 2024 03:05:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705117; x=1719309917; 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=D23sE3AgRotCDX4TIxE04BnGZoCJyb8IC4yJhLAVexA=; b=cIZ/vIzVZCiws11MWfgzT45vDPoI1jTvI6NwHGKCE+062sw9yWah7P4igVnEhiSsZa RGzydoATP6TozUz3R+BD2he35vuXZG4XNoF4G5n2J7gzj9gASc7C31l5bZqpTYU1jrB+ o9V3eQmFi5YqjZkr+TXQU5LYtJ1AGx4ik3xxsZRItGmX0iCr3mZDcg8Wd29WHWxYaVO8 v0IVf/N+FAy5wLY3EM9fToqcL/o+QUDJXvf+jEYM1gnnfvAn0WlbD71q9LsZGxG4H5RX 0/kCY7wSl/nj3IZfey/wUhnK6p2vkZ6VTk4kE5iZJNbgUjzGfN1ZJ3vkKN9wFvKWBf33 PSBw== X-Forwarded-Encrypted: i=1; AJvYcCXzyr9+ggUTK1HCtalLUwlWOeEi4M/UA2/05nW2ZgfXDkbBJoWlfmg4eiHi8J0xfbruCrDzVB6xJOBf1OTl1bP+PUpW8MU= X-Gm-Message-State: AOJu0Yyd54DMbK/LSwluBE26VILl1q4EOTu8zntmUhur8TTC1qKJxNis cRT6tugzFsw/sn+11Zv+KiAUnuTEM1nwhoqJaL/PcH8wAktKsvHInKfsJuHlzmt9+OeAFpWybNL fH1kx1/bGRYiSfZBdoLBrUoRHC47rBacZ1yzEaj4e8INQ1drjpvyD X-Received: by 2002:ac2:560a:0:b0:52c:8abe:5204 with SMTP id 2adb3069b0e04-52ca6e6d562mr7716698e87.32.1718705116894; Tue, 18 Jun 2024 03:05:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpXUNx/dD3F/Us1LkHzStUGnStkp9sk6wwAk93rcdOInVCHJzv7ITZuPi4ie95N3HkJXSaAw== X-Received: by 2002:ac2:560a:0:b0:52c:8abe:5204 with SMTP id 2adb3069b0e04-52ca6e6d562mr7716688e87.32.1718705116624; Tue, 18 Jun 2024 03:05:16 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-360751036c9sm13749648f8f.94.2024.06.18.03.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:05:14 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 10/13] contrib/vhost-user-blk: enable it on any POSIX system Date: Tue, 18 Jun 2024 12:05:11 +0200 Message-ID: <20240618100511.145789-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let's make the code more portable by adding defines from block/file-posix.c to support O_DIRECT in other systems (e.g. macOS). vhost-user-server.c is a dependency, let's enable it for any POSIX system. Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella --- v6: - reverted v5 changes since we can't move O_DSYNC and O_DIRECT in osdep [Daniel, failing tests on Windows] v5: - O_DSYNC and O_DIRECT definition are now in osdep [Phil] - commit updated since we moved out all code changes v4: - moved using of "qemu/bswap.h" API in a separate patch [Phil] --- meson.build | 2 -- contrib/vhost-user-blk/vhost-user-blk.c | 14 ++++++++++++++ util/meson.build | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 487153a431..f86ce92364 100644 --- a/meson.build +++ b/meson.build @@ -2001,8 +2001,6 @@ has_statx = cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', prefix: gnu_ has_statx_mnt_id = cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', prefix: gnu_source_prefix) have_vhost_user_blk_server = get_option('vhost_user_blk_server') \ - .require(host_os == 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user support') \ .disable_auto_if(not have_tools and not have_system) \ diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 9492146855..a450337685 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -25,6 +25,20 @@ #include #endif +/* OS X does not have O_DSYNC */ +#ifndef O_DSYNC +#ifdef O_SYNC +#define O_DSYNC O_SYNC +#elif defined(O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +#endif + +/* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ +#ifndef O_DIRECT +#define O_DIRECT O_DSYNC +#endif + enum { VHOST_USER_BLK_MAX_QUEUES = 8, }; diff --git a/util/meson.build b/util/meson.build index 72b505df11..c414178ace 100644 --- a/util/meson.build +++ b/util/meson.build @@ -112,10 +112,12 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif if host_os == 'linux' - util_ss.add(files('vhost-user-server.c'), vhost_user) util_ss.add(files('vfio-helpers.c')) util_ss.add(files('chardev_open.c')) endif + if host_os != 'windows' + util_ss.add(files('vhost-user-server.c'), vhost_user) + endif util_ss.add(files('yank.c')) endif From patchwork Tue Jun 18 10:05:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DCF4C27C4F for ; Tue, 18 Jun 2024 10:06:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJViZ-0004st-75; Tue, 18 Jun 2024 06:05:35 -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 1sJViW-0004nd-FU for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05: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 1sJViU-0001TQ-8h for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705129; 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=RXngxM8FKxUBfo8JQdNl7f7YbH+MS1ixL36xpxgXb0M=; b=NPlDD1UODA4oJaARtC+a6XkXcQAXNmFfqNAkAVALcAu56E7/mOOmNxVEEW0lIRRViPUMo3 r+ge/UWNWpSzAJTY+an0bNxGhNSWay7IbT/S1HjEvyoGpCmOe75IKOvZjHcr7s6R4aFa8F qJummgPQfwxPtkUaH1Un0I+ir6Rhcyw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-WpHHt2arNgKlgho3bLmwAw-1; Tue, 18 Jun 2024 06:05:26 -0400 X-MC-Unique: WpHHt2arNgKlgho3bLmwAw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4229bde57easo31963975e9.3 for ; Tue, 18 Jun 2024 03:05:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705125; x=1719309925; 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=RXngxM8FKxUBfo8JQdNl7f7YbH+MS1ixL36xpxgXb0M=; b=Zmxw/42BL5y36R2QQYRO7BISGBDVbjwDcm8oi1Tcv5aVlOgJtPoPtIN2wQcMrd4Ek5 RlnpFnsUrQKvSRmObpk2kiEELBpjo6ARKyQlWXKhXI9StNeqqf6JbV+OJ11jO/GI1toy xo9by1C87IXUfRCYDveLZSfWG4aJwtoG40sLvoDKGTAKsFgJttRLdML6feQoQ00Yr9UN nXafg6FSLsYSBhOvfOyOi/3ecJ9YoW1Fv4UjCD5xmLd5ORK0Qgogvqe80eqNCIknIaEM lftmjY+gsaqONA3BqsO2lNuIQb9r0mKTTGaOQrrdgPEIw205V8s8yOlRX4QDkAenznDO czGA== X-Forwarded-Encrypted: i=1; AJvYcCX4BnHqBLK69xWCl8Cb8QzZ7Cbz6vCWZfdcGziW/v/S7Q2mAmXE9i+lroIS+4HMP44hnSFGP60IFnbhWRhObmqpOcpLXgM= X-Gm-Message-State: AOJu0YzTe3HN9RgLW9FmCHYphfS3B8BToqfdvWbGll8E5LZkq8lxG1y0 mMj2s+e4tMyyZDWZ8y2m0fbKVZW5m658/VdVQnApmtM+YWWyauu11CpsrjqIYP/xbZgkhtjCq09 fzl2KpTWYUbzCyd6MOutl3JcnAFzlxaitnQkKOPLXbMIG9cX2AD+l X-Received: by 2002:a05:600c:1553:b0:422:1609:a7db with SMTP id 5b1f17b1804b1-42304822a02mr94548175e9.8.1718705124996; Tue, 18 Jun 2024 03:05:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMYlPQiOMCFpfcpAKB7tB+M7b66KpVX5mWAo18HsFUCXejozZz1ohpgI74z8orq/HoQHt6nQ== X-Received: by 2002:a05:600c:1553:b0:422:1609:a7db with SMTP id 5b1f17b1804b1-42304822a02mr94547995e9.8.1718705124594; Tue, 18 Jun 2024 03:05:24 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422874de68asm223696645e9.29.2024.06.18.03.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:05:22 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 11/13] hostmem: add a new memory backend based on POSIX shm_open() Date: Tue, 18 Jun 2024 12:05:19 +0200 Message-ID: <20240618100519.145853-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org shm_open() creates and opens a new POSIX shared memory object. A POSIX shared memory object allows creating memory backend with an associated file descriptor that can be shared with external processes (e.g. vhost-user). The new `memory-backend-shm` can be used as an alternative when `memory-backend-memfd` is not available (Linux only), since shm_open() should be provided by any POSIX-compliant operating system. This backend mimics memfd, allocating memory that is practically anonymous. In theory shm_open() requires a name, but this is allocated for a short time interval and shm_unlink() is called right after shm_open(). After that, only fd is shared with external processes (e.g., vhost-user) as if it were associated with anonymous memory. In the future we may also allow the user to specify the name to be passed to shm_open(), but for now we keep the backend simple, mimicking anonymous memory such as memfd. Acked-by: David Hildenbrand Acked-by: Stefan Hajnoczi Acked-by: Markus Armbruster (QAPI schema) Signed-off-by: Stefano Garzarella --- v8 - Fixed QAPI documentation about share option [Markus] v7 - changed default value documentation for @share rebasing on 20240611130231.83152-1-sgarzare@redhat.com [Markus] - used `memory-backend-shm` instead of `shm` and wrapped to 70 columns [Markus] - added 'if': 'CONFIG_POSIX' to MemoryBackendShmProperties [Markus] v5 - fixed documentation in qapi/qom.json and qemu-options.hx [Markus] v4 - fail if we find "share=off" in shm_backend_memory_alloc() [David] v3 - enriched commit message and documentation to highlight that we want to mimic memfd (David) --- docs/system/devices/vhost-user.rst | 5 +- qapi/qom.json | 23 +++++- backends/hostmem-shm.c | 123 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 16 ++++ 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 backends/hostmem-shm.c diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost-user.rst index 9b2da106ce..35259d8ec7 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -98,8 +98,9 @@ Shared memory object In order for the daemon to access the VirtIO queues to process the requests it needs access to the guest's address space. This is -achieved via the ``memory-backend-file`` or ``memory-backend-memfd`` -objects. A reference to a file-descriptor which can access this object +achieved via the ``memory-backend-file``, ``memory-backend-memfd``, or +``memory-backend-shm`` objects. +A reference to a file-descriptor which can access this object will be passed via the socket as part of the protocol negotiation. Currently the shared memory object needs to match the size of the main diff --git a/qapi/qom.json b/qapi/qom.json index 9b8f6a7ab5..92b0fea76c 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -601,8 +601,8 @@ # # @share: if false, the memory is private to QEMU; if true, it is # shared (default false for backends memory-backend-file and -# memory-backend-ram, true for backends memory-backend-epc and -# memory-backend-memfd) +# memory-backend-ram, true for backends memory-backend-epc, +# memory-backend-memfd, and memory-backend-shm) # # @reserve: if true, reserve swap space (or huge pages) if applicable # (default: true) (since 6.1) @@ -721,6 +721,21 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# This memory backend supports only shared memory, which is the +# default. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { }, + 'if': 'CONFIG_POSIX' } + ## # @MemoryBackendEpcProperties: # @@ -1049,6 +1064,8 @@ { 'name': 'memory-backend-memfd', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', + { 'name': 'memory-backend-shm', + 'if': 'CONFIG_POSIX' }, 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' }, @@ -1121,6 +1138,8 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdProperties', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', + 'if': 'CONFIG_POSIX' }, 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', diff --git a/backends/hostmem-shm.c b/backends/hostmem-shm.c new file mode 100644 index 0000000000..374edc3db8 --- /dev/null +++ b/backends/hostmem-shm.c @@ -0,0 +1,123 @@ +/* + * QEMU host POSIX shared memory object backend + * + * Copyright (C) 2024 Red Hat Inc + * + * Authors: + * Stefano Garzarella + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/hostmem.h" +#include "qapi/error.h" + +#define TYPE_MEMORY_BACKEND_SHM "memory-backend-shm" + +OBJECT_DECLARE_SIMPLE_TYPE(HostMemoryBackendShm, MEMORY_BACKEND_SHM) + +struct HostMemoryBackendShm { + HostMemoryBackend parent_obj; +}; + +static bool +shm_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) +{ + g_autoptr(GString) shm_name = g_string_new(NULL); + g_autofree char *backend_name = NULL; + uint32_t ram_flags; + int fd, oflag; + mode_t mode; + + if (!backend->size) { + error_setg(errp, "can't create shm backend with size 0"); + return false; + } + + if (!backend->share) { + error_setg(errp, "can't create shm backend with `share=off`"); + return false; + } + + /* + * Let's use `mode = 0` because we don't want other processes to open our + * memory unless we share the file descriptor with them. + */ + mode = 0; + oflag = O_RDWR | O_CREAT | O_EXCL; + backend_name = host_memory_backend_get_name(backend); + + /* + * Some operating systems allow creating anonymous POSIX shared memory + * objects (e.g. FreeBSD provides the SHM_ANON constant), but this is not + * defined by POSIX, so let's create a unique name. + * + * From Linux's shm_open(3) man-page: + * For portable use, a shared memory object should be identified + * by a name of the form /somename;" + */ + g_string_printf(shm_name, "/qemu-" FMT_pid "-shm-%s", getpid(), + backend_name); + + fd = shm_open(shm_name->str, oflag, mode); + if (fd < 0) { + error_setg_errno(errp, errno, + "failed to create POSIX shared memory"); + return false; + } + + /* + * We have the file descriptor, so we no longer need to expose the + * POSIX shared memory object. However it will remain allocated as long as + * there are file descriptors pointing to it. + */ + shm_unlink(shm_name->str); + + if (ftruncate(fd, backend->size) == -1) { + error_setg_errno(errp, errno, + "failed to resize POSIX shared memory to %" PRIu64, + backend->size); + close(fd); + return false; + } + + ram_flags = RAM_SHARED; + ram_flags |= backend->reserve ? 0 : RAM_NORESERVE; + + return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + backend_name, backend->size, + ram_flags, fd, 0, errp); +} + +static void +shm_backend_instance_init(Object *obj) +{ + HostMemoryBackendShm *m = MEMORY_BACKEND_SHM(obj); + + MEMORY_BACKEND(m)->share = true; +} + +static void +shm_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc); + + bc->alloc = shm_backend_memory_alloc; +} + +static const TypeInfo shm_backend_info = { + .name = TYPE_MEMORY_BACKEND_SHM, + .parent = TYPE_MEMORY_BACKEND, + .instance_init = shm_backend_instance_init, + .class_init = shm_backend_class_init, + .instance_size = sizeof(HostMemoryBackendShm), +}; + +static void register_types(void) +{ + type_register_static(&shm_backend_info); +} + +type_init(register_types); diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..3867b0d363 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -13,6 +13,7 @@ system_ss.add([files( if host_os != 'windows' system_ss.add(files('rng-random.c')) system_ss.add(files('hostmem-file.c')) + system_ss.add([files('hostmem-shm.c'), rt]) endif if host_os == 'linux' system_ss.add(files('hostmem-memfd.c')) diff --git a/qemu-options.hx b/qemu-options.hx index 8ca7f34ef0..ad6521ef5e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5240,6 +5240,22 @@ SRST The ``share`` boolean option is on by default with memfd. + ``-object memory-backend-shm,id=id,merge=on|off,dump=on|off,share=on|off,prealloc=on|off,size=size,host-nodes=host-nodes,policy=default|preferred|bind|interleave`` + Creates a POSIX shared memory backend object, which allows + QEMU to share the memory with an external process (e.g. when + using vhost-user). + + ``memory-backend-shm`` is a more portable and less featureful version + of ``memory-backend-memfd``. It can then be used in any POSIX system, + especially when memfd is not supported. + + Please refer to ``memory-backend-file`` for a description of the + options. + + The ``share`` boolean option is on by default with shm. Setting it to + off will cause a failure during allocation because it is not supported + by this backend. + ``-object iommufd,id=id[,fd=fd]`` Creates an iommufd backend which allows control of DMA mapping through the ``/dev/iommu`` device. From patchwork Tue Jun 18 10:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0521EC27C4F for ; Tue, 18 Jun 2024 10:06:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJViv-0005RR-FW; Tue, 18 Jun 2024 06:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVib-00057k-B1 for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:42 -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 1sJViZ-0001U1-H0 for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bLmIFJnBiZstRbWMCttQ1B85eqiav2i7bnLQ8L9RWs8=; b=ZabeN9EYJYwRw3DFUh7S3FBRPpx7H2TD91793IaFasWORq1cfQdxeyhFba/AbgpxgWTZ0v jO0LrDgNbrvRItJ5ey600pa4uPhfMs6zEbFywuXmEJct5asHYdWTQ7QQGxGaHnn9OyPvuA TbDnqGW+ZMrGiLYgQ8PjBAjTtRdq/2M= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-om0_B6AiPO-Lrno9Q9Wpsw-1; Tue, 18 Jun 2024 06:05:33 -0400 X-MC-Unique: om0_B6AiPO-Lrno9Q9Wpsw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-35f21956382so3381553f8f.0 for ; Tue, 18 Jun 2024 03:05:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705132; x=1719309932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bLmIFJnBiZstRbWMCttQ1B85eqiav2i7bnLQ8L9RWs8=; b=qj8kjSsM+QnO1DzWTM/khzaRYNNOpX0VOKeOfZuyODVF3AHTxD2RYQzIjCB1cT2M88 aabF3I0G6YppufdpHKHkANpnUp9nLsCYtiZk3vn5Fu9+n6wt6lVZTORWcLZinxhcIKKk XE2+VtRg2SF9IIAXReMziLzweyJ6B2ayzavGLTnpuiUCAlqDe0mkM2PDATxjdPkVCcjv IiYm1tYYXLcQYgCotwgUbN+GChJLfEjT0buzdfQF9/pT3WpExBFv6AnclxMLCUgIVwzU p3CSeMnfskUIZ+NQS3yV2OmjzJQLDq7w0y1q5223as48f93kzQBSMBo3VVfeKMR1A3/L 0ztg== X-Forwarded-Encrypted: i=1; AJvYcCXsJZVw8+jwAcAkUMUhpVV1YbSWGgkXUR0Y9S/n6Pj9pAWH1WunaiUPRn6zzDpI9sDnkxcn5iiElIvWMM/resul5rXLO48= X-Gm-Message-State: AOJu0YzhoBTtfV0tAYqXbSn4fbjL9dhbp4Y5mdGcLRT77yYp+4ibHCgL yR5t85P3kdpDdjP4HBo+ybw4clxg1CFX7F+SfSXx4jQMPNSUXfXAuzR9+97sOKl9iIwQyC4Mzu8 YC8V/10dgpiKYKqNckdjpqg67Wk0LD+zr81gu1uzGGr3ggpY5tI1k X-Received: by 2002:a05:6000:22e:b0:362:40cd:1bc with SMTP id ffacd0b85a97d-36240cd02aemr478548f8f.24.1718705132505; Tue, 18 Jun 2024 03:05:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnE0GCv/YZXncNH5Alm9LYmEI3nUwKhyNtbHP3mUE/cD3YzL7djLDsWpqx7H8taapurh7IeA== X-Received: by 2002:a05:6000:22e:b0:362:40cd:1bc with SMTP id ffacd0b85a97d-36240cd02aemr478519f8f.24.1718705132141; Tue, 18 Jun 2024 03:05:32 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3607509c906sm13811218f8f.39.2024.06.18.03.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:05:30 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 12/13] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Tue, 18 Jun 2024 12:05:27 +0200 Message-ID: <20240618100527.145883-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org `memory-backend-memfd` is available only on Linux while the new `memory-backend-shm` can be used on any POSIX-compliant operating system. Let's use it so we can run the test in multiple environments. Since we are here, let`s remove `share=on` which is the default for shm (and also for memfd). Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- v6 - removed `share=on` since it's the default [David] --- tests/qtest/vhost-user-blk-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index 117b9acd10..ea90d41232 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -906,7 +906,7 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances, vhost_user_blk_bin); g_string_append_printf(cmd_line, - " -object memory-backend-memfd,id=mem,size=256M,share=on " + " -object memory-backend-shm,id=mem,size=256M " " -M memory-backend=mem -m 256M "); for (i = 0; i < vus_instances; i++) { From patchwork Tue Jun 18 10:05:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13702053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5F595C2BA15 for ; Tue, 18 Jun 2024 10:06:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVix-0005la-3X; Tue, 18 Jun 2024 06:05:59 -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 1sJVim-0005Kw-4N for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05: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 1sJVij-0001Uf-UJ for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:05:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718705143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CNfNqVgiPACxEos23z/KKmFGM3slQs8eIq4L2oKEPI8=; b=cd3RyXMyJ+NcJMerv+34TQXZda/McuoNmvV1gA4XyTP1yXki6bDuZZ8uy6++qd3+7Dd8GX jxTqWSGbNIt+voJTnBcCa93CZ2Sb/buj/xaiP4zt9OYORiLaubu7QK1RtPMqpETE7JsHJp hZuGiI+EYfbMYvWHhaGyGW3Dx02pAN4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-uHrNavzQOuGYbVQTqORrNw-1; Tue, 18 Jun 2024 06:05:41 -0400 X-MC-Unique: uHrNavzQOuGYbVQTqORrNw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4247047e74aso6859285e9.3 for ; Tue, 18 Jun 2024 03:05:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718705140; x=1719309940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CNfNqVgiPACxEos23z/KKmFGM3slQs8eIq4L2oKEPI8=; b=cuXTbII6O1cSUE4wW9Zt/hwJcNPlcRQ6koiiNwB3xcpCdKGxQoNuvArYI9d3ACeoZ9 o6DuJE0UJIzr/+lchkzHdC5ZmQxseIJsie2vs7iDWpAmkuV7Y9GVpcQ6x/WiElZrR6pp Xdz4zcQCwCmdaZmq3F9C5I2JUiRQ8xgiXyQeI8CnOPFAaBdzgHyxGwTDUaljkMQi6EfR aTusid3/2C0C0LE6lwt40I8Kp18cCfM/uc8SSbs8VTQGFIBxuxvRBU+uFduJ4YpnWz7z jnfsirsxPM3NmqMa1QawncjSlKXu2Sd6GjPp7utrpYkYUPIBsqycUWmKAO0w0ZyTZDll bUnQ== X-Forwarded-Encrypted: i=1; AJvYcCXlQryz/LRlniSyi/ux8diD2J161nyDPpQhlH7zyQtX/Q6l89chUQjVopYqNd65jASJ1ifpmtOsHS3Vt0NYP0rdMBdiMes= X-Gm-Message-State: AOJu0Yw1zHnbOtP4WhNCE2N5cHdF5QWsNmAKWISAQlDTytag5P1D+es6 YR0oIu9Wa81OIR6xeJ+coFWAgdU8L8WmUGgzcHx1gwbFacMD60vpUgNnAtbiRO7gpeDHMcEN7gn djdIBscDjRC3EJIzAo4zSyvTbMZzBrkafDzR5UYlcY8yy3QtWIXNq X-Received: by 2002:a05:600c:3c9a:b0:41c:2313:da8d with SMTP id 5b1f17b1804b1-4230483252bmr136566445e9.0.1718705140589; Tue, 18 Jun 2024 03:05:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE52dnZ/72DVn6ipXjceblA0qx4BqRMRW1Er6XSnVUrJfTjDv7BA6onSXJon+w5K1J+dltbbg== X-Received: by 2002:a05:600c:3c9a:b0:41c:2313:da8d with SMTP id 5b1f17b1804b1-4230483252bmr136566125e9.0.1718705140186; Tue, 18 Jun 2024 03:05:40 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f6320c70sm183610035e9.30.2024.06.18.03.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:05:37 -0700 (PDT) From: Stefano Garzarella To: mst@redhat.com, qemu-devel@nongnu.org Cc: Thomas Huth , Kevin Wolf , qemu-block@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Gerd Hoffmann , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Hanna Reitz , Brad Smith , David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Laurent Vivier , Coiby Xu , slp@redhat.com, gmaglione@redhat.com, Igor Mammedov , stefanha@redhat.com, Raphael Norwitz , Markus Armbruster , Eric Blake , Stefano Garzarella Subject: [PATCH v8 13/13] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Tue, 18 Jun 2024 12:05:34 +0200 Message-ID: <20240618100534.145917-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org `memory-backend-shm` can be used with vhost-user devices, so let's add a new test case for it. Acked-by: Thomas Huth Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Stefano Garzarella --- tests/qtest/vhost-user-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index d4e437265f..8c1d903b2a 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -44,6 +44,8 @@ "mem-path=%s,share=on -numa node,memdev=mem" #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ " -numa node,memdev=mem" +#define QEMU_CMD_SHM " -m %d -object memory-backend-shm,id=mem,size=%dM," \ + " -numa node,memdev=mem" #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on" @@ -195,6 +197,7 @@ enum test_memfd { TEST_MEMFD_AUTO, TEST_MEMFD_YES, TEST_MEMFD_NO, + TEST_MEMFD_SHM, }; static void append_vhost_net_opts(TestServer *s, GString *cmd_line, @@ -228,6 +231,8 @@ static void append_mem_opts(TestServer *server, GString *cmd_line, if (memfd == TEST_MEMFD_YES) { g_string_append_printf(cmd_line, QEMU_CMD_MEMFD, size, size); + } else if (memfd == TEST_MEMFD_SHM) { + g_string_append_printf(cmd_line, QEMU_CMD_SHM, size, size); } else { const char *root = init_hugepagefs() ? : server->tmpfs; @@ -788,6 +793,19 @@ static void *vhost_user_test_setup_memfd(GString *cmd_line, void *arg) return server; } +static void *vhost_user_test_setup_shm(GString *cmd_line, void *arg) +{ + TestServer *server = test_server_new("vhost-user-test", arg); + test_server_listen(server); + + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_SHM); + server->vu_ops->append_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); + + return server; +} + static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *alloc) { TestServer *server = arg; @@ -1081,6 +1099,11 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); + opts.before = vhost_user_test_setup_shm; + qos_add_test("vhost-user/read-guest-mem/shm", + "virtio-net", + test_read_guest_mem, &opts); + if (qemu_memfd_check(MFD_ALLOW_SEALING)) { opts.before = vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd",