From patchwork Tue May 28 10:35: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: 13676450 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 D0310C25B7C for ; Tue, 28 May 2024 10:36:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBa-0004H4-Jf; Tue, 28 May 2024 06:36:09 -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 1sBuBR-0004G5-Dp for qemu-devel@nongnu.org; Tue, 28 May 2024 06:35:57 -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 1sBuBO-0008AN-UI for qemu-devel@nongnu.org; Tue, 28 May 2024 06:35:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=M6IUFiSxUs6k+M0DPac/gE1T4R+iGn5r1rI6LE/QoIvcpg9mx7whN4T1gWrauAefWvaG1e /3bHyjcn4bMRWDO5pJqIHCEtWB2V1OFAzCP3MI7u9pZSjpiT2Fr+ZGEinf/zRDEFXS6Pz+ fT0/42TJnBJbRTjU17psBt9ijeF9v4E= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-EgYDU-qnMauWdSwHeLPDfw-1; Tue, 28 May 2024 06:35:53 -0400 X-MC-Unique: EgYDU-qnMauWdSwHeLPDfw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3580f213373so518412f8f.3 for ; Tue, 28 May 2024 03:35:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892551; x=1717497351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3UtH0D4I15f6AmqPGZ/mKuxu8KcITJcJzO63ZIJCMrs=; b=CmtvuelmUE59KE8PuKPj6Jquj+qSBRRlcoBkxj4A/kkqzfxf+lhVMlFTModkca4S07 a4fOBLOQdjTL71Wjh3n6oBBk0FamyrxgHA5szSZLmz73Xp+P98qRSkBaYjsCiYWGlzXk 21Fbj7J8Gxl1sXa5slxaO+Ckac3sewBeth3GGpCQc2YJXzU1lCbMbjdqim63N/t6AuZR 9j5e+C/Y/dQEES0sE1vYszmTcDZYnKFvGU0MbhyyiahEJzXerd32CmMJp/QQQ6S541Kg 4Axef/FEZPNVzmPcyaTCPwl2WP1Z5HqNm/lWpEG/5EUyoQXfWk/0T5GgmTml22GzPeaN 3mVw== X-Gm-Message-State: AOJu0Yxm4r2JJd/Wicq+HbpnCFwmN7agyqIz2wUQBJi/CU4qGCRwlqSa tNugy+d9whVEafeEcSFoi6iCl1Qfz6idz/Fabkq7zmVA9dNdE+qFy8EHvzm9xfZj3hTrFydFhCs CwVQO8aeoHzsHMER9H54qwRJIU2NMbD/VXu0g/XjrJrlULSz4fEH+VPqweAq8hNbP7TLnlWDjo0 wG0i+p2O9Ch+brY2AVHyHwVuEOeeGcN1ny6xlY X-Received: by 2002:a5d:4385:0:b0:357:5051:2a58 with SMTP id ffacd0b85a97d-35750512b9fmr6204890f8f.16.1716892551404; Tue, 28 May 2024 03:35:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWuQ2BGJUk3myyZuI10BwMyCNuCR38/3F2ZlIx6PoUKn8VGkBeGUglZZ5r0fNeXYH/kE3XLA== X-Received: by 2002:a5d:4385:0:b0:357:5051:2a58 with SMTP id ffacd0b85a97d-35750512b9fmr6204854f8f.16.1716892551077; Tue, 28 May 2024 03:35:51 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3564b762ca8sm10588060f8f.112.2024.05.28.03.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:35:50 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 01/12] libvhost-user: set msg.msg_control to NULL when it is empty Date: Tue, 28 May 2024 12:35:32 +0200 Message-ID: <20240528103543.145412-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 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 May 28 10:35: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: 13676458 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 4B691C25B78 for ; Tue, 28 May 2024 10:38:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBs-0004P2-3e; Tue, 28 May 2024 06:36:24 -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 1sBuBX-0004H9-AO for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:05 -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 1sBuBU-0008BJ-Jr for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892559; 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=R1hrZjd8C+P/TJKcTay5AIq/j09eUcHNdpUi41ujwU8=; b=VpiOmzn7PhWOF3iF5mPgldH7kHpq8GALL702bjVHCZ+vSlkn56ZPPrxOZZv+fSBgQMf1xd EeZ0rLxyzOqVl+6Ceygz+TFpvlJkboPEd4bI0ABJxNEVK6LJjVmc0j68oBD1vSxos+eWk3 CCYUMvRwlre8UivmztktI+k/morl9Ww= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-43-n5CxWwGsP3eYeUOPAXW9gQ-1; Tue, 28 May 2024 06:35:58 -0400 X-MC-Unique: n5CxWwGsP3eYeUOPAXW9gQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-354de3c747bso433647f8f.0 for ; Tue, 28 May 2024 03:35:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892556; x=1717497356; 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=R1hrZjd8C+P/TJKcTay5AIq/j09eUcHNdpUi41ujwU8=; b=bEyGHuSpKptnla9VdaUFa9As2RO10pzoDFeltMdb168JVLBC/Bmyklg7Dq7PAGmhXP HRtvkynHP2BrnnsPMVPNmVC1wRxiFfKt0IwNoteMfx1vRYUvjbD+Ckp1UWxxD06Q0qB6 Y19UikIrP6sI8VlqcigUCBrNPjyAD9Y6QrVSlR/diyC5JzXnTkgO9DDxV5BplBGIRGyg Zij4r8xbnLWDzwuMjiKiQLxYgvo5N8E9oLvxKAJhfT/pSytTxJezus/nfgLFbJGAGzHP GRkrfVZo1v1oFhGTNUwSVVn15XeBReCS761xNskeWhs3VJfS7wrrcwKrWtP+C7IGBaWA Y2Pg== X-Gm-Message-State: AOJu0Yw8rtaN/r/lnvqVEo/5t8ESnebIxOvQYYCaaeWmlcXe2RUeeMBe 43z3ean2i+W+Re5ePk1SBablnafnx+AFmkxEBn6W0RyCjWcROlUx05VgmAGT4fm2BmlwQm5wKlU SLRBR/sBony0t5k0H8EosJ5ZEVDBLEjDzP3BYEZiH8LukI6a3B+cyb55XR0oJxamzIZ4PEaO37A UP3U7falW9gddGtk9WjeURyvLZhn55quou+V03 X-Received: by 2002:a5d:6846:0:b0:354:cf3b:5791 with SMTP id ffacd0b85a97d-3552fe0211cmr9126222f8f.70.1716892556389; Tue, 28 May 2024 03:35:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoFM14g7vg/DaHhzW3IUmtDA0rAdyjmuaGRucVyIZrFB7HdNjC1uXP/Zkw3JMBff5GHhxh6g== X-Received: by 2002:a5d:6846:0:b0:354:cf3b:5791 with SMTP id ffacd0b85a97d-3552fe0211cmr9126176f8f.70.1716892555892; Tue, 28 May 2024 03:35:55 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a1c93a5sm11364472f8f.70.2024.05.28.03.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:35:55 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 02/12] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Tue, 28 May 2024 12:35:33 +0200 Message-ID: <20240528103543.145412-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 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 May 28 10:35: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: 13676455 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 11AA9C25B78 for ; Tue, 28 May 2024 10:37:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBu-0004RU-9N; Tue, 28 May 2024 06:36:26 -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 1sBuBb-0004Hj-OZ for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:11 -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 1sBuBZ-0008Bk-0i for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892564; 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=1S2/FREUTloncOeuDDrajxRNh9S3+Gj4t6YZDhkj1gc=; b=XdJ9IfzdSiPo6JAI3hPN0bDMcDdKxk4Epx9hxpNrAl59bztjPKc88vDxVukfubO+jj7/W+ BxUXBw9mRKM8wEvwPG17zLwVCgdnryIbZyVx+BrLVETToPp1JEkUNJtSPde8t8mKkXRokc b99RrEVMcysdGJmS4JJArykfEdwwVB0= 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-682-AbgRrUeLP3egJT5C4pfgyA-1; Tue, 28 May 2024 06:36:03 -0400 X-MC-Unique: AbgRrUeLP3egJT5C4pfgyA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42109a85f5cso4638865e9.2 for ; Tue, 28 May 2024 03:36:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892561; x=1717497361; 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=1S2/FREUTloncOeuDDrajxRNh9S3+Gj4t6YZDhkj1gc=; b=CPtuFxytrijp8joprFPvbRntR1DbISliBDT+vMUtRNrvNqRuY9C3mIvDJU5JUgPFaC Q+DK0oUhVb1n1n/78Ggm9eQmR9U1nnwyx6sGLkXjd69q5IngZQkBDUYlNwZT55wfw4Gl Dmvd51foP3lOP1yrQzB5QUtgVMCd5ioKDudxisHE9Ec46sfsEo28HEHtJEuR/e6d/ceH UiXfhGxhxYS4iqvRFJUxd4CySh3l73tQU1B8csLQyZa2HqT6jgK0H1gibH7i4nEHUaUB ljDMYVqT5RR6BxEtNWEOIpJk+e6PXUiulcxO2wT9HPDf8QhFB16dho/xTTFSCFjoLWrW Yd0w== X-Gm-Message-State: AOJu0YyWc2VY7Sw+uFzHZ3BxLKRcvRhYWp4kePJ/X8O+IwBYk/0w6V9J AHh8DufPnnVD354ehfXvaKxwBVozncGz8IX5iFst+evToggCWEKtSmWSQ0nCU8UrBbZs+16SkTO us0G/XKghPvOnyrizzysOdFYJtJGWeo82X1ily8Xteqo/B5jmU1TamoEgzML6u4w5V1PmTevCYg xF1rZ9TbR9ZR40wFX52Gvvl0a1uIh+1g8WUI22 X-Received: by 2002:a7b:ce8c:0:b0:41b:edf4:4071 with SMTP id 5b1f17b1804b1-42108aa6fc3mr136175265e9.35.1716892561665; Tue, 28 May 2024 03:36:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAHjoS3mWbS3S5UrzxHwxs2o/RE6gwgI0Ih4ab6GDi4TNszd+g85Axky2YD+4HZL6p13/6FA== X-Received: by 2002:a7b:ce8c:0:b0:41b:edf4:4071 with SMTP id 5b1f17b1804b1-42108aa6fc3mr136174815e9.35.1716892561256; Tue, 28 May 2024 03:36:01 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35579d7dba2sm11244776f8f.17.2024.05.28.03.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:00 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 03/12] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Tue, 28 May 2024 12:35:34 +0200 Message-ID: <20240528103543.145412-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 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 May 28 10:35: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: 13676453 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 CDDDCC25B7C for ; Tue, 28 May 2024 10:37:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBv-0004SH-J6; Tue, 28 May 2024 06:36:27 -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 1sBuBh-0004Kg-C3 for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:16 -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 1sBuBe-0008CY-Cx for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892569; 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=gcMdg1C44DPSxqgUst9QRh9S77EyKlJRt0SoqUaUqls=; b=CewPHu07UzAlzSu0tl9AZFaQAwSP+Wwomr5XhaN2qrVxf3QgFgRCdRzLxKWxH68LS49CaQ R05eWYbbaXAQC90TahpQbBGxXE/SJEK7IuixOkmq9sEp5OmF6nmvkDqgJsSJK1QjHMZic2 TSzWKowAvY2NmLoaY6E+kA1cAaK8jx0= 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-210-fh72tz-zNaiG9cyQk-v6gA-1; Tue, 28 May 2024 06:36:08 -0400 X-MC-Unique: fh72tz-zNaiG9cyQk-v6gA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42120e123beso1600995e9.0 for ; Tue, 28 May 2024 03:36:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892566; x=1717497366; 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=gcMdg1C44DPSxqgUst9QRh9S77EyKlJRt0SoqUaUqls=; b=i7vXkKfxheGp345fL9JAXXKRNOqw+OxtIoJZB/fftYlJwO7ux1G9EuZFtxbqlcFVuv dgzsM1Oq4Q/+FDR9+ZdZIKA4q25ZwJZH5xB0yPIOwWNV+h0mXNftO0Hx5Pi2XHrdbFZD ssZZgfXZqHWe6vFk8nGAbHTHlaAO8XhtYb2fbyrpIvbHmoMJ/NPg5pxyr6MGSaa5UTay GRaJnwdrO8gFYDcF3t2D1oUgQqLbx+VRO8tNxznosEUfCaLyXeTxytTt6XZqHWeFACaV y/ZN+S5vqlRKqOa2AGDV25GGh0BibiANNn7KFiLKQBKt+2F1oSiCe9B2cpIwK6JIx/SE fBVw== X-Gm-Message-State: AOJu0YwDrGkSa4INEvqGjCde3KHaTC/O30rW0puP39T4q+GVP2prOE85 TsNw6V7I8ws4Hbu4y+z+tTuP0nWp+IFTgopvAVykfCzUDl9KUpZTVXpiZiHf8fEa5qIcKxeTJQw oSpCgIWQfBDNpUjldNf1rxT6tnHs1VmJSaMYTciSAouGBbrfT12fiHW4qI/zZHeZh9X2mNiLRUE 9DWh3N75JPj8lT4tAiQB1+zQGAistRuNOe+8Oq X-Received: by 2002:a05:600c:63d6:b0:41b:f6b6:46cf with SMTP id 5b1f17b1804b1-42108a40d1fmr125049865e9.11.1716892566529; Tue, 28 May 2024 03:36:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxGsL+lkv7+GYt5RQJfSGZRCesMmsGpI3fY/XA7nhVa5XJeLs/IwrQsfGn1paE/WqYCd4R2w== X-Received: by 2002:a05:600c:63d6:b0:41b:f6b6:46cf with SMTP id 5b1f17b1804b1-42108a40d1fmr125049365e9.11.1716892566119; Tue, 28 May 2024 03:36:06 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f759f0sm165844865e9.28.2024.05.28.03.36.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:05 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 04/12] vhost-user-server: do not set memory fd non-blocking Date: Tue, 28 May 2024 12:35:35 +0200 Message-ID: <20240528103543.145412-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 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 May 28 10:35:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676452 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 84451C25B7C for ; Tue, 28 May 2024 10:37:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBt-0004R0-Rr; Tue, 28 May 2024 06:36:25 -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 1sBuBr-0004Mr-TP for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:23 -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 1sBuBl-0008EZ-Pz for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892574; 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=4bUhfln96QjtAy11XUS1EjId/7CwaVd+bJQnV2M45BI=; b=AuaaOy/aHpVM6IjPXBG29/2M1BCYoRo4jKZ+3wdpXdk7PJXInO8mFjwEAp0WAF5o06N3dp ascgdisJJGpq0q4wbSKJ/GSq24tZHLzN3EqUIwPQXaX0RmDXjZgNYqJtxtwhntY2cfnUnZ /X4WEndmQ/WsgQ+i3oXXIYLa0tlgpwA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-_I0jgNvGMHCs0GywptXwaQ-1; Tue, 28 May 2024 06:36:12 -0400 X-MC-Unique: _I0jgNvGMHCs0GywptXwaQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3564bb7b352so372174f8f.3 for ; Tue, 28 May 2024 03:36:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892571; x=1717497371; 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=4bUhfln96QjtAy11XUS1EjId/7CwaVd+bJQnV2M45BI=; b=aBZ7y/mX8H6ZE3ijJhiZLovTAuwxgO8XTp6KbpULqSK0NMofQXo2zz8VjlI32hMoBB xjLDeFSD+iaT+qJmjf/QoEu0bHUO/6OzHsYXA+3fHRsAEuqNE7xlFvwJE1xZKhw3J00a QcabgS5auv8t+x90oit98mC3L1do1476hbuZCVb2aykNFSFcjzTYO/lZ3fwj3mWOC+RS j11B4qi6jyHU+K1wI9pfFJFa3Y4Ah/2UgmCknhNXkED/1mYRMxHpndnQdeYoaatghalb MCcTtsx7Vt032gOySBGeyhZMU6Xb/AZJ0dIySenaa7ddkXwtJANNFs/arFiOqcId5lW+ f+cw== X-Gm-Message-State: AOJu0YyAEsHTNQz0A42BFAKMxv0ViNF/EGBKQMExPzrIpG9KUbktot5p 6M+kLe2CW31G9t5OEpHAT3QY4Jer5L9LUZZZxgVn1C8BxtjqRujo/HSx/P/YW+U/yyHuvgRtS1z JSf9GX2E4Pr0Ps1EBjIl7ueKeedZSPV1bB7Gy5CwS2rpXkDPS/Z0LdmiMA7e5TsowklA7P/8kpk m2ku+7KNfF/mL4Zg1n4zz9Axh9qVNVEcfKolW4 X-Received: by 2002:adf:a316:0:b0:354:f444:c21e with SMTP id ffacd0b85a97d-35522186c5amr6992169f8f.22.1716892571334; Tue, 28 May 2024 03:36:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLhNQ8/ZaebS0APBXilO61bzf36ADNcAkfEhqPDQzntQVYr0Z2ify1MYaBOdN0D+hBcqsHxA== X-Received: by 2002:adf:a316:0:b0:354:f444:c21e with SMTP id ffacd0b85a97d-35522186c5amr6992132f8f.22.1716892570870; Tue, 28 May 2024 03:36:10 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3577505a218sm8155894f8f.31.2024.05.28.03.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:10 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 05/12] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Tue, 28 May 2024 12:35:36 +0200 Message-ID: <20240528103543.145412-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 May 28 10:35:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676456 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 CEAC8C25B7C for ; Tue, 28 May 2024 10:37:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBw-0004Ss-5k; Tue, 28 May 2024 06:36:28 -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 1sBuBs-0004Px-DI for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:24 -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 1sBuBq-0008F5-NX for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892582; 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=e7uQF4Gi0pZ6bwyXQv9cyLYqbc38Kf+gnOBq39sMLzc=; b=gfvx1msfygBzUOmeKcJGXZvp4cGBNDPUJ6G1LJXvfSMQqvT70ViT7lcgzkXfGAFYA7Ga1Y 2rvr66JE7utDgMWA0oUFfAXgwvIN04WFx8a9/iZPDVfO287DBY7/E1KK7SsSon4wHkJzAi 13wANqPnJ5FEnRK42OIZo2XDTUzuBic= 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-508-sfcix_OQMvyYS04tUludeA-1; Tue, 28 May 2024 06:36:20 -0400 X-MC-Unique: sfcix_OQMvyYS04tUludeA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4211211e18cso3266475e9.3 for ; Tue, 28 May 2024 03:36:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892576; x=1717497376; 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=e7uQF4Gi0pZ6bwyXQv9cyLYqbc38Kf+gnOBq39sMLzc=; b=mkHNdfle9cvY/H94PZy01ZhPfKR3d9Q4+Rbo+teoeGck0aA8se/b8g9kKCG2usuNQN X7xXjKT0tjh7NQJFhnvHKY5WmSPuw/oJNCYHaD83Edew2PsRfdj2B2h2alOypQUq7vO6 39FrTp6MNbFOMBuRp4Qql/pZzB9KRABRZ0Al/UHdssS/ek3i7jDSYzq/ts830rh6A2ls sTKWtM33KIwOUwxaZzV8n56Wk2uCR9y8xdwhSEKTnZG+EZ1csxS9Y//K7YLhrIzc2CM3 zLXSoO9xKTWnL2KQPSAMLOoABfYT1gRre8EFuDe5b+uL/gDkYb0L7zDg67Tooq8OsKJj /4uA== X-Gm-Message-State: AOJu0Yy+SJzLNJ2UWOUcVA0CDsAoUuwe3U2skGpPiVnjlhiOqZI2rVfe XS8QrOhou+ukhOIFlmGYPnE48wTPMOFzZheG7z2r0ENaSZvnnX4tgIQa4YZocnfacTIeRnSt2ju 1a7+vnqDXYkQGpNcdihP2/9e8lMxvoDP8ZqLCjohkq4+WY8swGW+yJBpv4IgZynQXWYcHUOh+Fq sVOrW1cr7UTBRx1qZ2akENNAW3/wHTJuPCOljF X-Received: by 2002:a05:600c:2948:b0:41f:ec3e:9797 with SMTP id 5b1f17b1804b1-421089de607mr105969355e9.16.1716892576015; Tue, 28 May 2024 03:36:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIxOxzA8eL9YpWF+7ehAGvkh3xRIaVcT9fg19M67elzzhEy+5NF+4HBuR6WsYqq00Etmm/Tw== X-Received: by 2002:a05:600c:2948:b0:41f:ec3e:9797 with SMTP id 5b1f17b1804b1-421089de607mr105968945e9.16.1716892575649; Tue, 28 May 2024 03:36:15 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100fad638sm170283785e9.29.2024.05.28.03.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:14 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 06/12] contrib/vhost-user-*: use QEMU bswap helper functions Date: Tue, 28 May 2024 12:35:37 +0200 Message-ID: <20240528103543.145412-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 May 28 10:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676451 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 DA434C25B78 for ; Tue, 28 May 2024 10:36:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBz-0004Tn-PD; Tue, 28 May 2024 06:36:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBuBy-0004TD-EK for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:30 -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 1sBuBw-0008Hu-Ht for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892588; 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=QWgDH/gDQAxyHJPRHaKd8r5IWyJMqj8jhSH9L5DHuSs=; b=PX8LnCiErlTqinScRaUxJbUH3BlwYdpHEsJ7pQYk+JdFq/v3195ijaQtkpvCVppLsKE15F AcABhGGKc72BDoCTfFu4npfhKoghUpY6JHZkGl90fUuSE6Z6aPo8yK9Gkpe+j3RYIFHHe5 OP+y66aTnn5DTYBg8jxP4ZavGESLbM4= 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-240-zntWtRH7OmG4nZm3nBuyjQ-1; Tue, 28 May 2024 06:36:26 -0400 X-MC-Unique: zntWtRH7OmG4nZm3nBuyjQ-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-5236c5cec7dso585586e87.2 for ; Tue, 28 May 2024 03:36:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892581; x=1717497381; 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=QWgDH/gDQAxyHJPRHaKd8r5IWyJMqj8jhSH9L5DHuSs=; b=Ti5dJFUZ2WPTZyvPL7wKr5Qg9OqZLSrFtdze4gMNUa6De0THuI4EWCTrIIdurThpoF 56FWZ6x+we4r39+91LAOKvODLhkV4wY7f4M9tRvNf06wag+s4U8Tfjonjr+++wPhWLb9 483SxBgfDl6xxVtaYDP6wifP3MQVgsGG9T9vkH1VB1v4SN3UdrM13bzs+lCO31xWPjiQ KkAiKu65b260QoSg5CtAHsYTpNmE3Vn/nKOkeSVj/I2DVCC84RizIOjiWvDYknz842e1 uZWm+NXHXaRomY5IP19bQ1qn+eABdzKcuos5A6gq7c+9Jfzhsf2fD5YCD2L1Vf2bYXOa INCg== X-Gm-Message-State: AOJu0Yz8z40rLyFrQJvBKUVGlDDDYpsYsFQJEQ8NLmMuCs2MpCvLhePs G8ebj4ybu6MG6pbpfEShQyYq4LEgLgyJiW5l05+vPWnmDIb2TF54AQHw61k9P6AKejI+baAvJmS uiaTplmod+sC+0ubLA0Sl45jYKN4JN9FB7VI2QQ5+0TLG9FDbRHwsQCSWso5rNFJT6s2ZP9mVPG EivGM8wUlSOey/GLpRwoyEIP+mg20F05O+w3u1 X-Received: by 2002:a05:6512:110a:b0:529:a6f6:1b03 with SMTP id 2adb3069b0e04-529a6f61b4dmr8420657e87.14.1716892581512; Tue, 28 May 2024 03:36:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkqFaQhWkWgum4f5hE8KsQlq89AehXAbjYzuR81wRF8t6iD1TeW8UNVZ+xnGtVO04DVyStDQ== X-Received: by 2002:a05:6512:110a:b0:529:a6f6:1b03 with SMTP id 2adb3069b0e04-529a6f61b4dmr8420621e87.14.1716892580988; Tue, 28 May 2024 03:36:20 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42108966ce0sm137940055e9.8.2024.05.28.03.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:19 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 07/12] vhost-user: enable frontends on any POSIX system Date: Tue, 28 May 2024 12:35:38 +0200 Message-ID: <20240528103543.145412-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 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 6386607144..a72500be77 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 May 28 10:35: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: 13676454 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 71D95C25B7C for ; Tue, 28 May 2024 10:37:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuC1-0004UL-9j; Tue, 28 May 2024 06:36:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBuC0-0004U7-92 for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36: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 1sBuBy-0008I6-Kh for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892590; 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=Ip8mp5/iMw0SwNnO89V12jrYLC8O/3xN2u7Jx3Io+wc=; b=gpKiO3hCUiWFRYTQL/qtQLXmgE1q2Qb8XkGMO8LdYNKe/ngJb/VLNVg3zdds7VJn06XfeS GaqUpyXd+v5oh9iSLbvk6QUilwwtYT0MpMx0NCpbLzitGpeOiRGjVp1X7o72B0RCQU/MUJ 8Dtmmq8f4CCuk11I4yjtKDJpIcBtOzE= 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-365-K861vp1LMdafezdcFFtEdg-1; Tue, 28 May 2024 06:36:28 -0400 X-MC-Unique: K861vp1LMdafezdcFFtEdg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42024ca94d0so3284445e9.1 for ; Tue, 28 May 2024 03:36:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892585; x=1717497385; 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=Ip8mp5/iMw0SwNnO89V12jrYLC8O/3xN2u7Jx3Io+wc=; b=vIZs9Vp3A33EaUC+N5QE0IRAunXYdHykoeyeELeVNGMpl27KD4TEtg5aff6NIZU17Z Ym/GozO5EFmDaE33eZtyjUN+VRvBXw69C8JELPwjojrCjheFBfebqNg2i57mmYyM8OW1 PSU184H3eulR4d2rQZ+1bW+xF6pod6MDDYn9YH36nHmgx9qQKDZudkfRJqx0XKX+S1TD 8Dzkc9eKWSayVfuAnyqn5cQsQawKmfAu1MGMv7hxcgSTZEi44T1R0VOSZuHOAGdTndkc PMDVc8HkP1Zy1CruAe/xQ2Y8EfsNbeN+PCBvT+VGtr6MUdvmEqcER5HMD340vv3FvqnW o7QA== X-Gm-Message-State: AOJu0Ywvmw3dCdNCJMB53c+4uqs0I0qp8WPK/EVngAfoTUPIaG9mwYhI XJtFQIwtlgQXsbkU32fwNHhIEaS6Wijo7f1Mz5+7aJOQnfCL/I/IF1F11uAm1BBeN/gyiIx9CI3 QHpK0w/yWx5WfK2gQid/HP0fleNJX7SGhHXIyMf9JeFL1CN6/naryXlkXvZZ6a37c+eBLk/+R0B veF2L+/enbwdtsCKIuiNZ5ZD/OjR2ZpUDLe5ZG X-Received: by 2002:a05:600c:4f52:b0:41f:fca0:8c09 with SMTP id 5b1f17b1804b1-42108a15120mr84210615e9.40.1716892585635; Tue, 28 May 2024 03:36:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLihbkYiuY/sHdEh1Uq35i8VXI6O3hhOIRMCr4FsbNaMBIqWKLGOZ+IoWT6DLR8suQwTncrw== X-Received: by 2002:a05:600c:4f52:b0:41f:fca0:8c09 with SMTP id 5b1f17b1804b1-42108a15120mr84210275e9.40.1716892585267; Tue, 28 May 2024 03:36:25 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-421089b0410sm136686465e9.29.2024.05.28.03.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:24 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 08/12] libvhost-user: enable it on any POSIX system Date: Tue, 28 May 2024 12:35:39 +0200 Message-ID: <20240528103543.145412-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 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 a72500be77..48e476b237 100644 --- a/meson.build +++ b/meson.build @@ -3162,7 +3162,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 May 28 10:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676459 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 5D6F5C25B78 for ; Tue, 28 May 2024 10:38:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuDz-0001aZ-Ib; Tue, 28 May 2024 06:38: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 1sBuDv-0001K8-AF for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38: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 1sBuDs-0000El-9T for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892707; 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=ZtdNE96DR7TVj2y2oELNu+a95VAeTxLMI49tULfbBf4=; b=HZmkWvP9EFAWRhEayRnTt3fePnxaAjmCFkuu9goD14b1cQbIkSh0/kKRCOoYw/ZRM4MpMM G28x/8J62TrObiyZlAW45mlwm82l3iIwECQ1YxlCNtUXzm5lt7OYOTPpr3pwamP4KfQ/nz CHp7MjQgA8ot7HUGKwSb8A7XYMFF9b0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-uOqV8CLFPC6emb5gwXXMrw-1; Tue, 28 May 2024 06:38:26 -0400 X-MC-Unique: uOqV8CLFPC6emb5gwXXMrw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-35559d30617so521216f8f.2 for ; Tue, 28 May 2024 03:38:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892701; x=1717497501; 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=ZtdNE96DR7TVj2y2oELNu+a95VAeTxLMI49tULfbBf4=; b=g+MSC/cakS46DAqggsVTgbyv8faepSd0fJ17nJ4cvqfp/wCTr9SiLWsMID2tsWOAf7 dnAr1DDSiMZZeXImn4oeJyfjBG3KCavMTnyrY6sFMyqG4qtTZdmrVtw14gppn5YrJ5ud e01i/QdcxcQfvxehkQTtL+rF9UQ+XS/L1WnJw8wQC7bZcqoofDpgVaYlKWAtItV2TTyU MfXbMa+IqkZ116j+dYR8BvUZKKFTzDFzCUtHsPwexrsT7Un6wCTqNAcxh4uZCnQEk2EE lnbTSbaCEkUiy+/lHgOKbGwGX/ag4LTQjCVMPSO2ASP1OFxDRAeHyrzHmVTlCUOxlbmP uQtw== X-Gm-Message-State: AOJu0YwIqEwp3pMULga00HfVic1N4yM/vbRnYKTAUI6r/0Ao1LVnEDsR XMct+MNvfSJyyp5RlfXws8zgmTU3tE9epcUh35MMiTVLmJnMSxpZqIBIsaMfNDBZMb1I5mgq3kp FTHdsNoQJj91oPYC5yn1EZ7axSKZ6Le2+uq0MlZ57MLBrok5mkhJSlqHH5HATrj0DMqGLirETX3 mN1LUbTyAeT0cJW6F2kd0rllp9l1ueaBCGvab1 X-Received: by 2002:adf:ce06:0:b0:354:f2b0:ebda with SMTP id ffacd0b85a97d-35527056594mr11106686f8f.10.1716892701669; Tue, 28 May 2024 03:38:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF9z00vDduVMqpdXX+QLot3fUWnGz08uB1xoHWS2G0TYc6fHz9aV7b7T31eO2g+zmBYfhZag== X-Received: by 2002:adf:ce06:0:b0:354:f2b0:ebda with SMTP id ffacd0b85a97d-35527056594mr11106645f8f.10.1716892701215; Tue, 28 May 2024 03:38:21 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-359b3675c6csm4310736f8f.71.2024.05.28.03.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:38:19 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Hanna Reitz , Eric Blake , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , gmaglione@redhat.com, Raphael Norwitz , Laurent Vivier , Brad Smith , slp@redhat.com, stefanha@redhat.com, Igor Mammedov , Eduardo Habkost , David Hildenbrand , qemu-block@nongnu.org, Kevin Wolf , Thomas Huth , Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Paolo Bonzini , "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH v6 09/12] contrib/vhost-user-blk: enable it on any POSIX system Date: Tue, 28 May 2024 12:38:17 +0200 Message-ID: <20240528103817.146211-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 48e476b237..c89ee7b578 100644 --- a/meson.build +++ b/meson.build @@ -1981,8 +1981,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 May 28 10:38:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676460 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 A7109C25B7C for ; Tue, 28 May 2024 10:38:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuE2-0001sH-9B; Tue, 28 May 2024 06:38:38 -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 1sBuE0-0001jl-90 for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38: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 1sBuDy-0000FF-2K for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892713; 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=db29oXrpbJH0UickSPvavWdNOAkMBJOnZvy+b0VtUIk=; b=h2KsgAqmddPc6NzTSug6EjjV4HpOc+JrCgsN2Mk1LYKZ1rxSI/W3hmuh0FeH5gTn8xXZ2S 2e1Nd1Gr5W1yiU51rxadPayUKHOkhAWYyFM+4EatnYaInKue434UWTotsA06tT7ijzIekN gxiVyh4C+LCKq9ebaGmD/1dB0njH2pE= 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-515-boqFkDbqNdWKtOH8yR6Y1A-1; Tue, 28 May 2024 06:38:31 -0400 X-MC-Unique: boqFkDbqNdWKtOH8yR6Y1A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4206b3500f5so4669105e9.1 for ; Tue, 28 May 2024 03:38:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892708; x=1717497508; 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=db29oXrpbJH0UickSPvavWdNOAkMBJOnZvy+b0VtUIk=; b=SKp8JI5GTmbozrV2MF10SpYdEz8bGKa0OW7Simv8IrOh1Qwu8o5Gnu842JFco7Rl8z kU3cAkFWYORdsMy+zGiTTUeuxyNNrpsXJBmE+EKvjKG708Dmcc6xTXYNWRH5+9eg+fkF 5Lr7j/og5g1GpDT1eSrLhGMg3U1f0XfTN1QnJlfy9dsncEx4chJpS62Qy1Xa09CHS/KR KPKRwISJ+ZTa+txzZP0dqWcsTqVP5/kavo68DOYI4/ymZMB1NUxScPkfzfx0diFIqTaQ JN29bgW+PYyC7AaBYZWuROfCKyDGGAEaQ0BNiDUo1YoYtlfguPd2btwQu/OXpCAajSpn 67oA== X-Gm-Message-State: AOJu0YxScamXpnX2049DgoiAjL2oG6em9h6PhYnGqzGo6ZPWPKjvBXpq Su+8nSYaDGQdmOteb27kAn6SUlkMtx7sdHGx4yp5/7Nvqb5qBkxQFH7zCL48U9t9YZXSG2X9iP4 Iv7XF6HL8YS1qMj2XovWw9QUFVhbUmkXRH9STjGosCxm3TFJ0HLAa6fp1Z3FlREJxEGcceXH4Ky t+uvgtDLi3dCmm9suhltUrYCYjOozHjy5opfMp X-Received: by 2002:a05:600c:19d0:b0:421:20ac:1244 with SMTP id 5b1f17b1804b1-42120ac12d2mr7432825e9.22.1716892708480; Tue, 28 May 2024 03:38:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIEkv8TeVdmI6D54Z9twJYFgWC0lyFFvHOuiDyS4mUfcYF64wZIRv6qFyYnZA14DR0BqfaKg== X-Received: by 2002:a05:600c:19d0:b0:421:20ac:1244 with SMTP id 5b1f17b1804b1-42120ac12d2mr7432415e9.22.1716892707946; Tue, 28 May 2024 03:38:27 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4211efcf256sm14722245e9.0.2024.05.28.03.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:38:25 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Hanna Reitz , Eric Blake , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , gmaglione@redhat.com, Raphael Norwitz , Laurent Vivier , Brad Smith , slp@redhat.com, stefanha@redhat.com, Igor Mammedov , Eduardo Habkost , David Hildenbrand , qemu-block@nongnu.org, Kevin Wolf , Thomas Huth , Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Paolo Bonzini , "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH v6 10/12] hostmem: add a new memory backend based on POSIX shm_open() Date: Tue, 28 May 2024 12:38:23 +0200 Message-ID: <20240528103823.146231-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 shm_open() creates and opens a new POSIX shared memory object. A POSIX shared memory object allows creating memory backend with an associated file descriptor that can be shared with external processes (e.g. vhost-user). The new `memory-backend-shm` can be used as an alternative when `memory-backend-memfd` is not available (Linux only), since shm_open() should be provided by any POSIX-compliant operating system. This backend mimics memfd, allocating memory that is practically anonymous. In theory shm_open() requires a name, but this is allocated for a short time interval and shm_unlink() is called right after shm_open(). After that, only fd is shared with external processes (e.g., vhost-user) as if it were associated with anonymous memory. In the future we may also allow the user to specify the name to be passed to shm_open(), but for now we keep the backend simple, mimicking anonymous memory such as memfd. Acked-by: David Hildenbrand Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v5 - fixed documentation in qapi/qom.json and qemu-options.hx [Markus] v4 - fail if we find "share=off" in shm_backend_memory_alloc() [David] v3 - enriched commit message and documentation to highlight that we want to mimic memfd (David) --- docs/system/devices/vhost-user.rst | 5 +- qapi/qom.json | 19 +++++ backends/hostmem-shm.c | 123 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 16 ++++ 5 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 backends/hostmem-shm.c diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost-user.rst index 9b2da106ce..35259d8ec7 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -98,8 +98,9 @@ Shared memory object In order for the daemon to access the VirtIO queues to process the requests it needs access to the guest's address space. This is -achieved via the ``memory-backend-file`` or ``memory-backend-memfd`` -objects. A reference to a file-descriptor which can access this object +achieved via the ``memory-backend-file``, ``memory-backend-memfd``, or +``memory-backend-shm`` objects. +A reference to a file-descriptor which can access this object will be passed via the socket as part of the protocol negotiation. Currently the shared memory object needs to match the size of the main diff --git a/qapi/qom.json b/qapi/qom.json index 38dde6d785..d40592d863 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -721,6 +721,21 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# The @share boolean option is true by default with shm. Setting it to false +# will cause a failure during allocation because it is not supported by this +# backend. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { } } + ## # @MemoryBackendEpcProperties: # @@ -985,6 +1000,8 @@ { 'name': 'memory-backend-memfd', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', + { 'name': 'memory-backend-shm', + 'if': 'CONFIG_POSIX' }, 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' }, @@ -1056,6 +1073,8 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdProperties', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', + 'if': 'CONFIG_POSIX' }, 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', diff --git a/backends/hostmem-shm.c b/backends/hostmem-shm.c new file mode 100644 index 0000000000..374edc3db8 --- /dev/null +++ b/backends/hostmem-shm.c @@ -0,0 +1,123 @@ +/* + * QEMU host POSIX shared memory object backend + * + * Copyright (C) 2024 Red Hat Inc + * + * Authors: + * Stefano Garzarella + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/hostmem.h" +#include "qapi/error.h" + +#define TYPE_MEMORY_BACKEND_SHM "memory-backend-shm" + +OBJECT_DECLARE_SIMPLE_TYPE(HostMemoryBackendShm, MEMORY_BACKEND_SHM) + +struct HostMemoryBackendShm { + HostMemoryBackend parent_obj; +}; + +static bool +shm_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) +{ + g_autoptr(GString) shm_name = g_string_new(NULL); + g_autofree char *backend_name = NULL; + uint32_t ram_flags; + int fd, oflag; + mode_t mode; + + if (!backend->size) { + error_setg(errp, "can't create shm backend with size 0"); + return false; + } + + if (!backend->share) { + error_setg(errp, "can't create shm backend with `share=off`"); + return false; + } + + /* + * Let's use `mode = 0` because we don't want other processes to open our + * memory unless we share the file descriptor with them. + */ + mode = 0; + oflag = O_RDWR | O_CREAT | O_EXCL; + backend_name = host_memory_backend_get_name(backend); + + /* + * Some operating systems allow creating anonymous POSIX shared memory + * objects (e.g. FreeBSD provides the SHM_ANON constant), but this is not + * defined by POSIX, so let's create a unique name. + * + * From Linux's shm_open(3) man-page: + * For portable use, a shared memory object should be identified + * by a name of the form /somename;" + */ + g_string_printf(shm_name, "/qemu-" FMT_pid "-shm-%s", getpid(), + backend_name); + + fd = shm_open(shm_name->str, oflag, mode); + if (fd < 0) { + error_setg_errno(errp, errno, + "failed to create POSIX shared memory"); + return false; + } + + /* + * We have the file descriptor, so we no longer need to expose the + * POSIX shared memory object. However it will remain allocated as long as + * there are file descriptors pointing to it. + */ + shm_unlink(shm_name->str); + + if (ftruncate(fd, backend->size) == -1) { + error_setg_errno(errp, errno, + "failed to resize POSIX shared memory to %" PRIu64, + backend->size); + close(fd); + return false; + } + + ram_flags = RAM_SHARED; + ram_flags |= backend->reserve ? 0 : RAM_NORESERVE; + + return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + backend_name, backend->size, + ram_flags, fd, 0, errp); +} + +static void +shm_backend_instance_init(Object *obj) +{ + HostMemoryBackendShm *m = MEMORY_BACKEND_SHM(obj); + + MEMORY_BACKEND(m)->share = true; +} + +static void +shm_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc); + + bc->alloc = shm_backend_memory_alloc; +} + +static const TypeInfo shm_backend_info = { + .name = TYPE_MEMORY_BACKEND_SHM, + .parent = TYPE_MEMORY_BACKEND, + .instance_init = shm_backend_instance_init, + .class_init = shm_backend_class_init, + .instance_size = sizeof(HostMemoryBackendShm), +}; + +static void register_types(void) +{ + type_register_static(&shm_backend_info); +} + +type_init(register_types); diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..3867b0d363 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -13,6 +13,7 @@ system_ss.add([files( if host_os != 'windows' system_ss.add(files('rng-random.c')) system_ss.add(files('hostmem-file.c')) + system_ss.add([files('hostmem-shm.c'), rt]) endif if host_os == 'linux' system_ss.add(files('hostmem-memfd.c')) diff --git a/qemu-options.hx b/qemu-options.hx index 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 May 28 10:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676462 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 518B2C25B78 for ; Tue, 28 May 2024 10:39:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuEN-0002bh-Ag; Tue, 28 May 2024 06:38: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 1sBuE8-0001zD-SL for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38:46 -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 1sBuE7-0000H4-E3 for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892722; 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=7wj7gnJyB4SMKmHEg0BihWZTUVviWXwgvTE/XsVbq+I=; b=K8P/kDMFIL/5ZKuzeU/Iw3KjesYyLJXjovDsGxKk8GEzVUQWrfW3H4A7YAoKt3X6535Oyk rAL9dVAwSMwW+JE5LfYEsn6ivhaTBYM6qYJkJz/fewPbNPqwzEWraH96xpkRQZTITb/qIo QjiVU0O+PaevhB3XzO4hzy5fpmvr9eE= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-245-jHh4zLY6PAuIVAp5n2Ppfg-1; Tue, 28 May 2024 06:38:40 -0400 X-MC-Unique: jHh4zLY6PAuIVAp5n2Ppfg-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2e95ad38ad1so5249691fa.3 for ; Tue, 28 May 2024 03:38:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892715; x=1717497515; 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=7wj7gnJyB4SMKmHEg0BihWZTUVviWXwgvTE/XsVbq+I=; b=rekInwCp0Po2u7IOc+6Owm0U/TIQM5AEGMXAGOq40xt38bvwFbON+WjDd++V+Fs3SC YLolp/20q1J2RHpnjicPEU33rxLMGGc+No9ZMnD8w87E+y6ONmclGsfthTTw43vdNwf7 DxlJ3ErEzXom6M+/FzkiM72OH/B5BVYH3VmNxMfRqiN1l8JPtDI/f7YTvaiIBZeZxiLb Vg2gqylz+1ys3LwDw2hddZnVCGPgQo7n0cYM3nDV/5Ty3QAprkDXjHzRTCvo+lfPI1B/ eYrTOgIrYbuCXvEhj0ZKumtD3aQ86EpHQGD1gA0uGwTSVdnXRfASIAw4GKkdWdpRLX4/ Rg/g== X-Gm-Message-State: AOJu0Yx3cnMmyuTprYd+q9R0m4gA0MPUcICqOPzJdRLncLdoqCOsFnC1 w56FVwM3DelbmufUZX6Al0wnqBa8PWxzbp+LPCkZm0NF+nyZUj8sOQFc5flU7Ae4hQto5RuEufu JZAjxNFdiRe7ahdgPmRawWyUcndPff16wY2NJR1HOYQVwwaZadBQWt8K4vR3R1L0w/aLQuRJt3A hR5sJa3KFQ6tyCNzW6mGCLIDZbevy8ScpaqMc+ X-Received: by 2002:a05:651c:b0a:b0:2e9:7fa4:b34e with SMTP id 38308e7fff4ca-2e97fa4b4ebmr35459071fa.16.1716892714971; Tue, 28 May 2024 03:38:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQ4Dp0Wh/isyRgLJ33Dhya7bZa8HCODyohqU9sO3Tz5mR26misn3ZNoqp/+rbmNAqW7MVgGw== X-Received: by 2002:a05:651c:b0a:b0:2e9:7fa4:b34e with SMTP id 38308e7fff4ca-2e97fa4b4ebmr35458561fa.16.1716892714462; Tue, 28 May 2024 03:38:34 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f163a8sm168842015e9.13.2024.05.28.03.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:38:31 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Hanna Reitz , Eric Blake , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , gmaglione@redhat.com, Raphael Norwitz , Laurent Vivier , Brad Smith , slp@redhat.com, stefanha@redhat.com, Igor Mammedov , Eduardo Habkost , David Hildenbrand , qemu-block@nongnu.org, Kevin Wolf , Thomas Huth , Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Paolo Bonzini , "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH v6 11/12] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Tue, 28 May 2024 12:38:30 +0200 Message-ID: <20240528103830.146286-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 `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 May 28 10:38:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13676461 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 210A5C25B78 for ; Tue, 28 May 2024 10:39:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuEM-0002OH-46; Tue, 28 May 2024 06:38:58 -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 1sBuEA-00022f-OB for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38:47 -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 1sBuE9-0000HD-7Z for qemu-devel@nongnu.org; Tue, 28 May 2024 06:38:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892724; 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=Jj9DMa1a2kLFeW0PYaRyvpcvlG+v7dmvNjlskp42Xlw=; b=BZtvUoh4s0MIUez37Hj5hRszqZwasOMoN5RPXBaGK30Xj6z1x3FDv9czwCnjlsG/Gpwk3n MYbFFK/WudPxF00uYwQGm37NRYukcx9up4aWWL6Uhm58zW8B6Cn/ToRnZMEKnNPg1DGiZ0 DHiwbsQyjLjWmPOLO97a4vFgL9fOGvI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-YbgfjFMrNwKCr8VX_rviow-1; Tue, 28 May 2024 06:38:43 -0400 X-MC-Unique: YbgfjFMrNwKCr8VX_rviow-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-35858762c31so751630f8f.0 for ; Tue, 28 May 2024 03:38:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892720; x=1717497520; 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=Jj9DMa1a2kLFeW0PYaRyvpcvlG+v7dmvNjlskp42Xlw=; b=jPMzGrXMmnbSWTUGocUwiL1qiJ/cnEkKAsIbRO3FG6tW+ZJiCGtvCYpxobKp2RpF87 6NfHm6ZaKmRXoL50yoXiHNmM2PPP1OPXmKLYWmqasxMlBUU5H1PqiMl/ULj1IJ2I/Bdq a/t2HMr+W99cxERKObyaU2GNrI+aHUEuYI9YVchvz7mp9oaIpj8Mx1VDZW//Wc0VPvG4 zN+fPXa9jVsQHxBzAtwPSao6O+XIaoAiVk4uY3wGrWiWK5GcnRvRBqpltHW9O0U6Qnjh j4x/MbhXUIfNYgZzQeVlGkw++mpWQge2d4+lPfyYZ3yBqzxVSd7cdP/VE/xU5JMNaWuk 7MtA== X-Gm-Message-State: AOJu0YxgJ7Xo++EgQKGtGxgsp8o4nawjjtRYBiGOewCioFZDDfseij1m 4KIG3aaVMugz4q6oUE2nrFEMSIKCeGsv6kRnSyp9VsOVW68Opiv0b+j0tnqzhVSG8BFv1jdtD5z y2az1EG9fPvmp8rZe3EaFv1HMNnXuuCzZ25BRZLH0q8Dlm6rD0oBAF0548JIQF7e06zcTW2VXL8 xao5HnPoAfLMMvSQ4/ajTIbqlmKa+lhasn8IpD X-Received: by 2002:a05:600c:3b1c:b0:418:2981:c70f with SMTP id 5b1f17b1804b1-421015fdc48mr125139265e9.19.1716892720589; Tue, 28 May 2024 03:38:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoa8bQibVSTUxgeoVSf0SEBhZZsLfkpa2WaY0Kwu75I2QpO8URjF4XBQ1gLGsfAcQ4Heshdg== X-Received: by 2002:a05:600c:3b1c:b0:418:2981:c70f with SMTP id 5b1f17b1804b1-421015fdc48mr125138875e9.19.1716892720282; Tue, 28 May 2024 03:38:40 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-421089cd6f7sm137281485e9.46.2024.05.28.03.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:38:38 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Hanna Reitz , Eric Blake , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Gerd Hoffmann , gmaglione@redhat.com, Raphael Norwitz , Laurent Vivier , Brad Smith , slp@redhat.com, stefanha@redhat.com, Igor Mammedov , Eduardo Habkost , David Hildenbrand , qemu-block@nongnu.org, Kevin Wolf , Thomas Huth , Coiby Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang , Paolo Bonzini , "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH v6 12/12] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Tue, 28 May 2024 12:38:36 +0200 Message-ID: <20240528103836.146338-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, 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 Signed-off-by: Stefano Garzarella Reviewed-by: Philippe Mathieu-Daudé --- 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",