From patchwork Mon Mar 22 22:59:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=F6U0AHmO; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F496x6hCMz9sTD for ; Tue, 23 Mar 2021 10:04:24 +1100 (AEDT) Received: from localhost ([::1]:34716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTav-0001j1-0g for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:04:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWp-0006jx-SO for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWj-00014b-QU for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454001; 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=Nqu5CR5/71RBCEO2pfu+7+JzFwUquycm34gwnLoLIUQ=; b=F6U0AHmO/eFcvU6wiS0rtDg8leB8dZAYNPn6M7eUrAWEgtXxhXxNgHh1anPCC0h2pADGgy +EDfqj7r8N/ZcwvowfWi9lAzOJcBqYxICN583+z9x/3tPF4ISw6jCjzxLaqyT2RMpxYS07 8p7V7Qo6uZufdDv1yVoMlb5+jtE2LsY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384--rPUKOOIMXCBHKk7kcalWw-1; Mon, 22 Mar 2021 18:59:58 -0400 X-MC-Unique: -rPUKOOIMXCBHKk7kcalWw-1 Received: by mail-wr1-f70.google.com with SMTP id h5so143414wrr.17 for ; Mon, 22 Mar 2021 15:59:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Nqu5CR5/71RBCEO2pfu+7+JzFwUquycm34gwnLoLIUQ=; b=Rtvqv7uTcv5F6Xjnl1QtY2n2lPL4iPLTjz5rx+2+mpo2DaPlP6wrPTftbmA0rphqjs s/vkSqlZP9Es14+MOqiidE7y1oUvwJf+WUt3jVmmurxxLbzo9U72ngfL+GQ21OEisn0T 81a5C+FK6MLx3cdrJSmLNajrDtklMl++s7LZ+Z8ZV+1wLCBzL/AEbbEmVMFI5Wl5CEZM l/xjmBbwuP4AsHpwNgfPK7CikBBVY2w+Ke0F/mW4ZL5BWyc6BWsKbys/h+3blrfo2cGZ DUVQM9To7QGg6KzkgOUZKeCVuovMDctIQrOiTzt72M0tt8POd/JbRXF8um/D9f7nb2KC Dq9A== X-Gm-Message-State: AOAM5320tOz6msry/B20zFSakysGNz9848DZXNA75fa3RUDz4z9LiuwI UF7rdJJOHEPftiC3Jdueo0ztnEAW/xLKVYF5b/boLtyGeg+mE2XGyS2WwVH3H2Q2E76Bd8sxpdt sS7RCB5Un4nNDF8etbwmOlTUjQacRH/Usaaxe2kPwSWTB0QcTjAb5Vf5oiMb1 X-Received: by 2002:adf:a302:: with SMTP id c2mr833660wrb.212.1616453997354; Mon, 22 Mar 2021 15:59:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXlFiMnvLYdab8pPcOXb+/G1FxDQ0BM5Gatuk+fKo29jYA5dTW33zzIhJuIwdTKqI4R6oQwQ== X-Received: by 2002:adf:a302:: with SMTP id c2mr833644wrb.212.1616453997196; Mon, 22 Mar 2021 15:59:57 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id u2sm997328wmm.5.2021.03.22.15.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 15:59:56 -0700 (PDT) Date: Mon, 22 Mar 2021 18:59:55 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 01/19] virtio: Fix virtio_mmio_read()/virtio_mmio_write() Message-ID: <20210322225907.541943-2-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Laurent Vivier , Stefano Garzarella Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier Both functions don't check the personality of the interface (legacy or modern) before accessing the configuration memory and always use virtio_config_readX()/virtio_config_writeX(). With this patch, they now check the personality and in legacy mode call virtio_config_readX()/virtio_config_writeX(), otherwise call virtio_config_modern_readX()/virtio_config_modern_writeX(). This change has been tested with virtio-mmio guests (virt stretch/armhf and virt sid/m68k) and virtio-pci guests (pseries RHEL-7.3/ppc64 and /ppc64le). Signed-off-by: Laurent Vivier Message-Id: <20210314200300.3259170-1-laurent@vivier.eu> Reviewed-by: Stefano Garzarella Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mmio.c | 74 +++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 6990b9879c..342c918ea7 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -112,15 +112,28 @@ static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size) if (offset >= VIRTIO_MMIO_CONFIG) { offset -= VIRTIO_MMIO_CONFIG; - switch (size) { - case 1: - return virtio_config_readb(vdev, offset); - case 2: - return virtio_config_readw(vdev, offset); - case 4: - return virtio_config_readl(vdev, offset); - default: - abort(); + if (proxy->legacy) { + switch (size) { + case 1: + return virtio_config_readb(vdev, offset); + case 2: + return virtio_config_readw(vdev, offset); + case 4: + return virtio_config_readl(vdev, offset); + default: + abort(); + } + } else { + switch (size) { + case 1: + return virtio_config_modern_readb(vdev, offset); + case 2: + return virtio_config_modern_readw(vdev, offset); + case 4: + return virtio_config_modern_readl(vdev, offset); + default: + abort(); + } } } if (size != 4) { @@ -245,20 +258,37 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, if (offset >= VIRTIO_MMIO_CONFIG) { offset -= VIRTIO_MMIO_CONFIG; - switch (size) { - case 1: - virtio_config_writeb(vdev, offset, value); - break; - case 2: - virtio_config_writew(vdev, offset, value); - break; - case 4: - virtio_config_writel(vdev, offset, value); - break; - default: - abort(); + if (proxy->legacy) { + switch (size) { + case 1: + virtio_config_writeb(vdev, offset, value); + break; + case 2: + virtio_config_writew(vdev, offset, value); + break; + case 4: + virtio_config_writel(vdev, offset, value); + break; + default: + abort(); + } + return; + } else { + switch (size) { + case 1: + virtio_config_modern_writeb(vdev, offset, value); + break; + case 2: + virtio_config_modern_writew(vdev, offset, value); + break; + case 4: + virtio_config_modern_writel(vdev, offset, value); + break; + default: + abort(); + } + return; } - return; } if (size != 4) { qemu_log_mask(LOG_GUEST_ERROR, From patchwork Mon Mar 22 22:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=O6UbKEk1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49CJ35SQz9sTD for ; Tue, 23 Mar 2021 10:08:12 +1100 (AEDT) Received: from localhost ([::1]:42880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTec-0005FH-C5 for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:08:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWp-0006k2-T4 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWn-00016W-IK for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454003; 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=6vu1+ACkXCKQbE27Tv6eHhaq4c2H7x25sMTUeP1pT0c=; b=O6UbKEk11Ol5vBtsB8y3p7ySv7nzk+rjFJSe9aGRieT3fBcDxaNIT99xAGY3iNkCWj0j8k bwp4SA/ffwNDXnsD/O9tlvT7xsBBLk8LY9+YhpVNeNANzoA6xVU2oxxIvwB1zkdVxu1Ju2 Zr34/6TxG9v2n7nMehbzVGY/UnkmDQU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-124-eI8g3IfcOjG-M7SSBNBweg-1; Mon, 22 Mar 2021 19:00:01 -0400 X-MC-Unique: eI8g3IfcOjG-M7SSBNBweg-1 Received: by mail-wr1-f69.google.com with SMTP id p12so142819wrn.18 for ; Mon, 22 Mar 2021 16:00:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6vu1+ACkXCKQbE27Tv6eHhaq4c2H7x25sMTUeP1pT0c=; b=EsbfFtoRSgTct/wD2UjZOfKIpEQcFugmbPBdbh9lRhO098fiqne8J87+eQuxUAgS9f 6EdT7Fw+nMOWkFdUEPMsfC3YHyuq5udQQG6eHxzrDxIMJ2ZDyKDnL513FuTx/Xp7btZ2 AH0vXaQany6xLq0tozcR93WcAb8PAodzSZStEXIhJPrmNujeLJA/WuNdQbxSiSZT4lWr MXzUm2dmIXlmVxC5VdhL3576UvQjSgTmuJWUWGgcTtdD1gvY3eOMIm3C5GNbcC2v1FE0 BCeh7qIqky+kFZlZqSRIq59e1if++dSzEg0mZPpbFqL8wMJNWvi94DtdOr6OlDLArRB/ PyOg== X-Gm-Message-State: AOAM531Tx7EAiAQhOXhhul1WqXR56PWQnXcgr1Ef+q0qXhNsQvj5GKDN O8lMhXLND/YfvN3/2ffqv20yOZPnSowJVXohaS3GAw8kd9dkNPCYIWYUKlGmUIksfUSC4IAs7sp Zvb+Il4h4t2H5uFt/E49T5koEZ7B7bll4bKQWqnVs9FqfQ57sG1LiyPY6yPRB X-Received: by 2002:adf:c3c8:: with SMTP id d8mr795132wrg.167.1616453999806; Mon, 22 Mar 2021 15:59:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHGhLUmWcq/ug6RwdlhBfK2TJItj1VxXC6X+IBM6xzL5bLZUYACwiNcUbflEtVZNV6JSjzfg== X-Received: by 2002:adf:c3c8:: with SMTP id d8mr795120wrg.167.1616453999659; Mon, 22 Mar 2021 15:59:59 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id k13sm12079566wri.27.2021.03.22.15.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 15:59:59 -0700 (PDT) Date: Mon, 22 Mar 2021 18:59:57 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 02/19] vhost-user: Drop misleading EAGAIN checks in slave_read() Message-ID: <20210322225907.541943-3-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz slave_read() checks EAGAIN when reading or writing to the socket fails. This gives the impression that the slave channel is in non-blocking mode, which is certainly not the case with the current code base. And the rest of the code isn't actually ready to cope with non-blocking I/O. Just drop the checks everywhere in this function for the sake of clarity. Signed-off-by: Greg Kurz Message-Id: <20210312092212.782255-2-groug@kaod.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 2fdd5daf74..6af9b43a72 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1420,7 +1420,7 @@ static void slave_read(void *opaque) do { size = recvmsg(u->slave_fd, &msgh, 0); - } while (size < 0 && (errno == EINTR || errno == EAGAIN)); + } while (size < 0 && errno == EINTR); if (size != VHOST_USER_HDR_SIZE) { error_report("Failed to read from slave."); @@ -1452,7 +1452,7 @@ static void slave_read(void *opaque) /* Read payload */ do { size = read(u->slave_fd, &payload, hdr.size); - } while (size < 0 && (errno == EINTR || errno == EAGAIN)); + } while (size < 0 && errno == EINTR); if (size != hdr.size) { error_report("Failed to read payload from slave."); @@ -1503,7 +1503,7 @@ static void slave_read(void *opaque) do { size = writev(u->slave_fd, iovec, ARRAY_SIZE(iovec)); - } while (size < 0 && (errno == EINTR || errno == EAGAIN)); + } while (size < 0 && errno == EINTR); if (size != VHOST_USER_HDR_SIZE + hdr.size) { error_report("Failed to send msg reply to slave."); From patchwork Mon Mar 22 22:59:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=I2+q6aLW; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49394nYjz9sTD for ; Tue, 23 Mar 2021 10:01:09 +1100 (AEDT) Received: from localhost ([::1]:55632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTXn-0006rc-Lp for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:01:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWs-0006lU-Ed for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWp-00017Y-I2 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454005; 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=/f4sPKYnR+jmUvWYKdHqcmtAZpHXplnd+zjl3HCMvLg=; b=I2+q6aLW+zNgO2xsTJ/NVQyBEkjf2Btv+kNYJvT7xHeVVXxmXStGWNc1rFBlQED+mp5Pzk miLr02+h5umrCR9jLUoGujnfJbe7WtsWJH4Z959F46iDHPLe40zKhPkB1msXVKpdhKqQXq 0udshFxgs9aG0r6cu6K4w43vRP72UJc= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-YfDodTdgMnWVeQhoQ8rS1Q-1; Mon, 22 Mar 2021 19:00:03 -0400 X-MC-Unique: YfDodTdgMnWVeQhoQ8rS1Q-1 Received: by mail-wr1-f71.google.com with SMTP id p15so146506wre.13 for ; Mon, 22 Mar 2021 16:00:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/f4sPKYnR+jmUvWYKdHqcmtAZpHXplnd+zjl3HCMvLg=; b=Gxr3UcFx2tBoNvYg/vWmCJ6+ed2sBgrANtp9oPtC+lsfbSNPPPAj5h9jyen21VXHO8 tc9n6grlnQpJ/InSK+uVDBfkrTvD09OAO3c4DuT4l+be4VCI/4kU3LR8NiIjdfdps86u pelnUx1M+GlYOTMr6x2fb8RJvbTTGcqrAJjH4qK5Nhuffqz/DEnsoetEk2r60pWlP9f5 pQe0zIkzHX8YtgpRXOjIHOBSHsSZNt1t9i1+pNi7Gkf+yN8JKuXsDVNXKDMePnj9Kgcu yOgkD3p3b2bdQV5tTHfKjw4XBzKWRD4+x62koOm//sxlKUULgfRlhAsxrV9+qHmaQreo yTYQ== X-Gm-Message-State: AOAM531GbVuvm6hoqJa7/GjSHDIIQqhuHRwCr8mpD/O0UwStc+Gaz4oG JyLhC5ErqUPwz1w5U+N67JFdP8lUiOijSkl05rLvg6J3YSedqeu4SoUE3Kajbafe8tjvd9maPRm 2oWVMrBlFBR1PRwv4NlxV7YA2fUC5qk0TcUuCMUwuS5fZ0hjFc4Kgby+Hg7aK X-Received: by 2002:a7b:cd8f:: with SMTP id y15mr576750wmj.185.1616454002138; Mon, 22 Mar 2021 16:00:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmq1n8eU3OQbtAvF31rAUHxo0tI01XhCZNqi3wPGpKsw51axNjjvITZjuOUB1tVfwF9hA2QQ== X-Received: by 2002:a7b:cd8f:: with SMTP id y15mr576729wmj.185.1616454001846; Mon, 22 Mar 2021 16:00:01 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id i3sm22429110wra.66.2021.03.22.16.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:01 -0700 (PDT) Date: Mon, 22 Mar 2021 18:59:59 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 03/19] vhost-user: Fix double-close on slave_read() error path Message-ID: <20210322225907.541943-4-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz Some message types, e.g. VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG, can convey file descriptors. These must be closed before returning from slave_read() to avoid being leaked. This can currently be done in two different places: [1] just after the request has been processed [2] on the error path, under the goto label err: These path are supposed to be mutually exclusive but they are not actually. If the VHOST_USER_NEED_REPLY_MASK flag was passed and the sending of the reply fails, both [1] and [2] are performed with the same descriptor values. This can potentially cause subtle bugs if one of the descriptor was recycled by some other thread in the meantime. This code duplication complicates rollback for no real good benefit. Do the closing in a unique place, under a new fdcleanup: goto label at the end of the function. Signed-off-by: Greg Kurz Message-Id: <20210312092212.782255-3-groug@kaod.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 6af9b43a72..acde1d2936 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1475,13 +1475,6 @@ static void slave_read(void *opaque) ret = -EINVAL; } - /* Close the remaining file descriptors. */ - for (i = 0; i < fdsize; i++) { - if (fd[i] != -1) { - close(fd[i]); - } - } - /* * REPLY_ACK feature handling. Other reply types has to be managed * directly in their request handlers. @@ -1511,12 +1504,14 @@ static void slave_read(void *opaque) } } - return; + goto fdcleanup; err: qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); close(u->slave_fd); u->slave_fd = -1; + +fdcleanup: for (i = 0; i < fdsize; i++) { if (fd[i] != -1) { close(fd[i]); From patchwork Mon Mar 22 23:00:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=Jbiv3vhp; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49FV3rnTz9sTD for ; Tue, 23 Mar 2021 10:10:06 +1100 (AEDT) Received: from localhost ([::1]:49974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTgS-0008Gb-IQ for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWu-0006nt-5H for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lOTWs-00018g-BP for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454009; 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=OODRMeLBe2YwGT9N6jsblOs6YEuAMEZWHaowpQ1bt8o=; b=Jbiv3vhp5DwwWJhbam8sH7q4UJ5B25O6ZnbiQm1pscgx0kCio2iNxXHPnJGlvNKraOCiXw OOMRLXJncFBnq5+cUB3dVhbWU0HL/vdGI46Fh3OmH2BYcSv3dd4qIua7B2OUsZEzoR3unP 1Ow0E5Apk7CDHgixIFopVA8vecm1cDI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-OHcAtKITP9KZCzSX2T1uwg-1; Mon, 22 Mar 2021 19:00:05 -0400 X-MC-Unique: OHcAtKITP9KZCzSX2T1uwg-1 Received: by mail-wr1-f69.google.com with SMTP id h30so149962wrh.10 for ; Mon, 22 Mar 2021 16:00:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OODRMeLBe2YwGT9N6jsblOs6YEuAMEZWHaowpQ1bt8o=; b=S7IQDesU7v8knM3Ty31f9vYEhRWoLjK24EBxNAWtsfmOUMwUp/Rf9FpYEs2aimFJDN mqPUSTLAUkO/8vQiFgI5orvMEkEdyUmZZxpnPypoqHvfpFeOrShYXgw8VfzwNRBiHdC4 X75cMQqV0VB8YHQtMTy4qnhukiUsMxeAYZ8T1RmpmAZkADHPHAhhgU1ngF2TFcm69h79 ZDxUc4xUtqatV8wxwunz9ad3Ozw51eFPKOFEIHg4Bzvu+MtqmFpyOTAZc4CSx6G/aINQ 5FDlGe5TD4k1QZGNOQXvbGDoKb+5U+nJiEU22QS9cGXuy3N3kTmzc5m/O/cNi2avPPxs k0ZA== X-Gm-Message-State: AOAM533zX3rXIrGT9tlsCUpS3ALrn8b4BJdYvP/g8PfbcdXNGFHgVORg BfrXcACE9IZ0pCZNq3qFCwiqjJXMmzbllY3tqHH+WpG9avIZEwlkem+izBgEoaGCIFrZ/2avTPr NynHDaqvou3lImG0WH2Y7099tpfyn9bzYTc62bR83wT08TREhMsXE+6DRydJF X-Received: by 2002:a05:6000:18ab:: with SMTP id b11mr766797wri.403.1616454004293; Mon, 22 Mar 2021 16:00:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCxH5YsEPfS2KT/lwooIUGagW1phE4FdvsJoxiNgTUnMhgUe1xEtuOY19lw2Cmt3B0HG8GMA== X-Received: by 2002:a05:6000:18ab:: with SMTP id b11mr766774wri.403.1616454004032; Mon, 22 Mar 2021 16:00:04 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id c11sm22316286wrm.67.2021.03.22.16.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:03 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:01 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 04/19] vhost-user: Factor out duplicated slave_fd teardown code Message-ID: <20210322225907.541943-5-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz Signed-off-by: Greg Kurz Message-Id: <20210312092212.782255-4-groug@kaod.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index acde1d2936..cb0c98f30a 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1392,6 +1392,13 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev, return 0; } +static void close_slave_channel(struct vhost_user *u) +{ + qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); + close(u->slave_fd); + u->slave_fd = -1; +} + static void slave_read(void *opaque) { struct vhost_dev *dev = opaque; @@ -1507,9 +1514,7 @@ static void slave_read(void *opaque) goto fdcleanup; err: - qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); - close(u->slave_fd); - u->slave_fd = -1; + close_slave_channel(u); fdcleanup: for (i = 0; i < fdsize; i++) { @@ -1560,9 +1565,7 @@ static int vhost_setup_slave_channel(struct vhost_dev *dev) out: close(sv[1]); if (ret) { - qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); - close(u->slave_fd); - u->slave_fd = -1; + close_slave_channel(u); } return ret; @@ -1915,9 +1918,7 @@ static int vhost_user_backend_cleanup(struct vhost_dev *dev) u->postcopy_fd.handler = NULL; } if (u->slave_fd >= 0) { - qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); - close(u->slave_fd); - u->slave_fd = -1; + close_slave_channel(u); } g_free(u->region_rb); u->region_rb = NULL; From patchwork Mon Mar 22 23:00:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=OyhFm/Q9; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49421MvQz9sTD for ; Tue, 23 Mar 2021 10:01:54 +1100 (AEDT) Received: from localhost ([::1]:56776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTYW-0007Wb-5Y for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:01:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWu-0006oJ-KL for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWs-000191-GA for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454009; 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=3wfKO2rZFFtkKy5CCLD/ZROT2nv5W2q7ph4quX8YOEw=; b=OyhFm/Q92Sr4JnTThRsN/tXEYgQi54vNGNtQkeErnqF7T05dcPZtaOO1MdERApnq7j6wgx UHUH2Fhi6uE+L7jaXAb79SBThEQMDFYhut8UaKFooFCzYUkY5QgAaZWai/ijyX3WR7ERH7 OrnoBhMhzZxl2OawAEebsWnVG+0WXmQ= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-Tv3uYvQYMEWpQppsG03mZQ-1; Mon, 22 Mar 2021 19:00:08 -0400 X-MC-Unique: Tv3uYvQYMEWpQppsG03mZQ-1 Received: by mail-wr1-f72.google.com with SMTP id n16so161608wro.1 for ; Mon, 22 Mar 2021 16:00:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3wfKO2rZFFtkKy5CCLD/ZROT2nv5W2q7ph4quX8YOEw=; b=G0E2Su6DJoaN34N0dcvltZuLc+Dw7tS08cgx2A8rzGG6ZhPO6iChBC3XRkt9pqZ4zD w4/gzb8G05FbYr579qEhP7fWJcPG4Rr2Uk9bJ/M+cCpEWOE3aoz1Ws54uIQQgO2Py05h Zut8QZk8LmbIfQHSCTtFWDaMoS2O4vTo8FZEjp7DiijAwb9cQ5z1qdmgWswnU81zJXIB SiYayjoYtCGTOE91r4fth49ZrxBp/7lRBl9H6u1+YCMFYBcYrWKirOlG9vsTQcTBToVh i66iwcFqdLu7lVF2fTHW+neEHoBDRYDRFrC0twIPwnqx0lSw4LtMqZvZFy3gfJVh7CJd dKug== X-Gm-Message-State: AOAM533XOPPJCrU+127gE1Rgjc1F6umDuL4P7JQid428vmio19XWf3Cr Tb9zOeGNVsYoGfZzvIBHorX0RsNdkxdYWr06AUdxgr9ydp3FvSMvKJyQZWvMsa1dqcd+UeGacSI XMyXWio0Mholi7WgnFMWHs7wqjn6QSiIRowek2JOCvqOZGNlfGUfW7K/NkYBb X-Received: by 2002:a05:6000:1819:: with SMTP id m25mr798012wrh.169.1616454006449; Mon, 22 Mar 2021 16:00:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzClUwzadQI5LovqvXN0p3CDwRuyVRGu7iUzPeUuvgSzAMHqYFjfpCGPE6q5z5C0LTipl+CkA== X-Received: by 2002:a05:6000:1819:: with SMTP id m25mr797995wrh.169.1616454006226; Mon, 22 Mar 2021 16:00:06 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id p16sm25452025wrt.54.2021.03.22.16.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:05 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:04 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 05/19] vhost-user: Convert slave channel to QIOChannelSocket Message-ID: <20210322225907.541943-6-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz The slave channel is implemented with socketpair() : QEMU creates the pair, passes one of the socket to virtiofsd and monitors the other one with the main event loop using qemu_set_fd_handler(). In order to fix a potential deadlock between QEMU and a vhost-user external process (e.g. virtiofsd with DAX), we want to be able to monitor and service the slave channel while handling vhost-user requests. Prepare ground for this by converting the slave channel to be a QIOChannelSocket. This will make monitoring of the slave channel as simple as calling qio_channel_add_watch_source(). Since the connection is already established between the two sockets, only incoming I/O (G_IO_IN) and disconnect (G_IO_HUP) need to be serviced. This also allows to get rid of the ancillary data parsing since QIOChannelSocket can do this for us. Note that the MSG_CTRUNC check is dropped on the way because QIOChannelSocket ignores this case. This isn't a problem since slave_read() provisions space for 8 file descriptors, but affected vhost-user slave protocol messages generally only convey one. If for some reason a buggy implementation passes more file descriptors, no need to break the connection, just like we don't break it if some other type of ancillary data is received : this isn't explicitely violating the protocol per-se so it seems better to ignore it. The current code errors out on short reads and writes. Use the qio_channel_*_all() variants to address this on the way. Signed-off-by: Greg Kurz Message-Id: <20210312092212.782255-5-groug@kaod.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 99 +++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 60 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index cb0c98f30a..3c1e1611b0 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -16,6 +16,7 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-net.h" #include "chardev/char-fe.h" +#include "io/channel-socket.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" @@ -237,7 +238,8 @@ struct vhost_user { struct vhost_dev *dev; /* Shared between vhost devs of the same virtio device */ VhostUserState *user; - int slave_fd; + QIOChannel *slave_ioc; + GSource *slave_src; NotifierWithReturn postcopy_notifier; struct PostCopyFD postcopy_fd; uint64_t postcopy_client_bases[VHOST_USER_MAX_RAM_SLOTS]; @@ -1394,61 +1396,37 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev, static void close_slave_channel(struct vhost_user *u) { - qemu_set_fd_handler(u->slave_fd, NULL, NULL, NULL); - close(u->slave_fd); - u->slave_fd = -1; + g_source_destroy(u->slave_src); + g_source_unref(u->slave_src); + u->slave_src = NULL; + object_unref(OBJECT(u->slave_ioc)); + u->slave_ioc = NULL; } -static void slave_read(void *opaque) +static gboolean slave_read(QIOChannel *ioc, GIOCondition condition, + gpointer opaque) { struct vhost_dev *dev = opaque; struct vhost_user *u = dev->opaque; VhostUserHeader hdr = { 0, }; VhostUserPayload payload = { 0, }; - int size, ret = 0; + Error *local_err = NULL; + gboolean rc = G_SOURCE_CONTINUE; + int ret = 0; struct iovec iov; - struct msghdr msgh; - int fd[VHOST_USER_SLAVE_MAX_FDS]; - char control[CMSG_SPACE(sizeof(fd))]; - struct cmsghdr *cmsg; - int i, fdsize = 0; - - memset(&msgh, 0, sizeof(msgh)); - msgh.msg_iov = &iov; - msgh.msg_iovlen = 1; - msgh.msg_control = control; - msgh.msg_controllen = sizeof(control); - - memset(fd, -1, sizeof(fd)); + g_autofree int *fd = NULL; + size_t fdsize = 0; + int i; /* Read header */ iov.iov_base = &hdr; iov.iov_len = VHOST_USER_HDR_SIZE; - do { - size = recvmsg(u->slave_fd, &msgh, 0); - } while (size < 0 && errno == EINTR); - - if (size != VHOST_USER_HDR_SIZE) { - error_report("Failed to read from slave."); + if (qio_channel_readv_full_all(ioc, &iov, 1, &fd, &fdsize, &local_err)) { + error_report_err(local_err); goto err; } - if (msgh.msg_flags & MSG_CTRUNC) { - error_report("Truncated message."); - goto err; - } - - for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msgh, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_RIGHTS) { - fdsize = cmsg->cmsg_len - CMSG_LEN(0); - memcpy(fd, CMSG_DATA(cmsg), fdsize); - break; - } - } - if (hdr.size > VHOST_USER_PAYLOAD_SIZE) { error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", hdr.size, @@ -1457,12 +1435,8 @@ static void slave_read(void *opaque) } /* Read payload */ - do { - size = read(u->slave_fd, &payload, hdr.size); - } while (size < 0 && errno == EINTR); - - if (size != hdr.size) { - error_report("Failed to read payload from slave."); + if (qio_channel_read_all(ioc, (char *) &payload, hdr.size, &local_err)) { + error_report_err(local_err); goto err; } @@ -1475,7 +1449,7 @@ static void slave_read(void *opaque) break; case VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG: ret = vhost_user_slave_handle_vring_host_notifier(dev, &payload.area, - fd[0]); + fd ? fd[0] : -1); break; default: error_report("Received unexpected msg type: %d.", hdr.request); @@ -1501,12 +1475,8 @@ static void slave_read(void *opaque) iovec[1].iov_base = &payload; iovec[1].iov_len = hdr.size; - do { - size = writev(u->slave_fd, iovec, ARRAY_SIZE(iovec)); - } while (size < 0 && errno == EINTR); - - if (size != VHOST_USER_HDR_SIZE + hdr.size) { - error_report("Failed to send msg reply to slave."); + if (qio_channel_writev_all(ioc, iovec, ARRAY_SIZE(iovec), &local_err)) { + error_report_err(local_err); goto err; } } @@ -1515,14 +1485,15 @@ static void slave_read(void *opaque) err: close_slave_channel(u); + rc = G_SOURCE_REMOVE; fdcleanup: - for (i = 0; i < fdsize; i++) { - if (fd[i] != -1) { + if (fd) { + for (i = 0; i < fdsize; i++) { close(fd[i]); } } - return; + return rc; } static int vhost_setup_slave_channel(struct vhost_dev *dev) @@ -1535,6 +1506,8 @@ static int vhost_setup_slave_channel(struct vhost_dev *dev) int sv[2], ret = 0; bool reply_supported = virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_REPLY_ACK); + Error *local_err = NULL; + QIOChannel *ioc; if (!virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_SLAVE_REQ)) { @@ -1546,8 +1519,15 @@ static int vhost_setup_slave_channel(struct vhost_dev *dev) return -1; } - u->slave_fd = sv[0]; - qemu_set_fd_handler(u->slave_fd, slave_read, NULL, dev); + ioc = QIO_CHANNEL(qio_channel_socket_new_fd(sv[0], &local_err)); + if (!ioc) { + error_report_err(local_err); + return -1; + } + u->slave_ioc = ioc; + u->slave_src = qio_channel_add_watch_source(u->slave_ioc, + G_IO_IN | G_IO_HUP, + slave_read, dev, NULL, NULL); if (reply_supported) { msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK; @@ -1802,7 +1782,6 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque) u = g_new0(struct vhost_user, 1); u->user = opaque; - u->slave_fd = -1; u->dev = dev; dev->opaque = u; @@ -1917,7 +1896,7 @@ static int vhost_user_backend_cleanup(struct vhost_dev *dev) close(u->postcopy_fd.fd); u->postcopy_fd.handler = NULL; } - if (u->slave_fd >= 0) { + if (u->slave_ioc) { close_slave_channel(u); } g_free(u->region_rb); From patchwork Mon Mar 22 23:00:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=Emq1Wa7F; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49JH0x50z9sTD for ; Tue, 23 Mar 2021 10:12:31 +1100 (AEDT) Received: from localhost ([::1]:55690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTin-0002JI-4e for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:12:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWy-0006tb-Cu for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWv-0001AM-7o for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454012; 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=6xWs/CEw54bPeKwwY9J/GoUWPgYTmmSzfK7BGIvIz68=; b=Emq1Wa7F+rpMHYI7tGbZXgGLAJyUZmgGCeOnJKsKmMBFZWY1uqKzna9i8tehEEhsD/a0w5 1X5LiYu1TRfkAzxs37FG/2UevJslRUlw4cjBN0Dtb5lgh3HdtRGyPqKNRLqGRTxFXBPuj8 6uq9jB3hE8Byx0DO226A9pJ7vziPpOk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-gMPqw64AO2GWwAgwH5Vaow-1; Mon, 22 Mar 2021 19:00:10 -0400 X-MC-Unique: gMPqw64AO2GWwAgwH5Vaow-1 Received: by mail-wr1-f71.google.com with SMTP id p12so143048wrn.18 for ; Mon, 22 Mar 2021 16:00:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6xWs/CEw54bPeKwwY9J/GoUWPgYTmmSzfK7BGIvIz68=; b=QoI1AUPqiHs7F91AYYzCJ4qmbKIl+Fk9nm6DvSOQ3P/O2rC4V7DTRQFW5sGquEqv1a mMus75eSPNomCLv6Ab72MyDZoDwnZ1aR9S/1pKXpz/Z/67h01LpRK58uirFyUJ0mcZEa OC1MOnFGoNSgCOYydJqYQsQukY+g1+bqou3pK9xvTKTeYAgC/F6O4Im/StHzVH49tzJM sEhBUARZYjKFYTH6B/TwKFZ22iJb+2/CnlwK+zbemTdYBccjhsfpoUFO7kyrtf766pxm NSDO0cvDCkF7kkKp2vw8WWfmpcnJQYCGx7TLDyYyi2FdsgHOL3SSORFUy/rWZ0OYH8Eo a52w== X-Gm-Message-State: AOAM532xlm1uPplV6ptIt6gyUoqrqgcpBz2dnh/37KCt3z+rtAXPPzNO fCqvh8ONErgzOMSU04abGeNAkqrazChYkguuChBwyXJXZlmJLz2xDwOHql6mJxkvak/47bVaUGT PuDvpRyd3SL4igG9SrI14sk/a74cq2k7/1wcflHzkpzLJMJCUjTYQxk0PvI3d X-Received: by 2002:a5d:6c67:: with SMTP id r7mr778619wrz.373.1616454008434; Mon, 22 Mar 2021 16:00:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv4seyXaTA3AwjNj674rEqTLE5mUarKiBJ+pVt8OA085kb+zButkYQnaFJb0RXWmniBMSGKg== X-Received: by 2002:a5d:6c67:: with SMTP id r7mr778601wrz.373.1616454008220; Mon, 22 Mar 2021 16:00:08 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id b15sm10604534wrx.73.2021.03.22.16.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:07 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:06 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 06/19] vhost-user: Introduce nested event loop in vhost_user_read() Message-ID: <20210322225907.541943-7-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz A deadlock condition potentially exists if a vhost-user process needs to request something to QEMU on the slave channel while processing a vhost-user message. This doesn't seem to affect any vhost-user implementation so far, but this is currently biting the upcoming enablement of DAX with virtio-fs. The issue is being observed when the guest does an emergency reboot while a mapping still exits in the DAX window, which is very easy to get with a busy enough workload (e.g. as simulated by blogbench [1]) : - QEMU sends VHOST_USER_GET_VRING_BASE to virtiofsd. - In order to complete the request, virtiofsd then asks QEMU to remove the mapping on the slave channel. All these dialogs are synchronous, hence the deadlock. As pointed out by Stefan Hajnoczi: When QEMU's vhost-user master implementation sends a vhost-user protocol message, vhost_user_read() does a "blocking" read during which slave_fd is not monitored by QEMU. The natural solution for this issue is an event loop. The main event loop cannot be nested though since we have no guarantees that its fd handlers are prepared for re-entrancy. Introduce a new event loop that only monitors the chardev I/O for now in vhost_user_read() and push the actual reading to a one-shot handler. A subsequent patch will teach the loop to monitor and process messages from the slave channel as well. [1] https://github.com/jedisct1/Blogbench Suggested-by: Stefan Hajnoczi Signed-off-by: Greg Kurz Message-Id: <20210312092212.782255-6-groug@kaod.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 65 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 3c1e1611b0..00256fa318 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -296,15 +296,27 @@ static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) return 0; } -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +struct vhost_user_read_cb_data { + struct vhost_dev *dev; + VhostUserMsg *msg; + GMainLoop *loop; + int ret; +}; + +static gboolean vhost_user_read_cb(GIOChannel *source, GIOCondition condition, + gpointer opaque) { + struct vhost_user_read_cb_data *data = opaque; + struct vhost_dev *dev = data->dev; + VhostUserMsg *msg = data->msg; struct vhost_user *u = dev->opaque; CharBackend *chr = u->user->chr; uint8_t *p = (uint8_t *) msg; int r, size; if (vhost_user_read_header(dev, msg) < 0) { - return -1; + data->ret = -1; + goto end; } /* validate message size is sane */ @@ -312,7 +324,8 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->hdr.size, VHOST_USER_PAYLOAD_SIZE); - return -1; + data->ret = -1; + goto end; } if (msg->hdr.size) { @@ -322,11 +335,53 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg payload." " Read %d instead of %d.", r, msg->hdr.size); - return -1; + data->ret = -1; + goto end; } } - return 0; +end: + g_main_loop_quit(data->loop); + return G_SOURCE_REMOVE; +} + +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +{ + struct vhost_user *u = dev->opaque; + CharBackend *chr = u->user->chr; + GMainContext *prev_ctxt = chr->chr->gcontext; + GMainContext *ctxt = g_main_context_new(); + GMainLoop *loop = g_main_loop_new(ctxt, FALSE); + struct vhost_user_read_cb_data data = { + .dev = dev, + .loop = loop, + .msg = msg, + .ret = 0 + }; + + /* + * We want to be able to monitor the slave channel fd while waiting + * for chr I/O. This requires an event loop, but we can't nest the + * one to which chr is currently attached : its fd handlers might not + * be prepared for re-entrancy. So we create a new one and switch chr + * to use it. + */ + qemu_chr_be_update_read_handlers(chr->chr, ctxt); + qemu_chr_fe_add_watch(chr, G_IO_IN | G_IO_HUP, vhost_user_read_cb, &data); + + g_main_loop_run(loop); + + /* + * Restore the previous event loop context. This also destroys/recreates + * event sources : this guarantees that all pending events in the original + * context that have been processed by the nested loop are purged. + */ + qemu_chr_be_update_read_handlers(chr->chr, prev_ctxt); + + g_main_loop_unref(loop); + g_main_context_unref(ctxt); + + return data.ret; } static int process_message_reply(struct vhost_dev *dev, From patchwork Mon Mar 22 23:00:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=TuY5FvYw; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F497Q49vHz9sTD for ; Tue, 23 Mar 2021 10:04:50 +1100 (AEDT) Received: from localhost ([::1]:36684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTbM-0002YS-Hg for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:04:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWy-0006u2-Mi for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lOTWw-0001BC-QR for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454014; 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=nQQq4fHiGykQygfi1oKmBz5Z/Rv0I+HheOSqIDO6h3I=; b=TuY5FvYwpRCOYLAwzX0CSktYIdFDWTGYwl5ANd98nNQJai5/EvEDPkY5kndnfGnF57bcvh wQmYZHWrYVyvJm0BRqp0BqU6Mro5alxqt4YUvwMS+U5wmA1ofEoiSg3ZPvNymMy6eol/N0 kqSwC1I6/eaUWCeubpQRxX3cHivpVhQ= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-Rs81GhhcN3GTbysF3gU4Xw-1; Mon, 22 Mar 2021 19:00:12 -0400 X-MC-Unique: Rs81GhhcN3GTbysF3gU4Xw-1 Received: by mail-wr1-f72.google.com with SMTP id x9so150298wro.9 for ; Mon, 22 Mar 2021 16:00:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=nQQq4fHiGykQygfi1oKmBz5Z/Rv0I+HheOSqIDO6h3I=; b=luB4REoGXIZ3Cps5033VuY/4jPksyQKaiTPr47PYU3gZnDVs5npTjuNc8pjbj+YXO6 zy2vG8zAAmoBc/A6JeEcnolNUKt5slvHvvBq8SyM1cWGxNS/d5VGHHpbgL1jqKhFYXBe ruAZ1aaZnLDBZX7JrGCJ239bGr0uHP3gQEKLF0DaBImflpTHGEj3ipjN470H7e1mxV1S oHdldemkGug9YmGkxgWeob9pC7gNBF2O8wHarFm/EULbZgMBhMrSHXN2QpIAZ4g/6Cao NDyXXZjZHDYvU6vCpxSljdPXModpj114TcNrzLW6zDYpm7ch3qxGSf/qLr2PbxM+GkCO 98cA== X-Gm-Message-State: AOAM530He++XfZzZQPAHOcAIEEJEZCj+i3AnwiW8AzlrPimN4Yf9jF6+ 9vn7t5r/y1lIXUkS7UrGVZnxzcrino329g2LZ9WfrHLNcr6Lra6yoQnF57AcPHK/bslOCtP17/M vOjzBAfAMIIYO6T8wERHNrxzsxjl6QWBpgRY0AUWgNLuQLtoOlMzUUD5qBycj X-Received: by 2002:a05:600c:1548:: with SMTP id f8mr582538wmg.81.1616454010826; Mon, 22 Mar 2021 16:00:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxHPT4pWG7HeQh3lhzsaUfK5/+F+e4KssYRxcUMgk3fkRwXCjb2XaRGfxRV+c5H5b8E04FGQ== X-Received: by 2002:a05:600c:1548:: with SMTP id f8mr582517wmg.81.1616454010591; Mon, 22 Mar 2021 16:00:10 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id v14sm20516842wrd.48.2021.03.22.16.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:10 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:08 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 07/19] vhost-user: Monitor slave channel in vhost_user_read() Message-ID: <20210322225907.541943-8-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz Now that everything is in place, have the nested event loop to monitor the slave channel. The source in the main event loop is destroyed and recreated to ensure any pending even for the slave channel that was previously detected is purged. This guarantees that the main loop wont invoke slave_read() based on an event that was already handled by the nested loop. Signed-off-by: Greg Kurz Message-Id: <20210312092212.782255-7-groug@kaod.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/virtio/vhost-user.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 00256fa318..ded0c10453 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -345,6 +345,35 @@ end: return G_SOURCE_REMOVE; } +static gboolean slave_read(QIOChannel *ioc, GIOCondition condition, + gpointer opaque); + +/* + * This updates the read handler to use a new event loop context. + * Event sources are removed from the previous context : this ensures + * that events detected in the previous context are purged. They will + * be re-detected and processed in the new context. + */ +static void slave_update_read_handler(struct vhost_dev *dev, + GMainContext *ctxt) +{ + struct vhost_user *u = dev->opaque; + + if (!u->slave_ioc) { + return; + } + + if (u->slave_src) { + g_source_destroy(u->slave_src); + g_source_unref(u->slave_src); + } + + u->slave_src = qio_channel_add_watch_source(u->slave_ioc, + G_IO_IN | G_IO_HUP, + slave_read, dev, NULL, + ctxt); +} + static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u = dev->opaque; @@ -366,6 +395,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) * be prepared for re-entrancy. So we create a new one and switch chr * to use it. */ + slave_update_read_handler(dev, ctxt); qemu_chr_be_update_read_handlers(chr->chr, ctxt); qemu_chr_fe_add_watch(chr, G_IO_IN | G_IO_HUP, vhost_user_read_cb, &data); @@ -377,6 +407,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) * context that have been processed by the nested loop are purged. */ qemu_chr_be_update_read_handlers(chr->chr, prev_ctxt); + slave_update_read_handler(dev, NULL); g_main_loop_unref(loop); g_main_context_unref(ctxt); @@ -1580,9 +1611,7 @@ static int vhost_setup_slave_channel(struct vhost_dev *dev) return -1; } u->slave_ioc = ioc; - u->slave_src = qio_channel_add_watch_source(u->slave_ioc, - G_IO_IN | G_IO_HUP, - slave_read, dev, NULL, NULL); + slave_update_read_handler(dev, NULL); if (reply_supported) { msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK; From patchwork Mon Mar 22 23:00:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JprzvDlr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49Ch04Fcz9sTD for ; Tue, 23 Mar 2021 10:08:31 +1100 (AEDT) Received: from localhost ([::1]:44914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTew-000664-17 for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:08:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX1-0006ys-Ac for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTWz-0001CU-KD for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454017; 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=vJdnuz4O5jTyvKH1AcU41+VrJbgX4Tt2CgNqnbi0l3s=; b=JprzvDlrLv/1pBkCbQfgiF/iexu+cM+yq6KsIruSaBTDeKnWzOAP3US3+Dgd0bL11xh6iu 3GjivIRocldQSgQhsApaJn99yK6mW4hs2Z3HD5mI1F6r6lkMNOXf8DKTuknHHUgMFznbqv bSTWCrptEAUY0Ajj4KoECMOgmm/XSBU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-SYebeE59PASxdYp2Eb-b4Q-1; Mon, 22 Mar 2021 19:00:14 -0400 X-MC-Unique: SYebeE59PASxdYp2Eb-b4Q-1 Received: by mail-wr1-f72.google.com with SMTP id p15so146804wre.13 for ; Mon, 22 Mar 2021 16:00:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vJdnuz4O5jTyvKH1AcU41+VrJbgX4Tt2CgNqnbi0l3s=; b=TxEormLfD5l4uyf1kSi4iXhx6yp2i0+gf6Nc+HGBg9S076oCGZMUN+IbJvE8gT8vmu y6sCDtfZp/YutETzBYh9zlpDZeSGnLHedam2TWZtuZwAdtXx8tQno8jXQfvefQ0Oppw0 G7gSDbBoFqdt6kSd4xscaSJxF0Ll15jeAG6in0F/sGfu8+uaHB9dfdRVXpfkjzsKVI+j 7RMi3lOCE4t2/OH9z4mFGl1qyudH+0JUVhKv2UOQA9O+5RGnz7HqGfQtu51fK1BwnkDB xyUxrtbWMpr6pKo0AjxHmN2L+V67ya+VPYStdMsHBWx/wsGZm58XBKCzdfbKvTq9nkMh dMtQ== X-Gm-Message-State: AOAM532KuLcN7RdC3+fyNY0acujqoWF/cFHRdGAdQskeIts8HdtWnUY3 ZYjAg2OjcNkSyffBGrSXygljQ6IDCK8JqA/2I99nlSZ943BXyNlsDm9hsFOSy1f2ILL9+MIg0zN /6eHq0ivdVEFZUoHvYdtKUj9F23dPAPO/bd4i/jg15Dc9afqoRn11OyZr8uq1 X-Received: by 2002:a05:600c:47d7:: with SMTP id l23mr582439wmo.155.1616454013307; Mon, 22 Mar 2021 16:00:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykrWQpJADG2OTWqKItljcWh2pfv0ofZ/Qvqjg3VTJOl3oTiILRksi6ebGv5HsA6GSt/PzBRQ== X-Received: by 2002:a05:600c:47d7:: with SMTP id l23mr582422wmo.155.1616454013111; Mon, 22 Mar 2021 16:00:13 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id x14sm20450547wrw.13.2021.03.22.16.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:12 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:10 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 08/19] virtio-pmem: fix virtio_pmem_resp assign problem Message-ID: <20210322225907.541943-9-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Wang Liang , David Hildenbrand , Pankaj Gupta , Stefano Garzarella Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Wang Liang ret in virtio_pmem_resp is a uint32_t variable, which should be assigned using virtio_stl_p. The kernel side driver does not guarantee virtio_pmem_resp to be initialized to zero in advance, So sometimes the flush operation will fail. Signed-off-by: Wang Liang Message-Id: <20210317024145.271212-1-wangliangzz@126.com> Reviewed-by: Stefano Garzarella Reviewed-by: David Hildenbrand Reviewed-by: Pankaj Gupta Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-pmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index a3e0688a89..d1aeb90a31 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -47,7 +47,7 @@ static int worker_cb(void *opaque) err = 1; } - virtio_stw_p(req_data->vdev, &req_data->resp.ret, err); + virtio_stl_p(req_data->vdev, &req_data->resp.ret, err); return 0; } From patchwork Mon Mar 22 23:00:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=Lt1E3JDs; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49731T55z9sTD for ; Tue, 23 Mar 2021 10:04:31 +1100 (AEDT) Received: from localhost ([::1]:35348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTb3-00020Y-3g for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:04:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX4-00075g-M8 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX2-0001Dv-U2 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454020; 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=JvOManbKVW60cRwLAfNSDeNnb3glbQKDFfztyXD6vBs=; b=Lt1E3JDszVNtgjY1T7qhtdyRUEVRqR9zHj25kizNVq8SsEBOBy+yyj7W+IDy8f3U2H3r2f sGOj5z1wG3X/FcnGDRwwllKMjYpwT0ckUX0021xNa4lPCnZ+sUTRqFPT5foYJ+kFFocSQ9 i05NQg+pteaQwyj3xHxDwW05ARrFxbM= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-vlRgijupOUu90We1j667ZQ-1; Mon, 22 Mar 2021 19:00:17 -0400 X-MC-Unique: vlRgijupOUu90We1j667ZQ-1 Received: by mail-wm1-f70.google.com with SMTP id z26so171954wml.4 for ; Mon, 22 Mar 2021 16:00:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JvOManbKVW60cRwLAfNSDeNnb3glbQKDFfztyXD6vBs=; b=UUMejm5v50mCJkZHpea8p7n1y9OB/nrH3ESirW2RFtV5G6VIxJifZ7P6uDGi9JRN1f NG+MjhL/jptpRWZNeTjJMCJgW511jzLhtP3sCz8g5sJL/DfFpR450k8vaNTJcq8ns+wX AcuqjJ4Bas+a31Ue/l9Noe+rVFNf1jopneqh82xVx1pj66nAOw/LLGxh2l+/KEfRahiS 9Z/EiaVBs7IWQEl7HGrBrt5pEO1fyr0jh3rliESZEYDvGvAy6k1dt0uG5h2kuyt7u75U hUhmiauE2/KMW5sr0zaO1RACvwPKyp+bv+XpNO82g6uZghF3UGom0MNLA/dBi5rvsw0F j5Hw== X-Gm-Message-State: AOAM53140QzFdK2q1rn1WOowlxbXBzoWC2kxdu5m0d3mX+aoz+rm3y5o V5n+PyLkAQF1yZHja3u2JsHwH2SK6UEunchy/Je1TswaTQGYcn8M8qHbG6If0Ifp8+fimM1AKsc /ET5U45sDGxDByqKZo/ZWa/SttdEp55HkujDrl8M8y5zg88Qdx/U0wCHoncHG X-Received: by 2002:a7b:c10c:: with SMTP id w12mr624410wmi.112.1616454015660; Mon, 22 Mar 2021 16:00:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOcSb1zegdbu/19hB4c4541utruv3md93NinRUFM81GH07q2dbx1ggDmAO6Te6J92N0/wcjw== X-Received: by 2002:a7b:c10c:: with SMTP id w12mr624399wmi.112.1616454015402; Mon, 22 Mar 2021 16:00:15 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id k11sm764791wmj.1.2021.03.22.16.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:15 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:13 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 09/19] tests: acpi: temporary whitelist DSDT changes Message-ID: <20210322225907.541943-10-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov Signed-off-by: Igor Mammedov Message-Id: <20210315180102.3008391-2-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test-allowed-diff.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h index dfb8523c8b..fddcfc061f 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1 +1,12 @@ /* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/pc/DSDT", +"tests/data/acpi/pc/DSDT.acpihmat", +"tests/data/acpi/pc/DSDT.bridge", +"tests/data/acpi/pc/DSDT.cphp", +"tests/data/acpi/pc/DSDT.dimmpxm", +"tests/data/acpi/pc/DSDT.hpbridge", +"tests/data/acpi/pc/DSDT.hpbrroot", +"tests/data/acpi/pc/DSDT.ipmikcs", +"tests/data/acpi/pc/DSDT.memhp", +"tests/data/acpi/pc/DSDT.numamem", +"tests/data/acpi/pc/DSDT.roothp", From patchwork Mon Mar 22 23:00:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456853 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h05kcmDS; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F493v4kL1z9sVt for ; Tue, 23 Mar 2021 10:01:47 +1100 (AEDT) Received: from localhost ([::1]:56218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTYP-0007Eu-KY for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:01:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX7-0007AS-4y for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX4-0001F5-LW for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454022; 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=yRTMNBKw7FKwBdiOn8Z7rlkQXm7qiYXIhC+rts1BLws=; b=h05kcmDSryHgy/pgPZhnanfvEXwJz2VmIgY0S/AZZXLXVqaC6jVrksKLnP0z/ug/qPUFYR Aqt5woy2jXu+UVr5ldiRdOtKccea4PVsTsMGMKc43dENjdsIt1gIfdUks6vZ305PFAT8SD aU1IMu5/mSpwCz2he3NrN9sq1BAFnYY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-OkIO_jUQOk2cH4zvvLKOkQ-1; Mon, 22 Mar 2021 19:00:20 -0400 X-MC-Unique: OkIO_jUQOk2cH4zvvLKOkQ-1 Received: by mail-wr1-f71.google.com with SMTP id n16so161917wro.1 for ; Mon, 22 Mar 2021 16:00:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=yRTMNBKw7FKwBdiOn8Z7rlkQXm7qiYXIhC+rts1BLws=; b=WppxcFv4h+7mSbJSyLF8bRJ/9DqNnPpfZF/Y6zCTFK96AXOFX3OepXFd2ZpYV8d9eJ ChK14+Y4mADHDT9sGUFyi9ROoCYAX5FVWbmSdbf3WX1rZ+zYxShQWIqCwesLsv/lzJxB 9K5vfd8SOBMEdigUSjXjw86IqA6+xCe1uFySTYkL6uKNVHy96puQtdypIImA+KorTKEy 64z9CoOnWjhOIf+3lSlwzG3ZxE3acRyWA8Fe45u3609jt9/VaxTQzBqfiDLBLfIMdfG3 Pr3b1FKQyJ/yXzkMHUIRUiexCoEbnY443bZOJSPIHa6yZAL6HFVMfVLzPCIZLogcyPPO Qatw== X-Gm-Message-State: AOAM531GMYfpQS9yeofz9jZAIRudGG5MA/FUhiKq+JV2Xu1yY4pxQjNk WjHZizZJrF2j85WBj8+s20O3PbR1UO9rcK4p9if41Zv+9MTBYm8lXhk+CPpSCaVeN2WmaLs/waS 38XWmzRClXgHbAWqx35Ew5XQin/b2jrhVGxvlqhuFNsaJO3xeBq7nlfvS48H6 X-Received: by 2002:a1c:ddc6:: with SMTP id u189mr588394wmg.171.1616454018514; Mon, 22 Mar 2021 16:00:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGmWqRPXITbBpDzgi/ebjO5MnXhUAShFw4dYvChbrn1og34hvYJ136EmDeZiSFfJqPma0STg== X-Received: by 2002:a1c:ddc6:: with SMTP id u189mr588368wmg.171.1616454018173; Mon, 22 Mar 2021 16:00:18 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id n6sm21846032wrt.1.2021.03.22.16.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:17 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:15 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 10/19] pci: introduce acpi-index property for PCI device Message-ID: <20210322225907.541943-11-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Philippe =?utf-8?q?Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Igor Mammedov , Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov In x86/ACPI world, linux distros are using predictable network interface naming since systemd v197. Which on QEMU based VMs results into path based naming scheme, that names network interfaces based on PCI topology. With itm on has to plug NIC in exactly the same bus/slot, which was used when disk image was first provisioned/configured or one risks to loose network configuration due to NIC being renamed to actually used topology. That also restricts freedom to reshape PCI configuration of VM without need to reconfigure used guest image. systemd also offers "onboard" naming scheme which is preferred over PCI slot/topology one, provided that firmware implements: " PCI Firmware Specification 3.1 4.6.7. DSM for Naming a PCI or PCI Express Device Under Operating Systems " that allows to assign user defined index to PCI device, which systemd will use to name NIC. For example, using -device e1000,acpi-index=100 guest will rename NIC to 'eno100', where 'eno' is default prefix for "onboard" naming scheme. This doesn't require any advance configuration on guest side to com in effect at 'onboard' scheme takes priority over path based naming. Hope is that 'acpi-index' it will be easier to consume by management layer, compared to forcing specific PCI topology and/or having several disk image templates for different topologies and will help to simplify process of spawning VM from the same template without need to reconfigure guest NIC. This patch adds, 'acpi-index'* property and wires up a 32bit register on top of pci hotplug register block to pass index value to AML code at runtime. Following patch will add corresponding _DSM code and wire it up to PCI devices described in ACPI. *) name comes from linux kernel terminology Signed-off-by: Igor Mammedov Message-Id: <20210315180102.3008391-3-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/pcihp.h | 9 +++++-- include/hw/pci/pci.h | 1 + hw/acpi/pci.c | 1 - hw/acpi/pcihp.c | 58 +++++++++++++++++++++++++++++++++++++++-- hw/acpi/piix4.c | 3 ++- hw/i386/acpi-build.c | 13 ++++++++- hw/pci/pci.c | 1 + hw/acpi/trace-events | 2 ++ 8 files changed, 81 insertions(+), 7 deletions(-) diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h index dfd375820f..2dd90aea30 100644 --- a/include/hw/acpi/pcihp.h +++ b/include/hw/acpi/pcihp.h @@ -46,6 +46,7 @@ typedef struct AcpiPciHpPciStatus { typedef struct AcpiPciHpState { AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS]; uint32_t hotplug_select; + uint32_t acpi_index; PCIBus *root; MemoryRegion io; bool legacy_piix; @@ -71,13 +72,17 @@ void acpi_pcihp_reset(AcpiPciHpState *s, bool acpihp_root_off); extern const VMStateDescription vmstate_acpi_pcihp_pci_status; -#define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp) \ +bool vmstate_acpi_pcihp_use_acpi_index(void *opaque, int version_id); + +#define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp, test_acpi_index) \ VMSTATE_UINT32_TEST(pcihp.hotplug_select, state, \ test_pcihp), \ VMSTATE_STRUCT_ARRAY_TEST(pcihp.acpi_pcihp_pci_status, state, \ ACPI_PCIHP_MAX_HOTPLUG_BUS, \ test_pcihp, 1, \ vmstate_acpi_pcihp_pci_status, \ - AcpiPciHpPciStatus) + AcpiPciHpPciStatus), \ + VMSTATE_UINT32_TEST(pcihp.acpi_index, state, \ + test_acpi_index) #endif diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 1bc231480f..6be4e0c460 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -359,6 +359,7 @@ struct PCIDevice { /* ID of standby device in net_failover pair */ char *failover_pair_id; + uint32_t acpi_index; }; void pci_register_bar(PCIDevice *pci_dev, int region_num, diff --git a/hw/acpi/pci.c b/hw/acpi/pci.c index ec455c3b25..75b1103ec4 100644 --- a/hw/acpi/pci.c +++ b/hw/acpi/pci.c @@ -59,4 +59,3 @@ void build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info, build_header(linker, table_data, (void *)(table_data->data + mcfg_start), "MCFG", table_data->len - mcfg_start, 1, oem_id, oem_table_id); } - diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 9dc4d3e2db..ceab287bd3 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -39,12 +39,13 @@ #include "trace.h" #define ACPI_PCIHP_ADDR 0xae00 -#define ACPI_PCIHP_SIZE 0x0014 +#define ACPI_PCIHP_SIZE 0x0018 #define PCI_UP_BASE 0x0000 #define PCI_DOWN_BASE 0x0004 #define PCI_EJ_BASE 0x0008 #define PCI_RMV_BASE 0x000c #define PCI_SEL_BASE 0x0010 +#define PCI_AIDX_BASE 0x0014 typedef struct AcpiPciHpFind { int bsel; @@ -251,9 +252,13 @@ void acpi_pcihp_reset(AcpiPciHpState *s, bool acpihp_root_off) acpi_pcihp_update(s); } +#define ONBOARD_INDEX_MAX (16 * 1024 - 1) + void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + PCIDevice *pdev = PCI_DEVICE(dev); + /* Only hotplugged devices need the hotplug capability. */ if (dev->hotplugged && acpi_pcihp_get_bsel(pci_get_bus(PCI_DEVICE(dev))) < 0) { @@ -261,6 +266,17 @@ void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, ACPI_PCIHP_PROP_BSEL "' set"); return; } + + /* + * capped by systemd (see: udev-builtin-net_id.c) + * as it's the only known user honor it to avoid users + * misconfigure QEMU and then wonder why acpi-index doesn't work + */ + if (pdev->acpi_index > ONBOARD_INDEX_MAX) { + error_setg(errp, "acpi-index should be less or equal to %u", + ONBOARD_INDEX_MAX); + return; + } } void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, @@ -347,7 +363,6 @@ static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size) trace_acpi_pci_down_read(val); break; case PCI_EJ_BASE: - /* No feature defined yet */ trace_acpi_pci_features_read(val); break; case PCI_RMV_BASE: @@ -357,6 +372,12 @@ static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size) case PCI_SEL_BASE: val = s->hotplug_select; trace_acpi_pci_sel_read(val); + break; + case PCI_AIDX_BASE: + val = s->acpi_index; + s->acpi_index = 0; + trace_acpi_pci_acpi_index_read(val); + break; default: break; } @@ -367,8 +388,35 @@ static uint64_t pci_read(void *opaque, hwaddr addr, unsigned int size) static void pci_write(void *opaque, hwaddr addr, uint64_t data, unsigned int size) { + int slot; + PCIBus *bus; + BusChild *kid, *next; AcpiPciHpState *s = opaque; + + s->acpi_index = 0; switch (addr) { + case PCI_AIDX_BASE: + /* + * fetch acpi-index for specified slot so that follow up read from + * PCI_AIDX_BASE can return it to guest + */ + slot = ctz32(data); + + if (s->hotplug_select >= ACPI_PCIHP_MAX_HOTPLUG_BUS) { + break; + } + + bus = acpi_pcihp_find_hotplug_bus(s, s->hotplug_select); + QTAILQ_FOREACH_SAFE(kid, &bus->qbus.children, sibling, next) { + Object *o = OBJECT(kid->child); + PCIDevice *dev = PCI_DEVICE(o); + if (PCI_SLOT(dev->devfn) == slot) { + s->acpi_index = object_property_get_uint(o, "acpi-index", NULL); + break; + } + } + trace_acpi_pci_acpi_index_write(s->hotplug_select, slot, s->acpi_index); + break; case PCI_EJ_BASE: if (s->hotplug_select >= ACPI_PCIHP_MAX_HOTPLUG_BUS) { break; @@ -413,6 +461,12 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus, OBJ_PROP_FLAG_READ); } +bool vmstate_acpi_pcihp_use_acpi_index(void *opaque, int version_id) +{ + AcpiPciHpState *s = opaque; + return s->acpi_index; +} + const VMStateDescription vmstate_acpi_pcihp_pci_status = { .name = "acpi_pcihp_pci_status", .version_id = 1, diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 1efc0ded9f..6056d51667 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -297,7 +297,8 @@ static const VMStateDescription vmstate_acpi = { 2, vmstate_pci_status, struct AcpiPciHpPciStatus), VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug, PIIX4PMState, - vmstate_test_use_acpi_hotplug_bridge), + vmstate_test_use_acpi_hotplug_bridge, + vmstate_acpi_pcihp_use_acpi_index), VMSTATE_END_OF_LIST() }, .subsections = (const VMStateDescription*[]) { diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 442b4629a9..e49fae2bfd 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1168,9 +1168,10 @@ static void build_piix4_pci_hotplug(Aml *table) aml_append(scope, field); aml_append(scope, - aml_operation_region("BNMR", AML_SYSTEM_IO, aml_int(0xae10), 0x04)); + aml_operation_region("BNMR", AML_SYSTEM_IO, aml_int(0xae10), 0x08)); field = aml_field("BNMR", AML_DWORD_ACC, AML_NOLOCK, AML_WRITE_AS_ZEROS); aml_append(field, aml_named_field("BNUM", 32)); + aml_append(field, aml_named_field("PIDX", 32)); aml_append(scope, field); aml_append(scope, aml_mutex("BLCK", 0)); @@ -1184,6 +1185,16 @@ static void build_piix4_pci_hotplug(Aml *table) aml_append(method, aml_return(aml_int(0))); aml_append(scope, method); + method = aml_method("AIDX", 2, AML_NOTSERIALIZED); + aml_append(method, aml_acquire(aml_name("BLCK"), 0xFFFF)); + aml_append(method, aml_store(aml_arg(0), aml_name("BNUM"))); + aml_append(method, + aml_store(aml_shiftleft(aml_int(1), aml_arg(1)), aml_name("PIDX"))); + aml_append(method, aml_store(aml_name("PIDX"), aml_local(0))); + aml_append(method, aml_release(aml_name("BLCK"))); + aml_append(method, aml_return(aml_local(0))); + aml_append(scope, method); + aml_append(table, scope); } diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 0eadcdbc9e..ac9a24889c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -79,6 +79,7 @@ static Property pci_props[] = { QEMU_PCIE_EXTCAP_INIT_BITNR, true), DEFINE_PROP_STRING("failover_pair_id", PCIDevice, failover_pair_id), + DEFINE_PROP_UINT32("acpi-index", PCIDevice, acpi_index, 0), DEFINE_PROP_END_OF_LIST() }; diff --git a/hw/acpi/trace-events b/hw/acpi/trace-events index f91ced477d..dcc1438f3a 100644 --- a/hw/acpi/trace-events +++ b/hw/acpi/trace-events @@ -41,6 +41,8 @@ acpi_pci_unplug_request(int bsel, int slot) "bsel: %d slot: %d" acpi_pci_up_read(uint32_t val) "%" PRIu32 acpi_pci_down_read(uint32_t val) "%" PRIu32 acpi_pci_features_read(uint32_t val) "%" PRIu32 +acpi_pci_acpi_index_read(uint32_t val) "%" PRIu32 +acpi_pci_acpi_index_write(unsigned bsel, unsigned slot, uint32_t aidx) "bsel: %u slot: %u aidx: %" PRIu32 acpi_pci_rmv_read(uint32_t val) "%" PRIu32 acpi_pci_sel_read(uint32_t val) "%" PRIu32 acpi_pci_ej_write(uint64_t addr, uint64_t data) "0x%" PRIx64 " <== %" PRIu64 From patchwork Mon Mar 22 23:00:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=APZHheOA; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49G51Ll9z9sTD for ; Tue, 23 Mar 2021 10:10:37 +1100 (AEDT) Received: from localhost ([::1]:51362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTgx-0000P5-4k for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:10:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXA-0007Aw-8o for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX7-0001Fy-76 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454024; 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=EeUbWNKIk7cGoc8diCDeN3aye5mUMnS1oxxE/sJ37XE=; b=APZHheOAC9hU5PAmWnr4rQRMICLY2QmFYJDfefJTinBqv69JbUOsGDJTA3yRl4HVhSAj1U 4QZAQng7Y01lw6tKU4qeP2j0zh6G/vDF2vH2RDRGGNQG2t0yltJ786RNYMCtr6Sd/9xhif hL9oHp3mQJAunvKaEELaTNMsXnE4bYA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-o5NXuE5FMBGQgYAE4VjlLQ-1; Mon, 22 Mar 2021 19:00:21 -0400 X-MC-Unique: o5NXuE5FMBGQgYAE4VjlLQ-1 Received: by mail-wr1-f70.google.com with SMTP id n17so157215wrq.5 for ; Mon, 22 Mar 2021 16:00:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EeUbWNKIk7cGoc8diCDeN3aye5mUMnS1oxxE/sJ37XE=; b=T7GuOT/qFjtjDigqVClstuAwxwsKod1Ym+aBIRg3yIDfSOLcAP7/0jo+/+CbNDqaml 2bGrx9NP1S330tijFjdupe+/ES7+S4FReG0F8GpyC0keTysxq9/sorCyW/UO9XIC2qmf Y3UNsAX1ej3dP01yMpKle7jLsIUg8a1Nza4iSMeldjtieezgnKbsWjAVuPo0RJSfjG1s T/kbk0BYrrSBrkATbdUrTvLl88XHdkoqvu4NdmhJ467KnjnL2RLK875vmBrVx1lUZxp5 vq0411OSXP+elrMKYxqEB0tK8QBmh2F1Qa8XjsO1QxhqlZ/d9+lAkOfDFR+tJI/DhcBS JtLQ== X-Gm-Message-State: AOAM5336hxFK7qeXQU22ib8J2Prq0Gm4dSb+E1F2A1WVJC1HFeA5dEIw P7VQsWAu3+xMYHI1bFO3DsRVykQxmvEZGBK6AChhbSrsm+YpJQJd4Ewj92Mby6G1959AYchDeVx C0n/W2Dni+cC4mZBjGII3rVVVKBDd2cmpikeP8FvoZvjgJ0wMA75llk4R+TTN X-Received: by 2002:adf:fec5:: with SMTP id q5mr786953wrs.43.1616454020315; Mon, 22 Mar 2021 16:00:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ5hivH+0voe/RMrd7OHkv1XxfyCytp9PK3ZKOXG0/WjEfI5RgP26T0YGHzo2e6rc+sSbOSw== X-Received: by 2002:adf:fec5:: with SMTP id q5mr786940wrs.43.1616454020151; Mon, 22 Mar 2021 16:00:20 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id k12sm21485090wrx.7.2021.03.22.16.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:19 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:18 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 11/19] pci: acpi: ensure that acpi-index is unique Message-ID: <20210322225907.541943-12-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov it helps to avoid device naming conflicts when guest OS is configured to use acpi-index for naming. Spec ialso says so: PCI Firmware Specification Revision 3.2 4.6.7. _DSM for Naming a PCI or PCI Express Device Under Operating Systems " Instance number must be unique under \_SB scope. This instance number does not have to be sequential in a given system configuration. " Signed-off-by: Igor Mammedov Message-Id: <20210315180102.3008391-4-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/pcihp.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index ceab287bd3..f4cb3c979d 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -52,6 +52,21 @@ typedef struct AcpiPciHpFind { PCIBus *bus; } AcpiPciHpFind; +static gint g_cmp_uint32(gconstpointer a, gconstpointer b, gpointer user_data) +{ + return a - b; +} + +static GSequence *pci_acpi_index_list(void) +{ + static GSequence *used_acpi_index_list; + + if (!used_acpi_index_list) { + used_acpi_index_list = g_sequence_new(NULL); + } + return used_acpi_index_list; +} + static int acpi_pcihp_get_bsel(PCIBus *bus) { Error *local_err = NULL; @@ -277,6 +292,23 @@ void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, ONBOARD_INDEX_MAX); return; } + + /* + * make sure that acpi-index is unique across all present PCI devices + */ + if (pdev->acpi_index) { + GSequence *used_indexes = pci_acpi_index_list(); + + if (g_sequence_lookup(used_indexes, GINT_TO_POINTER(pdev->acpi_index), + g_cmp_uint32, NULL)) { + error_setg(errp, "a PCI device with acpi-index = %" PRIu32 + " already exist", pdev->acpi_index); + return; + } + g_sequence_insert_sorted(used_indexes, + GINT_TO_POINTER(pdev->acpi_index), + g_cmp_uint32, NULL); + } } void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, @@ -315,8 +347,22 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, DeviceState *dev, Error **errp) { + PCIDevice *pdev = PCI_DEVICE(dev); + trace_acpi_pci_unplug(PCI_SLOT(PCI_DEVICE(dev)->devfn), acpi_pcihp_get_bsel(pci_get_bus(PCI_DEVICE(dev)))); + + /* + * clean up acpi-index so it could reused by another device + */ + if (pdev->acpi_index) { + GSequence *used_indexes = pci_acpi_index_list(); + + g_sequence_remove(g_sequence_lookup(used_indexes, + GINT_TO_POINTER(pdev->acpi_index), + g_cmp_uint32, NULL)); + } + qdev_unrealize(dev); } From patchwork Mon Mar 22 23:00:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=Qc0I3DPt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F497J0Gy0z9sTD for ; Tue, 23 Mar 2021 10:04:44 +1100 (AEDT) Received: from localhost ([::1]:36126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTbG-0002K9-14 for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:04:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXC-0007CJ-Fd for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56157) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTX8-0001Gf-FI for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454025; 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=7MCCUAv4xuBxw3NN3h6dkjufSelH9In4sztB/9L9w9g=; b=Qc0I3DPtxsxu83s1+XT8azJYae6iMw8PwecQxtbbcZIJUEvrw2SYqMf2BiBRsDV9AAJSfB ZCzUWzZFw0JvBhoxOuj1VnTaYFohEiLYKAuSgjDid0v4GmAUOGLvo7wto7u1rDDEG5aaIo qGPKDM0iXVtG20X/8V1VmOxhC3/kXyw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-R_dxmVTNNgKM59dMNVDVwg-1; Mon, 22 Mar 2021 19:00:24 -0400 X-MC-Unique: R_dxmVTNNgKM59dMNVDVwg-1 Received: by mail-wr1-f72.google.com with SMTP id 75so157538wrl.3 for ; Mon, 22 Mar 2021 16:00:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7MCCUAv4xuBxw3NN3h6dkjufSelH9In4sztB/9L9w9g=; b=HdPyTvrD42Tc6uYlhXqjaj/McOrOr5+BaoNJvDKtIOH5J4crqXjb0XVdzvd7n9PgRU 5RzgwmlB7k7kFwgRtRQQLrtIK3xQqgjg7pqmp0Yny1oVlgwc1gqPPtsOILN4SPxzTiQE opc63ZEK/kR9PgS9qi1OOYB9QqAoRAYbi4clDHi2u0TTTCq9O+FxZLOITKstbmpHF9hG JqfAINTaN7pC+VirNKU9B0ThDOUL4DhFMSe7jr6wXh3GdUzcxEkMNVvWx3+YyNJlxQ/E oO9V92kVDlGGHFT/hyeWApEp/Z5g4x7O6bRdOMXHtJVUnhcvnrNOWSZz4rI2q6iftBFb 94wQ== X-Gm-Message-State: AOAM531TQrOK0BMkh4QqJP6XEyZsLcfrHFx6vrtgJRKnF1Iqo1d6YDQf z3L/87SqfKIyt2Fx/JjNU3sTj79/2Dhkgj0Zd8NNfE76k3lYME2lKzqVHM3mWIUkvzr0aafHKLQ iCuSW6Z2uLTtGZs4+n9Plry3z0b0/7lw9pyxeYLRg4wcWc+t1MtHyvwJW0RpC X-Received: by 2002:a05:600c:4f03:: with SMTP id l3mr575040wmq.149.1616454022628; Mon, 22 Mar 2021 16:00:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbsiaweEsba1J/eja9tw08n3gbJA/zQB/N65lMg8sVjD33NHIPLsZKbZVnbzJ60JNMCz1SCw== X-Received: by 2002:a05:600c:4f03:: with SMTP id l3mr575029wmq.149.1616454022410; Mon, 22 Mar 2021 16:00:22 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id e13sm24840415wrg.72.2021.03.22.16.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:22 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:20 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 12/19] acpi: add aml_to_decimalstring() and aml_call6() helpers Message-ID: <20210322225907.541943-13-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov it will be used by follow up patches Signed-off-by: Igor Mammedov Message-Id: <20210315180102.3008391-5-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/aml-build.h | 3 +++ hw/acpi/aml-build.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 380d3e3924..e652106e26 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -301,6 +301,7 @@ Aml *aml_arg(int pos); Aml *aml_to_integer(Aml *arg); Aml *aml_to_hexstring(Aml *src, Aml *dst); Aml *aml_to_buffer(Aml *src, Aml *dst); +Aml *aml_to_decimalstring(Aml *src, Aml *dst); Aml *aml_store(Aml *val, Aml *target); Aml *aml_and(Aml *arg1, Aml *arg2, Aml *dst); Aml *aml_or(Aml *arg1, Aml *arg2, Aml *dst); @@ -323,6 +324,8 @@ Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3); Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4); Aml *aml_call5(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, Aml *arg5); +Aml *aml_call6(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, + Aml *arg5, Aml *arg6); Aml *aml_gpio_int(AmlConsumerAndProducer con_and_pro, AmlLevelAndEdge edge_level, AmlActiveHighAndLow active_level, AmlShared shared, diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index a2cd7a5830..d33ce8954a 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -634,6 +634,19 @@ Aml *aml_to_buffer(Aml *src, Aml *dst) return var; } +/* ACPI 2.0a: 17.2.4.4 Type 2 Opcodes Encoding: DefToDecimalString */ +Aml *aml_to_decimalstring(Aml *src, Aml *dst) +{ + Aml *var = aml_opcode(0x97 /* ToDecimalStringOp */); + aml_append(var, src); + if (dst) { + aml_append(var, dst); + } else { + build_append_byte(var->buf, 0x00 /* NullNameOp */); + } + return var; +} + /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */ Aml *aml_store(Aml *val, Aml *target) { @@ -835,6 +848,21 @@ Aml *aml_call5(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, return var; } +/* helper to call method with 5 arguments */ +Aml *aml_call6(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, + Aml *arg5, Aml *arg6) +{ + Aml *var = aml_alloc(); + build_append_namestring(var->buf, "%s", method); + aml_append(var, arg1); + aml_append(var, arg2); + aml_append(var, arg3); + aml_append(var, arg4); + aml_append(var, arg5); + aml_append(var, arg6); + return var; +} + /* * ACPI 5.0: 6.4.3.8.1 GPIO Connection Descriptor * Type 1, Large Item Name 0xC From patchwork Mon Mar 22 23:00:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H8m4eKfN; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49Lc2n3Qz9sVt for ; Tue, 23 Mar 2021 10:14:30 +1100 (AEDT) Received: from localhost ([::1]:59886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTkh-000466-Oy for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:14:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXF-0007EL-84 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46401) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXC-0001IS-9D for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454028; 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=oP0DWqO2hTVUoBgftUJivGqbVs8/LxKOJqfcj2wPLwU=; b=H8m4eKfNpNK454B6KdilL0Dhx740p6rQkWuAYCP0xzLu70fTGurORXtFp11j6CtGGHhFTL AEyeso55ib75eNjqDsKRmqLwwbVoHK7QDdXuSa8ueIwSKvcSXQ0rsttahN8gXZDnwUZap+ HdG75lFlBAYO1iGiomKRtbrQ/7V/NLs= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-wGuPFBfSNIe-FNHuQ00MvA-1; Mon, 22 Mar 2021 19:00:26 -0400 X-MC-Unique: wGuPFBfSNIe-FNHuQ00MvA-1 Received: by mail-wr1-f70.google.com with SMTP id p15so147091wre.13 for ; Mon, 22 Mar 2021 16:00:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oP0DWqO2hTVUoBgftUJivGqbVs8/LxKOJqfcj2wPLwU=; b=IhSB+X4HkzT09ZtEdjg4CjYg35LCFu1CC1RGaXJz+wPfN7wMyoFyKjnNxlAqBQTTeW 8vLjSiFwS+YwJPcnckWhlJvBFFW7o6VLeguxmeex61VL5mZOgYz4Ru8+7ur/RnDXR0aR z8kJqclVCAO3/eC6UPZFim3LSruhN1luN+eOMgQ6fjsgcoz/cI+/bCWRvcKaGRmKgxAy xqNSchOg85ObfU0uqbmoUIzVmJI/ku/jtd0pB9TXenpRcBESbjpwd5mUCnwAKO9bm1B5 doGeYrxLSn1obrYMOJv66Jw9EJ9kI+LkWD8HRi5QLdPqTnjMql3NNrCIo+Vtbwh1MaEV 7rqA== X-Gm-Message-State: AOAM533IojIXTxHtzv70BMK7Yj0pawGh+H2x4NKHBptAGfa8PfWpZl1q 8NpZesYc7nQ30swAkxhaF0cF2B1urYUbPqn3oCpf0TjgYgFNp4uHP2ZLvbBPkH69vqr1TtUFdoQ T1lzGqpKrL+i0503jWZX5YIS1vnruH1QPEu96u6O59wMiefCxAVQ9KO+ilMZ5 X-Received: by 2002:adf:b313:: with SMTP id j19mr823777wrd.188.1616454025262; Mon, 22 Mar 2021 16:00:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyNFwZvzfCE0Hq/wN0YCXtwQzVtflOW5WR9UQM17iUw3iihNuZiOCmMsJESXI/FVIFzlZ1GQ== X-Received: by 2002:adf:b313:: with SMTP id j19mr823750wrd.188.1616454024945; Mon, 22 Mar 2021 16:00:24 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id z2sm24204646wrm.0.2021.03.22.16.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:24 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:22 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 13/19] pci: acpi: add _DSM method to PCI devices Message-ID: <20210322225907.541943-14-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Richard Henderson , Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov Implement _DSM according to: PCI Firmware Specification 3.1 4.6.7. DSM for Naming a PCI or PCI Express Device Under Operating Systems and wire it up to cold and hot-plugged PCI devices. Feature depends on ACPI hotplug being enabled (as that provides PCI devices descriptions in ACPI and MMIO registers that are reused to fetch acpi-index). acpi-index should work for - cold plugged NICs: $QEMU -device e1000,acpi-index=100 => 'eno100' - hot-plugged (monitor) device_add e1000,acpi-index=200,id=remove_me => 'eno200' - re-plugged (monitor) device_del remove_me (monitor) device_add e1000,acpi-index=1 => 'eno1' Windows also sees index under "PCI Label Id" field in properties dialog but otherwise it doesn't seem to have any effect. Signed-off-by: Igor Mammedov Message-Id: <20210315180102.3008391-6-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/pci.h | 1 + hw/i386/acpi-build.c | 105 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/include/hw/acpi/pci.h b/include/hw/acpi/pci.h index e514f179d8..b5deee0a9d 100644 --- a/include/hw/acpi/pci.h +++ b/include/hw/acpi/pci.h @@ -35,4 +35,5 @@ typedef struct AcpiMcfgInfo { void build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info, const char *oem_id, const char *oem_table_id); +Aml *aml_pci_device_dsm(void); #endif diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index e49fae2bfd..a95b42c8b3 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -397,6 +397,13 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN")) ); aml_append(dev, method); + method = aml_method("_DSM", 4, AML_SERIALIZED); + aml_append(method, + aml_return(aml_call6("PDSM", aml_arg(0), aml_arg(1), + aml_arg(2), aml_arg(3), + aml_name("BSEL"), aml_name("_SUN"))) + ); + aml_append(dev, method); aml_append(parent_scope, dev); build_append_pcihp_notify_entry(notify_method, slot); @@ -424,6 +431,16 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, dev = aml_device("S%.02X", PCI_DEVFN(slot, 0)); aml_append(dev, aml_name_decl("_ADR", aml_int(slot << 16))); + if (bsel) { + aml_append(dev, aml_name_decl("_SUN", aml_int(slot))); + method = aml_method("_DSM", 4, AML_SERIALIZED); + aml_append(method, aml_return( + aml_call6("PDSM", aml_arg(0), aml_arg(1), aml_arg(2), + aml_arg(3), aml_name("BSEL"), aml_name("_SUN")) + )); + aml_append(dev, method); + } + if (pc->class_id == PCI_CLASS_DISPLAY_VGA) { /* add VGA specific AML methods */ int s3d; @@ -446,9 +463,7 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, aml_append(method, aml_return(aml_int(s3d))); aml_append(dev, method); } else if (hotplug_enabled_dev) { - /* add _SUN/_EJ0 to make slot hotpluggable */ - aml_append(dev, aml_name_decl("_SUN", aml_int(slot))); - + /* add _EJ0 to make slot hotpluggable */ method = aml_method("_EJ0", 1, AML_NOTSERIALIZED); aml_append(method, aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN")) @@ -511,6 +526,88 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, qobject_unref(bsel); } +Aml *aml_pci_device_dsm(void) +{ + Aml *method, *UUID, *ifctx, *ifctx1, *ifctx2, *ifctx3, *elsectx; + Aml *acpi_index = aml_local(0); + Aml *zero = aml_int(0); + Aml *bnum = aml_arg(4); + Aml *func = aml_arg(2); + Aml *rev = aml_arg(1); + Aml *sun = aml_arg(5); + + method = aml_method("PDSM", 6, AML_SERIALIZED); + + /* + * PCI Firmware Specification 3.1 + * 4.6. _DSM Definitions for PCI + */ + UUID = aml_touuid("E5C937D0-3553-4D7A-9117-EA4D19C3434D"); + ifctx = aml_if(aml_equal(aml_arg(0), UUID)); + { + aml_append(ifctx, aml_store(aml_call2("AIDX", bnum, sun), acpi_index)); + ifctx1 = aml_if(aml_equal(func, zero)); + { + uint8_t byte_list[1]; + + ifctx2 = aml_if(aml_equal(rev, aml_int(2))); + { + /* + * advertise function 7 if device has acpi-index + * acpi_index values: + * 0: not present (default value) + * FFFFFFFF: not supported (old QEMU without PIDX reg) + * other: device's acpi-index + */ + ifctx3 = aml_if(aml_lnot( + aml_or(aml_equal(acpi_index, zero), + aml_equal(acpi_index, aml_int(0xFFFFFFFF)), NULL) + )); + { + byte_list[0] = + 1 /* have supported functions */ | + 1 << 7 /* support for function 7 */ + ; + aml_append(ifctx3, aml_return(aml_buffer(1, byte_list))); + } + aml_append(ifctx2, ifctx3); + } + aml_append(ifctx1, ifctx2); + + byte_list[0] = 0; /* nothing supported */ + aml_append(ifctx1, aml_return(aml_buffer(1, byte_list))); + } + aml_append(ifctx, ifctx1); + elsectx = aml_else(); + /* + * PCI Firmware Specification 3.1 + * 4.6.7. _DSM for Naming a PCI or PCI Express Device Under + * Operating Systems + */ + ifctx1 = aml_if(aml_equal(func, aml_int(7))); + { + Aml *pkg = aml_package(2); + Aml *ret = aml_local(1); + + aml_append(pkg, zero); + /* + * optional, if not impl. should return null string + */ + aml_append(pkg, aml_string("%s", "")); + aml_append(ifctx1, aml_store(pkg, ret)); + /* + * update acpi-index to actual value + */ + aml_append(ifctx1, aml_store(acpi_index, aml_index(ret, zero))); + aml_append(ifctx1, aml_return(ret)); + } + aml_append(elsectx, ifctx1); + aml_append(ifctx, elsectx); + } + aml_append(method, ifctx); + return method; +} + /** * build_prt_entry: * @link_name: link name for PCI route entry @@ -1195,6 +1292,8 @@ static void build_piix4_pci_hotplug(Aml *table) aml_append(method, aml_return(aml_local(0))); aml_append(scope, method); + aml_append(scope, aml_pci_device_dsm()); + aml_append(table, scope); } From patchwork Mon Mar 22 23:00:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: 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=Y3UvWwPd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49Cc0fZPz9sTD for ; Tue, 23 Mar 2021 10:08:28 +1100 (AEDT) Received: from localhost ([::1]:44414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTes-0005tJ-2a for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:08:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXI-0007GD-Qn for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54555) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXD-0001J9-Iu for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454031; 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=+RDzDMndTg6QZnrXTrq6jfDB4LFI0581rTxRNnHZJik=; b=Y3UvWwPdyUAsL0+GFvPJe3XBlpC3RnKl8EASPCw5YC6rBOaAs4KNFoyQ9GoftR1+j6S6Ra g9SW/+yEMhCCxA+3nOa+BAzdvn34FnbHgKPLZazHamBeZD/8qels+EU9MRLK6kUueq40Ss wb5ZiyNvzKBqnNEGNfuFr7qcBjpuNKM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-173-WR20ryKlPwCedlzJvgqSfQ-1; Mon, 22 Mar 2021 19:00:28 -0400 X-MC-Unique: WR20ryKlPwCedlzJvgqSfQ-1 Received: by mail-wr1-f70.google.com with SMTP id 75so157640wrl.3 for ; Mon, 22 Mar 2021 16:00:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+RDzDMndTg6QZnrXTrq6jfDB4LFI0581rTxRNnHZJik=; b=VbQqJDQnu5293/GC2y47EgjLj1h3HVWfuG3qO3c3F4GjU3uVUDKOUMC8yCle064wiN 4A78egI1qE31b0E7QHiOiSlMBVtW81oCQTQdhvQDZjl00IIT5vrSfAUcndbQz3Se5Zsd ozDzciiPMn1dYbRHiSBL7hjgojO7qRe/AAPLDlm2B2nIZ18l+Y2mZ6fVicgtrYNxOxCo PpPSTmILedhc0TcvA9lwzAOW3MhdKXyuvnzyMQ5e/pH+S2ygprpj8PnVidB1t69IpQT8 bVzrLxCDj6LA6/mCM57EJa60rSUamkJhzozr7uodMWZ13DOWSr7pWCctrv6bjMwVtJnN boqg== X-Gm-Message-State: AOAM530xGKrfw19j3h59fxkL6+rWWBIBguGU8whdXVz4eRWbDtZCoU6t 4qFqUokhkzmkbkhvp1fpykM72i3bOJaLOBROyirUarsGNVbx8Aypv2MFvLuSyIE4Y/CtU5qeoob ujSyMjXjXfWErLsHhWRXCc9N+/TAhAzft6p82TR2viCt5bGSRndJw1+ZkfFOo X-Received: by 2002:a5d:4582:: with SMTP id p2mr835117wrq.34.1616454027187; Mon, 22 Mar 2021 16:00:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNTfNMzbAm0dc9H9uhisgmPvvYBmVFDyBZZeXdnQaEKYUm0sIRkhp0SgwDFm+mhLhorhVUbQ== X-Received: by 2002:a5d:4582:: with SMTP id p2mr835097wrq.34.1616454026915; Mon, 22 Mar 2021 16:00:26 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id j4sm730907wmo.10.2021.03.22.16.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:26 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:25 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 14/19] tests: acpi: update expected blobs Message-ID: <20210322225907.541943-15-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov expected changes are: * larger BNMR operation region * new PIDX field and method to fetch acpi-index * PDSM method that implements PCI device _DSM + per device _DSM that calls PDSM @@ -221,10 +221,11 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS ", "BXPC ", 0x00000001) B0EJ, 32 } - OperationRegion (BNMR, SystemIO, 0xAE10, 0x04) + OperationRegion (BNMR, SystemIO, 0xAE10, 0x08) Field (BNMR, DWordAcc, NoLock, WriteAsZeros) { - BNUM, 32 + BNUM, 32, + PIDX, 32 } Mutex (BLCK, 0x00) @@ -236,6 +237,52 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS ", "BXPC ", 0x00000001) Release (BLCK) Return (Zero) } + + Method (AIDX, 2, NotSerialized) + { + Acquire (BLCK, 0xFFFF) + BNUM = Arg0 + PIDX = (One << Arg1) + Local0 = PIDX /* \_SB_.PCI0.PIDX */ + Release (BLCK) + Return (Local0) + } + + Method (PDSM, 6, Serialized) + { + If ((Arg0 == ToUUID ("e5c937d0-3553-4d7a-9117-ea4d19c3434d") /* Device Labeling Interface */)) + { + Local0 = AIDX (Arg4, Arg5) + If ((Arg2 == Zero)) + { + If ((Arg1 == 0x02)) + { + If (!((Local0 == Zero) | (Local0 == 0xFFFFFFFF))) + { + Return (Buffer (One) + { + 0x81 // . + }) + } + } + + Return (Buffer (One) + { + 0x00 // . + }) + } + ElseIf ((Arg2 == 0x07)) + { + Local1 = Package (0x02) + { + Zero, + "" + } + Local1 [Zero] = Local0 + Return (Local1) + } + } + } } Scope (_SB) @@ -785,7 +832,7 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS ", "BXPC ", 0x00000001) 0xAE00, // Range Minimum 0xAE00, // Range Maximum 0x01, // Alignment - 0x14, // Length + 0x18, // Length ) }) } @@ -842,11 +889,22 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS ", "BXPC ", 0x00000001) Device (S00) { Name (_ADR, Zero) // _ADR: Address + Name (_SUN, Zero) // _SUN: Slot User Number + Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method + { + Return (PDSM (Arg0, Arg1, Arg2, Arg3, BSEL, _SUN)) + } } Device (S10) { Name (_ADR, 0x00020000) // _ADR: Address + Name (_SUN, 0x02) // _SUN: Slot User Number + Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method + { + Return (PDSM (Arg0, Arg1, Arg2, Arg3, BSEL, _SUN)) + } + Method (_S1D, 0, NotSerialized) // _S1D: S1 Device State { Return (Zero) [...] Signed-off-by: Igor Mammedov Message-Id: <20210315180102.3008391-7-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/bios-tables-test-allowed-diff.h | 11 ----------- tests/data/acpi/pc/DSDT | Bin 5065 -> 6002 bytes tests/data/acpi/pc/DSDT.acpihmat | Bin 6390 -> 7327 bytes tests/data/acpi/pc/DSDT.bridge | Bin 6924 -> 8668 bytes tests/data/acpi/pc/DSDT.cphp | Bin 5529 -> 6466 bytes tests/data/acpi/pc/DSDT.dimmpxm | Bin 6719 -> 7656 bytes tests/data/acpi/pc/DSDT.hpbridge | Bin 5026 -> 5969 bytes tests/data/acpi/pc/DSDT.ipmikcs | Bin 5137 -> 6074 bytes tests/data/acpi/pc/DSDT.memhp | Bin 6424 -> 7361 bytes tests/data/acpi/pc/DSDT.nohpet | Bin 4923 -> 5860 bytes tests/data/acpi/pc/DSDT.numamem | Bin 5071 -> 6008 bytes tests/data/acpi/pc/DSDT.roothp | Bin 5261 -> 6210 bytes 12 files changed, 11 deletions(-) diff --git a/tests/data/acpi/pc/DSDT b/tests/data/acpi/pc/DSDT index 11ef89bd322271ee30f3971b880dadfda565d413..b9dd9b38e4ef720636ba19ccbdf262de8a6439d5 100644 GIT binary patch delta 1301 zcmajfKTE?<5CHH?>Yo~-P1puW8^!=sfM~y4g)ZgSKKwr>LO{d zYeBzxD9F0DuE=^;8_%TFO)~C_Rix=;D`m|IIjyWUn@*mVojs-ilsGilW`q_!TT**6 zs-X?I>28u2L!9t5|M+6e?Q6&3H*Mrj(Hz>Vv}3yyqzLW^DR8VCIyoRV5Swqd4tS!E zIivw}H`Ka*lnJ1MqTn-N*Ma!^GqZm6h6-WyqGWSj#A>xL-Dw(qLAj zMm%o$t)#jRe#^+}Acd{gT)ao8%NL5<)X{=jUF|XwZOa3&f1YDIJ&;=c5-NB=lNnWL zXS4Lmtjb+P>Yp0x^!OJnV4#SBQw-c-;2i@)1IQLh43sc%hJjlQd|+TWfNY^)U>5`D v7`Vs4Ck93ZWQ!#XI2gFVzyk)pFfb+}TP$OsjDbrGG{k7&-$zh?6`z?OB0Yu? delta 345 zcmeyQcT%0pCDmqyI*(Jxoj<9FtEldGoSFH*!1q`35;V`GxvUR%O=P{Dhf@ zlTl>yN1jY0*MgY%V5fKi-~0e)PXi98U{@c8=qB!91A};uct@8YAV(|M5X#|UU|?dH ze2Q0=QFHQ3UJd5xCe6vZd=R=2N^gbIKcTcOKSaI}N*{&NoB|MWUno5hN?(Q2l7bNV zSSY;^Niz1tEIsTJI1M z;R^c&qHCv$uugr2h%P}yL|x5So&uS77=|~$H_Tk#ccQVtNvgEghyXCp7u*%gDn8O; zGk%v=^9qW*Dhf(o9?zwvbu#XluJTjKPReRgAuDFuZL>(r<{nc5N=zCIZGskUgO~bq zk}7+wtdkUd0nYn4fB&M+?aN1@S9#<{lug>JvSnCNQU+^;lsMK393Kz^h~aK`4%j{i zQ=`2#b!=S$6bP&%7Rvp zsqwh((v#9ExO6qI03XsjbGdCgU9nW&q>dJ}`bwXg=vp@b`{y~f*8{%OFCl>qG?|gS z-E5X#X?3BGB>j_-UXOo41p_A-xW>R62EqYkND%|u7&yhiEe75(Fv=raq%dG&;0yzI w82G?IB#3OWgn=CloMWJcflmyK4I^8mF|dn)1_mB5@HHG8`u7oB218HG4_Q%&Gynhq delta 345 zcmbPl`OT2aCD5fk8Y+yrWAHkfRlB2<7lFFfcJp z{w^fTs5x0oSc5sbNpo@(l%5BrA3uWnZzLCZcw@l zN}q$$LgEnlFep6>O5cOhN)izHG$_3aO232BMv@TuGAO+ZO8PErv0HYv@`$E9vC F0szp9V*vmF diff --git a/tests/data/acpi/pc/DSDT.bridge b/tests/data/acpi/pc/DSDT.bridge index a234075518fa8e187349d64c313779cc25db8299..a9b4d5659457f6de30b993962bce673c9413d81d 100644 GIT binary patch delta 2375 zcmeA%yW`B|66_LkN0EVn@y153Jxok~f|E}$c?)qwHwrlU`35;V`Gxu_1bDhcOjcml zs~6FB1TvYTm7RQ?z5o9&$N)(fR5E5VfRq$~h=gc$kmQmC5f`=qmtbGM1wO2kGX#aX z1TL7Ld>U+8Mk$u^4C=Gt@91WedKNWpDF3fM#mSYb#= zK@1@U?SvHk=Of^TyM#>O5F=nh13v);afD3hB&2{*fPfYE37NnpPQV0HLJATHDd;Ao zU>hL?4+$yYks#m;b3zK%3lcD)myiiN2q`cSB47odq$WRF3AMReh?9v4n6XE*C9sqR XhQnyKgoMLrwuFSk0A))($$N|dt?#vOym?uo8@ZkQe1n{w{6c*vt1|0te!|Sd z$tW`UBTuH0$CH@&V5fKihbIBfo(3FF!LB|G(M{aJ1_tpQ@s2J*K#o?hA(X?zz`(>X z`3$eDq<>kkp#?+*P>`7ctdTLgNoBGkpE7fFlg8u(K6N0iIe9Uk2AF;hrM3AX{Cp_A z8A^YL($)eH`FbdQ7)rAXLd3nHbU&2745h_|Ao9^rdOnnX45ihDA@bQ!dOei>45iIQ uAoA5vdOwtA7KMnrL+NfPeI7~+i$UbW#WWYs5MyH0oIH$uxS3tyDkA`KW3MOx diff --git a/tests/data/acpi/pc/DSDT.cphp b/tests/data/acpi/pc/DSDT.cphp index 6ac47a7d1001c711b957f8e28cab1a143d2cf65f..8d86155e275aa688f8767dd92c4b9df08b4a18ad 100644 GIT binary patch delta 1301 zcmajfPfG$(5CHJmRZAArT~{%oL(ri_2sI*z2wOMkkGqJQ5NxpPA#$x?uLU7`icZyw zsM`wr1;R^E5!Iz`eSj`OMM&SleB~*Kd52+m^LxY0<(((*Gn}l+D^eVQIk@1iSymOu zBfA{->vdjIm10g(OUiIzQC=m(p7B~FIoC~DeMHLVmOCB0Ld*6JV*w>L4W>Ryi>?`w z`wFtA1f9H(R0NUZpQoPQwaH!ODArcu4>`rAy|%VZXM|M2i4%)s9r1XNm_W=xr+dH^ zJWQPiXvUlICz##^%Fz|r^fk(EO!N3Lvjxlh9flmyG0U5&H8Hv@XS0<{JoRhA995 delta 345 zcmX?PG*g?)CDrP7Q%eJ6|N=F2wBTK$O1Uo3)NE$a8dda&hJf?77a}@g5#xhaysFaw8<3c z#kiJ87+zyS&Vbj@=2Z|QhC7$fVbkUEg*E0_LNCtLXgz<{2S9#3PpTD&ZoeKG9AKAT zneGUFBGu4Cp|iDGiC%QUB?ewG&>$jD3}7IOfg=oDVc;DDjZMfFLl{`bz%d4{G4O$b yKr^z%Fa}mIaDssw418fA6hXEa#lR{C&Mc({V$fHZ`=5fk8Y+yrWAHkfRlB2<7lFFfcJp zb`X(e)SMhIqQM;9q&ayplztASwM8M~`A~W@l>QE-t;Hbn^-%gSlx7!)h4H0*T(%n${ytL+K0ht?& E09A8hhX4Qo diff --git a/tests/data/acpi/pc/DSDT.hpbridge b/tests/data/acpi/pc/DSDT.hpbridge index 9dfac45eab12b680bc963d0528553a7149a378cc..5d8ba195055f2eda74223323baeb88390ea36739 100644 GIT binary patch delta 1315 zcmajf&o9GZ7zgmDZ~d62SZ6X42Z_imi)ACik**?GYxW|NO4{AFA?X#7Wpi=my;IVN zh)BfM&4r5)#M!~c-yo)M>?Gmo;mwmipMKxxx%4>tn2hl^w+LO#l#Au5!xf9FR&eeho1RVvR63afvl^qx zq!q9xv>XI1x@bT+V)=8)9-ppIEUj|K8)kK;fu`zK1|UCPB7c1l_VZF2c)*JxZMCX`>)@^)xGj8 Fd;_9>h+F^w delta 354 zcmcbpw@97KCDyN1jY0zucJkV5fKix7+|{PXi98U{@c8=qB!91A};uct@8YAV(|M5X#|UU|?dH ze2Q0Ah(FlS0-^vY#tc-XIa!iVgBe7}Lg|H2`YDvwk2(eNzQg0e`@P3|hp!duE()5VZFeI8O!r<0aBMzIBrYrS zWp3u+b4EOF z@m5OP0^Tx;c~ByjznAFI?JCvU0d=%sHa7#t(w`Lp*k3QOgBlcn-jW6$&}3O7dN9PQ z0a6OarUtc`O&^?L-~j{g7~n(54l5Yg#lQsy9x?EN0bvZeB7p%L1D6!Vd-n=Z)joeOtzCq4TexbgTbD8xv>#*=} zGKx&LQ5)9r+>htx)IBqI0z0Zg0vMWiijo={L_SD6od##5wU3%vMNZilar`V z#4&|TZqi9qq`2tjR}fT0{0_BGI|*`cIF5I}cib)SBGZ`QRYP5A^Z_u5EB=;cb%8vx zOHs}|h{(FOtjPMR)}LQc*GPY0v?7kowo=v{kaNmXv*{LT+1+Ivpv0xYHV0|Zw?(xx zuNqp9m+K%!A;w3Zvrliv_?~tmeQL=EMRRGd?H$`2ASLjU#Nk;lcDhe&AarB3a))v0PqWSJz(}Q334eomHFDbWyn@!rj}P0Qk-ne<-n{C z8>y7VS+nXgaF(&EgD6?8xk5gjuIQA?)X{=jT?`uOwhaNWzn*9Rdmy&@rB(2OCK)x- z&c^7KS(SriBRbUg-{T)}gn?@eyka06LuQ!7z$ONcF>r%{cMJ$3vc(hzwlHvtfjbO* vU?3JpwwT6%gMl*)++*Mq1MyyDix~`*F>sE71_r(`AW6gFKOaFoE4?t^B&CLx delta 344 zcmX?TIm3v{CD#vOym?uo8@ZkQe1n{w{6c*vt1|0te!?8h z$0#z{K`7J6wIC)w*ePDXH$TAH(}2S%*wu$2x`{j3z#yI@-q9rp$k7TmgmQQo7?>C) zOA5;}YEHHg)?kiq(wtlar4K-977>WJ2bAuC(ifn#h$uup0!q(;(hs1tiWo#b14^%f z(jTC-i8w^Q0!r_J(32z}!Y)v{14^HP(gKnY`4A{Q14`e4(h5=#`4lLU+8Ff0^bAUZjV zi@iXIm5G6uA+aE#Bawk&Nuq$CS$wclyujuYOe~y?5|htzXV!Zxi~)-|EDUh=G~jRw zcJ*P1Zqf`kFo@@fcXSD2;D`?n^uW8JStxAax*#=q4|gU_+={9tH*` zhQDP&P9ut!X$7CxeZ(f$@Ms6oR-ymlvzfj-F)0y-(hcWYT zGKx%2=E*d2Er^K^c8VA9%@1()G~jRwcJ*P1ZsHC$Fo@@fcXSB?aHJGEDG$+r8(vP9EIv+$l8%nQ-(x0KUIX^_c8cOen(#!%7ad#-)4W-XR zX<X=f3Ld^?mrEuy)ZNAw0G E0LKMiz5oCK diff --git a/tests/data/acpi/pc/DSDT.numamem b/tests/data/acpi/pc/DSDT.numamem index 195f8da900c5fc56c504adfef756af8f74f5823d..8632dfe8a8bdd991871a1e633162eb9a2e1497ea 100644 GIT binary patch delta 1291 zcmajePfG$(5CHJmXO?aLTQjVXkUE$IqCs@6b)!so5jP>&VAq>k!4eS`gygAfy<0J!!Ae?^EQ&|8uV zd9;I|sK~{PsFdVbAuFxYm@C-`Pt7|i(I&)vCfDhh6;?KPxhgPXvS4U&RC0Dv?2`h!S?Lki#oF>A4Oi}k?V|XvRNCOhBZNJV2#i!PprY?eQE$TydCF(Ex5P? z7N8ZehG;Fs_n9F#0Uwl2yi^2_u9g%CM|5W|ug$irRBP+Zv4YlI?orc!)(b#>Jx{tdgq?Y532b1=v_uDd zej@hJQQu^=TZ`6ozybzL44h!#1_SRHi29K$7BR4efm00JV&DSw1Ct_3mi!A|i4zWD*po(3FF!LB|G(M{aJ1_tpQ@s2J*K#o?hA(X?zz`(>X z`2w#jqvquIyc*2WO`4O9`5<&Tl->=c|3hhKeu#WKls*lm`2`^2!BBcSl)eq6QB+?S&!o%~1L{l;#$Ji2Fn7$x!+_l$I8S$j6InZeAdI GgAo8NGGr|P diff --git a/tests/data/acpi/pc/DSDT.roothp b/tests/data/acpi/pc/DSDT.roothp index 1d0a2c2f3cc4bfac75948d2ed6a69403cd18379b..cee3b4d80b51ad30153953ace46127923ce8b271 100644 GIT binary patch delta 1279 zcmeCxJY>M-66_MP562flQ`oWhWnJ@BjY`GCR!(lh0_DkB3=1SDXL2zu5S~;!Ie}qv0?&USU|1r^ z%-9Gb7#4~z5S^SQ#Km49#LC3L%aB-*(2>Z%uq1J_A2Sapqr~KBo=h%}busb5PVoW` z>n5M$v1jsIF`1uNjL~MY8n3d9hUJd*T77|i$hLD2qgcK<85paVqAq5qL6f7pB;2a?ZKM5&N;V0k=e?khX2q{=f zNWld{3Vst(pe8`T7lDKn)DTjzoRES`gcSTGq(DQEfG>gxDX1f)U?m|1R|qNiPe_55 T5CLC=3Tg7A<^Ij3LJ~{>th0qv delta 353 zcmX?P(5uPi66_MvE5g9QSh|sG4-=CI$K(@C-n=Z)joeOtzCq4TexbgTRhjiRKVjzK zWE7eFktdVOvnD1!*ePDXv1W1#uf3#yS+Jo+JV(5vOArqO12Y4MQ?RQKLv)kM|#jWZ(b* diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h index fddcfc061f..dfb8523c8b 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1,12 +1 @@ /* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/pc/DSDT", -"tests/data/acpi/pc/DSDT.acpihmat", -"tests/data/acpi/pc/DSDT.bridge", -"tests/data/acpi/pc/DSDT.cphp", -"tests/data/acpi/pc/DSDT.dimmpxm", -"tests/data/acpi/pc/DSDT.hpbridge", -"tests/data/acpi/pc/DSDT.hpbrroot", -"tests/data/acpi/pc/DSDT.ipmikcs", -"tests/data/acpi/pc/DSDT.memhp", -"tests/data/acpi/pc/DSDT.numamem", -"tests/data/acpi/pc/DSDT.roothp", From patchwork Mon Mar 22 23:00:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RxiMbepM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49P92c8zz9sTD for ; Tue, 23 Mar 2021 10:16:45 +1100 (AEDT) Received: from localhost ([::1]:35742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTmt-0005uF-6y for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:16:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXL-0007GZ-Hy for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28145) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lOTXI-0001Kh-Gm for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454035; 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=KkS5Xp0caFryRCO3+REG/uo3Q121Qkg68IyU+rSFR+w=; b=RxiMbepM4pW584WwPimH9MUZHUIPb97Y7s7WFNXUoXmMZjdp4+GjWs1plDY/JF/9MpANt0 +TAD97aGmeawXDrmLD3jRG8PUh7yBM1KKX0IPOk/O4Z10tOglTyMYKqSb77R30rbh/e6Ky qtSBy8GCGJxbXxkaL3fcfGxSsJo10G8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-VPkUXp7INK2ucu4Hrj8ztg-1; Mon, 22 Mar 2021 19:00:33 -0400 X-MC-Unique: VPkUXp7INK2ucu4Hrj8ztg-1 Received: by mail-wr1-f70.google.com with SMTP id p12so143594wrn.18 for ; Mon, 22 Mar 2021 16:00:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KkS5Xp0caFryRCO3+REG/uo3Q121Qkg68IyU+rSFR+w=; b=KP+sqhnCt8e3Goc2Wzh1A67PI+jKCExhJ+kce8GBgfY7QVlrEW1q44l14VYJMmvEsR EHKYDRzd7WDsbU9UlUgkbhCG7wSi5gkdZBDeWuT4vQoY3s6FQVQ6a8pideVvt0jjWU8U mf5lEtC0jDQ0wnWfNISOp1O1to8QwBV222FvcMsw5m4fffkvWjfRwlxBwKdCIQzcE8AH dhixrK0n2qJw8sYS6cUh2WpchgihmLHBujqC515RlpY+xC7YoN7LtEvlNzqWZLTYKiRI H7ggnvGIwEOao9vyz+e/RvE7XODkAdQCv+LMSevx8lEvxNUsSl+NQpGRCSKofLwMEUp4 HT0Q== X-Gm-Message-State: AOAM532AjKSSCh1RIWaKCsI1Vz/jBw5AfJ97emzrBE663Ft42OOHB897 16HU7ejBed8Ps+1gOS75qaBufs/cyX7dRfouFYcOXQVynecXLhEuxw77HaUqgf//hX4uYok4Opa t5cp2t72jwj9pWYx9KqPoRraYoT65xxRgUZ/9rIMy7Sbw32pQebMWnYKvOBry X-Received: by 2002:a05:6000:181:: with SMTP id p1mr805835wrx.73.1616454029904; Mon, 22 Mar 2021 16:00:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq3MTFybc9T4Y+ZnKeHUmd1ntZ6/3dYt7MgSqIlksPyzsSB3YqTCqtRRVprM5gcvUUQ4qUFg== X-Received: by 2002:a05:6000:181:: with SMTP id p1mr805802wrx.73.1616454029594; Mon, 22 Mar 2021 16:00:29 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id k12sm21485370wrx.7.2021.03.22.16.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:29 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:27 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 15/19] acpi: Set proper maximum size for "etc/table-loader" blob Message-ID: <20210322225907.541943-16-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , David Hildenbrand , Richard Henderson , Alistair Francis , Shannon Zhao , qemu-arm@nongnu.org, Paolo Bonzini , Igor Mammedov , Laszlo Ersek Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The resizeable memory region / RAMBlock that is created for the cmd blob has a maximum size of whole host pages (e.g., 4k), because RAMBlocks work on full host pages. In addition, in i386 ACPI code: acpi_align_size(tables->linker->cmd_blob, ACPI_BUILD_ALIGN_SIZE); makes sure to align to multiples of 4k, padding with 0. For example, if our cmd_blob is created with a size of 2k, the maximum size is 4k - we cannot grow beyond that. Growing might be required due to guest action when rebuilding the tables, but also on incoming migration. This automatic generation of the maximum size used to be sufficient, however, there are cases where we cross host pages now when growing at runtime: we exceed the maximum size of the RAMBlock and can crash QEMU when trying to resize the resizeable memory region / RAMBlock: $ build/qemu-system-x86_64 --enable-kvm \ -machine q35,nvdimm=on \ -smp 1 \ -cpu host \ -m size=2G,slots=8,maxmem=4G \ -object memory-backend-file,id=mem0,mem-path=/tmp/nvdimm,size=256M \ -device nvdimm,label-size=131072,memdev=mem0,id=nvdimm0,slot=1 \ -nodefaults \ -device vmgenid \ -device intel-iommu Results in: Unexpected error in qemu_ram_resize() at ../softmmu/physmem.c:1850: qemu-system-x86_64: Size too large: /rom@etc/table-loader: 0x2000 > 0x1000: Invalid argument In this configuration, we consume exactly 4k (32 entries, 128 bytes each) when creating the VM. However, once the guest boots up and maps the MCFG, we also create the MCFG table and end up consuming 2 additional entries (pointer + checksum) -- which is where we try resizing the memory region / RAMBlock, however, the maximum size does not allow for it. Currently, we get the following maximum sizes for our different mutable tables based on behavior of resizeable RAMBlock: hw table max_size ------- --------------------------------------------------------- virt "etc/acpi/tables" ACPI_BUILD_TABLE_MAX_SIZE (0x200000) virt "etc/table-loader" HOST_PAGE_ALIGN(initial_size) virt "etc/acpi/rsdp" HOST_PAGE_ALIGN(initial_size) i386 "etc/acpi/tables" ACPI_BUILD_TABLE_MAX_SIZE (0x200000) i386 "etc/table-loader" HOST_PAGE_ALIGN(initial_size) i386 "etc/acpi/rsdp" HOST_PAGE_ALIGN(initial_size) microvm "etc/acpi/tables" ACPI_BUILD_TABLE_MAX_SIZE (0x200000) microvm "etc/table-loader" HOST_PAGE_ALIGN(initial_size) microvm "etc/acpi/rsdp" HOST_PAGE_ALIGN(initial_size) Let's set the maximum table size for "etc/table-loader" to 64k, so we can properly grow at runtime, which should be good enough for the future. Migration is not concerned with the maximum size of a RAMBlock, only with the used size - so existing setups are not affected. Of course, we cannot migrate a VM that would have crash when started on older QEMU from new QEMU to older QEMU without failing early on the destination when synchronizing the RAM state: qemu-system-x86_64: Size too large: /rom@etc/table-loader: 0x2000 > 0x1000: Invalid argument qemu-system-x86_64: error while loading state for instance 0x0 of device 'ram' qemu-system-x86_64: load of migration failed: Invalid argument We'll refactor the code next, to make sure we get rid of this implicit behavior for "etc/acpi/rsdp" as well and to make the code easier to grasp. Reviewed-by: Igor Mammedov Cc: Alistair Francis Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Peter Maydell Cc: Shannon Zhao Cc: Marcel Apfelbaum Cc: Paolo Bonzini Cc: Richard Henderson Cc: Laszlo Ersek Signed-off-by: David Hildenbrand Message-Id: <20210304105554.121674-2-david@redhat.com> Reviewed-by: Laszlo Ersek Reviewed-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/aml-build.h | 1 + hw/arm/virt-acpi-build.c | 3 ++- hw/i386/acpi-build.c | 3 ++- hw/i386/acpi-microvm.c | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index e652106e26..ca781f3531 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -6,6 +6,7 @@ /* Reserve RAM space for tables: add another order of magnitude. */ #define ACPI_BUILD_TABLE_MAX_SIZE 0x200000 +#define ACPI_BUILD_LOADER_MAX_SIZE 0x10000 #define ACPI_BUILD_APPNAME6 "BOCHS " #define ACPI_BUILD_APPNAME8 "BXPC " diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index f9c9df916c..a91550de6f 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -865,7 +865,8 @@ void virt_acpi_setup(VirtMachineState *vms) build_state->linker_mr = acpi_add_rom_blob(virt_acpi_build_update, build_state, - tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, 0); + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, + ACPI_BUILD_LOADER_MAX_SIZE); fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index a95b42c8b3..dc56006353 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2634,7 +2634,8 @@ void acpi_setup(void) build_state->linker_mr = acpi_add_rom_blob(acpi_build_update, build_state, - tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, 0); + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, + ACPI_BUILD_LOADER_MAX_SIZE); fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); diff --git a/hw/i386/acpi-microvm.c b/hw/i386/acpi-microvm.c index 54b3af478a..01f1945ac1 100644 --- a/hw/i386/acpi-microvm.c +++ b/hw/i386/acpi-microvm.c @@ -255,7 +255,7 @@ void acpi_setup_microvm(MicrovmMachineState *mms) ACPI_BUILD_TABLE_MAX_SIZE); acpi_add_rom_blob(acpi_build_no_update, NULL, tables.linker->cmd_blob, - "etc/table-loader", 0); + "etc/table-loader", ACPI_BUILD_LOADER_MAX_SIZE); acpi_add_rom_blob(acpi_build_no_update, NULL, tables.rsdp, ACPI_BUILD_RSDP_FILE, 0); From patchwork Mon Mar 22 23:00:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PchqOeZ8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49Km1bt0z9sTD for ; Tue, 23 Mar 2021 10:13:48 +1100 (AEDT) Received: from localhost ([::1]:58170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTk2-0003M8-7y for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:13:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXQ-0007HW-BQ for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39172) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXL-0001Lb-CI for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454038; 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=943xaER/uZ2yx+0NU3LkWfKz9OTuumEUfbOODT+zbzU=; b=PchqOeZ81qNJnmuQA/726IBhdmqqGrD3peFXesUkidRKXlXcCX0jfQR7uIGAGAU+60N+Vq BYr/BXmgKhTIS8kN6LfgN/xcCsO0hUc2/SMQhDm0VyecSZcmuTThaUPt0QH26qo5c/BeV4 NkU/vDER82Ai5KG9tcYXI1yxrsVILEA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-447-lDYxRaddMhir6D15nKebDQ-1; Mon, 22 Mar 2021 19:00:36 -0400 X-MC-Unique: lDYxRaddMhir6D15nKebDQ-1 Received: by mail-wr1-f71.google.com with SMTP id s10so161884wre.0 for ; Mon, 22 Mar 2021 16:00:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=943xaER/uZ2yx+0NU3LkWfKz9OTuumEUfbOODT+zbzU=; b=T4ZOXmCoyrMOYn8oS75jH6Ffmi0Cw+/j0kCSb+AMMcr6XpyWTtGgRm1p58nnnS4fn2 5Pexhwgj9Sa3gFnzkpC9ZsikFn/D6jX27iJMRgjY1H/h9M9esp59DNf/x9h40QVlKhZV Fj9mRCdIFgb4xTnKilREYszp7JIeZutWdXCpLJyLeLziPg3C2dQIXzzzH1AR/7yaRVB5 W83oFzq7dCe+LzBMp3JSrruGLfm0BEaanEG4EQMTcmrUHSWhgXFaV0vb+UqQKhpzfupv /HtUkiAlQMD0cxH6K2EUHU8zACo9IKZS3VXjlmNly1ekfidm+3ZhwJqnQ0klcKmdvh92 nkug== X-Gm-Message-State: AOAM530USCjr2bNuXnOrgESGVOrOoKWKsz/IcDBFGpa+527CLkTE4G2L 6Egtc6vbqkmufpsy2dosnoHdgkjJlY7swpm/LWy5I7R1aUBwgOVOXESvYt3Ug7AtrpGFigcH2CK K/94BD/QlVOlplsCJ7wBpQu23F/90V/RG4iP3i8tsTMe9GYDj9hIXM/0RemCv X-Received: by 2002:adf:fa4e:: with SMTP id y14mr849634wrr.170.1616454035228; Mon, 22 Mar 2021 16:00:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRz5qnsKBRjkXP9y9tK5HyLWXJWUPnqUWG5JqSGmi/yjTQZQjwqX3tp7/dzyR2KbRgIUqSwA== X-Received: by 2002:adf:fa4e:: with SMTP id y14mr849612wrr.170.1616454034999; Mon, 22 Mar 2021 16:00:34 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id w6sm20891865wrl.49.2021.03.22.16.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:34 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:32 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 17/19] acpi: Move maximum size logic into acpi_add_rom_blob() Message-ID: <20210322225907.541943-18-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , David Hildenbrand , Richard Henderson , Alistair Francis , Shannon Zhao , qemu-arm@nongnu.org, Paolo Bonzini , Igor Mammedov , Laszlo Ersek Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We want to have safety margins for all tables based on the table type. Let's move the maximum size logic into acpi_add_rom_blob() and make it dependent on the table name, so we don't have to replicate for each and every instance that creates such tables. Suggested-by: Laszlo Ersek Cc: Alistair Francis Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Peter Maydell Cc: Shannon Zhao Cc: Marcel Apfelbaum Cc: Paolo Bonzini Cc: Richard Henderson Cc: Laszlo Ersek Signed-off-by: David Hildenbrand Message-Id: <20210304105554.121674-4-david@redhat.com> Reviewed-by: Laszlo Ersek Reviewed-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/aml-build.h | 4 ---- include/hw/acpi/utils.h | 3 +-- hw/acpi/utils.c | 12 ++++++++++-- hw/arm/virt-acpi-build.c | 13 ++++++------- hw/i386/acpi-build.c | 8 +++----- hw/i386/acpi-microvm.c | 16 ++++++---------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index ca781f3531..471266d739 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -4,10 +4,6 @@ #include "hw/acpi/acpi-defs.h" #include "hw/acpi/bios-linker-loader.h" -/* Reserve RAM space for tables: add another order of magnitude. */ -#define ACPI_BUILD_TABLE_MAX_SIZE 0x200000 -#define ACPI_BUILD_LOADER_MAX_SIZE 0x10000 - #define ACPI_BUILD_APPNAME6 "BOCHS " #define ACPI_BUILD_APPNAME8 "BXPC " diff --git a/include/hw/acpi/utils.h b/include/hw/acpi/utils.h index 140b4de603..0022df027d 100644 --- a/include/hw/acpi/utils.h +++ b/include/hw/acpi/utils.h @@ -4,6 +4,5 @@ #include "hw/nvram/fw_cfg.h" MemoryRegion *acpi_add_rom_blob(FWCfgCallback update, void *opaque, - GArray *blob, const char *name, - uint64_t max_size); + GArray *blob, const char *name); #endif diff --git a/hw/acpi/utils.c b/hw/acpi/utils.c index a134a4d554..f2d69a6d92 100644 --- a/hw/acpi/utils.c +++ b/hw/acpi/utils.c @@ -27,9 +27,17 @@ #include "hw/loader.h" MemoryRegion *acpi_add_rom_blob(FWCfgCallback update, void *opaque, - GArray *blob, const char *name, - uint64_t max_size) + GArray *blob, const char *name) { + uint64_t max_size = 0; + + /* Reserve RAM space for tables: add another order of magnitude. */ + if (!strcmp(name, ACPI_BUILD_TABLE_FILE)) { + max_size = 0x200000; + } else if (!strcmp(name, ACPI_BUILD_LOADER_FILE)) { + max_size = 0x10000; + } + return rom_add_blob(name, blob->data, acpi_data_len(blob), max_size, -1, name, update, opaque, NULL, true); } diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index a91550de6f..f5a2b2d4cb 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -859,14 +859,13 @@ void virt_acpi_setup(VirtMachineState *vms) /* Now expose it all to Guest */ build_state->table_mr = acpi_add_rom_blob(virt_acpi_build_update, build_state, tables.table_data, - ACPI_BUILD_TABLE_FILE, - ACPI_BUILD_TABLE_MAX_SIZE); + ACPI_BUILD_TABLE_FILE); assert(build_state->table_mr != NULL); - build_state->linker_mr = - acpi_add_rom_blob(virt_acpi_build_update, build_state, - tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, - ACPI_BUILD_LOADER_MAX_SIZE); + build_state->linker_mr = acpi_add_rom_blob(virt_acpi_build_update, + build_state, + tables.linker->cmd_blob, + ACPI_BUILD_LOADER_FILE); fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); @@ -880,7 +879,7 @@ void virt_acpi_setup(VirtMachineState *vms) build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, build_state, tables.rsdp, - ACPI_BUILD_RSDP_FILE, 0); + ACPI_BUILD_RSDP_FILE); qemu_register_reset(virt_acpi_build_reset, build_state); virt_acpi_build_reset(build_state); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index dc56006353..3aeae15e57 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2628,14 +2628,12 @@ void acpi_setup(void) /* Now expose it all to Guest */ build_state->table_mr = acpi_add_rom_blob(acpi_build_update, build_state, tables.table_data, - ACPI_BUILD_TABLE_FILE, - ACPI_BUILD_TABLE_MAX_SIZE); + ACPI_BUILD_TABLE_FILE); assert(build_state->table_mr != NULL); build_state->linker_mr = acpi_add_rom_blob(acpi_build_update, build_state, - tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, - ACPI_BUILD_LOADER_MAX_SIZE); + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE); fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); @@ -2674,7 +2672,7 @@ void acpi_setup(void) build_state->rsdp = NULL; build_state->rsdp_mr = acpi_add_rom_blob(acpi_build_update, build_state, tables.rsdp, - ACPI_BUILD_RSDP_FILE, 0); + ACPI_BUILD_RSDP_FILE); } qemu_register_reset(acpi_build_reset, build_state); diff --git a/hw/i386/acpi-microvm.c b/hw/i386/acpi-microvm.c index 502aac0ba2..271710eb92 100644 --- a/hw/i386/acpi-microvm.c +++ b/hw/i386/acpi-microvm.c @@ -249,16 +249,12 @@ void acpi_setup_microvm(MicrovmMachineState *mms) acpi_build_microvm(&tables, mms); /* Now expose it all to Guest */ - acpi_add_rom_blob(acpi_build_no_update, NULL, - tables.table_data, - ACPI_BUILD_TABLE_FILE, - ACPI_BUILD_TABLE_MAX_SIZE); - acpi_add_rom_blob(acpi_build_no_update, NULL, - tables.linker->cmd_blob, - ACPI_BUILD_LOADER_FILE, ACPI_BUILD_LOADER_MAX_SIZE); - acpi_add_rom_blob(acpi_build_no_update, NULL, - tables.rsdp, - ACPI_BUILD_RSDP_FILE, 0); + acpi_add_rom_blob(acpi_build_no_update, NULL, tables.table_data, + ACPI_BUILD_TABLE_FILE); + acpi_add_rom_blob(acpi_build_no_update, NULL, tables.linker->cmd_blob, + ACPI_BUILD_LOADER_FILE); + acpi_add_rom_blob(acpi_build_no_update, NULL, tables.rsdp, + ACPI_BUILD_RSDP_FILE); acpi_build_tables_cleanup(&tables, false); } From patchwork Mon Mar 22 23:00:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bJXOdDso; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49Rh04xjz9sTD for ; Tue, 23 Mar 2021 10:18:56 +1100 (AEDT) Received: from localhost ([::1]:37768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOToz-0006oY-V5 for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:18:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXR-0007Kj-Sq for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXQ-0001MZ-1V for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454041; 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=merc1D0xul3Ny+Jrf4XDcCdbekcd0CVvJdhC+IhKUGI=; b=bJXOdDsoqeD0EQ4tuMjYiiyWbjSmvXBUtKZVvlG5WxP4VCHOoru0ZV42fKH/Pgk6+pI3K6 kBqK0gQEDkrgPNTR4imBbLhyVYOLBAgPfJqvUjtb6pvi57zhj7bAuTcOkz/6naXk8rKbLU kEeERrn4BqYjjOnH7LhbqG3fQQjFpbQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-6A8u07EENjKMRKa_8x30dg-1; Mon, 22 Mar 2021 19:00:39 -0400 X-MC-Unique: 6A8u07EENjKMRKa_8x30dg-1 Received: by mail-wr1-f71.google.com with SMTP id y5so158843wrp.2 for ; Mon, 22 Mar 2021 16:00:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=merc1D0xul3Ny+Jrf4XDcCdbekcd0CVvJdhC+IhKUGI=; b=DTLi/VTmfmyZfQr4cPuDRcXphKZFu8/rwctI3dgK8O/EHPI+5FuQ+MIyxIjQ2wzWla vJRdfi9aqFWwKvzkoA5imZ4YP+21fjefVkfA3mPjkA2Wer27fSg1z1JH08erUke/LH/9 NiY5lPTSVYcbS408Fs0FstfhxnHPCYzSE1CCDYGHf/BG+fm8u8CgHv5HtiMSBNUw2cVp T+psk3XkbQ3Z2OzIlx83gOwYFqf0LuamSABR3kGLqxIWgCJv99YGjywFrGBMw9onPRU4 wDTVClpEXbXIQJGEX4SWDN2oYShXWUKhaz5+K/C8BU/iaxeEmpHQjkOQbGKd0tsFQUNd 3kFg== X-Gm-Message-State: AOAM531dcw8Vq6t5N6Ng6XuYQV8YjZ6T/7XHNwDviD6ez+qcmHwpuwT4 nsbclYLUFIaSJmL62/KXr3areTkoymh2xZfoLJ8MWrRbN/aeRZblRSPePtyjpbGtLPXr7ATlSbx Ue9JtG2H2Xh9tKigMLJF/5OCpluMvth4oZkanN4YbyFYtlqb57IMzfspbjslN X-Received: by 2002:a1c:9a47:: with SMTP id c68mr577794wme.63.1616454037829; Mon, 22 Mar 2021 16:00:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH1oEJxVVjMqsdEb7i27VnHFsMIJZoafdc+02Hvuc414s4ZfqrG3NoCFtR+VtktrA57BQnqg== X-Received: by 2002:a1c:9a47:: with SMTP id c68mr577769wme.63.1616454037550; Mon, 22 Mar 2021 16:00:37 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id x11sm814815wme.9.2021.03.22.16.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:37 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:35 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 18/19] acpi: Set proper maximum size for "etc/acpi/rsdp" blob Message-ID: <20210322225907.541943-19-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Richard Henderson , Alistair Francis , Shannon Zhao , Paolo Bonzini , Igor Mammedov , Laszlo Ersek Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's also set a maximum size for "etc/acpi/rsdp", so the maximum size doesn't get implicitly set based on the initial table size. In my experiments, the table size was in the range of 22 bytes, so a single page (== what we used until now) seems to be good enough. Now that we have defined maximum sizes for all currently used table types, let's assert that we catch usage with new tables that need a proper maximum size definition. Also assert that our initial size does not exceed the maximum size; while qemu_ram_alloc_internal() properly asserts that the initial RAMBlock size is <= its maximum size, the result might differ when the host page size is bigger than 4k. Suggested-by: Laszlo Ersek Cc: Alistair Francis Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Peter Maydell Cc: Shannon Zhao Cc: Marcel Apfelbaum Cc: Paolo Bonzini Cc: Richard Henderson Cc: Laszlo Ersek Signed-off-by: David Hildenbrand Message-Id: <20210304105554.121674-5-david@redhat.com> Reviewed-by: Laszlo Ersek Reviewed-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/utils.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/acpi/utils.c b/hw/acpi/utils.c index f2d69a6d92..0c486ea29f 100644 --- a/hw/acpi/utils.c +++ b/hw/acpi/utils.c @@ -29,14 +29,19 @@ MemoryRegion *acpi_add_rom_blob(FWCfgCallback update, void *opaque, GArray *blob, const char *name) { - uint64_t max_size = 0; + uint64_t max_size; /* Reserve RAM space for tables: add another order of magnitude. */ if (!strcmp(name, ACPI_BUILD_TABLE_FILE)) { max_size = 0x200000; } else if (!strcmp(name, ACPI_BUILD_LOADER_FILE)) { max_size = 0x10000; + } else if (!strcmp(name, ACPI_BUILD_RSDP_FILE)) { + max_size = 0x1000; + } else { + g_assert_not_reached(); } + g_assert(acpi_data_len(blob) <= max_size); return rom_add_blob(name, blob->data, acpi_data_len(blob), max_size, -1, name, update, opaque, NULL, true); From patchwork Mon Mar 22 23:00:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1456870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GhpPeXkn; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F49Sz3xtGz9sVt for ; Tue, 23 Mar 2021 10:20:03 +1100 (AEDT) Received: from localhost ([::1]:39822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOTq4-0007vy-Dw for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 19:20:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOTXV-0007RN-38 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21749) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lOTXS-0001OS-2r for qemu-devel@nongnu.org; Mon, 22 Mar 2021 19:00:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616454045; 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=7QMpITZSGUKZibXovsWgyeItbCiwAguqi/2S/1J5HDs=; b=GhpPeXknjZE3FBLxacAYTLvcMytegjGHKKfmCIi2lY/nYheoDSOOr/9yPe8DSmlZqPA2r1 myVGLbH06ptUSg2QGyn8/JMkf+JK2ONO5cizXMic0vOlm4yHBHbaVuhfiN7J7BTpe1wyaw aprQzsawoYkn0dYghdFvFyQN39yKjeA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-526-Kt2BbuaWOgO7ckLq0w-mNg-1; Mon, 22 Mar 2021 19:00:43 -0400 X-MC-Unique: Kt2BbuaWOgO7ckLq0w-mNg-1 Received: by mail-wr1-f70.google.com with SMTP id i5so152306wrp.8 for ; Mon, 22 Mar 2021 16:00:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7QMpITZSGUKZibXovsWgyeItbCiwAguqi/2S/1J5HDs=; b=Tfe2Vussdqx5uj2oAhdmkG24Va9o5PyzoeYQW79zTtK9aZd7zE4jo8cGUPu06fMAD2 rAAolcVulXu2Vu5wG3kQ1JQxcpccMwmVPSJ/tg9my1XPSXHk5m9K8gDjtsByaVwQmnfw VMgWZvOazgZqTyo3zyX3i2NgbM/QdJYP4tjELY5T4hXDRVMhabqDWO5/piTd3C39zmo2 sUpz1k4gIBtJ9gUX7Z2jWbs1bbFCPobnHaVsmhRQaw+dAQk/g6M0prZCfMQqCaeOTBiY MJCKinrzqb3raf6bv0Rada7J6rQWbRMjz9FPRGBDz803bhm9/OEqNt0/RfmRpEJ7k+u0 Ln3Q== X-Gm-Message-State: AOAM533DXCoYN6Wce+Xiu18KH19vBtwwslUhI8owCC3VPzNBk231ldtk AvAmDfh4EkZ4v3KG5frNwIYcFokGvc9Zbnj5Eb6o6hqdB65j6mYy+4uDWl9OWjgcwoVefMFkD2d WjiNvNqbBxcRe6X++ZhJqbLZ/Uu4NTiSbxAgzvmUADps4uLijaVuBj8IvMqOt X-Received: by 2002:a05:600c:1992:: with SMTP id t18mr572589wmq.125.1616454040724; Mon, 22 Mar 2021 16:00:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmtYxeWOqPM2eAqPRJeouTLBKuNAU+A6LAVyX0F6frWtAc3UAxIBZh44YPMXUYW/+Ujiiafw== X-Received: by 2002:a05:600c:1992:: with SMTP id t18mr572560wmq.125.1616454040371; Mon, 22 Mar 2021 16:00:40 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id y1sm712271wmq.29.2021.03.22.16.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 16:00:39 -0700 (PDT) Date: Mon, 22 Mar 2021 19:00:37 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v2 19/19] acpi: Move setters/getters of oem fields to X86MachineState Message-ID: <20210322225907.541943-20-mst@redhat.com> References: <20210322225907.541943-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210322225907.541943-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Sergio Lopez , Richard Henderson , Marian Postevca , Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marian Postevca The code that sets/gets oem fields is duplicated in both PC and MICROVM variants. This commit moves it to X86MachineState so that all x86 variants can use it and duplication is removed. Signed-off-by: Marian Postevca Message-Id: <20210221001737.24499-2-posteuca@mutex.one> Reviewed-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/microvm.h | 4 --- include/hw/i386/pc.h | 4 --- include/hw/i386/x86.h | 4 +++ hw/i386/acpi-build.c | 48 ++++++++++++++-------------- hw/i386/acpi-microvm.c | 16 +++++----- hw/i386/microvm.c | 66 --------------------------------------- hw/i386/pc.c | 63 ------------------------------------- hw/i386/x86.c | 64 +++++++++++++++++++++++++++++++++++++ 8 files changed, 100 insertions(+), 169 deletions(-) diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h index 372b05774e..f25f837441 100644 --- a/include/hw/i386/microvm.h +++ b/include/hw/i386/microvm.h @@ -76,8 +76,6 @@ #define MICROVM_MACHINE_ISA_SERIAL "isa-serial" #define MICROVM_MACHINE_OPTION_ROMS "x-option-roms" #define MICROVM_MACHINE_AUTO_KERNEL_CMDLINE "auto-kernel-cmdline" -#define MICROVM_MACHINE_OEM_ID "oem-id" -#define MICROVM_MACHINE_OEM_TABLE_ID "oem-table-id" struct MicrovmMachineClass { X86MachineClass parent; @@ -106,8 +104,6 @@ struct MicrovmMachineState { Notifier machine_done; Notifier powerdown_req; struct GPEXConfig gpex; - char *oem_id; - char *oem_table_id; }; #define TYPE_MICROVM_MACHINE MACHINE_TYPE_NAME("microvm") diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index d4c3d73c11..dcf060b791 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -46,8 +46,6 @@ typedef struct PCMachineState { bool pit_enabled; bool hpet_enabled; uint64_t max_fw_size; - char *oem_id; - char *oem_table_id; /* NUMA information: */ uint64_t numa_nodes; @@ -65,8 +63,6 @@ typedef struct PCMachineState { #define PC_MACHINE_SATA "sata" #define PC_MACHINE_PIT "pit" #define PC_MACHINE_MAX_FW_SIZE "max-fw-size" -#define PC_MACHINE_OEM_ID "oem-id" -#define PC_MACHINE_OEM_TABLE_ID "oem-table-id" /** * PCMachineClass: * diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 56080bd1fb..26c9cc45a4 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -67,6 +67,8 @@ struct X86MachineState { OnOffAuto smm; OnOffAuto acpi; + char *oem_id; + char *oem_table_id; /* * Address space used by IOAPIC device. All IOAPIC interrupts * will be translated to MSI messages in the address space. @@ -76,6 +78,8 @@ struct X86MachineState { #define X86_MACHINE_SMM "smm" #define X86_MACHINE_ACPI "acpi" +#define X86_MACHINE_OEM_ID "oem-id" +#define X86_MACHINE_OEM_TABLE_ID "oem-table-id" #define TYPE_X86_MACHINE MACHINE_TYPE_NAME("x86") OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86_MACHINE) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 3aeae15e57..de98750aef 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1807,7 +1807,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len); build_header(linker, table_data, (void *)(table_data->data + table_data->len - dsdt->buf->len), - "DSDT", dsdt->buf->len, 1, pcms->oem_id, pcms->oem_table_id); + "DSDT", dsdt->buf->len, 1, x86ms->oem_id, x86ms->oem_table_id); free_aml_allocator(); } @@ -1984,8 +1984,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) build_header(linker, table_data, (void *)(table_data->data + srat_start), "SRAT", - table_data->len - srat_start, 1, pcms->oem_id, - pcms->oem_table_id); + table_data->len - srat_start, 1, x86ms->oem_id, + x86ms->oem_table_id); } /* @@ -2338,13 +2338,13 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) if (slic_oem.id) { oem_id = slic_oem.id; } else { - oem_id = pcms->oem_id; + oem_id = x86ms->oem_id; } if (slic_oem.table_id) { oem_table_id = slic_oem.table_id; } else { - oem_table_id = pcms->oem_table_id; + oem_table_id = x86ms->oem_table_id; } table_offsets = g_array_new(false, true /* clear */, @@ -2385,30 +2385,30 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) acpi_add_table(table_offsets, tables_blob); acpi_build_madt(tables_blob, tables->linker, x86ms, - ACPI_DEVICE_IF(x86ms->acpi_dev), pcms->oem_id, - pcms->oem_table_id); + ACPI_DEVICE_IF(x86ms->acpi_dev), x86ms->oem_id, + x86ms->oem_table_id); vmgenid_dev = find_vmgenid_dev(); if (vmgenid_dev) { acpi_add_table(table_offsets, tables_blob); vmgenid_build_acpi(VMGENID(vmgenid_dev), tables_blob, - tables->vmgenid, tables->linker, pcms->oem_id); + tables->vmgenid, tables->linker, x86ms->oem_id); } if (misc.has_hpet) { acpi_add_table(table_offsets, tables_blob); - build_hpet(tables_blob, tables->linker, pcms->oem_id, - pcms->oem_table_id); + build_hpet(tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); } if (misc.tpm_version != TPM_VERSION_UNSPEC) { if (misc.tpm_version == TPM_VERSION_1_2) { acpi_add_table(table_offsets, tables_blob); build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog, - pcms->oem_id, pcms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id); } else { /* TPM_VERSION_2_0 */ acpi_add_table(table_offsets, tables_blob); build_tpm2(tables_blob, tables->linker, tables->tcpalog, - pcms->oem_id, pcms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id); } } if (pcms->numa_nodes) { @@ -2416,40 +2416,40 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) build_srat(tables_blob, tables->linker, machine); if (machine->numa_state->have_numa_distance) { acpi_add_table(table_offsets, tables_blob); - build_slit(tables_blob, tables->linker, machine, pcms->oem_id, - pcms->oem_table_id); + build_slit(tables_blob, tables->linker, machine, x86ms->oem_id, + x86ms->oem_table_id); } if (machine->numa_state->hmat_enabled) { acpi_add_table(table_offsets, tables_blob); build_hmat(tables_blob, tables->linker, machine->numa_state, - pcms->oem_id, pcms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id); } } if (acpi_get_mcfg(&mcfg)) { acpi_add_table(table_offsets, tables_blob); - build_mcfg(tables_blob, tables->linker, &mcfg, pcms->oem_id, - pcms->oem_table_id); + build_mcfg(tables_blob, tables->linker, &mcfg, x86ms->oem_id, + x86ms->oem_table_id); } if (x86_iommu_get_default()) { IommuType IOMMUType = x86_iommu_get_type(); if (IOMMUType == TYPE_AMD) { acpi_add_table(table_offsets, tables_blob); - build_amd_iommu(tables_blob, tables->linker, pcms->oem_id, - pcms->oem_table_id); + build_amd_iommu(tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); } else if (IOMMUType == TYPE_INTEL) { acpi_add_table(table_offsets, tables_blob); - build_dmar_q35(tables_blob, tables->linker, pcms->oem_id, - pcms->oem_table_id); + build_dmar_q35(tables_blob, tables->linker, x86ms->oem_id, + x86ms->oem_table_id); } } if (machine->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker, machine->nvdimms_state, machine->ram_slots, - pcms->oem_id, pcms->oem_table_id); + x86ms->oem_id, x86ms->oem_table_id); } acpi_add_table(table_offsets, tables_blob); - build_waet(tables_blob, tables->linker, pcms->oem_id, pcms->oem_table_id); + build_waet(tables_blob, tables->linker, x86ms->oem_id, x86ms->oem_table_id); /* Add tables supplied by user (if any) */ for (u = acpi_table_first(); u; u = acpi_table_next(u)) { @@ -2468,7 +2468,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) { AcpiRsdpData rsdp_data = { .revision = 0, - .oem_id = pcms->oem_id, + .oem_id = x86ms->oem_id, .xsdt_tbl_offset = NULL, .rsdt_tbl_offset = &rsdt, }; diff --git a/hw/i386/acpi-microvm.c b/hw/i386/acpi-microvm.c index 271710eb92..ccd3303aac 100644 --- a/hw/i386/acpi-microvm.c +++ b/hw/i386/acpi-microvm.c @@ -149,7 +149,7 @@ build_dsdt_microvm(GArray *table_data, BIOSLinker *linker, g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len); build_header(linker, table_data, (void *)(table_data->data + table_data->len - dsdt->buf->len), - "DSDT", dsdt->buf->len, 2, mms->oem_id, mms->oem_table_id); + "DSDT", dsdt->buf->len, 2, x86ms->oem_id, x86ms->oem_table_id); free_aml_allocator(); } @@ -201,24 +201,24 @@ static void acpi_build_microvm(AcpiBuildTables *tables, pmfadt.dsdt_tbl_offset = &dsdt; pmfadt.xdsdt_tbl_offset = &dsdt; acpi_add_table(table_offsets, tables_blob); - build_fadt(tables_blob, tables->linker, &pmfadt, mms->oem_id, - mms->oem_table_id); + build_fadt(tables_blob, tables->linker, &pmfadt, x86ms->oem_id, + x86ms->oem_table_id); acpi_add_table(table_offsets, tables_blob); acpi_build_madt(tables_blob, tables->linker, X86_MACHINE(machine), - ACPI_DEVICE_IF(x86ms->acpi_dev), mms->oem_id, - mms->oem_table_id); + ACPI_DEVICE_IF(x86ms->acpi_dev), x86ms->oem_id, + x86ms->oem_table_id); xsdt = tables_blob->len; - build_xsdt(tables_blob, tables->linker, table_offsets, mms->oem_id, - mms->oem_table_id); + build_xsdt(tables_blob, tables->linker, table_offsets, x86ms->oem_id, + x86ms->oem_table_id); /* RSDP is in FSEG memory, so allocate it separately */ { AcpiRsdpData rsdp_data = { /* ACPI 2.0: 5.2.4.3 RSDP Structure */ .revision = 2, /* xsdt needs v2 */ - .oem_id = mms->oem_id, + .oem_id = x86ms->oem_id, .xsdt_tbl_offset = &xsdt, .rsdt_tbl_offset = NULL, }; diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 4e0cf4c522..edf2b0f061 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -648,51 +648,6 @@ static void microvm_powerdown_req(Notifier *notifier, void *data) } } -static char *microvm_machine_get_oem_id(Object *obj, Error **errp) -{ - MicrovmMachineState *mms = MICROVM_MACHINE(obj); - - return g_strdup(mms->oem_id); -} - -static void microvm_machine_set_oem_id(Object *obj, const char *value, - Error **errp) -{ - MicrovmMachineState *mms = MICROVM_MACHINE(obj); - size_t len = strlen(value); - - if (len > 6) { - error_setg(errp, - "User specified "MICROVM_MACHINE_OEM_ID" value is bigger than " - "6 bytes in size"); - return; - } - - strncpy(mms->oem_id, value, 6); -} - -static char *microvm_machine_get_oem_table_id(Object *obj, Error **errp) -{ - MicrovmMachineState *mms = MICROVM_MACHINE(obj); - - return g_strdup(mms->oem_table_id); -} - -static void microvm_machine_set_oem_table_id(Object *obj, const char *value, - Error **errp) -{ - MicrovmMachineState *mms = MICROVM_MACHINE(obj); - size_t len = strlen(value); - - if (len > 8) { - error_setg(errp, - "User specified "MICROVM_MACHINE_OEM_TABLE_ID" value is bigger than " - "8 bytes in size"); - return; - } - strncpy(mms->oem_table_id, value, 8); -} - static void microvm_machine_initfn(Object *obj) { MicrovmMachineState *mms = MICROVM_MACHINE(obj); @@ -714,9 +669,6 @@ static void microvm_machine_initfn(Object *obj) qemu_add_machine_init_done_notifier(&mms->machine_done); mms->powerdown_req.notify = microvm_powerdown_req; qemu_register_powerdown_notifier(&mms->powerdown_req); - - mms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6); - mms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8); } static void microvm_class_init(ObjectClass *oc, void *data) @@ -805,24 +757,6 @@ static void microvm_class_init(ObjectClass *oc, void *data) MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, "Set off to disable adding virtio-mmio devices to the kernel cmdline"); - object_class_property_add_str(oc, MICROVM_MACHINE_OEM_ID, - microvm_machine_get_oem_id, - microvm_machine_set_oem_id); - object_class_property_set_description(oc, MICROVM_MACHINE_OEM_ID, - "Override the default value of field OEMID " - "in ACPI table header." - "The string may be up to 6 bytes in size"); - - - object_class_property_add_str(oc, MICROVM_MACHINE_OEM_TABLE_ID, - microvm_machine_get_oem_table_id, - microvm_machine_set_oem_table_id); - object_class_property_set_description(oc, MICROVM_MACHINE_OEM_TABLE_ID, - "Override the default value of field OEM Table ID " - "in ACPI table header." - "The string may be up to 8 bytes in size"); - - machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 35e1770950..8a84b25a03 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1608,49 +1608,6 @@ static void pc_machine_set_max_fw_size(Object *obj, Visitor *v, pcms->max_fw_size = value; } -static char *pc_machine_get_oem_id(Object *obj, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - - return g_strdup(pcms->oem_id); -} - -static void pc_machine_set_oem_id(Object *obj, const char *value, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - size_t len = strlen(value); - - if (len > 6) { - error_setg(errp, - "User specified "PC_MACHINE_OEM_ID" value is bigger than " - "6 bytes in size"); - return; - } - - strncpy(pcms->oem_id, value, 6); -} - -static char *pc_machine_get_oem_table_id(Object *obj, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - - return g_strdup(pcms->oem_table_id); -} - -static void pc_machine_set_oem_table_id(Object *obj, const char *value, - Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - size_t len = strlen(value); - - if (len > 8) { - error_setg(errp, - "User specified "PC_MACHINE_OEM_TABLE_ID" value is bigger than " - "8 bytes in size"); - return; - } - strncpy(pcms->oem_table_id, value, 8); -} static void pc_machine_initfn(Object *obj) { @@ -1664,8 +1621,6 @@ static void pc_machine_initfn(Object *obj) pcms->max_ram_below_4g = 0; /* use default */ /* acpi build is enabled by default if machine supports it */ pcms->acpi_build_enabled = PC_MACHINE_GET_CLASS(pcms)->has_acpi_build; - pcms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6); - pcms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8); pcms->smbus_enabled = true; pcms->sata_enabled = true; pcms->pit_enabled = true; @@ -1802,24 +1757,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) NULL, NULL); object_class_property_set_description(oc, PC_MACHINE_MAX_FW_SIZE, "Maximum combined firmware size"); - - object_class_property_add_str(oc, PC_MACHINE_OEM_ID, - pc_machine_get_oem_id, - pc_machine_set_oem_id); - object_class_property_set_description(oc, PC_MACHINE_OEM_ID, - "Override the default value of field OEMID " - "in ACPI table header." - "The string may be up to 6 bytes in size"); - - - object_class_property_add_str(oc, PC_MACHINE_OEM_TABLE_ID, - pc_machine_get_oem_table_id, - pc_machine_set_oem_table_id); - object_class_property_set_description(oc, PC_MACHINE_OEM_TABLE_ID, - "Override the default value of field OEM Table ID " - "in ACPI table header." - "The string may be up to 8 bytes in size"); - } static const TypeInfo pc_machine_info = { diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 7865660e2c..ed796fe6ba 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1201,6 +1201,51 @@ static void x86_machine_set_acpi(Object *obj, Visitor *v, const char *name, visit_type_OnOffAuto(v, name, &x86ms->acpi, errp); } +static char *x86_machine_get_oem_id(Object *obj, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + + return g_strdup(x86ms->oem_id); +} + +static void x86_machine_set_oem_id(Object *obj, const char *value, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + size_t len = strlen(value); + + if (len > 6) { + error_setg(errp, + "User specified "X86_MACHINE_OEM_ID" value is bigger than " + "6 bytes in size"); + return; + } + + strncpy(x86ms->oem_id, value, 6); +} + +static char *x86_machine_get_oem_table_id(Object *obj, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + + return g_strdup(x86ms->oem_table_id); +} + +static void x86_machine_set_oem_table_id(Object *obj, const char *value, + Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + size_t len = strlen(value); + + if (len > 8) { + error_setg(errp, + "User specified "X86_MACHINE_OEM_TABLE_ID + " value is bigger than " + "8 bytes in size"); + return; + } + strncpy(x86ms->oem_table_id, value, 8); +} + static void x86_machine_initfn(Object *obj) { X86MachineState *x86ms = X86_MACHINE(obj); @@ -1209,6 +1254,8 @@ static void x86_machine_initfn(Object *obj) x86ms->acpi = ON_OFF_AUTO_AUTO; x86ms->smp_dies = 1; x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS; + x86ms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6); + x86ms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8); } static void x86_machine_class_init(ObjectClass *oc, void *data) @@ -1235,6 +1282,23 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) NULL, NULL); object_class_property_set_description(oc, X86_MACHINE_ACPI, "Enable ACPI"); + + object_class_property_add_str(oc, X86_MACHINE_OEM_ID, + x86_machine_get_oem_id, + x86_machine_set_oem_id); + object_class_property_set_description(oc, X86_MACHINE_OEM_ID, + "Override the default value of field OEMID " + "in ACPI table header." + "The string may be up to 6 bytes in size"); + + + object_class_property_add_str(oc, X86_MACHINE_OEM_TABLE_ID, + x86_machine_get_oem_table_id, + x86_machine_set_oem_table_id); + object_class_property_set_description(oc, X86_MACHINE_OEM_TABLE_ID, + "Override the default value of field OEM Table ID " + "in ACPI table header." + "The string may be up to 8 bytes in size"); } static const TypeInfo x86_machine_info = {