From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154451; cv=none; d=zohomail.com; s=zohoarc; b=ASP9tHP5aNDZPfziy7Zz3fqrTQgr78FQ3WxfFxMkQQUICBTMiueSU7+ootQs8g0udmjhIiqzJ6L5yglXCUg1e7maxFlTBEvyg5tvFpbO8k97uHik1oPPAFT+BSdN0sJKd7L33Qc39xSSYj7+tua3yBow1oqp6oWb68hvOJ8wpDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154451; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YbzVl5wRGWe908cwmJ2aOwwM140Jnex44Vl/80qgX2Q=; b=GhWuKnNvwwq1sM21KTsvkv5IGHy/KSgtDQMGwdftrhEsbTk2x84qnxF8ako4+U5N5LjbF5nIphkO9A+l/YPnC3VRq0bd+4V+4Drzx4IWf8MV88FzG285JYFOuv9gzHpSbNPBUSigNOOMtGZF5tSFcD8McgxScbppVJlsX+iWjNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154451401692.4561510894988; Wed, 8 May 2024 00:47:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4bzs-0003d7-Jn; Wed, 08 May 2024 03:45:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzI-0003Ce-KG for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzG-0000pI-Gx for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:15 -0400 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-68-dGFZ_OiCVeJU0I9T8tw-1; Wed, 08 May 2024 03:45:11 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-572eea3758dso620455a12.0 for ; Wed, 08 May 2024 00:45:10 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id d25-20020aa7ce19000000b00572a7127cb0sm7303838edv.50.2024.05.08.00.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YbzVl5wRGWe908cwmJ2aOwwM140Jnex44Vl/80qgX2Q=; b=dTqlNn9R8VQwPQDSIk9emQ+t3mEBdVFUDKvq3aFH+VtPh+ZZY7QE10vNlQqozGyWppSJv3 JddX4RD+1OVCW2Pt0eSIKjRsYPGPPKv4ZbUgsY9hjy/NsrnyEUO6gpgfFI+2z1P/5OzuNW emIyiFwiD+tm7nQnHBE7T9CMKoO7Lp4= X-MC-Unique: 68-dGFZ_OiCVeJU0I9T8tw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154309; x=1715759109; 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=YbzVl5wRGWe908cwmJ2aOwwM140Jnex44Vl/80qgX2Q=; b=Hxdu2IGey5912Ot0kDas09DpMG1cCeJ7FuSBdFcLRco6PTwa4dUHY1qFsWq5oQeG5Q WiPBXPr4guv42ZnEKhURgXPOyJbbudWHJiS3teEVLfSjrxqQK3j7TaeBaKX18JtsG7CR pN+bCOpGQQfAedaXzeXNtxlzXZnGfiO8bbU5lnZHlC4w/uF+Zr16i216cEHMMbvkQ1s1 BZvbbm7wBVO7BmLy0wUWToEJp5GMQrC0KEin019d+/+FNvTEaWpYkGHXI0RkVmYgpTxt +H8SfD8acIzCEWjWTqSDojR4pKXHwDuyOQFfrwqUIsrltjlRg5XYEMpAWFd1mjo/Xg4P 9y6w== X-Gm-Message-State: AOJu0YybYTyPscHoihpnSeQl+zqdqmLDz3/AIBSvmkZzIm5VZMnLtSI6 nvUKs/SpR+NX1cAvShuVAHhmOOVnMBs8J7dcqLGcE2trICISN1T6h6Omn0z58r8ojlpsJ8xt0qp qS1UHL/+3PoAdouGhaMm4zrszdR2/ypHoUTMhXnDbqJdwvBk4ABpoNGTVL9eub1mLrDdPv87Kw4 +foLh/bNn6uh1Z9s6/AwYOUDINS6DcYFPMDL5D X-Received: by 2002:a05:6402:1d97:b0:572:b0a8:65fd with SMTP id 4fb4d7f45d1cf-57311023570mr3919815a12.6.1715154309470; Wed, 08 May 2024 00:45:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF38JbOblCH1yEilJgauIqNafLDlu99f3VffjFz2RRltfCOib6epN92pAMjSCaMK4qMlUXRyg== X-Received: by 2002:a05:6402:1d97:b0:572:b0a8:65fd with SMTP id 4fb4d7f45d1cf-57311023570mr3919778a12.6.1715154308974; Wed, 08 May 2024 00:45:08 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 01/12] libvhost-user: set msg.msg_control to NULL when it is empty Date: Wed, 8 May 2024 09:44:45 +0200 Message-ID: <20240508074457.12367-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154452237100001 On some OS (e.g. macOS) sendmsg() returns -1 (errno EINVAL) if the `struct msghdr` has the field `msg_controllen` set to 0, but `msg_control` is not NULL. Reviewed-by: Eric Blake Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Tested-by: Philippe Mathieu-Daud=C3=A9 --- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index a879149fef..22bea0c775 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -632,6 +632,7 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg = *vmsg) memcpy(CMSG_DATA(cmsg), vmsg->fds, fdsize); } else { msg.msg_controllen =3D 0; + msg.msg_control =3D NULL; } =20 do { --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154518; cv=none; d=zohomail.com; s=zohoarc; b=laF/535edOmEX9k4Ao0PHUbGuY9+J76r2HkcIWk+SPX2SBzyH53E+dLsIDR5trA0kfDRS9mmurpHUmEkGqVghv0PipMJX5/zzacNT/80JdvXemnbLtDpm0oGyiXg5Wne0u58lfIFR7KXwfczNshAZuvwNhqvnDl2AEy59JtSqzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154518; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vs3QOPT0b+rkefawz4PPNw8XtECEjgm+FjXJsIBmtfo=; b=XxiGa9hgG9dne6PEgM9nUsX8lOz4/gF77u7XrOuRAnC5uSxwDL5G7uJQwQR9dt298kwgK8AgMebTRe5FQppWmz0RiJJofhMjjsRTXnd4QIvyGu1E0L4QPGLRZ3A4i4Nh0/Gtz39g1jXDyAySmDo26uZfcSn7PAZKaSQzIhNuNkU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154518630905.9153453968975; Wed, 8 May 2024 00:48:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4bzs-0003az-8C; Wed, 08 May 2024 03:45:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzS-0003SE-Bn for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzO-0000q6-H0 for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:25 -0400 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-LizKm5plOdKsxa1X90lQtg-1; Wed, 08 May 2024 03:45:15 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-572b3091d68so2349579a12.2 for ; Wed, 08 May 2024 00:45:15 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id bt9-20020a0564020a4900b005729c4c2501sm7303585edb.24.2024.05.08.00.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154317; 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=Vs3QOPT0b+rkefawz4PPNw8XtECEjgm+FjXJsIBmtfo=; b=i5fMwZrFIGxXV/Uqcfj3hDCQz7qOiF8nWPf8NBRGd5uiEEBbJRnvGI4ZNIkS+yuXuApmtR 2anxvrRIveFhxRyOfrBKbz86pTMDoq8h/FZ8ul3VF5I3RFHYCbhzpEiRgMzLJ2wF/1KbIQ 7/1COt/PS23FKaD7kQ5VWA+DYoAOhYE= X-MC-Unique: LizKm5plOdKsxa1X90lQtg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154314; x=1715759114; 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=Vs3QOPT0b+rkefawz4PPNw8XtECEjgm+FjXJsIBmtfo=; b=d/hwByzQa/L3J5cG2xyondP8wIrYm9SZBIfet1OKqDPF7z+cn75LZ0OLqk6QgQqw+t gzY0Z9koa0+r25/Azrcgpmq2JtBTvl9RAOqSH3BlvbehsXjwMWdoJtRQ2Uj81fYa5Sn2 s3hQLrWS76JuHxcc80qFAdcJl9J+FPvKJE9khOFeLpEnrJd8OPmXZ+CKkFzvFvTBlGRl Cn6ltG5vSMUAFFuw1/Ugd2EO14fx0YRMfXJ7AfFMo7fQ7wOBz9SomwN7VmvHrBKpn3VA 1qayeLnBGFWvG2mg2TWQrpdhZmxlwD70fIdRGI0NElsW3uFngWmTBGrx7QnG+hpPxdvs 0s2w== X-Gm-Message-State: AOJu0YwSF5IY3kKX2GNOQv3uPw+rSW6X3Z0AqnUDW5D9dkWti9Ny/zsK GqV/ie5v3HvUgoQNcFDDh6/IqMAtPJz87szKIT/KDYo3dki8DsQ8PSq7Mbixo3HUs8JGE9lPhc2 0FIbQiiOzpQV3BD3+smG28/tNTv6YcmeIHAQs30rg0CkoOhY5Ff7FJCxnV8413JKMRZpSm6P9UC wis7GMa+ZcLTc3Spqivm3I3xD6W3XvDPK62+e1 X-Received: by 2002:a50:9317:0:b0:572:8aab:441c with SMTP id 4fb4d7f45d1cf-5731da5b65amr1253646a12.26.1715154314054; Wed, 08 May 2024 00:45:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHrsrWeJgIT3Ek9Coozq8NQkbRqXhAGzux1zrYc55O/lshafDqRssXbCHqeprmjqg24zdK3A== X-Received: by 2002:a50:9317:0:b0:572:8aab:441c with SMTP id 4fb4d7f45d1cf-5731da5b65amr1253613a12.26.1715154313727; Wed, 08 May 2024 00:45:13 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 02/12] libvhost-user: fail vu_message_write() if sendmsg() is failing Date: Wed, 8 May 2024 09:44:46 +0200 Message-ID: <20240508074457.12367-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154520455100003 Content-Type: text/plain; charset="utf-8" In vu_message_write() we use sendmsg() to send the message header, then a write() to send the payload. If sendmsg() fails we should avoid sending the payload, since we were unable to send the header. Discovered before fixing the issue with the previous patch, where sendmsg() failed on macOS due to wrong parameters, but the frontend still sent the payload which the backend incorrectly interpreted as a wrong header. Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- subprojects/libvhost-user/libvhost-user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 22bea0c775..a11afd1960 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -639,6 +639,11 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg= *vmsg) rc =3D sendmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); =20 + if (rc <=3D 0) { + vu_panic(dev, "Error while writing: %s", strerror(errno)); + return false; + } + if (vmsg->size) { do { if (vmsg->data) { --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154371; cv=none; d=zohomail.com; s=zohoarc; b=YfJw3fkht8Q/2fFVNz4/52XAVDwFY4VQpKbeg891x2Qh6oat5TC6jKt3ndJ0rZqOweqVrFdeighMvgtQop8CAekbE1pr5EkGjMZWEE7rMJADqzM1bbJ5Z5UNaE52/+jktPQNlLNn4NfwfllPWvjjjxfYj8lJ9xzLijHqE5KV990= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154371; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JySjkPtU/07Xae9r5wqBkaPv+VNyRJfG/fS50MPt6jw=; b=NYy6Plczg/rgd20Wl6kv+SPidHcmw7Bmnj0kB9k4Rd9jTfn3PQSrmVVXDHK9OeNdWCIun9OGLO630D8pPOFimmlYTSpWxvwXOu4ijRucTuYO4ZTOQQIyy8mtn2emoWfc5uzZ/G1TVqe1kWwHlMZDu6BeUWXPvQNsxaO2k4fC3Fw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154371939767.8053623832435; Wed, 8 May 2024 00:46:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c02-0004A8-1l; Wed, 08 May 2024 03:46:02 -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 1s4bzW-0003Uo-M8 for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:31 -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 1s4bzR-0000su-VM for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:29 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-tQcDG_GRNbGirr7IPjOuoQ-1; Wed, 08 May 2024 03:45:20 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a51fdbd06c8so281454266b.3 for ; Wed, 08 May 2024 00:45:19 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id cx10-20020a170906c80a00b00a59fac165dfsm883206ejb.204.2024.05.08.00.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154321; 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=JySjkPtU/07Xae9r5wqBkaPv+VNyRJfG/fS50MPt6jw=; b=Y2HAW0I18SNk4cqWGMPw022ANv6lPHFwWp0feBO3FnBB9odnAFbUeyv/4/wgCTdnRc6iDc +165ZSibmyfNLpmftc/SZ2m8zZoJYOXuICWqv9eNMIV8QmtbcOpleo0VmHYh0X0zLb0Ueu +Caw7jgv+sCP7gOQ6xk3/pxXW7Gnqc0= X-MC-Unique: tQcDG_GRNbGirr7IPjOuoQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154318; x=1715759118; 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=JySjkPtU/07Xae9r5wqBkaPv+VNyRJfG/fS50MPt6jw=; b=aRHpcla0T9lVlQfhSmdVdYz//iQCnKSn2FLaLjfkFW6/zMUrjGB2AJe0TBsmY6lJLu kFKp0lMTUcfyq/SuNfifVyn8bnikBd2fC/7KsKOuzK8CSMeUcBYk6TyY+6xmheG5ZO2s i9TtciGBt/1NpAMgIpNEEHB5BAvEK7q+KcrCN951YSQ0C1D22xBe7xe52C31iAaBJQJz SqCmfkjckv9q2AoFVB8vhCcFYgy9/fzwbHN16L3nyIobdogqWMgSgDr/fb6do+lMIp1b stGjixtpANwMi/xOWFEh8ufOz4YgjM2zLkCxL80UNh8AIpmm1RbFfbAp3qSNQfeiuHwx NiHQ== X-Gm-Message-State: AOJu0YwA+fIHYK1bsctaEocVT34n7LL4FU255uYzQruGrOw8Q0JXGrGA C8klAlnfSwEM+0heoKiTyWEnYPH4sxDZaIKw5v5AQft8aBCyR4vse8eHQkHlgBVZP4CAmdmIKy7 rOWv5XZcH6sJKAfNm4a5EceqDg3aYuesl2Wrb9TTQxiR+cyBhAAC/oc0E6IU4evHsGWkjPRTogr jwtxZ08roQ3jPSWk5biRWY1W+mgx38T/eeANYP X-Received: by 2002:a17:906:e244:b0:a59:8fae:f5c8 with SMTP id a640c23a62f3a-a59fb81a1b5mr98053866b.7.1715154318447; Wed, 08 May 2024 00:45:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+NQidDII/N5W+g/qnrYrrhcSyBuWj66wwaqQXp3y4MDv5PXN3smV31TDaLJBMtnaSq0wr2A== X-Received: by 2002:a17:906:e244:b0:a59:8fae:f5c8 with SMTP id a640c23a62f3a-a59fb81a1b5mr98049566b.7.1715154317993; Wed, 08 May 2024 00:45:17 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 03/12] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Date: Wed, 8 May 2024 09:44:47 +0200 Message-ID: <20240508074457.12367-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154373929100003 Content-Type: text/plain; charset="utf-8" libvhost-user will panic when receiving VHOST_USER_GET_INFLIGHT_FD message if MFD_ALLOW_SEALING is not defined, since it's not able to create a memfd. VHOST_USER_GET_INFLIGHT_FD is used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is negotiated. So, let's mask that feature if the backend is not able to properly handle these messages. Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- subprojects/libvhost-user/libvhost-user.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index a11afd1960..1c361ffd51 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1674,6 +1674,16 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserM= sg *vmsg) features |=3D dev->iface->get_protocol_features(dev); } =20 + /* + * If MFD_ALLOW_SEALING is not defined, we are not able to handle + * VHOST_USER_GET_INFLIGHT_FD messages, since we can't create a memfd. + * Those messages are used only if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD + * is negotiated. A device implementation can enable it, so let's mask + * it to avoid a runtime panic. + */ +#ifndef MFD_ALLOW_SEALING + features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD); +#endif vmsg_set_reply_u64(vmsg, features); return true; } --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154465; cv=none; d=zohomail.com; s=zohoarc; b=cy/ZbFxk79zMGELdBxh622ZAwb0nwEe6mTv332zvNpTvoGauGEKQ7dcqcCQo9lmbLcgampqx2+ZuLxuj96FEfTnHEt6nnE0OMQbYJuLn2P9ubyATGa4ub3IoDxcELJ00Bz+x0eICIEiWpgTcFBE6l5Np7bB/RrpuUumVftAlXnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154465; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lre/0draOF6HH9l6k6o2fQVvpnBFZwZ7jVfKTeMsOsg=; b=gMAN9LXIZADRfkiMD5aECSirsl8HPcAEtMkQ3E8+gA6DSkrHE1TEixSY/z9uyMnsehMP9sQQH4jHiksrIDQ+Q/ztcCL9VGuFt63PciB8nKoI448w6dXwGflWMiQGMYCmJeVi8tEuiZrp5WDky1vr7yT0hkGVw9SOxtH+NpXagy0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154465000773.365010525546; Wed, 8 May 2024 00:47:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4bzy-0003pB-Br; Wed, 08 May 2024 03:45: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 1s4bzW-0003Un-KH for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:31 -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 1s4bzU-0000va-W7 for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:30 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-WX2JHosFOme7Rev5IDdMog-1; Wed, 08 May 2024 03:45:25 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a592c35ac06so55274266b.0 for ; Wed, 08 May 2024 00:45:24 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id wn3-20020a170907068300b00a59a5af8001sm5326505ejb.208.2024.05.08.00.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154326; 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=lre/0draOF6HH9l6k6o2fQVvpnBFZwZ7jVfKTeMsOsg=; b=a78b+pbqp4vDmuExBWVZ3r09XuoNbBFeP6XZ2adFQls8mOkXIdqiTbkkPb8G/Gwt2WAlPC rLwKwEX2ojc+onmW1YpMuqKQODAD0Du5A7jxjLOEL9IXXDMl7Lh2L1fEaClBBPLw8zPQQv 3aAv/0LUvuqIHvTUdV6ZqDce/a6b8Io= X-MC-Unique: WX2JHosFOme7Rev5IDdMog-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154323; x=1715759123; 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=lre/0draOF6HH9l6k6o2fQVvpnBFZwZ7jVfKTeMsOsg=; b=e271RtZTmf5cxo+TuB6nueKJttORrQ/qQqIvFI7YUjsmvQwRHDWWoupL+gIrxeVDJS Vgy2kfTUGkUP4Gzo6ZLuDTX2eNvpDMfFqo8YPQ8N5z3jVPOG0p6Q0vwJnTVLdULRohSO pt8P2RwMzpi7pNoV8B69fmZTJ9kciGbxT2dEOO+UlaojDN9ioLrf1qo1IEMWm35i6LGN L2+X7ra4VkjYibe/fep8tz98fw+fJzdcw/zT0USx8pyowsRTBorzkgbB1JwnyjIvB7u6 C66aDaxMepfX+lJYntdfo2ZhC3u3VeOTUOnd19vcR2pa+dRU/KekNoAohTS/Ht8TX2C6 +Tnw== X-Gm-Message-State: AOJu0YwWRO+hz3dXoVYoPl91SLnWEsGS6J4BqoBLpF//XaRqtm8Nd3wj munnZXXI2YEgUxRf24wMTFz2WULEOdVnEuXlLLsn3cqgOTBPs8XJ5RGDtP3ExOlIWlm52Z2PoU7 RTfG5Z3oknkyKrOTaDwTzMKh9PupUugKYE0DSmV1B1mXdNHFRGldJ8eu7lfh2SW5ottqHrhIVvN EcpyEt9VnJDJXAAlzhIcOa0ywu96+lpv+EANKE X-Received: by 2002:a17:906:558c:b0:a59:9f47:2045 with SMTP id a640c23a62f3a-a59e4e891famr370304166b.37.1715154323598; Wed, 08 May 2024 00:45:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5Y5yGG//3dXz+0naCgWcWmxEiOV6bEy1aMzP9DyQjvveYtboAeGq9PtkKFgvqPHHKRbh3gQ== X-Received: by 2002:a17:906:558c:b0:a59:9f47:2045 with SMTP id a640c23a62f3a-a59e4e891famr370298866b.37.1715154322426; Wed, 08 May 2024 00:45:22 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 04/12] vhost-user-server: do not set memory fd non-blocking Date: Wed, 8 May 2024 09:44:48 +0200 Message-ID: <20240508074457.12367-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154466297100001 Content-Type: text/plain; charset="utf-8" In vhost-user-server we set all fd received from the other peer in non-blocking mode. For some of them (e.g. memfd, shm_open, etc.) it's not really needed, because we don't use these fd with blocking operations, but only to map memory. In addition, in some systems this operation can fail (e.g. in macOS setting an fd returned by shm_open() non-blocking fails with errno =3D ENOTTY). So, let's avoid setting fd non-blocking for those messages that we know carry memory fd (e.g. VHOST_USER_ADD_MEM_REG, VHOST_USER_SET_MEM_TABLE). Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- v3: - avoiding setting fd non-blocking for messages where we have memory fd (Eric) --- util/vhost-user-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 3bfb1ad3ec..b19229074a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -65,6 +65,18 @@ static void vmsg_close_fds(VhostUserMsg *vmsg) static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; + + /* + * These messages carry fd used to map memory, not to send/receive mes= sages, + * so this operation is useless. In addition, in some systems this + * operation can fail (e.g. in macOS setting an fd returned by shm_ope= n() + * non-blocking fails with errno =3D ENOTTY) + */ + if (vmsg->request =3D=3D VHOST_USER_ADD_MEM_REG || + vmsg->request =3D=3D VHOST_USER_SET_MEM_TABLE) { + return; + } + for (i =3D 0; i < vmsg->fd_num; i++) { qemu_socket_set_nonblock(vmsg->fds[i]); } --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154421; cv=none; d=zohomail.com; s=zohoarc; b=Xu6HNgulgSQPpc8ZrQSA2rDO4AIWcN3BKsFBVJnx7S8dz4nctgTyqGc44cKRLAS+XdyTK3zkAyejSzg8tyNrNiyO2LE2pnMvB9VPyfJhXLuZrRyH+I4csmFBICE0MNwJ0lgEI431sC8dpPBMcWQD6CsmJ0Q6bfm1MYdW9E+XEKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154421; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CT6o3ZwtECB2PcxE9pmEPhRk7rw6h5Hp8cLiKJNeUWg=; b=XPxbpt+RSmuv7JCbuqmQrUOXvqIHVghWWmswQvjj0sh2jOJ/Kl+HIN6sG/+DukHmLkGoncqWe8Ek6KmEygLaJu0Jowk3DvKljH+/rV/6ooHtsl82GzPLqhRkks1pZpx4a+AaNjpqniNYozAShfUrsm7zrlDggIsAF/cXKw8wg68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154421561641.2340671767507; Wed, 8 May 2024 00:47:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4bzy-0003sC-MV; Wed, 08 May 2024 03:45: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 1s4bzg-0003Zb-2l for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bza-0000xo-Sg for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:39 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-d1R5-qgyOOiGlKqXgmWGuQ-1; Wed, 08 May 2024 03:45:29 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a524b774e39so52552566b.1 for ; Wed, 08 May 2024 00:45:29 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id bf14-20020a170907098e00b00a59c3e28917sm4030519ejc.70.2024.05.08.00.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CT6o3ZwtECB2PcxE9pmEPhRk7rw6h5Hp8cLiKJNeUWg=; b=SX+dUMI097yLreglYeCHFWM6EJ0FmdpmTeyPP0rWuK41mFeC0wWorBxI4B7ifRDd0/rU4k 8BqacXi6YmvDnOwRuH3DE0AupUlU7teuEOZjGeNZGbfHW91VQIVzGJfLLBV0foM6bVyAVL YDRcs2hck2/sNYSmOONJcAcvF8ZJkQY= X-MC-Unique: d1R5-qgyOOiGlKqXgmWGuQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154328; x=1715759128; 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=CT6o3ZwtECB2PcxE9pmEPhRk7rw6h5Hp8cLiKJNeUWg=; b=WlWxjuEZB5CUQRWp91v70qghhlmJing4xCDbJpwz2bHXHkKaKVbeFd65aMZJlETHbW ZGn76QhuCk3kbC+ktpc1+xTXANpJOmOIxDLEbAyr2Cq8/XndAxHCQn2VU1qsA5ovVQ7Z 5KoxfRUU/EjX63wh082T7PfG7IIaqOukkCuWxjAmSMYRi1VmVcCGm9IDmh7czqyQg3ak dswdgA0hlRlGk3T00cL5bmUTefE8hPNC2d2LWbTftDu7xn9RRw3+13YueI0c0bs4QLde KrKch7z9UGBAzxUOiUv8tKg+/ruFJKL6oX8uQuz04583yk5UCtTNBfCI/LJwQIAU027N RUkA== X-Gm-Message-State: AOJu0YwhzRdfw+Exn8jtnl1wCK1Aqpq8MaAwstuxFlRAvmZjYrJjehPm Wmf7pMqAnkER2l1xYCSX3DdcBfmFW3tRZOQcXCRal0RpckmBCNZiEO6RFf1VgLRa0miTSLf30a2 2jhGYkTZ6vWjCNKtBGnlzlIL8hF3QqZtApVE990C+UrU+kSuM4pi+6Aqr29j5BeAvojHT2gV72f FNJG9rBx2tSYxRV1YKkNCR66gGvtW2U3JLEiqG X-Received: by 2002:a17:906:6806:b0:a59:deaf:e81d with SMTP id a640c23a62f3a-a59faa6278bmr159690166b.33.1715154327815; Wed, 08 May 2024 00:45:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlIU7ymKnMk3t2pDhs92VxcgWtrt9douFzguz3qfdrYMl7PPMI0+nYdbd8zyHAoOf1ZIOb6g== X-Received: by 2002:a17:906:6806:b0:a59:deaf:e81d with SMTP id a640c23a62f3a-a59faa6278bmr159686566b.33.1715154327487; Wed, 08 May 2024 00:45:27 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 05/12] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Wed, 8 May 2024 09:44:49 +0200 Message-ID: <20240508074457.12367-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154422145100002 On macOS passing `-s /tmp/vhost.socket` parameter to the vhost-user-blk application, the bind was done on `/tmp/vhost.socke` pathname, missing the last character. This sounds like one of the portability problems described in the unix(7) manpage: Pathname sockets When binding a socket to a pathname, a few rules should be observed for maximum portability and ease of coding: =E2=80=A2 The pathname in sun_path should be null-terminated. =E2=80=A2 The length of the pathname, including the terminating null byte, should not exceed the size of sun_path. =E2=80=A2 The addrlen argument that describes the enclosing sockaddr_un structure should have a value of at least: offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)+1 or, more simply, addrlen can be specified as sizeof(struct sockaddr_un). So let's follow the last advice and simplify the code as well. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Tested-by: Philippe Mathieu-Daud=C3=A9 --- contrib/vhost-user-blk/vhost-user-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index 89e5f11a64..a8ab9269a2 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -469,7 +469,6 @@ static int unix_sock_new(char *unix_fn) { int sock; struct sockaddr_un un; - size_t len; =20 assert(unix_fn); =20 @@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn) =20 un.sun_family =3D AF_UNIX; (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); - len =3D sizeof(un.sun_family) + strlen(un.sun_path); =20 (void)unlink(unix_fn); - if (bind(sock, (struct sockaddr *)&un, len) < 0) { + if (bind(sock, (struct sockaddr *)&un, sizeof(un)) < 0) { perror("bind"); goto fail; } --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154508; cv=none; d=zohomail.com; s=zohoarc; b=MjLUSuxVp4TSki7wEypgXwKh53nGV7KqMC/ngcM/pOjs50PxSm0FxklGQVZ6X1MIRBZyBKPoFT0jzSJCVOOQSjL8ODD+8sH6rtUnWLI1ul90VpcMKs15AGdKDTcCRtDSboSHorXXllGg6I6L86so2OaAlh9s0YlAwvspmDOC5g4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154508; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f9/pSe/RtLHFpk03BlIEeBTC9MFrpAeOA+hs4I40IHM=; b=UUUio4aOF/TlkHMavNp2HS5m6+bzcaQOyxcjVzlOXB0s05+P9JTdktKlKFwiabTW+lwTqDQilDurDx8IMacg3c1ijKwGHudGZhmp4N3LUvP5LoNudA5eqmHFQRsNpH4Q2/NTmadsQA8iY6ZSvvLVCAQYDXQaxTWZca2qikEPt/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154508848301.7434428291119; Wed, 8 May 2024 00:48:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c01-000493-Pa; Wed, 08 May 2024 03:46:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzi-0003b0-OO for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzh-0000zF-46 for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:42 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-AZNxO1iZOfyrpZy4hjUvTg-1; Wed, 08 May 2024 03:45:39 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a59d0fb7731so220493366b.0 for ; Wed, 08 May 2024 00:45:38 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id b18-20020a170906039200b00a59d9e71778sm2890528eja.111.2024.05.08.00.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f9/pSe/RtLHFpk03BlIEeBTC9MFrpAeOA+hs4I40IHM=; b=KLOof4oF5hmFyIv311jVL4LyOwxYwHS7epfJUqX9f5B5BZ+yknW5+HtIZ6/jHmznqsJ3c4 mwwmWrAdEKcyHttJBto5mA01V6nrisDhzsP663R+zKrhWPjiz0SkWD9Ob7HGndu5VADLy6 cmgLJ1h2FNNRu9aLnC/sbqSDtC3+2lQ= X-MC-Unique: AZNxO1iZOfyrpZy4hjUvTg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154333; x=1715759133; 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=f9/pSe/RtLHFpk03BlIEeBTC9MFrpAeOA+hs4I40IHM=; b=ZE8MC7ugR7vTkgNbX2zATpxNjiWs9GLaDZXaWu2zvA1PaFTDYwg0E9kRnMNJV962UE LXU1rVbVKF4+S8a7vitJwJWy4wXh0zpPFcHIvrWBtagQ0gjXZKEIfDg/e19o/mWMv7aK MWaeT2ete1Uz1KYQqlPj+iJ2q6ApigXG89dbDfWpTooLs/z0iq4C3Vi7GP8+brjwtb8y u9+2kgeS1kUM6YSHiv3HUhbE/Y2Jm6Xlyokkny4sEp9WqvFlPV3JmNW3qyYZ72yXyFJ3 CM2JwS2jQHDKoE3RhowBmOOf7rc3TKuW1AR2ohSJ9vZVtqd/grsklduP7VbBoQhEUafO vqkg== X-Gm-Message-State: AOJu0Yzsf/21nm3ly1B/MoTnuFJXL+72u+UnVQfE9lfIYr2uma+Exjpb 6J6LSJHTBRLnptTHJ1BpqamsJqofcZnsk93cVlNhSibWrd1ci9gxiMtwSkdS0mVa473bktCf/9r KGUwuMJ0+ga/LZf+kaSRkEFS+MLIedMYP6AgrQb7ntkMv8LBnuSH+wUJMrgyKGXjkhTDneULLRh x7hv8zoj+biPc0O9zyqImV5kliRFE78KZldhEV X-Received: by 2002:a17:906:e297:b0:a59:a7b7:2b9e with SMTP id a640c23a62f3a-a59fb94b8d7mr94667266b.8.1715154332785; Wed, 08 May 2024 00:45:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlQS93Md9pICqCOE6XzARyKyU8jaFnTv8bnyOTZCC2t6mEPXCkjojl4lLJr5zCzVB9vRmEXA== X-Received: by 2002:a17:906:e297:b0:a59:a7b7:2b9e with SMTP id a640c23a62f3a-a59fb94b8d7mr94661666b.8.1715154331935; Wed, 08 May 2024 00:45:31 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 06/12] contrib/vhost-user-*: use QEMU bswap helper functions Date: Wed, 8 May 2024 09:44:50 +0200 Message-ID: <20240508074457.12367-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-type: text/plain Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154510480100001 Let's replace the calls to le*toh() and htole*() with qemu/bswap.h helpers to make the code more portable. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- contrib/vhost-user-blk/vhost-user-blk.c | 9 +++++---- contrib/vhost-user-input/main.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index a8ab9269a2..9492146855 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -16,6 +16,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" =20 @@ -194,8 +195,8 @@ vub_discard_write_zeroes(VubReq *req, struct iovec *iov= , uint32_t iovcnt, #if defined(__linux__) && defined(BLKDISCARD) && defined(BLKZEROOUT) VubDev *vdev_blk =3D req->vdev_blk; desc =3D buf; - uint64_t range[2] =3D { le64toh(desc->sector) << 9, - le32toh(desc->num_sectors) << 9 }; + uint64_t range[2] =3D { le64_to_cpu(desc->sector) << 9, + le32_to_cpu(desc->num_sectors) << 9 }; if (type =3D=3D VIRTIO_BLK_T_DISCARD) { if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) =3D=3D 0) { g_free(buf); @@ -267,13 +268,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk, req->in =3D (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_bas= e; in_num--; =20 - type =3D le32toh(req->out->type); + type =3D le32_to_cpu(req->out->type); switch (type & ~VIRTIO_BLK_T_BARRIER) { case VIRTIO_BLK_T_IN: case VIRTIO_BLK_T_OUT: { ssize_t ret =3D 0; bool is_write =3D type & VIRTIO_BLK_T_OUT; - req->sector_num =3D le64toh(req->out->sector); + req->sector_num =3D le64_to_cpu(req->out->sector); if (is_write) { ret =3D vub_writev(req, &elem->out_sg[1], out_num); } else { diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/mai= n.c index 081230da54..f3362d41ac 100644 --- a/contrib/vhost-user-input/main.c +++ b/contrib/vhost-user-input/main.c @@ -51,8 +51,8 @@ static void vi_input_send(VuInput *vi, struct virtio_inpu= t_event *event) vi->queue[vi->qindex++].event =3D *event; =20 /* ... until we see a report sync ... */ - if (event->type !=3D htole16(EV_SYN) || - event->code !=3D htole16(SYN_REPORT)) { + if (event->type !=3D cpu_to_le16(EV_SYN) || + event->code !=3D cpu_to_le16(SYN_REPORT)) { return; } =20 @@ -103,9 +103,9 @@ vi_evdev_watch(VuDev *dev, int condition, void *data) =20 g_debug("input %d %d %d", evdev.type, evdev.code, evdev.value); =20 - virtio.type =3D htole16(evdev.type); - virtio.code =3D htole16(evdev.code); - virtio.value =3D htole32(evdev.value); + virtio.type =3D cpu_to_le16(evdev.type); + virtio.code =3D cpu_to_le16(evdev.code); + virtio.value =3D cpu_to_le32(evdev.value); vi_input_send(vi, &virtio); } } @@ -124,9 +124,9 @@ static void vi_handle_status(VuInput *vi, virtio_input_= event *event) =20 evdev.input_event_sec =3D tval.tv_sec; evdev.input_event_usec =3D tval.tv_usec; - evdev.type =3D le16toh(event->type); - evdev.code =3D le16toh(event->code); - evdev.value =3D le32toh(event->value); + evdev.type =3D le16_to_cpu(event->type); + evdev.code =3D le16_to_cpu(event->code); + evdev.value =3D le32_to_cpu(event->value); =20 rc =3D write(vi->evdevfd, &evdev, sizeof(evdev)); if (rc =3D=3D -1) { --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154431; cv=none; d=zohomail.com; s=zohoarc; b=iHewS1+fZ2XZm+CxjmLZ2IJgJG2nYhCYlPHSsG1GvK9XJZ3UtdQ1nobnw+SgEUOvZF3668HOLgIpq9nbLJkyJ425WPWTJIbYysweOhpFdbEJT7kM0b6qgVGEppMAfOhxBartsoCLoMlbGO2iyCQodlN/x+OpTFAJNivRxZoIRF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154431; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UTRHyTyXKiahujrFXbpPQFmYDHPg3542Nh2vIJCWy60=; b=XcV8dCmHEmM5GxNARX1ozXQYMXN8XBcsthGDWPISydKx0BO7BMmht7ufJtX6Hw2jtICQHkNcywgx/yqP6gXCmoCKOHhM0XBA/Q0BguAueeU3HSQYwtYGXXzc1q4BafC0a7BxO21Nfsa18xV06ciA3x8GUjn1vpxmDmJ6JLQA8Io= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17151544310931011.2811587498287; Wed, 8 May 2024 00:47:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4bzz-0003w1-Fv; Wed, 08 May 2024 03:45: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 1s4bzq-0003br-BS for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzl-0000zs-Pm for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:47 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-GfflmaO8N5uDBU-nkb6cQw-1; Wed, 08 May 2024 03:45:43 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a59ad2436f8so314275866b.2 for ; Wed, 08 May 2024 00:45:43 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id kf6-20020a17090776c600b00a599a97a66fsm6032444ejc.55.2024.05.08.00.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154345; 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=UTRHyTyXKiahujrFXbpPQFmYDHPg3542Nh2vIJCWy60=; b=NVxtrKhoQxISIxjLMNCMB8JJRiwSDIU6cDdyMvRi21TtyKZs5kEH3bcUCsWoeDaRxtAFXW SDjsd56AH9Az9uUH9zik4Wc6rQaEftfhlBcokAO1V+Q7tTrasebjN/Gfo30F4Yiy2pd5DJ ntvEGsKKdcOP/G1Rgz/tFwHU8RoQvrY= X-MC-Unique: GfflmaO8N5uDBU-nkb6cQw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154338; x=1715759138; 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=UTRHyTyXKiahujrFXbpPQFmYDHPg3542Nh2vIJCWy60=; b=Vwhv9qlh1Ckc/lGE/0Bw+ZydpC5bgvZ4awvPVg01z9W19R99XQGKLDnAVvNV9xc3J9 2U9F9/KPU2qSRsPc7GDUJTqF/5guDBdRlnvp65tvsFa8Nq0rrzJvtWTMy8QYxZK3zQzh 40gfyKr1aoWWxTw1yQlZVr7F3cx6Ugr1ad+H6qB5o8rupMfawwnz5yAeQUnTfODCLluh Nx6PV19Bv6GmfWgsJFiabzGNMRWIRzKydHJZZmaHmpq+qxr22OUoYxMzNmnmjeXU2jve KWeIaYGSrsFxHAO/HEm7qQrTBhlDeu3V5MUsXBL9wBzkbRwm0LhAX/oYV8x5zJcncoKN XP7Q== X-Gm-Message-State: AOJu0YyfCb56FKXZjsYorftUG27CVkWnN0NmXM9kNAZewEg7zuMtBjcN Kvtrj2vKyRIfNWjaDo/gaykVYJ6Fdq4E9fcBoy40XhVRA5EiJIBsmdTzpBQsfvq4JqIgkUJQX6h bJ3p6KpJQ2faXLwvqmHUpvvngvbl35Mg8sZEP3AKlCKknPuXRtkRq1KoTnRafOvZ/c5cSM+qePJ nEX+PPRO5vgMbhS+mK21KEO8SxXjaq+Z6sn3F5 X-Received: by 2002:a17:906:f919:b0:a51:8d60:215a with SMTP id a640c23a62f3a-a59fb95a4e8mr100174866b.27.1715154337886; Wed, 08 May 2024 00:45:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCJloW+tlX1rdN71yJ2zslkMrWJlodATZZ5ms7JnKp+2p1sbtuQcShHuTFTLI9XSpoHaSE5Q== X-Received: by 2002:a17:906:f919:b0:a51:8d60:215a with SMTP id a640c23a62f3a-a59fb95a4e8mr100171466b.27.1715154337526; Wed, 08 May 2024 00:45:37 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 07/12] vhost-user: enable frontends on any POSIX system Date: Wed, 8 May 2024 09:44:51 +0200 Message-ID: <20240508074457.12367-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154432164100005 Content-Type: text/plain; charset="utf-8" The vhost-user protocol is not really Linux-specific so let's enable vhost-user frontends for any POSIX system. In vhost_net.c we use VHOST_FILE_UNBIND which is defined in a Linux specific header, let's define it for other systems as well. Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- 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 43da492372..955921dcb8 100644 --- a/meson.build +++ b/meson.build @@ -151,7 +151,6 @@ have_tpm =3D get_option('tpm') \ =20 # vhost have_vhost_user =3D get_option('vhost_user') \ - .disable_auto_if(host_os !=3D 'linux') \ .require(host_os !=3D 'windows', error_message: 'vhost-user is not available on Windows').allowe= d() have_vhost_vdpa =3D get_option('vhost_vdpa') \ diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index fd1a93701a..fced429813 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -34,8 +34,13 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" +#if defined(__linux__) #include "linux-headers/linux/vhost.h" +#endif =20 +#ifndef VHOST_FILE_UNBIND +#define VHOST_FILE_UNBIND -1 +#endif =20 /* Features supported by host kernel. */ static const int kernel_feature_bits[] =3D { diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 9e8f28f982..29ee09e434 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -40,7 +40,7 @@ config VHOST_USER_BLK bool # Only PCI devices are provided for now default y if VIRTIO_PCI - depends on VIRTIO && VHOST_USER && LINUX + depends on VIRTIO && VHOST_USER =20 config SWIM bool --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154470; cv=none; d=zohomail.com; s=zohoarc; b=i4kFlLzpb35jQeGoFrWk4TrPpoFSKMXxreTWPLTYhEK6bRoSgAVn+FT+7mFGLTjN8TF9NgqulH9xBAA+VDM/FahE5f+DFBZlsGE4jabCteZGMeEi35FilJXSFOtxrkpg9JoLfQg0T8YCtTY10FS3V55on7xB4XN4OEAdkJ0wk2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154470; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=c2iLWpiAMoSh5bQUokPRhQNz1XWV7X7XRsP0hDRBa4c=; b=BAQcO0NcUDwbKjbBnIbyg4uvmxVCAwS49FoLo+skFXQ8KYKT4WUL0ep36LP5EEc7xEhofiERc9N5ByVhzjR5WTx0AjZVzqZkkaFUrFAvuxQVHMCt/KH4wZXPzZoHo5hYS/A0YKSICg10hQ9UfYsBtR5jfVyWeaL9gflrg+kZSjM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154470983917.9990978894672; Wed, 8 May 2024 00:47:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c0A-0004N5-V9; Wed, 08 May 2024 03:46:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzz-0003w5-JU for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzx-00011l-Rq for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:59 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-pv2HmawDOVacDG6LKND-Fw-1; Wed, 08 May 2024 03:45:54 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a599dffe736so55481266b.1 for ; Wed, 08 May 2024 00:45:54 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id oy29-20020a170907105d00b00a59b077a70esm4689996ejb.2.2024.05.08.00.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154355; 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=c2iLWpiAMoSh5bQUokPRhQNz1XWV7X7XRsP0hDRBa4c=; b=fwdKopCWfuYDrx82Dhfyhf8pEY6jTuRITGlYiEMCRQQzYVnsNqG6YmyKRFJO1oSbOtXJMN 2oGp4S3fV8ywzD9WTRIEzmI1BWxh4oDSGciEIJl4TVC33scn+yp53HpAAIVPaBQ+Rfy3u0 afp9cjn8aNHzQTm+P9QHm0dHH4l8S8E= X-MC-Unique: pv2HmawDOVacDG6LKND-Fw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154352; x=1715759152; 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=c2iLWpiAMoSh5bQUokPRhQNz1XWV7X7XRsP0hDRBa4c=; b=VOPuXNn/lqo1jeAmelQgeZ+JMRG911I7mjZl0UPyKdRYuVhfdLQWd1kdKH+OTRq2AO VY+CvHvtwKsO9QjQeR0hk/dbOvSe7YUeTpC+q3gwTTRvQeuZC3P1RJVoGbiiuGGMtbPH WhS2L5rI6MEy5IfQThMZHowQyyt9ritB3QBtgVbAHAHaw02MzmOSsG1ffoY2N7t8nxKm uCK1XvAfoGlQDvGKdHcuPc14wxw4AdvysYdWzM1bkQjD4u5Gk3xSU3XxlrAh+do/rqp8 hqG9qf0Xu3uy3AsfnAoO3YRtL3bKWfw/MeiVtyLJ9itUuZZy17NNae68Yz0/15FGKUNl LmEw== X-Gm-Message-State: AOJu0YzWy6Itg4FyZ0LNCT/WW9GAii+KoBJG6uvjBbVqnseyC3WuAM4D WAdgMvPQkp+/rBnEmDvSffJ0ekUA+bC+XwTIcP53pPnze0mcH5b5Y0REn2ivqVdoCQsQOonGO4B 0kpLryOwMv5cfV+AfoYhfcCGu0BTTPETYnw4Co82V+3NTmULY9DHZv3XcVHd2mPSoMfuSDSFPf2 CRsC2aTONzjD8+5yRaq4U+4vwbSnlb0HiQsIe0 X-Received: by 2002:a17:906:498:b0:a59:9636:f3e with SMTP id a640c23a62f3a-a59e4e861a4mr407165366b.33.1715154352266; Wed, 08 May 2024 00:45:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEHbvCtZ9hcsvG3a9DzMXNl9DxNDxD4G+5ADPgwPi0p6h0oawBgSnDwz8pL6CljHUwDaKxGA== X-Received: by 2002:a17:906:498:b0:a59:9636:f3e with SMTP id a640c23a62f3a-a59e4e861a4mr407161766b.33.1715154351754; Wed, 08 May 2024 00:45:51 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 08/12] libvhost-user: enable it on any POSIX system Date: Wed, 8 May 2024 09:44:52 +0200 Message-ID: <20240508074457.12367-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154472346100001 Content-Type: text/plain; charset="utf-8" The vhost-user protocol is not really Linux-specific so let's enable libvhost-user for any POSIX system. Compiling it on macOS and FreeBSD some problems came up: - avoid to include linux/vhost.h which is avaibale only on Linux (vhost_types.h contains many of the things we need) - macOS doesn't provide sys/endian.h, so let's define them (note: libvhost-user doesn't include qemu's headers, so we can't use use "qemu/bswap.h") - define eventfd_[write|read] as write/read wrapper when system doesn't provide those (e.g. macOS) - copy SEAL defines from include/qemu/memfd.h to make the code works on FreeBSD where MFD_ALLOW_SEALING is defined - define MAP_NORESERVE if it's not defined (e.g. on FreeBSD) Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- 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 955921dcb8..7954da5971 100644 --- a/meson.build +++ b/meson.build @@ -3168,7 +3168,7 @@ endif config_host_data.set('CONFIG_FDT', fdt.found()) =20 vhost_user =3D not_found -if host_os =3D=3D 'linux' and have_vhost_user +if have_vhost_user libvhost_user =3D subproject('libvhost-user') vhost_user =3D libvhost_user.get_variable('vhost_user_dep') endif diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index deb40e77b3..e13e1d3931 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -18,9 +18,9 @@ #include #include #include -#include #include #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/vhost_types.h" =20 /* Based on qemu/hw/virtio/vhost-user.c */ #define VHOST_USER_F_PROTOCOL_FEATURES 30 diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 1c361ffd51..03edb4bf64 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -28,9 +28,7 @@ #include #include #include -#include #include -#include =20 /* Necessary to provide VIRTIO_F_VERSION_1 on system * with older linux headers. Must appear before @@ -39,8 +37,8 @@ #include "standard-headers/linux/virtio_config.h" =20 #if defined(__linux__) +#include #include -#include #include #include #include @@ -52,6 +50,62 @@ =20 #endif =20 +#if defined(__APPLE__) && (__MACH__) +#include +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#endif + +#ifdef CONFIG_EVENTFD +#include +#else +#define eventfd_t uint64_t + +int eventfd_write(int fd, eventfd_t value) +{ + return (write(fd, &value, sizeof(value)) =3D=3D sizeof(value)) ? 0 : -= 1; +} + +int eventfd_read(int fd, eventfd_t *value) +{ + return (read(fd, value, sizeof(*value)) =3D=3D sizeof(*value)) ? 0 : -= 1; +} +#endif + +#ifdef MFD_ALLOW_SEALING +#include + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#endif +#endif + +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif + #include "include/atomic.h" =20 #include "libvhost-user.h" --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154403; cv=none; d=zohomail.com; s=zohoarc; b=RY/KAnpvG2lxzYR6g4KmaKSzbznisl5Ug1OlOzd71q3VWbTjwgvCzA+mnmQ+STLrvporFlQXn68pb1eoxTzjKsBvnQOUVF6vz7QZoc5PHyP2WX2pwEvi/sqEoRyJCz9PoCFzMBEkx9HjbNRCIF56zE1WTLXj+OPObEkNJzjOTmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154403; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pXltNfUgHXCTLeT3zt76n46oHy9O/2v0PFK5rixV6Jo=; b=oFaGRxO1EAlyEmSWDI4jg2OeN6tfnmqIrOr9quXS1uzNOkWsKG+T3kGjpe7ybPrwTZo6wBYFVYsFrrRyAGws4Ec+qskYdlNRLg2PyOJ0nksEV4mZj+A1op+rX4L63Rhpe07CUxn0vLM43azRzElECTSC2b8ChWnnao3oMklTo38= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154403452977.6197654649811; Wed, 8 May 2024 00:46:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c0O-0004Uz-DC; Wed, 08 May 2024 03:46:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4c0A-0004Mj-1f for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:10 -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 1s4c05-00014A-Sj for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:08 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-kLukLsXVOtCOpxXDCOr_dQ-1; Wed, 08 May 2024 03:46:03 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a599dbd2b6aso238345166b.2 for ; Wed, 08 May 2024 00:46:03 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id my9-20020a1709065a4900b00a59ba75059asm4431600ejc.153.2024.05.08.00.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154364; 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=pXltNfUgHXCTLeT3zt76n46oHy9O/2v0PFK5rixV6Jo=; b=fZaqCDdzVLqjj0IigU1ql2XytBu/RyKWmk3jqev2UpjiQoe93njcT3E52fkdk/bYNfN66O NoL3hcRnVi7p69ffXG0aX5mHC1U9NcBVspKM+a/alBHercKwULGt7+HY+vs1vRAVXqswDL 6yqwHmvj7u3ROSjC+gi6miBoQLfCBWc= X-MC-Unique: kLukLsXVOtCOpxXDCOr_dQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154357; x=1715759157; 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=pXltNfUgHXCTLeT3zt76n46oHy9O/2v0PFK5rixV6Jo=; b=DQyiHLgNJ656V7g5sq0VARgCEIHM1Zr8NXwHzdJxCqCLxnFwV8Ax6FLS+MFdrN6YY5 Dw3/cnYaMzWzgEOPBeihK/VBI47Bw+k0MQ8F7rqm+EkuV5YVnFHEuMaqxu4F443B0FRq b7qc85jssQsTyAghmpv9xaCYoeYfLPu8rsvEvK+DJneRdWnK4068vYnzwQvvPhzBesbT H9q2rcALm9LdmX3p048K8HMaOaHv6vu+qIqhy6nOBJXcepBqqdvIjWRrk4OKn/sVxWoC qsE/icVYo2loonpeqQys33doyOsiPWAf63QJF94Z0qwaqUn/F0CnjeWIS0PrzwMsYenl a87w== X-Gm-Message-State: AOJu0YxskCZpkkC0RypJbRuoCryoN9zOGqafIMXf7dGHIgXMDrhunKAQ g9HbEpc4bOgwVO+rDnCnac7vngR9raRWEk7eeTiOBWUanLbgT+tJks4/OaurLAe2LVVSa0T9Cqc 1+34xN2cvd5V4IIwwE7Xy3DbIZz4Bnff29SaKuNoKjTgUdL0HaltoRKGp81YOy87Xychma+ljQG 0yaChkwoVw/GthkPZsiGCxe5hkGj5vjkXLGYo5 X-Received: by 2002:a17:907:170b:b0:a59:a0c1:b217 with SMTP id a640c23a62f3a-a59fb95a633mr115438266b.46.1715154357610; Wed, 08 May 2024 00:45:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4yQEaQD/23q48AYVEgeyj5b9+UjZPeGSGGV11icHoY5oLwxFDOm2QCV39u+WWx3eAzg7mVw== X-Received: by 2002:a17:907:170b:b0:a59:a0c1:b217 with SMTP id a640c23a62f3a-a59fb95a633mr115434666b.46.1715154357296; Wed, 08 May 2024 00:45:57 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 09/12] contrib/vhost-user-blk: enable it on any POSIX system Date: Wed, 8 May 2024 09:44:53 +0200 Message-ID: <20240508074457.12367-10-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154404113100001 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- 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 7954da5971..25047db3c1 100644 --- a/meson.build +++ b/meson.build @@ -1960,8 +1960,6 @@ has_statx =3D cc.has_header_symbol('sys/stat.h', 'STA= TX_BASIC_STATS', prefix: gnu_ has_statx_mnt_id =3D cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', pr= efix: gnu_source_prefix) =20 have_vhost_user_blk_server =3D get_option('vhost_user_blk_server') \ - .require(host_os =3D=3D 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user suppo= rt') \ .disable_auto_if(not have_tools and not have_system) \ diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index 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 =20 +/* OS X does not have O_DSYNC */ +#ifndef O_DSYNC +#ifdef O_SYNC +#define O_DSYNC O_SYNC +#elif defined(O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +#endif + +/* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ +#ifndef O_DIRECT +#define O_DIRECT O_DSYNC +#endif + enum { VHOST_USER_BLK_MAX_QUEUES =3D 8, }; diff --git a/util/meson.build b/util/meson.build index 2ad57b10ba..93054f2340 100644 --- a/util/meson.build +++ b/util/meson.build @@ -112,10 +112,12 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif if host_os =3D=3D 'linux' - util_ss.add(files('vhost-user-server.c'), vhost_user) util_ss.add(files('vfio-helpers.c')) util_ss.add(files('chardev_open.c')) endif + if host_os !=3D 'windows' + util_ss.add(files('vhost-user-server.c'), vhost_user) + endif util_ss.add(files('yank.c')) endif =20 --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154429; cv=none; d=zohomail.com; s=zohoarc; b=DW9rByLa/vfPjDYClWtJDTs6wO6REHX+mpqZQdKX43qAvDWnq4pDEOmliIE5N82E2YUnHpF7AQsDAz2RRYZPQRFobdYToEvp0xZQ7h/uIY+jqeZxciV4+27Bd/Ni6l/bHPN0H4Tr+XxOu6sMUABBzR1lWFlYbjks1K1wv9DuOzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154429; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qnBjMZvtt9t1QFwXBUJ/qjAC2g68U312pSRebToMuY0=; b=m8NNRomnqZJF/zOiEl9F7kKIgQuHK8dzRGgNGIyDdkYjIGzumAN6WOoWmfxKD67nxxVAHS/HTNdS0acfRxOHqqX+SetrXezinawTOMHzrw086UDRCz7e3yyDlohx7gdiGDJ3jR7d0vdH/Ds7k0gnIzwxh8Vwuq8JBsD92cnQ69A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154429960121.51981057245791; Wed, 8 May 2024 00:47:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c0i-0004vG-1R; Wed, 08 May 2024 03:46:45 -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 1s4c0F-0004W5-1z for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:18 -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 1s4c0B-0001Bg-UI for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:14 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-35-sx9oFBI9Md69Os14RFWWEQ-1; Wed, 08 May 2024 03:46:09 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a59c942611bso215225866b.0 for ; Wed, 08 May 2024 00:46:09 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id gh5-20020a170906e08500b00a59a9ffeea6sm5067915ejb.96.2024.05.08.00.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154371; 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=qnBjMZvtt9t1QFwXBUJ/qjAC2g68U312pSRebToMuY0=; b=F8L6e0U5fIXqCRh21DfyH7skDzo4/b96LSV/4EEaWDk9WiqegGqhPGqxZFyMIi5py+ba1t Meacpg0Znu+o8h+oA+w4itnvdD8/jUL48ZlhCcoGOR3JHmY7I5D+zEfCDDePQ0i6KThtTU 9n13sYUPABu8Oa2jl0Q5aFF37p90HMw= X-MC-Unique: sx9oFBI9Md69Os14RFWWEQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154365; x=1715759165; 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=qnBjMZvtt9t1QFwXBUJ/qjAC2g68U312pSRebToMuY0=; b=wybW49p70HDrB2Z+/V2AIBwFYGKRMzLzq/Q98ugj8xgQQXqFNCY+GmLW2dxbTp5BL2 I7KpQw1H7FZjCcaMpRFT1LRxK4xf8VQ5UBsUuBbMgwOMwdwnPyWB7O9fPkWDmw5nuLg7 0pQi5K52z2ZMQ27ApH690BpmcrWXazXkTqAEA39dg8yPcElhcL1PlKovvHOp3fn8EGOA 8Q9Fm8PmpJ8tMNwNVzImxK0A8S7wHSRNk3jwoYb0a2jd+U80fX2mBSje19d5TW/bSS1W F6ESr7qUu4FNcfrum0sd+vs+14Y0ojimmBpgyVCAS6Uh/H5WXl8cEI9Jz/Pk0WHi0Fh1 EvAA== X-Gm-Message-State: AOJu0YzlOi1UxXGmaMbE4z5XIh/c2pva9evMMJvGPzmbfpH6ahcjrrql uBNgF76lkhX9fPX1ZGcN8auXPOAootOG7b+jRhJIbGfCOsLpUOI2/11eF5eHtSn8YeK2ScnK1eW IHegflUajqYc6MpcjJemOEM5k+wHhwEMfDlzF/bnIAGfNO3jOleS3VtCLijxddpcQy4ELUmPmi6 Zr2w5XqHNdjMX5pPAtNN5esp6NjSXdga4n60MY X-Received: by 2002:a17:907:8693:b0:a59:adf8:a6d5 with SMTP id a640c23a62f3a-a59fb9e9985mr134237266b.72.1715154365004; Wed, 08 May 2024 00:46:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzbVEiunVHe44seHHobP4rnUYXei6b9wDBkx7Dc5/g67xIUZ3w2VyHtnL/9euHW5veOoKY+g== X-Received: by 2002:a17:907:8693:b0:a59:adf8:a6d5 with SMTP id a640c23a62f3a-a59fb9e9985mr134232966b.72.1715154364471; Wed, 08 May 2024 00:46:04 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 10/12] hostmem: add a new memory backend based on POSIX shm_open() Date: Wed, 8 May 2024 09:44:54 +0200 Message-ID: <20240508074457.12367-11-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154430207100001 Content-Type: text/plain; charset="utf-8" shm_open() creates and opens a new POSIX shared memory object. A POSIX shared memory object allows creating memory backend with an associated file descriptor that can be shared with external processes (e.g. vhost-user). The new `memory-backend-shm` can be used as an alternative when `memory-backend-memfd` is not available (Linux only), since shm_open() should be provided by any POSIX-compliant operating system. This backend mimics memfd, allocating memory that is practically anonymous. In theory shm_open() requires a name, but this is allocated for a short time interval and shm_unlink() is called right after shm_open(). After that, only fd is shared with external processes (e.g., vhost-user) as if it were associated with anonymous memory. In the future we may also allow the user to specify the name to be passed to shm_open(), but for now we keep the backend simple, mimicking anonymous memory such as memfd. Acked-by: David Hildenbrand Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi --- v4 - fail if we find "share=3Doff" in shm_backend_memory_alloc() [David] v3 - enriched commit message and documentation to highlight that we want to mimic memfd (David) --- docs/system/devices/vhost-user.rst | 5 +- qapi/qom.json | 17 ++++ backends/hostmem-shm.c | 123 +++++++++++++++++++++++++++++ backends/meson.build | 1 + qemu-options.hx | 13 +++ 5 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 backends/hostmem-shm.c diff --git a/docs/system/devices/vhost-user.rst b/docs/system/devices/vhost= -user.rst index 9b2da106ce..35259d8ec7 100644 --- a/docs/system/devices/vhost-user.rst +++ b/docs/system/devices/vhost-user.rst @@ -98,8 +98,9 @@ Shared memory object =20 In order for the daemon to access the VirtIO queues to process the requests it needs access to the guest's address space. This is -achieved via the ``memory-backend-file`` or ``memory-backend-memfd`` -objects. A reference to a file-descriptor which can access this object +achieved via the ``memory-backend-file``, ``memory-backend-memfd``, or +``memory-backend-shm`` objects. +A reference to a file-descriptor which can access this object will be passed via the socket as part of the protocol negotiation. =20 Currently the shared memory object needs to match the size of the main diff --git a/qapi/qom.json b/qapi/qom.json index 38dde6d785..52df052df8 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -721,6 +721,19 @@ '*hugetlbsize': 'size', '*seal': 'bool' } } =20 +## +# @MemoryBackendShmProperties: +# +# Properties for memory-backend-shm objects. +# +# The @share boolean option is true by default with shm. +# +# Since: 9.1 +## +{ 'struct': 'MemoryBackendShmProperties', + 'base': 'MemoryBackendProperties', + 'data': { } } + ## # @MemoryBackendEpcProperties: # @@ -985,6 +998,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 +1071,8 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdPropertie= s', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', + 'if': 'CONFIG_POSIX' }, 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', diff --git a/backends/hostmem-shm.c b/backends/hostmem-shm.c new file mode 100644 index 0000000000..374edc3db8 --- /dev/null +++ b/backends/hostmem-shm.c @@ -0,0 +1,123 @@ +/* + * QEMU host POSIX shared memory object backend + * + * Copyright (C) 2024 Red Hat Inc + * + * Authors: + * Stefano Garzarella + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "sysemu/hostmem.h" +#include "qapi/error.h" + +#define TYPE_MEMORY_BACKEND_SHM "memory-backend-shm" + +OBJECT_DECLARE_SIMPLE_TYPE(HostMemoryBackendShm, MEMORY_BACKEND_SHM) + +struct HostMemoryBackendShm { + HostMemoryBackend parent_obj; +}; + +static bool +shm_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) +{ + g_autoptr(GString) shm_name =3D g_string_new(NULL); + g_autofree char *backend_name =3D NULL; + uint32_t ram_flags; + int fd, oflag; + mode_t mode; + + if (!backend->size) { + error_setg(errp, "can't create shm backend with size 0"); + return false; + } + + if (!backend->share) { + error_setg(errp, "can't create shm backend with `share=3Doff`"); + return false; + } + + /* + * Let's use `mode =3D 0` because we don't want other processes to ope= n our + * memory unless we share the file descriptor with them. + */ + mode =3D 0; + oflag =3D O_RDWR | O_CREAT | O_EXCL; + backend_name =3D host_memory_backend_get_name(backend); + + /* + * Some operating systems allow creating anonymous POSIX shared memory + * objects (e.g. FreeBSD provides the SHM_ANON constant), but this is = not + * defined by POSIX, so let's create a unique name. + * + * From Linux's shm_open(3) man-page: + * For portable use, a shared memory object should be identified + * by a name of the form /somename;" + */ + g_string_printf(shm_name, "/qemu-" FMT_pid "-shm-%s", getpid(), + backend_name); + + fd =3D shm_open(shm_name->str, oflag, mode); + if (fd < 0) { + error_setg_errno(errp, errno, + "failed to create POSIX shared memory"); + return false; + } + + /* + * We have the file descriptor, so we no longer need to expose the + * POSIX shared memory object. However it will remain allocated as lon= g as + * there are file descriptors pointing to it. + */ + shm_unlink(shm_name->str); + + if (ftruncate(fd, backend->size) =3D=3D -1) { + error_setg_errno(errp, errno, + "failed to resize POSIX shared memory to %" PRIu6= 4, + backend->size); + close(fd); + return false; + } + + ram_flags =3D RAM_SHARED; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + + return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), + backend_name, backend->size, + ram_flags, fd, 0, errp); +} + +static void +shm_backend_instance_init(Object *obj) +{ + HostMemoryBackendShm *m =3D MEMORY_BACKEND_SHM(obj); + + MEMORY_BACKEND(m)->share =3D true; +} + +static void +shm_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); + + bc->alloc =3D shm_backend_memory_alloc; +} + +static const TypeInfo shm_backend_info =3D { + .name =3D TYPE_MEMORY_BACKEND_SHM, + .parent =3D TYPE_MEMORY_BACKEND, + .instance_init =3D shm_backend_instance_init, + .class_init =3D shm_backend_class_init, + .instance_size =3D sizeof(HostMemoryBackendShm), +}; + +static void register_types(void) +{ + type_register_static(&shm_backend_info); +} + +type_init(register_types); diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..3867b0d363 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -13,6 +13,7 @@ system_ss.add([files( if host_os !=3D 'windows' system_ss.add(files('rng-random.c')) system_ss.add(files('hostmem-file.c')) + system_ss.add([files('hostmem-shm.c'), rt]) endif if host_os =3D=3D 'linux' system_ss.add(files('hostmem-memfd.c')) diff --git a/qemu-options.hx b/qemu-options.hx index cf61f6b863..2226172fb0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5227,6 +5227,19 @@ SRST =20 The ``share`` boolean option is on by default with memfd. =20 + ``-object memory-backend-shm,id=3Did,merge=3Don|off,dump=3Don|off,shar= e=3Don|off,prealloc=3Don|off,size=3Dsize,host-nodes=3Dhost-nodes,policy=3Dd= efault|preferred|bind|interleave`` + Creates a POSIX shared memory backend object, which allows + QEMU to share the memory with an external process (e.g. when + using vhost-user). This backend mimics memfd, allocating memory th= at is + practically anonymous. This is useful when memfd is not available. + + Please refer to ``memory-backend-file`` for a description of the + options. + + The ``share`` boolean option is on by default with shm. Setting it= to + off will cause a failure during allocation because it is not suppo= rted + by this backend. + ``-object iommufd,id=3Did[,fd=3Dfd]`` Creates an iommufd backend which allows control of DMA mapping through the ``/dev/iommu`` device. --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154421; cv=none; d=zohomail.com; s=zohoarc; b=ZGABjZszfkcaiyPZ3SbGYIJmBkyfiw2f6m4qTlNEA4+L/YkJK9SwGy5Zrve8IYb111Vxwyk49NuiFMc6vL5edo9LYurrm5xy0tgqoNjBH6Ut1V8lSTV942dJPCRk4YeC1RXBM5kSchQiCVVt2p4zWWSVhjqyQX+Y96lqr/NvpLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154421; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YAiSzzjOveYimzBp5y2bZ/4qPL62nC5N/ynRpoSPmwU=; b=Bd+EyrxgdEXTIsaa8xG3uwo1AKU1dciF4W1EbD8bDAfVAuUNlVC41uL14hdtP1xUXUgZWbvcK3L4T7XU0xfKO6bqjkYtnoof7JdMi8mIU7EisF4gbqIz9kQyITZFjS0lNcixkTBKPKghgVpsZQWqziexAo2/08JdamWfd3Qutao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154421159254.89453535193843; Wed, 8 May 2024 00:47:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c0h-0004v0-KJ; Wed, 08 May 2024 03:46:45 -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 1s4c0M-0004XX-LI for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:24 -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 1s4c0I-0001FP-RM for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:21 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-Z4AAhblfOz28vz4C358WEQ-1; Wed, 08 May 2024 03:46:16 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a599b55056bso228896166b.0 for ; Wed, 08 May 2024 00:46:16 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id xh9-20020a170906da8900b00a597ff2fc0dsm6730359ejb.69.2024.05.08.00.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154378; 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=YAiSzzjOveYimzBp5y2bZ/4qPL62nC5N/ynRpoSPmwU=; b=Bsr+siGCFzeGTYmUJhMIneIfX0runPGjiM/OMXjIPaRokZRPSgxWNOk7yRmZPHNUPtokeh tSRGPwvteHCvfMcywTHjDK6iAzNfvKP5dpXYT6+byRZNfHoEEOccf17NfjVF/0rDbH7eD1 lt+lQe7DKCkhGBdDXkmSBnyNUs/U8ts= X-MC-Unique: Z4AAhblfOz28vz4C358WEQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154374; x=1715759174; 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=YAiSzzjOveYimzBp5y2bZ/4qPL62nC5N/ynRpoSPmwU=; b=CVQ2Qx6UgaN5Ivpueiz3FKGA1kcm2UJntIakPKSo3DxjLA9O651kg8BaPcoMTOvODv c93D4SXNVdwq2a+pNMwtYqPutLbGst2aeGdGhy+7eRGlOlpiD/afhJsBOt2hRQrqe682 2Fdj0DTc/0vKG0fd5aZrTFQSLjKkUeLPkQ2zIeKcD1b2jpx9IQfLMJjSY0KVICvu1yMt GKGEtQNBcPentUBK9RG8K1iSL30glH2zLxDc6Hl2LXwj5oPx9OvskxR/1z8S/qyXBV+a TRjt1YlDzOx09qdSPw1itcEpkaLbjuYPoAJpgwt5EgRfOIJ/E0XZSOzQNcMrvw2Mb8yM FAIA== X-Gm-Message-State: AOJu0YzwYRZRTENMjCqvl/9kKT1orBzHVPx8fUlvxRHy7jmEEkONIW0X WYlb1g/kJDGYUjyW6T9BBCOAjP+M15n2OXw0hH4lHUlEWuCQAFqKXUT0FZ+ImrB/sHtauq/cE/B x1o7N5AVn2/VcjuTSn2z1rpxa1NQocCiH6cuGAjBISbS4rJfYSj7P+fWF+ihYJcFScjUxp/T03k 1B+T71qPBH0YvKPNvmn/f8cr824AC3Be7/ywZg X-Received: by 2002:a17:906:e2c1:b0:a59:b730:59d7 with SMTP id a640c23a62f3a-a59fb94b7d0mr105984766b.25.1715154373844; Wed, 08 May 2024 00:46:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmngoyj+GfqYTNwBA2bNoe0AiZ/8XfiJm6Y9bTQSzlPG3avE6Vy66Uym5vEfMbG7PwqkTWww== X-Received: by 2002:a17:906:e2c1:b0:a59:b730:59d7 with SMTP id a640c23a62f3a-a59fb94b7d0mr105981666b.25.1715154373503; Wed, 08 May 2024 00:46:13 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 11/12] tests/qtest/vhost-user-blk-test: use memory-backend-shm Date: Wed, 8 May 2024 09:44:55 +0200 Message-ID: <20240508074457.12367-12-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154422131100001 Content-Type: text/plain; charset="utf-8" `memory-backend-memfd` is available only on Linux while the new `memory-backend-shm` can be used on any POSIX-compliant operating system. Let's use it so we can run the test in multiple environments. Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Acked-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- tests/qtest/vhost-user-blk-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk= -test.c index 117b9acd10..e945f6abf2 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -906,7 +906,7 @@ static void start_vhost_user_blk(GString *cmd_line, int= vus_instances, vhost_user_blk_bin); =20 g_string_append_printf(cmd_line, - " -object memory-backend-memfd,id=3Dmem,size=3D256M,share=3Don= " + " -object memory-backend-shm,id=3Dmem,size=3D256M,share=3Don " " -M memory-backend=3Dmem -m 256M "); =20 for (i =3D 0; i < vus_instances; i++) { --=20 2.45.0 From nobody Mon Nov 25 13:17:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154441; cv=none; d=zohomail.com; s=zohoarc; b=NspASm2vF3fRwZxEaroG34+cQ1xjLnBph/cWLjzx/zN1TIpvelK3Wh30H2YZnsugEsGLjr+E6bLWAAF7pyomwzP6Hu6TleTERDqJJjMShyVCmJE0UDtGdcgVN+to60RYF6uoVG335W9WF06R6hblkVZT59YqiBI5dve5uqXo0Nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154441; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wxCuZszVHlCJxUpW/lwQjeZcg0cjYRwA7TwhfqaB2hk=; b=js4rTLwB+TdEOoMpOXnyeaT0UnSx9zJC1brPMnAAkeS3ILnWkgSXC6Qi+YsB8FbK62hanKlG/h4ABzNu2bB1YKs4LsOI5BWP8TevJxEht2lodYASlZAKbpz26sf8usm5b+fKWm+gbwfcuqqebgiuaRXl88mG4XG0mvp9ejzXs3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154441367876.3504950459575; Wed, 8 May 2024 00:47:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c0o-0005eF-KI; Wed, 08 May 2024 03:46:50 -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 1s4c0U-0004hs-C3 for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46: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 1s4c0R-0001GG-Vb for qemu-devel@nongnu.org; Wed, 08 May 2024 03:46:29 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-WnFK9LrEP9W3FfiPzTx5fQ-1; Wed, 08 May 2024 03:46:23 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a59a63a1f78so245707966b.0 for ; Wed, 08 May 2024 00:46:23 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id ov10-20020a170906fc0a00b00a599ec95792sm5727217ejb.162.2024.05.08.00.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154384; 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=wxCuZszVHlCJxUpW/lwQjeZcg0cjYRwA7TwhfqaB2hk=; b=RFgT3GVGAeO4TT7edpNAJuf7ztu/7bh+JlSbG9rOOczivnNWQUvribIw7dvI0Qzvucdh2Z mklzwoVdrFjAy0YHMfrE26xkhWp9O2dDMYlx9qwE90FChWzZV9LA5AVV4QlQL9eoobAqAq ovt9/Nr8n3ezJ/2y1yTmpYAuZAy13VU= X-MC-Unique: WnFK9LrEP9W3FfiPzTx5fQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154380; x=1715759180; 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=wxCuZszVHlCJxUpW/lwQjeZcg0cjYRwA7TwhfqaB2hk=; b=D6j1P/GT0ebUOW5xRyDELFniF93IMCBWujP97HS1zDrtFuQFVMnr1a9zhyL5WEWuxs rCpU1QRW81MRHgr3I0cxOYolEWauDb+bIZiu1rBhSu6R7WGqHBz22r/lkC41h4PDASgK /A5zuzLTdXZofFu9dAonX8Olji5g61FBV4y/x0FK6daYpL2osWkiubIj+B0ike+IebQ5 MWbWyHgNq1qYsX//E4AKbuXh2FCaYlFfTAtGV2+F+j9rasL8fKTK2lNGIvXpzocr/V3q 76HIPxA7zLQurWWGBRBnXO4Y5UXWuJCfgBCpXQzzFdzLNgQdu/4BF1rEOP14RyIcdPGZ yNrw== X-Gm-Message-State: AOJu0YwpbhTRKFwrt9fek6UX3eLSyoOL+FLL9JhJmsPuhWWaxv5/MFeP 0YjTGSYjXrWflbEkQ2mYFbgLHTJ/lIaV+73j2taCvSfywzzBxhL1gw7zc/mIy3ka+I1jZ+SNcrE +8g/syI/gGfsrrlgiXmAXANSc7ghOxLYSDkxUeO3t/2WN3kboZl8WNd68wE4BJTZCl8PHGEhqhU ZdTByz+n4OKJmXWNngzNQ2YYwZWbqg/o0v/OK+ X-Received: by 2002:a17:907:eaa:b0:a52:2441:99c with SMTP id a640c23a62f3a-a59fb9d1f69mr135816966b.69.1715154380132; Wed, 08 May 2024 00:46:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWyYRBqilqM3dbWzsFmhbu0xPiCPjxZK5N0n+7HJjel3NTnWPz6rJ1rQ4L727i2rMqwriRmg== X-Received: by 2002:a17:907:eaa:b0:a52:2441:99c with SMTP id a640c23a62f3a-a59fb9d1f69mr135812166b.69.1715154379698; Wed, 08 May 2024 00:46:19 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 12/12] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Date: Wed, 8 May 2024 09:44:56 +0200 Message-ID: <20240508074457.12367-13-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154442196100001 Content-Type: text/plain; charset="utf-8" `memory-backend-shm` can be used with vhost-user devices, so let's add a new test case for it. Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Acked-by: Thomas Huth --- tests/qtest/vhost-user-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index d4e437265f..8c1d903b2a 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -44,6 +44,8 @@ "mem-path=3D%s,share=3Don -numa node,memdev=3Dmem" #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=3Dmem,size= =3D%dM," \ " -numa node,memdev=3Dmem" +#define QEMU_CMD_SHM " -m %d -object memory-backend-shm,id=3Dmem,size= =3D%dM," \ + " -numa node,memdev=3Dmem" #define QEMU_CMD_CHR " -chardev socket,id=3D%s,path=3D%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=3Dhs0,chardev=3D%s,vhostfo= rce=3Don" =20 @@ -195,6 +197,7 @@ enum test_memfd { TEST_MEMFD_AUTO, TEST_MEMFD_YES, TEST_MEMFD_NO, + TEST_MEMFD_SHM, }; =20 static void append_vhost_net_opts(TestServer *s, GString *cmd_line, @@ -228,6 +231,8 @@ static void append_mem_opts(TestServer *server, GString= *cmd_line, =20 if (memfd =3D=3D TEST_MEMFD_YES) { g_string_append_printf(cmd_line, QEMU_CMD_MEMFD, size, size); + } else if (memfd =3D=3D TEST_MEMFD_SHM) { + g_string_append_printf(cmd_line, QEMU_CMD_SHM, size, size); } else { const char *root =3D init_hugepagefs() ? : server->tmpfs; =20 @@ -788,6 +793,19 @@ static void *vhost_user_test_setup_memfd(GString *cmd_= line, void *arg) return server; } =20 +static void *vhost_user_test_setup_shm(GString *cmd_line, void *arg) +{ + TestServer *server =3D test_server_new("vhost-user-test", arg); + test_server_listen(server); + + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_SHM); + server->vu_ops->append_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); + + return server; +} + static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *all= oc) { TestServer *server =3D arg; @@ -1081,6 +1099,11 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); =20 + opts.before =3D vhost_user_test_setup_shm; + qos_add_test("vhost-user/read-guest-mem/shm", + "virtio-net", + test_read_guest_mem, &opts); + if (qemu_memfd_check(MFD_ALLOW_SEALING)) { opts.before =3D vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd", --=20 2.45.0