From patchwork Tue Mar 12 22:25:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iv9XIQa5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTDz2Wjnz23qj for ; Wed, 13 Mar 2024 09:42:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZd-0004Xw-PE; Tue, 12 Mar 2024 18:26:17 -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 1rkAZ7-0004Op-Np for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:50 -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 1rkAZ2-0004CL-TZ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282340; 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=krVRp63g5I+fEEA6M4zx0/VUoa56zmARDX83eYqmjT0=; b=iv9XIQa5l9zo7qePeuXQallJGrAAJJ/NZGmWFfEgd6K38ibV6dLt0+9ba7kCNSgyM9UmS3 9vvUmmdOjSdyZYOMrQN+jG13K5GxZkCkYnMuPEI5e0scQ82VlWsnrg8XkNF+iX6ehwiRu1 fAk8gjreWVegVysvS6Z6lmhIZrc+zgM= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-mtUONPT4PnmiInIu_7OAMw-1; Tue, 12 Mar 2024 18:25:39 -0400 X-MC-Unique: mtUONPT4PnmiInIu_7OAMw-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-513c6e69b85so348555e87.0 for ; Tue, 12 Mar 2024 15:25:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282336; x=1710887136; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=krVRp63g5I+fEEA6M4zx0/VUoa56zmARDX83eYqmjT0=; b=cvVpkjkChD+cxNFYn1OjVxQunmjkQQ6rUMFZb7dDGxhHzJ0avQ/2Q1bVulyqRfdcmX J3AiW2iDxqkiLORLZIWOPvX6dR5kUpW1qpP0MumPVwFjq77+vspQUNFYH9N1VZedqqwV DJCKYqRlV2LAycmwLtkDYQhhfngf2q6t9KZLxNSPSkO+JdaxgMgcQFBO5DqATJcvzl+X wNU3E2ucpob5s1zUG2v7SzqXsp5bvAtwRxCq3PuYhgqTtu3GyYctX1cm4Nekb+ovDna2 /LXrCX9jg9BqMApJYEBCGXw4u9Mab+JYx+N8q1kmo2y1eZJWHEkOhAjvrV4I7B39G9yP wxgA== X-Gm-Message-State: AOJu0Yx2/kDJgjsZYsj7WqoiGrlswkbfy2bLkb5AApAEqOx8lh3kKUbk Y+u2ondEzj/oRAHXs7cUzfSJ+c1gzNzn/6KGPxtSWzvm3lPYCbsPobgODVXBWPyCthLpgafVS73 m6leBcChAkmqegb7KYANoKJJzTTR5WNpWf8pmYyXQJemzN0F1V3xfvCf9HuexX/in9fqGupDWYr MeHCphaTPGJ+s7mO8gyU1RZCmkhtwX/g9K X-Received: by 2002:ac2:4c9c:0:b0:513:7ef5:1059 with SMTP id d28-20020ac24c9c000000b005137ef51059mr7631689lfl.18.1710282336475; Tue, 12 Mar 2024 15:25:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiPRmz0z8sAT7zaOzl680KYS5WmcNdKjtBRGKMACegR27ISQ3JMkUPDnJ1/4EnuR7x79M9WA== X-Received: by 2002:ac2:4c9c:0:b0:513:7ef5:1059 with SMTP id d28-20020ac24c9c000000b005137ef51059mr7631666lfl.18.1710282335763; Tue, 12 Mar 2024 15:25:35 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id ws7-20020a170907704700b00a42f6d17123sm4176501ejb.46.2024.03.12.15.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:35 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:33 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 01/68] vdpa: add back vhost_vdpa_net_first_nc_vdpa Message-ID: <573581b18dfd458ddac22f832bfb3f6fc9b585dc.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu Previous commits had it removed. Now adding it back because this function will be needed by future patches. Message-Id: <1707910082-10243-2-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index e6bdb4562d..1d9496cdd9 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -287,6 +287,16 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf, return size; } + +/** From any vdpa net client, get the netclient of the first queue pair */ +static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa(VhostVDPAState *s) +{ + NICState *nic = qemu_get_nic(s->nc.peer); + NetClientState *nc0 = qemu_get_peer(nic->ncs, 0); + + return DO_UPCAST(VhostVDPAState, nc, nc0); +} + static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable) { struct vhost_vdpa *v = &s->vhost_vdpa; @@ -511,7 +521,7 @@ dma_map_err: static int vhost_vdpa_net_cvq_start(NetClientState *nc) { - VhostVDPAState *s; + VhostVDPAState *s, *s0; struct vhost_vdpa *v; int64_t cvq_group; int r; @@ -522,7 +532,8 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) s = DO_UPCAST(VhostVDPAState, nc, nc); v = &s->vhost_vdpa; - v->shadow_vqs_enabled = v->shared->shadow_data; + s0 = vhost_vdpa_net_first_nc_vdpa(s); + v->shadow_vqs_enabled = s0->vhost_vdpa.shadow_vqs_enabled; s->vhost_vdpa.address_space_id = VHOST_VDPA_GUEST_PA_ASID; if (v->shared->shadow_data) { From patchwork Tue Mar 12 22:25:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ezJYepoe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT4b6QHXz1yWy for ; Wed, 13 Mar 2024 09:35:43 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZQ-0004Rh-11; Tue, 12 Mar 2024 18:26:04 -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 1rkAZ9-0004Ox-KH for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZ7-0004CY-1p for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282342; 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=oWHeCTwjwE1j/gB8xg8GGFC+NRd4QASP7jVSN89iyRY=; b=ezJYepoeUIhBNjRcvybbxlfeZJj1aW9+wEpvdwOoW9//G0SND8lIy8vTkl+6/+7D1H8Q1E TOKiSiWp7Z6SCquEzOzEFNd9KgCHPBAQJQfEYyxU6ml22rcfoxLcQcU5Lvc1y8i0xTurCd pAFeI8Z1JW/QMagIVFLgLL2pgFaWQ70= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-qmvZRCV-N5mpVwQA-Tj-Ag-1; Tue, 12 Mar 2024 18:25:41 -0400 X-MC-Unique: qmvZRCV-N5mpVwQA-Tj-Ag-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d449d2db37so16052141fa.3 for ; Tue, 12 Mar 2024 15:25:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282339; x=1710887139; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oWHeCTwjwE1j/gB8xg8GGFC+NRd4QASP7jVSN89iyRY=; b=P9+OPPFglA/N/TrdaAV9GY32Tph7B+xrAQAugiQM3IQp1PJbFh17r6NCem+iokM9WE TbxSs+pTXZETfwP6JCv0MctXtSUAnaKzWKrt3rwKuG6gPD1agkS7FUGtUTzCShrwIypB O03mb96KMAx7PXkMC6im138Vf7FXMtIl89nn9LSK923cm6dMo+b/I9cuSX7y/gASS7F6 z9hQBfM1E+OjdpRztnRDkB8353G/Ny1qomD3tnniP4e5QwZ+0lUwqomG2AM26hnjGdC7 nDNvLEWeioX/tfw248wb9yYbHlPpI6wwn52pGd4Rbatjs4Tmb9f88hCaT7A9HG1W4eu0 A/UQ== X-Gm-Message-State: AOJu0YxqKroCiczm8nfOk0AgWEEH/CcfSrn+8tOrOXjQ7CX4w09Duzxl iHFllfxQxGY0M5DFonohi/w8t4+rKfYkAwBTQMPvdM0IMcwL0U1+Z97t6nuTGunpG4T6fPRIDW8 31irNLsA//QBDuQMidiDwndHsRucQqWP13CuXGYGVIm+VVBwbp7BH/PBUKbwVPj54qQLA02Er3Z aZtqR9OgOvueHTshvyxx9dNXbJ9QTvP8gy X-Received: by 2002:a05:651c:222c:b0:2d4:64fc:65bb with SMTP id y44-20020a05651c222c00b002d464fc65bbmr1673380ljq.48.1710282339312; Tue, 12 Mar 2024 15:25:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnR0lKcptk0t7HrPsNHLjXPb0w+I5sMcXvf3J5hlqPyVi0JBLSHVVENXtLZlb25IjGtJ5HwQ== X-Received: by 2002:a05:651c:222c:b0:2d4:64fc:65bb with SMTP id y44-20020a05651c222c00b002d464fc65bbmr1673363ljq.48.1710282338667; Tue, 12 Mar 2024 15:25:38 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id e12-20020a056402104c00b005686037bc12sm2248238edu.29.2024.03.12.15.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:38 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:35 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 02/68] vdpa: factor out vhost_vdpa_last_dev Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu Generalize duplicated condition check for the last vq of vdpa device to a common function. Message-Id: <1707910082-10243-4-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Acked-by: Jason Wang Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ddae494ca8..8bd62e8dd2 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -555,6 +555,11 @@ static bool vhost_vdpa_first_dev(struct vhost_dev *dev) return v->index == 0; } +static bool vhost_vdpa_last_dev(struct vhost_dev *dev) +{ + return dev->vq_index + dev->nvqs == dev->vq_index_end; +} + static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, uint64_t *features) { @@ -1315,7 +1320,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } - if (dev->vq_index + dev->nvqs != dev->vq_index_end) { + if (!vhost_vdpa_last_dev(dev)) { return 0; } @@ -1337,7 +1342,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev) { struct vhost_vdpa *v = dev->opaque; - if (dev->vq_index + dev->nvqs != dev->vq_index_end) { + if (!vhost_vdpa_last_dev(dev)) { return; } From patchwork Tue Mar 12 22:25:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gpK8oArL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSt048R7z1yWt for ; Wed, 13 Mar 2024 09:26:32 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZN-0004Q1-2N; Tue, 12 Mar 2024 18:26: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 1rkAZB-0004Oy-Iq for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25: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 1rkAZ7-0004Ce-UE for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282345; 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=eZaG+KxyK0GG+1USXRX9tkoASWxplBOifAD/25exeOE=; b=gpK8oArLyp4fTTN/YILeT3f0F+Kb/9FLdmf2vM4jIgMjBNkFqWrHGJYWmPVswx6zem/rJO 2OZd8T8BePCWYr76npiEYtCjSkR1vkM62aE5fks06p3PJGm0Cv9B2u2keS5bzzrCRzc/nN 523LJhGQObAgy0Imi03SWOcBBDFX7hY= 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-261-nGiaZPuGNeKLwK-pelqGSw-1; Tue, 12 Mar 2024 18:25:43 -0400 X-MC-Unique: nGiaZPuGNeKLwK-pelqGSw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a448cfe2266so493947366b.2 for ; Tue, 12 Mar 2024 15:25:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282342; x=1710887142; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eZaG+KxyK0GG+1USXRX9tkoASWxplBOifAD/25exeOE=; b=vvB+gYsJ2LHAmwqaCaFbVwB9J3WhT/+AuL+4yGRgu4rceQpF9jkuz7/yvBQ2vfdybp qG0bxwEK8hbMSBZKuc254CqHe+4h8CfrA5TBQDOqpFsmYS469NTEcVKMp2F34ycUbtSO B7gXQSxjXxjqcOpX53rBw3ESzDmigo5JLPHIi0lPxnrU0usZYQWT2gI0Rr1FQcNZobOZ 1ekwdXtbN9OEURZ1Yq45VU55B+i3y1R9uAIb8FHTCGIe2PxRvHUQGEPGShn745/ZfVkg ozxXO9eJp+QSlDdSHWH+OZfmJTOrwyY715sssHEMr9nKoo41x8nbQgnTs2YwZw/gcZ0I O4sw== X-Gm-Message-State: AOJu0YycqBzotV8dlhYoQAsXUXglPni70n0JWPWf7dEc/gI1TnRQDSFv poYwlQ98+0wU5hc+E+U0qD3ugFBNhL+SkA2FCQaNsG48o5hKaGWrglDxKs4NnS6mw7fCnielRKn zeHM8CRVUbes9PMs2iob45T2Z2dpdLo681Cya2dQuxi88VMuDel1NukMENoUZzNzf0z+JfH+i+y ghPW8ZB88S1osCIMwCkjpKgnnemdKCr4s6 X-Received: by 2002:a17:906:2849:b0:a40:18ad:3fcc with SMTP id s9-20020a170906284900b00a4018ad3fccmr6717719ejc.36.1710282342217; Tue, 12 Mar 2024 15:25:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcgUqFAOBYdoFIkhpbmGXSZECgdnB18gutJb8fuwdBHO2vnaSXKj4KCVPlk7ydt9OKlJ51vg== X-Received: by 2002:a17:906:2849:b0:a40:18ad:3fcc with SMTP id s9-20020a170906284900b00a4018ad3fccmr6717711ejc.36.1710282341774; Tue, 12 Mar 2024 15:25:41 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id lt10-20020a170906fa8a00b00a45ab830eabsm4250612ejb.51.2024.03.12.15.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:41 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:38 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 03/68] vdpa: factor out vhost_vdpa_net_get_nc_vdpa Message-ID: <77c3a336a44272e8a6e9b18c6b765f08aa84151f.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu Introduce new API. No functional change on existing API. Message-Id: <1707910082-10243-5-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Acked-by: Jason Wang Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 1d9496cdd9..85efda9e67 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -288,13 +288,18 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf, } -/** From any vdpa net client, get the netclient of the first queue pair */ -static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa(VhostVDPAState *s) +/** From any vdpa net client, get the netclient of the i-th queue pair */ +static VhostVDPAState *vhost_vdpa_net_get_nc_vdpa(VhostVDPAState *s, int i) { NICState *nic = qemu_get_nic(s->nc.peer); - NetClientState *nc0 = qemu_get_peer(nic->ncs, 0); + NetClientState *nc_i = qemu_get_peer(nic->ncs, i); - return DO_UPCAST(VhostVDPAState, nc, nc0); + return DO_UPCAST(VhostVDPAState, nc, nc_i); +} + +static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa(VhostVDPAState *s) +{ + return vhost_vdpa_net_get_nc_vdpa(s, 0); } static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable) From patchwork Tue Mar 12 22:25:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911386 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bwkq6lbb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSv527Clz1yWt for ; Wed, 13 Mar 2024 09:27:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZO-0004QT-Gf; Tue, 12 Mar 2024 18:26: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 1rkAZD-0004PT-KE for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:53 -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 1rkAZB-0004Cy-BE for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282348; 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=IhIYiGuhexxvR3Vz4hV/FS6E5xXXWvMe6jUtxyAzs0w=; b=Bwkq6lbbTwP+0NmI5VsQjIWFXUVuBcEJmD9OEQaStJWDT3oj4X7bA9JDMVjSp1ROBl0azF IaDej1MK8Zc/XdmV5a/ig5hGIFQY+cNPr2kUdG+9QGocxuEzwvNlhYKb9cemO8ph729EI2 9UhxlXzhdZiHste2E+HFWQbhR6ZyKyU= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-Gt2KAMLxOTOKLfX7MX7tDw-1; Tue, 12 Mar 2024 18:25:46 -0400 X-MC-Unique: Gt2KAMLxOTOKLfX7MX7tDw-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5684c1abc33so2349660a12.2 for ; Tue, 12 Mar 2024 15:25:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282345; x=1710887145; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IhIYiGuhexxvR3Vz4hV/FS6E5xXXWvMe6jUtxyAzs0w=; b=Yusaq9StvHxN2/WWOIXdvkmaLxmniTswjH2aeLPPtAu8n13VLlM+LDptYboffz38Uh /u84ZxOoHsaEbWCnr7mqF9zb0JwAXcCxCwibc3FDb4JiikpnDZTXgoNV5R1wNc7JxsUM NGw4L3tEvCKe+RAu34phHUqI6KvAvfFe34COLkOX/zptrJyw3ycJASBNfqh9TQO23PIp qEERjdAV+yOZvpg8sOvrtBrnBrzttukzRdVXPXAPbms5mXICCW+1h3xIqW0yk7MtBXNi F26ziQ5ZnQaks7TI+SdgX2TIJEoZZ6fJWeAIBIJ5GND0OnUQwU2ZwppQXO5aoA78V9t+ JHqA== X-Gm-Message-State: AOJu0YxZ3wbz4KUz3k7OxrJFjvHmKDI/gqdUrhz+tqU5I6fdz15dzIO2 Giz3/vkF2k6xp0kNUaL5V5ZcH7N/2ctuGxssAcU5xvGpu4HrR4OZWWLQfEp42/f34Md18EqcN5C yGJtFW0eips0c66dJtBAHvzSvITIZF/NIUQBPf6jGeKfSzRTXJflpRizLErXQYWY+a2kJuDHqcv 2c8sixSCYPf6Rl/dg81wWeC7CDpfP8snQa X-Received: by 2002:a17:907:a0cc:b0:a46:3814:c3e6 with SMTP id hw12-20020a170907a0cc00b00a463814c3e6mr1862669ejc.60.1710282345060; Tue, 12 Mar 2024 15:25:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES2M1dOcee666O2Fia2vWrwes+9oU14EnP00+flDUeVT10DfBrcD/fZACLoclnW3uK7afdWA== X-Received: by 2002:a17:907:a0cc:b0:a46:3814:c3e6 with SMTP id hw12-20020a170907a0cc00b00a463814c3e6mr1862656ejc.60.1710282344640; Tue, 12 Mar 2024 15:25:44 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id k13-20020a1709065fcd00b00a44f0d99d58sm4209000ejv.208.2024.03.12.15.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:44 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:41 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 04/68] vdpa: add vhost_vdpa_set_address_space_id trace Message-ID: <62845d3296ab7565e66f6e1f7bcfedb877f6fe7b.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu For better debuggability and observability. Message-Id: <1707910082-10243-6-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 3 +++ net/trace-events | 3 +++ 2 files changed, 6 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 85efda9e67..9e8aded41d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -29,6 +29,7 @@ #include "migration/migration.h" #include "migration/misc.h" #include "hw/virtio/vhost.h" +#include "trace.h" /* Todo:need to add the multiqueue support here */ typedef struct VhostVDPAState { @@ -460,6 +461,8 @@ static int vhost_vdpa_set_address_space_id(struct vhost_vdpa *v, }; int r; + trace_vhost_vdpa_set_address_space_id(v, vq_group, asid_num); + r = ioctl(v->shared->device_fd, VHOST_VDPA_SET_GROUP_ASID, &asid); if (unlikely(r < 0)) { error_report("Can't set vq group %u asid %u, errno=%d (%s)", diff --git a/net/trace-events b/net/trace-events index 823a071bdc..aab666a6a0 100644 --- a/net/trace-events +++ b/net/trace-events @@ -23,3 +23,6 @@ colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, in # filter-rewriter.c colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u flags=0x%x" colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" + +# vhost-vdpa.c +vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" From patchwork Tue Mar 12 22:25:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fUifkuJl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSv11Zkhz1yWt for ; Wed, 13 Mar 2024 09:27:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZU-0004S8-88; Tue, 12 Mar 2024 18:26:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZI-0004Pz-A0 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:00 -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 1rkAZE-0004DS-QC for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282351; 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=eN4YswExUhrgK7Cwoxr2sBU+v3bHPhBMUx7Ts5pHAAo=; b=fUifkuJlyztYJSDNwpLeqFf2cnsh2OFRyNDDWo/Hiz1BtwPFdSokJ/ImbJUDLA6aV1FEi7 s32wOJS1nxgDTKCNKDyF7aVX7D8A0WPN+lZ4yCBFEwdsatCVxlTUKPWyWNacQ6xEiPnAh6 NmLYSsxAGT+Wx2tc/dEIMbiEV7jW95c= 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-672-raDGrAxFOuiJmC4SoNYpeg-1; Tue, 12 Mar 2024 18:25:50 -0400 X-MC-Unique: raDGrAxFOuiJmC4SoNYpeg-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a3fb52f121eso28236766b.0 for ; Tue, 12 Mar 2024 15:25:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282348; x=1710887148; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eN4YswExUhrgK7Cwoxr2sBU+v3bHPhBMUx7Ts5pHAAo=; b=t/QBMlDYjqLf4GXzVcUuVTJn9+mWO0aaFOtFwvpix9fevVDXZmaXapMzKZGQPKPlVk x3GYBDB7jJ0llovTpo1jIU1mmefbpESo8AmEkqIVqDOVBXjfHk1ZY2X8Gp2diVtiQs1h QwsktVCeHtYIr+/rK8gKr9dyfcj4sPj4v4cWrOS+v/WXOys0BzIF5R6gVYe/GEBlGK+i FGb0xSSfiMEnOA3CJR/QQEywyheet5PADy3N7Yj33hICSD9KSzOjP6MAC3Vj/2zpsj08 0YTac5YlVmqyoR6zJRwkOrdzhjhnSVLH2T+DJPmvPPk7LBSIDcLBsjYU7KvQSvd6d6WO b50A== X-Gm-Message-State: AOJu0YzIyjWrok8eRn/rDLJUNUNABmMTq09hmkGwoZhDjlPw9J2lq1a9 boO8dzCLzrsjXXVY+u6JeFacsolh8UuVtI38JxSuQbLGNftpSKwmSu0r0Q7DsL04Cnlau4UUT7g n3HsdEBnxLvKvCtuiTsLWGwfjHdd0ud/l5MTgUA2lkJ56jpnlGRSeiJvozWeJ3i2C2xjEvrjGZK UVnVq+bMFjYY9y88Rjh/XQvkjnX6VjsqRW X-Received: by 2002:a17:906:408e:b0:a46:28c2:49b2 with SMTP id u14-20020a170906408e00b00a4628c249b2mr3350514ejj.24.1710282348070; Tue, 12 Mar 2024 15:25:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0+Vp8iKRH1juUxUdy8yXrVoSqXyA6MXfDW7JoolubekoJ98wAyS09nR8Rlj8QEdKQtUjEnw== X-Received: by 2002:a17:906:408e:b0:a46:28c2:49b2 with SMTP id u14-20020a170906408e00b00a4628c249b2mr3350499ejj.24.1710282347659; Tue, 12 Mar 2024 15:25:47 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id jx24-20020a170907761800b00a45fefe57d5sm4190850ejc.96.2024.03.12.15.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:47 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:44 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 05/68] vdpa: add vhost_vdpa_get_vring_base trace for svq mode Message-ID: <6ec0a7467828f228e00ec83978fb5267f81079e0.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu For better debuggability and observability. Message-Id: <1707910082-10243-7-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Acked-by: Jason Wang Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 3 ++- hw/virtio/trace-events | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 8bd62e8dd2..c7271093dd 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1412,6 +1412,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, if (v->shadow_vqs_enabled) { ring->num = virtio_queue_get_last_avail_idx(dev->vdev, ring->index); + trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num, true); return 0; } @@ -1424,7 +1425,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, } ret = vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); - trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num); + trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num, false); return ret; } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 77905d1994..28d6d78380 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -58,7 +58,7 @@ vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int r vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_set_vring_kick(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64 From patchwork Tue Mar 12 22:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U4UTsKf8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT7P4fm9z1yWy for ; Wed, 13 Mar 2024 09:38:09 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZc-0004Xe-2q; Tue, 12 Mar 2024 18:26:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZI-0004Q2-PW for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:00 -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 1rkAZG-0004Db-Un for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:25:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282354; 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=qJIP+mB13E58BkNpHusyPXxmrUBHtsi0jjjQcT0sAlM=; b=U4UTsKf84WWKljM4LFNn8TuPYBCdxGw9AQrYH/NedOiod33sQegOTw4zDv/WNpUhj85RfB N5RYupBiYzthFxYte+783wZ9+p9j6fScnD5xGCiznkFeBwrqRwVnotZmgCgLYqYlaPOaTT pMdxrAL7VqCIhhKmdr9GRLnMYNx+s18= 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-511-5b6rj8n4Pq-H_-OO4i8aBA-1; Tue, 12 Mar 2024 18:25:52 -0400 X-MC-Unique: 5b6rj8n4Pq-H_-OO4i8aBA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a44143c8908so27787166b.1 for ; Tue, 12 Mar 2024 15:25:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282351; x=1710887151; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qJIP+mB13E58BkNpHusyPXxmrUBHtsi0jjjQcT0sAlM=; b=PhRLLR+1kDdRf3SPazv07vkQ7yqKSsf00NJSFtIsi+/+DXPRDS6UX8wEPXGFZxL402 7rXvNoNpDxUBeit9GgqFYsFFab786SZR6PoyDGqdch+74DI8XqXvXpantI9wLLyIRlDF OaQ6eAy+k4aREaAtPavcAADhBuyYnktFRMVeagtgQI3yWoOL8rBSIeQ3gCcgyKE+1VXD s65gwKN2B2Q40gnoPbJpkyhZwDg89LpRbDWVEfKuMebaLbfHNxXRnGou/MxgRW6iULRj 49hrhhoJL5YvnfMDCpOAkaVAMpGCLAZ6e1O5g6T/zx5ESvTr0+EoP5hwWFOveUbHIljL rxcw== X-Gm-Message-State: AOJu0YzOoNudehGTMhb1GuQv3GqIELR3EHdnrhnfiDVyIRqzGep6x0PG zFGk5teXcNRXy/rdw2EeDewdxzD1jdOYc+YD3ZexNmcAv/bcdb+Pn+TvP0uhpGPXPRlVG1mDue8 hzXiGFB9yXo3NXbNzDFDazDV4N8FlF0Q/2FHPzgH8LfxCvMfYHy5oy9nnyHlyjtfVeX0AG4Eh20 OBncxHU+SFFFh7Obbb1N1LR0boHU7VHL+V X-Received: by 2002:a17:907:1b0e:b0:a46:4ea8:9df5 with SMTP id mp14-20020a1709071b0e00b00a464ea89df5mr1010792ejc.5.1710282351064; Tue, 12 Mar 2024 15:25:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzPloPYs+h7K6vPtgWVfpz0mMmWbvHAanSG3iRRGLaGPPKaLQTLd3hVZpqL+8xMzTra38J1w== X-Received: by 2002:a17:907:1b0e:b0:a46:4ea8:9df5 with SMTP id mp14-20020a1709071b0e00b00a464ea89df5mr1010768ejc.5.1710282350442; Tue, 12 Mar 2024 15:25:50 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id bn23-20020a170906c0d700b00a462e4d7216sm2028670ejb.76.2024.03.12.15.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:49 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:47 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 06/68] vdpa: add vhost_vdpa_set_dev_vring_base trace for svq mode Message-ID: <19a060bce17316d9ff7d8b3637fb391010be8144.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu For better debuggability and observability. Message-Id: <1707910082-10243-8-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Acked-by: Jason Wang Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 5 ++++- hw/virtio/trace-events | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index c7271093dd..fc84cf6ec6 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -970,7 +970,10 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, static int vhost_vdpa_set_dev_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { - trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); + struct vhost_vdpa *v = dev->opaque; + + trace_vhost_vdpa_set_dev_vring_base(dev, ring->index, ring->num, + v->shadow_vqs_enabled); return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 28d6d78380..20577aa584 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -57,7 +57,7 @@ vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d" vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcnt: %d fd: %d log: %p" vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" -vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u" +vhost_vdpa_set_dev_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_get_vring_base(void *dev, unsigned int index, unsigned int num, bool svq) "dev: %p index: %u num: %u svq: %d" vhost_vdpa_set_vring_kick(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index: %u fd: %d" From patchwork Tue Mar 12 22:25:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=F8WKF7MB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSv26tQGz1yWt for ; Wed, 13 Mar 2024 09:27:26 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZd-0004Y1-UY; Tue, 12 Mar 2024 18:26:17 -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 1rkAZO-0004QX-4T for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZM-0004E9-F3 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282358; 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=dUCwppk0yqzd6oST72OHAmOacyZwa2NHyNO8Qzr3EqY=; b=F8WKF7MBlXQbv3TTZgTqRei/Px98r4b/01vzejKmB+sYnt1yvIOCsS5cNsR7LBGG1mofWm mlIPffyL96ZDG8VELybS/XabOG/wjXKxHTYMZoIa+IAwNevbwdx5XHFxu6lk5X0/93JF5l owYSDPBPyW1js5hw56gWfQBKcqvrhIA= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-x_sbzPQ4N3KOd8s9hw6buQ-1; Tue, 12 Mar 2024 18:25:56 -0400 X-MC-Unique: x_sbzPQ4N3KOd8s9hw6buQ-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5687a5239f7so624138a12.2 for ; Tue, 12 Mar 2024 15:25:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282354; x=1710887154; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dUCwppk0yqzd6oST72OHAmOacyZwa2NHyNO8Qzr3EqY=; b=Y+G341QIT+DNsCQR8RoBoaIl64qnWZMEjLDS/kqKiQ9ziuGewvbHzS8ZB15B+La5PW uCsUa1H28Kb9xIDWQgh01Pqa+K7bKznKGds5wGjIFF3KfD6pAS/Jv55jMmzIkn3Zk329 b6GyT0lqvoIFnVbkgVa7Jm/Stx6gpRFTGO3aA9moPf6sgzTb1WklKntl6pRwx6SHcvWi F0fmqtLaUzC0ek/AIHO4SsIB+thckzoVtlOYUViEQYvvjqKJOKabV4HypAXp/oMHf9d9 unNmaHhKpwUYIq61aGG7x0oLygtORKyiI0Q7g+2rTL6DJ5L55i3Sp+nbyS3whmhuUYxB ZspA== X-Gm-Message-State: AOJu0YxhbNN5MV8YlxhuwOgqC21GUl0c5CuDLzZA6HxwnNrsJyBlGp6z H3Bn2dcnZOs0GvOZY6at+TYJTvGVZUultMrs1LgkurM6OxJxvRu0b7yQ8Bh4mzEz6SClrAIeZTt 7JIrmoYHIhJlgfuvN+xOpLlA+pfbmt2TJigIWWn7kAn1hll/HTWYz0/lLYCqLQ/RC0bJoYlf7v7 c0h+ApXHf7R8woMTliXKBSl+6nxVp+HhQA X-Received: by 2002:a17:906:2812:b0:a45:c694:98ae with SMTP id r18-20020a170906281200b00a45c69498aemr1109305ejc.20.1710282354131; Tue, 12 Mar 2024 15:25:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+EVH6nT8OqcAieFctqYsD5szHh6McmP6umIZU4jumA9WpoEykSZblEJ3bi1sUQ7CaTg994A== X-Received: by 2002:a17:906:2812:b0:a45:c694:98ae with SMTP id r18-20020a170906281200b00a45c69498aemr1109289ejc.20.1710282353577; Tue, 12 Mar 2024 15:25:53 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id t24-20020a1709063e5800b00a45bbeeea9asm4210716eji.167.2024.03.12.15.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:52 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:50 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 07/68] vdpa: add trace events for vhost_vdpa_net_load_cmd Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu For better debuggability and observability. Message-Id: <1707910082-10243-9-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 2 ++ net/trace-events | 2 ++ 2 files changed, 4 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 9e8aded41d..2c95a98cc6 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -715,6 +715,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, assert(data_size < vhost_vdpa_net_cvq_cmd_page_len() - sizeof(ctrl)); cmd_size = sizeof(ctrl) + data_size; + trace_vhost_vdpa_net_load_cmd(s, class, cmd, data_num, data_size); if (vhost_svq_available_slots(svq) < 2 || iov_size(out_cursor, 1) < cmd_size) { /* @@ -746,6 +747,7 @@ static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, r = vhost_vdpa_net_cvq_add(s, &out, 1, &in, 1); if (unlikely(r < 0)) { + trace_vhost_vdpa_net_load_cmd_retval(s, class, cmd, r); return r; } diff --git a/net/trace-events b/net/trace-events index aab666a6a0..88f56f2428 100644 --- a/net/trace-events +++ b/net/trace-events @@ -26,3 +26,5 @@ colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" # vhost-vdpa.c vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" +vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" +vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d" From patchwork Tue Mar 12 22:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eT4l62Xw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSy10bPxz1yWt for ; Wed, 13 Mar 2024 09:30:01 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZQ-0004Ro-S8; Tue, 12 Mar 2024 18:26:04 -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 1rkAZO-0004QY-4U for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZM-0004ED-FC for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282359; 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=529XxwutIRv0EVLfrPXEt8NF5I7KrDY1qBpYH7/4N5E=; b=eT4l62XweRvZ5yEoIec3tjwhUovKv+WhSQ9gFgBqxqNn9f0eAB/fg5Ol7HD4QzNhR0/KYX ul2Sf4hQi3Je3N169N+hnyVq+bvH+dMv15gO2fQHY76M6qFwiqflMbm63A8d8Hw9OqiQWP jYCxGiZBoLD1qjTj7XkIGHFcwfQXUWk= 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-249-50D0yG17Ppap6KpG4-Ckeg-1; Tue, 12 Mar 2024 18:25:58 -0400 X-MC-Unique: 50D0yG17Ppap6KpG4-Ckeg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a45fb3a5430so220801266b.2 for ; Tue, 12 Mar 2024 15:25:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282356; x=1710887156; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=529XxwutIRv0EVLfrPXEt8NF5I7KrDY1qBpYH7/4N5E=; b=pudV+LT13LDUeduGByQ6XYoVXafxc9d1SIjIpSvNQf13XhQBBSfeIuViaWSyVm+KEW f82fZ38VDHWJyYOEZA+BnZOo1AQu6H083FM6l9L+DnfqvzODtArixYOyqP1rVnVrlIRP NPN9A/+/32Jsq7OdtnUazvWQTHeSjVqjwl5Kt6YjbzEc/uW7Mr+H2GUcN6nQedPVZeH/ S2wB3k/a6/k7Ji+KHUNLQUbW+YHAdbUmqrdfja+0tKBak7JkAvjb1FWA9nZVYo8obna7 YrOeG5pg3XkuAzd78TWSlXkDbXDktT6ex/P4tUbEe+ciWCoDtVEP/CHygHTEVhxvSmfm Aimw== X-Gm-Message-State: AOJu0YzZ0xN6jhemB5BrSitdi10RLz9vSHAxuh5MIqK1lJmHFxr2jVTt IzN1U+Di4jkmsSoTpZkqdzIa1JBJUzwFtAHTz1dLfjYqOemHs9Rl8RHDca1y+pSDc/VOsxhhcV3 wgkY4e6YtY5y3iFSQh/OTPJsgOXDvdb8QRDU8og0IugZ8Db7JcG/vYRxkjMRTQqefWCpzVn/cpg Ecdu5229gNu0UZA9IzsKLGkKR2y9wC2FSR X-Received: by 2002:a17:907:c287:b0:a46:52f5:494c with SMTP id tk7-20020a170907c28700b00a4652f5494cmr272975ejc.70.1710282356667; Tue, 12 Mar 2024 15:25:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYPlMKS9V+CM9++5Aja+vexRGnxVcAhBF9cNTTNOad7zvNlw8t9udKSnsfYgkN/6Rmo6bcEg== X-Received: by 2002:a17:907:c287:b0:a46:52f5:494c with SMTP id tk7-20020a170907c28700b00a4652f5494cmr272963ejc.70.1710282356233; Tue, 12 Mar 2024 15:25:56 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id gh16-20020a170906e09000b00a45380dfd09sm4216185ejb.105.2024.03.12.15.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:55 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:53 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 08/68] vdpa: add trace event for vhost_vdpa_net_load_mq Message-ID: <1c4eab477fb0aa5a039513c26dac63d3460e1b08.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu For better debuggability and observability. Message-Id: <1707910082-10243-10-git-send-email-si-wei.liu@oracle.com> Reviewed-by: Eugenio Pérez Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 2 ++ net/trace-events | 1 + 2 files changed, 3 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 2c95a98cc6..2254859dec 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -939,6 +939,8 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s, return 0; } + trace_vhost_vdpa_net_load_mq(s, n->curr_queue_pairs); + mq.virtqueue_pairs = cpu_to_le16(n->curr_queue_pairs); const struct iovec data = { .iov_base = &mq, diff --git a/net/trace-events b/net/trace-events index 88f56f2428..cda960f42b 100644 --- a/net/trace-events +++ b/net/trace-events @@ -28,3 +28,4 @@ colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u" vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u" vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num, int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r) "vdpa state: %p class: %u cmd: %u retval: %d" +vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpairs: %d" From patchwork Tue Mar 12 22:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ee1PggiJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8v2XXvz23qj for ; Wed, 13 Mar 2024 09:39:27 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZb-0004Ww-5A; Tue, 12 Mar 2024 18:26:15 -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 1rkAZW-0004UD-Oy for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:12 -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 1rkAZS-0004Ee-MX for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282365; 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: in-reply-to:in-reply-to:references:references; bh=bC0eTdSzwxwKSxJCZ+HWjFlnIeg3Of9nGwQJMYhFWrM=; b=ee1PggiJQJSFLAo1sI+zgoW8wOitr0I1Ev7isVEjsOjDVgFuv9jK7bvF6eUSh7fyJXBY4q kbJu+W1U1IMruAysmz9yGcrYnCh+CYpBVIc3WD+tIF45MIsbJY5Qf4sQpZq4O/uVvBBWi2 K1dwEEPv0u5fyNLfWk5vDSRG9SfrqiM= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-glI8KeiCPOWOtpPznw1Z7g-1; Tue, 12 Mar 2024 18:26:02 -0400 X-MC-Unique: glI8KeiCPOWOtpPznw1Z7g-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d45c7efcb0so8521191fa.1 for ; Tue, 12 Mar 2024 15:26:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282360; x=1710887160; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bC0eTdSzwxwKSxJCZ+HWjFlnIeg3Of9nGwQJMYhFWrM=; b=Xoys0SHzUUUT6804ypRXigLLiJ6i1prK60I0IQ+0I97oGtM5GHqusZ4p9vy+FVCczX 7jd8y9Ww7iobe5QpaGH1KrDyuu6cTZLXtL3KhRklII/Ty2SCbTJ5I9EfWiy9nNEP5PCn 2i02Ht5xbxlGD+cjFgox+6/GYwDr8c5FDfYUVD1LFSwEwUotV7SsmXuUfBW3hSMVw4HP OfQBsTG6V3ziYQ0E2mlLIJcI+hvJUBO+gVSQHJ8FB7GbImkEbDKYA4yQIlHrc53FrYVI 9Q95BoJt0aHh7d56Lb94+29jPB2PEM13UXUrG3qNGVywoJJpz5dl5oqMobsKwvOa2hlq MOuw== X-Gm-Message-State: AOJu0YwZpgjFIG/YzZz27TAEhBeGmGVdxKjnb8dfVAJ3LJHnLYDLhuDY 1qsklO01mjgpNioUfao0SKuu9BkicEnJ4NYzi6Xa+pJ9fxltZv227poCIzbnI/7wa+3A0nmlQKV KlOnlVejU/zSr/ipvR9t5ywDVUe5m0gd2+E5VXmEi1VBvUyrSvVV6EtkvvtlFQeWmWWjrGyqzHt wHopsRJ4xEWlA/0/M0yOVuoyEu88u9q4xm X-Received: by 2002:a05:651c:19a9:b0:2d4:2b05:a671 with SMTP id bx41-20020a05651c19a900b002d42b05a671mr7666107ljb.32.1710282359603; Tue, 12 Mar 2024 15:25:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAoIEyxTnZ9vjcVpxXXFeCb8/ssxZsQQlAHxBpPu2nwqEY8GXIzeBzrNE2FVCZr7MQ3HCRWw== X-Received: by 2002:a05:651c:19a9:b0:2d4:2b05:a671 with SMTP id bx41-20020a05651c19a900b002d42b05a671mr7666093ljb.32.1710282359035; Tue, 12 Mar 2024 15:25:59 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id j12-20020a170906474c00b00a45bd9ccb55sm4205619ejs.155.2024.03.12.15.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:25:58 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:56 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu Subject: [PULL 09/68] vdpa: define SVQ transitioning state for mode switching Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu Will be used in following patches. DISABLING(-1) means SVQ is being switched off to passthrough mode. ENABLING(1) means passthrough VQs are being switched to SVQ. DONE(0) means SVQ switching is completed. Message-Id: <1707910082-10243-11-git-send-email-si-wei.liu@oracle.com> Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-vdpa.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 8f54e5edd4..0a9575b469 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -30,6 +30,12 @@ typedef struct VhostVDPAHostNotifier { void *addr; } VhostVDPAHostNotifier; +typedef enum SVQTransitionState { + SVQ_TSTATE_DISABLING = -1, + SVQ_TSTATE_DONE, + SVQ_TSTATE_ENABLING +} SVQTransitionState; + /* Info shared by all vhost_vdpa device models */ typedef struct vhost_vdpa_shared { int device_fd; @@ -47,6 +53,9 @@ typedef struct vhost_vdpa_shared { /* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */ bool shadow_data; + + /* SVQ switching is in progress, or already completed? */ + SVQTransitionState svq_switching; } VhostVDPAShared; typedef struct vhost_vdpa { From patchwork Tue Mar 12 22:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RKGkadLC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSyG10cgz23qj for ; Wed, 13 Mar 2024 09:30:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZc-0004Xf-34; Tue, 12 Mar 2024 18:26:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZY-0004UG-AC for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:12 -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 1rkAZS-0004Eb-Lq for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282365; 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: in-reply-to:in-reply-to:references:references; bh=lAOsHoQ8Q+B9MtUklOYVBNfmlL6poKBOv9a1HTNc0Ww=; b=RKGkadLCEG/SgL8g/e74EWQ9HcaoMjGwz1biawuF3u3zzv4ftBPiu20kkqE1CFnSHNJAdY FUzcOOYMOQQj+Wn+y5xTjELR1t5v2vN11NwEjk+QUjHu4q2lminK3hErpqz5fZLPo1Gvpz ggLSwe71yvqxl7iSjR4vNb+Sc2z0Me8= 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-450-2yzKWk6MMfavFceh9OjiiQ-1; Tue, 12 Mar 2024 18:26:03 -0400 X-MC-Unique: 2yzKWk6MMfavFceh9OjiiQ-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a4655acf23dso4013666b.3 for ; Tue, 12 Mar 2024 15:26:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282362; x=1710887162; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lAOsHoQ8Q+B9MtUklOYVBNfmlL6poKBOv9a1HTNc0Ww=; b=iXx22IiV8mbuN17rvJpu0iNnw3zxKKpg1Aq3pePAroWDrKsB9l8cN4CGxAiDwN5XAZ naWjzD2NI20CfDk8SW/gJlq1tjUykOMa6oe2tx9feJkKHpb+j/lEseGuuM/pYem3C5GW wi8o2U8CcdSas7a+25YroN268Vy3mtM9aXs7JNJKp992ft/bjlGKafWfCZrh5sjxYNTF sPTCsOIAe6ruM3Ft/etpErIXzYD7F1IzjiFMReRB0sUauDtr8nVqYCTLi2mLp42l0/2A 1QhAplrypYgwB8X3IHcWVNRoesuQgqbTesjhj7jRIzl7jxwEbjbLqciITrbC6uuvFfvL KzWw== X-Gm-Message-State: AOJu0YylvdvUTRylwSctd5Wb3N/Ga52WIZDilt433IdUFJcHs/emQ2pe MH2xZ5KEyjs48p34iddURuZ85t+/iZjB1RWXorNHYb8bzMQv+ugKwssSBrfpZn0HGFpmV/YSEeH n9dT4wSg3qC1fpwQrpXqKU2SfXPO+f/FQMv49P+LvDW5tEHkmYhRg5qsdByTDULiUefR05zdEwy +HBcGqdmNzS/xQ0MHzA8MieIA0m65Qxxak X-Received: by 2002:a17:906:6442:b0:a45:a7e5:fb98 with SMTP id l2-20020a170906644200b00a45a7e5fb98mr3555083ejn.27.1710282362140; Tue, 12 Mar 2024 15:26:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELeuHmFBCuFVOPXX9dQq9GCtGMvqGuR2zAxARIMBvnfY3ka2AEo6kKYVOKYgfyvzfBIhiuVQ== X-Received: by 2002:a17:906:6442:b0:a45:a7e5:fb98 with SMTP id l2-20020a170906644200b00a45a7e5fb98mr3555070ejn.27.1710282361779; Tue, 12 Mar 2024 15:26:01 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id t13-20020a170906a10d00b00a4605a343ffsm3829944ejy.21.2024.03.12.15.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:01 -0700 (PDT) Date: Tue, 12 Mar 2024 18:25:59 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Jason Wang Subject: [PULL 10/68] vdpa: indicate transitional state for SVQ switching Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu svq_switching indicates the transitional state whether or not SVQ mode switching is in progress, and towards which direction. Add the neccessary state around where the switching would take place. Message-Id: <1707910082-10243-12-git-send-email-si-wei.liu@oracle.com> Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 2254859dec..5f06c39f63 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -324,6 +324,8 @@ static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable) data_queue_pairs = n->multiqueue ? n->max_queue_pairs : 1; cvq = virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ) ? n->max_ncs - n->max_queue_pairs : 0; + v->shared->svq_switching = enable ? + SVQ_TSTATE_ENABLING : SVQ_TSTATE_DISABLING; /* * TODO: vhost_net_stop does suspend, get_base and reset. We can be smarter * in the future and resume the device if read-only operations between @@ -336,6 +338,7 @@ static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enable) if (unlikely(r < 0)) { error_report("unable to start vhost net: %s(%d)", g_strerror(-r), -r); } + v->shared->svq_switching = SVQ_TSTATE_DONE; } static int vdpa_net_migration_state_notifier(NotifierWithReturn *notifier, From patchwork Tue Mar 12 22:26:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W4YaKiBl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSyF4M2yz1ydl for ; Wed, 13 Mar 2024 09:30:13 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZe-0004YP-O5; Tue, 12 Mar 2024 18:26:18 -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 1rkAZZ-0004Vp-Bb for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZW-0004Eo-HU for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282368; 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=MrO3S6qkYN4YcSINTZDLnuyG2BO2ocVcVpe9efTc8ao=; b=W4YaKiBlBADFfONC+I1KE5pzUHkHj1gBlk2WRiPC6AsP/OPX8URxgQwlFWb+gEYq/Zd8dt 2fiqIZT4A5sOjL/zyNy2DX6W8Q+lZfr/l2nZCH5y5a7RjsABkF2NvDRwHwFoS3RYiqTv1f de7eXCkEFt1dH2bom3wqYQzlpLJ8R94= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-114-ewRgsndZNRGERW0y8Ny4vg-1; Tue, 12 Mar 2024 18:26:07 -0400 X-MC-Unique: ewRgsndZNRGERW0y8Ny4vg-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2d32656e8c2so3717401fa.2 for ; Tue, 12 Mar 2024 15:26:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282365; x=1710887165; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MrO3S6qkYN4YcSINTZDLnuyG2BO2ocVcVpe9efTc8ao=; b=PX1JwgkRikJ9NEqSIUIF9hptZOaGKS+JN6hpz/yk8XhsZp7kK+yID+und11rmyhpln DPhUajbCV2a5ufZi51WuGKHreMW5TGaza3LnPuCDqulSkkR7/2pfypnJCWk6ibukujzJ xI4GcdZUoqSFC/BbrNmZZm0zMSyCo/E7sqjnN1uLHrFk3Ra/hCQx7w1wNrpKMCN6sfNV oCMWf/YK86zq/C2wZ+GfMBa95JuEwGJD2v+NasntjLnNxhquPNAu2gSNzrbpL0BLnhOy msGOK9KykSCB9XhflFTSk/FL3TzQaIRanF2gHf47L4F9Pzxk84BDgklGKfpAvnoEvctR bRpQ== X-Gm-Message-State: AOJu0Yy4OB1n7x8nwBS8G2bdbYdYCOSaiFxlDZmQfkGgw1pEEt6++y1d Hhvcqj/DVNQdg1DszWil5DVgpxvxEs28D1n7hONC8XFgFY3sq3vqvBJnzCHWdhGrBAE1GJhMkMJ Xew+dFixSYaRIcwLY6h4pfSQNBfvTmzlk4S5oTMiofAvgDd2uqJst8Le6YMhg8rLnLWisQYodQE G2hcdkwILKEXX5VN7chIMx0Edmn/NUZkqG X-Received: by 2002:a05:651c:1423:b0:2d4:68b8:adcf with SMTP id u35-20020a05651c142300b002d468b8adcfmr735454lje.5.1710282364934; Tue, 12 Mar 2024 15:26:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEl9z3lHOJqTNEGKEAgsRcik+9rCSIiBIn54XC/7Jl87Lqax72LCf95f8+2QGQXXWgxXrMkyg== X-Received: by 2002:a05:651c:1423:b0:2d4:68b8:adcf with SMTP id u35-20020a05651c142300b002d468b8adcfmr735435lje.5.1710282364476; Tue, 12 Mar 2024 15:26:04 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id s21-20020a50ab15000000b00568699d4b83sm1686322edc.44.2024.03.12.15.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:04 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:01 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Si-Wei Liu , Eugenio =?utf-8?b?UMOpcmV6?= , Jason Wang Subject: [PULL 11/68] vdpa: fix network breakage after cancelling migration Message-ID: <9ed62809b6e28ab0d887aff502ed24f77f1edafd.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Si-Wei Liu Fix an issue where cancellation of ongoing migration ends up with no network connectivity. When canceling migration, SVQ will be switched back to the passthrough mode, but the right call fd is not programed to the device and the svq's own call fd is still used. At the point of this transitioning period, the shadow_vqs_enabled hadn't been set back to false yet, causing the installation of call fd inadvertently bypassed. Message-Id: <1707910082-10243-13-git-send-email-si-wei.liu@oracle.com> Fixes: a8ac88585da1 ("vhost: Add Shadow VirtQueue call forwarding capabilities") Cc: Eugenio Pérez Acked-by: Jason Wang Signed-off-by: Si-Wei Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index fc84cf6ec6..c968278e70 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1456,7 +1456,15 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, /* Remember last call fd because we can switch to SVQ anytime. */ vhost_svq_set_svq_call_fd(svq, file->fd); - if (v->shadow_vqs_enabled) { + /* + * When SVQ is transitioning to off, shadow_vqs_enabled has + * not been set back to false yet, but the underlying call fd + * will have to switch back to the guest notifier to signal the + * passthrough virtqueues. In other situations, SVQ's own call + * fd shall be used to signal the device model. + */ + if (v->shadow_vqs_enabled && + v->shared->svq_switching != SVQ_TSTATE_DISABLING) { return 0; } From patchwork Tue Mar 12 22:26:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SjFXPfEc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTCB4jMWz1yWt for ; Wed, 13 Mar 2024 09:41:26 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZf-0004Yh-Am; Tue, 12 Mar 2024 18:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZa-0004Wk-Kv for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:14 -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 1rkAZX-0004F6-UJ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282371; 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: in-reply-to:in-reply-to:references:references; bh=gyYIKMrI3SRF/ysRxD0KwjA2vDDvjUVwVWXBG4PxT30=; b=SjFXPfEcL/QvRCW90UOzsGbJ9UkXsO68DQw5G7PAujz0+ZpzUYMphTFaOFThUnvZilo/gr QF2T+Rodtm/mS97veBO8Sc3JcqT0/ts+W8b/9aCB1Yh0Wb/39SZKatKkYL7uKiGdKiVHuq v8mRQt0s7nCzB/Cl4uWzJdq1CM7psPo= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-PCvCupVZMhiV2L9ewoJ-5Q-1; Tue, 12 Mar 2024 18:26:09 -0400 X-MC-Unique: PCvCupVZMhiV2L9ewoJ-5Q-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-56844c6a2cbso2298288a12.3 for ; Tue, 12 Mar 2024 15:26:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282368; x=1710887168; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gyYIKMrI3SRF/ysRxD0KwjA2vDDvjUVwVWXBG4PxT30=; b=uo7ZWRoh9jSDUmFkKLRF+sCuHi3az57m8WmrmG/HCGQaJF0Rq19StMGyCjCiCvS/Zp PCbpbXW16gi5/SMC6I3ryyr9TIrS8ZuwMyS2PcQQevG9sOFFDEQ2s42YOhAXF0x6zcoD aJ2wbtrUK7V0PRXdjznk/SiTKx66UrsTkOG8AClFg+LIy88WeovbvBMj+udZQm5ayGuo AUcOaJjW52TxLjTfRvlfIxP9Gr9wBcEPFROJBT/q73z0z185mI07JmTFE5p4DuIMO22d OegnEqnBPyKmWahArWr6tv4XSAfjfCPu8VLz9ann2fG1cvfdnOHE/pCOTIL/NDFSbfAW MOtg== X-Gm-Message-State: AOJu0Yxrj4XlsCnOLzAdF0+4W7t9Lly/Z4Hy8gZotZ6yKWBXb1c022rn PMgQ6Ryz66w5E40qBITkOSfcrBukA3isYb/JX9wy1NLGrYP3j6QbZ7K29roiISyrF5lmFRn4zgP M/NSe2JBfuW/dv7gktJgmMK5ehmRwb6Tf2WlM0EoSBIUwk3zJjQ9GqKyW2i/ZjPEqHAzyBwXZFQ 8W53N7OEIZCiGhcMLCiK44VbUD4+qbbKhz X-Received: by 2002:a17:907:1688:b0:a46:13f3:eb84 with SMTP id cx8-20020a170907168800b00a4613f3eb84mr1254240ejd.0.1710282367955; Tue, 12 Mar 2024 15:26:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGewxjL+ux1V0g6HyHL9tz9M5FkwSzKmuAHQY+jVmJejvtwGqAjEYY1tixuvxc3snwC69XBNQ== X-Received: by 2002:a17:907:1688:b0:a46:13f3:eb84 with SMTP id cx8-20020a170907168800b00a4613f3eb84mr1254227ejd.0.1710282367404; Tue, 12 Mar 2024 15:26:07 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id be10-20020a1709070a4a00b00a461d2a3374sm2892729ejc.47.2024.03.12.15.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:06 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:04 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 12/68] libvhost-user: Dynamically allocate memory for memory slots Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's prepare for increasing VHOST_USER_MAX_RAM_SLOTS by dynamically allocating dev->regions. We don't have any ABI guarantees (not dynamically linked), so we can simply change the layout of VuDev. Let's zero out the memory, just as we used to do. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-2-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.h | 2 +- subprojects/libvhost-user/libvhost-user.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h index c2352904f0..c882b4e3a2 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -398,7 +398,7 @@ typedef struct VuDevInflightInfo { struct VuDev { int sock; uint32_t nregions; - VuDevRegion regions[VHOST_USER_MAX_RAM_SLOTS]; + VuDevRegion *regions; VuVirtq *vq; VuDevInflightInfo inflight_info; int log_call_fd; diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a3b158c671..360c5366d6 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -2171,6 +2171,8 @@ vu_deinit(VuDev *dev) free(dev->vq); dev->vq = NULL; + free(dev->regions); + dev->regions = NULL; } bool @@ -2205,9 +2207,18 @@ vu_init(VuDev *dev, dev->backend_fd = -1; dev->max_queues = max_queues; + dev->regions = malloc(VHOST_USER_MAX_RAM_SLOTS * sizeof(dev->regions[0])); + if (!dev->regions) { + DPRINT("%s: failed to malloc mem regions\n", __func__); + return false; + } + memset(dev->regions, 0, VHOST_USER_MAX_RAM_SLOTS * sizeof(dev->regions[0])); + dev->vq = malloc(max_queues * sizeof(dev->vq[0])); if (!dev->vq) { DPRINT("%s: failed to malloc virtqueues\n", __func__); + free(dev->regions); + dev->regions = NULL; return false; } From patchwork Tue Mar 12 22:26:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W/kTga2Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTC746dkz23rC for ; Wed, 13 Mar 2024 09:41:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZf-0004Ym-Sc; Tue, 12 Mar 2024 18:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZd-0004Xx-O8 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:17 -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 1rkAZc-0004Fk-1y for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282375; 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: in-reply-to:in-reply-to:references:references; bh=MLCjiyp8QnFBUxFc7qME1kR1X9QPWEmOeOJtA7Cligg=; b=W/kTga2ZBmVo5z7uF2aHrh14minwS0QojcU3+SP9JBOqUkgxA8S/5HQkVn2WmPoVOAp/0n iMks6wW4jA5bvU48G6TuHQMV6H8o6wvAsoto4BcyY9831+UTwr9mPK2c1edHo47W+erzT/ rSRMVDvfoehrX7We0wC9Rst4FrPmVOk= 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-649-xhJqIxGEPBuOO7jszLO39g-1; Tue, 12 Mar 2024 18:26:13 -0400 X-MC-Unique: xhJqIxGEPBuOO7jszLO39g-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a448cfe2266so493964066b.2 for ; Tue, 12 Mar 2024 15:26:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282372; x=1710887172; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MLCjiyp8QnFBUxFc7qME1kR1X9QPWEmOeOJtA7Cligg=; b=gFrl9nsefcsYrp5/g10Wp56JoiOHX/TkadDZDqumprHqBM7bPbCt8wsZX5kpFVcCYC CLWSLC6nCFRAwNpqjs3JjY962NbhJrf7vWCNYD0KW41iEIDZL9qk7y+cLADiWkgqTU0t X3aVRz6EcniMi9nPGVrF3uAmyzwViSgAlee9JO8RBIlIb//hZF6TMaXkg4D7jdsBowo2 mPHzavE8bDRlHldPhtyci3fLlLs4t1QurpRApQPUMQamndeHQGEpXU7CJHvZe5utufo9 etQsDu8rO7uGreCGnZKPXoePlTR/mAC9bP1cSCSv3hkedQnMNke2sw+wqG8F8RfPPhAI Xk/g== X-Gm-Message-State: AOJu0YzQmA0yiJ1xFaFNoyew/LhBOGWGPjFkHkMJ5XPHurS5XSQJuuS8 K1qeHTdqGMkwrD0cv+4KN+WJMLruceyOWhx+YKwVYf+biHUP/n+fS5/d6IZ7BTVHeDA6y6w9pHh pTeudu9niQfvcVPZ7aeb3a1FkiJiHuHGkkvxjY9zzCwh6i7vLFKWhv1c4AbbrSMPLpECe8JW6G6 JYhv2QSD4Bj4cCWjmW/Nuwf0f0eXiyteUP X-Received: by 2002:a17:907:1004:b0:a44:1e32:a503 with SMTP id ox4-20020a170907100400b00a441e32a503mr7150146ejb.22.1710282371786; Tue, 12 Mar 2024 15:26:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES1LxCqbH1uEMSvTyEC79+6VedJiYlHK04C0if/XXiZLQnAeB/scJCjQwYTr0SnPXLLP1A3g== X-Received: by 2002:a17:907:1004:b0:a44:1e32:a503 with SMTP id ox4-20020a170907100400b00a441e32a503mr7150131ejb.22.1710282371182; Tue, 12 Mar 2024 15:26:11 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id lg12-20020a170906f88c00b00a4432543b21sm4217408ejb.198.2024.03.12.15.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:10 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:07 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 13/68] libvhost-user: Bump up VHOST_USER_MAX_RAM_SLOTS to 509 Message-ID: <0fa6344c90a093e2421ecac3c96a8823ad74ee89.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's support up to 509 mem slots, just like vhost in the kernel usually does and the rust vhost-user implementation recently [1] started doing. This is required to properly support memory hotplug, either using multiple DIMMs (ACPI supports up to 256) or using virtio-mem. The 509 used to be the KVM limit, it supported 512, but 3 were used for internal purposes. Currently, KVM supports more than 512, but it usually doesn't make use of more than ~260 (i.e., 256 DIMMs + boot memory), except when other memory devices like PCI devices with BARs are used. So, 509 seems to work well for vhost in the kernel. Details can be found in the QEMU change that made virtio-mem consume up to 256 mem slots across all virtio-mem devices. [2] 509 mem slots implies 509 VMAs/mappings in the worst case (even though, in practice with virtio-mem we won't be seeing more than ~260 in most setups). With max_map_count under Linux defaulting to 64k, 509 mem slots still correspond to less than 1% of the maximum number of mappings. There are plenty left for the application to consume. [1] https://github.com/rust-vmm/vhost/pull/224 [2] https://lore.kernel.org/all/20230926185738.277351-1-david@redhat.com/ Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-3-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h index c882b4e3a2..deb40e77b3 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -31,10 +31,12 @@ #define VHOST_MEMORY_BASELINE_NREGIONS 8 /* - * Set a reasonable maximum number of ram slots, which will be supported by - * any architecture. + * vhost in the kernel usually supports 509 mem slots. 509 used to be the + * KVM limit, it supported 512, but 3 were used for internal purposes. This + * limit is sufficient to support many DIMMs and virtio-mem in + * "dynamic-memslots" mode. */ -#define VHOST_USER_MAX_RAM_SLOTS 32 +#define VHOST_USER_MAX_RAM_SLOTS 509 #define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) From patchwork Tue Mar 12 22:26:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911390 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=etA7GxpG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSvg5HGHz1yWt for ; Wed, 13 Mar 2024 09:27:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZi-0004ZB-B8; Tue, 12 Mar 2024 18:26:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZf-0004Yi-Jk for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:19 -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 1rkAZd-0004G3-WB for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282377; 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: in-reply-to:in-reply-to:references:references; bh=uK1DhLEmCwAUM4WVYh1w+A/omwtvVrpMmMYYh4o/i+I=; b=etA7GxpGGihpb+lC2svpvzqpycddIJVXpMhvAuneJ8xz1Q5XH3b1YlWckAeH0pNq2iSCIA cW0c2vRMIeXNa/ddTonBiVw9VosEDdyQ1penyFGpxggEDEbhXosl8k6MQ5x8zml7JMeqfg 2ltDOHSqGjCZXqi8hgTy53d5i9X90Dw= 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-482-lWYgiSLkM16maHv1DA4wWg-1; Tue, 12 Mar 2024 18:26:16 -0400 X-MC-Unique: lWYgiSLkM16maHv1DA4wWg-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5684345c0ebso290142a12.1 for ; Tue, 12 Mar 2024 15:26:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282374; x=1710887174; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uK1DhLEmCwAUM4WVYh1w+A/omwtvVrpMmMYYh4o/i+I=; b=Dvuw+zTN4L0yDNopNqe3/o60pk9vNJPLGcyM32/YUH0/j5SKL85+OSzILZ9nx3Zet/ Ngf/UrZIsXqwOGX4ccEjvSTub2vPuRakpP+2kxX0Y8EloIHYcR1fUtSz0ax6KLeSRl4n ey6roKmzu67ih7x2R+1uzZrMpv/N/owH5PE5pU8fWseyu6RCZq1f2U7YlDsvFnVJbO9l HajGi4taZD0OJjzwXx5l1UMCmiF8L/NrKl+vvAzR9/dDzH6OzYsQYZTPfdWN41A8Ipeg XEPXE00obgRUXGs+5uW9O4753qoruj7VJMPDjt/r+IBsvL4vUPAzC0wZlq+IocEbiUp0 4K3g== X-Gm-Message-State: AOJu0Yy9aznRE3GzNU0sWSM7YvkgqiykiS9ffHniwTg0SD8igx/gpfMP qNMC30iz00JoWU6LHyy5RJwU9ZApDuO6hK8gnKt+A4cyVoIf4H8XM+UB64Pb6AaCQ4JdbA9EEsf cfWC4FEFy14sW7bUdc0G8OTAvWlvl9b2SMO4jXr7ffy/HU3e+ZDmLApo5wh03TTXTu83z2SNSMX zdqTHXzKuiEGCd411/FkpmMzXAIP262b0N X-Received: by 2002:a50:8a9d:0:b0:568:145a:4a22 with SMTP id j29-20020a508a9d000000b00568145a4a22mr860130edj.4.1710282374609; Tue, 12 Mar 2024 15:26:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFm2A3qaPDQU67tgC1/XF2+5KDNl9m2TgWcYz9HmefGM0Eg8eHZzAght4sV3YThZwA0hiE6Q== X-Received: by 2002:a50:8a9d:0:b0:568:145a:4a22 with SMTP id j29-20020a508a9d000000b00568145a4a22mr860108edj.4.1710282374252; Tue, 12 Mar 2024 15:26:14 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id et3-20020a056402378300b005687a473947sm720658edb.28.2024.03.12.15.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:13 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:11 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 14/68] libvhost-user: Factor out removing all mem regions Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's factor it out. Note that the check for MAP_FAILED was wrong as we never set mmap_addr if mmap() failed. We'll remove the NULL check separately. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-4-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 360c5366d6..e4907dfc26 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -240,6 +240,22 @@ qva_to_va(VuDev *dev, uint64_t qemu_addr) return NULL; } +static void +vu_remove_all_mem_regs(VuDev *dev) +{ + unsigned int i; + + for (i = 0; i < dev->nregions; i++) { + VuDevRegion *r = &dev->regions[i]; + void *ma = (void *)(uintptr_t)r->mmap_addr; + + if (ma) { + munmap(ma, r->size + r->mmap_offset); + } + } + dev->nregions = 0; +} + static void vmsg_close_fds(VhostUserMsg *vmsg) { @@ -1003,14 +1019,7 @@ vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg) unsigned int i; VhostUserMemory m = vmsg->payload.memory, *memory = &m; - for (i = 0; i < dev->nregions; i++) { - VuDevRegion *r = &dev->regions[i]; - void *ma = (void *) (uintptr_t) r->mmap_addr; - - if (ma) { - munmap(ma, r->size + r->mmap_offset); - } - } + vu_remove_all_mem_regs(dev); dev->nregions = memory->nregions; if (dev->postcopy_listening) { @@ -2112,14 +2121,7 @@ vu_deinit(VuDev *dev) { unsigned int i; - for (i = 0; i < dev->nregions; i++) { - VuDevRegion *r = &dev->regions[i]; - void *m = (void *) (uintptr_t) r->mmap_addr; - if (m != MAP_FAILED) { - munmap(m, r->size + r->mmap_offset); - } - } - dev->nregions = 0; + vu_remove_all_mem_regs(dev); for (i = 0; i < dev->max_queues; i++) { VuVirtq *vq = &dev->vq[i]; From patchwork Tue Mar 12 22:26:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MrH8KAAf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT0q4SyDz1ydl for ; Wed, 13 Mar 2024 09:32:27 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZn-0004aJ-NY; Tue, 12 Mar 2024 18:26:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZj-0004Zo-An for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:25 -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 1rkAZh-0004GU-ND for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282381; 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: in-reply-to:in-reply-to:references:references; bh=C3gI7KDqXQ5rJjw/W3xZ/HO2un4Jd+r+mgG1cVGay/M=; b=MrH8KAAfG3MhI/RZcrGm6BL9i7bgSRNRmRw0NsYNLa5fmr74aHnFQOLzQOxw8iQtQwWaH9 FmL84UpZlRcK72Cmzzqjv+pUk5PUepCFHaCsUxNQPUAobd245HErjAnlUh+wxgZP3GnDG4 5d5Af+wYQsvbW9oe2VD4JuhaM/3FDrE= 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-395-lEcBUeg-Nv6LRmcvceGBBQ-1; Tue, 12 Mar 2024 18:26:19 -0400 X-MC-Unique: lEcBUeg-Nv6LRmcvceGBBQ-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a449be9db59so337053366b.1 for ; Tue, 12 Mar 2024 15:26:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282378; x=1710887178; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=C3gI7KDqXQ5rJjw/W3xZ/HO2un4Jd+r+mgG1cVGay/M=; b=EMbODWtGo+OM3gfubJ3DL+DXIbI6lGtwLzkYR7UIKRSQZi4aRGE47EAmlst90BwDbu Fv+OPuhMo6a00yLtAiIHDOnE5rnHRxo/FF+PYYig7sJW+Kb4/iETYJlT/fN4VwRqSRQU 5hzOBQEjbnpyFD+GBPAbJtXEjMKjblabVN7rdXmiyFd1gk1hALfOD9smJUGgJKlF8mFU qENtyR1g6+nGv2sPReHUt1TcrnvcPyae0/9PN1Y+S/hALZNFRK28jpNMC/g3EUaqzp/y cNlGLuvmw00KPyMBf2JjavdrOxcPz4gdvu4LF7Ttl3kE18+22F1jzeq8z0dQw6HN3Fa1 ZA1g== X-Gm-Message-State: AOJu0YyZOIk04Pc438FTin1OhZPreQrtD6dmSvaxpzSif7rP2Ma1UEx3 Rk4ZBBuNwDnTnC8tCS866Ew/uhCATnY63J7BFP+A0U1ZsHPj36TomdulptKCA0j4lXPNKmpu+uI lGPhrANOujSun2LsnJnzuMij57tcgOBs0JxdJdBo55czHIYG7Oo4W8O2rzzQrHc3nvWFxaIk+Vv VZI0gzo3QpxW3W0bbvrTPI2/NUwuHSWL/j X-Received: by 2002:a17:907:1606:b0:a45:efb1:d4d8 with SMTP id cw6-20020a170907160600b00a45efb1d4d8mr9023424ejd.53.1710282377995; Tue, 12 Mar 2024 15:26:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhc5iBBmaqN8PXAOg2HvOoy0Hk+iVvTJ+DcQyoxX0LLfqkbxsOogKZD1/2h+Sc4hdIXRpBog== X-Received: by 2002:a17:907:1606:b0:a45:efb1:d4d8 with SMTP id cw6-20020a170907160600b00a45efb1d4d8mr9023406ejd.53.1710282377462; Tue, 12 Mar 2024 15:26:17 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id zn6-20020a170906ff0600b00a3e643e61e1sm4226442ejb.214.2024.03.12.15.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:16 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:14 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 15/68] libvhost-user: Merge vu_set_mem_table_exec_postcopy() into vu_set_mem_table_exec() Message-ID: <05a58ce47167a95b554f9afc47f78f267c394c6e.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's reduce some code duplication and prepare for further changes. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-5-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 119 +++++++--------------- 1 file changed, 39 insertions(+), 80 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index e4907dfc26..a7bd7de3cd 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -937,95 +937,23 @@ vu_get_shared_object(VuDev *dev, VhostUserMsg *vmsg) } static bool -vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg) +vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg) { - unsigned int i; VhostUserMemory m = vmsg->payload.memory, *memory = &m; - dev->nregions = memory->nregions; + int prot = PROT_READ | PROT_WRITE; + unsigned int i; - DPRINT("Nregions: %u\n", memory->nregions); - for (i = 0; i < dev->nregions; i++) { - void *mmap_addr; - VhostUserMemoryRegion *msg_region = &memory->regions[i]; - VuDevRegion *dev_region = &dev->regions[i]; - - DPRINT("Region %d\n", i); - DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", - msg_region->guest_phys_addr); - DPRINT(" memory_size: 0x%016"PRIx64"\n", - msg_region->memory_size); - DPRINT(" userspace_addr 0x%016"PRIx64"\n", - msg_region->userspace_addr); - DPRINT(" mmap_offset 0x%016"PRIx64"\n", - msg_region->mmap_offset); - - dev_region->gpa = msg_region->guest_phys_addr; - dev_region->size = msg_region->memory_size; - dev_region->qva = msg_region->userspace_addr; - dev_region->mmap_offset = msg_region->mmap_offset; - - /* We don't use offset argument of mmap() since the - * mapped address has to be page aligned, and we use huge - * pages. + if (dev->postcopy_listening) { + /* * In postcopy we're using PROT_NONE here to catch anyone * accessing it before we userfault */ - mmap_addr = mmap(0, dev_region->size + dev_region->mmap_offset, - PROT_NONE, MAP_SHARED | MAP_NORESERVE, - vmsg->fds[i], 0); - - if (mmap_addr == MAP_FAILED) { - vu_panic(dev, "region mmap error: %s", strerror(errno)); - } else { - dev_region->mmap_addr = (uint64_t)(uintptr_t)mmap_addr; - DPRINT(" mmap_addr: 0x%016"PRIx64"\n", - dev_region->mmap_addr); - } - - /* Return the address to QEMU so that it can translate the ufd - * fault addresses back. - */ - msg_region->userspace_addr = (uintptr_t)(mmap_addr + - dev_region->mmap_offset); - close(vmsg->fds[i]); + prot = PROT_NONE; } - /* Send the message back to qemu with the addresses filled in */ - vmsg->fd_num = 0; - if (!vu_send_reply(dev, dev->sock, vmsg)) { - vu_panic(dev, "failed to respond to set-mem-table for postcopy"); - return false; - } - - /* Wait for QEMU to confirm that it's registered the handler for the - * faults. - */ - if (!dev->read_msg(dev, dev->sock, vmsg) || - vmsg->size != sizeof(vmsg->payload.u64) || - vmsg->payload.u64 != 0) { - vu_panic(dev, "failed to receive valid ack for postcopy set-mem-table"); - return false; - } - - /* OK, now we can go and register the memory and generate faults */ - (void)generate_faults(dev); - - return false; -} - -static bool -vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg) -{ - unsigned int i; - VhostUserMemory m = vmsg->payload.memory, *memory = &m; - vu_remove_all_mem_regs(dev); dev->nregions = memory->nregions; - if (dev->postcopy_listening) { - return vu_set_mem_table_exec_postcopy(dev, vmsg); - } - DPRINT("Nregions: %u\n", memory->nregions); for (i = 0; i < dev->nregions; i++) { void *mmap_addr; @@ -1051,8 +979,7 @@ vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg) * mapped address has to be page aligned, and we use huge * pages. */ mmap_addr = mmap(0, dev_region->size + dev_region->mmap_offset, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, - vmsg->fds[i], 0); + prot, MAP_SHARED | MAP_NORESERVE, vmsg->fds[i], 0); if (mmap_addr == MAP_FAILED) { vu_panic(dev, "region mmap error: %s", strerror(errno)); @@ -1062,9 +989,41 @@ vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg) dev_region->mmap_addr); } + if (dev->postcopy_listening) { + /* + * Return the address to QEMU so that it can translate the ufd + * fault addresses back. + */ + msg_region->userspace_addr = (uintptr_t)(mmap_addr + + dev_region->mmap_offset); + } close(vmsg->fds[i]); } + if (dev->postcopy_listening) { + /* Send the message back to qemu with the addresses filled in */ + vmsg->fd_num = 0; + if (!vu_send_reply(dev, dev->sock, vmsg)) { + vu_panic(dev, "failed to respond to set-mem-table for postcopy"); + return false; + } + + /* + * Wait for QEMU to confirm that it's registered the handler for the + * faults. + */ + if (!dev->read_msg(dev, dev->sock, vmsg) || + vmsg->size != sizeof(vmsg->payload.u64) || + vmsg->payload.u64 != 0) { + vu_panic(dev, "failed to receive valid ack for postcopy set-mem-table"); + return false; + } + + /* OK, now we can go and register the memory and generate faults */ + (void)generate_faults(dev); + return false; + } + for (i = 0; i < dev->max_queues; i++) { if (dev->vq[i].vring.desc) { if (map_ring(dev, &dev->vq[i])) { From patchwork Tue Mar 12 22:26:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EQpyx3V2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTCB0BP7z23qj for ; Wed, 13 Mar 2024 09:41:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZq-0004fu-Ud; Tue, 12 Mar 2024 18:26:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZo-0004ad-0z for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26: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 1rkAZl-0004Gj-B4 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282384; 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: in-reply-to:in-reply-to:references:references; bh=GfiNxS0IofyqjxunoDfGXaaQJGBOsSjO5kFks3IxXfg=; b=EQpyx3V2U7nH3XGW/G+LLUl1w1GYtC4FdrpbWLtoirR7fRbvaH0GeCBpcwZ+8bFWDHW1Ov aVyWzNzE1Qvdr0/tal1sqWEE7MQtXtFqWYEKaVU4HkKOTU2e5hIYcP6fUsegace2f4ATlU JtdCTes1gAJFzrqfvjCt6W1GzdZ+Q28= 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-235-bEJOzdDTOpufj75vcQAnEg-1; Tue, 12 Mar 2024 18:26:23 -0400 X-MC-Unique: bEJOzdDTOpufj75vcQAnEg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a35ef7abe08so328448566b.2 for ; Tue, 12 Mar 2024 15:26:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282381; x=1710887181; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GfiNxS0IofyqjxunoDfGXaaQJGBOsSjO5kFks3IxXfg=; b=Xrwq/lAMeeUMrin2Fa6S+kuTy2ZIUlvq9mRbagLfjo7clRTUpPZjV0NtilKnjVTAws Eo3SJX8nzPMbx9FaFcx7pXxj2OTN4Vogf0pOe8mckriqAC/Y1euKgRaaFAPUJbl7ajKn PmS3SONBQKVoR9aITZIPy0tiyfON0/u3W2JH3vVB97GenIyld90z4V0a7cOXg6KZ5hL6 hw4BoZ9RWDouEIHU/VPSdwih7NTomw0nMBBdXs0+UXR0QtOrSXdy8XqAHGcf4XJ2c1OZ Q47EY+5iadcqCCFhCioayS8CjYv5grxCqzNflxT6zaxyDZlDyhCOF7PQDKpTPUNrkz7V 8DIg== X-Gm-Message-State: AOJu0YwypuAol9LLmGi+1H07neBpRLNriLMfAw89R63Ki6uAajJcMOgb jK5r5zqskgchnJkqH2ptBVcVOLmCIWd3l43agRdU90TpFnrUun3CwgqnvVMm3aEtqpj8QEG08VA RYZtOny5VLqJ87tEriaqX/exrEgBJ7VxSzD6uDFuh+3Tdvgycd/25z2i3AFtHDwB8w4ARA88DNC U1PAhP56dpZ9xX8H4tMB8K6Um/UYDvF1gE X-Received: by 2002:a17:906:285a:b0:a44:b9e0:8592 with SMTP id s26-20020a170906285a00b00a44b9e08592mr5910877ejc.8.1710282381295; Tue, 12 Mar 2024 15:26:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFG+tBRXmTA4GkqOdV3hFiwR5qeOq5fj2yW9+TesCbrbHagKJBG+glQW9tJVNkB6s69QNkcJA== X-Received: by 2002:a17:906:285a:b0:a44:b9e0:8592 with SMTP id s26-20020a170906285a00b00a44b9e08592mr5910861ejc.8.1710282380782; Tue, 12 Mar 2024 15:26:20 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id x17-20020a1709064bd100b00a44f6ce3e7fsm4244893ejv.77.2024.03.12.15.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:20 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:17 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 16/68] libvhost-user: Factor out adding a memory region Message-ID: <93fec23d8cecebf0e6917044a0c1635df20e350d.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's factor it out, reducing quite some code duplication and perparing for further changes. If we fail to mmap a region and panic, we now simply don't add that (broken) region. Note that we now increment dev->nregions as we are successfully adding memory regions, and don't increment dev->nregions if anything went wrong. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-6-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 168 ++++++++-------------- 1 file changed, 60 insertions(+), 108 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index a7bd7de3cd..f43b5096d0 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -256,6 +256,61 @@ vu_remove_all_mem_regs(VuDev *dev) dev->nregions = 0; } +static void +_vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) +{ + int prot = PROT_READ | PROT_WRITE; + VuDevRegion *r; + void *mmap_addr; + + DPRINT("Adding region %d\n", dev->nregions); + DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", + msg_region->guest_phys_addr); + DPRINT(" memory_size: 0x%016"PRIx64"\n", + msg_region->memory_size); + DPRINT(" userspace_addr: 0x%016"PRIx64"\n", + msg_region->userspace_addr); + DPRINT(" mmap_offset: 0x%016"PRIx64"\n", + msg_region->mmap_offset); + + if (dev->postcopy_listening) { + /* + * In postcopy we're using PROT_NONE here to catch anyone + * accessing it before we userfault + */ + prot = PROT_NONE; + } + + /* + * We don't use offset argument of mmap() since the mapped address has + * to be page aligned, and we use huge pages. + */ + mmap_addr = mmap(0, msg_region->memory_size + msg_region->mmap_offset, + prot, MAP_SHARED | MAP_NORESERVE, fd, 0); + if (mmap_addr == MAP_FAILED) { + vu_panic(dev, "region mmap error: %s", strerror(errno)); + return; + } + DPRINT(" mmap_addr: 0x%016"PRIx64"\n", + (uint64_t)(uintptr_t)mmap_addr); + + r = &dev->regions[dev->nregions]; + r->gpa = msg_region->guest_phys_addr; + r->size = msg_region->memory_size; + r->qva = msg_region->userspace_addr; + r->mmap_addr = (uint64_t)(uintptr_t)mmap_addr; + r->mmap_offset = msg_region->mmap_offset; + dev->nregions++; + + if (dev->postcopy_listening) { + /* + * Return the address to QEMU so that it can translate the ufd + * fault addresses back. + */ + msg_region->userspace_addr = r->mmap_addr + r->mmap_offset; + } +} + static void vmsg_close_fds(VhostUserMsg *vmsg) { @@ -727,10 +782,7 @@ generate_faults(VuDev *dev) { static bool vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { int i; - bool track_ramblocks = dev->postcopy_listening; VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m; - VuDevRegion *dev_region = &dev->regions[dev->nregions]; - void *mmap_addr; if (vmsg->fd_num != 1) { vmsg_close_fds(vmsg); @@ -760,69 +812,20 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { * we know all the postcopy client bases have been received, and we * should start generating faults. */ - if (track_ramblocks && + if (dev->postcopy_listening && vmsg->size == sizeof(vmsg->payload.u64) && vmsg->payload.u64 == 0) { (void)generate_faults(dev); return false; } - DPRINT("Adding region: %u\n", dev->nregions); - DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", - msg_region->guest_phys_addr); - DPRINT(" memory_size: 0x%016"PRIx64"\n", - msg_region->memory_size); - DPRINT(" userspace_addr 0x%016"PRIx64"\n", - msg_region->userspace_addr); - DPRINT(" mmap_offset 0x%016"PRIx64"\n", - msg_region->mmap_offset); - - dev_region->gpa = msg_region->guest_phys_addr; - dev_region->size = msg_region->memory_size; - dev_region->qva = msg_region->userspace_addr; - dev_region->mmap_offset = msg_region->mmap_offset; - - /* - * We don't use offset argument of mmap() since the - * mapped address has to be page aligned, and we use huge - * pages. - */ - if (track_ramblocks) { - /* - * In postcopy we're using PROT_NONE here to catch anyone - * accessing it before we userfault. - */ - mmap_addr = mmap(0, dev_region->size + dev_region->mmap_offset, - PROT_NONE, MAP_SHARED | MAP_NORESERVE, - vmsg->fds[0], 0); - } else { - mmap_addr = mmap(0, dev_region->size + dev_region->mmap_offset, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, - vmsg->fds[0], 0); - } - - if (mmap_addr == MAP_FAILED) { - vu_panic(dev, "region mmap error: %s", strerror(errno)); - } else { - dev_region->mmap_addr = (uint64_t)(uintptr_t)mmap_addr; - DPRINT(" mmap_addr: 0x%016"PRIx64"\n", - dev_region->mmap_addr); - } - + _vu_add_mem_reg(dev, msg_region, vmsg->fds[0]); close(vmsg->fds[0]); - if (track_ramblocks) { - /* - * Return the address to QEMU so that it can translate the ufd - * fault addresses back. - */ - msg_region->userspace_addr = (uintptr_t)(mmap_addr + - dev_region->mmap_offset); - + if (dev->postcopy_listening) { /* Send the message back to qemu with the addresses filled in. */ vmsg->fd_num = 0; DPRINT("Successfully added new region in postcopy\n"); - dev->nregions++; return true; } else { for (i = 0; i < dev->max_queues; i++) { @@ -835,7 +838,6 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { } DPRINT("Successfully added new region\n"); - dev->nregions++; return false; } } @@ -940,63 +942,13 @@ static bool vu_set_mem_table_exec(VuDev *dev, VhostUserMsg *vmsg) { VhostUserMemory m = vmsg->payload.memory, *memory = &m; - int prot = PROT_READ | PROT_WRITE; unsigned int i; - if (dev->postcopy_listening) { - /* - * In postcopy we're using PROT_NONE here to catch anyone - * accessing it before we userfault - */ - prot = PROT_NONE; - } - vu_remove_all_mem_regs(dev); - dev->nregions = memory->nregions; DPRINT("Nregions: %u\n", memory->nregions); - for (i = 0; i < dev->nregions; i++) { - void *mmap_addr; - VhostUserMemoryRegion *msg_region = &memory->regions[i]; - VuDevRegion *dev_region = &dev->regions[i]; - - DPRINT("Region %d\n", i); - DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", - msg_region->guest_phys_addr); - DPRINT(" memory_size: 0x%016"PRIx64"\n", - msg_region->memory_size); - DPRINT(" userspace_addr 0x%016"PRIx64"\n", - msg_region->userspace_addr); - DPRINT(" mmap_offset 0x%016"PRIx64"\n", - msg_region->mmap_offset); - - dev_region->gpa = msg_region->guest_phys_addr; - dev_region->size = msg_region->memory_size; - dev_region->qva = msg_region->userspace_addr; - dev_region->mmap_offset = msg_region->mmap_offset; - - /* We don't use offset argument of mmap() since the - * mapped address has to be page aligned, and we use huge - * pages. */ - mmap_addr = mmap(0, dev_region->size + dev_region->mmap_offset, - prot, MAP_SHARED | MAP_NORESERVE, vmsg->fds[i], 0); - - if (mmap_addr == MAP_FAILED) { - vu_panic(dev, "region mmap error: %s", strerror(errno)); - } else { - dev_region->mmap_addr = (uint64_t)(uintptr_t)mmap_addr; - DPRINT(" mmap_addr: 0x%016"PRIx64"\n", - dev_region->mmap_addr); - } - - if (dev->postcopy_listening) { - /* - * Return the address to QEMU so that it can translate the ufd - * fault addresses back. - */ - msg_region->userspace_addr = (uintptr_t)(mmap_addr + - dev_region->mmap_offset); - } + for (i = 0; i < memory->nregions; i++) { + _vu_add_mem_reg(dev, &memory->regions[i], vmsg->fds[i]); close(vmsg->fds[i]); } From patchwork Tue Mar 12 22:26:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N0grytnd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT4R4G6lz1yWy for ; Wed, 13 Mar 2024 09:35:35 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAZu-0004qG-Nm; Tue, 12 Mar 2024 18:26:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZp-0004du-W1 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:30 -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 1rkAZo-0004Gu-H2 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282387; 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: in-reply-to:in-reply-to:references:references; bh=XmqbP21rV19SZz1LR6bA4tErtgG1bGr8AxCV75JHetc=; b=N0grytndk31Assrr48YZCeqEWzuRi/9g23+ZgMHOiKeOSL6Sh7BY2D2OGhqCFXht1T/vTb 9C6N/EhLy0FPTUhTnEGDzvDzhSKhFu717F8BK5szmNn8qnTXapzUbew31LUpUdMmFku+bB oMAVjmmZmcvTTK2qGKKUPUWMMTEE5/8= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-mS-GkQNRPt65rWoIucf84A-1; Tue, 12 Mar 2024 18:26:26 -0400 X-MC-Unique: mS-GkQNRPt65rWoIucf84A-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-513b2e92c19so2692370e87.3 for ; Tue, 12 Mar 2024 15:26:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282384; x=1710887184; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XmqbP21rV19SZz1LR6bA4tErtgG1bGr8AxCV75JHetc=; b=CgRPyZ06i1MV/cEQCM50mHfB/39mASaD2gM6z6V63Azvo9FSCrmZWTC0UP7Aw65I0A Nzk7i9V6/hH/713NJmn92H8aWxuSHCPNTprGvGe2C6EUJAgZtzrq/VjlGRgSpYsZtycQ tNGX96DMIOXJXzkRquYdZvAZC4RCWz2xkmbFxHsekOb7yHRubdGo2tkj1JYYqwIT0et0 gkWVkuZW5toB1XOjAdXmCSQSgMfRnctB/gnuO2bWFBhqwFUUUYL2LmdyTWBSiB7H8H7X PDc6F58pU2MyM/QIL4eILs0IXjuUlE8CpA7g09fkb8ZZY1f3Ns26ToGvolTUwhAr7jtA 9s1g== X-Gm-Message-State: AOJu0YzxSueFYhSu2OaMfpob0hV3+FZ5C9OZKqfTbmO8Y4w1LNwEqvsi qEhsWsDJzj2egHkyOEPubPG3ozsohcSRcGDLA+vJRK7lv81j0gy1WECdCKYGieD46Vf9u/+6wi3 jtLU5pUvioxj9th3DTEGQA27b4DvSARQpiFJU+QD0353I/HT2EV7Ouvp03rXjdtbiNwhMCH+fvA roZTwPbtjtfG3vIVA3L78DuWAOr1V3yK1O X-Received: by 2002:a05:6512:2823:b0:512:fe1f:da5b with SMTP id cf35-20020a056512282300b00512fe1fda5bmr9869949lfb.57.1710282384286; Tue, 12 Mar 2024 15:26:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0S1YuEcGHQTwe253y4qd7XvAkqG2xegD1ZDjzDjqqcaIu/l3HrjLNS2Xe/lcfAEnDCoW55A== X-Received: by 2002:a05:6512:2823:b0:512:fe1f:da5b with SMTP id cf35-20020a056512282300b00512fe1fda5bmr9869932lfb.57.1710282383779; Tue, 12 Mar 2024 15:26:23 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id lk16-20020a170906cb1000b00a45bda3cbb8sm4225545ejb.134.2024.03.12.15.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:23 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:21 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 17/68] libvhost-user: No need to check for NULL when unmapping Message-ID: <4f865c3b15a71dbeae999a10256742751410394e.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand We never add a memory region if mmap() failed. Therefore, no need to check for NULL. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-7-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index f43b5096d0..225283f764 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -247,11 +247,8 @@ vu_remove_all_mem_regs(VuDev *dev) for (i = 0; i < dev->nregions; i++) { VuDevRegion *r = &dev->regions[i]; - void *ma = (void *)(uintptr_t)r->mmap_addr; - if (ma) { - munmap(ma, r->size + r->mmap_offset); - } + munmap((void *)(uintptr_t)r->mmap_addr, r->size + r->mmap_offset); } dev->nregions = 0; } @@ -888,11 +885,8 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { for (i = 0; i < dev->nregions; i++) { if (reg_equal(&dev->regions[i], msg_region)) { VuDevRegion *r = &dev->regions[i]; - void *ma = (void *) (uintptr_t) r->mmap_addr; - if (ma) { - munmap(ma, r->size + r->mmap_offset); - } + munmap((void *)(uintptr_t)r->mmap_addr, r->size + r->mmap_offset); /* * Shift all affected entries by 1 to close the hole at index i and From patchwork Tue Mar 12 22:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911388 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W3ufxu6r; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSvd3VwRz23qj for ; Wed, 13 Mar 2024 09:27:57 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAaD-00050i-VE; Tue, 12 Mar 2024 18:27: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 1rkAZu-0004qc-ID for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:34 -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 1rkAZr-0004HJ-Pw for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282391; 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: in-reply-to:in-reply-to:references:references; bh=i1e4GUGjzQM8a1eupwANxlFHs977Y0k1VRi7DWaQORU=; b=W3ufxu6ro6h7bUPksp6UTp/MbwU6wLcfiKlItSW73ypYWaHTUgFA88qyirmC0k9hrVAIl2 vtKNpxHEqzd/x2El5PwctNQURgt1ZUYn156f7F1o9b4qHPfirdVPzxSSYLM7Qn/h36ugaC tZkiwrBfko4xnVeuIG87T/AJNqgxtpQ= 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-124-n9gIghEyPaSa5ASW0bRh7g-1; Tue, 12 Mar 2024 18:26:29 -0400 X-MC-Unique: n9gIghEyPaSa5ASW0bRh7g-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a464f5e2499so14321166b.2 for ; Tue, 12 Mar 2024 15:26:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282388; x=1710887188; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i1e4GUGjzQM8a1eupwANxlFHs977Y0k1VRi7DWaQORU=; b=iepSmQFexDPG7SJ1kBMf9hXzP5uEveeMq0kAf0xHO/0CF0z0JW66d41peUuRT+MenY g7n3eLbyuKv+YwSgWiUS62PsC3LM/s80ZnHGjqvoVFiQC6ErpcpEu/UOHIasAiWbxPPv VOcILRKAwjGSAJm5yg0cv6B/C/Y8agjvc4eulMBkCqu+e0rx0PyE2oCEZVvRAIdtkQj5 26dYHH56G4lNZDRkF9FfcpcH1dEZ+mfKmfwwWeeECyX5+xZ55magHt6TzN85DbgNZIFF UV2FMYbGq+zaqoCnYyZGCF/Mo5cqYCYidwRo5QxDlmMFacKn5Srmy0P+1cmYJpNDJHtc MjUw== X-Gm-Message-State: AOJu0Yzj3njJ5W+HucBebgtb9/FClGgu50nAKivwPLlPGL3oIiELwXgW 7ShWGIhBIdkoP+5rbhCgBzY26WE97UMq2f/0PZ0uol9Il9OrtM7GSJMsljky3NQ0LL6h5NrVanf zYLCd9MzuDENNxPb42e5NU9r2vfPFus/7SpawevGgcx4FNI1jSLe1xr5ncscrDb2dWKDV8TjDak q2OAXph8gDy5zIgVa07C0sQ24K3OGLgDQw X-Received: by 2002:a17:906:f90f:b0:a44:8caf:a2e0 with SMTP id lc15-20020a170906f90f00b00a448cafa2e0mr1929339ejb.74.1710282387751; Tue, 12 Mar 2024 15:26:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/MCi3z4oMxir9FcDKAtv878bHogVlAHR+NcU0p9cztfKybkEjs04BFHfUYEs8AcH1tkOTdA== X-Received: by 2002:a17:906:f90f:b0:a44:8caf:a2e0 with SMTP id lc15-20020a170906f90f00b00a448cafa2e0mr1929322ejb.74.1710282387215; Tue, 12 Mar 2024 15:26:27 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id ov9-20020a170906fc0900b00a46367a17f7sm1700996ejb.206.2024.03.12.15.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:26 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:24 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 18/68] libvhost-user: Don't zero out memory for memory regions Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand dev->nregions always covers only valid entries. Stop zeroing out other array elements that are unused. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-8-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 225283f764..2e8b611385 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -888,13 +888,9 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { munmap((void *)(uintptr_t)r->mmap_addr, r->size + r->mmap_offset); - /* - * Shift all affected entries by 1 to close the hole at index i and - * zero out the last entry. - */ + /* Shift all affected entries by 1 to close the hole at index. */ memmove(dev->regions + i, dev->regions + i + 1, sizeof(VuDevRegion) * (dev->nregions - i - 1)); - memset(dev->regions + dev->nregions - 1, 0, sizeof(VuDevRegion)); DPRINT("Successfully removed a region\n"); dev->nregions--; i--; @@ -2119,7 +2115,6 @@ vu_init(VuDev *dev, DPRINT("%s: failed to malloc mem regions\n", __func__); return false; } - memset(dev->regions, 0, VHOST_USER_MAX_RAM_SLOTS * sizeof(dev->regions[0])); dev->vq = malloc(max_queues * sizeof(dev->vq[0])); if (!dev->vq) { From patchwork Tue Mar 12 22:26:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IfnLTV1k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSw34jPJz1yWt for ; Wed, 13 Mar 2024 09:28:19 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAaa-0005lD-VL; Tue, 12 Mar 2024 18:27:17 -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 1rkAZx-0004vd-PR for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:39 -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 1rkAZv-0004Ha-Rm for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282394; 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: in-reply-to:in-reply-to:references:references; bh=B6OhfpIW75q+gyT4clF9x+dnePUQGPnZ4oMwJv+v17w=; b=IfnLTV1kAXl4748ZDrTYKLLwdioRqkl8levVLiDB8D1eeRbtq2Lx/w2HVQVjBIGDur7rxH ARmH0BG6h+xdvhxJohknV7kYli96pMJNmVx/8BCLfcquvaIUtQsGBWMWyYW0TTiA4DLOLC W+HsTNOgRxf+2ONBfj3hRvO7XCG4gg8= 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-597-6y-MYXH_MHWN4QGe133sbQ-1; Tue, 12 Mar 2024 18:26:33 -0400 X-MC-Unique: 6y-MYXH_MHWN4QGe133sbQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a45acc7f191so403091066b.0 for ; Tue, 12 Mar 2024 15:26:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282391; x=1710887191; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=B6OhfpIW75q+gyT4clF9x+dnePUQGPnZ4oMwJv+v17w=; b=ui+NZ3Ev8+YsGKx+EfEC7pHLmYimM+jW3tOv+lqU/U5m8nsTvcAfk+b+EbDK+bLTwj APJKdnQHy0/XUPREj28X4O1cmVEkEuPssfl92ohcXRGM5v+cehnT7kj29/ZQGhQkCZqp vDazPMAsjNeqagTCoyZluY0beHTrMrulA75U9zTRKJonybUZ3+szmTZj6WCKi/MUvKyw xKmn1u956QKvaT3aCrIcbyIWqzpToVzhzb4SiCa2BehPJDxvv7LlCVrE7OsGdDStQOFp +FvUpGlQJbBtIluDEMNWmfmql9wXVfeeP2xu8bsGP2gr0WlBt+809DTT8zmLFF+4lhrC 1EGA== X-Gm-Message-State: AOJu0Yx6HKAPQzQ5yJlL1z6ksggEhQY2S/1QI/fPVL4waYLf8fkL34us 7jN4CjZ0ghb3ErByS3jgu88CAKKuhqz5THzDqEg/RnOR4lGdXBe+Ua53S5zt4EXD4uqeOym4/fj IXzNSnMQw+kgnmtA95U6pBO6GOisLa+3/svHnuATcC54MCmH2pRrNmPSNJd7CzOHQBfi++F6oL2 OrMUtSaH/CMWc6FPA4ALx3TgJInJRLbNr2 X-Received: by 2002:a17:906:a388:b0:a46:4bbb:5f66 with SMTP id k8-20020a170906a38800b00a464bbb5f66mr1445536ejz.9.1710282391355; Tue, 12 Mar 2024 15:26:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEViuvageTK2HlYNK6QQmlb0Y5s66yvCyHA0i7BKMtXL8cizjuXADhOmA86g92r95IOvBSvrg== X-Received: by 2002:a17:906:a388:b0:a46:4bbb:5f66 with SMTP id k8-20020a170906a38800b00a464bbb5f66mr1445523ejz.9.1710282390899; Tue, 12 Mar 2024 15:26:30 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id jy21-20020a170907763500b00a4652efd795sm163830ejc.83.2024.03.12.15.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:30 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:27 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 19/68] libvhost-user: Don't search for duplicates when removing memory regions Message-ID: <9c254cb413a631f6601e6e34429547759d7d63a6.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand We cannot have duplicate memory regions, something would be deeply flawed elsewhere. Let's just stop the search once we found an entry. We'll add more sanity checks when adding memory regions later. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-9-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 2e8b611385..7f29e01c30 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -896,8 +896,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { i--; found = true; - - /* Continue the search for eventual duplicates. */ + break; } } From patchwork Tue Mar 12 22:26:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dVSp/B2K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8t3BSQz1yWy for ; Wed, 13 Mar 2024 09:39:26 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAab-0005tj-Qm; Tue, 12 Mar 2024 18:27:17 -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 1rkAa2-000515-8m for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAZz-0004JB-8H for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282398; 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: in-reply-to:in-reply-to:references:references; bh=tiNY6DUe9/nrekxQjna/PMEUvIOJcBoh6jUWaAmbJLw=; b=dVSp/B2KSGXqpgblI3c0ymG2QPrb3HiO/gAupNrod7E62Y4IUVKLehoOXt+OvM3YEzfOby x+yZVEl2LRNOTvhJ8n4bv4pO1pR6QLXzpVKzad7L62BxJiCXwg9RoRuEu3qgk7hSr+tPaU 3D4gx7DuB74JrYjkUS3JVLxrZ6vxTTI= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-1HCqYbXHOi2TeS2xMR8RyQ-1; Tue, 12 Mar 2024 18:26:37 -0400 X-MC-Unique: 1HCqYbXHOi2TeS2xMR8RyQ-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2d45c064742so13199641fa.3 for ; Tue, 12 Mar 2024 15:26:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282395; x=1710887195; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tiNY6DUe9/nrekxQjna/PMEUvIOJcBoh6jUWaAmbJLw=; b=CcyGZYqaYgtyWp0niopx0wIZr4rzbMN+6ttjdW+EYAEBFX+ACq0Vbeks+VDzGw4Vyn ku+Sn2pDAV8o1ZddjLQhJ6hZFwjx+Q2vQqAb6a55JTVo8IHrv6Hk4VWq9r8uB9yLCV9q WGaoJlYEHdlLBhzBZ72jvMC/+P4S/V29clcrQQieDFptYqsYkMkGl2nNrgTSXrmboflP CswfnQHufjIYkmn7Im8SzdutUzxcGtRWUDGfhHT1Eefed4MOMP0rWl84sLObQzfKh3LE jZsKPBTq9sWqlH6f4g8/l3KUJ+PQErEG5IdLnE8YnIsx4hcagEWol7z2T+4YAf9Mmplk b3Fw== X-Gm-Message-State: AOJu0YxiR30a6M38gwqFoNZ+Hti0BaFsfB6TSSwFs9gRLrvtXBQefv1S db+cuIo70DGj5hlUymjR0WUrETXxICh5Mso3mzb7QNpIIDvzwm0PVd6qrHooy2VfIpFEDl0k6Gx 9qczZttS26ycVeta1+sSFYLrk79Ycz5ytlRogmRAhrHVm6Fc/+N0S3VeLuvHbiTriIEnJFjzmVJ 2M/7TT07qwGhRPSSb3KxjONiIrhwlUFYI+ X-Received: by 2002:a05:651c:c6:b0:2d2:4108:72a with SMTP id 6-20020a05651c00c600b002d24108072amr1945678ljr.12.1710282394852; Tue, 12 Mar 2024 15:26:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXtvTWfvO2ebBTyTRSa+iWBU1PPnXrcd6I1dON3MnrLYLeO5N8ZJLkUV156h574SXl0pmJBw== X-Received: by 2002:a05:651c:c6:b0:2d2:4108:72a with SMTP id 6-20020a05651c00c600b002d24108072amr1945662ljr.12.1710282394296; Tue, 12 Mar 2024 15:26:34 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id h19-20020aa7c613000000b005673e29cc0fsm4296218edq.54.2024.03.12.15.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:33 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:31 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 20/68] libvhost-user: Factor out search for memory region by GPA and simplify Message-ID: <60ccdca42d96f730f57478caaf376da90c3d97f3.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Memory regions cannot overlap, and if we ever hit that case something would be really flawed. For example, when vhost code in QEMU decides to increase the size of memory regions to cover full huge pages, it makes sure to never create overlaps, and if there would be overlaps, it would bail out. QEMU commits 48d7c9757749 ("vhost: Merge sections added to temporary list"), c1ece84e7c93 ("vhost: Huge page align and merge") and e7b94a84b6cb ("vhost: Allow adjoining regions") added and clarified that handling and how overlaps are impossible. Consequently, each GPA can belong to at most one memory region, and everything else doesn't make sense. Let's factor out our search to prepare for further changes. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-10-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 79 +++++++++++++---------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 7f29e01c30..d72f25396d 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -195,30 +195,47 @@ vu_panic(VuDev *dev, const char *msg, ...) */ } +/* Search for a memory region that covers this guest physical address. */ +static VuDevRegion * +vu_gpa_to_mem_region(VuDev *dev, uint64_t guest_addr) +{ + unsigned int i; + + /* + * Memory regions cannot overlap in guest physical address space. Each + * GPA belongs to exactly one memory region, so there can only be one + * match. + */ + for (i = 0; i < dev->nregions; i++) { + VuDevRegion *cur = &dev->regions[i]; + + if (guest_addr >= cur->gpa && guest_addr < cur->gpa + cur->size) { + return cur; + } + } + return NULL; +} + /* Translate guest physical address to our virtual address. */ void * vu_gpa_to_va(VuDev *dev, uint64_t *plen, uint64_t guest_addr) { - unsigned int i; + VuDevRegion *r; if (*plen == 0) { return NULL; } - /* Find matching memory region. */ - for (i = 0; i < dev->nregions; i++) { - VuDevRegion *r = &dev->regions[i]; - - if ((guest_addr >= r->gpa) && (guest_addr < (r->gpa + r->size))) { - if ((guest_addr + *plen) > (r->gpa + r->size)) { - *plen = r->gpa + r->size - guest_addr; - } - return (void *)(uintptr_t) - guest_addr - r->gpa + r->mmap_addr + r->mmap_offset; - } + r = vu_gpa_to_mem_region(dev, guest_addr); + if (!r) { + return NULL; } - return NULL; + if ((guest_addr + *plen) > (r->gpa + r->size)) { + *plen = r->gpa + r->size - guest_addr; + } + return (void *)(uintptr_t)guest_addr - r->gpa + r->mmap_addr + + r->mmap_offset; } /* Translate qemu virtual address to our virtual address. */ @@ -854,8 +871,8 @@ static inline bool reg_equal(VuDevRegion *vudev_reg, static bool vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m; - unsigned int i; - bool found = false; + unsigned int idx; + VuDevRegion *r; if (vmsg->fd_num > 1) { vmsg_close_fds(vmsg); @@ -882,28 +899,22 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { DPRINT(" mmap_offset 0x%016"PRIx64"\n", msg_region->mmap_offset); - for (i = 0; i < dev->nregions; i++) { - if (reg_equal(&dev->regions[i], msg_region)) { - VuDevRegion *r = &dev->regions[i]; - - munmap((void *)(uintptr_t)r->mmap_addr, r->size + r->mmap_offset); - - /* Shift all affected entries by 1 to close the hole at index. */ - memmove(dev->regions + i, dev->regions + i + 1, - sizeof(VuDevRegion) * (dev->nregions - i - 1)); - DPRINT("Successfully removed a region\n"); - dev->nregions--; - i--; - - found = true; - break; - } - } - - if (!found) { + r = vu_gpa_to_mem_region(dev, msg_region->guest_phys_addr); + if (!r || !reg_equal(r, msg_region)) { + vmsg_close_fds(vmsg); vu_panic(dev, "Specified region not found\n"); + return false; } + munmap((void *)(uintptr_t)r->mmap_addr, r->size + r->mmap_offset); + + idx = r - dev->regions; + assert(idx < dev->nregions); + /* Shift all affected entries by 1 to close the hole. */ + memmove(r, r + 1, sizeof(VuDevRegion) * (dev->nregions - idx - 1)); + DPRINT("Successfully removed a region\n"); + dev->nregions--; + vmsg_close_fds(vmsg); return false; From patchwork Tue Mar 12 22:26:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iK/WIe37; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8l3fXTz1yWy for ; Wed, 13 Mar 2024 09:39:19 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAae-0006Gx-2D; Tue, 12 Mar 2024 18:27:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAa2-00051P-NL for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAa1-0004JF-5Y for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282400; 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: in-reply-to:in-reply-to:references:references; bh=kuEw/qjyX67TtnsTtkeQbRtswvxdOIF5Wj6N4Z6tg+M=; b=iK/WIe37bcei/guxfc8Y1nuH0IFwXkXo62qnaXJd9FHxP4WvtbK9Zfj74BXjVYbhsML1r+ X2DPtfbaUIBYMnceV2Kbo0wSOOBIvFXLKpCg0yXAr6QEuwbumHi/82uEKaftFioTjVhyVO OtFtwYv+vYwPOTiyqSfVDD2kmUcG/v8= 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-562-zCpsfkUuPW2rz_ozc5U20Q-1; Tue, 12 Mar 2024 18:26:39 -0400 X-MC-Unique: zCpsfkUuPW2rz_ozc5U20Q-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5684650b00bso197339a12.2 for ; Tue, 12 Mar 2024 15:26:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282398; x=1710887198; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kuEw/qjyX67TtnsTtkeQbRtswvxdOIF5Wj6N4Z6tg+M=; b=CROg71ORa7E1VLk20Oj3f32w60LM8ToAonJDlFGwiK7MdLzR2H3B6UBueKOP/WlkrS hz2Xmj6VDRzfqRS4reCCjxZ6Vls2LxIXeaiKvnkgtOjOc9zMAmj0X9AAoKRw9ZjU/3JA C8W84ZLe01zoMe1vHib4jHG6hNhs4VLGQYRr2xVqqvQJ1fQKYlVKUVFWsyxQIh4OPUsu Vi/RAqehBOMPqusxFqgqiLPZvC77I5qfZmNTEaj+DMSWQeOARcNkQ9oTXkxl5UOOsdn2 J6U3zAJHMRC/9iy7kBopR8gsRAUkugeqog8kdp+b+9N8jmHnwKdJd8Lv581OESe8nzvo ST/Q== X-Gm-Message-State: AOJu0Yw0C0wvIZV+ytfR/GlDnfJR6uxXSB3RQWvB6bQYdwpjD1gdtp0v as5Y7Jf52LJaDgI2wvuQzCv06O1+ogNoeE55k2IEtnlv2LFrd+ffrAgsQBCZZYwC5VF5f/ZWcux 6MIfxD0ziJ8KzwtWlcrOUH7YhzWpbFfR7rdDezFjzzEbb62IiWZkr8kMrLCoFDWBvMSzztsx9QZ IvH7I02pga79uTNR6goLIPyYj0L0im1afV X-Received: by 2002:a50:cd07:0:b0:567:c0ac:b31d with SMTP id z7-20020a50cd07000000b00567c0acb31dmr3239045edi.37.1710282397762; Tue, 12 Mar 2024 15:26:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzKExrWXvkSicF1QyPBfmJJoUhq+5gI90oLC/H9I9Cz8E4q6klZu+4vvB9XFTQaSLFR8qadg== X-Received: by 2002:a50:cd07:0:b0:567:c0ac:b31d with SMTP id z7-20020a50cd07000000b00567c0acb31dmr3239026edi.37.1710282397223; Tue, 12 Mar 2024 15:26:37 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id f21-20020a50d555000000b0056835320f76sm4582789edj.8.2024.03.12.15.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:36 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:34 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 21/68] libvhost-user: Speedup gpa_to_mem_region() and vu_gpa_to_va() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's speed up GPA to memory region / virtual address lookup. Store the memory regions ordered by guest physical addresses, and use binary search for address translation, as well as when adding/removing memory regions. Most importantly, this will speed up GPA->VA address translation when we have many memslots. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-11-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 49 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index d72f25396d..ef6353d847 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -199,19 +199,30 @@ vu_panic(VuDev *dev, const char *msg, ...) static VuDevRegion * vu_gpa_to_mem_region(VuDev *dev, uint64_t guest_addr) { - unsigned int i; + int low = 0; + int high = dev->nregions - 1; /* * Memory regions cannot overlap in guest physical address space. Each * GPA belongs to exactly one memory region, so there can only be one * match. + * + * We store our memory regions ordered by GPA and can simply perform a + * binary search. */ - for (i = 0; i < dev->nregions; i++) { - VuDevRegion *cur = &dev->regions[i]; + while (low <= high) { + unsigned int mid = low + (high - low) / 2; + VuDevRegion *cur = &dev->regions[mid]; if (guest_addr >= cur->gpa && guest_addr < cur->gpa + cur->size) { return cur; } + if (guest_addr >= cur->gpa + cur->size) { + low = mid + 1; + } + if (guest_addr < cur->gpa) { + high = mid - 1; + } } return NULL; } @@ -273,9 +284,14 @@ vu_remove_all_mem_regs(VuDev *dev) static void _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) { + const uint64_t start_gpa = msg_region->guest_phys_addr; + const uint64_t end_gpa = start_gpa + msg_region->memory_size; int prot = PROT_READ | PROT_WRITE; VuDevRegion *r; void *mmap_addr; + int low = 0; + int high = dev->nregions - 1; + unsigned int idx; DPRINT("Adding region %d\n", dev->nregions); DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n", @@ -295,6 +311,29 @@ _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) prot = PROT_NONE; } + /* + * We will add memory regions into the array sorted by GPA. Perform a + * binary search to locate the insertion point: it will be at the low + * index. + */ + while (low <= high) { + unsigned int mid = low + (high - low) / 2; + VuDevRegion *cur = &dev->regions[mid]; + + /* Overlap of GPA addresses. */ + if (start_gpa < cur->gpa + cur->size && cur->gpa < end_gpa) { + vu_panic(dev, "regions with overlapping guest physical addresses"); + return; + } + if (start_gpa >= cur->gpa + cur->size) { + low = mid + 1; + } + if (start_gpa < cur->gpa) { + high = mid - 1; + } + } + idx = low; + /* * We don't use offset argument of mmap() since the mapped address has * to be page aligned, and we use huge pages. @@ -308,7 +347,9 @@ _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) DPRINT(" mmap_addr: 0x%016"PRIx64"\n", (uint64_t)(uintptr_t)mmap_addr); - r = &dev->regions[dev->nregions]; + /* Shift all affected entries by 1 to open a hole at idx. */ + r = &dev->regions[idx]; + memmove(r + 1, r, sizeof(VuDevRegion) * (dev->nregions - idx)); r->gpa = msg_region->guest_phys_addr; r->size = msg_region->memory_size; r->qva = msg_region->userspace_addr; From patchwork Tue Mar 12 22:26:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cStTQd37; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT0C1tfmz23qj for ; Wed, 13 Mar 2024 09:31:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAae-0006LM-HV; Tue, 12 Mar 2024 18:27:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAa7-000520-IC for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:53 -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 1rkAa4-0004Jd-JJ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282404; 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: in-reply-to:in-reply-to:references:references; bh=TGTA4tkwpu8e0JNzPWdgaIpfsSfnaoNmPizTVrLG4go=; b=cStTQd37PQxOU2eOTbVMDzBNMTzfuWuMi77s7MHXDfCS/uecKrB9DkrDjFWoVEQTGMc8EQ JUkMEJ0du9xGg7+OHbqq1LrBAV7uZu+McMtW+vBGjiIU9UKl2PfKE9kkY2K4BDGT5NTZlW fnvx8/bA6YQzIRD0kpRbT53YqzWiQO0= 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-145-eSmXNE-IMeaCBFROcn7zuw-1; Tue, 12 Mar 2024 18:26:42 -0400 X-MC-Unique: eSmXNE-IMeaCBFROcn7zuw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a44143c8908so27826866b.1 for ; Tue, 12 Mar 2024 15:26:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282401; x=1710887201; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TGTA4tkwpu8e0JNzPWdgaIpfsSfnaoNmPizTVrLG4go=; b=rkBzv+jIVGA3OZDS0dwFvcJPXoYC47/Z4MLb16H8pRYBOPwFIk2PpQ5aIr6npeBFGv MbNT9stpGXNnVGElJvfW5oRvRUuWghttm0cYn44+kNPDucR72U3IazqmR7of2VRXyP4A 4WCyj262QJliQN5sAoSyZnZyqiFsfDReFC2WILTRuTy2oU3fxWlX90Cqpp4y7qUBn1bL R0Xdhj3xT3gVwMEexE84Uv8I5jU2SWoOscidQbvpfpmmrNB34jp2PBaW0v0HC0sYsM7f PNYua5OcBGNrZspAqaeOjDGwGBQqFlOiucjoCbIECds2Vp6ilqEjPwAiaeNJaZu8x08R FwBQ== X-Gm-Message-State: AOJu0YwYGxHP7dvnu75+fzcfkoB7q2DU5jCF+eWMMcTWnCcIBmdfhH4g uAwD37F1RkVFDXb/lptTqKdogByPJ0WN41vcKxMPda4mNR+K5b9t6Gt75sQFR9oa9dj2LXpEIpI AgNf5RcD8TE2e+HDzUx3Ltg340Rg6RWCj6sNy7E5+6O/641zXOjSYgSfYGn6VlgBUbacIPRKGUH YmHgbKGETrKpJWOdFWMXugUX3zHxvXbM4e X-Received: by 2002:a17:906:903:b0:a45:40e4:8c8 with SMTP id i3-20020a170906090300b00a4540e408c8mr839495ejd.16.1710282400722; Tue, 12 Mar 2024 15:26:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJL2Ys4/++xwgfi9gFfLtyI/ysDicsbusZ6hZyoKNohXG2YuGDtJ+aUI0y9ZOPv+GM1Kmiyw== X-Received: by 2002:a17:906:903:b0:a45:40e4:8c8 with SMTP id i3-20020a170906090300b00a4540e408c8mr839473ejd.16.1710282400287; Tue, 12 Mar 2024 15:26:40 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id x19-20020a170906135300b00a4644397aa9sm1000340ejb.67.2024.03.12.15.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:39 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:37 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 22/68] libvhost-user: Use most of mmap_offset as fd_offset Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand In the past, QEMU would create memory regions that could partially cover hugetlb pages, making mmap() fail if we would use the mmap_offset as an fd_offset. For that reason, we never used the mmap_offset as an offset into the fd and instead always mapped the fd from the very start. However, that can easily result in us mmap'ing a lot of unnecessary parts of an fd, possibly repeatedly. QEMU nowadays does not create memory regions that partially cover huge pages -- it never really worked with postcopy. QEMU handles merging of regions that partially cover huge pages (due to holes in boot memory) since 2018 in c1ece84e7c93 ("vhost: Huge page align and merge"). Let's be a bit careful and not unconditionally convert the mmap_offset into an fd_offset. Instead, let's simply detect the hugetlb size and pass as much as we can as fd_offset, making sure that we call mmap() with a properly aligned offset. With QEMU and a virtio-mem device that is fully plugged (50GiB using 50 memslots) the qemu-storage daemon process consumes in the VA space 1281GiB before this change and 58GiB after this change. ================ Vhost user message ================ Request: VHOST_USER_ADD_MEM_REG (37) Flags: 0x9 Size: 40 Fds: 59 Adding region 4 guest_phys_addr: 0x0000000200000000 memory_size: 0x0000000040000000 userspace_addr: 0x00007fb73bffe000 old mmap_offset: 0x0000000080000000 fd_offset: 0x0000000080000000 new mmap_offset: 0x0000000000000000 mmap_addr: 0x00007f02f1bdc000 Successfully added new region ================ Vhost user message ================ Request: VHOST_USER_ADD_MEM_REG (37) Flags: 0x9 Size: 40 Fds: 59 Adding region 5 guest_phys_addr: 0x0000000240000000 memory_size: 0x0000000040000000 userspace_addr: 0x00007fb77bffe000 old mmap_offset: 0x00000000c0000000 fd_offset: 0x00000000c0000000 new mmap_offset: 0x0000000000000000 mmap_addr: 0x00007f0284000000 Successfully added new region Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-12-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 54 ++++++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index ef6353d847..55aef5fcc6 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -43,6 +43,8 @@ #include #include #include +#include +#include #ifdef __NR_userfaultfd #include @@ -281,12 +283,32 @@ vu_remove_all_mem_regs(VuDev *dev) dev->nregions = 0; } +static size_t +get_fd_hugepagesize(int fd) +{ +#if defined(__linux__) + struct statfs fs; + int ret; + + do { + ret = fstatfs(fd, &fs); + } while (ret != 0 && errno == EINTR); + + if (!ret && (unsigned int)fs.f_type == HUGETLBFS_MAGIC) { + return fs.f_bsize; + } +#endif + return 0; +} + static void _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) { const uint64_t start_gpa = msg_region->guest_phys_addr; const uint64_t end_gpa = start_gpa + msg_region->memory_size; int prot = PROT_READ | PROT_WRITE; + uint64_t mmap_offset, fd_offset; + size_t hugepagesize; VuDevRegion *r; void *mmap_addr; int low = 0; @@ -300,7 +322,7 @@ _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) msg_region->memory_size); DPRINT(" userspace_addr: 0x%016"PRIx64"\n", msg_region->userspace_addr); - DPRINT(" mmap_offset: 0x%016"PRIx64"\n", + DPRINT(" old mmap_offset: 0x%016"PRIx64"\n", msg_region->mmap_offset); if (dev->postcopy_listening) { @@ -335,11 +357,31 @@ _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) idx = low; /* - * We don't use offset argument of mmap() since the mapped address has - * to be page aligned, and we use huge pages. + * Convert most of msg_region->mmap_offset to fd_offset. In almost all + * cases, this will leave us with mmap_offset == 0, mmap()'ing only + * what we really need. Only if a memory region would partially cover + * hugetlb pages, we'd get mmap_offset != 0, which usually doesn't happen + * anymore (i.e., modern QEMU). + * + * Note that mmap() with hugetlb would fail if the offset into the file + * is not aligned to the huge page size. */ - mmap_addr = mmap(0, msg_region->memory_size + msg_region->mmap_offset, - prot, MAP_SHARED | MAP_NORESERVE, fd, 0); + hugepagesize = get_fd_hugepagesize(fd); + if (hugepagesize) { + fd_offset = ALIGN_DOWN(msg_region->mmap_offset, hugepagesize); + mmap_offset = msg_region->mmap_offset - fd_offset; + } else { + fd_offset = msg_region->mmap_offset; + mmap_offset = 0; + } + + DPRINT(" fd_offset: 0x%016"PRIx64"\n", + fd_offset); + DPRINT(" new mmap_offset: 0x%016"PRIx64"\n", + mmap_offset); + + mmap_addr = mmap(0, msg_region->memory_size + mmap_offset, + prot, MAP_SHARED | MAP_NORESERVE, fd, fd_offset); if (mmap_addr == MAP_FAILED) { vu_panic(dev, "region mmap error: %s", strerror(errno)); return; @@ -354,7 +396,7 @@ _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) r->size = msg_region->memory_size; r->qva = msg_region->userspace_addr; r->mmap_addr = (uint64_t)(uintptr_t)mmap_addr; - r->mmap_offset = msg_region->mmap_offset; + r->mmap_offset = mmap_offset; dev->nregions++; if (dev->postcopy_listening) { From patchwork Tue Mar 12 22:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A3KNTBdE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT936FdTz1yWy for ; Wed, 13 Mar 2024 09:39:35 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAac-0005yQ-5B; Tue, 12 Mar 2024 18:27:18 -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 1rkAaC-00053b-En for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:00 -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 1rkAa8-0004K0-JW for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282407; 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: in-reply-to:in-reply-to:references:references; bh=mYZExF4b/5G+QkupUCgRhC1lWR4Wq2MT6nsHzd4F7G4=; b=A3KNTBdENf018SPxZEtyU0YTxJVJRD3YliE09SmenU+axfxsZ+WDUc76a2WLMSXlxWxv4s vTTX6Ni8A5LH9tIGdlWg0TtTqTdUBxB7SL6BXmlxVezYp6OCeVQtorR8CC89ZNmxwl2HKj de+aWM00FwlZP7NTvJGrglOk8IVssFQ= 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-644-vVz6AAPiPn283p0nSjTz6A-1; Tue, 12 Mar 2024 18:26:45 -0400 X-MC-Unique: vVz6AAPiPn283p0nSjTz6A-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a46447b0b13so67813466b.3 for ; Tue, 12 Mar 2024 15:26:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282404; x=1710887204; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mYZExF4b/5G+QkupUCgRhC1lWR4Wq2MT6nsHzd4F7G4=; b=ZavbaCewPsR3kOTxveJhjZA1xc6bdqzFMfb2VBnVz1zuUS+n4sVEJBEeJZT0pksPUB eFg82bjqjQDv9xszD8wwQuFNI4bum7ezc5aQbHdU3WrzPeDdVq9rFuAWUPFD7U/UqJCn JlLs13aLhNchk/CJOn+PU4qmQa2aKYomV3tphlBAOnLFYHJqonWQbvhn3VIt4WtVkNLP ZMDuMMiLMvcaXxwkN2hZk0XSxUt41Umgr/C+wS3NfQiMXA+uv6nDQX/X+C0vQFpotyEp EmUtzV2ZeBk+1hCRh33uvAz21CM8m33Im/WpBDV6B4++FRGSP1L3W6YgmVW3/8zzbhGG VIqQ== X-Gm-Message-State: AOJu0Yy0u/B6yZIfjNnR5YZm/qh7qu57WhI2n34s+rGom3HoDKfGqFIg V06EmmMSzFIALz7u3fPkc1gUazxmPI/XR2Yp3jEs/8095VUtBwwlocANEH27jFmMTAoHJx0VNJR HTNZkohYr7M+HY3NB9bdlO5R/NwSiKc71b78V60qi3SY9KZuYFIJOvcg+K0eRRw7D6v0Ts2fXcq 7wvTHOETCKvjtCLOnkzzaSpLZoKv2a5p9Z X-Received: by 2002:a17:907:a708:b0:a45:becb:6e3d with SMTP id vw8-20020a170907a70800b00a45becb6e3dmr8250022ejc.20.1710282403884; Tue, 12 Mar 2024 15:26:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/xIuX935586122cMvJOFsGklUux1lP46CD3GBOEmRAQ2odG0jk0rQYyFLNq0hMrAJpYAxVQ== X-Received: by 2002:a17:907:a708:b0:a45:becb:6e3d with SMTP id vw8-20020a170907a70800b00a45becb6e3dmr8250004ejc.20.1710282403331; Tue, 12 Mar 2024 15:26:43 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id uz17-20020a170907119100b00a45cac9ae6bsm4213324ejb.162.2024.03.12.15.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:42 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:40 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 23/68] libvhost-user: Factor out vq usability check Message-ID: <2a29022768f1777d71e26b784a264323d1914dd6.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Let's factor it out to prepare for further changes. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-13-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 55aef5fcc6..ed0a978d4f 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -283,6 +283,12 @@ vu_remove_all_mem_regs(VuDev *dev) dev->nregions = 0; } +static bool +vu_is_vq_usable(VuDev *dev, VuVirtq *vq) +{ + return likely(!dev->broken) && likely(vq->vring.avail); +} + static size_t get_fd_hugepagesize(int fd) { @@ -2380,8 +2386,7 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int *in_bytes, idx = vq->last_avail_idx; total_bufs = in_total = out_total = 0; - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { + if (!vu_is_vq_usable(dev, vq)) { goto done; } @@ -2496,8 +2501,7 @@ vu_queue_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int in_bytes, bool vu_queue_empty(VuDev *dev, VuVirtq *vq) { - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { + if (!vu_is_vq_usable(dev, vq)) { return true; } @@ -2536,8 +2540,7 @@ vring_notify(VuDev *dev, VuVirtq *vq) static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync) { - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { + if (!vu_is_vq_usable(dev, vq)) { return; } @@ -2862,8 +2865,7 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) unsigned int head; VuVirtqElement *elem; - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { + if (!vu_is_vq_usable(dev, vq)) { return NULL; } @@ -3020,8 +3022,7 @@ vu_queue_fill(VuDev *dev, VuVirtq *vq, { struct vring_used_elem uelem; - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { + if (!vu_is_vq_usable(dev, vq)) { return; } @@ -3050,8 +3051,7 @@ vu_queue_flush(VuDev *dev, VuVirtq *vq, unsigned int count) { uint16_t old, new; - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { + if (!vu_is_vq_usable(dev, vq)) { return; } From patchwork Tue Mar 12 22:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NWQ9SGzk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT9p0ScVz1yWt for ; Wed, 13 Mar 2024 09:40:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAaf-0006Ya-PO; Tue, 12 Mar 2024 18:27:21 -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 1rkAaD-00053k-4q for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:00 -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 1rkAaA-0004KD-Sn for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282410; 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: in-reply-to:in-reply-to:references:references; bh=xADFZP6JmWXiAhsHChjJDu1LMnWZYRBzbs2QYwTiK+0=; b=NWQ9SGzk5wTxfB3Ka+2/VyPqWrL8WxBdbVFbmed0O7zbUP3ctDUd+t6LAuwbFl62vNr99R ejXBrGlnddgXmGDEiWtEmKWG8THutGUzt6d1fUNFPti5HkujHr3fuy5XeW6A3TUJuIzhio ellOBZx4MRB05DHqY+a2fCvaeUaH4xM= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-xAJRcectMhWDwJ4MyZGJVg-1; Tue, 12 Mar 2024 18:26:48 -0400 X-MC-Unique: xAJRcectMhWDwJ4MyZGJVg-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5682e95fc68so226393a12.1 for ; Tue, 12 Mar 2024 15:26:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282407; x=1710887207; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xADFZP6JmWXiAhsHChjJDu1LMnWZYRBzbs2QYwTiK+0=; b=jf3W4oO/ey3Kogs4Bky7Eio+wiKFOsR1kxh/XsqUc1RsZUlogsvVPGNrF7/hgG/dO8 e/LrJnM6u3Zn4MmPOSjCJ8OoMCAr0eLlRgrv7BynIM3HqdI6ZEO9KKDWroSKh5AyWRui yj02Ea2axEyVoLqnffJ3NpB+exyaI8tRm6Tj3B7f6Bce0GBuwsOeKyzrUndz9RV+Fmwi K8SsM/VNEOznJsuNUEoh22i8nlAtYMXxorAp6uOnQZatwP+R2oUxSlNts5SdB3004VoB aKoFe3aALD0gya1skBnIa28dRPZpYMKVL6zdl9KoP8nIPO5fJx/OGaDyYI+lH5thEsxv dazg== X-Gm-Message-State: AOJu0Yw1DlYQQ+3qv/lfrgHxJmfz26AGZS/a4ug5MOrYUytBvLhMWEh2 Pawf+QS4dHrlSHDSrDOrS6V3ZKlYvBLbtRyHOCKLAtN8SE3LcBgsjEdzCVHoDrOrafFEC1RT30v AJMpPlc/etgMiXpCZRm+72l7FuisN9zKO5vEYWxSmX/cytfsRLwfS8sCYcedcKckmTpstQadQJb 4lE71NDSvR9ep1uhmCC53lNsLWRHJtv2dj X-Received: by 2002:a50:d498:0:b0:568:13a5:1801 with SMTP id s24-20020a50d498000000b0056813a51801mr1045882edi.1.1710282407333; Tue, 12 Mar 2024 15:26:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHooA28wMiPqcekjOLj9whtrMBauh9vFIgFa1856uX+Ih5nsseTkmdvkKP0gBaQ2g3si3rDJw== X-Received: by 2002:a50:d498:0:b0:568:13a5:1801 with SMTP id s24-20020a50d498000000b0056813a51801mr1045861edi.1.1710282406699; Tue, 12 Mar 2024 15:26:46 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id t21-20020a50d715000000b005682a0e915fsm4571629edi.76.2024.03.12.15.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:46 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:43 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 24/68] libvhost-user: Dynamically remap rings after (temporarily?) removing memory regions Message-ID: <67f4f663cd6179d57f3e5a558f1526c7dc8c6742.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand Currently, we try to remap all rings whenever we add a single new memory region. That doesn't quite make sense, because we already map rings when setting the ring address, and panic if that goes wrong. Likely, that handling was simply copied from set_mem_table code, where we actually have to remap all rings. Remapping all rings might require us to walk quite a lot of memory regions to perform the address translations. Ideally, we'd simply remove that remapping. However, let's be a bit careful. There might be some weird corner cases where we might temporarily remove a single memory region (e.g., resize it), that would have worked for now. Further, a ring might be located on hotplugged memory, and as the VM reboots, we might unplug that memory, to hotplug memory before resetting the ring addresses. So let's unmap affected rings as we remove a memory region, and try dynamically mapping the ring again when required. Acked-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-14-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 107 ++++++++++++++++------ 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index ed0a978d4f..61fb3050b3 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -283,10 +283,75 @@ vu_remove_all_mem_regs(VuDev *dev) dev->nregions = 0; } +static bool +map_ring(VuDev *dev, VuVirtq *vq) +{ + vq->vring.desc = qva_to_va(dev, vq->vra.desc_user_addr); + vq->vring.used = qva_to_va(dev, vq->vra.used_user_addr); + vq->vring.avail = qva_to_va(dev, vq->vra.avail_user_addr); + + DPRINT("Setting virtq addresses:\n"); + DPRINT(" vring_desc at %p\n", vq->vring.desc); + DPRINT(" vring_used at %p\n", vq->vring.used); + DPRINT(" vring_avail at %p\n", vq->vring.avail); + + return !(vq->vring.desc && vq->vring.used && vq->vring.avail); +} + static bool vu_is_vq_usable(VuDev *dev, VuVirtq *vq) { - return likely(!dev->broken) && likely(vq->vring.avail); + if (unlikely(dev->broken)) { + return false; + } + + if (likely(vq->vring.avail)) { + return true; + } + + /* + * In corner cases, we might temporarily remove a memory region that + * mapped a ring. When removing a memory region we make sure to + * unmap any rings that would be impacted. Let's try to remap if we + * already succeeded mapping this ring once. + */ + if (!vq->vra.desc_user_addr || !vq->vra.used_user_addr || + !vq->vra.avail_user_addr) { + return false; + } + if (map_ring(dev, vq)) { + vu_panic(dev, "remapping queue on access"); + return false; + } + return true; +} + +static void +unmap_rings(VuDev *dev, VuDevRegion *r) +{ + int i; + + for (i = 0; i < dev->max_queues; i++) { + VuVirtq *vq = &dev->vq[i]; + const uintptr_t desc = (uintptr_t)vq->vring.desc; + const uintptr_t used = (uintptr_t)vq->vring.used; + const uintptr_t avail = (uintptr_t)vq->vring.avail; + + if (desc < r->mmap_addr || desc >= r->mmap_addr + r->size) { + continue; + } + if (used < r->mmap_addr || used >= r->mmap_addr + r->size) { + continue; + } + if (avail < r->mmap_addr || avail >= r->mmap_addr + r->size) { + continue; + } + + DPRINT("Unmapping rings of queue %d\n", i); + vq->vring.desc = NULL; + vq->vring.used = NULL; + vq->vring.avail = NULL; + } } static size_t @@ -786,21 +851,6 @@ vu_reset_device_exec(VuDev *dev, VhostUserMsg *vmsg) return false; } -static bool -map_ring(VuDev *dev, VuVirtq *vq) -{ - vq->vring.desc = qva_to_va(dev, vq->vra.desc_user_addr); - vq->vring.used = qva_to_va(dev, vq->vra.used_user_addr); - vq->vring.avail = qva_to_va(dev, vq->vra.avail_user_addr); - - DPRINT("Setting virtq addresses:\n"); - DPRINT(" vring_desc at %p\n", vq->vring.desc); - DPRINT(" vring_used at %p\n", vq->vring.used); - DPRINT(" vring_avail at %p\n", vq->vring.avail); - - return !(vq->vring.desc && vq->vring.used && vq->vring.avail); -} - static bool generate_faults(VuDev *dev) { unsigned int i; @@ -884,7 +934,6 @@ generate_faults(VuDev *dev) { static bool vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { - int i; VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m; if (vmsg->fd_num != 1) { @@ -930,19 +979,9 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { vmsg->fd_num = 0; DPRINT("Successfully added new region in postcopy\n"); return true; - } else { - for (i = 0; i < dev->max_queues; i++) { - if (dev->vq[i].vring.desc) { - if (map_ring(dev, &dev->vq[i])) { - vu_panic(dev, "remapping queue %d for new memory region", - i); - } - } - } - - DPRINT("Successfully added new region\n"); - return false; } + DPRINT("Successfully added new region\n"); + return false; } static inline bool reg_equal(VuDevRegion *vudev_reg, @@ -995,6 +1034,16 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { return false; } + /* + * There might be valid cases where we temporarily remove memory regions + * to readd them again, or remove memory regions and don't use the rings + * anymore before we set the ring addresses and restart the device. + * + * Unmap all affected rings, remapping them on demand later. This should + * be a corner case. + */ + unmap_rings(dev, r); + munmap((void *)(uintptr_t)r->mmap_addr, r->size + r->mmap_offset); idx = r - dev->regions; From patchwork Tue Mar 12 22:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NWefr1Ag; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT0w2C84z1ydl for ; Wed, 13 Mar 2024 09:32:32 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAal-0007MJ-5n; Tue, 12 Mar 2024 18:27:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaH-00054R-Fl for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaF-0004KV-1p for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:26:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282414; 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: in-reply-to:in-reply-to:references:references; bh=Co9AeQNCftuPr7tCy5EYmuY1ACdZWH3K/U2GLTPiBGU=; b=NWefr1AgBJc2mGmjCInRapboJJFVvYRfU3sIQbT/9Bt4JsYD+uLioCX9xOkSEkNBbnwQgW BJRhhLEf/xgBrvHeE2P7NwxHEBmPZqVmeWBMqGBTupkvdXoyMrs8s0ZnKZQrWyWCYlkJTp A9Ueke4OqQwgKxMeS9/Dy4piY7Xo+Bs= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-ukHqRQMDN02SZFWnyRFuUA-1; Tue, 12 Mar 2024 18:26:53 -0400 X-MC-Unique: ukHqRQMDN02SZFWnyRFuUA-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2d449d2db37so16056741fa.3 for ; Tue, 12 Mar 2024 15:26:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282411; x=1710887211; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Co9AeQNCftuPr7tCy5EYmuY1ACdZWH3K/U2GLTPiBGU=; b=vLhANlPA2mupHYEKQP3iut4/2MiamIp1/W5votkU1ZhkZZQ95gvkfgOzamEwPVhAM/ jjrH32WrV51vmuIhgnQmbSj3sdxtoDvbj5dnBNEcxDhhqHRD05dUMNJrj7w3rjMpCT1u P8s8NPmyCmd391gALQ97qwyXuvKM2VvFZWvJ4CkRp6/DFFwXO4xM5wdOuovY5eKylRGR usttTrn7Ju0ARakjxagX+YEe5JJaTSdzf0f47DRNcVY9+ES/BXjgGOW4R5BuLFUiiB80 KRUXnkessW6SFSicQ2hhLDgWSATB4PbZuCnTnkma3YR23F975oKyvQ9xEBYvMnhHEA3c DOig== X-Gm-Message-State: AOJu0Yz1E5uDNF6nSy9rGysVJySOyg9+M6MRdeIOtWUGx+f2pn2Pum1p 1xsDI3bqF3VLB8UYUNlK4raOk86zycc8m+isb2p/YIQYP/iqltWfkGShBEnRsPZ/il9irLG3PDB FhBXaARz4q9swjdTkKKCSrK6x7fcyF0rmxXN51lxzNnpvaA8VYtikcrDEfpmGCXV2+5n2QhPl9I X+AK8/z0FaP7qJbCxYRZ76AHdyGfWrycR+ X-Received: by 2002:a2e:a454:0:b0:2d2:a9d6:c435 with SMTP id v20-20020a2ea454000000b002d2a9d6c435mr6934965ljn.34.1710282411015; Tue, 12 Mar 2024 15:26:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLp6eB82URiPUxCOpRJfGkhOb8Y8+bEpirUtvEcKr+D8VxJnR1qOiEZA6ZAfDaTvQw/ep+EQ== X-Received: by 2002:a2e:a454:0:b0:2d2:a9d6:c435 with SMTP id v20-20020a2ea454000000b002d2a9d6c435mr6934945ljn.34.1710282410304; Tue, 12 Mar 2024 15:26:50 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id sa38-20020a1709076d2600b00a453123b111sm4217921ejc.120.2024.03.12.15.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:49 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:47 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , David Hildenbrand , Raphael Norwitz , Stefano Garzarella , Mario Casquero Subject: [PULL 25/68] libvhost-user: Mark mmap'ed region memory as MADV_DONTDUMP Message-ID: <52767e1063beaa17d59c739efd0b9c342923929d.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Hildenbrand We already use MADV_NORESERVE to deal with sparse memory regions. Let's also set madvise(MADV_DONTDUMP), otherwise a crash of the process can result in us allocating all memory in the mmap'ed region for dumping purposes. This change implies that the mmap'ed rings won't be included in a coredump. If ever required for debugging purposes, we could mark only the mapped rings MADV_DODUMP. Ignore errors during madvise() for now. Reviewed-by: Raphael Norwitz Acked-by: Stefano Garzarella Signed-off-by: David Hildenbrand Message-Id: <20240214151701.29906-15-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- subprojects/libvhost-user/libvhost-user.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index 61fb3050b3..a879149fef 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -460,6 +460,12 @@ _vu_add_mem_reg(VuDev *dev, VhostUserMemoryRegion *msg_region, int fd) DPRINT(" mmap_addr: 0x%016"PRIx64"\n", (uint64_t)(uintptr_t)mmap_addr); +#if defined(__linux__) + /* Don't include all guest memory in a coredump. */ + madvise(mmap_addr, msg_region->memory_size + mmap_offset, + MADV_DONTDUMP); +#endif + /* Shift all affected entries by 1 to open a hole at idx. */ r = &dev->regions[idx]; memmove(r + 1, r, sizeof(VuDevRegion) * (dev->nregions - idx)); From patchwork Tue Mar 12 22:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y6pVXa07; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSvc1THVz1yWt for ; Wed, 13 Mar 2024 09:27:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAad-0006Al-DC; Tue, 12 Mar 2024 18:27:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaK-00059Z-T9 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaI-0004Kh-67 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282417; 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: in-reply-to:in-reply-to:references:references; bh=fbl/4oY5S27H5N4x4Mfso73+4TVfz4B6Urk0mgRqeEc=; b=Y6pVXa07AWElXBenVKGKiOliTNFTBFw2TLZ53vhiLxKFP9k4UEK/3wvOUfJZVoDoGpfyDU gIRk1vjRKOjAy5vYymsV2lX1yvdSHWRpNtLE9dyWOE6BS3RZIds5e/UIQHnXI4PUEQwqXz Q1IWrq0O/JXa+rOLYOD12GQn6WxXWMY= 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-583-_SUAqW6sN0i1_1h1pn4w_Q-1; Tue, 12 Mar 2024 18:26:56 -0400 X-MC-Unique: _SUAqW6sN0i1_1h1pn4w_Q-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a4606018ec4so29755966b.0 for ; Tue, 12 Mar 2024 15:26:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282414; x=1710887214; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fbl/4oY5S27H5N4x4Mfso73+4TVfz4B6Urk0mgRqeEc=; b=CNWxmjBvPinn3GIYB9HZTML/dk06XTB2st9jqP4IHLzgGsdWTrbWqELP2k0Zaz7F+9 pvWUJ9iBqIoIAoDX2uDwZh3lOgDtre6htQYwypMbVar315Jwmi2iM7yzop3PkIolKYtb VRjZ/JGCj9Sia3Pij0iZrDuVcsGd9nBbsWRLLI2ShQUP7caPfNwYe7gJ4eM9+bnN+UTv EODjnEIOKi1YsEC7BEBmdxuLCiNOC7pUd2VfUr1dXh1KFqmEoO59LMtvfQ6e9+EDkOkK rBXwZTwqttCMC75rui6nrGdoI3Xw5ntOoEFeSY88Ugtl1qTcJ81TvmBvy9Oo2xreK8rb fn1A== X-Gm-Message-State: AOJu0YxgXbScLPuZ4NqnEeZcz9ljAZ2N0gprRw4AR9FEsn88mhwQdRgf 1j0sqZCn2frpNJslo8ThEEJdefygHCZgVYiEe6hekRNzNrM7mqWw5tuXz9L9ucVR+1UJkLfLOmx itEEIQvb2do/OaigTp/FHxiIsGe8rHuzjA74rSzf4aj2v16S+2EopIq5ZsUISKCTVMVH+UKOqx4 jY+xuLpdJr1Rt2ThmrF8kA3p8PsRDjIUsI X-Received: by 2002:a17:906:ba84:b0:a46:13a0:2e5c with SMTP id cu4-20020a170906ba8400b00a4613a02e5cmr797812ejd.25.1710282414408; Tue, 12 Mar 2024 15:26:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkM5wjMUTJem7bMnk1rIh4+fw7093GCMqaUGBLDBhtf+NP1nzXwtGQofoGY2DEKFZAUu4pVg== X-Received: by 2002:a17:906:ba84:b0:a46:13a0:2e5c with SMTP id cu4-20020a170906ba8400b00a4613a02e5cmr797775ejd.25.1710282413823; Tue, 12 Mar 2024 15:26:53 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id x6-20020a1709065ac600b00a465ad6e994sm6687ejs.152.2024.03.12.15.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:53 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:50 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Lukas Stockner , Manos Pitsidianakis , Paolo Bonzini , Daniel =?utf-8?b?UC4gQmVycmFuZ8Op?= , Eduardo Habkost , Marcel Apfelbaum , Eric Blake , Markus Armbruster Subject: [PULL 26/68] pcie: Support PCIe Gen5/Gen6 link speeds Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Lukas Stockner This patch extends the PCIe link speed option so that slots can be configured as supporting 32GT/s (Gen5) or 64GT/s (Gen5) speeds. This is as simple as setting the appropriate bit in LnkCap2 and the appropriate value in LnkCap and LnkCtl2. Signed-off-by: Lukas Stockner Message-Id: <20240215012326.3272366-1-lstockner@genesiscloud.com> Reviewed-by: Manos Pitsidianakis Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/common.json | 6 +++++- include/hw/pci/pcie_regs.h | 2 ++ hw/core/qdev-properties-system.c | 16 ++++++++++++++-- hw/pci/pcie.c | 8 ++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/qapi/common.json b/qapi/common.json index f1bb841951..867a9ad9b0 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -107,10 +107,14 @@ # # @16: 16.0GT/s # +# @32: 32.0GT/s +# +# @64: 64.0GT/s +# # Since: 4.0 ## { 'enum': 'PCIELinkSpeed', - 'data': [ '2_5', '5', '8', '16' ] } + 'data': [ '2_5', '5', '8', '16', '32', '64' ] } ## # @PCIELinkWidth: diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h index 4972106c42..9d3b6868dc 100644 --- a/include/hw/pci/pcie_regs.h +++ b/include/hw/pci/pcie_regs.h @@ -39,6 +39,8 @@ typedef enum PCIExpLinkSpeed { QEMU_PCI_EXP_LNK_5GT, QEMU_PCI_EXP_LNK_8GT, QEMU_PCI_EXP_LNK_16GT, + QEMU_PCI_EXP_LNK_32GT, + QEMU_PCI_EXP_LNK_64GT, } PCIExpLinkSpeed; #define QEMU_PCI_EXP_LNKCAP_MLS(speed) (speed) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index b45e90edb2..28ce6162c7 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -955,7 +955,7 @@ const PropertyInfo qdev_prop_off_auto_pcibar = { .set_default_value = qdev_propinfo_set_default_value_enum, }; -/* --- PCIELinkSpeed 2_5/5/8/16 -- */ +/* --- PCIELinkSpeed 2_5/5/8/16/32/64 -- */ static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -977,6 +977,12 @@ static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name, case QEMU_PCI_EXP_LNK_16GT: speed = PCIE_LINK_SPEED_16; break; + case QEMU_PCI_EXP_LNK_32GT: + speed = PCIE_LINK_SPEED_32; + break; + case QEMU_PCI_EXP_LNK_64GT: + speed = PCIE_LINK_SPEED_64; + break; default: /* Unreachable */ abort(); @@ -1010,6 +1016,12 @@ static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name, case PCIE_LINK_SPEED_16: *p = QEMU_PCI_EXP_LNK_16GT; break; + case PCIE_LINK_SPEED_32: + *p = QEMU_PCI_EXP_LNK_32GT; + break; + case PCIE_LINK_SPEED_64: + *p = QEMU_PCI_EXP_LNK_64GT; + break; default: /* Unreachable */ abort(); @@ -1018,7 +1030,7 @@ static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name, const PropertyInfo qdev_prop_pcie_link_speed = { .name = "PCIELinkSpeed", - .description = "2_5/5/8/16", + .description = "2_5/5/8/16/32/64", .enum_table = &PCIELinkSpeed_lookup, .get = get_prop_pcielinkspeed, .set = set_prop_pcielinkspeed, diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 6db0cf69cd..0b4817e144 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -153,6 +153,14 @@ static void pcie_cap_fill_slot_lnk(PCIDevice *dev) pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKCAP2, PCI_EXP_LNKCAP2_SLS_16_0GB); } + if (s->speed > QEMU_PCI_EXP_LNK_16GT) { + pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKCAP2, + PCI_EXP_LNKCAP2_SLS_32_0GB); + } + if (s->speed > QEMU_PCI_EXP_LNK_32GT) { + pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKCAP2, + PCI_EXP_LNKCAP2_SLS_64_0GB); + } } } From patchwork Tue Mar 12 22:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Kfk0QgKz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSvd3Vp0z1yWt for ; Wed, 13 Mar 2024 09:27:57 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAaa-0005hc-MF; Tue, 12 Mar 2024 18:27:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaM-0005CY-C8 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:05 -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 1rkAaK-0004Ks-SW for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282420; 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=wh6YuVoxx+DYLxPaX83mzfkVZkTHaR33Y90YpXonUkk=; b=Kfk0QgKzsJS4GswQ0AxDnSjUz2tVEkbpNVmeBmocB41Giq0Hk6xhHZwE2Q0fy7YVs6T7Aa 9p74TjHQOifjYWhNTK3/UK6uioFoxvimcs/WG8/VTfsGYZsmX2bwwBzxC7SvVA/0yFHu4M t3Ru6fgCJTePpA9mUsv2/J8M+fLBw8Y= 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-38-Lho1bPFlNP6Pm3q_YxlnUA-1; Tue, 12 Mar 2024 18:26:59 -0400 X-MC-Unique: Lho1bPFlNP6Pm3q_YxlnUA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a44143c8908so27848466b.1 for ; Tue, 12 Mar 2024 15:26:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282417; x=1710887217; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wh6YuVoxx+DYLxPaX83mzfkVZkTHaR33Y90YpXonUkk=; b=ZvwlLb40IaDsJzi1FXvl6iWtisDtcv3wuzTQbXfhwIZsImsv57HzW2Qx1foUhZh/dd 6eXayy4qu6o5Oin6E58WTSWp12eCtfhrYZ7HdaN8iK+NOgnQaZTuq26fBPg3WF72a9v9 V/z6BF2+9txan/zXL9j66LDepMvBR6mUCGGimeU2FR2h8u/iuRQv9iB0AY6qu/GbMTB9 RNZK/W98WMU5Di/QoGrmmrITtll8Fj6xLmCp2gBLj4X+jLCHS3m/9hBlUlVkNIlsWTKk 85BlWHx+9lEvduEijMfYx10SyyhdcU9Kw4idCI4XRNP0H7/DTAr3zg7maT+wWu617yTb qAew== X-Gm-Message-State: AOJu0YwSq9O93I4viCONsQSFO5vYmvCwamNl03a6JXYD8ly3prkSlRS5 GCoPhojtblEF+YxuZvz0fbLV33L8t2p5+bOp6v8bfZ28vLqJVrPIDHfvodkR3YveIkSqWyS3GRf GfQTGw7fm0TfdgV9lTtFVi5WiAc0lumu8jk2PvaNZRdcSUBPGSVL4O5llLq7/2fFJxUJXZxYp5g UfouKa/CPxn7DyomPsUApLM+cHDftymIP2 X-Received: by 2002:a17:906:3511:b0:a46:371b:c4d5 with SMTP id r17-20020a170906351100b00a46371bc4d5mr815102eja.22.1710282417132; Tue, 12 Mar 2024 15:26:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBwZQhv8wXOSlf5kWVr6MCyK/Jh40PObLKzbVq92mpJ+119Eo9rJiLpnqS4I8QG/+u+duFAw== X-Received: by 2002:a17:906:3511:b0:a46:371b:c4d5 with SMTP id r17-20020a170906351100b00a46371bc4d5mr815084eja.22.1710282416607; Tue, 12 Mar 2024 15:26:56 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id bx4-20020a170906a1c400b00a4528658771sm4212653ejb.31.2024.03.12.15.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:56 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:54 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eugenio =?utf-8?b?UMOpcmV6?= Subject: [PULL 27/68] vdpa: stash memory region properties in vars Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eugenio Pérez Next changes uses this variables, so avoid call repeatedly to memory region functions. No functional change intended. Signed-off-by: Eugenio Pérez Message-Id: <20240215103616.330518-2-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index c968278e70..5559d4f89c 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -47,12 +47,14 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, int page_mask) { Int128 llend; + bool is_ram = memory_region_is_ram(section->mr); + bool is_iommu = memory_region_is_iommu(section->mr); + bool is_protected = memory_region_is_protected(section->mr); - if ((!memory_region_is_ram(section->mr) && - !memory_region_is_iommu(section->mr)) || - memory_region_is_protected(section->mr) || - /* vhost-vDPA doesn't allow MMIO to be mapped */ - memory_region_is_ram_device(section->mr)) { + /* vhost-vDPA doesn't allow MMIO to be mapped */ + bool is_ram_device = memory_region_is_ram_device(section->mr); + + if ((!is_ram && !is_iommu) || is_protected || is_ram_device) { return true; } @@ -69,7 +71,7 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, * size that maps to the kernel */ - if (!memory_region_is_iommu(section->mr)) { + if (!is_iommu) { llend = vhost_vdpa_section_end(section, page_mask); if (int128_gt(llend, int128_make64(iova_max))) { error_report("RAM section out of device range (max=0x%" PRIx64 From patchwork Tue Mar 12 22:26:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911392 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TkEGZAAC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSvy2TS2z23qj for ; Wed, 13 Mar 2024 09:28:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAah-0006qZ-G7; Tue, 12 Mar 2024 18:27:23 -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 1rkAaP-0005Cr-2x for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaN-0004L9-Kr for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282423; 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=AurzQqFpLzlXuBxIL8RZRvJLoJVHujck2MunJ5OHm/A=; b=TkEGZAAC023Wk4Od/24M7nYvAE7e8Bt12uAHsKH6TxhZmMoKqBdvRe0n/Bcyfw7MoUHmav /2HAi73PPVLpL78hl/4NBdVbGBfLidJmVxzapMbUmeNFsBpO9T0peEBEszSd1exWjeMozk ZSEOczvxod9B8YGDzyI+MB4qHhElxdU= 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-668-iVtBERrFOf-8rWQyqUohXA-1; Tue, 12 Mar 2024 18:27:01 -0400 X-MC-Unique: iVtBERrFOf-8rWQyqUohXA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a4651c22fd2so13431966b.3 for ; Tue, 12 Mar 2024 15:27:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282419; x=1710887219; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AurzQqFpLzlXuBxIL8RZRvJLoJVHujck2MunJ5OHm/A=; b=wmLqc7GSw0oX7T3boca5yBolys1qVN84wPq+SccF9RLOfinX50XJYIL6Xsb0r7jrL2 Y76A/GgY/j02tH66Ol6isttPGEc1t2x7FkR+iXqSg7p8BRhO+vSCig+sYNCuh69ZmTkY 8QoivkGcIMvbze6ynXt/edJqfG/u/7cZ1Ntm+RHIid9ZPy4HPp8sHTMxIn8n/g6vvXOT fgb2t+XicwkLtBTqZMnx8uiCeng+n/0qw4WoclXS1k84pk8EMYzHCyMqZ93wPwwVke8m 1q+bcCqJ2U0Cpsn+yEGNZLWrQGb33ebS6T1GuEK1WWloQyEtfuPJ54E+I14AmKS69Xwn OT1Q== X-Gm-Message-State: AOJu0Yz9GwDd3POXxpRpTiqur4wKnELcPkwZwHtIRlu7d7V50UKIKwZZ tKOwRc8kmlBKubvRzPKKS/WxFCDarV5PiNhJTzonDiuTWKYmVNc7WPMTpnBH0fl/PgEq4c9NXeY deTW4G1HKVGkLFvS1xIsBFE81A/BV9cvu8U1f/DgZggK70iMZ7jZwnhAEZH96HXR72lGD/HYUPk RC5U9/QHRwIMAcdDZX8wLORt6Wn9I4pJ+g X-Received: by 2002:a17:906:3984:b0:a44:1f3:e474 with SMTP id h4-20020a170906398400b00a4401f3e474mr6422436eje.23.1710282419582; Tue, 12 Mar 2024 15:26:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYD/1NG1Sa14VJz3wbarGz8hPiW7rFJxlXu8xjn1LlPtMm9umoofuX94IQIgERRJIL/ZRTIw== X-Received: by 2002:a17:906:3984:b0:a44:1f3:e474 with SMTP id h4-20020a170906398400b00a4401f3e474mr6422425eje.23.1710282419137; Tue, 12 Mar 2024 15:26:59 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id lt9-20020a170906fa8900b00a45c4d3ee11sm4224960ejb.123.2024.03.12.15.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:26:58 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:56 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eugenio =?utf-8?b?UMOpcmV6?= Subject: [PULL 28/68] vdpa: trace skipped memory sections Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eugenio Pérez Sometimes, certain parts are not being skipped in vhost_vdpa_listener_region_del, but they are skipped in vhost_vdpa_listener_region_add, or vice versa. The vhost-vdpa code expects all parts to maintain their properties, so we're adding a trace to help with debugging when any part is skipped. Signed-off-by: Eugenio Pérez Message-Id: <20240215103616.330518-3-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-vdpa.c | 3 +++ hw/virtio/trace-events | 1 + 2 files changed, 4 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 5559d4f89c..3bcd05cc22 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -55,6 +55,9 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, bool is_ram_device = memory_region_is_ram_device(section->mr); if ((!is_ram && !is_iommu) || is_protected || is_ram_device) { + trace_vhost_vdpa_skipped_memory_section(is_ram, is_iommu, is_protected, + is_ram_device, iova_min, + iova_max, page_mask); return true; } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 20577aa584..9df24864a2 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -30,6 +30,7 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c +vhost_vdpa_skipped_memory_section(int is_ram, int is_iommu, int is_protected, int is_ram_device, uint64_t first, uint64_t last, int page_mask) "is_ram=%d, is_iommu=%d, is_protected=%d, is_ram_device=%d iova_min=0x%"PRIx64" iova_last=0x%"PRIx64" page_mask=0x%x" vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 From patchwork Tue Mar 12 22:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=f2nDNgNC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT9W426Rz1yWy for ; Wed, 13 Mar 2024 09:39:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAaf-0006Sr-66; Tue, 12 Mar 2024 18:27:21 -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 1rkAaU-0005FT-01 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:12 -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 1rkAaP-0004LL-SF for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282425; 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: in-reply-to:in-reply-to:references:references; bh=Fp9mS7QfM+i2wlqzdpjfyEOvEAobNn6YKxIWUVqj07Y=; b=f2nDNgNCLqkpLr1JCfwC/b3KEjUIu32fdTYNzLc6A1+pjylvinp6VmOckFOgAnFj3uopI1 r2BuHlttTEiFZ3WjKAz3YrFgQHwEFL622tF80fXyE2TX2xUlSeJECcEUMstvu9CgmLuWk6 DgZ9IgXCUQoXsbNOw7/BX/tDWtPj7Yk= 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-684-UX_qX2bnNyqpzBH8LA0_gA-1; Tue, 12 Mar 2024 18:27:04 -0400 X-MC-Unique: UX_qX2bnNyqpzBH8LA0_gA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a4488afb812so23111366b.3 for ; Tue, 12 Mar 2024 15:27:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282423; x=1710887223; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Fp9mS7QfM+i2wlqzdpjfyEOvEAobNn6YKxIWUVqj07Y=; b=Kaj4R5oW0XZxVWsbnWKTdj6WJqcrvJLJrOEA/eeYkwmTf8R3vFJvVjEHT+hOyKBzLZ zVczOMRwTZiJDT1AMblJVzseniHo6V/brNEP6XjxumHN5zv2QHH8WOcGUH52zh/qW1UC Xs18PPr2lixW28zOK9Cmv3dOrsCWukF91gCa3jHaLH38SoO0qG/qbuDbSgImfIdYyXCq +oNP5sSqfrHjjMBuxtWyq9l0jgS+g1HECxsJCFhpqVn2Q5+2V39kwEXX9WOVSVp/d30m pXtqPZOfcmfZkr9im2kB1Y5Ey29BmKUu/X0dxPVZtALVzF3NOIHy6tNWZ389kwvcSltd +sAg== X-Gm-Message-State: AOJu0YxQhX1sNFKOVB2Q+c0r8t7CmdjAyEi1Daza+gaVEM7FX2XAAq6V 3OYpb8vLhDwfyMwKrpCcY5vqRPZmHm/oQPm8leHEIGCepCNMd8PAqNXUL0NLDGwJZWr1yFDbjzT G7bSjOmB02pV4JHe3JAoGZyriDb4d3jtPAr2UpP7ZqYg04Tx/FKRTCzpKrOiJ+ty3YE0zmHrF+G /Uj+KEpn+uasMO30EVlgOKDT6b/IQhjBmt X-Received: by 2002:a17:906:6b97:b0:a46:5277:79b0 with SMTP id l23-20020a1709066b9700b00a46527779b0mr358970ejr.21.1710282422667; Tue, 12 Mar 2024 15:27:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMxoGdSAd7PH+l40CgdNm6iIezqlbzyxoxMV/n5yoxszf5Y1pTfDtct88ikFByTxy+KBcZ1Q== X-Received: by 2002:a17:906:6b97:b0:a46:5277:79b0 with SMTP id l23-20020a1709066b9700b00a46527779b0mr358954ejr.21.1710282422088; Tue, 12 Mar 2024 15:27:02 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id o23-20020a1709062e9700b00a44cf710cc3sm4213832eji.182.2024.03.12.15.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:01 -0700 (PDT) Date: Tue, 12 Mar 2024 18:26:59 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Fan Ni , Marcel Apfelbaum Subject: [PULL 29/68] hw/pci-bridge/pxb-cxl: Drop RAS capability from host bridge. Message-ID: <3a95f572112ab4c789d66af666644adcdb2b45a6.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jonathan Cameron This CXL component isn't allowed to have a RAS capability. Whilst this should be harmless as software is not expected to look here, good to clean it up. Signed-off-by: Jonathan Cameron Message-Id: <20240215155206.2736-1-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/cxl/cxl_component.h | 1 + hw/cxl/cxl-component-utils.c | 21 +++++++++++++++++---- hw/pci-bridge/pci_expander_bridge.c | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/hw/cxl/cxl_component.h b/include/hw/cxl/cxl_component.h index 0e5d35c263..5012fab6f7 100644 --- a/include/hw/cxl/cxl_component.h +++ b/include/hw/cxl/cxl_component.h @@ -25,6 +25,7 @@ enum reg_type { CXL2_TYPE3_DEVICE, CXL2_LOGICAL_DEVICE, CXL2_ROOT_PORT, + CXL2_RC, CXL2_UPSTREAM_PORT, CXL2_DOWNSTREAM_PORT, CXL3_SWITCH_MAILBOX_CCI, diff --git a/hw/cxl/cxl-component-utils.c b/hw/cxl/cxl-component-utils.c index 84ab503325..cd116c0401 100644 --- a/hw/cxl/cxl-component-utils.c +++ b/hw/cxl/cxl-component-utils.c @@ -297,6 +297,7 @@ void cxl_component_register_init_common(uint32_t *reg_state, caps = 3; break; case CXL2_ROOT_PORT: + case CXL2_RC: /* + Extended Security, + Snoop */ caps = 5; break; @@ -326,8 +327,19 @@ void cxl_component_register_init_common(uint32_t *reg_state, CXL_##reg##_REGISTERS_OFFSET); \ } while (0) + switch (type) { + case CXL2_DEVICE: + case CXL2_TYPE3_DEVICE: + case CXL2_LOGICAL_DEVICE: + case CXL2_ROOT_PORT: + case CXL2_UPSTREAM_PORT: + case CXL2_DOWNSTREAM_PORT: init_cap_reg(RAS, 2, CXL_RAS_CAPABILITY_VERSION); - ras_init_common(reg_state, write_msk); + ras_init_common(reg_state, write_msk); + break; + default: + break; + } init_cap_reg(LINK, 4, CXL_LINK_CAPABILITY_VERSION); @@ -335,9 +347,10 @@ void cxl_component_register_init_common(uint32_t *reg_state, return; } - init_cap_reg(HDM, 5, CXL_HDM_CAPABILITY_VERSION); - hdm_init_common(reg_state, write_msk, type); - + if (type != CXL2_ROOT_PORT) { + init_cap_reg(HDM, 5, CXL_HDM_CAPABILITY_VERSION); + hdm_init_common(reg_state, write_msk, type); + } if (caps < 5) { return; } diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c index 535889f7c2..0411ad31ea 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -290,7 +290,7 @@ static void pxb_cxl_dev_reset(DeviceState *dev) uint32_t *write_msk = cxl_cstate->crb.cache_mem_regs_write_mask; int dsp_count = 0; - cxl_component_register_init_common(reg_state, write_msk, CXL2_ROOT_PORT); + cxl_component_register_init_common(reg_state, write_msk, CXL2_RC); /* * The CXL specification allows for host bridges with no HDM decoders * if they only have a single root port. From patchwork Tue Mar 12 22:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Sz1k3gH8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT312Mpgz1ydl for ; Wed, 13 Mar 2024 09:34:21 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAac-00062C-IK; Tue, 12 Mar 2024 18:27:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaU-0005Jr-RX for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaT-0004Li-A8 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282428; 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=HZviP4yQ6PlfNYlhjLnO9O0fDmhpIErXsX1IdIBxhxY=; b=Sz1k3gH8Bw4DCRAuHxGXQDE+xRu4C9/7DYOborcbXIsWNyOnVYsov6VfTLBXGdYjryasgW TKJTntR/d8wlR+nAMTd2yv8MlT9mUEk+EIeuiT/mnQrBp+YIpyKyeKDpG5QC9MsKT+8wxT HPKsLXCY/SqVfxMnkXyhu5M73HSFRsw= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-d4WTOU5SM_OTp5vbNf6guA-1; Tue, 12 Mar 2024 18:27:07 -0400 X-MC-Unique: d4WTOU5SM_OTp5vbNf6guA-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5684650b00bso197475a12.2 for ; Tue, 12 Mar 2024 15:27:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282426; x=1710887226; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HZviP4yQ6PlfNYlhjLnO9O0fDmhpIErXsX1IdIBxhxY=; b=GbkEJJUB1nAieTIg25lkxX7O5JJftRUbSXT36rNHQ4D8bDDxPZhWaXR+uzgdlqDgsk Ndujii3gHqcqXHlB65zO6N2s7h3v80hwmb2EvH8oyo/RsXLi6iq3k69vJarA6MVYTAXV En81/qlK5lmNE0NYsrBgVTHT4IfwxcnKipr5DTo396d/ZlE76dRzSuiGpV6jq7qrf/Yz MxzBBpFXi07BML+z5bAKbaIeXc0PKojxCIY8DNn0viVHDd2W4HzNHCagXHh/UMA6Qdi/ LdWD6Uk7TSEXtFeXL+Av4zqEqATv5hru8MBXLsunCyeXQ/ZgcOU9jHRWv7iV1nyctYuD XGdw== X-Gm-Message-State: AOJu0Yxu9WdgjQ7FSfVMx+CgB8A8Keslf78RuxNIA55vYh4+OovtU7pg kDTA3U7xgf1fde++shrBIjP1chkjOlSZup4Hfm2ewMu42MHynbfLeHw4Hn8LYy/lIXUoER/VS79 m7I2QrvNGGBpiWohewfUMT5oSSgrhpqv9mRdP3lpYE+5MnFDKXZLZFRSeUC8VmC6RPooso53F/P AROcNh+jca2zqKzQfQxqVy9h+1+0nSVjsW X-Received: by 2002:a50:d69b:0:b0:568:1c9c:95a7 with SMTP id r27-20020a50d69b000000b005681c9c95a7mr3130005edi.40.1710282426083; Tue, 12 Mar 2024 15:27:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfHQzJ1JyQ7t76fDjre6/5htUCC57Xu8nWAgvtBGdQOxE6DKGNxgCsu4K3e7aDb+q3J0GZbQ== X-Received: by 2002:a50:d69b:0:b0:568:1c9c:95a7 with SMTP id r27-20020a50d69b000000b005681c9c95a7mr3129989edi.40.1710282425662; Tue, 12 Mar 2024 15:27:05 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id r14-20020aa7cfce000000b005687f8721f9sm296397edy.82.2024.03.12.15.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:05 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:02 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Volker =?utf-8?q?R=C3=BCmelin?= , =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9?= Lureau , Gerd Hoffmann , Manos Pitsidianakis Subject: [PULL 30/68] hw/audio/virtio-sound: return correct command response size Message-ID: <633487df8d303b37a88584d5a57a39dbcd91c7bf.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Volker Rümelin The payload size returned by command VIRTIO_SND_R_PCM_INFO is wrong. The code in process_cmd() assumes that all commands return only a virtio_snd_hdr payload, but some commands like VIRTIO_SND_R_PCM_INFO may return an additional payload. Add a zero initialized payload_size variable to struct virtio_snd_ctrl_command to allow for additional payloads. Reviewed-by: Marc-André Lureau Signed-off-by: Volker Rümelin Message-Id: <20240218083351.8524-1-vr_qemu@t-online.de> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/audio/virtio-snd.h | 1 + hw/audio/virtio-snd.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index c3767f442b..3d79181364 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -230,6 +230,7 @@ struct virtio_snd_ctrl_command { VirtQueue *vq; virtio_snd_hdr ctrl; virtio_snd_hdr resp; + size_t payload_size; QTAILQ_ENTRY(virtio_snd_ctrl_command) next; }; #endif diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index ea2aeaef14..e604d8f30c 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -243,12 +243,13 @@ static void virtio_snd_handle_pcm_info(VirtIOSound *s, memset(&pcm_info[i].padding, 0, 5); } + cmd->payload_size = sizeof(virtio_snd_pcm_info) * count; cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_OK); iov_from_buf(cmd->elem->in_sg, cmd->elem->in_num, sizeof(virtio_snd_hdr), pcm_info, - sizeof(virtio_snd_pcm_info) * count); + cmd->payload_size); } /* @@ -749,7 +750,8 @@ process_cmd(VirtIOSound *s, virtio_snd_ctrl_command *cmd) 0, &cmd->resp, sizeof(virtio_snd_hdr)); - virtqueue_push(cmd->vq, cmd->elem, sizeof(virtio_snd_hdr)); + virtqueue_push(cmd->vq, cmd->elem, + sizeof(virtio_snd_hdr) + cmd->payload_size); virtio_notify(VIRTIO_DEVICE(s), cmd->vq); } @@ -808,6 +810,7 @@ static void virtio_snd_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) cmd->elem = elem; cmd->vq = vq; cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_OK); + /* implicit cmd->payload_size = 0; */ QTAILQ_INSERT_TAIL(&s->cmdq, cmd, next); elem = virtqueue_pop(vq, sizeof(VirtQueueElement)); } From patchwork Tue Mar 12 22:27:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iC1cdtnf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT6y57BKz23qj for ; Wed, 13 Mar 2024 09:37:46 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAag-0006i1-M6; Tue, 12 Mar 2024 18:27:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaZ-0005bo-RZ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaX-0004MR-Nt for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282433; 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: in-reply-to:in-reply-to:references:references; bh=E/KhWbfbprqpAcQoWcPKeg1kaPY6b8jfhMedPQoGKm8=; b=iC1cdtnfNXiGKwMaCc9Kru5rtNL7QUCcG0FoTiEX3XDMlVgqSp33rPEs1L0DzdZfbef0Gf bJdnJeqaBZZo341zTY8hfjJKVM7ihuZorBJ6t31oYl4h7PhJBECWWjvKuhyQNsq/VKBfCw 4r0Oy19GrZ5+/jJSXOIbd+BvpBW3AIU= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-tQTwYCJ7MUKcnc-jK0zWFQ-1; Tue, 12 Mar 2024 18:27:11 -0400 X-MC-Unique: tQTwYCJ7MUKcnc-jK0zWFQ-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-513b2e92c19so2692681e87.3 for ; Tue, 12 Mar 2024 15:27:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282430; x=1710887230; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E/KhWbfbprqpAcQoWcPKeg1kaPY6b8jfhMedPQoGKm8=; b=gpICx4q33SRuXyp2KQQleH+R/O+8bshcDWSFjYhqvaQ4rHfiMaXH4nzPz70Xdqw/RJ i5/JaDc17K+rGM3zJSP0tBC/It1krZZA9pDa64Ry93mQQHEuW7LwxErj/6d9xML6YW6t sMOQUTzXDUmdEKk9JV7pBv6Jjm4k2mMqp7k6DXSvFPkxFLHUPXQCLa9TPZ2MNIK8LQNq 71t50Hcopo4DW2w87NRleovbh/oHodWGmRhYFWg+z+/7u7ZnUsMoDtXIJtxZcRxUmMaV 4gWbmXEh1sGdx9UbrpGSjppItx3rqgCinkJ57i5kXrE35fxoLxEpf5zrfnGYO8I6lZjZ 7BkA== X-Gm-Message-State: AOJu0YzvxtMYys6fM8JfdfNVnb0t714JL1NIZZMXzRCJ7ozE7fi2Mf15 5eIO9RIHR7HGGePFOmPjwDEUiU8059rW0yuhI30ueXJ9aBJkw8HB+Maf7najjOz1QxQ34pI/FqS YoXHph6gvJH8BNgLVh2jCuAR7akO1m786y+nXLsxeEdpIDJ1EQU1wkRZ3OFS0lqlwLKYq6QnbfH 1Zd9fm0WhzDd9Z0QEBimvUbaDzLTRxKD4b X-Received: by 2002:a19:7607:0:b0:513:1561:af08 with SMTP id c7-20020a197607000000b005131561af08mr6854754lff.60.1710282429658; Tue, 12 Mar 2024 15:27:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKgJmjKml6kZ20bxUvmvsQSjKMsRjxuZ3sy0MwxgT1LG4tuunvV/OHWfgWZQN60VvmzpRn1Q== X-Received: by 2002:a19:7607:0:b0:513:1561:af08 with SMTP id c7-20020a197607000000b005131561af08mr6854742lff.60.1710282429129; Tue, 12 Mar 2024 15:27:09 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id k13-20020a1709065fcd00b00a44f0d99d58sm4209874ejv.208.2024.03.12.15.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:08 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:05 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Albert Esteve , Stefan Hajnoczi Subject: [PULL 31/68] hw/virtio: check owner for removing objects Message-ID: <043e127a126bb3ceb5fc753deee27d261fd0c5ce.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Albert Esteve Shared objects lack spoofing protection. For VHOST_USER_BACKEND_SHARED_OBJECT_REMOVE messages received by the vhost-user interface, any backend was allowed to remove entries from the shared table just by knowing the UUID. Only the owner of the entry shall be allowed to removed their resources from the table. To fix that, add a check for all *SHARED_OBJECT_REMOVE messages received. A vhost device can only remove TYPE_VHOST_DEV entries that are owned by them, otherwise skip the removal, and inform the device that the entry has not been removed in the answer. Signed-off-by: Albert Esteve Acked-by: Stefan Hajnoczi Message-Id: <20240219143423.272012-2-aesteve@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-user.c | 21 +++++++++++++++++++-- docs/interop/vhost-user.rst | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index a1eea8547e..9d654efd3d 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1611,11 +1611,27 @@ vhost_user_backend_handle_shared_object_add(struct vhost_dev *dev, } static int -vhost_user_backend_handle_shared_object_remove(VhostUserShared *object) +vhost_user_backend_handle_shared_object_remove(struct vhost_dev *dev, + VhostUserShared *object) { QemuUUID uuid; memcpy(uuid.data, object->uuid, sizeof(object->uuid)); + switch (virtio_object_type(&uuid)) { + case TYPE_VHOST_DEV: + { + struct vhost_dev *owner = virtio_lookup_vhost_device(&uuid); + if (dev != owner) { + /* Not allowed to remove non-owned entries */ + return 0; + } + break; + } + default: + /* Not allowed to remove non-owned entries */ + return 0; + } + return virtio_remove_resource(&uuid); } @@ -1794,7 +1810,8 @@ static gboolean backend_read(QIOChannel *ioc, GIOCondition condition, ret = vhost_user_backend_handle_shared_object_add(dev, &payload.object); break; case VHOST_USER_BACKEND_SHARED_OBJECT_REMOVE: - ret = vhost_user_backend_handle_shared_object_remove(&payload.object); + ret = vhost_user_backend_handle_shared_object_remove(dev, + &payload.object); break; case VHOST_USER_BACKEND_SHARED_OBJECT_LOOKUP: ret = vhost_user_backend_handle_shared_object_lookup(dev->opaque, ioc, diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index d1ed39dfa0..d8419fd2f1 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -1839,7 +1839,9 @@ is sent by the front-end. When the ``VHOST_USER_PROTOCOL_F_SHARED_OBJECT`` protocol feature has been successfully negotiated, this message can be submitted by the backend to remove themselves from to the virtio-dmabuf shared - table API. The shared table will remove the back-end device associated with + table API. Only the back-end owning the entry (i.e., the one that first added + it) will have permission to remove it. Otherwise, the message is ignored. + The shared table will remove the back-end device associated with the UUID. If ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, and the back-end sets the ``VHOST_USER_NEED_REPLY`` flag, the front-end must respond with zero when operation is successfully completed, or non-zero otherwise. From patchwork Tue Mar 12 22:27:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=af2beovl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT0B68b7z1ydl for ; Wed, 13 Mar 2024 09:31:54 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAal-0007NY-F8; Tue, 12 Mar 2024 18:27:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAae-0006RZ-Ul for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:21 -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 1rkAab-0004NC-2u for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282436; 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: in-reply-to:in-reply-to:references:references; bh=eG6b6Bshachf1sMCGcDdt9tD3P036RkZ5y4ysBbwGp4=; b=af2beovlhtGEZe6Km8N8LhaL7pZQeHCnvn5QRntKRLXxr2Hm+1sbxOXivOtkrgokVwOD2n tNjblJix78XYHkSZ2Q9EkullJl651ai5mHcn1n3OAAkWJZCmhG2g3ZWfiTqb2Q4SoMgrkS NNHQvJhUT8B0OUp6NwyGfwAVoTZFHgs= 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-344-ZI70OlpjPqazyyotquwL8g-1; Tue, 12 Mar 2024 18:27:15 -0400 X-MC-Unique: ZI70OlpjPqazyyotquwL8g-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a4648e992c4so51014966b.2 for ; Tue, 12 Mar 2024 15:27:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282433; x=1710887233; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eG6b6Bshachf1sMCGcDdt9tD3P036RkZ5y4ysBbwGp4=; b=ppKmJh8QGLY7jYaLeKSAbNE3o6qyH6P0uUV6mcPfZS7mp0GkduGynlUf7UYkUrG/3X 69ZW/cPt+cGUAM4S9VuzyVekrL/jxOt6GzWMN9LA2QpfXCn1oILwOPIWU9Yl3zbRP0L2 s2lK0fNVdu9s+pSMh/Np65BptdVW5mGtW0nSgzi6FYo6P97OJTchMftUKj4/HaMDv52Z LX/uULee1Icd7vxA1TTpualozjsZtGAtm4ss1EY5DL1Qr9ku+11ZajcRAawxOxjdAKrV LJql6rsH6ykvecEYM3XiRPeboNe6bVN1cyt/aHS4zy0cCj+5m91NkfaKEkCxVbtUI+Pk Ki7A== X-Gm-Message-State: AOJu0YwGMrAhjOsuJXSsroPVEV9+2qXRjka/0982rC9v53p2n635zl64 wPRGmivl1BuUmKlGFTx/Cc+pvSDVqvJd/U8fXtkaUrr+KwgH3y+GFOSuY8QzevCOtMmVrOuidZP 80DlEHIZiUPmh27GvYjSl8na1lMYCyYznUXEaAibSMe7pSn4AG2MLhLmB0LTOyEGgx2wxvfaraA PYDeE6R52WQJjE/qTAhFGmxL51GpO1YCXm X-Received: by 2002:a17:907:1603:b0:a45:20e4:e5ed with SMTP id cw3-20020a170907160300b00a4520e4e5edmr5887500ejd.77.1710282433171; Tue, 12 Mar 2024 15:27:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDXWv6Ix/0R7uIdLlOFBQbcbbVKXkNlUDfYziB244BXe5p5Mf51qSxBueVkN62xcm/MUEJYg== X-Received: by 2002:a17:907:1603:b0:a45:20e4:e5ed with SMTP id cw3-20020a170907160300b00a4520e4e5edmr5887482ejd.77.1710282432590; Tue, 12 Mar 2024 15:27:12 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id x19-20020a1709064bd300b00a44e2f3024bsm4238409ejv.68.2024.03.12.15.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:12 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:09 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Hao Chen , Jason Wang , Cornelia Huck , Paolo Bonzini Subject: [PULL 32/68] hw/virtio: Add support for VDPA network simulation devices Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Hao Chen This patch adds support for VDPA network simulation devices. The device is developed based on virtio-net and tap backend, and supports hardware live migration function. For more details, please refer to "docs/system/devices/vdpa-net.rst" Signed-off-by: Hao Chen Message-Id: <20240221073802.2888022-1-chenh@yusur.tech> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-pci.h | 5 + include/hw/virtio/virtio.h | 19 ++ include/standard-headers/linux/virtio_pci.h | 7 + hw/net/virtio-net.c | 16 ++ hw/virtio/virtio-pci.c | 189 +++++++++++++++++++- hw/virtio/virtio.c | 39 ++++ MAINTAINERS | 5 + docs/system/device-emulation.rst | 1 + docs/system/devices/vdpa-net.rst | 121 +++++++++++++ 9 files changed, 399 insertions(+), 3 deletions(-) create mode 100644 docs/system/devices/vdpa-net.rst diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 59d88018c1..4d57a9c751 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -43,6 +43,7 @@ enum { VIRTIO_PCI_FLAG_INIT_FLR_BIT, VIRTIO_PCI_FLAG_AER_BIT, VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT, + VIRTIO_PCI_FLAG_VDPA_BIT, }; /* Need to activate work-arounds for buggy guests at vmstate load. */ @@ -89,6 +90,9 @@ enum { #define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \ (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT) +/* VDPA supported flags */ +#define VIRTIO_PCI_FLAG_VDPA (1 << VIRTIO_PCI_FLAG_VDPA_BIT) + typedef struct { MSIMessage msg; int virq; @@ -140,6 +144,7 @@ struct VirtIOPCIProxy { }; VirtIOPCIRegion regs[5]; }; + VirtIOPCIRegion lm; MemoryRegion modern_bar; MemoryRegion io_bar; uint32_t legacy_io_bar_idx; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index c8f72850bc..b3c74a1bca 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -35,6 +35,9 @@ (0x1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \ (0x1ULL << VIRTIO_F_ANY_LAYOUT)) +#define LM_DISABLE 0x00 +#define LM_ENABLE 0x01 + struct VirtQueue; static inline hwaddr vring_align(hwaddr addr, @@ -95,6 +98,11 @@ enum virtio_device_endian { VIRTIO_DEVICE_ENDIAN_BIG, }; +typedef struct BitmapMemoryRegionCaches { + struct rcu_head rcu; + MemoryRegionCache bitmap; +} BitmapMemoryRegionCaches; + /** * struct VirtIODevice - common VirtIO structure * @name: name of the device @@ -128,6 +136,14 @@ struct VirtIODevice uint32_t generation; int nvectors; VirtQueue *vq; + uint8_t lm_logging_ctrl; + uint32_t lm_base_addr_low; + uint32_t lm_base_addr_high; + uint32_t lm_end_addr_low; + uint32_t lm_end_addr_high; + + BitmapMemoryRegionCaches *caches; + MemoryListener listener; uint16_t device_id; /* @vm_running: current VM running state via virtio_vmstate_change() */ @@ -379,8 +395,11 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n); unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); +unsigned int virtio_queue_get_vring_states(VirtIODevice *vdev, int n); void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, unsigned int idx); +void virtio_queue_set_vring_states(VirtIODevice *vdev, int n, + unsigned int idx); void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n); void virtio_queue_update_used_idx(VirtIODevice *vdev, int n); diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h index 3e2bc2c97e..86733278ba 100644 --- a/include/standard-headers/linux/virtio_pci.h +++ b/include/standard-headers/linux/virtio_pci.h @@ -221,6 +221,13 @@ struct virtio_pci_cfg_cap { #define VIRTIO_PCI_COMMON_ADM_Q_IDX 60 #define VIRTIO_PCI_COMMON_ADM_Q_NUM 62 +#define LM_LOGGING_CTRL 0 +#define LM_BASE_ADDR_LOW 4 +#define LM_BASE_ADDR_HIGH 8 +#define LM_END_ADDR_LOW 12 +#define LM_END_ADDR_HIGH 16 +#define LM_VRING_STATE_OFFSET 0x20 + #endif /* VIRTIO_PCI_NO_MODERN */ /* Admin command status. */ diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a3c711b56d..27055a4b8e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1999,6 +1999,22 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, goto err; } + /* Mark dirty page's bitmap of guest memory */ + if (vdev->lm_logging_ctrl == LM_ENABLE) { + uint64_t chunk = elem->in_addr[i] / VHOST_LOG_CHUNK; + /* Get chunk index */ + BitmapMemoryRegionCaches *caches = qatomic_rcu_read(&vdev->caches); + uint64_t index = chunk / 8; + uint64_t shift = chunk % 8; + uint8_t val = 0; + address_space_read_cached(&caches->bitmap, index, &val, + sizeof(val)); + val |= 1 << shift; + address_space_write_cached(&caches->bitmap, index, &val, + sizeof(val)); + address_space_cache_invalidate(&caches->bitmap, index, sizeof(val)); + } + elems[i] = elem; lens[i] = total; i++; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1a7039fb0c..e42ac6e7f9 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1442,6 +1442,155 @@ int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, return virtio_pci_add_mem_cap(proxy, &cap.cap); } +/* Called within call_rcu(). */ +static void bitmap_free_region_cache(BitmapMemoryRegionCaches *caches) +{ + assert(caches != NULL); + address_space_cache_destroy(&caches->bitmap); + g_free(caches); +} + +static void lm_disable(VirtIODevice *vdev) +{ + BitmapMemoryRegionCaches *caches; + caches = qatomic_read(&vdev->caches); + qatomic_rcu_set(&vdev->caches, NULL); + if (caches) { + call_rcu(caches, bitmap_free_region_cache, rcu); + } +} + +static void lm_enable(VirtIODevice *vdev) +{ + BitmapMemoryRegionCaches *old = vdev->caches; + BitmapMemoryRegionCaches *new = NULL; + hwaddr addr, end, size; + int64_t len; + + addr = vdev->lm_base_addr_low | ((hwaddr)(vdev->lm_base_addr_high) << 32); + end = vdev->lm_end_addr_low | ((hwaddr)(vdev->lm_end_addr_high) << 32); + size = end - addr; + if (size <= 0) { + error_report("Invalid lm size."); + return; + } + + new = g_new0(BitmapMemoryRegionCaches, 1); + len = address_space_cache_init(&new->bitmap, vdev->dma_as, addr, size, + true); + if (len < size) { + virtio_error(vdev, "Cannot map bitmap"); + goto err_bitmap; + } + qatomic_rcu_set(&vdev->caches, new); + + if (old) { + call_rcu(old, bitmap_free_region_cache, rcu); + } + + return; + +err_bitmap: + address_space_cache_destroy(&new->bitmap); + g_free(new); +} + +static uint64_t virtio_pci_lm_read(void *opaque, hwaddr addr, + unsigned size) +{ + VirtIOPCIProxy *proxy = opaque; + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + hwaddr offset_end = LM_VRING_STATE_OFFSET + + virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX; + uint32_t val; + int qid; + + if (vdev == NULL) { + return UINT64_MAX; + } + switch (addr) { + case LM_LOGGING_CTRL: + val = vdev->lm_logging_ctrl; + break; + case LM_BASE_ADDR_LOW: + val = vdev->lm_base_addr_low; + break; + case LM_BASE_ADDR_HIGH: + val = vdev->lm_base_addr_high; + break; + case LM_END_ADDR_LOW: + val = vdev->lm_end_addr_low; + break; + case LM_END_ADDR_HIGH: + val = vdev->lm_end_addr_high; + break; + default: + if (addr >= LM_VRING_STATE_OFFSET && addr <= offset_end) { + qid = (addr - LM_VRING_STATE_OFFSET) / + virtio_pci_queue_mem_mult(proxy); + val = virtio_queue_get_vring_states(vdev, qid); + } else + val = 0; + + break; + } + + return val; +} + +static void virtio_pci_lm_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + VirtIOPCIProxy *proxy = opaque; + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + hwaddr offset_end = LM_VRING_STATE_OFFSET + + virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX; + int qid; + + if (vdev == NULL) { + return; + } + + switch (addr) { + case LM_LOGGING_CTRL: + vdev->lm_logging_ctrl = val; + switch (val) { + case LM_DISABLE: + lm_disable(vdev); + break; + case LM_ENABLE: + lm_enable(vdev); + break; + default: + virtio_error(vdev, "Unsupport LM_LOGGING_CTRL value: %"PRIx64, + val); + break; + }; + + break; + case LM_BASE_ADDR_LOW: + vdev->lm_base_addr_low = val; + break; + case LM_BASE_ADDR_HIGH: + vdev->lm_base_addr_high = val; + break; + case LM_END_ADDR_LOW: + vdev->lm_end_addr_low = val; + break; + case LM_END_ADDR_HIGH: + vdev->lm_end_addr_high = val; + break; + default: + if (addr >= LM_VRING_STATE_OFFSET && addr <= offset_end) { + qid = (addr - LM_VRING_STATE_OFFSET) / + virtio_pci_queue_mem_mult(proxy); + virtio_queue_set_vring_states(vdev, qid, val); + } else + virtio_error(vdev, "Unsupport addr: %"PRIx64, addr); + break; + } +} + static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, unsigned size) { @@ -1823,6 +1972,15 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy, }, .endianness = DEVICE_LITTLE_ENDIAN, }; + static const MemoryRegionOps lm_ops = { + .read = virtio_pci_lm_read, + .write = virtio_pci_lm_write, + .impl = { + .min_access_size = 1, + .max_access_size = 4, + }, + .endianness = DEVICE_LITTLE_ENDIAN, + }; g_autoptr(GString) name = g_string_new(NULL); g_string_printf(name, "virtio-pci-common-%s", vdev_name); @@ -1859,6 +2017,14 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy, proxy, name->str, proxy->notify_pio.size); + if (proxy->flags & VIRTIO_PCI_FLAG_VDPA) { + g_string_printf(name, "virtio-pci-lm-%s", vdev_name); + memory_region_init_io(&proxy->lm.mr, OBJECT(proxy), + &lm_ops, + proxy, + name->str, + proxy->lm.size); + } } static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, @@ -2021,6 +2187,10 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->device, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->notify, ¬ify.cap); + if (proxy->flags & VIRTIO_PCI_FLAG_VDPA) { + memory_region_add_subregion(&proxy->modern_bar, + proxy->lm.offset, &proxy->lm.mr); + } if (modern_pio) { memory_region_init(&proxy->io_bar, OBJECT(proxy), @@ -2090,6 +2260,9 @@ static void virtio_pci_device_unplugged(DeviceState *d) virtio_pci_modern_mem_region_unmap(proxy, &proxy->isr); virtio_pci_modern_mem_region_unmap(proxy, &proxy->device); virtio_pci_modern_mem_region_unmap(proxy, &proxy->notify); + if (proxy->flags & VIRTIO_PCI_FLAG_VDPA) { + memory_region_del_subregion(&proxy->modern_bar, &proxy->lm.mr); + } if (modern_pio) { virtio_pci_modern_io_region_unmap(proxy, &proxy->notify_pio); } @@ -2144,9 +2317,17 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG; /* subclasses can enforce modern, so do this unconditionally */ - memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", - /* PCI BAR regions must be powers of 2 */ - pow2ceil(proxy->notify.offset + proxy->notify.size)); + if (!(proxy->flags & VIRTIO_PCI_FLAG_VDPA)) { + memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", + /* PCI BAR regions must be powers of 2 */ + pow2ceil(proxy->notify.offset + proxy->notify.size)); + } else { + proxy->lm.offset = proxy->notify.offset + proxy->notify.size; + proxy->lm.size = 0x20 + VIRTIO_QUEUE_MAX * 4; + memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", + /* PCI BAR regions must be powers of 2 */ + pow2ceil(proxy->lm.offset + proxy->lm.size)); + } if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) { proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; @@ -2301,6 +2482,8 @@ static Property virtio_pci_properties[] = { VIRTIO_PCI_FLAG_INIT_FLR_BIT, true), DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_AER_BIT, false), + DEFINE_PROP_BIT("vdpa", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_VDPA_BIT, false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d229755eae..fb6b4ccd83 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3368,6 +3368,18 @@ static uint16_t virtio_queue_split_get_last_avail_idx(VirtIODevice *vdev, return vdev->vq[n].last_avail_idx; } +static uint32_t virtio_queue_split_get_vring_states(VirtIODevice *vdev, + int n) +{ + struct VirtQueue *vq = &vdev->vq[n]; + uint16_t avail, used; + + avail = vq->last_avail_idx; + used = vq->used_idx; + + return avail | (uint32_t)used << 16; +} + unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n) { if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { @@ -3377,6 +3389,33 @@ unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n) } } +unsigned int virtio_queue_get_vring_states(VirtIODevice *vdev, int n) +{ + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return -1; + } else { + return virtio_queue_split_get_vring_states(vdev, n); + } +} + +static void virtio_queue_split_set_vring_states(VirtIODevice *vdev, + int n, uint32_t idx) +{ + struct VirtQueue *vq = &vdev->vq[n]; + vq->last_avail_idx = (uint16_t)(idx & 0xffff); + vq->shadow_avail_idx = (uint16_t)(idx & 0xffff); + vq->used_idx = (uint16_t)(idx >> 16); +} + +void virtio_queue_set_vring_states(VirtIODevice *vdev, int n, uint32_t idx) +{ + if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + return; + } else { + virtio_queue_split_set_vring_states(vdev, n, idx); + } +} + static void virtio_queue_packed_set_last_avail_idx(VirtIODevice *vdev, int n, unsigned int idx) { diff --git a/MAINTAINERS b/MAINTAINERS index 4d96f855de..5abf6f54c4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2372,6 +2372,11 @@ F: hw/virtio/vhost-user-scmi* F: include/hw/virtio/vhost-user-scmi.h F: tests/qtest/libqos/virtio-scmi.* +vdpa-net +M: Hao Chen +S: Maintained +F: docs/system/devices/vdpa-net.rst + virtio-crypto M: Gonglei S: Supported diff --git a/docs/system/device-emulation.rst b/docs/system/device-emulation.rst index f19777411c..e4a27f53c8 100644 --- a/docs/system/device-emulation.rst +++ b/docs/system/device-emulation.rst @@ -99,3 +99,4 @@ Emulated Devices devices/canokey.rst devices/usb-u2f.rst devices/igb.rst + devices/vdpa-net.rst diff --git a/docs/system/devices/vdpa-net.rst b/docs/system/devices/vdpa-net.rst new file mode 100644 index 0000000000..323d8c926a --- /dev/null +++ b/docs/system/devices/vdpa-net.rst @@ -0,0 +1,121 @@ +vdpa net +============ + +This document explains the setup and usage of the vdpa network device. +The vdpa network device is a paravirtualized vdpa emulate device. + +Description +----------- + +VDPA net devices support dirty page bitmap mark and vring state saving and recovery. + +Users can use this VDPA device for live migration simulation testing in a nested virtualization environment. + +Registers layout +---------------- + +The vdpa device add live migrate registers layout as follow:: + + Offset Register Name Bitwidth Associated vq + 0x0 LM_LOGGING_CTRL 4bits + 0x10 LM_BASE_ADDR_LOW 32bits + 0x14 LM_BASE_ADDR_HIGH 32bits + 0x18 LM_END_ADDR_LOW 32bits + 0x1c LM_END_ADDR_HIGH 32bits + 0x20 LM_RING_STATE_OFFSET 32bits vq0 + 0x24 LM_RING_STATE_OFFSET 32bits vq1 + 0x28 LM_RING_STATE_OFFSET 32bits vq2 + ...... + 0x20+1023*4 LM_RING_STATE_OFFSET 32bits vq1023 + +These registers are extended at the end of the notify bar space. + +Architecture diagram +-------------------- +:: + + |------------------------------------------------------------------------| + | guest-L1-user-space | + | | + | |----------------------------------------| + | | [virtio-net driver] | + | | ^ guest-L2-src(iommu=on) | + | |--------------|-------------------------| + | | | qemu-L2-src(viommu) | + | [dpdk-vdpa]<->[vhost socket]<-+->[vhost-user backend(iommu=on)] | + -------------------------------------------------------------------------- + -------------------------------------------------------------------------- + | ^ guest-L1-kernel-space | + | | | + | [VFIO] | + | ^ | + | | guest-L1-src(iommu=on) | + --------|----------------------------------------------------------------- + --------|----------------------------------------------------------------- + | [vdpa net device(iommu=on)] [manager nic device] | + | | | | + | | | | + | [tap device] qemu-L1-src(viommu) | | + ------------------------------------------------+------------------------- + | + | + --------------------- | + | kernel net bridge |<----- + | virbr0 |<---------------------------------- + --------------------- | + | + | + -------------------------------------------------------------------------- | + | guest-L1-user-space | | + | | | + | |----------------------------------------| | + | | [virtio-net driver] | | + | | ^ guest-L2-dst(iommu=on) | | + | |--------------|-------------------------| | + | | | qemu-L2-dst(viommu) | | + | [dpdk-vdpa]<->[vhost socket]<-+->[vhost-user backend(iommu=on)] | | + -------------------------------------------------------------------------- | + -------------------------------------------------------------------------- | + | ^ guest-L1-kernel-space | | + | | | | + | [VFIO] | | + | ^ | | + | | guest-L1-dst(iommu=on) | | + --------|----------------------------------------------------------------- | + --------|----------------------------------------------------------------- | + | [vdpa net device(iommu=on)] [manager nic device]----------------+---- + | | | + | | | + | [tap device] qemu-L1-dst(viommu) | + -------------------------------------------------------------------------- + + +Device properties +----------------- + +The Virtio vdpa device can be configured with the following properties: + + * ``vdpa=on`` open vdpa device emulated. + +Usages +-------- +This patch add virtio sriov support and vdpa live migrate support. +You can open vdpa by set xml file as follow:: + + + + + + + + + + +Limitations +----------- +1. Dependent on tap device with param ``vhost=off``. +2. Nested virtualization environment only supports ``q35`` machines. +3. Current only support split vring live migrate. + + + From patchwork Tue Mar 12 22:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ii1iK+Wk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSvx5Hd0z1yWt for ; Wed, 13 Mar 2024 09:28:13 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAaj-00077e-6w; Tue, 12 Mar 2024 18:27:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAaf-0006Yi-OK for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:21 -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 1rkAae-0004Nh-4p for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282439; 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: in-reply-to:in-reply-to:references:references; bh=tOh3XMBYaTXqwwXatODmJZBdFVP40l8SCuosqwHz9Dw=; b=ii1iK+WkwFh73+BkYZVSb+Pdsrx0lio9MABqJgCrfXbiQs8EmxralwvrNcIlrAgJfyKVzz Nj01Q8Hc0EKmKjuQm4kN6PW2JP3yqXZ73ZoZk2f1tBMggqft3a7SXgK3/EmauWLKN2mGVj h+ZePIaWy7cmeOxf7yUuyDSxPUihxLI= 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-36-ILpux4BcPtGBPqoRS-_61Q-1; Tue, 12 Mar 2024 18:27:18 -0400 X-MC-Unique: ILpux4BcPtGBPqoRS-_61Q-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-56864b8f5f9so1354730a12.3 for ; Tue, 12 Mar 2024 15:27:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282436; x=1710887236; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tOh3XMBYaTXqwwXatODmJZBdFVP40l8SCuosqwHz9Dw=; b=TNBB36HZdgGwX3wE7Gnl5m4YT2SqAoLN3038QZNd0hNkegA20Iy4EuHz7KkAq8jCPe ox+/i9jhjOTZ7nGRHpft602IKNWFte4Cnvk0pzLsQS6PGryDmO2M7s9xRCFO1d+MSMfL 4FkVqRTkC6IcShBV1dv1SA5PoXgtQlr1PdO65zdP/Tx/q+JCZ6MqPeZAksTbyNkY/Wcc gSbCFZxn85P3vRkFBmwbq0HwCkiAzcGVgcq2KOx2APV0c3gAT1BOvxYIDFjvCeBW4i9y d7o7vcBsUyFiWGzDgmh4GdqaixdRnPiSns0BipkuH+We44J/p7kKh8H2diVx/dPDD2ml P5ow== X-Gm-Message-State: AOJu0YwCWJ+lJfxyFXGyd5Xzu98hPmSKybUXh1X6VBRsngtQTsNX2EOn nyBWUOb3P6KhtqIdrB6jIF8tlZw8KyjioojQsA+V/HjTH1Y6xsxVPJ3rnprMObliy/7+1eMceoD iaz03VFh7i9U8PvbqPofC6EvGryodK406GmMK8VNqh6z/5bs8Gjqi8TSCfz5mbXy0zOKNU0fTST pNvMwUYBGwY5Id1AX/djxMx3oI1pEHfpWg X-Received: by 2002:a50:c315:0:b0:566:1127:4bb5 with SMTP id a21-20020a50c315000000b0056611274bb5mr8334967edb.1.1710282436390; Tue, 12 Mar 2024 15:27:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm4qsXUUXmwGcv9qOYj47DS6cCLXV96uTaaYGD6Tno7zfR92dtE36eMtWzlJW8oTvz41fALg== X-Received: by 2002:a50:c315:0:b0:566:1127:4bb5 with SMTP id a21-20020a50c315000000b0056611274bb5mr8334950edb.1.1710282435946; Tue, 12 Mar 2024 15:27:15 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id fe5-20020a056402390500b005684173e413sm2318047edb.72.2024.03.12.15.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:15 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:12 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Jonathan Cameron , Fan Ni Subject: [PULL 33/68] hw/cxl/cxl-host: Fix missing ERRP_GUARD() in cxl_fixed_memory_window_config() Message-ID: <2a0e0a35002db7ac64f4e82ea2a4ad2fb6d934b0.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in cxl_fixed_memory_window_config(), @errp is dereferenced in 2 places without ERRP_GUARD(): fw->enc_int_ways = cxl_interleave_ways_enc(fw->num_targets, errp); if (*errp) { return; } and fw->enc_int_gran = cxl_interleave_granularity_enc(object->interleave_granularity, errp); if (*errp) { return; } For the above 2 places, we check "*errp", because neither function returns a suitable error code. And since machine_set_cfmw() - the caller of cxl_fixed_memory_window_config() - doesn't get the NULL @errp parameter as the "set" method of object property, cxl_fixed_memory_window_config() hasn't triggered the bug that dereferencing the NULL @errp. To follow the requirement of @errp, add missing ERRP_GUARD() in cxl_fixed_memory_window_config(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Reviewed-by: Markus Armbruster Message-Id: <20240223085653.1255438-2-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jonathan Cameron --- hw/cxl/cxl-host.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c index 2aa776c79c..c5f5fcfd64 100644 --- a/hw/cxl/cxl-host.c +++ b/hw/cxl/cxl-host.c @@ -26,6 +26,7 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state, CXLFixedMemoryWindowOptions *object, Error **errp) { + ERRP_GUARD(); g_autofree CXLFixedWindow *fw = g_malloc0(sizeof(*fw)); strList *target; int i; From patchwork Tue Mar 12 22:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a3cZDmUf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSxx5zBhz1yWt for ; Wed, 13 Mar 2024 09:29:57 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAat-0007dj-GU; Tue, 12 Mar 2024 18:27:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAak-0007Lz-MX for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:26 -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 1rkAaj-0004OJ-6a for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282443; 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: in-reply-to:in-reply-to:references:references; bh=faJjZcgxeJc4r0dC1qxSrJM/ByQyn32iy5RAHwtp21Y=; b=a3cZDmUfEVgHZb9WiAmhjpvGwkDo0UskJQTJj1nBwk+vLC7Y6f0V+lmobdI9DJ7B5HIcZv y3oheOjMTlPCdQ+IBlpHKkLQM9GUQQ+bkWeJqM0mrJRYi2GRIe5hNp3OKTXre9NQ4bIJFu kM/i9yVgy1bWcwaNC2zZDKL73+MnMMQ= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-2-YenIqga5MXaBxcbXBuU7jA-1; Tue, 12 Mar 2024 18:27:22 -0400 X-MC-Unique: YenIqga5MXaBxcbXBuU7jA-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d45f5bfdd6so8794541fa.2 for ; Tue, 12 Mar 2024 15:27:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282440; x=1710887240; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=faJjZcgxeJc4r0dC1qxSrJM/ByQyn32iy5RAHwtp21Y=; b=gsV7i2LAKCYd53AWdpu8x1mOqryAO6FHnCY38VPJ0J3muEgjE04qlKAROllqwmtGdl toJ1zCLaY+UEtREf+vvFGJDmAmJ9rBX08YsPVX5OGOS2jJjQSUkrmO39ctgueFCYhra5 OKHN04p1WTzBJ3jf9TYl/mqyfrueemV0MyKLnXzbr8NAo51Z20djTiIwgSwIq5AU5MGo sn/klqhsmn58ok1QKw3yAQiE67rLJQ0Os3zYZbltlKyigHnJjSFT+7z6az5XraEXBz8l GhiCmSe5mr/Mr7ugltsR4KYiLZFY6vfQRoq96dpa6yQEixRytBRT4VgQtOzeOhzziae/ osqA== X-Gm-Message-State: AOJu0YwuWu5HnjAUtp4FMcG9GcF2SBWLalfkzC8OskNhdM+JjXsIUCQU IRupbvUCRfKSxWpEaFF5mpdov44Z5ysPAoLzfbPZna/fy3EOISaj7ak4wc4Revg6kFUkTjd9xUN 9XLxeCN9TvKsAYhOUEuD6WmTCd2OvbYkwW+OFPKg9A3r5NIeD6m7tuHV2BaYe/DOv6lK+06R06z fyiKrQVF1/6kFWZwXKDULz0EPvAeIAT3xt X-Received: by 2002:a2e:9b92:0:b0:2d4:3df6:5330 with SMTP id z18-20020a2e9b92000000b002d43df65330mr4505707lji.38.1710282439966; Tue, 12 Mar 2024 15:27:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3YX9G6WbZMkL7HIiFH3dR6CIOBVpQSNi87CHPEqh8tgYkMZAXGYT9x6vL+ERqSREaGP/ztw== X-Received: by 2002:a2e:9b92:0:b0:2d4:3df6:5330 with SMTP id z18-20020a2e9b92000000b002d43df65330mr4505691lji.38.1710282439509; Tue, 12 Mar 2024 15:27:19 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id e20-20020a056402149400b00568229390f2sm4359050edv.70.2024.03.12.15.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:18 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:16 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Laurent Vivier Subject: [PULL 34/68] hw/display/macfb: Fix missing ERRP_GUARD() in macfb_nubus_realize() Message-ID: <5aa4a6417b0f7acbfd7f4c21dca26293bc3d9348.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in macfb_nubus_realize(), @errp is dereferenced without ERRP_GUARD(): ndc->parent_realize(dev, errp); if (*errp) { return; } Here we check *errp, because the ndc->parent_realize(), as a DeviceClass.realize() callback, returns void. And since macfb_nubus_realize(), also as a DeviceClass.realize(), doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. To follow the requirement of @errp, add missing ERRP_GUARD() in macfb_nubus_realize(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Reviewed-by: Markus Armbruster Message-Id: <20240223085653.1255438-3-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/display/macfb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/display/macfb.c b/hw/display/macfb.c index 418e99c8e1..1ace341a0f 100644 --- a/hw/display/macfb.c +++ b/hw/display/macfb.c @@ -714,6 +714,7 @@ static void macfb_nubus_set_irq(void *opaque, int n, int level) static void macfb_nubus_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); NubusDevice *nd = NUBUS_DEVICE(dev); MacfbNubusState *s = NUBUS_MACFB(dev); MacfbNubusDeviceClass *ndc = NUBUS_MACFB_GET_CLASS(dev); From patchwork Tue Mar 12 22:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QNWHfJat; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT295Jkwz1ydl for ; Wed, 13 Mar 2024 09:33:37 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAb6-00088l-LG; Tue, 12 Mar 2024 18:27:48 -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 1rkAan-0007Tn-LL for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27: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 1rkAak-0004OU-Jz for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282446; 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: in-reply-to:in-reply-to:references:references; bh=D2lpmRuQpB9vA5OA++aQfNEAFEu+9OfR1snJEg9JCvg=; b=QNWHfJateMJOpd5zofEo7uc7oGrmwB+q60va+CjFMPwiQzGLSLrmqHWr4BVRSRLqFSyHdR WEWLKQr9Wb22Z7J7PTnKJ9ecIeUQ1giFEUyP2YYZ590scnGQApaFd+JqodnZfQ/1YnCqUk t1cjiThexcg3/XrslbHASWom9v1y0AA= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-lr1Wul9_NUyt_XQBe1GpzQ-1; Tue, 12 Mar 2024 18:27:24 -0400 X-MC-Unique: lr1Wul9_NUyt_XQBe1GpzQ-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5684c1abc33so2350501a12.2 for ; Tue, 12 Mar 2024 15:27:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282443; x=1710887243; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=D2lpmRuQpB9vA5OA++aQfNEAFEu+9OfR1snJEg9JCvg=; b=tLRb/Y4S3ja4DbpznNiV27QpFzmZU/ZfU1dQXQ9hAa25xvobQX2i3DnREXOBzAf5nJ PYlfbXu/aiu7YTwkjHz5hdsOz3t6DZRvIjVDBsM1b+UEUihFFO5Mc06iMuW2480meqZI VGtwQxst9z8/f0J+fwY4vKSEc+KPcqbbgqmUqvbiCLTo26HqI7ABzjDIZVbR9S9j491M FX/6Oaus68sNnARFP784ghRBDLuRlgKQaciKc7OmkhGM1bEEYnza+pqzZy4cVhnjC2/f o3Y7pi8xaiMwT1aIlOtqumWekd1TOW3/UP63NNmZYm1Dj9Oje8O3RFEWIpLKQT0SvPUP OLwg== X-Gm-Message-State: AOJu0YzRuB350MT4JbsQ11swVVingKc4DEg0tzNdxAzv9e0nlx4ZWy14 ga84WmxGHBbJKDTKqlA+wPdi2dnFfJcPesmO5FnJTuu4C40zs47tjaEEhxAAYFujI313yQOBe8g Q1EakLK0kL0OlMqhqIGzNiqf/44vlnA34YkKQRgbV7fUaWw3NUcSL/LUPYrnLKp4xpiYgF++6/Y 5MZBgOz7oSMeskIU0k9Sc2j3VVvTJ/49Tg X-Received: by 2002:a50:9e48:0:b0:566:ab45:e6c5 with SMTP id z66-20020a509e48000000b00566ab45e6c5mr2157423ede.28.1710282443024; Tue, 12 Mar 2024 15:27:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxDO4TGc3w2tLD2JLb7Y5kfREmjXSbzSX6P7SIcBHWNwfLLoRHL27m3wQgi5keSuq/qBGa+A== X-Received: by 2002:a50:9e48:0:b0:566:ab45:e6c5 with SMTP id z66-20020a509e48000000b00566ab45e6c5mr2157407ede.28.1710282442491; Tue, 12 Mar 2024 15:27:22 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id b2-20020aa7c902000000b00564e489ce9asm4411838edt.12.2024.03.12.15.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:21 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:19 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Jonathan Cameron , Fan Ni Subject: [PULL 35/68] hw/mem/cxl_type3: Fix missing ERRP_GUARD() in ct3_realize() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in ct3_realize(), @errp is dereferenced without ERRP_GUARD(): cxl_doe_cdat_init(cxl_cstate, errp); if (*errp) { goto err_free_special_ops; } Here we check *errp, because cxl_doe_cdat_init() returns void. And ct3_realize() - as a PCIDeviceClass.realize() method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. To follow the requirement of @errp, add missing ERRP_GUARD() in ct3_realize(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Reviewed-by: Markus Armbruster Message-Id: <20240223085653.1255438-4-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jonathan Cameron --- hw/mem/cxl_type3.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index b679dfae1c..b0a7e9f11b 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -645,6 +645,7 @@ static DOEProtocol doe_cdat_prot[] = { static void ct3_realize(PCIDevice *pci_dev, Error **errp) { + ERRP_GUARD(); CXLType3Dev *ct3d = CXL_TYPE3(pci_dev); CXLComponentState *cxl_cstate = &ct3d->cxl_cstate; ComponentRegisters *regs = &cxl_cstate->crb; From patchwork Tue Mar 12 22:27:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911394 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WUvAHO5X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSwM5yyMz1yWt for ; Wed, 13 Mar 2024 09:28:35 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbJ-0000Pl-Nj; Tue, 12 Mar 2024 18:28:03 -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 1rkAap-0007ZR-M7 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:31 -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 1rkAao-0004Oy-5E for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282449; 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=DBULQTyw/cBuXLWadxHOJ8GjlhZzF81MHpi5mkmgU0I=; b=WUvAHO5XM7ThL5C0mM54i06sZrjpqRqDxUUXd+9A7o5k9fYwymI6GoAVH7WZwoNX2eJkn1 V6IHK3t1aNAK56hqwy7wl+nslw2ZKs/VfTFVjYxho5G9KTC40kXux5W8K6R0yY7kDowYJZ ep+THSmh0JpmnivH0sb5MFQazkL7fmk= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-eGKl3PvKP2We7xRUD4-1hQ-1; Tue, 12 Mar 2024 18:27:28 -0400 X-MC-Unique: eGKl3PvKP2We7xRUD4-1hQ-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d468f7779cso3600881fa.3 for ; Tue, 12 Mar 2024 15:27:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282446; x=1710887246; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DBULQTyw/cBuXLWadxHOJ8GjlhZzF81MHpi5mkmgU0I=; b=kojqw2up9N16bC+nOP6L24JxPw4tqFOoIgvLlAgFJQ+G0zlRl5v85zIAsLEwvbH8Xs 0mMJC3O1S5sr1F1R9wpJFrX/Xcv1W3eOjiTII81p0ZcCcyA2rjDQdZrPj9lSIMVDekgL Rc2XqdNLmEr2VLKDomeAb4JTA4xRTiVUxAvNpsYA2WPkfbmTlpAWngozq69jNUHz99ZE XjEh0ISlCyaK5UcEfcvMi7TsivjYi9MdXOTI/2jSVHesjgy8GJt+L5I5iA6dYqkTGo/T lj9OzpetJoWtRuWKZySNUAZ3Lzfu3pFLvgkQgOEERD5VWvgsngoQdPpGeFr7UG22YSky DkVw== X-Gm-Message-State: AOJu0YxjDPWyD0gbQyUAn0SNfr3SWHl3eNaOhq2odgJ+QuVJYjL7RS3x QC1nHOdQBS4s3swA/gi30946tcEs+eLIOQtrpUjtVeTn6gR9kKCD3cQe8yQzTQe76As7c3jdO7m 4HVrnMl2cbYvCbOi7siPy5xfMlImlMU5qQqTWjxzTkyhUQcprQw4QYagO3yWdTVtdJN1bvh4wi6 TIE8OP3xqkrJy+FrRUwYzsmE90dZWYYhe4 X-Received: by 2002:a05:6512:ac1:b0:513:27a1:24cb with SMTP id n1-20020a0565120ac100b0051327a124cbmr1220494lfu.51.1710282446264; Tue, 12 Mar 2024 15:27:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBJlRJm45tw8nSf3m96fIX0dBg9+ATVRCHcfVPcXIrv3z5nzZBbV0/mkZh64QXI68PAG9kbA== X-Received: by 2002:a05:6512:ac1:b0:513:27a1:24cb with SMTP id n1-20020a0565120ac100b0051327a124cbmr1220469lfu.51.1710282445684; Tue, 12 Mar 2024 15:27:25 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id hg22-20020a1709072cd600b00a463c821e4dsm1260636ejc.10.2024.03.12.15.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:25 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:22 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Philippe =?utf-8?q?Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Alistair Francis , "Edgar E. Iglesias" , qemu-arm@nongnu.org Subject: [PULL 36/68] hw/misc/xlnx-versal-trng: Check returned bool in trng_prop_fault_event_set() Message-ID: <305446015848f0b5d71b817b53e7e02b08c36ede.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in trng_prop_fault_event_set, @errp is dereferenced without ERRP_GUARD(): visit_type_uint32(v, name, events, errp); if (*errp) { return; } Currently, since trng_prop_fault_event_set() doesn't get the NULL @errp parameter as a "set" method of object property, it hasn't triggered the bug that dereferencing the NULL @errp. And since visit_type_uint32() returns bool, check the returned bool directly instead of dereferencing @errp, then we needn't the add missing ERRP_GUARD(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Message-Id: <20240223085653.1255438-5-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- hw/misc/xlnx-versal-trng.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/misc/xlnx-versal-trng.c b/hw/misc/xlnx-versal-trng.c index b8111b8b66..6495188dc7 100644 --- a/hw/misc/xlnx-versal-trng.c +++ b/hw/misc/xlnx-versal-trng.c @@ -644,8 +644,7 @@ static void trng_prop_fault_event_set(Object *obj, Visitor *v, Property *prop = opaque; uint32_t *events = object_field_prop_ptr(obj, prop); - visit_type_uint32(v, name, events, errp); - if (*errp) { + if (!visit_type_uint32(v, name, events, errp)) { return; } From patchwork Tue Mar 12 22:27:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CSlbMxBV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8r1vFzz1yWy for ; Wed, 13 Mar 2024 09:39:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAb8-0008Ol-2G; Tue, 12 Mar 2024 18:27: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 1rkAau-0007kB-PU for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:37 -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 1rkAat-0004PN-Ax for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282453; 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: in-reply-to:in-reply-to:references:references; bh=YRkgmEXK4kdbpAxqfwfMTxmqWS9DlUTeU9ylZaG1Bss=; b=CSlbMxBVqW3jVB0CcQBmfkett6nFIwqAY3tKNShOeJLvgkslgz5hFNVudBIrmggx9F60CN BgZ4lvpJDAGHIIHTKwo6ps/lSJJCcPMzLSoHXeHy0Di4pTLQ+r9CKnOgRZvYgoIbsTA1Z+ 2KK5biuorbuZD+Qp9NM9lWL8MxE4mDY= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-sPXTNW1UOeGeQNxkkRWfZg-1; Tue, 12 Mar 2024 18:27:32 -0400 X-MC-Unique: sPXTNW1UOeGeQNxkkRWfZg-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2d45c84435eso10086721fa.0 for ; Tue, 12 Mar 2024 15:27:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282450; x=1710887250; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YRkgmEXK4kdbpAxqfwfMTxmqWS9DlUTeU9ylZaG1Bss=; b=ZHLMXolocZOxhCkaRBoTH8eIbSN+6shXvuifKR7H6Th9BuPNqUpSOfKFM4NrzSOnpy jHZM8fJk+xFLEMCBVZWoGx1GNu2BQATitrJtl5l3pTFH7/a9fTtGLlhKxBvaUIWjCVt5 YXqzu7DEYOWEs7R0jrQaB6UdZoey4T8IeZmkJULWrTqjmIkQSQI6b6AWuCYTElwhdRoA K/S/hwUkHF10jRsnb0hGK2lkiAbR0ZplBRFd+ZPoj7xbuEY84ZBqit5/dZY3UIxFBwg7 KYP6ZyLe6cH3LSXkx73aYeJQeAE1JxfmUWrZU17GX3D3ZHzgvPgEOQN0fT7SWSJ7inlC 6XWg== X-Gm-Message-State: AOJu0YxwUmmlV8DknTXw42xpr+7pAHlnIDD6G+JNmaIrgBnvxAwKwFtJ 90iiLqj/lT1ThZ0M9Jr7h+Mm+u8GVXXTJZte6eFQ6LxCxDwTV5D/wk5fioEVxcrGWGRBeopd1TG Sgeozjiv0wRwWH03zMu0Kaz6CC0/VI8Fdxg57g+OJRGBbTN5vQHOfYSpalEhyE2l/d10fMLwMhH 6p/POS1587nBtv/6EpcYwIQ/NSOyycjPF/ X-Received: by 2002:a2e:869a:0:b0:2d2:c8c1:d844 with SMTP id l26-20020a2e869a000000b002d2c8c1d844mr7098965lji.13.1710282450085; Tue, 12 Mar 2024 15:27:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2G7TQGxxQ82zzE1Eh/Xb1X/sflYU+64zTbr29Puoikel9mRMyBe4a3d24kRjCMZuwIyYVzw== X-Received: by 2002:a2e:869a:0:b0:2d2:c8c1:d844 with SMTP id l26-20020a2e869a000000b002d2c8c1d844mr7098944lji.13.1710282449537; Tue, 12 Mar 2024 15:27:29 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id ho34-20020a1709070ea200b00a460d8222fbsm3641217ejc.215.2024.03.12.15.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:28 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:25 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Jonathan Cameron , Thomas Huth , Marcel Apfelbaum Subject: [PULL 37/68] hw/pci-bridge/cxl_upstream: Fix missing ERRP_GUARD() in cxl_usp_realize() Message-ID: <4f5a3f49b934ff24227ebc95b3f9177f0147ff52.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in cxl_usp_realize(), @errp is dereferenced without ERRP_GUARD(): cxl_doe_cdat_init(cxl_cstate, errp); if (*errp) { goto err_cap; } Here we check *errp, because cxl_doe_cdat_init() returns void. And since cxl_usp_realize() - as a PCIDeviceClass.realize() method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. To follow the requirement of @errp, add missing ERRP_GUARD() in cxl_usp_realize(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Reviewed-by: Markus Armbruster Message-Id: <20240223085653.1255438-6-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Jonathan Cameron Reviewed-by: Thomas Huth --- hw/pci-bridge/cxl_upstream.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/pci-bridge/cxl_upstream.c b/hw/pci-bridge/cxl_upstream.c index 537f9affb8..783fa6adac 100644 --- a/hw/pci-bridge/cxl_upstream.c +++ b/hw/pci-bridge/cxl_upstream.c @@ -289,6 +289,7 @@ static void free_default_cdat_table(CDATSubHeader **cdat_table, int num, static void cxl_usp_realize(PCIDevice *d, Error **errp) { + ERRP_GUARD(); PCIEPort *p = PCIE_PORT(d); CXLUpstreamPort *usp = CXL_USP(d); CXLComponentState *cxl_cstate = &usp->cxl_cstate; From patchwork Tue Mar 12 22:27:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fr1aX4Zv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT0W5QSJz1ydl for ; Wed, 13 Mar 2024 09:32:11 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAb7-0008El-96; Tue, 12 Mar 2024 18:27:49 -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 1rkAav-0007s6-PD for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:39 -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 1rkAat-0004Qv-Sh for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282455; 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: in-reply-to:in-reply-to:references:references; bh=vE++ACnpq2l4kPgdISccW6Kl+44m7WS4zYEt6708zkc=; b=fr1aX4ZvVmT1vdatnVgL96aJmnzYGr+5omFSsKV6Z56VMAt1PURSJmYYs/BLyNEmYpRrW5 8vA5fooHL2AZmsq/MGR256d5ZNBACTCxWkyErhbrGpg4hgUyF5matE6kBCbCR9lxkdAF2K v/8IzxetDy0a9vzKI9aQ0fiKZ5AXx48= 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-62-AmoocxrMME2I7yw4VuCcYg-1; Tue, 12 Mar 2024 18:27:34 -0400 X-MC-Unique: AmoocxrMME2I7yw4VuCcYg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a45acc7f07cso26151466b.2 for ; Tue, 12 Mar 2024 15:27:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282453; x=1710887253; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vE++ACnpq2l4kPgdISccW6Kl+44m7WS4zYEt6708zkc=; b=quCSRddzy+cJ8mu+UMZx3crgZhjQyOqsnkh67sEb3D53/SyznKFWUx9gaV3xikqTvC EoMCzE35bmLsAT/dwmEl1MJfm27aEN4VlA695yxyGcunRozfT4grdltYMLV4P/fI+Xcq QryX6LXacolOT9HPcORT90LT+vNyWjR3+yf7jKmz1xoZ3HIhTiNSJoM9OVPFX4Axqurj Gclx0LW3GnrqoKGXasnuyPYWc1mxKes5oFOHxqjoTCY38PGeS9yewFTT/iiadx25beSK shD1go0vMNjrcjuWUTSMlzlH1WTYNmhcO+5SBjKGkR5YSDBqxJWlBw+EB15n2LmFjEE9 p66Q== X-Gm-Message-State: AOJu0YxMdPv1xVRvMomitwRL5WnRk+DcF52oButbpTFjjVsB+K2cbnF4 tyhfBoMeA5UPZXhU8snJYeaEge49X8GQwcl07IpGxr+AutVQGJrSuSpbaEEgkakrUHZFahP9bVD PJeRd9xkyclEOt32jB95cJMQ9QslA7zM5T78z33Wa5EK3Ly0rf7BGq2eAy2YhcnrFlppS837Zdm 0P8SpR5xce+6c5gVEXer9hgUrDCmz6S5xJ X-Received: by 2002:a17:906:11da:b0:a44:dc35:df19 with SMTP id o26-20020a17090611da00b00a44dc35df19mr3401125eja.67.1710282452826; Tue, 12 Mar 2024 15:27:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFShTwndBcRkeoht7ojHvVlKJpYFRIl0GU53PrRq7iZx6RC6WF5++L2bf/eldEvFoH2w3HqWw== X-Received: by 2002:a17:906:11da:b0:a44:dc35:df19 with SMTP id o26-20020a17090611da00b00a44dc35df19mr3401105eja.67.1710282452350; Tue, 12 Mar 2024 15:27:32 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id s19-20020a170906501300b00a433f470cf1sm4252067ejj.138.2024.03.12.15.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:31 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:29 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Alex Williamson , =?utf-8?q?C=C3=A9dric?= Le Goater Subject: [PULL 38/68] hw/vfio/iommufd: Fix missing ERRP_GUARD() in iommufd_cdev_getfd() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in iommufd_cdev_getfd(), @errp is dereferenced without ERRP_GUARD(): if (*errp) { error_prepend(errp, VFIO_MSG_PREFIX, path); } Currently, since vfio_attach_device() - the caller of iommufd_cdev_getfd() - is always called in DeviceClass.realize() context and doesn't get the NULL @errp parameter, iommufd_cdev_getfd() hasn't triggered the bug that dereferencing the NULL @errp. To follow the requirement of @errp, add missing ERRP_GUARD() in iommufd_cdev_getfd(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Reviewed-by: Markus Armbruster Message-Id: <20240223085653.1255438-7-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/vfio/iommufd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 9bfddc1360..7baf49e6ee 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -116,6 +116,7 @@ static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev) static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) { + ERRP_GUARD(); long int ret = -ENOTTY; char *path, *vfio_dev_path = NULL, *vfio_path = NULL; DIR *dir = NULL; From patchwork Tue Mar 12 22:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=i7Zq6YC0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT4b6dXhz23qj for ; Wed, 13 Mar 2024 09:35:43 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbP-0000eI-GZ; Tue, 12 Mar 2024 18:28:07 -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 1rkAb1-00083t-93 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:45 -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 1rkAay-0004RU-IQ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282460; 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=k/EiRia/WktsB6CMALV6JgPPHjttgoWQ71frCIn+d3U=; b=i7Zq6YC0JTuQG+bwNzljE6wQSGN5P1K6FQiDqHYwc0oGSqWL0y5FI8NebQuBj3NdS8N/N8 pUkJx+oNr8f67ddCjDNZgmS7DxzU1vtiyq7rDEbahgs9DKyeEnSXZBANvs0BVcKndpw64a 0X9HzsNYyHq4VvdQGukmlSeGvpb5ygk= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578--cRv60GgNbWzAbsDY5d3Jg-1; Tue, 12 Mar 2024 18:27:38 -0400 X-MC-Unique: -cRv60GgNbWzAbsDY5d3Jg-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-513c6e69b85so349570e87.0 for ; Tue, 12 Mar 2024 15:27:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282456; x=1710887256; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k/EiRia/WktsB6CMALV6JgPPHjttgoWQ71frCIn+d3U=; b=NfsQB8yhCiiJA00XsqSclXx1Vvjs8a/+Br0RIE+Dc5JsDcv2jibA5MvkV0+gTTLDQq wu24XVag7gvIu4oD/WbnFEvUM0m+s1k3lGqmhtmyXCz2zzUGna2SpR5UY9gVj37WYENx lt+2/XcIzlaBYthr8DdWhbBhrnv8QO0LBUaVq8EOuXU4zRCfC9syJKuNZ3Avap46W3Xc E0E/tS7rdjkc96UL8RHBhbkSiYSErn+Oy5h5ISTkrA7H3WmbjVEkTkShB11W6DHFRgoY QM7tKB9d06xTK12DbzZlKHfjy1zDQPrTxmjRLrt0TDkUo5OWtyhslHBxBSyXwVbuYpqe ul4g== X-Gm-Message-State: AOJu0YyMGB7/zIIdG9ntisuXffCxXR1ddB7whfk+tLJvbuVi7Pl6tf7l AtUiSB1nCm+dKv7tBAnSIfu6c5YDElBsEUUu7F1PG0/dYVJ3097d9go3f2LijaXJYjLI1lq5SDv gRRIThNh38/ZX79RvvJ8JLYoOlfPKSoF25Jr6G40sy7BKdHZRZLOuD7qKLePDsyazYqIJd0QcoY Fle/I602nNUk8Lsxc0/4fefp+b9by7ZPW7 X-Received: by 2002:ac2:4241:0:b0:513:b9ab:6e99 with SMTP id m1-20020ac24241000000b00513b9ab6e99mr2201498lfl.50.1710282455854; Tue, 12 Mar 2024 15:27:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIsyggiUH+m4JIci3RtHFIKVTzWpPPe3lFquwvm/56wnC/n+ScFPNCjsMQZPpnGCD+1HVtKg== X-Received: by 2002:ac2:4241:0:b0:513:b9ab:6e99 with SMTP id m1-20020ac24241000000b00513b9ab6e99mr2201483lfl.50.1710282455356; Tue, 12 Mar 2024 15:27:35 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id v15-20020a170906564f00b00a44bc99cd89sm4258490ejr.42.2024.03.12.15.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:34 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:32 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PULL 39/68] hw/intc: Check @errp to handle the error of IOAPICCommonClass.realize() Message-ID: <0f9c30350bdf9d062609a15124f30f6c2b0a4b60.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zhao Liu IOAPICCommonClass implements its own private realize(), and this private realize() allows error. Since IOAPICCommonClass.realize() returns void, to check the error, dereference @errp with ERRP_GUARD(). Signed-off-by: Zhao Liu Message-Id: <20240223085653.1255438-8-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- hw/intc/ioapic_common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/intc/ioapic_common.c b/hw/intc/ioapic_common.c index cb9bf62146..efbe6958c8 100644 --- a/hw/intc/ioapic_common.c +++ b/hw/intc/ioapic_common.c @@ -152,6 +152,7 @@ static int ioapic_dispatch_post_load(void *opaque, int version_id) static void ioapic_common_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); IOAPICCommonState *s = IOAPIC_COMMON(dev); IOAPICCommonClass *info; @@ -162,6 +163,9 @@ static void ioapic_common_realize(DeviceState *dev, Error **errp) info = IOAPIC_COMMON_GET_CLASS(s); info->realize(dev, errp); + if (*errp) { + return; + } sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io_memory); ioapic_no++; From patchwork Tue Mar 12 22:27:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QxS+FDY/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTC70nxLz1yWt for ; Wed, 13 Mar 2024 09:41:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbO-0000Wi-Eo; Tue, 12 Mar 2024 18:28:06 -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 1rkAb3-000847-Ct for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAb1-0004Rs-1v for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282462; 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: in-reply-to:in-reply-to:references:references; bh=GTX598p9HArzTLuFOxLRmny//KCE0d5V+ZWq2MLzXgc=; b=QxS+FDY/zP7uIwQub2R6AkEb4Erxop61k1p+mJzWeC5I4LRsUGb8uv4NsAytCikPCaSgqG eqriYXGIhOxLyvKH6DFHY4m1M/JkaEgAXEUXqqY5f4Qjp6wREafjX8R1/1wU5pArKtmUhQ n4q8xl/ivfLobCii4rToRYO/lKM8GYs= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-hw04cfAjPsmqkqFyvvBt6w-1; Tue, 12 Mar 2024 18:27:41 -0400 X-MC-Unique: hw04cfAjPsmqkqFyvvBt6w-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5684b85e0c9so296076a12.1 for ; Tue, 12 Mar 2024 15:27:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282459; x=1710887259; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GTX598p9HArzTLuFOxLRmny//KCE0d5V+ZWq2MLzXgc=; b=WD+9/4v42lRgC5qIck+mLZhMhBxPeWU4NmlViPBzi36V4aAeedoz9naPsvFoMdCIvu uJ6VPTNZWGV2N9wzF5+Dk/gtP5C/QuB+xo0qgoOj2jnp/pSuO+yD1a0J20JRxHzUK0WK or8W+JLShiP4vUOTQy1E/R8BrASV2838HymJYZwqyNlp/HgsvC2YESMD7lUNwU1nP2Mu /i/NZfvxml3ivkWZBtvGLreVived0gfauZJKwfs8+L05YXpKu2kZWoWF1y8lKNxtwRtz hGTdUXYtrQzk/yhgABnOTWLfPFf0mnNocTK2TjfRER/qitt+2hltDOpt2PnKYAt/0wjk yPPA== X-Gm-Message-State: AOJu0YyZVlD9OWyiK93sqlPkVzIgK8aJBlP6bAV7XaDu3sJ4PVKVq9bM Q1uy1dffXpHku2s0bc2zJOIz9tUKii+WhILBSzDBE4cmO2s5gyX2V/BGdPEQNweNmrZYqVWibwo qfm9dtNvbq+mGCsUA+i0ezrhu5Z13HRkDk7K/XZ1kFAxWC/JeruYCfzDwsfJPyJzlSd+w/Yj1m9 X7GTNSDmyzNHiLDQ3bPzB4/cS7XxZXejxW X-Received: by 2002:a50:cc89:0:b0:566:d083:df68 with SMTP id q9-20020a50cc89000000b00566d083df68mr707136edi.21.1710282459418; Tue, 12 Mar 2024 15:27:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGa5S5keexVi6Dkun5xvRgm/rGhpB0nN6qsiA5dFpVWMgHBQyZQ3SAvwwblUKBHQFX95crq8Q== X-Received: by 2002:a50:cc89:0:b0:566:d083:df68 with SMTP id q9-20020a50cc89000000b00566d083df68mr707095edi.21.1710282458418; Tue, 12 Mar 2024 15:27:38 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id m26-20020aa7c2da000000b005682d4f12b4sm4339184edp.45.2024.03.12.15.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:38 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:35 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Felix Wu , Nabih Estefan , Igor Mammedov , Ani Sinha Subject: [PULL 40/68] Implement base of SMBIOS type 9 descriptor. Message-ID: <735eee07d1f963635d3c3bf9f5e4bf1bc000870e.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Felix Wu Version 2.1+. Signed-off-by: Felix Wu Signed-off-by: Nabih Estefan Message-Id: <20240221170027.1027325-2-nabihestefan@google.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/firmware/smbios.h | 13 +++++ hw/smbios/smbios.c | 99 ++++++++++++++++++++++++++++++++++++ qemu-options.hx | 3 ++ 3 files changed, 115 insertions(+) diff --git a/include/hw/firmware/smbios.h b/include/hw/firmware/smbios.h index 6e514982d4..9ab114aea2 100644 --- a/include/hw/firmware/smbios.h +++ b/include/hw/firmware/smbios.h @@ -211,6 +211,19 @@ struct smbios_type_8 { uint8_t port_type; } QEMU_PACKED; +/* SMBIOS type 9 - System Slots (v2.1+) */ +struct smbios_type_9 { + struct smbios_structure_header header; + uint8_t slot_designation; + uint8_t slot_type; + uint8_t slot_data_bus_width; + uint8_t current_usage; + uint8_t slot_length; + uint16_t slot_id; + uint8_t slot_characteristics1; + uint8_t slot_characteristics2; +} QEMU_PACKED; + /* SMBIOS type 11 - OEM strings */ struct smbios_type_11 { struct smbios_structure_header header; diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index a3c4e52ce9..38b3ea172c 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -121,6 +121,16 @@ struct type8_instance { }; static QTAILQ_HEAD(, type8_instance) type8 = QTAILQ_HEAD_INITIALIZER(type8); +/* type 9 instance for parsing */ +struct type9_instance { + const char *slot_designation; + uint8_t slot_type, slot_data_bus_width, current_usage, slot_length, + slot_characteristics1, slot_characteristics2; + uint16_t slot_id; + QTAILQ_ENTRY(type9_instance) next; +}; +static QTAILQ_HEAD(, type9_instance) type9 = QTAILQ_HEAD_INITIALIZER(type9); + static struct { size_t nvalues; char **values; @@ -380,6 +390,54 @@ static const QemuOptDesc qemu_smbios_type8_opts[] = { { /* end of list */ } }; +static const QemuOptDesc qemu_smbios_type9_opts[] = { + { + .name = "type", + .type = QEMU_OPT_NUMBER, + .help = "SMBIOS element type", + }, + { + .name = "slot_designation", + .type = QEMU_OPT_STRING, + .help = "string number for reference designation", + }, + { + .name = "slot_type", + .type = QEMU_OPT_NUMBER, + .help = "connector type", + }, + { + .name = "slot_data_bus_width", + .type = QEMU_OPT_NUMBER, + .help = "port type", + }, + { + .name = "current_usage", + .type = QEMU_OPT_NUMBER, + .help = "current usage", + }, + { + .name = "slot_length", + .type = QEMU_OPT_NUMBER, + .help = "system slot length", + }, + { + .name = "slot_id", + .type = QEMU_OPT_NUMBER, + .help = "system slot id", + }, + { + .name = "slot_characteristics1", + .type = QEMU_OPT_NUMBER, + .help = "slot characteristics1, see the spec", + }, + { + .name = "slot_characteristics2", + .type = QEMU_OPT_NUMBER, + .help = "slot characteristics2, see the spec", + }, +}; + static const QemuOptDesc qemu_smbios_type11_opts[] = { { .name = "type", @@ -609,6 +667,7 @@ bool smbios_skip_table(uint8_t type, bool required_table) #define T2_BASE 0x200 #define T3_BASE 0x300 #define T4_BASE 0x400 +#define T9_BASE 0x900 #define T11_BASE 0xe00 #define T16_BASE 0x1000 @@ -807,6 +866,28 @@ static void smbios_build_type_8_table(void) } } +static void smbios_build_type_9_table(void) +{ + unsigned instance = 0; + struct type9_instance *t9; + + QTAILQ_FOREACH(t9, &type9, next) { + SMBIOS_BUILD_TABLE_PRE(9, T9_BASE + instance, true); + + SMBIOS_TABLE_SET_STR(9, slot_designation, t9->slot_designation); + t->slot_type = t9->slot_type; + t->slot_data_bus_width = t9->slot_data_bus_width; + t->current_usage = t9->current_usage; + t->slot_length = t9->slot_length; + t->slot_id = t9->slot_id; + t->slot_characteristics1 = t9->slot_characteristics1; + t->slot_characteristics2 = t9->slot_characteristics2; + + SMBIOS_BUILD_TABLE_POST; + instance++; + } +} + static void smbios_build_type_11_table(void) { char count_str[128]; @@ -1126,6 +1207,7 @@ void smbios_get_tables(MachineState *ms, } smbios_build_type_8_table(); + smbios_build_type_9_table(); smbios_build_type_11_table(); #define MAX_DIMM_SZ (16 * GiB) @@ -1460,6 +1542,23 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) t8_i->port_type = qemu_opt_get_number(opts, "port_type", 0); QTAILQ_INSERT_TAIL(&type8, t8_i, next); return; + case 9: { + if (!qemu_opts_validate(opts, qemu_smbios_type9_opts, errp)) { + return; + } + struct type9_instance *t; + t = g_new0(struct type9_instance, 1); + save_opt(&t->slot_designation, opts, "slot_designation"); + t->slot_type = qemu_opt_get_number(opts, "slot_type", 0); + t->slot_data_bus_width = qemu_opt_get_number(opts, "slot_data_bus_width", 0); + t->current_usage = qemu_opt_get_number(opts, "current_usage", 0); + t->slot_length = qemu_opt_get_number(opts, "slot_length", 0); + t->slot_id = qemu_opt_get_number(opts, "slot_id", 0); + t->slot_characteristics1 = qemu_opt_get_number(opts, "slot_characteristics1", 0); + t->slot_characteristics2 = qemu_opt_get_number(opts, "slot_characteristics2", 0); + QTAILQ_INSERT_TAIL(&type9, t, next); + return; + } case 11: if (!qemu_opts_validate(opts, qemu_smbios_type11_opts, errp)) { return; diff --git a/qemu-options.hx b/qemu-options.hx index ac4a30fa83..7da9235b08 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2718,6 +2718,9 @@ SRST ``-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-family=%d][,processor-id=%d]`` Specify SMBIOS type 4 fields +``-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d]`` + Specify SMBIOS type 9 fields + ``-smbios type=11[,value=str][,path=filename]`` Specify SMBIOS type 11 fields From patchwork Tue Mar 12 22:27:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911399 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I0wzsbSm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSxw3lY1z1yWt for ; Wed, 13 Mar 2024 09:29:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbS-000121-I3; Tue, 12 Mar 2024 18:28:10 -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 1rkAb6-00089z-Ew for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:48 -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 1rkAb3-0004SE-K4 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282464; 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: in-reply-to:in-reply-to:references:references; bh=NqqINJTPjtPrz9SrOlmZuaNG/epdXuQvR5UtyixbkoQ=; b=I0wzsbSmJd4VOW9JkRAUVcTrJleu9kw4sAWLbTikvkIypQT63lJMkQ69cJMnZnbnrkCeOi 6OAKpVB2fyj8gC5d9NCjLs7iTO9xAdHJ45WG+LrqcKeZySEoXLzJnhn63CahO5C2lqY6Ze WGQ26fhU+AROJ982NrCz2lm70BuBc/k= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-bK85dkSoMJyIq9ccpL3ITg-1; Tue, 12 Mar 2024 18:27:43 -0400 X-MC-Unique: bK85dkSoMJyIq9ccpL3ITg-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5684c1abc33so2350646a12.2 for ; Tue, 12 Mar 2024 15:27:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282462; x=1710887262; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NqqINJTPjtPrz9SrOlmZuaNG/epdXuQvR5UtyixbkoQ=; b=mavIEnlSqC9WD3Wyy0zdJz4mlFEdBhF4AeHW25JRmu/moGaqRyjbZlHNI+9x2K99mb yu+r/25fI1ONU/vWLdqmqChcKAjx9j7NplyjYWlEKGBAGm2S9jHVRVcVm86ICIWXXq4X SRBwYCHUHEc3oODiWNv2/Yhrxy4+s+MeNksrWPQM5lQEgk5wfRQllrI9bNyIf3ThnzEq OA7mqlI5ecMFIYBqz26BXiJjUtFuIihLlG96mFKeAYGL//iJM7LYem6tQZxxFxCEapkV 8XhxwcFlW2nGa1juYSEovxHVFG2jFB1s3as4NY8QiMmtm5HI2Tp1NoHJIanC60BbcvmA eQmg== X-Gm-Message-State: AOJu0YxyRDFy3vUBtiTk0OaS5YeFwGsKdwLjMyJFvv+7IiHOuewyoLAv dTZgSvhIr8xwcnNX1HnlLHMKD0lEVpY06paBaZ808+e09cZwPkxB1lWn9POqBApRnU0cmTCzMns Sx6ujsuqv8UKMJNTdvio6B1LRB5dc0TFEKi9mfVI/IKiKdNeWtJvtsT8Tg116A9cBwuTa22eozZ teF8zTuAnMbODGJTFHYOEFOtWujDfHS4Aw X-Received: by 2002:a50:d65c:0:b0:565:cbba:b7a1 with SMTP id c28-20020a50d65c000000b00565cbbab7a1mr2363372edj.1.1710282461942; Tue, 12 Mar 2024 15:27:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3xP+hoJCD7tM/5GLrYX3TvO3O01GDiQDOFMhaSmPaWqureyJ5Ly4APgqiEGnwWA/i7FxgDw== X-Received: by 2002:a50:d65c:0:b0:565:cbba:b7a1 with SMTP id c28-20020a50d65c000000b00565cbbab7a1mr2363353edj.1.1710282461517; Tue, 12 Mar 2024 15:27:41 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id r24-20020aa7d158000000b00568525ab2e8sm2964730edo.55.2024.03.12.15.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:41 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:38 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Felix Wu , Nabih Estefan , Igor Mammedov , Ani Sinha Subject: [PULL 41/68] Implement SMBIOS type 9 v2.6 Message-ID: <04f143d828845d0fd52dd4a52664d81a4f5431f7.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Felix Wu Signed-off-by: Felix Wu Signed-off-by: Nabih Estefan Message-Id: <20240221170027.1027325-3-nabihestefan@google.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/firmware/smbios.h | 4 +++ hw/smbios/smbios.c | 49 +++++++++++++++++++++++++++++++++--- qemu-options.hx | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/include/hw/firmware/smbios.h b/include/hw/firmware/smbios.h index 9ab114aea2..c21b8d3285 100644 --- a/include/hw/firmware/smbios.h +++ b/include/hw/firmware/smbios.h @@ -222,6 +222,10 @@ struct smbios_type_9 { uint16_t slot_id; uint8_t slot_characteristics1; uint8_t slot_characteristics2; + /* SMBIOS spec v2.6+ */ + uint16_t segment_group_number; + uint8_t bus_number; + uint8_t device_number; } QEMU_PACKED; /* SMBIOS type 11 - OEM strings */ diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 38b3ea172c..e3d5d8f2e2 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -123,7 +123,7 @@ static QTAILQ_HEAD(, type8_instance) type8 = QTAILQ_HEAD_INITIALIZER(type8); /* type 9 instance for parsing */ struct type9_instance { - const char *slot_designation; + const char *slot_designation, *pcidev; uint8_t slot_type, slot_data_bus_width, current_usage, slot_length, slot_characteristics1, slot_characteristics2; uint16_t slot_id; @@ -436,6 +436,11 @@ static const QemuOptDesc qemu_smbios_type9_opts[] = { .type = QEMU_OPT_NUMBER, .help = "slot characteristics2, see the spec", }, + { + .name = "pci_device", + .type = QEMU_OPT_STRING, + .help = "PCI device, if provided." + } }; static const QemuOptDesc qemu_smbios_type11_opts[] = { @@ -866,7 +871,7 @@ static void smbios_build_type_8_table(void) } } -static void smbios_build_type_9_table(void) +static void smbios_build_type_9_table(Error **errp) { unsigned instance = 0; struct type9_instance *t9; @@ -883,6 +888,43 @@ static void smbios_build_type_9_table(void) t->slot_characteristics1 = t9->slot_characteristics1; t->slot_characteristics2 = t9->slot_characteristics2; + if (t9->pcidev) { + PCIDevice *pdev = NULL; + int rc = pci_qdev_find_device(t9->pcidev, &pdev); + if (rc != 0) { + error_setg(errp, + "No PCI device %s for SMBIOS type 9 entry %s", + t9->pcidev, t9->slot_designation); + return; + } + /* + * We only handle the case were the device is attached to + * the PCI root bus. The general case is more complex as + * bridges are enumerated later and the table would need + * to be updated at this moment. + */ + if (!pci_bus_is_root(pci_get_bus(pdev))) { + error_setg(errp, + "Cannot create type 9 entry for PCI device %s: " + "not attached to the root bus", + t9->pcidev); + return; + } + t->segment_group_number = cpu_to_le16(0); + t->bus_number = pci_dev_bus_num(pdev); + t->device_number = pdev->devfn; + } else { + /* + * Per SMBIOS spec, For slots that are not of the PCI, AGP, PCI-X, + * or PCI-Express type that do not have bus/device/function + * information, 0FFh should be populated in the fields of Segment + * Group Number, Bus Number, Device/Function Number. + */ + t->segment_group_number = 0xff; + t->bus_number = 0xff; + t->device_number = 0xff; + } + SMBIOS_BUILD_TABLE_POST; instance++; } @@ -1207,7 +1249,7 @@ void smbios_get_tables(MachineState *ms, } smbios_build_type_8_table(); - smbios_build_type_9_table(); + smbios_build_type_9_table(errp); smbios_build_type_11_table(); #define MAX_DIMM_SZ (16 * GiB) @@ -1556,6 +1598,7 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) t->slot_id = qemu_opt_get_number(opts, "slot_id", 0); t->slot_characteristics1 = qemu_opt_get_number(opts, "slot_characteristics1", 0); t->slot_characteristics2 = qemu_opt_get_number(opts, "slot_characteristics2", 0); + save_opt(&t->pcidev, opts, "pcidev"); QTAILQ_INSERT_TAIL(&type9, t, next); return; } diff --git a/qemu-options.hx b/qemu-options.hx index 7da9235b08..937fd7ed84 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2718,7 +2718,7 @@ SRST ``-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-family=%d][,processor-id=%d]`` Specify SMBIOS type 4 fields -``-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d]`` +``-smbios type=9[,slot_designation=str][,slot_type=%d][,slot_data_bus_width=%d][,current_usage=%d][,slot_length=%d][,slot_id=%d][,slot_characteristics1=%d][,slot_characteristics12=%d][,pci_device=str]`` Specify SMBIOS type 9 fields ``-smbios type=11[,value=str][,path=filename]`` From patchwork Tue Mar 12 22:27:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Mc0LDPwX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT962631z1yWy for ; Wed, 13 Mar 2024 09:39:38 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbT-00010x-51; Tue, 12 Mar 2024 18:28: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 1rkAb9-00006S-92 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:53 -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 1rkAb7-0004Sz-Qa for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282469; 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: in-reply-to:in-reply-to:references:references; bh=WT7mvIjYqgBHqdRAbqMYX7U4dE3tDIe5od3vvmggkX8=; b=Mc0LDPwX/PNonZ4OTxYXWi7WIzCjZdJACgOhETrwM4zOgwu1pTRWvnlZrJoeiKOCaaPept ccgbCVZqOwGq4qS7ystiE+1OgybwQysJRttZoMAYCWat+knwk5lKXCkXQdNhLib7T2TeL2 6H/bKZHGnX0rkacnA41mkP3h4lf6WRE= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-CmHP_ilWMQatFu2tJRwRwQ-1; Tue, 12 Mar 2024 18:27:47 -0400 X-MC-Unique: CmHP_ilWMQatFu2tJRwRwQ-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-513b15ac4e0so363610e87.1 for ; Tue, 12 Mar 2024 15:27:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282466; x=1710887266; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WT7mvIjYqgBHqdRAbqMYX7U4dE3tDIe5od3vvmggkX8=; b=VIMXEwCHd07RDxQIXUZjwfpjYfn9573pBgQpdo6VStUri4tQtheuk7OQuApxuKUar9 SmqR+i2wzkgjw8lYmDDk4leXZQNm0XBZ6A1vKLwZ7n9Dven3PconuOqb0Qj2UlsH8w7J 7HXaqH82VZEYeblEEBJuYz1wDiXzOhQ8ygFrtlNocGUIl0yWG3JEORsn9btQ8BMPJ9BH VZobcuUcPE4lirjIw9UiYoe8WRs1gMw++8X/65tzM3Bhc9ob/ueD1JZzT/1dbNi41y6r FUo6zRkeqCntrE7lC27sCaAaNxBcog01DgPOLArObq40Qcn+WK3aSv8BMw5ohOyJ9vAl 8X0Q== X-Gm-Message-State: AOJu0Yyt2DgxQzRnkqIMTNmbvEwmzjIoQQUuVk8+WP91xOGOWPqNhfp5 vs+YfchOWBbnS0Js/m/kJcx+3bm8JUjialJwidvpFHn+0xTvUh5d0lqG7eBy8Dcgrth3C0DcubV MrAEwn1pwx5lMabUY/6hb+Y+bdDNn2rMtYzXjGJfcwQm9L/9o8wWA8mex9tjLDny2f9D/YTLcte Nn+HZyeZnAVIGuWXACeMVyMiC9fahlIkt0 X-Received: by 2002:ac2:5e39:0:b0:513:b574:9421 with SMTP id o25-20020ac25e39000000b00513b5749421mr845673lfg.21.1710282465729; Tue, 12 Mar 2024 15:27:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSYfmj84CJPxIWoLHx29PhQWusG/lj1ODWAbotGSB73/UOaFyGdPnX9oM19wKN5iNZxfLJtw== X-Received: by 2002:ac2:5e39:0:b0:513:b574:9421 with SMTP id o25-20020ac25e39000000b00513b5749421mr845660lfg.21.1710282465220; Tue, 12 Mar 2024 15:27:45 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id la18-20020a170907781200b00a43e8e76825sm4299260ejc.149.2024.03.12.15.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:44 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:41 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , qemu-stable@nongnu.org, Keith Busch , Klaus Jensen , qemu-block@nongnu.org Subject: [PULL 42/68] hw/nvme: Use pcie_sriov_num_vfs() Message-ID: <91bb64a8d2014fda33a81fcf0fce37340f0d3b0c.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Akihiko Odaki nvme_sriov_pre_write_ctrl() used to directly inspect SR-IOV configurations to know the number of VFs being disabled due to SR-IOV configuration writes, but the logic was flawed and resulted in out-of-bound memory access. It assumed PCI_SRIOV_NUM_VF always has the number of currently enabled VFs, but it actually doesn't in the following cases: - PCI_SRIOV_NUM_VF has been set but PCI_SRIOV_CTRL_VFE has never been. - PCI_SRIOV_NUM_VF was written after PCI_SRIOV_CTRL_VFE was set. - VFs were only partially enabled because of realization failure. It is a responsibility of pcie_sriov to interpret SR-IOV configurations and pcie_sriov does it correctly, so use pcie_sriov_num_vfs(), which it provides, to get the number of enabled VFs before and after SR-IOV configuration writes. Cc: qemu-stable@nongnu.org Fixes: CVE-2024-26328 Fixes: 11871f53ef8e ("hw/nvme: Add support for the Virtualization Management command") Suggested-by: Michael S. Tsirkin Signed-off-by: Akihiko Odaki Message-Id: <20240228-reuse-v8-1-282660281e60@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/nvme/ctrl.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 76fe039704..2860a9bed1 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8466,36 +8466,26 @@ static void nvme_pci_reset(DeviceState *qdev) nvme_ctrl_reset(n, NVME_RESET_FUNCTION); } -static void nvme_sriov_pre_write_ctrl(PCIDevice *dev, uint32_t address, - uint32_t val, int len) +static void nvme_sriov_post_write_config(PCIDevice *dev, uint16_t old_num_vfs) { NvmeCtrl *n = NVME(dev); NvmeSecCtrlEntry *sctrl; - uint16_t sriov_cap = dev->exp.sriov_cap; - uint32_t off = address - sriov_cap; - int i, num_vfs; + int i; - if (!sriov_cap) { - return; - } - - if (range_covers_byte(off, len, PCI_SRIOV_CTRL)) { - if (!(val & PCI_SRIOV_CTRL_VFE)) { - num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); - for (i = 0; i < num_vfs; i++) { - sctrl = &n->sec_ctrl_list.sec[i]; - nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false); - } - } + for (i = pcie_sriov_num_vfs(dev); i < old_num_vfs; i++) { + sctrl = &n->sec_ctrl_list.sec[i]; + nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false); } } static void nvme_pci_write_config(PCIDevice *dev, uint32_t address, uint32_t val, int len) { - nvme_sriov_pre_write_ctrl(dev, address, val, len); + uint16_t old_num_vfs = pcie_sriov_num_vfs(dev); + pci_default_write_config(dev, address, val, len); pcie_cap_flr_write_config(dev, address, val, len); + nvme_sriov_post_write_config(dev, old_num_vfs); } static const VMStateDescription nvme_vmstate = { From patchwork Tue Mar 12 22:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AWKVya8x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT0C2wT4z23rC for ; Wed, 13 Mar 2024 09:31:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbS-00010Q-Rr; Tue, 12 Mar 2024 18:28: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 1rkAbB-0000Io-P1 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbA-0004TW-72 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282471; 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: in-reply-to:in-reply-to:references:references; bh=+ZUqhBABaLKjAmH/al3SU44QSVSzRDb6r3qc1ttxIM8=; b=AWKVya8xCOvu1wpQ/e0N8Dfo4h1yJpQW5HQALux+2XT33u1uBCDcq09+mtva/jG26Ue+o5 N2uisTtrKiYCycP8mgLWSwL1SGDUNkecG5a+VC9lrBDJ7+r4eVGiLBcljzFzg/7Q/pQQ0F qhNP70PaXpzMpOdbkrtDL/nlH7VxumI= 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-682-8I-Z5UTkPoS3tK-wYlD00g-1; Tue, 12 Mar 2024 18:27:50 -0400 X-MC-Unique: 8I-Z5UTkPoS3tK-wYlD00g-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a4488afb812so23139966b.3 for ; Tue, 12 Mar 2024 15:27:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282469; x=1710887269; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+ZUqhBABaLKjAmH/al3SU44QSVSzRDb6r3qc1ttxIM8=; b=R4bGbcUT6ab772edHu09Sj+Z0YU+cLp4TL5fQc2vjHA5gs3mdnVEOeoihMr2uDCxKG +FOB1S6W5eUQO8um3jGalTNMzWx9T+zn7NKtYKWLDbZXU1A1Gcgum1EZhEiqBqxTH+LE DUt15k07jZ8EvPv/7A2gETUX9TmolBHSXH2CaMo3VndQtXT1bCvc6urF85IpkrfDAIfl Gjp6ya+QQ1WoBPUmgDeF1t74UdQOsXMezGSjVKE0XKADK8W3afvs56eXfKOHBLSc1j0q IhUj88AVaKkTlfzE0KelRjIRUjrwZg7XuRjM6rPwRqW0ESEt23VT+vhIikG1LPbZ4Cyo 8rnw== X-Gm-Message-State: AOJu0YwLUAeYOl8t/+39Tg2wdU7QIWMN8dZulgdBLjzFTiA/oQV+aSTs hzvy20GfRlCcrCqU5bNyyNTGhhHWlRR8oS+gAgJPxOZRutWQCPt4RWTZLH4Rp/1g8vDHDpRQhCC q29qYJ3kwde7XNI4L0uKbl9QAN2895DnYPRvHNG6+biy8G5YBxfAytQUrARpFKp+GkbtdWMWO3Q s8rGTgDg8R64Q0rYFwZKo+LLFRvshsSaj8 X-Received: by 2002:a17:907:d406:b0:a44:8fa9:d36f with SMTP id vi6-20020a170907d40600b00a448fa9d36fmr1092528ejc.41.1710282468762; Tue, 12 Mar 2024 15:27:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5pw7kRt7c+5TfJrv0kbEABOl2QpB/bkvikW4SIAjo2uhx5MPcRI8ySm4lXR6t6FSz0JPy9g== X-Received: by 2002:a17:907:d406:b0:a44:8fa9:d36f with SMTP id vi6-20020a170907d40600b00a448fa9d36fmr1092513ejc.41.1710282468144; Tue, 12 Mar 2024 15:27:48 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id be10-20020a1709070a4a00b00a461d2a3374sm2893740ejc.47.2024.03.12.15.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:47 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:45 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , qemu-stable@nongnu.org, Sriram Yagnaraman , Marcel Apfelbaum Subject: [PULL 43/68] pcie_sriov: Validate NumVFs Message-ID: <6081b4243cd64dff1b2cf5b0c215c71e9d7e753b.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Akihiko Odaki The guest may write NumVFs greater than TotalVFs and that can lead to buffer overflow in VF implementations. Cc: qemu-stable@nongnu.org Fixes: CVE-2024-26327 Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki Message-Id: <20240228-reuse-v8-2-282660281e60@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Sriram Yagnaraman --- hw/pci/pcie_sriov.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index a1fe65f5d8..da209b7f47 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -176,6 +176,9 @@ static void register_vfs(PCIDevice *dev) assert(sriov_cap > 0); num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF); + if (num_vfs > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_VF)) { + return; + } dev->exp.sriov_pf.vf = g_new(PCIDevice *, num_vfs); From patchwork Tue Mar 12 22:27:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dyeOiIPa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvSxG6Hy3z1yWt for ; Wed, 13 Mar 2024 09:29:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbj-0002Bc-TD; Tue, 12 Mar 2024 18:28:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbH-0000Rx-QC for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:01 -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 1rkAbF-0004U3-1q for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282476; 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: in-reply-to:in-reply-to:references:references; bh=BVAzYUdYDXeS1BjbLwTo4D9WpXNY+EQLjqjS51o2N6Q=; b=dyeOiIPaaJs1SJrXaolOdlEYq1SGkqvNo3TDI0Nz2WS/LmHIkt3Re6IeTB0uAl7S53+K4A I6KVB3Yoiu6RZDaxhB+E9TcV5xfAuYChrTBuvgf79iV6QsPnNoUwRuWpuKcgXvRNjRIvk1 hsXL0dGiisQGm5sU8EJxSoZZ2Hzhls4= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-15-MaE45JF1ObmG0yAQj-e9VA-1; Tue, 12 Mar 2024 18:27:54 -0400 X-MC-Unique: MaE45JF1ObmG0yAQj-e9VA-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d45ce4457eso10603441fa.0 for ; Tue, 12 Mar 2024 15:27:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282473; x=1710887273; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BVAzYUdYDXeS1BjbLwTo4D9WpXNY+EQLjqjS51o2N6Q=; b=WoxXyDY90gM4984Mwu1QbpcsBrj7xPx8JQk6NCuSNnaEZiukBxeozUQKOqnjyVpmdI 4GaOB398cHwC+g6LLJRWbVXuFeRHe037UFNhqcOA+jr4zHSKw91bWy+B39GmZBVeqH7Z hrC+GIMC2pfCcxYtUx0oYOdQ31MtG9LsxygBag6C/KGBsbWdhElgRlu4ZTUeSz2O3kkX m4rRdceVVujgxRceWZD2mmwGeT2UvE3R4RpbrrlsPNckcyu2KlvTHaJ8onplbxY+BUH0 MplCVbW46Cs+BjQ/TzEjBI5GFZHKCxLIb8mGZRjPrinU8boocrEfQxjDzUpJ9k/Fq/i3 fFNg== X-Gm-Message-State: AOJu0Yxgyz475RQjDnmwexwUvBfdlkQza2NdbMDBmrHsK513dfRYavH9 tlVQRRGL33KHMXfih/uYClzZ9mD3F7amfv7JMb6w7CFXWNkI2P14B0zZYpONn1GMKGxD50CwnXg ImwohoaCmFaO40vAFdA9tiTvfS/iAGPeIO0kn9Ox74VcyN9WY5SkEre3a9vzjwcjJWg6LMyfxfa 1fJiLvsxMeWlkUwPT94PWuKykckAMeWidB X-Received: by 2002:a05:651c:19a9:b0:2d4:2b05:a671 with SMTP id bx41-20020a05651c19a900b002d42b05a671mr7668447ljb.32.1710282472818; Tue, 12 Mar 2024 15:27:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaakUsdseKRtUZRtuj29cuQXD8qIflaps60yPx+hhLx32+EVGLUZdyRhKZBfmHXm9/KF77LQ== X-Received: by 2002:a05:651c:19a9:b0:2d4:2b05:a671 with SMTP id bx41-20020a05651c19a900b002d42b05a671mr7668417ljb.32.1710282472155; Tue, 12 Mar 2024 15:27:52 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id f8-20020a056402004800b00568550a0762sm2805826edu.6.2024.03.12.15.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:51 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:48 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Sriram Yagnaraman , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , qemu-block@nongnu.org Subject: [PULL 44/68] pcie_sriov: Reset SR-IOV extended capability Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Akihiko Odaki pcie_sriov_pf_disable_vfs() is called when resetting the PF, but it only disables VFs and does not reset SR-IOV extended capability, leaking the state and making the VF Enable register inconsistent with the actual state. Replace pcie_sriov_pf_disable_vfs() with pcie_sriov_pf_reset(), which does not only disable VFs but also resets the capability. Signed-off-by: Akihiko Odaki Message-Id: <20240228-reuse-v8-3-282660281e60@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Sriram Yagnaraman --- include/hw/pci/pcie_sriov.h | 4 ++-- hw/net/igb.c | 2 +- hw/nvme/ctrl.c | 2 +- hw/pci/pcie_sriov.c | 26 ++++++++++++++++++-------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h index 095fb0c9ed..b77eb7bf58 100644 --- a/include/hw/pci/pcie_sriov.h +++ b/include/hw/pci/pcie_sriov.h @@ -58,8 +58,8 @@ void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t opt_sup_pgsize); void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, uint32_t val, int len); -/* Reset SR/IOV VF Enable bit to unregister all VFs */ -void pcie_sriov_pf_disable_vfs(PCIDevice *dev); +/* Reset SR/IOV */ +void pcie_sriov_pf_reset(PCIDevice *dev); /* Get logical VF number of a VF - only valid for VFs */ uint16_t pcie_sriov_vf_number(PCIDevice *dev); diff --git a/hw/net/igb.c b/hw/net/igb.c index 0b5c31a58b..9345506f81 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -493,7 +493,7 @@ static void igb_qdev_reset_hold(Object *obj) trace_e1000e_cb_qdev_reset_hold(); - pcie_sriov_pf_disable_vfs(d); + pcie_sriov_pf_reset(d); igb_core_reset(&s->core); } diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 2860a9bed1..447c4de6fd 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -7116,7 +7116,7 @@ static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetType rst) } if (rst != NVME_RESET_CONTROLLER) { - pcie_sriov_pf_disable_vfs(pci_dev); + pcie_sriov_pf_reset(pci_dev); } } diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index da209b7f47..51b66d1bb3 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -249,16 +249,26 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, } -/* Reset SR/IOV VF Enable bit to trigger an unregister of all VFs */ -void pcie_sriov_pf_disable_vfs(PCIDevice *dev) +/* Reset SR/IOV */ +void pcie_sriov_pf_reset(PCIDevice *dev) { uint16_t sriov_cap = dev->exp.sriov_cap; - if (sriov_cap) { - uint32_t val = pci_get_byte(dev->config + sriov_cap + PCI_SRIOV_CTRL); - if (val & PCI_SRIOV_CTRL_VFE) { - val &= ~PCI_SRIOV_CTRL_VFE; - pcie_sriov_config_write(dev, sriov_cap + PCI_SRIOV_CTRL, val, 1); - } + if (!sriov_cap) { + return; + } + + pci_set_word(dev->config + sriov_cap + PCI_SRIOV_CTRL, 0); + unregister_vfs(dev); + + /* + * Default is to use 4K pages, software can modify it + * to any of the supported bits + */ + pci_set_word(dev->config + sriov_cap + PCI_SRIOV_SYS_PGSIZE, 0x1); + + for (uint16_t i = 0; i < PCI_NUM_REGIONS; i++) { + pci_set_quad(dev->config + sriov_cap + PCI_SRIOV_BAR + i * 4, + dev->exp.sriov_pf.vf_bar_type[i]); } } From patchwork Tue Mar 12 22:27:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Z5Fn5NM2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT4k51P5z1yWy for ; Wed, 13 Mar 2024 09:35:50 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbm-0002CK-14; Tue, 12 Mar 2024 18:28:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbJ-0000ST-5t for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:01 -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 1rkAbH-0004UG-OG for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282478; 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: in-reply-to:in-reply-to:references:references; bh=uONnc8dalxn5KqbUxXF6SkXpgxsJrMvte59h3sp2Ce0=; b=Z5Fn5NM2CpWCeNfmsKgZdQWBR+V2a6bwdXpHBfjl+KR7ZhamzpF7fQ17PmvqHyXCAaq+qN 2FPmVQeoH0oVsc38UrvshBr339ST58qaZRTfj3YsGQcS4GSODknvBAM38Mxbksc6BG57Gp PM0GZUpgvJGmP8n/k4UY/ki89fd7jjQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-FAGwaPCOMVCHc5b0TfKkSA-1; Tue, 12 Mar 2024 18:27:57 -0400 X-MC-Unique: FAGwaPCOMVCHc5b0TfKkSA-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-568647e6d9dso197027a12.3 for ; Tue, 12 Mar 2024 15:27:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282476; x=1710887276; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uONnc8dalxn5KqbUxXF6SkXpgxsJrMvte59h3sp2Ce0=; b=YBId2Zn3M7eTr3oM8U+tguCmZjw/y782ykQWFoZNrv+25M7WPGkGgvFJPTbCRU5FOA +8OFR/8Jb5eAysOJo5/mbQ2yDnMxdgd54jiR5ZBpWP2n8Q7dVKqqoyCJG8xB1OQqFMlu 1DnxPiSkvY90KHeACczx6iy7s9nFjyXuuwEkkUbT6sjWUQ/q4piOUIYtRBS8W0yf/SFB kq59mkCong3knQ48p1SzGHOE3crSshkcIeoqIoY9F78oRKen2KBPS2reJNrovCoDc6Yc WlG8qtZupGXP1PY7qmo38NoPFNwpLeIh/A1+LQlCCxuWXxNHUoE12cSta2EvigwoBrwJ 0gTg== X-Gm-Message-State: AOJu0YyJtNVJydLosu1dbVW6ZXXznPIIPGT49GqlGvV5wm4h0CV+JHaQ 2eRni/+65zl4DbZS5aD0V/9KXlhWBT214wkDQgCIghvUkBuEcKKmLyHr4XKYeo/AksSSnG15cBc U9tDWb9eQaVc3hIs1DMs2DhQEQZladiGqUlthhHA9uzzr265gCGsKlwRScuzOOEr3j09Psd935s Sl+QEXq/UiTDLqBwq65wawi/8H7gfZJl8P X-Received: by 2002:a50:d594:0:b0:565:b4ca:72f3 with SMTP id v20-20020a50d594000000b00565b4ca72f3mr3862904edi.35.1710282476023; Tue, 12 Mar 2024 15:27:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFf9Hz0rZaiQCY9cfMLdqVUs/oKzdSOXs1K3kKi7oFgeYUQa01wvwwDvM0E3MT5+nTFW8PvKA== X-Received: by 2002:a50:d594:0:b0:565:b4ca:72f3 with SMTP id v20-20020a50d594000000b00565b4ca72f3mr3862885edi.35.1710282475466; Tue, 12 Mar 2024 15:27:55 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id o23-20020aa7c7d7000000b005686b5c3c1asm1463352eds.22.2024.03.12.15.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:55 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:52 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Marcel Apfelbaum Subject: [PULL 45/68] pcie_sriov: Do not reset NumVFs after disabling VFs Message-ID: <63eb76dda237843582f3616f4403ae795e471e17.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Akihiko Odaki The spec does not NumVFs is reset after disabling VFs except when resetting the PF. Clearing it is guest visible and out of spec, even though Linux doesn't rely on this value being preserved, so we never noticed. Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki Message-Id: <20240228-reuse-v8-4-282660281e60@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pcie_sriov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 51b66d1bb3..e9b23221d7 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -215,7 +215,6 @@ static void unregister_vfs(PCIDevice *dev) g_free(dev->exp.sriov_pf.vf); dev->exp.sriov_pf.vf = NULL; dev->exp.sriov_pf.num_vfs = 0; - pci_set_word(dev->config + dev->exp.sriov_cap + PCI_SRIOV_NUM_VF, 0); } void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, @@ -260,6 +259,8 @@ void pcie_sriov_pf_reset(PCIDevice *dev) pci_set_word(dev->config + sriov_cap + PCI_SRIOV_CTRL, 0); unregister_vfs(dev); + pci_set_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF, 0); + /* * Default is to use 4K pages, software can modify it * to any of the supported bits From patchwork Tue Mar 12 22:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HXawJCET; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8r2gYcz23qj for ; Wed, 13 Mar 2024 09:39:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbo-0002Sl-5i; Tue, 12 Mar 2024 18:28: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 1rkAbN-0000VS-Bo for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbL-0004V0-Uc for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282483; 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: in-reply-to:in-reply-to:references:references; bh=akonLPthwYIhBZHpIZGIq9r2NNojszL0eybTb3tNgkY=; b=HXawJCETuy4AYLzhUJ8P67m4onfiR9y4MK5W4iWDjMp/r+XZORNUtuTaLIi+iGwe8sUnti NWTqgj4jgvQKAsl21mnj7YGXHo7DaIwQ70Wo/y+Vs+o2LGqDrnDNmdAv1Hl4UIupR/hrkJ yBs4FsdJ1ZNjaWXGWHi/YZ8RCkcsmhw= 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-343-EdPnNFw3MdaalUHAy6TPlQ-1; Tue, 12 Mar 2024 18:28:01 -0400 X-MC-Unique: EdPnNFw3MdaalUHAy6TPlQ-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-568728e521bso1094416a12.0 for ; Tue, 12 Mar 2024 15:28:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282479; x=1710887279; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=akonLPthwYIhBZHpIZGIq9r2NNojszL0eybTb3tNgkY=; b=K8B+EHGGud8hL1zefhUcBrhvaBOd4/vVsq0BzFF5YKGNxQ873FO8rdsxRfn1R/LdW5 i/MVmO4CBqj1G33cQ8Z+YRrzW9ouJvjwFaI7H7kgAJ3Gc7HFr+aboLwJhKeTTaFR+c2n HFO3cZhx0wfdDbfJNhn2q58t08d4xDk26+s/cxlHFv/olecaUSIQQGUSZPsYZ8hJROPK XsFQxQn0g35jpXWzS22fGSRJsK0AvnpfohxhI9NbVFllvn8qsuPYIwo8XQyLKyTqfa9B 2Q6IPEs5Zo6bvo0G/KlCk4TPK4jM+1U/dq+K7O6wnoChmg59mnc7bMc34j7t3Q9JepHO j3eg== X-Gm-Message-State: AOJu0YyLkCNXJk6OUt4AU4REB4ibIFo34l1h/JudcnC4YdE9sO2d3Yoe ZvaoDT6/Lkyz0c/LrdYMW2M8LdCiuk5U2ucMRLG6j9AgihneMsIzJsfTTnXgaKkCuQKXtKMYxlh ASo11jvbVidiZwNX42YXAQpcfNiWIwJ186hAMwOygDRBBYDXv1DwjlcJUbShfJWfp02p0EJA6Kw TVrR7FbS4rsj2S6/OJtSTRV957jx8WNFN1 X-Received: by 2002:a50:85ca:0:b0:565:9c76:73c3 with SMTP id q10-20020a5085ca000000b005659c7673c3mr2234764edh.29.1710282479559; Tue, 12 Mar 2024 15:27:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjfWqhJk0JNsuF2PrMzMadSWRjBqomqSwwXYF3xskZ8Ar3sCxBUHY7Jt/aQrUTZM3RTh8H+g== X-Received: by 2002:a50:85ca:0:b0:565:9c76:73c3 with SMTP id q10-20020a5085ca000000b005659c7673c3mr2234746edh.29.1710282479009; Tue, 12 Mar 2024 15:27:59 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id ek24-20020a056402371800b005682fbc2531sm4262946edb.74.2024.03.12.15.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:58 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:55 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Sriram Yagnaraman , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Marcel Apfelbaum , qemu-block@nongnu.org Subject: [PULL 46/68] hw/pci: Always call pcie_sriov_pf_reset() Message-ID: <1a909e3dd85d5c57a0e6a7e3285a29e57574f80d.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Akihiko Odaki Call pcie_sriov_pf_reset() from pci_do_device_reset() just as we do for msi_reset() and msix_reset() to prevent duplicating code for each SR-IOV PF. Signed-off-by: Akihiko Odaki Message-Id: <20240228-reuse-v8-5-282660281e60@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Sriram Yagnaraman --- hw/net/igb.c | 2 -- hw/nvme/ctrl.c | 4 ---- hw/pci/pci.c | 1 + 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/hw/net/igb.c b/hw/net/igb.c index 9345506f81..9b37523d6d 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -488,12 +488,10 @@ static void igb_pci_uninit(PCIDevice *pci_dev) static void igb_qdev_reset_hold(Object *obj) { - PCIDevice *d = PCI_DEVICE(obj); IGBState *s = IGB(obj); trace_e1000e_cb_qdev_reset_hold(); - pcie_sriov_pf_reset(d); igb_core_reset(&s->core); } diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 447c4de6fd..40159f39b8 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -7114,10 +7114,6 @@ static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetType rst) sctrl = &n->sec_ctrl_list.sec[i]; nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false); } - - if (rst != NVME_RESET_CONTROLLER) { - pcie_sriov_pf_reset(pci_dev); - } } if (rst != NVME_RESET_CONTROLLER) { diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 6496d027ca..e7a39cb203 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -409,6 +409,7 @@ static void pci_do_device_reset(PCIDevice *dev) msi_reset(dev); msix_reset(dev); + pcie_sriov_pf_reset(dev); } /* From patchwork Tue Mar 12 22:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O1/1AcEy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTBy2v2Pz1yWt for ; Wed, 13 Mar 2024 09:41:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbq-0002cg-Jv; Tue, 12 Mar 2024 18:28:34 -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 1rkAbS-0001DF-55 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:10 -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 1rkAbQ-0004Vn-An for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282487; 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=etBZs3HX2lGuBR1hbVUB0rO/sMf1IGM8GxytboDqRdM=; b=O1/1AcEyI9TRYBPOepTRs1L8Wnry4vD8MS8OMnWnZsXeKtkzv2wM8Sw66WqxhhODjw9a4m bOeXgf1S36VF5tsHYk8u410f90nlF2feWRfPoqgj6FNkT7XEJwAzxCYYWd/10SRe3oVjYy rZKHFSx28uRo0OlGs8y0HGrfZiR2S5g= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-GzzxZA9xPHmCU2_lKKWONA-1; Tue, 12 Mar 2024 18:28:06 -0400 X-MC-Unique: GzzxZA9xPHmCU2_lKKWONA-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-513c65ffba5so471443e87.2 for ; Tue, 12 Mar 2024 15:28:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282484; x=1710887284; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=etBZs3HX2lGuBR1hbVUB0rO/sMf1IGM8GxytboDqRdM=; b=v8eGxFmZktfUtYCs4oqlGRYqrOauRWVhlKdJCHm95ht9lq7IVEyojfEPJ0KzWq47J/ LAuB+gfh3kq9FcZWNfYPheBviSjuoqQa5LVLTwdDiHfJginw9E7hyWZ6Sg9Jg9IAJdeD Sf5sfhmM0APTTXJ9y16voJHGKDWnsX2abjlm8juTZyaGUYWqpKHm0MMBlPBO1K9Wune7 hJGEnMmmy18i1+xKMzTUBlv6Ei7XZ351s0WDuDuLQ8B4wECXlIxrFETssIUUb3KX3Axi GHvkE0rDebrEDanBs+7n08FKD8tYvCmyJIW9arDPXj3o4w+u/Wd22RbEUWWYPMJ2E+NO bEww== X-Gm-Message-State: AOJu0Yz4KLMhP2tF9GYyY9fgKH7Eln5HWyuvQkYfeor9xz7t/W0y8X6y mtyk8MyilzCM62euhKHvJHvzGhP64M7wh9LTAZnI3F9XTKwvf9tkqAOGE+wVQei56M1iDAPCCuG T2ww1Vg7ICoW2Ge5TL5xPf1SM1jsn0vZdyJz9M0XupY97so8yLNHrd8xx7SLFeEq7tz1e6wlpd5 ZuHShOMl8Fr5joX51VaaF2N7tMJSvgt48M X-Received: by 2002:a2e:731a:0:b0:2d2:869a:55af with SMTP id o26-20020a2e731a000000b002d2869a55afmr1159329ljc.17.1710282483747; Tue, 12 Mar 2024 15:28:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSFqKvR2UcFJXgi5mGcjFeYUWNfakFoXm8r2jVygLNu+yNQcChYg+JznZMhc4eaNfM6rgQiQ== X-Received: by 2002:a2e:731a:0:b0:2d2:869a:55af with SMTP id o26-20020a2e731a000000b002d2869a55afmr1159305ljc.17.1710282483136; Tue, 12 Mar 2024 15:28:03 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id f8-20020a056402004800b00568550a0762sm2805946edu.6.2024.03.12.15.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:02 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:59 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ani Sinha , Daniel P =?utf-8?b?LiBCZXJyYW5nw6k=?= , Igor Mammedov , Julia Suvorova , kraxel@redhat.com, Zhao Liu , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 47/68] pc: q35: Bump max_cpus to 4096 vcpus Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ani Sinha Since commit f10a570b093e6 ("KVM: x86: Add CONFIG_KVM_MAX_NR_VCPUS to allow up to 4096 vCPUs") Linux kernel can support upto a maximum number of 4096 vcpus when MAXSMP is enabled in the kernel. At present, QEMU has been tested to correctly boot a linux guest with 4096 vcpus using the current edk2 upstream master branch that has the fixes corresponding to the following two PRs: https://github.com/tianocore/edk2/pull/5410 https://github.com/tianocore/edk2/pull/5418 The changes merged into edk2 with the above PRs will be in the upcoming 2024-05 release. With current seabios firmware, it boots fine with 4096 vcpus already. So bump up the value max_cpus to 4096 for q35 machines versions 9 and newer. Q35 machines versions 8.2 and older continue to support 1024 maximum vcpus as before for compatibility reasons. If KVM is not able to support the specified number of vcpus, QEMU would return the following error messages: $ ./qemu-system-x86_64 -cpu host -accel kvm -machine q35 -smp 1728 qemu-system-x86_64: -accel kvm: warning: Number of SMP cpus requested (1728) exceeds the recommended cpus supported by KVM (12) qemu-system-x86_64: -accel kvm: warning: Number of hotpluggable cpus requested (1728) exceeds the recommended cpus supported by KVM (12) Number of SMP cpus requested (1728) exceeds the maximum cpus supported by KVM (1024) Cc: Daniel P. Berrangé Cc: Igor Mammedov Cc: Michael S. Tsirkin Cc: Julia Suvorova Cc: kraxel@redhat.com Reviewed-by: Daniel P. Berrangé Reviewed-by: Igor Mammedov Reviewed-by: Gerd Hoffmann Signed-off-by: Ani Sinha Message-Id: <20240228143351.3967-1-anisinha@redhat.com> Reviewed-by: Zhao Liu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc_q35.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 45a4102e75..df63a92b78 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -350,7 +350,7 @@ static void pc_q35_machine_options(MachineClass *m) m->default_nic = "e1000e"; m->default_kernel_irqchip_split = false; m->no_floppy = 1; - m->max_cpus = 1024; + m->max_cpus = 4096; m->no_parallel = !module_object_class_by_name(TYPE_ISA_PARALLEL); machine_class_allow_dynamic_sysbus_dev(m, TYPE_AMD_IOMMU_DEVICE); machine_class_allow_dynamic_sysbus_dev(m, TYPE_INTEL_IOMMU_DEVICE); @@ -371,6 +371,7 @@ static void pc_q35_8_2_machine_options(MachineClass *m) { pc_q35_9_0_machine_options(m); m->alias = NULL; + m->max_cpus = 1024; compat_props_add(m->compat_props, hw_compat_8_2, hw_compat_8_2_len); compat_props_add(m->compat_props, pc_compat_8_2, pc_compat_8_2_len); } From patchwork Tue Mar 12 22:28:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GRhNtTje; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTDz07Gcz1yWt for ; Wed, 13 Mar 2024 09:42:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbn-0002Nk-9v; Tue, 12 Mar 2024 18:28:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbV-0001Tq-0i for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbT-0004W8-As for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282490; 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: in-reply-to:in-reply-to:references:references; bh=rnobKvRBI1kxmZ+zEo4/9xYhnFk0DiLD2cKoeuPWbew=; b=GRhNtTjemHO9+X/1YAUmBla9XknTzx9Zg7h+1MkP/kjdr3g/0Y4fnse+0jL1iDi5H4NYK0 MPCj/g3x4aP8bYoQ14ItP06kyc7lSpzd0yn7ZeLNnBem2TPmkCOpM0rZzXVCR5MZ6jMeiU j57V9P8QKZZpKBX4dplc3FFAzEGU2hA= 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-422-UULgOr5OOMSnecr7gP9Qiw-1; Tue, 12 Mar 2024 18:28:09 -0400 X-MC-Unique: UULgOr5OOMSnecr7gP9Qiw-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a448cfe2266so494039266b.2 for ; Tue, 12 Mar 2024 15:28:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282487; x=1710887287; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rnobKvRBI1kxmZ+zEo4/9xYhnFk0DiLD2cKoeuPWbew=; b=wQVIOocvuG6sHrDSZnT6LnyKC+ZLhdeQjXQ4hqWWVqzk+Oq+l8ab2Y+sFep+mns+hF HCMx4W5lmyS+hW0gs/dlVNfJfM9kssA5WkcJHdJH7Vnc7UpNCNKS9MNrVukWNNcO1tk7 wFzb/K7LZi9DxM3pZh41qo3h+cC1tT16YVNjExKcggGP59PcVaLE/22TKnnqss2lsewG 8WD/OsgTVOLzAfsHd1Z7ArErFa97HlkHHfh/GAmxsMicumLLjsTYi1TG4YFVbz8abmE5 aNiQktMiRqHvAADvJH6Ps1fLZ6my6JlZrzCKRszsZSAZkJEABE1TWt3FKl3c9jxoPpC0 UBZA== X-Gm-Message-State: AOJu0YxBbWg14f8aXJw/icvmEdgOYAAp+zlBJr8paPL5oP7wQRHnqdhA 2NSeeCDPB5wHME1B2MioZiVqHAyRRT2xKru00GQ898fSrsbmwq77p9Ej3qqzH4twQ4EEfaPmFQW WIHQaglqX54p3Pzn1wuG+USd/ZA8r20Zoc6kmheXWflooEA4s9q3oyko7Ei7WcDcFfjrT2swi2O oR7ZJqyWKxH29ySOf4VmRgVBFd5NY7KAod X-Received: by 2002:a17:906:58d:b0:a43:e63b:2ecc with SMTP id 13-20020a170906058d00b00a43e63b2eccmr6034334ejn.67.1710282487337; Tue, 12 Mar 2024 15:28:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTrLNq7Dbg6AfyrLulJW5b8yqFhP3W0+WDTcknfkVMZI8z6z/xvHj6UMDaeEFZbP0lSHu6eQ== X-Received: by 2002:a17:906:58d:b0:a43:e63b:2ecc with SMTP id 13-20020a170906058d00b00a43e63b2eccmr6034316ejn.67.1710282486817; Tue, 12 Mar 2024 15:28:06 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id bx21-20020a170906a1d500b00a45ff890df0sm4116271ejb.35.2024.03.12.15.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:06 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:03 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Bernhard Beschow , Alex Williamson , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PULL 48/68] Revert "hw/i386/pc_sysfw: Inline pc_system_flash_create() and remove it" Message-ID: <0fbe8d7c4c7e44fc86986217dc3ab65ec4e6a302.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bernhard Beschow Commit 6f6ad2b24582 "hw/i386/pc: Confine system flash handling to pc_sysfw" causes a regression when specifying the property `-M pflash0` in the PCI PC machines: qemu-system-x86_64: Property 'pc-q35-9.0-machine.pflash0' not found In order to revert the commit, the commit below must be reverted first. This reverts commit cb05cc16029bb0a61ac5279ab7b3b90dcf2aa69f. Signed-off-by: Bernhard Beschow Message-Id: <20240226215909.30884-2-shentey@gmail.com> Tested-by: Alex Williamson Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc_sysfw.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index b02e285579..b9c1eb352d 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -91,6 +91,18 @@ static PFlashCFI01 *pc_pflash_create(PCMachineState *pcms, return PFLASH_CFI01(dev); } +static void pc_system_flash_create(PCMachineState *pcms) +{ + PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); + + if (pcmc->pci_enabled) { + pcms->flash[0] = pc_pflash_create(pcms, "system.flash0", + "pflash0"); + pcms->flash[1] = pc_pflash_create(pcms, "system.flash1", + "pflash1"); + } +} + static void pc_system_flash_cleanup_unused(PCMachineState *pcms) { char *prop_name; @@ -198,8 +210,7 @@ void pc_system_firmware_init(PCMachineState *pcms, return; } - pcms->flash[0] = pc_pflash_create(pcms, "system.flash0", "pflash0"); - pcms->flash[1] = pc_pflash_create(pcms, "system.flash1", "pflash1"); + pc_system_flash_create(pcms); /* Map legacy -drive if=pflash to machine properties */ for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) { From patchwork Tue Mar 12 22:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hrAuymyF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTC86wvnz23qj for ; Wed, 13 Mar 2024 09:41:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbp-0002Zh-SD; Tue, 12 Mar 2024 18:28:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbY-0001vV-Lw for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:18 -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 1rkAbW-0004Wf-Df for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282493; 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=yc5lDH4MBP7afzT8lUJV0jnq7XYBGeFbKEEd+01/J0E=; b=hrAuymyFnI2ceU7nrKX5i05nsgnp2gUo4JiE0IaAeSb1cxE9/Cz4+es21uCYhjuXJpT9EZ ixHJe+qUZveT3X0/DVZNwPDb1tI7nlTOrBlelTAeiilK1yPuEmVtpxf6Gc6xjRV3Dv6OLo aik9zbStegQmF8rwa60Y7mKgnGQ+BxE= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-RdPBmW4qNKq1xRnc8CPGBw-1; Tue, 12 Mar 2024 18:28:12 -0400 X-MC-Unique: RdPBmW4qNKq1xRnc8CPGBw-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-564fec337b1so275606a12.0 for ; Tue, 12 Mar 2024 15:28:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282491; x=1710887291; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yc5lDH4MBP7afzT8lUJV0jnq7XYBGeFbKEEd+01/J0E=; b=OuLcnMGJR5ulTtNSfXqD9bX9CRjKlN8OzQyRK51O/vVpzk1uoPsRCVAcokqqVy1KRX r00ScNMK7+hepmY+lT8hDGScKCwRWb5xH6IlLLr3r1EZn2rZN+BP9sVx83dVd0xV1zJz 7HwyburdebV+lqNBBWbDUSwv6dZbs8584Tv+8CUK5CAmY7DL8top6+vakozLz4aVcvK3 OcoV8u+sun2wQrwgaxpPE6WMOmCpXlbiJNKRv1YPSN8V+IKX08LiHgjwBX/aB0L8CVpI 0p4y2DoWUeA1rVlrbGBmVFdF+NLKDJfTvhbejVndlxGuF7Xi8rKQibHR/95ItDyofRKd 3rOg== X-Gm-Message-State: AOJu0YyevzrnJrLw6PvdQUOBu+rgvxNQ48CeFVf9X4aDTlsyoR7xKt+H M7XI/ANHtmgNGP/w+2d6voD4ml7lP7YTFc7ppzb9rCtFPxnTqxjPfhqupSueVtSNRueAtdkQsX1 Q1q5Jl89rNyfCWmJNrTbhoTRJ1hV8FlMGiDpU0HbQE5xEKwnp9QyfFbplA/8IToeXawf109zmil 1fyPJIHXWeh8/Tz4djvahxXy2TQ74XGW6+ X-Received: by 2002:a50:8a93:0:b0:564:4211:faa3 with SMTP id j19-20020a508a93000000b005644211faa3mr923758edj.1.1710282491176; Tue, 12 Mar 2024 15:28:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSg5Lt1vagvNktxkbfgl4aek3QdcvJCB+GRRByMcf7WDNYhy5GaDCN0nWebKUYDvUL/2OreQ== X-Received: by 2002:a50:8a93:0:b0:564:4211:faa3 with SMTP id j19-20020a508a93000000b005644211faa3mr923716edj.1.1710282490660; Tue, 12 Mar 2024 15:28:10 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id b2-20020aa7c902000000b00564e489ce9asm4412356edt.12.2024.03.12.15.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:10 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:07 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Bernhard Beschow , Volker =?utf-8?q?R=C3=BCmelin?= , Alex Williamson , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 49/68] Revert "hw/i386/pc: Confine system flash handling to pc_sysfw" Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bernhard Beschow Specifying the property `-M pflash0` results in a regression: qemu-system-x86_64: Property 'pc-q35-9.0-machine.pflash0' not found Revert the change for now until a solution is found. This reverts commit 6f6ad2b24582593d8feb00434ce2396840666227. Reported-by: Volker Rümelin Signed-off-by: Bernhard Beschow Message-Id: <20240226215909.30884-3-shentey@gmail.com> Tested-by: Alex Williamson Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 2 ++ hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_sysfw.c | 6 ++---- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index b958023187..8458487a5e 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -190,6 +190,8 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); #define TYPE_PORT92 "port92" /* pc_sysfw.c */ +void pc_system_flash_create(PCMachineState *pcms); +void pc_system_flash_cleanup_unused(PCMachineState *pcms); void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory); bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f5ff970acf..24e8879894 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1750,6 +1750,7 @@ static void pc_machine_initfn(Object *obj) pcms->fd_bootchk = true; pcms->default_bus_bypass_iommu = false; + pc_system_flash_create(pcms); pcms->pcspk = isa_new(TYPE_PC_SPEAKER); object_property_add_alias(OBJECT(pcms), "pcspk-audiodev", OBJECT(pcms->pcspk), "audiodev"); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 319bc4b180..9dd9f5562e 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -228,6 +228,7 @@ static void pc_init1(MachineState *machine, const char *pci_type) assert(machine->ram_size == x86ms->below_4g_mem_size + x86ms->above_4g_mem_size); + pc_system_flash_cleanup_unused(pcms); if (machine->kernel_filename != NULL) { /* For xen HVM direct kernel boot, load linux here */ xen_load_linux(pcms); diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index b9c1eb352d..3efabbbab2 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -91,7 +91,7 @@ static PFlashCFI01 *pc_pflash_create(PCMachineState *pcms, return PFLASH_CFI01(dev); } -static void pc_system_flash_create(PCMachineState *pcms) +void pc_system_flash_create(PCMachineState *pcms) { PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); @@ -103,7 +103,7 @@ static void pc_system_flash_create(PCMachineState *pcms) } } -static void pc_system_flash_cleanup_unused(PCMachineState *pcms) +void pc_system_flash_cleanup_unused(PCMachineState *pcms) { char *prop_name; int i; @@ -210,8 +210,6 @@ void pc_system_firmware_init(PCMachineState *pcms, return; } - pc_system_flash_create(pcms); - /* Map legacy -drive if=pflash to machine properties */ for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) { pflash_cfi01_legacy_drive(pcms->flash[i], From patchwork Tue Mar 12 22:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MEJ/q3U7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTDx51TTz1yWt for ; Wed, 13 Mar 2024 09:42:57 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbp-0002Z3-NL; Tue, 12 Mar 2024 18:28:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbc-00020D-4g for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAba-0004X8-Bv for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282497; 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=NyTDZtJqprCGpfIUlVDmTHoGSmpXfrw9EDci6rQtZxA=; b=MEJ/q3U7lbGncX9W1wSzev+wYDKPxCy69epDAOnX8VokizfFNTYtqwKgwcjb4sTeEIpwcP 2MGU38ZUzHwzpNrotXnSSUsvx7ixpT9D7QQz/peszosXSQM1zyStjAuYcV7qowdJ2vDfkB KTWBFsCgcvTfpO4Nn4luTo0jmVpa3no= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-iUMbNeYHOpSVkMigWTgExg-1; Tue, 12 Mar 2024 18:28:16 -0400 X-MC-Unique: iUMbNeYHOpSVkMigWTgExg-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-51321a5bfadso4755305e87.2 for ; Tue, 12 Mar 2024 15:28:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282494; x=1710887294; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NyTDZtJqprCGpfIUlVDmTHoGSmpXfrw9EDci6rQtZxA=; b=lYD+HmCCukaRtLbzRy7FI9UYSe3kVW8Wz/U4MmPghDlVOWeNgijV7m4v5FeyWOFCmV /gLRCVdwociA/NkRJe0puL0Xmodykk8onobvF563fGwEM/Z6h7ZagzfNnWv7kq9jhUE/ cTd5MPxqs13U+yLZr63EIjDNewMnoBygg+amAQtls8vguhv05Bf91LlrANjo5z2TlBJP +l608Qox6DjWrAKW33VPwQRUu1kDCUl/mHGL3NLA/up6ADILt5NBFLiePGztSDPsN3ce DdWGfo8aNxOn5v4E3x6IMECJDyxvCk+kshUzdC9LgLCTmv3Ih93LrXoeGSTV1CVczeRN i0FA== X-Gm-Message-State: AOJu0YxN4VoTziBKtbDCLp9IDw+nL/9JVaRVXSf94ZGo5h5JeMrBWMwK xc0WTqP5uBPZWwQtS6BopmgtZLMEFwBlxJ8sFD/iFi40OVUan2v0NHBgFv1kChBzJogNL1vBOVq GCbVIEm2bwFBxJomO4iuDWlsYh+JVVjWOmGTubGapG9K86AsaTDkIbf/HkpjU4K8gt/Ozu9nicA Id+kg+7G8+1WTj/eyWGeBoDur2YlLIDp3I X-Received: by 2002:a19:7716:0:b0:513:c2ad:8b05 with SMTP id s22-20020a197716000000b00513c2ad8b05mr1527207lfc.34.1710282494485; Tue, 12 Mar 2024 15:28:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoT3EBjmE5J0rOuPHNW2bsAhQYWyg6iyV/T/p+/qWFcprUA9KkMDQaABu4OtI5BIzRyKsm9w== X-Received: by 2002:a19:7716:0:b0:513:c2ad:8b05 with SMTP id s22-20020a197716000000b00513c2ad8b05mr1527193lfc.34.1710282494010; Tue, 12 Mar 2024 15:28:14 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id hg13-20020a1709072ccd00b00a45fefe4fc5sm4177062ejc.135.2024.03.12.15.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:13 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:10 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Bernhard Beschow , Paolo Bonzini , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 50/68] hw/i386/pc: Remove "rtc_state" link again Message-ID: <6cd2b093e771ee606b4e065f615d9b2fafd76d22.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bernhard Beschow Commit 99e1c1137b6f "hw/i386/pc: Populate RTC attribute directly" made linking the "rtc_state" property unnecessary and removed it. Commit 84e945aad2d0 "vl, pc: turn -no-fd-bootchk into a machine property" accidently reintroduced the link. Remove it again since it is not needed. Fixes: 84e945aad2d0 "vl, pc: turn -no-fd-bootchk into a machine property" Cc: Paolo Bonzini Signed-off-by: Bernhard Beschow Message-Id: <20240303185332.1408-2-shentey@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- hw/i386/pc.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 24e8879894..98bcf4d420 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -613,14 +613,6 @@ void pc_cmos_init(PCMachineState *pcms, mc146818rtc_set_cmos_data(s, 0x5c, val >> 8); mc146818rtc_set_cmos_data(s, 0x5d, val >> 16); - object_property_add_link(OBJECT(pcms), "rtc_state", - TYPE_ISA_DEVICE, - (Object **)&x86ms->rtc, - object_property_allow_set_link, - OBJ_PROP_LINK_STRONG); - object_property_set_link(OBJECT(pcms), "rtc_state", OBJECT(s), - &error_abort); - set_boot_dev(pcms, s, MACHINE(pcms)->boot_config.order, &error_fatal); val = 0; From patchwork Tue Mar 12 22:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U7QXKRcC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8y1Sn4z1yWy for ; Wed, 13 Mar 2024 09:39:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbt-0002k1-7q; Tue, 12 Mar 2024 18:28:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbf-00022L-0y for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:23 -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 1rkAbd-0004Xa-MG for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282501; 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=Injg7cneMn8eAOXhLA6j7Wl6zrm7JF8+SWheD737+3s=; b=U7QXKRcCNxeenDkkzo/Hr1Qm1iMCWcj+oT/d+ueJ2lF1gs4lnVGp/KBX77vrI6IhCibFX9 sXdZECZ9GS7phdq/li1kMFSnmpi73hL5f9KR3Tb8oa8Tub76v8h8kkgEhRdmY1VfsWiWVP 7H8DPDwhZ/Zcc6YIJxVI/YPLWaaw9tI= 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-352-ZK5YOAZXObyIWWpTgoxdsg-1; Tue, 12 Mar 2024 18:28:19 -0400 X-MC-Unique: ZK5YOAZXObyIWWpTgoxdsg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a4606018ec4so29845266b.0 for ; Tue, 12 Mar 2024 15:28:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282498; x=1710887298; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Injg7cneMn8eAOXhLA6j7Wl6zrm7JF8+SWheD737+3s=; b=eDAEPd+o/ssV4X/j4e+aBQ4+xzFgmMK4hEkgSj187MHZxQXqQ3qEjOF7WoLfzuL7FF RlZCNqh2FfTuCHa8zi6qG/+3U4OsnKVFXPbf1JlisxUO8iR4OAQNlJeFx50j38GJSGdM sw+XrL1X5PZBFqBHYLhKfjQxuCu4HGB1S0uBbXJF5DPFaH1ns+gsD+oP2lNL+y+S8KyW 6ICHIIuLweEugYjDAC8BKRkFIzM6zIzJ8DSB34uT6OeGXMSa7Jzg1T8KGZGpFd307Abq YB26GfP/hsQm9OqgBztfYHbGcu5mhROo8+3LtUlj/MEdkw6xN09UWGfyMAKtIjCi6CnC lgGw== X-Gm-Message-State: AOJu0YzfYRt3y6D8zoooBRFGIExicOiZyl59gRde/pzDeScmB/usp71F AaqyqFiAv2u3T8uQEgF1CPvEw6nqY3QXkbyz7T9yL3Ywxvo5Clg/I0MBBMXe8j7B4WPVRLWdpKS hcTm4gk62hPqtnCfox7MXALv4QGxkrkpZ0u3JVZrTzqNXW/9jQoH7FpiMDm1qTzVNVreRSAmHsl KLKyKDXYlZTlxahkKGhY1A77fpOOoYgSu0 X-Received: by 2002:a17:907:a809:b0:a45:b506:11ca with SMTP id vo9-20020a170907a80900b00a45b50611camr915489ejc.7.1710282498465; Tue, 12 Mar 2024 15:28:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFn5JpY9eP8hcgxpEIzKW0ew9Upj7T/CVLDRTuNlcsmsXXOzuIc6kwHsMRmF06FI0QEQopj4g== X-Received: by 2002:a17:907:a809:b0:a45:b506:11ca with SMTP id vo9-20020a170907a80900b00a45b50611camr915469ejc.7.1710282498042; Tue, 12 Mar 2024 15:28:18 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id v8-20020a1709067d8800b00a45aeaf9969sm4241375ejo.5.2024.03.12.15.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:17 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:14 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Bernhard Beschow , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 51/68] hw/i386/pc: Avoid one use of the current_machine global Message-ID: <6605d09791df7387c3e82c9554731a752789987e.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bernhard Beschow The RTC can be accessed through the X86 machine instance, so rather than passing the RTC it's possible to pass the machine state instead. This avoids pc_boot_set() from having to access the current_machine global. Signed-off-by: Bernhard Beschow Message-Id: <20240303185332.1408-3-shentey@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- hw/i386/pc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 98bcf4d420..4077d8162c 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -425,9 +425,10 @@ static void set_boot_dev(PCMachineState *pcms, MC146818RtcState *s, static void pc_boot_set(void *opaque, const char *boot_device, Error **errp) { - PCMachineState *pcms = PC_MACHINE(current_machine); + PCMachineState *pcms = opaque; + X86MachineState *x86ms = X86_MACHINE(pcms); - set_boot_dev(pcms, opaque, boot_device, errp); + set_boot_dev(pcms, MC146818_RTC(x86ms->rtc), boot_device, errp); } static void pc_cmos_init_floppy(MC146818RtcState *rtc_state, ISADevice *floppy) @@ -1252,7 +1253,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, } #endif - qemu_register_boot_set(pc_boot_set, rtc_state); + qemu_register_boot_set(pc_boot_set, pcms); if (!xen_enabled() && (x86ms->pit == ON_OFF_AUTO_AUTO || x86ms->pit == ON_OFF_AUTO_ON)) { From patchwork Tue Mar 12 22:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I3/S8yUM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT2F2s5Sz1ydl for ; Wed, 13 Mar 2024 09:33:41 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAcA-0002qG-T4; Tue, 12 Mar 2024 18:28:56 -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 1rkAbj-0002Hc-5A for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbh-0004Xu-Iw for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282504; 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: in-reply-to:in-reply-to:references:references; bh=RVo6YlMfVuw9z+NrVasJcWSQp6XiMZPaDOieWuMq5y8=; b=I3/S8yUMYuA+lxVFwulY6obp7sFmAjDYteSqSbM46epN8SHs5mjEFPKQbOfOeeE2IHznLA oUywls2Q30T6RFQYBT7yeUvbn3h46ZtiTIYxNdo59N8Hj1etfOJf0HqZqqZxHI6g0q66iI gPbBPdE2xf4GXmbv6Iynvi717DHWL7c= 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-595-bVqveck9PgWG6QTBjmO5lg-1; Tue, 12 Mar 2024 18:28:23 -0400 X-MC-Unique: bVqveck9PgWG6QTBjmO5lg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a448cfe2266so494050466b.2 for ; Tue, 12 Mar 2024 15:28:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282502; x=1710887302; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RVo6YlMfVuw9z+NrVasJcWSQp6XiMZPaDOieWuMq5y8=; b=jWB9ljVGoV4yU3alW66FnwI+1CZhZdf1H3CKSqYZq/wj3UMqmjIqawBinxdO6s1Ddq FrSYqjevP29JmQK0uasmhcFSBW1oyvH/kaP4nvY/NUl0yNg1HdBsg36SE2bYwc6J39X7 A+sSEBZFl0+bfENSXPHEPNZ+Q7TIPwWJD7tvO/UvQFgs7rBZL9J4fRvrIsD1xDWlRzal hwVauQgPrrnkk/qSvYwbNbtRs6fU2o9UbjHzwCyxvjnm4py56Fp8hFdpP9FCPz7zUgGq KWfjYgOc/GPVkfXp9VgEutrHSfK8krzXndnquPp9haPxJ/IOI2lxCdQbgyXxFUYEFKP9 GBXQ== X-Gm-Message-State: AOJu0Yz36V2y1ygEpn1ZjyVffzBnC/gUiIetfLkF1zvu+TLI7jcXhAbV 0BLlj7pr4RWCZzSm+ddOr+9TOsUJpfTzn72E2eoN1GaG/0+xpw5LZviPoWImfXOzNTMMtBbk6aq x/dHIr8YWWmZoCMauNE7gs3wpt5Gzlde6IyO/EEPnp7R3HLep8XMPMw/UQsEUf0p/1IJclAItnJ EwEM8jbztcIm/sdBuU9MJwVPnecVuWs6ho X-Received: by 2002:a17:907:a095:b0:a46:127a:61a7 with SMTP id hu21-20020a170907a09500b00a46127a61a7mr6829711ejc.72.1710282501626; Tue, 12 Mar 2024 15:28:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKmhgE/ofZZ8UXO0d8b/a5qbMynNr/sGPXj4AU0/5oQEyY+6946rHDoK9dFWkAwQ5wl0+9dA== X-Received: by 2002:a17:907:a095:b0:a46:127a:61a7 with SMTP id hu21-20020a170907a09500b00a46127a61a7mr6829692ejc.72.1710282500977; Tue, 12 Mar 2024 15:28:20 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id s19-20020a170906501300b00a433f470cf1sm4252594ejj.138.2024.03.12.15.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:20 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:18 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Bernhard Beschow , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 52/68] hw/i386/pc: Set "normal" boot device order in pc_basic_device_init() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bernhard Beschow The boot device order may change during the lifetime of a VM. Usually, the "normal" order is set once during machine init(). However, if a user specifies `-boot once=...`, the "normal" order is overwritten by the "once" order just before machine_done, and a reset handler is registered which restores the "normal" order during the next reset. In the next patch, pc_cmos_init() will be inlined into pc_cmos_init_late() which runs during machine_done. This means that the "once" boot order would be overwritten again with the "normal" boot order -- which renders the user's choice ineffective. Fix this by setting the "normal" boot order in pc_basic_device_init() which already registers the boot_set() handler. Signed-off-by: Bernhard Beschow Message-Id: <20240303185332.1408-4-shentey@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4077d8162c..c614697ca6 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -614,8 +614,6 @@ void pc_cmos_init(PCMachineState *pcms, mc146818rtc_set_cmos_data(s, 0x5c, val >> 8); mc146818rtc_set_cmos_data(s, 0x5d, val >> 16); - set_boot_dev(pcms, s, MACHINE(pcms)->boot_config.order, &error_fatal); - val = 0; val |= 0x02; /* FPU is there */ val |= 0x04; /* PS/2 mouse installed */ @@ -1254,6 +1252,8 @@ void pc_basic_device_init(struct PCMachineState *pcms, #endif qemu_register_boot_set(pc_boot_set, pcms); + set_boot_dev(pcms, MC146818_RTC(rtc_state), + MACHINE(pcms)->boot_config.order, &error_fatal); if (!xen_enabled() && (x86ms->pit == ON_OFF_AUTO_AUTO || x86ms->pit == ON_OFF_AUTO_ON)) { From patchwork Tue Mar 12 22:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XU/2vra1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT3S5g1Gz1ydl for ; Wed, 13 Mar 2024 09:34:44 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAbs-0002i5-Vl; Tue, 12 Mar 2024 18:28:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbl-0002KV-EN for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAbj-0004Y8-Tz for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282507; 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: in-reply-to:in-reply-to:references:references; bh=HRYAFmiIOZoNHp71a+p+TPZ7pg4hnnbXtufAOJw7DWA=; b=XU/2vra1PWQSHPur1xTVrnYq19RsDQjGYCF9ZClR3ib98GvK3cyha6DPysRACxtZO64hxk aVn546Jec/KX+GU6ZPN9SaYHjhPx6Yyw8n1CcLrw813sN+dRKj2sKhD52qENJnrO9qErGG D9QJkdUSyeBToAUpM28Kg0ngIUZQsCw= 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-168--rx-xyUmMmatqjUSnaJXbg-1; Tue, 12 Mar 2024 18:28:26 -0400 X-MC-Unique: -rx-xyUmMmatqjUSnaJXbg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a4489805a2dso176750166b.2 for ; Tue, 12 Mar 2024 15:28:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282504; x=1710887304; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HRYAFmiIOZoNHp71a+p+TPZ7pg4hnnbXtufAOJw7DWA=; b=Rc5I9oqncetp2qwoP3RPZKzJZ3onycVdZb7fL4Ch37tGuvsWHGiqmvPJxRrV4vfP3T RSQSJ9OC2SPMITqo17CnKrQ7feUN357mKHfTVo3mrF7Dc7ss3vyNZ7gVmSoxD6/Vk48F IU4mvOl7h6G9SOP/4mSpHPDcHlv0emR+64+WCuLSbJGz0K/xVsk9mDNIvYbOHCXlwFRC xHXEokk/kKJ+6hC9gafnc6k8SIOQhz9r9YT0XZ6ErBT4EgK72xNe/0scZhN8G0cqX8Ew 5dUEicIli9kb4iQdcegQztG7MriEvOveulLUOOwKwbxPIcY4BEwYW9czUXz9IiYFDB+b L7lg== X-Gm-Message-State: AOJu0Yz4HZahX1/YhUjRxtiuB6cYOPyLgRZulhueO+NZahddPNjmNBD0 Sd9bTViplaoBJmJKXiyPbSK+wVTjMoL4MIPwjzSaPe2H39/Uf1QqEZqQzQsLEfwLAmrPfa9S29g YfG1C3D/3HgYtEoO3sRtYmr+tVedU5esEVH1dYDQXTmWTRfnJ0jidLqQvLUVEIVK9l8C8CzV89h nj1WDTniqT7e2bT34O7GUuAuWvZ72LaiXv X-Received: by 2002:a17:907:cbc1:b0:a45:a3e9:debd with SMTP id vk1-20020a170907cbc100b00a45a3e9debdmr8213828ejc.59.1710282504462; Tue, 12 Mar 2024 15:28:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAvwH57dOUxhey4nr9xzfL0gG/qe5PxWH+ERvbPuSEkol8XBL1gj4Napla/sPHr1tplaMDpw== X-Received: by 2002:a17:907:cbc1:b0:a45:a3e9:debd with SMTP id vk1-20020a170907cbc100b00a45a3e9debdmr8213810ejc.59.1710282503982; Tue, 12 Mar 2024 15:28:23 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id jo11-20020a170906f6cb00b00a46522c38c4sm200844ejb.207.2024.03.12.15.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:23 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:21 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Bernhard Beschow , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PULL 53/68] hw/i386/pc: Inline pc_cmos_init() into pc_cmos_init_late() and remove it Message-ID: <7d12305ec8c3fa8c60b39aae0d952245a62696d4.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bernhard Beschow Now that pc_cmos_init() doesn't populate the X86MachineState::rtc attribute any longer, its duties can be merged into pc_cmos_init_late() which is called within machine_done notifier. This frees pc_piix and pc_q35 from explicit CMOS initialization. Signed-off-by: Bernhard Beschow Message-Id: <20240303185332.1408-5-shentey@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 2 -- hw/i386/pc.c | 10 ---------- hw/i386/pc_piix.c | 2 -- hw/i386/pc_q35.c | 2 -- 4 files changed, 16 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 8458487a5e..27a68071d7 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -178,8 +178,6 @@ void pc_basic_device_init(struct PCMachineState *pcms, ISADevice *rtc_state, bool create_fdctrl, uint32_t hpet_irqs); -void pc_cmos_init(PCMachineState *pcms, - ISADevice *s); void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus); void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c614697ca6..1590352bb5 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -570,14 +570,6 @@ static void pc_cmos_init_late(PCMachineState *pcms) mc146818rtc_set_cmos_data(s, 0x39, val); pc_cmos_init_floppy(s, pc_find_fdc0()); -} - -void pc_cmos_init(PCMachineState *pcms, - ISADevice *rtc) -{ - int val; - X86MachineState *x86ms = X86_MACHINE(pcms); - MC146818RtcState *s = MC146818_RTC(rtc); /* various important CMOS locations needed by PC/Bochs bios */ @@ -618,8 +610,6 @@ void pc_cmos_init(PCMachineState *pcms, val |= 0x02; /* FPU is there */ val |= 0x04; /* PS/2 mouse installed */ mc146818rtc_set_cmos_data(s, REG_EQUIPMENT_BYTE, val); - - /* hard drives and FDC are handled by pc_cmos_init_late() */ } static void handle_a20_line_change(void *opaque, int irq, int level) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 9dd9f5562e..c9a6c0aa68 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -344,8 +344,6 @@ static void pc_init1(MachineState *machine, const char *pci_type) } #endif - pc_cmos_init(pcms, x86ms->rtc); - if (piix4_pm) { smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index df63a92b78..1356c5d107 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -311,8 +311,6 @@ static void pc_q35_init(MachineState *machine) smbus_eeprom_init(pcms->smbus, 8, NULL, 0); } - pc_cmos_init(pcms, x86ms->rtc); - /* the rest devices to which pci devfn is automatically assigned */ pc_vga_init(isa_bus, pcms->pcibus); pc_nic_init(pcmc, isa_bus, pcms->pcibus); From patchwork Tue Mar 12 22:28:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TBQTCnpo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT3S5h20z23qj for ; Wed, 13 Mar 2024 09:34:44 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAd6-0004iy-Oo; Tue, 12 Mar 2024 18:29: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 1rkAbw-0002nx-Vd for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:41 -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 1rkAbo-0004Ya-Ro for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282512; 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: in-reply-to:in-reply-to:references:references; bh=NKjNHtkXPHoAzSk29a1QOldo8lgRrG30XA8l+09SuTY=; b=TBQTCnpogQ4IC1wKf3NIQZBCofqbCQMDvzPcs+tNI2OHqCrz0l7ba72AGR82ZS1N4Gcyu/ TP0AvVqpQs4X+0/KjNuxNeLM5bH0JkwfV2EItqPWEwX1OFuD3G9W3BeAzq3rphRF5vbQeb JPMnDmBqPxesQQt6pEUsho1GZ5wOpAc= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-L4dEMc-RPeqzurL0GXCX0g-1; Tue, 12 Mar 2024 18:28:30 -0400 X-MC-Unique: L4dEMc-RPeqzurL0GXCX0g-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-513b1027dd5so2937228e87.1 for ; Tue, 12 Mar 2024 15:28:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282508; x=1710887308; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NKjNHtkXPHoAzSk29a1QOldo8lgRrG30XA8l+09SuTY=; b=NBwMz7hjsQ2psE6oSLZNaNCE2xjrcZZxtmxgEVruCc25l/eBx571+kMAzGAOMwWkhY GjDkksqqT6NQ2zxzddKv/ZnAyiV1gGufn/8AXJtNQDnGmPk3XP2515FlxM2NCoC7rDxY 3Qpvcm0schVN1xoG2wLFvoIOsDaLCVYXPquddSvc7qxbq6QV26cRcU6yAbKLAUHr5m2H iKfojni2wMdyxnqsqbb6zTZaMPjn6fersLbzGQP2oT5hWdcGXDeLOWdJl9Ww+26wa5PK fCNN4/KXTdklw8nfG2pvs4V73gwbobNl8eI6FOXYZByWxev04vMFZ6j5/Dv+0FE2nN6+ kO7w== X-Gm-Message-State: AOJu0YwGw0Qky27GAHttOSawGq6geQJa+99wP7/OOBfpg24nmrDDrC+z L00nGZgdxIsgQjvh/7mlKpiZVmnO97BQntjkIX6kmyV0zSwgpSpe4SUTFvDrM0GsSm6RmFTgr0B RFRMQ0yvl72VbwG/XBvlGFbQCCvCKpzt3hrnxCzFVZGG44ItDiBakOnXXoeEFUWcTpww74E5L4u lknFGt4hdqKfEsWyT1hX+73a/u7bmZlKJj X-Received: by 2002:a19:434f:0:b0:513:c147:e66a with SMTP id m15-20020a19434f000000b00513c147e66amr1654656lfj.32.1710282508251; Tue, 12 Mar 2024 15:28:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+BIPJVZdOHVJ0RQIqDpf/EIIkrKAzl+iLCPO9VtEntktC4BqJ3KZ+X1Rlv73oEAOwqvj8Gw== X-Received: by 2002:a19:434f:0:b0:513:c147:e66a with SMTP id m15-20020a19434f000000b00513c147e66amr1654633lfj.32.1710282507743; Tue, 12 Mar 2024 15:28:27 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id ho14-20020a1709070e8e00b00a44d3847811sm4254673ejc.102.2024.03.12.15.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:27 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:24 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ankit Agrawal , Alex Williamson , Markus Armbruster , Jonathan Cameron , Igor Mammedov , Ani Sinha , Paolo Bonzini , Daniel =?utf-8?b?UC4gQmVycmFuZ8Op?= , Eduardo Habkost , Eric Blake Subject: [PULL 54/68] qom: new object to associate device to NUMA node Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ankit Agrawal NVIDIA GPU's support MIG (Mult-Instance GPUs) feature [1], which allows partitioning of the GPU device resources (including device memory) into several (upto 8) isolated instances. Each of the partitioned memory needs a dedicated NUMA node to operate. The partitions are not fixed and they can be created/deleted at runtime. Unfortunately Linux OS does not provide a means to dynamically create/destroy NUMA nodes and such feature implementation is not expected to be trivial. The nodes that OS discovers at the boot time while parsing SRAT remains fixed. So we utilize the Generic Initiator (GI) Affinity structures that allows association between nodes and devices. Multiple GI structures per BDF is possible, allowing creation of multiple nodes by exposing unique PXM in each of these structures. Implement the mechanism to build the GI affinity structures as Qemu currently does not. Introduce a new acpi-generic-initiator object to allow host admin link a device with an associated NUMA node. Qemu maintains this association and use this object to build the requisite GI Affinity Structure. When multiple NUMA nodes are associated with a device, it is required to create those many number of acpi-generic-initiator objects, each representing a unique device:node association. Following is one of a decoded GI affinity structure in VM ACPI SRAT. [0C8h 0200 1] Subtable Type : 05 [Generic Initiator Affinity] [0C9h 0201 1] Length : 20 [0CAh 0202 1] Reserved1 : 00 [0CBh 0203 1] Device Handle Type : 01 [0CCh 0204 4] Proximity Domain : 00000007 [0D0h 0208 16] Device Handle : 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 [0E0h 0224 4] Flags (decoded below) : 00000001 Enabled : 1 [0E4h 0228 4] Reserved2 : 00000000 [0E8h 0232 1] Subtable Type : 05 [Generic Initiator Affinity] [0E9h 0233 1] Length : 20 An admin can provide a range of acpi-generic-initiator objects, each associating a device (by providing the id through pci-dev argument) to the desired NUMA node (using the node argument). Currently, only PCI device is supported. For the grace hopper system, create a range of 8 nodes and associate that with the device using the acpi-generic-initiator object. While a configuration of less than 8 nodes per device is allowed, such configuration will prevent utilization of the feature to the fullest. The following sample creates 8 nodes per PCI device for a VM with 2 PCI devices and link them to the respecitve PCI device using acpi-generic-initiator objects: -numa node,nodeid=2 -numa node,nodeid=3 -numa node,nodeid=4 \ -numa node,nodeid=5 -numa node,nodeid=6 -numa node,nodeid=7 \ -numa node,nodeid=8 -numa node,nodeid=9 \ -device vfio-pci-nohotplug,host=0009:01:00.0,bus=pcie.0,addr=04.0,rombar=0,id=dev0 \ -object acpi-generic-initiator,id=gi0,pci-dev=dev0,node=2 \ -object acpi-generic-initiator,id=gi1,pci-dev=dev0,node=3 \ -object acpi-generic-initiator,id=gi2,pci-dev=dev0,node=4 \ -object acpi-generic-initiator,id=gi3,pci-dev=dev0,node=5 \ -object acpi-generic-initiator,id=gi4,pci-dev=dev0,node=6 \ -object acpi-generic-initiator,id=gi5,pci-dev=dev0,node=7 \ -object acpi-generic-initiator,id=gi6,pci-dev=dev0,node=8 \ -object acpi-generic-initiator,id=gi7,pci-dev=dev0,node=9 \ -numa node,nodeid=10 -numa node,nodeid=11 -numa node,nodeid=12 \ -numa node,nodeid=13 -numa node,nodeid=14 -numa node,nodeid=15 \ -numa node,nodeid=16 -numa node,nodeid=17 \ -device vfio-pci-nohotplug,host=0009:01:01.0,bus=pcie.0,addr=05.0,rombar=0,id=dev1 \ -object acpi-generic-initiator,id=gi8,pci-dev=dev1,node=10 \ -object acpi-generic-initiator,id=gi9,pci-dev=dev1,node=11 \ -object acpi-generic-initiator,id=gi10,pci-dev=dev1,node=12 \ -object acpi-generic-initiator,id=gi11,pci-dev=dev1,node=13 \ -object acpi-generic-initiator,id=gi12,pci-dev=dev1,node=14 \ -object acpi-generic-initiator,id=gi13,pci-dev=dev1,node=15 \ -object acpi-generic-initiator,id=gi14,pci-dev=dev1,node=16 \ -object acpi-generic-initiator,id=gi15,pci-dev=dev1,node=17 \ Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu [1] Cc: Jonathan Cameron Cc: Alex Williamson Cc: Markus Armbruster Reviewed-by: Jonathan Cameron Acked-by: Markus Armbruster Signed-off-by: Ankit Agrawal Message-Id: <20240308145525.10886-2-ankita@nvidia.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- qapi/qom.json | 17 ++++++ include/hw/acpi/acpi_generic_initiator.h | 22 ++++++++ hw/acpi/acpi_generic_initiator.c | 71 ++++++++++++++++++++++++ hw/acpi/meson.build | 1 + 4 files changed, 111 insertions(+) create mode 100644 include/hw/acpi/acpi_generic_initiator.h create mode 100644 hw/acpi/acpi_generic_initiator.c diff --git a/qapi/qom.json b/qapi/qom.json index 032c6fa037..baae3a183f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -811,6 +811,21 @@ { 'struct': 'IOMMUFDProperties', 'data': { '*fd': 'str' } } +## +# @AcpiGenericInitiatorProperties: +# +# Properties for acpi-generic-initiator objects. +# +# @pci-dev: PCI device ID to be associated with the node +# +# @node: NUMA node associated with the PCI device +# +# Since: 9.0 +## +{ 'struct': 'AcpiGenericInitiatorProperties', + 'data': { 'pci-dev': 'str', + 'node': 'uint32' } } + ## # @RngProperties: # @@ -928,6 +943,7 @@ ## { 'enum': 'ObjectType', 'data': [ + 'acpi-generic-initiator', 'authz-list', 'authz-listfile', 'authz-pam', @@ -999,6 +1015,7 @@ 'id': 'str' }, 'discriminator': 'qom-type', 'data': { + 'acpi-generic-initiator': 'AcpiGenericInitiatorProperties', 'authz-list': 'AuthZListProperties', 'authz-listfile': 'AuthZListFileProperties', 'authz-pam': 'AuthZPAMProperties', diff --git a/include/hw/acpi/acpi_generic_initiator.h b/include/hw/acpi/acpi_generic_initiator.h new file mode 100644 index 0000000000..16de1d3d80 --- /dev/null +++ b/include/hw/acpi/acpi_generic_initiator.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved + */ + +#ifndef ACPI_GENERIC_INITIATOR_H +#define ACPI_GENERIC_INITIATOR_H + +#include "qom/object_interfaces.h" + +#define TYPE_ACPI_GENERIC_INITIATOR "acpi-generic-initiator" + +typedef struct AcpiGenericInitiator { + /* private */ + Object parent; + + /* public */ + char *pci_dev; + uint16_t node; +} AcpiGenericInitiator; + +#endif diff --git a/hw/acpi/acpi_generic_initiator.c b/hw/acpi/acpi_generic_initiator.c new file mode 100644 index 0000000000..130d6ae8c1 --- /dev/null +++ b/hw/acpi/acpi_generic_initiator.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved + */ + +#include "qemu/osdep.h" +#include "hw/acpi/acpi_generic_initiator.h" +#include "hw/boards.h" +#include "qemu/error-report.h" + +typedef struct AcpiGenericInitiatorClass { + ObjectClass parent_class; +} AcpiGenericInitiatorClass; + +OBJECT_DEFINE_TYPE_WITH_INTERFACES(AcpiGenericInitiator, acpi_generic_initiator, + ACPI_GENERIC_INITIATOR, OBJECT, + { TYPE_USER_CREATABLE }, + { NULL }) + +OBJECT_DECLARE_SIMPLE_TYPE(AcpiGenericInitiator, ACPI_GENERIC_INITIATOR) + +static void acpi_generic_initiator_init(Object *obj) +{ + AcpiGenericInitiator *gi = ACPI_GENERIC_INITIATOR(obj); + + gi->node = MAX_NODES; + gi->pci_dev = NULL; +} + +static void acpi_generic_initiator_finalize(Object *obj) +{ + AcpiGenericInitiator *gi = ACPI_GENERIC_INITIATOR(obj); + + g_free(gi->pci_dev); +} + +static void acpi_generic_initiator_set_pci_device(Object *obj, const char *val, + Error **errp) +{ + AcpiGenericInitiator *gi = ACPI_GENERIC_INITIATOR(obj); + + gi->pci_dev = g_strdup(val); +} + +static void acpi_generic_initiator_set_node(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + AcpiGenericInitiator *gi = ACPI_GENERIC_INITIATOR(obj); + uint32_t value; + + if (!visit_type_uint32(v, name, &value, errp)) { + return; + } + + if (value >= MAX_NODES) { + error_printf("%s: Invalid NUMA node specified\n", + TYPE_ACPI_GENERIC_INITIATOR); + exit(1); + } + + gi->node = value; +} + +static void acpi_generic_initiator_class_init(ObjectClass *oc, void *data) +{ + object_class_property_add_str(oc, "pci-dev", NULL, + acpi_generic_initiator_set_pci_device); + object_class_property_add(oc, "node", "int", NULL, + acpi_generic_initiator_set_node, NULL, NULL); +} diff --git a/hw/acpi/meson.build b/hw/acpi/meson.build index 5441c9b1e4..fa5c07db90 100644 --- a/hw/acpi/meson.build +++ b/hw/acpi/meson.build @@ -1,5 +1,6 @@ acpi_ss = ss.source_set() acpi_ss.add(files( + 'acpi_generic_initiator.c', 'acpi_interface.c', 'aml-build.c', 'bios-linker-loader.c', From patchwork Tue Mar 12 22:28:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EuKZsuIx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT9r16SXz1yWt for ; Wed, 13 Mar 2024 09:40:16 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdI-0005V9-Ge; Tue, 12 Mar 2024 18:30:04 -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 1rkAbx-0002oT-Dh for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:41 -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 1rkAbs-0004aC-Eb for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282515; 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=f5mdyjCEbyffW9T7OKjJbIrqSM8blOZkF1pxw/tMTzk=; b=EuKZsuIxB8hzA8rWqvIyMbr1v1FezI9d+C+wQ1o/OT16G/Oz729oK8eqWzZsupVnuBK370 JZqbyx43TF6HaDx50jEI6B+50mPHuOGXxxMzA5HOwSftkW1Xg4bG6hdxslsTWl0DL3oqja ZOKJ2g4Q0oTs4hiQseKPnIRyPxmgdto= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-dzFvI5WaNimTuQBZrZgY7Q-1; Tue, 12 Mar 2024 18:28:34 -0400 X-MC-Unique: dzFvI5WaNimTuQBZrZgY7Q-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d44551e1ccso2831621fa.3 for ; Tue, 12 Mar 2024 15:28:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282513; x=1710887313; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f5mdyjCEbyffW9T7OKjJbIrqSM8blOZkF1pxw/tMTzk=; b=KnE9MJ9TwDW3mmPdpc8oiOOUWcR7uFBaL0cvs80+B2oraUyoD+Y0taqzdT1QT8X2bw soD5DFnStLHMrwazPKFWF5CSd5GMD3eur/+VIcL5XGOWcbJy4Op219e+S7lMWzSKS303 mmx2Ulm7rKMiY8YYbMj8gF3pZxS7OMY8h8bMiZdbT4tvRipF8j4JgBouR013VG5jtVBU PWb870jRJNmviiELAViBa4A/y+FD+9Mak1E9EL5kHTBXGGuC3sLf63HUyyttsohtBVmr 1gR+s6P885VhbHzQJYVHKWsQ5elABUef9ZzB4adzw3UWcNeZxlmIV6AtBwiroXLBPhmA HJkQ== X-Gm-Message-State: AOJu0YyeIt7HUthS6zu2qQEbSEezFZ2HMssgMlGu5qB+OkIOiH6ZaX7d Ly3wyYHvaxw9KTvVeBajNz2DppUQJgP/jjE5na2VW8rvc/cV22Ca31v7F8kzCyO75U6n1m3zxJ6 EygiGLcuyqdISkt30LAd3gcRxsonH2JcG8VOcjtlUNPTc/ZnoCu8IDsGlar7p4gk5bP71OTvNLz TVJxW2vNatIKzpcGCB//NzL113ZdR+uGqZ X-Received: by 2002:a2e:bc1f:0:b0:2d4:1d45:d5e2 with SMTP id b31-20020a2ebc1f000000b002d41d45d5e2mr4317076ljf.10.1710282512546; Tue, 12 Mar 2024 15:28:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUnmOqgm4Tgu6e+odGAVI2IUdSFoEFX6iS0Efekr73qNPWVUuTYS4wNi0FN6UafvMtCjoPhA== X-Received: by 2002:a2e:bc1f:0:b0:2d4:1d45:d5e2 with SMTP id b31-20020a2ebc1f000000b002d41d45d5e2mr4317051ljf.10.1710282511986; Tue, 12 Mar 2024 15:28:31 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id jw22-20020a170906e95600b00a4623030893sm2658289ejb.126.2024.03.12.15.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:31 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:27 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ankit Agrawal , Alex Williamson , Cedric Le Goater , Jonathan Cameron , Igor Mammedov , Ani Sinha , Shannon Zhao , Eduardo Habkost , Marcel Apfelbaum , Philippe =?utf-8?q?Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , qemu-arm@nongnu.org Subject: [PULL 55/68] hw/acpi: Implement the SRAT GI affinity structure Message-ID: <0a5b5acdf2d8c7302ca48d42e6ef3423e1b956d5.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ankit Agrawal ACPI spec provides a scheme to associate "Generic Initiators" [1] (e.g. heterogeneous processors and accelerators, GPUs, and I/O devices with integrated compute or DMA engines GPUs) with Proximity Domains. This is achieved using Generic Initiator Affinity Structure in SRAT. During bootup, Linux kernel parse the ACPI SRAT to determine the PXM ids and create a NUMA node for each unique PXM ID encountered. Qemu currently do not implement these structures while building SRAT. Add GI structures while building VM ACPI SRAT. The association between device and node are stored using acpi-generic-initiator object. Lookup presence of all such objects and use them to build these structures. The structure needs a PCI device handle [2] that consists of the device BDF. The vfio-pci device corresponding to the acpi-generic-initiator object is located to determine the BDF. [1] ACPI Spec 6.3, Section 5.2.16.6 [2] ACPI Spec 6.3, Table 5.80 Cc: Jonathan Cameron Cc: Alex Williamson Cc: Cedric Le Goater Reviewed-by: Jonathan Cameron Signed-off-by: Ankit Agrawal Message-Id: <20240308145525.10886-3-ankita@nvidia.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/acpi_generic_initiator.h | 25 ++++++++ include/sysemu/numa.h | 1 + hw/acpi/acpi_generic_initiator.c | 77 ++++++++++++++++++++++++ hw/acpi/hmat.c | 2 +- hw/arm/virt-acpi-build.c | 3 + hw/core/numa.c | 3 +- 6 files changed, 109 insertions(+), 2 deletions(-) diff --git a/include/hw/acpi/acpi_generic_initiator.h b/include/hw/acpi/acpi_generic_initiator.h index 16de1d3d80..a304bad73e 100644 --- a/include/hw/acpi/acpi_generic_initiator.h +++ b/include/hw/acpi/acpi_generic_initiator.h @@ -19,4 +19,29 @@ typedef struct AcpiGenericInitiator { uint16_t node; } AcpiGenericInitiator; +/* + * ACPI 6.3: + * Table 5-81 Flags – Generic Initiator Affinity Structure + */ +typedef enum { + /* + * If clear, the OSPM ignores the contents of the Generic + * Initiator/Port Affinity Structure. This allows system firmware + * to populate the SRAT with a static number of structures, but only + * enable them as necessary. + */ + GEN_AFFINITY_ENABLED = (1 << 0), +} GenericAffinityFlags; + +/* + * ACPI 6.3: + * Table 5-80 Device Handle - PCI + */ +typedef struct PCIDeviceHandle { + uint16_t segment; + uint16_t bdf; +} PCIDeviceHandle; + +void build_srat_generic_pci_initiator(GArray *table_data); + #endif diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index 4173ef2afa..825cfe86bc 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -41,6 +41,7 @@ struct NodeInfo { struct HostMemoryBackend *node_memdev; bool present; bool has_cpu; + bool has_gi; uint8_t lb_info_provided; uint16_t initiator; uint8_t distance[MAX_NODES]; diff --git a/hw/acpi/acpi_generic_initiator.c b/hw/acpi/acpi_generic_initiator.c index 130d6ae8c1..17b9a052f5 100644 --- a/hw/acpi/acpi_generic_initiator.c +++ b/hw/acpi/acpi_generic_initiator.c @@ -5,7 +5,9 @@ #include "qemu/osdep.h" #include "hw/acpi/acpi_generic_initiator.h" +#include "hw/acpi/aml-build.h" #include "hw/boards.h" +#include "hw/pci/pci_device.h" #include "qemu/error-report.h" typedef struct AcpiGenericInitiatorClass { @@ -47,6 +49,7 @@ static void acpi_generic_initiator_set_node(Object *obj, Visitor *v, Error **errp) { AcpiGenericInitiator *gi = ACPI_GENERIC_INITIATOR(obj); + MachineState *ms = MACHINE(qdev_get_machine()); uint32_t value; if (!visit_type_uint32(v, name, &value, errp)) { @@ -60,6 +63,7 @@ static void acpi_generic_initiator_set_node(Object *obj, Visitor *v, } gi->node = value; + ms->numa_state->nodes[gi->node].has_gi = true; } static void acpi_generic_initiator_class_init(ObjectClass *oc, void *data) @@ -69,3 +73,76 @@ static void acpi_generic_initiator_class_init(ObjectClass *oc, void *data) object_class_property_add(oc, "node", "int", NULL, acpi_generic_initiator_set_node, NULL, NULL); } + +/* + * ACPI 6.3: + * Table 5-78 Generic Initiator Affinity Structure + */ +static void +build_srat_generic_pci_initiator_affinity(GArray *table_data, int node, + PCIDeviceHandle *handle) +{ + uint8_t index; + + build_append_int_noprefix(table_data, 5, 1); /* Type */ + build_append_int_noprefix(table_data, 32, 1); /* Length */ + build_append_int_noprefix(table_data, 0, 1); /* Reserved */ + build_append_int_noprefix(table_data, 1, 1); /* Device Handle Type: PCI */ + build_append_int_noprefix(table_data, node, 4); /* Proximity Domain */ + + /* Device Handle - PCI */ + build_append_int_noprefix(table_data, handle->segment, 2); + build_append_int_noprefix(table_data, handle->bdf, 2); + for (index = 0; index < 12; index++) { + build_append_int_noprefix(table_data, 0, 1); + } + + build_append_int_noprefix(table_data, GEN_AFFINITY_ENABLED, 4); /* Flags */ + build_append_int_noprefix(table_data, 0, 4); /* Reserved */ +} + +static int build_all_acpi_generic_initiators(Object *obj, void *opaque) +{ + MachineState *ms = MACHINE(qdev_get_machine()); + AcpiGenericInitiator *gi; + GArray *table_data = opaque; + PCIDeviceHandle dev_handle; + PCIDevice *pci_dev; + Object *o; + + if (!object_dynamic_cast(obj, TYPE_ACPI_GENERIC_INITIATOR)) { + return 0; + } + + gi = ACPI_GENERIC_INITIATOR(obj); + if (gi->node >= ms->numa_state->num_nodes) { + error_printf("%s: Specified node %d is invalid.\n", + TYPE_ACPI_GENERIC_INITIATOR, gi->node); + exit(1); + } + + o = object_resolve_path_type(gi->pci_dev, TYPE_PCI_DEVICE, NULL); + if (!o) { + error_printf("%s: Specified device must be a PCI device.\n", + TYPE_ACPI_GENERIC_INITIATOR); + exit(1); + } + + pci_dev = PCI_DEVICE(o); + + dev_handle.segment = 0; + dev_handle.bdf = PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_dev)), + pci_dev->devfn); + + build_srat_generic_pci_initiator_affinity(table_data, + gi->node, &dev_handle); + + return 0; +} + +void build_srat_generic_pci_initiator(GArray *table_data) +{ + object_child_foreach_recursive(object_get_root(), + build_all_acpi_generic_initiators, + table_data); +} diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 3042d223c8..2242981e18 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -214,7 +214,7 @@ static void hmat_build_table_structs(GArray *table_data, NumaState *numa_state) } for (i = 0; i < numa_state->num_nodes; i++) { - if (numa_state->nodes[i].has_cpu) { + if (numa_state->nodes[i].has_cpu || numa_state->nodes[i].has_gi) { initiator_list[num_initiator++] = i; } } diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 6a1bde61ce..c3ccfef026 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -57,6 +57,7 @@ #include "migration/vmstate.h" #include "hw/acpi/ghes.h" #include "hw/acpi/viot.h" +#include "hw/acpi/acpi_generic_initiator.h" #include "hw/virtio/virtio-acpi.h" #include "target/arm/multiprocessing.h" @@ -504,6 +505,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) } } + build_srat_generic_pci_initiator(table_data); + if (ms->nvdimms_state->is_enabled) { nvdimm_build_srat(table_data); } diff --git a/hw/core/numa.c b/hw/core/numa.c index f08956ddb0..58a32f1564 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -229,7 +229,8 @@ void parse_numa_hmat_lb(NumaState *numa_state, NumaHmatLBOptions *node, node->target, numa_state->num_nodes); return; } - if (!numa_info[node->initiator].has_cpu) { + if (!numa_info[node->initiator].has_cpu && + !numa_info[node->initiator].has_gi) { error_setg(errp, "Invalid initiator=%d, it isn't an " "initiator proximity domain", node->initiator); return; From patchwork Tue Mar 12 22:28:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ILHs0oc0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT2l0KtSz1ydl for ; Wed, 13 Mar 2024 09:34:07 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdB-0004xH-BG; Tue, 12 Mar 2024 18:29:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAc6-0002pk-J8 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:52 -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 1rkAbw-0004ai-D7 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282519; 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: in-reply-to:in-reply-to:references:references; bh=7lDoWlZCcLIPjIofqG1lsxz2N/rHF6vbYam4xDSG+ms=; b=ILHs0oc0mWI2IuW0l8sBZ2ZRbIXY/IEJ+UyWd0eyLPHvg+ktwnzc/rICneYJZbTA4pJt85 MXSHB08sYifmp0azv/+O7tlmgtNjjDWrtR/Y+UOD8JuHVAdIuSaeheT3JiacumnwIvniC9 kPFwgIMa41sA1ofl8W2+u/VkFqOmE9c= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-vc8x0h2pMVSBFhPNMFg5SA-1; Tue, 12 Mar 2024 18:28:38 -0400 X-MC-Unique: vc8x0h2pMVSBFhPNMFg5SA-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-513b3ca9650so1713532e87.2 for ; Tue, 12 Mar 2024 15:28:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282517; x=1710887317; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7lDoWlZCcLIPjIofqG1lsxz2N/rHF6vbYam4xDSG+ms=; b=nPMyqQF4i3ANFBlyvZPyMJcqa38+jjTpVlN1ps2KdGT65QXcr3Dq7beGJ2s0SsyxW+ QwCMPLTcDx6kG0RxIHSuV5ELxkd1TyVT+2HfTLRB1VMKnKt/knW9nUpeOiHKocXQmhcH rAxHPUNpuhwuZ6ZyDyq3zFXF4ymxpY53Xr5tcngg+6vwyzF8y7sBaAAIJZd0/1+JKBSq wJQXjaM1rooM8VSU6Xlh0g8ANjrPaeqMURySvwuNOYMofEJiGgXyz9QA0Wcr04LdQGSv kpcbwprNA3+0IHqoIPSDhoau6aU08/ezOSPqWbAoKPJj4WDHIGxTfLrLiULsEQkfJiCO +/lQ== X-Gm-Message-State: AOJu0YwiGmGGMsXq7zWkt4389M/q/wvY97qNaBmXD5mkQUCApEhi0be5 fFzTajEwOuGADZg4u3FSdMFo+4cDCPK8iJ9HMHCrrp1UeTI4u1ITwjP7TwUzlmr/zKbAG2qrStr axRa6s4WdyoNZ6P0rfqE5RQ36D5qclrHO56RKLIyaiHnaYemLMgGSqNzkdmuY+ctSmVVBWasykk o6DlqGu+UIqyEffYmknTi21mkT0pigtQ14 X-Received: by 2002:a05:6512:3c86:b0:513:b18a:f207 with SMTP id h6-20020a0565123c8600b00513b18af207mr5102661lfv.51.1710282516754; Tue, 12 Mar 2024 15:28:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjJRCeEnD+IZCxNVFAo1p3/DyYoT1Hgicy9EADwv7IZaBtOi/HinFFX6woqkaBzOjFH66H8g== X-Received: by 2002:a05:6512:3c86:b0:513:b18a:f207 with SMTP id h6-20020a0565123c8600b00513b18af207mr5102644lfv.51.1710282516241; Tue, 12 Mar 2024 15:28:36 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id l26-20020a1709061c5a00b00a463d1d017esm1203169ejg.1.2024.03.12.15.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:35 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:32 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ankit Agrawal , Jonathan Cameron , Igor Mammedov , Ani Sinha , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 56/68] hw/i386/acpi-build: Add support for SRAT Generic Initiator structures Message-ID: <5deced6a13de9409fd9114432b25072189a68942.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ankit Agrawal The acpi-generic-initiator object is added to allow a host device to be linked with a NUMA node. Qemu use it to build the SRAT Generic Initiator Affinity structure [1]. Add support for i386. [1] ACPI Spec 6.3, Section 5.2.16.6 Suggested-by: Jonathan Cameron Signed-off-by: Ankit Agrawal Message-Id: <20240308145525.10886-4-ankita@nvidia.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Jonathan Cameron --- hw/i386/acpi-build.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 15242b9096..53f804ac16 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -68,6 +68,7 @@ #include "hw/acpi/utils.h" #include "hw/acpi/pci.h" #include "hw/acpi/cxl.h" +#include "hw/acpi/acpi_generic_initiator.h" #include "qom/qom-qobject.h" #include "hw/i386/amd_iommu.h" @@ -2046,6 +2047,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) build_srat_memory(table_data, 0, 0, 0, MEM_AFFINITY_NOFLAGS); } + build_srat_generic_pci_initiator(table_data); + /* * Entry is required for Windows to enable memory hotplug in OS * and for Linux to enable SWIOTLB when booted with less than From patchwork Tue Mar 12 22:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bW61fXtJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT6y50zWz1yWy for ; Wed, 13 Mar 2024 09:37:46 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdO-00062v-Dk; Tue, 12 Mar 2024 18:30:12 -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 1rkAc6-0002pt-Tq for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28: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 1rkAbz-0004b4-Px for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282522; 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=uqNCLYNUFKo35EsbQeEwK2046y6pYoTM2WTmQ8XGtVc=; b=bW61fXtJUwJ3TPMd1wE/r5o2/CCdKLz5SvOC/DXFJD0I7Y3I0/aT2eay6xpY3XmIAU+VeX DBC/OLNyWRkHoEi9hshfQWSWwxq5lSZ0CbjJfPDC/eEiK/jrYLVlavb3LwL7UPtUvDIwJ1 Lj/emQH6MVkk48e9R9V7NT86z9K/SeQ= 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-80-dejjTPj8PBipPYfHgC-W2Q-1; Tue, 12 Mar 2024 18:28:41 -0400 X-MC-Unique: dejjTPj8PBipPYfHgC-W2Q-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a448cfe2266so494065866b.2 for ; Tue, 12 Mar 2024 15:28:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282520; x=1710887320; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uqNCLYNUFKo35EsbQeEwK2046y6pYoTM2WTmQ8XGtVc=; b=u7J9UqDd2MZQ5SgPn+JpC0lmQ0DYhmDWSzB7x3mwH4nkPucmMdygorIQa/pST8+slt T3gB8h/ebEcsQZQR0QuauEjZmUiUiI1ijeUnMWqVsYtPQzEatyvteCqj3Lq+JrM2R2w6 O+bu0DzABT1yCo8q/jo8yiuSIMPC8k0h3TdaB8WuVz8C82qrD7/rp1KiWCG97SHpCfER N6R6n6C9vJG16YbHc9/P/x0/B5vPhh92rGWHFS1vETRxUKRnDhxJRBm02xX+S2Y8sIAv zHSdXlEWtrmmiuiAspEzZkXLE+2Kl+Ha5k18zpV9QmcrhPsXExftXqyMXRT1TXzghIyp CX+A== X-Gm-Message-State: AOJu0YwmOvLP8Dph7uUsOjZXDn9kxVdnGlcr9Kzh4OA1ZFOCJwMyIEJv KnCanPfuJPhff8VSJTj4mp+4PttXtVa2u69TVRZ/Hp64aXBcNtjiRdkuMlPFyunda7UGXTjZ5cd 0b604wIa/2PtkDkVcpAtGB5mtjyiAnnvcopZokor7uX0NtRSMJ1H1CpsdGtEkWB4vuWAnLu9oHK PmK5Vg6gtMZFaWkBh5tW0HCWLmpEVB89xD X-Received: by 2002:a17:907:a0ce:b0:a45:ed7f:265c with SMTP id hw14-20020a170907a0ce00b00a45ed7f265cmr9062359ejc.0.1710282519585; Tue, 12 Mar 2024 15:28:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/S/BqBM2V7Jrt2QdHmO7PZKEbCOG4ZawwTRy9y4f2ruoDpWpdeaAnfaxeyxperd+aZE7hBA== X-Received: by 2002:a17:907:a0ce:b0:a45:ed7f:265c with SMTP id hw14-20020a170907a0ce00b00a45ed7f265cmr9062346ejc.0.1710282519093; Tue, 12 Mar 2024 15:28:39 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id h16-20020a1709067cd000b00a45f63d2959sm4221145ejp.210.2024.03.12.15.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:38 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:36 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Zhenzhong Duan Subject: [PULL 57/68] virtio-iommu: Add a granule property Message-ID: <294ac5fef3aa78111de07357734285744103f47c.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger This allows to choose which granule will be used by default by the virtio-iommu. Current page size mask default is qemu_target_page_mask so this translates into a 4k granule on ARM and x86_64 where virtio-iommu is supported. Signed-off-by: Eric Auger Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Zhenzhong Duan Message-Id: <20240307134445.92296-3-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-iommu.h | 2 ++ hw/virtio/virtio-iommu.c | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index 781ebaea8f..67ea5022af 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -24,6 +24,7 @@ #include "hw/virtio/virtio.h" #include "hw/pci/pci.h" #include "qom/object.h" +#include "qapi/qapi-types-virtio.h" #define TYPE_VIRTIO_IOMMU "virtio-iommu-device" #define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci" @@ -66,6 +67,7 @@ struct VirtIOIOMMU { bool boot_bypass; Notifier machine_done; bool granule_frozen; + GranuleMode granule_mode; }; #endif diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 86623d55a5..84d6819d3b 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -29,6 +29,7 @@ #include "sysemu/reset.h" #include "sysemu/sysemu.h" #include "qemu/reserved-region.h" +#include "qemu/units.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "trace.h" @@ -1115,8 +1116,8 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, } /* - * The default mask (TARGET_PAGE_MASK) is the smallest supported guest granule, - * for example 0xfffffffffffff000. When an assigned device has page size + * The default mask depends on the "granule" property. For example, with + * 4k granule, it is -(4 * KiB). When an assigned device has page size * restrictions due to the hardware IOMMU configuration, apply this restriction * to the mask. */ @@ -1313,8 +1314,27 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) * in vfio realize */ s->config.bypass = s->boot_bypass; - s->config.page_size_mask = qemu_target_page_mask(); s->config.input_range.end = UINT64_MAX; + + switch (s->granule_mode) { + case GRANULE_MODE_4K: + s->config.page_size_mask = -(4 * KiB); + break; + case GRANULE_MODE_8K: + s->config.page_size_mask = -(8 * KiB); + break; + case GRANULE_MODE_16K: + s->config.page_size_mask = -(16 * KiB); + break; + case GRANULE_MODE_64K: + s->config.page_size_mask = -(64 * KiB); + break; + case GRANULE_MODE_HOST: + s->config.page_size_mask = qemu_real_host_page_mask(); + break; + default: + error_setg(errp, "Unsupported granule mode"); + } s->config.domain_range.end = UINT32_MAX; s->config.probe_size = VIOMMU_PROBE_SIZE; @@ -1522,6 +1542,8 @@ static Property virtio_iommu_properties[] = { DEFINE_PROP_LINK("primary-bus", VirtIOIOMMU, primary_bus, TYPE_PCI_BUS, PCIBus *), DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), + DEFINE_PROP_GRANULE_MODE("granule", VirtIOIOMMU, granule_mode, + GRANULE_MODE_4K), DEFINE_PROP_END_OF_LIST(), }; From patchwork Tue Mar 12 22:28:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ES5cmuHf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT5y4ZB9z1yWy for ; Wed, 13 Mar 2024 09:36:54 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAe7-0006OK-Ri; Tue, 12 Mar 2024 18:30: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 1rkAcC-0002qv-Ji for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:58 -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 1rkAc2-0004bN-9l for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282525; 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=eKrjNhHTN2bPQP/9cRYriG9FH7mBRIe1f63zB2PVbVw=; b=ES5cmuHfO73k3iFI8yPrTMLcY/4OoS0NoxuCUnzzNUr2A/TcdV3cU3x6XCsSTqMbfPBvEU o89iSH14TCf5VCdaA4vX68zu0Twnfu35RBz78WpnDvxLDWFGChBHZFJzukJeQMaC5cabuG forRJxAk0RJ/igyu1W2BHW7E58tG5FQ= 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-672-gCok1JwIMdS2QJvfDSsfpQ-1; Tue, 12 Mar 2024 18:28:44 -0400 X-MC-Unique: gCok1JwIMdS2QJvfDSsfpQ-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-558aafe9bf2so4144768a12.1 for ; Tue, 12 Mar 2024 15:28:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282523; x=1710887323; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eKrjNhHTN2bPQP/9cRYriG9FH7mBRIe1f63zB2PVbVw=; b=N23n0FrTGjt/JjIuij4rere5Q+1IdpdSXPdVgwx892F+XCjb+rWmhACYBAzv8T0Hq+ ZHdsQ8v9nMRIotwHLhn6Y8hvTgp8yktKegym6MAbgdU4P8tlMA5dHsBQo5nVxIXxo6eH BmhapBZsYbRPXr+rWCQn+wk5Pkp5kdb6pCerkhhI3L7jIuLM5jIeh9idhX4KYTdHUd/s Sh1fspns5s+Ptf+fn5wAEfdSHlxEJX7qUVXEe1i6JXMsrq4Ds00XW++K5yIvYOnoZhGg 8zou2aem1E60VzWO2JeQasMl+meznlW3sdumgrW80YvGfPSAXhVqA+cQPDa4f0v8GQtI +fgQ== X-Gm-Message-State: AOJu0Yy6SS7hRlHcB5xvr8HTDYO1zDri8DqP4xHWKmUzbLXGK2ih/jY3 AgOzfat4okGa9TXb5LH/wnrVTEvSpawtlq15PnMLk8QolY5/s4lMA6loNsKjMwNCyWEyttnBXyW UIGL6nhmJWiv9VF6bSUN159mTwrYDlpeeR4QzahJGdEKVv/TVjSdCS2zcfq/erT/kL8uVdCUAVC xwpEpJzihkUEyzk/AK5h0uNR+RLQTEO1On X-Received: by 2002:a50:ab48:0:b0:566:825b:98 with SMTP id t8-20020a50ab48000000b00566825b0098mr1245567edc.6.1710282522958; Tue, 12 Mar 2024 15:28:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHsKh62kUegGSPD66dBTmSIcnTJFZISZxwV9K1n6JmG5gn76XpggUKe4TMUIWl1pS9MDTy3w== X-Received: by 2002:a50:ab48:0:b0:566:825b:98 with SMTP id t8-20020a50ab48000000b00566825b0098mr1245547edc.6.1710282522417; Tue, 12 Mar 2024 15:28:42 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id cn19-20020a0564020cb300b0056828004c75sm4397850edb.51.2024.03.12.15.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:41 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:39 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Zhenzhong Duan , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang Subject: [PULL 58/68] virtio-iommu: Change the default granule to the host page size Message-ID: <9dd5e808fc17ac92180965178a6e867c1e96ac57.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger We used to set the default granule to 4KB but with VFIO assignment it makes more sense to use the actual host page size. Indeed when hotplugging a VFIO device protected by a virtio-iommu on a 64kB/64kB host/guest config, we current get a qemu crash: "vfio: DMA mapping failed, unable to continue" This is due to the hot-attached VFIO device calling memory_region_iommu_set_page_size_mask() with 64kB granule whereas the virtio-iommu granule was already frozen to 4KB on machine init done. Set the granule property to "host" and introduce a new compat. The page size mask used before 9.0 was qemu_target_page_mask(). Since the virtio-iommu currently only supports x86_64 and aarch64, this matched a 4KB granule. Note that the new default will prevent 4kB guest on 64kB host because the granule will be set to 64kB which would be larger than the guest page size. In that situation, the virtio-iommu driver fails on viommu_domain_finalise() with "granule 0x10000 larger than system page size 0x1000". In that case the workaround is to request 4K granule. The current limitation of global granule in the virtio-iommu should be removed and turned into per domain granule. But until we get this upgraded, this new default is probably better because I don't think anyone is currently interested in running a 4KB page size guest with virtio-iommu on a 64KB host. However supporting 64kB guest on 64kB host with virtio-iommu and VFIO looks a more important feature. Signed-off-by: Eric Auger Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Zhenzhong Duan Message-Id: <20240307134445.92296-4-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/core/machine.c | 5 ++++- hw/virtio/virtio-iommu.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 9ac5d5389a..6bd09d4592 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -30,9 +30,12 @@ #include "exec/confidential-guest-support.h" #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + { TYPE_VIRTIO_IOMMU_PCI, "granule", "4k" }, +}; const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2); GlobalProperty hw_compat_8_1[] = { diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 84d6819d3b..aab97e1527 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1543,7 +1543,7 @@ static Property virtio_iommu_properties[] = { TYPE_PCI_BUS, PCIBus *), DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), DEFINE_PROP_GRANULE_MODE("granule", VirtIOIOMMU, granule_mode, - GRANULE_MODE_4K), + GRANULE_MODE_HOST), DEFINE_PROP_END_OF_LIST(), }; From patchwork Tue Mar 12 22:28:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PSirbAlG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTC84D81z1yWt for ; Wed, 13 Mar 2024 09:41:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAeG-0006Ul-EV; Tue, 12 Mar 2024 18:31:04 -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 1rkAcG-0002rc-Pg for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:02 -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 1rkAc6-0004bn-Gf for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282529; 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=q+KmS4ZjhMpglK5yf3m23Viq3SpbBkSkvKu7CqYvcy0=; b=PSirbAlGDkovQUQDNlLEzJPL6q+oUzOcEizgccJXzZTT1prjg7fImExjl53EO8oIEPJpqy FMwulPDQCniEv8dJumBM+2wSZJc0I4LGWCSoke4Z4FLk3GWXAr4bIoTjjJ40UjtGh/e+Pt Esy4wBccP0htKRtEjt1+jrUBy/lmqwQ= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-Dr4quDAbOkC9A4Ca48DfrQ-1; Tue, 12 Mar 2024 18:28:47 -0400 X-MC-Unique: Dr4quDAbOkC9A4Ca48DfrQ-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-513332823cfso6021450e87.3 for ; Tue, 12 Mar 2024 15:28:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282526; x=1710887326; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=q+KmS4ZjhMpglK5yf3m23Viq3SpbBkSkvKu7CqYvcy0=; b=Nm4Yte1qCcLZ9jujALwaQVq9berGs1edpur1fgIvapk+b8Xky7VOIKYaTkoR//dEp+ xZAMqrNXBiKti/wwB/qDn9hNIn7glmPqbf9TtZcGluhhWtCgPv0ohOT89TnYg6rCpmso +DA379YzHB95fbbJ3MvKd7hHg69HMTlza+ED8hQ+bPcbTQF+r2hT1sOImgmn71r7Dz/V Qv+Dehh+4x4S2X55QJ82PcoatZDYNyvfTj9ox1s29v5tPNNnIulPSHKVIxGBTdeDj3vc 3TGGVvmGvB9Z3HSb63r0dUOTWhvdce/SCumShdVMIHaabFNhbzmj4NBtSfMyOANs6a+x F3RQ== X-Gm-Message-State: AOJu0YzXseb+K9hTfG5gBxBfLAUCbwn0ZhBskUGwkYfL+po0l7zD3occ 8BnDsxENoxsy2VzNOUeILuK4FvXU9paBAPILH5Nb96Kd2fokrfTlB01Ge65bd0YUPk4SNEuyThZ bACGdy4IJ2YahXitrvRMOnPNgQ8qk1Cz8LAnqSV4aVuj8DbCkuolPAUsFM9IWvFovfEC+LSfl8e NonaTbxEdKUnyk5B6f1xHcEJu85TsQmm9P X-Received: by 2002:a19:f706:0:b0:513:9e39:e8b7 with SMTP id z6-20020a19f706000000b005139e39e8b7mr2232214lfe.16.1710282525913; Tue, 12 Mar 2024 15:28:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEo3qlAKiLGgeTkL9KtX7dBkt5NvQ6u03phXTDQ8n4klSi8/G06Mw7YCVgp5Fpf9JdaR+4MKg== X-Received: by 2002:a19:f706:0:b0:513:9e39:e8b7 with SMTP id z6-20020a19f706000000b005139e39e8b7mr2232195lfe.16.1710282525378; Tue, 12 Mar 2024 15:28:45 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id p26-20020a170906b21a00b00a4655a71a27sm73803ejz.163.2024.03.12.15.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:45 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:42 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Thomas Huth , Michael Tokarev , Markus Armbruster Subject: [PULL 59/68] qemu-options.hx: Document the virtio-iommu-pci granule option Message-ID: <695012903f99d42c03a5bc87fe24f591b6bf7153.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger We are missing an entry for the virtio-iommu-pci device. Add the information on which machine it is currently supported and document the new granule option. Signed-off-by: Eric Auger Message-Id: <20240307134445.92296-5-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- qemu-options.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 937fd7ed84..c6f3d2e76d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1172,6 +1172,14 @@ SRST Please also refer to the wiki page for general scenarios of VT-d emulation in QEMU: https://wiki.qemu.org/Features/VT-d. +``-device virtio-iommu-pci[,option=...]`` + This is only supported by ``-machine q35`` (x86_64) and ``-machine virt`` (ARM). + It supports below options: + + ``granule=val`` (possible values are 4k, 8k, 16k, 64k and host; default: host) + This decides the default granule to be be exposed by the + virtio-iommu. If host, the granule matches the host page size. + ERST DEF("name", HAS_ARG, QEMU_OPTION_name, From patchwork Tue Mar 12 22:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aJb7n1fr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT322CCCz1ydl for ; Wed, 13 Mar 2024 09:34:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdJ-0005ar-Vo; Tue, 12 Mar 2024 18:30:06 -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 1rkAcI-0002ry-4a for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAc8-0004c7-F8 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282531; 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=SkLCskZADtvicMPgS7N3Shz0FKc1G4wcmgr3/rSi1jg=; b=aJb7n1frFuC7gbxlWndEONrwaC7rAPJRrSOo1HPkuSTPXqTdEYI0vzlXD4NTAHr48k51G/ 06BUYh9rvCICJilWoQHqkhmeQqt+h7UXktgLntwSqmYd0fbzm+x2vyCkGk/ColzK0oXQt6 vBFnC89ejBfzriMvEnGHr88/rujShBE= 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-251-RRueLvNdPhGBjT357YJz8g-1; Tue, 12 Mar 2024 18:28:50 -0400 X-MC-Unique: RRueLvNdPhGBjT357YJz8g-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-568728e521bso1094767a12.0 for ; Tue, 12 Mar 2024 15:28:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282529; x=1710887329; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SkLCskZADtvicMPgS7N3Shz0FKc1G4wcmgr3/rSi1jg=; b=TOPU6zyM57/il/m8aK8pqPlj1s/t1qXUddUKQ7dFdbL5bCGObqMyroDYDqSHXyFoS7 HWxduP+ofB11bRMHdCqw7cBuH0fgyP4BiYAgJPVUGfL92Ys0qy+XPPHT19uJcYTBHBkC xnBdPFKGNuDHiG1BfsKolfP4+5gg1KEwLj9j2PRGcUkErhkFfhW6ZowfK8V7+xeVUrjB eAVbR813bye7Xyycd+1F93tEumJiJ2+wzlD+yj4Su9dixlztiACK+kau2WeohQUp4gIH 7zYycKgGfmfzgcfED0/9zchZ4OkmQLq0tfZSwQsVioHiun59gMtrpXfyEZIU18gV6lTU Wijw== X-Gm-Message-State: AOJu0YwpxsCLQMZ2Xdq+jAnhbufLfpZBpDjTnzfXeDJ1VKkOVrD/Ww2a dmNu1vPkx56YknBMNx5/go9Hmk6OKGLcM/FUh6/IqiHNuhBtmCMq9pOY21EmLJBRcsVr0Q8jGGz pZgPFD/xJAmsJuIFxrJ/fCcNhkPEfmgkxELBW1BtQKBGJyWbHEgoLa8CfpMjPBeT1V4nVJrR35j FWlnJSHkv3H8dXPnjkkV9iwJeKuyLOCa73 X-Received: by 2002:a50:f696:0:b0:567:3bbd:cefb with SMTP id d22-20020a50f696000000b005673bbdcefbmr2561979edn.35.1710282528788; Tue, 12 Mar 2024 15:28:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDO+cV22/TTgsh2a4S0j3ck470gwU1x6D2mZTQmKgd2I2B7B7BebfU5zaGEa6MERtj9rfCRQ== X-Received: by 2002:a50:f696:0:b0:567:3bbd:cefb with SMTP id d22-20020a50f696000000b005673bbdcefbmr2561963edn.35.1710282528377; Tue, 12 Mar 2024 15:28:48 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id v22-20020aa7d816000000b005687e041608sm440346edq.37.2024.03.12.15.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:48 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:45 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , =?utf-8?q?C=C3=A9dric?= Le Goater Subject: [PULL 60/68] virtio-iommu: Trace domain range limits as unsigned int Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger Use %u format to trace domain_range limits. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan Reviewed-by: Cédric Le Goater Message-Id: <20240307134445.92296-6-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 9df24864a2..13b6991179 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -112,7 +112,7 @@ virtio_iommu_device_reset(void) "reset!" virtio_iommu_system_reset(void) "system reset!" virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx64 virtio_iommu_device_status(uint8_t status) "driver status = %d" -virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_start, uint32_t domain_end, uint32_t probe_size, uint8_t bypass) "page_size_mask=0x%"PRIx64" input range start=0x%"PRIx64" input range end=0x%"PRIx64" domain range start=%d domain range end=%d probe_size=0x%x bypass=0x%x" +virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_start, uint32_t domain_end, uint32_t probe_size, uint8_t bypass) "page_size_mask=0x%"PRIx64" input range start=0x%"PRIx64" input range end=0x%"PRIx64" domain range start=%u domain range end=%u probe_size=0x%x bypass=0x%x" virtio_iommu_set_config(uint8_t bypass) "bypass=0x%x" virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" From patchwork Tue Mar 12 22:28:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b6lJdB7R; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTC71BJtz23qj for ; Wed, 13 Mar 2024 09:41:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAeP-0006hT-1K; Tue, 12 Mar 2024 18:31:13 -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 1rkAcO-0002sX-3X for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAcB-0004cR-8G for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:28:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282534; 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=fScw+GbeSb7Y/URvyjrtWLndZz8ykgk7NaxW0WCLA+8=; b=b6lJdB7RTbPoKIpwqvo9kC/d1BCPDE+Ve/0RPT4p/GBlsZ2nUcrrQKjQ4klod9i3WRNKGr ZYQiNRIpqjYUrTGY5FbvQzpNVv33+zDL+Be6w+qoewGU9krdoeKWHskxc6e6UMZwj0hAE9 NnRD0lAMEshCDrgsvYrzcVB4MPxQTUQ= 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-182-OqxLRk_fPCWq0SEIBN2z4A-1; Tue, 12 Mar 2024 18:28:53 -0400 X-MC-Unique: OqxLRk_fPCWq0SEIBN2z4A-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a45190fd2fcso278651666b.0 for ; Tue, 12 Mar 2024 15:28:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282532; x=1710887332; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fScw+GbeSb7Y/URvyjrtWLndZz8ykgk7NaxW0WCLA+8=; b=fucTjwYQuESfLjfJSe10oU5xYduBWtLp9uaC7mqEbeM5c0whVzn/ZMqOo4DVOyv7XH wVc3y+63Pn/2Q30JpRchgoUrfKo5E5+k4fc2H14LrZdevJxY6zTzc+FNK/uVEgWoTGgd 3i+STeMbpdic7bYBa4B45IaAjT8R/ExHTvS9pMAAqVy3L0za5wtihSw0TRDrZlOs4Ne3 yyhgQD5+fKo/h+7+Ho7Thdzt7oZWjfSDWe6YMXuSAtAZjP2TDyklKZz981lNapLWmS+3 WPRqd+pVFUMYCTObnm7IDDbJrxzIrwHWkLv0sQlQrSxgcCZ5mxmKs7RMJq883kzic60J XNQA== X-Gm-Message-State: AOJu0Ywbnc1X3XJ+4O4L/47mnj5cNFRrNuObBMkEnhWePSdFHk9oVl/R UAPcVFSZ+dcayT3Dq3wKiuuWd70XjWSwwTfGXwsykWa6MjXgDjd1iTAN2EhJmLhrEYM2NDJWUOD QMZOdAj8unCLv3ae0p3LT+n/glyvRIlpC65DlfVBQwH/BodHvKyrdaA+rY80XzTQlvyPZA0sJC0 venhBrygPNOj9xg+HBnaz2aLoOZdsY53Qk X-Received: by 2002:a17:907:7d9e:b0:a46:30f4:6321 with SMTP id oz30-20020a1709077d9e00b00a4630f46321mr5098891ejc.58.1710282531877; Tue, 12 Mar 2024 15:28:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvzpcqEL0CG+1pobs8bJpTj9boPaW9IzYrExRw17aftRGIy7teSuOAfCNdc63I+EFuN7Mylw== X-Received: by 2002:a17:907:7d9e:b0:a46:30f4:6321 with SMTP id oz30-20020a1709077d9e00b00a4630f46321mr5098879ejc.58.1710282531463; Tue, 12 Mar 2024 15:28:51 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id l19-20020a170906231300b00a449d6184dasm4213363eja.6.2024.03.12.15.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:51 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:48 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , =?utf-8?q?C=C3=A9dric?= Le Goater Subject: [PULL 61/68] virtio-iommu: Add an option to define the input range width Message-ID: <01e7e4921ccebb81cebc69eb648040a57be4f5ff.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger aw-bits is a new option that allows to set the bit width of the input address range. This value will be used as a default for the device config input_range.end. By default it is set to 64 bits which is the current value. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan Reviewed-by: Cédric Le Goater Message-Id: <20240307134445.92296-7-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-iommu.h | 1 + hw/virtio/virtio-iommu.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h index 67ea5022af..83a52cc446 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -68,6 +68,7 @@ struct VirtIOIOMMU { Notifier machine_done; bool granule_frozen; GranuleMode granule_mode; + uint8_t aw_bits; }; #endif diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index aab97e1527..1326c6ec41 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1314,7 +1314,12 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) * in vfio realize */ s->config.bypass = s->boot_bypass; - s->config.input_range.end = UINT64_MAX; + if (s->aw_bits < 32 || s->aw_bits > 64) { + error_setg(errp, "aw-bits must be within [32,64]"); + return; + } + s->config.input_range.end = + s->aw_bits == 64 ? UINT64_MAX : BIT_ULL(s->aw_bits) - 1; switch (s->granule_mode) { case GRANULE_MODE_4K: @@ -1544,6 +1549,7 @@ static Property virtio_iommu_properties[] = { DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true), DEFINE_PROP_GRANULE_MODE("granule", VirtIOIOMMU, granule_mode, GRANULE_MODE_HOST), + DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 64), DEFINE_PROP_END_OF_LIST(), }; From patchwork Tue Mar 12 22:28:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K6PrVm6f; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT1f2jBQz1ydl for ; Wed, 13 Mar 2024 09:33:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdU-0006Fd-TQ; Tue, 12 Mar 2024 18:30:17 -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 1rkAcQ-0002te-KK for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:12 -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 1rkAcF-0004ck-85 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282538; 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: in-reply-to:in-reply-to:references:references; bh=hNPO4kQBGY7YaJZTv5HNb+C3+l45QRRRyhlniT9lFxI=; b=K6PrVm6fQNfKcLi05X4SvFLWFddKg8Kdk54zKQmj+4SK8JUpn6fklc72f+Rgq6uvQJVd0K FsDdwUh57hjEYtooewrx00B0ZypEAuD0rD1H7MkXHaVxRtzMl63heBwWo9x1YGTvVOHvVa ZP7CE9aJaV3VMmCkMtAjvJgbIa7BC0U= 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-26-lZBMGBbvMEaxQ6igJ6Y3Lw-1; Tue, 12 Mar 2024 18:28:57 -0400 X-MC-Unique: lZBMGBbvMEaxQ6igJ6Y3Lw-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a449be9db59so337138566b.1 for ; Tue, 12 Mar 2024 15:28:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282536; x=1710887336; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hNPO4kQBGY7YaJZTv5HNb+C3+l45QRRRyhlniT9lFxI=; b=ElDKVBhdiOSDihYsmJ5KSTxiw+sgHX7nezyW3997KGHMcDEOvLZADoKFPsJzpSnKmV B4k5pe930rqRGjid26nq8V/pJqtpYL3WfePxmkSk+U0yZBjkFgi34d0tXYr5GC79Ahty 6swdZOPbbaP5kNuuWo6/2gyLpTEPPOJeHWNogne1Be5U2M2ObYC72MNQ1n3Zimsh9Jf2 c2GDP9FRslWSaP3ADL0wSo/1cFYSooTYLrKpjZP2NwYDYjGBHcd/c6Py5udia89Tev7+ oHenftDyv/nE7Ih1Alh3eklcGq9DBycmxrBKnPnN8pUq+Ig7vuWCXG5owojbuAoVZpm5 F9/Q== X-Gm-Message-State: AOJu0YzhlhPPOX9zZrBttrHNwVYiJEmahG2Ac3S4NGqGGqs4YEDUCoY7 VCYTPFyP+UMlqGYAiECnMzJaEgfMnHqqB5a05iKLEqixPNKzcQ3KhdkgVp6piNcjYeP1QiP9w9H z1s23/hYa9UKTuULFMfA1jkBTnsj6j9dfOBCubPGBX+Tz9qDwbhcWMr1ZglT4g3xc+Zd2P1yZ4W swexL909Eo62d9WY7jOGInR11YlQ8WlC5S X-Received: by 2002:a17:906:a013:b0:a46:2e54:43fb with SMTP id p19-20020a170906a01300b00a462e5443fbmr3773299ejy.70.1710282535760; Tue, 12 Mar 2024 15:28:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAiURKDqc1NjT/2fHPHap0y/SwUUkVa+5iK/x5vmihfCzWhY/ICm2JQWBhOJKJtVDeuPc41g== X-Received: by 2002:a17:906:a013:b0:a46:2e54:43fb with SMTP id p19-20020a170906a01300b00a462e5443fbmr3773281ejy.70.1710282535147; Tue, 12 Mar 2024 15:28:55 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id dn18-20020a17090794d200b00a45f545beeesm4219220ejc.122.2024.03.12.15.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:54 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:51 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , Eduardo Habkost , Marcel Apfelbaum , Philippe =?utf-8?q?Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Paolo Bonzini , Richard Henderson , Thomas Huth , Laurent Vivier Subject: [PULL 62/68] hw/i386/q35: Set virtio-iommu aw-bits default value to 39 Message-ID: <9b588be373ad01e7ce09e25f69f66b811af0b799.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger Currently the default input range can extend to 64 bits. On x86, when the virtio-iommu protects vfio devices, the physical iommu may support only 39 bits. Let's set the default to 39, as done for the intel-iommu. We use hw_compat_8_2 to handle the compatibility for machines before 9.0 which used to have a virtio-iommu default input range of 64 bits. Of course if aw-bits is set from the command line, the default is overriden. Signed-off-by: Eric Auger Message-Id: <20240307134445.92296-8-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Zhenzhong Duan --- hw/core/machine.c | 1 + hw/i386/pc_q35.c | 9 +++++++++ tests/qtest/virtio-iommu-test.c | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 6bd09d4592..4b89172d1c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -35,6 +35,7 @@ GlobalProperty hw_compat_8_2[] = { { TYPE_VIRTIO_IOMMU_PCI, "granule", "4k" }, + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "64" }, }; const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 1356c5d107..8a427c4647 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -45,6 +45,7 @@ #include "hw/i386/pc.h" #include "hw/i386/amd_iommu.h" #include "hw/i386/intel_iommu.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/display/ramfb.h" #include "hw/ide/pci.h" #include "hw/ide/ahci-pci.h" @@ -63,6 +64,12 @@ /* ICH9 AHCI has 6 ports */ #define MAX_SATA_PORTS 6 +static GlobalProperty pc_q35_compat_defaults[] = { + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "39" }, +}; +static const size_t pc_q35_compat_defaults_len = + G_N_ELEMENTS(pc_q35_compat_defaults); + struct ehci_companions { const char *name; int func; @@ -354,6 +361,8 @@ static void pc_q35_machine_options(MachineClass *m) machine_class_allow_dynamic_sysbus_dev(m, TYPE_INTEL_IOMMU_DEVICE); machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE); machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE); + compat_props_add(m->compat_props, + pc_q35_compat_defaults, pc_q35_compat_defaults_len); } static void pc_q35_9_0_machine_options(MachineClass *m) diff --git a/tests/qtest/virtio-iommu-test.c b/tests/qtest/virtio-iommu-test.c index 068e7a9e6c..afb225971d 100644 --- a/tests/qtest/virtio-iommu-test.c +++ b/tests/qtest/virtio-iommu-test.c @@ -34,7 +34,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) uint8_t bypass = qvirtio_config_readb(dev, 36); g_assert_cmpint(input_range_start, ==, 0); - g_assert_cmphex(input_range_end, ==, UINT64_MAX); + g_assert_cmphex(input_range_end, >=, UINT32_MAX); g_assert_cmpint(domain_range_start, ==, 0); g_assert_cmpint(domain_range_end, ==, UINT32_MAX); g_assert_cmpint(bypass, ==, 1); From patchwork Tue Mar 12 22:28:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IOKkATAS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT972Yxsz1yWy for ; Wed, 13 Mar 2024 09:39:39 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAeK-0006ad-Bm; Tue, 12 Mar 2024 18:31:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAcV-0002ui-Nd for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:18 -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 1rkAcI-0004d5-Gj for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282541; 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: in-reply-to:in-reply-to:references:references; bh=MKkSDazDM8plKzOrprMyap3/frHtZRjZMB1Z0hTsQYk=; b=IOKkATASqWqUwtw6agW+2i8If2heOjtkf/fKTi0CP/QL5chScubz+YDkbQ9Ht5u/LDZRVe BeTyB/aQQ+Y6E8iOk+p1hNII6wYpXE/fqx/Wp5hPUCd7CfXO5swXEkuYkaWXHCwgVbxX6Y KZat2U69udO3oQ7ljaXFPENblm2uJRQ= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-18JZP0X8N4eGzur0fMTOHw-1; Tue, 12 Mar 2024 18:29:00 -0400 X-MC-Unique: 18JZP0X8N4eGzur0fMTOHw-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2d45c84435eso10091791fa.0 for ; Tue, 12 Mar 2024 15:29:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282538; x=1710887338; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MKkSDazDM8plKzOrprMyap3/frHtZRjZMB1Z0hTsQYk=; b=XpLq1rk0CCuAWWTtBSKBrmebnpMkvbxmEFQDsk8j7T29pmIg2p+6AdQJBc5rpAYyYv jnVxUlhElSJ0xSKD6VGD2oSszGAIN+4MlkamTAvEIpgdSYwCh5ejG7HQpYZlQvExuMPE 0L+dHI1SogGENgtUEIjTav6pf4arB8kBjijgiShG4x9WmglJptRUpiJiEh5EO6ugmg6R BTdNVOPHWMteBSfK33xV7JxnytUJFty0tr3xr8Ty7b6JsIdwRa3kGlW5bV7HsG3gsSyv Rt9jriRR0lN22SEuKkGsoSL1rsY0oDoUQDBYlZ4H6p0af97cMxMzZRDcaJh9xNXDveq9 tRJA== X-Gm-Message-State: AOJu0YyRR8kyJP7qxpMxsdlqi22l7X37DL5rDM/j5GpgPk+soVghkgiW JdCh0nJp8bVDVW0Eu0DuZJUg9wzwrySEhMWwCuAP+Q4YYVy6iGsy259bJmrf6wjW88W3lWIkf3i keZjoWpmXJgbh9NG6HCbIiT1xCJsAE5DAI/eOcgjsNp6eaDgkXIPW61mBQ8RE18/z/1nnGd0gr4 UfOAR+NVotDKMovemllFziggAZciajZjQK X-Received: by 2002:a2e:720b:0:b0:2d4:49d1:38e with SMTP id n11-20020a2e720b000000b002d449d1038emr3547950ljc.28.1710282538507; Tue, 12 Mar 2024 15:28:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTHwlpwOhQH8XRXj1WIhU77gbrM669UAtKbXGhtG3RKMWI4lBcPnVPheexgEOdZeeNAnMX2w== X-Received: by 2002:a2e:720b:0:b0:2d4:49d1:38e with SMTP id n11-20020a2e720b000000b002d449d1038emr3547935ljc.28.1710282537949; Tue, 12 Mar 2024 15:28:57 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id d34-20020a056402402200b005687e7b0cd2sm388946eda.40.2024.03.12.15.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:28:57 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:55 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Zhenzhong Duan , qemu-arm@nongnu.org Subject: [PULL 63/68] hw/arm/virt: Set virtio-iommu aw-bits default value to 48 Message-ID: <62d776002c990d5b6fd4a2b6809ab2956c6e1ff0.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger On ARM we set 48b as a default (matching SMMUv3 SMMU_IDR5.VAX == 0). hw_compat_8_2 is used to handle the compatibility for machine types before 9.0 (default was 64 bits). Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan Message-Id: <20240307134445.92296-9-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/arm/virt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0af1943697..e5cd935232 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -85,11 +85,28 @@ #include "hw/char/pl011.h" #include "qemu/guest-random.h" +static GlobalProperty arm_virt_compat[] = { + { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "48" }, +}; +static const size_t arm_virt_compat_len = G_N_ELEMENTS(arm_virt_compat); + +/* + * This cannot be called from the virt_machine_class_init() because + * TYPE_VIRT_MACHINE is abstract and mc->compat_props g_ptr_array_new() + * only is called on virt non abstract class init. + */ +static void arm_virt_compat_set(MachineClass *mc) +{ + compat_props_add(mc->compat_props, arm_virt_compat, + arm_virt_compat_len); +} + #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ void *data) \ { \ MachineClass *mc = MACHINE_CLASS(oc); \ + arm_virt_compat_set(mc); \ virt_machine_##major##_##minor##_options(mc); \ mc->desc = "QEMU " # major "." # minor " ARM Virtual Machine"; \ if (latest) { \ From patchwork Tue Mar 12 22:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fSJjp1Bo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8r5HZbz23rC for ; Wed, 13 Mar 2024 09:39:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAeK-0006aX-Am; Tue, 12 Mar 2024 18:31:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAcX-0002v0-3G for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:18 -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 1rkAcL-0004dc-MK for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282545; 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=+rXUT31BNk1l3JXvgoTOKQhMWbk4Q8QKbLyl08Dff9k=; b=fSJjp1BoofDqCCRRbH1JYkhfJivwsKecF9arYMAsH61BAqU0PTGr3c68wr5mJZuM73AULQ 7saq1tiMje5c3eUDubnf6SpTCip3vyX/ZHImhEbNK2VtImyvF9TY6NIMGa5gr+VZseqjwm eHQNn7EgWoCYyNWL3R2bR6zV23r1TwY= 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-52-YGNiLGBwNZ-zO9lm4FCM8w-1; Tue, 12 Mar 2024 18:29:03 -0400 X-MC-Unique: YGNiLGBwNZ-zO9lm4FCM8w-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5686eca9cc8so939193a12.1 for ; Tue, 12 Mar 2024 15:29:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282542; x=1710887342; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+rXUT31BNk1l3JXvgoTOKQhMWbk4Q8QKbLyl08Dff9k=; b=VuF9D0OBH+UiTGlsnP0ijHzypdcE9QxFG1dJDNe4XPBUcPCiKlDQ2ed6uz+AdPtBra LcLeIzWBWUZSB6apJcInPO2ccrP5w0bhW7FrA8gyoikgIyBsrysImr8xYCB/l15i0gGw NHYUyR2Nidg40KWNYT7QQ7aCIh9X5/MDDhWzsqMmQbA/Nq5iVnJv295bMROJhkRZgU4O kYXsmbB6N06j0676Ly8lVuDdXiNF57HBS+mBfVbSZEANHZuCbSfoZZk72M4rMm/GCX4i 0W391O9p6mDNMpiiX99ZLs1jPOaNlKLIC+6kZc7afxkKxj08gFknIGJ04OuW3blUmkVk fxzQ== X-Gm-Message-State: AOJu0YzsBNvtwscLIYQfdA0Hlu9BdtSkgLEFBuMzkYEJwGM1qCwaxyH6 PlCPYuoPlXhHNdYhrTLUiXrINKA3v5RGXCPo39qSYJOhM4GZ94CKIu02uFlV8LtIiRVbtxzoEfd h2JigUqA9ctCbyj3gtWJ/xx5y7PY+MH0C4pDXwG1rhLB5gnpcntb3It+Gy2UDO6GakeTn65RrCh owa9VLa1yzXwxTsbnDiCvNP0Ei8pDvtmi6 X-Received: by 2002:a50:cc04:0:b0:568:7abc:a845 with SMTP id m4-20020a50cc04000000b005687abca845mr1675359edi.13.1710282541801; Tue, 12 Mar 2024 15:29:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdAWy+qi+pbX/8Fy8qKerPwcwDYbD97DiFpkkYH5I0v0KmizK9TnucqF97EtO2mVtIir+MZQ== X-Received: by 2002:a50:cc04:0:b0:568:7abc:a845 with SMTP id m4-20020a50cc04000000b005687abca845mr1675346edi.13.1710282541462; Tue, 12 Mar 2024 15:29:01 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id gy4-20020a0564025bc400b0056820311668sm4336104edb.57.2024.03.12.15.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:29:01 -0700 (PDT) Date: Tue, 12 Mar 2024 18:28:58 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Auger , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Thomas Huth , Michael Tokarev , Markus Armbruster Subject: [PULL 64/68] qemu-options.hx: Document the virtio-iommu-pci aw-bits option Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Eric Auger Document the new aw-bits option. Signed-off-by: Eric Auger Message-Id: <20240307134445.92296-10-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé --- qemu-options.hx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index c6f3d2e76d..7fd1713fa8 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1180,6 +1180,9 @@ SRST This decides the default granule to be be exposed by the virtio-iommu. If host, the granule matches the host page size. + ``aw-bits=val`` (val between 32 and 64, default depends on machine) + This decides the address width of the IOVA address space. + ERST DEF("name", HAS_ARG, QEMU_OPTION_name, From patchwork Tue Mar 12 22:29:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AzGHL/aY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTC95Gqcz1yWt for ; Wed, 13 Mar 2024 09:41:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAeG-0006V3-Kb; Tue, 12 Mar 2024 18:31:04 -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 1rkAcY-0002vM-11 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:22 -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 1rkAcQ-0004dy-EU for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282548; 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: in-reply-to:in-reply-to:references:references; bh=tvskLJuZlte5MbngUkjQAr+sRrlvuUkQnWRcVHGQVPU=; b=AzGHL/aYotVQvf8ighfu5dA/ctgH5TJQq58OJy15Y+6ALwUBVo4jdNwK2dQ2ZUEbHZLFjS R0ckPMtstiDQZVtdzTFluZ677cyAWzEpyRzCZRfevOD6mHcLd9gfxrMqfnKKRHqtreYN9o MDu2P3zvBHim0u7sX3ImbArtX7UX8EM= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-2HO4ty4EOLCbl8J6ocvs3w-1; Tue, 12 Mar 2024 18:29:06 -0400 X-MC-Unique: 2HO4ty4EOLCbl8J6ocvs3w-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d2ecf61dd7so46311801fa.1 for ; Tue, 12 Mar 2024 15:29:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282545; x=1710887345; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tvskLJuZlte5MbngUkjQAr+sRrlvuUkQnWRcVHGQVPU=; b=OxoEJ5+gfKKaI5ftaTJYSakzAiiwlPR6+8DMcdAygryghxHWtlxd7CjmKcQimyM6ET 8KF04ifdxNuu8GK4Ea6U5zHwt+jpDRi3RYAMnF9QjuAZPeZr6zoKTAHvAGlIk1Ub3NA1 83aaOgaTgzkUfMkfNGbexiRqx7drVtMjHnPfC35cOZ1AsgT8HJ5/iTT1RDLBCUGO3Mjl 4o+qiJH/oDIu/rqVrIEhiawxIGnjo4o0Z1a/I+m0914/ixYtOcrUfVoxz9rQYUhDAhA8 soWdTAcBIVeh/9EjWDrbDGvEdEimLUMQ6riWPJ+fCkULtrG6j3/hNZndZMMGFKLhi1vh R1cQ== X-Gm-Message-State: AOJu0YxyfnSfxkp8Nhk0vYFUKINkplJtA8R3pvtuz/u61lg+i61P6hXQ N/XEENdZFLYn8DyOEytn44cBbckQTFP/kQs8qmW0mOtfls12VxV+JV1G3+Pgy76/4Xc5LNqIv4C VtDP9x15+OfuLrlmDuxCxD3UfF+oz5ZY1I0nNKb+1hKnKl0JaXlqSSd9E93dQt+kZxHHu9D+IEB Rr2ukj9lwQSvfa1WWeMyFJ+Pg/bMFWePGP X-Received: by 2002:a05:6512:3188:b0:513:28b3:bd5d with SMTP id i8-20020a056512318800b0051328b3bd5dmr2803327lfe.54.1710282544864; Tue, 12 Mar 2024 15:29:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHK4BRn7zVVB48QoZ/7Q+Gso3634VHGiSN2BO+yMn2ZaShP9d57VPeNClenceHNgUtOnE+d6Q== X-Received: by 2002:a05:6512:3188:b0:513:28b3:bd5d with SMTP id i8-20020a056512318800b0051328b3bd5dmr2803306lfe.54.1710282544327; Tue, 12 Mar 2024 15:29:04 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id jo11-20020a170906f6cb00b00a46522c38c4sm201218ejb.207.2024.03.12.15.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:29:03 -0700 (PDT) Date: Tue, 12 Mar 2024 18:29:01 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Igor Mammedov , Ani Sinha Subject: [PULL 65/68] hmat acpi: Do not add Memory Proximity Domain Attributes Structure targetting non existent memory. Message-ID: <2eb6672cfdaea7dacd8e9bb0523887f13b9f85ce.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jonathan Cameron If qemu is started with a proximity node containing CPUs alone, it will provide one of these structures to say memory in this node is directly connected to itself. This description is arguably pointless even if there is memory in the node. If there is no memory present, and hence no SRAT entry it breaks Linux HMAT passing and the table is rejected. https://elixir.bootlin.com/linux/v6.7/source/drivers/acpi/numa/hmat.c#L444 Signed-off-by: Jonathan Cameron Message-Id: <20240307160326.31570-2-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/hmat.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 2242981e18..8ea240878a 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -204,6 +204,13 @@ static void hmat_build_table_structs(GArray *table_data, NumaState *numa_state) build_append_int_noprefix(table_data, 0, 4); /* Reserved */ for (i = 0; i < numa_state->num_nodes; i++) { + /* + * Linux rejects whole HMAT table if a node with no memory + * has one of these structures listing it as a target. + */ + if (!numa_state->nodes[i].node_mem) { + continue; + } flags = 0; if (numa_state->nodes[i].initiator < MAX_NODES) { From patchwork Tue Mar 12 22:29:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Wxlq23ng; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTCF3Cgpz1yWt for ; Wed, 13 Mar 2024 09:41:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdI-0005O2-5O; Tue, 12 Mar 2024 18:30:04 -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 1rkAcY-0002vl-OO for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:23 -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 1rkAcU-0004eN-F7 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282553; 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: in-reply-to:in-reply-to:references:references; bh=2oYq0iZXaQr5DMI6kVH19Up4p/ecK9SPws94ZnuK5Hw=; b=Wxlq23ngghDveUN5llanCGgTuJ40glV6WazUDlpNlyRloGyR0hLFsXSifN5H/chFlwmNwt nQIruKlT1pQGbJ8mOv3iaX+g3tW1B9aBBH9fVF3iOMJ+WLL03AwFBy5z/AoGo3L8SUYhjn Z6gGUflS5o4Zam4V/g+/Q+WxbizAm04= 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-208-asIaeoxHNsqQv5wm1YCzMA-1; Tue, 12 Mar 2024 18:29:10 -0400 X-MC-Unique: asIaeoxHNsqQv5wm1YCzMA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a44143c8908so28013366b.1 for ; Tue, 12 Mar 2024 15:29:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282548; x=1710887348; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2oYq0iZXaQr5DMI6kVH19Up4p/ecK9SPws94ZnuK5Hw=; b=e4/5gVMN0ecta4M6klHfdVCCraMmVe2mzWIJaF+CWrWRfFGTeN9cYKGizOFuVIDw1B t/duJZo3ccDFLN8te7ciQrAJgfg+B1xv4mrGXe6yua5ebiaCfT9nQDOArhqG19lokyCQ 3BbgW5NhKnzb35D+lhlHFXA1Ire4FCxS4UqT4u6qYeMWAgV9lYfXjmmfGCJphWpHjznT HhRQguyYp3tnGHNbYx23NmV94nRb70fnyYPgMpK7tJiOelVHg9oq4EToVhz3M/E0nIqQ KHEsAZoTXn66KmjPPWBxh5RWx6iqZpnlhW2bu+kZbG1O6mSAIcRT1IwI5St7FGYZeo0D /yTQ== X-Gm-Message-State: AOJu0YyC+Ipq/jDddud5aQVLRf7Yql1umhlqmSsvT+BfmoJzgqvLrs1q 6PvfWf4XaOTxNWnl5KK3aIL3azidLrpmBDBXLRtMtlY2dhZGSUZM1JymyIw1AwhmxpF2RQA3glL 5gOo7KxntbFATmD2MoMdzECMREq4+bVpRF/PlE8BXIiD7NfPWGVoWqU+QM7ako5yQ1xiZr8z5p7 LxPrLzOvlyifCUTq0Lj24WYM7K/rBGcU6I X-Received: by 2002:a17:906:c00a:b0:a46:4fc1:c9fe with SMTP id e10-20020a170906c00a00b00a464fc1c9femr688800ejz.27.1710282548395; Tue, 12 Mar 2024 15:29:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsCZTemK7QdO83y+cy6XCnKxRfZWuO0Db+MI2RJ4EjaTptmWAseH4bdsysjaZg3Xa0Jp441Q== X-Received: by 2002:a17:906:c00a:b0:a46:4fc1:c9fe with SMTP id e10-20020a170906c00a00b00a464fc1c9femr688769ejz.27.1710282547683; Tue, 12 Mar 2024 15:29:07 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id kn22-20020a170906aa5600b00a45200fe2b5sm4242271ejb.224.2024.03.12.15.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:29:07 -0700 (PDT) Date: Tue, 12 Mar 2024 18:29:04 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Igor Mammedov , Ani Sinha Subject: [PULL 66/68] hmat acpi: Fix out of bounds access due to missing use of indirection Message-ID: <74e2845c5f95b0c139c79233ddb65bb17f2dd679.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jonathan Cameron With a numa set up such as -numa nodeid=0,cpus=0 \ -numa nodeid=1,memdev=mem \ -numa nodeid=2,cpus=1 and appropriate hmat_lb entries the initiator list is correctly computed and writen to HMAT as 0,2 but then the LB data is accessed using the node id (here 2), landing outside the entry_list array. Stash the reverse lookup when writing the initiator list and use it to get the correct array index index. Fixes: 4586a2cb83 ("hmat acpi: Build System Locality Latency and Bandwidth Information Structure(s)") Signed-off-by: Jonathan Cameron Message-Id: <20240307160326.31570-3-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/hmat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 8ea240878a..9b1662b6b8 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -78,6 +78,7 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB_Info *hmat_lb, uint32_t *initiator_list) { int i, index; + uint32_t initiator_to_index[MAX_NODES] = {}; HMAT_LB_Data *lb_data; uint16_t *entry_list; uint32_t base; @@ -121,6 +122,8 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB_Info *hmat_lb, /* Initiator Proximity Domain List */ for (i = 0; i < num_initiator; i++) { build_append_int_noprefix(table_data, initiator_list[i], 4); + /* Reverse mapping for array possitions */ + initiator_to_index[initiator_list[i]] = i; } /* Target Proximity Domain List */ @@ -132,7 +135,8 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB_Info *hmat_lb, entry_list = g_new0(uint16_t, num_initiator * num_target); for (i = 0; i < hmat_lb->list->len; i++) { lb_data = &g_array_index(hmat_lb->list, HMAT_LB_Data, i); - index = lb_data->initiator * num_target + lb_data->target; + index = initiator_to_index[lb_data->initiator] * num_target + + lb_data->target; entry_list[index] = (uint16_t)(lb_data->data / hmat_lb->base); } From patchwork Tue Mar 12 22:29:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Rt8tTZ6k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvTCH0cHNz1yWt for ; Wed, 13 Mar 2024 09:41:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAdV-0006GM-8k; Tue, 12 Mar 2024 18:30:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAca-0002wp-1Q for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:23 -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 1rkAcU-0004eV-Im for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282554; 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: in-reply-to:in-reply-to:references:references; bh=9Q3ZMhxuiBKQgwWVuadLMzxaLaVsdjhfX4rDv2UGsEo=; b=Rt8tTZ6k2tXTHHFO1N39I2xLVWGCx2JCYVhMNLalH1HoWvmNj3/q60BJchiJhacE3R4oFt xNyOIU5JNOLNAsGri6ItnqJAJhDnUw/Ksw0vk3uiQMitIt7mnm8jevGfV7h3JTmfvwb/Gy KIfCjWdsxH4HgWgORl14AYNAZTY//9s= 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-226-BJLYu9CHOcOKtr9LNGA8zg-1; Tue, 12 Mar 2024 18:29:12 -0400 X-MC-Unique: BJLYu9CHOcOKtr9LNGA8zg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a45acc7f191so403167666b.0 for ; Tue, 12 Mar 2024 15:29:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282551; x=1710887351; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9Q3ZMhxuiBKQgwWVuadLMzxaLaVsdjhfX4rDv2UGsEo=; b=gTZq3IPy7K1X+LD0Lti+eUyYBhVN+Zkl3hjLzHRTWblmF+2Ymslr6l15NPPtwXM+OH pj8cRiA0ePdmHIT+yaA2dOmLaMCEd9vv7UiGl6KxLaHxHBw+OxaH3/6L54iA6i+gaYoY uaGGyOxRUAJ3K/p0Eq/3c1M6Tfh4ha9d9oPaAHI2DyFrqwm0iO3jWj2xPQ9sSHN7FMVI BeB8Iu0AzGNUlHzMEqAy04bn7qy8oDudYA9rIG6BhQEU0xu/QnDer0LtOImGGY6F1L6/ VMuIlN24bZ4xEifqrZZuEXSFtemEMFC3FeDzO6HfLpwTuVhIj2ZXvc9fPgU2hmkFCUvq Hz8A== X-Gm-Message-State: AOJu0YyxZymH5oyYnfQt3YAVNyOO7jXldaasYmuh0c0Y+e6dD4/FjL0a /PYoETNXJKONtYttLAmo4LlDl+moAUJW4n0DnntEMAAALLJ4QtVfWIkfWGrdZfz2YEa1RrA6sNS jDFIEMW4m4CsaWqrVmA4WI0bqTboIBD/NQYgBclmf5EyuatrG1X/mMDIpp30Rlwnhhp8Qpc9YyJ /9MovYzu4l8mT2NxhMTg7I4jQnFbHh/9j0 X-Received: by 2002:a17:907:8749:b0:a46:2b07:5334 with SMTP id qo9-20020a170907874900b00a462b075334mr4717116ejc.48.1710282551071; Tue, 12 Mar 2024 15:29:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQ07Jy5RT2nxEDcvs+D9Txc5FhbTkeaabAnwIDZRnVrBlgpFrUvVI6LAQOJjHu1D1i5W47bA== X-Received: by 2002:a17:907:8749:b0:a46:2b07:5334 with SMTP id qo9-20020a170907874900b00a462b075334mr4717103ejc.48.1710282550623; Tue, 12 Mar 2024 15:29:10 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id gh16-20020a170906e09000b00a45380dfd09sm4218155ejb.105.2024.03.12.15.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:29:10 -0700 (PDT) Date: Tue, 12 Mar 2024 18:29:07 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Fan Ni Subject: [PULL 67/68] hw/cxl: Fix missing reserved data in CXL Device DVSEC Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jonathan Cameron The r3.1 specification introduced a new 2 byte field, but to maintain DWORD alignment, a additional 2 reserved bytes were added. Forgot those in updating the structure definition but did include them in the size define leading to a buffer overrun. Also use the define so that we don't duplicate the value. Fixes: Coverity ID 1534095 buffer overrun Fixes: 8700ee15de ("hw/cxl: Standardize all references on CXL r3.1 and minor updates") Reported-by: Peter Maydell Signed-off-by: Jonathan Cameron Message-Id: <20240308143831.6256-1-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/cxl/cxl_pci.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hw/cxl/cxl_pci.h b/include/hw/cxl/cxl_pci.h index 265db6c407..d0855ed78b 100644 --- a/include/hw/cxl/cxl_pci.h +++ b/include/hw/cxl/cxl_pci.h @@ -92,8 +92,9 @@ typedef struct CXLDVSECDevice { uint32_t range2_base_hi; uint32_t range2_base_lo; uint16_t cap3; + uint16_t resv; } QEMU_PACKED CXLDVSECDevice; -QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDevice) != 0x3A); +QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDevice) != PCIE_CXL_DEVICE_DVSEC_LENGTH); /* * CXL r3.1 Section 8.1.5: CXL Extensions DVSEC for Ports From patchwork Tue Mar 12 22:29:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GXDJCBzs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvT8b4wFrz1yWy for ; Wed, 13 Mar 2024 09:39:11 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAe7-0006LD-Rl; Tue, 12 Mar 2024 18:30: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 1rkAch-0003gs-RZ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:31 -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 1rkAcY-0004eq-0Z for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:29:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282557; 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=5PeMFDO4130XoQfHKpWr48T0PbkJVOHJ4wOnTCp2Y/U=; b=GXDJCBzsDFRXWaKaCgn6GGBCaBXTHPcY/86nM+TvEy1hGeQ9YszuzeqmGop7S7MN7I2r+p x8J5oc4WJaHTFMZMcwj5GSH5RPFXPJe/+KspZIbTLKuKd0ajjrDzRTAOHKvZJzhXEVj3cO jUW18scqc45reW596Kz+eH8BNlnqHpo= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-H9iHv4UANqyhMI7SR3RrsQ-1; Tue, 12 Mar 2024 18:29:16 -0400 X-MC-Unique: H9iHv4UANqyhMI7SR3RrsQ-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-564fec337b1so276122a12.0 for ; Tue, 12 Mar 2024 15:29:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282555; x=1710887355; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5PeMFDO4130XoQfHKpWr48T0PbkJVOHJ4wOnTCp2Y/U=; b=eKUOa39jXAfXrlEPA5b9RYcjN7a6rzj+LJiT6CbVjdXjkogqxw6xCt1urXzLaSN6vY rF8pKiuaDQMd/2C6suJRZFA0NXyevf4qzL9b1ig0DHB3XtUkviyZwhoSBvx9dtgxmJwJ 52sXZ/l517CO2d3yU1RIFggAml/0GBlYfYA+lOIjzF1Hy/nAYWnp5d8bPTYriAUeqPtD FrqRyDNmUO4dOyfo5fPD4dwx3T0QaWhGT9pDI24l989hU1++iWBEc3OSKmltV8RqooKS JMHxti85O3HTJDoYMt1cpomMaIVDUV7oOMSleE55795BgK+WmCB8Tu5mTcE1r00QmF5G 9giQ== X-Gm-Message-State: AOJu0Yy2GhUMPqi2XDVkaDxlPKvNo/uPRRibwbDl+LVuEFImc1PkkVSO jcrBTdcLfmU2EskSayYJCRLG2SyfE+rR/CWGSW16EykiUVtAJObz5/wLJ8QzQyul42Wd1YRPObi JGsXixGENaszjTSGEjKaB/KW3+eHEyqHcdNyrF4IScZURqlUdMTmfLPQS4OJ2OFNmln2yngqNhB bhFBl2B1xnsgkAQPb3gADeJ3mC6lgeLhHC X-Received: by 2002:a17:906:6d4a:b0:a46:38aa:a649 with SMTP id a10-20020a1709066d4a00b00a4638aaa649mr745271ejt.34.1710282554844; Tue, 12 Mar 2024 15:29:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbwlQGCQgW49cMn3mEBZA0YljSpO2uGzdfkTp0+iwD9p2uJjuSB+9NCod5iLFMNAzQPtOKjQ== X-Received: by 2002:a17:906:6d4a:b0:a46:38aa:a649 with SMTP id a10-20020a1709066d4a00b00a4638aaa649mr745256ejt.34.1710282554487; Tue, 12 Mar 2024 15:29:14 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id n3-20020a170906118300b00a451e507cfcsm4218421eja.52.2024.03.12.15.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:29:13 -0700 (PDT) Date: Tue, 12 Mar 2024 18:29:10 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Thomas =?utf-8?q?Wei=C3=9Fschu?= =?utf-8?q?h?= , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= Subject: [PULL 68/68] docs/specs/pvpanic: document shutdown event Message-ID: <73279cecca03f7c2b4489c5fea994e7349eaafaa.1710282274.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Thomas Weißschuh Shutdown requests are normally hardware dependent. By extending pvpanic to also handle shutdown requests, guests can submit such requests with an easily implementable and cross-platform mechanism. Signed-off-by: Thomas Weißschuh Message-Id: <20240310-pvpanic-shutdown-spec-v1-1-b258e182ce55@t-8ch.de> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- docs/specs/pvpanic.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/specs/pvpanic.rst b/docs/specs/pvpanic.rst index f894bc1955..61a80480ed 100644 --- a/docs/specs/pvpanic.rst +++ b/docs/specs/pvpanic.rst @@ -29,6 +29,8 @@ bit 1 a guest panic has happened and will be handled by the guest; the host should record it or report it, but should not affect the execution of the guest. +bit 2 + a regular guest shutdown has happened and should be processed by the host PCI Interface -------------