From nobody Thu Sep 19 15:36:58 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=1718704939; cv=none; d=zohomail.com; s=zohoarc; b=TBJtSfGNdArjoTBi5c0VcsGWUlVUbEIl3qED21psbesTl/QOY/J5g4XHAPZparXyFGGYEAWhR6vjPXB01Lq7uo7s8CC8dG1CLD3SZp1A8Rk1X0fD4mdgajfQX2qNnGGEK8P1cciysty6e4tGh7LasfNvyXmj7IUQTvtaTHyh1AU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718704939; 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=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=HJp/NLY2Hj2dqHVtNvEWXsGjKz2waPJva/Z/n9pQC+Uwhr/aMzpcGzvGHTuyBbqGaNAYRAUUYglvi16JXy6kKYbZ3TC1pnNDHKNtKZ14LdZvG/xuWbEutVqR2z+mhN/+qjDqeVB8Be4G4K3mnhYluNrDOy1nZuOwprHwIuUjvlM= 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 1718704939138573.4053971400474; Tue, 18 Jun 2024 03:02:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJVeq-0006l1-91; Tue, 18 Jun 2024 06:01:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVeh-0006jC-TH for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJVeg-0000qB-Av for qemu-devel@nongnu.org; Tue, 18 Jun 2024 06:01:35 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-tMtTOpasMnypUW6DSVXa4w-1; Tue, 18 Jun 2024 06:01:32 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-421f3b7b27eso47390165e9.1 for ; Tue, 18 Jun 2024 03:01:32 -0700 (PDT) Received: from step1.redhat.com ([193.207.160.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4246b67f0aesm52531845e9.45.2024.06.18.03.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 03:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718704893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=aZr5Wlctk8b1mxFPd4AgeoQLly05AMaQIO46BY1UaTNGsdXgWGMtP05x3dEjBthmGcQ5RU 3s+vZzHW0YnfaL3V5LEvUEAFfr2ILbZB3tRyS2DTWw1UidqJdp/Ih4EKyz18OidVVZtQsx EyKs/f2P1jFGgAOCIfEyuwTOsYW0evs= X-MC-Unique: tMtTOpasMnypUW6DSVXa4w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718704889; x=1719309689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=omq0CP5he99OGK2yfFFh7e+anHH7U6JGORMDNNdU/Yw=; b=kBaS88iKkRhMpVZaoR1e1Pmxsj9s24S2Q69Halk3A2D49sEG5HFdbV9ZZyM4WjIA7t Z7is7e9QuyC/413YjI/x4bfGqbkvNgecelJm0tEpo2sl/ItQDePxoTyNmqAKEv7U4EpC 9CzhTGxYTWUwrqHhYYGeoO2+H0PZYbV+gIU3blO1QNuRGRX+0a9S35TfR3LOGfAY2y/f NknCHpxMiAeGpWDWjeuraxkrWbQ4mV+jOm6X5FEGLlD2lnru7Lt8oa8AwYAKgGBNaB0y 0sZaR4w+MbVzCjhOD3mJK+8RwUVA7xQRbHVXqkpG89LmY2rnY4du7OTQwa6PWLyEmfYa y10g== X-Gm-Message-State: AOJu0YyxdmUkw91Si3lU0/c3u9thNkoT+bEeSLHKiEGVWFxs9ddL9P8R dRAV8apJ1MxzoF2KDcJ1nm6hf/oi9UwLrWszOijQh2+PCyNsRbrzweyhL0azpBEbQrhF5UdXnc9 dYZczo5QBDxYpXQYoBhCgeIZr7nFgpb2XGAu73xdNKlZ87c9aGq6r/lF7naKUqD681tFFaJVsBt mNQUfTGXa9WWU7LC2W2/ghJ0dKKpIYfPKfOV+l X-Received: by 2002:a05:600c:460a:b0:422:fa63:33c1 with SMTP id 5b1f17b1804b1-423b6042b14mr85155035e9.3.1718704889303; Tue, 18 Jun 2024 03:01:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHz/n6EkirxnAOJq5rTblqIlHIMDurzatdzRs3nNi9adNaPfP2xl/YDqcTsIttfk38Ssr3cpw== X-Received: by 2002:a05:600c:460a:b0:422:fa63:33c1 with SMTP id 5b1f17b1804b1-423b6042b14mr85154465e9.3.1718704888769; Tue, 18 Jun 2024 03:01:28 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org, mst@redhat.com Cc: Coiby Xu , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , stefanha@redhat.com, Markus Armbruster , slp@redhat.com, Eduardo Habkost , David Hildenbrand , Raphael Norwitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Igor Mammedov , Gerd Hoffmann , Thomas Huth , qemu-block@nongnu.org, Brad Smith , Hanna Reitz , Eric Blake , gmaglione@redhat.com, Paolo Bonzini , Jason Wang , Laurent Vivier , Stefano Garzarella Subject: [PATCH v8 05/13] vhost-user-server: do not set memory fd non-blocking Date: Tue, 18 Jun 2024 12:00:35 +0200 Message-ID: <20240618100043.144657-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618100043.144657-1-sgarzare@redhat.com> References: <20240618100043.144657-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.148, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718704939959100011 In vhost-user-server we set all fd received from the other peer in non-blocking mode. For some of them (e.g. memfd, shm_open, etc.) it's not really needed, because we don't use these fd with blocking operations, but only to map memory. In addition, in some systems this operation can fail (e.g. in macOS setting an fd returned by shm_open() non-blocking fails with errno =3D ENOTTY). So, let's avoid setting fd non-blocking for those messages that we know carry memory fd (e.g. VHOST_USER_ADD_MEM_REG, VHOST_USER_SET_MEM_TABLE). Reviewed-by: Daniel P. Berrang=C3=A9 Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- v3: - avoiding setting fd non-blocking for messages where we have memory fd (Eric) --- util/vhost-user-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 3bfb1ad3ec..b19229074a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -65,6 +65,18 @@ static void vmsg_close_fds(VhostUserMsg *vmsg) static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; + + /* + * These messages carry fd used to map memory, not to send/receive 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.2