From patchwork Mon Dec 5 09:51:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631044 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2422304pvb; Mon, 5 Dec 2022 01:54:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf4STrDYifkch9+QikFov/wB8KT5tnJDu8JiA2g2+FNU7xAJUk84bxMDdlfaUWeg77dy7aBU X-Received: by 2002:ac8:4792:0:b0:3a7:e606:2783 with SMTP id k18-20020ac84792000000b003a7e6062783mr1578587qtq.511.1670234074456; Mon, 05 Dec 2022 01:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234074; cv=none; d=google.com; s=arc-20160816; b=T+YAYhhgKayelkAe/T3lZ5BdXDAa+YhewNKUg+tjdyITchDMtosgM1R7yz15ge86zb xz2S9lYxnXV9DUwatkKAJICVj3wmAqZbDRBaf3PC84/euSjH6BVUDaxvJSL/5x7zgVq8 iTCQ1r/apx/2PIE+s9mvsGZ93c54LOuVVj5paSLZf3q7N6T8gn8sew62ozM+6y2EOUjq 3iD09a3HzTOVv6xB+9w86cG1HrGHMUqyF5dF19IjEsChU+6bmXmx2/9Gn+DqlEwPYUCZ 339oPdckfo1XTh5XF9x3ub1m5+MOFUcwjVNWyVUyEln50/GxWBTAcro31qgXJ6AlwsUl b1BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gM1FzBim53KQXgBVytxLzbWYxEf9vN7NkiErlAjlFr4=; b=SiW1Cdw8Ror8Ggl63DZERSK6Dq6KvuVAxic9eTOAOvDRyohYY7ozeebBevmIsr1geA pfwXHq9E96kw0K25zTgv7ugxvyGL1c6M3KYE3+x8SjiigSoHS5arH8MOC1t9nSRcH4H7 v06P6i+C0BPXA6PJXQnesU1KuFY5CW525vVRi+PDrTMkP6xDmvikCc98HqdVomFwuz04 PT1AWZfQC5sDU73uSdkbpkqaSQSgS7TdH6w/aQUENToVK3jVhzH3RT11W8+07nvGpa/F QTCS6yZGrAubpRUwqHyp+ia1rtMOigbjKRl4ZW9IBrkb2je61KcNM3kz/+Saa9E12NuU mS9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="KzQkt/tc"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r16-20020ac87ef0000000b003a622111f5csi7163081qtc.787.2022.12.05.01.54.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 01:54:34 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="KzQkt/tc"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28AH-0000gB-PN; Mon, 05 Dec 2022 04:53:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28A2-0000b9-U5 for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p289w-0006Pi-U5 for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670233991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gM1FzBim53KQXgBVytxLzbWYxEf9vN7NkiErlAjlFr4=; b=KzQkt/tc7jHKpS/ZW/kiObBg8cz+d0BNM3vy1o6kib/YzBTLRhhl7unUK8G7FCXbsrRKmD ZlKiP717BqVgQT9rUcawdMj8y+FA2bMeEN79Wf05pBEx/1lm2axYSjo7SS7/j6nJPQc/uh zYv/9e2Q8jv09D5Rh40e6lNoKSMmgYI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-232-y6LLJ39VMn-SjpfmQaPpNg-1; Mon, 05 Dec 2022 04:53:06 -0500 X-MC-Unique: y6LLJ39VMn-SjpfmQaPpNg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F4AA1C09B82; Mon, 5 Dec 2022 09:53:05 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BFA32166B29; Mon, 5 Dec 2022 09:52:57 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wilfred Mallawa , Pavel Dovgalyuk Subject: [PATCH v2 03/51] replay: Fix declaration of replay_read_next_clock Date: Mon, 5 Dec 2022 10:51:40 +0100 Message-Id: <20221205095228.1314-4-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Fixes the build with gcc 13: replay/replay-time.c:34:6: error: conflicting types for \ 'replay_read_next_clock' due to enum/integer mismatch; \ have 'void(ReplayClockKind)' [-Werror=enum-int-mismatch] 34 | void replay_read_next_clock(ReplayClockKind kind) | ^~~~~~~~~~~~~~~~~~~~~~ In file included from ../qemu/replay/replay-time.c:14: replay/replay-internal.h:139:6: note: previous declaration of \ 'replay_read_next_clock' with type 'void(unsigned int)' 139 | void replay_read_next_clock(unsigned int kind); | ^~~~~~~~~~~~~~~~~~~~~~ Fixes: 8eda206e090 ("replay: recording and replaying clock ticks") Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Wilfred Mallawa Reviewed-by: Pavel Dovgalyuk Signed-off-by: Stefan Hajnoczi Message-Id: <20221129010547.284051-1-richard.henderson@linaro.org> --- replay/replay-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 89e377be90..b6836354ac 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -136,7 +136,7 @@ bool replay_next_event_is(int event); /*! Reads next clock value from the file. If clock kind read from the file is different from the parameter, the value is not used. */ -void replay_read_next_clock(unsigned int kind); +void replay_read_next_clock(ReplayClockKind kind); /* Asynchronous events queue */ From patchwork Mon Dec 5 09:51:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631045 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2422334pvb; Mon, 5 Dec 2022 01:54:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ka4B+lsFtVU4MAsZFjx5Jr8tsLsBddiq2cnKPY4YUD2mJUuBKiywmHUdylXSBtABlv3Uy X-Received: by 2002:a0c:edcf:0:b0:4b3:fe67:349d with SMTP id i15-20020a0cedcf000000b004b3fe67349dmr74565090qvr.60.1670234078007; Mon, 05 Dec 2022 01:54:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234078; cv=none; d=google.com; s=arc-20160816; b=Hqxr3WAFiLoVdXHQxkUzl1OifCc9WZZeEjPR/LjpIb/0hiATrDdN+f8YQGSzvbyth/ Pj3IprmCJiJrvzkqQF+YTKTl9cx+EHGQHxA3fEaoJEwBkgBq8ymMR1D1gTJcuaQxsDMk btLZYZSAfuNQtAridLabJuEYhRHJ+14ryZ6ofncVQDaPexmll1iQI1n+Arl2oHxtd8sp 0/LRU0MPE9JjhGPz7FeMMzIk2Wfp4pKYu2vx8XlKoq48oKZ63X/O95xCXXVTYsrcNBEr iN77itMK+wZeleWcLzlsUAlpigxut9lkJ0ZXQJ/OS4zjcz/dlYGIOQlX8jeajIFV6HyL hZkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i2+Mno2782955D37e2Tk3rpJLYwAGRf+TLqC5a0fYsE=; b=HnMxnlkCTLq+dHLausrDpowg0biCl23SY0buD/QjsN2KB/migg6DrbkrQKesU7CmjI 7XGdzCuGiSlFVTGPOcoRmdb766zLDbTGcOxzhI+KqXSl5tkIN0DDd72kWQLDW+7bG1lH lD8PTWEBjW8zGslwEfsQ2zn+K02hjZ8j7EOWYBvzTqtMpRF++7nrmvPKZtQ2JolwoX8/ PysAtS95mVVzaBecBH/WZbP/6aDyUT9doaxxhsJzagu4ZSlSBmCdig6VVregj+uEbR+G 2XFjg7GxTUgJw1Sa6rxJQKVHxPFujpxD45zdq2kQSdz+CdKQYGAu2DMjR3fvJJKcrqo3 SX6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gt0X0oqc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i14-20020ac8488e000000b003a7e7f08f6esi267773qtq.737.2022.12.05.01.54.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 01:54:38 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gt0X0oqc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28AM-0000lS-Ns; Mon, 05 Dec 2022 04:53:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28A5-0000c6-Du for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28A2-0006Qm-AB for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670233997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i2+Mno2782955D37e2Tk3rpJLYwAGRf+TLqC5a0fYsE=; b=Gt0X0oqclauMlmYCZexZ5PycCHQLKs41W3j3WE5aw9OwC328mx4vfwhnehtYpHeBCIEL79 Xlj3P81DpvM6uggj96Y78DQJgOOFmXn/iaQG4j3QMNXd8s3oMYXelvoIO7JMQGjG4XPViu A6yr0ziTHE0ABQx5IaLF/LtURCXKH0U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-CHUk4CsCOM6mJ6mmfIORaw-1; Mon, 05 Dec 2022 04:53:14 -0500 X-MC-Unique: CHUk4CsCOM6mJ6mmfIORaw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FD6E894E81; Mon, 5 Dec 2022 09:53:13 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B08C2166B29; Mon, 5 Dec 2022 09:53:05 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= Subject: [PATCH v2 04/51] hw/display/qxl: Have qxl_log_command Return early if no log_cmd handler Date: Mon, 5 Dec 2022 10:51:41 +0100 Message-Id: <20221205095228.1314-5-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Only 3 command types are logged: no need to call qxl_phys2virt() for the other types. Using different cases will help to pass different structure sizes to qxl_phys2virt() in a pair of commits. Reviewed-by: Marc-André Lureau Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Stefan Hajnoczi Message-Id: <20221128202741.4945-2-philmd@linaro.org> --- hw/display/qxl-logger.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/display/qxl-logger.c b/hw/display/qxl-logger.c index 68bfa47568..1bcf803db6 100644 --- a/hw/display/qxl-logger.c +++ b/hw/display/qxl-logger.c @@ -247,6 +247,16 @@ int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext) qxl_name(qxl_type, ext->cmd.type), compat ? "(compat)" : ""); + switch (ext->cmd.type) { + case QXL_CMD_DRAW: + break; + case QXL_CMD_SURFACE: + break; + case QXL_CMD_CURSOR: + break; + default: + goto out; + } data = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); if (!data) { return 1; @@ -269,6 +279,7 @@ int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext) qxl_log_cmd_cursor(qxl, data, ext->group_id); break; } +out: fprintf(stderr, "\n"); return 0; } From patchwork Mon Dec 5 09:51:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631049 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2427029pvb; Mon, 5 Dec 2022 02:05:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf6I3rfGoJhqWgdrk5XvDq+loDsTrgcJvqMU9tgasUOh52iJtJJ6135age9gy9uLvbB8yXnG X-Received: by 2002:a0c:ef0b:0:b0:4c6:e904:3582 with SMTP id t11-20020a0cef0b000000b004c6e9043582mr40483671qvr.112.1670234753929; Mon, 05 Dec 2022 02:05:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234753; cv=none; d=google.com; s=arc-20160816; b=sQRbimAzrbhFCdv2CVEbdU1S3zmPg7e9hhViSnO4zEwP+ckNw5GeoLMOASE0utOyjO UXeig2AvPmcjlCqVg5FUox4rnLmXUPFP08fYb7/n9vZ3znwKY9axm80kueonBZTx8gh3 C7u1UL/2c5oqFYo1qWsspvNwlEyv2EcE2/2kLKJBebWZFPFFAY/4PmtW4x0zZYHq+hni J/iJPSTglihYiB0Gyd9jTQshBRwhBLo2/eJa1w5IzX7ETF/OB1ABTt9U2xqJz0uqbVVZ TvFZ+Zwx7wwpeCaoVhFqNNHiKvsR7wiSnFQ1trILIaFU5HwhCswlPfhgbwjPkablnPEf +Z4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vhSDhIeSjhWPGH/YRvNS3wqYgEd3nq856LWIZM6CoaU=; b=K1FNUqUn45oTA8i7NbsE3wo8gZSWZXeoEa0xtG+5VPM0V/c9+TfR34HGI6R96K8+T1 wXkxY9nSGvx1yGUgA9pWk2S/+D/VpJct59F5eN8HoLdSHcckFqeM7o1B/G03bggygcfm Ncrgp/CxR33V1+dfe52VyDCa4EeYl9LQJywdYmF5bX7TN9ajatgmp2zmU3Jf+UeNN7Ll 12kz0xOaD7Da2aKCIhEL2N411Q0H/qJkwG63unFErq9DSGeMrc5bmiu87gRSczN7cyKv 1iexkYwxG6uz3HD7/Xt4Tsr6aMYcmN87UYEGl3udvNmukQl66gnd8WiWNR+96xtfXcKO CyVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TQx617ha; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x12-20020a05620a14ac00b006febf853eb5si1251519qkj.759.2022.12.05.02.05.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:05:53 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TQx617ha; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28AM-0000lG-Ds; Mon, 05 Dec 2022 04:53:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28AB-0000dX-9z for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28A8-0006SA-NH for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vhSDhIeSjhWPGH/YRvNS3wqYgEd3nq856LWIZM6CoaU=; b=TQx617hakVnVntdBm40+3qOPKND1LYLeR+cT0y44gHWmuhCuD6+bCDR/3A+AosvaKOPz0H A7vOmpEBT86sC8ntLofY4f9qzqXNKu+uHKN3WI2zzHtNq+BhyvCS9z+mz3poSbiblFlOxB pMeokZVgWrgaKYyB9+Pp9TqsXDurAgU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-8YXU1xDhMUavtm--5Ww-Tg-1; Mon, 05 Dec 2022 04:53:22 -0500 X-MC-Unique: 8YXU1xDhMUavtm--5Ww-Tg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1CC73C0E204; Mon, 5 Dec 2022 09:53:20 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C8BD2166B29; Mon, 5 Dec 2022 09:53:13 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= Subject: [PATCH v2 05/51] hw/display/qxl: Document qxl_phys2virt() Date: Mon, 5 Dec 2022 10:51:42 +0100 Message-Id: <20221205095228.1314-6-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Reviewed-by: Marc-André Lureau Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Stefan Hajnoczi Message-Id: <20221128202741.4945-3-philmd@linaro.org> --- hw/display/qxl.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/display/qxl.h b/hw/display/qxl.h index e74de9579d..78b3a6c9ba 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -147,6 +147,25 @@ OBJECT_DECLARE_SIMPLE_TYPE(PCIQXLDevice, PCI_QXL) #define QXL_DEFAULT_REVISION (QXL_REVISION_STABLE_V12 + 1) /* qxl.c */ +/** + * qxl_phys2virt: Get a pointer within a PCI VRAM memory region. + * + * @qxl: QXL device + * @phys: physical offset of buffer within the VRAM + * @group_id: memory slot group + * + * Returns a host pointer to a buffer placed at offset @phys within the + * active slot @group_id of the PCI VGA RAM memory region associated with + * the @qxl device. If the slot is inactive, or the offset is out + * of the memory region, returns NULL. + * + * Use with care; by the time this function returns, the returned pointer is + * not protected by RCU anymore. If the caller is not within an RCU critical + * section and does not hold the iothread lock, it must have other means of + * protecting the pointer, such as a reference to the region that includes + * the incoming ram_addr_t. + * + */ void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id); void qxl_set_guest_bug(PCIQXLDevice *qxl, const char *msg, ...) G_GNUC_PRINTF(2, 3); From patchwork Mon Dec 5 09:51:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631048 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2426566pvb; Mon, 5 Dec 2022 02:04:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf49FUAKoC/VHtnSlQcfI9HSbY6mFMjCOBOc0yLoj2LPf8IdeS19ARVmLZuGW9gk6f894ih+ X-Received: by 2002:a0c:c602:0:b0:49c:699b:d5cf with SMTP id v2-20020a0cc602000000b0049c699bd5cfmr62303685qvi.126.1670234687761; Mon, 05 Dec 2022 02:04:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234687; cv=none; d=google.com; s=arc-20160816; b=YOYNshBgIAmlHNS7O4lr3QKhKuhmSghmQEOpi9tY92FUrK+QtYCvh+vfQ+kw0C4wU2 mV1jBEDkWCZlBNTjSYwdoOcXwEH1Q3GzGFV9epkWO9pdLIs62ZNYZrRxPKwfIrR5Q76B jcOstt1ODqjjpf6tgu6oesBd64n1/rCWbPhmBOIwFMlVOEbkkfeLi9ddirOUTgje1BEI Qm6YIhhlvYxhET4wVj1P08cPelG2FdsgTalzT+T/ZC1/+hBpjL0vAQBH3EASUrTEx9m7 9g/MjUc8jZOMUo8OLkcirqSjSY3CXjwr9RF/kDQyD1t8vtzszlCul29Z1n9NrBx/PR0r MfRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jwMT4Bso8g+QZEocTdEaOsjlcxvk1sa133j9SQ/bU+8=; b=uom+NKzuzAe23rXf6sFfFcJU+YJqBSLCHebelyo9cDmM+NSL5eMJtLN9K2tVS3rTRY zhxBCUnN0LwwojxCCg5/G1s1UhRcORu9o7POFuRv/S81Syx2D0DpI788zq/73+gG7azl nEuebAXLQjyr2lL0rwMldXtk3QLdxirETyw1CUaPFeIHJVVu2HAM4FNTRtJyYE7CBmQK vpl6dxjPYeRE7rzX5Al0RoK3ZwPnG+CvzAINcDxVX2S5WiYmjqn9qvxQhFUOPYEw/Rjq ztWnMl+L8h3zZfVcF02OQ98BiqbyFQlSw8RySgKJIdJupiXt/jVB55wiIh1hcsWvqQY+ VoHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iaxYstRW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id br39-20020a05620a462700b006fa26adea98si8539428qkb.68.2022.12.05.02.04.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:04:47 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iaxYstRW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Aa-00014l-9Y; Mon, 05 Dec 2022 04:53:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28AY-00013V-PV for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28AH-0006Tw-SQ for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jwMT4Bso8g+QZEocTdEaOsjlcxvk1sa133j9SQ/bU+8=; b=iaxYstRWYuQUUxDESAoB4VX7sffFMhc3LM/q6uocRaC0fUuGtH6TlL+H/BJTJwQMB/ke6K Shs6BsO8LhSiqKg999FhfBjkdN8gCEdwrSUsNARau6lbPqNUeSChk7cRulWEE8u5BCSMrp uCVMBTrpYqZY8b3Fe6WtZap8h5lEGms= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-Hb6V3QcrONa-b0idYxANAw-1; Mon, 05 Dec 2022 04:53:30 -0500 X-MC-Unique: Hb6V3QcrONa-b0idYxANAw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FDE13C0E206; Mon, 5 Dec 2022 09:53:28 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AF7F2166B29; Mon, 5 Dec 2022 09:53:21 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 06/51] hw/display/qxl: Pass requested buffer size to qxl_phys2virt() Date: Mon, 5 Dec 2022 10:51:43 +0100 Message-Id: <20221205095228.1314-7-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Currently qxl_phys2virt() doesn't check for buffer overrun. In order to do so in the next commit, pass the buffer size as argument. For QXLCursor in qxl_render_cursor() -> qxl_cursor() we verify the size of the chunked data ahead, checking we can access 'sizeof(QXLCursor) + chunk->data_size' bytes. Since in the SPICE_CURSOR_TYPE_MONO case the cursor is assumed to fit in one chunk, no change are required. In SPICE_CURSOR_TYPE_ALPHA the ahead read is handled in qxl_unpack_chunks(). Signed-off-by: Philippe Mathieu-Daudé Acked-by: Gerd Hoffmann Signed-off-by: Stefan Hajnoczi Message-Id: <20221128202741.4945-4-philmd@linaro.org> --- hw/display/qxl.h | 4 +++- hw/display/qxl-logger.c | 11 ++++++++--- hw/display/qxl-render.c | 20 ++++++++++++++++---- hw/display/qxl.c | 14 +++++++++----- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/hw/display/qxl.h b/hw/display/qxl.h index 78b3a6c9ba..bf03138ab4 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -153,6 +153,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(PCIQXLDevice, PCI_QXL) * @qxl: QXL device * @phys: physical offset of buffer within the VRAM * @group_id: memory slot group + * @size: size of the buffer * * Returns a host pointer to a buffer placed at offset @phys within the * active slot @group_id of the PCI VGA RAM memory region associated with @@ -166,7 +167,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(PCIQXLDevice, PCI_QXL) * the incoming ram_addr_t. * */ -void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id); +void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id, + size_t size); void qxl_set_guest_bug(PCIQXLDevice *qxl, const char *msg, ...) G_GNUC_PRINTF(2, 3); diff --git a/hw/display/qxl-logger.c b/hw/display/qxl-logger.c index 1bcf803db6..35c38f6252 100644 --- a/hw/display/qxl-logger.c +++ b/hw/display/qxl-logger.c @@ -106,7 +106,7 @@ static int qxl_log_image(PCIQXLDevice *qxl, QXLPHYSICAL addr, int group_id) QXLImage *image; QXLImageDescriptor *desc; - image = qxl_phys2virt(qxl, addr, group_id); + image = qxl_phys2virt(qxl, addr, group_id, sizeof(QXLImage)); if (!image) { return 1; } @@ -214,7 +214,8 @@ int qxl_log_cmd_cursor(PCIQXLDevice *qxl, QXLCursorCmd *cmd, int group_id) cmd->u.set.position.y, cmd->u.set.visible ? "yes" : "no", cmd->u.set.shape); - cursor = qxl_phys2virt(qxl, cmd->u.set.shape, group_id); + cursor = qxl_phys2virt(qxl, cmd->u.set.shape, group_id, + sizeof(QXLCursor)); if (!cursor) { return 1; } @@ -236,6 +237,7 @@ int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext) { bool compat = ext->flags & QXL_COMMAND_FLAG_COMPAT; void *data; + size_t datasz; int ret; if (!qxl->cmdlog) { @@ -249,15 +251,18 @@ int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext) switch (ext->cmd.type) { case QXL_CMD_DRAW: + datasz = compat ? sizeof(QXLCompatDrawable) : sizeof(QXLDrawable); break; case QXL_CMD_SURFACE: + datasz = sizeof(QXLSurfaceCmd); break; case QXL_CMD_CURSOR: + datasz = sizeof(QXLCursorCmd); break; default: goto out; } - data = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); + data = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id, datasz); if (!data) { return 1; } diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c index ca217004bf..fcfd40c3ac 100644 --- a/hw/display/qxl-render.c +++ b/hw/display/qxl-render.c @@ -107,7 +107,9 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) qxl->guest_primary.resized = 0; qxl->guest_primary.data = qxl_phys2virt(qxl, qxl->guest_primary.surface.mem, - MEMSLOT_GROUP_GUEST); + MEMSLOT_GROUP_GUEST, + qxl->guest_primary.abs_stride + * height); if (!qxl->guest_primary.data) { goto end; } @@ -228,7 +230,8 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl, if (offset == size) { return; } - chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id); + chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id, + sizeof(QXLDataChunk) + chunk->data_size); if (!chunk) { return; } @@ -295,7 +298,8 @@ fail: /* called from spice server thread context only */ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext) { - QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); + QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id, + sizeof(QXLCursorCmd)); QXLCursor *cursor; QEMUCursor *c; @@ -314,7 +318,15 @@ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext) } switch (cmd->type) { case QXL_CURSOR_SET: - cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id); + /* First read the QXLCursor to get QXLDataChunk::data_size ... */ + cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id, + sizeof(QXLCursor)); + if (!cursor) { + return 1; + } + /* Then read including the chunked data following QXLCursor. */ + cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id, + sizeof(QXLCursor) + cursor->chunk.data_size); if (!cursor) { return 1; } diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 5b10f697f1..231d733250 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -274,7 +274,8 @@ static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay) QXL_IO_MONITORS_CONFIG_ASYNC)); } - cfg = qxl_phys2virt(qxl, qxl->guest_monitors_config, MEMSLOT_GROUP_GUEST); + cfg = qxl_phys2virt(qxl, qxl->guest_monitors_config, MEMSLOT_GROUP_GUEST, + sizeof(QXLMonitorsConfig)); if (cfg != NULL && cfg->count == 1) { qxl->guest_primary.resized = 1; qxl->guest_head0_width = cfg->heads[0].width; @@ -459,7 +460,8 @@ static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext) switch (le32_to_cpu(ext->cmd.type)) { case QXL_CMD_SURFACE: { - QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); + QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id, + sizeof(QXLSurfaceCmd)); if (!cmd) { return 1; @@ -494,7 +496,8 @@ static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext) } case QXL_CMD_CURSOR: { - QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); + QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id, + sizeof(QXLCursorCmd)); if (!cmd) { return 1; @@ -1456,7 +1459,8 @@ static bool qxl_get_check_slot_offset(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, } /* can be also called from spice server thread context */ -void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id) +void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id, + size_t size) { uint64_t offset; uint32_t slot; @@ -1964,7 +1968,7 @@ static void qxl_dirty_surfaces(PCIQXLDevice *qxl) } cmd = qxl_phys2virt(qxl, qxl->guest_surfaces.cmds[i], - MEMSLOT_GROUP_GUEST); + MEMSLOT_GROUP_GUEST, sizeof(QXLSurfaceCmd)); assert(cmd); assert(cmd->type == QXL_SURFACE_CMD_CREATE); qxl_dirty_one_surface(qxl, cmd->u.surface_create.data, From patchwork Mon Dec 5 09:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631050 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2428545pvb; Mon, 5 Dec 2022 02:09:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5bCGBD21HRB+DinH2y/CH86MMda3YPCsg6IK2WaoH27m+hNS4Eda5oo00/LBA7XQx3GFAi X-Received: by 2002:a05:622a:6014:b0:3a6:8f2f:d0cc with SMTP id he20-20020a05622a601400b003a68f2fd0ccmr19535884qtb.412.1670234982772; Mon, 05 Dec 2022 02:09:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234982; cv=none; d=google.com; s=arc-20160816; b=fhDXWZhHKSiEu+mLqmA9sA4O6XNg7lNgA3wDM5kLBg370R3vJ6zR4b6jpCmnMpz+Tj OIuk0Za6r8QJG1zxJEOLupgD6KR+SW4Dz6qqRglqDrdrQrEZ2wLfYulp5XoDB1wPXcBF B6oHagmIz/LDwQie9YOynsxBIo1jn2BkG1gRgDwPYyF5VCQHQ5R7F4S1Mo1NSArx3jlP agO+Mg84SX6kav6Bg99s9vQhwQzdC2fzQ/tuOrpsvP3HANrrdTKv2CoXaBQSiw+25Qdg bAXcOe95MWclvbHx8+4gpyXiAOrVFCvOnmFhEiceZZ8kxVn6LNlSqr2wnBpCf5V15EbY L5BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5SGCfToDbM9WhOy+q3kxZx78SijHUnLuNZHHeTrr+MM=; b=VZd2B8uPat9ohct0emZwpHAWgPMzzT2NMNOnQNWM4fZ/QCzM6oWcaYN5yhgBB98WzK jfv55O0zgnGwYWqEJx7f5m7rrSirJeXb3dl6eodjKk0w1AsSMeAz9fqDJUpECvAKoylC XRpGGUGUfp2j38X9ZdWKAqtPaHynMXjHcPoRjCCk2j4CL98JU9HTunWO9f7dnvFP8ydL NWJswwubj7G8WPJXG3o6Au0dnz4XumTFeysqUxtHkjDochKmXBy24PNQt4+6KdMFFAt+ cPsu73dETqcuqSt9p7MXB6vAhEUPr/GPnh7Cse8kL3VX5Ms/JtfbUZvKST/+BMkYW/qS V3dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dJmSUhZ5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z7-20020ac84547000000b0039cbb79da6asi5798193qtn.346.2022.12.05.02.09.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:09:42 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dJmSUhZ5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28AT-0000uW-4P; Mon, 05 Dec 2022 04:53:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28AQ-0000qd-UI for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28AP-0006Vn-4r for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SGCfToDbM9WhOy+q3kxZx78SijHUnLuNZHHeTrr+MM=; b=dJmSUhZ5zv6IJN8q3hsNbWHtS60OYAQ8jyPQA+rcfoqAI+BMh5dp5vu9prZP7heh12TS4T p5rQCBsXJIW3FUXs2rHaV7w2SmHAxerZlXy8c62ie0QwJYhrO5g9x2a+kifMT/jd4eAbeB bLml/iyDtkSKg9sghBXKBPVe+XaCdJU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-z77S-848PwCeZE2Tmiy1Ew-1; Mon, 05 Dec 2022 04:53:37 -0500 X-MC-Unique: z77S-848PwCeZE2Tmiy1Ew-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A304862FEC; Mon, 5 Dec 2022 09:53:36 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED0652166B29; Mon, 5 Dec 2022 09:53:28 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 07/51] hw/display/qxl: Avoid buffer overrun in qxl_phys2virt (CVE-2022-4144) Date: Mon, 5 Dec 2022 10:51:44 +0100 Message-Id: <20221205095228.1314-8-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Have qxl_get_check_slot_offset() return false if the requested buffer size does not fit within the slot memory region. Similarly qxl_phys2virt() now returns NULL in such case, and qxl_dirty_one_surface() aborts. This avoids buffer overrun in the host pointer returned by memory_region_get_ram_ptr(). Fixes: CVE-2022-4144 (out-of-bounds read) Reported-by: Wenxu Yin (@awxylitol) Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1336 Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Stefan Hajnoczi Message-Id: <20221128202741.4945-5-philmd@linaro.org> --- hw/display/qxl.h | 2 +- hw/display/qxl.c | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hw/display/qxl.h b/hw/display/qxl.h index bf03138ab4..7894bd5134 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -157,7 +157,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(PCIQXLDevice, PCI_QXL) * * Returns a host pointer to a buffer placed at offset @phys within the * active slot @group_id of the PCI VGA RAM memory region associated with - * the @qxl device. If the slot is inactive, or the offset is out + * the @qxl device. If the slot is inactive, or the offset + size are out * of the memory region, returns NULL. * * Use with care; by the time this function returns, the returned pointer is diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 231d733250..0b21626aad 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1424,11 +1424,13 @@ static void qxl_reset_surfaces(PCIQXLDevice *d) /* can be also called from spice server thread context */ static bool qxl_get_check_slot_offset(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, - uint32_t *s, uint64_t *o) + uint32_t *s, uint64_t *o, + size_t size_requested) { uint64_t phys = le64_to_cpu(pqxl); uint32_t slot = (phys >> (64 - 8)) & 0xff; uint64_t offset = phys & 0xffffffffffff; + uint64_t size_available; if (slot >= NUM_MEMSLOTS) { qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot, @@ -1452,6 +1454,23 @@ static bool qxl_get_check_slot_offset(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, slot, offset, qxl->guest_slots[slot].size); return false; } + size_available = memory_region_size(qxl->guest_slots[slot].mr); + if (qxl->guest_slots[slot].offset + offset >= size_available) { + qxl_set_guest_bug(qxl, + "slot %d offset %"PRIu64" > region size %"PRIu64"\n", + slot, qxl->guest_slots[slot].offset + offset, + size_available); + return false; + } + size_available -= qxl->guest_slots[slot].offset + offset; + if (size_requested > size_available) { + qxl_set_guest_bug(qxl, + "slot %d offset %"PRIu64" size %zu: " + "overrun by %"PRIu64" bytes\n", + slot, offset, size_requested, + size_requested - size_available); + return false; + } *s = slot; *o = offset; @@ -1471,7 +1490,7 @@ void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id, offset = le64_to_cpu(pqxl) & 0xffffffffffff; return (void *)(intptr_t)offset; case MEMSLOT_GROUP_GUEST: - if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset)) { + if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset, size)) { return NULL; } ptr = memory_region_get_ram_ptr(qxl->guest_slots[slot].mr); @@ -1937,9 +1956,9 @@ static void qxl_dirty_one_surface(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, uint32_t slot; bool rc; - rc = qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset); - assert(rc == true); size = (uint64_t)height * abs(stride); + rc = qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset, size); + assert(rc == true); trace_qxl_surfaces_dirty(qxl->id, offset, size); qxl_set_dirty(qxl->guest_slots[slot].mr, qxl->guest_slots[slot].offset + offset, From patchwork Mon Dec 5 09:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631054 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2439273pvb; Mon, 5 Dec 2022 02:38:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6PgEiuolVQ5h1LMSpKoj0xaTLSRSw+huGIf/c5xsvQ1Gpac3vjsbTq+QjGZuEGNdLVRtmp X-Received: by 2002:a05:622a:40ca:b0:3a6:328d:ee8e with SMTP id ch10-20020a05622a40ca00b003a6328dee8emr60072996qtb.421.1670236720816; Mon, 05 Dec 2022 02:38:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670236720; cv=none; d=google.com; s=arc-20160816; b=s1WUE9EPyHKaRyADGFGVuNtvJ6ATcZQsQBICLDQdtF5jVwzI9l0h7+GjZtaGeaGuJL MnLd91ssYwdICSVdBwyaneBhs5UZ5QNHw8coOI0Gd/3LIQDwRdLOKJfpryP/I9X+18r7 KR/i38dHvZahW5PIIgtKrx3p1HTOw8UcEh2zoEdFLd0sSoY9g/2ouqm3DrFXCCHDzGX8 4jNpH57YZcyiidncDopsABqovbOXDFUbWoWTGOnJKJ5kliIoiGYsUitFr6Y5jg2DnHPK dXP81Rygv6yuFOnj0z87KskeR5VzEG1NpJP4HrE2kVv0+MoUnKnVUXJ5VkWlOv5G2tjV hGeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sWawvSWadu0bL+au53S7AJrJqJZVUFdCmV8iHivocyk=; b=ZYwUlbEqcADmGvd964IctvuT1KUwBL35e//0GiZh6q6lF4wQGIat//PKtEkk28T2LV AFyNZH5MUYueH+o3br329UqHQFjYesPUtXL8526fkte4uCrbbEeMXVawa7Est866c9Bw HvBZp5O9ekI5E/M3HgazrWVK2L6Cbf5GR6HH3OdIhl0J910LbaSB0JAxKEMZA0WlExjn fBeulH9NkseX2EUiL844xwJIZzs7unEnzPMHSOaz16DS80i4vEftCWcBkMHJvGMDPD0P qq3XZyQm7y3raf+cTlqwQ1fHPMarRlC+5d2qX9DcnZtd5daUOAyNUkIdeajuEtHA+xMa MOpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C8yFVILy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id hu14-20020a056214234e00b004bb65f4940asi428958qvb.377.2022.12.05.02.38.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:38:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C8yFVILy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Ad-00016j-2k; Mon, 05 Dec 2022 04:53:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28Ab-00015L-Kj for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28Aa-0006Y3-3R for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:53:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sWawvSWadu0bL+au53S7AJrJqJZVUFdCmV8iHivocyk=; b=C8yFVILyjXiZ8kqUpyh2yX8GLEPMRRIOjIGzEMcnfkvRVNGsMXW2qkX/5neNej0B30/nYo ZgJ6Eb1BITUaGFfiPUavsvDOV/Lu+nFp/7AgssL+xuWvEWE6WcgDUwq/9kKS62CgtoWnVx jIC0LIzwVgXLkKw9Rc3SRpnDh+g5uVs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-392-aAy9LTFLPj6yCjW41-Z7hg-1; Mon, 05 Dec 2022 04:53:45 -0500 X-MC-Unique: aAy9LTFLPj6yCjW41-Z7hg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C0F185A588; Mon, 5 Dec 2022 09:53:44 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id D73122166B29; Mon, 5 Dec 2022 09:53:36 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 08/51] hw/display/qxl: Assert memory slot fits in preallocated MemoryRegion Date: Mon, 5 Dec 2022 10:51:45 +0100 Message-Id: <20221205095228.1314-9-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Stefan Hajnoczi Message-Id: <20221128202741.4945-6-philmd@linaro.org> --- hw/display/qxl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 0b21626aad..6772849dec 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1384,6 +1384,7 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta, qxl_set_guest_bug(d, "%s: pci_region = %d", __func__, pci_region); return 1; } + assert(guest_end - pci_start <= memory_region_size(mr)); virt_start = (intptr_t)memory_region_get_ram_ptr(mr); memslot.slot_id = slot_id; From patchwork Mon Dec 5 09:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631046 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2423843pvb; Mon, 5 Dec 2022 01:59:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Ka7X7TNdFaEcoEgIFQMOSQNB6b5FDUjPkCV5UjGU2vIoemoG53mb1e6WXtnoVUj3HUGXR X-Received: by 2002:a05:620a:201c:b0:6ce:51a0:a80e with SMTP id c28-20020a05620a201c00b006ce51a0a80emr70914570qka.591.1670234347478; Mon, 05 Dec 2022 01:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234347; cv=none; d=google.com; s=arc-20160816; b=tCUISQ18TUW+yS7qVh5oVMONmQ5h3M5u2Jh7EpnBvmstaITCmz16yRxvGsa7ReJxts OYKw9dfRsEgoPL35TzIZNIy7ghE1IGMdDZZYsXtRlUEEDTTPeiuxdFmusR91XT7Veqxh DD+fkraCrAvEqwWKBSJ81i8ZmhJzozqEglPSDKdG4YkTaGW9vLltvyYSbajcViY7mEsB BKX2RsbGZ+kTySAUZ1TQaHLYZs/NRCyeH/MvcsnVClSvVOuhyXgyS1XqvavXC0axsAW4 ogNIF/T/TdUhjMDW5Y8sZXgCrb5hKPpH58nubIXViLNcCLHNYJziMfkL3HjSxaINGbYu BSqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JzR6LoP80zahpbmKbQVOVIoUoQ6EpDTG7DyoVVDdz14=; b=P+UYF78YLDYK8D9TE7Q9D7/+hcST/4sGdLzwB5DavTDzBh4BbhYyE8wqiGMj1ffKLD bW814DqOUHBOW2VpyZWI4j5d9iFvVpS7CkY7mIuj65wjF+gecB1/BwOW6Wedtgp6vlKL +WDcT8XZ9+p6H4mAUxs+Py3yxDWGo/hENblQYgKZhpFcI9ma2zu4TSPtRrYEGmsKBCVR zcqh+Lgk/wU3j3YvOed8JNDv2hImIW7a43OI8oyVGS8IP+An/IRfgO/vizas4rdNp0IO 8DLNGSditom8L75cjbHQNlzUrgPG07hEITEltNimLaM42wTUiCIj1ldnHwbPOgnGS8fh UnFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bEjnPzKf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l4-20020a378904000000b006fec601fc23si403960qkd.477.2022.12.05.01.59.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 01:59:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bEjnPzKf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28B9-0001hZ-IH; Mon, 05 Dec 2022 04:54:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28B5-0001be-8w for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28B3-0006ga-Ob for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JzR6LoP80zahpbmKbQVOVIoUoQ6EpDTG7DyoVVDdz14=; b=bEjnPzKfJlIs3/gwzjcfRzawCwEirnI2v6v8hxfj6ge9EVNXY9gqlwlMjJgGy/C8hjU9nG UItlqBwNdmMHu45oMINSq2EaUZ8tIqT3uLE7Ijjvf84Hl+lPbkijpmnSD2A4C/d1X6QL2Q fHn6n2xCSrvqXaiZ+x2Od86PAFPRVqU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-V-jSwxfUPjSLf24igefaqw-1; Mon, 05 Dec 2022 04:54:15 -0500 X-MC-Unique: V-jSwxfUPjSLf24igefaqw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CBA01101A54E; Mon, 5 Dec 2022 09:54:14 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id A245F2166B29; Mon, 5 Dec 2022 09:54:07 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz Subject: [PATCH v2 12/51] tests/qtests: override "force-legacy" for gpio virtio-mmio tests Date: Mon, 5 Dec 2022 10:51:49 +0100 Message-Id: <20221205095228.1314-13-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée The GPIO device is a VIRTIO_F_VERSION_1 devices but running with a legacy MMIO interface we miss out that feature bit causing confusion. For the GPIO test force the mmio bus to support non-legacy so we can properly test it. Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1333 Message-Id: <20221130112439.2527228-2-alex.bennee@linaro.org> Acked-by: Thomas Huth Signed-off-by: Michael S. Tsirkin --- tests/qtest/libqos/virtio-gpio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-gpio.c index 762aa6695b..f22d7b5eb5 100644 --- a/tests/qtest/libqos/virtio-gpio.c +++ b/tests/qtest/libqos/virtio-gpio.c @@ -154,7 +154,8 @@ static void virtio_gpio_register_nodes(void) QOSGraphEdgeOptions edge_opts = { }; /* vhost-user-gpio-device */ - edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test"; + edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test " + "-global virtio-mmio.force-legacy=false"; qos_node_create_driver("vhost-user-gpio-device", virtio_gpio_device_create); qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts); From patchwork Mon Dec 5 09:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631051 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2428619pvb; Mon, 5 Dec 2022 02:09:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4KbFGL2+WoJRSiugS3dvYw+FMnu2VwHm0s/MN74+VGyXC4H88//zVo+E4+WgkblRU8W5BE X-Received: by 2002:a05:620a:8d3:b0:6fa:23d4:aecc with SMTP id z19-20020a05620a08d300b006fa23d4aeccmr55105528qkz.678.1670234994497; Mon, 05 Dec 2022 02:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234994; cv=none; d=google.com; s=arc-20160816; b=Tab4GUX6C/kFH7iiLfo9i8MTzd3UoB15rRkcsl0xRq/svCGwEZnVw9CIX9R2UFGRWu 9gxHUbUh5RmKikJKpv8OXZypEPWoCeDhb+X66sDfDf/EmRXcDVphs9Bev7d8LdKoGVJj 0XgNdAK4mjI0ApeV7p3xmX89ODsR1pxXCbXZ8aiES1OTDeTE66QkHdltgAm6ZfAXklYn tmDtxpm/25bvyBN4m+Rlp7OZj7yWD+5HjLJGW5/wcCFFQYYG9ZAycmpCRUu+z+YYPLr9 jV9Uji8MTIYvyOfFt6gtjjHwAg3O4lyiUnS/ZTI/ArAnygKSrMh/9apJ+aUkIZ/pfPZd n2hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VpGPqFxym62K9GH7MKfAV+SJq1q0meLvnvyfpQU3Eqk=; b=L582j7zvoQz4+IMhiWboiTXbe6RnxK7ee5VjRqe0E7gWrsnYQGQfxCGr9KJoNizFcl o4ARV+a6qYYGNb/JFVj20nbYNa7U0VnrdxLvdZzJArPa6e/xpqxiY+R6svkqPX+VaZtR pzoy4d9+LTmnPO1/OmOJg0y7Quajtw5/6XLchHNQF109PbllRcE5vVb3/NKsbRAc2Z/4 O3sQRENw/PCgeT/k/tQCt3Frpp8ZUSqQjgyzznpdEBUN+OEgMuG66cxZ2cYS6OYbM39p xaJWJUE9ICqIolTJjj5LsbQfN8SGdDdLzm1e8iG4MkycOAvAKdqU+qjOF1i4m14fPjwm av3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PN9alLA+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n6-20020a05620a294600b006f983fcbec5si8147279qkp.559.2022.12.05.02.09.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:09:54 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PN9alLA+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Bb-000252-Dm; Mon, 05 Dec 2022 04:54:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BN-0001sn-Es for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BJ-0006sS-3a for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VpGPqFxym62K9GH7MKfAV+SJq1q0meLvnvyfpQU3Eqk=; b=PN9alLA+pQ55KGC0k9EGbY9UKHN9bkdEuvM3CiHPMFSPdxf0Gu+4iru0HNq0OwuSC7i0tV FMy1i3vN+orK3zAtFFQcfW8TAuZep1Lwmgv25dANBK/8dlpZEJxvECf5SpHhrWpMM6spTE 9eJaDSqUrxqTLS+hvMJiS+yEcOX7nTA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-263-AUpsFNRrNQKqMyJYVcGvEQ-1; Mon, 05 Dec 2022 04:54:31 -0500 X-MC-Unique: AUpsFNRrNQKqMyJYVcGvEQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E9A6299E755; Mon, 5 Dec 2022 09:54:30 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32C382166B29; Mon, 5 Dec 2022 09:54:23 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz Subject: [PATCH v2 14/51] hw/virtio: add started_vu status field to vhost-user-gpio Date: Mon, 5 Dec 2022 10:51:51 +0100 Message-Id: <20221205095228.1314-15-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée As per the fix to vhost-user-blk in f5b22d06fb (vhost: recheck dev state in the vhost_migration_log routine) we really should track the connection and starting separately. Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Message-Id: <20221130112439.2527228-4-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-gpio.h | 10 ++++++++++ hw/virtio/vhost-user-gpio.c | 11 ++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-user-gpio.h index 4fe9aeecc0..a9305c5e6c 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -28,7 +28,17 @@ struct VHostUserGPIO { VhostUserState vhost_user; VirtQueue *command_vq; VirtQueue *interrupt_vq; + /** + * There are at least two steps of initialization of the + * vhost-user device. The first is a "connect" step and + * second is a "start" step. Make a separation between + * those initialization phases by using two fields. + * + * @connected: see vu_gpio_connect()/vu_gpio_disconnect() + * @started_vu: see vu_gpio_start()/vu_gpio_stop() + */ bool connected; + bool started_vu; /*< public >*/ }; diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 0b40ebd15a..be9be08b4c 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -86,6 +86,7 @@ static int vu_gpio_start(VirtIODevice *vdev) error_report("Error starting vhost-user-gpio: %d", ret); goto err_guest_notifiers; } + gpio->started_vu = true; /* * guest_notifier_mask/pending not used yet, so just unmask @@ -126,16 +127,12 @@ static void vu_gpio_stop(VirtIODevice *vdev) struct vhost_dev *vhost_dev = &gpio->vhost_dev; int ret; - if (!k->set_guest_notifiers) { + if (!gpio->started_vu) { return; } + gpio->started_vu = false; - /* - * We can call vu_gpio_stop multiple times, for example from - * vm_state_notify and the final object finalisation. Check we - * aren't already stopped before doing so. - */ - if (!vhost_dev_is_started(vhost_dev)) { + if (!k->set_guest_notifiers) { return; } From patchwork Mon Dec 5 09:51:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631052 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2429452pvb; Mon, 5 Dec 2022 02:11:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Tkr0ipofoxJndf/ODzl1jBamrri2xHMO/jeL8fHi0/9yyhr7nM6JYYOeeeyXJBkIOMPnQ X-Received: by 2002:a05:622a:514b:b0:3a6:97f9:506b with SMTP id ew11-20020a05622a514b00b003a697f9506bmr13098446qtb.265.1670235110802; Mon, 05 Dec 2022 02:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670235110; cv=none; d=google.com; s=arc-20160816; b=DrhTc8w4Qyxaao7B9E6OOmiI4KjvzgeuTPSrhm8+iRZVD8AEuQDjHSOyIPf3IZMbef zN28O8SChCUcaTAWkjGEeVwEzGSY4nAWGJaEtF+oekvab0DiJoEunN0B3tLOpdhbwr0S dqwf0ldfCIAgqI3j0KuKwUl+tnxDrkI7TH9tXHtQNtntw+qfZezRNlupcldQJvnMY1hr BANh4pL89h3SLtncBbaNidYpC80h9JMCczALV/8YPWA+aScedUTlVSailmlmYXnO241m wGh14xm0juo+D0qgZ+H73R+kfBIKZAqjU9GXE+oAgux2QH7McNvC7I4cXdYHTRJMkdVc Wvxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wv3mQ50z7ELRb+0PxbMX5qClEbrZYnNWGDwG8BSgdlg=; b=YQNB2BJIAscIuiJSZShv1EbyizSLj5QA4VTvW8WGRfFMjqb+OBpzI6HCsPJWnh4uEi QhKSnUyIg40DyAbiLZ+UYwQRjqvTbLgOWKlGzBHvEXIDPRb4aHapG1YTu9YV79V+bOjx m6dewFEqFqA4Y3BV+NngRzpQ5csB70TcepbvUfU+wX+41Zof61NZoo5X+pYuAqebjVmX xDwlDkhAvw44EVE15th/IFCBHUFSd1xhnHD+wBUfTF2XeGweVA8Ldj9fdpW8ytT9H49Y zdhtVZvvAjy+yTx3stjeBmn4ilvKKjibQ3hq6eOiv/Xg4PbsYy5YETHcz4DuNy9EaMp4 Au9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OEeKb8Nl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay31-20020a05622a229f00b003a7e514c7fcsi1017377qtb.600.2022.12.05.02.11.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:11:50 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OEeKb8Nl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Bf-0002G0-As; Mon, 05 Dec 2022 04:54:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BT-0001xx-9s for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BP-0006wx-SL for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wv3mQ50z7ELRb+0PxbMX5qClEbrZYnNWGDwG8BSgdlg=; b=OEeKb8NlIf+HwalK72K5FStBYR0UwDUb0NOL8qCxadf+miCWeuBX9/DNV5qfgTTb0TGr/S W+Ix9t0EiWndbNLQ9QTFVam4CdpN+Xwpa2/ZEKr6sI1ehv+6WmSuzTTH6T7eQXRIH4tHMC sLdPq2EhQJckNbVGVOj9CmDtlVQOAXw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-47-SDGhJug8OKyBI7Not_p4Fg-1; Mon, 05 Dec 2022 04:54:39 -0500 X-MC-Unique: SDGhJug8OKyBI7Not_p4Fg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD957101A52A; Mon, 5 Dec 2022 09:54:37 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE8AE2166B30; Mon, 5 Dec 2022 09:54:30 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz Subject: [PATCH v2 15/51] hw/virtio: generalise CHR_EVENT_CLOSED handling Date: Mon, 5 Dec 2022 10:51:52 +0100 Message-Id: <20221205095228.1314-16-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée ..and use for both virtio-user-blk and virtio-user-gpio. This avoids the circular close by deferring shutdown due to disconnection until a later point. virtio-user-blk already had this mechanism in place so generalise it as a vhost-user helper function and use for both blk and gpio devices. While we are at it we also fix up vhost-user-gpio to re-establish the event handler after close down so we can reconnect later. Signed-off-by: Alex Bennée Reviewed-by: Michael S. Tsirkin Reviewed-by: Raphael Norwitz Message-Id: <20221130112439.2527228-5-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user.h | 18 +++++++++ hw/block/vhost-user-blk.c | 41 +++----------------- hw/virtio/vhost-user-gpio.c | 11 +++++- hw/virtio/vhost-user.c | 71 ++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 37 deletions(-) diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index c6e693cd3f..191216a74f 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -68,4 +68,22 @@ bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp); */ void vhost_user_cleanup(VhostUserState *user); +/** + * vhost_user_async_close() - cleanup vhost-user post connection drop + * @d: DeviceState for the associated device (passed to callback) + * @chardev: the CharBackend associated with the connection + * @vhost: the common vhost device + * @cb: the user callback function to complete the clean-up + * + * This function is used to handle the shutdown of a vhost-user + * connection to a backend. We handle this centrally to make sure we + * do all the steps and handle potential races due to VM shutdowns. + * Once the connection is disabled we call a backhalf to ensure + */ +typedef void (*vu_async_close_fn)(DeviceState *cb); + +void vhost_user_async_close(DeviceState *d, + CharBackend *chardev, struct vhost_dev *vhost, + vu_async_close_fn cb); + #endif diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1177064631..aff4d2b8cb 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -369,17 +369,10 @@ static void vhost_user_blk_disconnect(DeviceState *dev) vhost_user_blk_stop(vdev); vhost_dev_cleanup(&s->dev); -} -static void vhost_user_blk_chr_closed_bh(void *opaque) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBlk *s = VHOST_USER_BLK(vdev); - - vhost_user_blk_disconnect(dev); + /* Re-instate the event handler for new connections */ qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, - NULL, opaque, NULL, true); + NULL, dev, NULL, true); } static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) @@ -398,33 +391,9 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) } break; case CHR_EVENT_CLOSED: - if (!runstate_check(RUN_STATE_SHUTDOWN)) { - /* - * A close event may happen during a read/write, but vhost - * code assumes the vhost_dev remains setup, so delay the - * stop & clear. - */ - AioContext *ctx = qemu_get_current_aio_context(); - - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL, - NULL, NULL, false); - aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opaque); - - /* - * Move vhost device to the stopped state. The vhost-user device - * will be clean up and disconnected in BH. This can be useful in - * the vhost migration code. If disconnect was caught there is an - * option for the general vhost code to get the dev state without - * knowing its type (in this case vhost-user). - * - * FIXME: this is sketchy to be reaching into vhost_dev - * now because we are forcing something that implies we - * have executed vhost_dev_stop() but that won't happen - * until vhost_user_blk_stop() gets called from the bh. - * Really this state check should be tracked locally. - */ - s->dev.started = false; - } + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &s->chardev, &s->dev, + vhost_user_blk_disconnect); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index be9be08b4c..b7b82a1099 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -233,6 +233,8 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp) return 0; } +static void vu_gpio_event(void *opaque, QEMUChrEvent event); + static void vu_gpio_disconnect(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -245,6 +247,11 @@ static void vu_gpio_disconnect(DeviceState *dev) vu_gpio_stop(vdev); vhost_dev_cleanup(&gpio->vhost_dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&gpio->chardev, + NULL, NULL, vu_gpio_event, + NULL, dev, NULL, true); } static void vu_gpio_event(void *opaque, QEMUChrEvent event) @@ -262,7 +269,9 @@ static void vu_gpio_event(void *opaque, QEMUChrEvent event) } break; case CHR_EVENT_CLOSED: - vu_gpio_disconnect(dev); + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, + vu_gpio_disconnect); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index abe23d4ebe..8f635844af 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -21,6 +21,7 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" +#include "sysemu/runstate.h" #include "sysemu/cryptodev.h" #include "migration/migration.h" #include "migration/postcopy-ram.h" @@ -2670,6 +2671,76 @@ void vhost_user_cleanup(VhostUserState *user) user->chr = NULL; } + +typedef struct { + vu_async_close_fn cb; + DeviceState *dev; + CharBackend *cd; + struct vhost_dev *vhost; +} VhostAsyncCallback; + +static void vhost_user_async_close_bh(void *opaque) +{ + VhostAsyncCallback *data = opaque; + struct vhost_dev *vhost = data->vhost; + + /* + * If the vhost_dev has been cleared in the meantime there is + * nothing left to do as some other path has completed the + * cleanup. + */ + if (vhost->vdev) { + data->cb(data->dev); + } + + g_free(data); +} + +/* + * We only schedule the work if the machine is running. If suspended + * we want to keep all the in-flight data as is for migration + * purposes. + */ +void vhost_user_async_close(DeviceState *d, + CharBackend *chardev, struct vhost_dev *vhost, + vu_async_close_fn cb) +{ + if (!runstate_check(RUN_STATE_SHUTDOWN)) { + /* + * A close event may happen during a read/write, but vhost + * code assumes the vhost_dev remains setup, so delay the + * stop & clear. + */ + AioContext *ctx = qemu_get_current_aio_context(); + VhostAsyncCallback *data = g_new0(VhostAsyncCallback, 1); + + /* Save data for the callback */ + data->cb = cb; + data->dev = d; + data->cd = chardev; + data->vhost = vhost; + + /* Disable any further notifications on the chardev */ + qemu_chr_fe_set_handlers(chardev, + NULL, NULL, NULL, NULL, NULL, NULL, + false); + + aio_bh_schedule_oneshot(ctx, vhost_user_async_close_bh, data); + + /* + * Move vhost device to the stopped state. The vhost-user device + * will be clean up and disconnected in BH. This can be useful in + * the vhost migration code. If disconnect was caught there is an + * option for the general vhost code to get the dev state without + * knowing its type (in this case vhost-user). + * + * Note if the vhost device is fully cleared by the time we + * execute the bottom half we won't continue with the cleanup. + */ + vhost->started = false; + } +} + static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { if (!virtio_has_feature(dev->protocol_features, From patchwork Mon Dec 5 09:51:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631047 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2424188pvb; Mon, 5 Dec 2022 02:00:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Ck3t3Tz9ocKw27q74vZIGr+C5zodHUABL6vWStw1UO6iQtaUs9MSugLbni7rRoihNmyqN X-Received: by 2002:a37:b1c5:0:b0:6fb:11d1:dab2 with SMTP id a188-20020a37b1c5000000b006fb11d1dab2mr73559568qkf.75.1670234407920; Mon, 05 Dec 2022 02:00:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670234407; cv=none; d=google.com; s=arc-20160816; b=w0SKSPSTL1oU0k1/cf9asUzsGzjOBiDB652MQuKPaWfWx6dIHhz5k4rlliJwWwU7io +2IG3cgghiUadXdP6LOzVlf+LXXultx1UwUEkAm399Pv8V1s+n4pXraxhZwXhy9GJVc1 n5xUKAiLMb2b+AsQVgxu0rKY3c3KTEc5Vo6cinWqGgTzOF0uUJMDtPNbKzP0Rth3K14R LRiMTzpGQ7d4aEnPJ0QX21kZHMFRtiq11riHnISmoDjYLS+rsUPDBNQ9+ta/jtydE0Ig 5W9F71iZwAlWKNto6PgmFVvjzq5FQAhKURXSydxWPj/nYmCCGNa5xciiqTx+jeCva9lj 0enA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=No1rFWDOGgcpCRxA+eKIpRsQyOQa34f3lMNtg8s8nvw=; b=vBcKaO0NaQgkb8A8c8Bu+sVs+TBbfZBU98PB0wh3R7SJYk0zvQjgAY1Fq65F2dZAVb TFXlJiA6OroKR582OThSWcpmZkderD/G2A6s5VCXEJYbr9b79WZ2dwehmAQKWkwgkFug q4gMUOJs6ajIsMjVU5WKVtznxqB/XmhjO9DdP43XqcBJ5gxDaioGONixQ+ffUjCJLWE7 72eHeuKCNZ9xi/7XE7sVbU4JJdlND5Vx6s0rvRgCCJ7+sDBUNVgJxbeFt5qwlJnJKEmz 4MVhEFHA72Q1tRAC6BbUtxeGY02a6xktf5MRnCvK/qEKvCax5WSMOIbXNIMvXss4BrQF UE/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KNalBSSE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fy10-20020a05622a5a0a00b0039cdd7adeddsi7394490qtb.616.2022.12.05.02.00.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:00:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KNalBSSE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Bg-0002IJ-BW; Mon, 05 Dec 2022 04:55:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BX-000228-7L for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28BV-0006xs-MU for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:54:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=No1rFWDOGgcpCRxA+eKIpRsQyOQa34f3lMNtg8s8nvw=; b=KNalBSSEcivUUWmLJwjieYOoUjAVRSoK8iMh4IuW1zO+iHle/hZZDnWlKppuNxSjOQllxW KkrL4E7Jvui14J7IXCTWnGgIXKM2IbNaZnIDou8Muhbf3dHWp6kr9wniPNJuQMDC5iRT+W aOB33nZB+rdi6+ZdswJAqJe/KXTCgQw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-LvnWEbokMBiiSiQFcldH3Q-1; Mon, 05 Dec 2022 04:54:46 -0500 X-MC-Unique: LvnWEbokMBiiSiQFcldH3Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64306101A56C; Mon, 5 Dec 2022 09:54:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CCD52166B29; Mon, 5 Dec 2022 09:54:38 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz Subject: [PATCH v2 16/51] include/hw: VM state takes precedence in virtio_device_should_start Date: Mon, 5 Dec 2022 10:51:53 +0100 Message-Id: <20221205095228.1314-17-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée The VM status should always preempt the device status for these checks. This ensures the device is in the correct state when we suspend the VM prior to migrations. This restores the checks to the order they where in before the refactoring moved things around. While we are at it lets improve our documentation of the various fields involved and document the two functions. Fixes: 9f6bcfd99f (hw/virtio: move vm_running check to virtio_device_started) Fixes: 259d69c00b (hw/virtio: introduce virtio_device_should_start) Signed-off-by: Alex Bennée Tested-by: Christian Borntraeger Reviewed-by: Michael S. Tsirkin Message-Id: <20221130112439.2527228-6-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index a973811cbf..acfd4df125 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -116,6 +116,13 @@ struct VirtIODevice bool broken; /* device in invalid state, needs reset */ bool use_disabled_flag; /* allow use of 'disable' flag when needed */ bool disabled; /* device in temporarily disabled state */ + /** + * @use_started: true if the @started flag should be used to check the + * current state of the VirtIO device. Otherwise status bits + * should be checked for a current status of the device. + * @use_started is only set via QMP and defaults to true for all + * modern machines (since 4.1). + */ bool use_started; bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */ @@ -391,6 +398,16 @@ static inline bool virtio_is_big_endian(VirtIODevice *vdev) return false; } +/** + * virtio_device_started() - check if device started + * @vdev - the VirtIO device + * @status - the devices status bits + * + * Check if the device is started. For most modern machines this is + * tracked via the @vdev->started field (to support migration), + * otherwise we check for the final negotiated status bit that + * indicates everything is ready. + */ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) { if (vdev->use_started) { @@ -411,15 +428,11 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) */ static inline bool virtio_device_should_start(VirtIODevice *vdev, uint8_t status) { - if (vdev->use_started) { - return vdev->started; - } - if (!vdev->vm_running) { return false; } - return status & VIRTIO_CONFIG_S_DRIVER_OK; + return virtio_device_started(vdev, status); } static inline void virtio_set_started(VirtIODevice *vdev, bool started) From patchwork Mon Dec 5 09:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 631053 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2432011pvb; Mon, 5 Dec 2022 02:18:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf62HdoDhIkYF/tZDqQBXBsQPgxSh8ckiJv0Us//Px9aqa+n0z38VMuO5BNFNHKV2BU5fL1F X-Received: by 2002:ac8:1383:0:b0:3a7:e50f:69bc with SMTP id h3-20020ac81383000000b003a7e50f69bcmr2463569qtj.53.1670235525554; Mon, 05 Dec 2022 02:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670235525; cv=none; d=google.com; s=arc-20160816; b=A4VFVXtU3up8BcZkLhc+NWbMeM/iF8370KlGswQMGTwJLX1AnvsSoVBsdhbnJBiRxX Nf28RYVWs4k7QfPAmZE8DhrRDu0ypc/FfJUNQW6TmPC05I36z79wRIEIranpT1gUh1mt yBIO6Fs+Xpd/m3iDERN2jSIdSKU5Q9Hc/3BSRPwb4s/HaF3S5I4Mtt41CrnxOQyMxHYT v0zj5srsVq4DSFJg+xJQKHL5a/NFaVg3isRdnuqHc1dxfHwjGNBVUK1wtA6tgsIMB4IE oPOHU9CYBP+5hZm9zBQCMTYibMpXKorXmR7feyXpl1R3y6F0x+QEJ4xILzLisL7Xl4gd +xGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dnkYOrTgO+HGLMQelFOS97QjJMRgo81PYH7NJKA+HKk=; b=HCrj76BJDiLROJsTMf9otBL7kb5pRzwG+BV3trqIChbbdECZZ8MNVye9KS0Bp079Yx rPnEtmWvFceyVYdkAboUmGAA5KnzSCxLutmORxfkrW23/Od6169/5Jla4eFc+QehbBrp x+cVK47dWRdQ1f+0IMEuJQLIYdmRe5jcr8cViyWB/hHikC6wq0Gevze2qpQ0d+e+qVyK 6RoUvuzzCGgbp/bGPwKBS9xy2mX5VXlDclq2YG2Xd5g1tv/K79uFaKrM5qo5N13ck1cB lSeEOqA4p9GnsIqe+q9Toni622u+numE1vIglbJUDQPW+DUzSY0qG/GoWxWFysMTkccI Gcug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R1oPZn5w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bk42-20020a05620a1a2a00b006fb1bf042ddsi8074730qkb.360.2022.12.05.02.18.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 02:18:45 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R1oPZn5w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p28Cg-0003QP-J9; Mon, 05 Dec 2022 04:56:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28CS-00034Q-Ff for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:55:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p28CN-0007QX-DS for qemu-devel@nongnu.org; Mon, 05 Dec 2022 04:55:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670234142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnkYOrTgO+HGLMQelFOS97QjJMRgo81PYH7NJKA+HKk=; b=R1oPZn5waUm1MpNohvAiQEYBFMFNVxuLCpleOEKpiZK8z57kPlUmIXcZRmsk4rjItsqeQ5 da8TbB5/1l8zb132/Gdm5XTge+UqlLFi6rD/IYQp9fs0t/WSgxT6eTiqMiOzjRrUwMIsUu bzjHqI//SsF4wOFcMgyimQS2g5b3yo8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-5-8t4q3dc7PkiPR_2Ty-aeZg-1; Mon, 05 Dec 2022 04:55:40 -0500 X-MC-Unique: 8t4q3dc7PkiPR_2Ty-aeZg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5829B185A794; Mon, 5 Dec 2022 09:55:39 +0000 (UTC) Received: from secure.mitica (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id F35CF2166B29; Mon, 5 Dec 2022 09:55:31 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fam Zheng , Thomas Huth , Viresh Kumar , Kevin Wolf , Mathieu Poirier , Laurent Vivier , Eric Blake , Richard Henderson , Raphael Norwitz , Stefan Hajnoczi , Juan Quintela , virtio-fs@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Christian Borntraeger , "Gonglei (Arei)" , qemu-block@nongnu.org, Xiaojuan Yang , Thomas Huth , Ilya Leoshkevich , Eduardo Habkost , Gerd Hoffmann , "Dr. David Alan Gilbert" , Alex Williamson , Eric Farman , Halil Pasic , Peter Maydell , Vladimir Sementsov-Ogievskiy , Jason Wang , Laurent Vivier , Song Gao , qemu-s390x@nongnu.org, Pavel Dovgalyuk , Klaus Jensen , John Snow , Michael Tokarev , qemu-arm@nongnu.org, Paolo Bonzini , "Michael S. Tsirkin" , Keith Busch , David Hildenbrand , qemu-trivial@nongnu.org, Hanna Reitz , Daniel Hoffman Subject: [PATCH v2 23/51] target/i386: Always completely initialize TranslateFault Date: Mon, 5 Dec 2022 10:52:00 +0100 Message-Id: <20221205095228.1314-24-quintela@redhat.com> In-Reply-To: <20221205095228.1314-1-quintela@redhat.com> References: <20221205095228.1314-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson In get_physical_address, the canonical address check failed to set TranslateFault.stage2, which resulted in an uninitialized read from the struct when reporting the fault in x86_cpu_tlb_fill. Adjust all error paths to use structure assignment so that the entire struct is always initialized. Reported-by: Daniel Hoffman Fixes: 9bbcf372193a ("target/i386: Reorg GET_HPHYS") Signed-off-by: Richard Henderson Message-Id: <20221201074522.178498-1-richard.henderson@linaro.org> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1324 Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/excp_helper.c | 34 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c index 405a5d414a..55bd1194d3 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -71,10 +71,11 @@ static bool ptw_translate(PTETranslate *inout, hwaddr addr) TranslateFault *err = inout->err; assert(inout->ptw_idx == MMU_NESTED_IDX); - err->exception_index = 0; /* unused */ - err->error_code = inout->env->error_code; - err->cr2 = addr; - err->stage2 = S2_GPT; + *err = (TranslateFault){ + .error_code = inout->env->error_code, + .cr2 = addr, + .stage2 = S2_GPT, + }; return false; } return true; @@ -431,10 +432,11 @@ do_check_protect_pse36: MMU_NESTED_IDX, true, &pte_trans.haddr, &full, 0); if (unlikely(flags & TLB_INVALID_MASK)) { - err->exception_index = 0; /* unused */ - err->error_code = env->error_code; - err->cr2 = paddr; - err->stage2 = S2_GPA; + *err = (TranslateFault){ + .error_code = env->error_code, + .cr2 = paddr, + .stage2 = S2_GPA, + }; return false; } @@ -494,10 +496,11 @@ do_check_protect_pse36: } break; } - err->exception_index = EXCP0E_PAGE; - err->error_code = error_code; - err->cr2 = addr; - err->stage2 = S2_NONE; + *err = (TranslateFault){ + .exception_index = EXCP0E_PAGE, + .error_code = error_code, + .cr2 = addr, + }; return false; } @@ -564,9 +567,10 @@ static bool get_physical_address(CPUX86State *env, vaddr addr, int shift = in.pg_mode & PG_MODE_LA57 ? 56 : 47; int64_t sext = (int64_t)addr >> shift; if (sext != 0 && sext != -1) { - err->exception_index = EXCP0D_GPF; - err->error_code = 0; - err->cr2 = addr; + *err = (TranslateFault){ + .exception_index = EXCP0D_GPF, + .cr2 = addr, + }; return false; } }